ckeditor5-livewire 1.4.0 → 1.4.1

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
@@ -95,11 +95,11 @@ class L {
95
95
  */
96
96
  execute(t, e, r) {
97
97
  const n = this.items.get(t), a = this.initializationErrors.get(t);
98
- return a ? (r?.(a), Promise.reject(a)) : n ? Promise.resolve(e(n)) : new Promise((o, s) => {
98
+ return a ? (r?.(a), Promise.reject(a)) : n ? Promise.resolve(e(n)) : new Promise((s, o) => {
99
99
  const c = this.getPendingCallbacks(t);
100
100
  c.success.push(async (u) => {
101
- o(await e(u));
102
- }), r ? c.error.push(r) : c.error.push(s);
101
+ s(await e(u));
102
+ }), r ? c.error.push(r) : c.error.push(o);
103
103
  });
104
104
  }
105
105
  /**
@@ -272,15 +272,15 @@ function Y(i, {
272
272
  } = {}) {
273
273
  return new Promise((r, n) => {
274
274
  const a = Date.now();
275
- let o = null;
276
- const s = setTimeout(() => {
277
- n(o ?? new Error("Timeout"));
275
+ let s = null;
276
+ const o = setTimeout(() => {
277
+ n(s ?? new Error("Timeout"));
278
278
  }, t), c = async () => {
279
279
  try {
280
280
  const u = await i();
281
- clearTimeout(s), r(u);
281
+ clearTimeout(o), r(u);
282
282
  } catch (u) {
283
- o = u, Date.now() - a > t ? n(u) : setTimeout(c, e);
283
+ s = u, Date.now() - a > t ? n(u) : setTimeout(c, e);
284
284
  }
285
285
  };
286
286
  c();
@@ -296,15 +296,15 @@ async function X({ element: i, context: t, creator: e, config: r }) {
296
296
  type: "editor",
297
297
  config: r
298
298
  });
299
- const a = t.getItem(n), o = {
299
+ const a = t.getItem(n), s = {
300
300
  state: "available",
301
301
  editorContextId: n,
302
302
  context: t
303
303
  };
304
- a[D] = o;
305
- const s = t.destroy.bind(t);
306
- return t.destroy = async () => (o.state = "unavailable", s()), {
307
- ...o,
304
+ a[D] = s;
305
+ const o = t.destroy.bind(t);
306
+ return t.destroy = async () => (s.state = "unavailable", o()), {
307
+ ...s,
308
308
  editor: a
309
309
  };
310
310
  }
@@ -406,18 +406,18 @@ async function W(i) {
406
406
  const a = await S.the.get(n);
407
407
  if (a)
408
408
  return a;
409
- const { [n]: o } = t;
410
- if (o)
411
- return o;
409
+ const { [n]: s } = t;
410
+ if (s)
411
+ return s;
412
412
  if (!e)
413
413
  try {
414
414
  e = await import("ckeditor5-premium-features");
415
415
  } catch (c) {
416
416
  console.error(`Failed to load premium package: ${c}`);
417
417
  }
418
- const { [n]: s } = e || {};
419
- if (s)
420
- return s;
418
+ const { [n]: o } = e || {};
419
+ if (o)
420
+ return o;
421
421
  throw new Error(`Plugin "${n}" not found in base or premium packages.`);
422
422
  });
423
423
  return {
@@ -429,13 +429,13 @@ async function V(i, t) {
429
429
  const e = [i.ui, i.content];
430
430
  return await Promise.all(
431
431
  [
432
- R("ckeditor5", e),
432
+ M("ckeditor5", e),
433
433
  /* v8 ignore next */
434
- t && R("ckeditor5-premium-features", e)
434
+ t && M("ckeditor5-premium-features", e)
435
435
  ].filter((n) => !!n)
436
436
  ).then((n) => n.flat());
437
437
  }
438
- async function R(i, t) {
438
+ async function M(i, t) {
439
439
  return await Promise.all(
440
440
  t.filter((e) => e !== "en").map(async (e) => {
441
441
  const r = await tt(i, e);
@@ -753,13 +753,13 @@ function j(i) {
753
753
  return O(t, ({ element: e }) => e);
754
754
  }
755
755
  function N(i) {
756
- const t = window.Livewire.all().filter(({ name: o, canonical: s }) => o === "ckeditor5-editable" && s.editorId === i).reduce((o, { canonical: s, el: c }) => ({
757
- ...o,
758
- [s.rootName]: {
756
+ const t = window.Livewire.all().filter(({ name: s, canonical: o }) => s === "ckeditor5-editable" && o.editorId === i).reduce((s, { canonical: o, el: c }) => ({
757
+ ...s,
758
+ [o.rootName]: {
759
759
  element: c.querySelector("[data-cke-editable-content]"),
760
- content: s.content
760
+ content: o.content
761
761
  }
762
- }), /* @__PURE__ */ Object.create({})), r = window.Livewire.all().find(({ name: o, canonical: s }) => o === "ckeditor5" && s.editorId === i)?.canonical.content, n = document.querySelector(`#${i}_editor `), a = t.main;
762
+ }), /* @__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;
763
763
  return a && r?.main ? {
764
764
  ...t,
765
765
  main: {
@@ -815,8 +815,8 @@ async function rt(i) {
815
815
  function it(i) {
816
816
  return T in i ? i[T] : null;
817
817
  }
818
- class p extends L {
819
- static the = new p();
818
+ class w extends L {
819
+ static the = new w();
820
820
  }
821
821
  class nt extends P {
822
822
  /**
@@ -827,17 +827,17 @@ class nt extends P {
827
827
  * Mounts the context component.
828
828
  */
829
829
  async mounted() {
830
- const { contextId: t, language: e, context: r } = this.canonical, { customTranslations: n, watchdogConfig: a, config: { plugins: o, ...s } } = r, { loadedPlugins: c, hasPremium: u } = await W(o ?? []), C = [
830
+ const { contextId: t, language: e, context: r } = this.canonical, { customTranslations: n, watchdogConfig: a, config: { plugins: s, ...o } } = r, { loadedPlugins: c, hasPremium: u } = await W(s ?? []), C = [
831
831
  ...await V(e, u),
832
832
  B(n || {})
833
833
  ].filter((f) => !A(f));
834
834
  this.contextPromise = (async () => {
835
- const { ContextWatchdog: f, Context: w } = await import("ckeditor5"), h = new f(w, {
835
+ const { ContextWatchdog: f, Context: p } = await import("ckeditor5"), h = new f(p, {
836
836
  crashNumberLimit: 10,
837
837
  ...a
838
838
  });
839
839
  return await h.create({
840
- ...s,
840
+ ...o,
841
841
  language: e,
842
842
  plugins: c,
843
843
  ...C.length && {
@@ -848,7 +848,7 @@ class nt extends P {
848
848
  }), h;
849
849
  })();
850
850
  const v = await this.contextPromise;
851
- this.isBeingDestroyed() || p.the.register(t, v);
851
+ this.isBeingDestroyed() || w.the.register(t, v);
852
852
  }
853
853
  /**
854
854
  * Destroys the context component. Unmounts root from the editor.
@@ -859,12 +859,12 @@ class nt extends P {
859
859
  try {
860
860
  await (await this.contextPromise)?.destroy();
861
861
  } finally {
862
- this.contextPromise = null, p.the.hasItem(t) && p.the.unregister(t);
862
+ this.contextPromise = null, w.the.hasItem(t) && w.the.unregister(t);
863
863
  }
864
864
  }
865
865
  }
866
- class m extends L {
867
- static the = new m();
866
+ class d extends L {
867
+ static the = new d();
868
868
  }
869
869
  class at extends P {
870
870
  /**
@@ -880,11 +880,11 @@ class at extends P {
880
880
  */
881
881
  mounted() {
882
882
  const { editorId: t, rootName: e, content: r } = this.canonical;
883
- this.editorPromise = m.the.execute(t, (n) => {
883
+ this.editorPromise = d.the.execute(t, (n) => {
884
884
  if (this.isBeingDestroyed())
885
885
  return null;
886
- const { ui: a, editing: o, model: s } = n;
887
- if (s.document.getRoot(e)) {
886
+ const { ui: a, editing: s, model: o } = n;
887
+ if (o.document.getRoot(e)) {
888
888
  if (r !== null) {
889
889
  const c = n.getData({ rootName: e });
890
890
  c && c !== r && n.setData({
@@ -899,7 +899,7 @@ class at extends P {
899
899
  }
900
900
  });
901
901
  const c = this.element.querySelector("[data-cke-editable-content]"), u = a.view.createEditable(e, c);
902
- a.addEditable(u), o.view.forceRender();
902
+ a.addEditable(u), s.view.forceRender();
903
903
  }
904
904
  return this.syncTypingContentPush(n), this.setupPendingReceivedContentHandlers(n), n;
905
905
  });
@@ -909,11 +909,11 @@ class at extends P {
909
909
  */
910
910
  syncTypingContentPush(t) {
911
911
  const { rootName: e, saveDebounceMs: r } = this.canonical, n = this.element.querySelector("input"), a = () => {
912
- const s = t.getData({ rootName: e });
913
- n && (n.value = s), this.$wire.set("content", s);
914
- }, o = x(r, a);
915
- t.model.document.on("change:data", o), a(), this.onBeforeDestroy(() => {
916
- t.model.document.off("change:data", o);
912
+ const o = t.getData({ rootName: e });
913
+ n && (n.value = o), this.$wire.set("content", o);
914
+ }, s = x(r, a);
915
+ t.model.document.on("change:data", s), a(), this.onBeforeDestroy(() => {
916
+ t.model.document.off("change:data", s);
917
917
  });
918
918
  }
919
919
  /**
@@ -921,15 +921,15 @@ class at extends P {
921
921
  * content on user edits and applies pending content on blur).
922
922
  */
923
923
  setupPendingReceivedContentHandlers(t) {
924
- const { ui: e, model: r } = t, { focusTracker: n } = e, { rootName: a } = this.canonical, o = () => {
924
+ const { ui: e, model: r } = t, { focusTracker: n } = e, { rootName: a } = this.canonical, s = () => {
925
925
  this.pendingContent = null;
926
- }, s = () => {
926
+ }, o = () => {
927
927
  !n.isFocused && this.pendingContent !== null && (t.setData({
928
928
  [a]: this.pendingContent
929
929
  }), this.pendingContent = null);
930
930
  };
931
- r.document.on("change:data", o), n.on("change:isFocused", s), this.onBeforeDestroy(() => {
932
- r.document.off("change:data", o), n.off("change:isFocused", s);
931
+ r.document.on("change:data", s), n.on("change:isFocused", o), this.onBeforeDestroy(() => {
932
+ r.document.off("change:data", s), n.off("change:isFocused", o);
933
933
  });
934
934
  }
935
935
  /**
@@ -967,7 +967,7 @@ class at extends P {
967
967
  }
968
968
  }
969
969
  }
970
- async function ot({
970
+ async function st({
971
971
  saveDebounceMs: i,
972
972
  component: t
973
973
  }) {
@@ -983,7 +983,7 @@ async function ot({
983
983
  * Initializes the plugin.
984
984
  */
985
985
  init() {
986
- this.setupTypingContentPush(), this.setupFocusableEventPush(), this.setupAfterCommitHandler(), this.setupSetEditorContentHandler();
986
+ this.setupTypingContentPush(), this.setupFocusableEventPush(), this.setupAfterCommitHandler(), this.setupSetEditorContentHandler(), this.setupReadyDispatch();
987
987
  }
988
988
  /**
989
989
  * Setups handler that updates the editor content after Livewire changes attributes
@@ -991,21 +991,36 @@ async function ot({
991
991
  * disrupting the user while editing.
992
992
  */
993
993
  setupAfterCommitHandler() {
994
- const { editor: n } = this, { model: a, ui: { focusTracker: o } } = n;
995
- let s = null;
994
+ const { editor: n } = this, { model: a, ui: { focusTracker: s } } = n;
995
+ let o = null;
996
996
  n.on("afterCommitSynced", () => {
997
997
  if (!F(t.element))
998
998
  return;
999
999
  const { content: c } = t.canonical, u = this.getEditorRootsValues();
1000
- if (o.isFocused) {
1001
- b(c, u) || (s = c);
1000
+ if (s.isFocused) {
1001
+ b(c, u) || (o = c);
1002
1002
  return;
1003
1003
  }
1004
1004
  b(c, u) || n.setData(c);
1005
1005
  }), a.document.on("change:data", () => {
1006
- s = null;
1007
- }), o.on("change:isFocused", () => {
1008
- !o.isFocused && s !== null && (n.setData(s), s = null);
1006
+ o = null;
1007
+ }), s.on("change:isFocused", () => {
1008
+ !s.isFocused && o !== null && (n.setData(o), o = null);
1009
+ });
1010
+ }
1011
+ /**
1012
+ * Dispatches a Livewire event when the editor becomes ready.
1013
+ *
1014
+ * This allows the Livewire component or parent to react as soon as the
1015
+ * instance is fully initialized. The payload contains the editorId so the
1016
+ * listener can ignore events coming from other editors on the page.
1017
+ */
1018
+ setupReadyDispatch() {
1019
+ const { $wire: n } = t;
1020
+ this.editor.once("ready", () => {
1021
+ n.dispatch("editor-ready", {
1022
+ editorId: t.canonical.editorId
1023
+ });
1009
1024
  });
1010
1025
  }
1011
1026
  /**
@@ -1015,32 +1030,32 @@ async function ot({
1015
1030
  Livewire.on("set-editor-content", ({ editorId: n, content: a }) => {
1016
1031
  if (n !== t.canonical.editorId)
1017
1032
  return;
1018
- const o = this.getEditorRootsValues();
1019
- b(o, a) || this.editor.setData(a);
1033
+ const s = this.getEditorRootsValues();
1034
+ b(s, a) || this.editor.setData(a);
1020
1035
  });
1021
1036
  }
1022
1037
  /**
1023
1038
  * Setups the content push event for the editor.
1024
1039
  */
1025
1040
  setupTypingContentPush() {
1026
- const { model: n } = this.editor, { $wire: a } = t, o = () => {
1027
- const s = this.getEditorRootsValues();
1028
- b(s, t.canonical.content ?? {}) || (a.set("content", s), a.dispatch("editor-content-changed", {
1041
+ const { model: n } = this.editor, { $wire: a } = t, s = () => {
1042
+ const o = this.getEditorRootsValues();
1043
+ b(o, t.canonical.content ?? {}) || (a.set("content", o), a.dispatch("editor-content-changed", {
1029
1044
  editorId: t.canonical.editorId,
1030
- content: s
1045
+ content: o
1031
1046
  }));
1032
1047
  };
1033
- n.document.on("change:data", x(i, o)), this.editor.once("ready", o);
1048
+ n.document.on("change:data", x(i, s)), this.editor.once("ready", s);
1034
1049
  }
1035
1050
  /**
1036
1051
  * Setups the event push for the editor.
1037
1052
  */
1038
1053
  setupFocusableEventPush() {
1039
- const { ui: n } = this.editor, { $wire: a } = t, o = () => {
1040
- const s = this.getEditorRootsValues();
1041
- a.set("focused", n.focusTracker.isFocused), b(s, t.canonical.content ?? {}) || a.set("content", s);
1054
+ const { ui: n } = this.editor, { $wire: a } = t, s = () => {
1055
+ const o = this.getEditorRootsValues();
1056
+ a.set("focused", n.focusTracker.isFocused), b(o, t.canonical.content ?? {}) || a.set("content", o);
1042
1057
  };
1043
- n.focusTracker.on("change:isFocused", o);
1058
+ n.focusTracker.on("change:isFocused", s);
1044
1059
  }
1045
1060
  /**
1046
1061
  * Gets the current values of all editor roots.
@@ -1050,7 +1065,7 @@ async function ot({
1050
1065
  }
1051
1066
  };
1052
1067
  }
1053
- async function st(i) {
1068
+ async function ot(i) {
1054
1069
  const { Plugin: t } = await import("ckeditor5");
1055
1070
  return class extends t {
1056
1071
  /**
@@ -1101,15 +1116,15 @@ class ct extends P {
1101
1116
  */
1102
1117
  async mounted() {
1103
1118
  const { editorId: t } = this.canonical;
1104
- m.the.resetErrors(t);
1119
+ d.the.resetErrors(t);
1105
1120
  try {
1106
1121
  this.editorPromise = this.createEditor();
1107
1122
  const e = await this.editorPromise;
1108
- this.isBeingDestroyed() || (m.the.register(t, e), e.once("destroy", () => {
1109
- m.the.hasItem(t) && m.the.unregister(t);
1123
+ this.isBeingDestroyed() || (d.the.register(t, e), e.once("destroy", () => {
1124
+ d.the.hasItem(t) && d.the.unregister(t);
1110
1125
  }));
1111
1126
  } catch (e) {
1112
- console.error(`Error initializing CKEditor5 instance with ID "${t}":`, e), this.editorPromise = null, m.the.error(t, e);
1127
+ console.error(`Error initializing CKEditor5 instance with ID "${t}":`, e), this.editorPromise = null, d.the.error(t, e);
1113
1128
  }
1114
1129
  }
1115
1130
  /**
@@ -1144,72 +1159,72 @@ class ct extends P {
1144
1159
  contextId: r,
1145
1160
  editableHeight: n,
1146
1161
  saveDebounceMs: a,
1147
- language: o,
1148
- watchdog: s,
1162
+ language: s,
1163
+ watchdog: o,
1149
1164
  content: c
1150
1165
  } = this.canonical, {
1151
1166
  customTranslations: u,
1152
- editorType: d,
1167
+ editorType: m,
1153
1168
  licenseKey: C,
1154
1169
  config: { plugins: v, ...f }
1155
1170
  } = t;
1156
- let w = await Z(d);
1157
- const h = await (r ? p.the.waitFor(r) : null);
1158
- if (s && !h) {
1159
- const l = await rt(w);
1160
- ({ Constructor: w } = l), l.watchdog.on("restart", () => {
1171
+ let p = await Z(m);
1172
+ const h = await (r ? w.the.waitFor(r) : null);
1173
+ if (o && !h) {
1174
+ const l = await rt(p);
1175
+ ({ Constructor: p } = l), l.watchdog.on("restart", () => {
1161
1176
  const E = l.watchdog.editor;
1162
- this.editorPromise = Promise.resolve(E), m.the.register(e, E);
1177
+ this.editorPromise = Promise.resolve(E), d.the.register(e, E);
1163
1178
  });
1164
1179
  }
1165
1180
  const { loadedPlugins: g, hasPremium: _ } = await W(v);
1166
1181
  g.push(
1167
- await ot(
1182
+ await st(
1168
1183
  {
1169
1184
  saveDebounceMs: a,
1170
1185
  component: this
1171
1186
  }
1172
1187
  )
1173
- ), k(d) && g.push(
1174
- await st(a)
1188
+ ), k(m) && g.push(
1189
+ await ot(a)
1175
1190
  );
1176
1191
  const $ = [
1177
- ...await V(o, _),
1192
+ ...await V(s, _),
1178
1193
  B(u || {})
1179
1194
  ].filter((l) => !A(l));
1180
1195
  let y = {
1181
1196
  ...c,
1182
1197
  ...z(e)
1183
1198
  };
1184
- k(d) && (y = y.main || "");
1185
- const H = await (async () => {
1199
+ k(m) && (y = y.main || "");
1200
+ const R = await (async () => {
1186
1201
  let l = j(e);
1187
1202
  if (!(l instanceof HTMLElement) && !("main" in l)) {
1188
- const M = d === "decoupled" ? ["main"] : Object.keys(y);
1189
- q(l, M) || (l = await ut(e, M), y = {
1203
+ const H = m === "decoupled" ? ["main"] : Object.keys(y);
1204
+ q(l, H) || (l = await ut(e, H), y = {
1190
1205
  ...c,
1191
1206
  ...z(e)
1192
1207
  });
1193
1208
  }
1194
- k(d) && "main" in l && (l = l.main);
1209
+ k(m) && "main" in l && (l = l.main);
1195
1210
  const E = {
1196
1211
  ...I(f),
1197
1212
  initialData: y,
1198
1213
  licenseKey: C,
1199
1214
  plugins: g,
1200
- language: o,
1215
+ language: s,
1201
1216
  ...$.length && {
1202
1217
  translations: $
1203
1218
  }
1204
1219
  };
1205
- return !h || !(l instanceof HTMLElement) ? w.create(l, E) : (await X({
1220
+ return !h || !(l instanceof HTMLElement) ? p.create(l, E) : (await X({
1206
1221
  context: h,
1207
1222
  element: l,
1208
- creator: w,
1223
+ creator: p,
1209
1224
  config: E
1210
1225
  })).editor;
1211
1226
  })();
1212
- return k(d) && n && et(H, n), H;
1227
+ return k(m) && n && et(R, n), R;
1213
1228
  }
1214
1229
  }
1215
1230
  function q(i, t) {
@@ -1241,15 +1256,15 @@ class lt extends P {
1241
1256
  */
1242
1257
  async mounted() {
1243
1258
  const { editorId: t, name: e } = this.canonical;
1244
- this.mountedPromise = m.the.execute(t, (r) => {
1259
+ this.mountedPromise = d.the.execute(t, (r) => {
1245
1260
  if (this.isBeingDestroyed())
1246
1261
  return;
1247
- const { ui: n } = r, a = mt(e), o = n.view[a];
1248
- if (!o) {
1262
+ const { ui: n } = r, a = dt(e), s = n.view[a];
1263
+ if (!s) {
1249
1264
  console.error(`Unknown UI part name: "${e}". Supported names are "toolbar" and "menubar".`);
1250
1265
  return;
1251
1266
  }
1252
- this.element.appendChild(o.element);
1267
+ this.element.appendChild(s.element);
1253
1268
  });
1254
1269
  }
1255
1270
  /**
@@ -1259,7 +1274,7 @@ class lt extends P {
1259
1274
  this.element.style.display = "none", await this.mountedPromise, this.mountedPromise = null, this.element.innerHTML = "";
1260
1275
  }
1261
1276
  }
1262
- function mt(i) {
1277
+ function dt(i) {
1263
1278
  switch (i) {
1264
1279
  case "toolbar":
1265
1280
  return "toolbar";
@@ -1269,24 +1284,24 @@ function mt(i) {
1269
1284
  return null;
1270
1285
  }
1271
1286
  }
1272
- const dt = {
1287
+ const mt = {
1273
1288
  ckeditor5: ct,
1274
1289
  "ckeditor5-context": nt,
1275
1290
  "ckeditor5-ui-part": lt,
1276
1291
  "ckeditor5-editable": at
1277
1292
  };
1278
1293
  function ht() {
1279
- for (const [i, t] of Object.entries(dt))
1294
+ for (const [i, t] of Object.entries(mt))
1280
1295
  U(i, t);
1281
1296
  }
1282
1297
  ht();
1283
1298
  export {
1284
1299
  P as ClassHook,
1285
- p as ContextsRegistry,
1300
+ w as ContextsRegistry,
1286
1301
  S as CustomEditorPluginsRegistry,
1287
1302
  at as EditableComponentHook,
1288
1303
  ct as EditorComponentHook,
1289
- m as EditorsRegistry,
1304
+ d as EditorsRegistry,
1290
1305
  lt as UIPartComponentHook,
1291
1306
  U as registerLivewireComponentHook
1292
1307
  };