ckeditor5-livewire 1.7.0 → 1.9.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.
Files changed (46) hide show
  1. package/bundler/vite-ckeditor5-externalize.ts +15 -4
  2. package/dist/bundler/vite-ckeditor5-externalize.cjs +2 -2
  3. package/dist/bundler/vite-ckeditor5-externalize.cjs.map +1 -1
  4. package/dist/bundler/vite-ckeditor5-externalize.d.ts.map +1 -1
  5. package/dist/bundler/vite-ckeditor5-externalize.mjs +37 -37
  6. package/dist/bundler/vite-ckeditor5-externalize.mjs.map +1 -1
  7. package/dist/hooks/context/context.d.ts.map +1 -1
  8. package/dist/hooks/editable.d.ts +18 -6
  9. package/dist/hooks/editable.d.ts.map +1 -1
  10. package/dist/hooks/editor/editor.d.ts +14 -0
  11. package/dist/hooks/editor/editor.d.ts.map +1 -1
  12. package/dist/hooks/editor/plugins/livewire-sync.d.ts.map +1 -1
  13. package/dist/hooks/editor/plugins/sync-editor-with-input.d.ts.map +1 -1
  14. package/dist/hooks/editor/utils/index.d.ts +0 -1
  15. package/dist/hooks/editor/utils/index.d.ts.map +1 -1
  16. package/dist/hooks/editor/utils/load-editor-translations.d.ts.map +1 -1
  17. package/dist/hooks/hook.d.ts.map +1 -1
  18. package/dist/hooks/utils/index.d.ts +3 -0
  19. package/dist/hooks/utils/index.d.ts.map +1 -0
  20. package/dist/hooks/utils/is-wire-model-connected.d.ts +8 -0
  21. package/dist/hooks/utils/is-wire-model-connected.d.ts.map +1 -0
  22. package/dist/hooks/utils/root-attributes-updater.d.ts +16 -0
  23. package/dist/hooks/utils/root-attributes-updater.d.ts.map +1 -0
  24. package/dist/index.cjs +3 -3
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.mjs +921 -1328
  27. package/dist/index.mjs.map +1 -1
  28. package/package.json +4 -5
  29. package/src/hooks/context/context.ts +1 -0
  30. package/src/hooks/editable.test.ts +103 -0
  31. package/src/hooks/editable.ts +75 -32
  32. package/src/hooks/editor/editor.test.ts +77 -9
  33. package/src/hooks/editor/editor.ts +33 -1
  34. package/src/hooks/editor/plugins/livewire-sync.ts +30 -4
  35. package/src/hooks/editor/plugins/sync-editor-with-input.ts +1 -0
  36. package/src/hooks/editor/utils/index.ts +0 -1
  37. package/src/hooks/editor/utils/load-editor-plugins.ts +2 -2
  38. package/src/hooks/editor/utils/load-editor-translations.ts +16 -12
  39. package/src/hooks/hook.ts +1 -0
  40. package/src/hooks/ui-part.ts +1 -1
  41. package/src/hooks/utils/index.ts +2 -0
  42. package/src/hooks/{editor/utils → utils}/is-wire-model-connected.test.ts +2 -1
  43. package/src/hooks/{editor/utils → utils}/is-wire-model-connected.ts +6 -0
  44. package/src/hooks/utils/root-attributes-updater.ts +46 -0
  45. package/dist/hooks/editor/utils/is-wire-model-connected.d.ts +0 -2
  46. package/dist/hooks/editor/utils/is-wire-model-connected.d.ts.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,1333 +1,926 @@
1
- class D {
2
- constructor(t) {
3
- this.livewireComponent = t;
4
- }
5
- /**
6
- * The current state of the hook.
7
- */
8
- state = "mounting";
9
- /**
10
- * Callbacks to run before the hook is destroyed.
11
- */
12
- _beforeDestroyCallbacks = [];
13
- /**
14
- * Registers a callback to be called before the hook is destroyed.
15
- * Callbacks are called in LIFO order (last registered, first called).
16
- */
17
- onBeforeDestroy(t) {
18
- this._beforeDestroyCallbacks.push(t);
19
- }
20
- /**
21
- * The canonical snapshot of the Livewire component.
22
- */
23
- get canonical() {
24
- return this.livewireComponent.canonical;
25
- }
26
- /**
27
- * The root HTML element of the Livewire component.
28
- */
29
- get element() {
30
- return this.livewireComponent.el;
31
- }
32
- /**
33
- * The wire interface for the Livewire component.
34
- */
35
- get $wire() {
36
- return this.livewireComponent.$wire;
37
- }
38
- /**
39
- * Checks if the hook is in the process of being destroyed.
40
- */
41
- isBeingDestroyed() {
42
- return ["destroyed", "destroying"].includes(this.state);
43
- }
44
- /**
45
- * Runs all registered before-destroy callbacks and clears the list.
46
- * Called internally by makeHook before destroyed().
47
- */
48
- _runBeforeDestroyCallbacks() {
49
- for (const t of this._beforeDestroyCallbacks.reverse())
50
- t();
51
- this._beforeDestroyCallbacks = [];
52
- }
53
- }
54
- function G(i, t) {
55
- const e = /* @__PURE__ */ new Map();
56
- window.Livewire?.hook("component.init", async ({ component: r, cleanup: n }) => {
57
- if (r.name !== i)
58
- return;
59
- const a = new t(r);
60
- e.set(r.id, a), n(async () => {
61
- a.state = "destroying", a._runBeforeDestroyCallbacks(), await a.destroyed(), a.state = "destroyed", e.delete(r.id);
62
- }), await a.mounted(), a.state = "mounted";
63
- }), window.Livewire?.hook("commit", async ({ component: r, succeed: n }) => {
64
- r.name === i && n(() => {
65
- const a = e.get(r.id);
66
- a?.state === "mounted" && a?.afterCommitSynced?.();
67
- });
68
- });
69
- }
70
- class V {
71
- /**
72
- * Map of registered items.
73
- */
74
- items = /* @__PURE__ */ new Map();
75
- /**
76
- * Map of initialization errors for items that failed to register.
77
- */
78
- initializationErrors = /* @__PURE__ */ new Map();
79
- /**
80
- * Map of pending callbacks waiting for items to be registered or fail.
81
- */
82
- pendingCallbacks = /* @__PURE__ */ new Map();
83
- /**
84
- * Set of watchers that observe changes to the registry.
85
- */
86
- watchers = /* @__PURE__ */ new Set();
87
- /**
88
- * Executes a function on an item.
89
- * If the item is not yet registered, it will wait for it to be registered.
90
- *
91
- * @param id The ID of the item.
92
- * @param onSuccess The function to execute.
93
- * @param onError Optional error callback.
94
- * @returns A promise that resolves with the result of the function.
95
- */
96
- execute(t, e, r) {
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) => {
99
- const c = this.getPendingCallbacks(t);
100
- c.success.push(async (u) => {
101
- o(await e(u));
102
- }), r ? c.error.push(r) : c.error.push(s);
103
- });
104
- }
105
- /**
106
- * Registers an item.
107
- *
108
- * @param id The ID of the item.
109
- * @param item The item instance.
110
- */
111
- register(t, e) {
112
- if (this.items.has(t))
113
- throw new Error(`Item with ID "${t}" is already registered.`);
114
- this.resetErrors(t), this.items.set(t, e);
115
- const r = this.pendingCallbacks.get(t);
116
- r && (r.success.forEach((n) => n(e)), this.pendingCallbacks.delete(t)), this.registerAsDefault(t, e), this.notifyWatchers();
117
- }
118
- /**
119
- * Registers an error for an item.
120
- *
121
- * @param id The ID of the item.
122
- * @param error The error to register.
123
- */
124
- error(t, e) {
125
- this.items.delete(t), this.initializationErrors.set(t, e);
126
- const r = this.pendingCallbacks.get(t);
127
- r && (r.error.forEach((n) => n(e)), this.pendingCallbacks.delete(t)), this.initializationErrors.size === 1 && !this.items.size && this.error(null, e), this.notifyWatchers();
128
- }
129
- /**
130
- * Resets errors for an item.
131
- *
132
- * @param id The ID of the item.
133
- */
134
- resetErrors(t) {
135
- const { initializationErrors: e } = this;
136
- e.has(null) && e.get(null) === e.get(t) && e.delete(null), e.delete(t);
137
- }
138
- /**
139
- * Un-registers an item.
140
- *
141
- * @param id The ID of the item.
142
- */
143
- unregister(t) {
144
- if (!this.items.has(t))
145
- throw new Error(`Item with ID "${t}" is not registered.`);
146
- t && this.items.get(null) === this.items.get(t) && this.unregister(null), this.items.delete(t), this.pendingCallbacks.delete(t), this.notifyWatchers();
147
- }
148
- /**
149
- * Gets all registered items.
150
- *
151
- * @returns An array of all registered items.
152
- */
153
- getItems() {
154
- return Array.from(this.items.values());
155
- }
156
- /**
157
- * Checks if an item with the given ID is registered.
158
- *
159
- * @param id The ID of the item.
160
- * @returns `true` if the item is registered, `false` otherwise.
161
- */
162
- hasItem(t) {
163
- return this.items.has(t);
164
- }
165
- /**
166
- * Gets a promise that resolves with the item instance for the given ID.
167
- * If the item is not registered yet, it will wait for it to be registered.
168
- *
169
- * @param id The ID of the item.
170
- * @returns A promise that resolves with the item instance.
171
- */
172
- waitFor(t) {
173
- return new Promise((e, r) => {
174
- this.execute(t, e, r);
175
- });
176
- }
177
- /**
178
- * Destroys all registered items and clears the registry.
179
- * This will call the `destroy` method on each item.
180
- */
181
- async destroyAll() {
182
- const t = Array.from(new Set(this.items.values())).map((e) => e.destroy());
183
- this.items.clear(), this.pendingCallbacks.clear(), await Promise.all(t), this.notifyWatchers();
184
- }
185
- /**
186
- * Registers a watcher that will be called whenever the registry changes.
187
- *
188
- * @param watcher The watcher function to register.
189
- * @returns A function to unregister the watcher.
190
- */
191
- watch(t) {
192
- return this.watchers.add(t), t(
193
- new Map(this.items),
194
- new Map(this.initializationErrors)
195
- ), this.unwatch.bind(this, t);
196
- }
197
- /**
198
- * Un-registers a watcher.
199
- *
200
- * @param watcher The watcher function to unregister.
201
- */
202
- unwatch(t) {
203
- this.watchers.delete(t);
204
- }
205
- /**
206
- * Notifies all watchers about changes to the registry.
207
- */
208
- notifyWatchers() {
209
- this.watchers.forEach(
210
- (t) => t(
211
- new Map(this.items),
212
- new Map(this.initializationErrors)
213
- )
214
- );
215
- }
216
- /**
217
- * Gets or creates pending callbacks for a specific ID.
218
- *
219
- * @param id The ID of the item.
220
- * @returns The pending callbacks structure.
221
- */
222
- getPendingCallbacks(t) {
223
- let e = this.pendingCallbacks.get(t);
224
- return e || (e = { success: [], error: [] }, this.pendingCallbacks.set(t, e)), e;
225
- }
226
- /**
227
- * Registers an item as the default (null ID) item if it's the first one.
228
- *
229
- * @param id The ID of the item being registered.
230
- * @param item The item instance.
231
- */
232
- registerAsDefault(t, e) {
233
- this.items.size === 1 && t !== null && this.register(null, e);
234
- }
235
- }
236
- function S(i, t) {
237
- let e = null;
238
- return (...r) => {
239
- e && clearTimeout(e), e = setTimeout(() => {
240
- t(...r);
241
- }, i);
242
- };
243
- }
244
- function Y(i, t) {
245
- const e = Object.entries(i).filter(([r, n]) => t(n, r));
246
- return Object.fromEntries(e);
247
- }
248
- function W(i) {
249
- return Object.keys(i).length === 0 && i.constructor === Object;
250
- }
251
- function R(i, t) {
252
- const e = Object.entries(i).map(([r, n]) => [r, t(n, r)]);
253
- return Object.fromEntries(e);
254
- }
255
- function C(i, t) {
256
- if (i === t)
257
- return !0;
258
- const e = Object.keys(i), r = Object.keys(t);
259
- if (e.length !== r.length)
260
- return !1;
261
- for (const n of e)
262
- if (i[n] !== t[n] || !Object.prototype.hasOwnProperty.call(t, n))
263
- return !1;
264
- return !0;
265
- }
266
- function X() {
267
- return Math.random().toString(36).substring(2);
268
- }
269
- function J(i, {
270
- timeOutAfter: t = 500,
271
- retryAfter: e = 100
272
- } = {}) {
273
- return new Promise((r, n) => {
274
- const a = Date.now();
275
- let o = null;
276
- const s = setTimeout(() => {
277
- n(o ?? new Error("Timeout"));
278
- }, t), c = async () => {
279
- try {
280
- const u = await i();
281
- clearTimeout(s), r(u);
282
- } catch (u) {
283
- o = u, Date.now() - a > t ? n(u) : setTimeout(c, e);
284
- }
285
- };
286
- c();
287
- });
288
- }
289
- const O = Symbol.for("context-editor-watchdog");
290
- async function Q({ element: i, context: t, creator: e, config: r }) {
291
- const n = X();
292
- await t.add({
293
- creator: (c, u) => e.create(c, u),
294
- id: n,
295
- sourceElementOrData: i,
296
- type: "editor",
297
- config: r
298
- });
299
- const a = t.getItem(n), o = {
300
- state: "available",
301
- editorContextId: n,
302
- context: t
303
- };
304
- a[O] = o;
305
- const s = t.destroy.bind(t);
306
- return t.destroy = async () => (o.state = "unavailable", s()), {
307
- ...o,
308
- editor: a
309
- };
310
- }
311
- function Z(i) {
312
- return O in i ? i[O] : null;
313
- }
314
- function tt(i) {
315
- return i.model.document.getRootNames().reduce((e, r) => (e[r] = i.getData({ rootName: r }), e), /* @__PURE__ */ Object.create({}));
316
- }
317
- function k(i) {
318
- return ["inline", "classic", "balloon", "decoupled"].includes(i);
319
- }
320
- function B(i) {
321
- let t = i;
322
- for (; t; ) {
323
- for (const e of t.attributes)
324
- if (e.name.startsWith("wire:model"))
325
- return !0;
326
- t = t.parentElement;
327
- }
328
- return !1;
329
- }
330
- async function et(i) {
331
- const t = await import("ckeditor5"), r = {
332
- inline: t.InlineEditor,
333
- balloon: t.BalloonEditor,
334
- classic: t.ClassicEditor,
335
- decoupled: t.DecoupledEditor,
336
- multiroot: t.MultiRootEditor
337
- }[i];
338
- if (!r)
339
- throw new Error(`Unsupported editor type: ${i}`);
340
- return r;
341
- }
342
- class H {
343
- static the = new H();
344
- /**
345
- * Map of registered custom plugins.
346
- */
347
- plugins = /* @__PURE__ */ new Map();
348
- /**
349
- * Private constructor to enforce singleton pattern.
350
- */
351
- constructor() {
352
- }
353
- /**
354
- * Registers a custom plugin for the CKEditor.
355
- *
356
- * @param name The name of the plugin.
357
- * @param reader The plugin reader function that returns the plugin constructor.
358
- * @returns A function to unregister the plugin.
359
- */
360
- register(t, e) {
361
- if (this.plugins.has(t))
362
- throw new Error(`Plugin with name "${t}" is already registered.`);
363
- return this.plugins.set(t, e), this.unregister.bind(this, t);
364
- }
365
- /**
366
- * Removes a custom plugin by its name.
367
- *
368
- * @param name The name of the plugin to unregister.
369
- * @throws Will throw an error if the plugin is not registered.
370
- */
371
- unregister(t) {
372
- if (!this.plugins.has(t))
373
- throw new Error(`Plugin with name "${t}" is not registered.`);
374
- this.plugins.delete(t);
375
- }
376
- /**
377
- * Removes all custom editor plugins.
378
- * This is useful for cleanup in tests or when reloading plugins.
379
- */
380
- unregisterAll() {
381
- this.plugins.clear();
382
- }
383
- /**
384
- * Retrieves a custom plugin by its name.
385
- *
386
- * @param name The name of the plugin.
387
- * @returns The plugin constructor or undefined if not found.
388
- */
389
- async get(t) {
390
- return this.plugins.get(t)?.();
391
- }
392
- /**
393
- * Checks if a plugin with the given name is registered.
394
- *
395
- * @param name The name of the plugin.
396
- * @returns `true` if the plugin is registered, `false` otherwise.
397
- */
398
- has(t) {
399
- return this.plugins.has(t);
400
- }
401
- }
402
- async function N(i) {
403
- const t = await import("ckeditor5");
404
- let e = null;
405
- const r = i.map(async (n) => {
406
- const a = await H.the.get(n);
407
- if (a)
408
- return a;
409
- const { [n]: o } = t;
410
- if (o)
411
- return o;
412
- if (!e)
413
- try {
414
- e = await import("ckeditor5-premium-features");
415
- } catch (c) {
416
- console.error(`Failed to load premium package: ${c}`);
417
- }
418
- const { [n]: s } = e || {};
419
- if (s)
420
- return s;
421
- throw new Error(`Plugin "${n}" not found in base or premium packages.`);
422
- });
423
- return {
424
- loadedPlugins: await Promise.all(r),
425
- hasPremium: !!e
426
- };
427
- }
428
- async function q(i, t) {
429
- const e = [i.ui, i.content];
430
- return await Promise.all(
431
- [
432
- L("ckeditor5", e),
433
- /* v8 ignore next */
434
- t && L("ckeditor5-premium-features", e)
435
- ].filter((n) => !!n)
436
- ).then((n) => n.flat());
437
- }
438
- async function L(i, t) {
439
- return await Promise.all(
440
- t.filter((e) => e !== "en").map(async (e) => {
441
- const r = await rt(i, e);
442
- return r?.default ?? r;
443
- }).filter(Boolean)
444
- );
445
- }
446
- async function rt(i, t) {
447
- try {
448
- if (i === "ckeditor5")
449
- switch (t) {
450
- case "af":
451
- return await import("ckeditor5/translations/af.js");
452
- case "ar":
453
- return await import("ckeditor5/translations/ar.js");
454
- case "ast":
455
- return await import("ckeditor5/translations/ast.js");
456
- case "az":
457
- return await import("ckeditor5/translations/az.js");
458
- case "bg":
459
- return await import("ckeditor5/translations/bg.js");
460
- case "bn":
461
- return await import("ckeditor5/translations/bn.js");
462
- case "bs":
463
- return await import("ckeditor5/translations/bs.js");
464
- case "ca":
465
- return await import("ckeditor5/translations/ca.js");
466
- case "cs":
467
- return await import("ckeditor5/translations/cs.js");
468
- case "da":
469
- return await import("ckeditor5/translations/da.js");
470
- case "de":
471
- return await import("ckeditor5/translations/de.js");
472
- case "de-ch":
473
- return await import("ckeditor5/translations/de-ch.js");
474
- case "el":
475
- return await import("ckeditor5/translations/el.js");
476
- case "en":
477
- return await import("ckeditor5/translations/en.js");
478
- case "en-au":
479
- return await import("ckeditor5/translations/en-au.js");
480
- case "en-gb":
481
- return await import("ckeditor5/translations/en-gb.js");
482
- case "eo":
483
- return await import("ckeditor5/translations/eo.js");
484
- case "es":
485
- return await import("ckeditor5/translations/es.js");
486
- case "es-co":
487
- return await import("ckeditor5/translations/es-co.js");
488
- case "et":
489
- return await import("ckeditor5/translations/et.js");
490
- case "eu":
491
- return await import("ckeditor5/translations/eu.js");
492
- case "fa":
493
- return await import("ckeditor5/translations/fa.js");
494
- case "fi":
495
- return await import("ckeditor5/translations/fi.js");
496
- case "fr":
497
- return await import("ckeditor5/translations/fr.js");
498
- case "gl":
499
- return await import("ckeditor5/translations/gl.js");
500
- case "gu":
501
- return await import("ckeditor5/translations/gu.js");
502
- case "he":
503
- return await import("ckeditor5/translations/he.js");
504
- case "hi":
505
- return await import("ckeditor5/translations/hi.js");
506
- case "hr":
507
- return await import("ckeditor5/translations/hr.js");
508
- case "hu":
509
- return await import("ckeditor5/translations/hu.js");
510
- case "hy":
511
- return await import("ckeditor5/translations/hy.js");
512
- case "id":
513
- return await import("ckeditor5/translations/id.js");
514
- case "it":
515
- return await import("ckeditor5/translations/it.js");
516
- case "ja":
517
- return await import("ckeditor5/translations/ja.js");
518
- case "jv":
519
- return await import("ckeditor5/translations/jv.js");
520
- case "kk":
521
- return await import("ckeditor5/translations/kk.js");
522
- case "km":
523
- return await import("ckeditor5/translations/km.js");
524
- case "kn":
525
- return await import("ckeditor5/translations/kn.js");
526
- case "ko":
527
- return await import("ckeditor5/translations/ko.js");
528
- case "ku":
529
- return await import("ckeditor5/translations/ku.js");
530
- case "lt":
531
- return await import("ckeditor5/translations/lt.js");
532
- case "lv":
533
- return await import("ckeditor5/translations/lv.js");
534
- case "ms":
535
- return await import("ckeditor5/translations/ms.js");
536
- case "nb":
537
- return await import("ckeditor5/translations/nb.js");
538
- case "ne":
539
- return await import("ckeditor5/translations/ne.js");
540
- case "nl":
541
- return await import("ckeditor5/translations/nl.js");
542
- case "no":
543
- return await import("ckeditor5/translations/no.js");
544
- case "oc":
545
- return await import("ckeditor5/translations/oc.js");
546
- case "pl":
547
- return await import("ckeditor5/translations/pl.js");
548
- case "pt":
549
- return await import("ckeditor5/translations/pt.js");
550
- case "pt-br":
551
- return await import("ckeditor5/translations/pt-br.js");
552
- case "ro":
553
- return await import("ckeditor5/translations/ro.js");
554
- case "ru":
555
- return await import("ckeditor5/translations/ru.js");
556
- case "si":
557
- return await import("ckeditor5/translations/si.js");
558
- case "sk":
559
- return await import("ckeditor5/translations/sk.js");
560
- case "sl":
561
- return await import("ckeditor5/translations/sl.js");
562
- case "sq":
563
- return await import("ckeditor5/translations/sq.js");
564
- case "sr":
565
- return await import("ckeditor5/translations/sr.js");
566
- case "sr-latn":
567
- return await import("ckeditor5/translations/sr-latn.js");
568
- case "sv":
569
- return await import("ckeditor5/translations/sv.js");
570
- case "th":
571
- return await import("ckeditor5/translations/th.js");
572
- case "tk":
573
- return await import("ckeditor5/translations/tk.js");
574
- case "tr":
575
- return await import("ckeditor5/translations/tr.js");
576
- case "tt":
577
- return await import("ckeditor5/translations/tt.js");
578
- case "ug":
579
- return await import("ckeditor5/translations/ug.js");
580
- case "uk":
581
- return await import("ckeditor5/translations/uk.js");
582
- case "ur":
583
- return await import("ckeditor5/translations/ur.js");
584
- case "uz":
585
- return await import("ckeditor5/translations/uz.js");
586
- case "vi":
587
- return await import("ckeditor5/translations/vi.js");
588
- case "zh":
589
- return await import("ckeditor5/translations/zh.js");
590
- case "zh-cn":
591
- return await import("ckeditor5/translations/zh-cn.js");
592
- default:
593
- return console.warn(`Language ${t} not found in ckeditor5 translations`), null;
594
- }
595
- else
596
- switch (t) {
597
- case "af":
598
- return await import("ckeditor5-premium-features/translations/af.js");
599
- case "ar":
600
- return await import("ckeditor5-premium-features/translations/ar.js");
601
- case "ast":
602
- return await import("ckeditor5-premium-features/translations/ast.js");
603
- case "az":
604
- return await import("ckeditor5-premium-features/translations/az.js");
605
- case "bg":
606
- return await import("ckeditor5-premium-features/translations/bg.js");
607
- case "bn":
608
- return await import("ckeditor5-premium-features/translations/bn.js");
609
- case "bs":
610
- return await import("ckeditor5-premium-features/translations/bs.js");
611
- case "ca":
612
- return await import("ckeditor5-premium-features/translations/ca.js");
613
- case "cs":
614
- return await import("ckeditor5-premium-features/translations/cs.js");
615
- case "da":
616
- return await import("ckeditor5-premium-features/translations/da.js");
617
- case "de":
618
- return await import("ckeditor5-premium-features/translations/de.js");
619
- case "de-ch":
620
- return await import("ckeditor5-premium-features/translations/de-ch.js");
621
- case "el":
622
- return await import("ckeditor5-premium-features/translations/el.js");
623
- case "en":
624
- return await import("ckeditor5-premium-features/translations/en.js");
625
- case "en-au":
626
- return await import("ckeditor5-premium-features/translations/en-au.js");
627
- case "en-gb":
628
- return await import("ckeditor5-premium-features/translations/en-gb.js");
629
- case "eo":
630
- return await import("ckeditor5-premium-features/translations/eo.js");
631
- case "es":
632
- return await import("ckeditor5-premium-features/translations/es.js");
633
- case "es-co":
634
- return await import("ckeditor5-premium-features/translations/es-co.js");
635
- case "et":
636
- return await import("ckeditor5-premium-features/translations/et.js");
637
- case "eu":
638
- return await import("ckeditor5-premium-features/translations/eu.js");
639
- case "fa":
640
- return await import("ckeditor5-premium-features/translations/fa.js");
641
- case "fi":
642
- return await import("ckeditor5-premium-features/translations/fi.js");
643
- case "fr":
644
- return await import("ckeditor5-premium-features/translations/fr.js");
645
- case "gl":
646
- return await import("ckeditor5-premium-features/translations/gl.js");
647
- case "gu":
648
- return await import("ckeditor5-premium-features/translations/gu.js");
649
- case "he":
650
- return await import("ckeditor5-premium-features/translations/he.js");
651
- case "hi":
652
- return await import("ckeditor5-premium-features/translations/hi.js");
653
- case "hr":
654
- return await import("ckeditor5-premium-features/translations/hr.js");
655
- case "hu":
656
- return await import("ckeditor5-premium-features/translations/hu.js");
657
- case "hy":
658
- return await import("ckeditor5-premium-features/translations/hy.js");
659
- case "id":
660
- return await import("ckeditor5-premium-features/translations/id.js");
661
- case "it":
662
- return await import("ckeditor5-premium-features/translations/it.js");
663
- case "ja":
664
- return await import("ckeditor5-premium-features/translations/ja.js");
665
- case "jv":
666
- return await import("ckeditor5-premium-features/translations/jv.js");
667
- case "kk":
668
- return await import("ckeditor5-premium-features/translations/kk.js");
669
- case "km":
670
- return await import("ckeditor5-premium-features/translations/km.js");
671
- case "kn":
672
- return await import("ckeditor5-premium-features/translations/kn.js");
673
- case "ko":
674
- return await import("ckeditor5-premium-features/translations/ko.js");
675
- case "ku":
676
- return await import("ckeditor5-premium-features/translations/ku.js");
677
- case "lt":
678
- return await import("ckeditor5-premium-features/translations/lt.js");
679
- case "lv":
680
- return await import("ckeditor5-premium-features/translations/lv.js");
681
- case "ms":
682
- return await import("ckeditor5-premium-features/translations/ms.js");
683
- case "nb":
684
- return await import("ckeditor5-premium-features/translations/nb.js");
685
- case "ne":
686
- return await import("ckeditor5-premium-features/translations/ne.js");
687
- case "nl":
688
- return await import("ckeditor5-premium-features/translations/nl.js");
689
- case "no":
690
- return await import("ckeditor5-premium-features/translations/no.js");
691
- case "oc":
692
- return await import("ckeditor5-premium-features/translations/oc.js");
693
- case "pl":
694
- return await import("ckeditor5-premium-features/translations/pl.js");
695
- case "pt":
696
- return await import("ckeditor5-premium-features/translations/pt.js");
697
- case "pt-br":
698
- return await import("ckeditor5-premium-features/translations/pt-br.js");
699
- case "ro":
700
- return await import("ckeditor5-premium-features/translations/ro.js");
701
- case "ru":
702
- return await import("ckeditor5-premium-features/translations/ru.js");
703
- case "si":
704
- return await import("ckeditor5-premium-features/translations/si.js");
705
- case "sk":
706
- return await import("ckeditor5-premium-features/translations/sk.js");
707
- case "sl":
708
- return await import("ckeditor5-premium-features/translations/sl.js");
709
- case "sq":
710
- return await import("ckeditor5-premium-features/translations/sq.js");
711
- case "sr":
712
- return await import("ckeditor5-premium-features/translations/sr.js");
713
- case "sr-latn":
714
- return await import("ckeditor5-premium-features/translations/sr-latn.js");
715
- case "sv":
716
- return await import("ckeditor5-premium-features/translations/sv.js");
717
- case "th":
718
- return await import("ckeditor5-premium-features/translations/th.js");
719
- case "tk":
720
- return await import("ckeditor5-premium-features/translations/tk.js");
721
- case "tr":
722
- return await import("ckeditor5-premium-features/translations/tr.js");
723
- case "tt":
724
- return await import("ckeditor5-premium-features/translations/tt.js");
725
- case "ug":
726
- return await import("ckeditor5-premium-features/translations/ug.js");
727
- case "uk":
728
- return await import("ckeditor5-premium-features/translations/uk.js");
729
- case "ur":
730
- return await import("ckeditor5-premium-features/translations/ur.js");
731
- case "uz":
732
- return await import("ckeditor5-premium-features/translations/uz.js");
733
- case "vi":
734
- return await import("ckeditor5-premium-features/translations/vi.js");
735
- case "zh":
736
- return await import("ckeditor5-premium-features/translations/zh.js");
737
- case "zh-cn":
738
- return await import("ckeditor5-premium-features/translations/zh-cn.js");
739
- default:
740
- return console.warn(`Language ${t} not found in premium translations`), await import("ckeditor5-premium-features/translations/en.js");
741
- }
742
- } catch (e) {
743
- return console.error(`Failed to load translation for ${i}/${t}:`, e), null;
744
- }
745
- }
746
- function _(i) {
747
- return R(i, (t) => ({
748
- dictionary: t
749
- }));
750
- }
751
- function j(i) {
752
- const t = U(i);
753
- return R(t, ({ element: e }) => e);
754
- }
755
- function U(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]: {
759
- element: c.querySelector("[data-cke-editable-content]"),
760
- content: s.content
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;
763
- return a && r?.main ? {
764
- ...t,
765
- main: {
766
- ...a,
767
- content: a.content || r.main
768
- }
769
- } : n ? {
770
- ...t,
771
- main: {
772
- element: n,
773
- content: r?.main || null
774
- }
775
- } : t;
776
- }
777
- function F(i) {
778
- const t = U(i), e = R(t, ({ content: r }) => r);
779
- return Y(e, (r) => typeof r == "string");
780
- }
781
- function v(i) {
782
- if (!i || typeof i != "object")
783
- return i;
784
- if (Array.isArray(i))
785
- return i.map((r) => v(r));
786
- const t = i;
787
- if (t.$element && typeof t.$element == "string") {
788
- const r = document.querySelector(t.$element);
789
- return r || console.warn(`Element not found for selector: ${t.$element}`), r || null;
790
- }
791
- const e = /* @__PURE__ */ Object.create(null);
792
- for (const [r, n] of Object.entries(i))
793
- e[r] = v(n);
794
- return e;
795
- }
796
- function P(i, t, e) {
797
- if (!e || typeof e != "object")
798
- return e;
799
- if (Array.isArray(e))
800
- return e.map((a) => P(i, t, a));
801
- const r = e;
802
- if (r.$translation && typeof r.$translation == "string") {
803
- const a = r.$translation, o = it(i, a, t);
804
- return o === void 0 && console.warn(`Translation not found for key: ${a}`), o !== void 0 ? o : null;
805
- }
806
- const n = /* @__PURE__ */ Object.create(null);
807
- for (const [a, o] of Object.entries(e))
808
- n[a] = P(i, t, o);
809
- return n;
810
- }
811
- function it(i, t, e) {
812
- for (const r of i) {
813
- const n = r[e];
814
- if (n?.dictionary && t in n.dictionary)
815
- return n.dictionary[t];
816
- }
817
- }
818
- function nt(i, t) {
819
- const { editing: e } = i;
820
- e.view.change((r) => {
821
- r.setStyle("height", `${t}px`, e.view.document.getRoot());
822
- });
823
- }
824
- const $ = Symbol.for("elixir-editor-watchdog");
825
- async function at(i) {
826
- const { EditorWatchdog: t } = await import("ckeditor5"), e = new t(i);
827
- return e.setCreator(async (...r) => {
828
- const n = await i.create(...r);
829
- return n[$] = e, n;
830
- }), {
831
- watchdog: e,
832
- Constructor: {
833
- create: async (...r) => (await e.create(...r), e.editor)
834
- }
835
- };
836
- }
837
- function ot(i) {
838
- return $ in i ? i[$] : null;
839
- }
840
- class g extends V {
841
- static the = new g();
842
- }
843
- class st extends D {
844
- /**
845
- * The promise that resolves to the context instance.
846
- */
847
- contextPromise = null;
848
- /**
849
- * Mounts the context component.
850
- */
851
- async mounted() {
852
- const { contextId: t, language: e, context: r } = this.canonical, { customTranslations: n, watchdogConfig: a, config: { plugins: o, ...s } } = r, { loadedPlugins: c, hasPremium: u } = await N(o ?? []), y = [
853
- ...await q(e, u),
854
- _(n || {})
855
- ].filter((E) => !W(E));
856
- this.contextPromise = (async () => {
857
- const { ContextWatchdog: E, Context: w } = await import("ckeditor5"), h = new E(w, {
858
- crashNumberLimit: 10,
859
- ...a
860
- });
861
- let p = v(s);
862
- return p = P([...y].reverse(), e.ui, p), await h.create({
863
- ...p,
864
- language: e,
865
- plugins: c,
866
- ...y.length && {
867
- translations: y
868
- }
869
- }), h.on("itemError", (...I) => {
870
- console.error("Context item error:", ...I);
871
- }), h;
872
- })();
873
- const T = await this.contextPromise;
874
- this.isBeingDestroyed() || g.the.register(t, T);
875
- }
876
- /**
877
- * Destroys the context component. Unmounts root from the editor.
878
- */
879
- async destroyed() {
880
- const { contextId: t } = this.canonical;
881
- this.element.style.display = "none";
882
- try {
883
- await (await this.contextPromise)?.destroy();
884
- } finally {
885
- this.contextPromise = null, g.the.hasItem(t) && g.the.unregister(t);
886
- }
887
- }
888
- }
889
- class d extends V {
890
- static the = new d();
891
- }
892
- class ct extends D {
893
- /**
894
- * The promise that resolves when the editable is mounted.
895
- */
896
- editorPromise = null;
897
- /**
898
- * Pending content to apply when the editor loses focus.
899
- */
900
- pendingContent = null;
901
- /**
902
- * Mounts the editable component.
903
- */
904
- mounted() {
905
- const { editorId: t, rootName: e, content: r } = this.canonical;
906
- this.editorPromise = d.the.execute(t, (n) => {
907
- if (this.isBeingDestroyed())
908
- return null;
909
- const { ui: a, editing: o, model: s } = n;
910
- if (s.document.getRoot(e)) {
911
- if (r !== null) {
912
- const c = n.getData({ rootName: e });
913
- c && c !== r && n.setData({
914
- [e]: r
915
- });
916
- }
917
- } else {
918
- n.addRoot(e, {
919
- isUndoable: !1,
920
- ...r !== null && {
921
- data: r
922
- }
923
- });
924
- const c = this.element.querySelector("[data-cke-editable-content]"), u = a.view.createEditable(e, c);
925
- a.addEditable(u), o.view.forceRender();
926
- }
927
- return this.syncTypingContentPush(n), this.setupPendingReceivedContentHandlers(n), n;
928
- });
929
- }
930
- /**
931
- * Setups the content sync from the editor to Livewire on user input with debounce.
932
- */
933
- syncTypingContentPush(t) {
934
- const { rootName: e, saveDebounceMs: r } = this.canonical, n = this.element.querySelector("input"), a = () => {
935
- const s = t.getData({ rootName: e });
936
- n && (n.value = s), this.$wire.set("content", s);
937
- }, o = S(r, a);
938
- t.model.document.on("change:data", o), a(), this.onBeforeDestroy(() => {
939
- t.model.document.off("change:data", o);
940
- });
941
- }
942
- /**
943
- * Sets up handlers that manage pending incoming content (clears pending
944
- * content on user edits and applies pending content on blur).
945
- */
946
- setupPendingReceivedContentHandlers(t) {
947
- const { ui: e, model: r } = t, { focusTracker: n } = e, { rootName: a } = this.canonical, o = () => {
948
- this.pendingContent = null;
949
- }, s = () => {
950
- !n.isFocused && this.pendingContent !== null && (t.setData({
951
- [a]: this.pendingContent
952
- }), this.pendingContent = null);
953
- };
954
- r.document.on("change:data", o), n.on("change:isFocused", s), this.onBeforeDestroy(() => {
955
- r.document.off("change:data", o), n.off("change:isFocused", s);
956
- });
957
- }
958
- /**
959
- * Applies canonical content to the editor while respecting focus/pending state.
960
- */
961
- applyCanonicalContentToEditor(t) {
962
- if (!B(this.element))
963
- return;
964
- const { content: e, rootName: r } = this.canonical, { ui: n } = t;
965
- if (t.getData({ rootName: r }) !== (e ?? "")) {
966
- if (n.focusTracker.isFocused) {
967
- this.pendingContent = e ?? "";
968
- return;
969
- }
970
- t.setData({ [r]: e ?? "" });
971
- }
972
- }
973
- /**
974
- * Called when the component is updated by Livewire.
975
- */
976
- async afterCommitSynced() {
977
- const t = await this.editorPromise;
978
- this.applyCanonicalContentToEditor(t);
979
- }
980
- /**
981
- * Destroys the editable component. Unmounts root from the editor.
982
- */
983
- async destroyed() {
984
- const { rootName: t } = this.canonical;
985
- this.element.style.display = "none";
986
- const e = await this.editorPromise;
987
- if (this.editorPromise = null, e && e.state !== "destroyed") {
988
- const r = e.model.document.getRoot(t);
989
- r && "detachEditable" in e && (e.detachEditable(r), e.detachRoot(t, !1));
990
- }
991
- }
992
- }
993
- async function ut({
994
- saveDebounceMs: i,
995
- component: t
996
- }) {
997
- const { Plugin: e } = await import("ckeditor5");
998
- return class extends e {
999
- /**
1000
- * The name of the plugin.
1001
- */
1002
- static get pluginName() {
1003
- return "LivewireSync";
1004
- }
1005
- /**
1006
- * Initializes the plugin.
1007
- */
1008
- init() {
1009
- this.setupTypingContentPush(), this.setupFocusableEventPush(), this.setupAfterCommitHandler(), this.setupSetEditorContentHandler(), this.setupReadyDispatch();
1010
- }
1011
- /**
1012
- * Setups handler that updates the editor content after Livewire changes attributes
1013
- * on the component and commits the changes, but only if the editor is not focused to prevent
1014
- * disrupting the user while editing.
1015
- */
1016
- setupAfterCommitHandler() {
1017
- const { editor: n } = this, { model: a, ui: { focusTracker: o } } = n;
1018
- let s = null;
1019
- n.on("afterCommitSynced", () => {
1020
- if (!B(t.element))
1021
- return;
1022
- const { content: c } = t.canonical, u = this.getEditorRootsValues();
1023
- if (o.isFocused) {
1024
- C(c, u) || (s = c);
1025
- return;
1026
- }
1027
- C(c, u) || n.setData(c);
1028
- }), a.document.on("change:data", () => {
1029
- s = null;
1030
- }), o.on("change:isFocused", () => {
1031
- !o.isFocused && s !== null && (n.setData(s), s = null);
1032
- });
1033
- }
1034
- /**
1035
- * Dispatches a Livewire event when the editor becomes ready.
1036
- *
1037
- * This allows the Livewire component or parent to react as soon as the
1038
- * instance is fully initialized. The payload contains the editorId so the
1039
- * listener can ignore events coming from other editors on the page.
1040
- */
1041
- setupReadyDispatch() {
1042
- const { $wire: n } = t;
1043
- this.editor.once("ready", () => {
1044
- n.dispatch("editor-ready", {
1045
- editorId: t.canonical.editorId
1046
- });
1047
- });
1048
- }
1049
- /**
1050
- * Setups the content sync from Livewire to the editor when Livewire emits an event.
1051
- */
1052
- setupSetEditorContentHandler() {
1053
- Livewire.on("set-editor-content", ({ editorId: n, content: a }) => {
1054
- if (n !== t.canonical.editorId)
1055
- return;
1056
- const o = this.getEditorRootsValues();
1057
- C(o, a) || this.editor.setData(a);
1058
- });
1059
- }
1060
- /**
1061
- * Setups the content push event for the editor.
1062
- */
1063
- setupTypingContentPush() {
1064
- const { model: n } = this.editor, { $wire: a } = t, o = () => {
1065
- const s = this.getEditorRootsValues();
1066
- C(s, t.canonical.content ?? {}) || (a.set("content", s), a.dispatch("editor-content-changed", {
1067
- editorId: t.canonical.editorId,
1068
- content: s
1069
- }));
1070
- };
1071
- n.document.on("change:data", S(i, o)), this.editor.once("ready", o);
1072
- }
1073
- /**
1074
- * Setups the event push for the editor.
1075
- */
1076
- setupFocusableEventPush() {
1077
- const { ui: n } = this.editor, { $wire: a } = t, o = () => {
1078
- const s = this.getEditorRootsValues();
1079
- a.set("focused", n.focusTracker.isFocused), C(s, t.canonical.content ?? {}) || a.set("content", s);
1080
- };
1081
- n.focusTracker.on("change:isFocused", o);
1082
- }
1083
- /**
1084
- * Gets the current values of all editor roots.
1085
- */
1086
- getEditorRootsValues() {
1087
- return tt(this.editor);
1088
- }
1089
- };
1090
- }
1091
- async function lt(i) {
1092
- const { Plugin: t } = await import("ckeditor5");
1093
- return class extends t {
1094
- /**
1095
- * The input element to synchronize with.
1096
- */
1097
- input = null;
1098
- /**
1099
- * The form element reference for cleanup.
1100
- */
1101
- form = null;
1102
- /**
1103
- * The name of the plugin.
1104
- */
1105
- static get pluginName() {
1106
- return "SyncEditorWithInput";
1107
- }
1108
- /**
1109
- * Initializes the plugin.
1110
- */
1111
- afterInit() {
1112
- const { editor: r } = this, a = r.sourceElement.id.replace(/_editor$/, "");
1113
- this.input = document.getElementById(`${a}_input`), this.input && (r.model.document.on("change:data", S(i, () => this.sync())), r.once("ready", this.sync), this.form = this.input.closest("form"), this.form?.addEventListener("submit", this.sync));
1114
- }
1115
- /**
1116
- * Synchronizes the editor's content with the input field.
1117
- */
1118
- sync = () => {
1119
- if (this.input) {
1120
- const r = this.editor.getData();
1121
- this.input.value = r, this.input.dispatchEvent(new Event("input", { bubbles: !0 }));
1122
- }
1123
- };
1124
- /**
1125
- * Destroys the plugin.
1126
- */
1127
- destroy() {
1128
- this.form && this.form.removeEventListener("submit", this.sync), this.input = null, this.form = null;
1129
- }
1130
- };
1131
- }
1132
- class dt extends D {
1133
- /**
1134
- * The promise that resolves to the editor instance.
1135
- */
1136
- editorPromise = null;
1137
- /**
1138
- * @inheritdoc
1139
- */
1140
- async mounted() {
1141
- const { editorId: t } = this.canonical;
1142
- d.the.resetErrors(t);
1143
- try {
1144
- this.editorPromise = this.createEditor();
1145
- const e = await this.editorPromise;
1146
- this.isBeingDestroyed() || (d.the.register(t, e), e.once("destroy", () => {
1147
- d.the.hasItem(t) && d.the.unregister(t);
1148
- }));
1149
- } catch (e) {
1150
- console.error(`Error initializing CKEditor5 instance with ID "${t}":`, e), this.editorPromise = null, d.the.error(t, e);
1151
- }
1152
- }
1153
- /**
1154
- * Destroys the editor instance when the component is destroyed.
1155
- * This is important to prevent memory leaks and ensure that the editor is properly cleaned up.
1156
- */
1157
- async destroyed() {
1158
- this.element.style.display = "none";
1159
- try {
1160
- const t = await this.editorPromise;
1161
- if (!t)
1162
- return;
1163
- const e = Z(t), r = ot(t);
1164
- e ? e.state !== "unavailable" && await e.context.remove(e.editorContextId) : r ? await r.destroy() : await t.destroy();
1165
- } finally {
1166
- this.editorPromise = null;
1167
- }
1168
- }
1169
- /**
1170
- * Updates the editor content when the component is updated after commit changes.
1171
- */
1172
- async afterCommitSynced() {
1173
- (await this.editorPromise)?.fire("afterCommitSynced");
1174
- }
1175
- /**
1176
- * Creates the CKEditor instance.
1177
- */
1178
- async createEditor() {
1179
- const {
1180
- preset: t,
1181
- editorId: e,
1182
- contextId: r,
1183
- editableHeight: n,
1184
- saveDebounceMs: a,
1185
- language: o,
1186
- watchdog: s,
1187
- content: c
1188
- } = this.canonical, {
1189
- customTranslations: u,
1190
- editorType: m,
1191
- licenseKey: y,
1192
- config: { plugins: T, ...E }
1193
- } = t;
1194
- let w = await et(m);
1195
- const h = await (r ? g.the.waitFor(r) : null);
1196
- if (s && !h) {
1197
- const l = await at(w);
1198
- ({ Constructor: w } = l), l.watchdog.on("restart", () => {
1199
- const f = l.watchdog.editor;
1200
- this.editorPromise = Promise.resolve(f), d.the.register(e, f);
1201
- });
1202
- }
1203
- const { loadedPlugins: p, hasPremium: I } = await N(T);
1204
- p.push(
1205
- await ut(
1206
- {
1207
- saveDebounceMs: a,
1208
- component: this
1209
- }
1210
- )
1211
- ), k(m) && p.push(
1212
- await lt(a)
1213
- );
1214
- const x = [
1215
- ...await q(o, I),
1216
- _(u || {})
1217
- ].filter((l) => !W(l));
1218
- let b = {
1219
- ...c,
1220
- ...F(e)
1221
- };
1222
- k(m) && (b = b.main || "");
1223
- const M = await (async () => {
1224
- let l = j(e);
1225
- if (!(l instanceof HTMLElement) && !("main" in l)) {
1226
- const A = m === "decoupled" ? ["main"] : Object.keys(b);
1227
- K(l, A) || (l = await mt(e, A), b = {
1228
- ...c,
1229
- ...F(e)
1230
- });
1231
- }
1232
- k(m) && "main" in l && (l = l.main);
1233
- let f = v(E);
1234
- f = P([...x].reverse(), o.ui, f);
1235
- const z = {
1236
- ...f,
1237
- initialData: b,
1238
- licenseKey: y,
1239
- plugins: p,
1240
- language: o,
1241
- ...x.length && {
1242
- translations: x
1243
- }
1244
- };
1245
- return !h || !(l instanceof HTMLElement) ? w.create(l, z) : (await Q({
1246
- context: h,
1247
- element: l,
1248
- creator: w,
1249
- config: z
1250
- })).editor;
1251
- })();
1252
- return k(m) && n && nt(M, n), M;
1253
- }
1254
- }
1255
- function K(i, t) {
1256
- return t.every((e) => i[e]);
1
+ //#region src/hooks/hook.ts
2
+ var e = class {
3
+ state = "mounting";
4
+ _beforeDestroyCallbacks = [];
5
+ constructor(e) {
6
+ this.livewireComponent = e;
7
+ }
8
+ onBeforeDestroy(e) {
9
+ this._beforeDestroyCallbacks.push(e);
10
+ }
11
+ get canonical() {
12
+ return this.livewireComponent.canonical;
13
+ }
14
+ get element() {
15
+ return this.livewireComponent.el;
16
+ }
17
+ get $wire() {
18
+ return this.livewireComponent.$wire;
19
+ }
20
+ isBeingDestroyed() {
21
+ return ["destroyed", "destroying"].includes(this.state);
22
+ }
23
+ _runBeforeDestroyCallbacks() {
24
+ for (let e of this._beforeDestroyCallbacks.reverse()) e();
25
+ this._beforeDestroyCallbacks = [];
26
+ }
27
+ };
28
+ function t(e, t) {
29
+ let n = /* @__PURE__ */ new Map();
30
+ window.Livewire?.hook("component.init", async ({ component: r, cleanup: i }) => {
31
+ if (r.name !== e) return;
32
+ let a = new t(r);
33
+ n.set(r.id, a), i(async () => {
34
+ a.state = "destroying", a._runBeforeDestroyCallbacks(), await a.destroyed(), a.state = "destroyed", n.delete(r.id);
35
+ }), await a.mounted(), a.state = "mounted";
36
+ }), window.Livewire?.hook("commit", async ({ component: t, succeed: r }) => {
37
+ t.name === e && r(() => {
38
+ let e = n.get(t.id);
39
+ /* v8 ignore next if -- @preserve */
40
+ e?.state === "mounted" && e?.afterCommitSynced?.();
41
+ });
42
+ });
43
+ }
44
+ //#endregion
45
+ //#region src/shared/async-registry.ts
46
+ var n = class {
47
+ items = /* @__PURE__ */ new Map();
48
+ initializationErrors = /* @__PURE__ */ new Map();
49
+ pendingCallbacks = /* @__PURE__ */ new Map();
50
+ watchers = /* @__PURE__ */ new Set();
51
+ execute(e, t, n) {
52
+ let r = this.items.get(e), i = this.initializationErrors.get(e);
53
+ return i ? (n?.(i), Promise.reject(i)) : r ? Promise.resolve(t(r)) : new Promise((r, i) => {
54
+ let a = this.getPendingCallbacks(e);
55
+ a.success.push(async (e) => {
56
+ r(await t(e));
57
+ }), n ? a.error.push(n) : a.error.push(i);
58
+ });
59
+ }
60
+ register(e, t) {
61
+ if (this.items.has(e)) throw Error(`Item with ID "${e}" is already registered.`);
62
+ this.resetErrors(e), this.items.set(e, t);
63
+ let n = this.pendingCallbacks.get(e);
64
+ n && (n.success.forEach((e) => e(t)), this.pendingCallbacks.delete(e)), this.registerAsDefault(e, t), this.notifyWatchers();
65
+ }
66
+ error(e, t) {
67
+ this.items.delete(e), this.initializationErrors.set(e, t);
68
+ let n = this.pendingCallbacks.get(e);
69
+ n && (n.error.forEach((e) => e(t)), this.pendingCallbacks.delete(e)), this.initializationErrors.size === 1 && !this.items.size && this.error(null, t), this.notifyWatchers();
70
+ }
71
+ resetErrors(e) {
72
+ let { initializationErrors: t } = this;
73
+ t.has(null) && t.get(null) === t.get(e) && t.delete(null), t.delete(e);
74
+ }
75
+ unregister(e) {
76
+ if (!this.items.has(e)) throw Error(`Item with ID "${e}" is not registered.`);
77
+ e && this.items.get(null) === this.items.get(e) && this.unregister(null), this.items.delete(e), this.pendingCallbacks.delete(e), this.notifyWatchers();
78
+ }
79
+ getItems() {
80
+ return Array.from(this.items.values());
81
+ }
82
+ hasItem(e) {
83
+ return this.items.has(e);
84
+ }
85
+ waitFor(e) {
86
+ return new Promise((t, n) => {
87
+ this.execute(e, t, n);
88
+ });
89
+ }
90
+ async destroyAll() {
91
+ let e = Array.from(new Set(this.items.values())).map((e) => e.destroy());
92
+ this.items.clear(), this.pendingCallbacks.clear(), await Promise.all(e), this.notifyWatchers();
93
+ }
94
+ watch(e) {
95
+ return this.watchers.add(e), e(new Map(this.items), new Map(this.initializationErrors)), this.unwatch.bind(this, e);
96
+ }
97
+ unwatch(e) {
98
+ this.watchers.delete(e);
99
+ }
100
+ notifyWatchers() {
101
+ this.watchers.forEach((e) => e(new Map(this.items), new Map(this.initializationErrors)));
102
+ }
103
+ getPendingCallbacks(e) {
104
+ let t = this.pendingCallbacks.get(e);
105
+ return t || (t = {
106
+ success: [],
107
+ error: []
108
+ }, this.pendingCallbacks.set(e, t)), t;
109
+ }
110
+ registerAsDefault(e, t) {
111
+ this.items.size === 1 && e !== null && this.register(null, t);
112
+ }
113
+ };
114
+ //#endregion
115
+ //#region src/shared/debounce.ts
116
+ function r(e, t) {
117
+ let n = null;
118
+ return (...r) => {
119
+ n && clearTimeout(n), n = setTimeout(() => {
120
+ t(...r);
121
+ }, e);
122
+ };
123
+ }
124
+ //#endregion
125
+ //#region src/shared/filter-object-values.ts
126
+ function i(e, t) {
127
+ let n = Object.entries(e).filter(([e, n]) => t(n, e));
128
+ return Object.fromEntries(n);
129
+ }
130
+ //#endregion
131
+ //#region src/shared/is-empty-object.ts
132
+ function a(e) {
133
+ return Object.keys(e).length === 0 && e.constructor === Object;
134
+ }
135
+ //#endregion
136
+ //#region src/shared/map-object-values.ts
137
+ function o(e, t) {
138
+ let n = Object.entries(e).map(([e, n]) => [e, t(n, e)]);
139
+ return Object.fromEntries(n);
140
+ }
141
+ //#endregion
142
+ //#region src/shared/shallow-equal.ts
143
+ function s(e, t) {
144
+ if (e === t) return !0;
145
+ let n = Object.keys(e), r = Object.keys(t);
146
+ if (n.length !== r.length) return !1;
147
+ for (let r of n) if (e[r] !== t[r] || !Object.prototype.hasOwnProperty.call(t, r)) return !1;
148
+ return !0;
149
+ }
150
+ //#endregion
151
+ //#region src/shared/uid.ts
152
+ function c() {
153
+ return Math.random().toString(36).substring(2);
154
+ }
155
+ //#endregion
156
+ //#region src/shared/wait-for.ts
157
+ function l(e, { timeOutAfter: t = 500, retryAfter: n = 100 } = {}) {
158
+ return new Promise((r, i) => {
159
+ let a = Date.now(), o = null, s = setTimeout(() => {
160
+ i(o ?? /* @__PURE__ */ Error("Timeout"));
161
+ }, t), c = async () => {
162
+ try {
163
+ let t = await e();
164
+ clearTimeout(s), r(t);
165
+ } catch (e) {
166
+ o = e, Date.now() - a > t ? i(e) : setTimeout(c, n);
167
+ }
168
+ };
169
+ c();
170
+ });
171
+ }
172
+ //#endregion
173
+ //#region src/hooks/editor/utils/create-editor-in-context.ts
174
+ var u = Symbol.for("context-editor-watchdog");
175
+ async function d({ element: e, context: t, creator: n, config: r }) {
176
+ let i = c();
177
+ await t.add({
178
+ creator: (e, t) => n.create(e, t),
179
+ id: i,
180
+ sourceElementOrData: e,
181
+ type: "editor",
182
+ config: r
183
+ });
184
+ let a = t.getItem(i), o = {
185
+ state: "available",
186
+ editorContextId: i,
187
+ context: t
188
+ };
189
+ a[u] = o;
190
+ let s = t.destroy.bind(t);
191
+ return t.destroy = async () => (o.state = "unavailable", s()), {
192
+ ...o,
193
+ editor: a
194
+ };
195
+ }
196
+ function f(e) {
197
+ return u in e ? e[u] : null;
198
+ }
199
+ //#endregion
200
+ //#region src/hooks/editor/utils/get-editor-roots-values.ts
201
+ function p(e) {
202
+ return e.model.document.getRootNames().reduce((t, n) => (t[n] = e.getData({ rootName: n }), t), Object.create({}));
203
+ }
204
+ //#endregion
205
+ //#region src/hooks/editor/utils/is-single-root-editor.ts
206
+ function m(e) {
207
+ return [
208
+ "inline",
209
+ "classic",
210
+ "balloon",
211
+ "decoupled"
212
+ ].includes(e);
213
+ }
214
+ //#endregion
215
+ //#region src/hooks/editor/utils/load-editor-constructor.ts
216
+ async function h(e) {
217
+ let t = await import("ckeditor5"), n = {
218
+ inline: t.InlineEditor,
219
+ balloon: t.BalloonEditor,
220
+ classic: t.ClassicEditor,
221
+ decoupled: t.DecoupledEditor,
222
+ multiroot: t.MultiRootEditor
223
+ }[e];
224
+ if (!n) throw Error(`Unsupported editor type: ${e}`);
225
+ return n;
226
+ }
227
+ //#endregion
228
+ //#region src/hooks/editor/custom-editor-plugins.ts
229
+ var g = class e {
230
+ static the = new e();
231
+ plugins = /* @__PURE__ */ new Map();
232
+ constructor() {}
233
+ register(e, t) {
234
+ if (this.plugins.has(e)) throw Error(`Plugin with name "${e}" is already registered.`);
235
+ return this.plugins.set(e, t), this.unregister.bind(this, e);
236
+ }
237
+ unregister(e) {
238
+ if (!this.plugins.has(e)) throw Error(`Plugin with name "${e}" is not registered.`);
239
+ this.plugins.delete(e);
240
+ }
241
+ unregisterAll() {
242
+ this.plugins.clear();
243
+ }
244
+ async get(e) {
245
+ return this.plugins.get(e)?.();
246
+ }
247
+ has(e) {
248
+ return this.plugins.has(e);
249
+ }
250
+ };
251
+ //#endregion
252
+ //#region src/hooks/editor/utils/load-editor-plugins.ts
253
+ async function _(e) {
254
+ let t = await import("ckeditor5"), n = null, r = e.map(async (e) => {
255
+ let r = await g.the.get(e);
256
+ if (r) return r;
257
+ let { [e]: i } = t;
258
+ if (i) return i;
259
+ /* v8 ignore start -- @preserve */
260
+ if (!n) try {
261
+ n = await import("ckeditor5-premium-features");
262
+ } catch (e) {
263
+ console.error(`Failed to load premium package: ${e}`);
264
+ }
265
+ /* v8 ignore end */
266
+ let { [e]: a } = n || {};
267
+ if (a) return a;
268
+ throw Error(`Plugin "${e}" not found in base or premium packages.`);
269
+ });
270
+ return {
271
+ loadedPlugins: await Promise.all(r),
272
+ hasPremium: !!n
273
+ };
274
+ }
275
+ //#endregion
276
+ //#region src/hooks/editor/utils/load-editor-translations.ts
277
+ async function v(e, t) {
278
+ let n = [e.ui, e.content], r = [y("ckeditor5", n)];
279
+ return t && r.push(y("ckeditor5-premium-features", n)), await Promise.all(r).then((e) => e.flat());
280
+ }
281
+ async function y(e, t) {
282
+ /* v8 ignore next */
283
+ return await Promise.all(t.filter((e) => e !== "en").map(async (t) => {
284
+ let n = await b(e, t);
285
+ /* v8 ignore next -- @preserve */
286
+ return n?.default ?? n;
287
+ }).filter(Boolean));
288
+ }
289
+ async function b(e, t) {
290
+ try {
291
+ /* v8 ignore next if -- @preserve */
292
+ if (e === "ckeditor5") switch (t) {
293
+ case "af": return await import("ckeditor5/translations/af.js");
294
+ case "ar": return await import("ckeditor5/translations/ar.js");
295
+ case "ast": return await import("ckeditor5/translations/ast.js");
296
+ case "az": return await import("ckeditor5/translations/az.js");
297
+ case "bg": return await import("ckeditor5/translations/bg.js");
298
+ case "bn": return await import("ckeditor5/translations/bn.js");
299
+ case "bs": return await import("ckeditor5/translations/bs.js");
300
+ case "ca": return await import("ckeditor5/translations/ca.js");
301
+ case "cs": return await import("ckeditor5/translations/cs.js");
302
+ case "da": return await import("ckeditor5/translations/da.js");
303
+ case "de": return await import("ckeditor5/translations/de.js");
304
+ case "de-ch": return await import("ckeditor5/translations/de-ch.js");
305
+ case "el": return await import("ckeditor5/translations/el.js");
306
+ case "en": return await import("ckeditor5/translations/en.js");
307
+ case "en-au": return await import("ckeditor5/translations/en-au.js");
308
+ case "en-gb": return await import("ckeditor5/translations/en-gb.js");
309
+ case "eo": return await import("ckeditor5/translations/eo.js");
310
+ case "es": return await import("ckeditor5/translations/es.js");
311
+ case "es-co": return await import("ckeditor5/translations/es-co.js");
312
+ case "et": return await import("ckeditor5/translations/et.js");
313
+ case "eu": return await import("ckeditor5/translations/eu.js");
314
+ case "fa": return await import("ckeditor5/translations/fa.js");
315
+ case "fi": return await import("ckeditor5/translations/fi.js");
316
+ case "fr": return await import("ckeditor5/translations/fr.js");
317
+ case "gl": return await import("ckeditor5/translations/gl.js");
318
+ case "gu": return await import("ckeditor5/translations/gu.js");
319
+ case "he": return await import("ckeditor5/translations/he.js");
320
+ case "hi": return await import("ckeditor5/translations/hi.js");
321
+ case "hr": return await import("ckeditor5/translations/hr.js");
322
+ case "hu": return await import("ckeditor5/translations/hu.js");
323
+ case "hy": return await import("ckeditor5/translations/hy.js");
324
+ case "id": return await import("ckeditor5/translations/id.js");
325
+ case "it": return await import("ckeditor5/translations/it.js");
326
+ case "ja": return await import("ckeditor5/translations/ja.js");
327
+ case "jv": return await import("ckeditor5/translations/jv.js");
328
+ case "kk": return await import("ckeditor5/translations/kk.js");
329
+ case "km": return await import("ckeditor5/translations/km.js");
330
+ case "kn": return await import("ckeditor5/translations/kn.js");
331
+ case "ko": return await import("ckeditor5/translations/ko.js");
332
+ case "ku": return await import("ckeditor5/translations/ku.js");
333
+ case "lt": return await import("ckeditor5/translations/lt.js");
334
+ case "lv": return await import("ckeditor5/translations/lv.js");
335
+ case "ms": return await import("ckeditor5/translations/ms.js");
336
+ case "nb": return await import("ckeditor5/translations/nb.js");
337
+ case "ne": return await import("ckeditor5/translations/ne.js");
338
+ case "nl": return await import("ckeditor5/translations/nl.js");
339
+ case "no": return await import("ckeditor5/translations/no.js");
340
+ case "oc": return await import("ckeditor5/translations/oc.js");
341
+ case "pl": return await import("ckeditor5/translations/pl.js");
342
+ case "pt": return await import("ckeditor5/translations/pt.js");
343
+ case "pt-br": return await import("ckeditor5/translations/pt-br.js");
344
+ case "ro": return await import("ckeditor5/translations/ro.js");
345
+ case "ru": return await import("ckeditor5/translations/ru.js");
346
+ case "si": return await import("ckeditor5/translations/si.js");
347
+ case "sk": return await import("ckeditor5/translations/sk.js");
348
+ case "sl": return await import("ckeditor5/translations/sl.js");
349
+ case "sq": return await import("ckeditor5/translations/sq.js");
350
+ case "sr": return await import("ckeditor5/translations/sr.js");
351
+ case "sr-latn": return await import("ckeditor5/translations/sr-latn.js");
352
+ case "sv": return await import("ckeditor5/translations/sv.js");
353
+ case "th": return await import("ckeditor5/translations/th.js");
354
+ case "tk": return await import("ckeditor5/translations/tk.js");
355
+ case "tr": return await import("ckeditor5/translations/tr.js");
356
+ case "tt": return await import("ckeditor5/translations/tt.js");
357
+ case "ug": return await import("ckeditor5/translations/ug.js");
358
+ case "uk": return await import("ckeditor5/translations/uk.js");
359
+ case "ur": return await import("ckeditor5/translations/ur.js");
360
+ case "uz": return await import("ckeditor5/translations/uz.js");
361
+ case "vi": return await import("ckeditor5/translations/vi.js");
362
+ case "zh": return await import("ckeditor5/translations/zh.js");
363
+ case "zh-cn": return await import("ckeditor5/translations/zh-cn.js");
364
+ default: return console.warn(`Language ${t} not found in ckeditor5 translations`), null;
365
+ }
366
+ else switch (t) {
367
+ case "af": return await import("ckeditor5-premium-features/translations/af.js");
368
+ case "ar": return await import("ckeditor5-premium-features/translations/ar.js");
369
+ case "ast": return await import("ckeditor5-premium-features/translations/ast.js");
370
+ case "az": return await import("ckeditor5-premium-features/translations/az.js");
371
+ case "bg": return await import("ckeditor5-premium-features/translations/bg.js");
372
+ case "bn": return await import("ckeditor5-premium-features/translations/bn.js");
373
+ case "bs": return await import("ckeditor5-premium-features/translations/bs.js");
374
+ case "ca": return await import("ckeditor5-premium-features/translations/ca.js");
375
+ case "cs": return await import("ckeditor5-premium-features/translations/cs.js");
376
+ case "da": return await import("ckeditor5-premium-features/translations/da.js");
377
+ case "de": return await import("ckeditor5-premium-features/translations/de.js");
378
+ case "de-ch": return await import("ckeditor5-premium-features/translations/de-ch.js");
379
+ case "el": return await import("ckeditor5-premium-features/translations/el.js");
380
+ case "en": return await import("ckeditor5-premium-features/translations/en.js");
381
+ case "en-au": return await import("ckeditor5-premium-features/translations/en-au.js");
382
+ case "en-gb": return await import("ckeditor5-premium-features/translations/en-gb.js");
383
+ case "eo": return await import("ckeditor5-premium-features/translations/eo.js");
384
+ case "es": return await import("ckeditor5-premium-features/translations/es.js");
385
+ case "es-co": return await import("ckeditor5-premium-features/translations/es-co.js");
386
+ case "et": return await import("ckeditor5-premium-features/translations/et.js");
387
+ case "eu": return await import("ckeditor5-premium-features/translations/eu.js");
388
+ case "fa": return await import("ckeditor5-premium-features/translations/fa.js");
389
+ case "fi": return await import("ckeditor5-premium-features/translations/fi.js");
390
+ case "fr": return await import("ckeditor5-premium-features/translations/fr.js");
391
+ case "gl": return await import("ckeditor5-premium-features/translations/gl.js");
392
+ case "gu": return await import("ckeditor5-premium-features/translations/gu.js");
393
+ case "he": return await import("ckeditor5-premium-features/translations/he.js");
394
+ case "hi": return await import("ckeditor5-premium-features/translations/hi.js");
395
+ case "hr": return await import("ckeditor5-premium-features/translations/hr.js");
396
+ case "hu": return await import("ckeditor5-premium-features/translations/hu.js");
397
+ case "hy": return await import("ckeditor5-premium-features/translations/hy.js");
398
+ case "id": return await import("ckeditor5-premium-features/translations/id.js");
399
+ case "it": return await import("ckeditor5-premium-features/translations/it.js");
400
+ case "ja": return await import("ckeditor5-premium-features/translations/ja.js");
401
+ case "jv": return await import("ckeditor5-premium-features/translations/jv.js");
402
+ case "kk": return await import("ckeditor5-premium-features/translations/kk.js");
403
+ case "km": return await import("ckeditor5-premium-features/translations/km.js");
404
+ case "kn": return await import("ckeditor5-premium-features/translations/kn.js");
405
+ case "ko": return await import("ckeditor5-premium-features/translations/ko.js");
406
+ case "ku": return await import("ckeditor5-premium-features/translations/ku.js");
407
+ case "lt": return await import("ckeditor5-premium-features/translations/lt.js");
408
+ case "lv": return await import("ckeditor5-premium-features/translations/lv.js");
409
+ case "ms": return await import("ckeditor5-premium-features/translations/ms.js");
410
+ case "nb": return await import("ckeditor5-premium-features/translations/nb.js");
411
+ case "ne": return await import("ckeditor5-premium-features/translations/ne.js");
412
+ case "nl": return await import("ckeditor5-premium-features/translations/nl.js");
413
+ case "no": return await import("ckeditor5-premium-features/translations/no.js");
414
+ case "oc": return await import("ckeditor5-premium-features/translations/oc.js");
415
+ case "pl": return await import("ckeditor5-premium-features/translations/pl.js");
416
+ case "pt": return await import("ckeditor5-premium-features/translations/pt.js");
417
+ case "pt-br": return await import("ckeditor5-premium-features/translations/pt-br.js");
418
+ case "ro": return await import("ckeditor5-premium-features/translations/ro.js");
419
+ case "ru": return await import("ckeditor5-premium-features/translations/ru.js");
420
+ case "si": return await import("ckeditor5-premium-features/translations/si.js");
421
+ case "sk": return await import("ckeditor5-premium-features/translations/sk.js");
422
+ case "sl": return await import("ckeditor5-premium-features/translations/sl.js");
423
+ case "sq": return await import("ckeditor5-premium-features/translations/sq.js");
424
+ case "sr": return await import("ckeditor5-premium-features/translations/sr.js");
425
+ case "sr-latn": return await import("ckeditor5-premium-features/translations/sr-latn.js");
426
+ case "sv": return await import("ckeditor5-premium-features/translations/sv.js");
427
+ case "th": return await import("ckeditor5-premium-features/translations/th.js");
428
+ case "tk": return await import("ckeditor5-premium-features/translations/tk.js");
429
+ case "tr": return await import("ckeditor5-premium-features/translations/tr.js");
430
+ case "tt": return await import("ckeditor5-premium-features/translations/tt.js");
431
+ case "ug": return await import("ckeditor5-premium-features/translations/ug.js");
432
+ case "uk": return await import("ckeditor5-premium-features/translations/uk.js");
433
+ case "ur": return await import("ckeditor5-premium-features/translations/ur.js");
434
+ case "uz": return await import("ckeditor5-premium-features/translations/uz.js");
435
+ case "vi": return await import("ckeditor5-premium-features/translations/vi.js");
436
+ case "zh": return await import("ckeditor5-premium-features/translations/zh.js");
437
+ case "zh-cn": return await import("ckeditor5-premium-features/translations/zh-cn.js");
438
+ default: return console.warn(`Language ${t} not found in premium translations`), await import("ckeditor5-premium-features/translations/en.js");
439
+ }
440
+ }
441
+ /* v8 ignore start -- @preserve */
442
+ catch (n) {
443
+ return console.error(`Failed to load translation for ${e}/${t}:`, n), null;
444
+ }
445
+ /* v8 ignore stop -- @preserve */
446
+ }
447
+ //#endregion
448
+ //#region src/hooks/editor/utils/normalize-custom-translations.ts
449
+ function x(e) {
450
+ return o(e, (e) => ({ dictionary: e }));
451
+ }
452
+ //#endregion
453
+ //#region src/hooks/editor/utils/query-editor-editables.ts
454
+ function S(e) {
455
+ return o(C(e), ({ element: e }) => e);
456
+ }
457
+ function C(e) {
458
+ let t = window.Livewire.all().filter(({ name: t, canonical: n }) => t === "ckeditor5-editable" && n.editorId === e).reduce((e, { canonical: t, el: n }) => ({
459
+ ...e,
460
+ [t.rootName]: {
461
+ element: n.querySelector("[data-cke-editable-content]"),
462
+ content: t.content
463
+ }
464
+ }), Object.create({})), n = window.Livewire.all().find(({ name: t, canonical: n }) => t === "ckeditor5" && n.editorId === e)?.canonical.content, r = document.querySelector(`#${e}_editor `), i = t.main;
465
+ return i && n?.main ? {
466
+ ...t,
467
+ main: {
468
+ ...i,
469
+ content: i.content || n.main
470
+ }
471
+ } : r ? {
472
+ ...t,
473
+ main: {
474
+ element: r,
475
+ content: n?.main || null
476
+ }
477
+ } : t;
478
+ }
479
+ function w(e) {
480
+ return i(o(C(e), ({ content: e }) => e), (e) => typeof e == "string");
481
+ }
482
+ //#endregion
483
+ //#region src/hooks/editor/utils/resolve-editor-config-elements-references.ts
484
+ function T(e) {
485
+ if (!e || typeof e != "object") return e;
486
+ if (Array.isArray(e)) return e.map((e) => T(e));
487
+ let t = e;
488
+ if (t.$element && typeof t.$element == "string") {
489
+ let e = document.querySelector(t.$element);
490
+ return e || console.warn(`Element not found for selector: ${t.$element}`), e || null;
491
+ }
492
+ let n = Object.create(null);
493
+ for (let [t, r] of Object.entries(e)) n[t] = T(r);
494
+ return n;
495
+ }
496
+ //#endregion
497
+ //#region src/hooks/editor/utils/resolve-editor-config-translations.ts
498
+ function E(e, t, n) {
499
+ if (!n || typeof n != "object") return n;
500
+ if (Array.isArray(n)) return n.map((n) => E(e, t, n));
501
+ let r = n;
502
+ if (r.$translation && typeof r.$translation == "string") {
503
+ let n = r.$translation, i = D(e, n, t);
504
+ return i === void 0 && console.warn(`Translation not found for key: ${n}`), i === void 0 ? null : i;
505
+ }
506
+ let i = Object.create(null);
507
+ for (let [r, a] of Object.entries(n)) i[r] = E(e, t, a);
508
+ return i;
509
+ }
510
+ function D(e, t, n) {
511
+ for (let r of e) {
512
+ let e = r[n];
513
+ if (e?.dictionary && t in e.dictionary) return e.dictionary[t];
514
+ }
515
+ }
516
+ //#endregion
517
+ //#region src/hooks/editor/utils/set-editor-editable-height.ts
518
+ function O(e, t) {
519
+ let { editing: n } = e;
520
+ n.view.change((e) => {
521
+ e.setStyle("height", `${t}px`, n.view.document.getRoot());
522
+ });
523
+ }
524
+ //#endregion
525
+ //#region src/hooks/editor/utils/wrap-with-watchdog.ts
526
+ var k = Symbol.for("elixir-editor-watchdog");
527
+ async function A(e) {
528
+ let { EditorWatchdog: t } = await import("ckeditor5"), n = new t(e);
529
+ return n.setCreator(async (...t) => {
530
+ let r = await e.create(...t);
531
+ return r[k] = n, r;
532
+ }), {
533
+ watchdog: n,
534
+ Constructor: { create: async (...e) => (await n.create(...e), n.editor) }
535
+ };
536
+ }
537
+ function j(e) {
538
+ return k in e ? e[k] : null;
539
+ }
540
+ //#endregion
541
+ //#region src/hooks/context/contexts-registry.ts
542
+ var M = class e extends n {
543
+ static the = new e();
544
+ }, N = class extends e {
545
+ contextPromise = null;
546
+ async mounted() {
547
+ let { contextId: e, language: t, context: n } = this.canonical, { customTranslations: r, watchdogConfig: i, config: { plugins: o, ...s } } = n, { loadedPlugins: c, hasPremium: l } = await _(o ?? []), u = [...await v(t, l), x(r || {})].filter((e) => !a(e));
548
+ this.contextPromise = (async () => {
549
+ let { ContextWatchdog: e, Context: n } = await import("ckeditor5"), r = new e(n, {
550
+ crashNumberLimit: 10,
551
+ ...i
552
+ }), a = T(s);
553
+ return a = E([...u].reverse(), t.ui, a), await r.create({
554
+ ...a,
555
+ language: t,
556
+ plugins: c,
557
+ ...u.length && { translations: u }
558
+ }), r.on("itemError", (...e) => {
559
+ console.error("Context item error:", ...e);
560
+ }), r;
561
+ })();
562
+ let d = await this.contextPromise;
563
+ /* v8 ignore next if -- @preserve */
564
+ this.isBeingDestroyed() || M.the.register(e, d);
565
+ }
566
+ async destroyed() {
567
+ let { contextId: e } = this.canonical;
568
+ this.element.style.display = "none";
569
+ try {
570
+ await (await this.contextPromise)?.destroy();
571
+ } finally {
572
+ this.contextPromise = null, M.the.hasItem(e) && M.the.unregister(e);
573
+ }
574
+ }
575
+ }, P = class e extends n {
576
+ static the = new e();
577
+ };
578
+ //#endregion
579
+ //#region src/hooks/utils/is-wire-model-connected.ts
580
+ function F(e) {
581
+ let t = e;
582
+ for (; t;) {
583
+ for (let e of t.attributes) if (e.name.startsWith("wire:model")) return !0;
584
+ t = t.parentElement;
585
+ }
586
+ return !1;
587
+ }
588
+ //#endregion
589
+ //#region src/hooks/utils/root-attributes-updater.ts
590
+ function I(e, t) {
591
+ let n = /* @__PURE__ */ new Set();
592
+ return (r) => {
593
+ e.model.enqueueChange({ isUndoable: !1 }, (i) => {
594
+ let a = e.model.document.getRoot(t);
595
+ if (a) {
596
+ for (let e of n) r && e in r || (i.removeAttribute(e, a), n.delete(e));
597
+ for (let [e, t] of Object.entries(r ?? {})) i.setAttribute(e, t, a), n.add(e);
598
+ }
599
+ });
600
+ };
601
+ }
602
+ //#endregion
603
+ //#region src/hooks/editable.ts
604
+ var L = class extends e {
605
+ editorPromise = null;
606
+ rootAttributesUpdater = null;
607
+ pendingContent = null;
608
+ mounted() {
609
+ let { editorId: e, rootName: t, content: n } = this.canonical;
610
+ this.editorPromise = P.the.execute(e, (e) => {
611
+ /* v8 ignore next if -- @preserve */
612
+ if (this.isBeingDestroyed()) return null;
613
+ let { ui: r, editing: i, model: a } = e;
614
+ if (a.document.getRoot(t)) {
615
+ if (n !== null) {
616
+ let r = e.getData({ rootName: t });
617
+ r && r !== n && e.setData({ [t]: n });
618
+ }
619
+ } else {
620
+ e.addRoot(t, {
621
+ isUndoable: !1,
622
+ ...n !== null && { data: n }
623
+ });
624
+ let a = this.element.querySelector("[data-cke-editable-content]"), o = r.view.createEditable(t, a);
625
+ r.addEditable(o), i.view.forceRender();
626
+ }
627
+ return this.syncTypingContentPush(e), this.setupPendingReceivedContentHandlers(e), this.applyRootAttributes(e), e;
628
+ });
629
+ }
630
+ async afterCommitSynced() {
631
+ let e = await this.editorPromise;
632
+ this.applyCanonicalContentToEditor(e), this.applyRootAttributes(e);
633
+ }
634
+ async destroyed() {
635
+ let { rootName: e } = this.canonical;
636
+ this.element.style.display = "none";
637
+ let t = await this.editorPromise;
638
+ if (this.editorPromise = null, this.rootAttributesUpdater?.(null), t && t.state !== "destroyed") {
639
+ let n = t.model.document.getRoot(e);
640
+ /* v8 ignore next if -- @preserve */
641
+ n && "detachEditable" in t && (t.detachEditable(n), t.detachRoot(e, !1));
642
+ }
643
+ }
644
+ syncTypingContentPush(e) {
645
+ let { rootName: t, saveDebounceMs: n } = this.canonical, i = this.element.querySelector("input"), a = !1, o = () => {
646
+ if (a) return;
647
+ let n = e.getData({ rootName: t });
648
+ i && (i.value = n), this.$wire.set("content", n);
649
+ }, s = r(n, o), c = () => {
650
+ e.ui.focusTracker.isFocused ? s() : o();
651
+ };
652
+ e.model.document.on("change:data", c), o(), this.onBeforeDestroy(() => {
653
+ a = !0, e.model.document.off("change:data", c);
654
+ });
655
+ }
656
+ setupPendingReceivedContentHandlers(e) {
657
+ let { ui: t, model: n } = e, { focusTracker: r } = t, { rootName: i } = this.canonical, a = () => {
658
+ this.pendingContent = null;
659
+ }, o = () => {
660
+ !r.isFocused && this.pendingContent !== null && (e.setData({ [i]: this.pendingContent }), this.pendingContent = null);
661
+ };
662
+ n.document.on("change:data", a), r.on("change:isFocused", o), this.onBeforeDestroy(() => {
663
+ n.document.off("change:data", a), r.off("change:isFocused", o);
664
+ });
665
+ }
666
+ applyCanonicalContentToEditor(e) {
667
+ if (!F(this.element)) return;
668
+ let { content: t, rootName: n } = this.canonical, { ui: r } = e;
669
+ if (e.getData({ rootName: n }) !== (t ?? "")) {
670
+ if (r.focusTracker.isFocused) {
671
+ this.pendingContent = t ?? "";
672
+ return;
673
+ }
674
+ e.setData({ [n]: t ?? "" });
675
+ }
676
+ }
677
+ applyRootAttributes(e) {
678
+ let { rootName: t, rootAttributes: n } = this.canonical;
679
+ this.rootAttributesUpdater ??= I(e, t), this.rootAttributesUpdater(n);
680
+ }
681
+ };
682
+ //#endregion
683
+ //#region src/hooks/editor/plugins/livewire-sync.ts
684
+ async function R({ saveDebounceMs: e, component: t }) {
685
+ let { Plugin: n } = await import("ckeditor5");
686
+ return class extends n {
687
+ static get pluginName() {
688
+ return "LivewireSync";
689
+ }
690
+ init() {
691
+ this.setupTypingContentPush(), this.setupFocusableEventPush(), this.setupAfterCommitHandler(), this.setupSetEditorContentHandler(), this.setupReadyDispatch();
692
+ }
693
+ setupAfterCommitHandler() {
694
+ let { editor: e } = this, { model: n, ui: { focusTracker: r } } = e, i = null;
695
+ e.on("afterCommitSynced", () => {
696
+ if (!F(t.element)) return;
697
+ let { content: n } = t.canonical, a = this.getEditorRootsValues();
698
+ if (r.isFocused) {
699
+ /* v8 ignore next else -- @preserve */
700
+ s(n, a) || (i = n);
701
+ return;
702
+ }
703
+ /* v8 ignore next else -- @preserve */
704
+ s(n, a) || e.setData(n);
705
+ }), n.document.on("change:data", () => {
706
+ i = null;
707
+ }), r.on("change:isFocused", () => {
708
+ !r.isFocused && i !== null && (e.setData(i), i = null);
709
+ });
710
+ }
711
+ setupReadyDispatch() {
712
+ let { $wire: e } = t;
713
+ this.editor.once("ready", () => {
714
+ e.dispatch("editor-ready", { editorId: t.canonical.editorId });
715
+ });
716
+ }
717
+ setupSetEditorContentHandler() {
718
+ Livewire.on("set-editor-content", ({ editorId: e, content: n }) => {
719
+ e === t.canonical.editorId && (s(this.getEditorRootsValues(), n) || this.editor.setData(n));
720
+ });
721
+ }
722
+ setupTypingContentPush() {
723
+ let { editor: n } = this, { model: i, ui: a } = n, { $wire: o } = t, c = !1, l = () => {
724
+ /* v8 ignore next if -- @preserve */
725
+ if (c) return;
726
+ let e = this.getEditorRootsValues();
727
+ s(e, t.canonical.content ?? {}) || (o.set("content", e), o.dispatch("editor-content-changed", {
728
+ editorId: t.canonical.editorId,
729
+ content: e
730
+ }));
731
+ }, u = r(e, l), d = () => {
732
+ a.focusTracker.isFocused ? u() : l();
733
+ };
734
+ i.document.on("change:data", d), n.once("ready", l), n.once("destroy", () => {
735
+ c = !0, i.document.off("change:data", d);
736
+ });
737
+ }
738
+ setupFocusableEventPush() {
739
+ let { ui: e } = this.editor, { $wire: n } = t;
740
+ e.focusTracker.on("change:isFocused", () => {
741
+ let r = this.getEditorRootsValues();
742
+ n.set("focused", e.focusTracker.isFocused), s(r, t.canonical.content ?? {}) || n.set("content", r);
743
+ });
744
+ }
745
+ getEditorRootsValues() {
746
+ return p(this.editor);
747
+ }
748
+ };
749
+ }
750
+ //#endregion
751
+ //#region src/hooks/editor/plugins/sync-editor-with-input.ts
752
+ async function z(e) {
753
+ let { Plugin: t } = await import("ckeditor5");
754
+ return class extends t {
755
+ input = null;
756
+ form = null;
757
+ static get pluginName() {
758
+ return "SyncEditorWithInput";
759
+ }
760
+ afterInit() {
761
+ let { editor: t } = this, n = t.sourceElement.id.replace(/_editor$/, "");
762
+ this.input = document.getElementById(`${n}_input`), this.input && (t.model.document.on("change:data", r(e, () => this.sync())), t.once("ready", this.sync), this.form = this.input.closest("form"), this.form?.addEventListener("submit", this.sync));
763
+ }
764
+ sync = () => {
765
+ /* v8 ignore next else -- @preserve */
766
+ if (this.input) {
767
+ let e = this.editor.getData();
768
+ this.input.value = e, this.input.dispatchEvent(new Event("input", { bubbles: !0 }));
769
+ }
770
+ };
771
+ destroy() {
772
+ this.form && this.form.removeEventListener("submit", this.sync), this.input = null, this.form = null;
773
+ }
774
+ };
775
+ }
776
+ //#endregion
777
+ //#region src/hooks/editor/editor.ts
778
+ var B = class extends e {
779
+ editorPromise = null;
780
+ rootAttributesUpdater = null;
781
+ async mounted() {
782
+ let { editorId: e } = this.canonical;
783
+ P.the.resetErrors(e);
784
+ try {
785
+ this.editorPromise = this.createEditor();
786
+ let t = await this.editorPromise;
787
+ /* v8 ignore next if -- @preserve */
788
+ this.isBeingDestroyed() || (P.the.register(e, t), t.once("destroy", () => {
789
+ /* v8 ignore next if -- @preserve */
790
+ P.the.hasItem(e) && P.the.unregister(e);
791
+ }));
792
+ } catch (t) {
793
+ console.error(`Error initializing CKEditor5 instance with ID "${e}":`, t), this.editorPromise = null, P.the.error(e, t);
794
+ }
795
+ }
796
+ async destroyed() {
797
+ this.element.style.display = "none";
798
+ try {
799
+ let e = await this.editorPromise;
800
+ if (!e) return;
801
+ let t = f(e), n = j(e);
802
+ t ? t.state !== "unavailable" && await t.context.remove(t.editorContextId) : n ? await n.destroy() : await e.destroy();
803
+ } finally {
804
+ this.editorPromise = null;
805
+ }
806
+ }
807
+ async afterCommitSynced() {
808
+ let e = await this.editorPromise;
809
+ /* v8 ignore if -- @preserve */
810
+ e && (e.fire("afterCommitSynced"), this.applyRootAttributes(e));
811
+ }
812
+ applyRootAttributes(e) {
813
+ let { rootAttributes: t } = this.canonical;
814
+ this.rootAttributesUpdater ??= I(e, "main"), this.rootAttributesUpdater(t);
815
+ }
816
+ async createEditor() {
817
+ let { preset: e, editorId: t, contextId: n, editableHeight: r, saveDebounceMs: i, language: o, watchdog: s, content: c } = this.canonical, { customTranslations: l, editorType: u, licenseKey: f, config: { plugins: p, ...g } } = e, y = await h(u), b = await (n ? M.the.waitFor(n) : null);
818
+ if (s && !b) {
819
+ let e = await A(y);
820
+ ({Constructor: y} = e), e.watchdog.on("restart", () => {
821
+ let n = e.watchdog.editor;
822
+ this.editorPromise = Promise.resolve(n), P.the.register(t, n);
823
+ });
824
+ }
825
+ let { loadedPlugins: C, hasPremium: D } = await _(p);
826
+ C.push(await R({
827
+ saveDebounceMs: i,
828
+ component: this
829
+ })), m(u) && C.push(await z(i));
830
+ let k = [...await v(o, D), x(l || {})].filter((e) => !a(e)), j = {
831
+ ...c,
832
+ ...w(t)
833
+ };
834
+ m(u) && (j = j.main || "");
835
+ let N = await (async () => {
836
+ let e = S(t);
837
+ if (!(e instanceof HTMLElement) && !("main" in e)) {
838
+ let n = u === "decoupled" ? ["main"] : Object.keys(j);
839
+ V(e, n) || (e = await H(t, n), j = {
840
+ ...c,
841
+ ...w(t)
842
+ });
843
+ }
844
+ m(u) && "main" in e && (e = e.main);
845
+ let n = T(g);
846
+ n = E([...k].reverse(), o.ui, n);
847
+ let r = {
848
+ ...n,
849
+ initialData: j,
850
+ licenseKey: f,
851
+ plugins: C,
852
+ language: o,
853
+ ...k.length && { translations: k }
854
+ };
855
+ return !b || !(e instanceof HTMLElement) ? y.create(e, r) : (await d({
856
+ context: b,
857
+ element: e,
858
+ creator: y,
859
+ config: r
860
+ })).editor;
861
+ })();
862
+ return m(u) && r && O(N, r), this.applyRootAttributes(N), N;
863
+ }
864
+ };
865
+ function V(e, t) {
866
+ return t.every((t) => e[t]);
1257
867
  }
1258
- async function mt(i, t) {
1259
- return J(
1260
- () => {
1261
- const e = j(i);
1262
- if (!K(e, t))
1263
- throw new Error(
1264
- `It looks like not all required root elements are present yet.
868
+ async function H(e, t) {
869
+ return l(() => {
870
+ let n = S(e);
871
+ if (!V(n, t)) throw Error(`It looks like not all required root elements are present yet.
1265
872
  * If you want to wait for them, ensure they are registered before editor initialization.
1266
873
  * If you want lazy initialize roots, consider removing root values from the \`initialData\` config and assign initial data in editable components.
1267
- Missing roots: ${t.filter((r) => !e[r]).join(", ")}.`
1268
- );
1269
- return e;
1270
- },
1271
- { timeOutAfter: 2e3, retryAfter: 100 }
1272
- );
1273
- }
1274
- class ht extends D {
1275
- /**
1276
- * The promise that resolves when the UI part is mounted.
1277
- */
1278
- mountedPromise = null;
1279
- /**
1280
- * Mounts the UI part component.
1281
- */
1282
- async mounted() {
1283
- const { editorId: t, name: e } = this.canonical;
1284
- this.mountedPromise = d.the.execute(t, (r) => {
1285
- if (this.isBeingDestroyed())
1286
- return;
1287
- const { ui: n } = r, a = pt(e), o = n.view[a];
1288
- if (!o) {
1289
- console.error(`Unknown UI part name: "${e}". Supported names are "toolbar" and "menubar".`);
1290
- return;
1291
- }
1292
- this.element.appendChild(o.element);
1293
- });
1294
- }
1295
- /**
1296
- * Destroys the UI part component. Unmounts UI parts from the editor.
1297
- */
1298
- async destroyed() {
1299
- this.element.style.display = "none", await this.mountedPromise, this.mountedPromise = null, this.element.innerHTML = "";
1300
- }
1301
- }
1302
- function pt(i) {
1303
- switch (i) {
1304
- case "toolbar":
1305
- return "toolbar";
1306
- case "menubar":
1307
- return "menuBarView";
1308
- default:
1309
- return null;
1310
- }
1311
- }
1312
- const wt = {
1313
- ckeditor5: dt,
1314
- "ckeditor5-context": st,
1315
- "ckeditor5-ui-part": ht,
1316
- "ckeditor5-editable": ct
874
+ Missing roots: ${t.filter((e) => !n[e]).join(", ")}.`);
875
+ return n;
876
+ }, {
877
+ timeOutAfter: 2e3,
878
+ retryAfter: 100
879
+ });
880
+ }
881
+ //#endregion
882
+ //#region src/hooks/ui-part.ts
883
+ var U = class extends e {
884
+ mountedPromise = null;
885
+ async mounted() {
886
+ let { editorId: e, name: t } = this.canonical;
887
+ this.mountedPromise = P.the.execute(e, (e) => {
888
+ /* v8 ignore next if -- @preserve */
889
+ if (this.isBeingDestroyed()) return;
890
+ let { ui: n } = e, r = W(t), i = n.view[r];
891
+ if (!i) {
892
+ console.error(`Unknown UI part name: "${t}". Supported names are "toolbar" and "menubar".`);
893
+ return;
894
+ }
895
+ this.element.appendChild(i.element);
896
+ });
897
+ }
898
+ async destroyed() {
899
+ this.element.style.display = "none", await this.mountedPromise, this.mountedPromise = null, this.element.innerHTML = "";
900
+ }
1317
901
  };
1318
- function ft() {
1319
- for (const [i, t] of Object.entries(wt))
1320
- G(i, t);
1321
- }
1322
- ft();
1323
- export {
1324
- D as ClassHook,
1325
- g as ContextsRegistry,
1326
- H as CustomEditorPluginsRegistry,
1327
- ct as EditableComponentHook,
1328
- dt as EditorComponentHook,
1329
- d as EditorsRegistry,
1330
- ht as UIPartComponentHook,
1331
- G as registerLivewireComponentHook
902
+ function W(e) {
903
+ switch (e) {
904
+ case "toolbar": return "toolbar";
905
+ case "menubar": return "menuBarView";
906
+ default: return null;
907
+ }
908
+ }
909
+ //#endregion
910
+ //#region src/hooks/index.ts
911
+ var G = {
912
+ ckeditor5: B,
913
+ "ckeditor5-context": N,
914
+ "ckeditor5-ui-part": U,
915
+ "ckeditor5-editable": L
1332
916
  };
1333
- //# sourceMappingURL=index.mjs.map
917
+ function K() {
918
+ for (let [e, n] of Object.entries(G)) t(e, n);
919
+ }
920
+ //#endregion
921
+ //#region src/index.ts
922
+ K();
923
+ //#endregion
924
+ export { e as ClassHook, M as ContextsRegistry, g as CustomEditorPluginsRegistry, L as EditableComponentHook, B as EditorComponentHook, P as EditorsRegistry, U as UIPartComponentHook, t as registerLivewireComponentHook };
925
+
926
+ //# sourceMappingURL=index.mjs.map