ckeditor5-blazor 1.11.0 → 1.12.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.
Files changed (32) hide show
  1. package/dist/elements/editable.d.ts.map +1 -1
  2. package/dist/elements/editor/editor.d.ts.map +1 -1
  3. package/dist/elements/editor/utils/assign-editor-roots-to-config.d.ts +17 -0
  4. package/dist/elements/editor/utils/assign-editor-roots-to-config.d.ts.map +1 -0
  5. package/dist/elements/editor/utils/index.d.ts +2 -3
  6. package/dist/elements/editor/utils/index.d.ts.map +1 -1
  7. package/dist/elements/editor/utils/query-all-editor-editables.d.ts +24 -0
  8. package/dist/elements/editor/utils/query-all-editor-editables.d.ts.map +1 -0
  9. package/dist/index.cjs +2 -2
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.mjs +395 -437
  12. package/dist/index.mjs.map +1 -1
  13. package/package.json +3 -3
  14. package/src/elements/editable.test.ts +42 -3
  15. package/src/elements/editable.ts +2 -0
  16. package/src/elements/editor/editor.test.ts +97 -13
  17. package/src/elements/editor/editor.ts +39 -64
  18. package/src/elements/editor/utils/assign-editor-roots-to-config.ts +61 -0
  19. package/src/elements/editor/utils/get-editor-roots-values.ts +1 -1
  20. package/src/elements/editor/utils/index.ts +2 -3
  21. package/src/elements/editor/utils/query-all-editor-editables.ts +81 -0
  22. package/src/elements/ui-part.test.ts +8 -9
  23. package/src/interop/create-editable-blazor-interop.test.ts +5 -2
  24. package/dist/elements/editor/utils/assign-initial-data-to-editor-config.d.ts +0 -10
  25. package/dist/elements/editor/utils/assign-initial-data-to-editor-config.d.ts.map +0 -1
  26. package/dist/elements/editor/utils/assign-source-elements-to-editor-config.d.ts +0 -12
  27. package/dist/elements/editor/utils/assign-source-elements-to-editor-config.d.ts.map +0 -1
  28. package/dist/elements/editor/utils/query-editor-editables.d.ts +0 -25
  29. package/dist/elements/editor/utils/query-editor-editables.d.ts.map +0 -1
  30. package/src/elements/editor/utils/assign-initial-data-to-editor-config.ts +0 -47
  31. package/src/elements/editor/utils/assign-source-elements-to-editor-config.ts +0 -59
  32. package/src/elements/editor/utils/query-editor-editables.ts +0 -101
package/dist/index.mjs CHANGED
@@ -3,15 +3,15 @@ class v extends Error {
3
3
  super(t), this.name = "CKEditor5BlazorError";
4
4
  }
5
5
  }
6
- function B(r, t) {
6
+ function U(r, t) {
7
7
  if (!r || r.size !== t.size)
8
8
  return !1;
9
- for (const [e, a] of r)
10
- if (!t.has(e) || t.get(e) !== a)
9
+ for (const [e, n] of r)
10
+ if (!t.has(e) || t.get(e) !== n)
11
11
  return !1;
12
12
  return !0;
13
13
  }
14
- class Y {
14
+ class H {
15
15
  /**
16
16
  * Map of registered items.
17
17
  */
@@ -46,13 +46,13 @@ class Y {
46
46
  * @param onError Optional error callback.
47
47
  * @returns A promise that resolves with the result of the function.
48
48
  */
49
- execute(t, e, a) {
50
- const n = this.items.get(t), i = this.initializationErrors.get(t);
51
- return i ? (a?.(i), Promise.reject(i)) : n ? Promise.resolve(e(n)) : new Promise((o, s) => {
49
+ execute(t, e, n) {
50
+ const i = this.items.get(t), a = this.initializationErrors.get(t);
51
+ return a ? (n?.(a), Promise.reject(a)) : i ? Promise.resolve(e(i)) : new Promise((o, s) => {
52
52
  const c = this.getPendingCallbacks(t);
53
53
  c.success.push(async (u) => {
54
54
  o(await e(u));
55
- }), a ? c.error.push(a) : c.error.push(s);
55
+ }), n ? c.error.push(n) : c.error.push(s);
56
56
  });
57
57
  }
58
58
  /**
@@ -63,19 +63,19 @@ class Y {
63
63
  * @returns A function that stops observing and immediately runs any pending cleanup.
64
64
  */
65
65
  mountEffect(t, e) {
66
- let a, n, i = !1;
66
+ let n, i, a = !1;
67
67
  const o = this.watch((s) => {
68
68
  const c = s.get(t);
69
- if (c !== n && (a?.(), a = void 0, n = c, !!c))
69
+ if (c !== i && (n?.(), n = void 0, i = c, !!c))
70
70
  try {
71
71
  const u = e(c);
72
- i ? (u?.(), o()) : a = u;
72
+ a ? (u?.(), o()) : n = u;
73
73
  } catch (u) {
74
74
  throw console.error(u), u;
75
75
  }
76
76
  });
77
77
  return () => {
78
- i = !0, n && (o(), a?.(), a = void 0);
78
+ a = !0, i && (o(), n?.(), n = void 0);
79
79
  };
80
80
  }
81
81
  /**
@@ -89,8 +89,8 @@ class Y {
89
89
  if (this.items.has(t))
90
90
  throw new Error(`Item with ID "${t}" is already registered.`);
91
91
  this.resetErrors(t), this.items.set(t, e);
92
- const a = this.pendingCallbacks.get(t);
93
- a && (a.success.forEach((n) => n(e)), this.pendingCallbacks.delete(t)), this.items.size === 1 && t !== null && this.register(null, e);
92
+ const n = this.pendingCallbacks.get(t);
93
+ n && (n.success.forEach((i) => i(e)), this.pendingCallbacks.delete(t)), this.items.size === 1 && t !== null && this.register(null, e);
94
94
  });
95
95
  }
96
96
  /**
@@ -102,8 +102,8 @@ class Y {
102
102
  error(t, e) {
103
103
  this.batch(() => {
104
104
  this.items.delete(t), this.initializationErrors.set(t, e);
105
- const a = this.pendingCallbacks.get(t);
106
- a && (a.error.forEach((n) => n(e)), this.pendingCallbacks.delete(t)), this.initializationErrors.size === 1 && !this.items.size && this.error(null, e);
105
+ const n = this.pendingCallbacks.get(t);
106
+ n && (n.error.forEach((i) => i(e)), this.pendingCallbacks.delete(t)), this.initializationErrors.size === 1 && !this.items.size && this.error(null, e);
107
107
  });
108
108
  }
109
109
  /**
@@ -159,8 +159,8 @@ class Y {
159
159
  * @returns A promise that resolves with the item instance.
160
160
  */
161
161
  waitFor(t) {
162
- return new Promise((e, a) => {
163
- this.execute(t, e, a);
162
+ return new Promise((e, n) => {
163
+ this.execute(t, e, n);
164
164
  });
165
165
  }
166
166
  /**
@@ -220,7 +220,7 @@ class Y {
220
220
  * Immediately dispatches the current state to all watchers if it changed.
221
221
  */
222
222
  flushWatchers() {
223
- B(this.lastNotifiedItems, this.items) && B(this.lastNotifiedErrors, this.initializationErrors) || (this.lastNotifiedItems = new Map(this.items), this.lastNotifiedErrors = new Map(this.initializationErrors), this.watchers.forEach((t) => t(
223
+ U(this.lastNotifiedItems, this.items) && U(this.lastNotifiedErrors, this.initializationErrors) || (this.lastNotifiedItems = new Map(this.items), this.lastNotifiedErrors = new Map(this.initializationErrors), this.watchers.forEach((t) => t(
224
224
  new Map(this.items),
225
225
  new Map(this.initializationErrors)
226
226
  )));
@@ -236,54 +236,50 @@ class Y {
236
236
  return e || (e = { success: [], error: [] }, this.pendingCallbacks.set(t, e)), e;
237
237
  }
238
238
  }
239
- function $(r, t) {
239
+ function W(r, t) {
240
240
  let e = null;
241
- return (...a) => {
241
+ return (...n) => {
242
242
  e && clearTimeout(e), e = setTimeout(() => {
243
- t(...a);
243
+ t(...n);
244
244
  }, r);
245
245
  };
246
246
  }
247
- function st(r, t) {
248
- const e = Object.entries(r).filter(([a, n]) => t(n, a));
249
- return Object.fromEntries(e);
250
- }
251
- function S(r) {
247
+ function P(r) {
252
248
  return Object.keys(r).length === 0 && r.constructor === Object;
253
249
  }
254
- function W(r, t) {
255
- const e = Object.entries(r).map(([a, n]) => [a, t(n, a)]);
250
+ function nt(r, t) {
251
+ const e = Object.entries(r).map(([n, i]) => [n, t(i, n)]);
256
252
  return Object.fromEntries(e);
257
253
  }
258
- function ct(r, t) {
254
+ function at(r, t) {
259
255
  if (r === t)
260
256
  return !0;
261
- const e = Object.keys(r), a = Object.keys(t);
262
- if (e.length !== a.length)
257
+ const e = Object.keys(r), n = Object.keys(t);
258
+ if (e.length !== n.length)
263
259
  return !1;
264
- for (const n of e)
265
- if (r[n] !== t[n] || !Object.prototype.hasOwnProperty.call(t, n))
260
+ for (const i of e)
261
+ if (r[i] !== t[i] || !Object.prototype.hasOwnProperty.call(t, i))
266
262
  return !1;
267
263
  return !0;
268
264
  }
269
- function ut() {
265
+ function it() {
270
266
  return Math.random().toString(36).substring(2);
271
267
  }
272
- function lt(r, {
268
+ function ot(r, {
273
269
  timeOutAfter: t = 500,
274
270
  retryAfter: e = 100
275
271
  } = {}) {
276
- return new Promise((a, n) => {
277
- const i = Date.now();
272
+ return new Promise((n, i) => {
273
+ const a = Date.now();
278
274
  let o = null;
279
275
  const s = setTimeout(() => {
280
- n(o ?? new Error("Timeout"));
276
+ i(o ?? new Error("Timeout"));
281
277
  }, t), c = async () => {
282
278
  try {
283
279
  const u = await r();
284
- clearTimeout(s), a(u);
280
+ clearTimeout(s), n(u);
285
281
  } catch (u) {
286
- o = u, Date.now() - i > t ? n(u) : setTimeout(c, e);
282
+ o = u, Date.now() - a > t ? i(u) : setTimeout(c, e);
287
283
  }
288
284
  };
289
285
  c();
@@ -310,11 +306,11 @@ function L(r) {
310
306
  } };
311
307
  let t;
312
308
  return {
313
- promise: new Promise((a) => {
314
- t = new MutationObserver((n) => {
315
- for (const i of n)
316
- if (i.type === "attributes" && i.attributeName === "data-cke-interactive" && r.hasAttribute("data-cke-interactive")) {
317
- t.disconnect(), a();
309
+ promise: new Promise((n) => {
310
+ t = new MutationObserver((i) => {
311
+ for (const a of i)
312
+ if (a.type === "attributes" && a.attributeName === "data-cke-interactive" && r.hasAttribute("data-cke-interactive")) {
313
+ t.disconnect(), n();
318
314
  break;
319
315
  }
320
316
  }), t.observe(r, { attributes: !0 });
@@ -325,73 +321,50 @@ function L(r) {
325
321
  function x(r) {
326
322
  r.setAttribute("data-cke-interactive", "true");
327
323
  }
328
- function dt(r, t) {
329
- const e = mt(r), a = /* @__PURE__ */ new Set([
330
- ...Object.keys(e),
331
- ...Object.keys(t.roots ?? {})
332
- ]), n = Array.from(a).reduce((o, s) => ({
333
- ...o,
334
- [s]: {
335
- ...t.roots?.[s],
336
- ...s === "main" ? t.root : {},
337
- /* v8 ignore next 5 */
338
- ...s in e ? {
339
- initialData: e[s]
340
- } : {}
341
- }
342
- }), Object.create(t.roots || {})), i = {
343
- ...t,
344
- roots: n
345
- };
346
- return delete i.root, i;
347
- }
348
- function mt(r) {
349
- return typeof r == "string" ? { main: r } : { ...r };
350
- }
351
- function ht(r, t, e) {
352
- const a = ft(t);
353
- if (!r.editorName || r.editorName === "ClassicEditor")
354
- return {
355
- ...e,
356
- attachTo: a.main
357
- };
358
- const n = /* @__PURE__ */ new Set([
359
- ...Object.keys(a),
324
+ function st(r, t, e) {
325
+ const n = !r.editorName || r.editorName === "ClassicEditor", i = /* @__PURE__ */ new Set([
326
+ ...Object.keys(t),
360
327
  ...Object.keys(e.roots ?? {})
361
- ]), i = Array.from(n).reduce((s, c) => ({
328
+ ]), a = Array.from(i).reduce((s, c) => ({
362
329
  ...s,
363
330
  [c]: {
364
- /* v8 ignore next */
331
+ /* v8 ignore next 1 */
365
332
  ...e.roots?.[c],
366
333
  ...c === "main" ? e.root : {},
367
- /* v8 ignore next 5 */
368
- ...c in a ? {
369
- element: a[c]
334
+ /* v8 ignore next 12 */
335
+ ...c in t ? {
336
+ ...t[c].content !== null && {
337
+ initialData: t[c].content
338
+ },
339
+ modelElement: t[c].modelElement || "$root",
340
+ ...!n && t[c].element !== null && {
341
+ element: t[c].element
342
+ }
370
343
  } : {}
371
344
  }
372
- }), Object.create(e.roots || {})), o = {
345
+ }), { ...e.roots || {} }), o = {
373
346
  ...e,
374
- roots: i
347
+ roots: a,
348
+ ...n && t.main?.element && {
349
+ attachTo: t.main.element
350
+ }
375
351
  };
376
352
  return delete o.root, o;
377
353
  }
378
- function ft(r) {
379
- return r instanceof HTMLElement ? { main: r } : { ...r };
380
- }
381
- function pt(r) {
354
+ function ct(r) {
382
355
  const t = [
383
356
  r.ui?.element,
384
357
  r.ui?.view?.toolbar?.element,
385
358
  r.ui?.view?.menuBarView?.element
386
359
  ].filter(Boolean);
387
- for (const i of t)
388
- n(i);
360
+ for (const a of t)
361
+ i(a);
389
362
  const e = r.ui?.view?.body?._bodyCollectionContainer;
390
- e?.isConnected && n(e);
391
- const a = r.editing?.view;
392
- if (a)
393
- for (const i of a.domRoots.values())
394
- i instanceof HTMLElement && (i.removeAttribute("contenteditable"), i.removeAttribute("role"), i.removeAttribute("aria-label"), i.removeAttribute("aria-multiline"), i.removeAttribute("spellcheck"), i.classList.remove(
363
+ e?.isConnected && i(e);
364
+ const n = r.editing?.view;
365
+ if (n)
366
+ for (const a of n.domRoots.values())
367
+ a instanceof HTMLElement && (a.removeAttribute("contenteditable"), a.removeAttribute("role"), a.removeAttribute("aria-label"), a.removeAttribute("aria-multiline"), a.removeAttribute("spellcheck"), a.classList.remove(
395
368
  "ck",
396
369
  "ck-content",
397
370
  "ck-editor__editable",
@@ -399,55 +372,55 @@ function pt(r) {
399
372
  "ck-editor__editable_inline",
400
373
  "ck-blurred",
401
374
  "ck-focused"
402
- ), n(i));
403
- function n(i) {
404
- i.hasAttribute("data-cke-controlled") ? i.innerHTML = "" : i.remove();
375
+ ), i(a));
376
+ function i(a) {
377
+ a.hasAttribute("data-cke-controlled") ? a.innerHTML = "" : a.remove();
405
378
  }
406
379
  }
407
- const V = /* @__PURE__ */ Symbol.for("context-editor-watchdog");
408
- async function wt({ context: r, creator: t, config: e }) {
409
- const a = ut();
380
+ const z = /* @__PURE__ */ Symbol.for("context-editor-watchdog");
381
+ async function ut({ context: r, creator: t, config: e }) {
382
+ const n = it();
410
383
  await r.add({
411
384
  creator: t.create.bind(t),
412
- id: a,
385
+ id: n,
413
386
  type: "editor",
414
387
  config: e
415
388
  });
416
- const n = r.getItem(a), i = {
389
+ const i = r.getItem(n), a = {
417
390
  state: "available",
418
- editorContextId: a,
391
+ editorContextId: n,
419
392
  context: r
420
393
  };
421
- n[V] = i;
394
+ i[z] = a;
422
395
  const o = r.destroy.bind(r);
423
- return r.destroy = async () => (i.state = "unavailable", o()), {
424
- ...i,
425
- editor: n
396
+ return r.destroy = async () => (a.state = "unavailable", o()), {
397
+ ...a,
398
+ editor: i
426
399
  };
427
400
  }
428
- function gt(r) {
429
- return V in r ? r[V] : null;
401
+ function lt(r) {
402
+ return z in r ? r[z] : null;
430
403
  }
431
- function X(r) {
432
- return Array.from(r.model.document.getRoots()).reduce((t, e) => (e.rootName === "$graveyard" || (t[e.rootName] = r.getData({ rootName: e.rootName })), t), /* @__PURE__ */ Object.create({}));
404
+ function J(r) {
405
+ return Array.from(r.model.document.getRoots()).reduce((t, e) => (e.rootName === "$graveyard" || (t[e.rootName] = r.getData({ rootName: e.rootName })), t), /* @__PURE__ */ Object.create(null));
433
406
  }
434
- function T(r) {
407
+ function V(r) {
435
408
  return ["inline", "classic", "balloon", "decoupled"].includes(r);
436
409
  }
437
- async function H(r) {
438
- const t = await import("ckeditor5"), a = {
410
+ async function j(r) {
411
+ const t = await import("ckeditor5"), n = {
439
412
  inline: t.InlineEditor,
440
413
  balloon: t.BalloonEditor,
441
414
  classic: t.ClassicEditor,
442
415
  decoupled: t.DecoupledEditor,
443
416
  multiroot: t.MultiRootEditor
444
417
  }[r];
445
- if (!a)
418
+ if (!n)
446
419
  throw new v(`Unsupported editor type: ${r}`);
447
- return a;
420
+ return n;
448
421
  }
449
- class j {
450
- static the = new j();
422
+ class _ {
423
+ static the = new _();
451
424
  /**
452
425
  * Map of registered custom plugins.
453
426
  */
@@ -506,63 +479,63 @@ class j {
506
479
  return this.plugins.has(t);
507
480
  }
508
481
  }
509
- async function K(r) {
482
+ async function G(r) {
510
483
  const t = await import("ckeditor5");
511
484
  let e = null;
512
- const a = r.map(async (n) => {
513
- if (bt(n)) {
514
- const { name: c, path: u } = n.$import, d = await import(
485
+ const n = r.map(async (i) => {
486
+ if (dt(i)) {
487
+ const { name: c, path: u } = i.$import, l = await import(
515
488
  /* @vite-ignore */
516
489
  u
517
- ), f = (Object.prototype.hasOwnProperty.call(d, c) ? d[c] : void 0) ?? (Object.prototype.hasOwnProperty.call(d, "default") ? d.default : void 0);
490
+ ), f = (Object.prototype.hasOwnProperty.call(l, c) ? l[c] : void 0) ?? (Object.prototype.hasOwnProperty.call(l, "default") ? l.default : void 0);
518
491
  if (!f)
519
492
  throw new v(`Plugin "${c}" not found in module "${u}".`);
520
493
  return f;
521
494
  }
522
- const i = await j.the.get(n);
523
- if (i)
524
- return i;
525
- const { [n]: o } = t;
495
+ const a = await _.the.get(i);
496
+ if (a)
497
+ return a;
498
+ const { [i]: o } = t;
526
499
  if (o)
527
500
  return o;
528
501
  if (!e)
529
502
  try {
530
503
  e = await import("ckeditor5-premium-features");
531
504
  } catch (c) {
532
- throw console.error(`Failed to load premium package: ${c}`), new v(`Plugin "${n}" not found in base package and failed to load premium package.`);
505
+ throw console.error(`Failed to load premium package: ${c}`), new v(`Plugin "${i}" not found in base package and failed to load premium package.`);
533
506
  }
534
- const { [n]: s } = e || {};
507
+ const { [i]: s } = e || {};
535
508
  if (s)
536
509
  return s;
537
- throw new v(`Plugin "${n}" not found in base or premium packages.`);
510
+ throw new v(`Plugin "${i}" not found in base or premium packages.`);
538
511
  });
539
512
  return {
540
- loadedPlugins: await Promise.all(a),
513
+ loadedPlugins: await Promise.all(n),
541
514
  hasPremium: !!e
542
515
  };
543
516
  }
544
- function bt(r) {
517
+ function dt(r) {
545
518
  return typeof r == "object" && r !== null && "$import" in r;
546
519
  }
547
- async function Q(r, t) {
520
+ async function Y(r, t) {
548
521
  const e = [r.ui, r.content];
549
522
  return await Promise.all(
550
523
  [
551
- J("ckeditor5", e),
524
+ B("ckeditor5", e),
552
525
  /* v8 ignore next -- @preserve */
553
- t && J("ckeditor5-premium-features", e)
554
- ].filter((n) => !!n)
555
- ).then((n) => n.flat());
526
+ t && B("ckeditor5-premium-features", e)
527
+ ].filter((i) => !!i)
528
+ ).then((i) => i.flat());
556
529
  }
557
- async function J(r, t) {
530
+ async function B(r, t) {
558
531
  return await Promise.all(
559
532
  t.filter((e) => e !== "en").map(async (e) => {
560
- const a = await yt(r, e);
561
- return a?.default ?? a;
533
+ const n = await mt(r, e);
534
+ return n?.default ?? n;
562
535
  }).filter(Boolean)
563
536
  );
564
537
  }
565
- async function yt(r, t) {
538
+ async function mt(r, t) {
566
539
  try {
567
540
  if (r === "ckeditor5")
568
541
  switch (t) {
@@ -862,12 +835,12 @@ async function yt(r, t) {
862
835
  return console.error(`Failed to load translation for ${r}/${t}:`, e), null;
863
836
  }
864
837
  }
865
- function Z(r) {
866
- return W(r, (t) => ({
838
+ function X(r) {
839
+ return nt(r, (t) => ({
867
840
  dictionary: t
868
841
  }));
869
842
  }
870
- function tt(r) {
843
+ function Q(r) {
871
844
  return r ? typeof r == "string" ? {
872
845
  ui: r,
873
846
  content: r
@@ -876,103 +849,99 @@ function tt(r) {
876
849
  content: "en"
877
850
  };
878
851
  }
879
- function _() {
880
- return Array.from(document.querySelectorAll("cke5-editor")).map((r) => r.getAttribute("data-cke-editor-id")).filter((r) => r !== null);
881
- }
882
- function et(r) {
883
- const t = rt(r);
884
- return W(t, ({ element: e }) => e);
885
- }
886
- function G(r) {
887
- const t = rt(r), e = W(t, ({ content: a }) => a);
888
- return st(e, (a) => typeof a == "string");
889
- }
890
- function rt(r) {
852
+ function Z(r) {
891
853
  const t = Array.from(document.querySelectorAll(`cke5-editable[data-cke-editor-id="${r}"]`)).reduce((o, s) => {
892
- const c = s.getAttribute("data-cke-root-name"), u = s.getAttribute("data-cke-content");
854
+ const c = s.getAttribute("data-cke-root-name"), u = s.getAttribute("data-cke-root-model-element-name") || null;
893
855
  return o[c] = {
894
856
  element: s.querySelector("[data-cke-editable-content]"),
895
- content: u
857
+ content: s.getAttribute("data-cke-content"),
858
+ modelElement: u
896
859
  }, o;
897
- }, /* @__PURE__ */ Object.create({})), e = document.querySelector(`cke5-editor[data-cke-editor-id="${r}"]`);
860
+ }, /* @__PURE__ */ Object.create(null)), e = document.querySelector(`cke5-editor[data-cke-editor-id="${r}"]`);
898
861
  if (!e)
899
862
  return t;
900
- const a = t.main, n = JSON.parse(e.getAttribute("data-cke-content")), i = document.querySelector(`#${r}_editor `);
901
- return a && n?.main ? {
902
- ...t,
903
- main: {
904
- ...a,
905
- content: a.content || n.main
906
- }
907
- } : i ? {
908
- ...t,
909
- main: {
910
- element: i,
911
- content: n?.main || null
912
- }
913
- } : t;
863
+ const n = JSON.parse(e.getAttribute("data-cke-content")) ?? {}, i = document.querySelector(`#${r}_editor`), a = e.getAttribute("data-cke-root-model-element-name");
864
+ i && !t.main && (t.main = {
865
+ element: i,
866
+ content: n.main || "",
867
+ modelElement: a
868
+ });
869
+ for (const [o, s] of Object.entries(n))
870
+ t[o] ? t[o] = {
871
+ ...t[o],
872
+ content: t[o].content ?? s,
873
+ modelElement: t[o].modelElement ?? a
874
+ } : t[o] = {
875
+ element: null,
876
+ content: s,
877
+ modelElement: a
878
+ };
879
+ return t;
880
+ }
881
+ function F() {
882
+ return Array.from(document.querySelectorAll("cke5-editor")).map((r) => r.getAttribute("data-cke-editor-id")).filter((r) => r !== null);
914
883
  }
915
884
  function M(r) {
916
885
  if (!r || typeof r != "object")
917
886
  return r;
918
887
  if (Array.isArray(r))
919
- return r.map((a) => M(a));
888
+ return r.map((n) => M(n));
920
889
  const t = r;
921
890
  if (t.$element && typeof t.$element == "string") {
922
- const a = document.querySelector(t.$element);
923
- return a || console.warn(`Element not found for selector: ${t.$element}`), a || null;
891
+ const n = document.querySelector(t.$element);
892
+ return n || console.warn(`Element not found for selector: ${t.$element}`), n || null;
924
893
  }
925
894
  const e = /* @__PURE__ */ Object.create(null);
926
- for (const [a, n] of Object.entries(r))
927
- e[a] = M(n);
895
+ for (const [n, i] of Object.entries(r))
896
+ e[n] = M(i);
928
897
  return e;
929
898
  }
930
- function D(r, t, e) {
899
+ function S(r, t, e) {
931
900
  if (!e || typeof e != "object")
932
901
  return e;
933
902
  if (Array.isArray(e))
934
- return e.map((i) => D(r, t, i));
935
- const a = e;
936
- if (a.$translation && typeof a.$translation == "string") {
937
- const i = a.$translation, o = Et(r, i, t);
938
- return o === void 0 && console.warn(`Translation not found for key: ${i}`), o !== void 0 ? o : null;
903
+ return e.map((a) => S(r, t, a));
904
+ const n = e;
905
+ if (n.$translation && typeof n.$translation == "string") {
906
+ const a = n.$translation, o = ht(r, a, t);
907
+ return o === void 0 && console.warn(`Translation not found for key: ${a}`), o !== void 0 ? o : null;
939
908
  }
940
- const n = /* @__PURE__ */ Object.create(null);
941
- for (const [i, o] of Object.entries(e))
942
- n[i] = D(r, t, o);
943
- return n;
909
+ const i = /* @__PURE__ */ Object.create(null);
910
+ for (const [a, o] of Object.entries(e))
911
+ i[a] = S(r, t, o);
912
+ return i;
944
913
  }
945
- function Et(r, t, e) {
946
- for (const a of r) {
947
- const n = a[e];
948
- if (n?.dictionary && t in n.dictionary)
949
- return n.dictionary[t];
914
+ function ht(r, t, e) {
915
+ for (const n of r) {
916
+ const i = n[e];
917
+ if (i?.dictionary && t in i.dictionary)
918
+ return i.dictionary[t];
950
919
  }
951
920
  }
952
- function kt(r, t) {
921
+ function ft(r, t) {
953
922
  const { editing: e } = r;
954
- e.view.change((a) => {
955
- a.setStyle("height", `${t}px`, e.view.document.getRoot());
923
+ e.view.change((n) => {
924
+ n.setStyle("height", `${t}px`, e.view.document.getRoot());
956
925
  });
957
926
  }
958
- const z = /* @__PURE__ */ Symbol.for("elixir-editor-watchdog");
959
- async function vt(r, t) {
960
- const { EditorWatchdog: e } = await import("ckeditor5"), a = new e(null, t ?? {
927
+ const $ = /* @__PURE__ */ Symbol.for("elixir-editor-watchdog");
928
+ async function pt(r, t) {
929
+ const { EditorWatchdog: e } = await import("ckeditor5"), n = new e(null, t ?? {
961
930
  crashNumberLimit: 10,
962
931
  minimumNonErrorTimePeriod: 5e3
963
932
  });
964
- return a.setCreator(async () => {
965
- const n = await r();
966
- return n[z] = a, n;
967
- }), a;
933
+ return n.setCreator(async () => {
934
+ const i = await r();
935
+ return i[$] = n, i;
936
+ }), n;
968
937
  }
969
- function At(r) {
970
- return z in r ? r[z] : null;
938
+ function wt(r) {
939
+ return $ in r ? r[$] : null;
971
940
  }
972
- class O extends Y {
973
- static the = new O();
941
+ class C extends H {
942
+ static the = new C();
974
943
  }
975
- class Ct extends HTMLElement {
944
+ class gt extends HTMLElement {
976
945
  /**
977
946
  * The promise that resolves to the context instance.
978
947
  */
@@ -991,29 +960,29 @@ class Ct extends HTMLElement {
991
960
  * Initializes the context component.
992
961
  */
993
962
  async initializeContext() {
994
- const t = JSON.parse(this.getAttribute("data-cke-context")), { customTranslations: e, watchdogConfig: a, config: { plugins: n, ...i } } = t, o = this.getAttribute("data-cke-context-id"), s = this.getAttribute("data-cke-language") ? JSON.parse(this.getAttribute("data-cke-language")) : tt(i.language), { loadedPlugins: c, hasPremium: u } = await K(n ?? []), d = [
995
- ...await Q(s, u),
996
- Z(e || {})
997
- ].filter((b) => !S(b));
963
+ const t = JSON.parse(this.getAttribute("data-cke-context")), { customTranslations: e, watchdogConfig: n, config: { plugins: i, ...a } } = t, o = this.getAttribute("data-cke-context-id"), s = this.getAttribute("data-cke-language") ? JSON.parse(this.getAttribute("data-cke-language")) : Q(a.language), { loadedPlugins: c, hasPremium: u } = await G(i ?? []), l = [
964
+ ...await Y(s, u),
965
+ X(e || {})
966
+ ].filter((b) => !P(b));
998
967
  this.contextPromise = (async () => {
999
- const { ContextWatchdog: b, Context: y } = await import("ckeditor5"), w = new b(y, {
968
+ const { ContextWatchdog: b, Context: E } = await import("ckeditor5"), w = new b(E, {
1000
969
  crashNumberLimit: 10,
1001
- ...a
970
+ ...n
1002
971
  });
1003
- let h = M(i);
1004
- return h = D([...d].reverse(), s.ui, h), await w.create({
1005
- ...h,
972
+ let g = M(a);
973
+ return g = S([...l].reverse(), s.ui, g), await w.create({
974
+ ...g,
1006
975
  language: s,
1007
976
  plugins: c,
1008
- ...d.length && {
1009
- translations: d
977
+ ...l.length && {
978
+ translations: l
1010
979
  }
1011
- }), w.on("itemError", (...A) => {
1012
- console.error("Context item error:", ...A);
980
+ }), w.on("itemError", (...h) => {
981
+ console.error("Context item error:", ...h);
1013
982
  }), w;
1014
983
  })();
1015
984
  const f = await this.contextPromise;
1016
- this.isConnected && O.the.register(o, f);
985
+ this.isConnected && C.the.register(o, f);
1017
986
  }
1018
987
  /**
1019
988
  * Destroys the context component. Unmounts root from the editor.
@@ -1025,14 +994,14 @@ class Ct extends HTMLElement {
1025
994
  try {
1026
995
  await (await this.contextPromise)?.destroy();
1027
996
  } finally {
1028
- this.contextPromise = null, t && O.the.hasItem(t) && O.the.unregister(t);
997
+ this.contextPromise = null, t && C.the.hasItem(t) && C.the.unregister(t);
1029
998
  }
1030
999
  }
1031
1000
  }
1032
- class m extends Y {
1001
+ class m extends H {
1033
1002
  static the = new m();
1034
1003
  }
1035
- class Ot extends HTMLElement {
1004
+ class bt extends HTMLElement {
1036
1005
  /**
1037
1006
  * Stops observing the editor registry and immediately runs any pending cleanup.
1038
1007
  */
@@ -1051,55 +1020,56 @@ class Ot extends HTMLElement {
1051
1020
  * Initializes the editable instance.
1052
1021
  */
1053
1022
  async initializeEditable() {
1054
- this.hasAttribute("data-cke-editor-id") || this.setAttribute("data-cke-editor-id", _()[0]);
1055
- const t = this.getAttribute("data-cke-editor-id"), e = this.getAttribute("data-cke-root-name"), a = JSON.parse(this.getAttribute("data-cke-root-attributes") || "{}"), n = this.getAttribute("data-cke-content"), i = Number.parseInt(this.getAttribute("data-cke-save-debounce-ms"), 10);
1023
+ this.hasAttribute("data-cke-editor-id") || this.setAttribute("data-cke-editor-id", F()[0]);
1024
+ const t = this.getAttribute("data-cke-editor-id"), e = this.getAttribute("data-cke-root-name"), n = JSON.parse(this.getAttribute("data-cke-root-attributes") || "{}"), i = this.getAttribute("data-cke-root-model-element-name") || "$root", a = this.getAttribute("data-cke-content"), o = Number.parseInt(this.getAttribute("data-cke-save-debounce-ms"), 10);
1056
1025
  if (!t || !e)
1057
1026
  throw new v("Editor ID or Root Name is missing.");
1058
- this.style.display = "block", this.unmountEffect = m.the.mountEffect(t, (o) => {
1027
+ this.style.display = "block", this.unmountEffect = m.the.mountEffect(t, (s) => {
1059
1028
  if (!this.isConnected)
1060
1029
  return;
1061
- const { ui: s, editing: c, model: u } = o, l = this.querySelector("input"), d = u.document.getRoot(e);
1062
- if (d?.isAttached()) {
1063
- if (n !== null) {
1064
- const h = o.getData({ rootName: e });
1065
- h && h !== n && o.setData({
1066
- [e]: n
1030
+ const { ui: c, editing: u, model: d } = s, l = this.querySelector("input"), f = d.document.getRoot(e);
1031
+ if (f?.isAttached()) {
1032
+ if (a !== null) {
1033
+ const h = s.getData({ rootName: e });
1034
+ h && h !== a && s.setData({
1035
+ [e]: a
1067
1036
  });
1068
1037
  }
1069
- S(a) || o.model.change((h) => {
1070
- h.setAttributes(a, d);
1038
+ P(n) || s.model.change((h) => {
1039
+ h.setAttributes(n, f);
1071
1040
  });
1072
1041
  return;
1073
1042
  }
1074
- o.addRoot(e, {
1043
+ s.addRoot(e, {
1075
1044
  isUndoable: !1,
1076
- modelAttributes: { ...a },
1077
- ...n !== null && {
1078
- initialData: n
1045
+ modelAttributes: { ...n },
1046
+ modelElement: i,
1047
+ ...a !== null && {
1048
+ initialData: a
1079
1049
  }
1080
1050
  });
1081
- const f = this.querySelector("[data-cke-editable-content]"), b = s.view.createEditable(e, f);
1082
- s.addEditable(b), c.view.forceRender();
1083
- const y = () => {
1084
- if (!u.document.getRoot(e)?.isAttached())
1051
+ const b = this.querySelector("[data-cke-editable-content]"), E = c.view.createEditable(e, b);
1052
+ c.addEditable(E), u.view.forceRender();
1053
+ const w = () => {
1054
+ if (!d.document.getRoot(e)?.isAttached())
1085
1055
  return;
1086
- const h = o.getData({ rootName: e });
1056
+ const h = s.getData({ rootName: e });
1087
1057
  l && (l.value = h, l.dispatchEvent(new Event("input"))), this.dispatchEvent(new CustomEvent("change", {
1088
1058
  detail: {
1089
1059
  value: h
1090
1060
  }
1091
1061
  }));
1092
- }, w = $(i, y);
1093
- return o.model.document.on("change:data", w), y(), () => {
1094
- if (o.model.document.off("change:data", w), o.state !== "destroyed" && e) {
1095
- const h = o.model.document.getRoot(e);
1096
- if (h && "detachEditable" in o) {
1062
+ }, g = W(o, w);
1063
+ return s.model.document.on("change:data", g), w(), () => {
1064
+ if (s.model.document.off("change:data", g), s.state !== "destroyed" && e) {
1065
+ const h = s.model.document.getRoot(e);
1066
+ if (h && "detachEditable" in s) {
1097
1067
  try {
1098
- o.ui.view.editables[e] && o.detachEditable(h);
1099
- } catch (A) {
1100
- console.error("Unable unmount editable from root:", A);
1068
+ s.ui.view.editables[e] && s.detachEditable(h);
1069
+ } catch (p) {
1070
+ console.error("Unable unmount editable from root:", p);
1101
1071
  }
1102
- h.isAttached() && o.detachRoot(e, !1);
1072
+ h.isAttached() && s.detachRoot(e, !1);
1103
1073
  }
1104
1074
  }
1105
1075
  };
@@ -1112,13 +1082,13 @@ class Ot extends HTMLElement {
1112
1082
  this.interactiveWait?.disconnect(), this.style.display = "none", this.unmountEffect?.(), this.unmountEffect = null;
1113
1083
  }
1114
1084
  }
1115
- async function It({
1085
+ async function Et({
1116
1086
  saveDebounceMs: r,
1117
1087
  editorId: t,
1118
1088
  targetElement: e
1119
1089
  }) {
1120
- const { Plugin: a } = await import("ckeditor5");
1121
- return class extends a {
1090
+ const { Plugin: n } = await import("ckeditor5");
1091
+ return class extends n {
1122
1092
  /**
1123
1093
  * The name of the plugin.
1124
1094
  */
@@ -1129,34 +1099,34 @@ async function It({
1129
1099
  * Initializes the plugin.
1130
1100
  */
1131
1101
  afterInit() {
1132
- const { editor: i } = this, o = $(r, this.dispatch);
1133
- i.model.document.on("change:data", o), i.once("ready", this.dispatch);
1102
+ const { editor: a } = this, o = W(r, this.dispatch);
1103
+ a.model.document.on("change:data", o), a.once("ready", this.dispatch);
1134
1104
  }
1135
1105
  /**
1136
1106
  * Dispatches a custom event with all roots data.
1137
1107
  */
1138
1108
  dispatch = () => {
1139
- const { editor: i } = this;
1109
+ const { editor: a } = this;
1140
1110
  e.dispatchEvent(
1141
- new k({
1111
+ new y({
1142
1112
  editorId: t,
1143
- editor: i,
1144
- roots: X(i)
1113
+ editor: a,
1114
+ roots: J(a)
1145
1115
  })
1146
1116
  );
1147
1117
  };
1148
1118
  };
1149
1119
  }
1150
- class k extends CustomEvent {
1120
+ class y extends CustomEvent {
1151
1121
  static EVENT_NAME = "ckeditor5:change:data";
1152
1122
  constructor(t) {
1153
- super(k.EVENT_NAME, {
1123
+ super(y.EVENT_NAME, {
1154
1124
  detail: t,
1155
1125
  bubbles: !0
1156
1126
  });
1157
1127
  }
1158
1128
  }
1159
- async function Tt(r) {
1129
+ async function yt(r) {
1160
1130
  const { Plugin: t } = await import("ckeditor5");
1161
1131
  return class extends t {
1162
1132
  /**
@@ -1177,16 +1147,16 @@ async function Tt(r) {
1177
1147
  * Initializes the plugin.
1178
1148
  */
1179
1149
  afterInit() {
1180
- const { editor: a } = this, i = a.sourceElement.id.replace(/_editor$/, "");
1181
- this.input = document.getElementById(`${i}_input`), this.input && (a.model.document.on("change:data", $(r, () => this.sync())), a.once("ready", this.sync), this.form = this.input.closest("form"), this.form?.addEventListener("submit", this.sync));
1150
+ const { editor: n } = this, a = n.sourceElement.id.replace(/_editor$/, "");
1151
+ this.input = document.getElementById(`${a}_input`), this.input && (n.model.document.on("change:data", W(r, () => this.sync())), n.once("ready", this.sync), this.form = this.input.closest("form"), this.form?.addEventListener("submit", this.sync));
1182
1152
  }
1183
1153
  /**
1184
1154
  * Synchronizes the editor's content with the input field.
1185
1155
  */
1186
1156
  sync = () => {
1187
1157
  if (this.input) {
1188
- const a = this.editor.getData();
1189
- this.input.value = a, this.input.dispatchEvent(new Event("input", { bubbles: !0 }));
1158
+ const n = this.editor.getData();
1159
+ this.input.value = n, this.input.dispatchEvent(new Event("input", { bubbles: !0 }));
1190
1160
  }
1191
1161
  };
1192
1162
  /**
@@ -1197,7 +1167,7 @@ async function Tt(r) {
1197
1167
  }
1198
1168
  };
1199
1169
  }
1200
- class Nt extends HTMLElement {
1170
+ class kt extends HTMLElement {
1201
1171
  /**
1202
1172
  * Stops observing the editor registry and immediately runs any pending cleanup.
1203
1173
  */
@@ -1210,7 +1180,7 @@ class Nt extends HTMLElement {
1210
1180
  * Mounts the editor component.
1211
1181
  */
1212
1182
  async connectedCallback() {
1213
- await R(), this.interactiveWait = L(this), H("classic"), await this.interactiveWait.promise, await this.initializeEditor();
1183
+ await R(), this.interactiveWait = L(this), j("classic"), await this.interactiveWait.promise, await this.initializeEditor();
1214
1184
  }
1215
1185
  /**
1216
1186
  * Initializes the editor instance.
@@ -1220,15 +1190,15 @@ class Nt extends HTMLElement {
1220
1190
  m.the.resetErrors(t);
1221
1191
  try {
1222
1192
  this.style.display = "block";
1223
- const e = await this.createEditor(), a = gt(e), n = At(e);
1193
+ const e = await this.createEditor(), n = lt(e), i = wt(e);
1224
1194
  if (this.isConnected) {
1225
- const i = m.the.mountEffect(t, (o) => {
1195
+ const a = m.the.mountEffect(t, (o) => {
1226
1196
  o.once("destroy", () => {
1227
1197
  m.the.unregister(t, !1);
1228
1198
  }, { priority: "highest" });
1229
1199
  });
1230
1200
  this.unmountEffect = async () => {
1231
- m.the.unregister(t), i(), a ? a.state !== "unavailable" && await a.context.remove(a.editorContextId) : n ? await n.destroy() : await e.destroy();
1201
+ m.the.unregister(t), a(), n ? n.state !== "unavailable" && await n.context.remove(n.editorContextId) : i ? await i.destroy() : await e.destroy();
1232
1202
  }, m.the.register(t, e);
1233
1203
  }
1234
1204
  } catch (e) {
@@ -1248,94 +1218,82 @@ class Nt extends HTMLElement {
1248
1218
  async createEditor() {
1249
1219
  const t = JSON.parse(this.getAttribute("data-cke-preset")), {
1250
1220
  customTranslations: e,
1251
- editorType: a,
1252
- licenseKey: n,
1253
- watchdogConfig: i,
1221
+ editorType: n,
1222
+ licenseKey: i,
1223
+ watchdogConfig: a,
1254
1224
  config: { plugins: o, ...s }
1255
- } = t, c = this.getAttribute("data-cke-editor-id"), u = this.getAttribute("data-cke-context-id"), l = JSON.parse(this.getAttribute("data-cke-root-attributes") || "{}"), d = this.getAttribute("data-cke-editable-height") ? Number.parseInt(this.getAttribute("data-cke-editable-height"), 10) : null, f = Number.parseInt(this.getAttribute("data-cke-save-debounce-ms"), 10), b = this.hasAttribute("data-cke-watchdog"), y = JSON.parse(this.getAttribute("data-cke-content")), w = this.getAttribute("data-cke-language") ? JSON.parse(this.getAttribute("data-cke-language")) : tt(t.config.language), h = await H(a), A = await (u ? O.the.waitFor(u) : null), q = async () => {
1256
- const { loadedPlugins: E, hasPremium: N } = await K(o);
1257
- E.push(
1258
- await It({
1225
+ } = t, c = this.getAttribute("data-cke-editor-id"), u = this.getAttribute("data-cke-context-id"), d = JSON.parse(this.getAttribute("data-cke-root-attributes") || "{}"), l = this.getAttribute("data-cke-editable-height") ? Number.parseInt(this.getAttribute("data-cke-editable-height"), 10) : null, f = Number.parseInt(this.getAttribute("data-cke-save-debounce-ms"), 10), b = this.hasAttribute("data-cke-watchdog"), E = this.getAttribute("data-cke-language") ? JSON.parse(this.getAttribute("data-cke-language")) : Q(t.config.language), w = await j(n), g = await (u ? C.the.waitFor(u) : null), h = async () => {
1226
+ const { loadedPlugins: p, hasPremium: I } = await G(o);
1227
+ p.push(
1228
+ await Et({
1259
1229
  saveDebounceMs: f,
1260
1230
  editorId: c,
1261
1231
  targetElement: this
1262
1232
  })
1263
- ), T(a) && E.push(
1264
- await Tt(f)
1233
+ ), V(n) && p.push(
1234
+ await yt(f)
1265
1235
  );
1266
- const C = [
1267
- ...await Q(w, N),
1268
- Z(e || {})
1269
- ].filter((p) => !S(p));
1270
- let I = {
1271
- ...y,
1272
- ...G(c)
1273
- };
1274
- T(a) && (I = I.main || "");
1275
- const P = await (async () => {
1276
- let p = et(c);
1277
- if (!p.main) {
1278
- const U = T(a) ? ["main"] : Object.keys(I);
1279
- at(p, U) || (p = await Pt(c, U), I = {
1280
- ...y,
1281
- ...G(c)
1282
- });
1236
+ const A = [
1237
+ ...await Y(E, I),
1238
+ X(e || {})
1239
+ ].filter((N) => !P(N));
1240
+ let T = Z(c);
1241
+ const D = Object.keys(T);
1242
+ V(n) && D.push("main"), K(T, D) || (T = await vt(c, D));
1243
+ let k = {
1244
+ ...s,
1245
+ licenseKey: i,
1246
+ plugins: p,
1247
+ language: E,
1248
+ ...A.length && {
1249
+ translations: A
1283
1250
  }
1284
- T(a) && "main" in p && (p = p.main);
1285
- let g = {
1286
- ...s,
1287
- licenseKey: n,
1288
- plugins: E,
1289
- language: w,
1290
- ...C.length && {
1291
- translations: C
1292
- }
1293
- };
1294
- return g = M(g), g = D([...C].reverse(), w.ui, g), g = ht(h, p, g), g = dt(I, g), A ? (await wt({
1295
- context: A,
1296
- creator: h,
1297
- config: g
1298
- })).editor : h.create(g);
1299
- })();
1300
- return S(l) || P.model.change((p) => {
1301
- p.setAttributes(l, P.model.document.getRoot());
1302
- }), T(a) && d && kt(P, d), P;
1251
+ };
1252
+ k = M(k), k = S([...A].reverse(), E.ui, k), k = st(w, T, k);
1253
+ const O = await (async () => g ? (await ut({
1254
+ context: g,
1255
+ creator: w,
1256
+ config: k
1257
+ })).editor : w.create(k))();
1258
+ return P(d) || O.model.change((N) => {
1259
+ N.setAttributes(d, O.model.document.getRoot());
1260
+ }), V(n) && l && ft(O, l), O;
1303
1261
  };
1304
- if (b && !A) {
1305
- const E = await vt(q, i);
1306
- return E.on("error", (N, { causesRestart: F }) => {
1307
- if (F) {
1308
- const C = m.the.getItem(c);
1309
- C && (pt(C), m.the.unregister(c));
1262
+ if (b && !g) {
1263
+ const p = await pt(h, a);
1264
+ return p.on("error", (I, { causesRestart: q }) => {
1265
+ if (q) {
1266
+ const A = m.the.getItem(c);
1267
+ A && (ct(A), m.the.unregister(c));
1310
1268
  }
1311
- }), E.on("restart", () => {
1312
- const N = E.editor;
1313
- m.the.register(c, N);
1314
- }), await E.create({}), E.editor;
1269
+ }), p.on("restart", () => {
1270
+ const I = p.editor;
1271
+ m.the.register(c, I);
1272
+ }), await p.create({}), p.editor;
1315
1273
  }
1316
- return q();
1274
+ return h();
1317
1275
  }
1318
1276
  }
1319
- function at(r, t) {
1320
- return t.every((e) => r[e]);
1277
+ function K(r, t) {
1278
+ return t.every((e) => r[e]?.element);
1321
1279
  }
1322
- async function Pt(r, t) {
1323
- return lt(
1280
+ async function vt(r, t) {
1281
+ return ot(
1324
1282
  () => {
1325
- const e = et(r);
1326
- if (!at(e, t))
1283
+ const e = Z(r);
1284
+ if (!K(e, t))
1327
1285
  throw new Error(
1328
1286
  `It looks like not all required root elements are present yet.
1329
1287
  * If you want to wait for them, ensure they are registered before editor initialization.
1330
1288
  * If you want lazy initialize roots, consider removing root values from the \`initialData\` config and assign initial data in editable components.
1331
- Missing roots: ${t.filter((a) => !e[a]).join(", ")}.`
1289
+ Missing roots: ${t.filter((n) => !e[n]?.element).join(", ")}.`
1332
1290
  );
1333
1291
  return e;
1334
1292
  },
1335
1293
  { timeOutAfter: 2e3, retryAfter: 100 }
1336
1294
  );
1337
1295
  }
1338
- class St extends HTMLElement {
1296
+ class At extends HTMLElement {
1339
1297
  /**
1340
1298
  * Stops observing the editor registry and immediately runs any pending cleanup.
1341
1299
  */
@@ -1345,11 +1303,11 @@ class St extends HTMLElement {
1345
1303
  */
1346
1304
  async connectedCallback() {
1347
1305
  await R();
1348
- const t = this.getAttribute("data-cke-editor-id") || _()[0], e = this.getAttribute("data-cke-name");
1349
- !t || !e || (this.style.display = "block", this.unmountEffect = m.the.mountEffect(t, (a) => {
1306
+ const t = this.getAttribute("data-cke-editor-id") || F()[0], e = this.getAttribute("data-cke-name");
1307
+ !t || !e || (this.style.display = "block", this.unmountEffect = m.the.mountEffect(t, (n) => {
1350
1308
  if (!this.isConnected)
1351
1309
  return;
1352
- const { ui: n } = a, i = Mt(e), o = n.view[i];
1310
+ const { ui: i } = n, a = Ct(e), o = i.view[a];
1353
1311
  if (!o)
1354
1312
  throw new v(`Unknown UI part name: "${e}". Supported names are "toolbar" and "menubar".`);
1355
1313
  return this.appendChild(o.element), () => {
@@ -1364,7 +1322,7 @@ class St extends HTMLElement {
1364
1322
  this.style.display = "none", this.unmountEffect?.(), this.unmountEffect = null;
1365
1323
  }
1366
1324
  }
1367
- function Mt(r) {
1325
+ function Ct(r) {
1368
1326
  switch (r) {
1369
1327
  case "toolbar":
1370
1328
  return "toolbar";
@@ -1375,43 +1333,43 @@ function Mt(r) {
1375
1333
  return null;
1376
1334
  }
1377
1335
  }
1378
- const Dt = {
1379
- "cke5-editor": Nt,
1380
- "cke5-context": Ct,
1381
- "cke5-ui-part": St,
1382
- "cke5-editable": Ot
1336
+ const It = {
1337
+ "cke5-editor": kt,
1338
+ "cke5-context": gt,
1339
+ "cke5-ui-part": At,
1340
+ "cke5-editable": bt
1383
1341
  };
1384
- function Rt() {
1385
- for (const [r, t] of Object.entries(Dt))
1342
+ function Tt() {
1343
+ for (const [r, t] of Object.entries(It))
1386
1344
  window.customElements.get(r) || window.customElements.define(r, t);
1387
1345
  }
1388
- function Lt(r) {
1346
+ function St(r) {
1389
1347
  return x(r), {
1390
1348
  unmount() {
1391
1349
  }
1392
1350
  };
1393
1351
  }
1394
- function nt(r, t) {
1352
+ function tt(r, t) {
1395
1353
  const e = {
1396
1354
  /** Value received from Blazor while the editor was focused, pending application on blur. */
1397
1355
  pendingValue: null,
1398
1356
  /** The last value sent to or received from Blazor to prevent circular updates. */
1399
1357
  lastSyncedValue: null
1400
- }, a = () => {
1358
+ }, n = () => {
1401
1359
  e.pendingValue = null;
1402
- }, n = (i, o, s) => {
1360
+ }, i = (a, o, s) => {
1403
1361
  if (s || e.pendingValue === null)
1404
1362
  return;
1405
1363
  const c = t.getCurrentValue();
1406
1364
  t.isEqual(c, e.pendingValue) || t.applyValue(e.pendingValue), e.pendingValue = null;
1407
1365
  };
1408
- return r.model.document.on("change:data", a), r.ui.focusTracker.on("change:isFocused", n), {
1366
+ return r.model.document.on("change:data", n), r.ui.focusTracker.on("change:isFocused", i), {
1409
1367
  /**
1410
1368
  * Removes all editor listeners registered by this sync instance.
1411
1369
  * Call this when the Blazor component is disposed.
1412
1370
  */
1413
1371
  unmount() {
1414
- r.model.document.off("change:data", a), r.ui.focusTracker.off("change:isFocused", n);
1372
+ r.model.document.off("change:data", n), r.ui.focusTracker.off("change:isFocused", i);
1415
1373
  },
1416
1374
  /**
1417
1375
  * Checks whether the given value differs from the last synced value and, if so,
@@ -1420,24 +1378,24 @@ function nt(r, t) {
1420
1378
  * Call this from the `CKEditor5ChangeDataEvent` handler to conditionally invoke
1421
1379
  * the .NET interop method.
1422
1380
  */
1423
- shouldNotify(i) {
1424
- return e.lastSyncedValue !== null && t.isEqual(e.lastSyncedValue, i) ? !1 : (e.lastSyncedValue = i, !0);
1381
+ shouldNotify(a) {
1382
+ return e.lastSyncedValue !== null && t.isEqual(e.lastSyncedValue, a) ? !1 : (e.lastSyncedValue = a, !0);
1425
1383
  },
1426
1384
  /**
1427
1385
  * Pushes a new value from Blazor into the editor.
1428
1386
  * If the editor is currently focused, the update is deferred until blur.
1429
1387
  * If the value matches the last synced state, the update is skipped entirely.
1430
1388
  */
1431
- setValue(i) {
1389
+ setValue(a) {
1432
1390
  if (r.ui.focusTracker.isFocused) {
1433
- e.pendingValue = i;
1391
+ e.pendingValue = a;
1434
1392
  return;
1435
1393
  }
1436
- e.lastSyncedValue !== null && t.isEqual(e.lastSyncedValue, i) || (e.lastSyncedValue = i, t.applyValue(i));
1394
+ e.lastSyncedValue !== null && t.isEqual(e.lastSyncedValue, a) || (e.lastSyncedValue = a, t.applyValue(a));
1437
1395
  }
1438
1396
  };
1439
1397
  }
1440
- function it() {
1398
+ function et() {
1441
1399
  return {
1442
1400
  unmount() {
1443
1401
  },
@@ -1448,95 +1406,95 @@ function it() {
1448
1406
  }
1449
1407
  };
1450
1408
  }
1451
- function ot(r, t) {
1409
+ function rt(r, t) {
1452
1410
  const e = /* @__PURE__ */ new Set();
1453
- return (a) => {
1454
- r.model.enqueueChange({ isUndoable: !1 }, (n) => {
1455
- const i = r.model.document.getRoot(t);
1456
- if (i) {
1411
+ return (n) => {
1412
+ r.model.enqueueChange({ isUndoable: !1 }, (i) => {
1413
+ const a = r.model.document.getRoot(t);
1414
+ if (a) {
1457
1415
  for (const o of e)
1458
- a && o in a || (n.removeAttribute(o, i), e.delete(o));
1459
- for (const [o, s] of Object.entries(a ?? {}))
1460
- n.setAttribute(o, s, i), e.add(o);
1416
+ n && o in n || (i.removeAttribute(o, a), e.delete(o));
1417
+ for (const [o, s] of Object.entries(n ?? {}))
1418
+ i.setAttribute(o, s, a), e.add(o);
1461
1419
  }
1462
1420
  });
1463
1421
  };
1464
1422
  }
1465
- function jt(r, t) {
1466
- const e = r.getAttribute("data-cke-editor-id") ?? _()[0], a = r.getAttribute("data-cke-root-name") ?? "main";
1467
- let n = !1, i = null, o = null, s = it(), c = null;
1468
- const u = (l) => {
1469
- if (!(l instanceof k) || l.detail.editorId !== e)
1423
+ function Rt(r, t) {
1424
+ const e = r.getAttribute("data-cke-editor-id") ?? F()[0], n = r.getAttribute("data-cke-root-name") ?? "main";
1425
+ let i = !1, a = null, o = null, s = et(), c = null;
1426
+ const u = (d) => {
1427
+ if (!(d instanceof y) || d.detail.editorId !== e)
1470
1428
  return;
1471
- const d = l.detail.roots[a];
1472
- d !== void 0 && s.shouldNotify(d) && t.invokeMethodAsync("OnChangeEditableData", o, d);
1429
+ const l = d.detail.roots[n];
1430
+ l !== void 0 && s.shouldNotify(l) && t.invokeMethodAsync("OnChangeEditableData", o, l);
1473
1431
  };
1474
- return i = m.the.mountEffect(e, (l) => (o = globalThis.DotNet.createJSObjectReference(l), s = nt(l, {
1475
- getCurrentValue: () => l.getData({ rootName: a }) ?? "",
1476
- applyValue: (d) => l.setData({ [a]: d }),
1477
- isEqual: (d, f) => d === f
1478
- }), c = ot(l, a), () => {
1432
+ return a = m.the.mountEffect(e, (d) => (o = globalThis.DotNet.createJSObjectReference(d), s = tt(d, {
1433
+ getCurrentValue: () => d.getData({ rootName: n }) ?? "",
1434
+ applyValue: (l) => d.setData({ [n]: l }),
1435
+ isEqual: (l, f) => l === f
1436
+ }), c = rt(d, n), () => {
1479
1437
  s.unmount(), o && (globalThis.DotNet?.disposeJSObjectReference(o), o = null), c = null;
1480
- })), document.body.addEventListener(k.EVENT_NAME, u), x(r), {
1438
+ })), document.body.addEventListener(y.EVENT_NAME, u), x(r), {
1481
1439
  /**
1482
1440
  * Cleans up all event listeners when the Blazor component is disposed.
1483
1441
  */
1484
1442
  unmount() {
1485
- n || (document.body.removeEventListener(k.EVENT_NAME, u), i?.(), i = null, n = !0);
1443
+ i || (document.body.removeEventListener(y.EVENT_NAME, u), a?.(), a = null, i = !0);
1486
1444
  },
1487
1445
  /**
1488
1446
  * Updates this editable root's data from Blazor.
1489
1447
  * If the editor is focused, the update is deferred until blur to avoid interrupting the user.
1490
1448
  */
1491
- setValue: async (l) => {
1492
- n || (await m.the.waitFor(e), s.setValue(l));
1449
+ setValue: async (d) => {
1450
+ i || (await m.the.waitFor(e), s.setValue(d));
1493
1451
  },
1494
1452
  /**
1495
1453
  * Updates the root attributes on the editor. This is useful when the Blazor component
1496
1454
  * re-renders with new root attributes.
1497
1455
  */
1498
- setRootAttributes: async (l) => {
1499
- n || (await m.the.waitFor(e), c?.(l));
1456
+ setRootAttributes: async (d) => {
1457
+ i || (await m.the.waitFor(e), c?.(d));
1500
1458
  }
1501
1459
  };
1502
1460
  }
1503
- function _t(r, t) {
1461
+ function xt(r, t) {
1504
1462
  const e = r.getAttribute("data-cke-editor-id");
1505
- let a = !1, n = null, i = it(), o = null, s = null;
1463
+ let n = !1, i = null, a = et(), o = null, s = null;
1506
1464
  const c = (u) => {
1507
- !(u instanceof k) || u.detail.editorId !== e || i.shouldNotify(u.detail.roots) && t.invokeMethodAsync("OnChangeEditorData", s, u.detail.roots);
1465
+ !(u instanceof y) || u.detail.editorId !== e || a.shouldNotify(u.detail.roots) && t.invokeMethodAsync("OnChangeEditorData", s, u.detail.roots);
1508
1466
  };
1509
- return n = m.the.mountEffect(e, (u) => {
1510
- s = globalThis.DotNet.createJSObjectReference(u), i = nt(u, {
1511
- getCurrentValue: () => X(u),
1512
- applyValue: (d) => u.setData(d),
1513
- isEqual: ct
1514
- }), o = ot(u, "main");
1515
- const l = (d, f, b) => {
1516
- const y = b ? "OnEditorFocus" : "OnEditorBlur";
1517
- t.invokeMethodAsync(y, s);
1467
+ return i = m.the.mountEffect(e, (u) => {
1468
+ s = globalThis.DotNet.createJSObjectReference(u), a = tt(u, {
1469
+ getCurrentValue: () => J(u),
1470
+ applyValue: (l) => u.setData(l),
1471
+ isEqual: at
1472
+ }), o = rt(u, "main");
1473
+ const d = (l, f, b) => {
1474
+ const E = b ? "OnEditorFocus" : "OnEditorBlur";
1475
+ t.invokeMethodAsync(E, s);
1518
1476
  };
1519
- return u.ui.focusTracker.on("change:isFocused", l), t.invokeMethodAsync("OnEditorReady", s), () => {
1520
- u.ui.focusTracker.off("change:isFocused", l), i.unmount(), s && (globalThis.DotNet?.disposeJSObjectReference(s), s = null), o = null;
1477
+ return u.ui.focusTracker.on("change:isFocused", d), t.invokeMethodAsync("OnEditorReady", s), () => {
1478
+ u.ui.focusTracker.off("change:isFocused", d), a.unmount(), s && (globalThis.DotNet?.disposeJSObjectReference(s), s = null), o = null;
1521
1479
  };
1522
- }), document.body.addEventListener(k.EVENT_NAME, c), Rt(), x(r), {
1480
+ }), document.body.addEventListener(y.EVENT_NAME, c), Tt(), x(r), {
1523
1481
  /**
1524
1482
  * Updates the editor data from Blazor. If the editor is focused, the update is deferred until blur to avoid interrupting the user.
1525
1483
  */
1526
1484
  setValue: async (u) => {
1527
- a || (await m.the.waitFor(e), i.setValue(u));
1485
+ n || (await m.the.waitFor(e), a.setValue(u));
1528
1486
  },
1529
1487
  /**
1530
1488
  * Updates the root attributes on the editor instance.
1531
1489
  */
1532
1490
  setRootAttributes: async (u) => {
1533
- a || (await m.the.waitFor(e), o?.(u));
1491
+ n || (await m.the.waitFor(e), o?.(u));
1534
1492
  },
1535
1493
  /**
1536
1494
  * Cleans up all event listeners when the Blazor component is disposed.
1537
1495
  */
1538
1496
  unmount() {
1539
- a || (document.body.removeEventListener(k.EVENT_NAME, c), n?.(), n = null, a = !0);
1497
+ n || (document.body.removeEventListener(y.EVENT_NAME, c), i?.(), i = null, n = !0);
1540
1498
  },
1541
1499
  /**
1542
1500
  * Installs the custom image upload adapter that delegates uploads to Blazor.
@@ -1544,26 +1502,26 @@ function _t(r, t) {
1544
1502
  * to avoid unnecessary overhead for consumers that don't use this feature.
1545
1503
  */
1546
1504
  attachImageUploadAdapter: async () => {
1547
- a || m.the.mountEffect(e, (u) => {
1548
- xt(u, t);
1505
+ n || m.the.mountEffect(e, (u) => {
1506
+ Ot(u, t);
1549
1507
  });
1550
1508
  }
1551
1509
  };
1552
1510
  }
1553
- function xt(r, t) {
1511
+ function Ot(r, t) {
1554
1512
  if (!r.plugins.has("FileRepository"))
1555
1513
  return;
1556
1514
  const e = r.plugins.get("FileRepository");
1557
- e.createUploadAdapter = (a) => {
1558
- let n = !1;
1515
+ e.createUploadAdapter = (n) => {
1516
+ let i = !1;
1559
1517
  return {
1560
1518
  async upload() {
1561
- const i = await a.file;
1562
- if (n)
1519
+ const a = await n.file;
1520
+ if (i)
1563
1521
  throw new Error("Upload aborted.");
1564
- const o = await Vt(i), s = await t.invokeMethodAsync("OnEditorImageUpload", {
1565
- fileName: i.name,
1566
- mimeType: i.type,
1522
+ const o = await Nt(a), s = await t.invokeMethodAsync("OnEditorImageUpload", {
1523
+ fileName: a.name,
1524
+ mimeType: a.type,
1567
1525
  payload: o
1568
1526
  });
1569
1527
  if (!s)
@@ -1573,21 +1531,21 @@ function xt(r, t) {
1573
1531
  return { default: s };
1574
1532
  },
1575
1533
  abort() {
1576
- n = !0;
1534
+ i = !0;
1577
1535
  }
1578
1536
  };
1579
1537
  };
1580
1538
  }
1581
- function Vt(r) {
1539
+ function Nt(r) {
1582
1540
  return new Promise((t, e) => {
1583
- const a = new FileReader();
1584
- a.onload = () => {
1585
- const n = a.result, i = n.split(",")[1] ?? n;
1586
- t(i);
1587
- }, a.onerror = () => e(a.error), a.readAsDataURL(r);
1541
+ const n = new FileReader();
1542
+ n.onload = () => {
1543
+ const i = n.result, a = i.split(",")[1] ?? i;
1544
+ t(a);
1545
+ }, n.onerror = () => e(n.error), n.readAsDataURL(r);
1588
1546
  });
1589
1547
  }
1590
- function qt(r) {
1548
+ function Dt(r) {
1591
1549
  return x(r), {
1592
1550
  unmount() {
1593
1551
  }
@@ -1595,17 +1553,17 @@ function qt(r) {
1595
1553
  }
1596
1554
  export {
1597
1555
  v as CKEditor5BlazorError,
1598
- k as CKEditor5ChangeDataEvent,
1599
- O as ContextsRegistry,
1600
- j as CustomEditorPluginsRegistry,
1601
- Ot as EditableComponentElement,
1602
- Nt as EditorComponentElement,
1556
+ y as CKEditor5ChangeDataEvent,
1557
+ C as ContextsRegistry,
1558
+ _ as CustomEditorPluginsRegistry,
1559
+ bt as EditableComponentElement,
1560
+ kt as EditorComponentElement,
1603
1561
  m as EditorsRegistry,
1604
- St as UIPartComponentElement,
1605
- Lt as createContextBlazorInterop,
1606
- jt as createEditableBlazorInterop,
1607
- _t as createEditorBlazorInterop,
1608
- qt as createUIPartBlazorInterop,
1609
- Rt as ensureEditorElementsRegistered
1562
+ At as UIPartComponentElement,
1563
+ St as createContextBlazorInterop,
1564
+ Rt as createEditableBlazorInterop,
1565
+ xt as createEditorBlazorInterop,
1566
+ Dt as createUIPartBlazorInterop,
1567
+ Tt as ensureEditorElementsRegistered
1610
1568
  };
1611
1569
  //# sourceMappingURL=index.mjs.map