Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
submodule
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
web_component
submodule
Commits
e85cb9e9
Commit
e85cb9e9
authored
May 14, 2020
by
zhuyangbin
Browse files
Options
Browse Files
Download
Plain Diff
update
parents
aa2b1558
b99b0aa3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
3 deletions
+10
-3
index.tsx
components/braftEditor/index.tsx
+10
-3
No files found.
components/braftEditor/index.tsx
View file @
e85cb9e9
...
...
@@ -33,14 +33,16 @@ interface IProps {
onChange
?:
Function
}
const
EditorDemo
:
React
.
FC
<
IProps
>
=
({
value
,
language
=
'zh'
,
onChange
,
cRef
,
excludeControls
=
excludeControlsDefault
})
=>
{
const
EditorDemo
:
React
.
FC
<
IProps
>
=
({
value
,
language
=
'zh'
,
onChange
,
cRef
,
excludeControls
=
excludeControlsDefault
,
...
others
})
=>
{
// 创建一个空的editorState作为初始值
const
[
editorState
,
setEditorState
]
=
useState
(
BraftEditor
.
createEditorState
(
null
));
const
[
percent
,
setPercent
]
=
useState
(
0
);
// 进度条
const
previewRef
=
useRef
(
null
);
useEffect
(()
=>
{
if
(
value
&&
typeof
value
===
'object'
)
{
// 不做转换
setEditorState
(
value
)
if
(
value
&&
typeof
value
===
'object'
)
{
// 不做转换
setEditorState
(
value
)
;
}
else
{
// 使用BraftEditor.createEditorState将html字符串转换为编辑器需要的editorStat
setEditorState
(
BraftEditor
.
createEditorState
(
value
));
...
...
@@ -102,12 +104,16 @@ const EditorDemo: React.FC<IProps> = ({ value, language = 'zh', onChange, cRef,
),
},
];
const
insertText
=
(
text
:
string
)
=>
{
setEditorState
(
ContentUtils
.
insertText
(
editorState
,
text
));
};
// 向外抛出数据
useImperativeHandle
(
cRef
,
()
=>
{
return
{
getHtml
,
previewMth
,
insertText
,
};
});
...
...
@@ -128,6 +134,7 @@ const EditorDemo: React.FC<IProps> = ({ value, language = 'zh', onChange, cRef,
return
(
<
div
className=
{
styles
.
box
}
>
<
BraftEditor
{
...
others
}
id=
"editor-with-color-picker"
value=
{
editorState
}
excludeControls=
{
excludeControls
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment