@arkyn/components 1.3.120 → 1.3.121
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/bundle.js +5946 -4080
- package/dist/bundle.umd.cjs +33 -32
- package/dist/components/RichText/functions/deserialize.d.ts +3 -0
- package/dist/components/RichText/functions/deserialize.d.ts.map +1 -0
- package/dist/components/RichText/functions/deserialize.js +54 -0
- package/dist/components/RichText/functions/extractText.d.ts +4 -0
- package/dist/components/RichText/functions/extractText.d.ts.map +1 -0
- package/dist/components/RichText/functions/extractText.js +5 -0
- package/dist/components/RichText/functions/serialize.d.ts +3 -2
- package/dist/components/RichText/functions/serialize.d.ts.map +1 -1
- package/dist/components/RichText/functions/serialize.js +21 -24
- package/dist/components/RichText/index.d.ts.map +1 -1
- package/dist/components/RichText/index.js +17 -14
- package/package.json +2 -1
- package/src/components/RichText/defineType.d.ts +1 -0
- package/src/components/RichText/functions/deserialize.ts +62 -0
- package/src/components/RichText/functions/extractText.ts +7 -0
- package/src/components/RichText/functions/serialize.ts +22 -25
- package/src/components/RichText/index.tsx +20 -29
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"deserialize.d.ts","sourceRoot":"","sources":["../../../../src/components/RichText/functions/deserialize.ts"],"names":[],"mappings":"AA8CA,QAAA,MAAM,gBAAgB,SAAU,MAAM,mFAarC,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import parse from "html-react-parser";
|
2
|
+
const deserialize = (el) => {
|
3
|
+
if (typeof el === "string")
|
4
|
+
return { text: el || "" };
|
5
|
+
function parsedChildren(children) {
|
6
|
+
return children.map((child) => deserialize(child));
|
7
|
+
}
|
8
|
+
const children = Array.isArray(el.props.children)
|
9
|
+
? parsedChildren(el.props.children)
|
10
|
+
: [{ text: el.props.children }];
|
11
|
+
switch (el.type) {
|
12
|
+
case "p":
|
13
|
+
return { type: "paragraph", children };
|
14
|
+
case "blockquote":
|
15
|
+
return { type: "blockQuote", children };
|
16
|
+
case "ul":
|
17
|
+
return { type: "bulletedList", children };
|
18
|
+
case "h1":
|
19
|
+
return { type: "headingOne", children };
|
20
|
+
case "h2":
|
21
|
+
return { type: "headingTwo", children };
|
22
|
+
case "li":
|
23
|
+
return { type: "listItem", children };
|
24
|
+
case "ol":
|
25
|
+
return { type: "numberedList", children };
|
26
|
+
case "strong":
|
27
|
+
return { text: "", children, bold: true };
|
28
|
+
case "code":
|
29
|
+
return { text: "", children, code: true };
|
30
|
+
case "em":
|
31
|
+
return { text: "", children, italic: true };
|
32
|
+
case "u":
|
33
|
+
return { text: "", children, underline: true };
|
34
|
+
default:
|
35
|
+
return { text: "", children };
|
36
|
+
}
|
37
|
+
};
|
38
|
+
const getSlateFromHtml = (html) => {
|
39
|
+
const parsed = parse(html);
|
40
|
+
if (Array.isArray(parsed)) {
|
41
|
+
return parsed.flatMap((el) => {
|
42
|
+
if (typeof el === "string")
|
43
|
+
return { text: el };
|
44
|
+
return deserialize(el);
|
45
|
+
});
|
46
|
+
}
|
47
|
+
else if (typeof parsed === "string") {
|
48
|
+
return [{ text: parsed }];
|
49
|
+
}
|
50
|
+
else {
|
51
|
+
return [deserialize(parsed)];
|
52
|
+
}
|
53
|
+
};
|
54
|
+
export { getSlateFromHtml };
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"extractText.d.ts","sourceRoot":"","sources":["../../../../src/components/RichText/functions/extractText.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAQ,MAAM,OAAO,CAAC;AAEzC,iBAAS,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,UAEvC;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../../../src/components/RichText/functions/serialize.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../../../src/components/RichText/functions/serialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiC,MAAM,OAAO,CAAC;AA8C9D,QAAA,MAAM,gBAAgB,WAAY,MAAM,KAAG,MAE1C,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
@@ -1,11 +1,21 @@
|
|
1
|
-
|
2
|
-
import { Element as SlateElement } from "slate";
|
1
|
+
import { Element as SlateElement, Text } from "slate";
|
3
2
|
const serialize = (node) => {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
if (Text.isText(node)) {
|
4
|
+
let text = node.text;
|
5
|
+
if (node.bold) {
|
6
|
+
text = `<strong>${text}</strong>`;
|
7
|
+
}
|
8
|
+
if (node.code) {
|
9
|
+
text = `<code>${text}</code>`;
|
10
|
+
}
|
11
|
+
if (node.italic) {
|
12
|
+
text = `<em>${text}</em>`;
|
13
|
+
}
|
14
|
+
if (node.underline) {
|
15
|
+
text = `<u>${text}</u>`;
|
16
|
+
}
|
17
|
+
return text;
|
18
|
+
}
|
9
19
|
if (SlateElement.isElement(node)) {
|
10
20
|
const children = node.children.map((n) => serialize(n)).join("");
|
11
21
|
switch (node.type) {
|
@@ -27,22 +37,9 @@ const serialize = (node) => {
|
|
27
37
|
return children;
|
28
38
|
}
|
29
39
|
}
|
30
|
-
if (node.text) {
|
31
|
-
let text = node.text;
|
32
|
-
if (node.bold) {
|
33
|
-
text = `<strong>${text}</strong>`;
|
34
|
-
}
|
35
|
-
if (node.code) {
|
36
|
-
text = `<code>${text}</code>`;
|
37
|
-
}
|
38
|
-
if (node.italic) {
|
39
|
-
text = `<em>${text}</em>`;
|
40
|
-
}
|
41
|
-
if (node.underline) {
|
42
|
-
text = `<u>${text}</u>`;
|
43
|
-
}
|
44
|
-
return text;
|
45
|
-
}
|
46
40
|
return "";
|
47
41
|
};
|
48
|
-
|
42
|
+
const getHtmlFromSlate = (editor) => {
|
43
|
+
return editor.children.map((node) => serialize(node)).join("");
|
44
|
+
};
|
45
|
+
export { getHtmlFromSlate };
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/RichText/index.tsx"],"names":[],"mappings":"AAeA,OAAO,EAAgB,UAAU,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/RichText/index.tsx"],"names":[],"mappings":"AAeA,OAAO,EAAgB,UAAU,EAAc,MAAM,OAAO,CAAC;AAc7D,OAAO,cAAc,CAAC;AAMtB,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,uBAAuB,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,IAAI,CAAC;IACzC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACzC,CAAC;AAEF,iBAAS,QAAQ,CAAC,EAChB,IAAI,EACJ,YAAY,EACZ,qBAA6B,EAC7B,uBAAuB,EACvB,QAAe,EACf,aAAa,EACb,QAAQ,EACR,OAAO,EAAE,WAAW,GACrB,EAAE,aAAa,2CAwGf;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import isHotkey from "is-hotkey";
|
3
3
|
import { AlignCenter, AlignJustify, AlignLeft, AlignRight, Bold, Code, Heading1, Heading2, Italic, Quote, Underline, } from "lucide-react";
|
4
4
|
import { useCallback, useMemo, useRef, useState } from "react";
|
5
|
-
import { createEditor, Transforms
|
5
|
+
import { createEditor, Transforms } from "slate";
|
6
6
|
import { withHistory } from "slate-history";
|
7
7
|
import { Editable, Slate, withReact } from "slate-react";
|
8
8
|
import { BlockButton } from "./components/BlockButton/intex";
|
@@ -13,21 +13,24 @@ import { Toolbar } from "./components/Toolbar";
|
|
13
13
|
import { toggleMark } from "./functions/toggleMark";
|
14
14
|
import { HOTKEYS } from "./template/HOTKEYS";
|
15
15
|
import { INITIAL_VALUE } from "./template/INITIAL_VALUE";
|
16
|
-
import "./styles.css";
|
17
16
|
import { useFormController } from "../Form/FormController";
|
17
|
+
import "./styles.css";
|
18
|
+
import { getSlateFromHtml } from "./functions/deserialize";
|
19
|
+
import { extractText } from "./functions/extractText";
|
20
|
+
import { getHtmlFromSlate } from "./functions/serialize";
|
18
21
|
function RichText({ name, defaultValue, enforceCharacterLimit = false, onChangeCharactersCount, maxLimit = 2000, onValueChange, onChange, isError: baseIsError, }) {
|
19
|
-
|
20
|
-
return nodes.map((n) => Node.string(n)).join("");
|
21
|
-
}
|
22
|
-
const defaultNodes = defaultValue ? JSON.parse(defaultValue) : INITIAL_VALUE;
|
23
|
-
const [charactersCount, setCharactersCount] = useState(extractText(defaultNodes).length);
|
24
|
-
const [editorValue, setEditorValue] = useState(defaultNodes);
|
25
|
-
const [onFocus, setOnFocus] = useState(false);
|
22
|
+
const editor = useMemo(() => withHistory(withReact(createEditor())), []);
|
26
23
|
const { id, inputRef, error } = useFormController();
|
27
24
|
const baseRef = useRef(null);
|
25
|
+
const defaultNodes = defaultValue
|
26
|
+
? getSlateFromHtml(defaultValue)
|
27
|
+
: INITIAL_VALUE;
|
28
|
+
const textFromNodes = extractText(defaultNodes);
|
29
|
+
const [charactersCount, setCharactersCount] = useState(textFromNodes.length);
|
30
|
+
const [inputValue, setInputValue] = useState(defaultValue);
|
31
|
+
const [onFocus, setOnFocus] = useState(false);
|
28
32
|
const ref = inputRef || baseRef;
|
29
33
|
const isError = baseIsError || !!error;
|
30
|
-
const editor = useMemo(() => withHistory(withReact(createEditor())), []);
|
31
34
|
const renderLeaf = useCallback(Leaf, []);
|
32
35
|
const renderElement = useCallback(Element, []);
|
33
36
|
function handleChange(value) {
|
@@ -38,9 +41,9 @@ function RichText({ name, defaultValue, enforceCharacterLimit = false, onChangeC
|
|
38
41
|
return;
|
39
42
|
}
|
40
43
|
else {
|
41
|
-
|
44
|
+
setInputValue(getHtmlFromSlate(editor));
|
42
45
|
onChange && onChange(value);
|
43
|
-
onValueChange && onValueChange(
|
46
|
+
onValueChange && onValueChange(getHtmlFromSlate(editor));
|
44
47
|
editor.children = value;
|
45
48
|
Transforms.setNodes(editor, { children: value });
|
46
49
|
}
|
@@ -53,7 +56,7 @@ function RichText({ name, defaultValue, enforceCharacterLimit = false, onChangeC
|
|
53
56
|
: "errorFalse";
|
54
57
|
const className = `arkynRichText ${errorClass} ${focusClass}`;
|
55
58
|
const restatesCharacters = maxLimit - charactersCount;
|
56
|
-
return (_jsxs(Slate, { editor: editor, initialValue:
|
59
|
+
return (_jsxs(Slate, { editor: editor, initialValue: defaultNodes, onChange: handleChange, onValueChange: handleChange, children: [_jsxs("div", { className: className, children: [_jsxs(Toolbar, { children: [_jsx(BlockButton, { format: "headingOne", icon: Heading1 }), _jsx(BlockButton, { format: "headingTwo", icon: Heading2 }), _jsx(BlockButton, { format: "blockQuote", icon: Quote }), _jsx(MarkButton, { format: "bold", icon: Bold }), _jsx(MarkButton, { format: "italic", icon: Italic }), _jsx(MarkButton, { format: "underline", icon: Underline }), _jsx(MarkButton, { format: "code", icon: Code }), _jsx(BlockButton, { format: "left", icon: AlignLeft }), _jsx(BlockButton, { format: "right", icon: AlignRight }), _jsx(BlockButton, { format: "center", icon: AlignCenter }), _jsx(BlockButton, { format: "justify", icon: AlignJustify })] }), _jsx(Editable, { className: "editorContainer", renderElement: renderElement, renderLeaf: renderLeaf, spellCheck: true, id: id, onFocus: () => setOnFocus(true), onBlur: () => setOnFocus(false), onKeyDown: (event) => {
|
57
60
|
for (const hotkey in HOTKEYS) {
|
58
61
|
if (isHotkey(hotkey, event)) {
|
59
62
|
event.preventDefault();
|
@@ -61,6 +64,6 @@ function RichText({ name, defaultValue, enforceCharacterLimit = false, onChangeC
|
|
61
64
|
toggleMark(editor, mark);
|
62
65
|
}
|
63
66
|
}
|
64
|
-
} }), restatesCharacters < 0 && (_jsx("div", { className: "restatesCharacters", children: restatesCharacters }))] }), _jsx("input", { ref: ref, type: "hidden", name: name, value:
|
67
|
+
} }), restatesCharacters < 0 && (_jsx("div", { className: "restatesCharacters", children: restatesCharacters }))] }), _jsx("input", { ref: ref, type: "hidden", name: name, value: inputValue }), _jsx("input", { type: "hidden", name: `${name}Count`, value: charactersCount })] }));
|
65
68
|
}
|
66
69
|
export { RichText };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arkyn/components",
|
3
|
-
"version": "1.3.
|
3
|
+
"version": "1.3.121",
|
4
4
|
"main": "./dist/bundle.js",
|
5
5
|
"types": "./dist/index.d.ts",
|
6
6
|
"author": "Lucas Gonçalves",
|
@@ -14,6 +14,7 @@
|
|
14
14
|
"@react-google-maps/api": "^2.19.3",
|
15
15
|
"@react-input/mask": "^1.2.5",
|
16
16
|
"framer-motion": "^11.3.21",
|
17
|
+
"html-react-parser": "^5.1.16",
|
17
18
|
"is-hotkey": "^0.2.0",
|
18
19
|
"lucide-react": "^0.424.0",
|
19
20
|
"react-scroll": "^1.9.0",
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import { Descendant } from "slate";
|
2
|
+
import parse from "html-react-parser";
|
3
|
+
|
4
|
+
type ParseElement =
|
5
|
+
| { type: string; props: { children: ParseElement[] | string } }
|
6
|
+
| "string";
|
7
|
+
|
8
|
+
const deserialize = (el: ParseElement): Descendant => {
|
9
|
+
if (typeof el === "string") return { text: el || "" };
|
10
|
+
|
11
|
+
function parsedChildren(children: ParseElement[]) {
|
12
|
+
return children.map((child) => deserialize(child));
|
13
|
+
}
|
14
|
+
|
15
|
+
const children = Array.isArray(el.props.children)
|
16
|
+
? parsedChildren(el.props.children)
|
17
|
+
: [{ text: el.props.children }];
|
18
|
+
|
19
|
+
switch (el.type) {
|
20
|
+
case "p":
|
21
|
+
return { type: "paragraph", children };
|
22
|
+
case "blockquote":
|
23
|
+
return { type: "blockQuote", children };
|
24
|
+
case "ul":
|
25
|
+
return { type: "bulletedList", children };
|
26
|
+
case "h1":
|
27
|
+
return { type: "headingOne", children };
|
28
|
+
case "h2":
|
29
|
+
return { type: "headingTwo", children };
|
30
|
+
case "li":
|
31
|
+
return { type: "listItem", children };
|
32
|
+
case "ol":
|
33
|
+
return { type: "numberedList", children };
|
34
|
+
case "strong":
|
35
|
+
return { text: "", children, bold: true };
|
36
|
+
case "code":
|
37
|
+
return { text: "", children, code: true };
|
38
|
+
case "em":
|
39
|
+
return { text: "", children, italic: true };
|
40
|
+
case "u":
|
41
|
+
return { text: "", children, underline: true };
|
42
|
+
default:
|
43
|
+
return { text: "", children };
|
44
|
+
}
|
45
|
+
};
|
46
|
+
|
47
|
+
const getSlateFromHtml = (html: string) => {
|
48
|
+
const parsed = parse(html);
|
49
|
+
|
50
|
+
if (Array.isArray(parsed)) {
|
51
|
+
return parsed.flatMap((el) => {
|
52
|
+
if (typeof el === "string") return { text: el };
|
53
|
+
return deserialize(el);
|
54
|
+
});
|
55
|
+
} else if (typeof parsed === "string") {
|
56
|
+
return [{ text: parsed }];
|
57
|
+
} else {
|
58
|
+
return [deserialize(parsed)];
|
59
|
+
}
|
60
|
+
};
|
61
|
+
|
62
|
+
export { getSlateFromHtml };
|
@@ -1,12 +1,22 @@
|
|
1
|
-
|
2
|
-
import { Element as SlateElement } from "slate";
|
1
|
+
import { Editor, Element as SlateElement, Text } from "slate";
|
3
2
|
|
4
3
|
const serialize = (node: any): string => {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
if (Text.isText(node)) {
|
5
|
+
let text = node.text;
|
6
|
+
if (node.bold) {
|
7
|
+
text = `<strong>${text}</strong>`;
|
8
|
+
}
|
9
|
+
if (node.code) {
|
10
|
+
text = `<code>${text}</code>`;
|
11
|
+
}
|
12
|
+
if (node.italic) {
|
13
|
+
text = `<em>${text}</em>`;
|
14
|
+
}
|
15
|
+
if (node.underline) {
|
16
|
+
text = `<u>${text}</u>`;
|
17
|
+
}
|
18
|
+
return text;
|
19
|
+
}
|
10
20
|
|
11
21
|
if (SlateElement.isElement(node)) {
|
12
22
|
const children = node.children.map((n: any) => serialize(n)).join("");
|
@@ -31,24 +41,11 @@ const serialize = (node: any): string => {
|
|
31
41
|
}
|
32
42
|
}
|
33
43
|
|
34
|
-
if (node.text) {
|
35
|
-
let text = node.text;
|
36
|
-
if (node.bold) {
|
37
|
-
text = `<strong>${text}</strong>`;
|
38
|
-
}
|
39
|
-
if (node.code) {
|
40
|
-
text = `<code>${text}</code>`;
|
41
|
-
}
|
42
|
-
if (node.italic) {
|
43
|
-
text = `<em>${text}</em>`;
|
44
|
-
}
|
45
|
-
if (node.underline) {
|
46
|
-
text = `<u>${text}</u>`;
|
47
|
-
}
|
48
|
-
return text;
|
49
|
-
}
|
50
|
-
|
51
44
|
return "";
|
52
45
|
};
|
53
46
|
|
54
|
-
|
47
|
+
const getHtmlFromSlate = (editor: Editor): string => {
|
48
|
+
return editor.children.map((node) => serialize(node)).join("");
|
49
|
+
};
|
50
|
+
|
51
|
+
export { getHtmlFromSlate };
|
@@ -13,7 +13,7 @@ import {
|
|
13
13
|
Underline,
|
14
14
|
} from "lucide-react";
|
15
15
|
import { useCallback, useMemo, useRef, useState } from "react";
|
16
|
-
import { createEditor, Descendant, Transforms
|
16
|
+
import { createEditor, Descendant, Transforms } from "slate";
|
17
17
|
import { withHistory } from "slate-history";
|
18
18
|
import { Editable, Slate, withReact } from "slate-react";
|
19
19
|
|
@@ -26,8 +26,12 @@ import { toggleMark } from "./functions/toggleMark";
|
|
26
26
|
import { HOTKEYS } from "./template/HOTKEYS";
|
27
27
|
import { INITIAL_VALUE } from "./template/INITIAL_VALUE";
|
28
28
|
|
29
|
-
import "./styles.css";
|
30
29
|
import { useFormController } from "../Form/FormController";
|
30
|
+
import "./styles.css";
|
31
|
+
|
32
|
+
import { getSlateFromHtml } from "./functions/deserialize";
|
33
|
+
import { extractText } from "./functions/extractText";
|
34
|
+
import { getHtmlFromSlate } from "./functions/serialize";
|
31
35
|
|
32
36
|
type RichTextProps = {
|
33
37
|
name: string;
|
@@ -50,28 +54,24 @@ function RichText({
|
|
50
54
|
onChange,
|
51
55
|
isError: baseIsError,
|
52
56
|
}: RichTextProps) {
|
53
|
-
|
54
|
-
|
55
|
-
}
|
56
|
-
|
57
|
-
const defaultNodes = defaultValue ? JSON.parse(defaultValue) : INITIAL_VALUE;
|
57
|
+
const editor = useMemo(() => withHistory(withReact(createEditor())), []);
|
58
|
+
const { id, inputRef, error } = useFormController();
|
58
59
|
|
59
|
-
const
|
60
|
-
extractText(defaultNodes).length
|
61
|
-
);
|
60
|
+
const baseRef = useRef<HTMLInputElement>(null);
|
62
61
|
|
63
|
-
const
|
64
|
-
|
62
|
+
const defaultNodes = defaultValue
|
63
|
+
? getSlateFromHtml(defaultValue)
|
64
|
+
: INITIAL_VALUE;
|
65
65
|
|
66
|
-
const
|
66
|
+
const textFromNodes = extractText(defaultNodes);
|
67
67
|
|
68
|
-
const
|
68
|
+
const [charactersCount, setCharactersCount] = useState(textFromNodes.length);
|
69
|
+
const [inputValue, setInputValue] = useState(defaultValue);
|
70
|
+
const [onFocus, setOnFocus] = useState(false);
|
69
71
|
|
70
72
|
const ref = inputRef || baseRef;
|
71
73
|
const isError = baseIsError || !!error;
|
72
74
|
|
73
|
-
const editor = useMemo(() => withHistory(withReact(createEditor())), []);
|
74
|
-
|
75
75
|
const renderLeaf = useCallback(Leaf, []);
|
76
76
|
const renderElement = useCallback(Element, []);
|
77
77
|
|
@@ -84,10 +84,10 @@ function RichText({
|
|
84
84
|
if (enforceCharacterLimit && text.length >= maxLimit) {
|
85
85
|
return;
|
86
86
|
} else {
|
87
|
-
|
87
|
+
setInputValue(getHtmlFromSlate(editor));
|
88
88
|
|
89
89
|
onChange && onChange(value);
|
90
|
-
onValueChange && onValueChange(
|
90
|
+
onValueChange && onValueChange(getHtmlFromSlate(editor));
|
91
91
|
|
92
92
|
editor.children = value;
|
93
93
|
Transforms.setNodes(editor, { children: value });
|
@@ -108,7 +108,7 @@ function RichText({
|
|
108
108
|
return (
|
109
109
|
<Slate
|
110
110
|
editor={editor}
|
111
|
-
initialValue={
|
111
|
+
initialValue={defaultNodes}
|
112
112
|
onChange={handleChange}
|
113
113
|
onValueChange={handleChange}
|
114
114
|
>
|
@@ -117,9 +117,6 @@ function RichText({
|
|
117
117
|
<BlockButton format="headingOne" icon={Heading1} />
|
118
118
|
<BlockButton format="headingTwo" icon={Heading2} />
|
119
119
|
<BlockButton format="blockQuote" icon={Quote} />
|
120
|
-
{/* <BlockButton format="bulletedList" icon={ListVideo} /> */}
|
121
|
-
{/* <BlockButton format="listItem" icon={List} /> */}
|
122
|
-
{/* <BlockButton format="numberedList" icon={ListOrdered} /> */}
|
123
120
|
|
124
121
|
<MarkButton format="bold" icon={Bold} />
|
125
122
|
<MarkButton format="italic" icon={Italic} />
|
@@ -156,13 +153,7 @@ function RichText({
|
|
156
153
|
)}
|
157
154
|
</div>
|
158
155
|
|
159
|
-
<input
|
160
|
-
ref={ref}
|
161
|
-
type="hidden"
|
162
|
-
name={name}
|
163
|
-
value={JSON.stringify(editorValue)}
|
164
|
-
/>
|
165
|
-
|
156
|
+
<input ref={ref} type="hidden" name={name} value={inputValue} />
|
166
157
|
<input type="hidden" name={`${name}Count`} value={charactersCount} />
|
167
158
|
</Slate>
|
168
159
|
);
|