@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.
@@ -0,0 +1,3 @@
1
+ declare const isHtml: (str: string) => boolean;
2
+ export { isHtml };
3
+ //# sourceMappingURL=isHtml.d.ts.map
@@ -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"}
@@ -0,0 +1,5 @@
1
+ const isHtml = (str) => {
2
+ const htmlRegex = /<\/?[a-z][\s\S]*>/i;
3
+ return htmlRegex.test(str);
4
+ };
5
+ export { isHtml };
@@ -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;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"}
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkyn/components",
3
- "version": "1.3.122",
3
+ "version": "1.3.123",
4
4
  "main": "./dist/bundle.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Lucas Gonçalves",
@@ -0,0 +1,6 @@
1
+ const isHtml = (str: string): boolean => {
2
+ const htmlRegex = /<\/?[a-z][\s\S]*>/i;
3
+ return htmlRegex.test(str);
4
+ };
5
+
6
+ export { isHtml };
@@ -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(defaultValue);
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;