@arkyn/components 1.3.122 → 1.3.123
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/bundle.js +1347 -1345
- package/dist/bundle.umd.cjs +25 -25
- 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/isHtml.ts +6 -0
- package/src/components/RichText/index.tsx +6 -2
@@ -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
@@ -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;
|