ckeditor5-blazor 1.1.0 → 1.2.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
@@ -3,7 +3,7 @@ class b extends Error {
3
3
  super(t), this.name = "CKEditor5BlazorError";
4
4
  }
5
5
  }
6
- class j {
6
+ class _ {
7
7
  /**
8
8
  * Map of registered items.
9
9
  */
@@ -273,7 +273,7 @@ function M(r) {
273
273
  disconnect: () => t?.disconnect()
274
274
  };
275
275
  }
276
- function D(r) {
276
+ function O(r) {
277
277
  r.setAttribute("data-cke-interactive", "true");
278
278
  }
279
279
  const x = /* @__PURE__ */ Symbol.for("context-editor-watchdog");
@@ -301,7 +301,7 @@ async function nt({ element: r, context: t, creator: e, config: i }) {
301
301
  function ot(r) {
302
302
  return x in r ? r[x] : 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
307
  function A(r) {
@@ -319,8 +319,8 @@ async function L(r) {
319
319
  throw new b(`Unsupported editor type: ${r}`);
320
320
  return i;
321
321
  }
322
- class $ {
323
- static the = new $();
322
+ class R {
323
+ static the = new R();
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 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
- const n = await $.the.get(a);
386
+ const n = await R.the.get(a);
387
387
  if (n)
388
388
  return n;
389
389
  const { [a]: o } = t;
@@ -405,17 +405,17 @@ async function J(r) {
405
405
  hasPremium: !!e
406
406
  };
407
407
  }
408
- async function U(r, t) {
408
+ async function J(r, t) {
409
409
  const e = [r.ui, r.content];
410
410
  return await Promise.all(
411
411
  [
412
- F("ckeditor5", e),
412
+ q("ckeditor5", e),
413
413
  /* v8 ignore next -- @preserve */
414
- t && F("ckeditor5-premium-features", e)
414
+ t && q("ckeditor5-premium-features", e)
415
415
  ].filter((a) => !!a)
416
416
  ).then((a) => a.flat());
417
417
  }
418
- async function F(r, t) {
418
+ async function q(r, t) {
419
419
  return await Promise.all(
420
420
  t.filter((e) => e !== "en").map(async (e) => {
421
421
  const i = await st(r, e);
@@ -735,7 +735,7 @@ function Y(r) {
735
735
  const t = X(r);
736
736
  return V(t, ({ element: e }) => e);
737
737
  }
738
- function _(r) {
738
+ function U(r) {
739
739
  const t = X(r), e = V(t, ({ content: i }) => i);
740
740
  return et(e, (i) => typeof i == "string");
741
741
  }
@@ -823,7 +823,7 @@ async function lt(r) {
823
823
  function dt(r) {
824
824
  return N in r ? r[N] : null;
825
825
  }
826
- class v extends j {
826
+ class v extends _ {
827
827
  static the = new v();
828
828
  }
829
829
  class mt extends HTMLElement {
@@ -845,8 +845,8 @@ class mt extends HTMLElement {
845
845
  * Initializes the context component.
846
846
  */
847
847
  async initializeContext() {
848
- 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 ?? []), p = [
849
- ...await U(e, s),
848
+ 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 H(o ?? []), p = [
849
+ ...await J(e, s),
850
850
  K(a || {})
851
851
  ].filter((f) => !B(f));
852
852
  this.contextPromise = (async () => {
@@ -862,8 +862,8 @@ class mt extends HTMLElement {
862
862
  ...p.length && {
863
863
  translations: p
864
864
  }
865
- }), h.on("itemError", (...O) => {
866
- console.error("Context item error:", ...O);
865
+ }), h.on("itemError", (...D) => {
866
+ console.error("Context item error:", ...D);
867
867
  }), h;
868
868
  })();
869
869
  const E = await this.contextPromise;
@@ -883,7 +883,7 @@ class mt extends HTMLElement {
883
883
  }
884
884
  }
885
885
  }
886
- class m extends j {
886
+ class m extends _ {
887
887
  static the = new m();
888
888
  }
889
889
  class ht extends HTMLElement {
@@ -1006,7 +1006,7 @@ async function pt({
1006
1006
  new g({
1007
1007
  editorId: t,
1008
1008
  editor: n,
1009
- roots: H(n)
1009
+ roots: j(n)
1010
1010
  })
1011
1011
  );
1012
1012
  };
@@ -1128,7 +1128,7 @@ class ft extends HTMLElement {
1128
1128
  this.editorPromise = Promise.resolve(k), m.the.register(t, k);
1129
1129
  });
1130
1130
  }
1131
- const { loadedPlugins: y, hasPremium: O } = await J(E);
1131
+ const { loadedPlugins: y, hasPremium: D } = await H(E);
1132
1132
  y.push(
1133
1133
  await pt({
1134
1134
  saveDebounceMs: n,
@@ -1139,21 +1139,21 @@ class ft extends HTMLElement {
1139
1139
  await wt(n)
1140
1140
  );
1141
1141
  const S = [
1142
- ...await U(o, O),
1142
+ ...await J(o, D),
1143
1143
  K(s || {})
1144
1144
  ].filter((d) => !B(d));
1145
1145
  let C = {
1146
1146
  ...u,
1147
- ..._(t)
1147
+ ...U(t)
1148
1148
  };
1149
1149
  A(l) && (C = C.main || "");
1150
- const R = await (async () => {
1150
+ const $ = await (async () => {
1151
1151
  let d = Y(t);
1152
1152
  if (!d.main) {
1153
- const q = A(l) ? ["main"] : Object.keys(C);
1154
- Q(d, q) || (d = await gt(t, q), C = {
1153
+ const F = A(l) ? ["main"] : Object.keys(C);
1154
+ Q(d, F) || (d = await gt(t, F), C = {
1155
1155
  ...u,
1156
- ..._(t)
1156
+ ...U(t)
1157
1157
  });
1158
1158
  }
1159
1159
  A(l) && "main" in d && (d = d.main);
@@ -1176,7 +1176,7 @@ class ft extends HTMLElement {
1176
1176
  config: W
1177
1177
  })).editor;
1178
1178
  })();
1179
- return A(l) && a && ut(R, a), R;
1179
+ return A(l) && a && ut($, a), $;
1180
1180
  }
1181
1181
  }
1182
1182
  function Q(r, t) {
@@ -1246,8 +1246,8 @@ function kt() {
1246
1246
  for (const [r, t] of Object.entries(Et))
1247
1247
  window.customElements.get(r) || window.customElements.define(r, t);
1248
1248
  }
1249
- function Tt(r) {
1250
- return D(r), {
1249
+ function Ot(r) {
1250
+ return O(r), {
1251
1251
  unmount() {
1252
1252
  }
1253
1253
  };
@@ -1309,7 +1309,7 @@ function tt() {
1309
1309
  }
1310
1310
  };
1311
1311
  }
1312
- function It(r, t) {
1312
+ function Dt(r, t) {
1313
1313
  const e = r.getAttribute("data-cke-editor-id"), i = r.getAttribute("data-cke-root-name") ?? "main";
1314
1314
  let a = !1, n = tt(), o = null;
1315
1315
  const c = (s) => {
@@ -1325,7 +1325,7 @@ function It(r, t) {
1325
1325
  applyValue: (l) => s.setData({ [i]: l }),
1326
1326
  isEqual: (l, p) => l === p
1327
1327
  });
1328
- })(), document.body.addEventListener(g.EVENT_NAME, c), D(r), {
1328
+ })(), document.body.addEventListener(g.EVENT_NAME, c), O(r), {
1329
1329
  /**
1330
1330
  * Cleans up all event listeners when the Blazor component is disposed.
1331
1331
  */
@@ -1341,7 +1341,7 @@ function It(r, t) {
1341
1341
  }
1342
1342
  };
1343
1343
  }
1344
- function Dt(r, t) {
1344
+ function St(r, t) {
1345
1345
  const e = r.getAttribute("data-cke-editor-id");
1346
1346
  let i = !1, a = null, n = tt(), o = null;
1347
1347
  const c = (s) => {
@@ -1350,7 +1350,7 @@ function Dt(r, t) {
1350
1350
  return (async () => {
1351
1351
  const s = await m.the.waitFor(e);
1352
1352
  o = globalThis.DotNet.createJSObjectReference(s), n = Z(s, {
1353
- getCurrentValue: () => H(s),
1353
+ getCurrentValue: () => j(s),
1354
1354
  applyValue: (p) => s.setData(p),
1355
1355
  isEqual: rt
1356
1356
  });
@@ -1361,7 +1361,7 @@ function Dt(r, t) {
1361
1361
  s.ui.focusTracker.on("change:isFocused", l), t.invokeMethodAsync("OnEditorReady", o), a = () => {
1362
1362
  s.ui.focusTracker.off("change:isFocused", l);
1363
1363
  };
1364
- })(), document.body.addEventListener(g.EVENT_NAME, c), kt(), D(r), {
1364
+ })(), document.body.addEventListener(g.EVENT_NAME, c), kt(), O(r), {
1365
1365
  /**
1366
1366
  * Updates the editor data from Blazor. If the editor is focused, the update is deferred until blur to avoid interrupting the user.
1367
1367
  */
@@ -1373,11 +1373,59 @@ function Dt(r, t) {
1373
1373
  */
1374
1374
  unmount() {
1375
1375
  i || (document.body.removeEventListener(g.EVENT_NAME, c), n.unmount(), a?.(), o && (globalThis.DotNet.disposeJSObjectReference(o), o = null), i = !0);
1376
+ },
1377
+ /**
1378
+ * Installs the custom image upload adapter that delegates uploads to Blazor.
1379
+ * This is called lazily from Blazor when the consumer sets the `OnImageUpload` callback
1380
+ * to avoid unnecessary overhead for consumers that don't use this feature.
1381
+ */
1382
+ attachImageUploadAdapter: async () => {
1383
+ if (i)
1384
+ return;
1385
+ const s = await m.the.waitFor(e);
1386
+ vt(s, t);
1376
1387
  }
1377
1388
  };
1378
1389
  }
1379
- function Ot(r) {
1380
- return D(r), {
1390
+ function vt(r, t) {
1391
+ if (!r.plugins.has("FileRepository"))
1392
+ return;
1393
+ const e = r.plugins.get("FileRepository");
1394
+ e.createUploadAdapter = (i) => {
1395
+ let a = !1;
1396
+ return {
1397
+ async upload() {
1398
+ const n = await i.file;
1399
+ if (a)
1400
+ throw new Error("Upload aborted.");
1401
+ const o = await Ct(n), c = await t.invokeMethodAsync("OnEditorImageUpload", {
1402
+ fileName: n.name,
1403
+ mimeType: n.type,
1404
+ payload: o
1405
+ });
1406
+ if (!c)
1407
+ throw new Error(
1408
+ "OnImageUpload handler returned null. Make sure the OnImageUpload parameter is set on the <CKE5Editor> component."
1409
+ );
1410
+ return { default: c };
1411
+ },
1412
+ abort() {
1413
+ a = !0;
1414
+ }
1415
+ };
1416
+ };
1417
+ }
1418
+ function Ct(r) {
1419
+ return new Promise((t, e) => {
1420
+ const i = new FileReader();
1421
+ i.onload = () => {
1422
+ const a = i.result, n = a.split(",")[1] ?? a;
1423
+ t(n);
1424
+ }, i.onerror = () => e(i.error), i.readAsDataURL(r);
1425
+ });
1426
+ }
1427
+ function xt(r) {
1428
+ return O(r), {
1381
1429
  unmount() {
1382
1430
  }
1383
1431
  };
@@ -1386,15 +1434,15 @@ export {
1386
1434
  b as CKEditor5BlazorError,
1387
1435
  g as CKEditor5ChangeDataEvent,
1388
1436
  v as ContextsRegistry,
1389
- $ as CustomEditorPluginsRegistry,
1437
+ R as CustomEditorPluginsRegistry,
1390
1438
  ht as EditableComponentElement,
1391
1439
  ft as EditorComponentElement,
1392
1440
  m as EditorsRegistry,
1393
1441
  yt as UIPartComponentElement,
1394
- Tt as createContextBlazorInterop,
1395
- It as createEditableBlazorInterop,
1396
- Dt as createEditorBlazorInterop,
1397
- Ot as createUIPartBlazorInterop,
1442
+ Ot as createContextBlazorInterop,
1443
+ Dt as createEditableBlazorInterop,
1444
+ St as createEditorBlazorInterop,
1445
+ xt as createUIPartBlazorInterop,
1398
1446
  kt as ensureEditorElementsRegistered
1399
1447
  };
1400
1448
  //# sourceMappingURL=index.mjs.map