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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  JoditEditor_default
3
- } from "./chunk-73DTNKN6.mjs";
3
+ } from "./chunk-5THJHHYF.mjs";
4
4
  export {
5
5
  JoditEditor_default as default
6
6
  };
@@ -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) || !(onBlur || onChange)) {
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) => onChange && onChange(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 && value !== void 0 && jodit.value !== value) {
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
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  Jodit,
3
3
  JoditEditor_default
4
- } from "./chunk-73DTNKN6.mjs";
4
+ } from "./chunk-5THJHHYF.mjs";
5
5
 
6
6
  // src/index.ts
7
7
  var index_default = JoditEditor_default;