@richscripts/richtexteditor 2.14.1 → 2.16.0
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/README.md +182 -10
- package/angular/build-manifest.json +23 -0
- package/angular/index.d.ts +71 -76
- package/angular/index.mjs +2 -0
- package/angular/package.json +4 -0
- package/headless/index.d.ts +3 -1
- package/headless/index.js +72 -16
- package/index.d.ts +40 -52
- package/integrations/initialization-scope.js +27 -0
- package/integrations/native-mount.js +30 -0
- package/integrations/shared.d.ts +23 -1
- package/integrations/shared.js +68 -22
- package/package.json +25 -3
- package/react/index.js +118 -37
- package/react/index.mjs +29 -0
- package/richtexteditor/all_plugins.js +8816 -2373
- package/richtexteditor/all_plugins.min.js +77 -59
- package/richtexteditor/lang/emoji/LICENSE-CLDR.txt +41 -0
- package/richtexteditor/lang/emoji/rte-emoji-de.js +3 -0
- package/richtexteditor/lang/emoji/rte-emoji-es.js +3 -0
- package/richtexteditor/lang/emoji/rte-emoji-fr.js +3 -0
- package/richtexteditor/lang/emoji/rte-emoji-it.js +3 -0
- package/richtexteditor/lang/emoji/rte-emoji-ja.js +3 -0
- package/richtexteditor/lang/emoji/rte-emoji-ko.js +3 -0
- package/richtexteditor/lang/emoji/rte-emoji-nl.js +3 -0
- package/richtexteditor/lang/emoji/rte-emoji-pt-pt.js +3 -0
- package/richtexteditor/lang/emoji/rte-emoji-pt.js +3 -0
- package/richtexteditor/lang/emoji/rte-emoji-ru.js +3 -0
- package/richtexteditor/lang/emoji/rte-emoji-zh-Hans.js +3 -0
- package/richtexteditor/lang/emoji/rte-emoji-zh-Hant.js +3 -0
- package/richtexteditor/lang/rte-lang-af.js +1 -0
- package/richtexteditor/lang/rte-lang-ar.js +1 -0
- package/richtexteditor/lang/rte-lang-bg.js +1 -0
- package/richtexteditor/lang/rte-lang-bn.js +1 -0
- package/richtexteditor/lang/rte-lang-bs.js +1 -0
- package/richtexteditor/lang/rte-lang-ca.js +1 -0
- package/richtexteditor/lang/rte-lang-cs.js +1 -0
- package/richtexteditor/lang/rte-lang-cy.js +1 -0
- package/richtexteditor/lang/rte-lang-da.js +1 -0
- package/richtexteditor/lang/rte-lang-de.js +1050 -2
- package/richtexteditor/lang/rte-lang-el.js +1 -0
- package/richtexteditor/lang/rte-lang-en.js +1 -0
- package/richtexteditor/lang/rte-lang-es.js +1056 -2
- package/richtexteditor/lang/rte-lang-et.js +1 -0
- package/richtexteditor/lang/rte-lang-fa.js +1 -0
- package/richtexteditor/lang/rte-lang-fi.js +1 -0
- package/richtexteditor/lang/rte-lang-fil.js +1 -0
- package/richtexteditor/lang/rte-lang-fj.js +1 -0
- package/richtexteditor/lang/rte-lang-fr.js +1056 -2
- package/richtexteditor/lang/rte-lang-ga.js +1 -0
- package/richtexteditor/lang/rte-lang-gu.js +1 -0
- package/richtexteditor/lang/rte-lang-he.js +1 -0
- package/richtexteditor/lang/rte-lang-hi.js +1 -0
- package/richtexteditor/lang/rte-lang-hr.js +1 -0
- package/richtexteditor/lang/rte-lang-ht.js +1 -0
- package/richtexteditor/lang/rte-lang-hu.js +1 -0
- package/richtexteditor/lang/rte-lang-id.js +1 -0
- package/richtexteditor/lang/rte-lang-is.js +1 -0
- package/richtexteditor/lang/rte-lang-it.js +1056 -2
- package/richtexteditor/lang/rte-lang-ja.js +1056 -2
- package/richtexteditor/lang/rte-lang-kn.js +1 -0
- package/richtexteditor/lang/rte-lang-ko.js +1056 -2
- package/richtexteditor/lang/rte-lang-lt.js +1 -0
- package/richtexteditor/lang/rte-lang-lv.js +1 -0
- package/richtexteditor/lang/rte-lang-mg.js +1 -0
- package/richtexteditor/lang/rte-lang-mi.js +1 -0
- package/richtexteditor/lang/rte-lang-ml.js +1 -0
- package/richtexteditor/lang/rte-lang-mr.js +1 -0
- package/richtexteditor/lang/rte-lang-ms.js +1 -0
- package/richtexteditor/lang/rte-lang-mt.js +1 -0
- package/richtexteditor/lang/rte-lang-mww.js +1 -0
- package/richtexteditor/lang/rte-lang-nb.js +1 -0
- package/richtexteditor/lang/rte-lang-nl.js +1056 -2
- package/richtexteditor/lang/rte-lang-otq.js +1 -0
- package/richtexteditor/lang/rte-lang-pa.js +1 -0
- package/richtexteditor/lang/rte-lang-pl.js +1 -0
- package/richtexteditor/lang/rte-lang-pt-pt.js +1056 -2
- package/richtexteditor/lang/rte-lang-pt.js +1056 -2
- package/richtexteditor/lang/rte-lang-ro.js +1 -0
- package/richtexteditor/lang/rte-lang-ru.js +1056 -2
- package/richtexteditor/lang/rte-lang-sk.js +1 -0
- package/richtexteditor/lang/rte-lang-sl.js +1 -0
- package/richtexteditor/lang/rte-lang-sm.js +1 -0
- package/richtexteditor/lang/rte-lang-sr-Cyrl.js +1 -0
- package/richtexteditor/lang/rte-lang-sr-Latn.js +1 -0
- package/richtexteditor/lang/rte-lang-sv.js +1 -0
- package/richtexteditor/lang/rte-lang-sw.js +1 -0
- package/richtexteditor/lang/rte-lang-ta.js +1 -0
- package/richtexteditor/lang/rte-lang-te.js +1 -0
- package/richtexteditor/lang/rte-lang-th.js +1 -0
- package/richtexteditor/lang/rte-lang-tlh-Latn.js +1 -0
- package/richtexteditor/lang/rte-lang-tlh-Piqd.js +1 -0
- package/richtexteditor/lang/rte-lang-to.js +1 -0
- package/richtexteditor/lang/rte-lang-tr.js +1 -0
- package/richtexteditor/lang/rte-lang-ty.js +1 -0
- package/richtexteditor/lang/rte-lang-uk.js +1 -0
- package/richtexteditor/lang/rte-lang-ur.js +1 -0
- package/richtexteditor/lang/rte-lang-vi.js +1 -0
- package/richtexteditor/lang/rte-lang-yua.js +1 -0
- package/richtexteditor/lang/rte-lang-zh-Hans.js +1050 -2
- package/richtexteditor/lang/rte-lang-zh-Hant.js +1050 -2
- package/richtexteditor/plugins/a11yenhance.js +4 -1
- package/richtexteditor/plugins/a11yenhance.min.js +1 -1
- package/richtexteditor/plugins/accessibilitychecker.js +256 -64
- package/richtexteditor/plugins/accessibilitychecker.min.js +1 -1
- package/richtexteditor/plugins/aitoolkit.js +1057 -386
- package/richtexteditor/plugins/aitoolkit.min.js +7 -7
- package/richtexteditor/plugins/all_plugins.js +8816 -2373
- package/richtexteditor/plugins/all_plugins.min.js +77 -59
- package/richtexteditor/plugins/autocorrect.js +66 -31
- package/richtexteditor/plugins/autocorrect.min.js +1 -1
- package/richtexteditor/plugins/autoembed.js +18 -1
- package/richtexteditor/plugins/autoembed.min.js +1 -1
- package/richtexteditor/plugins/blocktypes.js +18 -9
- package/richtexteditor/plugins/blocktypes.min.js +1 -1
- package/richtexteditor/plugins/bookmarkcard.js +12 -5
- package/richtexteditor/plugins/bookmarkcard.min.js +2 -2
- package/richtexteditor/plugins/changecase.js +72 -19
- package/richtexteditor/plugins/changecase.min.js +1 -1
- package/richtexteditor/plugins/charlimit.js +62 -2
- package/richtexteditor/plugins/charlimit.min.js +2 -2
- package/richtexteditor/plugins/comments.js +460 -61
- package/richtexteditor/plugins/comments.min.js +4 -3
- package/richtexteditor/plugins/contentminimap.js +28 -9
- package/richtexteditor/plugins/contentminimap.min.js +1 -1
- package/richtexteditor/plugins/crdt-engine.js +27 -1
- package/richtexteditor/plugins/crossreference.js +1 -1
- package/richtexteditor/plugins/crossreference.min.js +1 -1
- package/richtexteditor/plugins/dialoga11y.js +26 -4
- package/richtexteditor/plugins/dialoga11y.min.js +1 -1
- package/richtexteditor/plugins/dictation.js +1 -1
- package/richtexteditor/plugins/documentimport.js +250 -59
- package/richtexteditor/plugins/documentimport.min.js +4 -4
- package/richtexteditor/plugins/documentoutline.js +47 -8
- package/richtexteditor/plugins/documentoutline.min.js +1 -1
- package/richtexteditor/plugins/docxexport.js +233 -32
- package/richtexteditor/plugins/docxexport.min.js +2 -2
- package/richtexteditor/plugins/draghandle.js +267 -3
- package/richtexteditor/plugins/draghandle.min.js +1 -1
- package/richtexteditor/plugins/emailtoolkit.js +28 -14
- package/richtexteditor/plugins/emailtoolkit.min.js +1 -1
- package/richtexteditor/plugins/emojiautocomplete.js +111 -57
- package/richtexteditor/plugins/emojiautocomplete.min.js +1 -1
- package/richtexteditor/plugins/footnotes.js +65 -11
- package/richtexteditor/plugins/footnotes.min.js +1 -1
- package/richtexteditor/plugins/formatpainter.js +10 -0
- package/richtexteditor/plugins/formatpainter.min.js +1 -1
- package/richtexteditor/plugins/formattingmarks.js +6 -6
- package/richtexteditor/plugins/formattingmarks.min.js +1 -1
- package/richtexteditor/plugins/gapcursor.js +60 -0
- package/richtexteditor/plugins/gapcursor.min.js +1 -1
- package/richtexteditor/plugins/ghostcomplete.js +1 -1
- package/richtexteditor/plugins/html2pdf.js +8 -8
- package/richtexteditor/plugins/html2pdf.min.js +1 -1
- package/richtexteditor/plugins/imageeditor.js +31 -12
- package/richtexteditor/plugins/imageeditor.min.js +1 -1
- package/richtexteditor/plugins/importstyles.js +1 -1
- package/richtexteditor/plugins/inlinecode.js +25 -0
- package/richtexteditor/plugins/inlinecode.min.js +1 -1
- package/richtexteditor/plugins/insertcode.js +29 -11
- package/richtexteditor/plugins/insertcode.min.js +6 -6
- package/richtexteditor/plugins/insertemoji.js +113 -16
- package/richtexteditor/plugins/insertemoji.min.js +1 -1
- package/richtexteditor/plugins/insertgallery.js +46 -40
- package/richtexteditor/plugins/insertgallery.min.js +1 -1
- package/richtexteditor/plugins/inserttemplate.js +43 -19
- package/richtexteditor/plugins/inserttemplate.min.js +1 -1
- package/richtexteditor/plugins/keyboarda11y.js +66 -3
- package/richtexteditor/plugins/keyboarda11y.min.js +1 -1
- package/richtexteditor/plugins/layouttable.js +20 -0
- package/richtexteditor/plugins/layouttable.min.js +1 -1
- package/richtexteditor/plugins/linkchecker.js +29 -9
- package/richtexteditor/plugins/linkchecker.min.js +1 -1
- package/richtexteditor/plugins/localdraft.js +51 -7
- package/richtexteditor/plugins/localdraft.min.js +1 -1
- package/richtexteditor/plugins/markdownexport.js +159 -0
- package/richtexteditor/plugins/markdownexport.min.js +2 -2
- package/richtexteditor/plugins/mathdialog.js +11 -5
- package/richtexteditor/plugins/mathdialog.min.js +1 -1
- package/richtexteditor/plugins/mentionplugin.js +90 -27
- package/richtexteditor/plugins/mentionplugin.min.js +1 -1
- package/richtexteditor/plugins/mermaiddiagram.js +14 -8
- package/richtexteditor/plugins/mermaiddiagram.min.js +2 -2
- package/richtexteditor/plugins/multilevellist.js +4 -0
- package/richtexteditor/plugins/multilevellist.min.js +1 -1
- package/richtexteditor/plugins/nodetypes.js +1 -1
- package/richtexteditor/plugins/nodetypes.min.js +1 -1
- package/richtexteditor/plugins/pagination.js +2 -2
- package/richtexteditor/plugins/pagination.min.js +1 -1
- package/richtexteditor/plugins/pdfexport.js +1752 -1167
- package/richtexteditor/plugins/pdfexport.min.js +28 -13
- package/richtexteditor/plugins/permanentpen.js +3 -3
- package/richtexteditor/plugins/permanentpen.min.js +1 -1
- package/richtexteditor/plugins/readabilitystats.js +25 -11
- package/richtexteditor/plugins/readabilitystats.min.js +1 -1
- package/richtexteditor/plugins/readaloud.js +30 -16
- package/richtexteditor/plugins/readaloud.min.js +1 -1
- package/richtexteditor/plugins/restrictedediting.js +166 -0
- package/richtexteditor/plugins/restrictedediting.min.js +2 -2
- package/richtexteditor/plugins/revisionhistory.js +173 -41
- package/richtexteditor/plugins/revisionhistory.min.js +3 -3
- package/richtexteditor/plugins/rubyannotation.js +21 -11
- package/richtexteditor/plugins/rubyannotation.min.js +1 -1
- package/richtexteditor/plugins/sanitizer.js +119 -7
- package/richtexteditor/plugins/sanitizer.min.js +1 -1
- package/richtexteditor/plugins/slashcommand.js +32 -18
- package/richtexteditor/plugins/slashcommand.min.js +2 -2
- package/richtexteditor/plugins/smartchips.js +39 -25
- package/richtexteditor/plugins/smartchips.min.js +2 -2
- package/richtexteditor/plugins/spellcheck.js +20 -11
- package/richtexteditor/plugins/spellcheck.min.js +2 -2
- package/richtexteditor/plugins/stateinspector.js +21 -11
- package/richtexteditor/plugins/stateinspector.min.js +2 -2
- package/richtexteditor/plugins/structured-content-bridge.js +90 -32
- package/richtexteditor/plugins/structured-content-bridge.min.js +8 -8
- package/richtexteditor/plugins/tableofcontents.js +5 -2
- package/richtexteditor/plugins/tableofcontents.min.js +1 -1
- package/richtexteditor/plugins/tabletools.js +388 -3
- package/richtexteditor/plugins/tabletools.min.js +1 -1
- package/richtexteditor/plugins/textdirection.js +19 -6
- package/richtexteditor/plugins/textdirection.min.js +1 -1
- package/richtexteditor/plugins/textpartlanguage.js +161 -32
- package/richtexteditor/plugins/textpartlanguage.min.js +1 -1
- package/richtexteditor/plugins/todolist.js +90 -6
- package/richtexteditor/plugins/todolist.min.js +1 -1
- package/richtexteditor/plugins/trackedchanges.js +1812 -25
- package/richtexteditor/plugins/trackedchanges.min.js +5 -3
- package/richtexteditor/plugins/wordexport.js +2 -2
- package/richtexteditor/plugins/yjscollab.js +11 -6
- package/richtexteditor/plugins/yjscollab.min.js +1 -1
- package/richtexteditor/plugins/zz_richtextbox_dialog_style.js +22 -13
- package/richtexteditor/plugins/zz_richtextbox_dialog_style.min.js +1 -1
- package/richtexteditor/rte-config.js +144 -86
- package/richtexteditor/rte-headless.js +19 -4
- package/richtexteditor/rte-watchdog.js +3 -1
- package/richtexteditor/rte-webcomponent.js +91 -16
- package/richtexteditor/rte.js +146 -88
- package/richtexteditor/runtime/colorpicker_more_ns.htm +3 -1
- package/scripts/build-angular.mjs +97 -0
- package/svelte/index.d.ts +2 -1
- package/svelte/index.js +80 -9
- package/vue/index.js +130 -34
- package/angular/component.ts +0 -297
- package/angular/index.ts +0 -24
package/react/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
1
3
|
var React = require("react");
|
|
2
4
|
var shared = require("../integrations/shared");
|
|
3
5
|
var headless = require("../headless");
|
|
6
|
+
var initializationScope = require("../integrations/initialization-scope");
|
|
4
7
|
|
|
5
8
|
function pluginAccessor(editorRef, name) {
|
|
6
9
|
return function () {
|
|
@@ -113,6 +116,9 @@ var RichTextEditorReact = React.forwardRef(function RichTextEditorReact(props, f
|
|
|
113
116
|
var editorRef = React.useRef(null);
|
|
114
117
|
var onChangeRef = React.useRef(props.onChange);
|
|
115
118
|
var lastEmittedRef = React.useRef(undefined);
|
|
119
|
+
var initialValueRef = React.useRef(props.value !== undefined ? props.value : props.defaultValue);
|
|
120
|
+
var lastKnownHtmlRef = React.useRef(null);
|
|
121
|
+
var writingValueRef = React.useRef(false);
|
|
116
122
|
// 0 disables coalescing and restores the pre-2.6 behaviour of emitting
|
|
117
123
|
// synchronously on every change.
|
|
118
124
|
var changeDelayRef = React.useRef(props.changeDelay == null ? 120 : props.changeDelay);
|
|
@@ -127,6 +133,7 @@ var RichTextEditorReact = React.forwardRef(function RichTextEditorReact(props, f
|
|
|
127
133
|
onErrorRef.current = props.onError;
|
|
128
134
|
formatRef.current = props.valueFormat || "html";
|
|
129
135
|
configRef.current = props.config || {};
|
|
136
|
+
initialValueRef.current = props.value !== undefined ? props.value : props.defaultValue;
|
|
130
137
|
});
|
|
131
138
|
|
|
132
139
|
React.useImperativeHandle(forwardedRef, function () {
|
|
@@ -136,8 +143,41 @@ var RichTextEditorReact = React.forwardRef(function RichTextEditorReact(props, f
|
|
|
136
143
|
React.useEffect(function () {
|
|
137
144
|
var disposed = false;
|
|
138
145
|
var changeHandler = null;
|
|
146
|
+
var blurHandler = null;
|
|
139
147
|
var emitChange = null;
|
|
140
148
|
var activeHost = hostRef.current;
|
|
149
|
+
var ownedEditor = null;
|
|
150
|
+
|
|
151
|
+
function emitCurrentValue() {
|
|
152
|
+
var editor = ownedEditor;
|
|
153
|
+
if (!editor || writingValueRef.current) return;
|
|
154
|
+
var value = shared.getEditorValue(editor, formatRef.current);
|
|
155
|
+
var html = typeof value === "string" ? value : (typeof value.html === "string" ? value.html : editor.getHTMLCode());
|
|
156
|
+
if (html === lastKnownHtmlRef.current) return;
|
|
157
|
+
lastKnownHtmlRef.current = html;
|
|
158
|
+
lastEmittedRef.current = value;
|
|
159
|
+
if (onChangeRef.current) onChangeRef.current(value, editor);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function releaseEditor() {
|
|
163
|
+
if (emitChange) emitChange.cancel();
|
|
164
|
+
emitChange = null;
|
|
165
|
+
var editor = ownedEditor;
|
|
166
|
+
ownedEditor = null;
|
|
167
|
+
if (editorRef.current === editor) editorRef.current = null;
|
|
168
|
+
if (editor && changeHandler && typeof editor.detachEvent === "function") {
|
|
169
|
+
try { editor.detachEvent("change", changeHandler); } catch (e) { /* Continue cleanup. */ }
|
|
170
|
+
}
|
|
171
|
+
changeHandler = null;
|
|
172
|
+
if (editor && blurHandler && typeof editor.detachEvent === "function") {
|
|
173
|
+
try { editor.detachEvent("blur", blurHandler); } catch (e) { /* Continue cleanup. */ }
|
|
174
|
+
}
|
|
175
|
+
blurHandler = null;
|
|
176
|
+
if (editor && typeof editor.destroy === "function") {
|
|
177
|
+
try { editor.destroy(); } catch (e) { /* Continue cleanup. */ }
|
|
178
|
+
}
|
|
179
|
+
if (activeHost && !editorRef.current) activeHost.innerHTML = "";
|
|
180
|
+
}
|
|
141
181
|
|
|
142
182
|
var readyPromise = props.autoload === false
|
|
143
183
|
? Promise.resolve().then(function () {
|
|
@@ -151,59 +191,60 @@ var RichTextEditorReact = React.forwardRef(function RichTextEditorReact(props, f
|
|
|
151
191
|
return;
|
|
152
192
|
}
|
|
153
193
|
|
|
154
|
-
|
|
194
|
+
// Plugins may wrap/move their container. Never give them the
|
|
195
|
+
// React-owned root: React removes that exact child on unmount.
|
|
196
|
+
var editorMount = activeHost.ownerDocument.createElement("div");
|
|
197
|
+
activeHost.appendChild(editorMount);
|
|
198
|
+
var editor = shared.createEditor(editorMount, configRef.current);
|
|
199
|
+
if (disposed) {
|
|
200
|
+
try { editor.destroy(); } catch (e) { /* Continue cleanup. */ }
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
ownedEditor = editor;
|
|
155
204
|
editorRef.current = editor;
|
|
156
205
|
|
|
157
|
-
var initialValue =
|
|
206
|
+
var initialValue = initialValueRef.current;
|
|
158
207
|
if (initialValue !== undefined) {
|
|
159
208
|
shared.setEditorValue(editor, initialValue, formatRef.current);
|
|
160
209
|
}
|
|
210
|
+
if (disposed) return;
|
|
211
|
+
lastKnownHtmlRef.current = editor.getHTMLCode();
|
|
212
|
+
lastEmittedRef.current = undefined;
|
|
161
213
|
|
|
162
214
|
// Serialise at most once per quiet period rather than once per
|
|
163
215
|
// keystroke. lastEmittedRef lets the value-sync effect below skip a
|
|
164
216
|
// SECOND full serialisation when the parent hands back exactly what
|
|
165
217
|
// we just emitted, which is the common controlled-component case.
|
|
166
|
-
emitChange = shared.createChangeCoalescer(
|
|
167
|
-
var value = shared.getEditorValue(editor, formatRef.current);
|
|
168
|
-
lastEmittedRef.current = value;
|
|
169
|
-
if (onChangeRef.current) {
|
|
170
|
-
onChangeRef.current(value, editor);
|
|
171
|
-
}
|
|
172
|
-
}, changeDelayRef.current);
|
|
218
|
+
emitChange = shared.createChangeCoalescer(emitCurrentValue, changeDelayRef.current);
|
|
173
219
|
|
|
174
|
-
changeHandler = function () { emitChange(); };
|
|
220
|
+
changeHandler = function () { if (!disposed && !writingValueRef.current && emitChange) emitChange(); };
|
|
175
221
|
|
|
176
222
|
editor.attachEvent("change", changeHandler);
|
|
223
|
+
blurHandler = function () {
|
|
224
|
+
if (disposed || writingValueRef.current) return;
|
|
225
|
+
if (emitChange) emitChange.flush();
|
|
226
|
+
emitCurrentValue();
|
|
227
|
+
};
|
|
228
|
+
editor.attachEvent("blur", blurHandler);
|
|
177
229
|
|
|
178
230
|
if (onReadyRef.current) {
|
|
179
231
|
onReadyRef.current(editor);
|
|
180
232
|
}
|
|
181
233
|
})
|
|
182
234
|
.catch(function (error) {
|
|
183
|
-
if (!disposed
|
|
184
|
-
|
|
235
|
+
if (!disposed) {
|
|
236
|
+
releaseEditor();
|
|
237
|
+
if (onErrorRef.current) onErrorRef.current(error);
|
|
185
238
|
}
|
|
186
239
|
});
|
|
187
240
|
|
|
188
241
|
return function () {
|
|
242
|
+
if (disposed) return;
|
|
189
243
|
disposed = true;
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
if (changeHandler && typeof ed.detachEvent === "function") {
|
|
195
|
-
ed.detachEvent("change", changeHandler);
|
|
196
|
-
}
|
|
197
|
-
// Tear down the editor's instance-level global listeners so an
|
|
198
|
-
// unmount (or React 18 StrictMode's mount→unmount→mount) doesn't leak.
|
|
199
|
-
if (typeof ed.destroy === "function") {
|
|
200
|
-
try { ed.destroy(); } catch (e) { /* ignore */ }
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
if (activeHost) {
|
|
204
|
-
activeHost.innerHTML = "";
|
|
205
|
-
}
|
|
206
|
-
editorRef.current = null;
|
|
244
|
+
try {
|
|
245
|
+
if (emitChange) emitChange.flush();
|
|
246
|
+
if (changeHandler) emitCurrentValue();
|
|
247
|
+
} finally { releaseEditor(); }
|
|
207
248
|
};
|
|
208
249
|
}, []);
|
|
209
250
|
|
|
@@ -221,13 +262,18 @@ var RichTextEditorReact = React.forwardRef(function RichTextEditorReact(props, f
|
|
|
221
262
|
return;
|
|
222
263
|
}
|
|
223
264
|
if (editorRef.current.getHTMLCode() !== nextHtml) {
|
|
224
|
-
|
|
265
|
+
writingValueRef.current = true;
|
|
266
|
+
try { shared.setEditorValue(editorRef.current, props.value, props.valueFormat || "html"); }
|
|
267
|
+
finally { writingValueRef.current = false; }
|
|
225
268
|
}
|
|
269
|
+
if (editorRef.current) lastKnownHtmlRef.current = editorRef.current.getHTMLCode();
|
|
270
|
+
lastEmittedRef.current = undefined;
|
|
226
271
|
}, [props.value, props.valueFormat]);
|
|
227
272
|
|
|
228
273
|
var divProps = Object.assign({}, props);
|
|
229
274
|
delete divProps.assetBasePath;
|
|
230
275
|
delete divProps.autoload;
|
|
276
|
+
delete divProps.changeDelay;
|
|
231
277
|
delete divProps.config;
|
|
232
278
|
delete divProps.defaultValue;
|
|
233
279
|
delete divProps.onChange;
|
|
@@ -249,8 +295,9 @@ RichTextEditorReact.defaultProps = {
|
|
|
249
295
|
|
|
250
296
|
// ---- Headless hook: bring-your-own-UI, Tiptap-style ----
|
|
251
297
|
// const editor = useRichTextEditor({ value: "<p>Hi</p>" });
|
|
252
|
-
// <button
|
|
253
|
-
//
|
|
298
|
+
// <button type="button" onPointerDown={e => e.preventDefault()}
|
|
299
|
+
// onClick={() => editor.run("bold")} disabled={!editor.editor}
|
|
300
|
+
// aria-pressed={!!editor.state.bold}>Bold</button>
|
|
254
301
|
// <EditorContent editor={editor} />
|
|
255
302
|
function useRichTextEditor(options) {
|
|
256
303
|
var optionsRef = React.useRef(options || {});
|
|
@@ -259,32 +306,66 @@ function useRichTextEditor(options) {
|
|
|
259
306
|
var stateRef = React.useRef({});
|
|
260
307
|
var rerender = React.useReducer(function (c) { return (c + 1) | 0; }, 0)[1];
|
|
261
308
|
|
|
309
|
+
React.useEffect(function () { optionsRef.current = options || {}; });
|
|
310
|
+
|
|
262
311
|
React.useEffect(function () {
|
|
263
312
|
var disposed = false;
|
|
264
313
|
var ctl = null;
|
|
265
|
-
|
|
314
|
+
var pendingScope = null;
|
|
315
|
+
var activeHost = hostRef.current;
|
|
316
|
+
function releaseController() {
|
|
317
|
+
var owned = ctl;
|
|
318
|
+
ctl = null;
|
|
319
|
+
if (controllerRef.current === owned) controllerRef.current = null;
|
|
320
|
+
if (owned) { try { owned.destroy(); } catch (e) { /* Continue cleanup. */ } }
|
|
321
|
+
if (activeHost && !controllerRef.current) activeHost.innerHTML = "";
|
|
322
|
+
}
|
|
323
|
+
Promise.resolve().then(function () {
|
|
324
|
+
if (disposed) return null;
|
|
325
|
+
if (!activeHost) throw new Error("useRichTextEditor: render EditorContent before initialization.");
|
|
326
|
+
pendingScope = initializationScope.createInitializationScope(optionsRef.current.signal);
|
|
327
|
+
var editorMount = activeHost.ownerDocument.createElement("div");
|
|
328
|
+
activeHost.appendChild(editorMount);
|
|
329
|
+
return headless.createHeadlessEditor(editorMount, Object.assign({}, optionsRef.current, { signal: pendingScope.signal }));
|
|
330
|
+
})
|
|
266
331
|
.then(function (controller) {
|
|
332
|
+
if (pendingScope) pendingScope.complete();
|
|
333
|
+
if (!controller) return;
|
|
267
334
|
if (disposed) { controller.destroy(); return; }
|
|
268
335
|
ctl = controller;
|
|
269
336
|
controllerRef.current = controller;
|
|
337
|
+
var value = optionsRef.current.value;
|
|
338
|
+
if (value != null && value !== controller.getHTML()) controller.setHTML(value);
|
|
270
339
|
controller.on("update", function (snapshot) {
|
|
340
|
+
if (disposed) return;
|
|
271
341
|
stateRef.current = snapshot;
|
|
272
342
|
rerender();
|
|
273
343
|
});
|
|
274
344
|
stateRef.current = controller.state();
|
|
275
345
|
if (optionsRef.current.onReady) { optionsRef.current.onReady(controller); }
|
|
276
|
-
rerender();
|
|
346
|
+
if (!disposed) rerender();
|
|
277
347
|
})
|
|
278
348
|
.catch(function (error) {
|
|
279
|
-
if (
|
|
349
|
+
if (pendingScope) pendingScope.complete();
|
|
350
|
+
if (!disposed) {
|
|
351
|
+
releaseController();
|
|
352
|
+
if (optionsRef.current.onError) optionsRef.current.onError(error);
|
|
353
|
+
}
|
|
280
354
|
});
|
|
281
355
|
return function () {
|
|
356
|
+
if (disposed) return;
|
|
282
357
|
disposed = true;
|
|
283
|
-
if (
|
|
284
|
-
|
|
358
|
+
if (pendingScope) pendingScope.dispose();
|
|
359
|
+
releaseController();
|
|
285
360
|
};
|
|
286
361
|
}, []);
|
|
287
362
|
|
|
363
|
+
React.useEffect(function () {
|
|
364
|
+
var controller = controllerRef.current;
|
|
365
|
+
var value = options && options.value;
|
|
366
|
+
if (controller && value != null && value !== controller.getHTML()) controller.setHTML(value);
|
|
367
|
+
}, [options && options.value]);
|
|
368
|
+
|
|
288
369
|
return {
|
|
289
370
|
ref: hostRef,
|
|
290
371
|
get editor() { return controllerRef.current; }, // controller (null until ready)
|
package/react/index.mjs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// A real ESM client boundary for React Server Component bundlers. Keep the CJS
|
|
4
|
+
// implementation available to require() consumers and conventional React SSR.
|
|
5
|
+
import bindings from "./index.js";
|
|
6
|
+
|
|
7
|
+
export const RichTextEditor = bindings.RichTextEditor;
|
|
8
|
+
export const RichTextEditorReact = bindings.RichTextEditorReact;
|
|
9
|
+
export const useRichTextEditor = bindings.useRichTextEditor;
|
|
10
|
+
export const EditorContent = bindings.EditorContent;
|
|
11
|
+
export const auditAccessibility = bindings.auditAccessibility;
|
|
12
|
+
export const auditLinks = bindings.auditLinks;
|
|
13
|
+
export const createStructuredDocument = bindings.createStructuredDocument;
|
|
14
|
+
export const createHeadlessEditor = bindings.createHeadlessEditor;
|
|
15
|
+
export const createStructuredContent = bindings.createStructuredContent;
|
|
16
|
+
export const fromMarkdown = bindings.fromMarkdown;
|
|
17
|
+
export const getDocumentPageSetup = bindings.getDocumentPageSetup;
|
|
18
|
+
export const getDocumentMetrics = bindings.getDocumentMetrics;
|
|
19
|
+
export const getDocumentOutline = bindings.getDocumentOutline;
|
|
20
|
+
export const getFootnotes = bindings.getFootnotes;
|
|
21
|
+
export const getTableOfContents = bindings.getTableOfContents;
|
|
22
|
+
export const getTextStatistics = bindings.getTextStatistics;
|
|
23
|
+
export const loadRichTextEditorAssets = bindings.loadRichTextEditorAssets;
|
|
24
|
+
export const renderHTML = bindings.renderHTML;
|
|
25
|
+
export const setDocumentPageSetup = bindings.setDocumentPageSetup;
|
|
26
|
+
export const syncTableOfContents = bindings.syncTableOfContents;
|
|
27
|
+
export const toMarkdown = bindings.toMarkdown;
|
|
28
|
+
export const validateStructuredContent = bindings.validateStructuredContent;
|
|
29
|
+
export default bindings;
|