@richscripts/richtexteditor 2.4.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 +360 -0
- package/admin/index.d.ts +100 -0
- package/admin/index.js +94 -0
- package/angular/component.ts +284 -0
- package/angular/index.d.ts +80 -0
- package/angular/index.ts +24 -0
- package/headless/index.d.ts +65 -0
- package/headless/index.js +272 -0
- package/index.d.ts +1412 -0
- package/integrations/shared.d.ts +138 -0
- package/integrations/shared.js +5182 -0
- package/package.json +130 -0
- package/react/index.d.ts +104 -0
- package/react/index.js +310 -0
- package/richtexteditor/CHANGELOG.md +1876 -0
- package/richtexteditor/all_plugins.js +31125 -0
- package/richtexteditor/all_plugins.min.js +78 -0
- package/richtexteditor/lang/rte-lang-af.js +193 -0
- package/richtexteditor/lang/rte-lang-ar.js +193 -0
- package/richtexteditor/lang/rte-lang-bg.js +193 -0
- package/richtexteditor/lang/rte-lang-bn.js +193 -0
- package/richtexteditor/lang/rte-lang-bs.js +193 -0
- package/richtexteditor/lang/rte-lang-ca.js +193 -0
- package/richtexteditor/lang/rte-lang-cs.js +193 -0
- package/richtexteditor/lang/rte-lang-cy.js +193 -0
- package/richtexteditor/lang/rte-lang-da.js +193 -0
- package/richtexteditor/lang/rte-lang-de.js +193 -0
- package/richtexteditor/lang/rte-lang-el.js +193 -0
- package/richtexteditor/lang/rte-lang-en.js +6 -0
- package/richtexteditor/lang/rte-lang-es.js +193 -0
- package/richtexteditor/lang/rte-lang-et.js +193 -0
- package/richtexteditor/lang/rte-lang-fa.js +193 -0
- package/richtexteditor/lang/rte-lang-fi.js +193 -0
- package/richtexteditor/lang/rte-lang-fil.js +193 -0
- package/richtexteditor/lang/rte-lang-fj.js +193 -0
- package/richtexteditor/lang/rte-lang-fr.js +193 -0
- package/richtexteditor/lang/rte-lang-ga.js +193 -0
- package/richtexteditor/lang/rte-lang-gu.js +193 -0
- package/richtexteditor/lang/rte-lang-he.js +193 -0
- package/richtexteditor/lang/rte-lang-hi.js +193 -0
- package/richtexteditor/lang/rte-lang-hr.js +193 -0
- package/richtexteditor/lang/rte-lang-ht.js +193 -0
- package/richtexteditor/lang/rte-lang-hu.js +193 -0
- package/richtexteditor/lang/rte-lang-id.js +193 -0
- package/richtexteditor/lang/rte-lang-is.js +193 -0
- package/richtexteditor/lang/rte-lang-it.js +193 -0
- package/richtexteditor/lang/rte-lang-ja.js +193 -0
- package/richtexteditor/lang/rte-lang-kn.js +193 -0
- package/richtexteditor/lang/rte-lang-ko.js +193 -0
- package/richtexteditor/lang/rte-lang-lt.js +193 -0
- package/richtexteditor/lang/rte-lang-lv.js +193 -0
- package/richtexteditor/lang/rte-lang-mg.js +193 -0
- package/richtexteditor/lang/rte-lang-mi.js +193 -0
- package/richtexteditor/lang/rte-lang-ml.js +193 -0
- package/richtexteditor/lang/rte-lang-mr.js +193 -0
- package/richtexteditor/lang/rte-lang-ms.js +193 -0
- package/richtexteditor/lang/rte-lang-mt.js +193 -0
- package/richtexteditor/lang/rte-lang-mww.js +193 -0
- package/richtexteditor/lang/rte-lang-nb.js +193 -0
- package/richtexteditor/lang/rte-lang-nl.js +193 -0
- package/richtexteditor/lang/rte-lang-otq.js +193 -0
- package/richtexteditor/lang/rte-lang-pa.js +193 -0
- package/richtexteditor/lang/rte-lang-pl.js +193 -0
- package/richtexteditor/lang/rte-lang-pt-pt.js +193 -0
- package/richtexteditor/lang/rte-lang-pt.js +193 -0
- package/richtexteditor/lang/rte-lang-ro.js +193 -0
- package/richtexteditor/lang/rte-lang-ru.js +193 -0
- package/richtexteditor/lang/rte-lang-sk.js +193 -0
- package/richtexteditor/lang/rte-lang-sl.js +193 -0
- package/richtexteditor/lang/rte-lang-sm.js +193 -0
- package/richtexteditor/lang/rte-lang-sr-Cyrl.js +193 -0
- package/richtexteditor/lang/rte-lang-sr-Latn.js +193 -0
- package/richtexteditor/lang/rte-lang-sv.js +193 -0
- package/richtexteditor/lang/rte-lang-sw.js +193 -0
- package/richtexteditor/lang/rte-lang-ta.js +193 -0
- package/richtexteditor/lang/rte-lang-te.js +193 -0
- package/richtexteditor/lang/rte-lang-th.js +193 -0
- package/richtexteditor/lang/rte-lang-tlh-Latn.js +193 -0
- package/richtexteditor/lang/rte-lang-tlh-Piqd.js +193 -0
- package/richtexteditor/lang/rte-lang-to.js +193 -0
- package/richtexteditor/lang/rte-lang-tr.js +193 -0
- package/richtexteditor/lang/rte-lang-ty.js +193 -0
- package/richtexteditor/lang/rte-lang-uk.js +193 -0
- package/richtexteditor/lang/rte-lang-ur.js +193 -0
- package/richtexteditor/lang/rte-lang-vi.js +193 -0
- package/richtexteditor/lang/rte-lang-yua.js +193 -0
- package/richtexteditor/lang/rte-lang-zh-Hans.js +193 -0
- package/richtexteditor/lang/rte-lang-zh-Hant.js +193 -0
- package/richtexteditor/lang/rte-lang.js +1 -0
- package/richtexteditor/plugins/-combine-plugin.txt +2 -0
- package/richtexteditor/plugins/-combine-plugins.bat +20 -0
- package/richtexteditor/plugins/a11yenhance.js +90 -0
- package/richtexteditor/plugins/accessibilitychecker.js +579 -0
- package/richtexteditor/plugins/aitoolkit.css +15830 -0
- package/richtexteditor/plugins/aitoolkit.js +19171 -0
- package/richtexteditor/plugins/all_plugins.js +31125 -0
- package/richtexteditor/plugins/all_plugins.min.js +78 -0
- package/richtexteditor/plugins/autoembed.js +174 -0
- package/richtexteditor/plugins/blocktypes.js +175 -0
- package/richtexteditor/plugins/bookmarkcard.js +226 -0
- package/richtexteditor/plugins/charlimit.js +195 -0
- package/richtexteditor/plugins/comments.js +672 -0
- package/richtexteditor/plugins/contentminimap.js +369 -0
- package/richtexteditor/plugins/crdt-engine.js +8905 -0
- package/richtexteditor/plugins/crdt-engine.min.js +5 -0
- package/richtexteditor/plugins/dialoga11y.js +174 -0
- package/richtexteditor/plugins/dictation.js +268 -0
- package/richtexteditor/plugins/documentimport.js +369 -0
- package/richtexteditor/plugins/documentoutline.js +341 -0
- package/richtexteditor/plugins/emailtoolkit.js +165 -0
- package/richtexteditor/plugins/emojiautocomplete.js +241 -0
- package/richtexteditor/plugins/foldheadings.js +181 -0
- package/richtexteditor/plugins/ghostcomplete.js +297 -0
- package/richtexteditor/plugins/html2pdf.js +158 -0
- package/richtexteditor/plugins/imageeditor.js +159 -0
- package/richtexteditor/plugins/insertcode.js +319 -0
- package/richtexteditor/plugins/insertemoji.js +229 -0
- package/richtexteditor/plugins/insertgallery.js +362 -0
- package/richtexteditor/plugins/inserttemplate.js +261 -0
- package/richtexteditor/plugins/localdraft.js +213 -0
- package/richtexteditor/plugins/markdownexport.js +110 -0
- package/richtexteditor/plugins/mathdialog.js +153 -0
- package/richtexteditor/plugins/mentionplugin.js +534 -0
- package/richtexteditor/plugins/mermaiddiagram.js +294 -0
- package/richtexteditor/plugins/readabilitystats.js +148 -0
- package/richtexteditor/plugins/readaloud.js +243 -0
- package/richtexteditor/plugins/restrictedediting.js +208 -0
- package/richtexteditor/plugins/revisionhistory.js +670 -0
- package/richtexteditor/plugins/samples/insertcode_v1.js +76 -0
- package/richtexteditor/plugins/slashcommand.js +705 -0
- package/richtexteditor/plugins/smartchips.js +250 -0
- package/richtexteditor/plugins/spellcheck.js +181 -0
- package/richtexteditor/plugins/todolist.js +137 -0
- package/richtexteditor/plugins/trackedchanges.js +658 -0
- package/richtexteditor/plugins/tui.image-editor/fabric.min.js +8 -0
- package/richtexteditor/plugins/tui.image-editor/note.txt +5 -0
- package/richtexteditor/plugins/tui.image-editor/svg/icon-a.svg +235 -0
- package/richtexteditor/plugins/tui.image-editor/svg/icon-b.svg +224 -0
- package/richtexteditor/plugins/tui.image-editor/svg/icon-c.svg +224 -0
- package/richtexteditor/plugins/tui.image-editor/svg/icon-d.svg +224 -0
- package/richtexteditor/plugins/tui.image-editor/tui-code-snippet.min.js +7 -0
- package/richtexteditor/plugins/tui.image-editor/tui-color-picker.min.css +6 -0
- package/richtexteditor/plugins/tui.image-editor/tui-color-picker.min.js +7 -0
- package/richtexteditor/plugins/tui.image-editor/tui-image-editor.min.css +7 -0
- package/richtexteditor/plugins/tui.image-editor/tui-image-editor.min.js +15 -0
- package/richtexteditor/plugins/typewriter.js +203 -0
- package/richtexteditor/plugins/wordexport.js +0 -0
- package/richtexteditor/plugins/yjscollab.js +693 -0
- package/richtexteditor/plugins/zz_richtextbox_dialog_style.js +335 -0
- package/richtexteditor/rte-config.js +933 -0
- package/richtexteditor/rte.js +943 -0
- package/richtexteditor/rte_mobile.css +234 -0
- package/richtexteditor/rte_theme_default.css +4819 -0
- package/richtexteditor/runtime/colorpicker_more_ns.htm +2613 -0
- package/richtexteditor/runtime/help.htm +162 -0
- package/richtexteditor/runtime/images/1x1.gif +0 -0
- package/richtexteditor/runtime/images/cpie_Color.cur +0 -0
- package/richtexteditor/runtime/images/cpie_GradientPositionDark.gif +0 -0
- package/richtexteditor/runtime/images/cpie_GradientPositionLight.gif +0 -0
- package/richtexteditor/runtime/images/cpie_VerticalPosition.gif +0 -0
- package/richtexteditor/runtime/images/cpie_WebSafe.gif +0 -0
- package/richtexteditor/runtime/images/cpie_gradients.png +0 -0
- package/richtexteditor/runtime/images/cpns_Color.cur +0 -0
- package/richtexteditor/runtime/images/cpns_ColorSpace1.png +0 -0
- package/richtexteditor/runtime/images/cpns_ColorSpace2.png +0 -0
- package/richtexteditor/runtime/images/cpns_GradientPositionDark.gif +0 -0
- package/richtexteditor/runtime/images/cpns_GradientPositionLight.gif +0 -0
- package/richtexteditor/runtime/images/cpns_Vertical1.png +0 -0
- package/richtexteditor/runtime/images/cpns_Vertical2.png +0 -0
- package/richtexteditor/runtime/images/cpns_VerticalPosition.gif +0 -0
- package/richtexteditor/runtime/images/cpns_WebSafe.gif +0 -0
- package/richtexteditor/runtime/images/cpns_gradients.png +0 -0
- package/richtexteditor/runtime/images/cpns_hue2.png +0 -0
- package/richtexteditor/runtime/images/formbn.gif +0 -0
- package/richtexteditor/runtime/images/multiclavier.gif +0 -0
- package/richtexteditor/runtime/richtexteditor_content.css +362 -0
- package/richtexteditor/runtime/richtexteditor_preview.css +302 -0
- package/richtexteditor/runtime/richtexteditor_preview.js +1 -0
- package/server/index.d.ts +21 -0
- package/server/index.js +23 -0
- package/svelte/index.d.ts +19 -0
- package/svelte/index.js +59 -0
- package/vue/index.d.ts +94 -0
- package/vue/index.js +291 -0
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* richtexteditor/headless
|
|
3
|
+
* ------------------------------------------------------------------
|
|
4
|
+
* Framework-agnostic, bundler-friendly headless controller. Loads the editor
|
|
5
|
+
* assets, mounts a chrome-less editor, and returns a controller you drive from
|
|
6
|
+
* your own UI — the same model as headless editor frameworks.
|
|
7
|
+
*
|
|
8
|
+
* import { createHeadlessEditor } from "@richscripts/richtexteditor/headless";
|
|
9
|
+
* const editor = await createHeadlessEditor(el, { value: "<p>Hi</p>" });
|
|
10
|
+
* editor.on("update", (s) => setActive(s));
|
|
11
|
+
* editor.run("bold");
|
|
12
|
+
*
|
|
13
|
+
* The React hook (./react useRichTextEditor) and Svelte action (./svelte) are
|
|
14
|
+
* thin wrappers over this. Browser-only (needs a DOM); for SSR, render a
|
|
15
|
+
* placeholder and create the editor in an effect / onMount.
|
|
16
|
+
*/
|
|
17
|
+
var shared = require("../integrations/shared");
|
|
18
|
+
|
|
19
|
+
var STATE_MAP = {
|
|
20
|
+
bold: { kind: "state", q: "bold" },
|
|
21
|
+
italic: { kind: "state", q: "italic" },
|
|
22
|
+
underline: { kind: "state", q: "underline" },
|
|
23
|
+
strike: { kind: "state", q: "strikethrough" },
|
|
24
|
+
strikethrough: { kind: "state", q: "strikethrough" },
|
|
25
|
+
subscript: { kind: "state", q: "subscript" },
|
|
26
|
+
superscript: { kind: "state", q: "superscript" },
|
|
27
|
+
ul: { kind: "state", q: "insertunorderedlist" },
|
|
28
|
+
ol: { kind: "state", q: "insertorderedlist" },
|
|
29
|
+
justifyleft: { kind: "state", q: "justifyleft" },
|
|
30
|
+
justifycenter: { kind: "state", q: "justifycenter" },
|
|
31
|
+
justifyright: { kind: "state", q: "justifyright" },
|
|
32
|
+
justifyfull: { kind: "state", q: "justifyfull" },
|
|
33
|
+
h1: { kind: "block", q: "h1" },
|
|
34
|
+
h2: { kind: "block", q: "h2" },
|
|
35
|
+
h3: { kind: "block", q: "h3" },
|
|
36
|
+
h4: { kind: "block", q: "h4" },
|
|
37
|
+
h5: { kind: "block", q: "h5" },
|
|
38
|
+
h6: { kind: "block", q: "h6" },
|
|
39
|
+
p: { kind: "block", q: "p" },
|
|
40
|
+
paragraph: { kind: "block", q: "p" },
|
|
41
|
+
blockquote: { kind: "block", q: "blockquote" },
|
|
42
|
+
pre: { kind: "block", q: "pre" }
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
var DEFAULT_STATE_KEYS = [
|
|
46
|
+
"bold", "italic", "underline", "strike", "ul", "ol",
|
|
47
|
+
"justifyleft", "justifycenter", "justifyright",
|
|
48
|
+
"blockquote", "h1", "h2", "h3", "p"
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
var _cssInjected = false;
|
|
52
|
+
function injectHeadlessCss() {
|
|
53
|
+
if (_cssInjected || typeof document === "undefined") {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
_cssInjected = true;
|
|
57
|
+
var css =
|
|
58
|
+
".rte-headless rte-toolbar,.rte-headless rte-subtoolbar,.rte-headless rte-bottom{display:none !important;}" +
|
|
59
|
+
".rte-headless{border:0 !important;background:transparent !important;}";
|
|
60
|
+
var style = document.createElement("style");
|
|
61
|
+
style.setAttribute("data-rte-headless", "");
|
|
62
|
+
style.appendChild(document.createTextNode(css));
|
|
63
|
+
(document.head || document.documentElement).appendChild(style);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function HeadlessController(editor, options) {
|
|
67
|
+
this.editor = editor;
|
|
68
|
+
this._opts = options || {};
|
|
69
|
+
this._handlers = {};
|
|
70
|
+
this._scheduled = false;
|
|
71
|
+
this._destroyed = false;
|
|
72
|
+
this._wire();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
HeadlessController.prototype._doc = function () {
|
|
76
|
+
try {
|
|
77
|
+
var ifr = this.editor && this.editor.iframe;
|
|
78
|
+
if (!ifr) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
return ifr.contentDocument || (ifr.contentWindow && ifr.contentWindow.document) || null;
|
|
82
|
+
} catch (e) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
HeadlessController.prototype._wire = function () {
|
|
88
|
+
var self = this;
|
|
89
|
+
// setTimeout (not requestAnimationFrame): rAF is paused in hidden tabs, which
|
|
90
|
+
// would latch the coalescing flag and drop every later update.
|
|
91
|
+
function emitUpdate() {
|
|
92
|
+
if (self._destroyed || self._scheduled) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
self._scheduled = true;
|
|
96
|
+
setTimeout(function () {
|
|
97
|
+
self._scheduled = false;
|
|
98
|
+
if (!self._destroyed) {
|
|
99
|
+
self._emit("update", self.state());
|
|
100
|
+
}
|
|
101
|
+
}, 16);
|
|
102
|
+
}
|
|
103
|
+
this._emitUpdate = emitUpdate;
|
|
104
|
+
|
|
105
|
+
["selectionchange", "change", "focus", "blur"].forEach(function (evt) {
|
|
106
|
+
try {
|
|
107
|
+
self.editor.attachEvent(evt, function (a, b) {
|
|
108
|
+
self._emit(evt, a, b);
|
|
109
|
+
if (evt === "selectionchange" || evt === "change") {
|
|
110
|
+
emitUpdate();
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
} catch (e) { /* event surface differs by build */ }
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
var doc = this._doc();
|
|
117
|
+
if (doc && doc.addEventListener) {
|
|
118
|
+
this._docListeners = [
|
|
119
|
+
["selectionchange", function () { emitUpdate(); }],
|
|
120
|
+
["mouseup", function () { emitUpdate(); }],
|
|
121
|
+
["keyup", function () { emitUpdate(); }],
|
|
122
|
+
["input", function () { emitUpdate(); }]
|
|
123
|
+
];
|
|
124
|
+
for (var i = 0; i < this._docListeners.length; i++) {
|
|
125
|
+
try { doc.addEventListener(this._docListeners[i][0], this._docListeners[i][1], true); } catch (e) {}
|
|
126
|
+
}
|
|
127
|
+
this._boundDoc = doc;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
HeadlessController.prototype.on = function (name, cb) {
|
|
132
|
+
if (typeof cb === "function") {
|
|
133
|
+
(this._handlers[name] = this._handlers[name] || []).push(cb);
|
|
134
|
+
}
|
|
135
|
+
return this;
|
|
136
|
+
};
|
|
137
|
+
HeadlessController.prototype.off = function (name, cb) {
|
|
138
|
+
var list = this._handlers[name];
|
|
139
|
+
if (list) {
|
|
140
|
+
this._handlers[name] = cb ? list.filter(function (f) { return f !== cb; }) : [];
|
|
141
|
+
}
|
|
142
|
+
return this;
|
|
143
|
+
};
|
|
144
|
+
HeadlessController.prototype._emit = function (name) {
|
|
145
|
+
var list = this._handlers[name];
|
|
146
|
+
if (!list || !list.length) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
|
150
|
+
for (var i = 0; i < list.length; i++) {
|
|
151
|
+
try { list[i].apply(this, args); } catch (e) { if (typeof console !== "undefined") { console.error(e); } }
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
HeadlessController.prototype.run = function (command, value) {
|
|
156
|
+
try { this.editor.execCommand(command, value); } catch (e) { if (typeof console !== "undefined") { console.error(e); } }
|
|
157
|
+
if (this._emitUpdate) { this._emitUpdate(); }
|
|
158
|
+
return this;
|
|
159
|
+
};
|
|
160
|
+
HeadlessController.prototype.cmd = HeadlessController.prototype.run;
|
|
161
|
+
|
|
162
|
+
HeadlessController.prototype.isActive = function (name) {
|
|
163
|
+
var spec = STATE_MAP[String(name || "").toLowerCase()];
|
|
164
|
+
var doc = this._doc();
|
|
165
|
+
if (!spec || !doc) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
if (spec.kind === "state") {
|
|
170
|
+
return !!doc.queryCommandState(spec.q);
|
|
171
|
+
}
|
|
172
|
+
var v = String(doc.queryCommandValue("formatBlock") || "").toLowerCase().replace(/[<>]/g, "");
|
|
173
|
+
return v === spec.q;
|
|
174
|
+
} catch (e) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
HeadlessController.prototype.can = function (command) {
|
|
180
|
+
var doc = this._doc();
|
|
181
|
+
if (!doc) {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
try { return !!doc.queryCommandEnabled(command); } catch (e) { return false; }
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
HeadlessController.prototype.state = function (keys) {
|
|
188
|
+
keys = keys || DEFAULT_STATE_KEYS;
|
|
189
|
+
var out = {};
|
|
190
|
+
for (var i = 0; i < keys.length; i++) {
|
|
191
|
+
out[keys[i]] = this.isActive(keys[i]);
|
|
192
|
+
}
|
|
193
|
+
out.canUndo = this.can("undo");
|
|
194
|
+
out.canRedo = this.can("redo");
|
|
195
|
+
return out;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
HeadlessController.prototype.getHTML = function () { return this.editor.getHTMLCode ? this.editor.getHTMLCode() : ""; };
|
|
199
|
+
HeadlessController.prototype.setHTML = function (html) { if (this.editor.setHTMLCode) { this.editor.setHTMLCode(html == null ? "" : html); } if (this._emitUpdate) { this._emitUpdate(); } return this; };
|
|
200
|
+
HeadlessController.prototype.getText = function () { return this.editor.getText ? this.editor.getText() : ""; };
|
|
201
|
+
HeadlessController.prototype.setText = function (t) { if (this.editor.setText) { this.editor.setText(t == null ? "" : t); } if (this._emitUpdate) { this._emitUpdate(); } return this; };
|
|
202
|
+
HeadlessController.prototype.getMarkdown = function () { return this.editor.toMarkdown ? this.editor.toMarkdown() : ""; };
|
|
203
|
+
HeadlessController.prototype.setMarkdown = function (md) { if (this.editor.fromMarkdown) { this.editor.fromMarkdown(md == null ? "" : md); } if (this._emitUpdate) { this._emitUpdate(); } return this; };
|
|
204
|
+
HeadlessController.prototype.getJSON = function () { return this.editor.getJSON ? this.editor.getJSON() : null; };
|
|
205
|
+
HeadlessController.prototype.getStatistics = function () { return this.editor.getStatistics ? this.editor.getStatistics() : null; };
|
|
206
|
+
HeadlessController.prototype.isEmpty = function () { return String(this.getText() || "").replace(/\s+/g, "").length === 0; };
|
|
207
|
+
|
|
208
|
+
HeadlessController.prototype.focus = function () { try { this.editor.focus(); } catch (e) {} return this; };
|
|
209
|
+
|
|
210
|
+
HeadlessController.prototype.destroy = function () {
|
|
211
|
+
this._destroyed = true;
|
|
212
|
+
this._handlers = {};
|
|
213
|
+
if (this._boundDoc && this._docListeners) {
|
|
214
|
+
for (var i = 0; i < this._docListeners.length; i++) {
|
|
215
|
+
try { this._boundDoc.removeEventListener(this._docListeners[i][0], this._docListeners[i][1], true); } catch (e) {}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
this._docListeners = null;
|
|
219
|
+
this._boundDoc = null;
|
|
220
|
+
try { if (this.editor.prepareDestroy) { this.editor.prepareDestroy(); } } catch (e) {}
|
|
221
|
+
return this;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
// Build a chrome-less editor and resolve to a controller. Loads assets first.
|
|
225
|
+
function createHeadlessEditor(element, options) {
|
|
226
|
+
options = options || {};
|
|
227
|
+
var loadPromise = options.autoload === false
|
|
228
|
+
? Promise.resolve(shared.installStructuredContentBridge())
|
|
229
|
+
: shared.loadRichTextEditorAssets({ basePath: options.assetBasePath });
|
|
230
|
+
|
|
231
|
+
return loadPromise.then(function () {
|
|
232
|
+
if (typeof window === "undefined" || typeof window.RichTextEditor !== "function") {
|
|
233
|
+
throw new Error("rte-headless: RichTextEditor failed to load.");
|
|
234
|
+
}
|
|
235
|
+
var el = (typeof element === "string") ? document.querySelector(element) : element;
|
|
236
|
+
if (!el) {
|
|
237
|
+
throw new Error("rte-headless: target element not found.");
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
var cfg = (typeof window.RTE_CreateConfig === "function") ? window.RTE_CreateConfig() : {};
|
|
241
|
+
if (options.config) {
|
|
242
|
+
for (var k in options.config) {
|
|
243
|
+
if (Object.prototype.hasOwnProperty.call(options.config, k)) {
|
|
244
|
+
cfg[k] = options.config[k];
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
cfg.toolbar = "headless";
|
|
249
|
+
cfg.toolbar_headless = " ";
|
|
250
|
+
cfg.toolbarMobile = "headless";
|
|
251
|
+
if (options.showStatistics !== true) {
|
|
252
|
+
cfg.showStatistics = false;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
injectHeadlessCss();
|
|
256
|
+
var editor = shared.createEditor(el, cfg);
|
|
257
|
+
if (editor.container && editor.container.classList) {
|
|
258
|
+
editor.container.classList.add("rte-headless");
|
|
259
|
+
}
|
|
260
|
+
if (options.value != null && editor.setHTMLCode) {
|
|
261
|
+
editor.setHTMLCode(options.value);
|
|
262
|
+
}
|
|
263
|
+
return new HeadlessController(editor, options);
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
module.exports = {
|
|
268
|
+
createHeadlessEditor: createHeadlessEditor,
|
|
269
|
+
HeadlessController: HeadlessController,
|
|
270
|
+
STATE_MAP: STATE_MAP,
|
|
271
|
+
DEFAULT_STATE_KEYS: DEFAULT_STATE_KEYS
|
|
272
|
+
};
|