ckeditor5-livewire 1.9.0 → 1.11.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/dist/hooks/editable.d.ts +3 -5
  2. package/dist/hooks/editable.d.ts.map +1 -1
  3. package/dist/hooks/editor/editor.d.ts +0 -4
  4. package/dist/hooks/editor/editor.d.ts.map +1 -1
  5. package/dist/hooks/editor/plugins/livewire-sync.d.ts.map +1 -1
  6. package/dist/hooks/editor/utils/cleanup-orphan-editor-elements.d.ts +8 -0
  7. package/dist/hooks/editor/utils/cleanup-orphan-editor-elements.d.ts.map +1 -0
  8. package/dist/hooks/editor/utils/create-editor-in-context.d.ts +6 -1
  9. package/dist/hooks/editor/utils/create-editor-in-context.d.ts.map +1 -1
  10. package/dist/hooks/editor/utils/index.d.ts +2 -0
  11. package/dist/hooks/editor/utils/index.d.ts.map +1 -1
  12. package/dist/hooks/editor/utils/is-multiroot-editor-instance.d.ts +6 -0
  13. package/dist/hooks/editor/utils/is-multiroot-editor-instance.d.ts.map +1 -0
  14. package/dist/hooks/editor/utils/wrap-with-watchdog.d.ts +7 -16
  15. package/dist/hooks/editor/utils/wrap-with-watchdog.d.ts.map +1 -1
  16. package/dist/hooks/ui-part.d.ts +2 -6
  17. package/dist/hooks/ui-part.d.ts.map +1 -1
  18. package/dist/index.cjs +2 -2
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.mjs +297 -220
  21. package/dist/index.mjs.map +1 -1
  22. package/dist/shared/are-maps-equal.d.ts +11 -0
  23. package/dist/shared/are-maps-equal.d.ts.map +1 -0
  24. package/dist/shared/async-registry.d.ts +43 -10
  25. package/dist/shared/async-registry.d.ts.map +1 -1
  26. package/dist/shared/index.d.ts +1 -0
  27. package/dist/shared/index.d.ts.map +1 -1
  28. package/package.json +3 -3
  29. package/src/hooks/context/context.test.ts +3 -1
  30. package/src/hooks/editable.ts +73 -46
  31. package/src/hooks/editor/editor.test.ts +44 -9
  32. package/src/hooks/editor/editor.ts +159 -149
  33. package/src/hooks/editor/plugins/livewire-sync.ts +17 -8
  34. package/src/hooks/editor/utils/cleanup-orphan-editor-elements.test.ts +285 -0
  35. package/src/hooks/editor/utils/cleanup-orphan-editor-elements.ts +60 -0
  36. package/src/hooks/editor/utils/create-editor-in-context.ts +6 -2
  37. package/src/hooks/editor/utils/index.ts +2 -0
  38. package/src/hooks/editor/utils/is-multiroot-editor-instance.ts +8 -0
  39. package/src/hooks/editor/utils/wrap-with-watchdog.test.ts +34 -14
  40. package/src/hooks/editor/utils/wrap-with-watchdog.ts +16 -26
  41. package/src/hooks/ui-part.ts +10 -16
  42. package/src/shared/are-maps-equal.test.ts +56 -0
  43. package/src/shared/are-maps-equal.ts +22 -0
  44. package/src/shared/async-registry.test.ts +212 -31
  45. package/src/shared/async-registry.ts +178 -61
  46. package/src/shared/index.ts +1 -0
@@ -3,10 +3,6 @@ import { ClassHook } from './hook';
3
3
  * Editable hook for Livewire. It allows you to create editables for multi-root editors.
4
4
  */
5
5
  export declare class EditableComponentHook extends ClassHook<Snapshot> {
6
- /**
7
- * The promise that resolves when the editable is mounted.
8
- */
9
- private editorPromise;
10
6
  /**
11
7
  * The root attributes updater for the editable's root.
12
8
  */
@@ -26,14 +22,16 @@ export declare class EditableComponentHook extends ClassHook<Snapshot> {
26
22
  /**
27
23
  * Destroys the editable component. Unmounts root from the editor.
28
24
  */
29
- destroyed(): Promise<void>;
25
+ destroyed(): void;
30
26
  /**
31
27
  * Setups the content sync from the editor to Livewire on user input with debounce.
28
+ * Returns a cleanup function that unregisters all event listeners.
32
29
  */
33
30
  private syncTypingContentPush;
34
31
  /**
35
32
  * Sets up handlers that manage pending incoming content (clears pending
36
33
  * content on user edits and applies pending content on blur).
34
+ * Returns a cleanup function that unregisters all event listeners.
37
35
  */
38
36
  private setupPendingReceivedContentHandlers;
39
37
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"editable.d.ts","sourceRoot":"","sources":["../../../src/hooks/editable.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGnC;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,SAAS,CAAC,QAAQ,CAAC;IAC5D;;OAEG;IACH,OAAO,CAAC,aAAa,CAAgD;IAErE;;OAEG;IACH,OAAO,CAAC,qBAAqB,CAAsC;IAEnE;;OAEG;IACH,OAAO,CAAC,cAAc,CAAuB;IAE7C;;OAEG;IACM,OAAO;IAiDhB;;OAEG;IACY,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAOjD;;OAEG;IACY,SAAS;IAyBxB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAuC7B;;;OAGG;IACH,OAAO,CAAC,mCAAmC;IA4B3C;;OAEG;IACH,OAAO,CAAC,6BAA6B;IAsBrC;;OAEG;IACH,OAAO,CAAC,mBAAmB;CAM5B;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;IAEvB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C,CAAC"}
1
+ {"version":3,"file":"editable.d.ts","sourceRoot":"","sources":["../../../src/hooks/editable.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGnC;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,SAAS,CAAC,QAAQ,CAAC;IAC5D;;OAEG;IACH,OAAO,CAAC,qBAAqB,CAAsC;IAEnE;;OAEG;IACH,OAAO,CAAC,cAAc,CAAuB;IAE7C;;OAEG;IACM,OAAO;IAwFhB;;OAEG;IACY,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAQjD;;OAEG;IACM,SAAS;IAMlB;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IA6C7B;;;;OAIG;IACH,OAAO,CAAC,mCAAmC;IA4B3C;;OAEG;IACH,OAAO,CAAC,6BAA6B;IAwBrC;;OAEG;IACH,OAAO,CAAC,mBAAmB;CAM5B;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;IAEvB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C,CAAC"}
@@ -4,10 +4,6 @@ import { ClassHook } from '../hook';
4
4
  * The Livewire hook that manages the lifecycle of CKEditor5 instances.
5
5
  */
6
6
  export declare class EditorComponentHook extends ClassHook<Snapshot> {
7
- /**
8
- * The promise that resolves to the editor instance.
9
- */
10
- private editorPromise;
11
7
  /**
12
8
  * Root attributes updater for the main editor root.
13
9
  */
@@ -1 +1 @@
1
- {"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../../../../src/hooks/editor/editor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAY,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAKxE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAwBpC;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,SAAS,CAAC,QAAQ,CAAC;IAC1D;;OAEG;IACH,OAAO,CAAC,aAAa,CAAgC;IAErD;;OAEG;IACH,OAAO,CAAC,qBAAqB,CAAsC;IAEnE;;OAEG;IACY,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA+BvC;;;OAGG;IACY,SAAS;IAkCxB;;OAEG;IACY,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAUjD;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IAO3B;;OAEG;YACW,YAAY;CAgJ3B;AA4CD;;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,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C,CAAC"}
1
+ {"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../../../../src/hooks/editor/editor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAY,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAIxE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAyBpC;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,SAAS,CAAC,QAAQ,CAAC;IAC1D;;OAEG;IACH,OAAO,CAAC,qBAAqB,CAAsC;IAEnE;;OAEG;IACY,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAuDvC;;;OAGG;IACY,SAAS;IAKxB;;OAEG;IACY,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAUjD;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IAO3B;;OAEG;YACW,YAAY;CAoK3B;AA4CD;;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,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C,CAAC"}
@@ -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,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAMrD;;GAEG;AACH,wBAAsB,wBAAwB,CAC5C,EACE,cAAc,EACd,SAAS,GACV,EAAE,KAAK,GACP,OAAO,CAAC,iBAAiB,CAAC,CAsL5B;AAUD;;GAEG;AACH,KAAK,KAAK,GAAG;IACX,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,mBAAmB,CAAC;CAChC,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;AAMrD;;GAEG;AACH,wBAAsB,wBAAwB,CAC5C,EACE,cAAc,EACd,SAAS,GACV,EAAE,KAAK,GACP,OAAO,CAAC,iBAAiB,CAAC,CA+L5B;AAUD;;GAEG;AACH,KAAK,KAAK,GAAG;IACX,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,mBAAmB,CAAC;CAChC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { Editor } from 'ckeditor5';
2
+ /**
3
+ * Removes all DOM elements injected by a specific CKEditor instance.
4
+ * Call this before assigning a new instance (e.g. in the 'restart' watchdog handler),
5
+ * because the watchdog does not clean up the previous editor's DOM on its own.
6
+ */
7
+ export declare function cleanupOrphanEditorElements(editor: Editor): void;
8
+ //# sourceMappingURL=cleanup-orphan-editor-elements.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cleanup-orphan-editor-elements.d.ts","sourceRoot":"","sources":["../../../../../src/hooks/editor/utils/cleanup-orphan-editor-elements.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAExC;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAoDhE"}
@@ -1,5 +1,4 @@
1
1
  import { Context, ContextWatchdog, Editor, EditorConfig } from 'ckeditor5';
2
- import { EditorCreator } from './wrap-with-watchdog';
3
2
  /**
4
3
  * Creates a CKEditor 5 editor instance within a given context watchdog.
5
4
  *
@@ -23,6 +22,12 @@ export declare function createEditorInContext({ element, context, creator, confi
23
22
  * @returns The context watchdog or null if not found.
24
23
  */
25
24
  export declare function unwrapEditorContext(editor: Editor): EditorContextDescriptor | null;
25
+ /**
26
+ * Type representing an Editor creator with a create method.
27
+ */
28
+ type EditorCreator = {
29
+ create: (...args: any) => Promise<Editor>;
30
+ };
26
31
  /**
27
32
  * Parameters for creating an editor in a context.
28
33
  */
@@ -1 +1 @@
1
- {"version":3,"file":"create-editor-in-context.d.ts","sourceRoot":"","sources":["../../../../../src/hooks/editor/utils/create-editor-in-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEhF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAU1D;;;;;;;;;GASG;AACH,wBAAsB,qBAAqB,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK;;WAgE/E,WAAW,GAAG,aAAa;qBACjB,MAAM;aACd,eAAe,CAAC,OAAO,CAAC;GAhClC;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,uBAAuB,GAAG,IAAI,CAMlF;AAED;;GAEG;AACH,KAAK,KAAK,GAAG;IACX,OAAO,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IAClC,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,EAAE,WAAW,CAAC;IACrB,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,KAAK,uBAAuB,GAAG;IAC7B,KAAK,EAAE,WAAW,GAAG,aAAa,CAAC;IACnC,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;CACnC,CAAC"}
1
+ {"version":3,"file":"create-editor-in-context.d.ts","sourceRoot":"","sources":["../../../../../src/hooks/editor/utils/create-editor-in-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAUhF;;;;;;;;;GASG;AACH,wBAAsB,qBAAqB,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK;;WAsE/E,WAAW,GAAG,aAAa;qBACjB,MAAM;aACd,eAAe,CAAC,OAAO,CAAC;GAtClC;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,uBAAuB,GAAG,IAAI,CAMlF;AAED;;GAEG;AACH,KAAK,aAAa,GAAG;IACnB,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CAC3C,CAAC;AACF;;GAEG;AACH,KAAK,KAAK,GAAG;IACX,OAAO,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IAClC,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,EAAE,WAAW,CAAC;IACrB,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,KAAK,uBAAuB,GAAG;IAC7B,KAAK,EAAE,WAAW,GAAG,aAAa,CAAC;IACnC,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;CACnC,CAAC"}
@@ -1,5 +1,7 @@
1
+ export * from './cleanup-orphan-editor-elements';
1
2
  export * from './create-editor-in-context';
2
3
  export * from './get-editor-roots-values';
4
+ export * from './is-multiroot-editor-instance';
3
5
  export * from './is-single-root-editor';
4
6
  export * from './load-editor-constructor';
5
7
  export * from './load-editor-plugins';
@@ -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,yBAAyB,CAAC;AACxC,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,sCAAsC,CAAC;AACrD,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,kCAAkC,CAAC;AACjD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,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,sCAAsC,CAAC;AACrD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { Editor, MultiRootEditor } from 'ckeditor5';
2
+ /**
3
+ * Check if passed editor is multiroot editor.
4
+ */
5
+ export declare function isMultirootEditorInstance(editor: Editor): editor is MultiRootEditor;
6
+ //# sourceMappingURL=is-multiroot-editor-instance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-multiroot-editor-instance.d.ts","sourceRoot":"","sources":["../../../../../src/hooks/editor/utils/is-multiroot-editor-instance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEzD;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,eAAe,CAEnF"}
@@ -1,24 +1,15 @@
1
- import { Editor, EditorWatchdog } from 'ckeditor5';
1
+ import { Editor, EditorWatchdog, WatchdogConfig } from 'ckeditor5';
2
2
  /**
3
- * Wraps an Editor creator with a watchdog for automatic recovery.
3
+ * Wraps an editor factory with a watchdog for automatic recovery.
4
+ * The factory is invoked on each (re)start, so configuration is rebuilt every time.
4
5
  *
5
- * @param Editor - The Editor creator to wrap.
6
- * @returns The Editor creator wrapped with a watchdog.
6
+ * @param factory Async function that creates and returns an Editor instance.
7
+ * @param watchdogConfig Configuration of the watchdog.
8
+ * @returns The watchdog instance.
7
9
  */
8
- export declare function wrapWithWatchdog(Editor: EditorCreator): Promise<{
9
- watchdog: EditorWatchdog<Editor>;
10
- Constructor: {
11
- create: (...args: Parameters<(typeof Editor)["create"]>) => Promise<Editor>;
12
- };
13
- }>;
10
+ export declare function wrapWithWatchdog(factory: () => Promise<Editor>, watchdogConfig?: WatchdogConfig | null): Promise<EditorWatchdog<Editor>>;
14
11
  /**
15
12
  * Unwraps the EditorWatchdog from the editor instance.
16
13
  */
17
14
  export declare function unwrapEditorWatchdog(editor: Editor): EditorWatchdog | null;
18
- /**
19
- * Type representing an Editor creator with a create method.
20
- */
21
- export type EditorCreator = {
22
- create: (...args: any) => Promise<Editor>;
23
- };
24
15
  //# sourceMappingURL=wrap-with-watchdog.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wrap-with-watchdog.d.ts","sourceRoot":"","sources":["../../../../../src/hooks/editor/utils/wrap-with-watchdog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAIxD;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,aAAa;;;0BAe9B,UAAU,CAAC,CAAA,OAAO,MAAM,EAAC,QAAQ,CAAC,CAAC;;GAOhE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAM1E;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CAC3C,CAAC"}
1
+ {"version":3,"file":"wrap-with-watchdog.d.ts","sourceRoot":"","sources":["../../../../../src/hooks/editor/utils/wrap-with-watchdog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAIxE;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,cAAc,CAAC,EAAE,cAAc,GAAG,IAAI,mCAiB5G;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAM1E"}
@@ -3,18 +3,14 @@ import { ClassHook } from './hook';
3
3
  * UI Part hook for Livewire. It allows you to create UI parts for multi-root editors.
4
4
  */
5
5
  export declare class UIPartComponentHook extends ClassHook<Snapshot> {
6
- /**
7
- * The promise that resolves when the UI part is mounted.
8
- */
9
- private mountedPromise;
10
6
  /**
11
7
  * Mounts the UI part component.
12
8
  */
13
- mounted(): Promise<void>;
9
+ mounted(): void;
14
10
  /**
15
11
  * Destroys the UI part component. Unmounts UI parts from the editor.
16
12
  */
17
- destroyed(): Promise<void>;
13
+ destroyed(): void;
18
14
  }
19
15
  /**
20
16
  * A snapshot of the Livewire component's state relevant to the CKEditor5 UI part hook.
@@ -1 +1 @@
1
- {"version":3,"file":"ui-part.d.ts","sourceRoot":"","sources":["../../../src/hooks/ui-part.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,SAAS,CAAC,QAAQ,CAAC;IAC1D;;OAEG;IACH,OAAO,CAAC,cAAc,CAA8B;IAEpD;;OAEG;IACY,OAAO;IAwBtB;;OAEG;IACY,SAAS;CAWzB;AAkBD;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
1
+ {"version":3,"file":"ui-part.d.ts","sourceRoot":"","sources":["../../../src/hooks/ui-part.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,SAAS,CAAC,QAAQ,CAAC;IAC1D;;OAEG;IACM,OAAO;IA6BhB;;OAEG;IACM,SAAS;CAKnB;AAkBD;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=class{state=`mounting`;_beforeDestroyCallbacks=[];constructor(e){this.livewireComponent=e}onBeforeDestroy(e){this._beforeDestroyCallbacks.push(e)}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)}_runBeforeDestroyCallbacks(){for(let e of this._beforeDestroyCallbacks.reverse())e();this._beforeDestroyCallbacks=[]}};function t(e,t){let n=new Map;window.Livewire?.hook(`component.init`,async({component:r,cleanup:i})=>{if(r.name!==e)return;let a=new t(r);n.set(r.id,a),i(async()=>{a.state=`destroying`,a._runBeforeDestroyCallbacks(),await a.destroyed(),a.state=`destroyed`,n.delete(r.id)}),await a.mounted(),a.state=`mounted`}),window.Livewire?.hook(`commit`,async({component:t,succeed:r})=>{t.name===e&&r(()=>{let e=n.get(t.id);e?.state===`mounted`&&e?.afterCommitSynced?.()})})}var n=class{items=new Map;initializationErrors=new Map;pendingCallbacks=new Map;watchers=new Set;execute(e,t,n){let r=this.items.get(e),i=this.initializationErrors.get(e);return i?(n?.(i),Promise.reject(i)):r?Promise.resolve(t(r)):new Promise((r,i)=>{let a=this.getPendingCallbacks(e);a.success.push(async e=>{r(await t(e))}),n?a.error.push(n):a.error.push(i)})}register(e,t){if(this.items.has(e))throw Error(`Item with ID "${e}" is already registered.`);this.resetErrors(e),this.items.set(e,t);let n=this.pendingCallbacks.get(e);n&&(n.success.forEach(e=>e(t)),this.pendingCallbacks.delete(e)),this.registerAsDefault(e,t),this.notifyWatchers()}error(e,t){this.items.delete(e),this.initializationErrors.set(e,t);let n=this.pendingCallbacks.get(e);n&&(n.error.forEach(e=>e(t)),this.pendingCallbacks.delete(e)),this.initializationErrors.size===1&&!this.items.size&&this.error(null,t),this.notifyWatchers()}resetErrors(e){let{initializationErrors:t}=this;t.has(null)&&t.get(null)===t.get(e)&&t.delete(null),t.delete(e)}unregister(e){if(!this.items.has(e))throw Error(`Item with ID "${e}" is not registered.`);e&&this.items.get(null)===this.items.get(e)&&this.unregister(null),this.items.delete(e),this.pendingCallbacks.delete(e),this.notifyWatchers()}getItems(){return Array.from(this.items.values())}hasItem(e){return this.items.has(e)}waitFor(e){return new Promise((t,n)=>{this.execute(e,t,n)})}async destroyAll(){let e=Array.from(new Set(this.items.values())).map(e=>e.destroy());this.items.clear(),this.pendingCallbacks.clear(),await Promise.all(e),this.notifyWatchers()}watch(e){return this.watchers.add(e),e(new Map(this.items),new Map(this.initializationErrors)),this.unwatch.bind(this,e)}unwatch(e){this.watchers.delete(e)}notifyWatchers(){this.watchers.forEach(e=>e(new Map(this.items),new Map(this.initializationErrors)))}getPendingCallbacks(e){let t=this.pendingCallbacks.get(e);return t||(t={success:[],error:[]},this.pendingCallbacks.set(e,t)),t}registerAsDefault(e,t){this.items.size===1&&e!==null&&this.register(null,t)}};function r(e,t){let n=null;return(...r)=>{n&&clearTimeout(n),n=setTimeout(()=>{t(...r)},e)}}function i(e,t){let n=Object.entries(e).filter(([e,n])=>t(n,e));return Object.fromEntries(n)}function a(e){return Object.keys(e).length===0&&e.constructor===Object}function o(e,t){let n=Object.entries(e).map(([e,n])=>[e,t(n,e)]);return Object.fromEntries(n)}function s(e,t){if(e===t)return!0;let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(e[r]!==t[r]||!Object.prototype.hasOwnProperty.call(t,r))return!1;return!0}function c(){return Math.random().toString(36).substring(2)}function l(e,{timeOutAfter:t=500,retryAfter:n=100}={}){return new Promise((r,i)=>{let a=Date.now(),o=null,s=setTimeout(()=>{i(o??Error(`Timeout`))},t),c=async()=>{try{let t=await e();clearTimeout(s),r(t)}catch(e){o=e,Date.now()-a>t?i(e):setTimeout(c,n)}};c()})}var u=Symbol.for(`context-editor-watchdog`);async function d({element:e,context:t,creator:n,config:r}){let i=c();await t.add({creator:(e,t)=>n.create(e,t),id:i,sourceElementOrData:e,type:`editor`,config:r});let a=t.getItem(i),o={state:`available`,editorContextId:i,context:t};a[u]=o;let s=t.destroy.bind(t);return t.destroy=async()=>(o.state=`unavailable`,s()),{...o,editor:a}}function f(e){return u in e?e[u]:null}function p(e){return e.model.document.getRootNames().reduce((t,n)=>(t[n]=e.getData({rootName:n}),t),Object.create({}))}function m(e){return[`inline`,`classic`,`balloon`,`decoupled`].includes(e)}async function h(e){let t=await import(`ckeditor5`),n={inline:t.InlineEditor,balloon:t.BalloonEditor,classic:t.ClassicEditor,decoupled:t.DecoupledEditor,multiroot:t.MultiRootEditor}[e];if(!n)throw Error(`Unsupported editor type: ${e}`);return n}var g=class e{static the=new e;plugins=new Map;constructor(){}register(e,t){if(this.plugins.has(e))throw Error(`Plugin with name "${e}" is already registered.`);return this.plugins.set(e,t),this.unregister.bind(this,e)}unregister(e){if(!this.plugins.has(e))throw Error(`Plugin with name "${e}" is not registered.`);this.plugins.delete(e)}unregisterAll(){this.plugins.clear()}async get(e){return this.plugins.get(e)?.()}has(e){return this.plugins.has(e)}};async function _(e){let t=await import(`ckeditor5`),n=null,r=e.map(async e=>{let r=await g.the.get(e);if(r)return r;let{[e]:i}=t;if(i)return i;if(!n)try{n=await import(`ckeditor5-premium-features`)}catch(e){console.error(`Failed to load premium package: ${e}`)}let{[e]:a}=n||{};if(a)return a;throw Error(`Plugin "${e}" not found in base or premium packages.`)});return{loadedPlugins:await Promise.all(r),hasPremium:!!n}}async function v(e,t){let n=[e.ui,e.content],r=[y(`ckeditor5`,n)];return t&&r.push(y(`ckeditor5-premium-features`,n)),await Promise.all(r).then(e=>e.flat())}async function y(e,t){return await Promise.all(t.filter(e=>e!==`en`).map(async t=>{let n=await b(e,t);return n?.default??n}).filter(Boolean))}async function b(e,t){try{if(e===`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(n){return console.error(`Failed to load translation for ${e}/${t}:`,n),null}}function x(e){return o(e,e=>({dictionary:e}))}function S(e){return o(C(e),({element:e})=>e)}function C(e){let t=window.Livewire.all().filter(({name:t,canonical:n})=>t===`ckeditor5-editable`&&n.editorId===e).reduce((e,{canonical:t,el:n})=>({...e,[t.rootName]:{element:n.querySelector(`[data-cke-editable-content]`),content:t.content}}),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;return i&&n?.main?{...t,main:{...i,content:i.content||n.main}}:r?{...t,main:{element:r,content:n?.main||null}}:t}function w(e){return i(o(C(e),({content:e})=>e),e=>typeof e==`string`)}function T(e){if(!e||typeof e!=`object`)return e;if(Array.isArray(e))return e.map(e=>T(e));let t=e;if(t.$element&&typeof t.$element==`string`){let e=document.querySelector(t.$element);return e||console.warn(`Element not found for selector: ${t.$element}`),e||null}let n=Object.create(null);for(let[t,r]of Object.entries(e))n[t]=T(r);return n}function E(e,t,n){if(!n||typeof n!=`object`)return n;if(Array.isArray(n))return n.map(n=>E(e,t,n));let r=n;if(r.$translation&&typeof r.$translation==`string`){let n=r.$translation,i=D(e,n,t);return i===void 0&&console.warn(`Translation not found for key: ${n}`),i===void 0?null:i}let i=Object.create(null);for(let[r,a]of Object.entries(n))i[r]=E(e,t,a);return i}function D(e,t,n){for(let r of e){let e=r[n];if(e?.dictionary&&t in e.dictionary)return e.dictionary[t]}}function O(e,t){let{editing:n}=e;n.view.change(e=>{e.setStyle(`height`,`${t}px`,n.view.document.getRoot())})}var k=Symbol.for(`elixir-editor-watchdog`);async function A(e){let{EditorWatchdog:t}=await import(`ckeditor5`),n=new t(e);return n.setCreator(async(...t)=>{let r=await e.create(...t);return r[k]=n,r}),{watchdog:n,Constructor:{create:async(...e)=>(await n.create(...e),n.editor)}}}function j(e){return k in e?e[k]:null}var M=class e extends n{static the=new e},N=class extends e{contextPromise=null;async mounted(){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));this.contextPromise=(async()=>{let{ContextWatchdog:e,Context:n}=await import(`ckeditor5`),r=new e(n,{crashNumberLimit:10,...i}),a=T(s);return a=E([...u].reverse(),t.ui,a),await r.create({...a,language:t,plugins:c,...u.length&&{translations:u}}),r.on(`itemError`,(...e)=>{console.error(`Context item error:`,...e)}),r})();let d=await this.contextPromise;this.isBeingDestroyed()||M.the.register(e,d)}async destroyed(){let{contextId:e}=this.canonical;this.element.style.display=`none`;try{await(await this.contextPromise)?.destroy()}finally{this.contextPromise=null,M.the.hasItem(e)&&M.the.unregister(e)}}},P=class e extends n{static the=new e};function F(e){let t=e;for(;t;){for(let e of t.attributes)if(e.name.startsWith(`wire:model`))return!0;t=t.parentElement}return!1}function I(e,t){let n=new Set;return r=>{e.model.enqueueChange({isUndoable:!1},i=>{let a=e.model.document.getRoot(t);if(a){for(let e of n)r&&e in r||(i.removeAttribute(e,a),n.delete(e));for(let[e,t]of Object.entries(r??{}))i.setAttribute(e,t,a),n.add(e)}})}}var L=class extends e{editorPromise=null;rootAttributesUpdater=null;pendingContent=null;mounted(){let{editorId:e,rootName:t,content:n}=this.canonical;this.editorPromise=P.the.execute(e,e=>{if(this.isBeingDestroyed())return null;let{ui:r,editing:i,model:a}=e;if(a.document.getRoot(t)){if(n!==null){let r=e.getData({rootName:t});r&&r!==n&&e.setData({[t]:n})}}else{e.addRoot(t,{isUndoable:!1,...n!==null&&{data:n}});let a=this.element.querySelector(`[data-cke-editable-content]`),o=r.view.createEditable(t,a);r.addEditable(o),i.view.forceRender()}return this.syncTypingContentPush(e),this.setupPendingReceivedContentHandlers(e),this.applyRootAttributes(e),e})}async afterCommitSynced(){let e=await this.editorPromise;this.applyCanonicalContentToEditor(e),this.applyRootAttributes(e)}async destroyed(){let{rootName:e}=this.canonical;this.element.style.display=`none`;let t=await this.editorPromise;if(this.editorPromise=null,this.rootAttributesUpdater?.(null),t&&t.state!==`destroyed`){let n=t.model.document.getRoot(e);n&&`detachEditable`in t&&(t.detachEditable(n),t.detachRoot(e,!1))}}syncTypingContentPush(e){let{rootName:t,saveDebounceMs:n}=this.canonical,i=this.element.querySelector(`input`),a=!1,o=()=>{if(a)return;let n=e.getData({rootName:t});i&&(i.value=n),this.$wire.set(`content`,n)},s=r(n,o),c=()=>{e.ui.focusTracker.isFocused?s():o()};e.model.document.on(`change:data`,c),o(),this.onBeforeDestroy(()=>{a=!0,e.model.document.off(`change:data`,c)})}setupPendingReceivedContentHandlers(e){let{ui:t,model:n}=e,{focusTracker:r}=t,{rootName:i}=this.canonical,a=()=>{this.pendingContent=null},o=()=>{!r.isFocused&&this.pendingContent!==null&&(e.setData({[i]:this.pendingContent}),this.pendingContent=null)};n.document.on(`change:data`,a),r.on(`change:isFocused`,o),this.onBeforeDestroy(()=>{n.document.off(`change:data`,a),r.off(`change:isFocused`,o)})}applyCanonicalContentToEditor(e){if(!F(this.element))return;let{content:t,rootName:n}=this.canonical,{ui:r}=e;if(e.getData({rootName:n})!==(t??``)){if(r.focusTracker.isFocused){this.pendingContent=t??``;return}e.setData({[n]:t??``})}}applyRootAttributes(e){let{rootName:t,rootAttributes:n}=this.canonical;this.rootAttributesUpdater??=I(e,t),this.rootAttributesUpdater(n)}};async function R({saveDebounceMs:e,component:t}){let{Plugin:n}=await import(`ckeditor5`);return class extends n{static get pluginName(){return`LivewireSync`}init(){this.setupTypingContentPush(),this.setupFocusableEventPush(),this.setupAfterCommitHandler(),this.setupSetEditorContentHandler(),this.setupReadyDispatch()}setupAfterCommitHandler(){let{editor:e}=this,{model:n,ui:{focusTracker:r}}=e,i=null;e.on(`afterCommitSynced`,()=>{if(!F(t.element))return;let{content:n}=t.canonical,a=this.getEditorRootsValues();if(r.isFocused){s(n,a)||(i=n);return}s(n,a)||e.setData(n)}),n.document.on(`change:data`,()=>{i=null}),r.on(`change:isFocused`,()=>{!r.isFocused&&i!==null&&(e.setData(i),i=null)})}setupReadyDispatch(){let{$wire:e}=t;this.editor.once(`ready`,()=>{e.dispatch(`editor-ready`,{editorId:t.canonical.editorId})})}setupSetEditorContentHandler(){Livewire.on(`set-editor-content`,({editorId:e,content:n})=>{e===t.canonical.editorId&&(s(this.getEditorRootsValues(),n)||this.editor.setData(n))})}setupTypingContentPush(){let{editor:n}=this,{model:i,ui:a}=n,{$wire:o}=t,c=!1,l=()=>{if(c)return;let e=this.getEditorRootsValues();s(e,t.canonical.content??{})||(o.set(`content`,e),o.dispatch(`editor-content-changed`,{editorId:t.canonical.editorId,content:e}))},u=r(e,l),d=()=>{a.focusTracker.isFocused?u():l()};i.document.on(`change:data`,d),n.once(`ready`,l),n.once(`destroy`,()=>{c=!0,i.document.off(`change:data`,d)})}setupFocusableEventPush(){let{ui:e}=this.editor,{$wire:n}=t;e.focusTracker.on(`change:isFocused`,()=>{let r=this.getEditorRootsValues();n.set(`focused`,e.focusTracker.isFocused),s(r,t.canonical.content??{})||n.set(`content`,r)})}getEditorRootsValues(){return p(this.editor)}}}async function z(e){let{Plugin:t}=await import(`ckeditor5`);return class extends t{input=null;form=null;static get pluginName(){return`SyncEditorWithInput`}afterInit(){let{editor:t}=this,n=t.sourceElement.id.replace(/_editor$/,``);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))}sync=()=>{if(this.input){let e=this.editor.getData();this.input.value=e,this.input.dispatchEvent(new Event(`input`,{bubbles:!0}))}};destroy(){this.form&&this.form.removeEventListener(`submit`,this.sync),this.input=null,this.form=null}}}var B=class extends e{editorPromise=null;rootAttributesUpdater=null;async mounted(){let{editorId:e}=this.canonical;P.the.resetErrors(e);try{this.editorPromise=this.createEditor();let t=await this.editorPromise;this.isBeingDestroyed()||(P.the.register(e,t),t.once(`destroy`,()=>{P.the.hasItem(e)&&P.the.unregister(e)}))}catch(t){console.error(`Error initializing CKEditor5 instance with ID "${e}":`,t),this.editorPromise=null,P.the.error(e,t)}}async destroyed(){this.element.style.display=`none`;try{let e=await this.editorPromise;if(!e)return;let t=f(e),n=j(e);t?t.state!==`unavailable`&&await t.context.remove(t.editorContextId):n?await n.destroy():await e.destroy()}finally{this.editorPromise=null}}async afterCommitSynced(){let e=await this.editorPromise;e&&(e.fire(`afterCommitSynced`),this.applyRootAttributes(e))}applyRootAttributes(e){let{rootAttributes:t}=this.canonical;this.rootAttributesUpdater??=I(e,`main`),this.rootAttributesUpdater(t)}async createEditor(){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);if(s&&!b){let e=await A(y);({Constructor:y}=e),e.watchdog.on(`restart`,()=>{let n=e.watchdog.editor;this.editorPromise=Promise.resolve(n),P.the.register(t,n)})}let{loadedPlugins:C,hasPremium:D}=await _(p);C.push(await R({saveDebounceMs:i,component:this})),m(u)&&C.push(await z(i));let k=[...await v(o,D),x(l||{})].filter(e=>!a(e)),j={...c,...w(t)};m(u)&&(j=j.main||``);let N=await(async()=>{let e=S(t);if(!(e instanceof HTMLElement)&&!(`main`in e)){let n=u===`decoupled`?[`main`]:Object.keys(j);V(e,n)||(e=await H(t,n),j={...c,...w(t)})}m(u)&&`main`in e&&(e=e.main);let n=T(g);n=E([...k].reverse(),o.ui,n);let r={...n,initialData:j,licenseKey:f,plugins:C,language:o,...k.length&&{translations:k}};return!b||!(e instanceof HTMLElement)?y.create(e,r):(await d({context:b,element:e,creator:y,config:r})).editor})();return m(u)&&r&&O(N,r),this.applyRootAttributes(N),N}};function V(e,t){return t.every(t=>e[t])}async function H(e,t){return l(()=>{let n=S(e);if(!V(n,t))throw Error(`It looks like not all required root elements are present yet.
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=class{state=`mounting`;_beforeDestroyCallbacks=[];constructor(e){this.livewireComponent=e}onBeforeDestroy(e){this._beforeDestroyCallbacks.push(e)}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)}_runBeforeDestroyCallbacks(){for(let e of this._beforeDestroyCallbacks.reverse())e();this._beforeDestroyCallbacks=[]}};function t(e,t){let n=new Map;window.Livewire?.hook(`component.init`,async({component:r,cleanup:i})=>{if(r.name!==e)return;let a=new t(r);n.set(r.id,a),i(async()=>{a.state=`destroying`,a._runBeforeDestroyCallbacks(),await a.destroyed(),a.state=`destroyed`,n.delete(r.id)}),await a.mounted(),a.state=`mounted`}),window.Livewire?.hook(`commit`,async({component:t,succeed:r})=>{t.name===e&&r(()=>{let e=n.get(t.id);e?.state===`mounted`&&e?.afterCommitSynced?.()})})}function n(e,t){if(!e||e.size!==t.size)return!1;for(let[n,r]of e)if(!t.has(n)||t.get(n)!==r)return!1;return!0}var r=class{items=new Map;initializationErrors=new Map;pendingCallbacks=new Map;watchers=new Set;batchDepth=0;lastNotifiedItems=null;lastNotifiedErrors=null;execute(e,t,n){let r=this.items.get(e),i=this.initializationErrors.get(e);return i?(n?.(i),Promise.reject(i)):r?Promise.resolve(t(r)):new Promise((r,i)=>{let a=this.getPendingCallbacks(e);a.success.push(async e=>{r(await t(e))}),n?a.error.push(n):a.error.push(i)})}mountEffect(e,t){let n,r,i=!1,a=this.watch(o=>{let s=o.get(e);if(s!==r&&(n?.(),n=void 0,r=s,s))try{let e=t(s);i?(e?.(),a()):n=e}catch(e){throw console.error(e),e}});return()=>{i=!0,r&&(a(),n?.(),n=void 0)}}register(e,t){this.batch(()=>{if(this.items.has(e))throw Error(`Item with ID "${e}" is already registered.`);this.resetErrors(e),this.items.set(e,t);let n=this.pendingCallbacks.get(e);n&&(n.success.forEach(e=>e(t)),this.pendingCallbacks.delete(e)),this.items.size===1&&e!==null&&this.register(null,t)})}error(e,t){this.batch(()=>{this.items.delete(e),this.initializationErrors.set(e,t);let n=this.pendingCallbacks.get(e);n&&(n.error.forEach(e=>e(t)),this.pendingCallbacks.delete(e)),this.initializationErrors.size===1&&!this.items.size&&this.error(null,t)})}resetErrors(e){let{initializationErrors:t}=this;t.has(null)&&t.get(null)===t.get(e)&&t.delete(null),t.delete(e)}unregister(e,t=!0){this.batch(()=>{e&&this.items.get(null)===this.items.get(e)&&this.unregister(null,!1),this.items.delete(e),t&&this.pendingCallbacks.delete(e),this.resetErrors(e)})}getItems(){return Array.from(this.items.values())}getItem(e){return this.items.get(e)}hasItem(e){return this.items.has(e)}waitFor(e){return new Promise((t,n)=>{this.execute(e,t,n)})}async destroyAll(){let e=Array.from(new Set(this.items.values())).map(e=>e.destroy());this.items.clear(),this.pendingCallbacks.clear(),await Promise.all(e),this.flushWatchers()}async reset(){await this.destroyAll(),this.watchers.clear()}batch(e){this.batchDepth++;try{return e()}finally{this.batchDepth--,this.batchDepth===0&&this.flushWatchers()}}watch(e){return this.watchers.add(e),e(new Map(this.items),new Map(this.initializationErrors)),this.unwatch.bind(this,e)}unwatch(e){this.watchers.delete(e)}flushWatchers(){n(this.lastNotifiedItems,this.items)&&n(this.lastNotifiedErrors,this.initializationErrors)||(this.lastNotifiedItems=new Map(this.items),this.lastNotifiedErrors=new Map(this.initializationErrors),this.watchers.forEach(e=>e(new Map(this.items),new Map(this.initializationErrors))))}getPendingCallbacks(e){let t=this.pendingCallbacks.get(e);return t||(t={success:[],error:[]},this.pendingCallbacks.set(e,t)),t}};function i(e,t){let n=null;return(...r)=>{n&&clearTimeout(n),n=setTimeout(()=>{t(...r)},e)}}function a(e,t){let n=Object.entries(e).filter(([e,n])=>t(n,e));return Object.fromEntries(n)}function o(e){return Object.keys(e).length===0&&e.constructor===Object}function s(e,t){let n=Object.entries(e).map(([e,n])=>[e,t(n,e)]);return Object.fromEntries(n)}function c(e,t){if(e===t)return!0;let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(e[r]!==t[r]||!Object.prototype.hasOwnProperty.call(t,r))return!1;return!0}function l(){return Math.random().toString(36).substring(2)}function u(e,{timeOutAfter:t=500,retryAfter:n=100}={}){return new Promise((r,i)=>{let a=Date.now(),o=null,s=setTimeout(()=>{i(o??Error(`Timeout`))},t),c=async()=>{try{let t=await e();clearTimeout(s),r(t)}catch(e){o=e,Date.now()-a>t?i(e):setTimeout(c,n)}};c()})}function d(e){let t=[e.ui?.element,e.ui?.view?.toolbar?.element,e.ui?.view?.menuBarView?.element].filter(Boolean);for(let e of t)i(e);let n=e.ui?.view?.body?._bodyCollectionContainer;n?.isConnected&&i(n);let r=e.editing?.view;if(r)for(let e of r.domRoots.values())e instanceof HTMLElement&&(e.removeAttribute(`contenteditable`),e.removeAttribute(`role`),e.removeAttribute(`aria-label`),e.removeAttribute(`aria-multiline`),e.removeAttribute(`spellcheck`),e.classList.remove(`ck`,`ck-content`,`ck-editor__editable`,`ck-rounded-corners`,`ck-editor__editable_inline`,`ck-blurred`,`ck-focused`),i(e));function i(e){e.hasAttribute(`data-cke-controlled`)?e.innerHTML=``:e.remove()}}var f=Symbol.for(`context-editor-watchdog`);async function p({element:e,context:t,creator:n,config:r}){let i=l();await t.add({creator:(e,t)=>n.create(e,t),id:i,sourceElementOrData:e,type:`editor`,config:r});let a=t.getItem(i),o={state:`available`,editorContextId:i,context:t};a[f]=o;let s=t.destroy.bind(t);return t.destroy=async()=>(o.state=`unavailable`,s()),{...o,editor:a}}function m(e){return f in e?e[f]:null}function h(e){return e.model.document.getRootNames().reduce((t,n)=>(t[n]=e.getData({rootName:n}),t),Object.create({}))}function g(e){return`addEditable`in e.ui}function _(e){return[`inline`,`classic`,`balloon`,`decoupled`].includes(e)}async function v(e){let t=await import(`ckeditor5`),n={inline:t.InlineEditor,balloon:t.BalloonEditor,classic:t.ClassicEditor,decoupled:t.DecoupledEditor,multiroot:t.MultiRootEditor}[e];if(!n)throw Error(`Unsupported editor type: ${e}`);return n}var y=class e{static the=new e;plugins=new Map;constructor(){}register(e,t){if(this.plugins.has(e))throw Error(`Plugin with name "${e}" is already registered.`);return this.plugins.set(e,t),this.unregister.bind(this,e)}unregister(e){if(!this.plugins.has(e))throw Error(`Plugin with name "${e}" is not registered.`);this.plugins.delete(e)}unregisterAll(){this.plugins.clear()}async get(e){return this.plugins.get(e)?.()}has(e){return this.plugins.has(e)}};async function b(e){let t=await import(`ckeditor5`),n=null,r=e.map(async e=>{let r=await y.the.get(e);if(r)return r;let{[e]:i}=t;if(i)return i;if(!n)try{n=await import(`ckeditor5-premium-features`)}catch(e){console.error(`Failed to load premium package: ${e}`)}let{[e]:a}=n||{};if(a)return a;throw Error(`Plugin "${e}" not found in base or premium packages.`)});return{loadedPlugins:await Promise.all(r),hasPremium:!!n}}async function x(e,t){let n=[e.ui,e.content],r=[S(`ckeditor5`,n)];return t&&r.push(S(`ckeditor5-premium-features`,n)),await Promise.all(r).then(e=>e.flat())}async function S(e,t){return await Promise.all(t.filter(e=>e!==`en`).map(async t=>{let n=await C(e,t);return n?.default??n}).filter(Boolean))}async function C(e,t){try{if(e===`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(n){return console.error(`Failed to load translation for ${e}/${t}:`,n),null}}function w(e){return s(e,e=>({dictionary:e}))}function T(e){return s(E(e),({element:e})=>e)}function E(e){let t=window.Livewire.all().filter(({name:t,canonical:n})=>t===`ckeditor5-editable`&&n.editorId===e).reduce((e,{canonical:t,el:n})=>({...e,[t.rootName]:{element:n.querySelector(`[data-cke-editable-content]`),content:t.content}}),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;return i&&n?.main?{...t,main:{...i,content:i.content||n.main}}:r?{...t,main:{element:r,content:n?.main||null}}:t}function D(e){return a(s(E(e),({content:e})=>e),e=>typeof e==`string`)}function O(e){if(!e||typeof e!=`object`)return e;if(Array.isArray(e))return e.map(e=>O(e));let t=e;if(t.$element&&typeof t.$element==`string`){let e=document.querySelector(t.$element);return e||console.warn(`Element not found for selector: ${t.$element}`),e||null}let n=Object.create(null);for(let[t,r]of Object.entries(e))n[t]=O(r);return n}function k(e,t,n){if(!n||typeof n!=`object`)return n;if(Array.isArray(n))return n.map(n=>k(e,t,n));let r=n;if(r.$translation&&typeof r.$translation==`string`){let n=r.$translation,i=A(e,n,t);return i===void 0&&console.warn(`Translation not found for key: ${n}`),i===void 0?null:i}let i=Object.create(null);for(let[r,a]of Object.entries(n))i[r]=k(e,t,a);return i}function A(e,t,n){for(let r of e){let e=r[n];if(e?.dictionary&&t in e.dictionary)return e.dictionary[t]}}function j(e,t){let{editing:n}=e;n.view.change(e=>{e.setStyle(`height`,`${t}px`,n.view.document.getRoot())})}var M=Symbol.for(`livewire-editor-watchdog`);async function N(e,t){let{EditorWatchdog:n}=await import(`ckeditor5`),r=new n(null,t??{crashNumberLimit:10,minimumNonErrorTimePeriod:5e3});return r.setCreator(async()=>{let t=await e();return t[M]=r,t}),r}function P(e){return M in e?e[M]:null}var F=class e extends r{static the=new e},I=class extends e{contextPromise=null;async mounted(){let{contextId:e,language:t,context:n}=this.canonical,{customTranslations:r,watchdogConfig:i,config:{plugins:a,...s}}=n,{loadedPlugins:c,hasPremium:l}=await b(a??[]),u=[...await x(t,l),w(r||{})].filter(e=>!o(e));this.contextPromise=(async()=>{let{ContextWatchdog:e,Context:n}=await import(`ckeditor5`),r=new e(n,{crashNumberLimit:10,...i}),a=O(s);return a=k([...u].reverse(),t.ui,a),await r.create({...a,language:t,plugins:c,...u.length&&{translations:u}}),r.on(`itemError`,(...e)=>{console.error(`Context item error:`,...e)}),r})();let d=await this.contextPromise;this.isBeingDestroyed()||F.the.register(e,d)}async destroyed(){let{contextId:e}=this.canonical;this.element.style.display=`none`;try{await(await this.contextPromise)?.destroy()}finally{this.contextPromise=null,F.the.hasItem(e)&&F.the.unregister(e)}}},L=class e extends r{static the=new e};function R(e){let t=e;for(;t;){for(let e of t.attributes)if(e.name.startsWith(`wire:model`))return!0;t=t.parentElement}return!1}function z(e,t){let n=new Set;return r=>{e.model.enqueueChange({isUndoable:!1},i=>{let a=e.model.document.getRoot(t);if(a){for(let e of n)r&&e in r||(i.removeAttribute(e,a),n.delete(e));for(let[e,t]of Object.entries(r??{}))i.setAttribute(e,t,a),n.add(e)}})}}var B=class extends e{rootAttributesUpdater=null;pendingContent=null;mounted(){let{editorId:e,rootName:t,content:n}=this.canonical,r=L.the.mountEffect(e,e=>{if(this.isBeingDestroyed())return;let r=e.model.document.getRoot(t);if(r?.isAttached()&&n!==null){let r=e.getData({rootName:t});r&&r!==n&&e.setData({[t]:n})}if(!r&&g(e)){let{ui:r,editing:i}=e;e.addRoot(t,{isUndoable:!1,...n!==null&&{data:n}});let a=this.element.querySelector(`[data-cke-editable-content]`),o=r.view.createEditable(t,a);r.addEditable(o),i.view.forceRender()}let i=this.syncTypingContentPush(e),a=this.setupPendingReceivedContentHandlers(e);return this.applyRootAttributes(e),()=>{if(i(),a(),this.rootAttributesUpdater?.(null),e.state!==`destroyed`){let n=e.model.document.getRoot(t);if(n&&g(e)){try{e.ui.view.editables[t]&&e.detachEditable(n)}catch(e){console.error(`Unable unmount editable from root:`,e)}n.isAttached()&&e.detachRoot(t,!1)}}}});this.onBeforeDestroy(r)}async afterCommitSynced(){let{editorId:e}=this.canonical,t=await L.the.waitFor(e);this.applyCanonicalContentToEditor(t),this.applyRootAttributes(t)}destroyed(){this.element.style.display=`none`}syncTypingContentPush(e){let{rootName:t,saveDebounceMs:n}=this.canonical,r=this.element.querySelector(`input`),a=!1,o=()=>{if(a||!e.model.document.getRoot(t)?.isAttached())return;let n=e.getData({rootName:t});r&&(r.value=n),this.$wire.set(`content`,n)},s=i(n,o),c=()=>{e.ui.focusTracker.isFocused?s():o()};return e.model.document.on(`change:data`,c),o(),()=>{a=!0,e.model.document.off(`change:data`,c)}}setupPendingReceivedContentHandlers(e){let{ui:t,model:n}=e,{focusTracker:r}=t,{rootName:i}=this.canonical,a=()=>{this.pendingContent=null},o=()=>{!r.isFocused&&this.pendingContent!==null&&(e.setData({[i]:this.pendingContent}),this.pendingContent=null)};return n.document.on(`change:data`,a),r.on(`change:isFocused`,o),()=>{n.document.off(`change:data`,a),r.off(`change:isFocused`,o)}}applyCanonicalContentToEditor(e){if(!R(this.element))return;let{content:t,rootName:n}=this.canonical,{ui:r}=e;if(e.getData({rootName:n})!==(t??``)){if(r.focusTracker.isFocused){this.pendingContent=t??``;return}e.setData({[n]:t??``})}}applyRootAttributes(e){let{rootName:t,rootAttributes:n}=this.canonical;this.rootAttributesUpdater??=z(e,t),this.rootAttributesUpdater(n)}};async function V({saveDebounceMs:e,component:t}){let{Plugin:n}=await import(`ckeditor5`);return class extends n{static get pluginName(){return`LivewireSync`}init(){this.setupTypingContentPush(),this.setupFocusableEventPush(),this.setupAfterCommitHandler(),this.setupSetEditorContentHandler(),this.setupReadyDispatch()}setupAfterCommitHandler(){let{editor:e}=this,{model:n,ui:{focusTracker:r}}=e,i=null;e.on(`afterCommitSynced`,()=>{if(!R(t.element))return;let{content:n}=t.canonical,a=this.getEditorRootsValues();if(r.isFocused){c(n,a)||(i=n);return}c(n,a)||e.setData(n)}),n.document.on(`change:data`,()=>{i=null}),r.on(`change:isFocused`,()=>{!r.isFocused&&i!==null&&(e.setData(i),i=null)})}setupReadyDispatch(){let{$wire:e}=t;this.editor.once(`ready`,()=>{e.dispatch(`editor-ready`,{editorId:t.canonical.editorId})})}setupSetEditorContentHandler(){let{editor:e}=this,n=Livewire.on(`set-editor-content`,({editorId:n,content:r})=>{n===t.canonical.editorId&&(c(this.getEditorRootsValues(),r)||e.setData(r))});typeof n==`function`&&e.once(`destroy`,n)}setupTypingContentPush(){let{editor:n}=this,{model:r,ui:a}=n,{$wire:o}=t,s=!1,l=()=>{if(s)return;let e=this.getEditorRootsValues();c(e,t.canonical.content??{})||(o.set(`content`,e),o.dispatch(`editor-content-changed`,{editorId:t.canonical.editorId,content:e}))},u=i(e,l);r.document.on(`change:data`,i(10,()=>{a.focusTracker.isFocused?u():l()})),n.once(`ready`,l),n.once(`destroy`,()=>{s=!0})}setupFocusableEventPush(){let{ui:e}=this.editor,{$wire:n}=t;e.focusTracker.on(`change:isFocused`,()=>{let r=this.getEditorRootsValues();n.set(`focused`,e.focusTracker.isFocused),c(r,t.canonical.content??{})||n.set(`content`,r)})}getEditorRootsValues(){return h(this.editor)}}}async function H(e){let{Plugin:t}=await import(`ckeditor5`);return class extends t{input=null;form=null;static get pluginName(){return`SyncEditorWithInput`}afterInit(){let{editor:t}=this,n=t.sourceElement.id.replace(/_editor$/,``);this.input=document.getElementById(`${n}_input`),this.input&&(t.model.document.on(`change:data`,i(e,()=>this.sync())),t.once(`ready`,this.sync),this.form=this.input.closest(`form`),this.form?.addEventListener(`submit`,this.sync))}sync=()=>{if(this.input){let e=this.editor.getData();this.input.value=e,this.input.dispatchEvent(new Event(`input`,{bubbles:!0}))}};destroy(){this.form&&this.form.removeEventListener(`submit`,this.sync),this.input=null,this.form=null}}}var U=class extends e{rootAttributesUpdater=null;async mounted(){let{editorId:e}=this.canonical;L.the.resetErrors(e);try{let t=await this.createEditor(),n=m(t),r=P(t);if(this.isBeingDestroyed())return;let i=L.the.mountEffect(e,t=>{t.once(`destroy`,()=>{L.the.unregister(e,!1)},{priority:`highest`})});this.onBeforeDestroy(async()=>{L.the.unregister(e),i(),n?n.state!==`unavailable`&&await n.context.remove(n.editorContextId):r?await r.destroy():await t.destroy()}),L.the.register(e,t)}catch(t){console.error(`Error initializing CKEditor5 instance with ID "${e}":`,t),L.the.error(e,t)}}async destroyed(){this.element.style.display=`none`}async afterCommitSynced(){let e=await L.the.waitFor(this.canonical.editorId);e&&(e.fire(`afterCommitSynced`),this.applyRootAttributes(e))}applyRootAttributes(e){let{rootAttributes:t}=this.canonical;this.rootAttributesUpdater??=z(e,`main`),this.rootAttributesUpdater(t)}async createEditor(){let{preset:e,editorId:t,contextId:n,editableHeight:r,saveDebounceMs:i,language:a,watchdog:s,content:c}=this.canonical,{customTranslations:l,editorType:u,licenseKey:f,watchdogConfig:m,config:{plugins:h,...g}}=e,y=await v(u),S=await(n?F.the.waitFor(n):null),C=async()=>{let{loadedPlugins:e,hasPremium:n}=await b(h);e.push(await V({saveDebounceMs:i,component:this})),_(u)&&e.push(await H(i));let s=[...await x(a,n),w(l||{})].filter(e=>!o(e)),d={...c,...D(t)};_(u)&&(d=d.main||``);let m=await(async()=>{let n=T(t);if(!(n instanceof HTMLElement)&&!(`main`in n)){let e=u===`decoupled`?[`main`]:Object.keys(d);W(n,e)||(n=await G(t,e),d={...c,...D(t)})}_(u)&&`main`in n&&(n=n.main);let r=O(g);r=k([...s].reverse(),a.ui,r);let i={...r,initialData:d,licenseKey:f,plugins:e,language:a,...s.length&&{translations:s}};return!S||!(n instanceof HTMLElement)?y.create(n,i):(await p({context:S,element:n,creator:y,config:i})).editor})();return _(u)&&r&&j(m,r),this.applyRootAttributes(m),m};if(s&&!S){let e=await N(C,m);return e.on(`error`,(e,{causesRestart:n})=>{if(n){let e=L.the.getItem(t);e&&(d(e),L.the.unregister(t))}}),e.on(`restart`,()=>{L.the.register(t,e.editor)}),await e.create({}),e.editor}return C()}};function W(e,t){return t.every(t=>e[t])}async function G(e,t){return u(()=>{let n=T(e);if(!W(n,t))throw 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: ${t.filter(e=>!n[e]).join(`, `)}.`);return n},{timeOutAfter:2e3,retryAfter:100})}var U=class extends e{mountedPromise=null;async mounted(){let{editorId:e,name:t}=this.canonical;this.mountedPromise=P.the.execute(e,e=>{if(this.isBeingDestroyed())return;let{ui:n}=e,r=W(t),i=n.view[r];if(!i){console.error(`Unknown UI part name: "${t}". Supported names are "toolbar" and "menubar".`);return}this.element.appendChild(i.element)})}async destroyed(){this.element.style.display=`none`,await this.mountedPromise,this.mountedPromise=null,this.element.innerHTML=``}};function W(e){switch(e){case`toolbar`:return`toolbar`;case`menubar`:return`menuBarView`;default:return null}}var G={ckeditor5:B,"ckeditor5-context":N,"ckeditor5-ui-part":U,"ckeditor5-editable":L};function K(){for(let[e,n]of Object.entries(G))t(e,n)}K(),exports.ClassHook=e,exports.ContextsRegistry=M,exports.CustomEditorPluginsRegistry=g,exports.EditableComponentHook=L,exports.EditorComponentHook=B,exports.EditorsRegistry=P,exports.UIPartComponentHook=U,exports.registerLivewireComponentHook=t;
4
+ Missing roots: ${t.filter(e=>!n[e]).join(`, `)}.`);return n},{timeOutAfter:2e3,retryAfter:100})}var K=class extends e{mounted(){let{editorId:e,name:t}=this.canonical,n=L.the.mountEffect(e,e=>{if(this.isBeingDestroyed())return;let{ui:n}=e,r=q(t),i=n.view[r];if(!i){console.error(`Unknown UI part name: "${t}". Supported names are "toolbar" and "menubar".`);return}return this.element.appendChild(i.element),()=>{this.element.innerHTML=``}});this.onBeforeDestroy(n)}destroyed(){this.element.style.display=`none`}};function q(e){switch(e){case`toolbar`:return`toolbar`;case`menubar`:return`menuBarView`;default:return null}}var J={ckeditor5:U,"ckeditor5-context":I,"ckeditor5-ui-part":K,"ckeditor5-editable":B};function Y(){for(let[e,n]of Object.entries(J))t(e,n)}Y(),exports.ClassHook=e,exports.ContextsRegistry=F,exports.CustomEditorPluginsRegistry=y,exports.EditableComponentHook=B,exports.EditorComponentHook=U,exports.EditorsRegistry=L,exports.UIPartComponentHook=K,exports.registerLivewireComponentHook=t;
5
5
  //# sourceMappingURL=index.cjs.map