ckeditor5 1.36.5 → 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.
@@ -1,87 +1,87 @@
1
- function p(s) {
1
+ function f(e) {
2
2
  switch (document.readyState) {
3
3
  case "loading":
4
- document.addEventListener("DOMContentLoaded", s, { once: !0 });
4
+ document.addEventListener("DOMContentLoaded", e, { once: !0 });
5
5
  break;
6
6
  case "interactive":
7
7
  case "complete":
8
- setTimeout(s, 0);
8
+ setTimeout(e, 0);
9
9
  break;
10
10
  default:
11
- console.warn("Unexpected document.readyState:", document.readyState), setTimeout(s, 0);
11
+ console.warn("Unexpected document.readyState:", document.readyState), setTimeout(e, 0);
12
12
  }
13
13
  }
14
- const g = /* @__PURE__ */ new Map();
15
- function E(s) {
16
- if (g.has(s))
17
- return g.get(s);
18
- const t = new Promise((e, i) => {
19
- const n = document.createElement("script");
20
- n.src = s, n.onload = e, n.onerror = i, document.head.appendChild(n);
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 g.set(s, t), t;
22
+ return E.set(e, t), t;
23
23
  }
24
- function v(s) {
25
- return typeof s == "string" && s !== "__proto__" && s !== "constructor" && s !== "prototype";
24
+ function v(e) {
25
+ return typeof e == "string" && e !== "__proto__" && e !== "constructor" && e !== "prototype";
26
26
  }
27
- function C(s) {
27
+ function C(e) {
28
28
  return Array.from(document.styleSheets).some(
29
- (t) => t.href === s || t.href === new URL(s, window.location.href).href
29
+ (t) => t.href === e || t.href === new URL(e, window.location.href).href
30
30
  );
31
31
  }
32
- function w(s = []) {
33
- const t = s.map(
34
- (e) => new Promise((i, n) => {
35
- if (C(e)) {
36
- i();
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 = e, r.onerror = n, r.onload = () => i(), document.head.appendChild(r);
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(s = []) {
46
- const t = async ({ url: i, import_name: n, import_as: r, window_name: o, stylesheets: a }) => {
47
- if (a?.length && await w(a), o) {
48
- let d = function() {
49
- return Object.prototype.hasOwnProperty.call(window, o);
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 (i && !d() && await E(i), d() || window.dispatchEvent(
52
- new CustomEvent(`ckeditor:request-cjs-plugin:${o}`)
53
- ), !d())
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['${o}'] not found in global scope. Please ensure the plugin is loaded before CKEditor initialization.`
55
+ `Plugin window['${c}'] not found in global scope. Please ensure the plugin is loaded before CKEditor initialization.`
56
56
  );
57
- return window[o];
57
+ return window[c];
58
58
  }
59
- const c = await import(n), l = c[r || "default"];
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 "${n}"! Available imports: ${Object.keys(c).join(", ")}! Consider changing "import_as" value.`
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 e(i) {
67
- return t(typeof i == "string" ? { import_name: "ckeditor5", import_as: i } : i);
66
+ function i(n) {
67
+ return t(typeof n == "string" ? { import_name: "ckeditor5", import_as: n } : n);
68
68
  }
69
- return Promise.all(s.map(e));
69
+ return Promise.all(e.map(i));
70
70
  }
71
- function u(s) {
72
- if (!s || typeof s != "object")
73
- return s;
74
- if (Array.isArray(s))
75
- return s.map((i) => u(i));
76
- const t = s;
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 i = document.querySelector(t.$element);
79
- return i || console.warn(`Element not found for selector: ${t.$element}`), i || null;
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 e = /* @__PURE__ */ Object.create(null);
82
- for (const [i, n] of Object.entries(s))
83
- e[i] = u(n);
84
- return e;
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
- p(() => this.#t());
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, e, i) {
104
- e !== null && e !== i && await this.#t();
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: e } = await import("ckeditor5"), i = await this.#i(), n = this.#s();
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: n, element: this } })
137
- ), this.instance = new e(t, {
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
- ...n,
141
- plugins: i
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 u(t);
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
- p(() => {
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((e) => {
196
- this.appendChild(e.ui.view[this.name].element);
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 b {
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, e = {}) {
246
- return this.#e = t, this.#t = e, new Proxy(this, {
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(i, n) {
254
- return typeof i[n] == "function" ? i[n].bind(i) : i.#t[n];
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(i, n, r) {
264
- return i.#t[n] !== r && (i.attachRoot(n, r), i.#t[n] = r), !0;
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(i, n) {
273
- return i.detachRoot(n), delete i.#t[n], !0;
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, e) {
286
- return await this.detachRoot(t), this.#e.runAfterEditorReady((i) => {
287
- const { ui: n, editing: r, model: o } = i;
288
- i.addRoot(t, {
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
- data: e.innerHTML
279
+ initialData: o ?? i.innerHTML,
280
+ ...d && { modelElement: d }
291
281
  });
292
- const a = o.document.getRoot(t);
293
- n.getEditableElement(t) && i.detachEditable(a);
294
- const c = n.view.createEditable(t, e);
295
- n.addEditable(c), r.view.forceRender();
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((e) => {
307
- const i = e.model.document.getRoot(t);
308
- i && (e.detachEditable(i), e.detachRoot(t, !0));
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,11 +307,11 @@ class b {
317
307
  return this.#t;
318
308
  }
319
309
  }
320
- class m extends HTMLElement {
310
+ class p extends HTMLElement {
321
311
  instancePromise = Promise.withResolvers();
322
312
  watchdog = null;
323
313
  instance = null;
324
- editables = /* @__PURE__ */ Object.create({});
314
+ editables = /* @__PURE__ */ Object.create(null);
325
315
  #e = "";
326
316
  #t = null;
327
317
  #i = null;
@@ -364,13 +354,7 @@ class m extends HTMLElement {
364
354
  * @returns Event handler or null
365
355
  */
366
356
  #r(t) {
367
- if (this.hasAttribute(`on${t}`)) {
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, e) {
383
- typeof e == "string" ? this.setAttribute(`on${t}`, e) : (this.removeAttribute(`on${t}`), this[`#${t}Handler`] = e);
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
- p(async () => {
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 e = new CustomEvent("editor-error", { detail: t });
400
- this.dispatchEvent(e), this.oneditorerror?.(e);
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, e, i) {
412
- e !== null && e !== i && m.observedAttributes.includes(t) && this.isConnected && await this.reinitializeEditor();
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.#d();
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") === "ClassicEditor" ? "textarea" : "div";
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 #d() {
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
- #l() {
458
- const t = JSON.parse(this.getAttribute("config") || "{}");
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 #u(t) {
447
+ async #h(t) {
465
448
  await Promise.all([
466
- this.#b(),
467
- this.#w()
449
+ this.#E(),
450
+ this.#b()
468
451
  ]);
469
- let e = t;
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: i })
454
+ new CustomEvent("ckeditor:attach:before", { detail: s })
478
455
  );
479
- const n = await this.#v(), [r, o] = await Promise.all([
480
- this.#E(),
481
- this.#y()
482
- ]), a = {
483
- ...this.#l(),
484
- ...o.length && {
485
- translations: o
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: r
464
+ plugins: c
488
465
  };
489
- window.dispatchEvent(
490
- new CustomEvent("ckeditor:attach", { detail: { config: a, ...i } })
466
+ D(o, n, i, this.isClassic()), window.dispatchEvent(
467
+ new CustomEvent("ckeditor:attach", { detail: { config: o, ...s } })
491
468
  );
492
- let c = null, l = null, d = null;
469
+ let l = null, a = null, u = null;
493
470
  if (this.#t)
494
- d = A(), await this.#a.add({
495
- creator: (f, y) => n.create(f, y),
496
- id: d,
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: a
500
- }), l = this.#a.getItem(d);
475
+ config: o
476
+ }), a = this.#a.getItem(u);
501
477
  else if (this.hasWatchdog()) {
502
- const { EditorWatchdog: f } = await import("ckeditor5");
503
- c = new f(n), await c.create(e, a), l = c.editor;
478
+ const { EditorWatchdog: g } = await import("ckeditor5");
479
+ l = new g(r), await l.create(o), a = l.editor;
504
480
  } else
505
- l = await n.create(e, a);
481
+ a = await r.create(o);
506
482
  return {
507
- contextId: d,
508
- instance: l,
509
- watchdog: c
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.#d(), 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 b(this, this.#h()) : this.isDecoupled() ? this.editables = null : this.editables = this.#h();
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: e, contextId: i } = await this.#u(this.editables || this.#l().initialData || "");
522
- this.watchdog = t, this.instance = e, this.#i = i, this.#f(), this.#g(), this.#m(), this.instancePromise.resolve(this.instance);
523
- const n = new CustomEvent("editor-ready", { detail: this.instance });
524
- this.dispatchEvent(n), this.oneditorready?.(n);
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 = (i) => this.instance.getData({ rootName: i }), e = () => this.instance?.model.document.getRootNames().reduce((i, n) => ({
534
- ...i,
535
- [n]: t(n)
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 i = new CustomEvent("editor-change", {
514
+ const n = new CustomEvent("editor-change", {
539
515
  detail: {
540
516
  editor: this.instance,
541
- data: e()
517
+ data: i()
542
518
  },
543
519
  bubbles: !0
544
520
  });
545
- this.dispatchEvent(i), this.oneditorchange?.(i);
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
- #h() {
557
+ #u() {
582
558
  if (this.isDecoupled())
583
559
  return {};
584
- if (this.isMultiroot())
585
- return [...this.querySelectorAll("ckeditor-editable-component")].reduce((i, n) => {
586
- if (!n.name)
587
- throw new Error('Editable component missing required "name" attribute');
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
- if (t)
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 e = () => {
618
- this.style.position = "relative", t.innerHTML = "", t.value = this.instance.getData(), t.tabIndex = -1, Object.assign(t.style, {
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
- e(), this.instance.model.document.on("change:data", () => {
633
- t.dispatchEvent(new Event("input", { bubbles: !0 })), t.dispatchEvent(new Event("change", { bubbles: !0 })), e();
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 { instance: t } = this, e = Number.parseInt(this.getAttribute("editable-height"), 10);
645
- Number.isNaN(e) || t.editing.view.change((i) => {
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 ||= JSON.parse(this.getAttribute("bundle"));
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 #b() {
659
- await w(this.#c()?.stylesheets || []);
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 #w() {
665
- const t = (this.#c()?.scripts || []).filter((e) => !!e.window_name);
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 #y() {
672
- const t = this.#c()?.scripts.filter((e) => e.translation);
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 #E() {
679
- const t = this.getAttribute("plugins"), i = (t ? JSON.parse(t) : []).map(
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"), e = this.getAttribute("type");
689
- if (!e || !Object.prototype.hasOwnProperty.call(t, e))
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
- customElements.define("ckeditor-component", m);
695
- class S extends HTMLElement {
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
- p(async () => {
702
- const t = this.getAttribute("name"), e = await this.#e().instancePromise.promise;
703
- this.appendChild(e.ui.view[t].element);
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", S);
758
+ customElements.define("ckeditor-ui-part-component", B);
714
759
  //# sourceMappingURL=index.mjs.map