ckeditor5-livewire 1.3.1 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/editor/plugins/livewire-sync.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +120 -105
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/hooks/editor/editor.test.ts +17 -0
- package/src/hooks/editor/plugins/livewire-sync.ts +20 -0
|
@@ -695,6 +695,23 @@ describe('editor component', () => {
|
|
|
695
695
|
});
|
|
696
696
|
|
|
697
697
|
describe('dispatch / receive events', () => {
|
|
698
|
+
it('should dispatch `editor-ready` event when editor becomes ready', async () => {
|
|
699
|
+
const { $wire } = livewireStub.$internal.appendComponentToDOM<EditorSnapshot>({
|
|
700
|
+
name: 'ckeditor5',
|
|
701
|
+
el: createEditorHtmlElement(),
|
|
702
|
+
canonical: createEditorSnapshot(),
|
|
703
|
+
});
|
|
704
|
+
|
|
705
|
+
// clear initial calls that may come from mounting logic
|
|
706
|
+
$wire.dispatch.mockClear();
|
|
707
|
+
|
|
708
|
+
await waitForTestEditor();
|
|
709
|
+
|
|
710
|
+
expect($wire.dispatch).toHaveBeenCalledExactlyOnceWith('editor-ready', {
|
|
711
|
+
editorId: DEFAULT_TEST_EDITOR_ID,
|
|
712
|
+
});
|
|
713
|
+
});
|
|
714
|
+
|
|
698
715
|
it('should dispatch `editor-content-changed` event on content change', async () => {
|
|
699
716
|
vi.useFakeTimers();
|
|
700
717
|
|
|
@@ -32,6 +32,7 @@ export async function createLivewireSyncPlugin(
|
|
|
32
32
|
this.setupFocusableEventPush();
|
|
33
33
|
this.setupAfterCommitHandler();
|
|
34
34
|
this.setupSetEditorContentHandler();
|
|
35
|
+
this.setupReadyDispatch();
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
/**
|
|
@@ -81,6 +82,25 @@ export async function createLivewireSyncPlugin(
|
|
|
81
82
|
});
|
|
82
83
|
}
|
|
83
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Dispatches a Livewire event when the editor becomes ready.
|
|
87
|
+
*
|
|
88
|
+
* This allows the Livewire component or parent to react as soon as the
|
|
89
|
+
* instance is fully initialized. The payload contains the editorId so the
|
|
90
|
+
* listener can ignore events coming from other editors on the page.
|
|
91
|
+
*/
|
|
92
|
+
private setupReadyDispatch() {
|
|
93
|
+
const { $wire } = component;
|
|
94
|
+
|
|
95
|
+
// `ready` is fired by CKEditor5 once initialization finishes. We only
|
|
96
|
+
// need to fire the Livewire event once, hence `once`.
|
|
97
|
+
this.editor.once('ready', () => {
|
|
98
|
+
$wire.dispatch('editor-ready', {
|
|
99
|
+
editorId: component.canonical.editorId,
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
84
104
|
/**
|
|
85
105
|
* Setups the content sync from Livewire to the editor when Livewire emits an event.
|
|
86
106
|
*/
|