ckeditor5-livewire 1.2.4 → 1.2.6

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,4 +1,4 @@
1
- class v {
1
+ class C {
2
2
  constructor(t) {
3
3
  this.livewireComponent = t;
4
4
  }
@@ -31,7 +31,7 @@ class v {
31
31
  return ["destroyed", "destroying"].includes(this.state);
32
32
  }
33
33
  }
34
- function _(i, t) {
34
+ function U(i, t) {
35
35
  const e = /* @__PURE__ */ new Map();
36
36
  window.Livewire?.hook("component.init", async ({ component: r, cleanup: n }) => {
37
37
  if (r.name !== i)
@@ -213,7 +213,7 @@ class H {
213
213
  this.items.size === 1 && t !== null && this.register(null, e);
214
214
  }
215
215
  }
216
- function O(i, t) {
216
+ function D(i, t) {
217
217
  let e = null;
218
218
  return (...r) => {
219
219
  e && clearTimeout(e), e = setTimeout(() => {
@@ -221,14 +221,14 @@ function O(i, t) {
221
221
  }, i);
222
222
  };
223
223
  }
224
- function K(i, t) {
224
+ function _(i, t) {
225
225
  const e = Object.entries(i).filter(([r, n]) => t(n, r));
226
226
  return Object.fromEntries(e);
227
227
  }
228
- function j(i) {
228
+ function W(i) {
229
229
  return Object.keys(i).length === 0 && i.constructor === Object;
230
230
  }
231
- function S(i, t) {
231
+ function O(i, t) {
232
232
  const e = Object.entries(i).map(([r, n]) => [r, t(n, r)]);
233
233
  return Object.fromEntries(e);
234
234
  }
@@ -243,10 +243,10 @@ function P(i, t) {
243
243
  return !1;
244
244
  return !0;
245
245
  }
246
- function G() {
246
+ function K() {
247
247
  return Math.random().toString(36).substring(2);
248
248
  }
249
- function Y(i, {
249
+ function G(i, {
250
250
  timeOutAfter: t = 500,
251
251
  retryAfter: e = 100
252
252
  } = {}) {
@@ -267,8 +267,8 @@ function Y(i, {
267
267
  });
268
268
  }
269
269
  const I = Symbol.for("context-editor-watchdog");
270
- async function X({ element: i, context: t, creator: e, config: r }) {
271
- const n = G();
270
+ async function Y({ element: i, context: t, creator: e, config: r }) {
271
+ const n = K();
272
272
  await t.add({
273
273
  creator: (c, u) => e.create(c, u),
274
274
  id: n,
@@ -288,16 +288,16 @@ async function X({ element: i, context: t, creator: e, config: r }) {
288
288
  editor: a
289
289
  };
290
290
  }
291
- function J(i) {
291
+ function X(i) {
292
292
  return I in i ? i[I] : null;
293
293
  }
294
- function Q(i) {
294
+ function J(i) {
295
295
  return i.model.document.getRootNames().reduce((e, r) => (e[r] = i.getData({ rootName: r }), e), /* @__PURE__ */ Object.create({}));
296
296
  }
297
- function C(i) {
297
+ function v(i) {
298
298
  return ["inline", "classic", "balloon", "decoupled"].includes(i);
299
299
  }
300
- function Z(i) {
300
+ function Q(i) {
301
301
  let t = i;
302
302
  for (; t; ) {
303
303
  for (const e of t.attributes)
@@ -307,7 +307,7 @@ function Z(i) {
307
307
  }
308
308
  return !1;
309
309
  }
310
- async function tt(i) {
310
+ async function Z(i) {
311
311
  const t = await import("ckeditor5"), r = {
312
312
  inline: t.InlineEditor,
313
313
  balloon: t.BalloonEditor,
@@ -319,8 +319,8 @@ async function tt(i) {
319
319
  throw new Error(`Unsupported editor type: ${i}`);
320
320
  return r;
321
321
  }
322
- class $ {
323
- static the = new $();
322
+ class S {
323
+ static the = new S();
324
324
  /**
325
325
  * Map of registered custom plugins.
326
326
  */
@@ -379,11 +379,11 @@ class $ {
379
379
  return this.plugins.has(t);
380
380
  }
381
381
  }
382
- async function F(i) {
382
+ async function A(i) {
383
383
  const t = await import("ckeditor5");
384
384
  let e = null;
385
385
  const r = i.map(async (n) => {
386
- const a = await $.the.get(n);
386
+ const a = await S.the.get(n);
387
387
  if (a)
388
388
  return a;
389
389
  const { [n]: s } = t;
@@ -409,21 +409,21 @@ async function V(i, t) {
409
409
  const e = [i.ui, i.content];
410
410
  return await Promise.all(
411
411
  [
412
- W("ckeditor5", e),
412
+ R("ckeditor5", e),
413
413
  /* v8 ignore next */
414
- t && W("ckeditor5-premium-features", e)
414
+ t && R("ckeditor5-premium-features", e)
415
415
  ].filter((n) => !!n)
416
416
  ).then((n) => n.flat());
417
417
  }
418
- async function W(i, t) {
418
+ async function R(i, t) {
419
419
  return await Promise.all(
420
420
  t.filter((e) => e !== "en").map(async (e) => {
421
- const r = await et(i, e);
421
+ const r = await tt(i, e);
422
422
  return r?.default ?? r;
423
423
  }).filter(Boolean)
424
424
  );
425
425
  }
426
- async function et(i, t) {
426
+ async function tt(i, t) {
427
427
  try {
428
428
  if (i === "ckeditor5")
429
429
  switch (t) {
@@ -723,52 +723,46 @@ async function et(i, t) {
723
723
  return console.error(`Failed to load translation for ${i}/${t}:`, e), null;
724
724
  }
725
725
  }
726
- function q(i) {
727
- return S(i, (t) => ({
726
+ function j(i) {
727
+ return O(i, (t) => ({
728
728
  dictionary: t
729
729
  }));
730
730
  }
731
- function M(i) {
732
- return window.Livewire.all().filter(({ name: t, canonical: e }) => t === "ckeditor5-editable" && e.editorId === i).reduce((t, { canonical: e, el: r }) => ({
731
+ function F(i) {
732
+ const t = q(i);
733
+ return O(t, ({ element: e }) => e);
734
+ }
735
+ function q(i) {
736
+ const t = window.Livewire.all().filter(({ name: s, canonical: o }) => s === "ckeditor5-editable" && o.editorId === i).reduce((s, { canonical: o, el: c }) => ({
737
+ ...s,
738
+ [o.rootName]: {
739
+ element: c.querySelector("[data-cke-editable-content]"),
740
+ content: o.content
741
+ }
742
+ }), /* @__PURE__ */ Object.create({})), r = window.Livewire.all().find(({ name: s, canonical: o }) => s === "ckeditor5" && o.editorId === i)?.canonical.content, n = document.querySelector(`#${i}_editor `), a = t.main;
743
+ return a && r?.main ? {
733
744
  ...t,
734
- [e.rootName]: {
735
- element: r.querySelector("[data-cke-editable-content]"),
736
- content: e.content
745
+ main: {
746
+ ...a,
747
+ content: a.content || r.main
737
748
  }
738
- }), /* @__PURE__ */ Object.create({}));
739
- }
740
- function T(i, t) {
741
- if (t === "decoupled") {
742
- const { element: r } = N(i);
743
- return r;
744
- }
745
- if (C(t))
746
- return document.getElementById(`${i}_editor`);
747
- const e = M(i);
748
- return S(e, ({ element: r }) => r);
749
- }
750
- function A(i, t) {
751
- if (t === "decoupled") {
752
- const { content: n } = N(i);
753
- if (typeof n == "string")
754
- return {
755
- main: n
756
- };
757
- }
758
- const e = M(i), r = S(e, ({ content: n }) => n);
759
- return K(r, (n) => typeof n == "string");
749
+ } : n ? {
750
+ ...t,
751
+ main: {
752
+ element: n,
753
+ content: r?.main || null
754
+ }
755
+ } : t;
760
756
  }
761
- function N(i) {
762
- const t = M(i).main;
763
- if (!t)
764
- throw new Error(`No "main" editable found for editor with ID "${i}".`);
765
- return t;
757
+ function L(i) {
758
+ const t = q(i), e = O(t, ({ content: r }) => r);
759
+ return _(e, (r) => typeof r == "string");
766
760
  }
767
- function x(i) {
761
+ function T(i) {
768
762
  if (!i || typeof i != "object")
769
763
  return i;
770
764
  if (Array.isArray(i))
771
- return i.map((r) => x(r));
765
+ return i.map((r) => T(r));
772
766
  const t = i;
773
767
  if (t.$element && typeof t.$element == "string") {
774
768
  const r = document.querySelector(t.$element);
@@ -776,21 +770,21 @@ function x(i) {
776
770
  }
777
771
  const e = /* @__PURE__ */ Object.create(null);
778
772
  for (const [r, n] of Object.entries(i))
779
- e[r] = x(n);
773
+ e[r] = T(n);
780
774
  return e;
781
775
  }
782
- function rt(i, t) {
776
+ function et(i, t) {
783
777
  const { editing: e } = i;
784
778
  e.view.change((r) => {
785
779
  r.setStyle("height", `${t}px`, e.view.document.getRoot());
786
780
  });
787
781
  }
788
- const D = Symbol.for("elixir-editor-watchdog");
789
- async function it(i) {
782
+ const x = Symbol.for("elixir-editor-watchdog");
783
+ async function rt(i) {
790
784
  const { EditorWatchdog: t } = await import("ckeditor5"), e = new t(i);
791
785
  return e.setCreator(async (...r) => {
792
786
  const n = await i.create(...r);
793
- return n[D] = e, n;
787
+ return n[x] = e, n;
794
788
  }), {
795
789
  watchdog: e,
796
790
  Constructor: {
@@ -798,13 +792,13 @@ async function it(i) {
798
792
  }
799
793
  };
800
794
  }
801
- function nt(i) {
802
- return D in i ? i[D] : null;
795
+ function it(i) {
796
+ return x in i ? i[x] : null;
803
797
  }
804
798
  class y extends H {
805
799
  static the = new y();
806
800
  }
807
- class at extends v {
801
+ class nt extends C {
808
802
  /**
809
803
  * The promise that resolves to the context instance.
810
804
  */
@@ -813,10 +807,10 @@ class at extends v {
813
807
  * Mounts the context component.
814
808
  */
815
809
  async mounted() {
816
- const { contextId: t, language: e, context: r } = this.canonical, { customTranslations: n, watchdogConfig: a, config: { plugins: s, ...o } } = r, { loadedPlugins: c, hasPremium: u } = await F(s ?? []), h = [
810
+ const { contextId: t, language: e, context: r } = this.canonical, { customTranslations: n, watchdogConfig: a, config: { plugins: s, ...o } } = r, { loadedPlugins: c, hasPremium: u } = await A(s ?? []), h = [
817
811
  ...await V(e, u),
818
- q(n || {})
819
- ].filter((d) => !j(d));
812
+ j(n || {})
813
+ ].filter((d) => !W(d));
820
814
  this.contextPromise = (async () => {
821
815
  const { ContextWatchdog: d, Context: g } = await import("ckeditor5"), p = new d(g, {
822
816
  crashNumberLimit: 10,
@@ -852,7 +846,7 @@ class at extends v {
852
846
  class w extends H {
853
847
  static the = new w();
854
848
  }
855
- class st extends v {
849
+ class at extends C {
856
850
  /**
857
851
  * The promise that resolves when the editable is mounted.
858
852
  */
@@ -879,13 +873,13 @@ class st extends v {
879
873
  data: r
880
874
  }
881
875
  });
882
- const l = this.element.querySelector("[data-cke-editable-content]"), h = o.view.createEditable(e, l);
876
+ const m = this.element.querySelector("[data-cke-editable-content]"), h = o.view.createEditable(e, m);
883
877
  o.addEditable(h), c.view.forceRender();
884
878
  const f = () => {
885
879
  const d = s.getData({ rootName: e });
886
880
  a && (a.value = d), this.$wire.set("content", d);
887
881
  };
888
- return s.model.document.on("change:data", O(n, f)), f(), s;
882
+ return s.model.document.on("change:data", D(n, f)), f(), s;
889
883
  });
890
884
  }
891
885
  /**
@@ -910,7 +904,7 @@ class st extends v {
910
904
  }
911
905
  }
912
906
  }
913
- async function ot({
907
+ async function st({
914
908
  saveDebounceMs: i,
915
909
  component: t
916
910
  }) {
@@ -936,7 +930,7 @@ async function ot({
936
930
  let o = null;
937
931
  n.on("afterCommitSynced", () => {
938
932
  const { content: c } = t.canonical, u = this.getEditorRootsValues();
939
- if (Z(t.element)) {
933
+ if (Q(t.element)) {
940
934
  if (s.isFocused) {
941
935
  P(c, u) || (o = c);
942
936
  return;
@@ -946,8 +940,8 @@ async function ot({
946
940
  }), Livewire.on("set-editor-content", ({ editorId: c, content: u }) => {
947
941
  if (c !== t.canonical.editorId)
948
942
  return;
949
- const l = this.getEditorRootsValues();
950
- P(l, u) || n.setData(u);
943
+ const m = this.getEditorRootsValues();
944
+ P(m, u) || n.setData(u);
951
945
  }), a.document.on("change:data", () => {
952
946
  o = null;
953
947
  }), s.on("change:isFocused", () => {
@@ -965,7 +959,7 @@ async function ot({
965
959
  content: o
966
960
  }));
967
961
  };
968
- n.document.on("change:data", O(i, s)), this.editor.once("ready", s);
962
+ n.document.on("change:data", D(i, s)), this.editor.once("ready", s);
969
963
  }
970
964
  /**
971
965
  * Setups the event push for the editor.
@@ -981,11 +975,11 @@ async function ot({
981
975
  * Gets the current values of all editor roots.
982
976
  */
983
977
  getEditorRootsValues() {
984
- return Q(this.editor);
978
+ return J(this.editor);
985
979
  }
986
980
  };
987
981
  }
988
- async function ct(i) {
982
+ async function ot(i) {
989
983
  const { Plugin: t } = await import("ckeditor5");
990
984
  return class extends t {
991
985
  /**
@@ -1007,7 +1001,7 @@ async function ct(i) {
1007
1001
  */
1008
1002
  afterInit() {
1009
1003
  const { editor: r } = this, a = r.sourceElement.id.replace(/_editor$/, "");
1010
- this.input = document.getElementById(`${a}_input`), this.input && (r.model.document.on("change:data", O(i, () => this.sync())), r.once("ready", this.sync), this.form = this.input.closest("form"), this.form?.addEventListener("submit", this.sync));
1004
+ this.input = document.getElementById(`${a}_input`), this.input && (r.model.document.on("change:data", D(i, () => this.sync())), r.once("ready", this.sync), this.form = this.input.closest("form"), this.form?.addEventListener("submit", this.sync));
1011
1005
  }
1012
1006
  /**
1013
1007
  * Synchronizes the editor's content with the input field.
@@ -1026,7 +1020,7 @@ async function ct(i) {
1026
1020
  }
1027
1021
  };
1028
1022
  }
1029
- class ut extends v {
1023
+ class ct extends C {
1030
1024
  /**
1031
1025
  * The promise that resolves to the editor instance.
1032
1026
  */
@@ -1057,7 +1051,7 @@ class ut extends v {
1057
1051
  const t = await this.editorPromise;
1058
1052
  if (!t)
1059
1053
  return;
1060
- const e = J(t), r = nt(t);
1054
+ const e = X(t), r = it(t);
1061
1055
  e ? e.state !== "unavailable" && await e.context.remove(e.editorContextId) : r ? await r.destroy() : await t.destroy();
1062
1056
  } finally {
1063
1057
  this.editorPromise = null;
@@ -1084,91 +1078,89 @@ class ut extends v {
1084
1078
  content: c
1085
1079
  } = this.canonical, {
1086
1080
  customTranslations: u,
1087
- editorType: l,
1081
+ editorType: m,
1088
1082
  licenseKey: h,
1089
1083
  config: { plugins: f, ...d }
1090
1084
  } = t;
1091
- let g = await tt(l);
1085
+ let g = await Z(m);
1092
1086
  const p = await (r ? y.the.waitFor(r) : null);
1093
1087
  if (o && !p) {
1094
- const m = await it(g);
1095
- ({ Constructor: g } = m), m.watchdog.on("restart", () => {
1096
- const k = m.watchdog.editor;
1088
+ const l = await rt(g);
1089
+ ({ Constructor: g } = l), l.watchdog.on("restart", () => {
1090
+ const k = l.watchdog.editor;
1097
1091
  this.editorPromise = Promise.resolve(k), w.the.register(e, k);
1098
1092
  });
1099
1093
  }
1100
- const { loadedPlugins: E, hasPremium: U } = await F(f);
1094
+ const { loadedPlugins: E, hasPremium: B } = await A(f);
1101
1095
  E.push(
1102
- await ot(
1096
+ await st(
1103
1097
  {
1104
1098
  saveDebounceMs: a,
1105
1099
  component: this
1106
1100
  }
1107
1101
  )
1108
- ), C(l) && E.push(
1109
- await ct(a)
1102
+ ), v(m) && E.push(
1103
+ await ot(a)
1110
1104
  );
1111
- const z = [
1112
- ...await V(s, U),
1113
- q(u || {})
1114
- ].filter((m) => !j(m));
1105
+ const $ = [
1106
+ ...await V(s, B),
1107
+ j(u || {})
1108
+ ].filter((l) => !W(l));
1115
1109
  let b = {
1116
1110
  ...c,
1117
- ...A(e, l)
1111
+ ...L(e)
1118
1112
  };
1119
- C(l) && (b = b.main || "");
1120
- const R = await (async () => {
1121
- let m = T(e, l);
1122
- if (mt(m, l)) {
1123
- const L = Object.keys(b);
1124
- B(m, L) || (m = await lt(e, l, L), b = {
1113
+ v(m) && (b = b.main || "");
1114
+ const M = await (async () => {
1115
+ let l = F(e);
1116
+ if (!(l instanceof HTMLElement) && !("main" in l)) {
1117
+ const z = m === "decoupled" ? ["main"] : Object.keys(b);
1118
+ N(l, z) || (l = await ut(e, z), b = {
1125
1119
  ...c,
1126
- ...A(e, l)
1120
+ ...L(e)
1127
1121
  });
1128
1122
  }
1123
+ v(m) && "main" in l && (l = l.main);
1129
1124
  const k = {
1130
- ...x(d),
1125
+ ...T(d),
1131
1126
  initialData: b,
1132
1127
  licenseKey: h,
1133
1128
  plugins: E,
1134
1129
  language: s,
1135
- ...z.length && {
1136
- translations: z
1130
+ ...$.length && {
1131
+ translations: $
1137
1132
  }
1138
1133
  };
1139
- return !p || !(m instanceof HTMLElement) ? g.create(m, k) : (await X({
1134
+ return !p || !(l instanceof HTMLElement) ? g.create(l, k) : (await Y({
1140
1135
  context: p,
1141
- element: m,
1136
+ element: l,
1142
1137
  creator: g,
1143
1138
  config: k
1144
1139
  })).editor;
1145
1140
  })();
1146
- return C(l) && n && rt(R, n), R;
1141
+ return v(m) && n && et(M, n), M;
1147
1142
  }
1148
1143
  }
1149
- function B(i, t) {
1144
+ function N(i, t) {
1150
1145
  return t.every((e) => i[e]);
1151
1146
  }
1152
- async function lt(i, t, e) {
1153
- return await Y(
1147
+ async function ut(i, t) {
1148
+ return G(
1154
1149
  () => {
1155
- const r = T(i, t);
1156
- if (!B(r, e))
1150
+ const e = F(i);
1151
+ if (!N(e, t))
1157
1152
  throw new Error(
1158
1153
  `It looks like not all required root elements are present yet.
1159
1154
  * If you want to wait for them, ensure they are registered before editor initialization.
1160
1155
  * If you want lazy initialize roots, consider removing root values from the \`initialData\` config and assign initial data in editable components.
1161
- Missing roots: ${e.filter((n) => !r[n]).join(", ")}.`
1156
+ Missing roots: ${t.filter((r) => !e[r]).join(", ")}.`
1162
1157
  );
1163
- return !0;
1158
+ return e;
1164
1159
  },
1165
1160
  { timeOutAfter: 2e3, retryAfter: 100 }
1166
- ), T(i, t);
1167
- }
1168
- function mt(i, t) {
1169
- return !C(t) && typeof i == "object" && !(i instanceof HTMLElement);
1161
+ );
1170
1162
  }
1171
- class dt extends v {
1163
+ class lt extends C {
1172
1164
  /**
1173
1165
  * The promise that resolves when the UI part is mounted.
1174
1166
  */
@@ -1179,7 +1171,7 @@ class dt extends v {
1179
1171
  async mounted() {
1180
1172
  const { editorId: t, name: e } = this.canonical;
1181
1173
  this.mountedPromise = w.the.execute(t, (r) => {
1182
- const { ui: n } = r, a = wt(e), s = n.view[a];
1174
+ const { ui: n } = r, a = mt(e), s = n.view[a];
1183
1175
  if (!s) {
1184
1176
  console.error(`Unknown UI part name: "${e}". Supported names are "toolbar" and "menubar".`);
1185
1177
  return;
@@ -1194,7 +1186,7 @@ class dt extends v {
1194
1186
  this.element.style.display = "none", await this.mountedPromise, this.mountedPromise = null, this.element.innerHTML = "";
1195
1187
  }
1196
1188
  }
1197
- function wt(i) {
1189
+ function mt(i) {
1198
1190
  switch (i) {
1199
1191
  case "toolbar":
1200
1192
  return "toolbar";
@@ -1204,15 +1196,15 @@ function wt(i) {
1204
1196
  return null;
1205
1197
  }
1206
1198
  }
1207
- const pt = {
1208
- ckeditor5: ut,
1209
- "ckeditor5-context": at,
1210
- "ckeditor5-ui-part": dt,
1211
- "ckeditor5-editable": st
1199
+ const dt = {
1200
+ ckeditor5: ct,
1201
+ "ckeditor5-context": nt,
1202
+ "ckeditor5-ui-part": lt,
1203
+ "ckeditor5-editable": at
1212
1204
  };
1213
- function ht() {
1214
- for (const [i, t] of Object.entries(pt))
1215
- _(i, t);
1205
+ function wt() {
1206
+ for (const [i, t] of Object.entries(dt))
1207
+ U(i, t);
1216
1208
  }
1217
- ht();
1209
+ wt();
1218
1210
  //# sourceMappingURL=index.mjs.map