l-min-components 1.0.1063 → 1.0.1066
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -7,33 +7,32 @@ import { Container } from "./styled";
|
|
|
7
7
|
import draftToHtml from "draftjs-to-html";
|
|
8
8
|
import htmlToDraft from "html-to-draftjs";
|
|
9
9
|
|
|
10
|
-
function TextEditor({
|
|
11
|
-
|
|
10
|
+
function TextEditor({ onChange, defaultValue }) {
|
|
11
|
+
let defaultState;
|
|
12
|
+
|
|
13
|
+
if (defaultValue) {
|
|
14
|
+
const contentBlock = htmlToDraft(defaultValue);
|
|
15
|
+
if (contentBlock) {
|
|
16
|
+
const contentState = ContentState.createFromBlockArray(
|
|
17
|
+
contentBlock.contentBlocks
|
|
18
|
+
);
|
|
19
|
+
defaultState = EditorState?.createWithContent(contentState);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const [editorState, setEditorState] = useState(
|
|
24
|
+
defaultState || EditorState.createEmpty()
|
|
25
|
+
);
|
|
12
26
|
|
|
13
27
|
const onEditorStateChange = (newState) => {
|
|
14
28
|
setEditorState(newState);
|
|
15
29
|
};
|
|
16
30
|
|
|
17
31
|
useEffect(() => {
|
|
18
|
-
const
|
|
19
|
-
|
|
32
|
+
const html = draftToHtml(convertToRaw(editorState?.getCurrentContent()));
|
|
33
|
+
onChange && onChange(html);
|
|
20
34
|
}, [editorState]);
|
|
21
35
|
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
if (defaultValue) {
|
|
24
|
-
const contentBlock = htmlToDraft(defaultValue);
|
|
25
|
-
if (contentBlock) {
|
|
26
|
-
const contentState = ContentState.createFromBlockArray(
|
|
27
|
-
contentBlock.contentBlocks
|
|
28
|
-
);
|
|
29
|
-
const defualtState = EditorState.createWithContent(contentState);
|
|
30
|
-
onEditorStateChange(defualtState);
|
|
31
|
-
}
|
|
32
|
-
} else {
|
|
33
|
-
onEditorStateChange(EditorState.createEmpty());
|
|
34
|
-
}
|
|
35
|
-
}, []);
|
|
36
|
-
|
|
37
36
|
return (
|
|
38
37
|
<Container>
|
|
39
38
|
<Editor
|