ckeditor5-phoenix 1.15.1 → 1.15.2

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
@@ -25,12 +25,12 @@ class V {
25
25
  * @returns A promise that resolves with the result of the function.
26
26
  */
27
27
  execute(t, e, r) {
28
- const i = this.items.get(t), n = this.initializationErrors.get(t);
29
- return n ? (r?.(n), Promise.reject(n)) : i ? Promise.resolve(e(i)) : new Promise((s, o) => {
30
- const c = this.getPendingCallbacks(t);
31
- c.success.push(async (m) => {
32
- s(await e(m));
33
- }), r ? c.error.push(r) : c.error.push(o);
28
+ const a = this.items.get(t), n = this.initializationErrors.get(t);
29
+ return n ? (r?.(n), Promise.reject(n)) : a ? Promise.resolve(e(a)) : new Promise((s, u) => {
30
+ const o = this.getPendingCallbacks(t);
31
+ o.success.push(async (c) => {
32
+ s(await e(c));
33
+ }), r ? o.error.push(r) : o.error.push(u);
34
34
  });
35
35
  }
36
36
  /**
@@ -44,7 +44,7 @@ class V {
44
44
  throw new Error(`Item with ID "${t}" is already registered.`);
45
45
  this.resetErrors(t), this.items.set(t, e);
46
46
  const r = this.pendingCallbacks.get(t);
47
- r && (r.success.forEach((i) => i(e)), this.pendingCallbacks.delete(t)), this.registerAsDefault(t, e), this.notifyWatchers();
47
+ r && (r.success.forEach((a) => a(e)), this.pendingCallbacks.delete(t)), this.registerAsDefault(t, e), this.notifyWatchers();
48
48
  }
49
49
  /**
50
50
  * Registers an error for an item.
@@ -55,7 +55,7 @@ class V {
55
55
  error(t, e) {
56
56
  this.items.delete(t), this.initializationErrors.set(t, e);
57
57
  const r = this.pendingCallbacks.get(t);
58
- r && (r.error.forEach((i) => i(e)), this.pendingCallbacks.delete(t)), this.initializationErrors.size === 1 && !this.items.size && this.error(null, e), this.notifyWatchers();
58
+ r && (r.error.forEach((a) => a(e)), this.pendingCallbacks.delete(t)), this.initializationErrors.size === 1 && !this.items.size && this.error(null, e), this.notifyWatchers();
59
59
  }
60
60
  /**
61
61
  * Resets errors for an item.
@@ -164,35 +164,35 @@ class V {
164
164
  this.items.size === 1 && t !== null && this.register(null, e);
165
165
  }
166
166
  }
167
- function F(a) {
168
- return a.replace(/[-_\s]+(.)?/g, (t, e) => e ? e.toUpperCase() : "").replace(/^./, (t) => t.toLowerCase());
167
+ function F(i) {
168
+ return i.replace(/[-_\s]+(.)?/g, (t, e) => e ? e.toUpperCase() : "").replace(/^./, (t) => t.toLowerCase());
169
169
  }
170
- function O(a, t) {
170
+ function O(i, t) {
171
171
  let e = null;
172
172
  return (...r) => {
173
173
  e && clearTimeout(e), e = setTimeout(() => {
174
174
  t(...r);
175
- }, a);
175
+ }, i);
176
176
  };
177
177
  }
178
- function G(a) {
179
- if (Object.prototype.toString.call(a) !== "[object Object]")
178
+ function G(i) {
179
+ if (Object.prototype.toString.call(i) !== "[object Object]")
180
180
  return !1;
181
- const t = Object.getPrototypeOf(a);
181
+ const t = Object.getPrototypeOf(i);
182
182
  return t === Object.prototype || t === null;
183
183
  }
184
- function E(a) {
185
- if (Array.isArray(a))
186
- return a.map(E);
187
- if (G(a)) {
184
+ function b(i) {
185
+ if (Array.isArray(i))
186
+ return i.map(b);
187
+ if (G(i)) {
188
188
  const t = /* @__PURE__ */ Object.create(null);
189
- for (const [e, r] of Object.entries(a))
190
- t[F(e)] = E(r);
189
+ for (const [e, r] of Object.entries(i))
190
+ t[F(e)] = b(r);
191
191
  return t;
192
192
  }
193
- return a;
193
+ return i;
194
194
  }
195
- class k {
195
+ class E {
196
196
  /**
197
197
  * The current state of the hook.
198
198
  */
@@ -234,15 +234,15 @@ class k {
234
234
  return this.state === "destroyed" || this.state === "destroying";
235
235
  }
236
236
  }
237
- function P(a) {
237
+ function k(i) {
238
238
  return {
239
239
  /**
240
240
  * The mounted lifecycle callback for the LiveView hook object.
241
241
  * It creates an instance of the user-defined hook class and sets up the necessary properties and methods.
242
242
  */
243
243
  async mounted() {
244
- const t = new a();
245
- this.el.instance = t, t.el = this.el, t.liveSocket = this.liveSocket, t.pushEvent = (r, i, n) => this.pushEvent?.(r, i, n), t.pushEventTo = (r, i, n, s) => this.pushEventTo?.(r, i, n, s), t.handleEvent = (r, i) => this.handleEvent?.(r, i), t.state = "mounting";
244
+ const t = new i();
245
+ this.el.instance = t, t.el = this.el, t.liveSocket = this.liveSocket, t.pushEvent = (r, a, n) => this.pushEvent?.(r, a, n), t.pushEventTo = (r, a, n, s) => this.pushEventTo?.(r, a, n, s), t.handleEvent = (r, a) => this.handleEvent?.(r, a), t.state = "mounting";
246
246
  const e = await t.mounted?.();
247
247
  return t.state = "mounted", e;
248
248
  },
@@ -273,67 +273,67 @@ function P(a) {
273
273
  }
274
274
  };
275
275
  }
276
- function W(a) {
277
- return Object.keys(a).length === 0 && a.constructor === Object;
276
+ function L(i) {
277
+ return Object.keys(i).length === 0 && i.constructor === Object;
278
278
  }
279
- function Y(a) {
280
- return a == null;
279
+ function Y(i) {
280
+ return i == null;
281
281
  }
282
- function A(a, t) {
283
- const e = Object.entries(a).map(([r, i]) => [r, t(i, r)]);
282
+ function A(i, t) {
283
+ const e = Object.entries(i).map(([r, a]) => [r, t(a, r)]);
284
284
  return Object.fromEntries(e);
285
285
  }
286
- function H(a) {
287
- if (a === null)
286
+ function N(i) {
287
+ if (i === null)
288
288
  return null;
289
- const t = Number.parseInt(a, 10);
289
+ const t = Number.parseInt(i, 10);
290
290
  return Number.isNaN(t) ? null : t;
291
291
  }
292
292
  function J() {
293
293
  return Math.random().toString(36).substring(2);
294
294
  }
295
295
  const I = Symbol.for("context-editor-watchdog");
296
- async function X({ element: a, context: t, creator: e, config: r }) {
297
- const i = J();
296
+ async function X({ element: i, context: t, creator: e, config: r }) {
297
+ const a = J();
298
298
  await t.add({
299
- creator: (c, m) => e.create(c, m),
300
- id: i,
301
- sourceElementOrData: a,
299
+ creator: (o, c) => e.create(o, c),
300
+ id: a,
301
+ sourceElementOrData: i,
302
302
  type: "editor",
303
303
  config: r
304
304
  });
305
- const n = t.getItem(i), s = {
305
+ const n = t.getItem(a), s = {
306
306
  state: "available",
307
- editorContextId: i,
307
+ editorContextId: a,
308
308
  context: t
309
309
  };
310
310
  n[I] = s;
311
- const o = t.destroy.bind(t);
312
- return t.destroy = async () => (s.state = "unavailable", o()), {
311
+ const u = t.destroy.bind(t);
312
+ return t.destroy = async () => (s.state = "unavailable", u()), {
313
313
  ...s,
314
314
  editor: n
315
315
  };
316
316
  }
317
- function Q(a) {
318
- return I in a ? a[I] : null;
317
+ function Q(i) {
318
+ return I in i ? i[I] : null;
319
319
  }
320
- function D(a) {
321
- return ["inline", "classic", "balloon", "decoupled"].includes(a);
320
+ function y(i) {
321
+ return ["inline", "classic", "balloon", "decoupled"].includes(i);
322
322
  }
323
- async function Z(a) {
323
+ async function Z(i) {
324
324
  const t = await import("ckeditor5"), r = {
325
325
  inline: t.InlineEditor,
326
326
  balloon: t.BalloonEditor,
327
327
  classic: t.ClassicEditor,
328
328
  decoupled: t.DecoupledEditor,
329
329
  multiroot: t.MultiRootEditor
330
- }[a];
330
+ }[i];
331
331
  if (!r)
332
- throw new Error(`Unsupported editor type: ${a}`);
332
+ throw new Error(`Unsupported editor type: ${i}`);
333
333
  return r;
334
334
  }
335
- class $ {
336
- static the = new $();
335
+ class D {
336
+ static the = new D();
337
337
  /**
338
338
  * Map of registered custom plugins.
339
339
  */
@@ -392,53 +392,53 @@ class $ {
392
392
  return this.plugins.has(t);
393
393
  }
394
394
  }
395
- async function q(a) {
395
+ async function q(i) {
396
396
  const t = await import("ckeditor5");
397
397
  let e = null;
398
- const r = a.map(async (i) => {
399
- const n = await $.the.get(i);
398
+ const r = i.map(async (a) => {
399
+ const n = await D.the.get(a);
400
400
  if (n)
401
401
  return n;
402
- const { [i]: s } = t;
402
+ const { [a]: s } = t;
403
403
  if (s)
404
404
  return s;
405
405
  if (!e)
406
406
  try {
407
407
  e = await import("ckeditor5-premium-features");
408
- } catch (c) {
409
- console.error(`Failed to load premium package: ${c}`);
408
+ } catch (o) {
409
+ console.error(`Failed to load premium package: ${o}`);
410
410
  }
411
- const { [i]: o } = e || {};
412
- if (o)
413
- return o;
414
- throw new Error(`Plugin "${i}" not found in base or premium packages.`);
411
+ const { [a]: u } = e || {};
412
+ if (u)
413
+ return u;
414
+ throw new Error(`Plugin "${a}" not found in base or premium packages.`);
415
415
  });
416
416
  return {
417
417
  loadedPlugins: await Promise.all(r),
418
418
  hasPremium: !!e
419
419
  };
420
420
  }
421
- async function B(a, t) {
422
- const e = [a.ui, a.content];
421
+ async function B(i, t) {
422
+ const e = [i.ui, i.content];
423
423
  return await Promise.all(
424
424
  [
425
425
  z("ckeditor5", e),
426
426
  /* v8 ignore next */
427
427
  t && z("ckeditor5-premium-features", e)
428
- ].filter((i) => !!i)
429
- ).then((i) => i.flat());
428
+ ].filter((a) => !!a)
429
+ ).then((a) => a.flat());
430
430
  }
431
- async function z(a, t) {
431
+ async function z(i, t) {
432
432
  return await Promise.all(
433
433
  t.filter((e) => e !== "en").map(async (e) => {
434
- const r = await tt(a, e);
434
+ const r = await tt(i, e);
435
435
  return r?.default ?? r;
436
436
  }).filter(Boolean)
437
437
  );
438
438
  }
439
- async function tt(a, t) {
439
+ async function tt(i, t) {
440
440
  try {
441
- if (a === "ckeditor5")
441
+ if (i === "ckeditor5")
442
442
  switch (t) {
443
443
  case "af":
444
444
  return await import("ckeditor5/translations/af.js");
@@ -733,76 +733,76 @@ async function tt(a, t) {
733
733
  return console.warn(`Language ${t} not found in premium translations`), await import("ckeditor5-premium-features/translations/en.js");
734
734
  }
735
735
  } catch (e) {
736
- return console.error(`Failed to load translation for ${a}/${t}:`, e), null;
736
+ return console.error(`Failed to load translation for ${i}/${t}:`, e), null;
737
737
  }
738
738
  }
739
- function L(a) {
740
- return A(a, (t) => ({
739
+ function U(i) {
740
+ return A(i, (t) => ({
741
741
  dictionary: t
742
742
  }));
743
743
  }
744
- function j(a) {
744
+ function S(i) {
745
745
  const t = document.querySelectorAll(
746
746
  [
747
- `[data-cke-editor-id="${a}"][data-cke-editable-root-name]`,
747
+ `[data-cke-editor-id="${i}"][data-cke-editable-root-name]`,
748
748
  "[data-cke-editable-root-name]:not([data-cke-editor-id])"
749
749
  ].join(", ")
750
750
  );
751
751
  return Array.from(t).reduce((e, r) => {
752
- const i = r.getAttribute("data-cke-editable-root-name"), n = r.getAttribute("data-cke-editable-initial-value") || "", s = r.querySelector("[data-cke-editable-content]");
753
- return !i || !s ? e : {
752
+ const a = r.getAttribute("data-cke-editable-root-name"), n = r.getAttribute("data-cke-editable-initial-value") || "", s = r.querySelector("[data-cke-editable-content]");
753
+ return !a || !s ? e : {
754
754
  ...e,
755
- [i]: {
755
+ [a]: {
756
756
  content: s,
757
757
  initialValue: n
758
758
  }
759
759
  };
760
760
  }, /* @__PURE__ */ Object.create({}));
761
761
  }
762
- const N = ["inline", "classic", "balloon", "decoupled", "multiroot"];
763
- function et(a) {
764
- const t = a.getAttribute("cke-preset");
762
+ const W = ["inline", "classic", "balloon", "decoupled", "multiroot"];
763
+ function et(i) {
764
+ const t = i.getAttribute("cke-preset");
765
765
  if (!t)
766
766
  throw new Error('CKEditor5 hook requires a "cke-preset" attribute on the element.');
767
- const { type: e, config: r, license: i, ...n } = JSON.parse(t);
768
- if (!e || !r || !i)
767
+ const { type: e, config: r, license: a, ...n } = JSON.parse(t);
768
+ if (!e || !r || !a)
769
769
  throw new Error('CKEditor5 hook configuration must include "editor", "config", and "license" properties.');
770
- if (!N.includes(e))
771
- throw new Error(`Invalid editor type: ${e}. Must be one of: ${N.join(", ")}.`);
770
+ if (!W.includes(e))
771
+ throw new Error(`Invalid editor type: ${e}. Must be one of: ${W.join(", ")}.`);
772
772
  return {
773
773
  type: e,
774
- license: i,
775
- config: E(r),
774
+ license: a,
775
+ config: b(r),
776
776
  customTranslations: n.customTranslations || n.custom_translations
777
777
  };
778
778
  }
779
- function T(a) {
780
- if (!a || typeof a != "object")
781
- return a;
782
- if (Array.isArray(a))
783
- return a.map((r) => T(r));
784
- const t = a;
779
+ function x(i) {
780
+ if (!i || typeof i != "object")
781
+ return i;
782
+ if (Array.isArray(i))
783
+ return i.map((r) => x(r));
784
+ const t = i;
785
785
  if (t.$element && typeof t.$element == "string") {
786
786
  const r = document.querySelector(t.$element);
787
787
  return r || console.warn(`Element not found for selector: ${t.$element}`), r || null;
788
788
  }
789
789
  const e = /* @__PURE__ */ Object.create(null);
790
- for (const [r, i] of Object.entries(a))
791
- e[r] = T(i);
790
+ for (const [r, a] of Object.entries(i))
791
+ e[r] = x(a);
792
792
  return e;
793
793
  }
794
- function rt(a, t) {
795
- const { editing: e } = a;
794
+ function rt(i, t) {
795
+ const { editing: e } = i;
796
796
  e.view.change((r) => {
797
797
  r.setStyle("height", `${t}px`, e.view.document.getRoot());
798
798
  });
799
799
  }
800
- const x = Symbol.for("elixir-editor-watchdog");
801
- async function at(a) {
802
- const { EditorWatchdog: t } = await import("ckeditor5"), e = new t(a);
800
+ const T = Symbol.for("elixir-editor-watchdog");
801
+ async function it(i) {
802
+ const { EditorWatchdog: t } = await import("ckeditor5"), e = new t(i);
803
803
  return e.setCreator(async (...r) => {
804
- const i = await a.create(...r);
805
- return i[x] = e, i;
804
+ const a = await i.create(...r);
805
+ return a[T] = e, a;
806
806
  }), {
807
807
  watchdog: e,
808
808
  Constructor: {
@@ -810,24 +810,24 @@ async function at(a) {
810
810
  }
811
811
  };
812
812
  }
813
- function it(a) {
814
- return x in a ? a[x] : null;
813
+ function at(i) {
814
+ return T in i ? i[T] : null;
815
815
  }
816
- class w extends V {
817
- static the = new w();
816
+ class p extends V {
817
+ static the = new p();
818
818
  }
819
- function nt(a) {
820
- const t = a.getAttribute("cke-context");
819
+ function nt(i) {
820
+ const t = i.getAttribute("cke-context");
821
821
  if (!t)
822
822
  throw new Error('CKEditor5 hook requires a "cke-context" attribute on the element.');
823
823
  const { config: e, ...r } = JSON.parse(t);
824
824
  return {
825
- config: E(e),
825
+ config: b(e),
826
826
  customTranslations: r.customTranslations || r.custom_translations,
827
827
  watchdogConfig: r.watchdogConfig || r.watchdog_config
828
828
  };
829
829
  }
830
- class st extends k {
830
+ class st extends E {
831
831
  /**
832
832
  * The promise that resolves to the context instance.
833
833
  */
@@ -855,28 +855,28 @@ class st extends k {
855
855
  * Mounts the context component.
856
856
  */
857
857
  async mounted() {
858
- const { id: t, language: e } = this.attrs, { customTranslations: r, watchdogConfig: i, config: { plugins: n, ...s } } = this.attrs.config, { loadedPlugins: o, hasPremium: c } = await q(n ?? []), d = [
859
- ...await B(e, c),
860
- L(r?.dictionary || {})
861
- ].filter((f) => !W(f));
858
+ const { id: t, language: e } = this.attrs, { customTranslations: r, watchdogConfig: a, config: { plugins: n, ...s } } = this.attrs.config, { loadedPlugins: u, hasPremium: o } = await q(n ?? []), l = [
859
+ ...await B(e, o),
860
+ U(r?.dictionary || {})
861
+ ].filter((w) => !L(w));
862
862
  this.contextPromise = (async () => {
863
- const { ContextWatchdog: f, Context: v } = await import("ckeditor5"), p = new f(v, {
863
+ const { ContextWatchdog: w, Context: P } = await import("ckeditor5"), m = new w(P, {
864
864
  crashNumberLimit: 10,
865
- ...i
865
+ ...a
866
866
  });
867
- return await p.create({
867
+ return await m.create({
868
868
  ...s,
869
869
  language: e,
870
- plugins: o,
871
- ...d.length && {
872
- translations: d
870
+ plugins: u,
871
+ ...l.length && {
872
+ translations: l
873
873
  }
874
- }), p.on("itemError", (...b) => {
875
- console.error("Context item error:", ...b);
876
- }), p;
874
+ }), m.on("itemError", (...g) => {
875
+ console.error("Context item error:", ...g);
876
+ }), m;
877
877
  })();
878
- const g = await this.contextPromise;
879
- this.isBeingDestroyed() || w.the.register(t, g);
878
+ const h = await this.contextPromise;
879
+ this.isBeingDestroyed() || p.the.register(t, h);
880
880
  }
881
881
  /**
882
882
  * Destroys the context component. Unmounts root from the editor.
@@ -887,15 +887,15 @@ class st extends k {
887
887
  try {
888
888
  await (await this.contextPromise)?.destroy();
889
889
  } finally {
890
- this.contextPromise = null, w.the.hasItem(t) && w.the.unregister(t);
890
+ this.contextPromise = null, p.the.hasItem(t) && p.the.unregister(t);
891
891
  }
892
892
  }
893
893
  }
894
- function ot(a) {
895
- return a.hasAttribute("cke-context");
894
+ function ot(i) {
895
+ return i.hasAttribute("cke-context");
896
896
  }
897
- function ct(a) {
898
- let t = a;
897
+ function ct(i) {
898
+ let t = i;
899
899
  for (; t; ) {
900
900
  if (ot(t))
901
901
  return t;
@@ -903,15 +903,15 @@ function ct(a) {
903
903
  }
904
904
  return null;
905
905
  }
906
- async function ut(a) {
907
- const t = ct(a);
908
- return t ? w.the.waitFor(t.id) : null;
906
+ async function ut(i) {
907
+ const t = ct(i);
908
+ return t ? p.the.waitFor(t.id) : null;
909
909
  }
910
- const lt = P(st);
911
- class l extends V {
912
- static the = new l();
910
+ const lt = k(st);
911
+ class d extends V {
912
+ static the = new d();
913
913
  }
914
- class dt extends k {
914
+ class dt extends E {
915
915
  /**
916
916
  * The name of the hook.
917
917
  */
@@ -937,17 +937,17 @@ class dt extends k {
937
937
  * Mounts the editable component.
938
938
  */
939
939
  async mounted() {
940
- const { editableId: t, editorId: e, rootName: r, initialValue: i } = this.attrs, n = this.el.querySelector(`#${t}_input`);
941
- this.editorPromise = l.the.execute(e, (s) => {
942
- const { ui: o, editing: c, model: m } = s;
943
- if (m.document.getRoot(r))
940
+ const { editableId: t, editorId: e, rootName: r, initialValue: a } = this.attrs, n = this.el.querySelector(`#${t}_input`);
941
+ this.editorPromise = d.the.execute(e, (s) => {
942
+ const { ui: u, editing: o, model: c } = s;
943
+ if (c.document.getRoot(r))
944
944
  return s;
945
945
  s.addRoot(r, {
946
946
  isUndoable: !1,
947
- data: i
947
+ data: a
948
948
  });
949
- const d = this.el.querySelector("[data-cke-editable-content]"), g = o.view.createEditable(r, d);
950
- return o.addEditable(g), c.view.forceRender(), n && pt(n, s, r), s;
949
+ const l = this.el.querySelector("[data-cke-editable-content]"), h = u.view.createEditable(r, l);
950
+ return u.addEditable(h), o.view.forceRender(), n && ht(n, s, r), s;
951
951
  });
952
952
  }
953
953
  /**
@@ -963,14 +963,110 @@ class dt extends k {
963
963
  }
964
964
  }
965
965
  }
966
- const mt = P(dt);
967
- function pt(a, t, e) {
966
+ const mt = k(dt);
967
+ function ht(i, t, e) {
968
968
  const r = () => {
969
- a.value = t.getData({ rootName: e });
969
+ i.value = t.getData({ rootName: e });
970
970
  };
971
971
  t.model.document.on("change:data", O(100, r)), r();
972
972
  }
973
- class ht extends k {
973
+ async function pt({
974
+ editorId: i,
975
+ saveDebounceMs: t
976
+ }) {
977
+ const { Plugin: e } = await import("ckeditor5");
978
+ return class extends e {
979
+ /**
980
+ * The input element to synchronize with.
981
+ */
982
+ input = null;
983
+ /**
984
+ * The form element reference for cleanup.
985
+ */
986
+ form = null;
987
+ /**
988
+ * The name of the plugin.
989
+ */
990
+ static get pluginName() {
991
+ return "SyncEditorWithInput";
992
+ }
993
+ /**
994
+ * Initializes the plugin.
995
+ */
996
+ afterInit() {
997
+ const { editor: a } = this;
998
+ this.input = document.getElementById(`${i}_input`), this.input && (a.model.document.on("change:data", O(t, () => this.sync())), a.once("ready", this.sync), this.form = this.input.closest("form"), this.form?.addEventListener("submit", this.sync));
999
+ }
1000
+ /**
1001
+ * Synchronizes the editor's content with the input field.
1002
+ */
1003
+ sync = () => {
1004
+ const a = this.editor.getData();
1005
+ this.input.value = a, this.input.dispatchEvent(new Event("input", { bubbles: !0 }));
1006
+ };
1007
+ /**
1008
+ * Destroys the plugin.
1009
+ */
1010
+ destroy() {
1011
+ this.form && this.form.removeEventListener("submit", this.sync), this.input = null, this.form = null;
1012
+ }
1013
+ };
1014
+ }
1015
+ async function wt(i) {
1016
+ const { Plugin: t } = await import("ckeditor5"), { editorId: e, saveDebounceMs: r, events: a, pushEvent: n, handleEvent: s } = i;
1017
+ return class extends t {
1018
+ /**
1019
+ * The name of the plugin.
1020
+ */
1021
+ static get pluginName() {
1022
+ return "SyncEditorWithPhoenix";
1023
+ }
1024
+ /**
1025
+ * Initializes the plugin.
1026
+ */
1027
+ init() {
1028
+ const { editor: o } = this;
1029
+ a.change && this.setupTypingContentPush(), a.blur && this.setupEventPush("blur"), a.focus && this.setupEventPush("focus"), s("ckeditor5:set-data", ({ editorId: c, data: l }) => {
1030
+ (Y(c) || c === e) && o.setData(l);
1031
+ });
1032
+ }
1033
+ /**
1034
+ * Setups the content push event for the editor.
1035
+ */
1036
+ setupTypingContentPush() {
1037
+ const { editor: o } = this, c = () => {
1038
+ n(
1039
+ "ckeditor5:change",
1040
+ {
1041
+ editorId: e,
1042
+ data: R(this.editor)
1043
+ }
1044
+ );
1045
+ };
1046
+ o.model.document.on("change:data", O(r, c)), o.once("ready", c);
1047
+ }
1048
+ /**
1049
+ * Setups the event push for the editor.
1050
+ */
1051
+ setupEventPush(o) {
1052
+ const { editor: c } = this, l = () => {
1053
+ const { isFocused: h } = c.ui.focusTracker;
1054
+ (h ? "focus" : "blur") === o && n(
1055
+ `ckeditor5:${o}`,
1056
+ {
1057
+ editorId: e,
1058
+ data: R(c)
1059
+ }
1060
+ );
1061
+ };
1062
+ c.ui.focusTracker.on("change:isFocused", l);
1063
+ }
1064
+ };
1065
+ }
1066
+ function R(i) {
1067
+ return i.model.document.getRootNames().reduce((e, r) => (e[r] = i.getData({ rootName: r }), e), /* @__PURE__ */ Object.create({}));
1068
+ }
1069
+ class ft extends E {
974
1070
  /**
975
1071
  * The promise that resolves to the editor instance.
976
1072
  */
@@ -979,44 +1075,44 @@ class ht extends k {
979
1075
  * Attributes for the editor instance.
980
1076
  */
981
1077
  get attrs() {
982
- const { el: t } = this, e = t.getAttribute.bind(t), r = t.hasAttribute.bind(t), i = {
1078
+ const { el: t } = this, e = t.getAttribute.bind(t), r = t.hasAttribute.bind(t), a = {
983
1079
  editorId: e("id"),
984
1080
  contextId: e("cke-context-id"),
985
1081
  preset: et(t),
986
- editableHeight: H(e("cke-editable-height")),
1082
+ editableHeight: N(e("cke-editable-height")),
987
1083
  watchdog: r("cke-watchdog"),
988
1084
  events: {
989
1085
  change: r("cke-change-event"),
990
1086
  blur: r("cke-blur-event"),
991
1087
  focus: r("cke-focus-event")
992
1088
  },
993
- saveDebounceMs: H(e("cke-save-debounce-ms")) ?? 400,
1089
+ saveDebounceMs: N(e("cke-save-debounce-ms")) ?? 400,
994
1090
  language: {
995
1091
  ui: e("cke-language") || "en",
996
1092
  content: e("cke-content-language") || "en"
997
1093
  }
998
1094
  };
999
1095
  return Object.defineProperty(this, "attrs", {
1000
- value: i,
1096
+ value: a,
1001
1097
  writable: !1,
1002
1098
  configurable: !1,
1003
1099
  enumerable: !0
1004
- }), i;
1100
+ }), a;
1005
1101
  }
1006
1102
  /**
1007
1103
  * Mounts the editor component.
1008
1104
  */
1009
1105
  async mounted() {
1010
1106
  const { editorId: t } = this.attrs;
1011
- l.the.resetErrors(t);
1107
+ d.the.resetErrors(t);
1012
1108
  try {
1013
1109
  this.editorPromise = this.createEditor();
1014
1110
  const e = await this.editorPromise;
1015
- this.isBeingDestroyed() || (l.the.register(t, e), e.once("destroy", () => {
1016
- l.the.hasItem(t) && l.the.unregister(t);
1111
+ this.isBeingDestroyed() || (d.the.register(t, e), e.once("destroy", () => {
1112
+ d.the.hasItem(t) && d.the.unregister(t);
1017
1113
  }));
1018
1114
  } catch (e) {
1019
- this.editorPromise = null, l.the.error(t, e);
1115
+ this.editorPromise = null, d.the.error(t, e);
1020
1116
  }
1021
1117
  return this;
1022
1118
  }
@@ -1030,7 +1126,7 @@ class ht extends k {
1030
1126
  const t = await this.editorPromise;
1031
1127
  if (!t)
1032
1128
  return;
1033
- const e = Q(t), r = it(t);
1129
+ const e = Q(t), r = at(t);
1034
1130
  e ? e.state !== "unavailable" && await e.context.remove(e.editorContextId) : r ? await r.destroy() : await t.destroy();
1035
1131
  } finally {
1036
1132
  this.editorPromise = null;
@@ -1040,116 +1136,81 @@ class ht extends k {
1040
1136
  * Creates the CKEditor instance.
1041
1137
  */
1042
1138
  async createEditor() {
1043
- const { preset: t, editorId: e, contextId: r, editableHeight: i, events: n, saveDebounceMs: s, language: o, watchdog: c } = this.attrs, { customTranslations: m, type: d, license: g, config: { plugins: f, ...v } } = t;
1044
- let p = await Z(d);
1045
- const b = await (r ? w.the.waitFor(r) : ut(this.el));
1046
- if (c && !b) {
1047
- const u = await at(p);
1048
- ({ Constructor: p } = u), u.watchdog.on("restart", () => {
1049
- const y = u.watchdog.editor;
1050
- this.editorPromise = Promise.resolve(y), l.the.register(e, y);
1139
+ const { preset: t, editorId: e, contextId: r, editableHeight: a, events: n, saveDebounceMs: s, language: u, watchdog: o } = this.attrs, { customTranslations: c, type: l, license: h, config: { plugins: w, ...P } } = t;
1140
+ let m = await Z(l);
1141
+ const g = await (r ? p.the.waitFor(r) : ut(this.el));
1142
+ if (o && !g) {
1143
+ const f = await it(m);
1144
+ ({ Constructor: m } = f), f.watchdog.on("restart", () => {
1145
+ const H = f.watchdog.editor;
1146
+ this.editorPromise = Promise.resolve(H), d.the.register(e, H);
1051
1147
  });
1052
1148
  }
1053
- const { loadedPlugins: _, hasPremium: K } = await q(f), M = [
1054
- ...await B(o, K),
1055
- L(m?.dictionary || {})
1056
- ].filter((u) => !W(u)), C = ft(e, d), S = {
1057
- ...T(v),
1058
- initialData: bt(e, d),
1059
- licenseKey: g.key,
1060
- plugins: _,
1061
- language: o,
1062
- ...M.length && {
1063
- translations: M
1149
+ const { loadedPlugins: v, hasPremium: K } = await q(w);
1150
+ y(l) && v.push(
1151
+ await pt({
1152
+ editorId: e,
1153
+ saveDebounceMs: s
1154
+ })
1155
+ ), v.push(
1156
+ await wt({
1157
+ editorId: e,
1158
+ saveDebounceMs: s,
1159
+ events: n,
1160
+ pushEvent: this.pushEvent.bind(this),
1161
+ handleEvent: this.handleEvent.bind(this)
1162
+ })
1163
+ );
1164
+ const $ = [
1165
+ ...await B(u, K),
1166
+ U(c?.dictionary || {})
1167
+ ].filter((f) => !L(f)), C = gt(e, l), j = {
1168
+ ...x(P),
1169
+ initialData: bt(e, l),
1170
+ licenseKey: h.key,
1171
+ plugins: v,
1172
+ language: u,
1173
+ ...$.length && {
1174
+ translations: $
1064
1175
  }
1065
- }, h = await (async () => !b || !(C instanceof HTMLElement) ? p.create(C, S) : (await X({
1066
- context: b,
1176
+ }, M = await (async () => !g || !(C instanceof HTMLElement) ? m.create(C, j) : (await X({
1177
+ context: g,
1067
1178
  element: C,
1068
- creator: p,
1069
- config: S
1179
+ creator: m,
1180
+ config: j
1070
1181
  })).editor)();
1071
- if (n.change && this.setupTypingContentPush(e, h, s), n.blur && this.setupEventPush(e, h, "blur"), n.focus && this.setupEventPush(e, h, "focus"), this.handleEvent("ckeditor5:set-data", ({ editorId: u, data: y }) => {
1072
- (Y(u) || u === this.attrs.editorId) && h.setData(y);
1073
- }), D(d)) {
1074
- const u = document.getElementById(`${e}_input`);
1075
- u && wt(u, h, s), i && rt(h, i);
1076
- }
1077
- return h;
1182
+ return y(l) && a && rt(M, a), M;
1078
1183
  }
1079
- /**
1080
- * Setups the content push event for the editor.
1081
- */
1082
- setupTypingContentPush(t, e, r) {
1083
- const i = () => {
1084
- this.pushEvent(
1085
- "ckeditor5:change",
1086
- {
1087
- editorId: t,
1088
- data: R(e)
1089
- }
1090
- );
1091
- };
1092
- e.model.document.on("change:data", O(r, i)), i();
1093
- }
1094
- /**
1095
- * Setups the event push for the editor.
1096
- */
1097
- setupEventPush(t, e, r) {
1098
- const i = () => {
1099
- const { isFocused: n } = e.ui.focusTracker;
1100
- (n ? "focus" : "blur") === r && this.pushEvent(
1101
- `ckeditor5:${r}`,
1102
- {
1103
- editorId: t,
1104
- data: R(e)
1105
- }
1106
- );
1107
- };
1108
- e.ui.focusTracker.on("change:isFocused", i);
1109
- }
1110
- }
1111
- function R(a) {
1112
- return a.model.document.getRootNames().reduce((e, r) => (e[r] = a.getData({ rootName: r }), e), /* @__PURE__ */ Object.create({}));
1113
- }
1114
- function wt(a, t, e) {
1115
- const r = () => {
1116
- const i = t.getData();
1117
- a.value = i, a.dispatchEvent(new Event("input", { bubbles: !0 }));
1118
- };
1119
- t.model.document.on("change:data", O(e, r)), gt(a)?.addEventListener("submit", r), r();
1120
- }
1121
- function gt(a) {
1122
- return a.closest("form");
1123
1184
  }
1124
- function ft(a, t) {
1185
+ function gt(i, t) {
1125
1186
  if (t === "decoupled") {
1126
- const { content: r } = U(a);
1187
+ const { content: r } = _(i);
1127
1188
  return r;
1128
1189
  }
1129
- if (D(t))
1130
- return document.getElementById(`${a}_editor`);
1131
- const e = j(a);
1190
+ if (y(t))
1191
+ return document.getElementById(`${i}_editor`);
1192
+ const e = S(i);
1132
1193
  return A(e, ({ content: r }) => r);
1133
1194
  }
1134
- function bt(a, t) {
1195
+ function bt(i, t) {
1135
1196
  if (t === "decoupled") {
1136
- const { initialValue: r } = U(a);
1197
+ const { initialValue: r } = _(i);
1137
1198
  if (r)
1138
1199
  return r;
1139
1200
  }
1140
- if (D(t))
1141
- return document.getElementById(a)?.getAttribute("cke-initial-value") || "";
1142
- const e = j(a);
1201
+ if (y(t))
1202
+ return document.getElementById(i)?.getAttribute("cke-initial-value") || "";
1203
+ const e = S(i);
1143
1204
  return A(e, ({ initialValue: r }) => r);
1144
1205
  }
1145
- function U(a) {
1146
- const t = j(a).main;
1206
+ function _(i) {
1207
+ const t = S(i).main;
1147
1208
  if (!t)
1148
- throw new Error(`No "main" editable found for editor with ID "${a}".`);
1209
+ throw new Error(`No "main" editable found for editor with ID "${i}".`);
1149
1210
  return t;
1150
1211
  }
1151
- const yt = P(ht);
1152
- class Et extends k {
1212
+ const yt = k(ft);
1213
+ class Et extends E {
1153
1214
  /**
1154
1215
  * The name of the hook.
1155
1216
  */
@@ -1174,8 +1235,8 @@ class Et extends k {
1174
1235
  */
1175
1236
  async mounted() {
1176
1237
  const { editorId: t, name: e } = this.attrs;
1177
- this.mountedPromise = l.the.execute(t, (r) => {
1178
- const { ui: i } = r, n = kt(e), s = i.view[n];
1238
+ this.mountedPromise = d.the.execute(t, (r) => {
1239
+ const { ui: a } = r, n = kt(e), s = a.view[n];
1179
1240
  if (!s) {
1180
1241
  console.error(`Unknown UI part name: "${e}". Supported names are "toolbar" and "menubar".`);
1181
1242
  return;
@@ -1190,8 +1251,8 @@ class Et extends k {
1190
1251
  this.el.style.display = "none", await this.mountedPromise, this.mountedPromise = null, this.el.innerHTML = "";
1191
1252
  }
1192
1253
  }
1193
- function kt(a) {
1194
- switch (a) {
1254
+ function kt(i) {
1255
+ switch (i) {
1195
1256
  case "toolbar":
1196
1257
  return "toolbar";
1197
1258
  case "menubar":
@@ -1200,17 +1261,17 @@ function kt(a) {
1200
1261
  return null;
1201
1262
  }
1202
1263
  }
1203
- const Pt = P(Et), Ct = {
1264
+ const Pt = k(Et), xt = {
1204
1265
  CKEditor5: yt,
1205
1266
  CKEditable: mt,
1206
1267
  CKUIPart: Pt,
1207
1268
  CKContext: lt
1208
1269
  };
1209
1270
  export {
1210
- $ as CustomEditorPluginsRegistry,
1211
- l as EditorsRegistry,
1212
- Ct as Hooks,
1271
+ D as CustomEditorPluginsRegistry,
1272
+ d as EditorsRegistry,
1273
+ xt as Hooks,
1213
1274
  Q as unwrapEditorContext,
1214
- it as unwrapEditorWatchdog
1275
+ at as unwrapEditorWatchdog
1215
1276
  };
1216
1277
  //# sourceMappingURL=index.mjs.map