ckeditor5-blazor 1.11.0 → 1.11.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/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 +23 -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 +300 -348
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/elements/editor/editor.ts +39 -64
- package/src/elements/editor/utils/assign-editor-roots-to-config.ts +60 -0
- package/src/elements/editor/utils/index.ts +2 -3
- package/src/elements/editor/utils/query-all-editor-editables.ts +74 -0
- 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
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { WaitForInteractiveResult } from '../../shared';
|
|
2
2
|
import type { EditorId, EditorLanguage, EditorPreset } from './typings';
|
|
3
|
+
import type { EditableItem } from './utils';
|
|
3
4
|
|
|
4
5
|
import {
|
|
5
6
|
isEmptyObject,
|
|
@@ -14,8 +15,7 @@ import {
|
|
|
14
15
|
createSyncEditorWithInputPlugin,
|
|
15
16
|
} from './plugins';
|
|
16
17
|
import {
|
|
17
|
-
|
|
18
|
-
assignSourceElementsToEditorConfig,
|
|
18
|
+
assignEditorRootsToConfig,
|
|
19
19
|
cleanupOrphanEditorElements,
|
|
20
20
|
createEditorInContext,
|
|
21
21
|
isSingleRootEditor,
|
|
@@ -24,8 +24,7 @@ import {
|
|
|
24
24
|
loadEditorPlugins,
|
|
25
25
|
normalizeCustomTranslations,
|
|
26
26
|
normalizeEditorLanguage,
|
|
27
|
-
|
|
28
|
-
queryEditablesSnapshotContent,
|
|
27
|
+
queryAllEditorEditables,
|
|
29
28
|
resolveEditorConfigElementReferences,
|
|
30
29
|
resolveEditorConfigTranslations,
|
|
31
30
|
setEditorEditableHeight,
|
|
@@ -158,7 +157,6 @@ export class EditorComponentElement extends HTMLElement {
|
|
|
158
157
|
const editableHeight = this.getAttribute('data-cke-editable-height') ? Number.parseInt(this.getAttribute('data-cke-editable-height')!, 10) : null;
|
|
159
158
|
const saveDebounceMs = Number.parseInt(this.getAttribute('data-cke-save-debounce-ms')!, 10);
|
|
160
159
|
const useWatchdog = this.hasAttribute('data-cke-watchdog');
|
|
161
|
-
const content = JSON.parse(this.getAttribute('data-cke-content')!) as Record<string, string>;
|
|
162
160
|
const language = (
|
|
163
161
|
this.getAttribute('data-cke-language')
|
|
164
162
|
? JSON.parse(this.getAttribute('data-cke-language')!)
|
|
@@ -200,59 +198,36 @@ export class EditorComponentElement extends HTMLElement {
|
|
|
200
198
|
]
|
|
201
199
|
.filter(translations => !isEmptyObject(translations));
|
|
202
200
|
|
|
203
|
-
//
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
201
|
+
// Query all editable elements along with their content in one pass.
|
|
202
|
+
// Roots present in the editor container's data-cke-content but not yet in the DOM
|
|
203
|
+
// are included with element: null so we know which roots to wait for.
|
|
204
|
+
let editables = queryAllEditorEditables(editorId);
|
|
205
|
+
const requiredRoots = Object.keys(editables);
|
|
208
206
|
|
|
209
207
|
if (isSingleRootEditor(editorType)) {
|
|
210
|
-
|
|
208
|
+
requiredRoots.push('main');
|
|
211
209
|
}
|
|
212
210
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
// Handle special case when user specified `initialData` of several root elements, but editable components
|
|
218
|
-
// are not yet present in the DOM. In other words - editor is initialized before attaching root elements.
|
|
219
|
-
if (!sourceElements['main']) {
|
|
220
|
-
const requiredRoots = (
|
|
221
|
-
isSingleRootEditor(editorType)
|
|
222
|
-
? ['main']
|
|
223
|
-
: Object.keys(initialData as Record<string, string>)
|
|
224
|
-
);
|
|
225
|
-
|
|
226
|
-
if (!checkIfAllRootsArePresent(sourceElements, requiredRoots)) {
|
|
227
|
-
sourceElements = await waitForAllRootsToBePresent(editorId, requiredRoots);
|
|
228
|
-
initialData = {
|
|
229
|
-
...content,
|
|
230
|
-
...queryEditablesSnapshotContent(editorId),
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// If single root editor, unwrap the element from the object.
|
|
236
|
-
if (isSingleRootEditor(editorType) && 'main' in sourceElements) {
|
|
237
|
-
sourceElements = sourceElements['main'];
|
|
238
|
-
}
|
|
211
|
+
if (!checkIfAllRootsArePresent(editables, requiredRoots)) {
|
|
212
|
+
editables = await waitForAllRootsToBePresent(editorId, requiredRoots);
|
|
213
|
+
}
|
|
239
214
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
215
|
+
// Do some postprocessing on received configuration.
|
|
216
|
+
let resolvedConfig = {
|
|
217
|
+
...config,
|
|
218
|
+
licenseKey,
|
|
219
|
+
plugins: loadedPlugins,
|
|
220
|
+
language,
|
|
221
|
+
...mixedTranslations.length && {
|
|
222
|
+
translations: mixedTranslations,
|
|
223
|
+
},
|
|
224
|
+
};
|
|
250
225
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
resolvedConfig = assignInitialDataToEditorConfig(initialData, resolvedConfig);
|
|
226
|
+
resolvedConfig = resolveEditorConfigElementReferences(resolvedConfig);
|
|
227
|
+
resolvedConfig = resolveEditorConfigTranslations([...mixedTranslations].reverse(), language.ui, resolvedConfig);
|
|
228
|
+
resolvedConfig = assignEditorRootsToConfig(Constructor, editables, resolvedConfig);
|
|
255
229
|
|
|
230
|
+
const editor = await (async () => {
|
|
256
231
|
if (!context) {
|
|
257
232
|
return Constructor.create(resolvedConfig);
|
|
258
233
|
}
|
|
@@ -313,42 +288,42 @@ export class EditorComponentElement extends HTMLElement {
|
|
|
313
288
|
}
|
|
314
289
|
|
|
315
290
|
/**
|
|
316
|
-
* Checks if all required root elements are present in the
|
|
291
|
+
* Checks if all required root elements are present (i.e. have a non-null element) in the editables map.
|
|
317
292
|
*
|
|
318
|
-
* @param
|
|
319
|
-
* @param requiredRoots The list of required root
|
|
320
|
-
* @returns True if all required roots
|
|
293
|
+
* @param editables The editables map keyed by root name.
|
|
294
|
+
* @param requiredRoots The list of required root names.
|
|
295
|
+
* @returns True if all required roots have a DOM element attached, false otherwise.
|
|
321
296
|
*/
|
|
322
|
-
function checkIfAllRootsArePresent(
|
|
323
|
-
return requiredRoots.every(rootId =>
|
|
297
|
+
function checkIfAllRootsArePresent(editables: Record<string, EditableItem>, requiredRoots: string[]): boolean {
|
|
298
|
+
return requiredRoots.every(rootId => editables[rootId]?.element);
|
|
324
299
|
}
|
|
325
300
|
|
|
326
301
|
/**
|
|
327
302
|
* Waits for all required root elements to be present in the DOM.
|
|
328
303
|
*
|
|
329
304
|
* @param editorId The editor's ID.
|
|
330
|
-
* @param requiredRoots The list of required root
|
|
331
|
-
* @returns A promise that resolves to the
|
|
305
|
+
* @param requiredRoots The list of required root names.
|
|
306
|
+
* @returns A promise that resolves to the updated editables map once all elements are attached.
|
|
332
307
|
*/
|
|
333
308
|
async function waitForAllRootsToBePresent(
|
|
334
309
|
editorId: EditorId,
|
|
335
310
|
requiredRoots: string[],
|
|
336
|
-
): Promise<Record<string,
|
|
311
|
+
): Promise<Record<string, EditableItem>> {
|
|
337
312
|
return waitFor(
|
|
338
313
|
() => {
|
|
339
|
-
const
|
|
314
|
+
const editables = queryAllEditorEditables(editorId);
|
|
340
315
|
|
|
341
|
-
if (!checkIfAllRootsArePresent(
|
|
316
|
+
if (!checkIfAllRootsArePresent(editables, requiredRoots)) {
|
|
342
317
|
throw new Error(
|
|
343
318
|
'It looks like not all required root elements are present yet.\n'
|
|
344
319
|
+ '* If you want to wait for them, ensure they are registered before editor initialization.\n'
|
|
345
320
|
+ '* If you want lazy initialize roots, consider removing root values from the `initialData` config '
|
|
346
321
|
+ 'and assign initial data in editable components.\n'
|
|
347
|
-
+ `Missing roots: ${requiredRoots.filter(rootId => !
|
|
322
|
+
+ `Missing roots: ${requiredRoots.filter(rootId => !editables[rootId]?.element).join(', ')}.`,
|
|
348
323
|
);
|
|
349
324
|
}
|
|
350
325
|
|
|
351
|
-
return
|
|
326
|
+
return editables;
|
|
352
327
|
},
|
|
353
328
|
{ timeOutAfter: 2000, retryAfter: 100 },
|
|
354
329
|
);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { EditorRelaxedConstructor } from '../types/editor-relaxed-constructor.type';
|
|
2
|
+
import type { EditableItem } from './query-all-editor-editables';
|
|
3
|
+
import type { EditorConfig } from 'ckeditor5';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Assigns DOM elements and initial data to the editor configuration in a way that is compatible
|
|
7
|
+
* with the specific editor type.
|
|
8
|
+
*
|
|
9
|
+
* Roots with `element: null` (pending roots not yet in the DOM) contribute only `initialData`
|
|
10
|
+
* and are skipped for element assignment.
|
|
11
|
+
*
|
|
12
|
+
* @param Editor Constructor of the editor used to determine the location of element config entry.
|
|
13
|
+
* @param editables Map of editable items (element + content) keyed by root name.
|
|
14
|
+
* @param config Config of the editor.
|
|
15
|
+
* @returns The updated configuration object.
|
|
16
|
+
*/
|
|
17
|
+
export function assignEditorRootsToConfig<C extends EditorConfig>(
|
|
18
|
+
Editor: EditorRelaxedConstructor,
|
|
19
|
+
editables: Record<string, EditableItem>,
|
|
20
|
+
config: C,
|
|
21
|
+
): C {
|
|
22
|
+
const isClassicEditor = !Editor.editorName || Editor.editorName === 'ClassicEditor';
|
|
23
|
+
const allRootsKeys = new Set([
|
|
24
|
+
...Object.keys(editables),
|
|
25
|
+
...Object.keys(config.roots ?? {}),
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
const rootsConfig = Array.from(allRootsKeys).reduce((acc, rootKey) => ({
|
|
29
|
+
...acc,
|
|
30
|
+
[rootKey]: {
|
|
31
|
+
/* v8 ignore next 1 */
|
|
32
|
+
...config.roots?.[rootKey],
|
|
33
|
+
...rootKey === 'main' ? config.root : {},
|
|
34
|
+
|
|
35
|
+
/* v8 ignore next 11 */
|
|
36
|
+
...rootKey in editables
|
|
37
|
+
? {
|
|
38
|
+
...editables[rootKey]!.content !== null && {
|
|
39
|
+
initialData: editables[rootKey]!.content,
|
|
40
|
+
},
|
|
41
|
+
...!isClassicEditor && editables[rootKey]!.element !== null && {
|
|
42
|
+
element: editables[rootKey]!.element,
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
: {},
|
|
46
|
+
},
|
|
47
|
+
}), Object.create(config.roots || {}));
|
|
48
|
+
|
|
49
|
+
const mappedConfig: C = {
|
|
50
|
+
...config,
|
|
51
|
+
roots: rootsConfig,
|
|
52
|
+
...isClassicEditor && editables['main']?.element && {
|
|
53
|
+
attachTo: editables['main'].element,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
delete mappedConfig.root;
|
|
58
|
+
|
|
59
|
+
return mappedConfig;
|
|
60
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export * from './assign-
|
|
2
|
-
export * from './assign-source-elements-to-editor-config';
|
|
1
|
+
export * from './assign-editor-roots-to-config';
|
|
3
2
|
export * from './cleanup-orphan-editor-elements';
|
|
4
3
|
export * from './create-editor-in-context';
|
|
5
4
|
export * from './get-editor-roots-values';
|
|
@@ -9,8 +8,8 @@ export * from './load-editor-plugins';
|
|
|
9
8
|
export * from './load-editor-translations';
|
|
10
9
|
export * from './normalize-custom-translations';
|
|
11
10
|
export * from './normalize-editor-language';
|
|
11
|
+
export * from './query-all-editor-editables';
|
|
12
12
|
export * from './query-all-editor-ids';
|
|
13
|
-
export * from './query-editor-editables';
|
|
14
13
|
export * from './resolve-editor-config-elements-references';
|
|
15
14
|
export * from './resolve-editor-config-translations';
|
|
16
15
|
export * from './set-editor-editable-height';
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { EditorId } from '../typings';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Queries all editable elements within a specific editor instance. It picks
|
|
5
|
+
* initial values from actually rendered elements or from the editor container's
|
|
6
|
+
* `data-cke-content` attribute, whichever is available.
|
|
7
|
+
*
|
|
8
|
+
* Roots present in the editor container's content but without a matching
|
|
9
|
+
* `cke5-editable` element yet are included with `element: null` — these are
|
|
10
|
+
* "pending" roots that haven't been attached to the DOM yet.
|
|
11
|
+
*
|
|
12
|
+
* @param editorId The ID of the editor to query.
|
|
13
|
+
* @returns An object mapping root names to their corresponding elements and content.
|
|
14
|
+
*/
|
|
15
|
+
export function queryAllEditorEditables(editorId: EditorId): Record<string, EditableItem> {
|
|
16
|
+
const acc = Array
|
|
17
|
+
.from(document.querySelectorAll<HTMLElement>(`cke5-editable[data-cke-editor-id="${editorId}"]`))
|
|
18
|
+
.reduce<Record<string, EditableItem>>((acc, element) => {
|
|
19
|
+
const rootName = element.getAttribute('data-cke-root-name')!;
|
|
20
|
+
|
|
21
|
+
acc[rootName] = {
|
|
22
|
+
element: element.querySelector<HTMLElement>('[data-cke-editable-content]'),
|
|
23
|
+
content: element.getAttribute('data-cke-content'),
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return acc;
|
|
27
|
+
}, Object.create({}));
|
|
28
|
+
|
|
29
|
+
const rootEditorElement = document.querySelector<HTMLElement>(`cke5-editor[data-cke-editor-id="${editorId}"]`);
|
|
30
|
+
|
|
31
|
+
/* v8 ignore next -- @preserve */
|
|
32
|
+
if (!rootEditorElement) {
|
|
33
|
+
return acc;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// v8 ignore next -- @preserve
|
|
37
|
+
const editorContent: Record<string, string> = JSON.parse(rootEditorElement.getAttribute('data-cke-content')!) ?? {};
|
|
38
|
+
const classicMainElement = document.querySelector<HTMLElement>(`#${editorId}_editor`);
|
|
39
|
+
|
|
40
|
+
if (classicMainElement && !acc['main']) {
|
|
41
|
+
acc['main'] = {
|
|
42
|
+
element: classicMainElement,
|
|
43
|
+
content: editorContent['main'] || '',
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
for (const [rootName, rootContent] of Object.entries(editorContent)) {
|
|
48
|
+
if (acc[rootName]) {
|
|
49
|
+
// Editable element is already present — fill content from editor level if the editable didn't provide its own.
|
|
50
|
+
acc[rootName] = {
|
|
51
|
+
...acc[rootName],
|
|
52
|
+
content: acc[rootName].content ?? rootContent,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
// Root has server-provided content but its editable element hasn't been attached to the DOM yet.
|
|
57
|
+
acc[rootName] = {
|
|
58
|
+
element: null,
|
|
59
|
+
content: rootContent,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return acc;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Type representing an editable item within an editor.
|
|
69
|
+
* `element` is null when the root's DOM element hasn't appeared yet (pending root).
|
|
70
|
+
*/
|
|
71
|
+
export type EditableItem = {
|
|
72
|
+
element: HTMLElement | null;
|
|
73
|
+
content: string | null;
|
|
74
|
+
};
|
|
@@ -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
|
-
};
|