ckeditor5-livewire 1.11.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/editor/editor.d.ts.map +1 -1
- package/dist/hooks/editor/types/editor-relaxed-constructor.type.d.ts +6 -0
- package/dist/hooks/editor/types/editor-relaxed-constructor.type.d.ts.map +1 -0
- package/dist/hooks/editor/types/index.d.ts +2 -0
- package/dist/hooks/editor/types/index.d.ts.map +1 -0
- package/dist/hooks/editor/utils/assign-initial-data-to-editor-config.d.ts +10 -0
- package/dist/hooks/editor/utils/assign-initial-data-to-editor-config.d.ts.map +1 -0
- package/dist/hooks/editor/utils/assign-source-elements-to-editor-config.d.ts +12 -0
- package/dist/hooks/editor/utils/assign-source-elements-to-editor-config.d.ts.map +1 -0
- package/dist/hooks/editor/utils/create-editor-in-context.d.ts +1 -3
- package/dist/hooks/editor/utils/create-editor-in-context.d.ts.map +1 -1
- package/dist/hooks/editor/utils/index.d.ts +2 -0
- package/dist/hooks/editor/utils/index.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +166 -126
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/hooks/editable.ts +1 -1
- package/src/hooks/editor/editor.ts +8 -6
- package/src/hooks/editor/types/editor-relaxed-constructor.type.ts +6 -0
- package/src/hooks/editor/types/index.ts +1 -0
- package/src/hooks/editor/utils/assign-initial-data-to-editor-config.ts +48 -0
- package/src/hooks/editor/utils/assign-source-elements-to-editor-config.ts +61 -0
- package/src/hooks/editor/utils/create-editor-in-context.ts +2 -5
- package/src/hooks/editor/utils/index.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ckeditor5-livewire",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "CKEditor 5 integration for Laravel Livewire",
|
|
5
5
|
"author": "Mateusz Bagiński <cziken58@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
],
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@vitest/coverage-v8": "^4.1.0",
|
|
33
|
-
"ckeditor5": "^
|
|
34
|
-
"ckeditor5-premium-features": "^
|
|
33
|
+
"ckeditor5": "^48.1.0",
|
|
34
|
+
"ckeditor5-premium-features": "^48.1.0",
|
|
35
35
|
"happy-dom": "^20.8.9",
|
|
36
36
|
"typescript": "^5.5.4",
|
|
37
37
|
"vite": "^8.0.5",
|
package/src/hooks/editable.ts
CHANGED
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
createSyncEditorWithInputPlugin,
|
|
14
14
|
} from './plugins';
|
|
15
15
|
import {
|
|
16
|
+
assignInitialDataToEditorConfig,
|
|
17
|
+
assignSourceElementsToEditorConfig,
|
|
16
18
|
cleanupOrphanEditorElements,
|
|
17
19
|
createEditorInContext,
|
|
18
20
|
isSingleRootEditor,
|
|
@@ -228,16 +230,17 @@ export class EditorComponentHook extends ClassHook<Snapshot> {
|
|
|
228
230
|
sourceElements = sourceElements['main'];
|
|
229
231
|
}
|
|
230
232
|
|
|
231
|
-
|
|
232
|
-
let resolvedConfig = resolveEditorConfigElementReferences(config);
|
|
233
|
+
let resolvedConfig = { ...config };
|
|
233
234
|
|
|
234
|
-
//
|
|
235
|
+
// Do some postprocessing on received configuration.
|
|
236
|
+
resolvedConfig = resolveEditorConfigElementReferences(resolvedConfig);
|
|
235
237
|
resolvedConfig = resolveEditorConfigTranslations([...mixedTranslations].reverse(), language.ui, resolvedConfig);
|
|
238
|
+
resolvedConfig = assignSourceElementsToEditorConfig(Constructor, sourceElements, resolvedConfig);
|
|
239
|
+
resolvedConfig = assignInitialDataToEditorConfig(initialData, resolvedConfig);
|
|
236
240
|
|
|
237
241
|
// Construct parsed config.
|
|
238
242
|
const parsedConfig = {
|
|
239
243
|
...resolvedConfig,
|
|
240
|
-
initialData,
|
|
241
244
|
licenseKey,
|
|
242
245
|
plugins: loadedPlugins,
|
|
243
246
|
language,
|
|
@@ -247,12 +250,11 @@ export class EditorComponentHook extends ClassHook<Snapshot> {
|
|
|
247
250
|
};
|
|
248
251
|
|
|
249
252
|
if (!context || !(sourceElements instanceof HTMLElement)) {
|
|
250
|
-
return Constructor.create(
|
|
253
|
+
return Constructor.create(parsedConfig);
|
|
251
254
|
}
|
|
252
255
|
|
|
253
256
|
const result = await createEditorInContext({
|
|
254
257
|
context,
|
|
255
|
-
element: sourceElements,
|
|
256
258
|
creator: Constructor,
|
|
257
259
|
config: parsedConfig,
|
|
258
260
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './editor-relaxed-constructor.type';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { EditorConfig } from 'ckeditor5';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Assigns initial data to specified editor config.
|
|
5
|
+
*
|
|
6
|
+
* @param dataOrMap Initial data to be assigned to config.
|
|
7
|
+
* @param config Config of the editor.
|
|
8
|
+
* @returns The updated configuration object.
|
|
9
|
+
*/
|
|
10
|
+
export function assignInitialDataToEditorConfig<C extends EditorConfig>(
|
|
11
|
+
dataOrMap: string | Record<string, string>,
|
|
12
|
+
config: C,
|
|
13
|
+
): C {
|
|
14
|
+
const dataMap = toDataMap(dataOrMap);
|
|
15
|
+
const allRootsKeys = new Set([
|
|
16
|
+
...Object.keys(dataMap),
|
|
17
|
+
...Object.keys(config.roots ?? {}),
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
const rootsConfig = Array.from(allRootsKeys).reduce((acc, rootKey) => ({
|
|
21
|
+
...acc,
|
|
22
|
+
[rootKey]: {
|
|
23
|
+
...config.roots?.[rootKey],
|
|
24
|
+
...rootKey === 'main' ? config.root : {},
|
|
25
|
+
|
|
26
|
+
/* v8 ignore start -- @preserve */
|
|
27
|
+
...rootKey in dataMap
|
|
28
|
+
? {
|
|
29
|
+
initialData: dataMap[rootKey],
|
|
30
|
+
}
|
|
31
|
+
: {},
|
|
32
|
+
/* v8 ignore stop -- @preserve */
|
|
33
|
+
},
|
|
34
|
+
}), Object.create(config.roots || {}));
|
|
35
|
+
|
|
36
|
+
const mappedConfig: C = {
|
|
37
|
+
...config,
|
|
38
|
+
roots: rootsConfig,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
delete mappedConfig.root;
|
|
42
|
+
|
|
43
|
+
return mappedConfig;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function toDataMap(element: string | Record<string, string>): Record<string, string> {
|
|
47
|
+
return typeof element === 'string' ? { main: element } : { ...element };
|
|
48
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { EditorConfig } from 'ckeditor5';
|
|
2
|
+
|
|
3
|
+
import type { EditorRelaxedConstructor } from '../types/editor-relaxed-constructor.type';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Assigns a DOM element to the editor configuration in a way that is compatible with the specific editor type.
|
|
7
|
+
*
|
|
8
|
+
* @param Editor Constructor of the editor used to determine the location of element config entry.
|
|
9
|
+
* @param elementOrMap Element to be assigned to config.
|
|
10
|
+
* @param config Config of the editor.
|
|
11
|
+
* @returns The updated configuration object.
|
|
12
|
+
*/
|
|
13
|
+
export function assignSourceElementsToEditorConfig<C extends EditorConfig>(
|
|
14
|
+
Editor: EditorRelaxedConstructor,
|
|
15
|
+
elementOrMap: HTMLElement | Record<string, HTMLElement>,
|
|
16
|
+
config: C,
|
|
17
|
+
): C {
|
|
18
|
+
const elementsMap = toElementsMap(elementOrMap);
|
|
19
|
+
|
|
20
|
+
if (!Editor.editorName || Editor.editorName === 'ClassicEditor') {
|
|
21
|
+
return {
|
|
22
|
+
...config,
|
|
23
|
+
attachTo: elementsMap['main'],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const allRootsKeys = new Set([
|
|
28
|
+
...Object.keys(elementsMap),
|
|
29
|
+
...Object.keys(config.roots ?? {}),
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
const rootsConfig = Array.from(allRootsKeys).reduce((acc, rootKey) => ({
|
|
33
|
+
...acc,
|
|
34
|
+
[rootKey]: {
|
|
35
|
+
/* v8 ignore next */
|
|
36
|
+
...config.roots?.[rootKey],
|
|
37
|
+
...rootKey === 'main' ? config.root : {},
|
|
38
|
+
|
|
39
|
+
/* v8 ignore start -- @preserve */
|
|
40
|
+
...rootKey in elementsMap
|
|
41
|
+
? {
|
|
42
|
+
element: elementsMap[rootKey],
|
|
43
|
+
}
|
|
44
|
+
: {},
|
|
45
|
+
/* v8 ignore stop -- @preserve */
|
|
46
|
+
},
|
|
47
|
+
}), Object.create(config.roots || {}));
|
|
48
|
+
|
|
49
|
+
const mappedConfig: C = {
|
|
50
|
+
...config,
|
|
51
|
+
roots: rootsConfig,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
delete mappedConfig.root;
|
|
55
|
+
|
|
56
|
+
return mappedConfig;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function toElementsMap(element: HTMLElement | Record<string, HTMLElement>): Record<string, HTMLElement> {
|
|
60
|
+
return element instanceof HTMLElement ? { main: element } : { ...element };
|
|
61
|
+
}
|
|
@@ -12,19 +12,17 @@ const CONTEXT_EDITOR_WATCHDOG_SYMBOL = Symbol.for('context-editor-watchdog');
|
|
|
12
12
|
* Creates a CKEditor 5 editor instance within a given context watchdog.
|
|
13
13
|
*
|
|
14
14
|
* @param params Parameters for editor creation.
|
|
15
|
-
* @param params.element The DOM element or data for the editor.
|
|
16
15
|
* @param params.context The context watchdog instance.
|
|
17
16
|
* @param params.creator The editor creator utility.
|
|
18
17
|
* @param params.config The editor configuration object.
|
|
19
18
|
* @returns The created editor instance.
|
|
20
19
|
*/
|
|
21
|
-
export async function createEditorInContext({
|
|
20
|
+
export async function createEditorInContext({ context, creator, config }: Attrs) {
|
|
22
21
|
const editorContextId = uid();
|
|
23
22
|
|
|
24
23
|
await context.add({
|
|
25
|
-
creator:
|
|
24
|
+
creator: creator.create.bind(creator),
|
|
26
25
|
id: editorContextId,
|
|
27
|
-
sourceElementOrData: element,
|
|
28
26
|
type: 'editor',
|
|
29
27
|
config,
|
|
30
28
|
});
|
|
@@ -80,7 +78,6 @@ type EditorCreator = {
|
|
|
80
78
|
type Attrs = {
|
|
81
79
|
context: ContextWatchdog<Context>;
|
|
82
80
|
creator: EditorCreator;
|
|
83
|
-
element: HTMLElement;
|
|
84
81
|
config: EditorConfig;
|
|
85
82
|
};
|
|
86
83
|
|