@ckeditor/ckeditor5-html-support 41.3.0-alpha.1 → 41.3.0-alpha.2
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/build/html-support.js +1 -1
- package/dist/translations/ar.d.ts +8 -0
- package/dist/translations/ar.js +5 -0
- package/dist/translations/bg.d.ts +8 -0
- package/dist/translations/bg.js +5 -0
- package/dist/translations/bn.d.ts +8 -0
- package/dist/translations/bn.js +5 -0
- package/dist/translations/ca.d.ts +8 -0
- package/dist/translations/ca.js +5 -0
- package/dist/translations/cs.d.ts +8 -0
- package/dist/translations/cs.js +5 -0
- package/dist/translations/da.d.ts +8 -0
- package/dist/translations/da.js +5 -0
- package/dist/translations/de.d.ts +8 -0
- package/dist/translations/de.js +5 -0
- package/dist/translations/el.d.ts +8 -0
- package/dist/translations/el.js +5 -0
- package/dist/translations/en-au.d.ts +8 -0
- package/dist/translations/en-au.js +5 -0
- package/dist/translations/en.d.ts +8 -0
- package/dist/translations/en.js +5 -0
- package/dist/translations/es.d.ts +8 -0
- package/dist/translations/es.js +5 -0
- package/dist/translations/et.d.ts +8 -0
- package/dist/translations/et.js +5 -0
- package/dist/translations/fi.d.ts +8 -0
- package/dist/translations/fi.js +5 -0
- package/dist/translations/fr.d.ts +8 -0
- package/dist/translations/fr.js +5 -0
- package/dist/translations/gl.d.ts +8 -0
- package/dist/translations/gl.js +5 -0
- package/dist/translations/he.d.ts +8 -0
- package/dist/translations/he.js +5 -0
- package/dist/translations/hi.d.ts +8 -0
- package/dist/translations/hi.js +5 -0
- package/dist/translations/hr.d.ts +8 -0
- package/dist/translations/hr.js +5 -0
- package/dist/translations/hu.d.ts +8 -0
- package/dist/translations/hu.js +5 -0
- package/dist/translations/id.d.ts +8 -0
- package/dist/translations/id.js +5 -0
- package/dist/translations/it.d.ts +8 -0
- package/dist/translations/it.js +5 -0
- package/dist/translations/ja.d.ts +8 -0
- package/dist/translations/ja.js +5 -0
- package/dist/translations/jv.d.ts +8 -0
- package/dist/translations/jv.js +5 -0
- package/dist/translations/ko.d.ts +8 -0
- package/dist/translations/ko.js +5 -0
- package/dist/translations/lt.d.ts +8 -0
- package/dist/translations/lt.js +5 -0
- package/dist/translations/lv.d.ts +8 -0
- package/dist/translations/lv.js +5 -0
- package/dist/translations/ms.d.ts +8 -0
- package/dist/translations/ms.js +5 -0
- package/dist/translations/nl.d.ts +8 -0
- package/dist/translations/nl.js +5 -0
- package/dist/translations/no.d.ts +8 -0
- package/dist/translations/no.js +5 -0
- package/dist/translations/pl.d.ts +8 -0
- package/dist/translations/pl.js +5 -0
- package/dist/translations/pt-br.d.ts +8 -0
- package/dist/translations/pt-br.js +5 -0
- package/dist/translations/pt.d.ts +8 -0
- package/dist/translations/pt.js +5 -0
- package/dist/translations/ro.d.ts +8 -0
- package/dist/translations/ro.js +5 -0
- package/dist/translations/ru.d.ts +8 -0
- package/dist/translations/ru.js +5 -0
- package/dist/translations/sk.d.ts +8 -0
- package/dist/translations/sk.js +5 -0
- package/dist/translations/sr-latn.d.ts +8 -0
- package/dist/translations/sr-latn.js +5 -0
- package/dist/translations/sr.d.ts +8 -0
- package/dist/translations/sr.js +5 -0
- package/dist/translations/sv.d.ts +8 -0
- package/dist/translations/sv.js +5 -0
- package/dist/translations/th.d.ts +8 -0
- package/dist/translations/th.js +5 -0
- package/dist/translations/tr.d.ts +8 -0
- package/dist/translations/tr.js +5 -0
- package/dist/translations/ug.d.ts +8 -0
- package/dist/translations/ug.js +5 -0
- package/dist/translations/uk.d.ts +8 -0
- package/dist/translations/uk.js +5 -0
- package/dist/translations/ur.d.ts +8 -0
- package/dist/translations/ur.js +5 -0
- package/dist/translations/vi.d.ts +8 -0
- package/dist/translations/vi.js +5 -0
- package/dist/translations/zh-cn.d.ts +8 -0
- package/dist/translations/zh-cn.js +5 -0
- package/dist/translations/zh.d.ts +8 -0
- package/dist/translations/zh.js +5 -0
- package/dist/types/augmentation.d.ts +4 -0
- package/dist/types/converters.d.ts +4 -0
- package/dist/types/datafilter.d.ts +4 -0
- package/dist/types/dataschema.d.ts +4 -0
- package/dist/types/fullpage.d.ts +4 -0
- package/dist/types/generalhtmlsupport.d.ts +4 -0
- package/dist/types/generalhtmlsupportconfig.d.ts +4 -0
- package/dist/types/htmlcomment.d.ts +4 -0
- package/dist/types/htmlpagedataprocessor.d.ts +4 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/integrations/codeblock.d.ts +4 -0
- package/dist/types/integrations/customelement.d.ts +4 -0
- package/dist/types/integrations/dualcontent.d.ts +4 -0
- package/dist/types/integrations/heading.d.ts +4 -0
- package/dist/types/integrations/image.d.ts +4 -0
- package/dist/types/integrations/integrationutils.d.ts +4 -0
- package/dist/types/integrations/list.d.ts +4 -0
- package/dist/types/integrations/mediaembed.d.ts +4 -0
- package/dist/types/integrations/script.d.ts +4 -0
- package/dist/types/integrations/style.d.ts +4 -0
- package/dist/types/integrations/table.d.ts +4 -0
- package/dist/types/schemadefinitions.d.ts +4 -0
- package/dist/types/utils.d.ts +4 -0
- package/package.json +2 -2
- package/dist/index.js +0 -4004
- package/dist/index.js.map +0 -1
package/dist/index.js
DELETED
|
@@ -1,4004 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2024, 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 { Plugin } from '@ckeditor/ckeditor5-core/dist/index.js';
|
|
6
|
-
import { toArray, priorities, CKEditorError, isValidAttributeName, uid } from '@ckeditor/ckeditor5-utils/dist/index.js';
|
|
7
|
-
import { Matcher, StylesMap, UpcastWriter, HtmlDataProcessor } from '@ckeditor/ckeditor5-engine/dist/index.js';
|
|
8
|
-
import { toWidget, Widget } from '@ckeditor/ckeditor5-widget/dist/index.js';
|
|
9
|
-
import { cloneDeep, startCase, mergeWith, isPlainObject, isEqual } from 'lodash-es';
|
|
10
|
-
import { Enter } from '@ckeditor/ckeditor5-enter/dist/index.js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
14
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* Helper function for the downcast converter. Updates attributes on the given view element.
|
|
18
|
-
*
|
|
19
|
-
* @param writer The view writer.
|
|
20
|
-
* @param oldViewAttributes The previous GHS attribute value.
|
|
21
|
-
* @param newViewAttributes The current GHS attribute value.
|
|
22
|
-
* @param viewElement The view element to update.
|
|
23
|
-
*/
|
|
24
|
-
function updateViewAttributes(writer, oldViewAttributes, newViewAttributes, viewElement) {
|
|
25
|
-
if (oldViewAttributes) {
|
|
26
|
-
removeViewAttributes(writer, oldViewAttributes, viewElement);
|
|
27
|
-
}
|
|
28
|
-
if (newViewAttributes) {
|
|
29
|
-
setViewAttributes(writer, newViewAttributes, viewElement);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Helper function for the downcast converter. Sets attributes on the given view element.
|
|
34
|
-
*
|
|
35
|
-
* @param writer The view writer.
|
|
36
|
-
* @param viewAttributes The GHS attribute value.
|
|
37
|
-
* @param viewElement The view element to update.
|
|
38
|
-
*/
|
|
39
|
-
function setViewAttributes(writer, viewAttributes, viewElement) {
|
|
40
|
-
if (viewAttributes.attributes) {
|
|
41
|
-
for (const [key, value] of Object.entries(viewAttributes.attributes)) {
|
|
42
|
-
writer.setAttribute(key, value, viewElement);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (viewAttributes.styles) {
|
|
46
|
-
writer.setStyle(viewAttributes.styles, viewElement);
|
|
47
|
-
}
|
|
48
|
-
if (viewAttributes.classes) {
|
|
49
|
-
writer.addClass(viewAttributes.classes, viewElement);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Helper function for the downcast converter. Removes attributes on the given view element.
|
|
54
|
-
*
|
|
55
|
-
* @param writer The view writer.
|
|
56
|
-
* @param viewAttributes The GHS attribute value.
|
|
57
|
-
* @param viewElement The view element to update.
|
|
58
|
-
*/
|
|
59
|
-
function removeViewAttributes(writer, viewAttributes, viewElement) {
|
|
60
|
-
if (viewAttributes.attributes) {
|
|
61
|
-
for (const [key] of Object.entries(viewAttributes.attributes)) {
|
|
62
|
-
writer.removeAttribute(key, viewElement);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (viewAttributes.styles) {
|
|
66
|
-
for (const style of Object.keys(viewAttributes.styles)) {
|
|
67
|
-
writer.removeStyle(style, viewElement);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (viewAttributes.classes) {
|
|
71
|
-
writer.removeClass(viewAttributes.classes, viewElement);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Merges view element attribute objects.
|
|
76
|
-
*/
|
|
77
|
-
function mergeViewElementAttributes(target, source) {
|
|
78
|
-
const result = cloneDeep(target);
|
|
79
|
-
let key = 'attributes';
|
|
80
|
-
for (key in source) {
|
|
81
|
-
// Merge classes.
|
|
82
|
-
if (key == 'classes') {
|
|
83
|
-
result[key] = Array.from(new Set([...(target[key] || []), ...source[key]]));
|
|
84
|
-
}
|
|
85
|
-
// Merge attributes or styles.
|
|
86
|
-
else {
|
|
87
|
-
result[key] = { ...target[key], ...source[key] };
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return result;
|
|
91
|
-
}
|
|
92
|
-
function modifyGhsAttribute(writer, item, ghsAttributeName, subject, callback) {
|
|
93
|
-
const oldValue = item.getAttribute(ghsAttributeName);
|
|
94
|
-
const newValue = {};
|
|
95
|
-
for (const kind of ['attributes', 'styles', 'classes']) {
|
|
96
|
-
// Properties other than `subject` should be assigned from `oldValue`.
|
|
97
|
-
if (kind != subject) {
|
|
98
|
-
if (oldValue && oldValue[kind]) {
|
|
99
|
-
newValue[kind] = oldValue[kind];
|
|
100
|
-
}
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
// `callback` should be applied on property [`subject`].
|
|
104
|
-
if (subject == 'classes') {
|
|
105
|
-
const values = new Set(oldValue && oldValue.classes || []);
|
|
106
|
-
callback(values);
|
|
107
|
-
if (values.size) {
|
|
108
|
-
newValue[kind] = Array.from(values);
|
|
109
|
-
}
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
const values = new Map(Object.entries(oldValue && oldValue[kind] || {}));
|
|
113
|
-
callback(values);
|
|
114
|
-
if (values.size) {
|
|
115
|
-
newValue[kind] = Object.fromEntries(values);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (Object.keys(newValue).length) {
|
|
119
|
-
if (item.is('documentSelection')) {
|
|
120
|
-
writer.setSelectionAttribute(ghsAttributeName, newValue);
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
writer.setAttribute(ghsAttributeName, newValue, item);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
else if (oldValue) {
|
|
127
|
-
if (item.is('documentSelection')) {
|
|
128
|
-
writer.removeSelectionAttribute(ghsAttributeName);
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
writer.removeAttribute(ghsAttributeName, item);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Transforms passed string to PascalCase format. Examples:
|
|
137
|
-
* * `div` => `Div`
|
|
138
|
-
* * `h1` => `H1`
|
|
139
|
-
* * `table` => `Table`
|
|
140
|
-
*/
|
|
141
|
-
function toPascalCase(data) {
|
|
142
|
-
return startCase(data).replace(/ /g, '');
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Returns the attribute name of the model element that holds raw HTML attributes.
|
|
146
|
-
*/
|
|
147
|
-
function getHtmlAttributeName(viewElementName) {
|
|
148
|
-
return `html${toPascalCase(viewElementName)}Attributes`;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
153
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
154
|
-
*/
|
|
155
|
-
/**
|
|
156
|
-
* View-to-model conversion helper for object elements.
|
|
157
|
-
*
|
|
158
|
-
* Preserves object element content in `htmlContent` attribute.
|
|
159
|
-
*
|
|
160
|
-
* @returns Returns a conversion callback.
|
|
161
|
-
*/
|
|
162
|
-
function viewToModelObjectConverter({ model: modelName }) {
|
|
163
|
-
return (viewElement, conversionApi) => {
|
|
164
|
-
// Let's keep element HTML and its attributes, so we can rebuild element in downcast conversions.
|
|
165
|
-
return conversionApi.writer.createElement(modelName, {
|
|
166
|
-
htmlContent: viewElement.getCustomProperty('$rawContent')
|
|
167
|
-
});
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Conversion helper converting an object element to an HTML object widget.
|
|
172
|
-
*
|
|
173
|
-
* @returns Returns a conversion callback.
|
|
174
|
-
*/
|
|
175
|
-
function toObjectWidgetConverter(editor, { view: viewName, isInline }) {
|
|
176
|
-
const t = editor.t;
|
|
177
|
-
return (modelElement, { writer }) => {
|
|
178
|
-
const widgetLabel = t('HTML object');
|
|
179
|
-
const viewElement = createObjectView(viewName, modelElement, writer);
|
|
180
|
-
const viewAttributes = modelElement.getAttribute(getHtmlAttributeName(viewName));
|
|
181
|
-
writer.addClass('html-object-embed__content', viewElement);
|
|
182
|
-
if (viewAttributes) {
|
|
183
|
-
setViewAttributes(writer, viewAttributes, viewElement);
|
|
184
|
-
}
|
|
185
|
-
// Widget cannot be a raw element because the widget system would not be able
|
|
186
|
-
// to add its UI to it. Thus, we need separate view container.
|
|
187
|
-
const viewContainer = writer.createContainerElement(isInline ? 'span' : 'div', {
|
|
188
|
-
class: 'html-object-embed',
|
|
189
|
-
'data-html-object-embed-label': widgetLabel
|
|
190
|
-
}, viewElement);
|
|
191
|
-
return toWidget(viewContainer, writer, { label: widgetLabel });
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Creates object view element from the given model element.
|
|
196
|
-
*/
|
|
197
|
-
function createObjectView(viewName, modelElement, writer) {
|
|
198
|
-
return writer.createRawElement(viewName, null, (domElement, domConverter) => {
|
|
199
|
-
domConverter.setContentOf(domElement, modelElement.getAttribute('htmlContent'));
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* View-to-attribute conversion helper preserving inline element attributes on `$text`.
|
|
204
|
-
*
|
|
205
|
-
* @returns Returns a conversion callback.
|
|
206
|
-
*/
|
|
207
|
-
function viewToAttributeInlineConverter({ view: viewName, model: attributeKey, allowEmpty }, dataFilter) {
|
|
208
|
-
return dispatcher => {
|
|
209
|
-
dispatcher.on(`element:${viewName}`, (evt, data, conversionApi) => {
|
|
210
|
-
let viewAttributes = dataFilter.processViewAttributes(data.viewItem, conversionApi);
|
|
211
|
-
// Do not apply the attribute if the element itself is already consumed and there are no view attributes to store.
|
|
212
|
-
if (!viewAttributes && !conversionApi.consumable.test(data.viewItem, { name: true })) {
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
// Otherwise, we might need to convert it to an empty object just to preserve element itself,
|
|
216
|
-
// for example `<cite>` => <$text htmlCite="{}">.
|
|
217
|
-
viewAttributes = viewAttributes || {};
|
|
218
|
-
// Consume the element itself if it wasn't consumed by any other converter.
|
|
219
|
-
conversionApi.consumable.consume(data.viewItem, { name: true });
|
|
220
|
-
// Since we are converting to attribute we need a range on which we will set the attribute.
|
|
221
|
-
// If the range is not created yet, we will create it.
|
|
222
|
-
if (!data.modelRange) {
|
|
223
|
-
data = Object.assign(data, conversionApi.convertChildren(data.viewItem, data.modelCursor));
|
|
224
|
-
}
|
|
225
|
-
// Convert empty inline element if allowed and has any attributes.
|
|
226
|
-
if (allowEmpty && data.modelRange.isCollapsed && Object.keys(viewAttributes).length) {
|
|
227
|
-
const modelElement = conversionApi.writer.createElement('htmlEmptyElement');
|
|
228
|
-
if (!conversionApi.safeInsert(modelElement, data.modelCursor)) {
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
const parts = conversionApi.getSplitParts(modelElement);
|
|
232
|
-
data.modelRange = conversionApi.writer.createRange(data.modelRange.start, conversionApi.writer.createPositionAfter(parts[parts.length - 1]));
|
|
233
|
-
conversionApi.updateConversionResult(modelElement, data);
|
|
234
|
-
setAttributeOnItem(modelElement, viewAttributes, conversionApi);
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
// Set attribute on each item in range according to the schema.
|
|
238
|
-
for (const node of data.modelRange.getItems()) {
|
|
239
|
-
setAttributeOnItem(node, viewAttributes, conversionApi);
|
|
240
|
-
}
|
|
241
|
-
}, { priority: 'low' });
|
|
242
|
-
};
|
|
243
|
-
function setAttributeOnItem(node, viewAttributes, conversionApi) {
|
|
244
|
-
if (conversionApi.schema.checkAttribute(node, attributeKey)) {
|
|
245
|
-
// Node's children are converted recursively, so node can already include model attribute.
|
|
246
|
-
// We want to extend it, not replace.
|
|
247
|
-
const nodeAttributes = node.getAttribute(attributeKey);
|
|
248
|
-
const attributesToAdd = mergeViewElementAttributes(viewAttributes, nodeAttributes || {});
|
|
249
|
-
conversionApi.writer.setAttribute(attributeKey, attributesToAdd, node);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Conversion helper converting an empty inline model element to an HTML element or widget.
|
|
255
|
-
*/
|
|
256
|
-
function emptyInlineModelElementToViewConverter({ model: attributeKey, view: viewName }, asWidget) {
|
|
257
|
-
return (item, { writer, consumable }) => {
|
|
258
|
-
if (!item.hasAttribute(attributeKey)) {
|
|
259
|
-
return null;
|
|
260
|
-
}
|
|
261
|
-
const viewElement = writer.createContainerElement(viewName);
|
|
262
|
-
const attributeValue = item.getAttribute(attributeKey);
|
|
263
|
-
consumable.consume(item, `attribute:${attributeKey}`);
|
|
264
|
-
setViewAttributes(writer, attributeValue, viewElement);
|
|
265
|
-
viewElement.getFillerOffset = () => null;
|
|
266
|
-
return asWidget ? toWidget(viewElement, writer) : viewElement;
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Attribute-to-view conversion helper applying attributes to view element preserved on `$text`.
|
|
271
|
-
*
|
|
272
|
-
* @returns Returns a conversion callback.
|
|
273
|
-
*/
|
|
274
|
-
function attributeToViewInlineConverter({ priority, view: viewName }) {
|
|
275
|
-
return (attributeValue, conversionApi) => {
|
|
276
|
-
if (!attributeValue) {
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
279
|
-
const { writer } = conversionApi;
|
|
280
|
-
const viewElement = writer.createAttributeElement(viewName, null, { priority });
|
|
281
|
-
setViewAttributes(writer, attributeValue, viewElement);
|
|
282
|
-
return viewElement;
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* View-to-model conversion helper preserving allowed attributes on block element.
|
|
287
|
-
*
|
|
288
|
-
* All matched attributes will be preserved on `html*Attributes` attribute.
|
|
289
|
-
*
|
|
290
|
-
* @returns Returns a conversion callback.
|
|
291
|
-
*/
|
|
292
|
-
function viewToModelBlockAttributeConverter({ view: viewName }, dataFilter) {
|
|
293
|
-
return (dispatcher) => {
|
|
294
|
-
dispatcher.on(`element:${viewName}`, (evt, data, conversionApi) => {
|
|
295
|
-
// Converting an attribute of an element that has not been converted to anything does not make sense
|
|
296
|
-
// because there will be nowhere to set that attribute on. At this stage, the element should've already
|
|
297
|
-
// been converted. A collapsed range can show up in to-do lists (<input>) or complex widgets (e.g. table).
|
|
298
|
-
// (https://github.com/ckeditor/ckeditor5/issues/11000).
|
|
299
|
-
if (!data.modelRange || data.modelRange.isCollapsed) {
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
const viewAttributes = dataFilter.processViewAttributes(data.viewItem, conversionApi);
|
|
303
|
-
if (!viewAttributes) {
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
conversionApi.writer.setAttribute(getHtmlAttributeName(data.viewItem.name), viewAttributes, data.modelRange);
|
|
307
|
-
}, { priority: 'low' });
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* Model-to-view conversion helper applying attributes preserved in `html*Attributes` attribute
|
|
312
|
-
* for block elements.
|
|
313
|
-
*
|
|
314
|
-
* @returns Returns a conversion callback.
|
|
315
|
-
*/
|
|
316
|
-
function modelToViewBlockAttributeConverter({ view: viewName, model: modelName }) {
|
|
317
|
-
return (dispatcher) => {
|
|
318
|
-
dispatcher.on(`attribute:${getHtmlAttributeName(viewName)}:${modelName}`, (evt, data, conversionApi) => {
|
|
319
|
-
if (!conversionApi.consumable.consume(data.item, evt.name)) {
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
const { attributeOldValue, attributeNewValue } = data;
|
|
323
|
-
const viewWriter = conversionApi.writer;
|
|
324
|
-
const viewElement = conversionApi.mapper.toViewElement(data.item);
|
|
325
|
-
updateViewAttributes(viewWriter, attributeOldValue, attributeNewValue, viewElement);
|
|
326
|
-
});
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
332
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
333
|
-
*/
|
|
334
|
-
/**
|
|
335
|
-
* @module html-support/schemadefinitions
|
|
336
|
-
*/
|
|
337
|
-
// Skipped elements due to HTML deprecation:
|
|
338
|
-
// * noframes (not sure if we should provide support for this element. CKE4 is not supporting frameset and frame,
|
|
339
|
-
// but it will unpack <frameset><noframes>foobar</noframes></frameset> to <noframes>foobar</noframes>, so there
|
|
340
|
-
// may be some content loss. Although using noframes as a standalone element seems invalid)
|
|
341
|
-
// * keygen (this one is also empty)
|
|
342
|
-
// * applet (support is limited mostly to old IE)
|
|
343
|
-
// * basefont (this one is also empty)
|
|
344
|
-
// * isindex (basically no support for modern browsers at all)
|
|
345
|
-
//
|
|
346
|
-
// Skipped elements due to lack empty element support:
|
|
347
|
-
// * hr
|
|
348
|
-
// * area
|
|
349
|
-
// * br
|
|
350
|
-
// * command
|
|
351
|
-
// * map
|
|
352
|
-
// * wbr
|
|
353
|
-
// * colgroup -> col
|
|
354
|
-
//
|
|
355
|
-
// Skipped elements due to complexity:
|
|
356
|
-
// * datalist with option elements used as a data source for input[list] element
|
|
357
|
-
//
|
|
358
|
-
// Skipped elements as they are handled as an object content:
|
|
359
|
-
// * track
|
|
360
|
-
// * source
|
|
361
|
-
// * option
|
|
362
|
-
// * param
|
|
363
|
-
// * optgroup
|
|
364
|
-
//
|
|
365
|
-
// Skipped full page HTML elements:
|
|
366
|
-
// * body
|
|
367
|
-
// * html
|
|
368
|
-
// * title
|
|
369
|
-
// * head
|
|
370
|
-
// * meta
|
|
371
|
-
// * link
|
|
372
|
-
// * etc...
|
|
373
|
-
//
|
|
374
|
-
// Skipped hidden elements:
|
|
375
|
-
// noscript
|
|
376
|
-
var defaultConfig = {
|
|
377
|
-
block: [
|
|
378
|
-
// Existing features.
|
|
379
|
-
{
|
|
380
|
-
model: 'codeBlock',
|
|
381
|
-
view: 'pre'
|
|
382
|
-
},
|
|
383
|
-
{
|
|
384
|
-
model: 'paragraph',
|
|
385
|
-
view: 'p'
|
|
386
|
-
},
|
|
387
|
-
{
|
|
388
|
-
model: 'blockQuote',
|
|
389
|
-
view: 'blockquote'
|
|
390
|
-
},
|
|
391
|
-
{
|
|
392
|
-
model: 'listItem',
|
|
393
|
-
view: 'li'
|
|
394
|
-
},
|
|
395
|
-
{
|
|
396
|
-
model: 'pageBreak',
|
|
397
|
-
view: 'div'
|
|
398
|
-
},
|
|
399
|
-
{
|
|
400
|
-
model: 'rawHtml',
|
|
401
|
-
view: 'div'
|
|
402
|
-
},
|
|
403
|
-
{
|
|
404
|
-
model: 'table',
|
|
405
|
-
view: 'table'
|
|
406
|
-
},
|
|
407
|
-
{
|
|
408
|
-
model: 'tableRow',
|
|
409
|
-
view: 'tr'
|
|
410
|
-
},
|
|
411
|
-
{
|
|
412
|
-
model: 'tableCell',
|
|
413
|
-
view: 'td'
|
|
414
|
-
},
|
|
415
|
-
{
|
|
416
|
-
model: 'tableCell',
|
|
417
|
-
view: 'th'
|
|
418
|
-
},
|
|
419
|
-
{
|
|
420
|
-
model: 'tableColumnGroup',
|
|
421
|
-
view: 'colgroup'
|
|
422
|
-
},
|
|
423
|
-
{
|
|
424
|
-
model: 'tableColumn',
|
|
425
|
-
view: 'col'
|
|
426
|
-
},
|
|
427
|
-
{
|
|
428
|
-
model: 'caption',
|
|
429
|
-
view: 'caption'
|
|
430
|
-
},
|
|
431
|
-
{
|
|
432
|
-
model: 'caption',
|
|
433
|
-
view: 'figcaption'
|
|
434
|
-
},
|
|
435
|
-
{
|
|
436
|
-
model: 'imageBlock',
|
|
437
|
-
view: 'img'
|
|
438
|
-
},
|
|
439
|
-
{
|
|
440
|
-
model: 'imageInline',
|
|
441
|
-
view: 'img'
|
|
442
|
-
},
|
|
443
|
-
// Compatibility features.
|
|
444
|
-
{
|
|
445
|
-
model: 'htmlP',
|
|
446
|
-
view: 'p',
|
|
447
|
-
modelSchema: {
|
|
448
|
-
inheritAllFrom: '$block'
|
|
449
|
-
}
|
|
450
|
-
},
|
|
451
|
-
{
|
|
452
|
-
model: 'htmlBlockquote',
|
|
453
|
-
view: 'blockquote',
|
|
454
|
-
modelSchema: {
|
|
455
|
-
inheritAllFrom: '$container'
|
|
456
|
-
}
|
|
457
|
-
},
|
|
458
|
-
{
|
|
459
|
-
model: 'htmlTable',
|
|
460
|
-
view: 'table',
|
|
461
|
-
modelSchema: {
|
|
462
|
-
allowWhere: '$block',
|
|
463
|
-
isBlock: true
|
|
464
|
-
}
|
|
465
|
-
},
|
|
466
|
-
{
|
|
467
|
-
model: 'htmlTbody',
|
|
468
|
-
view: 'tbody',
|
|
469
|
-
modelSchema: {
|
|
470
|
-
allowIn: 'htmlTable',
|
|
471
|
-
isBlock: false
|
|
472
|
-
}
|
|
473
|
-
},
|
|
474
|
-
{
|
|
475
|
-
model: 'htmlThead',
|
|
476
|
-
view: 'thead',
|
|
477
|
-
modelSchema: {
|
|
478
|
-
allowIn: 'htmlTable',
|
|
479
|
-
isBlock: false
|
|
480
|
-
}
|
|
481
|
-
},
|
|
482
|
-
{
|
|
483
|
-
model: 'htmlTfoot',
|
|
484
|
-
view: 'tfoot',
|
|
485
|
-
modelSchema: {
|
|
486
|
-
allowIn: 'htmlTable',
|
|
487
|
-
isBlock: false
|
|
488
|
-
}
|
|
489
|
-
},
|
|
490
|
-
{
|
|
491
|
-
model: 'htmlCaption',
|
|
492
|
-
view: 'caption',
|
|
493
|
-
modelSchema: {
|
|
494
|
-
allowIn: 'htmlTable',
|
|
495
|
-
allowChildren: '$text',
|
|
496
|
-
isBlock: false
|
|
497
|
-
}
|
|
498
|
-
},
|
|
499
|
-
{
|
|
500
|
-
model: 'htmlColgroup',
|
|
501
|
-
view: 'colgroup',
|
|
502
|
-
modelSchema: {
|
|
503
|
-
allowIn: 'htmlTable',
|
|
504
|
-
allowChildren: 'col',
|
|
505
|
-
isBlock: false
|
|
506
|
-
}
|
|
507
|
-
},
|
|
508
|
-
{
|
|
509
|
-
model: 'htmlCol',
|
|
510
|
-
view: 'col',
|
|
511
|
-
modelSchema: {
|
|
512
|
-
allowIn: 'htmlColgroup',
|
|
513
|
-
isBlock: false
|
|
514
|
-
}
|
|
515
|
-
},
|
|
516
|
-
{
|
|
517
|
-
model: 'htmlTr',
|
|
518
|
-
view: 'tr',
|
|
519
|
-
modelSchema: {
|
|
520
|
-
allowIn: ['htmlTable', 'htmlThead', 'htmlTbody'],
|
|
521
|
-
isLimit: true
|
|
522
|
-
}
|
|
523
|
-
},
|
|
524
|
-
// TODO can also include text.
|
|
525
|
-
{
|
|
526
|
-
model: 'htmlTd',
|
|
527
|
-
view: 'td',
|
|
528
|
-
modelSchema: {
|
|
529
|
-
allowIn: 'htmlTr',
|
|
530
|
-
allowContentOf: '$container',
|
|
531
|
-
isLimit: true,
|
|
532
|
-
isBlock: false
|
|
533
|
-
}
|
|
534
|
-
},
|
|
535
|
-
// TODO can also include text.
|
|
536
|
-
{
|
|
537
|
-
model: 'htmlTh',
|
|
538
|
-
view: 'th',
|
|
539
|
-
modelSchema: {
|
|
540
|
-
allowIn: 'htmlTr',
|
|
541
|
-
allowContentOf: '$container',
|
|
542
|
-
isLimit: true,
|
|
543
|
-
isBlock: false
|
|
544
|
-
}
|
|
545
|
-
},
|
|
546
|
-
// TODO can also include text.
|
|
547
|
-
{
|
|
548
|
-
model: 'htmlFigure',
|
|
549
|
-
view: 'figure',
|
|
550
|
-
modelSchema: {
|
|
551
|
-
inheritAllFrom: '$container',
|
|
552
|
-
isBlock: false
|
|
553
|
-
}
|
|
554
|
-
},
|
|
555
|
-
// TODO can also include other block elements.
|
|
556
|
-
{
|
|
557
|
-
model: 'htmlFigcaption',
|
|
558
|
-
view: 'figcaption',
|
|
559
|
-
modelSchema: {
|
|
560
|
-
allowIn: 'htmlFigure',
|
|
561
|
-
allowChildren: '$text',
|
|
562
|
-
isBlock: false
|
|
563
|
-
}
|
|
564
|
-
},
|
|
565
|
-
// TODO can also include text.
|
|
566
|
-
{
|
|
567
|
-
model: 'htmlAddress',
|
|
568
|
-
view: 'address',
|
|
569
|
-
modelSchema: {
|
|
570
|
-
inheritAllFrom: '$container',
|
|
571
|
-
isBlock: false
|
|
572
|
-
}
|
|
573
|
-
},
|
|
574
|
-
// TODO can also include text.
|
|
575
|
-
{
|
|
576
|
-
model: 'htmlAside',
|
|
577
|
-
view: 'aside',
|
|
578
|
-
modelSchema: {
|
|
579
|
-
inheritAllFrom: '$container',
|
|
580
|
-
isBlock: false
|
|
581
|
-
}
|
|
582
|
-
},
|
|
583
|
-
// TODO can also include text.
|
|
584
|
-
{
|
|
585
|
-
model: 'htmlMain',
|
|
586
|
-
view: 'main',
|
|
587
|
-
modelSchema: {
|
|
588
|
-
inheritAllFrom: '$container',
|
|
589
|
-
isBlock: false
|
|
590
|
-
}
|
|
591
|
-
},
|
|
592
|
-
// TODO can also include text.
|
|
593
|
-
{
|
|
594
|
-
model: 'htmlDetails',
|
|
595
|
-
view: 'details',
|
|
596
|
-
modelSchema: {
|
|
597
|
-
inheritAllFrom: '$container',
|
|
598
|
-
isBlock: false
|
|
599
|
-
}
|
|
600
|
-
},
|
|
601
|
-
{
|
|
602
|
-
model: 'htmlSummary',
|
|
603
|
-
view: 'summary',
|
|
604
|
-
modelSchema: {
|
|
605
|
-
allowChildren: '$text',
|
|
606
|
-
allowIn: 'htmlDetails',
|
|
607
|
-
isBlock: false
|
|
608
|
-
}
|
|
609
|
-
},
|
|
610
|
-
{
|
|
611
|
-
model: 'htmlDiv',
|
|
612
|
-
view: 'div',
|
|
613
|
-
paragraphLikeModel: 'htmlDivParagraph',
|
|
614
|
-
modelSchema: {
|
|
615
|
-
inheritAllFrom: '$container'
|
|
616
|
-
}
|
|
617
|
-
},
|
|
618
|
-
// TODO can also include text.
|
|
619
|
-
{
|
|
620
|
-
model: 'htmlFieldset',
|
|
621
|
-
view: 'fieldset',
|
|
622
|
-
modelSchema: {
|
|
623
|
-
inheritAllFrom: '$container',
|
|
624
|
-
isBlock: false
|
|
625
|
-
}
|
|
626
|
-
},
|
|
627
|
-
// TODO can also include h1-h6.
|
|
628
|
-
{
|
|
629
|
-
model: 'htmlLegend',
|
|
630
|
-
view: 'legend',
|
|
631
|
-
modelSchema: {
|
|
632
|
-
allowIn: 'htmlFieldset',
|
|
633
|
-
allowChildren: '$text'
|
|
634
|
-
}
|
|
635
|
-
},
|
|
636
|
-
// TODO can also include text.
|
|
637
|
-
{
|
|
638
|
-
model: 'htmlHeader',
|
|
639
|
-
view: 'header',
|
|
640
|
-
modelSchema: {
|
|
641
|
-
inheritAllFrom: '$container',
|
|
642
|
-
isBlock: false
|
|
643
|
-
}
|
|
644
|
-
},
|
|
645
|
-
// TODO can also include text.
|
|
646
|
-
{
|
|
647
|
-
model: 'htmlFooter',
|
|
648
|
-
view: 'footer',
|
|
649
|
-
modelSchema: {
|
|
650
|
-
inheritAllFrom: '$container',
|
|
651
|
-
isBlock: false
|
|
652
|
-
}
|
|
653
|
-
},
|
|
654
|
-
// TODO can also include text.
|
|
655
|
-
{
|
|
656
|
-
model: 'htmlForm',
|
|
657
|
-
view: 'form',
|
|
658
|
-
modelSchema: {
|
|
659
|
-
inheritAllFrom: '$container',
|
|
660
|
-
isBlock: true
|
|
661
|
-
}
|
|
662
|
-
},
|
|
663
|
-
{
|
|
664
|
-
model: 'htmlHgroup',
|
|
665
|
-
view: 'hgroup',
|
|
666
|
-
modelSchema: {
|
|
667
|
-
allowChildren: [
|
|
668
|
-
'htmlH1',
|
|
669
|
-
'htmlH2',
|
|
670
|
-
'htmlH3',
|
|
671
|
-
'htmlH4',
|
|
672
|
-
'htmlH5',
|
|
673
|
-
'htmlH6'
|
|
674
|
-
],
|
|
675
|
-
isBlock: false
|
|
676
|
-
}
|
|
677
|
-
},
|
|
678
|
-
{
|
|
679
|
-
model: 'htmlH1',
|
|
680
|
-
view: 'h1',
|
|
681
|
-
modelSchema: {
|
|
682
|
-
inheritAllFrom: '$block'
|
|
683
|
-
}
|
|
684
|
-
},
|
|
685
|
-
{
|
|
686
|
-
model: 'htmlH2',
|
|
687
|
-
view: 'h2',
|
|
688
|
-
modelSchema: {
|
|
689
|
-
inheritAllFrom: '$block'
|
|
690
|
-
}
|
|
691
|
-
},
|
|
692
|
-
{
|
|
693
|
-
model: 'htmlH3',
|
|
694
|
-
view: 'h3',
|
|
695
|
-
modelSchema: {
|
|
696
|
-
inheritAllFrom: '$block'
|
|
697
|
-
}
|
|
698
|
-
},
|
|
699
|
-
{
|
|
700
|
-
model: 'htmlH4',
|
|
701
|
-
view: 'h4',
|
|
702
|
-
modelSchema: {
|
|
703
|
-
inheritAllFrom: '$block'
|
|
704
|
-
}
|
|
705
|
-
},
|
|
706
|
-
{
|
|
707
|
-
model: 'htmlH5',
|
|
708
|
-
view: 'h5',
|
|
709
|
-
modelSchema: {
|
|
710
|
-
inheritAllFrom: '$block'
|
|
711
|
-
}
|
|
712
|
-
},
|
|
713
|
-
{
|
|
714
|
-
model: 'htmlH6',
|
|
715
|
-
view: 'h6',
|
|
716
|
-
modelSchema: {
|
|
717
|
-
inheritAllFrom: '$block'
|
|
718
|
-
}
|
|
719
|
-
},
|
|
720
|
-
{
|
|
721
|
-
model: '$htmlList',
|
|
722
|
-
modelSchema: {
|
|
723
|
-
allowWhere: '$container',
|
|
724
|
-
allowChildren: ['$htmlList', 'htmlLi'],
|
|
725
|
-
isBlock: false
|
|
726
|
-
}
|
|
727
|
-
},
|
|
728
|
-
{
|
|
729
|
-
model: 'htmlDir',
|
|
730
|
-
view: 'dir',
|
|
731
|
-
modelSchema: {
|
|
732
|
-
inheritAllFrom: '$htmlList'
|
|
733
|
-
}
|
|
734
|
-
},
|
|
735
|
-
{
|
|
736
|
-
model: 'htmlMenu',
|
|
737
|
-
view: 'menu',
|
|
738
|
-
modelSchema: {
|
|
739
|
-
inheritAllFrom: '$htmlList'
|
|
740
|
-
}
|
|
741
|
-
},
|
|
742
|
-
{
|
|
743
|
-
model: 'htmlUl',
|
|
744
|
-
view: 'ul',
|
|
745
|
-
modelSchema: {
|
|
746
|
-
inheritAllFrom: '$htmlList'
|
|
747
|
-
}
|
|
748
|
-
},
|
|
749
|
-
{
|
|
750
|
-
model: 'htmlOl',
|
|
751
|
-
view: 'ol',
|
|
752
|
-
modelSchema: {
|
|
753
|
-
inheritAllFrom: '$htmlList'
|
|
754
|
-
}
|
|
755
|
-
},
|
|
756
|
-
// TODO can also include other block elements.
|
|
757
|
-
{
|
|
758
|
-
model: 'htmlLi',
|
|
759
|
-
view: 'li',
|
|
760
|
-
modelSchema: {
|
|
761
|
-
allowIn: '$htmlList',
|
|
762
|
-
allowChildren: '$text',
|
|
763
|
-
isBlock: false
|
|
764
|
-
}
|
|
765
|
-
},
|
|
766
|
-
{
|
|
767
|
-
model: 'htmlPre',
|
|
768
|
-
view: 'pre',
|
|
769
|
-
modelSchema: {
|
|
770
|
-
inheritAllFrom: '$block'
|
|
771
|
-
}
|
|
772
|
-
},
|
|
773
|
-
{
|
|
774
|
-
model: 'htmlArticle',
|
|
775
|
-
view: 'article',
|
|
776
|
-
modelSchema: {
|
|
777
|
-
inheritAllFrom: '$container',
|
|
778
|
-
isBlock: false
|
|
779
|
-
}
|
|
780
|
-
},
|
|
781
|
-
{
|
|
782
|
-
model: 'htmlSection',
|
|
783
|
-
view: 'section',
|
|
784
|
-
modelSchema: {
|
|
785
|
-
inheritAllFrom: '$container',
|
|
786
|
-
isBlock: false
|
|
787
|
-
}
|
|
788
|
-
},
|
|
789
|
-
// TODO can also include text.
|
|
790
|
-
{
|
|
791
|
-
model: 'htmlNav',
|
|
792
|
-
view: 'nav',
|
|
793
|
-
modelSchema: {
|
|
794
|
-
inheritAllFrom: '$container',
|
|
795
|
-
isBlock: false
|
|
796
|
-
}
|
|
797
|
-
},
|
|
798
|
-
{
|
|
799
|
-
model: 'htmlDivDl',
|
|
800
|
-
view: 'div',
|
|
801
|
-
modelSchema: {
|
|
802
|
-
allowChildren: ['htmlDt', 'htmlDd'],
|
|
803
|
-
allowIn: 'htmlDl'
|
|
804
|
-
}
|
|
805
|
-
},
|
|
806
|
-
{
|
|
807
|
-
model: 'htmlDl',
|
|
808
|
-
view: 'dl',
|
|
809
|
-
modelSchema: {
|
|
810
|
-
allowWhere: '$container',
|
|
811
|
-
allowChildren: ['htmlDt', 'htmlDd', 'htmlDivDl'],
|
|
812
|
-
isBlock: false
|
|
813
|
-
}
|
|
814
|
-
},
|
|
815
|
-
{
|
|
816
|
-
model: 'htmlDt',
|
|
817
|
-
view: 'dt',
|
|
818
|
-
modelSchema: {
|
|
819
|
-
allowChildren: '$block',
|
|
820
|
-
isBlock: false
|
|
821
|
-
}
|
|
822
|
-
},
|
|
823
|
-
{
|
|
824
|
-
model: 'htmlDd',
|
|
825
|
-
view: 'dd',
|
|
826
|
-
modelSchema: {
|
|
827
|
-
allowChildren: '$block',
|
|
828
|
-
isBlock: false
|
|
829
|
-
}
|
|
830
|
-
},
|
|
831
|
-
{
|
|
832
|
-
model: 'htmlCenter',
|
|
833
|
-
view: 'center',
|
|
834
|
-
modelSchema: {
|
|
835
|
-
inheritAllFrom: '$container',
|
|
836
|
-
isBlock: false
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
],
|
|
840
|
-
inline: [
|
|
841
|
-
// Existing features (attribute set on an existing model element).
|
|
842
|
-
{
|
|
843
|
-
model: 'htmlLiAttributes',
|
|
844
|
-
view: 'li',
|
|
845
|
-
appliesToBlock: true,
|
|
846
|
-
coupledAttribute: 'listItemId'
|
|
847
|
-
},
|
|
848
|
-
{
|
|
849
|
-
model: 'htmlOlAttributes',
|
|
850
|
-
view: 'ol',
|
|
851
|
-
appliesToBlock: true,
|
|
852
|
-
coupledAttribute: 'listItemId'
|
|
853
|
-
},
|
|
854
|
-
{
|
|
855
|
-
model: 'htmlUlAttributes',
|
|
856
|
-
view: 'ul',
|
|
857
|
-
appliesToBlock: true,
|
|
858
|
-
coupledAttribute: 'listItemId'
|
|
859
|
-
},
|
|
860
|
-
{
|
|
861
|
-
model: 'htmlFigureAttributes',
|
|
862
|
-
view: 'figure',
|
|
863
|
-
appliesToBlock: 'table'
|
|
864
|
-
},
|
|
865
|
-
{
|
|
866
|
-
model: 'htmlTheadAttributes',
|
|
867
|
-
view: 'thead',
|
|
868
|
-
appliesToBlock: 'table'
|
|
869
|
-
},
|
|
870
|
-
{
|
|
871
|
-
model: 'htmlTbodyAttributes',
|
|
872
|
-
view: 'tbody',
|
|
873
|
-
appliesToBlock: 'table'
|
|
874
|
-
},
|
|
875
|
-
{
|
|
876
|
-
model: 'htmlFigureAttributes',
|
|
877
|
-
view: 'figure',
|
|
878
|
-
appliesToBlock: 'imageBlock'
|
|
879
|
-
},
|
|
880
|
-
// Compatibility features.
|
|
881
|
-
{
|
|
882
|
-
model: 'htmlAcronym',
|
|
883
|
-
view: 'acronym',
|
|
884
|
-
attributeProperties: {
|
|
885
|
-
copyOnEnter: true,
|
|
886
|
-
isFormatting: true
|
|
887
|
-
}
|
|
888
|
-
},
|
|
889
|
-
{
|
|
890
|
-
model: 'htmlTt',
|
|
891
|
-
view: 'tt',
|
|
892
|
-
attributeProperties: {
|
|
893
|
-
copyOnEnter: true,
|
|
894
|
-
isFormatting: true
|
|
895
|
-
}
|
|
896
|
-
},
|
|
897
|
-
{
|
|
898
|
-
model: 'htmlFont',
|
|
899
|
-
view: 'font',
|
|
900
|
-
attributeProperties: {
|
|
901
|
-
copyOnEnter: true,
|
|
902
|
-
isFormatting: true
|
|
903
|
-
}
|
|
904
|
-
},
|
|
905
|
-
{
|
|
906
|
-
model: 'htmlTime',
|
|
907
|
-
view: 'time',
|
|
908
|
-
attributeProperties: {
|
|
909
|
-
copyOnEnter: true,
|
|
910
|
-
isFormatting: true
|
|
911
|
-
}
|
|
912
|
-
},
|
|
913
|
-
{
|
|
914
|
-
model: 'htmlVar',
|
|
915
|
-
view: 'var',
|
|
916
|
-
attributeProperties: {
|
|
917
|
-
copyOnEnter: true,
|
|
918
|
-
isFormatting: true
|
|
919
|
-
}
|
|
920
|
-
},
|
|
921
|
-
{
|
|
922
|
-
model: 'htmlBig',
|
|
923
|
-
view: 'big',
|
|
924
|
-
attributeProperties: {
|
|
925
|
-
copyOnEnter: true,
|
|
926
|
-
isFormatting: true
|
|
927
|
-
}
|
|
928
|
-
},
|
|
929
|
-
{
|
|
930
|
-
model: 'htmlSmall',
|
|
931
|
-
view: 'small',
|
|
932
|
-
attributeProperties: {
|
|
933
|
-
copyOnEnter: true,
|
|
934
|
-
isFormatting: true
|
|
935
|
-
}
|
|
936
|
-
},
|
|
937
|
-
{
|
|
938
|
-
model: 'htmlSamp',
|
|
939
|
-
view: 'samp',
|
|
940
|
-
attributeProperties: {
|
|
941
|
-
copyOnEnter: true,
|
|
942
|
-
isFormatting: true
|
|
943
|
-
}
|
|
944
|
-
},
|
|
945
|
-
{
|
|
946
|
-
model: 'htmlQ',
|
|
947
|
-
view: 'q',
|
|
948
|
-
attributeProperties: {
|
|
949
|
-
copyOnEnter: true,
|
|
950
|
-
isFormatting: true
|
|
951
|
-
}
|
|
952
|
-
},
|
|
953
|
-
{
|
|
954
|
-
model: 'htmlOutput',
|
|
955
|
-
view: 'output',
|
|
956
|
-
attributeProperties: {
|
|
957
|
-
copyOnEnter: true,
|
|
958
|
-
isFormatting: true
|
|
959
|
-
}
|
|
960
|
-
},
|
|
961
|
-
{
|
|
962
|
-
model: 'htmlKbd',
|
|
963
|
-
view: 'kbd',
|
|
964
|
-
attributeProperties: {
|
|
965
|
-
copyOnEnter: true,
|
|
966
|
-
isFormatting: true
|
|
967
|
-
}
|
|
968
|
-
},
|
|
969
|
-
{
|
|
970
|
-
model: 'htmlBdi',
|
|
971
|
-
view: 'bdi',
|
|
972
|
-
attributeProperties: {
|
|
973
|
-
copyOnEnter: true,
|
|
974
|
-
isFormatting: true
|
|
975
|
-
}
|
|
976
|
-
},
|
|
977
|
-
{
|
|
978
|
-
model: 'htmlBdo',
|
|
979
|
-
view: 'bdo',
|
|
980
|
-
attributeProperties: {
|
|
981
|
-
copyOnEnter: true,
|
|
982
|
-
isFormatting: true
|
|
983
|
-
}
|
|
984
|
-
},
|
|
985
|
-
{
|
|
986
|
-
model: 'htmlAbbr',
|
|
987
|
-
view: 'abbr',
|
|
988
|
-
attributeProperties: {
|
|
989
|
-
copyOnEnter: true,
|
|
990
|
-
isFormatting: true
|
|
991
|
-
}
|
|
992
|
-
},
|
|
993
|
-
{
|
|
994
|
-
model: 'htmlA',
|
|
995
|
-
view: 'a',
|
|
996
|
-
priority: 5,
|
|
997
|
-
coupledAttribute: 'linkHref'
|
|
998
|
-
},
|
|
999
|
-
{
|
|
1000
|
-
model: 'htmlStrong',
|
|
1001
|
-
view: 'strong',
|
|
1002
|
-
coupledAttribute: 'bold',
|
|
1003
|
-
attributeProperties: {
|
|
1004
|
-
copyOnEnter: true,
|
|
1005
|
-
isFormatting: true
|
|
1006
|
-
}
|
|
1007
|
-
},
|
|
1008
|
-
{
|
|
1009
|
-
model: 'htmlB',
|
|
1010
|
-
view: 'b',
|
|
1011
|
-
coupledAttribute: 'bold',
|
|
1012
|
-
attributeProperties: {
|
|
1013
|
-
copyOnEnter: true,
|
|
1014
|
-
isFormatting: true
|
|
1015
|
-
}
|
|
1016
|
-
},
|
|
1017
|
-
{
|
|
1018
|
-
model: 'htmlI',
|
|
1019
|
-
view: 'i',
|
|
1020
|
-
coupledAttribute: 'italic',
|
|
1021
|
-
attributeProperties: {
|
|
1022
|
-
copyOnEnter: true,
|
|
1023
|
-
isFormatting: true
|
|
1024
|
-
}
|
|
1025
|
-
},
|
|
1026
|
-
{
|
|
1027
|
-
model: 'htmlEm',
|
|
1028
|
-
view: 'em',
|
|
1029
|
-
coupledAttribute: 'italic',
|
|
1030
|
-
attributeProperties: {
|
|
1031
|
-
copyOnEnter: true,
|
|
1032
|
-
isFormatting: true
|
|
1033
|
-
}
|
|
1034
|
-
},
|
|
1035
|
-
{
|
|
1036
|
-
model: 'htmlS',
|
|
1037
|
-
view: 's',
|
|
1038
|
-
coupledAttribute: 'strikethrough',
|
|
1039
|
-
attributeProperties: {
|
|
1040
|
-
copyOnEnter: true,
|
|
1041
|
-
isFormatting: true
|
|
1042
|
-
}
|
|
1043
|
-
},
|
|
1044
|
-
// TODO According to HTML-spec can behave as div-like element, although CKE4 only handles it as an inline element.
|
|
1045
|
-
{
|
|
1046
|
-
model: 'htmlDel',
|
|
1047
|
-
view: 'del',
|
|
1048
|
-
coupledAttribute: 'strikethrough',
|
|
1049
|
-
attributeProperties: {
|
|
1050
|
-
copyOnEnter: true,
|
|
1051
|
-
isFormatting: true
|
|
1052
|
-
}
|
|
1053
|
-
},
|
|
1054
|
-
// TODO According to HTML-spec can behave as div-like element, although CKE4 only handles it as an inline element.
|
|
1055
|
-
{
|
|
1056
|
-
model: 'htmlIns',
|
|
1057
|
-
view: 'ins',
|
|
1058
|
-
attributeProperties: {
|
|
1059
|
-
copyOnEnter: true,
|
|
1060
|
-
isFormatting: true
|
|
1061
|
-
}
|
|
1062
|
-
},
|
|
1063
|
-
{
|
|
1064
|
-
model: 'htmlU',
|
|
1065
|
-
view: 'u',
|
|
1066
|
-
coupledAttribute: 'underline',
|
|
1067
|
-
attributeProperties: {
|
|
1068
|
-
copyOnEnter: true,
|
|
1069
|
-
isFormatting: true
|
|
1070
|
-
}
|
|
1071
|
-
},
|
|
1072
|
-
{
|
|
1073
|
-
model: 'htmlSub',
|
|
1074
|
-
view: 'sub',
|
|
1075
|
-
coupledAttribute: 'subscript',
|
|
1076
|
-
attributeProperties: {
|
|
1077
|
-
copyOnEnter: true,
|
|
1078
|
-
isFormatting: true
|
|
1079
|
-
}
|
|
1080
|
-
},
|
|
1081
|
-
{
|
|
1082
|
-
model: 'htmlSup',
|
|
1083
|
-
view: 'sup',
|
|
1084
|
-
coupledAttribute: 'superscript',
|
|
1085
|
-
attributeProperties: {
|
|
1086
|
-
copyOnEnter: true,
|
|
1087
|
-
isFormatting: true
|
|
1088
|
-
}
|
|
1089
|
-
},
|
|
1090
|
-
{
|
|
1091
|
-
model: 'htmlCode',
|
|
1092
|
-
view: 'code',
|
|
1093
|
-
coupledAttribute: 'code',
|
|
1094
|
-
attributeProperties: {
|
|
1095
|
-
copyOnEnter: true,
|
|
1096
|
-
isFormatting: true
|
|
1097
|
-
}
|
|
1098
|
-
},
|
|
1099
|
-
{
|
|
1100
|
-
model: 'htmlMark',
|
|
1101
|
-
view: 'mark',
|
|
1102
|
-
attributeProperties: {
|
|
1103
|
-
copyOnEnter: true,
|
|
1104
|
-
isFormatting: true
|
|
1105
|
-
}
|
|
1106
|
-
},
|
|
1107
|
-
{
|
|
1108
|
-
model: 'htmlSpan',
|
|
1109
|
-
view: 'span',
|
|
1110
|
-
attributeProperties: {
|
|
1111
|
-
copyOnEnter: true,
|
|
1112
|
-
isFormatting: true
|
|
1113
|
-
}
|
|
1114
|
-
},
|
|
1115
|
-
{
|
|
1116
|
-
model: 'htmlCite',
|
|
1117
|
-
view: 'cite',
|
|
1118
|
-
attributeProperties: {
|
|
1119
|
-
copyOnEnter: true,
|
|
1120
|
-
isFormatting: true
|
|
1121
|
-
}
|
|
1122
|
-
},
|
|
1123
|
-
{
|
|
1124
|
-
model: 'htmlLabel',
|
|
1125
|
-
view: 'label',
|
|
1126
|
-
attributeProperties: {
|
|
1127
|
-
copyOnEnter: true,
|
|
1128
|
-
isFormatting: true
|
|
1129
|
-
}
|
|
1130
|
-
},
|
|
1131
|
-
{
|
|
1132
|
-
model: 'htmlDfn',
|
|
1133
|
-
view: 'dfn',
|
|
1134
|
-
attributeProperties: {
|
|
1135
|
-
copyOnEnter: true,
|
|
1136
|
-
isFormatting: true
|
|
1137
|
-
}
|
|
1138
|
-
},
|
|
1139
|
-
// Objects.
|
|
1140
|
-
{
|
|
1141
|
-
model: 'htmlObject',
|
|
1142
|
-
view: 'object',
|
|
1143
|
-
isObject: true,
|
|
1144
|
-
modelSchema: {
|
|
1145
|
-
inheritAllFrom: '$inlineObject'
|
|
1146
|
-
}
|
|
1147
|
-
},
|
|
1148
|
-
{
|
|
1149
|
-
model: 'htmlIframe',
|
|
1150
|
-
view: 'iframe',
|
|
1151
|
-
isObject: true,
|
|
1152
|
-
modelSchema: {
|
|
1153
|
-
inheritAllFrom: '$inlineObject'
|
|
1154
|
-
}
|
|
1155
|
-
},
|
|
1156
|
-
{
|
|
1157
|
-
model: 'htmlInput',
|
|
1158
|
-
view: 'input',
|
|
1159
|
-
isObject: true,
|
|
1160
|
-
modelSchema: {
|
|
1161
|
-
inheritAllFrom: '$inlineObject'
|
|
1162
|
-
}
|
|
1163
|
-
},
|
|
1164
|
-
{
|
|
1165
|
-
model: 'htmlButton',
|
|
1166
|
-
view: 'button',
|
|
1167
|
-
isObject: true,
|
|
1168
|
-
modelSchema: {
|
|
1169
|
-
inheritAllFrom: '$inlineObject'
|
|
1170
|
-
}
|
|
1171
|
-
},
|
|
1172
|
-
{
|
|
1173
|
-
model: 'htmlTextarea',
|
|
1174
|
-
view: 'textarea',
|
|
1175
|
-
isObject: true,
|
|
1176
|
-
modelSchema: {
|
|
1177
|
-
inheritAllFrom: '$inlineObject'
|
|
1178
|
-
}
|
|
1179
|
-
},
|
|
1180
|
-
{
|
|
1181
|
-
model: 'htmlSelect',
|
|
1182
|
-
view: 'select',
|
|
1183
|
-
isObject: true,
|
|
1184
|
-
modelSchema: {
|
|
1185
|
-
inheritAllFrom: '$inlineObject'
|
|
1186
|
-
}
|
|
1187
|
-
},
|
|
1188
|
-
{
|
|
1189
|
-
model: 'htmlVideo',
|
|
1190
|
-
view: 'video',
|
|
1191
|
-
isObject: true,
|
|
1192
|
-
modelSchema: {
|
|
1193
|
-
inheritAllFrom: '$inlineObject'
|
|
1194
|
-
}
|
|
1195
|
-
},
|
|
1196
|
-
{
|
|
1197
|
-
model: 'htmlEmbed',
|
|
1198
|
-
view: 'embed',
|
|
1199
|
-
isObject: true,
|
|
1200
|
-
modelSchema: {
|
|
1201
|
-
inheritAllFrom: '$inlineObject'
|
|
1202
|
-
}
|
|
1203
|
-
},
|
|
1204
|
-
{
|
|
1205
|
-
model: 'htmlOembed',
|
|
1206
|
-
view: 'oembed',
|
|
1207
|
-
isObject: true,
|
|
1208
|
-
modelSchema: {
|
|
1209
|
-
inheritAllFrom: '$inlineObject'
|
|
1210
|
-
}
|
|
1211
|
-
},
|
|
1212
|
-
{
|
|
1213
|
-
model: 'htmlAudio',
|
|
1214
|
-
view: 'audio',
|
|
1215
|
-
isObject: true,
|
|
1216
|
-
modelSchema: {
|
|
1217
|
-
inheritAllFrom: '$inlineObject'
|
|
1218
|
-
}
|
|
1219
|
-
},
|
|
1220
|
-
{
|
|
1221
|
-
model: 'htmlImg',
|
|
1222
|
-
view: 'img',
|
|
1223
|
-
isObject: true,
|
|
1224
|
-
modelSchema: {
|
|
1225
|
-
inheritAllFrom: '$inlineObject'
|
|
1226
|
-
}
|
|
1227
|
-
},
|
|
1228
|
-
{
|
|
1229
|
-
model: 'htmlCanvas',
|
|
1230
|
-
view: 'canvas',
|
|
1231
|
-
isObject: true,
|
|
1232
|
-
modelSchema: {
|
|
1233
|
-
inheritAllFrom: '$inlineObject'
|
|
1234
|
-
}
|
|
1235
|
-
},
|
|
1236
|
-
// TODO it could be probably represented as non-object element, although it has graphical representation,
|
|
1237
|
-
// so probably makes more sense to keep it as an object.
|
|
1238
|
-
{
|
|
1239
|
-
model: 'htmlMeter',
|
|
1240
|
-
view: 'meter',
|
|
1241
|
-
isObject: true,
|
|
1242
|
-
modelSchema: {
|
|
1243
|
-
inheritAllFrom: '$inlineObject'
|
|
1244
|
-
}
|
|
1245
|
-
},
|
|
1246
|
-
// TODO it could be probably represented as non-object element, although it has graphical representation,
|
|
1247
|
-
// so probably makes more sense to keep it as an object.
|
|
1248
|
-
{
|
|
1249
|
-
model: 'htmlProgress',
|
|
1250
|
-
view: 'progress',
|
|
1251
|
-
isObject: true,
|
|
1252
|
-
modelSchema: {
|
|
1253
|
-
inheritAllFrom: '$inlineObject'
|
|
1254
|
-
}
|
|
1255
|
-
},
|
|
1256
|
-
{
|
|
1257
|
-
model: 'htmlScript',
|
|
1258
|
-
view: 'script',
|
|
1259
|
-
modelSchema: {
|
|
1260
|
-
allowWhere: ['$text', '$block'],
|
|
1261
|
-
isInline: true
|
|
1262
|
-
}
|
|
1263
|
-
},
|
|
1264
|
-
{
|
|
1265
|
-
model: 'htmlStyle',
|
|
1266
|
-
view: 'style',
|
|
1267
|
-
modelSchema: {
|
|
1268
|
-
allowWhere: ['$text', '$block'],
|
|
1269
|
-
isInline: true
|
|
1270
|
-
}
|
|
1271
|
-
},
|
|
1272
|
-
{
|
|
1273
|
-
model: 'htmlCustomElement',
|
|
1274
|
-
view: '$customElement',
|
|
1275
|
-
modelSchema: {
|
|
1276
|
-
allowWhere: ['$text', '$block'],
|
|
1277
|
-
allowAttributesOf: '$inlineObject',
|
|
1278
|
-
isInline: true
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
]
|
|
1282
|
-
};
|
|
1283
|
-
|
|
1284
|
-
/**
|
|
1285
|
-
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
1286
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
1287
|
-
*/
|
|
1288
|
-
/**
|
|
1289
|
-
* @module html-support/dataschema
|
|
1290
|
-
*/
|
|
1291
|
-
/**
|
|
1292
|
-
* Holds representation of the extended HTML document type definitions to be used by the
|
|
1293
|
-
* editor in HTML support.
|
|
1294
|
-
*
|
|
1295
|
-
* Data schema is represented by data schema definitions.
|
|
1296
|
-
*
|
|
1297
|
-
* To add new definition for block element,
|
|
1298
|
-
* use {@link module:html-support/dataschema~DataSchema#registerBlockElement} method:
|
|
1299
|
-
*
|
|
1300
|
-
* ```ts
|
|
1301
|
-
* dataSchema.registerBlockElement( {
|
|
1302
|
-
* view: 'section',
|
|
1303
|
-
* model: 'my-section',
|
|
1304
|
-
* modelSchema: {
|
|
1305
|
-
* inheritAllFrom: '$block'
|
|
1306
|
-
* }
|
|
1307
|
-
* } );
|
|
1308
|
-
* ```
|
|
1309
|
-
*
|
|
1310
|
-
* To add new definition for inline element,
|
|
1311
|
-
* use {@link module:html-support/dataschema~DataSchema#registerInlineElement} method:
|
|
1312
|
-
*
|
|
1313
|
-
* ```
|
|
1314
|
-
* dataSchema.registerInlineElement( {
|
|
1315
|
-
* view: 'span',
|
|
1316
|
-
* model: 'my-span',
|
|
1317
|
-
* attributeProperties: {
|
|
1318
|
-
* copyOnEnter: true
|
|
1319
|
-
* }
|
|
1320
|
-
* } );
|
|
1321
|
-
* ```
|
|
1322
|
-
*/
|
|
1323
|
-
class DataSchema extends Plugin {
|
|
1324
|
-
constructor() {
|
|
1325
|
-
super(...arguments);
|
|
1326
|
-
/**
|
|
1327
|
-
* A map of registered data schema definitions.
|
|
1328
|
-
*/
|
|
1329
|
-
this._definitions = [];
|
|
1330
|
-
}
|
|
1331
|
-
/**
|
|
1332
|
-
* @inheritDoc
|
|
1333
|
-
*/
|
|
1334
|
-
static get pluginName() {
|
|
1335
|
-
return 'DataSchema';
|
|
1336
|
-
}
|
|
1337
|
-
/**
|
|
1338
|
-
* @inheritDoc
|
|
1339
|
-
*/
|
|
1340
|
-
init() {
|
|
1341
|
-
for (const definition of defaultConfig.block) {
|
|
1342
|
-
this.registerBlockElement(definition);
|
|
1343
|
-
}
|
|
1344
|
-
for (const definition of defaultConfig.inline) {
|
|
1345
|
-
this.registerInlineElement(definition);
|
|
1346
|
-
}
|
|
1347
|
-
}
|
|
1348
|
-
/**
|
|
1349
|
-
* Add new data schema definition describing block element.
|
|
1350
|
-
*/
|
|
1351
|
-
registerBlockElement(definition) {
|
|
1352
|
-
this._definitions.push({ ...definition, isBlock: true });
|
|
1353
|
-
}
|
|
1354
|
-
/**
|
|
1355
|
-
* Add new data schema definition describing inline element.
|
|
1356
|
-
*/
|
|
1357
|
-
registerInlineElement(definition) {
|
|
1358
|
-
this._definitions.push({ ...definition, isInline: true });
|
|
1359
|
-
}
|
|
1360
|
-
/**
|
|
1361
|
-
* Updates schema definition describing block element with new properties.
|
|
1362
|
-
*
|
|
1363
|
-
* Creates new scheme if it doesn't exist.
|
|
1364
|
-
* Array properties are concatenated with original values.
|
|
1365
|
-
*
|
|
1366
|
-
* @param definition Definition update.
|
|
1367
|
-
*/
|
|
1368
|
-
extendBlockElement(definition) {
|
|
1369
|
-
this._extendDefinition({ ...definition, isBlock: true });
|
|
1370
|
-
}
|
|
1371
|
-
/**
|
|
1372
|
-
* Updates schema definition describing inline element with new properties.
|
|
1373
|
-
*
|
|
1374
|
-
* Creates new scheme if it doesn't exist.
|
|
1375
|
-
* Array properties are concatenated with original values.
|
|
1376
|
-
*
|
|
1377
|
-
* @param definition Definition update.
|
|
1378
|
-
*/
|
|
1379
|
-
extendInlineElement(definition) {
|
|
1380
|
-
this._extendDefinition({ ...definition, isInline: true });
|
|
1381
|
-
}
|
|
1382
|
-
/**
|
|
1383
|
-
* Returns all definitions matching the given view name.
|
|
1384
|
-
*
|
|
1385
|
-
* @param includeReferences Indicates if this method should also include definitions of referenced models.
|
|
1386
|
-
*/
|
|
1387
|
-
getDefinitionsForView(viewName, includeReferences = false) {
|
|
1388
|
-
const definitions = new Set();
|
|
1389
|
-
for (const definition of this._getMatchingViewDefinitions(viewName)) {
|
|
1390
|
-
if (includeReferences) {
|
|
1391
|
-
for (const reference of this._getReferences(definition.model)) {
|
|
1392
|
-
definitions.add(reference);
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1395
|
-
definitions.add(definition);
|
|
1396
|
-
}
|
|
1397
|
-
return definitions;
|
|
1398
|
-
}
|
|
1399
|
-
/**
|
|
1400
|
-
* Returns definitions matching the given model name.
|
|
1401
|
-
*/
|
|
1402
|
-
getDefinitionsForModel(modelName) {
|
|
1403
|
-
return this._definitions.filter(definition => definition.model == modelName);
|
|
1404
|
-
}
|
|
1405
|
-
/**
|
|
1406
|
-
* Returns definitions matching the given view name.
|
|
1407
|
-
*/
|
|
1408
|
-
_getMatchingViewDefinitions(viewName) {
|
|
1409
|
-
return this._definitions.filter(def => def.view && testViewName(viewName, def.view));
|
|
1410
|
-
}
|
|
1411
|
-
/**
|
|
1412
|
-
* Resolves all definition references registered for the given data schema definition.
|
|
1413
|
-
*
|
|
1414
|
-
* @param modelName Data schema model name.
|
|
1415
|
-
*/
|
|
1416
|
-
*_getReferences(modelName) {
|
|
1417
|
-
const inheritProperties = [
|
|
1418
|
-
'inheritAllFrom',
|
|
1419
|
-
'inheritTypesFrom',
|
|
1420
|
-
'allowWhere',
|
|
1421
|
-
'allowContentOf',
|
|
1422
|
-
'allowAttributesOf'
|
|
1423
|
-
];
|
|
1424
|
-
const definitions = this._definitions.filter(definition => definition.model == modelName);
|
|
1425
|
-
for (const { modelSchema } of definitions) {
|
|
1426
|
-
if (!modelSchema) {
|
|
1427
|
-
continue;
|
|
1428
|
-
}
|
|
1429
|
-
for (const property of inheritProperties) {
|
|
1430
|
-
for (const referenceName of toArray(modelSchema[property] || [])) {
|
|
1431
|
-
const definitions = this._definitions.filter(definition => definition.model == referenceName);
|
|
1432
|
-
for (const definition of definitions) {
|
|
1433
|
-
if (referenceName !== modelName) {
|
|
1434
|
-
yield* this._getReferences(definition.model);
|
|
1435
|
-
yield definition;
|
|
1436
|
-
}
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
}
|
|
1440
|
-
}
|
|
1441
|
-
}
|
|
1442
|
-
/**
|
|
1443
|
-
* Updates schema definition with new properties.
|
|
1444
|
-
*
|
|
1445
|
-
* Creates new scheme if it doesn't exist.
|
|
1446
|
-
* Array properties are concatenated with original values.
|
|
1447
|
-
*
|
|
1448
|
-
* @param definition Definition update.
|
|
1449
|
-
*/
|
|
1450
|
-
_extendDefinition(definition) {
|
|
1451
|
-
const currentDefinitions = Array.from(this._definitions.entries())
|
|
1452
|
-
.filter(([, currentDefinition]) => currentDefinition.model == definition.model);
|
|
1453
|
-
if (currentDefinitions.length == 0) {
|
|
1454
|
-
this._definitions.push(definition);
|
|
1455
|
-
return;
|
|
1456
|
-
}
|
|
1457
|
-
for (const [idx, currentDefinition] of currentDefinitions) {
|
|
1458
|
-
this._definitions[idx] = mergeWith({}, currentDefinition, definition, (target, source) => {
|
|
1459
|
-
return Array.isArray(target) ? target.concat(source) : undefined;
|
|
1460
|
-
});
|
|
1461
|
-
}
|
|
1462
|
-
}
|
|
1463
|
-
}
|
|
1464
|
-
/**
|
|
1465
|
-
* Test view name against the given pattern.
|
|
1466
|
-
*/
|
|
1467
|
-
function testViewName(pattern, viewName) {
|
|
1468
|
-
if (typeof pattern === 'string') {
|
|
1469
|
-
return pattern === viewName;
|
|
1470
|
-
}
|
|
1471
|
-
if (pattern instanceof RegExp) {
|
|
1472
|
-
return pattern.test(viewName);
|
|
1473
|
-
}
|
|
1474
|
-
return false;
|
|
1475
|
-
}
|
|
1476
|
-
|
|
1477
|
-
/**
|
|
1478
|
-
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
1479
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
1480
|
-
*/
|
|
1481
|
-
/**
|
|
1482
|
-
* @module html-support/datafilter
|
|
1483
|
-
*/
|
|
1484
|
-
/**
|
|
1485
|
-
* Allows to validate elements and element attributes registered by {@link module:html-support/dataschema~DataSchema}.
|
|
1486
|
-
*
|
|
1487
|
-
* To enable registered element in the editor, use {@link module:html-support/datafilter~DataFilter#allowElement} method:
|
|
1488
|
-
*
|
|
1489
|
-
* ```ts
|
|
1490
|
-
* dataFilter.allowElement( 'section' );
|
|
1491
|
-
* ```
|
|
1492
|
-
*
|
|
1493
|
-
* You can also allow or disallow specific element attributes:
|
|
1494
|
-
*
|
|
1495
|
-
* ```ts
|
|
1496
|
-
* // Allow `data-foo` attribute on `section` element.
|
|
1497
|
-
* dataFilter.allowAttributes( {
|
|
1498
|
-
* name: 'section',
|
|
1499
|
-
* attributes: {
|
|
1500
|
-
* 'data-foo': true
|
|
1501
|
-
* }
|
|
1502
|
-
* } );
|
|
1503
|
-
*
|
|
1504
|
-
* // Disallow `color` style attribute on 'section' element.
|
|
1505
|
-
* dataFilter.disallowAttributes( {
|
|
1506
|
-
* name: 'section',
|
|
1507
|
-
* styles: {
|
|
1508
|
-
* color: /[\s\S]+/
|
|
1509
|
-
* }
|
|
1510
|
-
* } );
|
|
1511
|
-
* ```
|
|
1512
|
-
*
|
|
1513
|
-
* To apply the information about allowed and disallowed attributes in custom integration plugin,
|
|
1514
|
-
* use the {@link module:html-support/datafilter~DataFilter#processViewAttributes `processViewAttributes()`} method.
|
|
1515
|
-
*/
|
|
1516
|
-
class DataFilter extends Plugin {
|
|
1517
|
-
constructor(editor) {
|
|
1518
|
-
super(editor);
|
|
1519
|
-
this._dataSchema = editor.plugins.get('DataSchema');
|
|
1520
|
-
this._allowedAttributes = new Matcher();
|
|
1521
|
-
this._disallowedAttributes = new Matcher();
|
|
1522
|
-
this._allowedElements = new Set();
|
|
1523
|
-
this._disallowedElements = new Set();
|
|
1524
|
-
this._dataInitialized = false;
|
|
1525
|
-
this._coupledAttributes = null;
|
|
1526
|
-
this._registerElementsAfterInit();
|
|
1527
|
-
this._registerElementHandlers();
|
|
1528
|
-
this._registerCoupledAttributesPostFixer();
|
|
1529
|
-
this._registerAssociatedHtmlAttributesPostFixer();
|
|
1530
|
-
}
|
|
1531
|
-
/**
|
|
1532
|
-
* @inheritDoc
|
|
1533
|
-
*/
|
|
1534
|
-
static get pluginName() {
|
|
1535
|
-
return 'DataFilter';
|
|
1536
|
-
}
|
|
1537
|
-
/**
|
|
1538
|
-
* @inheritDoc
|
|
1539
|
-
*/
|
|
1540
|
-
static get requires() {
|
|
1541
|
-
return [DataSchema, Widget];
|
|
1542
|
-
}
|
|
1543
|
-
/**
|
|
1544
|
-
* Load a configuration of one or many elements, where their attributes should be allowed.
|
|
1545
|
-
*
|
|
1546
|
-
* **Note**: Rules will be applied just before next data pipeline data init or set.
|
|
1547
|
-
*
|
|
1548
|
-
* @param config Configuration of elements that should have their attributes accepted in the editor.
|
|
1549
|
-
*/
|
|
1550
|
-
loadAllowedConfig(config) {
|
|
1551
|
-
for (const pattern of config) {
|
|
1552
|
-
// MatcherPattern allows omitting `name` to widen the search of elements.
|
|
1553
|
-
// Let's keep it consistent and match every element if a `name` has not been provided.
|
|
1554
|
-
const elementName = pattern.name || /[\s\S]+/;
|
|
1555
|
-
const rules = splitRules(pattern);
|
|
1556
|
-
this.allowElement(elementName);
|
|
1557
|
-
rules.forEach(pattern => this.allowAttributes(pattern));
|
|
1558
|
-
}
|
|
1559
|
-
}
|
|
1560
|
-
/**
|
|
1561
|
-
* Load a configuration of one or many elements, where their attributes should be disallowed.
|
|
1562
|
-
*
|
|
1563
|
-
* **Note**: Rules will be applied just before next data pipeline data init or set.
|
|
1564
|
-
*
|
|
1565
|
-
* @param config Configuration of elements that should have their attributes rejected from the editor.
|
|
1566
|
-
*/
|
|
1567
|
-
loadDisallowedConfig(config) {
|
|
1568
|
-
for (const pattern of config) {
|
|
1569
|
-
// MatcherPattern allows omitting `name` to widen the search of elements.
|
|
1570
|
-
// Let's keep it consistent and match every element if a `name` has not been provided.
|
|
1571
|
-
const elementName = pattern.name || /[\s\S]+/;
|
|
1572
|
-
const rules = splitRules(pattern);
|
|
1573
|
-
// Disallow element itself if there is no other rules.
|
|
1574
|
-
if (rules.length == 0) {
|
|
1575
|
-
this.disallowElement(elementName);
|
|
1576
|
-
}
|
|
1577
|
-
else {
|
|
1578
|
-
rules.forEach(pattern => this.disallowAttributes(pattern));
|
|
1579
|
-
}
|
|
1580
|
-
}
|
|
1581
|
-
}
|
|
1582
|
-
/**
|
|
1583
|
-
* Load a configuration of one or many elements, where when empty should be allowed.
|
|
1584
|
-
*
|
|
1585
|
-
* **Note**: It modifies DataSchema so must be loaded before registering filtering rules.
|
|
1586
|
-
*
|
|
1587
|
-
* @param config Configuration of elements that should be preserved even if empty.
|
|
1588
|
-
*/
|
|
1589
|
-
loadAllowedEmptyElementsConfig(config) {
|
|
1590
|
-
for (const elementName of config) {
|
|
1591
|
-
this.allowEmptyElement(elementName);
|
|
1592
|
-
}
|
|
1593
|
-
}
|
|
1594
|
-
/**
|
|
1595
|
-
* Allow the given element in the editor context.
|
|
1596
|
-
*
|
|
1597
|
-
* This method will only allow elements described by the {@link module:html-support/dataschema~DataSchema} used
|
|
1598
|
-
* to create data filter.
|
|
1599
|
-
*
|
|
1600
|
-
* **Note**: Rules will be applied just before next data pipeline data init or set.
|
|
1601
|
-
*
|
|
1602
|
-
* @param viewName String or regular expression matching view name.
|
|
1603
|
-
*/
|
|
1604
|
-
allowElement(viewName) {
|
|
1605
|
-
for (const definition of this._dataSchema.getDefinitionsForView(viewName, true)) {
|
|
1606
|
-
this._addAllowedElement(definition);
|
|
1607
|
-
// Reset cached map to recalculate it on the next usage.
|
|
1608
|
-
this._coupledAttributes = null;
|
|
1609
|
-
}
|
|
1610
|
-
}
|
|
1611
|
-
/**
|
|
1612
|
-
* Disallow the given element in the editor context.
|
|
1613
|
-
*
|
|
1614
|
-
* This method will only disallow elements described by the {@link module:html-support/dataschema~DataSchema} used
|
|
1615
|
-
* to create data filter.
|
|
1616
|
-
*
|
|
1617
|
-
* @param viewName String or regular expression matching view name.
|
|
1618
|
-
*/
|
|
1619
|
-
disallowElement(viewName) {
|
|
1620
|
-
for (const definition of this._dataSchema.getDefinitionsForView(viewName, false)) {
|
|
1621
|
-
this._disallowedElements.add(definition.view);
|
|
1622
|
-
}
|
|
1623
|
-
}
|
|
1624
|
-
/**
|
|
1625
|
-
* Allow the given empty element in the editor context.
|
|
1626
|
-
*
|
|
1627
|
-
* This method will only allow elements described by the {@link module:html-support/dataschema~DataSchema} used
|
|
1628
|
-
* to create data filter.
|
|
1629
|
-
*
|
|
1630
|
-
* **Note**: It modifies DataSchema so must be called before registering filtering rules.
|
|
1631
|
-
*
|
|
1632
|
-
* @param viewName String or regular expression matching view name.
|
|
1633
|
-
*/
|
|
1634
|
-
allowEmptyElement(viewName) {
|
|
1635
|
-
for (const definition of this._dataSchema.getDefinitionsForView(viewName, true)) {
|
|
1636
|
-
if (definition.isInline) {
|
|
1637
|
-
this._dataSchema.extendInlineElement({ ...definition, allowEmpty: true });
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
/**
|
|
1642
|
-
* Allow the given attributes for view element allowed by {@link #allowElement} method.
|
|
1643
|
-
*
|
|
1644
|
-
* @param config Pattern matching all attributes which should be allowed.
|
|
1645
|
-
*/
|
|
1646
|
-
allowAttributes(config) {
|
|
1647
|
-
this._allowedAttributes.add(config);
|
|
1648
|
-
}
|
|
1649
|
-
/**
|
|
1650
|
-
* Disallow the given attributes for view element allowed by {@link #allowElement} method.
|
|
1651
|
-
*
|
|
1652
|
-
* @param config Pattern matching all attributes which should be disallowed.
|
|
1653
|
-
*/
|
|
1654
|
-
disallowAttributes(config) {
|
|
1655
|
-
this._disallowedAttributes.add(config);
|
|
1656
|
-
}
|
|
1657
|
-
/**
|
|
1658
|
-
* Processes all allowed and disallowed attributes on the view element by consuming them and returning the allowed ones.
|
|
1659
|
-
*
|
|
1660
|
-
* This method applies the configuration set up by {@link #allowAttributes `allowAttributes()`}
|
|
1661
|
-
* and {@link #disallowAttributes `disallowAttributes()`} over the given view element by consuming relevant attributes.
|
|
1662
|
-
* It returns the allowed attributes that were found on the given view element for further processing by integration code.
|
|
1663
|
-
*
|
|
1664
|
-
* ```ts
|
|
1665
|
-
* dispatcher.on( 'element:myElement', ( evt, data, conversionApi ) => {
|
|
1666
|
-
* // Get rid of disallowed and extract all allowed attributes from a viewElement.
|
|
1667
|
-
* const viewAttributes = dataFilter.processViewAttributes( data.viewItem, conversionApi );
|
|
1668
|
-
* // Do something with them, i.e. store inside a model as a dictionary.
|
|
1669
|
-
* if ( viewAttributes ) {
|
|
1670
|
-
* conversionApi.writer.setAttribute( 'htmlAttributesOfMyElement', viewAttributes, data.modelRange );
|
|
1671
|
-
* }
|
|
1672
|
-
* } );
|
|
1673
|
-
* ```
|
|
1674
|
-
*
|
|
1675
|
-
* @see module:engine/conversion/viewconsumable~ViewConsumable#consume
|
|
1676
|
-
*
|
|
1677
|
-
* @returns Object with following properties:
|
|
1678
|
-
* - attributes Set with matched attribute names.
|
|
1679
|
-
* - styles Set with matched style names.
|
|
1680
|
-
* - classes Set with matched class names.
|
|
1681
|
-
*/
|
|
1682
|
-
processViewAttributes(viewElement, conversionApi) {
|
|
1683
|
-
const { consumable } = conversionApi;
|
|
1684
|
-
// Make sure that the disabled attributes are handled before the allowed attributes are called.
|
|
1685
|
-
// For example, for block images the <figure> converter triggers conversion for <img> first and then for other elements, i.e. <a>.
|
|
1686
|
-
matchAndConsumeAttributes(viewElement, this._disallowedAttributes, consumable);
|
|
1687
|
-
return prepareGHSAttribute(viewElement, matchAndConsumeAttributes(viewElement, this._allowedAttributes, consumable));
|
|
1688
|
-
}
|
|
1689
|
-
/**
|
|
1690
|
-
* Adds allowed element definition and fires registration event.
|
|
1691
|
-
*/
|
|
1692
|
-
_addAllowedElement(definition) {
|
|
1693
|
-
if (this._allowedElements.has(definition)) {
|
|
1694
|
-
return;
|
|
1695
|
-
}
|
|
1696
|
-
this._allowedElements.add(definition);
|
|
1697
|
-
// For attribute based integrations (table figure, document lists, etc.) register related element definitions.
|
|
1698
|
-
if ('appliesToBlock' in definition && typeof definition.appliesToBlock == 'string') {
|
|
1699
|
-
for (const relatedDefinition of this._dataSchema.getDefinitionsForModel(definition.appliesToBlock)) {
|
|
1700
|
-
if (relatedDefinition.isBlock) {
|
|
1701
|
-
this._addAllowedElement(relatedDefinition);
|
|
1702
|
-
}
|
|
1703
|
-
}
|
|
1704
|
-
}
|
|
1705
|
-
// We need to wait for all features to be initialized before we can register
|
|
1706
|
-
// element, so we can access existing features model schemas.
|
|
1707
|
-
// If the data has not been initialized yet, _registerElementsAfterInit() method will take care of
|
|
1708
|
-
// registering elements.
|
|
1709
|
-
if (this._dataInitialized) {
|
|
1710
|
-
// Defer registration to the next data pipeline data set so any disallow rules could be applied
|
|
1711
|
-
// even if added after allow rule (disallowElement).
|
|
1712
|
-
this.editor.data.once('set', () => {
|
|
1713
|
-
this._fireRegisterEvent(definition);
|
|
1714
|
-
}, {
|
|
1715
|
-
// With the highest priority listener we are able to register elements right before
|
|
1716
|
-
// running data conversion.
|
|
1717
|
-
priority: priorities.highest + 1
|
|
1718
|
-
});
|
|
1719
|
-
}
|
|
1720
|
-
}
|
|
1721
|
-
/**
|
|
1722
|
-
* Registers elements allowed by {@link module:html-support/datafilter~DataFilter#allowElement} method
|
|
1723
|
-
* once {@link module:engine/controller/datacontroller~DataController editor's data controller} is initialized.
|
|
1724
|
-
*/
|
|
1725
|
-
_registerElementsAfterInit() {
|
|
1726
|
-
this.editor.data.on('init', () => {
|
|
1727
|
-
this._dataInitialized = true;
|
|
1728
|
-
for (const definition of this._allowedElements) {
|
|
1729
|
-
this._fireRegisterEvent(definition);
|
|
1730
|
-
}
|
|
1731
|
-
}, {
|
|
1732
|
-
// With highest priority listener we are able to register elements right before
|
|
1733
|
-
// running data conversion. Also:
|
|
1734
|
-
// * Make sure that priority is higher than the one used by `RealTimeCollaborationClient`,
|
|
1735
|
-
// as RTC is stopping event propagation.
|
|
1736
|
-
// * Make sure no other features hook into this event before GHS because otherwise the
|
|
1737
|
-
// downcast conversion (for these features) could run before GHS registered its converters
|
|
1738
|
-
// (https://github.com/ckeditor/ckeditor5/issues/11356).
|
|
1739
|
-
priority: priorities.highest + 1
|
|
1740
|
-
});
|
|
1741
|
-
}
|
|
1742
|
-
/**
|
|
1743
|
-
* Registers default element handlers.
|
|
1744
|
-
*/
|
|
1745
|
-
_registerElementHandlers() {
|
|
1746
|
-
this.on('register', (evt, definition) => {
|
|
1747
|
-
const schema = this.editor.model.schema;
|
|
1748
|
-
// Object element should be only registered for new features.
|
|
1749
|
-
// If the model schema is already registered, it should be handled by
|
|
1750
|
-
// #_registerBlockElement() or #_registerObjectElement() attribute handlers.
|
|
1751
|
-
if (definition.isObject && !schema.isRegistered(definition.model)) {
|
|
1752
|
-
this._registerObjectElement(definition);
|
|
1753
|
-
}
|
|
1754
|
-
else if (definition.isBlock) {
|
|
1755
|
-
this._registerBlockElement(definition);
|
|
1756
|
-
}
|
|
1757
|
-
else if (definition.isInline) {
|
|
1758
|
-
this._registerInlineElement(definition);
|
|
1759
|
-
}
|
|
1760
|
-
else {
|
|
1761
|
-
/**
|
|
1762
|
-
* The definition cannot be handled by the data filter.
|
|
1763
|
-
*
|
|
1764
|
-
* Make sure that the registered definition is correct.
|
|
1765
|
-
*
|
|
1766
|
-
* @error data-filter-invalid-definition
|
|
1767
|
-
*/
|
|
1768
|
-
throw new CKEditorError('data-filter-invalid-definition', null, definition);
|
|
1769
|
-
}
|
|
1770
|
-
evt.stop();
|
|
1771
|
-
}, { priority: 'lowest' });
|
|
1772
|
-
}
|
|
1773
|
-
/**
|
|
1774
|
-
* Registers a model post-fixer that is removing coupled GHS attributes of inline elements. Those attributes
|
|
1775
|
-
* are removed if a coupled feature attribute is removed.
|
|
1776
|
-
*
|
|
1777
|
-
* For example, consider following HTML:
|
|
1778
|
-
*
|
|
1779
|
-
* ```html
|
|
1780
|
-
* <a href="foo.html" id="myId">bar</a>
|
|
1781
|
-
* ```
|
|
1782
|
-
*
|
|
1783
|
-
* Which would be upcasted to following text node in the model:
|
|
1784
|
-
*
|
|
1785
|
-
* ```html
|
|
1786
|
-
* <$text linkHref="foo.html" htmlA="{ attributes: { id: 'myId' } }">bar</$text>
|
|
1787
|
-
* ```
|
|
1788
|
-
*
|
|
1789
|
-
* When the user removes the link from that text (using UI), only `linkHref` attribute would be removed:
|
|
1790
|
-
*
|
|
1791
|
-
* ```html
|
|
1792
|
-
* <$text htmlA="{ attributes: { id: 'myId' } }">bar</$text>
|
|
1793
|
-
* ```
|
|
1794
|
-
*
|
|
1795
|
-
* The `htmlA` attribute would stay in the model and would cause GHS to generate an `<a>` element.
|
|
1796
|
-
* This is incorrect from UX point of view, as the user wanted to remove the whole link (not only `href`).
|
|
1797
|
-
*/
|
|
1798
|
-
_registerCoupledAttributesPostFixer() {
|
|
1799
|
-
const model = this.editor.model;
|
|
1800
|
-
const selection = model.document.selection;
|
|
1801
|
-
model.document.registerPostFixer(writer => {
|
|
1802
|
-
const changes = model.document.differ.getChanges();
|
|
1803
|
-
let changed = false;
|
|
1804
|
-
const coupledAttributes = this._getCoupledAttributesMap();
|
|
1805
|
-
for (const change of changes) {
|
|
1806
|
-
// Handle only attribute removals.
|
|
1807
|
-
if (change.type != 'attribute' || change.attributeNewValue !== null) {
|
|
1808
|
-
continue;
|
|
1809
|
-
}
|
|
1810
|
-
// Find a list of coupled GHS attributes.
|
|
1811
|
-
const attributeKeys = coupledAttributes.get(change.attributeKey);
|
|
1812
|
-
if (!attributeKeys) {
|
|
1813
|
-
continue;
|
|
1814
|
-
}
|
|
1815
|
-
// Remove the coupled GHS attributes on the same range as the feature attribute was removed.
|
|
1816
|
-
for (const { item } of change.range.getWalker()) {
|
|
1817
|
-
for (const attributeKey of attributeKeys) {
|
|
1818
|
-
if (item.hasAttribute(attributeKey)) {
|
|
1819
|
-
writer.removeAttribute(attributeKey, item);
|
|
1820
|
-
changed = true;
|
|
1821
|
-
}
|
|
1822
|
-
}
|
|
1823
|
-
}
|
|
1824
|
-
}
|
|
1825
|
-
return changed;
|
|
1826
|
-
});
|
|
1827
|
-
this.listenTo(selection, 'change:attribute', (evt, { attributeKeys }) => {
|
|
1828
|
-
const removeAttributes = new Set();
|
|
1829
|
-
const coupledAttributes = this._getCoupledAttributesMap();
|
|
1830
|
-
for (const attributeKey of attributeKeys) {
|
|
1831
|
-
// Handle only attribute removals.
|
|
1832
|
-
if (selection.hasAttribute(attributeKey)) {
|
|
1833
|
-
continue;
|
|
1834
|
-
}
|
|
1835
|
-
// Find a list of coupled GHS attributes.
|
|
1836
|
-
const coupledAttributeKeys = coupledAttributes.get(attributeKey);
|
|
1837
|
-
if (!coupledAttributeKeys) {
|
|
1838
|
-
continue;
|
|
1839
|
-
}
|
|
1840
|
-
for (const coupledAttributeKey of coupledAttributeKeys) {
|
|
1841
|
-
if (selection.hasAttribute(coupledAttributeKey)) {
|
|
1842
|
-
removeAttributes.add(coupledAttributeKey);
|
|
1843
|
-
}
|
|
1844
|
-
}
|
|
1845
|
-
}
|
|
1846
|
-
if (removeAttributes.size == 0) {
|
|
1847
|
-
return;
|
|
1848
|
-
}
|
|
1849
|
-
model.change(writer => {
|
|
1850
|
-
for (const attributeKey of removeAttributes) {
|
|
1851
|
-
writer.removeSelectionAttribute(attributeKey);
|
|
1852
|
-
}
|
|
1853
|
-
});
|
|
1854
|
-
});
|
|
1855
|
-
}
|
|
1856
|
-
/**
|
|
1857
|
-
* Removes `html*Attributes` attributes from incompatible elements.
|
|
1858
|
-
*
|
|
1859
|
-
* For example, consider the following HTML:
|
|
1860
|
-
*
|
|
1861
|
-
* ```html
|
|
1862
|
-
* <heading2 htmlH2Attributes="...">foobar[]</heading2>
|
|
1863
|
-
* ```
|
|
1864
|
-
*
|
|
1865
|
-
* Pressing `enter` creates a new `paragraph` element that inherits
|
|
1866
|
-
* the `htmlH2Attributes` attribute from `heading2`.
|
|
1867
|
-
*
|
|
1868
|
-
* ```html
|
|
1869
|
-
* <heading2 htmlH2Attributes="...">foobar</heading2>
|
|
1870
|
-
* <paragraph htmlH2Attributes="...">[]</paragraph>
|
|
1871
|
-
* ```
|
|
1872
|
-
*
|
|
1873
|
-
* This postfixer ensures that this doesn't happen, and that elements can
|
|
1874
|
-
* only have `html*Attributes` associated with them,
|
|
1875
|
-
* e.g.: `htmlPAttributes` for `<p>`, `htmlDivAttributes` for `<div>`, etc.
|
|
1876
|
-
*
|
|
1877
|
-
* With it enabled, pressing `enter` at the end of `<heading2>` will create
|
|
1878
|
-
* a new paragraph without the `htmlH2Attributes` attribute.
|
|
1879
|
-
*
|
|
1880
|
-
* ```html
|
|
1881
|
-
* <heading2 htmlH2Attributes="...">foobar</heading2>
|
|
1882
|
-
* <paragraph>[]</paragraph>
|
|
1883
|
-
* ```
|
|
1884
|
-
*/
|
|
1885
|
-
_registerAssociatedHtmlAttributesPostFixer() {
|
|
1886
|
-
const model = this.editor.model;
|
|
1887
|
-
model.document.registerPostFixer(writer => {
|
|
1888
|
-
const changes = model.document.differ.getChanges();
|
|
1889
|
-
let changed = false;
|
|
1890
|
-
for (const change of changes) {
|
|
1891
|
-
if (change.type !== 'insert' || change.name === '$text') {
|
|
1892
|
-
continue;
|
|
1893
|
-
}
|
|
1894
|
-
for (const attr of change.attributes.keys()) {
|
|
1895
|
-
if (!attr.startsWith('html') || !attr.endsWith('Attributes')) {
|
|
1896
|
-
continue;
|
|
1897
|
-
}
|
|
1898
|
-
if (!model.schema.checkAttribute(change.name, attr)) {
|
|
1899
|
-
writer.removeAttribute(attr, change.position.nodeAfter);
|
|
1900
|
-
changed = true;
|
|
1901
|
-
}
|
|
1902
|
-
}
|
|
1903
|
-
}
|
|
1904
|
-
return changed;
|
|
1905
|
-
});
|
|
1906
|
-
}
|
|
1907
|
-
/**
|
|
1908
|
-
* Collects the map of coupled attributes. The returned map is keyed by the feature attribute name
|
|
1909
|
-
* and coupled GHS attribute names are stored in the value array.
|
|
1910
|
-
*/
|
|
1911
|
-
_getCoupledAttributesMap() {
|
|
1912
|
-
if (this._coupledAttributes) {
|
|
1913
|
-
return this._coupledAttributes;
|
|
1914
|
-
}
|
|
1915
|
-
this._coupledAttributes = new Map();
|
|
1916
|
-
for (const definition of this._allowedElements) {
|
|
1917
|
-
if (definition.coupledAttribute && definition.model) {
|
|
1918
|
-
const attributeNames = this._coupledAttributes.get(definition.coupledAttribute);
|
|
1919
|
-
if (attributeNames) {
|
|
1920
|
-
attributeNames.push(definition.model);
|
|
1921
|
-
}
|
|
1922
|
-
else {
|
|
1923
|
-
this._coupledAttributes.set(definition.coupledAttribute, [definition.model]);
|
|
1924
|
-
}
|
|
1925
|
-
}
|
|
1926
|
-
}
|
|
1927
|
-
return this._coupledAttributes;
|
|
1928
|
-
}
|
|
1929
|
-
/**
|
|
1930
|
-
* Fires `register` event for the given element definition.
|
|
1931
|
-
*/
|
|
1932
|
-
_fireRegisterEvent(definition) {
|
|
1933
|
-
if (definition.view && this._disallowedElements.has(definition.view)) {
|
|
1934
|
-
return;
|
|
1935
|
-
}
|
|
1936
|
-
this.fire(definition.view ? `register:${definition.view}` : 'register', definition);
|
|
1937
|
-
}
|
|
1938
|
-
/**
|
|
1939
|
-
* Registers object element and attribute converters for the given data schema definition.
|
|
1940
|
-
*/
|
|
1941
|
-
_registerObjectElement(definition) {
|
|
1942
|
-
const editor = this.editor;
|
|
1943
|
-
const schema = editor.model.schema;
|
|
1944
|
-
const conversion = editor.conversion;
|
|
1945
|
-
const { view: viewName, model: modelName } = definition;
|
|
1946
|
-
schema.register(modelName, definition.modelSchema);
|
|
1947
|
-
/* istanbul ignore next: paranoid check -- @preserve */
|
|
1948
|
-
if (!viewName) {
|
|
1949
|
-
return;
|
|
1950
|
-
}
|
|
1951
|
-
schema.extend(definition.model, {
|
|
1952
|
-
allowAttributes: [getHtmlAttributeName(viewName), 'htmlContent']
|
|
1953
|
-
});
|
|
1954
|
-
// Store element content in special `$rawContent` custom property to
|
|
1955
|
-
// avoid editor's data filtering mechanism.
|
|
1956
|
-
editor.data.registerRawContentMatcher({
|
|
1957
|
-
name: viewName
|
|
1958
|
-
});
|
|
1959
|
-
conversion.for('upcast').elementToElement({
|
|
1960
|
-
view: viewName,
|
|
1961
|
-
model: viewToModelObjectConverter(definition),
|
|
1962
|
-
// With a `low` priority, `paragraph` plugin auto-paragraphing mechanism is executed. Make sure
|
|
1963
|
-
// this listener is called before it. If not, some elements will be transformed into a paragraph.
|
|
1964
|
-
// `+ 2` is used to take priority over `_addDefaultH1Conversion` in the Heading plugin.
|
|
1965
|
-
converterPriority: priorities.low + 2
|
|
1966
|
-
});
|
|
1967
|
-
conversion.for('upcast').add(viewToModelBlockAttributeConverter(definition, this));
|
|
1968
|
-
conversion.for('editingDowncast').elementToStructure({
|
|
1969
|
-
model: {
|
|
1970
|
-
name: modelName,
|
|
1971
|
-
attributes: [getHtmlAttributeName(viewName)]
|
|
1972
|
-
},
|
|
1973
|
-
view: toObjectWidgetConverter(editor, definition)
|
|
1974
|
-
});
|
|
1975
|
-
conversion.for('dataDowncast').elementToElement({
|
|
1976
|
-
model: modelName,
|
|
1977
|
-
view: (modelElement, { writer }) => {
|
|
1978
|
-
return createObjectView(viewName, modelElement, writer);
|
|
1979
|
-
}
|
|
1980
|
-
});
|
|
1981
|
-
conversion.for('dataDowncast').add(modelToViewBlockAttributeConverter(definition));
|
|
1982
|
-
}
|
|
1983
|
-
/**
|
|
1984
|
-
* Registers block element and attribute converters for the given data schema definition.
|
|
1985
|
-
*/
|
|
1986
|
-
_registerBlockElement(definition) {
|
|
1987
|
-
const editor = this.editor;
|
|
1988
|
-
const schema = editor.model.schema;
|
|
1989
|
-
const conversion = editor.conversion;
|
|
1990
|
-
const { view: viewName, model: modelName } = definition;
|
|
1991
|
-
if (!schema.isRegistered(definition.model)) {
|
|
1992
|
-
schema.register(definition.model, definition.modelSchema);
|
|
1993
|
-
if (!viewName) {
|
|
1994
|
-
return;
|
|
1995
|
-
}
|
|
1996
|
-
conversion.for('upcast').elementToElement({
|
|
1997
|
-
model: modelName,
|
|
1998
|
-
view: viewName,
|
|
1999
|
-
// With a `low` priority, `paragraph` plugin auto-paragraphing mechanism is executed. Make sure
|
|
2000
|
-
// this listener is called before it. If not, some elements will be transformed into a paragraph.
|
|
2001
|
-
// `+ 2` is used to take priority over `_addDefaultH1Conversion` in the Heading plugin.
|
|
2002
|
-
converterPriority: priorities.low + 2
|
|
2003
|
-
});
|
|
2004
|
-
conversion.for('downcast').elementToElement({
|
|
2005
|
-
model: modelName,
|
|
2006
|
-
view: viewName
|
|
2007
|
-
});
|
|
2008
|
-
}
|
|
2009
|
-
if (!viewName) {
|
|
2010
|
-
return;
|
|
2011
|
-
}
|
|
2012
|
-
schema.extend(definition.model, {
|
|
2013
|
-
allowAttributes: getHtmlAttributeName(viewName)
|
|
2014
|
-
});
|
|
2015
|
-
conversion.for('upcast').add(viewToModelBlockAttributeConverter(definition, this));
|
|
2016
|
-
conversion.for('downcast').add(modelToViewBlockAttributeConverter(definition));
|
|
2017
|
-
}
|
|
2018
|
-
/**
|
|
2019
|
-
* Registers inline element and attribute converters for the given data schema definition.
|
|
2020
|
-
*
|
|
2021
|
-
* Extends `$text` model schema to allow the given definition model attribute and its properties.
|
|
2022
|
-
*/
|
|
2023
|
-
_registerInlineElement(definition) {
|
|
2024
|
-
const editor = this.editor;
|
|
2025
|
-
const schema = editor.model.schema;
|
|
2026
|
-
const conversion = editor.conversion;
|
|
2027
|
-
const attributeKey = definition.model;
|
|
2028
|
-
// This element is stored in the model as an attribute on a block element, for example DocumentLists.
|
|
2029
|
-
if (definition.appliesToBlock) {
|
|
2030
|
-
return;
|
|
2031
|
-
}
|
|
2032
|
-
schema.extend('$text', {
|
|
2033
|
-
allowAttributes: attributeKey
|
|
2034
|
-
});
|
|
2035
|
-
if (definition.attributeProperties) {
|
|
2036
|
-
schema.setAttributeProperties(attributeKey, definition.attributeProperties);
|
|
2037
|
-
}
|
|
2038
|
-
conversion.for('upcast').add(viewToAttributeInlineConverter(definition, this));
|
|
2039
|
-
conversion.for('downcast').attributeToElement({
|
|
2040
|
-
model: attributeKey,
|
|
2041
|
-
view: attributeToViewInlineConverter(definition)
|
|
2042
|
-
});
|
|
2043
|
-
if (!definition.allowEmpty) {
|
|
2044
|
-
return;
|
|
2045
|
-
}
|
|
2046
|
-
schema.setAttributeProperties(attributeKey, { copyFromObject: false });
|
|
2047
|
-
if (!schema.isRegistered('htmlEmptyElement')) {
|
|
2048
|
-
schema.register('htmlEmptyElement', {
|
|
2049
|
-
inheritAllFrom: '$inlineObject'
|
|
2050
|
-
});
|
|
2051
|
-
}
|
|
2052
|
-
editor.data.htmlProcessor.domConverter.registerInlineObjectMatcher(element => {
|
|
2053
|
-
// Element must be empty and have any attribute.
|
|
2054
|
-
if (element.name == definition.view &&
|
|
2055
|
-
element.isEmpty &&
|
|
2056
|
-
Array.from(element.getAttributeKeys()).length) {
|
|
2057
|
-
return {
|
|
2058
|
-
name: true
|
|
2059
|
-
};
|
|
2060
|
-
}
|
|
2061
|
-
return null;
|
|
2062
|
-
});
|
|
2063
|
-
conversion.for('editingDowncast')
|
|
2064
|
-
.elementToElement({
|
|
2065
|
-
model: 'htmlEmptyElement',
|
|
2066
|
-
view: emptyInlineModelElementToViewConverter(definition, true)
|
|
2067
|
-
});
|
|
2068
|
-
conversion.for('dataDowncast')
|
|
2069
|
-
.elementToElement({
|
|
2070
|
-
model: 'htmlEmptyElement',
|
|
2071
|
-
view: emptyInlineModelElementToViewConverter(definition)
|
|
2072
|
-
});
|
|
2073
|
-
}
|
|
2074
|
-
}
|
|
2075
|
-
/**
|
|
2076
|
-
* Matches and consumes matched attributes.
|
|
2077
|
-
*
|
|
2078
|
-
* @returns Object with following properties:
|
|
2079
|
-
* - attributes Array with matched attribute names.
|
|
2080
|
-
* - classes Array with matched class names.
|
|
2081
|
-
* - styles Array with matched style names.
|
|
2082
|
-
*/
|
|
2083
|
-
function matchAndConsumeAttributes(viewElement, matcher, consumable) {
|
|
2084
|
-
const matches = matcher.matchAll(viewElement) || [];
|
|
2085
|
-
const stylesProcessor = viewElement.document.stylesProcessor;
|
|
2086
|
-
return matches.reduce((result, { match }) => {
|
|
2087
|
-
// Verify and consume styles.
|
|
2088
|
-
for (const style of match.styles || []) {
|
|
2089
|
-
// Check longer forms of the same style as those could be matched
|
|
2090
|
-
// but not present in the element directly.
|
|
2091
|
-
// Consider only longhand (or longer than current notation) so that
|
|
2092
|
-
// we do not include all sides of the box if only one side is allowed.
|
|
2093
|
-
const sortedRelatedStyles = stylesProcessor.getRelatedStyles(style)
|
|
2094
|
-
.filter(relatedStyle => relatedStyle.split('-').length > style.split('-').length)
|
|
2095
|
-
.sort((a, b) => b.split('-').length - a.split('-').length);
|
|
2096
|
-
for (const relatedStyle of sortedRelatedStyles) {
|
|
2097
|
-
if (consumable.consume(viewElement, { styles: [relatedStyle] })) {
|
|
2098
|
-
result.styles.push(relatedStyle);
|
|
2099
|
-
}
|
|
2100
|
-
}
|
|
2101
|
-
// Verify and consume style as specified in the matcher.
|
|
2102
|
-
if (consumable.consume(viewElement, { styles: [style] })) {
|
|
2103
|
-
result.styles.push(style);
|
|
2104
|
-
}
|
|
2105
|
-
}
|
|
2106
|
-
// Verify and consume class names.
|
|
2107
|
-
for (const className of match.classes || []) {
|
|
2108
|
-
if (consumable.consume(viewElement, { classes: [className] })) {
|
|
2109
|
-
result.classes.push(className);
|
|
2110
|
-
}
|
|
2111
|
-
}
|
|
2112
|
-
// Verify and consume other attributes.
|
|
2113
|
-
for (const attributeName of match.attributes || []) {
|
|
2114
|
-
if (consumable.consume(viewElement, { attributes: [attributeName] })) {
|
|
2115
|
-
result.attributes.push(attributeName);
|
|
2116
|
-
}
|
|
2117
|
-
}
|
|
2118
|
-
return result;
|
|
2119
|
-
}, {
|
|
2120
|
-
attributes: [],
|
|
2121
|
-
classes: [],
|
|
2122
|
-
styles: []
|
|
2123
|
-
});
|
|
2124
|
-
}
|
|
2125
|
-
/**
|
|
2126
|
-
* Prepares the GHS attribute value as an object with element attributes' values.
|
|
2127
|
-
*/
|
|
2128
|
-
function prepareGHSAttribute(viewElement, { attributes, classes, styles }) {
|
|
2129
|
-
if (!attributes.length && !classes.length && !styles.length) {
|
|
2130
|
-
return null;
|
|
2131
|
-
}
|
|
2132
|
-
return {
|
|
2133
|
-
...(attributes.length && {
|
|
2134
|
-
attributes: getAttributes(viewElement, attributes)
|
|
2135
|
-
}),
|
|
2136
|
-
...(styles.length && {
|
|
2137
|
-
styles: getReducedStyles(viewElement, styles)
|
|
2138
|
-
}),
|
|
2139
|
-
...(classes.length && {
|
|
2140
|
-
classes
|
|
2141
|
-
})
|
|
2142
|
-
};
|
|
2143
|
-
}
|
|
2144
|
-
/**
|
|
2145
|
-
* Returns attributes as an object with names and values.
|
|
2146
|
-
*/
|
|
2147
|
-
function getAttributes(viewElement, attributes) {
|
|
2148
|
-
const attributesObject = {};
|
|
2149
|
-
for (const key of attributes) {
|
|
2150
|
-
const value = viewElement.getAttribute(key);
|
|
2151
|
-
if (value !== undefined && isValidAttributeName(key)) {
|
|
2152
|
-
attributesObject[key] = value;
|
|
2153
|
-
}
|
|
2154
|
-
}
|
|
2155
|
-
return attributesObject;
|
|
2156
|
-
}
|
|
2157
|
-
/**
|
|
2158
|
-
* Returns styles as an object reduced to shorthand notation without redundant entries.
|
|
2159
|
-
*/
|
|
2160
|
-
function getReducedStyles(viewElement, styles) {
|
|
2161
|
-
// Use StyleMap to reduce style value to the minimal form (without shorthand and long-hand notation and duplication).
|
|
2162
|
-
const stylesMap = new StylesMap(viewElement.document.stylesProcessor);
|
|
2163
|
-
for (const key of styles) {
|
|
2164
|
-
const styleValue = viewElement.getStyle(key);
|
|
2165
|
-
if (styleValue !== undefined) {
|
|
2166
|
-
stylesMap.set(key, styleValue);
|
|
2167
|
-
}
|
|
2168
|
-
}
|
|
2169
|
-
return Object.fromEntries(stylesMap.getStylesEntries());
|
|
2170
|
-
}
|
|
2171
|
-
/**
|
|
2172
|
-
* Matcher by default has to match **all** patterns to count it as an actual match. Splitting the pattern
|
|
2173
|
-
* into separate patterns means that any matched pattern will be count as a match.
|
|
2174
|
-
*
|
|
2175
|
-
* @param pattern Pattern to split.
|
|
2176
|
-
* @param attributeName Name of the attribute to split (e.g. 'attributes', 'classes', 'styles').
|
|
2177
|
-
*/
|
|
2178
|
-
function splitPattern(pattern, attributeName) {
|
|
2179
|
-
const { name } = pattern;
|
|
2180
|
-
const attributeValue = pattern[attributeName];
|
|
2181
|
-
if (isPlainObject(attributeValue)) {
|
|
2182
|
-
return Object.entries(attributeValue)
|
|
2183
|
-
.map(([key, value]) => ({
|
|
2184
|
-
name,
|
|
2185
|
-
[attributeName]: {
|
|
2186
|
-
[key]: value
|
|
2187
|
-
}
|
|
2188
|
-
}));
|
|
2189
|
-
}
|
|
2190
|
-
if (Array.isArray(attributeValue)) {
|
|
2191
|
-
return attributeValue
|
|
2192
|
-
.map(value => ({
|
|
2193
|
-
name,
|
|
2194
|
-
[attributeName]: [value]
|
|
2195
|
-
}));
|
|
2196
|
-
}
|
|
2197
|
-
return [pattern];
|
|
2198
|
-
}
|
|
2199
|
-
/**
|
|
2200
|
-
* Rules are matched in conjunction (AND operation), but we want to have a match if *any* of the rules is matched (OR operation).
|
|
2201
|
-
* By splitting the rules we force the latter effect.
|
|
2202
|
-
*/
|
|
2203
|
-
function splitRules(rules) {
|
|
2204
|
-
const { name, attributes, classes, styles } = rules;
|
|
2205
|
-
const splitRules = [];
|
|
2206
|
-
if (attributes) {
|
|
2207
|
-
splitRules.push(...splitPattern({ name, attributes }, 'attributes'));
|
|
2208
|
-
}
|
|
2209
|
-
if (classes) {
|
|
2210
|
-
splitRules.push(...splitPattern({ name, classes }, 'classes'));
|
|
2211
|
-
}
|
|
2212
|
-
if (styles) {
|
|
2213
|
-
splitRules.push(...splitPattern({ name, styles }, 'styles'));
|
|
2214
|
-
}
|
|
2215
|
-
return splitRules;
|
|
2216
|
-
}
|
|
2217
|
-
|
|
2218
|
-
/**
|
|
2219
|
-
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
2220
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
2221
|
-
*/
|
|
2222
|
-
/**
|
|
2223
|
-
* Provides the General HTML Support integration with {@link module:code-block/codeblock~CodeBlock Code Block} feature.
|
|
2224
|
-
*/
|
|
2225
|
-
class CodeBlockElementSupport extends Plugin {
|
|
2226
|
-
/**
|
|
2227
|
-
* @inheritDoc
|
|
2228
|
-
*/
|
|
2229
|
-
static get requires() {
|
|
2230
|
-
return [DataFilter];
|
|
2231
|
-
}
|
|
2232
|
-
/**
|
|
2233
|
-
* @inheritDoc
|
|
2234
|
-
*/
|
|
2235
|
-
static get pluginName() {
|
|
2236
|
-
return 'CodeBlockElementSupport';
|
|
2237
|
-
}
|
|
2238
|
-
/**
|
|
2239
|
-
* @inheritDoc
|
|
2240
|
-
*/
|
|
2241
|
-
init() {
|
|
2242
|
-
if (!this.editor.plugins.has('CodeBlockEditing')) {
|
|
2243
|
-
return;
|
|
2244
|
-
}
|
|
2245
|
-
const dataFilter = this.editor.plugins.get(DataFilter);
|
|
2246
|
-
dataFilter.on('register:pre', (evt, definition) => {
|
|
2247
|
-
if (definition.model !== 'codeBlock') {
|
|
2248
|
-
return;
|
|
2249
|
-
}
|
|
2250
|
-
const editor = this.editor;
|
|
2251
|
-
const schema = editor.model.schema;
|
|
2252
|
-
const conversion = editor.conversion;
|
|
2253
|
-
// Extend codeBlock to allow attributes required by attribute filtration.
|
|
2254
|
-
schema.extend('codeBlock', {
|
|
2255
|
-
allowAttributes: ['htmlPreAttributes', 'htmlContentAttributes']
|
|
2256
|
-
});
|
|
2257
|
-
conversion.for('upcast').add(viewToModelCodeBlockAttributeConverter(dataFilter));
|
|
2258
|
-
conversion.for('downcast').add(modelToViewCodeBlockAttributeConverter());
|
|
2259
|
-
evt.stop();
|
|
2260
|
-
});
|
|
2261
|
-
}
|
|
2262
|
-
}
|
|
2263
|
-
/**
|
|
2264
|
-
* View-to-model conversion helper preserving allowed attributes on {@link module:code-block/codeblock~CodeBlock Code Block}
|
|
2265
|
-
* feature model element.
|
|
2266
|
-
*
|
|
2267
|
-
* Attributes are preserved as a value of `html*Attributes` model attribute.
|
|
2268
|
-
* @param dataFilter
|
|
2269
|
-
* @returns Returns a conversion callback.
|
|
2270
|
-
*/
|
|
2271
|
-
function viewToModelCodeBlockAttributeConverter(dataFilter) {
|
|
2272
|
-
return (dispatcher) => {
|
|
2273
|
-
dispatcher.on('element:code', (evt, data, conversionApi) => {
|
|
2274
|
-
const viewCodeElement = data.viewItem;
|
|
2275
|
-
const viewPreElement = viewCodeElement.parent;
|
|
2276
|
-
if (!viewPreElement || !viewPreElement.is('element', 'pre')) {
|
|
2277
|
-
return;
|
|
2278
|
-
}
|
|
2279
|
-
preserveElementAttributes(viewPreElement, 'htmlPreAttributes');
|
|
2280
|
-
preserveElementAttributes(viewCodeElement, 'htmlContentAttributes');
|
|
2281
|
-
function preserveElementAttributes(viewElement, attributeName) {
|
|
2282
|
-
const viewAttributes = dataFilter.processViewAttributes(viewElement, conversionApi);
|
|
2283
|
-
if (viewAttributes) {
|
|
2284
|
-
conversionApi.writer.setAttribute(attributeName, viewAttributes, data.modelRange);
|
|
2285
|
-
}
|
|
2286
|
-
}
|
|
2287
|
-
}, { priority: 'low' });
|
|
2288
|
-
};
|
|
2289
|
-
}
|
|
2290
|
-
/**
|
|
2291
|
-
* Model-to-view conversion helper applying attributes from {@link module:code-block/codeblock~CodeBlock Code Block}
|
|
2292
|
-
* feature model element.
|
|
2293
|
-
* @returns Returns a conversion callback.
|
|
2294
|
-
*/
|
|
2295
|
-
function modelToViewCodeBlockAttributeConverter() {
|
|
2296
|
-
return (dispatcher) => {
|
|
2297
|
-
dispatcher.on('attribute:htmlPreAttributes:codeBlock', (evt, data, conversionApi) => {
|
|
2298
|
-
if (!conversionApi.consumable.consume(data.item, evt.name)) {
|
|
2299
|
-
return;
|
|
2300
|
-
}
|
|
2301
|
-
const { attributeOldValue, attributeNewValue } = data;
|
|
2302
|
-
const viewCodeElement = conversionApi.mapper.toViewElement(data.item);
|
|
2303
|
-
const viewPreElement = viewCodeElement.parent;
|
|
2304
|
-
updateViewAttributes(conversionApi.writer, attributeOldValue, attributeNewValue, viewPreElement);
|
|
2305
|
-
});
|
|
2306
|
-
dispatcher.on('attribute:htmlContentAttributes:codeBlock', (evt, data, conversionApi) => {
|
|
2307
|
-
if (!conversionApi.consumable.consume(data.item, evt.name)) {
|
|
2308
|
-
return;
|
|
2309
|
-
}
|
|
2310
|
-
const { attributeOldValue, attributeNewValue } = data;
|
|
2311
|
-
const viewCodeElement = conversionApi.mapper.toViewElement(data.item);
|
|
2312
|
-
updateViewAttributes(conversionApi.writer, attributeOldValue, attributeNewValue, viewCodeElement);
|
|
2313
|
-
});
|
|
2314
|
-
};
|
|
2315
|
-
}
|
|
2316
|
-
|
|
2317
|
-
/**
|
|
2318
|
-
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
2319
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
2320
|
-
*/
|
|
2321
|
-
/**
|
|
2322
|
-
* Provides the General HTML Support integration for elements which can behave like sectioning element (e.g. article) or
|
|
2323
|
-
* element accepting only inline content (e.g. paragraph).
|
|
2324
|
-
*
|
|
2325
|
-
* The distinction between this two content models is important for choosing correct schema model and proper content conversion.
|
|
2326
|
-
* As an example, it ensures that:
|
|
2327
|
-
*
|
|
2328
|
-
* * children elements paragraphing is enabled for sectioning elements only,
|
|
2329
|
-
* * element and its content can be correctly handled by editing view (splitting and merging elements),
|
|
2330
|
-
* * model element HTML is semantically correct and easier to work with.
|
|
2331
|
-
*
|
|
2332
|
-
* If element contains any block element, it will be treated as a sectioning element and registered using
|
|
2333
|
-
* {@link module:html-support/dataschema~DataSchemaDefinition#model} and
|
|
2334
|
-
* {@link module:html-support/dataschema~DataSchemaDefinition#modelSchema} in editor schema.
|
|
2335
|
-
* Otherwise, it will be registered under {@link module:html-support/dataschema~DataSchemaBlockElementDefinition#paragraphLikeModel} model
|
|
2336
|
-
* name with model schema accepting only inline content (inheriting from `$block`).
|
|
2337
|
-
*/
|
|
2338
|
-
class DualContentModelElementSupport extends Plugin {
|
|
2339
|
-
/**
|
|
2340
|
-
* @inheritDoc
|
|
2341
|
-
*/
|
|
2342
|
-
static get requires() {
|
|
2343
|
-
return [DataFilter];
|
|
2344
|
-
}
|
|
2345
|
-
/**
|
|
2346
|
-
* @inheritDoc
|
|
2347
|
-
*/
|
|
2348
|
-
static get pluginName() {
|
|
2349
|
-
return 'DualContentModelElementSupport';
|
|
2350
|
-
}
|
|
2351
|
-
/**
|
|
2352
|
-
* @inheritDoc
|
|
2353
|
-
*/
|
|
2354
|
-
init() {
|
|
2355
|
-
const dataFilter = this.editor.plugins.get(DataFilter);
|
|
2356
|
-
dataFilter.on('register', (evt, definition) => {
|
|
2357
|
-
const blockDefinition = definition;
|
|
2358
|
-
const editor = this.editor;
|
|
2359
|
-
const schema = editor.model.schema;
|
|
2360
|
-
const conversion = editor.conversion;
|
|
2361
|
-
if (!blockDefinition.paragraphLikeModel) {
|
|
2362
|
-
return;
|
|
2363
|
-
}
|
|
2364
|
-
// Can only apply to newly registered features.
|
|
2365
|
-
if (schema.isRegistered(blockDefinition.model) || schema.isRegistered(blockDefinition.paragraphLikeModel)) {
|
|
2366
|
-
return;
|
|
2367
|
-
}
|
|
2368
|
-
const paragraphLikeModelDefinition = {
|
|
2369
|
-
model: blockDefinition.paragraphLikeModel,
|
|
2370
|
-
view: blockDefinition.view
|
|
2371
|
-
};
|
|
2372
|
-
schema.register(blockDefinition.model, blockDefinition.modelSchema);
|
|
2373
|
-
schema.register(paragraphLikeModelDefinition.model, {
|
|
2374
|
-
inheritAllFrom: '$block'
|
|
2375
|
-
});
|
|
2376
|
-
conversion.for('upcast').elementToElement({
|
|
2377
|
-
view: blockDefinition.view,
|
|
2378
|
-
model: (viewElement, { writer }) => {
|
|
2379
|
-
if (this._hasBlockContent(viewElement)) {
|
|
2380
|
-
return writer.createElement(blockDefinition.model);
|
|
2381
|
-
}
|
|
2382
|
-
return writer.createElement(paragraphLikeModelDefinition.model);
|
|
2383
|
-
},
|
|
2384
|
-
// With a `low` priority, `paragraph` plugin auto-paragraphing mechanism is executed. Make sure
|
|
2385
|
-
// this listener is called before it. If not, some elements will be transformed into a paragraph.
|
|
2386
|
-
converterPriority: priorities.low + 0.5
|
|
2387
|
-
});
|
|
2388
|
-
conversion.for('downcast').elementToElement({
|
|
2389
|
-
view: blockDefinition.view,
|
|
2390
|
-
model: blockDefinition.model
|
|
2391
|
-
});
|
|
2392
|
-
this._addAttributeConversion(blockDefinition);
|
|
2393
|
-
conversion.for('downcast').elementToElement({
|
|
2394
|
-
view: paragraphLikeModelDefinition.view,
|
|
2395
|
-
model: paragraphLikeModelDefinition.model
|
|
2396
|
-
});
|
|
2397
|
-
this._addAttributeConversion(paragraphLikeModelDefinition);
|
|
2398
|
-
evt.stop();
|
|
2399
|
-
});
|
|
2400
|
-
}
|
|
2401
|
-
/**
|
|
2402
|
-
* Checks whether the given view element includes any other block element.
|
|
2403
|
-
*/
|
|
2404
|
-
_hasBlockContent(viewElement) {
|
|
2405
|
-
const view = this.editor.editing.view;
|
|
2406
|
-
const blockElements = view.domConverter.blockElements;
|
|
2407
|
-
// Traversing the viewElement subtree looking for block elements.
|
|
2408
|
-
// Especially for the cases like <div><a href="#"><p>foo</p></a></div>.
|
|
2409
|
-
// https://github.com/ckeditor/ckeditor5/issues/11513
|
|
2410
|
-
for (const viewItem of view.createRangeIn(viewElement).getItems()) {
|
|
2411
|
-
if (viewItem.is('element') && blockElements.includes(viewItem.name)) {
|
|
2412
|
-
return true;
|
|
2413
|
-
}
|
|
2414
|
-
}
|
|
2415
|
-
return false;
|
|
2416
|
-
}
|
|
2417
|
-
/**
|
|
2418
|
-
* Adds attribute filtering conversion for the given data schema.
|
|
2419
|
-
*/
|
|
2420
|
-
_addAttributeConversion(definition) {
|
|
2421
|
-
const editor = this.editor;
|
|
2422
|
-
const conversion = editor.conversion;
|
|
2423
|
-
const dataFilter = editor.plugins.get(DataFilter);
|
|
2424
|
-
editor.model.schema.extend(definition.model, {
|
|
2425
|
-
allowAttributes: getHtmlAttributeName(definition.view)
|
|
2426
|
-
});
|
|
2427
|
-
conversion.for('upcast').add(viewToModelBlockAttributeConverter(definition, dataFilter));
|
|
2428
|
-
conversion.for('downcast').add(modelToViewBlockAttributeConverter(definition));
|
|
2429
|
-
}
|
|
2430
|
-
}
|
|
2431
|
-
|
|
2432
|
-
/**
|
|
2433
|
-
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
2434
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
2435
|
-
*/
|
|
2436
|
-
/**
|
|
2437
|
-
* @module html-support/integrations/heading
|
|
2438
|
-
*/
|
|
2439
|
-
/**
|
|
2440
|
-
* Provides the General HTML Support integration with {@link module:heading/heading~Heading Heading} feature.
|
|
2441
|
-
*/
|
|
2442
|
-
class HeadingElementSupport extends Plugin {
|
|
2443
|
-
/**
|
|
2444
|
-
* @inheritDoc
|
|
2445
|
-
*/
|
|
2446
|
-
static get requires() {
|
|
2447
|
-
return [DataSchema, Enter];
|
|
2448
|
-
}
|
|
2449
|
-
/**
|
|
2450
|
-
* @inheritDoc
|
|
2451
|
-
*/
|
|
2452
|
-
static get pluginName() {
|
|
2453
|
-
return 'HeadingElementSupport';
|
|
2454
|
-
}
|
|
2455
|
-
/**
|
|
2456
|
-
* @inheritDoc
|
|
2457
|
-
*/
|
|
2458
|
-
init() {
|
|
2459
|
-
const editor = this.editor;
|
|
2460
|
-
if (!editor.plugins.has('HeadingEditing')) {
|
|
2461
|
-
return;
|
|
2462
|
-
}
|
|
2463
|
-
const options = editor.config.get('heading.options');
|
|
2464
|
-
this.registerHeadingElements(editor, options);
|
|
2465
|
-
}
|
|
2466
|
-
/**
|
|
2467
|
-
* Registers all elements supported by HeadingEditing to enable custom attributes for those elements.
|
|
2468
|
-
*/
|
|
2469
|
-
registerHeadingElements(editor, options) {
|
|
2470
|
-
const dataSchema = editor.plugins.get(DataSchema);
|
|
2471
|
-
const headerModels = [];
|
|
2472
|
-
for (const option of options) {
|
|
2473
|
-
if ('model' in option && 'view' in option) {
|
|
2474
|
-
dataSchema.registerBlockElement({
|
|
2475
|
-
view: option.view,
|
|
2476
|
-
model: option.model
|
|
2477
|
-
});
|
|
2478
|
-
headerModels.push(option.model);
|
|
2479
|
-
}
|
|
2480
|
-
}
|
|
2481
|
-
dataSchema.extendBlockElement({
|
|
2482
|
-
model: 'htmlHgroup',
|
|
2483
|
-
modelSchema: {
|
|
2484
|
-
allowChildren: headerModels
|
|
2485
|
-
}
|
|
2486
|
-
});
|
|
2487
|
-
}
|
|
2488
|
-
}
|
|
2489
|
-
|
|
2490
|
-
/**
|
|
2491
|
-
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
2492
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
2493
|
-
*/
|
|
2494
|
-
/**
|
|
2495
|
-
* @module html-support/integrations/integrationutils
|
|
2496
|
-
*/
|
|
2497
|
-
/**
|
|
2498
|
-
* Returns the first view element descendant matching the given view name.
|
|
2499
|
-
* Includes view element itself.
|
|
2500
|
-
*
|
|
2501
|
-
* @internal
|
|
2502
|
-
*/
|
|
2503
|
-
function getDescendantElement(writer, containerElement, elementName) {
|
|
2504
|
-
const range = writer.createRangeOn(containerElement);
|
|
2505
|
-
for (const { item } of range.getWalker()) {
|
|
2506
|
-
if (item.is('element', elementName)) {
|
|
2507
|
-
return item;
|
|
2508
|
-
}
|
|
2509
|
-
}
|
|
2510
|
-
}
|
|
2511
|
-
|
|
2512
|
-
/**
|
|
2513
|
-
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
2514
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
2515
|
-
*/
|
|
2516
|
-
/**
|
|
2517
|
-
* @module html-support/integrations/image
|
|
2518
|
-
*/
|
|
2519
|
-
/**
|
|
2520
|
-
* Provides the General HTML Support integration with the {@link module:image/image~Image Image} feature.
|
|
2521
|
-
*/
|
|
2522
|
-
class ImageElementSupport extends Plugin {
|
|
2523
|
-
/**
|
|
2524
|
-
* @inheritDoc
|
|
2525
|
-
*/
|
|
2526
|
-
static get requires() {
|
|
2527
|
-
return [DataFilter];
|
|
2528
|
-
}
|
|
2529
|
-
/**
|
|
2530
|
-
* @inheritDoc
|
|
2531
|
-
*/
|
|
2532
|
-
static get pluginName() {
|
|
2533
|
-
return 'ImageElementSupport';
|
|
2534
|
-
}
|
|
2535
|
-
/**
|
|
2536
|
-
* @inheritDoc
|
|
2537
|
-
*/
|
|
2538
|
-
init() {
|
|
2539
|
-
const editor = this.editor;
|
|
2540
|
-
// At least one image plugin should be loaded for the integration to work properly.
|
|
2541
|
-
if (!editor.plugins.has('ImageInlineEditing') && !editor.plugins.has('ImageBlockEditing')) {
|
|
2542
|
-
return;
|
|
2543
|
-
}
|
|
2544
|
-
const schema = editor.model.schema;
|
|
2545
|
-
const conversion = editor.conversion;
|
|
2546
|
-
const dataFilter = editor.plugins.get(DataFilter);
|
|
2547
|
-
dataFilter.on('register:figure', () => {
|
|
2548
|
-
conversion.for('upcast').add(viewToModelFigureAttributeConverter$1(dataFilter));
|
|
2549
|
-
});
|
|
2550
|
-
dataFilter.on('register:img', (evt, definition) => {
|
|
2551
|
-
if (definition.model !== 'imageBlock' && definition.model !== 'imageInline') {
|
|
2552
|
-
return;
|
|
2553
|
-
}
|
|
2554
|
-
if (schema.isRegistered('imageBlock')) {
|
|
2555
|
-
schema.extend('imageBlock', {
|
|
2556
|
-
allowAttributes: [
|
|
2557
|
-
'htmlImgAttributes',
|
|
2558
|
-
// Figure and Link don't have model counterpart.
|
|
2559
|
-
// We will preserve attributes on image model element using these attribute keys.
|
|
2560
|
-
'htmlFigureAttributes',
|
|
2561
|
-
'htmlLinkAttributes'
|
|
2562
|
-
]
|
|
2563
|
-
});
|
|
2564
|
-
}
|
|
2565
|
-
if (schema.isRegistered('imageInline')) {
|
|
2566
|
-
schema.extend('imageInline', {
|
|
2567
|
-
allowAttributes: [
|
|
2568
|
-
// `htmlA` is needed for standard GHS link integration.
|
|
2569
|
-
'htmlA',
|
|
2570
|
-
'htmlImgAttributes'
|
|
2571
|
-
]
|
|
2572
|
-
});
|
|
2573
|
-
}
|
|
2574
|
-
conversion.for('upcast').add(viewToModelImageAttributeConverter(dataFilter));
|
|
2575
|
-
conversion.for('downcast').add(modelToViewImageAttributeConverter());
|
|
2576
|
-
if (editor.plugins.has('LinkImage')) {
|
|
2577
|
-
conversion.for('upcast').add(viewToModelLinkImageAttributeConverter(dataFilter, editor));
|
|
2578
|
-
}
|
|
2579
|
-
evt.stop();
|
|
2580
|
-
});
|
|
2581
|
-
}
|
|
2582
|
-
}
|
|
2583
|
-
/**
|
|
2584
|
-
* View-to-model conversion helper preserving allowed attributes on the {@link module:image/image~Image Image}
|
|
2585
|
-
* feature model element.
|
|
2586
|
-
*
|
|
2587
|
-
* @returns Returns a conversion callback.
|
|
2588
|
-
*/
|
|
2589
|
-
function viewToModelImageAttributeConverter(dataFilter) {
|
|
2590
|
-
return (dispatcher) => {
|
|
2591
|
-
dispatcher.on('element:img', (evt, data, conversionApi) => {
|
|
2592
|
-
if (!data.modelRange) {
|
|
2593
|
-
return;
|
|
2594
|
-
}
|
|
2595
|
-
const viewImageElement = data.viewItem;
|
|
2596
|
-
const viewAttributes = dataFilter.processViewAttributes(viewImageElement, conversionApi);
|
|
2597
|
-
if (viewAttributes) {
|
|
2598
|
-
conversionApi.writer.setAttribute('htmlImgAttributes', viewAttributes, data.modelRange);
|
|
2599
|
-
}
|
|
2600
|
-
}, { priority: 'low' });
|
|
2601
|
-
};
|
|
2602
|
-
}
|
|
2603
|
-
/**
|
|
2604
|
-
* View-to-model conversion helper preserving allowed attributes on {@link module:image/image~Image Image}
|
|
2605
|
-
* feature model element from link view element.
|
|
2606
|
-
*
|
|
2607
|
-
* @returns Returns a conversion callback.
|
|
2608
|
-
*/
|
|
2609
|
-
function viewToModelLinkImageAttributeConverter(dataFilter, editor) {
|
|
2610
|
-
const imageUtils = editor.plugins.get('ImageUtils');
|
|
2611
|
-
return (dispatcher) => {
|
|
2612
|
-
dispatcher.on('element:a', (evt, data, conversionApi) => {
|
|
2613
|
-
const viewLink = data.viewItem;
|
|
2614
|
-
const viewImage = imageUtils.findViewImgElement(viewLink);
|
|
2615
|
-
if (!viewImage) {
|
|
2616
|
-
return;
|
|
2617
|
-
}
|
|
2618
|
-
const modelImage = data.modelCursor.parent;
|
|
2619
|
-
if (!modelImage.is('element', 'imageBlock')) {
|
|
2620
|
-
return;
|
|
2621
|
-
}
|
|
2622
|
-
const viewAttributes = dataFilter.processViewAttributes(viewLink, conversionApi);
|
|
2623
|
-
if (viewAttributes) {
|
|
2624
|
-
conversionApi.writer.setAttribute('htmlLinkAttributes', viewAttributes, modelImage);
|
|
2625
|
-
}
|
|
2626
|
-
}, { priority: 'low' });
|
|
2627
|
-
};
|
|
2628
|
-
}
|
|
2629
|
-
/**
|
|
2630
|
-
* View-to-model conversion helper preserving allowed attributes on {@link module:image/image~Image Image}
|
|
2631
|
-
* feature model element from figure view element.
|
|
2632
|
-
*
|
|
2633
|
-
* @returns Returns a conversion callback.
|
|
2634
|
-
*/
|
|
2635
|
-
function viewToModelFigureAttributeConverter$1(dataFilter) {
|
|
2636
|
-
return (dispatcher) => {
|
|
2637
|
-
dispatcher.on('element:figure', (evt, data, conversionApi) => {
|
|
2638
|
-
const viewFigureElement = data.viewItem;
|
|
2639
|
-
if (!data.modelRange || !viewFigureElement.hasClass('image')) {
|
|
2640
|
-
return;
|
|
2641
|
-
}
|
|
2642
|
-
const viewAttributes = dataFilter.processViewAttributes(viewFigureElement, conversionApi);
|
|
2643
|
-
if (viewAttributes) {
|
|
2644
|
-
conversionApi.writer.setAttribute('htmlFigureAttributes', viewAttributes, data.modelRange);
|
|
2645
|
-
}
|
|
2646
|
-
}, { priority: 'low' });
|
|
2647
|
-
};
|
|
2648
|
-
}
|
|
2649
|
-
/**
|
|
2650
|
-
* A model-to-view conversion helper applying attributes from the {@link module:image/image~Image Image}
|
|
2651
|
-
* feature.
|
|
2652
|
-
* @returns Returns a conversion callback.
|
|
2653
|
-
*/
|
|
2654
|
-
function modelToViewImageAttributeConverter() {
|
|
2655
|
-
return (dispatcher) => {
|
|
2656
|
-
addInlineAttributeConversion('htmlImgAttributes');
|
|
2657
|
-
addBlockAttributeConversion('img', 'htmlImgAttributes');
|
|
2658
|
-
addBlockAttributeConversion('figure', 'htmlFigureAttributes');
|
|
2659
|
-
addBlockAttributeConversion('a', 'htmlLinkAttributes');
|
|
2660
|
-
function addInlineAttributeConversion(attributeName) {
|
|
2661
|
-
dispatcher.on(`attribute:${attributeName}:imageInline`, (evt, data, conversionApi) => {
|
|
2662
|
-
if (!conversionApi.consumable.consume(data.item, evt.name)) {
|
|
2663
|
-
return;
|
|
2664
|
-
}
|
|
2665
|
-
const { attributeOldValue, attributeNewValue } = data;
|
|
2666
|
-
const viewElement = conversionApi.mapper.toViewElement(data.item);
|
|
2667
|
-
updateViewAttributes(conversionApi.writer, attributeOldValue, attributeNewValue, viewElement);
|
|
2668
|
-
}, { priority: 'low' });
|
|
2669
|
-
}
|
|
2670
|
-
function addBlockAttributeConversion(elementName, attributeName) {
|
|
2671
|
-
dispatcher.on(`attribute:${attributeName}:imageBlock`, (evt, data, conversionApi) => {
|
|
2672
|
-
if (!conversionApi.consumable.test(data.item, evt.name)) {
|
|
2673
|
-
return;
|
|
2674
|
-
}
|
|
2675
|
-
const { attributeOldValue, attributeNewValue } = data;
|
|
2676
|
-
const containerElement = conversionApi.mapper.toViewElement(data.item);
|
|
2677
|
-
const viewElement = getDescendantElement(conversionApi.writer, containerElement, elementName);
|
|
2678
|
-
if (viewElement) {
|
|
2679
|
-
updateViewAttributes(conversionApi.writer, attributeOldValue, attributeNewValue, viewElement);
|
|
2680
|
-
conversionApi.consumable.consume(data.item, evt.name);
|
|
2681
|
-
}
|
|
2682
|
-
}, { priority: 'low' });
|
|
2683
|
-
if (elementName === 'a') {
|
|
2684
|
-
// To have a link element in the view, we need to attach a converter to the `linkHref` attribute as well.
|
|
2685
|
-
dispatcher.on('attribute:linkHref:imageBlock', (evt, data, conversionApi) => {
|
|
2686
|
-
if (!conversionApi.consumable.consume(data.item, 'attribute:htmlLinkAttributes:imageBlock')) {
|
|
2687
|
-
return;
|
|
2688
|
-
}
|
|
2689
|
-
const containerElement = conversionApi.mapper.toViewElement(data.item);
|
|
2690
|
-
const viewElement = getDescendantElement(conversionApi.writer, containerElement, 'a');
|
|
2691
|
-
setViewAttributes(conversionApi.writer, data.item.getAttribute('htmlLinkAttributes'), viewElement);
|
|
2692
|
-
}, { priority: 'low' });
|
|
2693
|
-
}
|
|
2694
|
-
}
|
|
2695
|
-
};
|
|
2696
|
-
}
|
|
2697
|
-
|
|
2698
|
-
/**
|
|
2699
|
-
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
2700
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
2701
|
-
*/
|
|
2702
|
-
/**
|
|
2703
|
-
* @module html-support/integrations/mediaembed
|
|
2704
|
-
*/
|
|
2705
|
-
/**
|
|
2706
|
-
* Provides the General HTML Support integration with {@link module:media-embed/mediaembed~MediaEmbed Media Embed} feature.
|
|
2707
|
-
*/
|
|
2708
|
-
class MediaEmbedElementSupport extends Plugin {
|
|
2709
|
-
/**
|
|
2710
|
-
* @inheritDoc
|
|
2711
|
-
*/
|
|
2712
|
-
static get requires() {
|
|
2713
|
-
return [DataFilter];
|
|
2714
|
-
}
|
|
2715
|
-
/**
|
|
2716
|
-
* @inheritDoc
|
|
2717
|
-
*/
|
|
2718
|
-
static get pluginName() {
|
|
2719
|
-
return 'MediaEmbedElementSupport';
|
|
2720
|
-
}
|
|
2721
|
-
/**
|
|
2722
|
-
* @inheritDoc
|
|
2723
|
-
*/
|
|
2724
|
-
init() {
|
|
2725
|
-
const editor = this.editor;
|
|
2726
|
-
// Stop here if MediaEmbed plugin is not provided or the integrator wants to output markup with previews as
|
|
2727
|
-
// we do not support filtering previews.
|
|
2728
|
-
if (!editor.plugins.has('MediaEmbed') || editor.config.get('mediaEmbed.previewsInData')) {
|
|
2729
|
-
return;
|
|
2730
|
-
}
|
|
2731
|
-
const schema = editor.model.schema;
|
|
2732
|
-
const conversion = editor.conversion;
|
|
2733
|
-
const dataFilter = this.editor.plugins.get(DataFilter);
|
|
2734
|
-
const dataSchema = this.editor.plugins.get(DataSchema);
|
|
2735
|
-
const mediaElementName = editor.config.get('mediaEmbed.elementName');
|
|
2736
|
-
// Overwrite GHS schema definition for a given elementName.
|
|
2737
|
-
dataSchema.registerBlockElement({
|
|
2738
|
-
model: 'media',
|
|
2739
|
-
view: mediaElementName
|
|
2740
|
-
});
|
|
2741
|
-
dataFilter.on('register:figure', () => {
|
|
2742
|
-
conversion.for('upcast').add(viewToModelFigureAttributesConverter(dataFilter));
|
|
2743
|
-
});
|
|
2744
|
-
dataFilter.on(`register:${mediaElementName}`, (evt, definition) => {
|
|
2745
|
-
if (definition.model !== 'media') {
|
|
2746
|
-
return;
|
|
2747
|
-
}
|
|
2748
|
-
schema.extend('media', {
|
|
2749
|
-
allowAttributes: [
|
|
2750
|
-
getHtmlAttributeName(mediaElementName),
|
|
2751
|
-
'htmlFigureAttributes'
|
|
2752
|
-
]
|
|
2753
|
-
});
|
|
2754
|
-
conversion.for('upcast').add(viewToModelMediaAttributesConverter(dataFilter, mediaElementName));
|
|
2755
|
-
conversion.for('dataDowncast').add(modelToViewMediaAttributeConverter(mediaElementName));
|
|
2756
|
-
evt.stop();
|
|
2757
|
-
});
|
|
2758
|
-
}
|
|
2759
|
-
}
|
|
2760
|
-
function viewToModelMediaAttributesConverter(dataFilter, mediaElementName) {
|
|
2761
|
-
const upcastMedia = (evt, data, conversionApi) => {
|
|
2762
|
-
const viewMediaElement = data.viewItem;
|
|
2763
|
-
preserveElementAttributes(viewMediaElement, getHtmlAttributeName(mediaElementName));
|
|
2764
|
-
function preserveElementAttributes(viewElement, attributeName) {
|
|
2765
|
-
const viewAttributes = dataFilter.processViewAttributes(viewElement, conversionApi);
|
|
2766
|
-
if (viewAttributes) {
|
|
2767
|
-
conversionApi.writer.setAttribute(attributeName, viewAttributes, data.modelRange);
|
|
2768
|
-
}
|
|
2769
|
-
}
|
|
2770
|
-
};
|
|
2771
|
-
return (dispatcher) => {
|
|
2772
|
-
dispatcher.on(`element:${mediaElementName}`, upcastMedia, { priority: 'low' });
|
|
2773
|
-
};
|
|
2774
|
-
}
|
|
2775
|
-
/**
|
|
2776
|
-
* View-to-model conversion helper preserving allowed attributes on {@link module:media-embed/mediaembed~MediaEmbed MediaEmbed}
|
|
2777
|
-
* feature model element from figure view element.
|
|
2778
|
-
*
|
|
2779
|
-
* @returns Returns a conversion callback.
|
|
2780
|
-
*/
|
|
2781
|
-
function viewToModelFigureAttributesConverter(dataFilter) {
|
|
2782
|
-
return (dispatcher) => {
|
|
2783
|
-
dispatcher.on('element:figure', (evt, data, conversionApi) => {
|
|
2784
|
-
const viewFigureElement = data.viewItem;
|
|
2785
|
-
if (!data.modelRange || !viewFigureElement.hasClass('media')) {
|
|
2786
|
-
return;
|
|
2787
|
-
}
|
|
2788
|
-
const viewAttributes = dataFilter.processViewAttributes(viewFigureElement, conversionApi);
|
|
2789
|
-
if (viewAttributes) {
|
|
2790
|
-
conversionApi.writer.setAttribute('htmlFigureAttributes', viewAttributes, data.modelRange);
|
|
2791
|
-
}
|
|
2792
|
-
}, { priority: 'low' });
|
|
2793
|
-
};
|
|
2794
|
-
}
|
|
2795
|
-
function modelToViewMediaAttributeConverter(mediaElementName) {
|
|
2796
|
-
return (dispatcher) => {
|
|
2797
|
-
addAttributeConversionDispatcherHandler(mediaElementName, getHtmlAttributeName(mediaElementName));
|
|
2798
|
-
addAttributeConversionDispatcherHandler('figure', 'htmlFigureAttributes');
|
|
2799
|
-
function addAttributeConversionDispatcherHandler(elementName, attributeName) {
|
|
2800
|
-
dispatcher.on(`attribute:${attributeName}:media`, (evt, data, conversionApi) => {
|
|
2801
|
-
if (!conversionApi.consumable.consume(data.item, evt.name)) {
|
|
2802
|
-
return;
|
|
2803
|
-
}
|
|
2804
|
-
const { attributeOldValue, attributeNewValue } = data;
|
|
2805
|
-
const containerElement = conversionApi.mapper.toViewElement(data.item);
|
|
2806
|
-
const viewElement = getDescendantElement(conversionApi.writer, containerElement, elementName);
|
|
2807
|
-
updateViewAttributes(conversionApi.writer, attributeOldValue, attributeNewValue, viewElement);
|
|
2808
|
-
});
|
|
2809
|
-
}
|
|
2810
|
-
};
|
|
2811
|
-
}
|
|
2812
|
-
|
|
2813
|
-
/**
|
|
2814
|
-
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
2815
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
2816
|
-
*/
|
|
2817
|
-
/**
|
|
2818
|
-
* @module html-support/integrations/script
|
|
2819
|
-
*/
|
|
2820
|
-
/**
|
|
2821
|
-
* Provides the General HTML Support for `script` elements.
|
|
2822
|
-
*/
|
|
2823
|
-
class ScriptElementSupport extends Plugin {
|
|
2824
|
-
/**
|
|
2825
|
-
* @inheritDoc
|
|
2826
|
-
*/
|
|
2827
|
-
static get requires() {
|
|
2828
|
-
return [DataFilter];
|
|
2829
|
-
}
|
|
2830
|
-
/**
|
|
2831
|
-
* @inheritDoc
|
|
2832
|
-
*/
|
|
2833
|
-
static get pluginName() {
|
|
2834
|
-
return 'ScriptElementSupport';
|
|
2835
|
-
}
|
|
2836
|
-
/**
|
|
2837
|
-
* @inheritDoc
|
|
2838
|
-
*/
|
|
2839
|
-
init() {
|
|
2840
|
-
const dataFilter = this.editor.plugins.get(DataFilter);
|
|
2841
|
-
dataFilter.on('register:script', (evt, definition) => {
|
|
2842
|
-
const editor = this.editor;
|
|
2843
|
-
const schema = editor.model.schema;
|
|
2844
|
-
const conversion = editor.conversion;
|
|
2845
|
-
schema.register('htmlScript', definition.modelSchema);
|
|
2846
|
-
schema.extend('htmlScript', {
|
|
2847
|
-
allowAttributes: ['htmlScriptAttributes', 'htmlContent'],
|
|
2848
|
-
isContent: true
|
|
2849
|
-
});
|
|
2850
|
-
editor.data.registerRawContentMatcher({
|
|
2851
|
-
name: 'script'
|
|
2852
|
-
});
|
|
2853
|
-
conversion.for('upcast').elementToElement({
|
|
2854
|
-
view: 'script',
|
|
2855
|
-
model: viewToModelObjectConverter(definition)
|
|
2856
|
-
});
|
|
2857
|
-
conversion.for('upcast').add(viewToModelBlockAttributeConverter(definition, dataFilter));
|
|
2858
|
-
conversion.for('downcast').elementToElement({
|
|
2859
|
-
model: 'htmlScript',
|
|
2860
|
-
view: (modelElement, { writer }) => {
|
|
2861
|
-
return createObjectView('script', modelElement, writer);
|
|
2862
|
-
}
|
|
2863
|
-
});
|
|
2864
|
-
conversion.for('downcast').add(modelToViewBlockAttributeConverter(definition));
|
|
2865
|
-
evt.stop();
|
|
2866
|
-
});
|
|
2867
|
-
}
|
|
2868
|
-
}
|
|
2869
|
-
|
|
2870
|
-
/**
|
|
2871
|
-
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
2872
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
2873
|
-
*/
|
|
2874
|
-
/**
|
|
2875
|
-
* Provides the General HTML Support integration with {@link module:table/table~Table Table} feature.
|
|
2876
|
-
*/
|
|
2877
|
-
class TableElementSupport extends Plugin {
|
|
2878
|
-
/**
|
|
2879
|
-
* @inheritDoc
|
|
2880
|
-
*/
|
|
2881
|
-
static get requires() {
|
|
2882
|
-
return [DataFilter];
|
|
2883
|
-
}
|
|
2884
|
-
/**
|
|
2885
|
-
* @inheritDoc
|
|
2886
|
-
*/
|
|
2887
|
-
static get pluginName() {
|
|
2888
|
-
return 'TableElementSupport';
|
|
2889
|
-
}
|
|
2890
|
-
/**
|
|
2891
|
-
* @inheritDoc
|
|
2892
|
-
*/
|
|
2893
|
-
init() {
|
|
2894
|
-
const editor = this.editor;
|
|
2895
|
-
if (!editor.plugins.has('TableEditing')) {
|
|
2896
|
-
return;
|
|
2897
|
-
}
|
|
2898
|
-
const schema = editor.model.schema;
|
|
2899
|
-
const conversion = editor.conversion;
|
|
2900
|
-
const dataFilter = editor.plugins.get(DataFilter);
|
|
2901
|
-
const tableUtils = editor.plugins.get('TableUtils');
|
|
2902
|
-
dataFilter.on('register:figure', () => {
|
|
2903
|
-
conversion.for('upcast').add(viewToModelFigureAttributeConverter(dataFilter));
|
|
2904
|
-
});
|
|
2905
|
-
dataFilter.on('register:table', (evt, definition) => {
|
|
2906
|
-
if (definition.model !== 'table') {
|
|
2907
|
-
return;
|
|
2908
|
-
}
|
|
2909
|
-
schema.extend('table', {
|
|
2910
|
-
allowAttributes: [
|
|
2911
|
-
'htmlTableAttributes',
|
|
2912
|
-
// Figure, thead and tbody elements don't have model counterparts.
|
|
2913
|
-
// We will be preserving attributes on table element using these attribute keys.
|
|
2914
|
-
'htmlFigureAttributes', 'htmlTheadAttributes', 'htmlTbodyAttributes'
|
|
2915
|
-
]
|
|
2916
|
-
});
|
|
2917
|
-
conversion.for('upcast').add(viewToModelTableAttributeConverter(dataFilter));
|
|
2918
|
-
conversion.for('downcast').add(modelToViewTableAttributeConverter());
|
|
2919
|
-
editor.model.document.registerPostFixer(createHeadingRowsPostFixer(editor.model, tableUtils));
|
|
2920
|
-
evt.stop();
|
|
2921
|
-
});
|
|
2922
|
-
}
|
|
2923
|
-
}
|
|
2924
|
-
/**
|
|
2925
|
-
* Creates a model post-fixer for thead and tbody GHS related attributes.
|
|
2926
|
-
*/
|
|
2927
|
-
function createHeadingRowsPostFixer(model, tableUtils) {
|
|
2928
|
-
return writer => {
|
|
2929
|
-
const changes = model.document.differ.getChanges();
|
|
2930
|
-
let wasFixed = false;
|
|
2931
|
-
for (const change of changes) {
|
|
2932
|
-
if (change.type != 'attribute' || change.attributeKey != 'headingRows') {
|
|
2933
|
-
continue;
|
|
2934
|
-
}
|
|
2935
|
-
const table = change.range.start.nodeAfter;
|
|
2936
|
-
const hasTHeadAttributes = table.getAttribute('htmlTheadAttributes');
|
|
2937
|
-
const hasTBodyAttributes = table.getAttribute('htmlTbodyAttributes');
|
|
2938
|
-
if (hasTHeadAttributes && !change.attributeNewValue) {
|
|
2939
|
-
writer.removeAttribute('htmlTheadAttributes', table);
|
|
2940
|
-
wasFixed = true;
|
|
2941
|
-
}
|
|
2942
|
-
else if (hasTBodyAttributes && change.attributeNewValue == tableUtils.getRows(table)) {
|
|
2943
|
-
writer.removeAttribute('htmlTbodyAttributes', table);
|
|
2944
|
-
wasFixed = true;
|
|
2945
|
-
}
|
|
2946
|
-
}
|
|
2947
|
-
return wasFixed;
|
|
2948
|
-
};
|
|
2949
|
-
}
|
|
2950
|
-
/**
|
|
2951
|
-
* View-to-model conversion helper preserving allowed attributes on {@link module:table/table~Table Table}
|
|
2952
|
-
* feature model element.
|
|
2953
|
-
*
|
|
2954
|
-
* @returns Returns a conversion callback.
|
|
2955
|
-
*/
|
|
2956
|
-
function viewToModelTableAttributeConverter(dataFilter) {
|
|
2957
|
-
return (dispatcher) => {
|
|
2958
|
-
dispatcher.on('element:table', (evt, data, conversionApi) => {
|
|
2959
|
-
if (!data.modelRange) {
|
|
2960
|
-
return;
|
|
2961
|
-
}
|
|
2962
|
-
const viewTableElement = data.viewItem;
|
|
2963
|
-
preserveElementAttributes(viewTableElement, 'htmlTableAttributes');
|
|
2964
|
-
for (const childNode of viewTableElement.getChildren()) {
|
|
2965
|
-
if (childNode.is('element', 'thead')) {
|
|
2966
|
-
preserveElementAttributes(childNode, 'htmlTheadAttributes');
|
|
2967
|
-
}
|
|
2968
|
-
if (childNode.is('element', 'tbody')) {
|
|
2969
|
-
preserveElementAttributes(childNode, 'htmlTbodyAttributes');
|
|
2970
|
-
}
|
|
2971
|
-
}
|
|
2972
|
-
function preserveElementAttributes(viewElement, attributeName) {
|
|
2973
|
-
const viewAttributes = dataFilter.processViewAttributes(viewElement, conversionApi);
|
|
2974
|
-
if (viewAttributes) {
|
|
2975
|
-
conversionApi.writer.setAttribute(attributeName, viewAttributes, data.modelRange);
|
|
2976
|
-
}
|
|
2977
|
-
}
|
|
2978
|
-
}, { priority: 'low' });
|
|
2979
|
-
};
|
|
2980
|
-
}
|
|
2981
|
-
/**
|
|
2982
|
-
* View-to-model conversion helper preserving allowed attributes on {@link module:table/table~Table Table}
|
|
2983
|
-
* feature model element from figure view element.
|
|
2984
|
-
*
|
|
2985
|
-
* @returns Returns a conversion callback.
|
|
2986
|
-
*/
|
|
2987
|
-
function viewToModelFigureAttributeConverter(dataFilter) {
|
|
2988
|
-
return (dispatcher) => {
|
|
2989
|
-
dispatcher.on('element:figure', (evt, data, conversionApi) => {
|
|
2990
|
-
const viewFigureElement = data.viewItem;
|
|
2991
|
-
if (!data.modelRange || !viewFigureElement.hasClass('table')) {
|
|
2992
|
-
return;
|
|
2993
|
-
}
|
|
2994
|
-
const viewAttributes = dataFilter.processViewAttributes(viewFigureElement, conversionApi);
|
|
2995
|
-
if (viewAttributes) {
|
|
2996
|
-
conversionApi.writer.setAttribute('htmlFigureAttributes', viewAttributes, data.modelRange);
|
|
2997
|
-
}
|
|
2998
|
-
}, { priority: 'low' });
|
|
2999
|
-
};
|
|
3000
|
-
}
|
|
3001
|
-
/**
|
|
3002
|
-
* Model-to-view conversion helper applying attributes from {@link module:table/table~Table Table}
|
|
3003
|
-
* feature.
|
|
3004
|
-
*
|
|
3005
|
-
* @returns Returns a conversion callback.
|
|
3006
|
-
*/
|
|
3007
|
-
function modelToViewTableAttributeConverter() {
|
|
3008
|
-
return (dispatcher) => {
|
|
3009
|
-
addAttributeConversionDispatcherHandler('table', 'htmlTableAttributes');
|
|
3010
|
-
addAttributeConversionDispatcherHandler('figure', 'htmlFigureAttributes');
|
|
3011
|
-
addAttributeConversionDispatcherHandler('thead', 'htmlTheadAttributes');
|
|
3012
|
-
addAttributeConversionDispatcherHandler('tbody', 'htmlTbodyAttributes');
|
|
3013
|
-
function addAttributeConversionDispatcherHandler(elementName, attributeName) {
|
|
3014
|
-
dispatcher.on(`attribute:${attributeName}:table`, (evt, data, conversionApi) => {
|
|
3015
|
-
if (!conversionApi.consumable.test(data.item, evt.name)) {
|
|
3016
|
-
return;
|
|
3017
|
-
}
|
|
3018
|
-
const containerElement = conversionApi.mapper.toViewElement(data.item);
|
|
3019
|
-
const viewElement = getDescendantElement(conversionApi.writer, containerElement, elementName);
|
|
3020
|
-
if (!viewElement) {
|
|
3021
|
-
return;
|
|
3022
|
-
}
|
|
3023
|
-
conversionApi.consumable.consume(data.item, evt.name);
|
|
3024
|
-
updateViewAttributes(conversionApi.writer, data.attributeOldValue, data.attributeNewValue, viewElement);
|
|
3025
|
-
});
|
|
3026
|
-
}
|
|
3027
|
-
};
|
|
3028
|
-
}
|
|
3029
|
-
|
|
3030
|
-
/**
|
|
3031
|
-
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
3032
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
3033
|
-
*/
|
|
3034
|
-
/**
|
|
3035
|
-
* @module html-support/integrations/style
|
|
3036
|
-
*/
|
|
3037
|
-
/**
|
|
3038
|
-
* Provides the General HTML Support for `style` elements.
|
|
3039
|
-
*/
|
|
3040
|
-
class StyleElementSupport extends Plugin {
|
|
3041
|
-
/**
|
|
3042
|
-
* @inheritDoc
|
|
3043
|
-
*/
|
|
3044
|
-
static get requires() {
|
|
3045
|
-
return [DataFilter];
|
|
3046
|
-
}
|
|
3047
|
-
/**
|
|
3048
|
-
* @inheritDoc
|
|
3049
|
-
*/
|
|
3050
|
-
static get pluginName() {
|
|
3051
|
-
return 'StyleElementSupport';
|
|
3052
|
-
}
|
|
3053
|
-
/**
|
|
3054
|
-
* @inheritDoc
|
|
3055
|
-
*/
|
|
3056
|
-
init() {
|
|
3057
|
-
const dataFilter = this.editor.plugins.get(DataFilter);
|
|
3058
|
-
dataFilter.on('register:style', (evt, definition) => {
|
|
3059
|
-
const editor = this.editor;
|
|
3060
|
-
const schema = editor.model.schema;
|
|
3061
|
-
const conversion = editor.conversion;
|
|
3062
|
-
schema.register('htmlStyle', definition.modelSchema);
|
|
3063
|
-
schema.extend('htmlStyle', {
|
|
3064
|
-
allowAttributes: ['htmlStyleAttributes', 'htmlContent'],
|
|
3065
|
-
isContent: true
|
|
3066
|
-
});
|
|
3067
|
-
editor.data.registerRawContentMatcher({
|
|
3068
|
-
name: 'style'
|
|
3069
|
-
});
|
|
3070
|
-
conversion.for('upcast').elementToElement({
|
|
3071
|
-
view: 'style',
|
|
3072
|
-
model: viewToModelObjectConverter(definition)
|
|
3073
|
-
});
|
|
3074
|
-
conversion.for('upcast').add(viewToModelBlockAttributeConverter(definition, dataFilter));
|
|
3075
|
-
conversion.for('downcast').elementToElement({
|
|
3076
|
-
model: 'htmlStyle',
|
|
3077
|
-
view: (modelElement, { writer }) => {
|
|
3078
|
-
return createObjectView('style', modelElement, writer);
|
|
3079
|
-
}
|
|
3080
|
-
});
|
|
3081
|
-
conversion.for('downcast').add(modelToViewBlockAttributeConverter(definition));
|
|
3082
|
-
evt.stop();
|
|
3083
|
-
});
|
|
3084
|
-
}
|
|
3085
|
-
}
|
|
3086
|
-
|
|
3087
|
-
/**
|
|
3088
|
-
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
3089
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
3090
|
-
*/
|
|
3091
|
-
/**
|
|
3092
|
-
* @module html-support/integrations/list
|
|
3093
|
-
*/
|
|
3094
|
-
/**
|
|
3095
|
-
* Provides the General HTML Support integration with the {@link module:list/list~List List} feature.
|
|
3096
|
-
*/
|
|
3097
|
-
class ListElementSupport extends Plugin {
|
|
3098
|
-
/**
|
|
3099
|
-
* @inheritDoc
|
|
3100
|
-
*/
|
|
3101
|
-
static get requires() {
|
|
3102
|
-
return [DataFilter];
|
|
3103
|
-
}
|
|
3104
|
-
/**
|
|
3105
|
-
* @inheritDoc
|
|
3106
|
-
*/
|
|
3107
|
-
static get pluginName() {
|
|
3108
|
-
return 'ListElementSupport';
|
|
3109
|
-
}
|
|
3110
|
-
/**
|
|
3111
|
-
* @inheritDoc
|
|
3112
|
-
*/
|
|
3113
|
-
init() {
|
|
3114
|
-
const editor = this.editor;
|
|
3115
|
-
if (!editor.plugins.has('ListEditing')) {
|
|
3116
|
-
return;
|
|
3117
|
-
}
|
|
3118
|
-
const schema = editor.model.schema;
|
|
3119
|
-
const conversion = editor.conversion;
|
|
3120
|
-
const dataFilter = editor.plugins.get(DataFilter);
|
|
3121
|
-
const listEditing = editor.plugins.get('ListEditing');
|
|
3122
|
-
const viewElements = ['ul', 'ol', 'li'];
|
|
3123
|
-
// Register downcast strategy.
|
|
3124
|
-
// Note that this must be done before document list editing registers conversion in afterInit.
|
|
3125
|
-
listEditing.registerDowncastStrategy({
|
|
3126
|
-
scope: 'item',
|
|
3127
|
-
attributeName: 'htmlLiAttributes',
|
|
3128
|
-
setAttributeOnDowncast: setViewAttributes
|
|
3129
|
-
});
|
|
3130
|
-
listEditing.registerDowncastStrategy({
|
|
3131
|
-
scope: 'list',
|
|
3132
|
-
attributeName: 'htmlUlAttributes',
|
|
3133
|
-
setAttributeOnDowncast: setViewAttributes
|
|
3134
|
-
});
|
|
3135
|
-
listEditing.registerDowncastStrategy({
|
|
3136
|
-
scope: 'list',
|
|
3137
|
-
attributeName: 'htmlOlAttributes',
|
|
3138
|
-
setAttributeOnDowncast: setViewAttributes
|
|
3139
|
-
});
|
|
3140
|
-
dataFilter.on('register', (evt, definition) => {
|
|
3141
|
-
if (!viewElements.includes(definition.view)) {
|
|
3142
|
-
return;
|
|
3143
|
-
}
|
|
3144
|
-
evt.stop();
|
|
3145
|
-
// Do not register same converters twice.
|
|
3146
|
-
if (schema.checkAttribute('$block', 'htmlLiAttributes')) {
|
|
3147
|
-
return;
|
|
3148
|
-
}
|
|
3149
|
-
const allowAttributes = viewElements.map(element => getHtmlAttributeName(element));
|
|
3150
|
-
schema.extend('$listItem', { allowAttributes });
|
|
3151
|
-
conversion.for('upcast').add(dispatcher => {
|
|
3152
|
-
dispatcher.on('element:ul', viewToModelListAttributeConverter('htmlUlAttributes', dataFilter), { priority: 'low' });
|
|
3153
|
-
dispatcher.on('element:ol', viewToModelListAttributeConverter('htmlOlAttributes', dataFilter), { priority: 'low' });
|
|
3154
|
-
dispatcher.on('element:li', viewToModelListAttributeConverter('htmlLiAttributes', dataFilter), { priority: 'low' });
|
|
3155
|
-
});
|
|
3156
|
-
});
|
|
3157
|
-
// Make sure that all items in a single list (items at the same level & listType) have the same properties.
|
|
3158
|
-
listEditing.on('postFixer', (evt, { listNodes, writer }) => {
|
|
3159
|
-
for (const { node, previousNodeInList } of listNodes) {
|
|
3160
|
-
// This is a first item of a nested list.
|
|
3161
|
-
if (!previousNodeInList) {
|
|
3162
|
-
continue;
|
|
3163
|
-
}
|
|
3164
|
-
if (previousNodeInList.getAttribute('listType') == node.getAttribute('listType')) {
|
|
3165
|
-
const attribute = getAttributeFromListType(previousNodeInList.getAttribute('listType'));
|
|
3166
|
-
const value = previousNodeInList.getAttribute(attribute);
|
|
3167
|
-
if (!isEqual(node.getAttribute(attribute), value) &&
|
|
3168
|
-
writer.model.schema.checkAttribute(node, attribute)) {
|
|
3169
|
-
writer.setAttribute(attribute, value, node);
|
|
3170
|
-
evt.return = true;
|
|
3171
|
-
}
|
|
3172
|
-
}
|
|
3173
|
-
if (previousNodeInList.getAttribute('listItemId') == node.getAttribute('listItemId')) {
|
|
3174
|
-
const value = previousNodeInList.getAttribute('htmlLiAttributes');
|
|
3175
|
-
if (!isEqual(node.getAttribute('htmlLiAttributes'), value) &&
|
|
3176
|
-
writer.model.schema.checkAttribute(node, 'htmlLiAttributes')) {
|
|
3177
|
-
writer.setAttribute('htmlLiAttributes', value, node);
|
|
3178
|
-
evt.return = true;
|
|
3179
|
-
}
|
|
3180
|
-
}
|
|
3181
|
-
}
|
|
3182
|
-
});
|
|
3183
|
-
// Remove `ol` attributes from `ul` elements and vice versa.
|
|
3184
|
-
listEditing.on('postFixer', (evt, { listNodes, writer }) => {
|
|
3185
|
-
for (const { node } of listNodes) {
|
|
3186
|
-
const listType = node.getAttribute('listType');
|
|
3187
|
-
if (listType !== 'numbered' && node.getAttribute('htmlOlAttributes')) {
|
|
3188
|
-
writer.removeAttribute('htmlOlAttributes', node);
|
|
3189
|
-
evt.return = true;
|
|
3190
|
-
}
|
|
3191
|
-
if (listType === 'numbered' && node.getAttribute('htmlUlAttributes')) {
|
|
3192
|
-
writer.removeAttribute('htmlUlAttributes', node);
|
|
3193
|
-
evt.return = true;
|
|
3194
|
-
}
|
|
3195
|
-
}
|
|
3196
|
-
});
|
|
3197
|
-
}
|
|
3198
|
-
/**
|
|
3199
|
-
* @inheritDoc
|
|
3200
|
-
*/
|
|
3201
|
-
afterInit() {
|
|
3202
|
-
const editor = this.editor;
|
|
3203
|
-
if (!editor.commands.get('indentList')) {
|
|
3204
|
-
return;
|
|
3205
|
-
}
|
|
3206
|
-
// Reset list attributes after indenting list items.
|
|
3207
|
-
const indentList = editor.commands.get('indentList');
|
|
3208
|
-
this.listenTo(indentList, 'afterExecute', (evt, changedBlocks) => {
|
|
3209
|
-
editor.model.change(writer => {
|
|
3210
|
-
for (const node of changedBlocks) {
|
|
3211
|
-
const attribute = getAttributeFromListType(node.getAttribute('listType'));
|
|
3212
|
-
if (!editor.model.schema.checkAttribute(node, attribute)) {
|
|
3213
|
-
continue;
|
|
3214
|
-
}
|
|
3215
|
-
// Just reset the attribute.
|
|
3216
|
-
// If there is a previous indented list that this node should be merged into,
|
|
3217
|
-
// the postfixer will unify all the attributes of both sub-lists.
|
|
3218
|
-
writer.setAttribute(attribute, {}, node);
|
|
3219
|
-
}
|
|
3220
|
-
});
|
|
3221
|
-
});
|
|
3222
|
-
}
|
|
3223
|
-
}
|
|
3224
|
-
/**
|
|
3225
|
-
* View-to-model conversion helper preserving allowed attributes on {@link TODO}
|
|
3226
|
-
* feature model element.
|
|
3227
|
-
*
|
|
3228
|
-
* @returns Returns a conversion callback.
|
|
3229
|
-
*/
|
|
3230
|
-
function viewToModelListAttributeConverter(attributeName, dataFilter) {
|
|
3231
|
-
return (evt, data, conversionApi) => {
|
|
3232
|
-
const viewElement = data.viewItem;
|
|
3233
|
-
if (!data.modelRange) {
|
|
3234
|
-
Object.assign(data, conversionApi.convertChildren(data.viewItem, data.modelCursor));
|
|
3235
|
-
}
|
|
3236
|
-
const viewAttributes = dataFilter.processViewAttributes(viewElement, conversionApi);
|
|
3237
|
-
for (const item of data.modelRange.getItems({ shallow: true })) {
|
|
3238
|
-
// Apply only to list item blocks.
|
|
3239
|
-
if (!item.hasAttribute('listItemId')) {
|
|
3240
|
-
continue;
|
|
3241
|
-
}
|
|
3242
|
-
// Set list attributes only on same level items, those nested deeper are already handled
|
|
3243
|
-
// by the recursive conversion.
|
|
3244
|
-
if (item.hasAttribute(attributeName)) {
|
|
3245
|
-
continue;
|
|
3246
|
-
}
|
|
3247
|
-
if (conversionApi.writer.model.schema.checkAttribute(item, attributeName)) {
|
|
3248
|
-
conversionApi.writer.setAttribute(attributeName, viewAttributes || {}, item);
|
|
3249
|
-
}
|
|
3250
|
-
}
|
|
3251
|
-
};
|
|
3252
|
-
}
|
|
3253
|
-
/**
|
|
3254
|
-
* Returns HTML attribute name based on provided list type.
|
|
3255
|
-
*/
|
|
3256
|
-
function getAttributeFromListType(listType) {
|
|
3257
|
-
return listType === 'numbered' ?
|
|
3258
|
-
'htmlOlAttributes' :
|
|
3259
|
-
'htmlUlAttributes';
|
|
3260
|
-
}
|
|
3261
|
-
|
|
3262
|
-
/**
|
|
3263
|
-
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
3264
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
3265
|
-
*/
|
|
3266
|
-
/**
|
|
3267
|
-
* @module html-support/integrations/customelement
|
|
3268
|
-
*/
|
|
3269
|
-
/* globals document */
|
|
3270
|
-
/**
|
|
3271
|
-
* Provides the General HTML Support for custom elements (not registered in the {@link module:html-support/dataschema~DataSchema}).
|
|
3272
|
-
*/
|
|
3273
|
-
class CustomElementSupport extends Plugin {
|
|
3274
|
-
/**
|
|
3275
|
-
* @inheritDoc
|
|
3276
|
-
*/
|
|
3277
|
-
static get requires() {
|
|
3278
|
-
return [DataFilter, DataSchema];
|
|
3279
|
-
}
|
|
3280
|
-
/**
|
|
3281
|
-
* @inheritDoc
|
|
3282
|
-
*/
|
|
3283
|
-
static get pluginName() {
|
|
3284
|
-
return 'CustomElementSupport';
|
|
3285
|
-
}
|
|
3286
|
-
/**
|
|
3287
|
-
* @inheritDoc
|
|
3288
|
-
*/
|
|
3289
|
-
init() {
|
|
3290
|
-
const dataFilter = this.editor.plugins.get(DataFilter);
|
|
3291
|
-
const dataSchema = this.editor.plugins.get(DataSchema);
|
|
3292
|
-
dataFilter.on('register:$customElement', (evt, definition) => {
|
|
3293
|
-
evt.stop();
|
|
3294
|
-
const editor = this.editor;
|
|
3295
|
-
const schema = editor.model.schema;
|
|
3296
|
-
const conversion = editor.conversion;
|
|
3297
|
-
const unsafeElements = editor.editing.view.domConverter.unsafeElements;
|
|
3298
|
-
const preLikeElements = editor.data.htmlProcessor.domConverter.preElements;
|
|
3299
|
-
schema.register(definition.model, definition.modelSchema);
|
|
3300
|
-
schema.extend(definition.model, {
|
|
3301
|
-
allowAttributes: ['htmlElementName', 'htmlCustomElementAttributes', 'htmlContent'],
|
|
3302
|
-
isContent: true
|
|
3303
|
-
});
|
|
3304
|
-
// For the `<template>` element we use only raw-content because DOM API exposes its content
|
|
3305
|
-
// only as a document fragment in the `content` property (or innerHTML).
|
|
3306
|
-
editor.data.htmlProcessor.domConverter.registerRawContentMatcher({ name: 'template' });
|
|
3307
|
-
// Being executed on the low priority, it will catch all elements that were not caught by other converters.
|
|
3308
|
-
conversion.for('upcast').elementToElement({
|
|
3309
|
-
view: /.*/,
|
|
3310
|
-
model: (viewElement, conversionApi) => {
|
|
3311
|
-
// Do not try to convert $comment fake element.
|
|
3312
|
-
if (viewElement.name == '$comment') {
|
|
3313
|
-
return null;
|
|
3314
|
-
}
|
|
3315
|
-
if (!isValidElementName(viewElement.name)) {
|
|
3316
|
-
return null;
|
|
3317
|
-
}
|
|
3318
|
-
// Allow for fallback only if this element is not defined in data schema to make sure
|
|
3319
|
-
// that this will handle only custom elements not registered in the data schema.
|
|
3320
|
-
if (dataSchema.getDefinitionsForView(viewElement.name).size) {
|
|
3321
|
-
return null;
|
|
3322
|
-
}
|
|
3323
|
-
// Make sure that this element will not render in the editing view.
|
|
3324
|
-
if (!unsafeElements.includes(viewElement.name)) {
|
|
3325
|
-
unsafeElements.push(viewElement.name);
|
|
3326
|
-
}
|
|
3327
|
-
// Make sure that whitespaces will not be trimmed or replaced by nbsps while stringify content.
|
|
3328
|
-
if (!preLikeElements.includes(viewElement.name)) {
|
|
3329
|
-
preLikeElements.push(viewElement.name);
|
|
3330
|
-
}
|
|
3331
|
-
const modelElement = conversionApi.writer.createElement(definition.model, {
|
|
3332
|
-
htmlElementName: viewElement.name
|
|
3333
|
-
});
|
|
3334
|
-
const htmlAttributes = dataFilter.processViewAttributes(viewElement, conversionApi);
|
|
3335
|
-
if (htmlAttributes) {
|
|
3336
|
-
conversionApi.writer.setAttribute('htmlCustomElementAttributes', htmlAttributes, modelElement);
|
|
3337
|
-
}
|
|
3338
|
-
let htmlContent;
|
|
3339
|
-
// For the `<template>` element we use only raw-content because DOM API exposes its content
|
|
3340
|
-
// only as a document fragment in the `content` property.
|
|
3341
|
-
if (viewElement.is('element', 'template') && viewElement.getCustomProperty('$rawContent')) {
|
|
3342
|
-
htmlContent = viewElement.getCustomProperty('$rawContent');
|
|
3343
|
-
}
|
|
3344
|
-
else {
|
|
3345
|
-
// Store the whole element in the attribute so that DomConverter will be able to use the pre like element context.
|
|
3346
|
-
const viewWriter = new UpcastWriter(viewElement.document);
|
|
3347
|
-
const documentFragment = viewWriter.createDocumentFragment(viewElement);
|
|
3348
|
-
const domFragment = editor.data.htmlProcessor.domConverter.viewToDom(documentFragment);
|
|
3349
|
-
const domElement = domFragment.firstChild;
|
|
3350
|
-
while (domElement.firstChild) {
|
|
3351
|
-
domFragment.appendChild(domElement.firstChild);
|
|
3352
|
-
}
|
|
3353
|
-
domElement.remove();
|
|
3354
|
-
htmlContent = editor.data.htmlProcessor.htmlWriter.getHtml(domFragment);
|
|
3355
|
-
}
|
|
3356
|
-
conversionApi.writer.setAttribute('htmlContent', htmlContent, modelElement);
|
|
3357
|
-
// Consume the content of the element.
|
|
3358
|
-
for (const { item } of editor.editing.view.createRangeIn(viewElement)) {
|
|
3359
|
-
conversionApi.consumable.consume(item, { name: true });
|
|
3360
|
-
}
|
|
3361
|
-
return modelElement;
|
|
3362
|
-
},
|
|
3363
|
-
converterPriority: 'low'
|
|
3364
|
-
});
|
|
3365
|
-
// Because this element is unsafe (DomConverter#unsafeElements), it will render as a transparent <span> but it must
|
|
3366
|
-
// be rendered anyway for the mapping between the model and the view to exist.
|
|
3367
|
-
conversion.for('editingDowncast').elementToElement({
|
|
3368
|
-
model: {
|
|
3369
|
-
name: definition.model,
|
|
3370
|
-
attributes: ['htmlElementName', 'htmlCustomElementAttributes', 'htmlContent']
|
|
3371
|
-
},
|
|
3372
|
-
view: (modelElement, { writer }) => {
|
|
3373
|
-
const viewName = modelElement.getAttribute('htmlElementName');
|
|
3374
|
-
const viewElement = writer.createRawElement(viewName);
|
|
3375
|
-
if (modelElement.hasAttribute('htmlCustomElementAttributes')) {
|
|
3376
|
-
setViewAttributes(writer, modelElement.getAttribute('htmlCustomElementAttributes'), viewElement);
|
|
3377
|
-
}
|
|
3378
|
-
return viewElement;
|
|
3379
|
-
}
|
|
3380
|
-
});
|
|
3381
|
-
conversion.for('dataDowncast').elementToElement({
|
|
3382
|
-
model: {
|
|
3383
|
-
name: definition.model,
|
|
3384
|
-
attributes: ['htmlElementName', 'htmlCustomElementAttributes', 'htmlContent']
|
|
3385
|
-
},
|
|
3386
|
-
view: (modelElement, { writer }) => {
|
|
3387
|
-
const viewName = modelElement.getAttribute('htmlElementName');
|
|
3388
|
-
const htmlContent = modelElement.getAttribute('htmlContent');
|
|
3389
|
-
const viewElement = writer.createRawElement(viewName, null, (domElement, domConverter) => {
|
|
3390
|
-
domConverter.setContentOf(domElement, htmlContent);
|
|
3391
|
-
});
|
|
3392
|
-
if (modelElement.hasAttribute('htmlCustomElementAttributes')) {
|
|
3393
|
-
setViewAttributes(writer, modelElement.getAttribute('htmlCustomElementAttributes'), viewElement);
|
|
3394
|
-
}
|
|
3395
|
-
return viewElement;
|
|
3396
|
-
}
|
|
3397
|
-
});
|
|
3398
|
-
});
|
|
3399
|
-
}
|
|
3400
|
-
}
|
|
3401
|
-
/**
|
|
3402
|
-
* Returns true if name is valid for a DOM element name.
|
|
3403
|
-
*/
|
|
3404
|
-
function isValidElementName(name) {
|
|
3405
|
-
try {
|
|
3406
|
-
document.createElement(name);
|
|
3407
|
-
}
|
|
3408
|
-
catch (error) {
|
|
3409
|
-
return false;
|
|
3410
|
-
}
|
|
3411
|
-
return true;
|
|
3412
|
-
}
|
|
3413
|
-
|
|
3414
|
-
/**
|
|
3415
|
-
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
3416
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
3417
|
-
*/
|
|
3418
|
-
/**
|
|
3419
|
-
* @module html-support/generalhtmlsupport
|
|
3420
|
-
*/
|
|
3421
|
-
/**
|
|
3422
|
-
* The General HTML Support feature.
|
|
3423
|
-
*
|
|
3424
|
-
* This is a "glue" plugin which initializes the {@link module:html-support/datafilter~DataFilter data filter} configuration
|
|
3425
|
-
* and features integration with the General HTML Support.
|
|
3426
|
-
*/
|
|
3427
|
-
class GeneralHtmlSupport extends Plugin {
|
|
3428
|
-
/**
|
|
3429
|
-
* @inheritDoc
|
|
3430
|
-
*/
|
|
3431
|
-
static get pluginName() {
|
|
3432
|
-
return 'GeneralHtmlSupport';
|
|
3433
|
-
}
|
|
3434
|
-
/**
|
|
3435
|
-
* @inheritDoc
|
|
3436
|
-
*/
|
|
3437
|
-
static get requires() {
|
|
3438
|
-
return [
|
|
3439
|
-
DataFilter,
|
|
3440
|
-
CodeBlockElementSupport,
|
|
3441
|
-
DualContentModelElementSupport,
|
|
3442
|
-
HeadingElementSupport,
|
|
3443
|
-
ImageElementSupport,
|
|
3444
|
-
MediaEmbedElementSupport,
|
|
3445
|
-
ScriptElementSupport,
|
|
3446
|
-
TableElementSupport,
|
|
3447
|
-
StyleElementSupport,
|
|
3448
|
-
ListElementSupport,
|
|
3449
|
-
CustomElementSupport
|
|
3450
|
-
];
|
|
3451
|
-
}
|
|
3452
|
-
/**
|
|
3453
|
-
* @inheritDoc
|
|
3454
|
-
*/
|
|
3455
|
-
init() {
|
|
3456
|
-
const editor = this.editor;
|
|
3457
|
-
const dataFilter = editor.plugins.get(DataFilter);
|
|
3458
|
-
// Load the allowed empty inline elements' configuration.
|
|
3459
|
-
// Note that this modifies DataSchema so must be loaded before registering filtering rules.
|
|
3460
|
-
dataFilter.loadAllowedEmptyElementsConfig(editor.config.get('htmlSupport.allowEmpty') || []);
|
|
3461
|
-
// Load the filtering configuration.
|
|
3462
|
-
dataFilter.loadAllowedConfig(editor.config.get('htmlSupport.allow') || []);
|
|
3463
|
-
dataFilter.loadDisallowedConfig(editor.config.get('htmlSupport.disallow') || []);
|
|
3464
|
-
}
|
|
3465
|
-
/**
|
|
3466
|
-
* Returns a GHS model attribute name related to a given view element name.
|
|
3467
|
-
*
|
|
3468
|
-
* @internal
|
|
3469
|
-
* @param viewElementName A view element name.
|
|
3470
|
-
*/
|
|
3471
|
-
getGhsAttributeNameForElement(viewElementName) {
|
|
3472
|
-
const dataSchema = this.editor.plugins.get('DataSchema');
|
|
3473
|
-
const definitions = Array.from(dataSchema.getDefinitionsForView(viewElementName, false));
|
|
3474
|
-
const inlineDefinition = definitions.find(definition => (definition.isInline && !definitions[0].isObject));
|
|
3475
|
-
if (inlineDefinition) {
|
|
3476
|
-
return inlineDefinition.model;
|
|
3477
|
-
}
|
|
3478
|
-
return getHtmlAttributeName(viewElementName);
|
|
3479
|
-
}
|
|
3480
|
-
/**
|
|
3481
|
-
* Updates GHS model attribute for a specified view element name, so it includes the given class name.
|
|
3482
|
-
*
|
|
3483
|
-
* @internal
|
|
3484
|
-
* @param viewElementName A view element name.
|
|
3485
|
-
* @param className The css class to add.
|
|
3486
|
-
* @param selectable The selection or element to update.
|
|
3487
|
-
*/
|
|
3488
|
-
addModelHtmlClass(viewElementName, className, selectable) {
|
|
3489
|
-
const model = this.editor.model;
|
|
3490
|
-
const ghsAttributeName = this.getGhsAttributeNameForElement(viewElementName);
|
|
3491
|
-
model.change(writer => {
|
|
3492
|
-
for (const item of getItemsToUpdateGhsAttribute(model, selectable, ghsAttributeName)) {
|
|
3493
|
-
modifyGhsAttribute(writer, item, ghsAttributeName, 'classes', classes => {
|
|
3494
|
-
for (const value of toArray(className)) {
|
|
3495
|
-
classes.add(value);
|
|
3496
|
-
}
|
|
3497
|
-
});
|
|
3498
|
-
}
|
|
3499
|
-
});
|
|
3500
|
-
}
|
|
3501
|
-
/**
|
|
3502
|
-
* Updates GHS model attribute for a specified view element name, so it does not include the given class name.
|
|
3503
|
-
*
|
|
3504
|
-
* @internal
|
|
3505
|
-
* @param viewElementName A view element name.
|
|
3506
|
-
* @param className The css class to remove.
|
|
3507
|
-
* @param selectable The selection or element to update.
|
|
3508
|
-
*/
|
|
3509
|
-
removeModelHtmlClass(viewElementName, className, selectable) {
|
|
3510
|
-
const model = this.editor.model;
|
|
3511
|
-
const ghsAttributeName = this.getGhsAttributeNameForElement(viewElementName);
|
|
3512
|
-
model.change(writer => {
|
|
3513
|
-
for (const item of getItemsToUpdateGhsAttribute(model, selectable, ghsAttributeName)) {
|
|
3514
|
-
modifyGhsAttribute(writer, item, ghsAttributeName, 'classes', classes => {
|
|
3515
|
-
for (const value of toArray(className)) {
|
|
3516
|
-
classes.delete(value);
|
|
3517
|
-
}
|
|
3518
|
-
});
|
|
3519
|
-
}
|
|
3520
|
-
});
|
|
3521
|
-
}
|
|
3522
|
-
/**
|
|
3523
|
-
* Updates GHS model attribute for a specified view element name, so it includes the given attribute.
|
|
3524
|
-
*
|
|
3525
|
-
* @param viewElementName A view element name.
|
|
3526
|
-
* @param attributes The object with attributes to set.
|
|
3527
|
-
* @param selectable The selection or element to update.
|
|
3528
|
-
*/
|
|
3529
|
-
setModelHtmlAttributes(viewElementName, attributes, selectable) {
|
|
3530
|
-
const model = this.editor.model;
|
|
3531
|
-
const ghsAttributeName = this.getGhsAttributeNameForElement(viewElementName);
|
|
3532
|
-
model.change(writer => {
|
|
3533
|
-
for (const item of getItemsToUpdateGhsAttribute(model, selectable, ghsAttributeName)) {
|
|
3534
|
-
modifyGhsAttribute(writer, item, ghsAttributeName, 'attributes', attributesMap => {
|
|
3535
|
-
for (const [key, value] of Object.entries(attributes)) {
|
|
3536
|
-
attributesMap.set(key, value);
|
|
3537
|
-
}
|
|
3538
|
-
});
|
|
3539
|
-
}
|
|
3540
|
-
});
|
|
3541
|
-
}
|
|
3542
|
-
/**
|
|
3543
|
-
* Updates GHS model attribute for a specified view element name, so it does not include the given attribute.
|
|
3544
|
-
*
|
|
3545
|
-
* @param viewElementName A view element name.
|
|
3546
|
-
* @param attributeName The attribute name (or names) to remove.
|
|
3547
|
-
* @param selectable The selection or element to update.
|
|
3548
|
-
*/
|
|
3549
|
-
removeModelHtmlAttributes(viewElementName, attributeName, selectable) {
|
|
3550
|
-
const model = this.editor.model;
|
|
3551
|
-
const ghsAttributeName = this.getGhsAttributeNameForElement(viewElementName);
|
|
3552
|
-
model.change(writer => {
|
|
3553
|
-
for (const item of getItemsToUpdateGhsAttribute(model, selectable, ghsAttributeName)) {
|
|
3554
|
-
modifyGhsAttribute(writer, item, ghsAttributeName, 'attributes', attributesMap => {
|
|
3555
|
-
for (const key of toArray(attributeName)) {
|
|
3556
|
-
attributesMap.delete(key);
|
|
3557
|
-
}
|
|
3558
|
-
});
|
|
3559
|
-
}
|
|
3560
|
-
});
|
|
3561
|
-
}
|
|
3562
|
-
/**
|
|
3563
|
-
* Updates GHS model attribute for a specified view element name, so it includes a given style.
|
|
3564
|
-
*
|
|
3565
|
-
* @param viewElementName A view element name.
|
|
3566
|
-
* @param styles The object with styles to set.
|
|
3567
|
-
* @param selectable The selection or element to update.
|
|
3568
|
-
*/
|
|
3569
|
-
setModelHtmlStyles(viewElementName, styles, selectable) {
|
|
3570
|
-
const model = this.editor.model;
|
|
3571
|
-
const ghsAttributeName = this.getGhsAttributeNameForElement(viewElementName);
|
|
3572
|
-
model.change(writer => {
|
|
3573
|
-
for (const item of getItemsToUpdateGhsAttribute(model, selectable, ghsAttributeName)) {
|
|
3574
|
-
modifyGhsAttribute(writer, item, ghsAttributeName, 'styles', stylesMap => {
|
|
3575
|
-
for (const [key, value] of Object.entries(styles)) {
|
|
3576
|
-
stylesMap.set(key, value);
|
|
3577
|
-
}
|
|
3578
|
-
});
|
|
3579
|
-
}
|
|
3580
|
-
});
|
|
3581
|
-
}
|
|
3582
|
-
/**
|
|
3583
|
-
* Updates GHS model attribute for a specified view element name, so it does not include a given style.
|
|
3584
|
-
*
|
|
3585
|
-
* @param viewElementName A view element name.
|
|
3586
|
-
* @param properties The style (or styles list) to remove.
|
|
3587
|
-
* @param selectable The selection or element to update.
|
|
3588
|
-
*/
|
|
3589
|
-
removeModelHtmlStyles(viewElementName, properties, selectable) {
|
|
3590
|
-
const model = this.editor.model;
|
|
3591
|
-
const ghsAttributeName = this.getGhsAttributeNameForElement(viewElementName);
|
|
3592
|
-
model.change(writer => {
|
|
3593
|
-
for (const item of getItemsToUpdateGhsAttribute(model, selectable, ghsAttributeName)) {
|
|
3594
|
-
modifyGhsAttribute(writer, item, ghsAttributeName, 'styles', stylesMap => {
|
|
3595
|
-
for (const key of toArray(properties)) {
|
|
3596
|
-
stylesMap.delete(key);
|
|
3597
|
-
}
|
|
3598
|
-
});
|
|
3599
|
-
}
|
|
3600
|
-
});
|
|
3601
|
-
}
|
|
3602
|
-
}
|
|
3603
|
-
/**
|
|
3604
|
-
* Returns an iterator over an items in the selectable that accept given GHS attribute.
|
|
3605
|
-
*/
|
|
3606
|
-
function* getItemsToUpdateGhsAttribute(model, selectable, ghsAttributeName) {
|
|
3607
|
-
if (!selectable) {
|
|
3608
|
-
return;
|
|
3609
|
-
}
|
|
3610
|
-
if (!(Symbol.iterator in selectable) && selectable.is('documentSelection') && selectable.isCollapsed) {
|
|
3611
|
-
if (model.schema.checkAttributeInSelection(selectable, ghsAttributeName)) {
|
|
3612
|
-
yield selectable;
|
|
3613
|
-
}
|
|
3614
|
-
}
|
|
3615
|
-
else {
|
|
3616
|
-
for (const range of getValidRangesForSelectable(model, selectable, ghsAttributeName)) {
|
|
3617
|
-
yield* range.getItems({ shallow: true });
|
|
3618
|
-
}
|
|
3619
|
-
}
|
|
3620
|
-
}
|
|
3621
|
-
/**
|
|
3622
|
-
* Translates a given selectable to an iterable of ranges.
|
|
3623
|
-
*/
|
|
3624
|
-
function getValidRangesForSelectable(model, selectable, ghsAttributeName) {
|
|
3625
|
-
if (!(Symbol.iterator in selectable) &&
|
|
3626
|
-
(selectable.is('node') ||
|
|
3627
|
-
selectable.is('$text') ||
|
|
3628
|
-
selectable.is('$textProxy'))) {
|
|
3629
|
-
if (model.schema.checkAttribute(selectable, ghsAttributeName)) {
|
|
3630
|
-
return [model.createRangeOn(selectable)];
|
|
3631
|
-
}
|
|
3632
|
-
else {
|
|
3633
|
-
return [];
|
|
3634
|
-
}
|
|
3635
|
-
}
|
|
3636
|
-
else {
|
|
3637
|
-
return model.schema.getValidRanges(model.createSelection(selectable).getRanges(), ghsAttributeName);
|
|
3638
|
-
}
|
|
3639
|
-
}
|
|
3640
|
-
|
|
3641
|
-
/**
|
|
3642
|
-
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
3643
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
3644
|
-
*/
|
|
3645
|
-
/**
|
|
3646
|
-
* The HTML comment feature. It preserves the HTML comments (`<!-- -->`) in the editor data.
|
|
3647
|
-
*
|
|
3648
|
-
* For a detailed overview, check the {@glink features/html/html-comments HTML comment feature documentation}.
|
|
3649
|
-
*/
|
|
3650
|
-
class HtmlComment extends Plugin {
|
|
3651
|
-
/**
|
|
3652
|
-
* @inheritDoc
|
|
3653
|
-
*/
|
|
3654
|
-
static get pluginName() {
|
|
3655
|
-
return 'HtmlComment';
|
|
3656
|
-
}
|
|
3657
|
-
/**
|
|
3658
|
-
* @inheritDoc
|
|
3659
|
-
*/
|
|
3660
|
-
init() {
|
|
3661
|
-
const editor = this.editor;
|
|
3662
|
-
const loadedCommentsContent = new Map();
|
|
3663
|
-
editor.data.processor.skipComments = false;
|
|
3664
|
-
// Allow storing comment's content as the $root attribute with the name `$comment:<unique id>`.
|
|
3665
|
-
editor.model.schema.addAttributeCheck((context, attributeName) => {
|
|
3666
|
-
if (context.endsWith('$root') && attributeName.startsWith('$comment')) {
|
|
3667
|
-
return true;
|
|
3668
|
-
}
|
|
3669
|
-
});
|
|
3670
|
-
// Convert the `$comment` view element to `$comment:<unique id>` marker and store its content (the comment itself) as a $root
|
|
3671
|
-
// attribute. The comment content is needed in the `dataDowncast` pipeline to re-create the comment node.
|
|
3672
|
-
editor.conversion.for('upcast').elementToMarker({
|
|
3673
|
-
view: '$comment',
|
|
3674
|
-
model: viewElement => {
|
|
3675
|
-
const markerUid = uid();
|
|
3676
|
-
const markerName = `$comment:${markerUid}`;
|
|
3677
|
-
const commentContent = viewElement.getCustomProperty('$rawContent');
|
|
3678
|
-
loadedCommentsContent.set(markerName, commentContent);
|
|
3679
|
-
return markerName;
|
|
3680
|
-
}
|
|
3681
|
-
});
|
|
3682
|
-
// Convert the `$comment` marker to `$comment` UI element with `$rawContent` custom property containing the comment content.
|
|
3683
|
-
editor.conversion.for('dataDowncast').markerToElement({
|
|
3684
|
-
model: '$comment',
|
|
3685
|
-
view: (modelElement, { writer }) => {
|
|
3686
|
-
let root = undefined;
|
|
3687
|
-
for (const rootName of this.editor.model.document.getRootNames()) {
|
|
3688
|
-
root = this.editor.model.document.getRoot(rootName);
|
|
3689
|
-
if (root.hasAttribute(modelElement.markerName)) {
|
|
3690
|
-
break;
|
|
3691
|
-
}
|
|
3692
|
-
}
|
|
3693
|
-
const markerName = modelElement.markerName;
|
|
3694
|
-
const commentContent = root.getAttribute(markerName);
|
|
3695
|
-
const comment = writer.createUIElement('$comment');
|
|
3696
|
-
writer.setCustomProperty('$rawContent', commentContent, comment);
|
|
3697
|
-
return comment;
|
|
3698
|
-
}
|
|
3699
|
-
});
|
|
3700
|
-
// Remove comments' markers and their corresponding $root attributes, which are moved to the graveyard.
|
|
3701
|
-
editor.model.document.registerPostFixer(writer => {
|
|
3702
|
-
let changed = false;
|
|
3703
|
-
const markers = editor.model.document.differ.getChangedMarkers().filter(marker => marker.name.startsWith('$comment:'));
|
|
3704
|
-
for (const marker of markers) {
|
|
3705
|
-
const { oldRange, newRange } = marker.data;
|
|
3706
|
-
if (oldRange && newRange && oldRange.root == newRange.root) {
|
|
3707
|
-
// The marker was moved in the same root. Don't do anything.
|
|
3708
|
-
continue;
|
|
3709
|
-
}
|
|
3710
|
-
if (oldRange) {
|
|
3711
|
-
// The comment marker was moved from one root to another (most probably to the graveyard).
|
|
3712
|
-
// Remove the related attribute from the previous root.
|
|
3713
|
-
const oldRoot = oldRange.root;
|
|
3714
|
-
if (oldRoot.hasAttribute(marker.name)) {
|
|
3715
|
-
writer.removeAttribute(marker.name, oldRoot);
|
|
3716
|
-
changed = true;
|
|
3717
|
-
}
|
|
3718
|
-
}
|
|
3719
|
-
if (newRange) {
|
|
3720
|
-
const newRoot = newRange.root;
|
|
3721
|
-
if (newRoot.rootName == '$graveyard') {
|
|
3722
|
-
// Comment marker was moved to the graveyard -- remove it entirely.
|
|
3723
|
-
writer.removeMarker(marker.name);
|
|
3724
|
-
changed = true;
|
|
3725
|
-
}
|
|
3726
|
-
else if (!newRoot.hasAttribute(marker.name)) {
|
|
3727
|
-
// Comment marker was just added or was moved to another root - updated roots attributes.
|
|
3728
|
-
//
|
|
3729
|
-
// Added fallback to `''` for the comment content in case if someone incorrectly added just the marker "by hand"
|
|
3730
|
-
// and forgot to add the root attribute or add them in different change blocks.
|
|
3731
|
-
//
|
|
3732
|
-
// It caused an infinite loop in one of the unit tests.
|
|
3733
|
-
writer.setAttribute(marker.name, loadedCommentsContent.get(marker.name) || '', newRoot);
|
|
3734
|
-
changed = true;
|
|
3735
|
-
}
|
|
3736
|
-
}
|
|
3737
|
-
}
|
|
3738
|
-
return changed;
|
|
3739
|
-
});
|
|
3740
|
-
// Delete all comment markers from the document before setting new data.
|
|
3741
|
-
editor.data.on('set', () => {
|
|
3742
|
-
for (const commentMarker of editor.model.markers.getMarkersGroup('$comment')) {
|
|
3743
|
-
this.removeHtmlComment(commentMarker.name);
|
|
3744
|
-
}
|
|
3745
|
-
}, { priority: 'high' });
|
|
3746
|
-
// Delete all comment markers that are within a removed range.
|
|
3747
|
-
// Delete all comment markers at the limit element boundaries if the whole content of the limit element is removed.
|
|
3748
|
-
editor.model.on('deleteContent', (evt, [selection]) => {
|
|
3749
|
-
for (const range of selection.getRanges()) {
|
|
3750
|
-
const limitElement = editor.model.schema.getLimitElement(range);
|
|
3751
|
-
const firstPosition = editor.model.createPositionAt(limitElement, 0);
|
|
3752
|
-
const lastPosition = editor.model.createPositionAt(limitElement, 'end');
|
|
3753
|
-
let affectedCommentIDs;
|
|
3754
|
-
if (firstPosition.isTouching(range.start) && lastPosition.isTouching(range.end)) {
|
|
3755
|
-
affectedCommentIDs = this.getHtmlCommentsInRange(editor.model.createRange(firstPosition, lastPosition));
|
|
3756
|
-
}
|
|
3757
|
-
else {
|
|
3758
|
-
affectedCommentIDs = this.getHtmlCommentsInRange(range, { skipBoundaries: true });
|
|
3759
|
-
}
|
|
3760
|
-
for (const commentMarkerID of affectedCommentIDs) {
|
|
3761
|
-
this.removeHtmlComment(commentMarkerID);
|
|
3762
|
-
}
|
|
3763
|
-
}
|
|
3764
|
-
}, { priority: 'high' });
|
|
3765
|
-
}
|
|
3766
|
-
/**
|
|
3767
|
-
* Creates an HTML comment on the specified position and returns its ID.
|
|
3768
|
-
*
|
|
3769
|
-
* *Note*: If two comments are created at the same position, the second comment will be inserted before the first one.
|
|
3770
|
-
*
|
|
3771
|
-
* @returns Comment ID. This ID can be later used to e.g. remove the comment from the content.
|
|
3772
|
-
*/
|
|
3773
|
-
createHtmlComment(position, content) {
|
|
3774
|
-
const id = uid();
|
|
3775
|
-
const editor = this.editor;
|
|
3776
|
-
const model = editor.model;
|
|
3777
|
-
const root = model.document.getRoot(position.root.rootName);
|
|
3778
|
-
const markerName = `$comment:${id}`;
|
|
3779
|
-
return model.change(writer => {
|
|
3780
|
-
const range = writer.createRange(position);
|
|
3781
|
-
writer.addMarker(markerName, {
|
|
3782
|
-
usingOperation: true,
|
|
3783
|
-
affectsData: true,
|
|
3784
|
-
range
|
|
3785
|
-
});
|
|
3786
|
-
writer.setAttribute(markerName, content, root);
|
|
3787
|
-
return markerName;
|
|
3788
|
-
});
|
|
3789
|
-
}
|
|
3790
|
-
/**
|
|
3791
|
-
* Removes an HTML comment with the given comment ID.
|
|
3792
|
-
*
|
|
3793
|
-
* It does nothing and returns `false` if the comment with the given ID does not exist.
|
|
3794
|
-
* Otherwise it removes the comment and returns `true`.
|
|
3795
|
-
*
|
|
3796
|
-
* Note that a comment can be removed also by removing the content around the comment.
|
|
3797
|
-
*
|
|
3798
|
-
* @param commentID The ID of the comment to be removed.
|
|
3799
|
-
* @returns `true` when the comment with the given ID was removed, `false` otherwise.
|
|
3800
|
-
*/
|
|
3801
|
-
removeHtmlComment(commentID) {
|
|
3802
|
-
const editor = this.editor;
|
|
3803
|
-
const marker = editor.model.markers.get(commentID);
|
|
3804
|
-
if (!marker) {
|
|
3805
|
-
return false;
|
|
3806
|
-
}
|
|
3807
|
-
editor.model.change(writer => {
|
|
3808
|
-
writer.removeMarker(marker);
|
|
3809
|
-
});
|
|
3810
|
-
return true;
|
|
3811
|
-
}
|
|
3812
|
-
/**
|
|
3813
|
-
* Gets the HTML comment data for the comment with a given ID.
|
|
3814
|
-
*
|
|
3815
|
-
* Returns `null` if the comment does not exist.
|
|
3816
|
-
*/
|
|
3817
|
-
getHtmlCommentData(commentID) {
|
|
3818
|
-
const editor = this.editor;
|
|
3819
|
-
const marker = editor.model.markers.get(commentID);
|
|
3820
|
-
if (!marker) {
|
|
3821
|
-
return null;
|
|
3822
|
-
}
|
|
3823
|
-
let content = '';
|
|
3824
|
-
for (const root of this.editor.model.document.getRoots()) {
|
|
3825
|
-
if (root.hasAttribute(commentID)) {
|
|
3826
|
-
content = root.getAttribute(commentID);
|
|
3827
|
-
break;
|
|
3828
|
-
}
|
|
3829
|
-
}
|
|
3830
|
-
return {
|
|
3831
|
-
content,
|
|
3832
|
-
position: marker.getStart()
|
|
3833
|
-
};
|
|
3834
|
-
}
|
|
3835
|
-
/**
|
|
3836
|
-
* Gets all HTML comments in the given range.
|
|
3837
|
-
*
|
|
3838
|
-
* By default, it includes comments at the range boundaries.
|
|
3839
|
-
*
|
|
3840
|
-
* @param range
|
|
3841
|
-
* @param options.skipBoundaries When set to `true` the range boundaries will be skipped.
|
|
3842
|
-
* @returns HTML comment IDs
|
|
3843
|
-
*/
|
|
3844
|
-
getHtmlCommentsInRange(range, { skipBoundaries = false } = {}) {
|
|
3845
|
-
const includeBoundaries = !skipBoundaries;
|
|
3846
|
-
// Unfortunately, MarkerCollection#getMarkersAtPosition() filters out collapsed markers.
|
|
3847
|
-
return Array.from(this.editor.model.markers.getMarkersGroup('$comment'))
|
|
3848
|
-
.filter(marker => isCommentMarkerInRange(marker, range))
|
|
3849
|
-
.map(marker => marker.name);
|
|
3850
|
-
function isCommentMarkerInRange(commentMarker, range) {
|
|
3851
|
-
const position = commentMarker.getRange().start;
|
|
3852
|
-
return ((position.isAfter(range.start) || (includeBoundaries && position.isEqual(range.start))) &&
|
|
3853
|
-
(position.isBefore(range.end) || (includeBoundaries && position.isEqual(range.end))));
|
|
3854
|
-
}
|
|
3855
|
-
}
|
|
3856
|
-
}
|
|
3857
|
-
|
|
3858
|
-
/**
|
|
3859
|
-
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
3860
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
3861
|
-
*/
|
|
3862
|
-
/**
|
|
3863
|
-
* @module html-support/htmlpagedataprocessor
|
|
3864
|
-
*/
|
|
3865
|
-
/**
|
|
3866
|
-
* The full page HTML data processor class.
|
|
3867
|
-
* This data processor implementation uses HTML as input and output data.
|
|
3868
|
-
*/
|
|
3869
|
-
class HtmlPageDataProcessor extends HtmlDataProcessor {
|
|
3870
|
-
/**
|
|
3871
|
-
* @inheritDoc
|
|
3872
|
-
*/
|
|
3873
|
-
toView(data) {
|
|
3874
|
-
// Ignore content that is not a full page source.
|
|
3875
|
-
if (!data.match(/<(?:html|body|head|meta)(?:\s[^>]*)?>/i)) {
|
|
3876
|
-
return super.toView(data);
|
|
3877
|
-
}
|
|
3878
|
-
// Store doctype and xml declaration in a separate properties as they can't be stringified later.
|
|
3879
|
-
let docType = '';
|
|
3880
|
-
let xmlDeclaration = '';
|
|
3881
|
-
data = data.replace(/<!DOCTYPE[^>]*>/i, match => {
|
|
3882
|
-
docType = match;
|
|
3883
|
-
return '';
|
|
3884
|
-
});
|
|
3885
|
-
data = data.replace(/<\?xml\s[^?]*\?>/i, match => {
|
|
3886
|
-
xmlDeclaration = match;
|
|
3887
|
-
return '';
|
|
3888
|
-
});
|
|
3889
|
-
// Convert input HTML data to DOM DocumentFragment.
|
|
3890
|
-
const domFragment = this._toDom(data);
|
|
3891
|
-
// Convert DOM DocumentFragment to view DocumentFragment.
|
|
3892
|
-
const viewFragment = this.domConverter.domToView(domFragment, { skipComments: this.skipComments });
|
|
3893
|
-
const writer = new UpcastWriter(viewFragment.document);
|
|
3894
|
-
// Using the DOM document with body content extracted as a skeleton of the page.
|
|
3895
|
-
writer.setCustomProperty('$fullPageDocument', domFragment.ownerDocument.documentElement.outerHTML, viewFragment);
|
|
3896
|
-
if (docType) {
|
|
3897
|
-
writer.setCustomProperty('$fullPageDocType', docType, viewFragment);
|
|
3898
|
-
}
|
|
3899
|
-
if (xmlDeclaration) {
|
|
3900
|
-
writer.setCustomProperty('$fullPageXmlDeclaration', xmlDeclaration, viewFragment);
|
|
3901
|
-
}
|
|
3902
|
-
return viewFragment;
|
|
3903
|
-
}
|
|
3904
|
-
/**
|
|
3905
|
-
* @inheritDoc
|
|
3906
|
-
*/
|
|
3907
|
-
toData(viewFragment) {
|
|
3908
|
-
let data = super.toData(viewFragment);
|
|
3909
|
-
const page = viewFragment.getCustomProperty('$fullPageDocument');
|
|
3910
|
-
const docType = viewFragment.getCustomProperty('$fullPageDocType');
|
|
3911
|
-
const xmlDeclaration = viewFragment.getCustomProperty('$fullPageXmlDeclaration');
|
|
3912
|
-
if (page) {
|
|
3913
|
-
data = page.replace(/<\/body\s*>/, data + '$&');
|
|
3914
|
-
if (docType) {
|
|
3915
|
-
data = docType + '\n' + data;
|
|
3916
|
-
}
|
|
3917
|
-
if (xmlDeclaration) {
|
|
3918
|
-
data = xmlDeclaration + '\n' + data;
|
|
3919
|
-
}
|
|
3920
|
-
}
|
|
3921
|
-
return data;
|
|
3922
|
-
}
|
|
3923
|
-
}
|
|
3924
|
-
|
|
3925
|
-
/**
|
|
3926
|
-
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
3927
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
3928
|
-
*/
|
|
3929
|
-
/**
|
|
3930
|
-
* @module html-support/fullpage
|
|
3931
|
-
*/
|
|
3932
|
-
/**
|
|
3933
|
-
* The full page editing feature. It preserves the whole HTML page in the editor data.
|
|
3934
|
-
*/
|
|
3935
|
-
class FullPage extends Plugin {
|
|
3936
|
-
/**
|
|
3937
|
-
* @inheritDoc
|
|
3938
|
-
*/
|
|
3939
|
-
static get pluginName() {
|
|
3940
|
-
return 'FullPage';
|
|
3941
|
-
}
|
|
3942
|
-
/**
|
|
3943
|
-
* @inheritDoc
|
|
3944
|
-
*/
|
|
3945
|
-
init() {
|
|
3946
|
-
const editor = this.editor;
|
|
3947
|
-
const properties = ['$fullPageDocument', '$fullPageDocType', '$fullPageXmlDeclaration'];
|
|
3948
|
-
editor.data.processor = new HtmlPageDataProcessor(editor.data.viewDocument);
|
|
3949
|
-
editor.model.schema.extend('$root', {
|
|
3950
|
-
allowAttributes: properties
|
|
3951
|
-
});
|
|
3952
|
-
// Apply custom properties from view document fragment to the model root attributes.
|
|
3953
|
-
editor.data.on('toModel', (evt, [viewElementOrFragment]) => {
|
|
3954
|
-
const root = editor.model.document.getRoot();
|
|
3955
|
-
editor.model.change(writer => {
|
|
3956
|
-
for (const name of properties) {
|
|
3957
|
-
const value = viewElementOrFragment.getCustomProperty(name);
|
|
3958
|
-
if (value) {
|
|
3959
|
-
writer.setAttribute(name, value, root);
|
|
3960
|
-
}
|
|
3961
|
-
}
|
|
3962
|
-
});
|
|
3963
|
-
}, { priority: 'low' });
|
|
3964
|
-
// Apply root attributes to the view document fragment.
|
|
3965
|
-
editor.data.on('toView', (evt, [modelElementOrFragment]) => {
|
|
3966
|
-
if (!modelElementOrFragment.is('rootElement')) {
|
|
3967
|
-
return;
|
|
3968
|
-
}
|
|
3969
|
-
const root = modelElementOrFragment;
|
|
3970
|
-
const viewFragment = evt.return;
|
|
3971
|
-
if (!root.hasAttribute('$fullPageDocument')) {
|
|
3972
|
-
return;
|
|
3973
|
-
}
|
|
3974
|
-
const writer = new UpcastWriter(viewFragment.document);
|
|
3975
|
-
for (const name of properties) {
|
|
3976
|
-
const value = root.getAttribute(name);
|
|
3977
|
-
if (value) {
|
|
3978
|
-
writer.setCustomProperty(name, value, viewFragment);
|
|
3979
|
-
}
|
|
3980
|
-
}
|
|
3981
|
-
}, { priority: 'low' });
|
|
3982
|
-
// Clear root attributes related to full page editing on editor content reset.
|
|
3983
|
-
editor.data.on('set', () => {
|
|
3984
|
-
const root = editor.model.document.getRoot();
|
|
3985
|
-
editor.model.change(writer => {
|
|
3986
|
-
for (const name of properties) {
|
|
3987
|
-
if (root.hasAttribute(name)) {
|
|
3988
|
-
writer.removeAttribute(name, root);
|
|
3989
|
-
}
|
|
3990
|
-
}
|
|
3991
|
-
});
|
|
3992
|
-
}, { priority: 'high' });
|
|
3993
|
-
// Make sure that document is returned even if there is no content in the page body.
|
|
3994
|
-
editor.data.on('get', (evt, args) => {
|
|
3995
|
-
if (!args[0]) {
|
|
3996
|
-
args[0] = {};
|
|
3997
|
-
}
|
|
3998
|
-
args[0].trim = false;
|
|
3999
|
-
}, { priority: 'high' });
|
|
4000
|
-
}
|
|
4001
|
-
}
|
|
4002
|
-
|
|
4003
|
-
export { DataFilter, DataSchema, FullPage, GeneralHtmlSupport, HtmlComment, HtmlPageDataProcessor };
|
|
4004
|
-
//# sourceMappingURL=index.js.map
|