ckeditor5-phoenix 1.15.7 → 1.16.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/hooks/editor/editor.d.ts.map +1 -1
- package/dist/hooks/editor/plugins/index.d.ts +1 -0
- package/dist/hooks/editor/plugins/index.d.ts.map +1 -1
- package/dist/hooks/editor/plugins/phoenix-upload-adapter.d.ts +20 -0
- package/dist/hooks/editor/plugins/phoenix-upload-adapter.d.ts.map +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +231 -148
- package/dist/index.mjs.map +1 -1
- package/dist/shared/get-csrf-token.d.ts +7 -0
- package/dist/shared/get-csrf-token.d.ts.map +1 -0
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/hooks/editor/editor.test.ts +307 -0
- package/src/hooks/editor/editor.ts +16 -13
- package/src/hooks/editor/plugins/index.ts +1 -0
- package/src/hooks/editor/plugins/phoenix-upload-adapter.ts +155 -0
- package/src/index.ts +1 -0
- package/src/shared/get-csrf-token.test.ts +54 -0
- package/src/shared/get-csrf-token.ts +18 -0
- package/src/shared/index.ts +1 -0
- package/test-utils/editor/create-editor-preset.ts +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class W {
|
|
2
2
|
/**
|
|
3
3
|
* Map of registered items.
|
|
4
4
|
*/
|
|
@@ -26,11 +26,11 @@ class V {
|
|
|
26
26
|
*/
|
|
27
27
|
execute(t, e, i) {
|
|
28
28
|
const a = this.items.get(t), n = this.initializationErrors.get(t);
|
|
29
|
-
return n ? (i?.(n), Promise.reject(n)) : a ? Promise.resolve(e(a)) : new Promise((
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}), i ?
|
|
29
|
+
return n ? (i?.(n), Promise.reject(n)) : a ? Promise.resolve(e(a)) : new Promise((o, u) => {
|
|
30
|
+
const s = this.getPendingCallbacks(t);
|
|
31
|
+
s.success.push(async (c) => {
|
|
32
|
+
o(await e(c));
|
|
33
|
+
}), i ? s.error.push(i) : s.error.push(u);
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
@@ -167,7 +167,7 @@ class V {
|
|
|
167
167
|
function Y(r) {
|
|
168
168
|
return r.replace(/[-_\s]+(.)?/g, (t, e) => e ? e.toUpperCase() : "").replace(/^./, (t) => t.toLowerCase());
|
|
169
169
|
}
|
|
170
|
-
function
|
|
170
|
+
function O(r, t) {
|
|
171
171
|
let e = null;
|
|
172
172
|
return (...i) => {
|
|
173
173
|
e && clearTimeout(e), e = setTimeout(() => {
|
|
@@ -196,6 +196,13 @@ function X(r, t) {
|
|
|
196
196
|
const e = Object.entries(r).filter(([i, a]) => t(a, i));
|
|
197
197
|
return Object.fromEntries(e);
|
|
198
198
|
}
|
|
199
|
+
function Q() {
|
|
200
|
+
const r = document.querySelector('meta[name="csrf-token"]');
|
|
201
|
+
if (r)
|
|
202
|
+
return r.getAttribute("content");
|
|
203
|
+
const t = document.cookie.match(/(?:^|; )_csrf_token=([^;]*)/);
|
|
204
|
+
return t ? decodeURIComponent(t[1]) : null;
|
|
205
|
+
}
|
|
199
206
|
class P {
|
|
200
207
|
/**
|
|
201
208
|
* The current state of the hook.
|
|
@@ -238,7 +245,7 @@ class P {
|
|
|
238
245
|
return this.state === "destroyed" || this.state === "destroying";
|
|
239
246
|
}
|
|
240
247
|
}
|
|
241
|
-
function
|
|
248
|
+
function C(r) {
|
|
242
249
|
return {
|
|
243
250
|
/**
|
|
244
251
|
* The mounted lifecycle callback for the LiveView hook object.
|
|
@@ -246,7 +253,7 @@ function v(r) {
|
|
|
246
253
|
*/
|
|
247
254
|
async mounted() {
|
|
248
255
|
const t = new r();
|
|
249
|
-
this.el.instance = t, t.el = this.el, t.liveSocket = this.liveSocket, t.pushEvent = (i, a, n) => this.pushEvent?.(i, a, n), t.pushEventTo = (i, a, n,
|
|
256
|
+
this.el.instance = t, t.el = this.el, t.liveSocket = this.liveSocket, t.pushEvent = (i, a, n) => this.pushEvent?.(i, a, n), t.pushEventTo = (i, a, n, o) => this.pushEventTo?.(i, a, n, o), t.handleEvent = (i, a) => this.handleEvent?.(i, a), t.state = "mounting";
|
|
250
257
|
const e = await t.mounted?.();
|
|
251
258
|
return t.state = "mounted", e;
|
|
252
259
|
},
|
|
@@ -280,7 +287,7 @@ function v(r) {
|
|
|
280
287
|
function q(r) {
|
|
281
288
|
return Object.keys(r).length === 0 && r.constructor === Object;
|
|
282
289
|
}
|
|
283
|
-
function
|
|
290
|
+
function Z(r) {
|
|
284
291
|
return r == null;
|
|
285
292
|
}
|
|
286
293
|
function S(r, t) {
|
|
@@ -293,58 +300,58 @@ function z(r) {
|
|
|
293
300
|
const t = Number.parseInt(r, 10);
|
|
294
301
|
return Number.isNaN(t) ? null : t;
|
|
295
302
|
}
|
|
296
|
-
function
|
|
303
|
+
function tt() {
|
|
297
304
|
return Math.random().toString(36).substring(2);
|
|
298
305
|
}
|
|
299
|
-
function
|
|
306
|
+
function et(r, {
|
|
300
307
|
timeOutAfter: t = 500,
|
|
301
308
|
retryAfter: e = 100
|
|
302
309
|
} = {}) {
|
|
303
310
|
return new Promise((i, a) => {
|
|
304
311
|
const n = Date.now();
|
|
305
|
-
let
|
|
312
|
+
let o = null;
|
|
306
313
|
const u = setTimeout(() => {
|
|
307
|
-
a(
|
|
308
|
-
}, t),
|
|
314
|
+
a(o ?? new Error("Timeout"));
|
|
315
|
+
}, t), s = async () => {
|
|
309
316
|
try {
|
|
310
317
|
const c = await r();
|
|
311
318
|
clearTimeout(u), i(c);
|
|
312
319
|
} catch (c) {
|
|
313
|
-
|
|
320
|
+
o = c, Date.now() - n > t ? a(c) : setTimeout(s, e);
|
|
314
321
|
}
|
|
315
322
|
};
|
|
316
|
-
|
|
323
|
+
s();
|
|
317
324
|
});
|
|
318
325
|
}
|
|
319
|
-
const
|
|
320
|
-
async function
|
|
321
|
-
const a =
|
|
326
|
+
const I = Symbol.for("context-editor-watchdog");
|
|
327
|
+
async function rt({ element: r, context: t, creator: e, config: i }) {
|
|
328
|
+
const a = tt();
|
|
322
329
|
await t.add({
|
|
323
|
-
creator: (
|
|
330
|
+
creator: (s, c) => e.create(s, c),
|
|
324
331
|
id: a,
|
|
325
332
|
sourceElementOrData: r,
|
|
326
333
|
type: "editor",
|
|
327
334
|
config: i
|
|
328
335
|
});
|
|
329
|
-
const n = t.getItem(a),
|
|
336
|
+
const n = t.getItem(a), o = {
|
|
330
337
|
state: "available",
|
|
331
338
|
editorContextId: a,
|
|
332
339
|
context: t
|
|
333
340
|
};
|
|
334
|
-
n[
|
|
341
|
+
n[I] = o;
|
|
335
342
|
const u = t.destroy.bind(t);
|
|
336
|
-
return t.destroy = async () => (
|
|
337
|
-
...
|
|
343
|
+
return t.destroy = async () => (o.state = "unavailable", u()), {
|
|
344
|
+
...o,
|
|
338
345
|
editor: n
|
|
339
346
|
};
|
|
340
347
|
}
|
|
341
|
-
function
|
|
342
|
-
return
|
|
348
|
+
function it(r) {
|
|
349
|
+
return I in r ? r[I] : null;
|
|
343
350
|
}
|
|
344
351
|
function E(r) {
|
|
345
352
|
return ["inline", "classic", "balloon", "decoupled"].includes(r);
|
|
346
353
|
}
|
|
347
|
-
async function
|
|
354
|
+
async function at(r) {
|
|
348
355
|
const t = await import("ckeditor5"), i = {
|
|
349
356
|
inline: t.InlineEditor,
|
|
350
357
|
balloon: t.BalloonEditor,
|
|
@@ -416,21 +423,21 @@ class D {
|
|
|
416
423
|
return this.plugins.has(t);
|
|
417
424
|
}
|
|
418
425
|
}
|
|
419
|
-
async function
|
|
426
|
+
async function V(r) {
|
|
420
427
|
const t = await import("ckeditor5");
|
|
421
428
|
let e = null;
|
|
422
429
|
const i = r.map(async (a) => {
|
|
423
430
|
const n = await D.the.get(a);
|
|
424
431
|
if (n)
|
|
425
432
|
return n;
|
|
426
|
-
const { [a]:
|
|
427
|
-
if (
|
|
428
|
-
return
|
|
433
|
+
const { [a]: o } = t;
|
|
434
|
+
if (o)
|
|
435
|
+
return o;
|
|
429
436
|
if (!e)
|
|
430
437
|
try {
|
|
431
438
|
e = await import("ckeditor5-premium-features");
|
|
432
|
-
} catch (
|
|
433
|
-
console.error(`Failed to load premium package: ${
|
|
439
|
+
} catch (s) {
|
|
440
|
+
console.error(`Failed to load premium package: ${s}`);
|
|
434
441
|
}
|
|
435
442
|
const { [a]: u } = e || {};
|
|
436
443
|
if (u)
|
|
@@ -442,25 +449,25 @@ async function B(r) {
|
|
|
442
449
|
hasPremium: !!e
|
|
443
450
|
};
|
|
444
451
|
}
|
|
445
|
-
async function
|
|
452
|
+
async function B(r, t) {
|
|
446
453
|
const e = [r.ui, r.content];
|
|
447
454
|
return await Promise.all(
|
|
448
455
|
[
|
|
449
|
-
|
|
456
|
+
U("ckeditor5", e),
|
|
450
457
|
/* v8 ignore next */
|
|
451
|
-
t &&
|
|
458
|
+
t && U("ckeditor5-premium-features", e)
|
|
452
459
|
].filter((a) => !!a)
|
|
453
460
|
).then((a) => a.flat());
|
|
454
461
|
}
|
|
455
|
-
async function
|
|
462
|
+
async function U(r, t) {
|
|
456
463
|
return await Promise.all(
|
|
457
464
|
t.filter((e) => e !== "en").map(async (e) => {
|
|
458
|
-
const i = await
|
|
465
|
+
const i = await nt(r, e);
|
|
459
466
|
return i?.default ?? i;
|
|
460
467
|
}).filter(Boolean)
|
|
461
468
|
);
|
|
462
469
|
}
|
|
463
|
-
async function
|
|
470
|
+
async function nt(r, t) {
|
|
464
471
|
try {
|
|
465
472
|
if (r === "ckeditor5")
|
|
466
473
|
switch (t) {
|
|
@@ -760,27 +767,27 @@ async function at(r, t) {
|
|
|
760
767
|
return console.error(`Failed to load translation for ${r}/${t}:`, e), null;
|
|
761
768
|
}
|
|
762
769
|
}
|
|
763
|
-
function
|
|
770
|
+
function F(r) {
|
|
764
771
|
return S(r, (t) => ({
|
|
765
772
|
dictionary: t
|
|
766
773
|
}));
|
|
767
774
|
}
|
|
768
|
-
function
|
|
769
|
-
const t =
|
|
775
|
+
function _(r) {
|
|
776
|
+
const t = K(r);
|
|
770
777
|
return S(t, ({ content: e }) => e);
|
|
771
778
|
}
|
|
772
|
-
function
|
|
773
|
-
const t =
|
|
779
|
+
function R(r) {
|
|
780
|
+
const t = K(r), e = S(t, ({ initialValue: i }) => i);
|
|
774
781
|
return X(e, (i) => typeof i == "string");
|
|
775
782
|
}
|
|
776
|
-
function
|
|
783
|
+
function K(r) {
|
|
777
784
|
const t = document.querySelectorAll(
|
|
778
785
|
[
|
|
779
786
|
`[data-cke-editor-id="${r}"][data-cke-editable-root-name]`,
|
|
780
787
|
"[data-cke-editable-root-name]:not([data-cke-editor-id])"
|
|
781
788
|
].join(", ")
|
|
782
|
-
), e = Array.from(t).reduce((u,
|
|
783
|
-
const c =
|
|
789
|
+
), e = Array.from(t).reduce((u, s) => {
|
|
790
|
+
const c = s.getAttribute("data-cke-editable-root-name"), l = s.getAttribute("data-cke-editable-initial-value") || "", m = s.querySelector("[data-cke-editable-content]");
|
|
784
791
|
return !c || !m ? u : {
|
|
785
792
|
...u,
|
|
786
793
|
[c]: {
|
|
@@ -791,12 +798,12 @@ function _(r) {
|
|
|
791
798
|
}, /* @__PURE__ */ Object.create({})), i = document.querySelector(`[phx-hook="CKEditor5"][id="${r}"]`);
|
|
792
799
|
if (!i)
|
|
793
800
|
return e;
|
|
794
|
-
const a = i.getAttribute("cke-initial-value") || "", n = i.querySelector(`#${r}_editor `),
|
|
795
|
-
return
|
|
801
|
+
const a = i.getAttribute("cke-initial-value") || "", n = i.querySelector(`#${r}_editor `), o = e.main;
|
|
802
|
+
return o ? {
|
|
796
803
|
...e,
|
|
797
804
|
main: {
|
|
798
|
-
...
|
|
799
|
-
initialValue:
|
|
805
|
+
...o,
|
|
806
|
+
initialValue: o.initialValue || a
|
|
800
807
|
}
|
|
801
808
|
} : n ? {
|
|
802
809
|
...e,
|
|
@@ -806,16 +813,16 @@ function _(r) {
|
|
|
806
813
|
}
|
|
807
814
|
} : e;
|
|
808
815
|
}
|
|
809
|
-
const
|
|
810
|
-
function
|
|
816
|
+
const H = ["inline", "classic", "balloon", "decoupled", "multiroot"];
|
|
817
|
+
function ot(r) {
|
|
811
818
|
const t = r.getAttribute("cke-preset");
|
|
812
819
|
if (!t)
|
|
813
820
|
throw new Error('CKEditor5 hook requires a "cke-preset" attribute on the element.');
|
|
814
821
|
const { type: e, config: i, license: a, ...n } = JSON.parse(t);
|
|
815
822
|
if (!e || !i || !a)
|
|
816
823
|
throw new Error('CKEditor5 hook configuration must include "editor", "config", and "license" properties.');
|
|
817
|
-
if (!
|
|
818
|
-
throw new Error(`Invalid editor type: ${e}. Must be one of: ${
|
|
824
|
+
if (!H.includes(e))
|
|
825
|
+
throw new Error(`Invalid editor type: ${e}. Must be one of: ${H.join(", ")}.`);
|
|
819
826
|
return {
|
|
820
827
|
type: e,
|
|
821
828
|
license: a,
|
|
@@ -844,12 +851,12 @@ function st(r, t) {
|
|
|
844
851
|
i.setStyle("height", `${t}px`, e.view.document.getRoot());
|
|
845
852
|
});
|
|
846
853
|
}
|
|
847
|
-
const
|
|
848
|
-
async function
|
|
854
|
+
const A = Symbol.for("elixir-editor-watchdog");
|
|
855
|
+
async function ct(r) {
|
|
849
856
|
const { EditorWatchdog: t } = await import("ckeditor5"), e = new t(r);
|
|
850
857
|
return e.setCreator(async (...i) => {
|
|
851
858
|
const a = await r.create(...i);
|
|
852
|
-
return a[
|
|
859
|
+
return a[A] = e, a;
|
|
853
860
|
}), {
|
|
854
861
|
watchdog: e,
|
|
855
862
|
Constructor: {
|
|
@@ -857,13 +864,13 @@ async function ot(r) {
|
|
|
857
864
|
}
|
|
858
865
|
};
|
|
859
866
|
}
|
|
860
|
-
function
|
|
861
|
-
return
|
|
867
|
+
function ut(r) {
|
|
868
|
+
return A in r ? r[A] : null;
|
|
862
869
|
}
|
|
863
|
-
class w extends
|
|
870
|
+
class w extends W {
|
|
864
871
|
static the = new w();
|
|
865
872
|
}
|
|
866
|
-
function
|
|
873
|
+
function lt(r) {
|
|
867
874
|
const t = r.getAttribute("cke-context");
|
|
868
875
|
if (!t)
|
|
869
876
|
throw new Error('CKEditor5 hook requires a "cke-context" attribute on the element.');
|
|
@@ -874,7 +881,7 @@ function ut(r) {
|
|
|
874
881
|
watchdogConfig: i.watchdogConfig || i.watchdog_config
|
|
875
882
|
};
|
|
876
883
|
}
|
|
877
|
-
class
|
|
884
|
+
class dt extends P {
|
|
878
885
|
/**
|
|
879
886
|
* The promise that resolves to the context instance.
|
|
880
887
|
*/
|
|
@@ -885,7 +892,7 @@ class lt extends P {
|
|
|
885
892
|
get attrs() {
|
|
886
893
|
const t = (i) => this.el.getAttribute(i) || null, e = {
|
|
887
894
|
id: this.el.id,
|
|
888
|
-
config:
|
|
895
|
+
config: lt(this.el),
|
|
889
896
|
language: {
|
|
890
897
|
ui: t("cke-language") || "en",
|
|
891
898
|
content: t("cke-content-language") || "en"
|
|
@@ -902,17 +909,17 @@ class lt extends P {
|
|
|
902
909
|
* Mounts the context component.
|
|
903
910
|
*/
|
|
904
911
|
async mounted() {
|
|
905
|
-
const { id: t, language: e } = this.attrs, { customTranslations: i, watchdogConfig: a, config: { plugins: n, ...
|
|
906
|
-
...await
|
|
907
|
-
|
|
912
|
+
const { id: t, language: e } = this.attrs, { customTranslations: i, watchdogConfig: a, config: { plugins: n, ...o } } = this.attrs.config, { loadedPlugins: u, hasPremium: s } = await V(n ?? []), l = [
|
|
913
|
+
...await B(e, s),
|
|
914
|
+
F(i?.dictionary || {})
|
|
908
915
|
].filter((f) => !q(f));
|
|
909
916
|
this.contextPromise = (async () => {
|
|
910
|
-
const { ContextWatchdog: f, Context:
|
|
917
|
+
const { ContextWatchdog: f, Context: v } = await import("ckeditor5"), p = new f(v, {
|
|
911
918
|
crashNumberLimit: 10,
|
|
912
919
|
...a
|
|
913
920
|
});
|
|
914
921
|
return await p.create({
|
|
915
|
-
...
|
|
922
|
+
...o,
|
|
916
923
|
language: e,
|
|
917
924
|
plugins: u,
|
|
918
925
|
...l.length && {
|
|
@@ -938,27 +945,27 @@ class lt extends P {
|
|
|
938
945
|
}
|
|
939
946
|
}
|
|
940
947
|
}
|
|
941
|
-
function
|
|
948
|
+
function mt(r) {
|
|
942
949
|
return r.hasAttribute("cke-context");
|
|
943
950
|
}
|
|
944
|
-
function
|
|
951
|
+
function ht(r) {
|
|
945
952
|
let t = r;
|
|
946
953
|
for (; t; ) {
|
|
947
|
-
if (
|
|
954
|
+
if (mt(t))
|
|
948
955
|
return t;
|
|
949
956
|
t = t.parentElement;
|
|
950
957
|
}
|
|
951
958
|
return null;
|
|
952
959
|
}
|
|
953
|
-
async function
|
|
954
|
-
const t =
|
|
960
|
+
async function pt(r) {
|
|
961
|
+
const t = ht(r);
|
|
955
962
|
return t ? w.the.waitFor(t.id) : null;
|
|
956
963
|
}
|
|
957
|
-
const
|
|
958
|
-
class h extends
|
|
964
|
+
const wt = C(dt);
|
|
965
|
+
class h extends W {
|
|
959
966
|
static the = new h();
|
|
960
967
|
}
|
|
961
|
-
class
|
|
968
|
+
class ft extends P {
|
|
962
969
|
/**
|
|
963
970
|
* The name of the hook.
|
|
964
971
|
*/
|
|
@@ -985,18 +992,18 @@ class wt extends P {
|
|
|
985
992
|
*/
|
|
986
993
|
async mounted() {
|
|
987
994
|
const { editableId: t, editorId: e, rootName: i, initialValue: a } = this.attrs, n = this.el.querySelector(`#${t}_input`);
|
|
988
|
-
this.editorPromise = h.the.execute(e, (
|
|
995
|
+
this.editorPromise = h.the.execute(e, (o) => {
|
|
989
996
|
if (this.isBeingDestroyed())
|
|
990
997
|
return null;
|
|
991
|
-
const { ui: u, editing:
|
|
998
|
+
const { ui: u, editing: s, model: c } = o;
|
|
992
999
|
if (c.document.getRoot(i))
|
|
993
|
-
return
|
|
994
|
-
|
|
1000
|
+
return o;
|
|
1001
|
+
o.addRoot(i, {
|
|
995
1002
|
isUndoable: !1,
|
|
996
1003
|
data: a
|
|
997
1004
|
});
|
|
998
1005
|
const l = this.el.querySelector("[data-cke-editable-content]"), m = u.view.createEditable(i, l);
|
|
999
|
-
return u.addEditable(m),
|
|
1006
|
+
return u.addEditable(m), s.view.forceRender(), n && yt(n, o, i), o;
|
|
1000
1007
|
});
|
|
1001
1008
|
}
|
|
1002
1009
|
/**
|
|
@@ -1012,14 +1019,86 @@ class wt extends P {
|
|
|
1012
1019
|
}
|
|
1013
1020
|
}
|
|
1014
1021
|
}
|
|
1015
|
-
const
|
|
1016
|
-
function
|
|
1022
|
+
const gt = C(ft);
|
|
1023
|
+
function yt(r, t, e) {
|
|
1017
1024
|
const i = () => {
|
|
1018
1025
|
r.value = t.getData({ rootName: e });
|
|
1019
1026
|
};
|
|
1020
|
-
t.model.document.on("change:data",
|
|
1027
|
+
t.model.document.on("change:data", O(100, i)), i();
|
|
1021
1028
|
}
|
|
1022
|
-
async function
|
|
1029
|
+
async function bt() {
|
|
1030
|
+
const { Plugin: r, FileRepository: t } = await import("ckeditor5");
|
|
1031
|
+
return class extends r {
|
|
1032
|
+
/**
|
|
1033
|
+
* The name of the plugin.
|
|
1034
|
+
*/
|
|
1035
|
+
static get pluginName() {
|
|
1036
|
+
return "PhoenixUploadAdapter";
|
|
1037
|
+
}
|
|
1038
|
+
static get requires() {
|
|
1039
|
+
return [t];
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* Initializes the plugin.
|
|
1043
|
+
*/
|
|
1044
|
+
init() {
|
|
1045
|
+
const { editor: i } = this, { plugins: a, config: n } = i, o = n.get("phoenixUpload.url");
|
|
1046
|
+
if (!o || a.has("SimpleUploadAdapter") || a.has("Base64UploadAdapter") || a.has("CKFinderUploadAdapter"))
|
|
1047
|
+
return;
|
|
1048
|
+
const u = a.get(t);
|
|
1049
|
+
u.createUploadAdapter = (s) => new Et(s, o);
|
|
1050
|
+
}
|
|
1051
|
+
};
|
|
1052
|
+
}
|
|
1053
|
+
class Et {
|
|
1054
|
+
loader;
|
|
1055
|
+
uploadUrl;
|
|
1056
|
+
abortController = null;
|
|
1057
|
+
constructor(t, e) {
|
|
1058
|
+
this.loader = t, this.uploadUrl = e;
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Starts the upload process.
|
|
1062
|
+
*/
|
|
1063
|
+
async upload() {
|
|
1064
|
+
const t = await this.loader.file;
|
|
1065
|
+
this.abortController = new AbortController();
|
|
1066
|
+
const e = new FormData();
|
|
1067
|
+
e.append("file", t), t.size && (this.loader.uploadTotal = t.size, this.loader.uploaded = 0);
|
|
1068
|
+
const i = {}, a = Q();
|
|
1069
|
+
a && (i["X-CSRF-Token"] = a);
|
|
1070
|
+
try {
|
|
1071
|
+
const n = await fetch(this.uploadUrl, {
|
|
1072
|
+
method: "POST",
|
|
1073
|
+
headers: i,
|
|
1074
|
+
body: e,
|
|
1075
|
+
signal: this.abortController.signal
|
|
1076
|
+
});
|
|
1077
|
+
if (!n.ok) {
|
|
1078
|
+
let u = "Couldn't upload file!";
|
|
1079
|
+
try {
|
|
1080
|
+
const s = await n.json();
|
|
1081
|
+
s?.error?.message && (u = s.error.message);
|
|
1082
|
+
} catch {
|
|
1083
|
+
}
|
|
1084
|
+
throw new Error(u);
|
|
1085
|
+
}
|
|
1086
|
+
return this.loader.uploaded = this.loader.uploadTotal, {
|
|
1087
|
+
default: (await n.json()).url
|
|
1088
|
+
};
|
|
1089
|
+
} catch (n) {
|
|
1090
|
+
throw n.name === "AbortError" ? n : n.message || "Couldn't upload file!";
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
/**
|
|
1094
|
+
* Aborts the upload process.
|
|
1095
|
+
*/
|
|
1096
|
+
/* v8 ignore next 4 */
|
|
1097
|
+
abort() {
|
|
1098
|
+
this.abortController?.abort(), this.abortController = null;
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
async function kt({
|
|
1023
1102
|
editorId: r,
|
|
1024
1103
|
saveDebounceMs: t
|
|
1025
1104
|
}) {
|
|
@@ -1044,7 +1123,7 @@ async function yt({
|
|
|
1044
1123
|
*/
|
|
1045
1124
|
afterInit() {
|
|
1046
1125
|
const { editor: a } = this;
|
|
1047
|
-
this.input = document.getElementById(`${r}_input`), this.input && (a.model.document.on("change:data",
|
|
1126
|
+
this.input = document.getElementById(`${r}_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));
|
|
1048
1127
|
}
|
|
1049
1128
|
/**
|
|
1050
1129
|
* Synchronizes the editor's content with the input field.
|
|
@@ -1061,8 +1140,8 @@ async function yt({
|
|
|
1061
1140
|
}
|
|
1062
1141
|
};
|
|
1063
1142
|
}
|
|
1064
|
-
async function
|
|
1065
|
-
const { Plugin: t } = await import("ckeditor5"), { editorId: e, saveDebounceMs: i, events: a, pushEvent: n, handleEvent:
|
|
1143
|
+
async function Pt(r) {
|
|
1144
|
+
const { Plugin: t } = await import("ckeditor5"), { editorId: e, saveDebounceMs: i, events: a, pushEvent: n, handleEvent: o } = r;
|
|
1066
1145
|
return class extends t {
|
|
1067
1146
|
/**
|
|
1068
1147
|
* The name of the plugin.
|
|
@@ -1074,37 +1153,37 @@ async function bt(r) {
|
|
|
1074
1153
|
* Initializes the plugin.
|
|
1075
1154
|
*/
|
|
1076
1155
|
init() {
|
|
1077
|
-
const { editor:
|
|
1078
|
-
a.change && this.setupTypingContentPush(), a.blur && this.setupEventPush("blur"), a.focus && this.setupEventPush("focus"),
|
|
1079
|
-
(
|
|
1156
|
+
const { editor: s } = this;
|
|
1157
|
+
a.change && this.setupTypingContentPush(), a.blur && this.setupEventPush("blur"), a.focus && this.setupEventPush("focus"), o("ckeditor5:set-data", ({ editorId: c, data: l }) => {
|
|
1158
|
+
(Z(c) || c === e) && s.setData(l);
|
|
1080
1159
|
});
|
|
1081
1160
|
}
|
|
1082
1161
|
/**
|
|
1083
1162
|
* Setups the content push event for the editor.
|
|
1084
1163
|
*/
|
|
1085
1164
|
setupTypingContentPush() {
|
|
1086
|
-
const { editor:
|
|
1165
|
+
const { editor: s } = this, c = () => {
|
|
1087
1166
|
n(
|
|
1088
1167
|
"ckeditor5:change",
|
|
1089
1168
|
{
|
|
1090
1169
|
editorId: e,
|
|
1091
|
-
data:
|
|
1170
|
+
data: N(this.editor)
|
|
1092
1171
|
}
|
|
1093
1172
|
);
|
|
1094
1173
|
};
|
|
1095
|
-
|
|
1174
|
+
s.model.document.on("change:data", O(i, c)), s.once("ready", c);
|
|
1096
1175
|
}
|
|
1097
1176
|
/**
|
|
1098
1177
|
* Setups the event push for the editor.
|
|
1099
1178
|
*/
|
|
1100
|
-
setupEventPush(
|
|
1179
|
+
setupEventPush(s) {
|
|
1101
1180
|
const { editor: c } = this, l = () => {
|
|
1102
1181
|
const { isFocused: m } = c.ui.focusTracker;
|
|
1103
|
-
(m ? "focus" : "blur") ===
|
|
1104
|
-
`ckeditor5:${
|
|
1182
|
+
(m ? "focus" : "blur") === s && n(
|
|
1183
|
+
`ckeditor5:${s}`,
|
|
1105
1184
|
{
|
|
1106
1185
|
editorId: e,
|
|
1107
|
-
data:
|
|
1186
|
+
data: N(c)
|
|
1108
1187
|
}
|
|
1109
1188
|
);
|
|
1110
1189
|
};
|
|
@@ -1112,10 +1191,10 @@ async function bt(r) {
|
|
|
1112
1191
|
}
|
|
1113
1192
|
};
|
|
1114
1193
|
}
|
|
1115
|
-
function
|
|
1194
|
+
function N(r) {
|
|
1116
1195
|
return r.model.document.getRootNames().reduce((e, i) => (e[i] = r.getData({ rootName: i }), e), /* @__PURE__ */ Object.create({}));
|
|
1117
1196
|
}
|
|
1118
|
-
class
|
|
1197
|
+
class Ct extends P {
|
|
1119
1198
|
/**
|
|
1120
1199
|
* The promise that resolves to the editor instance.
|
|
1121
1200
|
*/
|
|
@@ -1127,7 +1206,7 @@ class Et extends P {
|
|
|
1127
1206
|
const { el: t } = this, e = t.getAttribute.bind(t), i = t.hasAttribute.bind(t), a = {
|
|
1128
1207
|
editorId: e("id"),
|
|
1129
1208
|
contextId: e("cke-context-id"),
|
|
1130
|
-
preset:
|
|
1209
|
+
preset: ot(t),
|
|
1131
1210
|
editableHeight: z(e("cke-editable-height")),
|
|
1132
1211
|
watchdog: i("cke-watchdog"),
|
|
1133
1212
|
events: {
|
|
@@ -1175,7 +1254,7 @@ class Et extends P {
|
|
|
1175
1254
|
const t = await this.editorPromise;
|
|
1176
1255
|
if (!t)
|
|
1177
1256
|
return;
|
|
1178
|
-
const e =
|
|
1257
|
+
const e = it(t), i = ut(t);
|
|
1179
1258
|
e ? e.state !== "unavailable" && await e.context.remove(e.editorContextId) : i ? await i.destroy() : await t.destroy();
|
|
1180
1259
|
} finally {
|
|
1181
1260
|
this.editorPromise = null;
|
|
@@ -1185,55 +1264,58 @@ class Et extends P {
|
|
|
1185
1264
|
* Creates the CKEditor instance.
|
|
1186
1265
|
*/
|
|
1187
1266
|
async createEditor() {
|
|
1188
|
-
const { preset: t, editorId: e, contextId: i, editableHeight: a, events: n, saveDebounceMs:
|
|
1189
|
-
let p = await
|
|
1190
|
-
const g = await (i ? w.the.waitFor(i) :
|
|
1191
|
-
if (
|
|
1192
|
-
const d = await
|
|
1267
|
+
const { preset: t, editorId: e, contextId: i, editableHeight: a, events: n, saveDebounceMs: o, language: u, watchdog: s } = this.attrs, { customTranslations: c, type: l, license: m, config: { plugins: f, ...v } } = t;
|
|
1268
|
+
let p = await at(l);
|
|
1269
|
+
const g = await (i ? w.the.waitFor(i) : pt(this.el));
|
|
1270
|
+
if (s && !g) {
|
|
1271
|
+
const d = await ct(p);
|
|
1193
1272
|
({ Constructor: p } = d), d.watchdog.on("restart", () => {
|
|
1194
1273
|
const b = d.watchdog.editor;
|
|
1195
1274
|
this.editorPromise = Promise.resolve(b), h.the.register(e, b);
|
|
1196
1275
|
});
|
|
1197
1276
|
}
|
|
1198
|
-
const { loadedPlugins:
|
|
1199
|
-
E(l) &&
|
|
1200
|
-
await
|
|
1201
|
-
editorId: e,
|
|
1202
|
-
saveDebounceMs: s
|
|
1203
|
-
})
|
|
1204
|
-
), I.push(
|
|
1205
|
-
await bt({
|
|
1277
|
+
const { loadedPlugins: T, hasPremium: G } = await V(f);
|
|
1278
|
+
E(l) && T.push(
|
|
1279
|
+
await kt({
|
|
1206
1280
|
editorId: e,
|
|
1207
|
-
saveDebounceMs:
|
|
1208
|
-
events: n,
|
|
1209
|
-
pushEvent: this.pushEvent.bind(this),
|
|
1210
|
-
handleEvent: this.handleEvent.bind(this)
|
|
1281
|
+
saveDebounceMs: o
|
|
1211
1282
|
})
|
|
1283
|
+
), T.push(
|
|
1284
|
+
...await Promise.all([
|
|
1285
|
+
Pt({
|
|
1286
|
+
editorId: e,
|
|
1287
|
+
saveDebounceMs: o,
|
|
1288
|
+
events: n,
|
|
1289
|
+
pushEvent: this.pushEvent.bind(this),
|
|
1290
|
+
handleEvent: this.handleEvent.bind(this)
|
|
1291
|
+
}),
|
|
1292
|
+
bt()
|
|
1293
|
+
])
|
|
1212
1294
|
);
|
|
1213
1295
|
const j = [
|
|
1214
|
-
...await
|
|
1215
|
-
|
|
1296
|
+
...await B(u, G),
|
|
1297
|
+
F(c?.dictionary || {})
|
|
1216
1298
|
].filter((d) => !q(d));
|
|
1217
|
-
let y =
|
|
1299
|
+
let y = R(e);
|
|
1218
1300
|
E(l) && (y = y.main || "");
|
|
1219
1301
|
const $ = await (async () => {
|
|
1220
|
-
let d =
|
|
1302
|
+
let d = _(e);
|
|
1221
1303
|
if (!(d instanceof HTMLElement) && !("main" in d)) {
|
|
1222
1304
|
const M = l === "decoupled" ? ["main"] : Object.keys(y);
|
|
1223
|
-
|
|
1305
|
+
L(d, M) || (d = await vt(e, M), y = R(e));
|
|
1224
1306
|
}
|
|
1225
1307
|
E(l) && "main" in d && (d = d.main);
|
|
1226
1308
|
const b = {
|
|
1227
|
-
...x(
|
|
1309
|
+
...x(v),
|
|
1228
1310
|
initialData: y,
|
|
1229
1311
|
licenseKey: m.key,
|
|
1230
|
-
plugins:
|
|
1312
|
+
plugins: T,
|
|
1231
1313
|
language: u,
|
|
1232
1314
|
...j.length && {
|
|
1233
1315
|
translations: j
|
|
1234
1316
|
}
|
|
1235
1317
|
};
|
|
1236
|
-
return !g || !(d instanceof HTMLElement) ? p.create(d, b) : (await
|
|
1318
|
+
return !g || !(d instanceof HTMLElement) ? p.create(d, b) : (await rt({
|
|
1237
1319
|
context: g,
|
|
1238
1320
|
element: d,
|
|
1239
1321
|
creator: p,
|
|
@@ -1243,14 +1325,14 @@ class Et extends P {
|
|
|
1243
1325
|
return E(l) && a && st($, a), $;
|
|
1244
1326
|
}
|
|
1245
1327
|
}
|
|
1246
|
-
function
|
|
1328
|
+
function L(r, t) {
|
|
1247
1329
|
return t.every((e) => r[e]);
|
|
1248
1330
|
}
|
|
1249
|
-
async function
|
|
1250
|
-
return
|
|
1331
|
+
async function vt(r, t) {
|
|
1332
|
+
return et(
|
|
1251
1333
|
() => {
|
|
1252
|
-
const e =
|
|
1253
|
-
if (!
|
|
1334
|
+
const e = _(r);
|
|
1335
|
+
if (!L(e, t))
|
|
1254
1336
|
throw new Error(
|
|
1255
1337
|
`It looks like not all required root elements are present yet.
|
|
1256
1338
|
* If you want to wait for them, ensure they are registered before editor initialization.
|
|
@@ -1262,8 +1344,8 @@ Missing roots: ${t.filter((i) => !e[i]).join(", ")}.`
|
|
|
1262
1344
|
{ timeOutAfter: 2e3, retryAfter: 100 }
|
|
1263
1345
|
);
|
|
1264
1346
|
}
|
|
1265
|
-
const
|
|
1266
|
-
class
|
|
1347
|
+
const Tt = C(Ct);
|
|
1348
|
+
class It extends P {
|
|
1267
1349
|
/**
|
|
1268
1350
|
* The name of the hook.
|
|
1269
1351
|
*/
|
|
@@ -1291,12 +1373,12 @@ class vt extends P {
|
|
|
1291
1373
|
this.mountedPromise = h.the.execute(t, (i) => {
|
|
1292
1374
|
if (this.isBeingDestroyed())
|
|
1293
1375
|
return;
|
|
1294
|
-
const { ui: a } = i, n =
|
|
1295
|
-
if (!
|
|
1376
|
+
const { ui: a } = i, n = xt(e), o = a.view[n];
|
|
1377
|
+
if (!o) {
|
|
1296
1378
|
console.error(`Unknown UI part name: "${e}". Supported names are "toolbar" and "menubar".`);
|
|
1297
1379
|
return;
|
|
1298
1380
|
}
|
|
1299
|
-
this.el.appendChild(
|
|
1381
|
+
this.el.appendChild(o.element);
|
|
1300
1382
|
});
|
|
1301
1383
|
}
|
|
1302
1384
|
/**
|
|
@@ -1306,7 +1388,7 @@ class vt extends P {
|
|
|
1306
1388
|
this.el.style.display = "none", await this.mountedPromise, this.mountedPromise = null, this.el.innerHTML = "";
|
|
1307
1389
|
}
|
|
1308
1390
|
}
|
|
1309
|
-
function
|
|
1391
|
+
function xt(r) {
|
|
1310
1392
|
switch (r) {
|
|
1311
1393
|
case "toolbar":
|
|
1312
1394
|
return "toolbar";
|
|
@@ -1316,17 +1398,18 @@ function Ct(r) {
|
|
|
1316
1398
|
return null;
|
|
1317
1399
|
}
|
|
1318
1400
|
}
|
|
1319
|
-
const
|
|
1320
|
-
CKEditor5:
|
|
1321
|
-
CKEditable:
|
|
1322
|
-
CKUIPart:
|
|
1323
|
-
CKContext:
|
|
1401
|
+
const At = C(It), Mt = {
|
|
1402
|
+
CKEditor5: Tt,
|
|
1403
|
+
CKEditable: gt,
|
|
1404
|
+
CKUIPart: At,
|
|
1405
|
+
CKContext: wt
|
|
1324
1406
|
};
|
|
1325
1407
|
export {
|
|
1408
|
+
w as ContextsRegistry,
|
|
1326
1409
|
D as CustomEditorPluginsRegistry,
|
|
1327
1410
|
h as EditorsRegistry,
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1411
|
+
Mt as Hooks,
|
|
1412
|
+
it as unwrapEditorContext,
|
|
1413
|
+
ut as unwrapEditorWatchdog
|
|
1331
1414
|
};
|
|
1332
1415
|
//# sourceMappingURL=index.mjs.map
|