@ckeditor/ckeditor5-html-support 45.2.1 → 46.0.0-alpha.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.
Files changed (50) hide show
  1. package/build/html-support.js +2 -2
  2. package/dist/index.js +66 -13
  3. package/dist/index.js.map +1 -1
  4. package/package.json +13 -12
  5. package/src/converters.d.ts +21 -11
  6. package/src/converters.js +10 -0
  7. package/src/datafilter.d.ts +6 -6
  8. package/src/datafilter.js +7 -5
  9. package/src/dataschema.d.ts +14 -14
  10. package/src/dataschema.js +2 -2
  11. package/src/emptyblock.d.ts +1 -1
  12. package/src/emptyblock.js +1 -1
  13. package/src/fullpage.d.ts +1 -1
  14. package/src/fullpage.js +4 -4
  15. package/src/generalhtmlsupport.d.ts +20 -16
  16. package/src/generalhtmlsupport.js +21 -14
  17. package/src/generalhtmlsupportconfig.d.ts +5 -5
  18. package/src/htmlcomment.d.ts +6 -6
  19. package/src/htmlcomment.js +1 -1
  20. package/src/htmlpagedataprocessor.d.ts +1 -1
  21. package/src/htmlpagedataprocessor.js +3 -3
  22. package/src/index.d.ts +23 -19
  23. package/src/index.js +11 -7
  24. package/src/integrations/codeblock.d.ts +2 -2
  25. package/src/integrations/codeblock.js +2 -2
  26. package/src/integrations/customelement.d.ts +3 -3
  27. package/src/integrations/customelement.js +7 -6
  28. package/src/integrations/dualcontent.d.ts +6 -5
  29. package/src/integrations/dualcontent.js +6 -5
  30. package/src/integrations/heading.d.ts +2 -2
  31. package/src/integrations/heading.js +2 -2
  32. package/src/integrations/horizontalline.d.ts +2 -2
  33. package/src/integrations/horizontalline.js +2 -2
  34. package/src/integrations/image.d.ts +2 -2
  35. package/src/integrations/image.js +2 -2
  36. package/src/integrations/integrationutils.d.ts +2 -2
  37. package/src/integrations/list.d.ts +2 -2
  38. package/src/integrations/list.js +2 -2
  39. package/src/integrations/mediaembed.d.ts +2 -2
  40. package/src/integrations/mediaembed.js +3 -3
  41. package/src/integrations/script.d.ts +2 -2
  42. package/src/integrations/script.js +4 -3
  43. package/src/integrations/style.d.ts +2 -2
  44. package/src/integrations/style.js +4 -3
  45. package/src/integrations/table.d.ts +2 -2
  46. package/src/integrations/table.js +2 -2
  47. package/src/schemadefinitions.d.ts +4 -5
  48. package/src/schemadefinitions.js +5 -2
  49. package/src/utils.d.ts +26 -7
  50. package/src/utils.js +30 -0
package/src/utils.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  /**
6
6
  * @module html-support/utils
7
7
  */
8
- import type { DocumentSelection, DowncastWriter, Item, ViewElement, Writer } from 'ckeditor5/src/engine.js';
8
+ import type { ModelDocumentSelection, ViewDowncastWriter, ModelItem, ModelRange, ViewElement, ModelWriter } from 'ckeditor5/src/engine.js';
9
9
  export interface GHSViewAttributes {
10
10
  attributes?: Record<string, unknown>;
11
11
  classes?: Array<string>;
@@ -18,26 +18,31 @@ export interface GHSViewAttributes {
18
18
  * @param oldViewAttributes The previous GHS attribute value.
19
19
  * @param newViewAttributes The current GHS attribute value.
20
20
  * @param viewElement The view element to update.
21
+ * @internal
21
22
  */
22
- export declare function updateViewAttributes(writer: DowncastWriter, oldViewAttributes: GHSViewAttributes, newViewAttributes: GHSViewAttributes, viewElement: ViewElement): void;
23
+ export declare function updateViewAttributes(writer: ViewDowncastWriter, oldViewAttributes: GHSViewAttributes, newViewAttributes: GHSViewAttributes, viewElement: ViewElement): void;
23
24
  /**
24
25
  * Helper function for the downcast converter. Sets attributes on the given view element.
25
26
  *
26
27
  * @param writer The view writer.
27
28
  * @param viewAttributes The GHS attribute value.
28
29
  * @param viewElement The view element to update.
30
+ * @internal
29
31
  */
30
- export declare function setViewAttributes(writer: DowncastWriter, viewAttributes: GHSViewAttributes, viewElement: ViewElement): void;
32
+ export declare function setViewAttributes(writer: ViewDowncastWriter, viewAttributes: GHSViewAttributes, viewElement: ViewElement): void;
31
33
  /**
32
34
  * Helper function for the downcast converter. Removes attributes on the given view element.
33
35
  *
34
36
  * @param writer The view writer.
35
37
  * @param viewAttributes The GHS attribute value.
36
38
  * @param viewElement The view element to update.
39
+ * @internal
37
40
  */
38
- export declare function removeViewAttributes(writer: DowncastWriter, viewAttributes: GHSViewAttributes, viewElement: ViewElement): void;
41
+ export declare function removeViewAttributes(writer: ViewDowncastWriter, viewAttributes: GHSViewAttributes, viewElement: ViewElement): void;
39
42
  /**
40
43
  * Merges view element attribute objects.
44
+ *
45
+ * @internal
41
46
  */
42
47
  export declare function mergeViewElementAttributes(target: GHSViewAttributes, source: GHSViewAttributes): GHSViewAttributes;
43
48
  type ModifyGhsAttributesCallback = (t: Map<string, unknown>) => void;
@@ -45,28 +50,42 @@ type ModifyGhsClassesCallback = (t: Set<string>) => void;
45
50
  type ModifyGhsStylesCallback = (t: Map<string, string>) => void;
46
51
  /**
47
52
  * Updates a GHS attribute on a specified item.
53
+ *
48
54
  * @param callback That receives a map as an argument and should modify it (add or remove entries).
55
+ * @internal
49
56
  */
50
- export declare function modifyGhsAttribute(writer: Writer, item: Item | DocumentSelection, ghsAttributeName: string, subject: 'attributes', callback: ModifyGhsAttributesCallback): void;
57
+ export declare function modifyGhsAttribute(writer: ModelWriter, item: ModelItem | ModelDocumentSelection, ghsAttributeName: string, subject: 'attributes', callback: ModifyGhsAttributesCallback): void;
51
58
  /**
52
59
  * Updates a GHS attribute on a specified item.
60
+ *
53
61
  * @param callback That receives a set as an argument and should modify it (add or remove entries).
62
+ * @internal
54
63
  */
55
- export declare function modifyGhsAttribute(writer: Writer, item: Item | DocumentSelection, ghsAttributeName: string, subject: 'classes', callback: ModifyGhsClassesCallback): void;
64
+ export declare function modifyGhsAttribute(writer: ModelWriter, item: ModelItem | ModelDocumentSelection, ghsAttributeName: string, subject: 'classes', callback: ModifyGhsClassesCallback): void;
56
65
  /**
57
66
  * Updates a GHS attribute on a specified item.
58
67
  * @param callback That receives a map as an argument and should modify it (add or remove entries).
59
68
  */
60
- export declare function modifyGhsAttribute(writer: Writer, item: Item | DocumentSelection, ghsAttributeName: string, subject: 'styles', callback: ModifyGhsStylesCallback): void;
69
+ export declare function modifyGhsAttribute(writer: ModelWriter, item: ModelItem | ModelDocumentSelection, ghsAttributeName: string, subject: 'styles', callback: ModifyGhsStylesCallback): void;
70
+ /**
71
+ * Strips the `styles`, and `classes` keys from the GHS attribute value on the given item.
72
+ *
73
+ * @internal
74
+ */
75
+ export declare function removeFormatting(ghsAttributeName: string, itemRange: ModelRange, writer: ModelWriter): void;
61
76
  /**
62
77
  * Transforms passed string to PascalCase format. Examples:
63
78
  * * `div` => `Div`
64
79
  * * `h1` => `H1`
65
80
  * * `table` => `Table`
81
+ *
82
+ * @internal
66
83
  */
67
84
  export declare function toPascalCase(data: string): string;
68
85
  /**
69
86
  * Returns the attribute name of the model element that holds raw HTML attributes.
87
+ *
88
+ * @internal
70
89
  */
71
90
  export declare function getHtmlAttributeName(viewElementName: string): string;
72
91
  export {};
package/src/utils.js CHANGED
@@ -10,6 +10,7 @@ import { startCase, cloneDeep } from 'es-toolkit/compat';
10
10
  * @param oldViewAttributes The previous GHS attribute value.
11
11
  * @param newViewAttributes The current GHS attribute value.
12
12
  * @param viewElement The view element to update.
13
+ * @internal
13
14
  */
14
15
  export function updateViewAttributes(writer, oldViewAttributes, newViewAttributes, viewElement) {
15
16
  if (oldViewAttributes) {
@@ -25,6 +26,7 @@ export function updateViewAttributes(writer, oldViewAttributes, newViewAttribute
25
26
  * @param writer The view writer.
26
27
  * @param viewAttributes The GHS attribute value.
27
28
  * @param viewElement The view element to update.
29
+ * @internal
28
30
  */
29
31
  export function setViewAttributes(writer, viewAttributes, viewElement) {
30
32
  if (viewAttributes.attributes) {
@@ -45,6 +47,7 @@ export function setViewAttributes(writer, viewAttributes, viewElement) {
45
47
  * @param writer The view writer.
46
48
  * @param viewAttributes The GHS attribute value.
47
49
  * @param viewElement The view element to update.
50
+ * @internal
48
51
  */
49
52
  export function removeViewAttributes(writer, viewAttributes, viewElement) {
50
53
  if (viewAttributes.attributes) {
@@ -63,6 +66,8 @@ export function removeViewAttributes(writer, viewAttributes, viewElement) {
63
66
  }
64
67
  /**
65
68
  * Merges view element attribute objects.
69
+ *
70
+ * @internal
66
71
  */
67
72
  export function mergeViewElementAttributes(target, source) {
68
73
  const result = cloneDeep(target);
@@ -122,17 +127,42 @@ export function modifyGhsAttribute(writer, item, ghsAttributeName, subject, call
122
127
  }
123
128
  }
124
129
  }
130
+ /**
131
+ * Strips the `styles`, and `classes` keys from the GHS attribute value on the given item.
132
+ *
133
+ * @internal
134
+ */
135
+ export function removeFormatting(ghsAttributeName, itemRange, writer) {
136
+ for (const item of itemRange.getItems({ shallow: true })) {
137
+ const value = item.getAttribute(ghsAttributeName);
138
+ // Copy only attributes to the new attribute value.
139
+ if (value && value.attributes && Object.keys(value.attributes).length) {
140
+ // But reset the GHS attribute only when there is anything more than just attributes.
141
+ if (Object.keys(value).length > 1) {
142
+ writer.setAttribute(ghsAttributeName, { attributes: value.attributes }, item);
143
+ }
144
+ }
145
+ else {
146
+ // There are no attributes, so remove the GHS attribute completely.
147
+ writer.removeAttribute(ghsAttributeName, item);
148
+ }
149
+ }
150
+ }
125
151
  /**
126
152
  * Transforms passed string to PascalCase format. Examples:
127
153
  * * `div` => `Div`
128
154
  * * `h1` => `H1`
129
155
  * * `table` => `Table`
156
+ *
157
+ * @internal
130
158
  */
131
159
  export function toPascalCase(data) {
132
160
  return startCase(data).replace(/ /g, '');
133
161
  }
134
162
  /**
135
163
  * Returns the attribute name of the model element that holds raw HTML attributes.
164
+ *
165
+ * @internal
136
166
  */
137
167
  export function getHtmlAttributeName(viewElementName) {
138
168
  return `html${toPascalCase(viewElementName)}Attributes`;