jodit-react 5.4.72 → 5.4.81
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.
|
@@ -9,6 +9,7 @@ var Jodit = JoditES5;
|
|
|
9
9
|
|
|
10
10
|
// src/JoditEditor.tsx
|
|
11
11
|
import { jsx } from "react/jsx-runtime";
|
|
12
|
+
var MAX_TRACKED_EMITTED_VALUES = 20;
|
|
12
13
|
function usePrevious(value) {
|
|
13
14
|
const ref = useRef("");
|
|
14
15
|
useEffect(() => {
|
|
@@ -31,6 +32,7 @@ var JoditEditor = forwardRef(
|
|
|
31
32
|
}, ref) => {
|
|
32
33
|
const textAreaRef = useRef(null);
|
|
33
34
|
const joditRef = useRef(null);
|
|
35
|
+
const emittedValuesRef = useRef([]);
|
|
34
36
|
useEffect(() => {
|
|
35
37
|
const element = textAreaRef.current;
|
|
36
38
|
const jodit = JoditConstructor.make(element, config);
|
|
@@ -72,14 +74,26 @@ var JoditEditor = forwardRef(
|
|
|
72
74
|
}, [tabIndex]);
|
|
73
75
|
useEffect(() => {
|
|
74
76
|
const jodit = joditRef.current;
|
|
75
|
-
if (!(jodit == null ? void 0 : jodit.events)
|
|
77
|
+
if (!(jodit == null ? void 0 : jodit.events)) {
|
|
76
78
|
return;
|
|
77
79
|
}
|
|
78
80
|
const onBlurHandler = (event) => {
|
|
79
81
|
var _a, _b;
|
|
80
82
|
return onBlur && onBlur((_b = (_a = joditRef == null ? void 0 : joditRef.current) == null ? void 0 : _a.value) != null ? _b : "", event);
|
|
81
83
|
};
|
|
82
|
-
const onChangeHandler = (value2) =>
|
|
84
|
+
const onChangeHandler = (value2) => {
|
|
85
|
+
const emitted = emittedValuesRef.current;
|
|
86
|
+
emitted.push(value2);
|
|
87
|
+
if (emitted.length > MAX_TRACKED_EMITTED_VALUES) {
|
|
88
|
+
emitted.splice(
|
|
89
|
+
0,
|
|
90
|
+
emitted.length - MAX_TRACKED_EMITTED_VALUES
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
if (onChange) {
|
|
94
|
+
onChange(value2);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
83
97
|
jodit.events.on("blur", onBlurHandler).on("change", onChangeHandler);
|
|
84
98
|
return () => {
|
|
85
99
|
var _a;
|
|
@@ -89,7 +103,17 @@ var JoditEditor = forwardRef(
|
|
|
89
103
|
useEffect(() => {
|
|
90
104
|
const jodit = joditRef.current;
|
|
91
105
|
const updateValue = () => {
|
|
92
|
-
if (jodit
|
|
106
|
+
if (!jodit || value === void 0) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const emitted = emittedValuesRef.current;
|
|
110
|
+
const echoIndex = emitted.indexOf(value);
|
|
111
|
+
if (echoIndex !== -1) {
|
|
112
|
+
emitted.splice(0, echoIndex + 1);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (jodit.value !== value) {
|
|
116
|
+
emitted.length = 0;
|
|
93
117
|
jodit.value = value;
|
|
94
118
|
}
|
|
95
119
|
};
|