ckeditor5 1.36.6 → 1.37.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.
- checksums.yaml +4 -4
- data/README.md +89 -5
- data/lib/ckeditor5/rails/editor/helpers/editor_helpers.rb +33 -5
- data/lib/ckeditor5/rails/version.rb +1 -1
- data/npm_package/dist/index.cjs +1 -1
- data/npm_package/dist/index.cjs.map +1 -1
- data/npm_package/dist/index.mjs +268 -223
- data/npm_package/dist/index.mjs.map +1 -1
- data/npm_package/dist/src/components/editable.d.ts +8 -12
- data/npm_package/dist/src/components/editable.d.ts.map +1 -1
- data/npm_package/dist/src/components/editor/editor.d.ts.map +1 -1
- data/npm_package/dist/src/components/editor/multiroot-editables-tracker.d.ts.map +1 -1
- data/npm_package/package.json +3 -3
- data/spec/e2e/features/editor_types_spec.rb +7 -4
- data/spec/lib/ckeditor5/rails/editor/helpers/editor_helpers_spec.rb +8 -2
- metadata +2 -2
data/npm_package/dist/index.mjs
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
function
|
|
1
|
+
function f(e) {
|
|
2
2
|
switch (document.readyState) {
|
|
3
3
|
case "loading":
|
|
4
|
-
document.addEventListener("DOMContentLoaded",
|
|
4
|
+
document.addEventListener("DOMContentLoaded", e, { once: !0 });
|
|
5
5
|
break;
|
|
6
6
|
case "interactive":
|
|
7
7
|
case "complete":
|
|
8
|
-
setTimeout(
|
|
8
|
+
setTimeout(e, 0);
|
|
9
9
|
break;
|
|
10
10
|
default:
|
|
11
|
-
console.warn("Unexpected document.readyState:", document.readyState), setTimeout(
|
|
11
|
+
console.warn("Unexpected document.readyState:", document.readyState), setTimeout(e, 0);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
const
|
|
15
|
-
function
|
|
16
|
-
if (
|
|
17
|
-
return
|
|
18
|
-
const t = new Promise((
|
|
19
|
-
const
|
|
20
|
-
|
|
14
|
+
const E = /* @__PURE__ */ new Map();
|
|
15
|
+
function y(e) {
|
|
16
|
+
if (E.has(e))
|
|
17
|
+
return E.get(e);
|
|
18
|
+
const t = new Promise((i, n) => {
|
|
19
|
+
const s = document.createElement("script");
|
|
20
|
+
s.src = e, s.onload = i, s.onerror = n, document.head.appendChild(s);
|
|
21
21
|
});
|
|
22
|
-
return
|
|
22
|
+
return E.set(e, t), t;
|
|
23
23
|
}
|
|
24
|
-
function v(
|
|
25
|
-
return typeof
|
|
24
|
+
function v(e) {
|
|
25
|
+
return typeof e == "string" && e !== "__proto__" && e !== "constructor" && e !== "prototype";
|
|
26
26
|
}
|
|
27
|
-
function C(
|
|
27
|
+
function C(e) {
|
|
28
28
|
return Array.from(document.styleSheets).some(
|
|
29
|
-
(t) => t.href ===
|
|
29
|
+
(t) => t.href === e || t.href === new URL(e, window.location.href).href
|
|
30
30
|
);
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
const t =
|
|
34
|
-
(
|
|
35
|
-
if (C(
|
|
36
|
-
|
|
32
|
+
function b(e = []) {
|
|
33
|
+
const t = e.map(
|
|
34
|
+
(i) => new Promise((n, s) => {
|
|
35
|
+
if (C(i)) {
|
|
36
|
+
n();
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
39
|
const r = document.createElement("link");
|
|
40
|
-
r.rel = "stylesheet", r.href =
|
|
40
|
+
r.rel = "stylesheet", r.href = i, r.onerror = s, r.onload = () => n(), document.head.appendChild(r);
|
|
41
41
|
})
|
|
42
42
|
);
|
|
43
43
|
return Promise.all(t);
|
|
44
44
|
}
|
|
45
|
-
function h(
|
|
46
|
-
const t = async ({ url:
|
|
47
|
-
if (
|
|
48
|
-
let
|
|
49
|
-
return Object.prototype.hasOwnProperty.call(window,
|
|
45
|
+
function h(e = []) {
|
|
46
|
+
const t = async ({ url: n, import_name: s, import_as: r, window_name: c, stylesheets: d }) => {
|
|
47
|
+
if (d?.length && await b(d), c) {
|
|
48
|
+
let a = function() {
|
|
49
|
+
return Object.prototype.hasOwnProperty.call(window, c);
|
|
50
50
|
};
|
|
51
|
-
if (
|
|
52
|
-
new CustomEvent(`ckeditor:request-cjs-plugin:${
|
|
53
|
-
), !
|
|
51
|
+
if (n && !a() && await y(n), a() || window.dispatchEvent(
|
|
52
|
+
new CustomEvent(`ckeditor:request-cjs-plugin:${c}`)
|
|
53
|
+
), !a())
|
|
54
54
|
throw new Error(
|
|
55
|
-
`Plugin window['${
|
|
55
|
+
`Plugin window['${c}'] not found in global scope. Please ensure the plugin is loaded before CKEditor initialization.`
|
|
56
56
|
);
|
|
57
|
-
return window[
|
|
57
|
+
return window[c];
|
|
58
58
|
}
|
|
59
|
-
const
|
|
59
|
+
const o = await import(s), l = o[r || "default"];
|
|
60
60
|
if (!l)
|
|
61
61
|
throw new Error(
|
|
62
|
-
`Plugin "${r || "default"}" not found in the ESM module "${
|
|
62
|
+
`Plugin "${r || "default"}" not found in the ESM module "${s}"! Available imports: ${Object.keys(o).join(", ")}! Consider changing "import_as" value.`
|
|
63
63
|
);
|
|
64
64
|
return l;
|
|
65
65
|
};
|
|
66
|
-
function
|
|
67
|
-
return t(typeof
|
|
66
|
+
function i(n) {
|
|
67
|
+
return t(typeof n == "string" ? { import_name: "ckeditor5", import_as: n } : n);
|
|
68
68
|
}
|
|
69
|
-
return Promise.all(
|
|
69
|
+
return Promise.all(e.map(i));
|
|
70
70
|
}
|
|
71
|
-
function
|
|
72
|
-
if (!
|
|
73
|
-
return
|
|
74
|
-
if (Array.isArray(
|
|
75
|
-
return
|
|
76
|
-
const t =
|
|
71
|
+
function m(e) {
|
|
72
|
+
if (!e || typeof e != "object")
|
|
73
|
+
return e;
|
|
74
|
+
if (Array.isArray(e))
|
|
75
|
+
return e.map((n) => m(n));
|
|
76
|
+
const t = e;
|
|
77
77
|
if (t.$element && typeof t.$element == "string") {
|
|
78
|
-
const
|
|
79
|
-
return
|
|
78
|
+
const n = document.querySelector(t.$element);
|
|
79
|
+
return n || console.warn(`Element not found for selector: ${t.$element}`), n || null;
|
|
80
80
|
}
|
|
81
|
-
const
|
|
82
|
-
for (const [
|
|
83
|
-
|
|
84
|
-
return
|
|
81
|
+
const i = /* @__PURE__ */ Object.create(null);
|
|
82
|
+
for (const [n, s] of Object.entries(e))
|
|
83
|
+
i[n] = m(s);
|
|
84
|
+
return i;
|
|
85
85
|
}
|
|
86
86
|
function A() {
|
|
87
87
|
return Math.random().toString(36).substring(2);
|
|
@@ -95,13 +95,13 @@ class P extends HTMLElement {
|
|
|
95
95
|
}
|
|
96
96
|
async connectedCallback() {
|
|
97
97
|
try {
|
|
98
|
-
|
|
98
|
+
f(() => this.#t());
|
|
99
99
|
} catch (t) {
|
|
100
100
|
console.error("Failed to initialize context:", t), this.dispatchEvent(new CustomEvent("context-error", { detail: t }));
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
-
async attributeChangedCallback(t,
|
|
104
|
-
|
|
103
|
+
async attributeChangedCallback(t, i, n) {
|
|
104
|
+
i !== null && i !== n && await this.#t();
|
|
105
105
|
}
|
|
106
106
|
async disconnectedCallback() {
|
|
107
107
|
this.instance && (await this.instance.destroy(), this.instance = null);
|
|
@@ -131,14 +131,14 @@ class P extends HTMLElement {
|
|
|
131
131
|
this.instance && (this.instancePromise = Promise.withResolvers(), await this.instance.destroy(), this.instance = null), window.dispatchEvent(
|
|
132
132
|
new CustomEvent("ckeditor:context:attach:before", { detail: { element: this } })
|
|
133
133
|
);
|
|
134
|
-
const { Context: t, ContextWatchdog:
|
|
134
|
+
const { Context: t, ContextWatchdog: i } = await import("ckeditor5"), n = await this.#i(), s = this.#s();
|
|
135
135
|
window.dispatchEvent(
|
|
136
|
-
new CustomEvent("ckeditor:context:attach", { detail: { config:
|
|
137
|
-
), this.instance = new
|
|
136
|
+
new CustomEvent("ckeditor:context:attach", { detail: { config: s, element: this } })
|
|
137
|
+
), this.instance = new i(t, {
|
|
138
138
|
crashNumberLimit: 10
|
|
139
139
|
}), await this.instance.create({
|
|
140
|
-
...
|
|
141
|
-
plugins:
|
|
140
|
+
...s,
|
|
141
|
+
plugins: n
|
|
142
142
|
}), this.instance.on("itemError", (...r) => {
|
|
143
143
|
console.error("Context item error:", ...r);
|
|
144
144
|
}), this.instancePromise.resolve(this.instance), this.dispatchEvent(new CustomEvent("context-ready", { detail: this.instance })), await Promise.all(
|
|
@@ -156,20 +156,11 @@ class P extends HTMLElement {
|
|
|
156
156
|
*/
|
|
157
157
|
#s() {
|
|
158
158
|
const t = JSON.parse(this.getAttribute("config") || "{}");
|
|
159
|
-
return
|
|
159
|
+
return m(t);
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
customElements.define("ckeditor-context-component", P);
|
|
163
163
|
class x extends HTMLElement {
|
|
164
|
-
/**
|
|
165
|
-
* List of attributes that trigger updates when changed
|
|
166
|
-
*
|
|
167
|
-
* @static
|
|
168
|
-
* @returns {string[]} Array of attribute names to observe
|
|
169
|
-
*/
|
|
170
|
-
static get observedAttributes() {
|
|
171
|
-
return ["name"];
|
|
172
|
-
}
|
|
173
164
|
/**
|
|
174
165
|
* Gets the name of this editable region
|
|
175
166
|
*/
|
|
@@ -182,18 +173,30 @@ class x extends HTMLElement {
|
|
|
182
173
|
get editableElement() {
|
|
183
174
|
return this.querySelector("div");
|
|
184
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Root model element.
|
|
178
|
+
*/
|
|
179
|
+
get modelElement() {
|
|
180
|
+
return this.getAttribute("inline") === "true" ? "$inlineRoot" : void 0;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Initial editable data.
|
|
184
|
+
*/
|
|
185
|
+
get initialData() {
|
|
186
|
+
return this.hasAttribute("initial-data") ? this.getAttribute("initial-data") : void 0;
|
|
187
|
+
}
|
|
185
188
|
/**
|
|
186
189
|
* Lifecycle callback when element is added to DOM
|
|
187
190
|
* Sets up the editable element and registers it with the parent editor
|
|
188
191
|
*/
|
|
189
192
|
connectedCallback() {
|
|
190
|
-
|
|
193
|
+
f(() => {
|
|
191
194
|
const t = this.#e();
|
|
192
195
|
if (!t)
|
|
193
196
|
throw new Error("ckeditor-editable-component must be a child of ckeditor-component");
|
|
194
197
|
if (this.innerHTML = `<div>${this.innerHTML}</div>`, this.style.display = "block", t.isDecoupled())
|
|
195
|
-
t.runAfterEditorReady((
|
|
196
|
-
this.appendChild(
|
|
198
|
+
t.runAfterEditorReady((i) => {
|
|
199
|
+
this.appendChild(i.ui.view[this.name].element);
|
|
197
200
|
});
|
|
198
201
|
else if (t.editables) {
|
|
199
202
|
if (!this.name)
|
|
@@ -202,20 +205,6 @@ class x extends HTMLElement {
|
|
|
202
205
|
}
|
|
203
206
|
});
|
|
204
207
|
}
|
|
205
|
-
/**
|
|
206
|
-
* Lifecycle callback for attribute changes
|
|
207
|
-
* Handles name changes and propagates other attributes to editable element
|
|
208
|
-
*/
|
|
209
|
-
attributeChangedCallback(t, e, i) {
|
|
210
|
-
if (e !== i)
|
|
211
|
-
if (t === "name") {
|
|
212
|
-
if (!e)
|
|
213
|
-
return;
|
|
214
|
-
const n = this.#e();
|
|
215
|
-
n?.editables?.[e] && (n.editables[i] = n.editables[e], delete n.editables[e]);
|
|
216
|
-
} else
|
|
217
|
-
this.editableElement.setAttribute(t, i);
|
|
218
|
-
}
|
|
219
208
|
/**
|
|
220
209
|
* Lifecycle callback when element is removed
|
|
221
210
|
* Un-registers this editable from the parent editor
|
|
@@ -232,7 +221,7 @@ class x extends HTMLElement {
|
|
|
232
221
|
}
|
|
233
222
|
}
|
|
234
223
|
customElements.define("ckeditor-editable-component", x);
|
|
235
|
-
class
|
|
224
|
+
class w {
|
|
236
225
|
#e;
|
|
237
226
|
#t;
|
|
238
227
|
/**
|
|
@@ -242,16 +231,16 @@ class b {
|
|
|
242
231
|
* @param initialEditables - Initial editable elements
|
|
243
232
|
* @returns Proxy wrapping the tracker
|
|
244
233
|
*/
|
|
245
|
-
constructor(t,
|
|
246
|
-
return this.#e = t, this.#t =
|
|
234
|
+
constructor(t, i = {}) {
|
|
235
|
+
return this.#e = t, this.#t = i, new Proxy(this, {
|
|
247
236
|
/**
|
|
248
237
|
* Handles property access, returns class methods or editable elements
|
|
249
238
|
*
|
|
250
239
|
* @param target - The tracker instance
|
|
251
240
|
* @param name - Property name being accessed
|
|
252
241
|
*/
|
|
253
|
-
get(
|
|
254
|
-
return typeof
|
|
242
|
+
get(n, s) {
|
|
243
|
+
return typeof n[s] == "function" ? n[s].bind(n) : n.#t[s];
|
|
255
244
|
},
|
|
256
245
|
/**
|
|
257
246
|
* Handles setting new editable elements, triggers root attachment
|
|
@@ -260,8 +249,8 @@ class b {
|
|
|
260
249
|
* @param name - Name of the editable root
|
|
261
250
|
* @param element - Element to attach as editable
|
|
262
251
|
*/
|
|
263
|
-
set(
|
|
264
|
-
return
|
|
252
|
+
set(n, s, r) {
|
|
253
|
+
return n.#t[s] !== r && (n.attachRoot(s, r), n.#t[s] = r), !0;
|
|
265
254
|
},
|
|
266
255
|
/**
|
|
267
256
|
* Handles removing editable elements, triggers root detachment
|
|
@@ -269,8 +258,8 @@ class b {
|
|
|
269
258
|
* @param target - The tracker instance
|
|
270
259
|
* @param name - Name of the root to remove
|
|
271
260
|
*/
|
|
272
|
-
deleteProperty(
|
|
273
|
-
return
|
|
261
|
+
deleteProperty(n, s) {
|
|
262
|
+
return n.detachRoot(s), delete n.#t[s], !0;
|
|
274
263
|
}
|
|
275
264
|
});
|
|
276
265
|
}
|
|
@@ -282,17 +271,18 @@ class b {
|
|
|
282
271
|
* @param element - DOM element to use as editable
|
|
283
272
|
* @returns Resolves when root is attached
|
|
284
273
|
*/
|
|
285
|
-
async attachRoot(t,
|
|
286
|
-
return await this.detachRoot(t), this.#e.runAfterEditorReady((
|
|
287
|
-
const { ui:
|
|
288
|
-
|
|
274
|
+
async attachRoot(t, i) {
|
|
275
|
+
return await this.detachRoot(t), this.#e.runAfterEditorReady((n) => {
|
|
276
|
+
const { ui: s, editing: r, model: c } = n, d = i.modelElement, o = i.initialData;
|
|
277
|
+
n.addRoot(t, {
|
|
289
278
|
isUndoable: !1,
|
|
290
|
-
|
|
279
|
+
initialData: o ?? i.innerHTML,
|
|
280
|
+
...d && { modelElement: d }
|
|
291
281
|
});
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
const
|
|
295
|
-
|
|
282
|
+
const l = c.document.getRoot(t);
|
|
283
|
+
s.getEditableElement(t) && n.detachEditable(l);
|
|
284
|
+
const a = s.view.createEditable(t, i);
|
|
285
|
+
s.addEditable(a), r.view.forceRender();
|
|
296
286
|
});
|
|
297
287
|
}
|
|
298
288
|
/**
|
|
@@ -303,9 +293,9 @@ class b {
|
|
|
303
293
|
* @returns Resolves when root is detached
|
|
304
294
|
*/
|
|
305
295
|
async detachRoot(t) {
|
|
306
|
-
return this.#e.runAfterEditorReady((
|
|
307
|
-
const
|
|
308
|
-
|
|
296
|
+
return this.#e.runAfterEditorReady((i) => {
|
|
297
|
+
const n = i.model.document.getRoot(t);
|
|
298
|
+
n && (i.detachEditable(n), i.detachRoot(t, !0));
|
|
309
299
|
});
|
|
310
300
|
}
|
|
311
301
|
/**
|
|
@@ -317,7 +307,7 @@ class b {
|
|
|
317
307
|
return this.#t;
|
|
318
308
|
}
|
|
319
309
|
}
|
|
320
|
-
class
|
|
310
|
+
class p extends HTMLElement {
|
|
321
311
|
instancePromise = Promise.withResolvers();
|
|
322
312
|
watchdog = null;
|
|
323
313
|
instance = null;
|
|
@@ -364,13 +354,7 @@ class m extends HTMLElement {
|
|
|
364
354
|
* @returns Event handler or null
|
|
365
355
|
*/
|
|
366
356
|
#r(t) {
|
|
367
|
-
|
|
368
|
-
const e = this.getAttribute(`on${t}`);
|
|
369
|
-
if (!v(e))
|
|
370
|
-
throw new Error(`Unsafe event handler attribute value: ${e}`);
|
|
371
|
-
return window[e] || new Function("event", e);
|
|
372
|
-
}
|
|
373
|
-
return this[`#${t}Handler`];
|
|
357
|
+
return this.hasAttribute(`on${t}`) ? z(this.getAttribute(`on${t}`)) : this[`#${t}Handler`];
|
|
374
358
|
}
|
|
375
359
|
/**
|
|
376
360
|
* Sets event handler function
|
|
@@ -379,8 +363,8 @@ class m extends HTMLElement {
|
|
|
379
363
|
* @param name - Event name without 'on' prefix
|
|
380
364
|
* @param handler - Event handler
|
|
381
365
|
*/
|
|
382
|
-
#o(t,
|
|
383
|
-
typeof
|
|
366
|
+
#o(t, i) {
|
|
367
|
+
typeof i == "string" ? this.setAttribute(`on${t}`, i) : (this.removeAttribute(`on${t}`), this[`#${t}Handler`] = i);
|
|
384
368
|
}
|
|
385
369
|
/**
|
|
386
370
|
* Lifecycle callback when element is connected to DOM
|
|
@@ -391,13 +375,13 @@ class m extends HTMLElement {
|
|
|
391
375
|
connectedCallback() {
|
|
392
376
|
this.#t = this.closest("ckeditor-context-component"), this.#e = this.innerHTML;
|
|
393
377
|
try {
|
|
394
|
-
|
|
378
|
+
f(async () => {
|
|
395
379
|
this.#t && (await this.#t.instancePromise.promise, this.#t.registerEditor(this)), await this.reinitializeEditor();
|
|
396
380
|
});
|
|
397
381
|
} catch (t) {
|
|
398
382
|
console.error("Failed to initialize editor:", t);
|
|
399
|
-
const
|
|
400
|
-
this.dispatchEvent(
|
|
383
|
+
const i = new CustomEvent("editor-error", { detail: t });
|
|
384
|
+
this.dispatchEvent(i), this.oneditorerror?.(i);
|
|
401
385
|
}
|
|
402
386
|
}
|
|
403
387
|
/**
|
|
@@ -408,8 +392,8 @@ class m extends HTMLElement {
|
|
|
408
392
|
* @param oldValue - Previous attribute value
|
|
409
393
|
* @param newValue - New attribute value
|
|
410
394
|
*/
|
|
411
|
-
async attributeChangedCallback(t,
|
|
412
|
-
|
|
395
|
+
async attributeChangedCallback(t, i, n) {
|
|
396
|
+
i !== null && i !== n && p.observedAttributes.includes(t) && this.isConnected && await this.reinitializeEditor();
|
|
413
397
|
}
|
|
414
398
|
/**
|
|
415
399
|
* Lifecycle callback when element is removed from DOM
|
|
@@ -419,7 +403,7 @@ class m extends HTMLElement {
|
|
|
419
403
|
async disconnectedCallback() {
|
|
420
404
|
this.#t && this.#t.unregisterEditor(this);
|
|
421
405
|
try {
|
|
422
|
-
await this.#
|
|
406
|
+
await this.#l();
|
|
423
407
|
} catch (t) {
|
|
424
408
|
console.error("Failed to destroy editor:", t);
|
|
425
409
|
}
|
|
@@ -437,7 +421,7 @@ class m extends HTMLElement {
|
|
|
437
421
|
* Determines appropriate editor element tag based on editor type
|
|
438
422
|
*/
|
|
439
423
|
get #n() {
|
|
440
|
-
return this.getAttribute("type")
|
|
424
|
+
return S(this.getAttribute("type"));
|
|
441
425
|
}
|
|
442
426
|
/**
|
|
443
427
|
* Gets the CKEditor context instance if available.
|
|
@@ -448,65 +432,57 @@ class m extends HTMLElement {
|
|
|
448
432
|
/**
|
|
449
433
|
* Destroys the editor instance and watchdog if available
|
|
450
434
|
*/
|
|
451
|
-
async #
|
|
435
|
+
async #l() {
|
|
452
436
|
this.#i && await this.#a.remove(this.#i), await this.instance?.destroy(), this.watchdog?.destroy();
|
|
453
437
|
}
|
|
454
438
|
/**
|
|
455
439
|
* Gets editor configuration with resolved element references
|
|
456
440
|
*/
|
|
457
|
-
#
|
|
458
|
-
|
|
459
|
-
return u(t);
|
|
441
|
+
#d() {
|
|
442
|
+
return R(this.getAttribute("config"));
|
|
460
443
|
}
|
|
461
444
|
/**
|
|
462
445
|
* Creates a new CKEditor instance
|
|
463
446
|
*/
|
|
464
|
-
async #
|
|
447
|
+
async #h(t) {
|
|
465
448
|
await Promise.all([
|
|
466
|
-
this.#
|
|
467
|
-
this.#
|
|
449
|
+
this.#E(),
|
|
450
|
+
this.#b()
|
|
468
451
|
]);
|
|
469
|
-
|
|
470
|
-
t instanceof b ? e = t.getAll() : typeof t != "string" && (e = t.main);
|
|
471
|
-
const i = {
|
|
472
|
-
...e instanceof HTMLElement && { element: e },
|
|
473
|
-
...typeof e == "string" && { data: e },
|
|
474
|
-
...e instanceof Object && { editables: e }
|
|
475
|
-
};
|
|
452
|
+
const { isMultiroot: i, content: n } = M(t), s = k(n, i);
|
|
476
453
|
window.dispatchEvent(
|
|
477
|
-
new CustomEvent("ckeditor:attach:before", { detail:
|
|
454
|
+
new CustomEvent("ckeditor:attach:before", { detail: s })
|
|
478
455
|
);
|
|
479
|
-
const
|
|
480
|
-
this.#
|
|
481
|
-
this.#
|
|
482
|
-
]),
|
|
483
|
-
...this.#
|
|
484
|
-
...
|
|
485
|
-
translations:
|
|
456
|
+
const r = await this.#v(), [c, d] = await Promise.all([
|
|
457
|
+
this.#y(),
|
|
458
|
+
this.#w()
|
|
459
|
+
]), o = {
|
|
460
|
+
...this.#d(),
|
|
461
|
+
...d.length && {
|
|
462
|
+
translations: d
|
|
486
463
|
},
|
|
487
|
-
plugins:
|
|
464
|
+
plugins: c
|
|
488
465
|
};
|
|
489
|
-
window.dispatchEvent(
|
|
490
|
-
new CustomEvent("ckeditor:attach", { detail: { config:
|
|
466
|
+
D(o, n, i, this.isClassic()), window.dispatchEvent(
|
|
467
|
+
new CustomEvent("ckeditor:attach", { detail: { config: o, ...s } })
|
|
491
468
|
);
|
|
492
|
-
let
|
|
469
|
+
let l = null, a = null, u = null;
|
|
493
470
|
if (this.#t)
|
|
494
|
-
|
|
495
|
-
creator: (
|
|
496
|
-
id:
|
|
497
|
-
sourceElementOrData: e,
|
|
471
|
+
u = A(), await this.#a.add({
|
|
472
|
+
creator: (g) => r.create(g),
|
|
473
|
+
id: u,
|
|
498
474
|
type: "editor",
|
|
499
|
-
config:
|
|
500
|
-
}),
|
|
475
|
+
config: o
|
|
476
|
+
}), a = this.#a.getItem(u);
|
|
501
477
|
else if (this.hasWatchdog()) {
|
|
502
|
-
const { EditorWatchdog:
|
|
503
|
-
|
|
478
|
+
const { EditorWatchdog: g } = await import("ckeditor5");
|
|
479
|
+
l = new g(r), await l.create(o), a = l.editor;
|
|
504
480
|
} else
|
|
505
|
-
|
|
481
|
+
a = await r.create(o);
|
|
506
482
|
return {
|
|
507
|
-
contextId:
|
|
508
|
-
instance:
|
|
509
|
-
watchdog:
|
|
483
|
+
contextId: u,
|
|
484
|
+
instance: a,
|
|
485
|
+
watchdog: l
|
|
510
486
|
};
|
|
511
487
|
}
|
|
512
488
|
/**
|
|
@@ -516,12 +492,12 @@ class m extends HTMLElement {
|
|
|
516
492
|
* @returns {Promise<void>}
|
|
517
493
|
*/
|
|
518
494
|
async reinitializeEditor() {
|
|
519
|
-
this.instance && (this.instancePromise = Promise.withResolvers(), await this.#
|
|
495
|
+
this.instance && (this.instancePromise = Promise.withResolvers(), await this.#l(), this.instance = null), this.style.display = "block", !this.isMultiroot() && !this.isDecoupled() && (this.innerHTML = `<${this.#n}>${this.#e}</${this.#n}>`, this.#p()), this.isMultiroot() ? this.editables = new w(this, this.#u()) : this.isDecoupled() ? this.editables = null : this.editables = this.#u();
|
|
520
496
|
try {
|
|
521
|
-
const { watchdog: t, instance:
|
|
522
|
-
this.watchdog = t, this.instance =
|
|
523
|
-
const
|
|
524
|
-
this.dispatchEvent(
|
|
497
|
+
const { watchdog: t, instance: i, contextId: n } = await this.#h(this.editables || this.#d().root?.initialData || "");
|
|
498
|
+
this.watchdog = t, this.instance = i, this.#i = n, this.#f(), this.#g(), this.#m(), this.instancePromise.resolve(this.instance);
|
|
499
|
+
const s = new CustomEvent("editor-ready", { detail: this.instance });
|
|
500
|
+
this.dispatchEvent(s), this.oneditorready?.(s);
|
|
525
501
|
} catch (t) {
|
|
526
502
|
throw this.instancePromise.reject(t), t;
|
|
527
503
|
}
|
|
@@ -530,19 +506,19 @@ class m extends HTMLElement {
|
|
|
530
506
|
* Sets up data change listener that broadcasts content changes
|
|
531
507
|
*/
|
|
532
508
|
#m() {
|
|
533
|
-
const t = (
|
|
534
|
-
...
|
|
535
|
-
[
|
|
509
|
+
const t = (n) => this.instance.getData({ rootName: n }), i = () => this.instance?.model.document.getRootNames().reduce((n, s) => ({
|
|
510
|
+
...n,
|
|
511
|
+
[s]: t(s)
|
|
536
512
|
}), {});
|
|
537
513
|
this.instance?.model.document.on("change:data", () => {
|
|
538
|
-
const
|
|
514
|
+
const n = new CustomEvent("editor-change", {
|
|
539
515
|
detail: {
|
|
540
516
|
editor: this.instance,
|
|
541
|
-
data:
|
|
517
|
+
data: i()
|
|
542
518
|
},
|
|
543
519
|
bubbles: !0
|
|
544
520
|
});
|
|
545
|
-
this.dispatchEvent(
|
|
521
|
+
this.dispatchEvent(n), this.oneditorchange?.(n);
|
|
546
522
|
});
|
|
547
523
|
}
|
|
548
524
|
/**
|
|
@@ -578,15 +554,13 @@ class m extends HTMLElement {
|
|
|
578
554
|
/**
|
|
579
555
|
* Queries and validates editable elements
|
|
580
556
|
*/
|
|
581
|
-
#
|
|
557
|
+
#u() {
|
|
582
558
|
if (this.isDecoupled())
|
|
583
559
|
return {};
|
|
584
|
-
if (this.isMultiroot())
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
return i[n.name] = n, i;
|
|
589
|
-
}, /* @__PURE__ */ Object.create(null));
|
|
560
|
+
if (this.isMultiroot()) {
|
|
561
|
+
const i = [...this.querySelectorAll("ckeditor-editable-component")];
|
|
562
|
+
return H(i);
|
|
563
|
+
}
|
|
590
564
|
const t = this.querySelector(this.#n);
|
|
591
565
|
if (!t)
|
|
592
566
|
throw new Error(`No ${this.#n} element found`);
|
|
@@ -599,9 +573,7 @@ class m extends HTMLElement {
|
|
|
599
573
|
*/
|
|
600
574
|
#p() {
|
|
601
575
|
const t = this.querySelector("textarea");
|
|
602
|
-
|
|
603
|
-
for (const e of m.inputAttributes)
|
|
604
|
-
this.hasAttribute(e) && t.setAttribute(e, this.getAttribute(e));
|
|
576
|
+
t && T(this, t, p.inputAttributes);
|
|
605
577
|
}
|
|
606
578
|
/**
|
|
607
579
|
* Sets up content sync between editor and textarea element.
|
|
@@ -614,23 +586,11 @@ class m extends HTMLElement {
|
|
|
614
586
|
const t = this.querySelector("textarea");
|
|
615
587
|
if (!t)
|
|
616
588
|
return;
|
|
617
|
-
const
|
|
618
|
-
this.style.position = "relative", t.innerHTML = "", t.value = this.instance.getData(),
|
|
619
|
-
display: "flex",
|
|
620
|
-
position: "absolute",
|
|
621
|
-
bottom: "0",
|
|
622
|
-
left: "50%",
|
|
623
|
-
width: "1px",
|
|
624
|
-
height: "1px",
|
|
625
|
-
opacity: "0",
|
|
626
|
-
pointerEvents: "none",
|
|
627
|
-
margin: "0",
|
|
628
|
-
padding: "0",
|
|
629
|
-
border: "none"
|
|
630
|
-
});
|
|
589
|
+
const i = () => {
|
|
590
|
+
this.style.position = "relative", t.innerHTML = "", t.value = this.instance.getData(), L(t);
|
|
631
591
|
};
|
|
632
|
-
|
|
633
|
-
t.dispatchEvent(new Event("input", { bubbles: !0 })), t.dispatchEvent(new Event("change", { bubbles: !0 })),
|
|
592
|
+
i(), this.instance.model.document.on("change:data", () => {
|
|
593
|
+
t.dispatchEvent(new Event("input", { bubbles: !0 })), t.dispatchEvent(new Event("change", { bubbles: !0 })), i();
|
|
634
594
|
});
|
|
635
595
|
}
|
|
636
596
|
/**
|
|
@@ -641,66 +601,151 @@ class m extends HTMLElement {
|
|
|
641
601
|
#g() {
|
|
642
602
|
if (!this.isClassic() && !this.isBallon())
|
|
643
603
|
return;
|
|
644
|
-
const
|
|
645
|
-
|
|
646
|
-
i.setStyle("height", `${e}px`, t.editing.view.document.getRoot());
|
|
647
|
-
});
|
|
604
|
+
const t = I(this.getAttribute("editable-height"));
|
|
605
|
+
t !== null && O(this.instance, t);
|
|
648
606
|
}
|
|
649
607
|
/**
|
|
650
608
|
* Gets bundle JSON description from translations attribute
|
|
651
609
|
*/
|
|
652
610
|
#c() {
|
|
653
|
-
return this.#s ||=
|
|
611
|
+
return this.#s ||= q(this.getAttribute("bundle"));
|
|
654
612
|
}
|
|
655
613
|
/**
|
|
656
614
|
* Checks if all required stylesheets are injected. If not, inject.
|
|
657
615
|
*/
|
|
658
|
-
async #
|
|
659
|
-
await
|
|
616
|
+
async #E() {
|
|
617
|
+
await b(this.#c()?.stylesheets || []);
|
|
660
618
|
}
|
|
661
619
|
/**
|
|
662
620
|
* Checks if all required scripts are injected. If not, inject.
|
|
663
621
|
*/
|
|
664
|
-
async #
|
|
665
|
-
const t = (this.#c()?.scripts || []).filter((
|
|
622
|
+
async #b() {
|
|
623
|
+
const t = (this.#c()?.scripts || []).filter((i) => !!i.window_name);
|
|
666
624
|
await h(t);
|
|
667
625
|
}
|
|
668
626
|
/**
|
|
669
627
|
* Loads translation modules
|
|
670
628
|
*/
|
|
671
|
-
async #
|
|
672
|
-
const t = this.#c()?.scripts.filter((
|
|
629
|
+
async #w() {
|
|
630
|
+
const t = this.#c()?.scripts.filter((i) => i.translation);
|
|
673
631
|
return h(t);
|
|
674
632
|
}
|
|
675
633
|
/**
|
|
676
634
|
* Loads plugin modules
|
|
677
635
|
*/
|
|
678
|
-
async #
|
|
679
|
-
|
|
680
|
-
(n) => typeof n == "string" ? { import_name: "ckeditor5", import_as: n } : n
|
|
681
|
-
);
|
|
682
|
-
return h(i);
|
|
636
|
+
async #y() {
|
|
637
|
+
return h(j(this.getAttribute("plugins")));
|
|
683
638
|
}
|
|
684
639
|
/**
|
|
685
640
|
* Gets editor constructor based on type attribute
|
|
686
641
|
*/
|
|
687
642
|
async #v() {
|
|
688
|
-
const t = await import("ckeditor5")
|
|
689
|
-
|
|
690
|
-
throw new Error(`Invalid editor type: ${e}`);
|
|
691
|
-
return t[e];
|
|
643
|
+
const t = await import("ckeditor5");
|
|
644
|
+
return N(t, this.getAttribute("type"));
|
|
692
645
|
}
|
|
693
646
|
}
|
|
694
|
-
|
|
695
|
-
|
|
647
|
+
function S(e) {
|
|
648
|
+
return e === "ClassicEditor" ? "textarea" : "div";
|
|
649
|
+
}
|
|
650
|
+
function R(e) {
|
|
651
|
+
const t = JSON.parse(e || "{}");
|
|
652
|
+
return m(t);
|
|
653
|
+
}
|
|
654
|
+
function M(e) {
|
|
655
|
+
const t = e instanceof w;
|
|
656
|
+
let i = e;
|
|
657
|
+
return t ? i = e.getAll() : typeof e != "string" && (i = e.main), { isMultiroot: t, content: i };
|
|
658
|
+
}
|
|
659
|
+
function k(e, t) {
|
|
660
|
+
return {
|
|
661
|
+
...e instanceof HTMLElement && { element: e },
|
|
662
|
+
...typeof e == "string" && { data: e },
|
|
663
|
+
...t && { editables: e }
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
function D(e, t, i, n) {
|
|
667
|
+
i ? e.roots = $(t) : n && t instanceof HTMLElement ? e.attachTo = t : t instanceof HTMLElement ? e.root = { ...e.root, element: t } : typeof t == "string" && (e.root = { ...e.root, initialData: t });
|
|
668
|
+
}
|
|
669
|
+
function $(e) {
|
|
670
|
+
return Object.fromEntries(
|
|
671
|
+
Object.entries(e).map(([t, i]) => {
|
|
672
|
+
const n = i.modelElement, s = i.initialData;
|
|
673
|
+
return [
|
|
674
|
+
t,
|
|
675
|
+
{
|
|
676
|
+
element: i,
|
|
677
|
+
initialData: s ?? i.innerHTML,
|
|
678
|
+
...n && { modelElement: n }
|
|
679
|
+
}
|
|
680
|
+
];
|
|
681
|
+
})
|
|
682
|
+
);
|
|
683
|
+
}
|
|
684
|
+
function H(e) {
|
|
685
|
+
return e.reduce((t, i) => {
|
|
686
|
+
if (!i.name)
|
|
687
|
+
throw new Error('Editable component missing required "name" attribute');
|
|
688
|
+
return t[i.name] = i, t;
|
|
689
|
+
}, /* @__PURE__ */ Object.create(null));
|
|
690
|
+
}
|
|
691
|
+
function T(e, t, i) {
|
|
692
|
+
for (const n of i)
|
|
693
|
+
e.hasAttribute(n) && t.setAttribute(n, e.getAttribute(n));
|
|
694
|
+
}
|
|
695
|
+
function L(e) {
|
|
696
|
+
e.tabIndex = -1, Object.assign(e.style, {
|
|
697
|
+
display: "flex",
|
|
698
|
+
position: "absolute",
|
|
699
|
+
bottom: "0",
|
|
700
|
+
left: "50%",
|
|
701
|
+
width: "1px",
|
|
702
|
+
height: "1px",
|
|
703
|
+
opacity: "0",
|
|
704
|
+
pointerEvents: "none",
|
|
705
|
+
margin: "0",
|
|
706
|
+
padding: "0",
|
|
707
|
+
border: "none"
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
function I(e) {
|
|
711
|
+
if (e === null)
|
|
712
|
+
return null;
|
|
713
|
+
const t = Number.parseInt(e, 10);
|
|
714
|
+
return Number.isNaN(t) ? null : t;
|
|
715
|
+
}
|
|
716
|
+
function O(e, t) {
|
|
717
|
+
e.editing.view.change((i) => {
|
|
718
|
+
i.setStyle("height", `${t}px`, e.editing.view.document.getRoot());
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
function q(e) {
|
|
722
|
+
return JSON.parse(e);
|
|
723
|
+
}
|
|
724
|
+
function j(e) {
|
|
725
|
+
return (e ? JSON.parse(e) : []).map(
|
|
726
|
+
(i) => typeof i == "string" ? { import_name: "ckeditor5", import_as: i } : i
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
function N(e, t) {
|
|
730
|
+
if (!t || !Object.prototype.hasOwnProperty.call(e, t))
|
|
731
|
+
throw new Error(`Invalid editor type: ${t}`);
|
|
732
|
+
return e[t];
|
|
733
|
+
}
|
|
734
|
+
function z(e) {
|
|
735
|
+
if (!v(e))
|
|
736
|
+
throw new Error(`Unsafe event handler attribute value: ${e}`);
|
|
737
|
+
return window[e] || new Function("event", e);
|
|
738
|
+
}
|
|
739
|
+
customElements.define("ckeditor-component", p);
|
|
740
|
+
class B extends HTMLElement {
|
|
696
741
|
/**
|
|
697
742
|
* Lifecycle callback when element is added to DOM.
|
|
698
743
|
* Adds the toolbar to the editor UI.
|
|
699
744
|
*/
|
|
700
745
|
connectedCallback() {
|
|
701
|
-
|
|
702
|
-
const t = this.getAttribute("name"),
|
|
703
|
-
this.appendChild(
|
|
746
|
+
f(async () => {
|
|
747
|
+
const t = this.getAttribute("name"), i = await this.#e().instancePromise.promise;
|
|
748
|
+
this.appendChild(i.ui.view[t].element);
|
|
704
749
|
});
|
|
705
750
|
}
|
|
706
751
|
/**
|
|
@@ -710,5 +755,5 @@ class S extends HTMLElement {
|
|
|
710
755
|
return this.closest("ckeditor-component") || document.body.querySelector("ckeditor-component");
|
|
711
756
|
}
|
|
712
757
|
}
|
|
713
|
-
customElements.define("ckeditor-ui-part-component",
|
|
758
|
+
customElements.define("ckeditor-ui-part-component", B);
|
|
714
759
|
//# sourceMappingURL=index.mjs.map
|