ckeditor5-blazor 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
- class b extends Error {
1
+ class E extends Error {
2
2
  constructor(t) {
3
3
  super(t), this.name = "CKEditor5BlazorError";
4
4
  }
5
5
  }
6
- class _ {
6
+ class B {
7
7
  /**
8
8
  * Map of registered items.
9
9
  */
@@ -31,11 +31,11 @@ class _ {
31
31
  */
32
32
  execute(t, e, i) {
33
33
  const a = this.items.get(t), n = this.initializationErrors.get(t);
34
- return n ? (i?.(n), Promise.reject(n)) : a ? Promise.resolve(e(a)) : new Promise((o, c) => {
34
+ return n ? (i?.(n), Promise.reject(n)) : a ? Promise.resolve(e(a)) : new Promise((o, s) => {
35
35
  const u = this.getPendingCallbacks(t);
36
- u.success.push(async (s) => {
37
- o(await e(s));
38
- }), i ? u.error.push(i) : u.error.push(c);
36
+ u.success.push(async (d) => {
37
+ o(await e(d));
38
+ }), i ? u.error.push(i) : u.error.push(s);
39
39
  });
40
40
  }
41
41
  /**
@@ -111,11 +111,11 @@ class _ {
111
111
  let n = !1, o = null;
112
112
  this.execute(
113
113
  t,
114
- (c) => {
115
- n || (o !== null && clearTimeout(o), i(c));
114
+ (s) => {
115
+ n || (o !== null && clearTimeout(o), i(s));
116
116
  },
117
- (c) => {
118
- n || (o !== null && clearTimeout(o), a(c));
117
+ (s) => {
118
+ n || (o !== null && clearTimeout(o), a(s));
119
119
  }
120
120
  ), e && (o = setTimeout(() => {
121
121
  n = !0, a(new Error(`Timeout waiting for item with ID "${t}" to be registered.`));
@@ -187,7 +187,7 @@ class _ {
187
187
  this.items.size === 1 && t !== null && this.register(null, e);
188
188
  }
189
189
  }
190
- function z(r, t) {
190
+ function R(r, t) {
191
191
  let e = null;
192
192
  return (...i) => {
193
193
  e && clearTimeout(e), e = setTimeout(() => {
@@ -195,18 +195,18 @@ function z(r, t) {
195
195
  }, r);
196
196
  };
197
197
  }
198
- function et(r, t) {
198
+ function it(r, t) {
199
199
  const e = Object.entries(r).filter(([i, a]) => t(a, i));
200
200
  return Object.fromEntries(e);
201
201
  }
202
- function B(r) {
202
+ function T(r) {
203
203
  return Object.keys(r).length === 0 && r.constructor === Object;
204
204
  }
205
- function V(r, t) {
205
+ function M(r, t) {
206
206
  const e = Object.entries(r).map(([i, a]) => [i, t(a, i)]);
207
207
  return Object.fromEntries(e);
208
208
  }
209
- function rt(r, t) {
209
+ function at(r, t) {
210
210
  if (r === t)
211
211
  return !0;
212
212
  const e = Object.keys(r), i = Object.keys(t);
@@ -217,30 +217,30 @@ function rt(r, t) {
217
217
  return !1;
218
218
  return !0;
219
219
  }
220
- function it() {
220
+ function nt() {
221
221
  return Math.random().toString(36).substring(2);
222
222
  }
223
- function at(r, {
223
+ function ot(r, {
224
224
  timeOutAfter: t = 500,
225
225
  retryAfter: e = 100
226
226
  } = {}) {
227
227
  return new Promise((i, a) => {
228
228
  const n = Date.now();
229
229
  let o = null;
230
- const c = setTimeout(() => {
230
+ const s = setTimeout(() => {
231
231
  a(o ?? new Error("Timeout"));
232
232
  }, t), u = async () => {
233
233
  try {
234
- const s = await r();
235
- clearTimeout(c), i(s);
236
- } catch (s) {
237
- o = s, Date.now() - n > t ? a(s) : setTimeout(u, e);
234
+ const d = await r();
235
+ clearTimeout(s), i(d);
236
+ } catch (d) {
237
+ o = d, Date.now() - n > t ? a(d) : setTimeout(u, e);
238
238
  }
239
239
  };
240
240
  u();
241
241
  });
242
242
  }
243
- function T() {
243
+ function D() {
244
244
  return new Promise((r) => {
245
245
  switch (document.readyState) {
246
246
  case "loading":
@@ -255,7 +255,7 @@ function T() {
255
255
  }
256
256
  });
257
257
  }
258
- function M(r) {
258
+ function $(r) {
259
259
  if (r.hasAttribute("data-cke-interactive"))
260
260
  return { promise: Promise.resolve(), disconnect: () => {
261
261
  } };
@@ -273,14 +273,14 @@ function M(r) {
273
273
  disconnect: () => t?.disconnect()
274
274
  };
275
275
  }
276
- function O(r) {
276
+ function x(r) {
277
277
  r.setAttribute("data-cke-interactive", "true");
278
278
  }
279
- const x = /* @__PURE__ */ Symbol.for("context-editor-watchdog");
280
- async function nt({ element: r, context: t, creator: e, config: i }) {
281
- const a = it();
279
+ const z = /* @__PURE__ */ Symbol.for("context-editor-watchdog");
280
+ async function st({ element: r, context: t, creator: e, config: i }) {
281
+ const a = nt();
282
282
  await t.add({
283
- creator: (u, s) => e.create(u, s),
283
+ creator: (u, d) => e.create(u, d),
284
284
  id: a,
285
285
  sourceElementOrData: r,
286
286
  type: "editor",
@@ -291,23 +291,23 @@ async function nt({ element: r, context: t, creator: e, config: i }) {
291
291
  editorContextId: a,
292
292
  context: t
293
293
  };
294
- n[x] = o;
295
- const c = t.destroy.bind(t);
296
- return t.destroy = async () => (o.state = "unavailable", c()), {
294
+ n[z] = o;
295
+ const s = t.destroy.bind(t);
296
+ return t.destroy = async () => (o.state = "unavailable", s()), {
297
297
  ...o,
298
298
  editor: n
299
299
  };
300
300
  }
301
- function ot(r) {
302
- return x in r ? r[x] : null;
301
+ function ct(r) {
302
+ return z in r ? r[z] : null;
303
303
  }
304
- function H(r) {
304
+ function J(r) {
305
305
  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({}));
306
306
  }
307
- function A(r) {
307
+ function P(r) {
308
308
  return ["inline", "classic", "balloon", "decoupled"].includes(r);
309
309
  }
310
- async function q(r) {
310
+ async function U(r) {
311
311
  const t = await import("ckeditor5"), i = {
312
312
  inline: t.InlineEditor,
313
313
  balloon: t.BalloonEditor,
@@ -316,11 +316,11 @@ async function q(r) {
316
316
  multiroot: t.MultiRootEditor
317
317
  }[r];
318
318
  if (!i)
319
- throw new b(`Unsupported editor type: ${r}`);
319
+ throw new E(`Unsupported editor type: ${r}`);
320
320
  return i;
321
321
  }
322
- class R {
323
- static the = new R();
322
+ class W {
323
+ static the = new W();
324
324
  /**
325
325
  * Map of registered custom plugins.
326
326
  */
@@ -339,7 +339,7 @@ class R {
339
339
  */
340
340
  register(t, e) {
341
341
  if (this.plugins.has(t))
342
- throw new b(`Plugin with name "${t}" is already registered.`);
342
+ throw new E(`Plugin with name "${t}" is already registered.`);
343
343
  return this.plugins.set(t, e), this.unregister.bind(this, t);
344
344
  }
345
345
  /**
@@ -350,7 +350,7 @@ class R {
350
350
  */
351
351
  unregister(t) {
352
352
  if (!this.plugins.has(t))
353
- throw new b(`Plugin with name "${t}" is not registered.`);
353
+ throw new E(`Plugin with name "${t}" is not registered.`);
354
354
  this.plugins.delete(t);
355
355
  }
356
356
  /**
@@ -379,20 +379,20 @@ class R {
379
379
  return this.plugins.has(t);
380
380
  }
381
381
  }
382
- async function J(r) {
382
+ async function H(r) {
383
383
  const t = await import("ckeditor5");
384
384
  let e = null;
385
385
  const i = r.map(async (a) => {
386
- if (st(a)) {
387
- const { name: u, path: s } = a.$import, d = await import(
386
+ if (ut(a)) {
387
+ const { name: u, path: d } = a.$import, l = await import(
388
388
  /* @vite-ignore */
389
- s
390
- ), g = (Object.prototype.hasOwnProperty.call(d, u) ? d[u] : void 0) ?? (Object.prototype.hasOwnProperty.call(d, "default") ? d.default : void 0);
391
- if (!g)
392
- throw new b(`Plugin "${u}" not found in module "${s}".`);
393
- return g;
389
+ d
390
+ ), w = (Object.prototype.hasOwnProperty.call(l, u) ? l[u] : void 0) ?? (Object.prototype.hasOwnProperty.call(l, "default") ? l.default : void 0);
391
+ if (!w)
392
+ throw new E(`Plugin "${u}" not found in module "${d}".`);
393
+ return w;
394
394
  }
395
- const n = await R.the.get(a);
395
+ const n = await W.the.get(a);
396
396
  if (n)
397
397
  return n;
398
398
  const { [a]: o } = t;
@@ -402,40 +402,40 @@ async function J(r) {
402
402
  try {
403
403
  e = await import("ckeditor5-premium-features");
404
404
  } catch (u) {
405
- throw console.error(`Failed to load premium package: ${u}`), new b(`Plugin "${a}" not found in base package and failed to load premium package.`);
405
+ throw console.error(`Failed to load premium package: ${u}`), new E(`Plugin "${a}" not found in base package and failed to load premium package.`);
406
406
  }
407
- const { [a]: c } = e || {};
408
- if (c)
409
- return c;
410
- throw new b(`Plugin "${a}" not found in base or premium packages.`);
407
+ const { [a]: s } = e || {};
408
+ if (s)
409
+ return s;
410
+ throw new E(`Plugin "${a}" not found in base or premium packages.`);
411
411
  });
412
412
  return {
413
413
  loadedPlugins: await Promise.all(i),
414
414
  hasPremium: !!e
415
415
  };
416
416
  }
417
- function st(r) {
417
+ function ut(r) {
418
418
  return typeof r == "object" && r !== null && "$import" in r;
419
419
  }
420
420
  async function K(r, t) {
421
421
  const e = [r.ui, r.content];
422
422
  return await Promise.all(
423
423
  [
424
- U("ckeditor5", e),
424
+ j("ckeditor5", e),
425
425
  /* v8 ignore next -- @preserve */
426
- t && U("ckeditor5-premium-features", e)
426
+ t && j("ckeditor5-premium-features", e)
427
427
  ].filter((a) => !!a)
428
428
  ).then((a) => a.flat());
429
429
  }
430
- async function U(r, t) {
430
+ async function j(r, t) {
431
431
  return await Promise.all(
432
432
  t.filter((e) => e !== "en").map(async (e) => {
433
- const i = await ct(r, e);
433
+ const i = await lt(r, e);
434
434
  return i?.default ?? i;
435
435
  }).filter(Boolean)
436
436
  );
437
437
  }
438
- async function ct(r, t) {
438
+ async function lt(r, t) {
439
439
  try {
440
440
  if (r === "ckeditor5")
441
441
  switch (t) {
@@ -736,27 +736,27 @@ async function ct(r, t) {
736
736
  }
737
737
  }
738
738
  function G(r) {
739
- return V(r, (t) => ({
739
+ return M(r, (t) => ({
740
740
  dictionary: t
741
741
  }));
742
742
  }
743
- function $() {
743
+ function F() {
744
744
  return Array.from(document.querySelectorAll("cke5-editor")).map((r) => r.getAttribute("data-cke-editor-id")).filter((r) => r !== null);
745
745
  }
746
746
  function Y(r) {
747
747
  const t = X(r);
748
- return V(t, ({ element: e }) => e);
748
+ return M(t, ({ element: e }) => e);
749
749
  }
750
- function j(r) {
751
- const t = X(r), e = V(t, ({ content: i }) => i);
752
- return et(e, (i) => typeof i == "string");
750
+ function _(r) {
751
+ const t = X(r), e = M(t, ({ content: i }) => i);
752
+ return it(e, (i) => typeof i == "string");
753
753
  }
754
754
  function X(r) {
755
- const t = Array.from(document.querySelectorAll(`cke5-editable[data-cke-editor-id="${r}"]`)).reduce((o, c) => {
756
- const u = c.getAttribute("data-cke-root-name"), s = c.getAttribute("data-cke-content");
755
+ const t = Array.from(document.querySelectorAll(`cke5-editable[data-cke-editor-id="${r}"]`)).reduce((o, s) => {
756
+ const u = s.getAttribute("data-cke-root-name"), d = s.getAttribute("data-cke-content");
757
757
  return o[u] = {
758
- element: c.querySelector("[data-cke-editable-content]"),
759
- content: s
758
+ element: s.querySelector("[data-cke-editable-content]"),
759
+ content: d
760
760
  }, o;
761
761
  }, /* @__PURE__ */ Object.create({})), e = document.querySelector(`cke5-editor[data-cke-editor-id="${r}"]`);
762
762
  if (!e)
@@ -776,11 +776,11 @@ function X(r) {
776
776
  }
777
777
  } : t;
778
778
  }
779
- function P(r) {
779
+ function O(r) {
780
780
  if (!r || typeof r != "object")
781
781
  return r;
782
782
  if (Array.isArray(r))
783
- return r.map((i) => P(i));
783
+ return r.map((i) => O(i));
784
784
  const t = r;
785
785
  if (t.$element && typeof t.$element == "string") {
786
786
  const i = document.querySelector(t.$element);
@@ -788,43 +788,43 @@ function P(r) {
788
788
  }
789
789
  const e = /* @__PURE__ */ Object.create(null);
790
790
  for (const [i, a] of Object.entries(r))
791
- e[i] = P(a);
791
+ e[i] = O(a);
792
792
  return e;
793
793
  }
794
- function I(r, t, e) {
794
+ function S(r, t, e) {
795
795
  if (!e || typeof e != "object")
796
796
  return e;
797
797
  if (Array.isArray(e))
798
- return e.map((n) => I(r, t, n));
798
+ return e.map((n) => S(r, t, n));
799
799
  const i = e;
800
800
  if (i.$translation && typeof i.$translation == "string") {
801
- const n = i.$translation, o = ut(r, n, t);
801
+ const n = i.$translation, o = dt(r, n, t);
802
802
  return o === void 0 && console.warn(`Translation not found for key: ${n}`), o !== void 0 ? o : null;
803
803
  }
804
804
  const a = /* @__PURE__ */ Object.create(null);
805
805
  for (const [n, o] of Object.entries(e))
806
- a[n] = I(r, t, o);
806
+ a[n] = S(r, t, o);
807
807
  return a;
808
808
  }
809
- function ut(r, t, e) {
809
+ function dt(r, t, e) {
810
810
  for (const i of r) {
811
811
  const a = i[e];
812
812
  if (a?.dictionary && t in a.dictionary)
813
813
  return a.dictionary[t];
814
814
  }
815
815
  }
816
- function lt(r, t) {
816
+ function mt(r, t) {
817
817
  const { editing: e } = r;
818
818
  e.view.change((i) => {
819
819
  i.setStyle("height", `${t}px`, e.view.document.getRoot());
820
820
  });
821
821
  }
822
- const N = /* @__PURE__ */ Symbol.for("elixir-editor-watchdog");
823
- async function dt(r) {
822
+ const V = /* @__PURE__ */ Symbol.for("elixir-editor-watchdog");
823
+ async function ht(r) {
824
824
  const { EditorWatchdog: t } = await import("ckeditor5"), e = new t(r);
825
825
  return e.setCreator(async (...i) => {
826
826
  const a = await r.create(...i);
827
- return a[N] = e, a;
827
+ return a[V] = e, a;
828
828
  }), {
829
829
  watchdog: e,
830
830
  Constructor: {
@@ -832,13 +832,13 @@ async function dt(r) {
832
832
  }
833
833
  };
834
834
  }
835
- function mt(r) {
836
- return N in r ? r[N] : null;
835
+ function pt(r) {
836
+ return V in r ? r[V] : null;
837
837
  }
838
- class v extends _ {
838
+ class v extends B {
839
839
  static the = new v();
840
840
  }
841
- class ht extends HTMLElement {
841
+ class wt extends HTMLElement {
842
842
  /**
843
843
  * The promise that resolves to the context instance.
844
844
  */
@@ -851,35 +851,35 @@ class ht extends HTMLElement {
851
851
  * Mounts the context component.
852
852
  */
853
853
  async connectedCallback() {
854
- await T(), this.interactiveWait = M(this), await this.interactiveWait.promise, await this.initializeContext();
854
+ await D(), this.interactiveWait = $(this), await this.interactiveWait.promise, await this.initializeContext();
855
855
  }
856
856
  /**
857
857
  * Initializes the context component.
858
858
  */
859
859
  async initializeContext() {
860
- const t = this.getAttribute("data-cke-context-id"), e = JSON.parse(this.getAttribute("data-cke-language")), i = JSON.parse(this.getAttribute("data-cke-context")), { customTranslations: a, watchdogConfig: n, config: { plugins: o, ...c } } = i, { loadedPlugins: u, hasPremium: s } = await J(o ?? []), d = [
861
- ...await K(e, s),
860
+ const t = this.getAttribute("data-cke-context-id"), e = JSON.parse(this.getAttribute("data-cke-language")), i = JSON.parse(this.getAttribute("data-cke-context")), { customTranslations: a, watchdogConfig: n, config: { plugins: o, ...s } } = i, { loadedPlugins: u, hasPremium: d } = await H(o ?? []), l = [
861
+ ...await K(e, d),
862
862
  G(a || {})
863
- ].filter((f) => !B(f));
863
+ ].filter((y) => !T(y));
864
864
  this.contextPromise = (async () => {
865
- const { ContextWatchdog: f, Context: w } = await import("ckeditor5"), p = new f(w, {
865
+ const { ContextWatchdog: y, Context: b } = await import("ckeditor5"), f = new y(b, {
866
866
  crashNumberLimit: 10,
867
867
  ...n
868
868
  });
869
- let E = P(c);
870
- return E = I([...d].reverse(), e.ui, E), await p.create({
871
- ...E,
869
+ let p = O(s);
870
+ return p = S([...l].reverse(), e.ui, p), await f.create({
871
+ ...p,
872
872
  language: e,
873
873
  plugins: u,
874
- ...d.length && {
875
- translations: d
874
+ ...l.length && {
875
+ translations: l
876
876
  }
877
- }), p.on("itemError", (...D) => {
878
- console.error("Context item error:", ...D);
879
- }), p;
877
+ }), f.on("itemError", (...A) => {
878
+ console.error("Context item error:", ...A);
879
+ }), f;
880
880
  })();
881
- const g = await this.contextPromise;
882
- this.isConnected && v.the.register(t, g);
881
+ const w = await this.contextPromise;
882
+ this.isConnected && v.the.register(t, w);
883
883
  }
884
884
  /**
885
885
  * Destroys the context component. Unmounts root from the editor.
@@ -895,10 +895,10 @@ class ht extends HTMLElement {
895
895
  }
896
896
  }
897
897
  }
898
- class h extends _ {
898
+ class h extends B {
899
899
  static the = new h();
900
900
  }
901
- class pt extends HTMLElement {
901
+ class ft extends HTMLElement {
902
902
  /**
903
903
  * The promise that resolves when the editable is mounted.
904
904
  */
@@ -921,48 +921,51 @@ class pt extends HTMLElement {
921
921
  * Mounts the editable component.
922
922
  */
923
923
  async connectedCallback() {
924
- await T(), this.interactiveWait = M(this), await this.interactiveWait.promise, await this.initializeEditable();
924
+ await D(), this.interactiveWait = $(this), await this.interactiveWait.promise, await this.initializeEditable();
925
925
  }
926
926
  /**
927
927
  * Initializes the editable instance.
928
928
  */
929
929
  async initializeEditable() {
930
- this.hasAttribute("data-cke-editor-id") || this.setAttribute("data-cke-editor-id", $()[0]);
931
- const t = this.getAttribute("data-cke-editor-id"), e = this.getAttribute("data-cke-root-name"), i = this.getAttribute("data-cke-content"), a = Number.parseInt(this.getAttribute("data-cke-save-debounce-ms"), 10);
930
+ this.hasAttribute("data-cke-editor-id") || this.setAttribute("data-cke-editor-id", F()[0]);
931
+ const t = this.getAttribute("data-cke-editor-id"), e = this.getAttribute("data-cke-root-name"), i = JSON.parse(this.getAttribute("data-cke-root-attributes") || "{}"), a = this.getAttribute("data-cke-content"), n = Number.parseInt(this.getAttribute("data-cke-save-debounce-ms"), 10);
932
932
  if (!t || !e)
933
- throw new b("Editor ID or Root Name is missing.");
934
- this.style.display = "block", this.editorPromise = h.the.execute(t, async (n) => {
933
+ throw new E("Editor ID or Root Name is missing.");
934
+ this.style.display = "block", this.editorPromise = h.the.execute(t, async (o) => {
935
935
  if (!this.isConnected)
936
936
  return null;
937
- const { ui: o, editing: c, model: u } = n, s = this.querySelector("input");
938
- if (u.document.getRoot(e)?.isAttached()) {
939
- if (i !== null) {
940
- const p = n.getData({ rootName: e });
941
- p && p !== i && n.setData({
942
- [e]: i
937
+ const { ui: s, editing: u, model: d } = o, c = this.querySelector("input"), l = d.document.getRoot(e);
938
+ if (l?.isAttached()) {
939
+ if (a !== null) {
940
+ const p = o.getData({ rootName: e });
941
+ p && p !== a && o.setData({
942
+ [e]: a
943
943
  });
944
944
  }
945
- return n;
945
+ return T(i) || o.model.change((p) => {
946
+ p.setAttributes(i, l);
947
+ }), o;
946
948
  }
947
- n.addRoot(e, {
949
+ o.addRoot(e, {
948
950
  isUndoable: !1,
949
- ...i !== null && {
950
- data: i
951
+ attributes: { ...i },
952
+ ...a !== null && {
953
+ data: a
951
954
  }
952
955
  });
953
- const d = this.querySelector("[data-cke-editable-content]"), g = o.view.createEditable(e, d);
954
- o.addEditable(g), c.view.forceRender();
955
- const f = () => {
956
- if (!u.document.getRoot(e)?.isAttached())
956
+ const w = this.querySelector("[data-cke-editable-content]"), y = s.view.createEditable(e, w);
957
+ s.addEditable(y), u.view.forceRender();
958
+ const b = () => {
959
+ if (!d.document.getRoot(e)?.isAttached())
957
960
  return;
958
- const p = n.getData({ rootName: e });
959
- s && (s.value = p, s.dispatchEvent(new Event("input"))), this.dispatchEvent(new CustomEvent("change", {
961
+ const p = o.getData({ rootName: e });
962
+ c && (c.value = p, c.dispatchEvent(new Event("input"))), this.dispatchEvent(new CustomEvent("change", {
960
963
  detail: {
961
964
  value: p
962
965
  }
963
966
  }));
964
- }, w = z(a, f);
965
- return n.model.document.on("change:data", w), this.onBeforeDestroy(() => n.model.document.off("change:data", w)), f(), n;
967
+ }, f = R(n, b);
968
+ return o.model.document.on("change:data", f), this.onBeforeDestroy(() => o.model.document.off("change:data", f)), b(), o;
966
969
  });
967
970
  }
968
971
  /**
@@ -989,7 +992,7 @@ class pt extends HTMLElement {
989
992
  }
990
993
  }
991
994
  }
992
- async function wt({
995
+ async function gt({
993
996
  saveDebounceMs: r,
994
997
  editorId: t,
995
998
  targetElement: e
@@ -1006,7 +1009,7 @@ async function wt({
1006
1009
  * Initializes the plugin.
1007
1010
  */
1008
1011
  afterInit() {
1009
- const { editor: n } = this, o = z(r, this.dispatch);
1012
+ const { editor: n } = this, o = R(r, this.dispatch);
1010
1013
  n.model.document.on("change:data", o), n.once("ready", this.dispatch);
1011
1014
  }
1012
1015
  /**
@@ -1015,25 +1018,25 @@ async function wt({
1015
1018
  dispatch = () => {
1016
1019
  const { editor: n } = this;
1017
1020
  e.dispatchEvent(
1018
- new y({
1021
+ new g({
1019
1022
  editorId: t,
1020
1023
  editor: n,
1021
- roots: H(n)
1024
+ roots: J(n)
1022
1025
  })
1023
1026
  );
1024
1027
  };
1025
1028
  };
1026
1029
  }
1027
- class y extends CustomEvent {
1030
+ class g extends CustomEvent {
1028
1031
  static EVENT_NAME = "ckeditor5:change:data";
1029
1032
  constructor(t) {
1030
- super(y.EVENT_NAME, {
1033
+ super(g.EVENT_NAME, {
1031
1034
  detail: t,
1032
1035
  bubbles: !0
1033
1036
  });
1034
1037
  }
1035
1038
  }
1036
- async function ft(r) {
1039
+ async function yt(r) {
1037
1040
  const { Plugin: t } = await import("ckeditor5");
1038
1041
  return class extends t {
1039
1042
  /**
@@ -1055,7 +1058,7 @@ async function ft(r) {
1055
1058
  */
1056
1059
  afterInit() {
1057
1060
  const { editor: i } = this, n = i.sourceElement.id.replace(/_editor$/, "");
1058
- this.input = document.getElementById(`${n}_input`), this.input && (i.model.document.on("change:data", z(r, () => this.sync())), i.once("ready", this.sync), this.form = this.input.closest("form"), this.form?.addEventListener("submit", this.sync));
1061
+ this.input = document.getElementById(`${n}_input`), this.input && (i.model.document.on("change:data", R(r, () => this.sync())), i.once("ready", this.sync), this.form = this.input.closest("form"), this.form?.addEventListener("submit", this.sync));
1059
1062
  }
1060
1063
  /**
1061
1064
  * Synchronizes the editor's content with the input field.
@@ -1074,7 +1077,7 @@ async function ft(r) {
1074
1077
  }
1075
1078
  };
1076
1079
  }
1077
- class gt extends HTMLElement {
1080
+ class bt extends HTMLElement {
1078
1081
  /**
1079
1082
  * The promise that resolves to the editor instance.
1080
1083
  */
@@ -1087,7 +1090,7 @@ class gt extends HTMLElement {
1087
1090
  * Mounts the editor component.
1088
1091
  */
1089
1092
  async connectedCallback() {
1090
- await T(), this.interactiveWait = M(this), q("classic"), await this.interactiveWait.promise, await this.initializeEditor();
1093
+ await D(), this.interactiveWait = $(this), U("classic"), await this.interactiveWait.promise, await this.initializeEditor();
1091
1094
  }
1092
1095
  /**
1093
1096
  * Initializes the editor instance.
@@ -1115,7 +1118,7 @@ class gt extends HTMLElement {
1115
1118
  const t = await this.editorPromise;
1116
1119
  if (!t)
1117
1120
  return;
1118
- const e = ot(t), i = mt(t);
1121
+ const e = ct(t), i = pt(t);
1119
1122
  e ? e.state !== "unavailable" && await e.context.remove(e.editorContextId) : i ? await i.destroy() : await t.destroy();
1120
1123
  } finally {
1121
1124
  this.editorPromise = null;
@@ -1125,77 +1128,79 @@ class gt extends HTMLElement {
1125
1128
  * Creates the CKEditor instance.
1126
1129
  */
1127
1130
  async createEditor() {
1128
- const t = this.getAttribute("data-cke-editor-id"), e = JSON.parse(this.getAttribute("data-cke-preset")), i = this.getAttribute("data-cke-context-id"), a = this.getAttribute("data-cke-editable-height") ? Number.parseInt(this.getAttribute("data-cke-editable-height"), 10) : null, n = Number.parseInt(this.getAttribute("data-cke-save-debounce-ms"), 10), o = JSON.parse(this.getAttribute("data-cke-language")), c = this.hasAttribute("data-cke-watchdog"), u = JSON.parse(this.getAttribute("data-cke-content")), {
1129
- customTranslations: s,
1131
+ const t = this.getAttribute("data-cke-editor-id"), e = JSON.parse(this.getAttribute("data-cke-preset")), i = this.getAttribute("data-cke-context-id"), a = JSON.parse(this.getAttribute("data-cke-root-attributes") || "{}"), n = this.getAttribute("data-cke-editable-height") ? Number.parseInt(this.getAttribute("data-cke-editable-height"), 10) : null, o = Number.parseInt(this.getAttribute("data-cke-save-debounce-ms"), 10), s = JSON.parse(this.getAttribute("data-cke-language")), u = this.hasAttribute("data-cke-watchdog"), d = JSON.parse(this.getAttribute("data-cke-content")), {
1132
+ customTranslations: c,
1130
1133
  editorType: l,
1131
- licenseKey: d,
1132
- config: { plugins: g, ...f }
1134
+ licenseKey: w,
1135
+ config: { plugins: y, ...b }
1133
1136
  } = e;
1134
- let w = await q(l);
1137
+ let f = await U(l);
1135
1138
  const p = await (i ? v.the.waitFor(i) : null);
1136
- if (c && !p) {
1137
- const m = await dt(w);
1138
- ({ Constructor: w } = m), m.watchdog.on("restart", () => {
1139
+ if (u && !p) {
1140
+ const m = await ht(f);
1141
+ ({ Constructor: f } = m), m.watchdog.on("restart", () => {
1139
1142
  const k = m.watchdog.editor;
1140
1143
  this.editorPromise = Promise.resolve(k), h.the.register(t, k);
1141
1144
  });
1142
1145
  }
1143
- const { loadedPlugins: E, hasPremium: D } = await J(g);
1144
- E.push(
1145
- await wt({
1146
- saveDebounceMs: n,
1146
+ const { loadedPlugins: A, hasPremium: rt } = await H(y);
1147
+ A.push(
1148
+ await gt({
1149
+ saveDebounceMs: o,
1147
1150
  editorId: t,
1148
1151
  targetElement: this
1149
1152
  })
1150
- ), A(l) && E.push(
1151
- await ft(n)
1153
+ ), P(l) && A.push(
1154
+ await yt(o)
1152
1155
  );
1153
- const S = [
1154
- ...await K(o, D),
1155
- G(s || {})
1156
- ].filter((m) => !B(m));
1156
+ const N = [
1157
+ ...await K(s, rt),
1158
+ G(c || {})
1159
+ ].filter((m) => !T(m));
1157
1160
  let C = {
1158
- ...u,
1159
- ...j(t)
1161
+ ...d,
1162
+ ..._(t)
1160
1163
  };
1161
- A(l) && (C = C.main || "");
1162
- const W = await (async () => {
1164
+ P(l) && (C = C.main || "");
1165
+ const I = await (async () => {
1163
1166
  let m = Y(t);
1164
1167
  if (!m.main) {
1165
- const L = A(l) ? ["main"] : Object.keys(C);
1166
- Q(m, L) || (m = await yt(t, L), C = {
1167
- ...u,
1168
- ...j(t)
1168
+ const L = P(l) ? ["main"] : Object.keys(C);
1169
+ Q(m, L) || (m = await Et(t, L), C = {
1170
+ ...d,
1171
+ ..._(t)
1169
1172
  });
1170
1173
  }
1171
- A(l) && "main" in m && (m = m.main);
1172
- let k = P(f);
1173
- k = I([...S].reverse(), o.ui, k);
1174
- const F = {
1174
+ P(l) && "main" in m && (m = m.main);
1175
+ let k = O(b);
1176
+ k = S([...N].reverse(), s.ui, k);
1177
+ const q = {
1175
1178
  ...k,
1176
1179
  initialData: C,
1177
- licenseKey: d,
1178
- plugins: E,
1179
- language: o,
1180
- ...S.length && {
1181
- translations: S
1180
+ licenseKey: w,
1181
+ plugins: A,
1182
+ language: s,
1183
+ ...N.length && {
1184
+ translations: N
1182
1185
  }
1183
1186
  };
1184
- return !p || !(m instanceof HTMLElement) ? w.create(m, F) : (await nt({
1187
+ return !p || !(m instanceof HTMLElement) ? f.create(m, q) : (await st({
1185
1188
  context: p,
1186
1189
  element: m,
1187
- creator: w,
1188
- config: F
1190
+ creator: f,
1191
+ config: q
1189
1192
  })).editor;
1190
1193
  })();
1191
- return A(l) && a && lt(W, a), W;
1194
+ return T(a) || I.model.change((m) => {
1195
+ m.setAttributes(a, I.model.document.getRoot());
1196
+ }), P(l) && n && mt(I, n), I;
1192
1197
  }
1193
1198
  }
1194
1199
  function Q(r, t) {
1195
1200
  return t.every((e) => r[e]);
1196
1201
  }
1197
- async function yt(r, t) {
1198
- return at(
1202
+ async function Et(r, t) {
1203
+ return ot(
1199
1204
  () => {
1200
1205
  const e = Y(r);
1201
1206
  if (!Q(e, t))
@@ -1210,7 +1215,7 @@ Missing roots: ${t.filter((i) => !e[i]).join(", ")}.`
1210
1215
  { timeOutAfter: 2e3, retryAfter: 100 }
1211
1216
  );
1212
1217
  }
1213
- class bt extends HTMLElement {
1218
+ class kt extends HTMLElement {
1214
1219
  /**
1215
1220
  * The promise that resolves when the UI part is mounted.
1216
1221
  */
@@ -1219,14 +1224,14 @@ class bt extends HTMLElement {
1219
1224
  * Mounts the UI part component.
1220
1225
  */
1221
1226
  async connectedCallback() {
1222
- await T();
1223
- const t = this.getAttribute("data-cke-editor-id") || $()[0], e = this.getAttribute("data-cke-name");
1227
+ await D();
1228
+ const t = this.getAttribute("data-cke-editor-id") || F()[0], e = this.getAttribute("data-cke-name");
1224
1229
  !t || !e || (this.style.display = "block", this.mountedPromise = h.the.execute(t, (i) => {
1225
1230
  if (!this.isConnected)
1226
1231
  return;
1227
- const { ui: a } = i, n = Et(e), o = a.view[n];
1232
+ const { ui: a } = i, n = vt(e), o = a.view[n];
1228
1233
  if (!o)
1229
- throw new b(`Unknown UI part name: "${e}". Supported names are "toolbar" and "menubar".`);
1234
+ throw new E(`Unknown UI part name: "${e}". Supported names are "toolbar" and "menubar".`);
1230
1235
  this.appendChild(o.element);
1231
1236
  }));
1232
1237
  }
@@ -1237,7 +1242,7 @@ class bt extends HTMLElement {
1237
1242
  this.style.display = "none", await this.mountedPromise, this.mountedPromise = null, this.innerHTML = "";
1238
1243
  }
1239
1244
  }
1240
- function Et(r) {
1245
+ function vt(r) {
1241
1246
  switch (r) {
1242
1247
  case "toolbar":
1243
1248
  return "toolbar";
@@ -1248,18 +1253,18 @@ function Et(r) {
1248
1253
  return null;
1249
1254
  }
1250
1255
  }
1251
- const kt = {
1252
- "cke5-editor": gt,
1253
- "cke5-context": ht,
1254
- "cke5-ui-part": bt,
1255
- "cke5-editable": pt
1256
+ const At = {
1257
+ "cke5-editor": bt,
1258
+ "cke5-context": wt,
1259
+ "cke5-ui-part": kt,
1260
+ "cke5-editable": ft
1256
1261
  };
1257
- function vt() {
1258
- for (const [r, t] of Object.entries(kt))
1262
+ function Ct() {
1263
+ for (const [r, t] of Object.entries(At))
1259
1264
  window.customElements.get(r) || window.customElements.define(r, t);
1260
1265
  }
1261
- function Dt(r) {
1262
- return O(r), {
1266
+ function xt(r) {
1267
+ return x(r), {
1263
1268
  unmount() {
1264
1269
  }
1265
1270
  };
@@ -1272,8 +1277,8 @@ function Z(r, t) {
1272
1277
  lastSyncedValue: null
1273
1278
  }, i = () => {
1274
1279
  e.pendingValue = null;
1275
- }, a = (n, o, c) => {
1276
- if (c || e.pendingValue === null)
1280
+ }, a = (n, o, s) => {
1281
+ if (s || e.pendingValue === null)
1277
1282
  return;
1278
1283
  const u = t.getCurrentValue();
1279
1284
  t.isEqual(u, e.pendingValue) || t.applyValue(e.pendingValue), e.pendingValue = null;
@@ -1321,70 +1326,97 @@ function tt() {
1321
1326
  }
1322
1327
  };
1323
1328
  }
1324
- function St(r, t) {
1325
- const e = r.getAttribute("data-cke-editor-id") ?? $()[0], i = r.getAttribute("data-cke-root-name") ?? "main";
1326
- let a = !1, n = tt(), o = null;
1327
- const c = (s) => {
1328
- if (!(s instanceof y) || s.detail.editorId !== e)
1329
+ function et(r, t) {
1330
+ const e = /* @__PURE__ */ new Set();
1331
+ return (i) => {
1332
+ r.model.enqueueChange({ isUndoable: !1 }, (a) => {
1333
+ const n = r.model.document.getRoot(t);
1334
+ if (n) {
1335
+ for (const o of e)
1336
+ i && o in i || (a.removeAttribute(o, n), e.delete(o));
1337
+ for (const [o, s] of Object.entries(i ?? {}))
1338
+ a.setAttribute(o, s, n), e.add(o);
1339
+ }
1340
+ });
1341
+ };
1342
+ }
1343
+ function Nt(r, t) {
1344
+ const e = r.getAttribute("data-cke-editor-id") ?? F()[0], i = r.getAttribute("data-cke-root-name") ?? "main";
1345
+ let a = !1, n = null, o = tt(), s = null;
1346
+ const u = (c) => {
1347
+ if (!(c instanceof g) || c.detail.editorId !== e)
1329
1348
  return;
1330
- const l = s.detail.roots[i];
1331
- l !== void 0 && n.shouldNotify(l) && t.invokeMethodAsync("OnChangeEditableData", o, l);
1349
+ const l = c.detail.roots[i];
1350
+ l !== void 0 && o.shouldNotify(l) && t.invokeMethodAsync("OnChangeEditableData", n, l);
1332
1351
  };
1333
1352
  return (async () => {
1334
- const s = await h.the.waitFor(e);
1335
- o = DotNet.createJSObjectReference(s), n = Z(s, {
1336
- getCurrentValue: () => s.getData({ rootName: i }) ?? "",
1337
- applyValue: (l) => s.setData({ [i]: l }),
1338
- isEqual: (l, d) => l === d
1339
- });
1340
- })(), document.body.addEventListener(y.EVENT_NAME, c), O(r), {
1353
+ const c = await h.the.waitFor(e);
1354
+ n = DotNet.createJSObjectReference(c), o = Z(c, {
1355
+ getCurrentValue: () => c.getData({ rootName: i }) ?? "",
1356
+ applyValue: (l) => c.setData({ [i]: l }),
1357
+ isEqual: (l, w) => l === w
1358
+ }), s = et(c, i);
1359
+ })(), document.body.addEventListener(g.EVENT_NAME, u), x(r), {
1341
1360
  /**
1342
1361
  * Cleans up all event listeners when the Blazor component is disposed.
1343
1362
  */
1344
1363
  unmount() {
1345
- a || (document.body.removeEventListener(y.EVENT_NAME, c), n.unmount(), o && (DotNet.disposeJSObjectReference(o), o = null), a = !0);
1364
+ a || (document.body.removeEventListener(g.EVENT_NAME, u), o.unmount(), n && (DotNet.disposeJSObjectReference(n), n = null), s = null, a = !0);
1346
1365
  },
1347
1366
  /**
1348
1367
  * Updates this editable root's data from Blazor.
1349
1368
  * If the editor is focused, the update is deferred until blur to avoid interrupting the user.
1350
1369
  */
1351
- setValue: async (s) => {
1352
- a || (await h.the.waitFor(e), n.setValue(s));
1370
+ setValue: async (c) => {
1371
+ a || (await h.the.waitFor(e), o.setValue(c));
1372
+ },
1373
+ /**
1374
+ * Updates the root attributes on the editor. This is useful when the Blazor component
1375
+ * re-renders with new root attributes.
1376
+ */
1377
+ setRootAttributes: async (c) => {
1378
+ a || (await h.the.waitFor(e), s?.(c));
1353
1379
  }
1354
1380
  };
1355
1381
  }
1356
- function xt(r, t) {
1382
+ function zt(r, t) {
1357
1383
  const e = r.getAttribute("data-cke-editor-id");
1358
- let i = !1, a = null, n = tt(), o = null;
1359
- const c = (s) => {
1360
- !(s instanceof y) || s.detail.editorId !== e || n.shouldNotify(s.detail.roots) && t.invokeMethodAsync("OnChangeEditorData", o, s.detail.roots);
1384
+ let i = !1, a = null, n = tt(), o = null, s = null;
1385
+ const u = (c) => {
1386
+ !(c instanceof g) || c.detail.editorId !== e || n.shouldNotify(c.detail.roots) && t.invokeMethodAsync("OnChangeEditorData", s, c.detail.roots);
1361
1387
  };
1362
1388
  return (async () => {
1363
- const s = await h.the.waitFor(e);
1364
- o = globalThis.DotNet.createJSObjectReference(s), n = Z(s, {
1365
- getCurrentValue: () => H(s),
1366
- applyValue: (d) => s.setData(d),
1367
- isEqual: rt
1368
- });
1369
- const l = (d, g, f) => {
1370
- const w = f ? "OnEditorFocus" : "OnEditorBlur";
1371
- t.invokeMethodAsync(w, o);
1389
+ const c = await h.the.waitFor(e);
1390
+ s = globalThis.DotNet.createJSObjectReference(c), n = Z(c, {
1391
+ getCurrentValue: () => J(c),
1392
+ applyValue: (w) => c.setData(w),
1393
+ isEqual: at
1394
+ }), o = et(c, "main");
1395
+ const l = (w, y, b) => {
1396
+ const f = b ? "OnEditorFocus" : "OnEditorBlur";
1397
+ t.invokeMethodAsync(f, s);
1372
1398
  };
1373
- s.ui.focusTracker.on("change:isFocused", l), t.invokeMethodAsync("OnEditorReady", o), a = () => {
1374
- s.ui.focusTracker.off("change:isFocused", l);
1399
+ c.ui.focusTracker.on("change:isFocused", l), t.invokeMethodAsync("OnEditorReady", s), a = () => {
1400
+ c.ui.focusTracker.off("change:isFocused", l);
1375
1401
  };
1376
- })(), document.body.addEventListener(y.EVENT_NAME, c), vt(), O(r), {
1402
+ })(), document.body.addEventListener(g.EVENT_NAME, u), Ct(), x(r), {
1377
1403
  /**
1378
1404
  * Updates the editor data from Blazor. If the editor is focused, the update is deferred until blur to avoid interrupting the user.
1379
1405
  */
1380
- setValue: async (s) => {
1381
- i || (await h.the.waitFor(e), n.setValue(s));
1406
+ setValue: async (c) => {
1407
+ i || (await h.the.waitFor(e), n.setValue(c));
1408
+ },
1409
+ /**
1410
+ * Updates the root attributes on the editor instance.
1411
+ */
1412
+ setRootAttributes: async (c) => {
1413
+ i || (await h.the.waitFor(e), o?.(c));
1382
1414
  },
1383
1415
  /**
1384
1416
  * Cleans up all event listeners when the Blazor component is disposed.
1385
1417
  */
1386
1418
  unmount() {
1387
- i || (document.body.removeEventListener(y.EVENT_NAME, c), n.unmount(), a?.(), o && (globalThis.DotNet.disposeJSObjectReference(o), o = null), i = !0);
1419
+ i || (document.body.removeEventListener(g.EVENT_NAME, u), n.unmount(), a?.(), s && (globalThis.DotNet.disposeJSObjectReference(s), s = null), o = null, i = !0);
1388
1420
  },
1389
1421
  /**
1390
1422
  * Installs the custom image upload adapter that delegates uploads to Blazor.
@@ -1394,12 +1426,12 @@ function xt(r, t) {
1394
1426
  attachImageUploadAdapter: async () => {
1395
1427
  if (i)
1396
1428
  return;
1397
- const s = await h.the.waitFor(e);
1398
- Ct(s, t);
1429
+ const c = await h.the.waitFor(e);
1430
+ Pt(c, t);
1399
1431
  }
1400
1432
  };
1401
1433
  }
1402
- function Ct(r, t) {
1434
+ function Pt(r, t) {
1403
1435
  if (!r.plugins.has("FileRepository"))
1404
1436
  return;
1405
1437
  const e = r.plugins.get("FileRepository");
@@ -1410,16 +1442,16 @@ function Ct(r, t) {
1410
1442
  const n = await i.file;
1411
1443
  if (a)
1412
1444
  throw new Error("Upload aborted.");
1413
- const o = await At(n), c = await t.invokeMethodAsync("OnEditorImageUpload", {
1445
+ const o = await It(n), s = await t.invokeMethodAsync("OnEditorImageUpload", {
1414
1446
  fileName: n.name,
1415
1447
  mimeType: n.type,
1416
1448
  payload: o
1417
1449
  });
1418
- if (!c)
1450
+ if (!s)
1419
1451
  throw new Error(
1420
1452
  "OnImageUpload handler returned null. Make sure the OnImageUpload parameter is set on the <CKE5Editor> component."
1421
1453
  );
1422
- return { default: c };
1454
+ return { default: s };
1423
1455
  },
1424
1456
  abort() {
1425
1457
  a = !0;
@@ -1427,7 +1459,7 @@ function Ct(r, t) {
1427
1459
  };
1428
1460
  };
1429
1461
  }
1430
- function At(r) {
1462
+ function It(r) {
1431
1463
  return new Promise((t, e) => {
1432
1464
  const i = new FileReader();
1433
1465
  i.onload = () => {
@@ -1436,25 +1468,25 @@ function At(r) {
1436
1468
  }, i.onerror = () => e(i.error), i.readAsDataURL(r);
1437
1469
  });
1438
1470
  }
1439
- function Nt(r) {
1440
- return O(r), {
1471
+ function Vt(r) {
1472
+ return x(r), {
1441
1473
  unmount() {
1442
1474
  }
1443
1475
  };
1444
1476
  }
1445
1477
  export {
1446
- b as CKEditor5BlazorError,
1447
- y as CKEditor5ChangeDataEvent,
1478
+ E as CKEditor5BlazorError,
1479
+ g as CKEditor5ChangeDataEvent,
1448
1480
  v as ContextsRegistry,
1449
- R as CustomEditorPluginsRegistry,
1450
- pt as EditableComponentElement,
1451
- gt as EditorComponentElement,
1481
+ W as CustomEditorPluginsRegistry,
1482
+ ft as EditableComponentElement,
1483
+ bt as EditorComponentElement,
1452
1484
  h as EditorsRegistry,
1453
- bt as UIPartComponentElement,
1454
- Dt as createContextBlazorInterop,
1455
- St as createEditableBlazorInterop,
1456
- xt as createEditorBlazorInterop,
1457
- Nt as createUIPartBlazorInterop,
1458
- vt as ensureEditorElementsRegistered
1485
+ kt as UIPartComponentElement,
1486
+ xt as createContextBlazorInterop,
1487
+ Nt as createEditableBlazorInterop,
1488
+ zt as createEditorBlazorInterop,
1489
+ Vt as createUIPartBlazorInterop,
1490
+ Ct as ensureEditorElementsRegistered
1459
1491
  };
1460
1492
  //# sourceMappingURL=index.mjs.map