@arkyn/components 1.3.117 → 1.3.118

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/RichText/index.tsx"],"names":[],"mappings":"AAeA,OAAO,EAAgB,UAAU,EAAoB,MAAM,OAAO,CAAC;AAanE,OAAO,cAAc,CAAC;AAGtB,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,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,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,2CAkHf;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,EAAoB,MAAM,OAAO,CAAC;AAanE,OAAO,cAAc,CAAC;AAGtB,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,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,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,2CAqHf;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
@@ -16,8 +16,12 @@ import { INITIAL_VALUE } from "./template/INITIAL_VALUE";
16
16
  import "./styles.css";
17
17
  import { useFormController } from "../Form/FormController";
18
18
  function RichText({ name, defaultValue, enforceCharacterLimit = false, onChangeCharactersCount, maxLimit = 2000, onValueChange, onChange, isError: baseIsError, }) {
19
- const [charactersCount, setCharactersCount] = useState(0);
20
- const [editorValue, setEditorValue] = useState(defaultValue ? JSON.parse(defaultValue) : INITIAL_VALUE);
19
+ function extractText(nodes) {
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);
21
25
  const [onFocus, setOnFocus] = useState(false);
22
26
  const { id, inputRef, error } = useFormController();
23
27
  const baseRef = useRef(null);
@@ -26,9 +30,6 @@ function RichText({ name, defaultValue, enforceCharacterLimit = false, onChangeC
26
30
  const editor = useMemo(() => withHistory(withReact(createEditor())), []);
27
31
  const renderLeaf = useCallback(Leaf, []);
28
32
  const renderElement = useCallback(Element, []);
29
- function extractText(nodes) {
30
- return nodes.map((n) => Node.string(n)).join("");
31
- }
32
33
  function handleChange(value) {
33
34
  const text = extractText(value);
34
35
  setCharactersCount(text.length);
@@ -47,7 +48,7 @@ function RichText({ name, defaultValue, enforceCharacterLimit = false, onChangeC
47
48
  const focusClass = onFocus ? "focusTrue" : "focusFalse";
48
49
  const errorClass = isError
49
50
  ? "errorTrue"
50
- : maxLimit === charactersCount
51
+ : maxLimit < charactersCount
51
52
  ? "errorTrue"
52
53
  : "errorFalse";
53
54
  const className = `arkynRichText ${errorClass} ${focusClass}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkyn/components",
3
- "version": "1.3.117",
3
+ "version": "1.3.118",
4
4
  "main": "./dist/bundle.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Lucas Gonçalves",
@@ -50,10 +50,17 @@ function RichText({
50
50
  onChange,
51
51
  isError: baseIsError,
52
52
  }: RichTextProps) {
53
- const [charactersCount, setCharactersCount] = useState(0);
54
- const [editorValue, setEditorValue] = useState<Descendant[]>(
55
- defaultValue ? JSON.parse(defaultValue) : INITIAL_VALUE
53
+ function extractText(nodes: Descendant[]) {
54
+ return nodes.map((n) => Node.string(n)).join("");
55
+ }
56
+
57
+ const defaultNodes = defaultValue ? JSON.parse(defaultValue) : INITIAL_VALUE;
58
+
59
+ const [charactersCount, setCharactersCount] = useState(
60
+ extractText(defaultNodes).length
56
61
  );
62
+
63
+ const [editorValue, setEditorValue] = useState<Descendant[]>(defaultNodes);
57
64
  const [onFocus, setOnFocus] = useState(false);
58
65
 
59
66
  const { id, inputRef, error } = useFormController();
@@ -68,10 +75,6 @@ function RichText({
68
75
  const renderLeaf = useCallback(Leaf, []);
69
76
  const renderElement = useCallback(Element, []);
70
77
 
71
- function extractText(nodes: Descendant[]) {
72
- return nodes.map((n) => Node.string(n)).join("");
73
- }
74
-
75
78
  function handleChange(value: Descendant[]) {
76
79
  const text = extractText(value);
77
80
  setCharactersCount(text.length);
@@ -94,7 +97,7 @@ function RichText({
94
97
  const focusClass = onFocus ? "focusTrue" : "focusFalse";
95
98
  const errorClass = isError
96
99
  ? "errorTrue"
97
- : maxLimit === charactersCount
100
+ : maxLimit < charactersCount
98
101
  ? "errorTrue"
99
102
  : "errorFalse";
100
103