ckeditor5-livewire 1.0.0 → 1.1.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 (39) hide show
  1. package/dist/hooks/editable.d.ts +4 -0
  2. package/dist/hooks/editable.d.ts.map +1 -1
  3. package/dist/hooks/editor/editor.d.ts +4 -7
  4. package/dist/hooks/editor/editor.d.ts.map +1 -1
  5. package/dist/hooks/editor/plugins/livewire-sync.d.ts +3 -7
  6. package/dist/hooks/editor/plugins/livewire-sync.d.ts.map +1 -1
  7. package/dist/hooks/editor/utils/index.d.ts +1 -0
  8. package/dist/hooks/editor/utils/index.d.ts.map +1 -1
  9. package/dist/hooks/editor/utils/is-wire-model-connected.d.ts +2 -0
  10. package/dist/hooks/editor/utils/is-wire-model-connected.d.ts.map +1 -0
  11. package/dist/hooks/hook.d.ts +6 -2
  12. package/dist/hooks/hook.d.ts.map +1 -1
  13. package/dist/index.cjs +2 -2
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.mjs +328 -262
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/shared/index.d.ts +1 -0
  18. package/dist/shared/index.d.ts.map +1 -1
  19. package/dist/shared/shallow-equal.d.ts +9 -0
  20. package/dist/shared/shallow-equal.d.ts.map +1 -0
  21. package/package.json +1 -1
  22. package/src/hooks/context/context.test.ts +22 -22
  23. package/src/hooks/context/context.ts +2 -2
  24. package/src/hooks/editable.test.ts +273 -38
  25. package/src/hooks/editable.ts +17 -2
  26. package/src/hooks/editor/editor.test.ts +207 -88
  27. package/src/hooks/editor/editor.ts +12 -13
  28. package/src/hooks/editor/plugins/livewire-sync.ts +71 -16
  29. package/src/hooks/editor/utils/index.ts +1 -0
  30. package/src/hooks/editor/utils/is-wire-model-connected.test.ts +86 -0
  31. package/src/hooks/editor/utils/is-wire-model-connected.ts +14 -0
  32. package/src/hooks/editor/utils/query-editor-editables.ts +4 -4
  33. package/src/hooks/hook.ts +33 -4
  34. package/src/hooks/ui-part.test.ts +8 -8
  35. package/src/hooks/ui-part.ts +1 -1
  36. package/src/livewire.d.ts +8 -1
  37. package/src/shared/index.ts +1 -0
  38. package/src/shared/shallow-equal.test.ts +51 -0
  39. package/src/shared/shallow-equal.ts +30 -0
@@ -11,6 +11,10 @@ export declare class EditableComponentHook extends ClassHook<Snapshot> {
11
11
  * Mounts the editable component.
12
12
  */
13
13
  mounted(): void;
14
+ /**
15
+ * Called when the component is updated by Livewire.
16
+ */
17
+ afterCommitSynced(): Promise<void>;
14
18
  /**
15
19
  * Destroys the editable component. Unmounts root from the editor.
16
20
  */
@@ -1 +1 @@
1
- {"version":3,"file":"editable.d.ts","sourceRoot":"","sources":["../../src/hooks/editable.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,SAAS,CAAC,QAAQ,CAAC;IAC5D;;OAEG;IACH,OAAO,CAAC,aAAa,CAAyC;IAE9D;;OAEG;IACM,OAAO;IAuDhB;;OAEG;IACY,SAAS;CAoBzB;AAED;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC"}
1
+ {"version":3,"file":"editable.d.ts","sourceRoot":"","sources":["../../src/hooks/editable.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,SAAS,CAAC,QAAQ,CAAC;IAC5D;;OAEG;IACH,OAAO,CAAC,aAAa,CAAyC;IAE9D;;OAEG;IACM,OAAO;IAuDhB;;OAEG;IACY,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAYjD;;OAEG;IACY,SAAS;CAoBzB;AAED;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC"}
@@ -17,6 +17,10 @@ export declare class EditorComponentHook extends ClassHook<Snapshot> {
17
17
  * This is important to prevent memory leaks and ensure that the editor is properly cleaned up.
18
18
  */
19
19
  destroyed(): Promise<void>;
20
+ /**
21
+ * Updates the editor content when the component is updated after commit changes.
22
+ */
23
+ afterCommitSynced(): Promise<void>;
20
24
  /**
21
25
  * Creates the CKEditor instance.
22
26
  */
@@ -58,12 +62,5 @@ export type Snapshot = {
58
62
  * The language of the editor UI and content.
59
63
  */
60
64
  language: EditorLanguage;
61
- /**
62
- * The global events of the editor to forward to Livewire.
63
- */
64
- emit: {
65
- change: boolean;
66
- focus: boolean;
67
- };
68
65
  };
69
66
  //# sourceMappingURL=editor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../../../src/hooks/editor/editor.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAY,cAAc,EAAE,YAAY,EAAc,MAAM,WAAW,CAAC;AAKpF,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAsBpC;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,SAAS,CAAC,QAAQ,CAAC;IAC1D;;OAEG;IACH,OAAO,CAAC,aAAa,CAAgC;IAErD;;OAEG;IACY,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA4BvC;;;OAGG;IACY,SAAS;IAkCxB;;OAEG;YACW,YAAY;CAiI3B;AAkED;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAEzB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,MAAM,EAAE,YAAY,CAAC;IAErB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEhC;;OAEG;IACH,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9B;;OAEG;IACH,QAAQ,EAAE,cAAc,CAAC;IAEzB;;OAEG;IACH,IAAI,EAAE;QACJ,MAAM,EAAE,OAAO,CAAC;QAChB,KAAK,EAAE,OAAO,CAAC;KAChB,CAAC;CACH,CAAC"}
1
+ {"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../../../src/hooks/editor/editor.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAY,cAAc,EAAE,YAAY,EAAc,MAAM,WAAW,CAAC;AAKpF,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAsBpC;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,SAAS,CAAC,QAAQ,CAAC;IAC1D;;OAEG;IACH,OAAO,CAAC,aAAa,CAAgC;IAErD;;OAEG;IACY,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA4BvC;;;OAGG;IACY,SAAS;IAkCxB;;OAEG;IACY,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAMjD;;OAEG;YACW,YAAY;CA+H3B;AAkED;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAEzB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,MAAM,EAAE,YAAY,CAAC;IAErB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEhC;;OAEG;IACH,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9B;;OAEG;IACH,QAAQ,EAAE,cAAc,CAAC;CAC1B,CAAC"}
@@ -1,19 +1,15 @@
1
1
  import { PluginConstructor } from 'ckeditor5';
2
- import { Wire } from '../../../livewire';
2
+ import { EditorComponentHook } from '../editor';
3
3
  /**
4
4
  * Creates a LivewireSync plugin class.
5
5
  */
6
- export declare function createLivewireSyncPlugin({ emit, saveDebounceMs, $wire, }: Attrs): Promise<PluginConstructor>;
6
+ export declare function createLivewireSyncPlugin({ saveDebounceMs, component, }: Attrs): Promise<PluginConstructor>;
7
7
  /**
8
8
  * The attributes required to create the LivewireSync plugin.
9
9
  */
10
10
  type Attrs = {
11
- emit: {
12
- change?: boolean;
13
- focus?: boolean;
14
- };
15
11
  saveDebounceMs: number;
16
- $wire: Wire;
12
+ component: EditorComponentHook;
17
13
  };
18
14
  export {};
19
15
  //# sourceMappingURL=livewire-sync.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"livewire-sync.d.ts","sourceRoot":"","sources":["../../../../src/hooks/editor/plugins/livewire-sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEnD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAK9C;;GAEG;AACH,wBAAsB,wBAAwB,CAC5C,EACE,IAAI,EACJ,cAAc,EACd,KAAK,GACN,EAAE,KAAK,GACP,OAAO,CAAC,iBAAiB,CAAC,CA2D5B;AAED;;GAEG;AACH,KAAK,KAAK,GAAG;IACX,IAAI,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAC;KAAE,CAAC;IAC7C,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,IAAI,CAAC;CACb,CAAC"}
1
+ {"version":3,"file":"livewire-sync.d.ts","sourceRoot":"","sources":["../../../../src/hooks/editor/plugins/livewire-sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAKrD;;GAEG;AACH,wBAAsB,wBAAwB,CAC5C,EACE,cAAc,EACd,SAAS,GACV,EAAE,KAAK,GACP,OAAO,CAAC,iBAAiB,CAAC,CA4G5B;AAUD;;GAEG;AACH,KAAK,KAAK,GAAG;IACX,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,mBAAmB,CAAC;CAChC,CAAC"}
@@ -1,6 +1,7 @@
1
1
  export * from './create-editor-in-context';
2
2
  export * from './get-editor-roots-values';
3
3
  export * from './is-single-editing-like-editor';
4
+ export * from './is-wire-model-connected';
4
5
  export * from './load-editor-constructor';
5
6
  export * from './load-editor-plugins';
6
7
  export * from './load-editor-translations';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/editor/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iCAAiC,CAAC;AAChD,cAAc,0BAA0B,CAAC;AACzC,cAAc,6CAA6C,CAAC;AAC5D,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/editor/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iCAAiC,CAAC;AAChD,cAAc,0BAA0B,CAAC;AACzC,cAAc,6CAA6C,CAAC;AAC5D,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function isWireModelConnected(element: HTMLElement): boolean;
2
+ //# sourceMappingURL=is-wire-model-connected.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-wire-model-connected.d.ts","sourceRoot":"","sources":["../../../../src/hooks/editor/utils/is-wire-model-connected.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAalE"}
@@ -18,9 +18,9 @@ export declare abstract class ClassHook<T extends object = Record<string, unknow
18
18
  */
19
19
  livewireComponent: LivewireComponent);
20
20
  /**
21
- * The ephemeral snapshot of the Livewire component.
21
+ * The canonical snapshot of the Livewire component.
22
22
  */
23
- get ephemeral(): T;
23
+ get canonical(): T;
24
24
  /**
25
25
  * The root HTML element of the Livewire component.
26
26
  */
@@ -41,6 +41,10 @@ export declare abstract class ClassHook<T extends object = Record<string, unknow
41
41
  * Called when the element has been removed from the DOM.
42
42
  */
43
43
  abstract destroyed(): CanBePromise<void>;
44
+ /**
45
+ * Called when the component is updated by Livewire.
46
+ */
47
+ afterCommitSynced?(): CanBePromise<void>;
44
48
  }
45
49
  /**
46
50
  * A type that represents the state of a class-based hook.
@@ -1 +1 @@
1
- {"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../../src/hooks/hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C;;GAEG;AACH,8BAAsB,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAOtE;;OAEG;IACH,SAAS,CAAC,iBAAiB,EAAE,iBAAiB;IAThD;;OAEG;IACH,KAAK,EAAE,cAAc,CAAc;;IAGjC;;OAEG;IACO,iBAAiB,EAAE,iBAAiB;IAGhD;;OAEG;IACH,IAAI,SAAS,IAAI,CAAC,CAEjB;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,WAAW,CAEzB;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,IAAI,CAEhB;IAED;;OAEG;IACH,gBAAgB,IAAI,OAAO;IAI3B;;OAEG;IACH,QAAQ,CAAC,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC;IAEtC;;OAEG;IACH,QAAQ,CAAC,SAAS,IAAI,YAAY,CAAC,IAAI,CAAC;CACzC;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,SAAS,GAAG,YAAY,GAAG,WAAW,CAAC;AAEjF;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE;IAAE,KAAI,SAAS,EAAE,iBAAiB,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;CAAE,QAiBvH"}
1
+ {"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../../src/hooks/hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C;;GAEG;AACH,8BAAsB,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAOtE;;OAEG;IACH,SAAS,CAAC,iBAAiB,EAAE,iBAAiB;IAThD;;OAEG;IACH,KAAK,EAAE,cAAc,CAAc;;IAGjC;;OAEG;IACO,iBAAiB,EAAE,iBAAiB;IAGhD;;OAEG;IACH,IAAI,SAAS,IAAI,CAAC,CAEjB;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,WAAW,CAEzB;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,IAAI,CAEhB;IAED;;OAEG;IACH,gBAAgB,IAAI,OAAO;IAI3B;;OAEG;IACH,QAAQ,CAAC,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC;IAEtC;;OAEG;IACH,QAAQ,CAAC,SAAS,IAAI,YAAY,CAAC,IAAI,CAAC;IAExC;;OAEG;IACH,iBAAiB,CAAC,IAAI,YAAY,CAAC,IAAI,CAAC;CACzC;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,SAAS,GAAG,YAAY,GAAG,WAAW,CAAC;AAEjF;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE;IAAE,KAAI,SAAS,EAAE,iBAAiB,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;CAAE,QAyCvH"}
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
- "use strict";var K=Object.create;var j=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,Q=Object.prototype.hasOwnProperty;var Z=(i,t,r,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of X(t))!Q.call(i,n)&&n!==r&&j(i,n,{get:()=>t[n],enumerable:!(a=Y(t,n))||a.enumerable});return i};var e=(i,t,r)=>(r=i!=null?K(J(i)):{},Z(t||!i||!i.__esModule?j(r,"default",{value:i,enumerable:!0}):r,i));class v{constructor(t){this.livewireComponent=t}state="mounting";get ephemeral(){return this.livewireComponent.ephemeral}get element(){return this.livewireComponent.el}get $wire(){return this.livewireComponent.$wire}isBeingDestroyed(){return["destroyed","destroying"].includes(this.state)}}function tt(i,t){window.Livewire.hook("component.init",async({component:r,cleanup:a})=>{if(r.name!==i)return;const n=new t(r);a(async()=>{n.state="destroying",await n.destroyed(),n.state="destroyed"}),await n.mounted(),n.state="mounted"})}class q{items=new Map;initializationErrors=new Map;pendingCallbacks=new Map;watchers=new Set;execute(t,r,a){const n=this.items.get(t),o=this.initializationErrors.get(t);return o?(a?.(o),Promise.reject(o)):n?Promise.resolve(r(n)):new Promise((s,c)=>{const u=this.getPendingCallbacks(t);u.success.push(async l=>{s(await r(l))}),a?u.error.push(a):u.error.push(c)})}register(t,r){if(this.items.has(t))throw new Error(`Item with ID "${t}" is already registered.`);this.resetErrors(t),this.items.set(t,r);const a=this.pendingCallbacks.get(t);a&&(a.success.forEach(n=>n(r)),this.pendingCallbacks.delete(t)),this.registerAsDefault(t,r),this.notifyWatchers()}error(t,r){this.items.delete(t),this.initializationErrors.set(t,r);const a=this.pendingCallbacks.get(t);a&&(a.error.forEach(n=>n(r)),this.pendingCallbacks.delete(t)),this.initializationErrors.size===1&&!this.items.size&&this.error(null,r),this.notifyWatchers()}resetErrors(t){const{initializationErrors:r}=this;r.has(null)&&r.get(null)===r.get(t)&&r.delete(null),r.delete(t)}unregister(t){if(!this.items.has(t))throw new Error(`Item with ID "${t}" is not registered.`);t&&this.items.get(null)===this.items.get(t)&&this.unregister(null),this.items.delete(t),this.pendingCallbacks.delete(t),this.notifyWatchers()}getItems(){return Array.from(this.items.values())}hasItem(t){return this.items.has(t)}waitFor(t){return new Promise((r,a)=>{this.execute(t,r,a)})}async destroyAll(){const t=Array.from(new Set(this.items.values())).map(r=>r.destroy());this.items.clear(),this.pendingCallbacks.clear(),await Promise.all(t),this.notifyWatchers()}watch(t){return this.watchers.add(t),t(new Map(this.items),new Map(this.initializationErrors)),this.unwatch.bind(this,t)}unwatch(t){this.watchers.delete(t)}notifyWatchers(){this.watchers.forEach(t=>t(new Map(this.items),new Map(this.initializationErrors)))}getPendingCallbacks(t){let r=this.pendingCallbacks.get(t);return r||(r={success:[],error:[]},this.pendingCallbacks.set(t,r)),r}registerAsDefault(t,r){this.items.size===1&&t!==null&&this.register(null,r)}}function $(i,t){let r=null;return(...a)=>{r&&clearTimeout(r),r=setTimeout(()=>{t(...a)},i)}}function et(i,t){const r=Object.entries(i).filter(([a,n])=>t(n,a));return Object.fromEntries(r)}function B(i){return Object.keys(i).length===0&&i.constructor===Object}function z(i,t){const r=Object.entries(i).map(([a,n])=>[a,t(n,a)]);return Object.fromEntries(r)}function rt(){return Math.random().toString(36).substring(2)}function it(i,{timeOutAfter:t=500,retryAfter:r=100}={}){return new Promise((a,n)=>{const o=Date.now();let s=null;const c=setTimeout(()=>{n(s??new Error("Timeout"))},t),u=async()=>{try{const l=await i();clearTimeout(c),a(l)}catch(l){s=l,Date.now()-o>t?n(l):setTimeout(u,r)}};u()})}const I=Symbol.for("context-editor-watchdog");async function at({element:i,context:t,creator:r,config:a}){const n=rt();await t.add({creator:(u,l)=>r.create(u,l),id:n,sourceElementOrData:i,type:"editor",config:a});const o=t.getItem(n),s={state:"available",editorContextId:n,context:t};o[I]=s;const c=t.destroy.bind(t);return t.destroy=async()=>(s.state="unavailable",c()),{...s,editor:o}}function nt(i){return I in i?i[I]:null}function st(i){return i.model.document.getRootNames().reduce((r,a)=>(r[a]=i.getData({rootName:a}),r),Object.create({}))}function k(i){return["inline","classic","balloon","decoupled"].includes(i)}async function ot(i){const t=await import("ckeditor5"),a={inline:t.InlineEditor,balloon:t.BalloonEditor,classic:t.ClassicEditor,decoupled:t.DecoupledEditor,multiroot:t.MultiRootEditor}[i];if(!a)throw new Error(`Unsupported editor type: ${i}`);return a}class M{static the=new M;plugins=new Map;constructor(){}register(t,r){if(this.plugins.has(t))throw new Error(`Plugin with name "${t}" is already registered.`);return this.plugins.set(t,r),this.unregister.bind(this,t)}unregister(t){if(!this.plugins.has(t))throw new Error(`Plugin with name "${t}" is not registered.`);this.plugins.delete(t)}unregisterAll(){this.plugins.clear()}async get(t){return this.plugins.get(t)?.()}has(t){return this.plugins.has(t)}}async function F(i){const t=await import("ckeditor5");let r=null;const a=i.map(async n=>{const o=await M.the.get(n);if(o)return o;const{[n]:s}=t;if(s)return s;if(!r)try{r=await import("ckeditor5-premium-features")}catch(u){console.error(`Failed to load premium package: ${u}`)}const{[n]:c}=r||{};if(c)return c;throw new Error(`Plugin "${n}" not found in base or premium packages.`)});return{loadedPlugins:await Promise.all(a),hasPremium:!!r}}async function N(i,t){const r=[i.ui,i.content];return await Promise.all([H("ckeditor5",r),t&&H("ckeditor5-premium-features",r)].filter(n=>!!n)).then(n=>n.flat())}async function H(i,t){return await Promise.all(t.filter(r=>r!=="en").map(async r=>{const a=await ct(i,r);return a?.default??a}).filter(Boolean))}async function ct(i,t){try{if(i==="ckeditor5")switch(t){case"af":return await import("ckeditor5/translations/af.js");case"ar":return await import("ckeditor5/translations/ar.js");case"ast":return await import("ckeditor5/translations/ast.js");case"az":return await import("ckeditor5/translations/az.js");case"bg":return await import("ckeditor5/translations/bg.js");case"bn":return await import("ckeditor5/translations/bn.js");case"bs":return await import("ckeditor5/translations/bs.js");case"ca":return await import("ckeditor5/translations/ca.js");case"cs":return await import("ckeditor5/translations/cs.js");case"da":return await import("ckeditor5/translations/da.js");case"de":return await import("ckeditor5/translations/de.js");case"de-ch":return await import("ckeditor5/translations/de-ch.js");case"el":return await import("ckeditor5/translations/el.js");case"en":return await import("ckeditor5/translations/en.js");case"en-au":return await import("ckeditor5/translations/en-au.js");case"en-gb":return await import("ckeditor5/translations/en-gb.js");case"eo":return await import("ckeditor5/translations/eo.js");case"es":return await import("ckeditor5/translations/es.js");case"es-co":return await import("ckeditor5/translations/es-co.js");case"et":return await import("ckeditor5/translations/et.js");case"eu":return await import("ckeditor5/translations/eu.js");case"fa":return await import("ckeditor5/translations/fa.js");case"fi":return await import("ckeditor5/translations/fi.js");case"fr":return await import("ckeditor5/translations/fr.js");case"gl":return await import("ckeditor5/translations/gl.js");case"gu":return await import("ckeditor5/translations/gu.js");case"he":return await import("ckeditor5/translations/he.js");case"hi":return await import("ckeditor5/translations/hi.js");case"hr":return await import("ckeditor5/translations/hr.js");case"hu":return await import("ckeditor5/translations/hu.js");case"hy":return await import("ckeditor5/translations/hy.js");case"id":return await import("ckeditor5/translations/id.js");case"it":return await import("ckeditor5/translations/it.js");case"ja":return await import("ckeditor5/translations/ja.js");case"jv":return await import("ckeditor5/translations/jv.js");case"kk":return await import("ckeditor5/translations/kk.js");case"km":return await import("ckeditor5/translations/km.js");case"kn":return await import("ckeditor5/translations/kn.js");case"ko":return await import("ckeditor5/translations/ko.js");case"ku":return await import("ckeditor5/translations/ku.js");case"lt":return await import("ckeditor5/translations/lt.js");case"lv":return await import("ckeditor5/translations/lv.js");case"ms":return await import("ckeditor5/translations/ms.js");case"nb":return await import("ckeditor5/translations/nb.js");case"ne":return await import("ckeditor5/translations/ne.js");case"nl":return await import("ckeditor5/translations/nl.js");case"no":return await import("ckeditor5/translations/no.js");case"oc":return await import("ckeditor5/translations/oc.js");case"pl":return await import("ckeditor5/translations/pl.js");case"pt":return await import("ckeditor5/translations/pt.js");case"pt-br":return await import("ckeditor5/translations/pt-br.js");case"ro":return await import("ckeditor5/translations/ro.js");case"ru":return await import("ckeditor5/translations/ru.js");case"si":return await import("ckeditor5/translations/si.js");case"sk":return await import("ckeditor5/translations/sk.js");case"sl":return await import("ckeditor5/translations/sl.js");case"sq":return await import("ckeditor5/translations/sq.js");case"sr":return await import("ckeditor5/translations/sr.js");case"sr-latn":return await import("ckeditor5/translations/sr-latn.js");case"sv":return await import("ckeditor5/translations/sv.js");case"th":return await import("ckeditor5/translations/th.js");case"tk":return await import("ckeditor5/translations/tk.js");case"tr":return await import("ckeditor5/translations/tr.js");case"tt":return await import("ckeditor5/translations/tt.js");case"ug":return await import("ckeditor5/translations/ug.js");case"uk":return await import("ckeditor5/translations/uk.js");case"ur":return await import("ckeditor5/translations/ur.js");case"uz":return await import("ckeditor5/translations/uz.js");case"vi":return await import("ckeditor5/translations/vi.js");case"zh":return await import("ckeditor5/translations/zh.js");case"zh-cn":return await import("ckeditor5/translations/zh-cn.js");default:return console.warn(`Language ${t} not found in ckeditor5 translations`),null}else switch(t){case"af":return await import("ckeditor5-premium-features/translations/af.js");case"ar":return await import("ckeditor5-premium-features/translations/ar.js");case"ast":return await import("ckeditor5-premium-features/translations/ast.js");case"az":return await import("ckeditor5-premium-features/translations/az.js");case"bg":return await import("ckeditor5-premium-features/translations/bg.js");case"bn":return await import("ckeditor5-premium-features/translations/bn.js");case"bs":return await import("ckeditor5-premium-features/translations/bs.js");case"ca":return await import("ckeditor5-premium-features/translations/ca.js");case"cs":return await import("ckeditor5-premium-features/translations/cs.js");case"da":return await import("ckeditor5-premium-features/translations/da.js");case"de":return await import("ckeditor5-premium-features/translations/de.js");case"de-ch":return await import("ckeditor5-premium-features/translations/de-ch.js");case"el":return await import("ckeditor5-premium-features/translations/el.js");case"en":return await import("ckeditor5-premium-features/translations/en.js");case"en-au":return await import("ckeditor5-premium-features/translations/en-au.js");case"en-gb":return await import("ckeditor5-premium-features/translations/en-gb.js");case"eo":return await import("ckeditor5-premium-features/translations/eo.js");case"es":return await import("ckeditor5-premium-features/translations/es.js");case"es-co":return await import("ckeditor5-premium-features/translations/es-co.js");case"et":return await import("ckeditor5-premium-features/translations/et.js");case"eu":return await import("ckeditor5-premium-features/translations/eu.js");case"fa":return await import("ckeditor5-premium-features/translations/fa.js");case"fi":return await import("ckeditor5-premium-features/translations/fi.js");case"fr":return await import("ckeditor5-premium-features/translations/fr.js");case"gl":return await import("ckeditor5-premium-features/translations/gl.js");case"gu":return await import("ckeditor5-premium-features/translations/gu.js");case"he":return await import("ckeditor5-premium-features/translations/he.js");case"hi":return await import("ckeditor5-premium-features/translations/hi.js");case"hr":return await import("ckeditor5-premium-features/translations/hr.js");case"hu":return await import("ckeditor5-premium-features/translations/hu.js");case"hy":return await import("ckeditor5-premium-features/translations/hy.js");case"id":return await import("ckeditor5-premium-features/translations/id.js");case"it":return await import("ckeditor5-premium-features/translations/it.js");case"ja":return await import("ckeditor5-premium-features/translations/ja.js");case"jv":return await import("ckeditor5-premium-features/translations/jv.js");case"kk":return await import("ckeditor5-premium-features/translations/kk.js");case"km":return await import("ckeditor5-premium-features/translations/km.js");case"kn":return await import("ckeditor5-premium-features/translations/kn.js");case"ko":return await import("ckeditor5-premium-features/translations/ko.js");case"ku":return await import("ckeditor5-premium-features/translations/ku.js");case"lt":return await import("ckeditor5-premium-features/translations/lt.js");case"lv":return await import("ckeditor5-premium-features/translations/lv.js");case"ms":return await import("ckeditor5-premium-features/translations/ms.js");case"nb":return await import("ckeditor5-premium-features/translations/nb.js");case"ne":return await import("ckeditor5-premium-features/translations/ne.js");case"nl":return await import("ckeditor5-premium-features/translations/nl.js");case"no":return await import("ckeditor5-premium-features/translations/no.js");case"oc":return await import("ckeditor5-premium-features/translations/oc.js");case"pl":return await import("ckeditor5-premium-features/translations/pl.js");case"pt":return await import("ckeditor5-premium-features/translations/pt.js");case"pt-br":return await import("ckeditor5-premium-features/translations/pt-br.js");case"ro":return await import("ckeditor5-premium-features/translations/ro.js");case"ru":return await import("ckeditor5-premium-features/translations/ru.js");case"si":return await import("ckeditor5-premium-features/translations/si.js");case"sk":return await import("ckeditor5-premium-features/translations/sk.js");case"sl":return await import("ckeditor5-premium-features/translations/sl.js");case"sq":return await import("ckeditor5-premium-features/translations/sq.js");case"sr":return await import("ckeditor5-premium-features/translations/sr.js");case"sr-latn":return await import("ckeditor5-premium-features/translations/sr-latn.js");case"sv":return await import("ckeditor5-premium-features/translations/sv.js");case"th":return await import("ckeditor5-premium-features/translations/th.js");case"tk":return await import("ckeditor5-premium-features/translations/tk.js");case"tr":return await import("ckeditor5-premium-features/translations/tr.js");case"tt":return await import("ckeditor5-premium-features/translations/tt.js");case"ug":return await import("ckeditor5-premium-features/translations/ug.js");case"uk":return await import("ckeditor5-premium-features/translations/uk.js");case"ur":return await import("ckeditor5-premium-features/translations/ur.js");case"uz":return await import("ckeditor5-premium-features/translations/uz.js");case"vi":return await import("ckeditor5-premium-features/translations/vi.js");case"zh":return await import("ckeditor5-premium-features/translations/zh.js");case"zh-cn":return await import("ckeditor5-premium-features/translations/zh-cn.js");default:return console.warn(`Language ${t} not found in premium translations`),await import("ckeditor5-premium-features/translations/en.js")}}catch(r){return console.error(`Failed to load translation for ${i}/${t}:`,r),null}}function V(i){return z(i,t=>({dictionary:t}))}function S(i){return window.Livewire.all().filter(({name:t,ephemeral:r})=>t==="ckeditor5-editable"&&r.editorId===i).reduce((t,{ephemeral:r,el:a})=>({...t,[r.rootName]:{element:a.querySelector("[data-cke-editable-content]"),content:r.content}}),Object.create({}))}function T(i,t){if(t==="decoupled"){const{element:a}=U(i);return a}if(k(t))return document.getElementById(`${i}_editor`);const r=S(i);return z(r,({element:a})=>a)}function W(i,t){if(t==="decoupled"){const{content:n}=U(i);if(typeof n=="string")return{main:n}}const r=S(i),a=z(r,({content:n})=>n);return et(a,n=>typeof n=="string")}function U(i){const t=S(i).main;if(!t)throw new Error(`No "main" editable found for editor with ID "${i}".`);return t}function O(i){if(!i||typeof i!="object")return i;if(Array.isArray(i))return i.map(a=>O(a));const t=i;if(t.$element&&typeof t.$element=="string"){const a=document.querySelector(t.$element);return a||console.warn(`Element not found for selector: ${t.$element}`),a||null}const r=Object.create(null);for(const[a,n]of Object.entries(i))r[a]=O(n);return r}function ut(i,t){const{editing:r}=i;r.view.change(a=>{a.setStyle("height",`${t}px`,r.view.document.getRoot())})}const D=Symbol.for("elixir-editor-watchdog");async function lt(i){const{EditorWatchdog:t}=await import("ckeditor5"),r=new t(i);return r.setCreator(async(...a)=>{const n=await i.create(...a);return n[D]=r,n}),{watchdog:r,Constructor:{create:async(...a)=>(await r.create(...a),r.editor)}}}function mt(i){return D in i?i[D]:null}class g extends q{static the=new g}class dt extends v{contextPromise=null;async mounted(){const{contextId:t,language:r,context:a}=this.ephemeral,{customTranslations:n,watchdogConfig:o,config:{plugins:s,...c}}=a,{loadedPlugins:u,hasPremium:l}=await F(s??[]),m=[...await N(r,l),V(n||{})].filter(p=>!B(p));this.contextPromise=(async()=>{const{ContextWatchdog:p,Context:C}=await import("ckeditor5"),h=new p(C,{crashNumberLimit:10,...o});return await h.create({...c,language:r,plugins:u,...m.length&&{translations:m}}),h.on("itemError",(...y)=>{console.error("Context item error:",...y)}),h})();const f=await this.contextPromise;this.isBeingDestroyed()||g.the.register(t,f)}async destroyed(){const{contextId:t}=this.ephemeral;this.element.style.display="none";try{await(await this.contextPromise)?.destroy()}finally{this.contextPromise=null,g.the.hasItem(t)&&g.the.unregister(t)}}}class w extends q{static the=new w}class pt extends v{editorPromise=null;mounted(){const{editorId:t,rootName:r,content:a,saveDebounceMs:n}=this.ephemeral,o=this.element.querySelector("input");this.editorPromise=w.the.execute(t,s=>{const{ui:c,editing:u,model:l}=s;if(l.document.getRoot(r)){if(a!==null){const p=s.getData({rootName:r});p&&p!==a&&s.setData({[r]:a})}return s}s.addRoot(r,{isUndoable:!1,...a!==null&&{data:a}});const P=this.element.querySelector("[data-cke-editable-content]"),m=c.view.createEditable(r,P);c.addEditable(m),u.view.forceRender();const f=()=>{const p=s.getData({rootName:r});o&&(o.value=p),this.$wire.set("content",p)};return s.model.document.on("change:data",$(n,f)),f(),s})}async destroyed(){const{rootName:t}=this.ephemeral;this.element.style.display="none";const r=await this.editorPromise;if(this.editorPromise=null,r&&r.state!=="destroyed"){const a=r.model.document.getRoot(t);a&&"detachEditable"in r&&(r.detachEditable(a),r.detachRoot(t,!1))}}}async function wt({emit:i,saveDebounceMs:t,$wire:r}){const{Plugin:a}=await import("ckeditor5");return class extends a{static get pluginName(){return"LivewireSync"}init(){i.change&&this.setupTypingContentPush(),i.focus&&this.setupFocusableEventPush()}setupTypingContentPush(){const{model:o}=this.editor,s=()=>{r.set("content",this.getEditorRootsValues())};o.document.on("change:data",$(t,s)),s()}setupFocusableEventPush(){const{ui:o}=this.editor,s=()=>{r.set("focused",o.focusTracker.isFocused),r.set("content",this.getEditorRootsValues())};o.focusTracker.on("change:isFocused",s)}getEditorRootsValues(){return st(this.editor)}}}async function ht(i){const{Plugin:t}=await import("ckeditor5");return class extends t{input=null;form=null;static get pluginName(){return"SyncEditorWithInput"}afterInit(){const{editor:a}=this,o=a.sourceElement.id.replace(/_editor$/,"");this.input=document.getElementById(`${o}_input`),this.input&&(a.model.document.on("change:data",$(i,()=>this.sync())),a.once("ready",this.sync),this.form=this.input.closest("form"),this.form?.addEventListener("submit",this.sync))}sync=()=>{const a=this.editor.getData();this.input.value=a,this.input.dispatchEvent(new Event("input",{bubbles:!0}))};destroy(){this.form&&this.form.removeEventListener("submit",this.sync),this.input=null,this.form=null}}}class ft extends v{editorPromise=null;async mounted(){const{editorId:t}=this.ephemeral;w.the.resetErrors(t);try{this.editorPromise=this.createEditor();const r=await this.editorPromise;this.isBeingDestroyed()||(w.the.register(t,r),r.once("destroy",()=>{w.the.hasItem(t)&&w.the.unregister(t)}))}catch(r){this.editorPromise=null,w.the.error(t,r)}}async destroyed(){this.element.style.display="none";try{const t=await this.editorPromise;if(!t)return;const r=nt(t),a=mt(t);r?r.state!=="unavailable"&&await r.context.remove(r.editorContextId):a?await a.destroy():await t.destroy()}finally{this.editorPromise=null}}async createEditor(){const{preset:t,editorId:r,contextId:a,editableHeight:n,emit:o,saveDebounceMs:s,language:c,watchdog:u,content:l}=this.ephemeral,{customTranslations:P,editorType:m,licenseKey:f,config:{plugins:p,...C}}=t;let h=await ot(m);const y=await(a?g.the.waitFor(a):null);if(u&&!y){const d=await lt(h);({Constructor:h}=d),d.watchdog.on("restart",()=>{const b=d.watchdog.editor;this.editorPromise=Promise.resolve(b),w.the.register(r,b)})}const{loadedPlugins:x,hasPremium:G}=await F(p);x.push(await wt({emit:o,saveDebounceMs:s,$wire:this.$wire})),k(m)&&x.push(await ht(s));const R=[...await N(c,G),V(P||{})].filter(d=>!B(d));let E={...l,...W(r,m)};k(m)&&(E=E.main||"");const L=await(async()=>{let d=T(r,m);if(yt(d,m)){const A=Object.keys(E);_(d,A)||(d=await gt(r,m,A),E={...l,...W(r,m)})}const b={...O(C),initialData:E,licenseKey:f,plugins:x,language:c,...R.length&&{translations:R}};return!y||!(d instanceof HTMLElement)?h.create(d,b):(await at({context:y,element:d,creator:h,config:b})).editor})();return k(m)&&n&&ut(L,n),L}}function _(i,t){return t.every(r=>i[r])}async function gt(i,t,r){return await it(()=>{const a=T(i,t);if(!_(a,r))throw new Error(`It looks like not all required root elements are present yet.
1
+ "use strict";var K=Object.create;var A=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,Q=Object.prototype.hasOwnProperty;var Z=(i,t,r,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of X(t))!Q.call(i,n)&&n!==r&&A(i,n,{get:()=>t[n],enumerable:!(a=Y(t,n))||a.enumerable});return i};var e=(i,t,r)=>(r=i!=null?K(J(i)):{},Z(t||!i||!i.__esModule?A(r,"default",{value:i,enumerable:!0}):r,i));class I{constructor(t){this.livewireComponent=t}state="mounting";get canonical(){return this.livewireComponent.canonical}get element(){return this.livewireComponent.el}get $wire(){return this.livewireComponent.$wire}isBeingDestroyed(){return["destroyed","destroying"].includes(this.state)}}function tt(i,t){const r=new Map;window.Livewire?.hook("component.init",async({component:a,cleanup:n})=>{if(a.name!==i)return;const s=new t(a);r.set(a.id,s),n(async()=>{s.state="destroying",await s.destroyed(),s.state="destroyed",r.delete(a.id)}),await s.mounted(),s.state="mounted"}),window.Livewire?.hook("commit",async({component:a,succeed:n})=>{a.name===i&&n(()=>{const s=r.get(a.id);s?.state==="mounted"&&s?.afterCommitSynced?.()})})}class V{items=new Map;initializationErrors=new Map;pendingCallbacks=new Map;watchers=new Set;execute(t,r,a){const n=this.items.get(t),s=this.initializationErrors.get(t);return s?(a?.(s),Promise.reject(s)):n?Promise.resolve(r(n)):new Promise((o,c)=>{const u=this.getPendingCallbacks(t);u.success.push(async l=>{o(await r(l))}),a?u.error.push(a):u.error.push(c)})}register(t,r){if(this.items.has(t))throw new Error(`Item with ID "${t}" is already registered.`);this.resetErrors(t),this.items.set(t,r);const a=this.pendingCallbacks.get(t);a&&(a.success.forEach(n=>n(r)),this.pendingCallbacks.delete(t)),this.registerAsDefault(t,r),this.notifyWatchers()}error(t,r){this.items.delete(t),this.initializationErrors.set(t,r);const a=this.pendingCallbacks.get(t);a&&(a.error.forEach(n=>n(r)),this.pendingCallbacks.delete(t)),this.initializationErrors.size===1&&!this.items.size&&this.error(null,r),this.notifyWatchers()}resetErrors(t){const{initializationErrors:r}=this;r.has(null)&&r.get(null)===r.get(t)&&r.delete(null),r.delete(t)}unregister(t){if(!this.items.has(t))throw new Error(`Item with ID "${t}" is not registered.`);t&&this.items.get(null)===this.items.get(t)&&this.unregister(null),this.items.delete(t),this.pendingCallbacks.delete(t),this.notifyWatchers()}getItems(){return Array.from(this.items.values())}hasItem(t){return this.items.has(t)}waitFor(t){return new Promise((r,a)=>{this.execute(t,r,a)})}async destroyAll(){const t=Array.from(new Set(this.items.values())).map(r=>r.destroy());this.items.clear(),this.pendingCallbacks.clear(),await Promise.all(t),this.notifyWatchers()}watch(t){return this.watchers.add(t),t(new Map(this.items),new Map(this.initializationErrors)),this.unwatch.bind(this,t)}unwatch(t){this.watchers.delete(t)}notifyWatchers(){this.watchers.forEach(t=>t(new Map(this.items),new Map(this.initializationErrors)))}getPendingCallbacks(t){let r=this.pendingCallbacks.get(t);return r||(r={success:[],error:[]},this.pendingCallbacks.set(t,r)),r}registerAsDefault(t,r){this.items.size===1&&t!==null&&this.register(null,r)}}function S(i,t){let r=null;return(...a)=>{r&&clearTimeout(r),r=setTimeout(()=>{t(...a)},i)}}function et(i,t){const r=Object.entries(i).filter(([a,n])=>t(n,a));return Object.fromEntries(r)}function q(i){return Object.keys(i).length===0&&i.constructor===Object}function $(i,t){const r=Object.entries(i).map(([a,n])=>[a,t(n,a)]);return Object.fromEntries(r)}function C(i,t){if(i===t)return!0;const r=Object.keys(i),a=Object.keys(t);if(r.length!==a.length)return!1;for(const n of r)if(i[n]!==t[n]||!Object.prototype.hasOwnProperty.call(t,n))return!1;return!0}function rt(){return Math.random().toString(36).substring(2)}function it(i,{timeOutAfter:t=500,retryAfter:r=100}={}){return new Promise((a,n)=>{const s=Date.now();let o=null;const c=setTimeout(()=>{n(o??new Error("Timeout"))},t),u=async()=>{try{const l=await i();clearTimeout(c),a(l)}catch(l){o=l,Date.now()-s>t?n(l):setTimeout(u,r)}};u()})}const x=Symbol.for("context-editor-watchdog");async function at({element:i,context:t,creator:r,config:a}){const n=rt();await t.add({creator:(u,l)=>r.create(u,l),id:n,sourceElementOrData:i,type:"editor",config:a});const s=t.getItem(n),o={state:"available",editorContextId:n,context:t};s[x]=o;const c=t.destroy.bind(t);return t.destroy=async()=>(o.state="unavailable",c()),{...o,editor:s}}function nt(i){return x in i?i[x]:null}function st(i){return i.model.document.getRootNames().reduce((r,a)=>(r[a]=i.getData({rootName:a}),r),Object.create({}))}function v(i){return["inline","classic","balloon","decoupled"].includes(i)}function ot(i){let t=i;for(;t;){for(const r of t.attributes)if(r.name.startsWith("wire:model"))return!0;t=t.parentElement}return!1}async function ct(i){const t=await import("ckeditor5"),a={inline:t.InlineEditor,balloon:t.BalloonEditor,classic:t.ClassicEditor,decoupled:t.DecoupledEditor,multiroot:t.MultiRootEditor}[i];if(!a)throw new Error(`Unsupported editor type: ${i}`);return a}class L{static the=new L;plugins=new Map;constructor(){}register(t,r){if(this.plugins.has(t))throw new Error(`Plugin with name "${t}" is already registered.`);return this.plugins.set(t,r),this.unregister.bind(this,t)}unregister(t){if(!this.plugins.has(t))throw new Error(`Plugin with name "${t}" is not registered.`);this.plugins.delete(t)}unregisterAll(){this.plugins.clear()}async get(t){return this.plugins.get(t)?.()}has(t){return this.plugins.has(t)}}async function N(i){const t=await import("ckeditor5");let r=null;const a=i.map(async n=>{const s=await L.the.get(n);if(s)return s;const{[n]:o}=t;if(o)return o;if(!r)try{r=await import("ckeditor5-premium-features")}catch(u){console.error(`Failed to load premium package: ${u}`)}const{[n]:c}=r||{};if(c)return c;throw new Error(`Plugin "${n}" not found in base or premium packages.`)});return{loadedPlugins:await Promise.all(a),hasPremium:!!r}}async function F(i,t){const r=[i.ui,i.content];return await Promise.all([H("ckeditor5",r),t&&H("ckeditor5-premium-features",r)].filter(n=>!!n)).then(n=>n.flat())}async function H(i,t){return await Promise.all(t.filter(r=>r!=="en").map(async r=>{const a=await ut(i,r);return a?.default??a}).filter(Boolean))}async function ut(i,t){try{if(i==="ckeditor5")switch(t){case"af":return await import("ckeditor5/translations/af.js");case"ar":return await import("ckeditor5/translations/ar.js");case"ast":return await import("ckeditor5/translations/ast.js");case"az":return await import("ckeditor5/translations/az.js");case"bg":return await import("ckeditor5/translations/bg.js");case"bn":return await import("ckeditor5/translations/bn.js");case"bs":return await import("ckeditor5/translations/bs.js");case"ca":return await import("ckeditor5/translations/ca.js");case"cs":return await import("ckeditor5/translations/cs.js");case"da":return await import("ckeditor5/translations/da.js");case"de":return await import("ckeditor5/translations/de.js");case"de-ch":return await import("ckeditor5/translations/de-ch.js");case"el":return await import("ckeditor5/translations/el.js");case"en":return await import("ckeditor5/translations/en.js");case"en-au":return await import("ckeditor5/translations/en-au.js");case"en-gb":return await import("ckeditor5/translations/en-gb.js");case"eo":return await import("ckeditor5/translations/eo.js");case"es":return await import("ckeditor5/translations/es.js");case"es-co":return await import("ckeditor5/translations/es-co.js");case"et":return await import("ckeditor5/translations/et.js");case"eu":return await import("ckeditor5/translations/eu.js");case"fa":return await import("ckeditor5/translations/fa.js");case"fi":return await import("ckeditor5/translations/fi.js");case"fr":return await import("ckeditor5/translations/fr.js");case"gl":return await import("ckeditor5/translations/gl.js");case"gu":return await import("ckeditor5/translations/gu.js");case"he":return await import("ckeditor5/translations/he.js");case"hi":return await import("ckeditor5/translations/hi.js");case"hr":return await import("ckeditor5/translations/hr.js");case"hu":return await import("ckeditor5/translations/hu.js");case"hy":return await import("ckeditor5/translations/hy.js");case"id":return await import("ckeditor5/translations/id.js");case"it":return await import("ckeditor5/translations/it.js");case"ja":return await import("ckeditor5/translations/ja.js");case"jv":return await import("ckeditor5/translations/jv.js");case"kk":return await import("ckeditor5/translations/kk.js");case"km":return await import("ckeditor5/translations/km.js");case"kn":return await import("ckeditor5/translations/kn.js");case"ko":return await import("ckeditor5/translations/ko.js");case"ku":return await import("ckeditor5/translations/ku.js");case"lt":return await import("ckeditor5/translations/lt.js");case"lv":return await import("ckeditor5/translations/lv.js");case"ms":return await import("ckeditor5/translations/ms.js");case"nb":return await import("ckeditor5/translations/nb.js");case"ne":return await import("ckeditor5/translations/ne.js");case"nl":return await import("ckeditor5/translations/nl.js");case"no":return await import("ckeditor5/translations/no.js");case"oc":return await import("ckeditor5/translations/oc.js");case"pl":return await import("ckeditor5/translations/pl.js");case"pt":return await import("ckeditor5/translations/pt.js");case"pt-br":return await import("ckeditor5/translations/pt-br.js");case"ro":return await import("ckeditor5/translations/ro.js");case"ru":return await import("ckeditor5/translations/ru.js");case"si":return await import("ckeditor5/translations/si.js");case"sk":return await import("ckeditor5/translations/sk.js");case"sl":return await import("ckeditor5/translations/sl.js");case"sq":return await import("ckeditor5/translations/sq.js");case"sr":return await import("ckeditor5/translations/sr.js");case"sr-latn":return await import("ckeditor5/translations/sr-latn.js");case"sv":return await import("ckeditor5/translations/sv.js");case"th":return await import("ckeditor5/translations/th.js");case"tk":return await import("ckeditor5/translations/tk.js");case"tr":return await import("ckeditor5/translations/tr.js");case"tt":return await import("ckeditor5/translations/tt.js");case"ug":return await import("ckeditor5/translations/ug.js");case"uk":return await import("ckeditor5/translations/uk.js");case"ur":return await import("ckeditor5/translations/ur.js");case"uz":return await import("ckeditor5/translations/uz.js");case"vi":return await import("ckeditor5/translations/vi.js");case"zh":return await import("ckeditor5/translations/zh.js");case"zh-cn":return await import("ckeditor5/translations/zh-cn.js");default:return console.warn(`Language ${t} not found in ckeditor5 translations`),null}else switch(t){case"af":return await import("ckeditor5-premium-features/translations/af.js");case"ar":return await import("ckeditor5-premium-features/translations/ar.js");case"ast":return await import("ckeditor5-premium-features/translations/ast.js");case"az":return await import("ckeditor5-premium-features/translations/az.js");case"bg":return await import("ckeditor5-premium-features/translations/bg.js");case"bn":return await import("ckeditor5-premium-features/translations/bn.js");case"bs":return await import("ckeditor5-premium-features/translations/bs.js");case"ca":return await import("ckeditor5-premium-features/translations/ca.js");case"cs":return await import("ckeditor5-premium-features/translations/cs.js");case"da":return await import("ckeditor5-premium-features/translations/da.js");case"de":return await import("ckeditor5-premium-features/translations/de.js");case"de-ch":return await import("ckeditor5-premium-features/translations/de-ch.js");case"el":return await import("ckeditor5-premium-features/translations/el.js");case"en":return await import("ckeditor5-premium-features/translations/en.js");case"en-au":return await import("ckeditor5-premium-features/translations/en-au.js");case"en-gb":return await import("ckeditor5-premium-features/translations/en-gb.js");case"eo":return await import("ckeditor5-premium-features/translations/eo.js");case"es":return await import("ckeditor5-premium-features/translations/es.js");case"es-co":return await import("ckeditor5-premium-features/translations/es-co.js");case"et":return await import("ckeditor5-premium-features/translations/et.js");case"eu":return await import("ckeditor5-premium-features/translations/eu.js");case"fa":return await import("ckeditor5-premium-features/translations/fa.js");case"fi":return await import("ckeditor5-premium-features/translations/fi.js");case"fr":return await import("ckeditor5-premium-features/translations/fr.js");case"gl":return await import("ckeditor5-premium-features/translations/gl.js");case"gu":return await import("ckeditor5-premium-features/translations/gu.js");case"he":return await import("ckeditor5-premium-features/translations/he.js");case"hi":return await import("ckeditor5-premium-features/translations/hi.js");case"hr":return await import("ckeditor5-premium-features/translations/hr.js");case"hu":return await import("ckeditor5-premium-features/translations/hu.js");case"hy":return await import("ckeditor5-premium-features/translations/hy.js");case"id":return await import("ckeditor5-premium-features/translations/id.js");case"it":return await import("ckeditor5-premium-features/translations/it.js");case"ja":return await import("ckeditor5-premium-features/translations/ja.js");case"jv":return await import("ckeditor5-premium-features/translations/jv.js");case"kk":return await import("ckeditor5-premium-features/translations/kk.js");case"km":return await import("ckeditor5-premium-features/translations/km.js");case"kn":return await import("ckeditor5-premium-features/translations/kn.js");case"ko":return await import("ckeditor5-premium-features/translations/ko.js");case"ku":return await import("ckeditor5-premium-features/translations/ku.js");case"lt":return await import("ckeditor5-premium-features/translations/lt.js");case"lv":return await import("ckeditor5-premium-features/translations/lv.js");case"ms":return await import("ckeditor5-premium-features/translations/ms.js");case"nb":return await import("ckeditor5-premium-features/translations/nb.js");case"ne":return await import("ckeditor5-premium-features/translations/ne.js");case"nl":return await import("ckeditor5-premium-features/translations/nl.js");case"no":return await import("ckeditor5-premium-features/translations/no.js");case"oc":return await import("ckeditor5-premium-features/translations/oc.js");case"pl":return await import("ckeditor5-premium-features/translations/pl.js");case"pt":return await import("ckeditor5-premium-features/translations/pt.js");case"pt-br":return await import("ckeditor5-premium-features/translations/pt-br.js");case"ro":return await import("ckeditor5-premium-features/translations/ro.js");case"ru":return await import("ckeditor5-premium-features/translations/ru.js");case"si":return await import("ckeditor5-premium-features/translations/si.js");case"sk":return await import("ckeditor5-premium-features/translations/sk.js");case"sl":return await import("ckeditor5-premium-features/translations/sl.js");case"sq":return await import("ckeditor5-premium-features/translations/sq.js");case"sr":return await import("ckeditor5-premium-features/translations/sr.js");case"sr-latn":return await import("ckeditor5-premium-features/translations/sr-latn.js");case"sv":return await import("ckeditor5-premium-features/translations/sv.js");case"th":return await import("ckeditor5-premium-features/translations/th.js");case"tk":return await import("ckeditor5-premium-features/translations/tk.js");case"tr":return await import("ckeditor5-premium-features/translations/tr.js");case"tt":return await import("ckeditor5-premium-features/translations/tt.js");case"ug":return await import("ckeditor5-premium-features/translations/ug.js");case"uk":return await import("ckeditor5-premium-features/translations/uk.js");case"ur":return await import("ckeditor5-premium-features/translations/ur.js");case"uz":return await import("ckeditor5-premium-features/translations/uz.js");case"vi":return await import("ckeditor5-premium-features/translations/vi.js");case"zh":return await import("ckeditor5-premium-features/translations/zh.js");case"zh-cn":return await import("ckeditor5-premium-features/translations/zh-cn.js");default:return console.warn(`Language ${t} not found in premium translations`),await import("ckeditor5-premium-features/translations/en.js")}}catch(r){return console.error(`Failed to load translation for ${i}/${t}:`,r),null}}function B(i){return $(i,t=>({dictionary:t}))}function M(i){return window.Livewire.all().filter(({name:t,canonical:r})=>t==="ckeditor5-editable"&&r.editorId===i).reduce((t,{canonical:r,el:a})=>({...t,[r.rootName]:{element:a.querySelector("[data-cke-editable-content]"),content:r.content}}),Object.create({}))}function T(i,t){if(t==="decoupled"){const{element:a}=U(i);return a}if(v(t))return document.getElementById(`${i}_editor`);const r=M(i);return $(r,({element:a})=>a)}function j(i,t){if(t==="decoupled"){const{content:n}=U(i);if(typeof n=="string")return{main:n}}const r=M(i),a=$(r,({content:n})=>n);return et(a,n=>typeof n=="string")}function U(i){const t=M(i).main;if(!t)throw new Error(`No "main" editable found for editor with ID "${i}".`);return t}function O(i){if(!i||typeof i!="object")return i;if(Array.isArray(i))return i.map(a=>O(a));const t=i;if(t.$element&&typeof t.$element=="string"){const a=document.querySelector(t.$element);return a||console.warn(`Element not found for selector: ${t.$element}`),a||null}const r=Object.create(null);for(const[a,n]of Object.entries(i))r[a]=O(n);return r}function lt(i,t){const{editing:r}=i;r.view.change(a=>{a.setStyle("height",`${t}px`,r.view.document.getRoot())})}const D=Symbol.for("elixir-editor-watchdog");async function mt(i){const{EditorWatchdog:t}=await import("ckeditor5"),r=new t(i);return r.setCreator(async(...a)=>{const n=await i.create(...a);return n[D]=r,n}),{watchdog:r,Constructor:{create:async(...a)=>(await r.create(...a),r.editor)}}}function dt(i){return D in i?i[D]:null}class E extends V{static the=new E}class wt extends I{contextPromise=null;async mounted(){const{contextId:t,language:r,context:a}=this.canonical,{customTranslations:n,watchdogConfig:s,config:{plugins:o,...c}}=a,{loadedPlugins:u,hasPremium:l}=await N(o??[]),f=[...await F(r,l),B(n||{})].filter(w=>!q(w));this.contextPromise=(async()=>{const{ContextWatchdog:w,Context:y}=await import("ckeditor5"),h=new w(y,{crashNumberLimit:10,...s});return await h.create({...c,language:r,plugins:u,...f.length&&{translations:f}}),h.on("itemError",(...b)=>{console.error("Context item error:",...b)}),h})();const g=await this.contextPromise;this.isBeingDestroyed()||E.the.register(t,g)}async destroyed(){const{contextId:t}=this.canonical;this.element.style.display="none";try{await(await this.contextPromise)?.destroy()}finally{this.contextPromise=null,E.the.hasItem(t)&&E.the.unregister(t)}}}class p extends V{static the=new p}class pt extends I{editorPromise=null;mounted(){const{editorId:t,rootName:r,content:a,saveDebounceMs:n}=this.canonical,s=this.element.querySelector("input");this.editorPromise=p.the.execute(t,o=>{const{ui:c,editing:u,model:l}=o;if(l.document.getRoot(r)){if(a!==null){const w=o.getData({rootName:r});w&&w!==a&&o.setData({[r]:a})}return o}o.addRoot(r,{isUndoable:!1,...a!==null&&{data:a}});const m=this.element.querySelector("[data-cke-editable-content]"),f=c.view.createEditable(r,m);c.addEditable(f),u.view.forceRender();const g=()=>{const w=o.getData({rootName:r});s&&(s.value=w),this.$wire.set("content",w)};return o.model.document.on("change:data",S(n,g)),g(),o})}async afterCommitSynced(){const t=await this.editorPromise,{content:r,rootName:a}=this.canonical;t.getData({rootName:a})!==r&&t.setData({[a]:r??""})}async destroyed(){const{rootName:t}=this.canonical;this.element.style.display="none";const r=await this.editorPromise;if(this.editorPromise=null,r&&r.state!=="destroyed"){const a=r.model.document.getRoot(t);a&&"detachEditable"in r&&(r.detachEditable(a),r.detachRoot(t,!1))}}}async function ht({saveDebounceMs:i,component:t}){const{Plugin:r}=await import("ckeditor5");return class extends r{static get pluginName(){return"LivewireSync"}init(){this.setupTypingContentPush(),this.setupFocusableEventPush(),this.setupContentServerSync(),this.setupLivewireEventListeners()}setupContentServerSync(){this.editor.on("afterCommitSynced",()=>{if(!ot(t.element))return;const{content:n}=t.canonical,s=this.getEditorRootsValues();C(n,s)||this.editor.setData(n)})}setupTypingContentPush(){const{model:n}=this.editor,{$wire:s}=t,o=()=>{const c=this.getEditorRootsValues();C(c,t.canonical.content)||(s.set("content",c),s.dispatch("editor-content-changed",{editorId:t.canonical.editorId,content:c}))};n.document.on("change:data",S(i,o)),this.editor.once("ready",o)}setupFocusableEventPush(){const{ui:n}=this.editor,{$wire:s}=t,o=()=>{const c=this.getEditorRootsValues();s.set("focused",n.focusTracker.isFocused),C(c,t.canonical.content)||s.set("content",c)};n.focusTracker.on("change:isFocused",o)}getEditorRootsValues(){return st(this.editor)}setupLivewireEventListeners(){Livewire.on("set-editor-content",({editorId:n,content:s})=>{if(n!==t.canonical.editorId)return;const o=this.getEditorRootsValues();C(o,s)||this.editor.setData(s)})}}}async function ft(i){const{Plugin:t}=await import("ckeditor5");return class extends t{input=null;form=null;static get pluginName(){return"SyncEditorWithInput"}afterInit(){const{editor:a}=this,s=a.sourceElement.id.replace(/_editor$/,"");this.input=document.getElementById(`${s}_input`),this.input&&(a.model.document.on("change:data",S(i,()=>this.sync())),a.once("ready",this.sync),this.form=this.input.closest("form"),this.form?.addEventListener("submit",this.sync))}sync=()=>{const a=this.editor.getData();this.input.value=a,this.input.dispatchEvent(new Event("input",{bubbles:!0}))};destroy(){this.form&&this.form.removeEventListener("submit",this.sync),this.input=null,this.form=null}}}class gt extends I{editorPromise=null;async mounted(){const{editorId:t}=this.canonical;p.the.resetErrors(t);try{this.editorPromise=this.createEditor();const r=await this.editorPromise;this.isBeingDestroyed()||(p.the.register(t,r),r.once("destroy",()=>{p.the.hasItem(t)&&p.the.unregister(t)}))}catch(r){this.editorPromise=null,p.the.error(t,r)}}async destroyed(){this.element.style.display="none";try{const t=await this.editorPromise;if(!t)return;const r=nt(t),a=dt(t);r?r.state!=="unavailable"&&await r.context.remove(r.editorContextId):a?await a.destroy():await t.destroy()}finally{this.editorPromise=null}}async afterCommitSynced(){(await this.editorPromise)?.fire("afterCommitSynced")}async createEditor(){const{preset:t,editorId:r,contextId:a,editableHeight:n,saveDebounceMs:s,language:o,watchdog:c,content:u}=this.canonical,{customTranslations:l,editorType:m,licenseKey:f,config:{plugins:g,...w}}=t;let y=await ct(m);const h=await(a?E.the.waitFor(a):null);if(c&&!h){const d=await mt(y);({Constructor:y}=d),d.watchdog.on("restart",()=>{const P=d.watchdog.editor;this.editorPromise=Promise.resolve(P),p.the.register(r,P)})}const{loadedPlugins:b,hasPremium:G}=await N(g);b.push(await ht({saveDebounceMs:s,component:this})),v(m)&&b.push(await ft(s));const z=[...await F(o,G),B(l||{})].filter(d=>!q(d));let k={...u,...j(r,m)};v(m)&&(k=k.main||"");const R=await(async()=>{let d=T(r,m);if(Et(d,m)){const W=Object.keys(k);_(d,W)||(d=await yt(r,m,W),k={...u,...j(r,m)})}const P={...O(w),initialData:k,licenseKey:f,plugins:b,language:o,...z.length&&{translations:z}};return!h||!(d instanceof HTMLElement)?y.create(d,P):(await at({context:h,element:d,creator:y,config:P})).editor})();return v(m)&&n&&lt(R,n),R}}function _(i,t){return t.every(r=>i[r])}async function yt(i,t,r){return await it(()=>{const a=T(i,t);if(!_(a,r))throw new Error(`It looks like not all required root elements are present yet.
2
2
  * If you want to wait for them, ensure they are registered before editor initialization.
3
3
  * If you want lazy initialize roots, consider removing root values from the \`initialData\` config and assign initial data in editable components.
4
- Missing roots: ${r.filter(n=>!a[n]).join(", ")}.`);return!0},{timeOutAfter:2e3,retryAfter:100}),T(i,t)}function yt(i,t){return!k(t)&&typeof i=="object"&&!(i instanceof HTMLElement)}class Et extends v{mountedPromise=null;async mounted(){const{editorId:t,name:r}=this.ephemeral;this.mountedPromise=w.the.execute(t,a=>{const{ui:n}=a,o=bt(r),s=n.view[o];if(!s){console.error(`Unknown UI part name: "${r}". Supported names are "toolbar" and "menubar".`);return}this.element.appendChild(s.element)})}async destroyed(){this.element.style.display="none",await this.mountedPromise,this.mountedPromise=null,this.element.innerHTML=""}}function bt(i){switch(i){case"toolbar":return"toolbar";case"menubar":return"menuBarView";default:return null}}const kt={ckeditor5:ft,"ckeditor5-context":dt,"ckeditor5-ui-part":Et,"ckeditor5-editable":pt};function Pt(){for(const[i,t]of Object.entries(kt))tt(i,t)}Pt();
4
+ Missing roots: ${r.filter(n=>!a[n]).join(", ")}.`);return!0},{timeOutAfter:2e3,retryAfter:100}),T(i,t)}function Et(i,t){return!v(t)&&typeof i=="object"&&!(i instanceof HTMLElement)}class bt extends I{mountedPromise=null;async mounted(){const{editorId:t,name:r}=this.canonical;this.mountedPromise=p.the.execute(t,a=>{const{ui:n}=a,s=kt(r),o=n.view[s];if(!o){console.error(`Unknown UI part name: "${r}". Supported names are "toolbar" and "menubar".`);return}this.element.appendChild(o.element)})}async destroyed(){this.element.style.display="none",await this.mountedPromise,this.mountedPromise=null,this.element.innerHTML=""}}function kt(i){switch(i){case"toolbar":return"toolbar";case"menubar":return"menuBarView";default:return null}}const Pt={ckeditor5:gt,"ckeditor5-context":wt,"ckeditor5-ui-part":bt,"ckeditor5-editable":pt};function vt(){for(const[i,t]of Object.entries(Pt))tt(i,t)}vt();
5
5
  //# sourceMappingURL=index.cjs.map