@longline/aqua-ui 1.0.337 → 1.0.338
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.
- package/inputs/Editor/Editor.js +13 -4
- package/package.json +1 -1
package/inputs/Editor/Editor.js
CHANGED
|
@@ -78,10 +78,16 @@ var EditorBase = function (props) {
|
|
|
78
78
|
var wrapperRef = React.useRef(null);
|
|
79
79
|
// Ref to actual editor div (with contentEditable).
|
|
80
80
|
var contentEditableRef = React.useRef(null);
|
|
81
|
+
// Last HTML the editor itself emitted via onUpdate. Used to detect
|
|
82
|
+
// round-trips so we don't re-sanitize the editor's own output (which would
|
|
83
|
+
// strip the empty <li> created by pressing Enter on a list item).
|
|
84
|
+
var lastEmittedRef = React.useRef(null);
|
|
81
85
|
var _a = React.useState(false), fullscreen = _a[0], setFullscreen = _a[1];
|
|
82
86
|
var handleUpdate = function (p) {
|
|
87
|
+
var html = p.editor.getHTML();
|
|
88
|
+
lastEmittedRef.current = html;
|
|
83
89
|
if (props.onChange)
|
|
84
|
-
props.onChange(
|
|
90
|
+
props.onChange(html);
|
|
85
91
|
};
|
|
86
92
|
var handleFullscreenChange = function () {
|
|
87
93
|
setFullscreen(document.fullscreenElement != null);
|
|
@@ -105,10 +111,13 @@ var EditorBase = function (props) {
|
|
|
105
111
|
onUpdate: handleUpdate
|
|
106
112
|
});
|
|
107
113
|
React.useEffect(function () {
|
|
114
|
+
// If props.value is exactly what the editor just emitted, this is a
|
|
115
|
+
// round-trip from our own onChange — skip sanitizing and re-setting
|
|
116
|
+
// content. Sanitizing here would, e.g., strip the empty <li> created by
|
|
117
|
+
// pressing Enter inside a list, undoing the user's keystroke.
|
|
118
|
+
if (props.value === lastEmittedRef.current)
|
|
119
|
+
return;
|
|
108
120
|
var safeValue = sanitizeEditorHTML(props.value);
|
|
109
|
-
// Only replace content if it actually differs from what's in the editor.
|
|
110
|
-
// This avoids resetting the cursor when the editor's own changes round-trip
|
|
111
|
-
// back through props.
|
|
112
121
|
if (editor.getHTML() !== safeValue) {
|
|
113
122
|
editor.commands.setContent(safeValue, true, { preserveWhitespace: "full" });
|
|
114
123
|
}
|