ckeditor5-blazor 1.10.3 → 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.
Files changed (36) hide show
  1. package/dist/elements/context/context.d.ts.map +1 -1
  2. package/dist/elements/editor/editor.d.ts.map +1 -1
  3. package/dist/elements/editor/types/editor-relaxed-constructor.type.d.ts +6 -0
  4. package/dist/elements/editor/types/editor-relaxed-constructor.type.d.ts.map +1 -0
  5. package/dist/elements/editor/types/index.d.ts +2 -0
  6. package/dist/elements/editor/types/index.d.ts.map +1 -0
  7. package/dist/elements/editor/utils/assign-editor-roots-to-config.d.ts +17 -0
  8. package/dist/elements/editor/utils/assign-editor-roots-to-config.d.ts.map +1 -0
  9. package/dist/elements/editor/utils/create-editor-in-context.d.ts +1 -3
  10. package/dist/elements/editor/utils/create-editor-in-context.d.ts.map +1 -1
  11. package/dist/elements/editor/utils/index.d.ts +3 -1
  12. package/dist/elements/editor/utils/index.d.ts.map +1 -1
  13. package/dist/elements/editor/utils/normalize-editor-language.d.ts +9 -0
  14. package/dist/elements/editor/utils/normalize-editor-language.d.ts.map +1 -0
  15. package/dist/elements/editor/utils/query-all-editor-editables.d.ts +23 -0
  16. package/dist/elements/editor/utils/query-all-editor-editables.d.ts.map +1 -0
  17. package/dist/index.cjs +2 -2
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.mjs +396 -387
  20. package/dist/index.mjs.map +1 -1
  21. package/package.json +3 -3
  22. package/src/elements/context/context.test.ts +107 -66
  23. package/src/elements/context/context.ts +9 -3
  24. package/src/elements/editable.ts +2 -2
  25. package/src/elements/editor/editor.ts +55 -76
  26. package/src/elements/editor/types/editor-relaxed-constructor.type.ts +6 -0
  27. package/src/elements/editor/types/index.ts +1 -0
  28. package/src/elements/editor/utils/assign-editor-roots-to-config.ts +60 -0
  29. package/src/elements/editor/utils/create-editor-in-context.ts +2 -5
  30. package/src/elements/editor/utils/index.ts +3 -1
  31. package/src/elements/editor/utils/normalize-editor-language.test.ts +50 -0
  32. package/src/elements/editor/utils/normalize-editor-language.ts +25 -0
  33. package/src/elements/editor/utils/query-all-editor-editables.ts +74 -0
  34. package/dist/elements/editor/utils/query-editor-editables.d.ts +0 -25
  35. package/dist/elements/editor/utils/query-editor-editables.d.ts.map +0 -1
  36. package/src/elements/editor/utils/query-editor-editables.ts +0 -101
@@ -0,0 +1,25 @@
1
+ import type { EditorLanguage } from '../typings';
2
+
3
+ /**
4
+ * Normalize editor language into object.
5
+ *
6
+ * @param lang Editor language.
7
+ * @returns Language object.
8
+ */
9
+ export function normalizeEditorLanguage(lang: EditorLanguage | string): EditorLanguage {
10
+ if (!lang) {
11
+ return {
12
+ ui: 'en',
13
+ content: 'en',
14
+ };
15
+ }
16
+
17
+ if (typeof lang === 'string') {
18
+ return {
19
+ ui: lang,
20
+ content: lang,
21
+ };
22
+ }
23
+
24
+ return lang;
25
+ }
@@ -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,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,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
- };