@ckeditor/ckeditor5-html-support 40.0.0 → 40.1.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/LICENSE.md +4 -4
- package/build/html-support.js +1 -1
- package/package.json +2 -2
- package/src/augmentation.d.ts +33 -33
- package/src/augmentation.js +5 -5
- package/src/converters.d.ts +60 -60
- package/src/converters.js +180 -180
- package/src/datafilter.d.ts +304 -304
- package/src/datafilter.js +720 -720
- package/src/dataschema.d.ts +183 -183
- package/src/dataschema.js +196 -196
- package/src/fullpage.d.ts +21 -21
- package/src/fullpage.js +80 -80
- package/src/generalhtmlsupport.d.ts +98 -98
- package/src/generalhtmlsupport.js +240 -240
- package/src/generalhtmlsupportconfig.d.ts +77 -77
- package/src/generalhtmlsupportconfig.js +5 -5
- package/src/htmlcomment.d.ts +71 -71
- package/src/htmlcomment.js +218 -218
- package/src/htmlpagedataprocessor.d.ts +22 -22
- package/src/htmlpagedataprocessor.js +67 -67
- package/src/index.d.ts +25 -25
- package/src/index.js +14 -14
- package/src/integrations/codeblock.d.ts +23 -23
- package/src/integrations/codeblock.js +101 -101
- package/src/integrations/customelement.d.ts +27 -27
- package/src/integrations/customelement.js +146 -146
- package/src/integrations/documentlist.d.ts +27 -27
- package/src/integrations/documentlist.js +178 -178
- package/src/integrations/dualcontent.d.ts +45 -45
- package/src/integrations/dualcontent.js +119 -119
- package/src/integrations/heading.d.ts +31 -31
- package/src/integrations/heading.js +60 -60
- package/src/integrations/image.d.ts +26 -26
- package/src/integrations/image.js +189 -189
- package/src/integrations/integrationutils.d.ts +15 -15
- package/src/integrations/integrationutils.js +21 -21
- package/src/integrations/mediaembed.d.ts +26 -26
- package/src/integrations/mediaembed.js +119 -119
- package/src/integrations/script.d.ts +26 -26
- package/src/integrations/script.js +59 -59
- package/src/integrations/style.d.ts +26 -26
- package/src/integrations/style.js +59 -59
- package/src/integrations/table.d.ts +23 -23
- package/src/integrations/table.js +163 -163
- package/src/schemadefinitions.d.ts +13 -13
- package/src/schemadefinitions.js +953 -956
- package/src/utils.d.ts +72 -72
- package/src/utils.js +139 -139
- package/build/html-support.js.map +0 -1
package/src/utils.d.ts
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module html-support/utils
|
|
7
|
-
*/
|
|
8
|
-
import type { DocumentSelection, DowncastWriter, Item, ViewElement, Writer } from 'ckeditor5/src/engine';
|
|
9
|
-
export interface GHSViewAttributes {
|
|
10
|
-
attributes?: Record<string, unknown>;
|
|
11
|
-
classes?: Array<string>;
|
|
12
|
-
styles?: Record<string, string>;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Helper function for the downcast converter. Updates attributes on the given view element.
|
|
16
|
-
*
|
|
17
|
-
* @param writer The view writer.
|
|
18
|
-
* @param oldViewAttributes The previous GHS attribute value.
|
|
19
|
-
* @param newViewAttributes The current GHS attribute value.
|
|
20
|
-
* @param viewElement The view element to update.
|
|
21
|
-
*/
|
|
22
|
-
export declare function updateViewAttributes(writer: DowncastWriter, oldViewAttributes: GHSViewAttributes, newViewAttributes: GHSViewAttributes, viewElement: ViewElement): void;
|
|
23
|
-
/**
|
|
24
|
-
* Helper function for the downcast converter. Sets attributes on the given view element.
|
|
25
|
-
*
|
|
26
|
-
* @param writer The view writer.
|
|
27
|
-
* @param viewAttributes The GHS attribute value.
|
|
28
|
-
* @param viewElement The view element to update.
|
|
29
|
-
*/
|
|
30
|
-
export declare function setViewAttributes(writer: DowncastWriter, viewAttributes: GHSViewAttributes, viewElement: ViewElement): void;
|
|
31
|
-
/**
|
|
32
|
-
* Helper function for the downcast converter. Removes attributes on the given view element.
|
|
33
|
-
*
|
|
34
|
-
* @param writer The view writer.
|
|
35
|
-
* @param viewAttributes The GHS attribute value.
|
|
36
|
-
* @param viewElement The view element to update.
|
|
37
|
-
*/
|
|
38
|
-
export declare function removeViewAttributes(writer: DowncastWriter, viewAttributes: GHSViewAttributes, viewElement: ViewElement): void;
|
|
39
|
-
/**
|
|
40
|
-
* Merges view element attribute objects.
|
|
41
|
-
*/
|
|
42
|
-
export declare function mergeViewElementAttributes(target: GHSViewAttributes, source: GHSViewAttributes): GHSViewAttributes;
|
|
43
|
-
type ModifyGhsAttributesCallback = (t: Map<string, unknown>) => void;
|
|
44
|
-
type ModifyGhsClassesCallback = (t: Set<string>) => void;
|
|
45
|
-
type ModifyGhsStylesCallback = (t: Map<string, string>) => void;
|
|
46
|
-
/**
|
|
47
|
-
* Updates a GHS attribute on a specified item.
|
|
48
|
-
* @param callback That receives a map as an argument and should modify it (add or remove entries).
|
|
49
|
-
*/
|
|
50
|
-
export declare function modifyGhsAttribute(writer: Writer, item: Item | DocumentSelection, ghsAttributeName: string, subject: 'attributes', callback: ModifyGhsAttributesCallback): void;
|
|
51
|
-
/**
|
|
52
|
-
* Updates a GHS attribute on a specified item.
|
|
53
|
-
* @param callback That receives a set as an argument and should modify it (add or remove entries).
|
|
54
|
-
*/
|
|
55
|
-
export declare function modifyGhsAttribute(writer: Writer, item: Item | DocumentSelection, ghsAttributeName: string, subject: 'classes', callback: ModifyGhsClassesCallback): void;
|
|
56
|
-
/**
|
|
57
|
-
* Updates a GHS attribute on a specified item.
|
|
58
|
-
* @param callback That receives a map as an argument and should modify it (add or remove entries).
|
|
59
|
-
*/
|
|
60
|
-
export declare function modifyGhsAttribute(writer: Writer, item: Item | DocumentSelection, ghsAttributeName: string, subject: 'styles', callback: ModifyGhsStylesCallback): void;
|
|
61
|
-
/**
|
|
62
|
-
* Transforms passed string to PascalCase format. Examples:
|
|
63
|
-
* * `div` => `Div`
|
|
64
|
-
* * `h1` => `H1`
|
|
65
|
-
* * `table` => `Table`
|
|
66
|
-
*/
|
|
67
|
-
export declare function toPascalCase(data: string): string;
|
|
68
|
-
/**
|
|
69
|
-
* Returns the attribute name of the model element that holds raw HTML attributes.
|
|
70
|
-
*/
|
|
71
|
-
export declare function getHtmlAttributeName(viewElementName: string): string;
|
|
72
|
-
export {};
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module html-support/utils
|
|
7
|
+
*/
|
|
8
|
+
import type { DocumentSelection, DowncastWriter, Item, ViewElement, Writer } from 'ckeditor5/src/engine';
|
|
9
|
+
export interface GHSViewAttributes {
|
|
10
|
+
attributes?: Record<string, unknown>;
|
|
11
|
+
classes?: Array<string>;
|
|
12
|
+
styles?: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Helper function for the downcast converter. Updates attributes on the given view element.
|
|
16
|
+
*
|
|
17
|
+
* @param writer The view writer.
|
|
18
|
+
* @param oldViewAttributes The previous GHS attribute value.
|
|
19
|
+
* @param newViewAttributes The current GHS attribute value.
|
|
20
|
+
* @param viewElement The view element to update.
|
|
21
|
+
*/
|
|
22
|
+
export declare function updateViewAttributes(writer: DowncastWriter, oldViewAttributes: GHSViewAttributes, newViewAttributes: GHSViewAttributes, viewElement: ViewElement): void;
|
|
23
|
+
/**
|
|
24
|
+
* Helper function for the downcast converter. Sets attributes on the given view element.
|
|
25
|
+
*
|
|
26
|
+
* @param writer The view writer.
|
|
27
|
+
* @param viewAttributes The GHS attribute value.
|
|
28
|
+
* @param viewElement The view element to update.
|
|
29
|
+
*/
|
|
30
|
+
export declare function setViewAttributes(writer: DowncastWriter, viewAttributes: GHSViewAttributes, viewElement: ViewElement): void;
|
|
31
|
+
/**
|
|
32
|
+
* Helper function for the downcast converter. Removes attributes on the given view element.
|
|
33
|
+
*
|
|
34
|
+
* @param writer The view writer.
|
|
35
|
+
* @param viewAttributes The GHS attribute value.
|
|
36
|
+
* @param viewElement The view element to update.
|
|
37
|
+
*/
|
|
38
|
+
export declare function removeViewAttributes(writer: DowncastWriter, viewAttributes: GHSViewAttributes, viewElement: ViewElement): void;
|
|
39
|
+
/**
|
|
40
|
+
* Merges view element attribute objects.
|
|
41
|
+
*/
|
|
42
|
+
export declare function mergeViewElementAttributes(target: GHSViewAttributes, source: GHSViewAttributes): GHSViewAttributes;
|
|
43
|
+
type ModifyGhsAttributesCallback = (t: Map<string, unknown>) => void;
|
|
44
|
+
type ModifyGhsClassesCallback = (t: Set<string>) => void;
|
|
45
|
+
type ModifyGhsStylesCallback = (t: Map<string, string>) => void;
|
|
46
|
+
/**
|
|
47
|
+
* Updates a GHS attribute on a specified item.
|
|
48
|
+
* @param callback That receives a map as an argument and should modify it (add or remove entries).
|
|
49
|
+
*/
|
|
50
|
+
export declare function modifyGhsAttribute(writer: Writer, item: Item | DocumentSelection, ghsAttributeName: string, subject: 'attributes', callback: ModifyGhsAttributesCallback): void;
|
|
51
|
+
/**
|
|
52
|
+
* Updates a GHS attribute on a specified item.
|
|
53
|
+
* @param callback That receives a set as an argument and should modify it (add or remove entries).
|
|
54
|
+
*/
|
|
55
|
+
export declare function modifyGhsAttribute(writer: Writer, item: Item | DocumentSelection, ghsAttributeName: string, subject: 'classes', callback: ModifyGhsClassesCallback): void;
|
|
56
|
+
/**
|
|
57
|
+
* Updates a GHS attribute on a specified item.
|
|
58
|
+
* @param callback That receives a map as an argument and should modify it (add or remove entries).
|
|
59
|
+
*/
|
|
60
|
+
export declare function modifyGhsAttribute(writer: Writer, item: Item | DocumentSelection, ghsAttributeName: string, subject: 'styles', callback: ModifyGhsStylesCallback): void;
|
|
61
|
+
/**
|
|
62
|
+
* Transforms passed string to PascalCase format. Examples:
|
|
63
|
+
* * `div` => `Div`
|
|
64
|
+
* * `h1` => `H1`
|
|
65
|
+
* * `table` => `Table`
|
|
66
|
+
*/
|
|
67
|
+
export declare function toPascalCase(data: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* Returns the attribute name of the model element that holds raw HTML attributes.
|
|
70
|
+
*/
|
|
71
|
+
export declare function getHtmlAttributeName(viewElementName: string): string;
|
|
72
|
+
export {};
|
package/src/utils.js
CHANGED
|
@@ -1,139 +1,139 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
import { startCase, cloneDeep } from 'lodash-es';
|
|
6
|
-
/**
|
|
7
|
-
* Helper function for the downcast converter. Updates attributes on the given view element.
|
|
8
|
-
*
|
|
9
|
-
* @param writer The view writer.
|
|
10
|
-
* @param oldViewAttributes The previous GHS attribute value.
|
|
11
|
-
* @param newViewAttributes The current GHS attribute value.
|
|
12
|
-
* @param viewElement The view element to update.
|
|
13
|
-
*/
|
|
14
|
-
export function updateViewAttributes(writer, oldViewAttributes, newViewAttributes, viewElement) {
|
|
15
|
-
if (oldViewAttributes) {
|
|
16
|
-
removeViewAttributes(writer, oldViewAttributes, viewElement);
|
|
17
|
-
}
|
|
18
|
-
if (newViewAttributes) {
|
|
19
|
-
setViewAttributes(writer, newViewAttributes, viewElement);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Helper function for the downcast converter. Sets attributes on the given view element.
|
|
24
|
-
*
|
|
25
|
-
* @param writer The view writer.
|
|
26
|
-
* @param viewAttributes The GHS attribute value.
|
|
27
|
-
* @param viewElement The view element to update.
|
|
28
|
-
*/
|
|
29
|
-
export function setViewAttributes(writer, viewAttributes, viewElement) {
|
|
30
|
-
if (viewAttributes.attributes) {
|
|
31
|
-
for (const [key, value] of Object.entries(viewAttributes.attributes)) {
|
|
32
|
-
writer.setAttribute(key, value, viewElement);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
if (viewAttributes.styles) {
|
|
36
|
-
writer.setStyle(viewAttributes.styles, viewElement);
|
|
37
|
-
}
|
|
38
|
-
if (viewAttributes.classes) {
|
|
39
|
-
writer.addClass(viewAttributes.classes, viewElement);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Helper function for the downcast converter. Removes attributes on the given view element.
|
|
44
|
-
*
|
|
45
|
-
* @param writer The view writer.
|
|
46
|
-
* @param viewAttributes The GHS attribute value.
|
|
47
|
-
* @param viewElement The view element to update.
|
|
48
|
-
*/
|
|
49
|
-
export function removeViewAttributes(writer, viewAttributes, viewElement) {
|
|
50
|
-
if (viewAttributes.attributes) {
|
|
51
|
-
for (const [key] of Object.entries(viewAttributes.attributes)) {
|
|
52
|
-
writer.removeAttribute(key, viewElement);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (viewAttributes.styles) {
|
|
56
|
-
for (const style of Object.keys(viewAttributes.styles)) {
|
|
57
|
-
writer.removeStyle(style, viewElement);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (viewAttributes.classes) {
|
|
61
|
-
writer.removeClass(viewAttributes.classes, viewElement);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Merges view element attribute objects.
|
|
66
|
-
*/
|
|
67
|
-
export function mergeViewElementAttributes(target, source) {
|
|
68
|
-
const result = cloneDeep(target);
|
|
69
|
-
let key = 'attributes';
|
|
70
|
-
for (key in source) {
|
|
71
|
-
// Merge classes.
|
|
72
|
-
if (key == 'classes') {
|
|
73
|
-
result[key] = Array.from(new Set([...(target[key] || []), ...source[key]]));
|
|
74
|
-
}
|
|
75
|
-
// Merge attributes or styles.
|
|
76
|
-
else {
|
|
77
|
-
result[key] = { ...target[key], ...source[key] };
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return result;
|
|
81
|
-
}
|
|
82
|
-
export function modifyGhsAttribute(writer, item, ghsAttributeName, subject, callback) {
|
|
83
|
-
const oldValue = item.getAttribute(ghsAttributeName);
|
|
84
|
-
const newValue = {};
|
|
85
|
-
for (const kind of ['attributes', 'styles', 'classes']) {
|
|
86
|
-
// Properties other than `subject` should be assigned from `oldValue`.
|
|
87
|
-
if (kind != subject) {
|
|
88
|
-
if (oldValue && oldValue[kind]) {
|
|
89
|
-
newValue[kind] = oldValue[kind];
|
|
90
|
-
}
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
// `callback` should be applied on property [`subject`].
|
|
94
|
-
if (subject == 'classes') {
|
|
95
|
-
const values = new Set(oldValue && oldValue.classes || []);
|
|
96
|
-
callback(values);
|
|
97
|
-
if (values.size) {
|
|
98
|
-
newValue[kind] = Array.from(values);
|
|
99
|
-
}
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
const values = new Map(Object.entries(oldValue && oldValue[kind] || {}));
|
|
103
|
-
callback(values);
|
|
104
|
-
if (values.size) {
|
|
105
|
-
newValue[kind] = Object.fromEntries(values);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (Object.keys(newValue).length) {
|
|
109
|
-
if (item.is('documentSelection')) {
|
|
110
|
-
writer.setSelectionAttribute(ghsAttributeName, newValue);
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
writer.setAttribute(ghsAttributeName, newValue, item);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
else if (oldValue) {
|
|
117
|
-
if (item.is('documentSelection')) {
|
|
118
|
-
writer.removeSelectionAttribute(ghsAttributeName);
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
writer.removeAttribute(ghsAttributeName, item);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Transforms passed string to PascalCase format. Examples:
|
|
127
|
-
* * `div` => `Div`
|
|
128
|
-
* * `h1` => `H1`
|
|
129
|
-
* * `table` => `Table`
|
|
130
|
-
*/
|
|
131
|
-
export function toPascalCase(data) {
|
|
132
|
-
return startCase(data).replace(/ /g, '');
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Returns the attribute name of the model element that holds raw HTML attributes.
|
|
136
|
-
*/
|
|
137
|
-
export function getHtmlAttributeName(viewElementName) {
|
|
138
|
-
return `html${toPascalCase(viewElementName)}Attributes`;
|
|
139
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
import { startCase, cloneDeep } from 'lodash-es';
|
|
6
|
+
/**
|
|
7
|
+
* Helper function for the downcast converter. Updates attributes on the given view element.
|
|
8
|
+
*
|
|
9
|
+
* @param writer The view writer.
|
|
10
|
+
* @param oldViewAttributes The previous GHS attribute value.
|
|
11
|
+
* @param newViewAttributes The current GHS attribute value.
|
|
12
|
+
* @param viewElement The view element to update.
|
|
13
|
+
*/
|
|
14
|
+
export function updateViewAttributes(writer, oldViewAttributes, newViewAttributes, viewElement) {
|
|
15
|
+
if (oldViewAttributes) {
|
|
16
|
+
removeViewAttributes(writer, oldViewAttributes, viewElement);
|
|
17
|
+
}
|
|
18
|
+
if (newViewAttributes) {
|
|
19
|
+
setViewAttributes(writer, newViewAttributes, viewElement);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Helper function for the downcast converter. Sets attributes on the given view element.
|
|
24
|
+
*
|
|
25
|
+
* @param writer The view writer.
|
|
26
|
+
* @param viewAttributes The GHS attribute value.
|
|
27
|
+
* @param viewElement The view element to update.
|
|
28
|
+
*/
|
|
29
|
+
export function setViewAttributes(writer, viewAttributes, viewElement) {
|
|
30
|
+
if (viewAttributes.attributes) {
|
|
31
|
+
for (const [key, value] of Object.entries(viewAttributes.attributes)) {
|
|
32
|
+
writer.setAttribute(key, value, viewElement);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (viewAttributes.styles) {
|
|
36
|
+
writer.setStyle(viewAttributes.styles, viewElement);
|
|
37
|
+
}
|
|
38
|
+
if (viewAttributes.classes) {
|
|
39
|
+
writer.addClass(viewAttributes.classes, viewElement);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Helper function for the downcast converter. Removes attributes on the given view element.
|
|
44
|
+
*
|
|
45
|
+
* @param writer The view writer.
|
|
46
|
+
* @param viewAttributes The GHS attribute value.
|
|
47
|
+
* @param viewElement The view element to update.
|
|
48
|
+
*/
|
|
49
|
+
export function removeViewAttributes(writer, viewAttributes, viewElement) {
|
|
50
|
+
if (viewAttributes.attributes) {
|
|
51
|
+
for (const [key] of Object.entries(viewAttributes.attributes)) {
|
|
52
|
+
writer.removeAttribute(key, viewElement);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (viewAttributes.styles) {
|
|
56
|
+
for (const style of Object.keys(viewAttributes.styles)) {
|
|
57
|
+
writer.removeStyle(style, viewElement);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (viewAttributes.classes) {
|
|
61
|
+
writer.removeClass(viewAttributes.classes, viewElement);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Merges view element attribute objects.
|
|
66
|
+
*/
|
|
67
|
+
export function mergeViewElementAttributes(target, source) {
|
|
68
|
+
const result = cloneDeep(target);
|
|
69
|
+
let key = 'attributes';
|
|
70
|
+
for (key in source) {
|
|
71
|
+
// Merge classes.
|
|
72
|
+
if (key == 'classes') {
|
|
73
|
+
result[key] = Array.from(new Set([...(target[key] || []), ...source[key]]));
|
|
74
|
+
}
|
|
75
|
+
// Merge attributes or styles.
|
|
76
|
+
else {
|
|
77
|
+
result[key] = { ...target[key], ...source[key] };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
export function modifyGhsAttribute(writer, item, ghsAttributeName, subject, callback) {
|
|
83
|
+
const oldValue = item.getAttribute(ghsAttributeName);
|
|
84
|
+
const newValue = {};
|
|
85
|
+
for (const kind of ['attributes', 'styles', 'classes']) {
|
|
86
|
+
// Properties other than `subject` should be assigned from `oldValue`.
|
|
87
|
+
if (kind != subject) {
|
|
88
|
+
if (oldValue && oldValue[kind]) {
|
|
89
|
+
newValue[kind] = oldValue[kind];
|
|
90
|
+
}
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
// `callback` should be applied on property [`subject`].
|
|
94
|
+
if (subject == 'classes') {
|
|
95
|
+
const values = new Set(oldValue && oldValue.classes || []);
|
|
96
|
+
callback(values);
|
|
97
|
+
if (values.size) {
|
|
98
|
+
newValue[kind] = Array.from(values);
|
|
99
|
+
}
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const values = new Map(Object.entries(oldValue && oldValue[kind] || {}));
|
|
103
|
+
callback(values);
|
|
104
|
+
if (values.size) {
|
|
105
|
+
newValue[kind] = Object.fromEntries(values);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (Object.keys(newValue).length) {
|
|
109
|
+
if (item.is('documentSelection')) {
|
|
110
|
+
writer.setSelectionAttribute(ghsAttributeName, newValue);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
writer.setAttribute(ghsAttributeName, newValue, item);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else if (oldValue) {
|
|
117
|
+
if (item.is('documentSelection')) {
|
|
118
|
+
writer.removeSelectionAttribute(ghsAttributeName);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
writer.removeAttribute(ghsAttributeName, item);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Transforms passed string to PascalCase format. Examples:
|
|
127
|
+
* * `div` => `Div`
|
|
128
|
+
* * `h1` => `H1`
|
|
129
|
+
* * `table` => `Table`
|
|
130
|
+
*/
|
|
131
|
+
export function toPascalCase(data) {
|
|
132
|
+
return startCase(data).replace(/ /g, '');
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Returns the attribute name of the model element that holds raw HTML attributes.
|
|
136
|
+
*/
|
|
137
|
+
export function getHtmlAttributeName(viewElementName) {
|
|
138
|
+
return `html${toPascalCase(viewElementName)}Attributes`;
|
|
139
|
+
}
|