ckeditor5-blazor 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/elements/editable.d.ts.map +1 -1
- package/dist/elements/editor/editor.d.ts.map +1 -1
- package/dist/elements/editor/utils/assign-editor-roots-to-config.d.ts +17 -0
- package/dist/elements/editor/utils/assign-editor-roots-to-config.d.ts.map +1 -0
- package/dist/elements/editor/utils/index.d.ts +2 -3
- package/dist/elements/editor/utils/index.d.ts.map +1 -1
- package/dist/elements/editor/utils/query-all-editor-editables.d.ts +24 -0
- package/dist/elements/editor/utils/query-all-editor-editables.d.ts.map +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +395 -437
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/elements/editable.test.ts +42 -3
- package/src/elements/editable.ts +2 -0
- package/src/elements/editor/editor.test.ts +97 -13
- package/src/elements/editor/editor.ts +39 -64
- package/src/elements/editor/utils/assign-editor-roots-to-config.ts +61 -0
- package/src/elements/editor/utils/get-editor-roots-values.ts +1 -1
- package/src/elements/editor/utils/index.ts +2 -3
- package/src/elements/editor/utils/query-all-editor-editables.ts +81 -0
- package/src/elements/ui-part.test.ts +8 -9
- package/src/interop/create-editable-blazor-interop.test.ts +5 -2
- package/dist/elements/editor/utils/assign-initial-data-to-editor-config.d.ts +0 -10
- package/dist/elements/editor/utils/assign-initial-data-to-editor-config.d.ts.map +0 -1
- package/dist/elements/editor/utils/assign-source-elements-to-editor-config.d.ts +0 -12
- package/dist/elements/editor/utils/assign-source-elements-to-editor-config.d.ts.map +0 -1
- package/dist/elements/editor/utils/query-editor-editables.d.ts +0 -25
- package/dist/elements/editor/utils/query-editor-editables.d.ts.map +0 -1
- package/src/elements/editor/utils/assign-initial-data-to-editor-config.ts +0 -47
- package/src/elements/editor/utils/assign-source-elements-to-editor-config.ts +0 -59
- package/src/elements/editor/utils/query-editor-editables.ts +0 -101
|
@@ -2,7 +2,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
createEditorPreset,
|
|
5
|
-
createUIPartSnapshot,
|
|
6
5
|
renderTestEditor,
|
|
7
6
|
renderTestUIPart,
|
|
8
7
|
waitForDestroyAllEditors,
|
|
@@ -34,7 +33,7 @@ describe('ui-part component', () => {
|
|
|
34
33
|
const editor = await waitForTestEditor();
|
|
35
34
|
const toolbarElement = editor.ui.view.toolbar?.element;
|
|
36
35
|
|
|
37
|
-
const el = renderTestUIPart(
|
|
36
|
+
const el = renderTestUIPart();
|
|
38
37
|
|
|
39
38
|
await vi.waitFor(() => {
|
|
40
39
|
expect(el.contains(toolbarElement!)).toBe(true);
|
|
@@ -49,7 +48,7 @@ describe('ui-part component', () => {
|
|
|
49
48
|
const editor = await waitForTestEditor();
|
|
50
49
|
const menubarElement = (editor.ui.view as any).menuBarView.element;
|
|
51
50
|
|
|
52
|
-
const el = renderTestUIPart(
|
|
51
|
+
const el = renderTestUIPart({ name: 'menubar' });
|
|
53
52
|
|
|
54
53
|
await vi.waitFor(() => {
|
|
55
54
|
expect(el.children.length).toBeGreaterThan(0);
|
|
@@ -59,7 +58,7 @@ describe('ui-part component', () => {
|
|
|
59
58
|
});
|
|
60
59
|
|
|
61
60
|
it('should mount UI part before editor is created', async () => {
|
|
62
|
-
const el = renderTestUIPart(
|
|
61
|
+
const el = renderTestUIPart();
|
|
63
62
|
|
|
64
63
|
appendMultirootEditor();
|
|
65
64
|
|
|
@@ -80,7 +79,7 @@ describe('ui-part component', () => {
|
|
|
80
79
|
const toolbarElement = editor.ui.view.toolbar?.element;
|
|
81
80
|
|
|
82
81
|
// Render UI part without editorId
|
|
83
|
-
const el = renderTestUIPart({ editorId:
|
|
82
|
+
const el = renderTestUIPart({ editorId: null });
|
|
84
83
|
|
|
85
84
|
await vi.waitFor(() => {
|
|
86
85
|
expect(el.contains(toolbarElement!)).toBe(true);
|
|
@@ -90,7 +89,7 @@ describe('ui-part component', () => {
|
|
|
90
89
|
});
|
|
91
90
|
|
|
92
91
|
it('should not mount UI part if element is disconnected before editor is ready', async () => {
|
|
93
|
-
const el = renderTestUIPart(
|
|
92
|
+
const el = renderTestUIPart();
|
|
94
93
|
el.remove();
|
|
95
94
|
|
|
96
95
|
appendMultirootEditor();
|
|
@@ -109,7 +108,7 @@ describe('ui-part component', () => {
|
|
|
109
108
|
});
|
|
110
109
|
|
|
111
110
|
it('should clear UI part element on destruction', async () => {
|
|
112
|
-
const el = renderTestUIPart(
|
|
111
|
+
const el = renderTestUIPart();
|
|
113
112
|
|
|
114
113
|
await vi.waitFor(() => {
|
|
115
114
|
expect(el.children.length).toBeGreaterThan(0);
|
|
@@ -125,7 +124,7 @@ describe('ui-part component', () => {
|
|
|
125
124
|
});
|
|
126
125
|
|
|
127
126
|
it('should hide element during destruction', async () => {
|
|
128
|
-
const el = renderTestUIPart(
|
|
127
|
+
const el = renderTestUIPart();
|
|
129
128
|
|
|
130
129
|
// If we remove immediately, disconnectedCallback should hide it.
|
|
131
130
|
el.remove();
|
|
@@ -138,7 +137,7 @@ describe('ui-part component', () => {
|
|
|
138
137
|
document.body.innerHTML = '';
|
|
139
138
|
await EditorsRegistry.the.reset();
|
|
140
139
|
|
|
141
|
-
const el = renderTestUIPart(
|
|
140
|
+
const el = renderTestUIPart();
|
|
142
141
|
|
|
143
142
|
el.remove();
|
|
144
143
|
|
|
@@ -28,7 +28,7 @@ describe('createEditableBlazorInterop', () => {
|
|
|
28
28
|
dotnetInterop = createDotNetInteropMock();
|
|
29
29
|
globalThis.DotNet = createDotnet();
|
|
30
30
|
|
|
31
|
-
element = renderTestEditable({
|
|
31
|
+
element = renderTestEditable({
|
|
32
32
|
interactive: false,
|
|
33
33
|
});
|
|
34
34
|
|
|
@@ -120,7 +120,10 @@ describe('createEditableBlazorInterop', () => {
|
|
|
120
120
|
});
|
|
121
121
|
|
|
122
122
|
it('should ignore events for an unknown root name', async () => {
|
|
123
|
-
const custom = renderTestEditable({
|
|
123
|
+
const custom = renderTestEditable({
|
|
124
|
+
rootName: 'other',
|
|
125
|
+
interactive: false,
|
|
126
|
+
});
|
|
124
127
|
|
|
125
128
|
const interop = createEditableBlazorInterop(custom, dotnetInterop);
|
|
126
129
|
const editor = await waitForTestEditor();
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { EditorConfig } from 'ckeditor5';
|
|
2
|
-
/**
|
|
3
|
-
* Assigns initial data to specified editor config.
|
|
4
|
-
*
|
|
5
|
-
* @param dataOrMap Initial data to be assigned to config.
|
|
6
|
-
* @param config Config of the editor.
|
|
7
|
-
* @returns The updated configuration object.
|
|
8
|
-
*/
|
|
9
|
-
export declare function assignInitialDataToEditorConfig<C extends EditorConfig>(dataOrMap: string | Record<string, string>, config: C): C;
|
|
10
|
-
//# sourceMappingURL=assign-initial-data-to-editor-config.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"assign-initial-data-to-editor-config.d.ts","sourceRoot":"","sources":["../../../../../src/elements/editor/utils/assign-initial-data-to-editor-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAAC,CAAC,SAAS,YAAY,EACpE,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC1C,MAAM,EAAE,CAAC,GACR,CAAC,CA8BH"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { EditorRelaxedConstructor } from '../types/editor-relaxed-constructor.type';
|
|
2
|
-
import { EditorConfig } from 'ckeditor5';
|
|
3
|
-
/**
|
|
4
|
-
* Assigns a DOM element to the editor configuration in a way that is compatible with the specific editor type.
|
|
5
|
-
*
|
|
6
|
-
* @param Editor Constructor of the editor used to determine the location of element config entry.
|
|
7
|
-
* @param elementOrMap Element to be assigned to config.
|
|
8
|
-
* @param config Config of the editor.
|
|
9
|
-
* @returns The updated configuration object.
|
|
10
|
-
*/
|
|
11
|
-
export declare function assignSourceElementsToEditorConfig<C extends EditorConfig>(Editor: EditorRelaxedConstructor, elementOrMap: HTMLElement | Record<string, HTMLElement>, config: C): C;
|
|
12
|
-
//# sourceMappingURL=assign-source-elements-to-editor-config.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"assign-source-elements-to-editor-config.d.ts","sourceRoot":"","sources":["../../../../../src/elements/editor/utils/assign-source-elements-to-editor-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C;;;;;;;GAOG;AACH,wBAAgB,kCAAkC,CAAC,CAAC,SAAS,YAAY,EACvE,MAAM,EAAE,wBAAwB,EAChC,YAAY,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACvD,MAAM,EAAE,CAAC,GACR,CAAC,CAuCH"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { EditorId } from '../typings';
|
|
2
|
-
/**
|
|
3
|
-
* Gets the initial root elements for the editor based on its type.
|
|
4
|
-
*
|
|
5
|
-
* @param editorId The editor's ID.
|
|
6
|
-
* @returns The root element(s) for the editor.
|
|
7
|
-
*/
|
|
8
|
-
export declare function queryEditablesElements(editorId: EditorId): Record<string, HTMLElement>;
|
|
9
|
-
/**
|
|
10
|
-
* Gets the initial data for the roots of the editor. If the editor is a single editing-like editor,
|
|
11
|
-
* it retrieves the initial value from the element's attribute. Otherwise, it returns an object mapping
|
|
12
|
-
* editable names to their initial values.
|
|
13
|
-
*
|
|
14
|
-
* @param editorId The editor's ID.
|
|
15
|
-
* @returns The initial values for the editor's roots.
|
|
16
|
-
*/
|
|
17
|
-
export declare function queryEditablesSnapshotContent(editorId: EditorId): Record<string, string>;
|
|
18
|
-
/**
|
|
19
|
-
* Type representing an editable item within an editor.
|
|
20
|
-
*/
|
|
21
|
-
export type EditableItem = {
|
|
22
|
-
element: HTMLElement;
|
|
23
|
-
content: string | null;
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=query-editor-editables.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"query-editor-editables.d.ts","sourceRoot":"","sources":["../../../../../src/elements/editor/utils/query-editor-editables.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAI3C;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,+BAIxD;AAED;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,QAAQ,GAIW,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAChG;AAiED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,CAAC"}
|
|
@@ -1,47 +0,0 @@
|
|
|
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 next 5 */
|
|
27
|
-
...rootKey in dataMap
|
|
28
|
-
? {
|
|
29
|
-
initialData: dataMap[rootKey],
|
|
30
|
-
}
|
|
31
|
-
: {},
|
|
32
|
-
},
|
|
33
|
-
}), Object.create(config.roots || {}));
|
|
34
|
-
|
|
35
|
-
const mappedConfig: C = {
|
|
36
|
-
...config,
|
|
37
|
-
roots: rootsConfig,
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
delete mappedConfig.root;
|
|
41
|
-
|
|
42
|
-
return mappedConfig;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function toDataMap(element: string | Record<string, string>): Record<string, string> {
|
|
46
|
-
return typeof element === 'string' ? { main: element } : { ...element };
|
|
47
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import type { EditorRelaxedConstructor } from '../types/editor-relaxed-constructor.type';
|
|
2
|
-
import type { EditorConfig } from 'ckeditor5';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Assigns a DOM element to the editor configuration in a way that is compatible with the specific editor type.
|
|
6
|
-
*
|
|
7
|
-
* @param Editor Constructor of the editor used to determine the location of element config entry.
|
|
8
|
-
* @param elementOrMap Element to be assigned to config.
|
|
9
|
-
* @param config Config of the editor.
|
|
10
|
-
* @returns The updated configuration object.
|
|
11
|
-
*/
|
|
12
|
-
export function assignSourceElementsToEditorConfig<C extends EditorConfig>(
|
|
13
|
-
Editor: EditorRelaxedConstructor,
|
|
14
|
-
elementOrMap: HTMLElement | Record<string, HTMLElement>,
|
|
15
|
-
config: C,
|
|
16
|
-
): C {
|
|
17
|
-
const elementsMap = toElementsMap(elementOrMap);
|
|
18
|
-
|
|
19
|
-
if (!Editor.editorName || Editor.editorName === 'ClassicEditor') {
|
|
20
|
-
return {
|
|
21
|
-
...config,
|
|
22
|
-
attachTo: elementsMap['main'],
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const allRootsKeys = new Set([
|
|
27
|
-
...Object.keys(elementsMap),
|
|
28
|
-
...Object.keys(config.roots ?? {}),
|
|
29
|
-
]);
|
|
30
|
-
|
|
31
|
-
const rootsConfig = Array.from(allRootsKeys).reduce((acc, rootKey) => ({
|
|
32
|
-
...acc,
|
|
33
|
-
[rootKey]: {
|
|
34
|
-
/* v8 ignore next */
|
|
35
|
-
...config.roots?.[rootKey],
|
|
36
|
-
...rootKey === 'main' ? config.root : {},
|
|
37
|
-
|
|
38
|
-
/* v8 ignore next 5 */
|
|
39
|
-
...rootKey in elementsMap
|
|
40
|
-
? {
|
|
41
|
-
element: elementsMap[rootKey],
|
|
42
|
-
}
|
|
43
|
-
: {},
|
|
44
|
-
},
|
|
45
|
-
}), Object.create(config.roots || {}));
|
|
46
|
-
|
|
47
|
-
const mappedConfig: C = {
|
|
48
|
-
...config,
|
|
49
|
-
roots: rootsConfig,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
delete mappedConfig.root;
|
|
53
|
-
|
|
54
|
-
return mappedConfig;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function toElementsMap(element: HTMLElement | Record<string, HTMLElement>): Record<string, HTMLElement> {
|
|
58
|
-
return element instanceof HTMLElement ? { main: element } : { ...element };
|
|
59
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import type { EditorId } from '../typings';
|
|
2
|
-
|
|
3
|
-
import { filterObjectValues, mapObjectValues } from '../../../shared';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Gets the initial root elements for the editor based on its type.
|
|
7
|
-
*
|
|
8
|
-
* @param editorId The editor's ID.
|
|
9
|
-
* @returns The root element(s) for the editor.
|
|
10
|
-
*/
|
|
11
|
-
export function queryEditablesElements(editorId: EditorId) {
|
|
12
|
-
const editables = queryAllEditorEditables(editorId);
|
|
13
|
-
|
|
14
|
-
return mapObjectValues(editables, ({ element }) => element);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Gets the initial data for the roots of the editor. If the editor is a single editing-like editor,
|
|
19
|
-
* it retrieves the initial value from the element's attribute. Otherwise, it returns an object mapping
|
|
20
|
-
* editable names to their initial values.
|
|
21
|
-
*
|
|
22
|
-
* @param editorId The editor's ID.
|
|
23
|
-
* @returns The initial values for the editor's roots.
|
|
24
|
-
*/
|
|
25
|
-
export function queryEditablesSnapshotContent(editorId: EditorId) {
|
|
26
|
-
const editables = queryAllEditorEditables(editorId);
|
|
27
|
-
const values = mapObjectValues(editables, ({ content }) => content);
|
|
28
|
-
|
|
29
|
-
return filterObjectValues(values, value => typeof value === 'string') as Record<string, string>;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Queries all editable elements within a specific editor instance. It picks
|
|
34
|
-
* initial values from actually rendered elements or from the editor container's.
|
|
35
|
-
*
|
|
36
|
-
* It may differ from the `initialData` used during editor creation, as it might
|
|
37
|
-
* not set all roots or set different values.
|
|
38
|
-
*
|
|
39
|
-
* @param editorId The ID of the editor to query.
|
|
40
|
-
* @returns An object mapping editable names to their corresponding elements and initial values.
|
|
41
|
-
*/
|
|
42
|
-
function queryAllEditorEditables(editorId: EditorId) {
|
|
43
|
-
const acc = (
|
|
44
|
-
Array
|
|
45
|
-
.from(document.querySelectorAll<HTMLElement>(`cke5-editable[data-cke-editor-id="${editorId}"]`))
|
|
46
|
-
.reduce<Record<string, EditableItem>>((acc, element) => {
|
|
47
|
-
const rootName = element.getAttribute('data-cke-root-name')!;
|
|
48
|
-
const content = element.getAttribute('data-cke-content');
|
|
49
|
-
|
|
50
|
-
acc[rootName] = {
|
|
51
|
-
element: element.querySelector<HTMLElement>('[data-cke-editable-content]')!,
|
|
52
|
-
content,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
return acc;
|
|
56
|
-
}, Object.create({}))
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
const editor = document.querySelector<HTMLElement>(`cke5-editor[data-cke-editor-id="${editorId}"]`);
|
|
60
|
-
|
|
61
|
-
/* v8 ignore next -- @preserve */
|
|
62
|
-
if (!editor) {
|
|
63
|
-
return acc;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const currentMain = acc['main'];
|
|
67
|
-
const initialRootEditableValue = JSON.parse(editor.getAttribute('data-cke-content')!);
|
|
68
|
-
const contentElement = document.querySelector<HTMLElement>(`#${editorId}_editor `);
|
|
69
|
-
|
|
70
|
-
// If found `main` editable, but it has no content, try to fill it from the editor container.
|
|
71
|
-
if (currentMain && initialRootEditableValue?.['main']) {
|
|
72
|
-
return {
|
|
73
|
-
...acc,
|
|
74
|
-
main: {
|
|
75
|
-
...currentMain,
|
|
76
|
-
content: currentMain.content || initialRootEditableValue['main'],
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// If no `main` editable found, try to create it from the editor container.
|
|
82
|
-
if (contentElement) {
|
|
83
|
-
return {
|
|
84
|
-
...acc,
|
|
85
|
-
main: {
|
|
86
|
-
element: contentElement,
|
|
87
|
-
content: initialRootEditableValue?.['main'] || null,
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return acc;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Type representing an editable item within an editor.
|
|
97
|
-
*/
|
|
98
|
-
export type EditableItem = {
|
|
99
|
-
element: HTMLElement;
|
|
100
|
-
content: string | null;
|
|
101
|
-
};
|