@arkyn/components 1.3.121 → 1.3.123
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/dist/bundle.js +1355 -1353
- package/dist/bundle.umd.cjs +25 -25
- package/dist/components/RichText/functions/deserialize.d.ts.map +1 -1
- package/dist/components/RichText/functions/deserialize.js +6 -5
- package/dist/components/RichText/functions/isHtml.d.ts +3 -0
- package/dist/components/RichText/functions/isHtml.d.ts.map +1 -0
- package/dist/components/RichText/functions/isHtml.js +5 -0
- package/dist/components/RichText/index.d.ts.map +1 -1
- package/dist/components/RichText/index.js +3 -2
- package/package.json +1 -1
- package/src/components/RichText/functions/deserialize.ts +8 -5
- package/src/components/RichText/functions/isHtml.ts +6 -0
- package/src/components/RichText/index.tsx +7 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deserialize.d.ts","sourceRoot":"","sources":["../../../../src/components/RichText/functions/deserialize.ts"],"names":[],"mappings":"
|
|
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"}
|
|
@@ -8,6 +8,7 @@ const deserialize = (el) => {
|
|
|
8
8
|
const children = Array.isArray(el.props.children)
|
|
9
9
|
? parsedChildren(el.props.children)
|
|
10
10
|
: [{ text: el.props.children }];
|
|
11
|
+
const childrenString = typeof el.props.children === "string" ? el.props.children : "";
|
|
11
12
|
switch (el.type) {
|
|
12
13
|
case "p":
|
|
13
14
|
return { type: "paragraph", children };
|
|
@@ -24,15 +25,15 @@ const deserialize = (el) => {
|
|
|
24
25
|
case "ol":
|
|
25
26
|
return { type: "numberedList", children };
|
|
26
27
|
case "strong":
|
|
27
|
-
return { text:
|
|
28
|
+
return { text: childrenString, bold: true };
|
|
28
29
|
case "code":
|
|
29
|
-
return { text:
|
|
30
|
+
return { text: childrenString, code: true };
|
|
30
31
|
case "em":
|
|
31
|
-
return { text:
|
|
32
|
+
return { text: childrenString, italic: true };
|
|
32
33
|
case "u":
|
|
33
|
-
return { text:
|
|
34
|
+
return { text: childrenString, underline: true };
|
|
34
35
|
default:
|
|
35
|
-
return { text:
|
|
36
|
+
return { text: childrenString };
|
|
36
37
|
}
|
|
37
38
|
};
|
|
38
39
|
const getSlateFromHtml = (html) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isHtml.d.ts","sourceRoot":"","sources":["../../../../src/components/RichText/functions/isHtml.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,MAAM,QAAS,MAAM,KAAG,OAG7B,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAOtB,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,2CA2Gf;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
|
@@ -18,16 +18,17 @@ import "./styles.css";
|
|
|
18
18
|
import { getSlateFromHtml } from "./functions/deserialize";
|
|
19
19
|
import { extractText } from "./functions/extractText";
|
|
20
20
|
import { getHtmlFromSlate } from "./functions/serialize";
|
|
21
|
+
import { isHtml } from "./functions/isHtml";
|
|
21
22
|
function RichText({ name, defaultValue, enforceCharacterLimit = false, onChangeCharactersCount, maxLimit = 2000, onValueChange, onChange, isError: baseIsError, }) {
|
|
22
23
|
const editor = useMemo(() => withHistory(withReact(createEditor())), []);
|
|
23
24
|
const { id, inputRef, error } = useFormController();
|
|
24
25
|
const baseRef = useRef(null);
|
|
25
|
-
const defaultNodes = defaultValue
|
|
26
|
+
const defaultNodes = isHtml(defaultValue)
|
|
26
27
|
? getSlateFromHtml(defaultValue)
|
|
27
28
|
: INITIAL_VALUE;
|
|
28
29
|
const textFromNodes = extractText(defaultNodes);
|
|
29
30
|
const [charactersCount, setCharactersCount] = useState(textFromNodes.length);
|
|
30
|
-
const [inputValue, setInputValue] = useState(defaultValue);
|
|
31
|
+
const [inputValue, setInputValue] = useState(isHtml(defaultValue) ? defaultValue : "");
|
|
31
32
|
const [onFocus, setOnFocus] = useState(false);
|
|
32
33
|
const ref = inputRef || baseRef;
|
|
33
34
|
const isError = baseIsError || !!error;
|
package/package.json
CHANGED
|
@@ -16,6 +16,9 @@ const deserialize = (el: ParseElement): Descendant => {
|
|
|
16
16
|
? parsedChildren(el.props.children)
|
|
17
17
|
: [{ text: el.props.children }];
|
|
18
18
|
|
|
19
|
+
const childrenString =
|
|
20
|
+
typeof el.props.children === "string" ? el.props.children : "";
|
|
21
|
+
|
|
19
22
|
switch (el.type) {
|
|
20
23
|
case "p":
|
|
21
24
|
return { type: "paragraph", children };
|
|
@@ -32,15 +35,15 @@ const deserialize = (el: ParseElement): Descendant => {
|
|
|
32
35
|
case "ol":
|
|
33
36
|
return { type: "numberedList", children };
|
|
34
37
|
case "strong":
|
|
35
|
-
return { text:
|
|
38
|
+
return { text: childrenString, bold: true };
|
|
36
39
|
case "code":
|
|
37
|
-
return { text:
|
|
40
|
+
return { text: childrenString, code: true };
|
|
38
41
|
case "em":
|
|
39
|
-
return { text:
|
|
42
|
+
return { text: childrenString, italic: true };
|
|
40
43
|
case "u":
|
|
41
|
-
return { text:
|
|
44
|
+
return { text: childrenString, underline: true };
|
|
42
45
|
default:
|
|
43
|
-
return { text:
|
|
46
|
+
return { text: childrenString };
|
|
44
47
|
}
|
|
45
48
|
};
|
|
46
49
|
|
|
@@ -32,6 +32,7 @@ import "./styles.css";
|
|
|
32
32
|
import { getSlateFromHtml } from "./functions/deserialize";
|
|
33
33
|
import { extractText } from "./functions/extractText";
|
|
34
34
|
import { getHtmlFromSlate } from "./functions/serialize";
|
|
35
|
+
import { isHtml } from "./functions/isHtml";
|
|
35
36
|
|
|
36
37
|
type RichTextProps = {
|
|
37
38
|
name: string;
|
|
@@ -59,14 +60,17 @@ function RichText({
|
|
|
59
60
|
|
|
60
61
|
const baseRef = useRef<HTMLInputElement>(null);
|
|
61
62
|
|
|
62
|
-
const defaultNodes = defaultValue
|
|
63
|
+
const defaultNodes = isHtml(defaultValue)
|
|
63
64
|
? getSlateFromHtml(defaultValue)
|
|
64
65
|
: INITIAL_VALUE;
|
|
65
66
|
|
|
66
67
|
const textFromNodes = extractText(defaultNodes);
|
|
67
68
|
|
|
68
69
|
const [charactersCount, setCharactersCount] = useState(textFromNodes.length);
|
|
69
|
-
const [inputValue, setInputValue] = useState(
|
|
70
|
+
const [inputValue, setInputValue] = useState(
|
|
71
|
+
isHtml(defaultValue) ? defaultValue : ""
|
|
72
|
+
);
|
|
73
|
+
|
|
70
74
|
const [onFocus, setOnFocus] = useState(false);
|
|
71
75
|
|
|
72
76
|
const ref = inputRef || baseRef;
|
|
@@ -77,8 +81,8 @@ function RichText({
|
|
|
77
81
|
|
|
78
82
|
function handleChange(value: Descendant[]) {
|
|
79
83
|
const text = extractText(value);
|
|
80
|
-
setCharactersCount(text.length);
|
|
81
84
|
|
|
85
|
+
setCharactersCount(text.length);
|
|
82
86
|
onChangeCharactersCount && onChangeCharactersCount(text.length);
|
|
83
87
|
|
|
84
88
|
if (enforceCharacterLimit && text.length >= maxLimit) {
|