@ckeditor/ckeditor5-html-support 40.0.0 → 40.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +4 -4
- package/build/html-support.js +1 -1
- package/package.json +2 -2
- package/src/augmentation.d.ts +33 -33
- package/src/augmentation.js +5 -5
- package/src/converters.d.ts +60 -60
- package/src/converters.js +180 -180
- package/src/datafilter.d.ts +304 -304
- package/src/datafilter.js +720 -720
- package/src/dataschema.d.ts +183 -183
- package/src/dataschema.js +196 -196
- package/src/fullpage.d.ts +21 -21
- package/src/fullpage.js +80 -80
- package/src/generalhtmlsupport.d.ts +98 -98
- package/src/generalhtmlsupport.js +240 -240
- package/src/generalhtmlsupportconfig.d.ts +77 -77
- package/src/generalhtmlsupportconfig.js +5 -5
- package/src/htmlcomment.d.ts +71 -71
- package/src/htmlcomment.js +218 -218
- package/src/htmlpagedataprocessor.d.ts +22 -22
- package/src/htmlpagedataprocessor.js +67 -67
- package/src/index.d.ts +25 -25
- package/src/index.js +14 -14
- package/src/integrations/codeblock.d.ts +23 -23
- package/src/integrations/codeblock.js +101 -101
- package/src/integrations/customelement.d.ts +27 -27
- package/src/integrations/customelement.js +146 -146
- package/src/integrations/documentlist.d.ts +27 -27
- package/src/integrations/documentlist.js +178 -178
- package/src/integrations/dualcontent.d.ts +45 -45
- package/src/integrations/dualcontent.js +119 -119
- package/src/integrations/heading.d.ts +31 -31
- package/src/integrations/heading.js +60 -60
- package/src/integrations/image.d.ts +26 -26
- package/src/integrations/image.js +189 -189
- package/src/integrations/integrationutils.d.ts +15 -15
- package/src/integrations/integrationutils.js +21 -21
- package/src/integrations/mediaembed.d.ts +26 -26
- package/src/integrations/mediaembed.js +119 -119
- package/src/integrations/script.d.ts +26 -26
- package/src/integrations/script.js +59 -59
- package/src/integrations/style.d.ts +26 -26
- package/src/integrations/style.js +59 -59
- package/src/integrations/table.d.ts +23 -23
- package/src/integrations/table.js +163 -163
- package/src/schemadefinitions.d.ts +13 -13
- package/src/schemadefinitions.js +953 -956
- package/src/utils.d.ts +72 -72
- package/src/utils.js +139 -139
- package/build/html-support.js.map +0 -1
|
@@ -1,146 +1,146 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module html-support/integrations/customelement
|
|
7
|
-
*/
|
|
8
|
-
/* globals document */
|
|
9
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
10
|
-
import { UpcastWriter } from 'ckeditor5/src/engine';
|
|
11
|
-
import DataSchema from '../dataschema';
|
|
12
|
-
import DataFilter from '../datafilter';
|
|
13
|
-
import { setViewAttributes } from '../utils';
|
|
14
|
-
/**
|
|
15
|
-
* Provides the General HTML Support for custom elements (not registered in the {@link module:html-support/dataschema~DataSchema}).
|
|
16
|
-
*/
|
|
17
|
-
export default class CustomElementSupport extends Plugin {
|
|
18
|
-
/**
|
|
19
|
-
* @inheritDoc
|
|
20
|
-
*/
|
|
21
|
-
static get requires() {
|
|
22
|
-
return [DataFilter, DataSchema];
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* @inheritDoc
|
|
26
|
-
*/
|
|
27
|
-
static get pluginName() {
|
|
28
|
-
return 'CustomElementSupport';
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* @inheritDoc
|
|
32
|
-
*/
|
|
33
|
-
init() {
|
|
34
|
-
const dataFilter = this.editor.plugins.get(DataFilter);
|
|
35
|
-
const dataSchema = this.editor.plugins.get(DataSchema);
|
|
36
|
-
dataFilter.on('register:$customElement', (evt, definition) => {
|
|
37
|
-
evt.stop();
|
|
38
|
-
const editor = this.editor;
|
|
39
|
-
const schema = editor.model.schema;
|
|
40
|
-
const conversion = editor.conversion;
|
|
41
|
-
const unsafeElements = editor.editing.view.domConverter.unsafeElements;
|
|
42
|
-
const preLikeElements = editor.data.htmlProcessor.domConverter.preElements;
|
|
43
|
-
schema.register(definition.model, definition.modelSchema);
|
|
44
|
-
schema.extend(definition.model, {
|
|
45
|
-
allowAttributes: ['htmlElementName', 'htmlCustomElementAttributes', 'htmlContent'],
|
|
46
|
-
isContent: true
|
|
47
|
-
});
|
|
48
|
-
// Being executed on the low priority, it will catch all elements that were not caught by other converters.
|
|
49
|
-
conversion.for('upcast').elementToElement({
|
|
50
|
-
view: /.*/,
|
|
51
|
-
model: (viewElement, conversionApi) => {
|
|
52
|
-
// Do not try to convert $comment fake element.
|
|
53
|
-
if (viewElement.name == '$comment') {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
if (!isValidElementName(viewElement.name)) {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
// Allow for fallback only if this element is not defined in data schema to make sure
|
|
60
|
-
// that this will handle only custom elements not registered in the data schema.
|
|
61
|
-
if (dataSchema.getDefinitionsForView(viewElement.name).size) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
// Make sure that this element will not render in the editing view.
|
|
65
|
-
if (!unsafeElements.includes(viewElement.name)) {
|
|
66
|
-
unsafeElements.push(viewElement.name);
|
|
67
|
-
}
|
|
68
|
-
// Make sure that whitespaces will not be trimmed or replaced by nbsps while stringify content.
|
|
69
|
-
if (!preLikeElements.includes(viewElement.name)) {
|
|
70
|
-
preLikeElements.push(viewElement.name);
|
|
71
|
-
}
|
|
72
|
-
const modelElement = conversionApi.writer.createElement(definition.model, {
|
|
73
|
-
htmlElementName: viewElement.name
|
|
74
|
-
});
|
|
75
|
-
const htmlAttributes = dataFilter.processViewAttributes(viewElement, conversionApi);
|
|
76
|
-
if (htmlAttributes) {
|
|
77
|
-
conversionApi.writer.setAttribute('htmlCustomElementAttributes', htmlAttributes, modelElement);
|
|
78
|
-
}
|
|
79
|
-
// Store the whole element in the attribute so that DomConverter will be able to use the pre like element context.
|
|
80
|
-
const viewWriter = new UpcastWriter(viewElement.document);
|
|
81
|
-
const documentFragment = viewWriter.createDocumentFragment(viewElement);
|
|
82
|
-
const htmlContent = editor.data.processor.toData(documentFragment);
|
|
83
|
-
conversionApi.writer.setAttribute('htmlContent', htmlContent, modelElement);
|
|
84
|
-
// Consume the content of the element.
|
|
85
|
-
for (const { item } of editor.editing.view.createRangeIn(viewElement)) {
|
|
86
|
-
conversionApi.consumable.consume(item, { name: true });
|
|
87
|
-
}
|
|
88
|
-
return modelElement;
|
|
89
|
-
},
|
|
90
|
-
converterPriority: 'low'
|
|
91
|
-
});
|
|
92
|
-
// Because this element is unsafe (DomConverter#unsafeElements), it will render as a transparent <span> but it must
|
|
93
|
-
// be rendered anyway for the mapping between the model and the view to exist.
|
|
94
|
-
conversion.for('editingDowncast').elementToElement({
|
|
95
|
-
model: {
|
|
96
|
-
name: definition.model,
|
|
97
|
-
attributes: ['htmlElementName', 'htmlCustomElementAttributes', 'htmlContent']
|
|
98
|
-
},
|
|
99
|
-
view: (modelElement, { writer }) => {
|
|
100
|
-
const viewName = modelElement.getAttribute('htmlElementName');
|
|
101
|
-
const viewElement = writer.createRawElement(viewName);
|
|
102
|
-
if (modelElement.hasAttribute('htmlCustomElementAttributes')) {
|
|
103
|
-
setViewAttributes(writer, modelElement.getAttribute('htmlCustomElementAttributes'), viewElement);
|
|
104
|
-
}
|
|
105
|
-
return viewElement;
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
conversion.for('dataDowncast').elementToElement({
|
|
109
|
-
model: {
|
|
110
|
-
name: definition.model,
|
|
111
|
-
attributes: ['htmlElementName', 'htmlCustomElementAttributes', 'htmlContent']
|
|
112
|
-
},
|
|
113
|
-
view: (modelElement, { writer }) => {
|
|
114
|
-
const viewName = modelElement.getAttribute('htmlElementName');
|
|
115
|
-
const htmlContent = modelElement.getAttribute('htmlContent');
|
|
116
|
-
const viewElement = writer.createRawElement(viewName, null, (domElement, domConverter) => {
|
|
117
|
-
domConverter.setContentOf(domElement, htmlContent);
|
|
118
|
-
// Unwrap the custom element content (it was stored in the attribute as the whole custom element).
|
|
119
|
-
// See the upcast conversion for the "htmlContent" attribute to learn more.
|
|
120
|
-
const customElement = domElement.firstChild;
|
|
121
|
-
customElement.remove();
|
|
122
|
-
while (customElement.firstChild) {
|
|
123
|
-
domElement.appendChild(customElement.firstChild);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
if (modelElement.hasAttribute('htmlCustomElementAttributes')) {
|
|
127
|
-
setViewAttributes(writer, modelElement.getAttribute('htmlCustomElementAttributes'), viewElement);
|
|
128
|
-
}
|
|
129
|
-
return viewElement;
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Returns true if name is valid for a DOM element name.
|
|
137
|
-
*/
|
|
138
|
-
function isValidElementName(name) {
|
|
139
|
-
try {
|
|
140
|
-
document.createElement(name);
|
|
141
|
-
}
|
|
142
|
-
catch (error) {
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module html-support/integrations/customelement
|
|
7
|
+
*/
|
|
8
|
+
/* globals document */
|
|
9
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
10
|
+
import { UpcastWriter } from 'ckeditor5/src/engine';
|
|
11
|
+
import DataSchema from '../dataschema';
|
|
12
|
+
import DataFilter from '../datafilter';
|
|
13
|
+
import { setViewAttributes } from '../utils';
|
|
14
|
+
/**
|
|
15
|
+
* Provides the General HTML Support for custom elements (not registered in the {@link module:html-support/dataschema~DataSchema}).
|
|
16
|
+
*/
|
|
17
|
+
export default class CustomElementSupport extends Plugin {
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
static get requires() {
|
|
22
|
+
return [DataFilter, DataSchema];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @inheritDoc
|
|
26
|
+
*/
|
|
27
|
+
static get pluginName() {
|
|
28
|
+
return 'CustomElementSupport';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @inheritDoc
|
|
32
|
+
*/
|
|
33
|
+
init() {
|
|
34
|
+
const dataFilter = this.editor.plugins.get(DataFilter);
|
|
35
|
+
const dataSchema = this.editor.plugins.get(DataSchema);
|
|
36
|
+
dataFilter.on('register:$customElement', (evt, definition) => {
|
|
37
|
+
evt.stop();
|
|
38
|
+
const editor = this.editor;
|
|
39
|
+
const schema = editor.model.schema;
|
|
40
|
+
const conversion = editor.conversion;
|
|
41
|
+
const unsafeElements = editor.editing.view.domConverter.unsafeElements;
|
|
42
|
+
const preLikeElements = editor.data.htmlProcessor.domConverter.preElements;
|
|
43
|
+
schema.register(definition.model, definition.modelSchema);
|
|
44
|
+
schema.extend(definition.model, {
|
|
45
|
+
allowAttributes: ['htmlElementName', 'htmlCustomElementAttributes', 'htmlContent'],
|
|
46
|
+
isContent: true
|
|
47
|
+
});
|
|
48
|
+
// Being executed on the low priority, it will catch all elements that were not caught by other converters.
|
|
49
|
+
conversion.for('upcast').elementToElement({
|
|
50
|
+
view: /.*/,
|
|
51
|
+
model: (viewElement, conversionApi) => {
|
|
52
|
+
// Do not try to convert $comment fake element.
|
|
53
|
+
if (viewElement.name == '$comment') {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
if (!isValidElementName(viewElement.name)) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
// Allow for fallback only if this element is not defined in data schema to make sure
|
|
60
|
+
// that this will handle only custom elements not registered in the data schema.
|
|
61
|
+
if (dataSchema.getDefinitionsForView(viewElement.name).size) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
// Make sure that this element will not render in the editing view.
|
|
65
|
+
if (!unsafeElements.includes(viewElement.name)) {
|
|
66
|
+
unsafeElements.push(viewElement.name);
|
|
67
|
+
}
|
|
68
|
+
// Make sure that whitespaces will not be trimmed or replaced by nbsps while stringify content.
|
|
69
|
+
if (!preLikeElements.includes(viewElement.name)) {
|
|
70
|
+
preLikeElements.push(viewElement.name);
|
|
71
|
+
}
|
|
72
|
+
const modelElement = conversionApi.writer.createElement(definition.model, {
|
|
73
|
+
htmlElementName: viewElement.name
|
|
74
|
+
});
|
|
75
|
+
const htmlAttributes = dataFilter.processViewAttributes(viewElement, conversionApi);
|
|
76
|
+
if (htmlAttributes) {
|
|
77
|
+
conversionApi.writer.setAttribute('htmlCustomElementAttributes', htmlAttributes, modelElement);
|
|
78
|
+
}
|
|
79
|
+
// Store the whole element in the attribute so that DomConverter will be able to use the pre like element context.
|
|
80
|
+
const viewWriter = new UpcastWriter(viewElement.document);
|
|
81
|
+
const documentFragment = viewWriter.createDocumentFragment(viewElement);
|
|
82
|
+
const htmlContent = editor.data.processor.toData(documentFragment);
|
|
83
|
+
conversionApi.writer.setAttribute('htmlContent', htmlContent, modelElement);
|
|
84
|
+
// Consume the content of the element.
|
|
85
|
+
for (const { item } of editor.editing.view.createRangeIn(viewElement)) {
|
|
86
|
+
conversionApi.consumable.consume(item, { name: true });
|
|
87
|
+
}
|
|
88
|
+
return modelElement;
|
|
89
|
+
},
|
|
90
|
+
converterPriority: 'low'
|
|
91
|
+
});
|
|
92
|
+
// Because this element is unsafe (DomConverter#unsafeElements), it will render as a transparent <span> but it must
|
|
93
|
+
// be rendered anyway for the mapping between the model and the view to exist.
|
|
94
|
+
conversion.for('editingDowncast').elementToElement({
|
|
95
|
+
model: {
|
|
96
|
+
name: definition.model,
|
|
97
|
+
attributes: ['htmlElementName', 'htmlCustomElementAttributes', 'htmlContent']
|
|
98
|
+
},
|
|
99
|
+
view: (modelElement, { writer }) => {
|
|
100
|
+
const viewName = modelElement.getAttribute('htmlElementName');
|
|
101
|
+
const viewElement = writer.createRawElement(viewName);
|
|
102
|
+
if (modelElement.hasAttribute('htmlCustomElementAttributes')) {
|
|
103
|
+
setViewAttributes(writer, modelElement.getAttribute('htmlCustomElementAttributes'), viewElement);
|
|
104
|
+
}
|
|
105
|
+
return viewElement;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
conversion.for('dataDowncast').elementToElement({
|
|
109
|
+
model: {
|
|
110
|
+
name: definition.model,
|
|
111
|
+
attributes: ['htmlElementName', 'htmlCustomElementAttributes', 'htmlContent']
|
|
112
|
+
},
|
|
113
|
+
view: (modelElement, { writer }) => {
|
|
114
|
+
const viewName = modelElement.getAttribute('htmlElementName');
|
|
115
|
+
const htmlContent = modelElement.getAttribute('htmlContent');
|
|
116
|
+
const viewElement = writer.createRawElement(viewName, null, (domElement, domConverter) => {
|
|
117
|
+
domConverter.setContentOf(domElement, htmlContent);
|
|
118
|
+
// Unwrap the custom element content (it was stored in the attribute as the whole custom element).
|
|
119
|
+
// See the upcast conversion for the "htmlContent" attribute to learn more.
|
|
120
|
+
const customElement = domElement.firstChild;
|
|
121
|
+
customElement.remove();
|
|
122
|
+
while (customElement.firstChild) {
|
|
123
|
+
domElement.appendChild(customElement.firstChild);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
if (modelElement.hasAttribute('htmlCustomElementAttributes')) {
|
|
127
|
+
setViewAttributes(writer, modelElement.getAttribute('htmlCustomElementAttributes'), viewElement);
|
|
128
|
+
}
|
|
129
|
+
return viewElement;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Returns true if name is valid for a DOM element name.
|
|
137
|
+
*/
|
|
138
|
+
function isValidElementName(name) {
|
|
139
|
+
try {
|
|
140
|
+
document.createElement(name);
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
6
|
-
import DataFilter from '../datafilter';
|
|
7
|
-
/**
|
|
8
|
-
* Provides the General HTML Support integration with the {@link module:list/documentlist~DocumentList Document List} feature.
|
|
9
|
-
*/
|
|
10
|
-
export default class DocumentListElementSupport extends Plugin {
|
|
11
|
-
/**
|
|
12
|
-
* @inheritDoc
|
|
13
|
-
*/
|
|
14
|
-
static get requires(): readonly [typeof DataFilter];
|
|
15
|
-
/**
|
|
16
|
-
* @inheritDoc
|
|
17
|
-
*/
|
|
18
|
-
static get pluginName(): "DocumentListElementSupport";
|
|
19
|
-
/**
|
|
20
|
-
* @inheritDoc
|
|
21
|
-
*/
|
|
22
|
-
init(): void;
|
|
23
|
-
/**
|
|
24
|
-
* @inheritDoc
|
|
25
|
-
*/
|
|
26
|
-
afterInit(): void;
|
|
27
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
6
|
+
import DataFilter from '../datafilter';
|
|
7
|
+
/**
|
|
8
|
+
* Provides the General HTML Support integration with the {@link module:list/documentlist~DocumentList Document List} feature.
|
|
9
|
+
*/
|
|
10
|
+
export default class DocumentListElementSupport extends Plugin {
|
|
11
|
+
/**
|
|
12
|
+
* @inheritDoc
|
|
13
|
+
*/
|
|
14
|
+
static get requires(): readonly [typeof DataFilter];
|
|
15
|
+
/**
|
|
16
|
+
* @inheritDoc
|
|
17
|
+
*/
|
|
18
|
+
static get pluginName(): "DocumentListElementSupport";
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
init(): void;
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
afterInit(): void;
|
|
27
|
+
}
|