@arkyn/components 1.3.115 → 1.3.117
Sign up to get free protection for your applications and to get access to all the features.
@@ -6,9 +6,10 @@ type RichTextProps = {
|
|
6
6
|
enforceCharacterLimit?: boolean;
|
7
7
|
defaultValue?: string;
|
8
8
|
isError?: boolean;
|
9
|
+
onChangeCharactersCount: (e: number) => void;
|
9
10
|
onChange?: (value: Descendant[]) => void;
|
10
11
|
onValueChange?: (value: string) => void;
|
11
12
|
};
|
12
|
-
declare function RichText({ name, defaultValue, enforceCharacterLimit, maxLimit, onValueChange, onChange, isError: baseIsError, }: RichTextProps): import("react/jsx-runtime").JSX.Element;
|
13
|
+
declare function RichText({ name, defaultValue, enforceCharacterLimit, onChangeCharactersCount, maxLimit, onValueChange, onChange, isError: baseIsError, }: RichTextProps): import("react/jsx-runtime").JSX.Element;
|
13
14
|
export { RichText };
|
14
15
|
//# sourceMappingURL=index.d.ts.map
|
@@ -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,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,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,2CAkHf;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
@@ -15,7 +15,7 @@ import { HOTKEYS } from "./template/HOTKEYS";
|
|
15
15
|
import { INITIAL_VALUE } from "./template/INITIAL_VALUE";
|
16
16
|
import "./styles.css";
|
17
17
|
import { useFormController } from "../Form/FormController";
|
18
|
-
function RichText({ name, defaultValue, enforceCharacterLimit = false, maxLimit = 2000, onValueChange, onChange, isError: baseIsError, }) {
|
18
|
+
function RichText({ name, defaultValue, enforceCharacterLimit = false, onChangeCharactersCount, maxLimit = 2000, onValueChange, onChange, isError: baseIsError, }) {
|
19
19
|
const [charactersCount, setCharactersCount] = useState(0);
|
20
20
|
const [editorValue, setEditorValue] = useState(defaultValue ? JSON.parse(defaultValue) : INITIAL_VALUE);
|
21
21
|
const [onFocus, setOnFocus] = useState(false);
|
@@ -32,6 +32,7 @@ function RichText({ name, defaultValue, enforceCharacterLimit = false, maxLimit
|
|
32
32
|
function handleChange(value) {
|
33
33
|
const text = extractText(value);
|
34
34
|
setCharactersCount(text.length);
|
35
|
+
onChangeCharactersCount && onChangeCharactersCount(text.length);
|
35
36
|
if (enforceCharacterLimit && text.length >= maxLimit) {
|
36
37
|
return;
|
37
38
|
}
|
@@ -59,6 +60,6 @@ function RichText({ name, defaultValue, enforceCharacterLimit = false, maxLimit
|
|
59
60
|
toggleMark(editor, mark);
|
60
61
|
}
|
61
62
|
}
|
62
|
-
} }),
|
63
|
+
} }), restatesCharacters < 0 && (_jsx("div", { className: "restatesCharacters", children: restatesCharacters }))] }), _jsx("input", { ref: ref, type: "hidden", name: name, value: JSON.stringify(editorValue) }), _jsx("input", { type: "hidden", name: `${name}Count`, value: charactersCount })] }));
|
63
64
|
}
|
64
65
|
export { RichText };
|
package/package.json
CHANGED
@@ -35,6 +35,7 @@ type RichTextProps = {
|
|
35
35
|
enforceCharacterLimit?: boolean;
|
36
36
|
defaultValue?: string;
|
37
37
|
isError?: boolean;
|
38
|
+
onChangeCharactersCount: (e: number) => void;
|
38
39
|
onChange?: (value: Descendant[]) => void;
|
39
40
|
onValueChange?: (value: string) => void;
|
40
41
|
};
|
@@ -43,6 +44,7 @@ function RichText({
|
|
43
44
|
name,
|
44
45
|
defaultValue,
|
45
46
|
enforceCharacterLimit = false,
|
47
|
+
onChangeCharactersCount,
|
46
48
|
maxLimit = 2000,
|
47
49
|
onValueChange,
|
48
50
|
onChange,
|
@@ -74,6 +76,8 @@ function RichText({
|
|
74
76
|
const text = extractText(value);
|
75
77
|
setCharactersCount(text.length);
|
76
78
|
|
79
|
+
onChangeCharactersCount && onChangeCharactersCount(text.length);
|
80
|
+
|
77
81
|
if (enforceCharacterLimit && text.length >= maxLimit) {
|
78
82
|
return;
|
79
83
|
} else {
|
@@ -144,10 +148,6 @@ function RichText({
|
|
144
148
|
}}
|
145
149
|
/>
|
146
150
|
|
147
|
-
{JSON.stringify(maxLimit)}
|
148
|
-
{JSON.stringify(charactersCount)}
|
149
|
-
{JSON.stringify(restatesCharacters)}
|
150
|
-
|
151
151
|
{restatesCharacters < 0 && (
|
152
152
|
<div className="restatesCharacters">{restatesCharacters}</div>
|
153
153
|
)}
|
@@ -159,6 +159,8 @@ function RichText({
|
|
159
159
|
name={name}
|
160
160
|
value={JSON.stringify(editorValue)}
|
161
161
|
/>
|
162
|
+
|
163
|
+
<input type="hidden" name={`${name}Count`} value={charactersCount} />
|
162
164
|
</Slate>
|
163
165
|
);
|
164
166
|
}
|