@arkyn/components 1.3.120 → 1.3.122
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 +55 -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 +65 -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 +21 -30
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"deserialize.d.ts","sourceRoot":"","sources":["../../../../src/components/RichText/functions/deserialize.ts"],"names":[],"mappings":"AAiDA,QAAA,MAAM,gBAAgB,SAAU,MAAM,mFAarC,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
@@ -0,0 +1,55 @@
|
|
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
|
+
const childrenString = typeof el.props.children === "string" ? el.props.children : "";
|
12
|
+
switch (el.type) {
|
13
|
+
case "p":
|
14
|
+
return { type: "paragraph", children };
|
15
|
+
case "blockquote":
|
16
|
+
return { type: "blockQuote", children };
|
17
|
+
case "ul":
|
18
|
+
return { type: "bulletedList", children };
|
19
|
+
case "h1":
|
20
|
+
return { type: "headingOne", children };
|
21
|
+
case "h2":
|
22
|
+
return { type: "headingTwo", children };
|
23
|
+
case "li":
|
24
|
+
return { type: "listItem", children };
|
25
|
+
case "ol":
|
26
|
+
return { type: "numberedList", children };
|
27
|
+
case "strong":
|
28
|
+
return { text: childrenString, bold: true };
|
29
|
+
case "code":
|
30
|
+
return { text: childrenString, code: true };
|
31
|
+
case "em":
|
32
|
+
return { text: childrenString, italic: true };
|
33
|
+
case "u":
|
34
|
+
return { text: childrenString, underline: true };
|
35
|
+
default:
|
36
|
+
return { text: childrenString };
|
37
|
+
}
|
38
|
+
};
|
39
|
+
const getSlateFromHtml = (html) => {
|
40
|
+
const parsed = parse(html);
|
41
|
+
if (Array.isArray(parsed)) {
|
42
|
+
return parsed.flatMap((el) => {
|
43
|
+
if (typeof el === "string")
|
44
|
+
return { text: el };
|
45
|
+
return deserialize(el);
|
46
|
+
});
|
47
|
+
}
|
48
|
+
else if (typeof parsed === "string") {
|
49
|
+
return [{ text: parsed }];
|
50
|
+
}
|
51
|
+
else {
|
52
|
+
return [deserialize(parsed)];
|
53
|
+
}
|
54
|
+
};
|
55
|
+
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.122",
|
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,65 @@
|
|
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
|
+
const childrenString =
|
20
|
+
typeof el.props.children === "string" ? el.props.children : "";
|
21
|
+
|
22
|
+
switch (el.type) {
|
23
|
+
case "p":
|
24
|
+
return { type: "paragraph", children };
|
25
|
+
case "blockquote":
|
26
|
+
return { type: "blockQuote", children };
|
27
|
+
case "ul":
|
28
|
+
return { type: "bulletedList", children };
|
29
|
+
case "h1":
|
30
|
+
return { type: "headingOne", children };
|
31
|
+
case "h2":
|
32
|
+
return { type: "headingTwo", children };
|
33
|
+
case "li":
|
34
|
+
return { type: "listItem", children };
|
35
|
+
case "ol":
|
36
|
+
return { type: "numberedList", children };
|
37
|
+
case "strong":
|
38
|
+
return { text: childrenString, bold: true };
|
39
|
+
case "code":
|
40
|
+
return { text: childrenString, code: true };
|
41
|
+
case "em":
|
42
|
+
return { text: childrenString, italic: true };
|
43
|
+
case "u":
|
44
|
+
return { text: childrenString, underline: true };
|
45
|
+
default:
|
46
|
+
return { text: childrenString };
|
47
|
+
}
|
48
|
+
};
|
49
|
+
|
50
|
+
const getSlateFromHtml = (html: string) => {
|
51
|
+
const parsed = parse(html);
|
52
|
+
|
53
|
+
if (Array.isArray(parsed)) {
|
54
|
+
return parsed.flatMap((el) => {
|
55
|
+
if (typeof el === "string") return { text: el };
|
56
|
+
return deserialize(el);
|
57
|
+
});
|
58
|
+
} else if (typeof parsed === "string") {
|
59
|
+
return [{ text: parsed }];
|
60
|
+
} else {
|
61
|
+
return [deserialize(parsed)];
|
62
|
+
}
|
63
|
+
};
|
64
|
+
|
65
|
+
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,44 +54,40 @@ 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
|
|
78
78
|
function handleChange(value: Descendant[]) {
|
79
79
|
const text = extractText(value);
|
80
|
-
setCharactersCount(text.length);
|
81
80
|
|
81
|
+
setCharactersCount(text.length);
|
82
82
|
onChangeCharactersCount && onChangeCharactersCount(text.length);
|
83
83
|
|
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
|
);
|