@ckeditor/ckeditor5-html-support 36.0.0 → 37.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/html-support.js +1 -1
- package/package.json +42 -36
- package/src/conversionutils.d.ts +42 -0
- package/src/conversionutils.js +57 -77
- package/src/converters.d.ts +56 -0
- package/src/converters.js +104 -156
- package/src/datafilter.d.ts +255 -0
- package/src/datafilter.js +566 -782
- package/src/dataschema.d.ts +174 -0
- package/src/dataschema.js +143 -229
- package/src/fullpage.d.ts +26 -0
- package/src/fullpage.js +65 -86
- package/src/generalhtmlsupport.d.ts +93 -0
- package/src/generalhtmlsupport.js +244 -327
- package/src/generalhtmlsupportconfig.d.ts +76 -0
- package/src/generalhtmlsupportconfig.js +5 -0
- package/src/htmlcomment.d.ts +77 -0
- package/src/htmlcomment.js +175 -239
- package/src/htmlpagedataprocessor.d.ts +22 -0
- package/src/htmlpagedataprocessor.js +53 -76
- package/src/index.d.ts +13 -0
- package/src/index.js +0 -2
- package/src/integrations/codeblock.d.ts +27 -0
- package/src/integrations/codeblock.js +87 -115
- package/src/integrations/customelement.d.ts +30 -0
- package/src/integrations/customelement.js +127 -160
- package/src/integrations/documentlist.d.ts +31 -0
- package/src/integrations/documentlist.js +154 -191
- package/src/integrations/dualcontent.d.ts +49 -0
- package/src/integrations/dualcontent.js +92 -128
- package/src/integrations/heading.d.ts +30 -0
- package/src/integrations/heading.js +41 -54
- package/src/integrations/image.d.ts +30 -0
- package/src/integrations/image.js +154 -212
- package/src/integrations/integrationutils.d.ts +15 -0
- package/src/integrations/integrationutils.js +21 -0
- package/src/integrations/mediaembed.d.ts +30 -0
- package/src/integrations/mediaembed.js +101 -147
- package/src/integrations/script.d.ts +30 -0
- package/src/integrations/script.js +45 -67
- package/src/integrations/style.d.ts +30 -0
- package/src/integrations/style.js +45 -67
- package/src/integrations/table.d.ts +27 -0
- package/src/integrations/table.js +113 -160
- package/src/schemadefinitions.d.ts +13 -0
- package/src/schemadefinitions.js +846 -835
|
@@ -2,206 +2,169 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module html-support/integrations/documentlist
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { isEqual } from 'lodash-es';
|
|
11
9
|
import { Plugin } from 'ckeditor5/src/core';
|
|
12
|
-
import { setViewAttributes } from '../conversionutils
|
|
13
|
-
|
|
10
|
+
import { setViewAttributes } from '../conversionutils';
|
|
14
11
|
import DataFilter from '../datafilter';
|
|
15
|
-
|
|
16
12
|
/**
|
|
17
13
|
* Provides the General HTML Support integration with the {@link module:list/documentlist~DocumentList Document List} feature.
|
|
18
|
-
*
|
|
19
|
-
* @extends module:core/plugin~Plugin
|
|
20
14
|
*/
|
|
21
15
|
export default class DocumentListElementSupport extends Plugin {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
} );
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* @inheritDoc
|
|
153
|
-
*/
|
|
154
|
-
afterInit() {
|
|
155
|
-
const editor = this.editor;
|
|
156
|
-
|
|
157
|
-
if ( !editor.commands.get( 'indentList' ) ) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Reset list attributes after indenting list items.
|
|
162
|
-
this.listenTo( editor.commands.get( 'indentList' ), 'afterExecute', ( evt, changedBlocks ) => {
|
|
163
|
-
editor.model.change( writer => {
|
|
164
|
-
for ( const node of changedBlocks ) {
|
|
165
|
-
// Just reset the attribute.
|
|
166
|
-
// If there is a previous indented list that this node should be merged into,
|
|
167
|
-
// the postfixer will unify all the attributes of both sub-lists.
|
|
168
|
-
writer.setAttribute( 'htmlListAttributes', {}, node );
|
|
169
|
-
}
|
|
170
|
-
} );
|
|
171
|
-
} );
|
|
172
|
-
}
|
|
16
|
+
/**
|
|
17
|
+
* @inheritDoc
|
|
18
|
+
*/
|
|
19
|
+
static get requires() {
|
|
20
|
+
return [DataFilter];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @inheritDoc
|
|
24
|
+
*/
|
|
25
|
+
static get pluginName() {
|
|
26
|
+
return 'DocumentListElementSupport';
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @inheritDoc
|
|
30
|
+
*/
|
|
31
|
+
init() {
|
|
32
|
+
const editor = this.editor;
|
|
33
|
+
if (!editor.plugins.has('DocumentListEditing')) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const schema = editor.model.schema;
|
|
37
|
+
const conversion = editor.conversion;
|
|
38
|
+
const dataFilter = editor.plugins.get(DataFilter);
|
|
39
|
+
const documentListEditing = editor.plugins.get('DocumentListEditing');
|
|
40
|
+
// Register downcast strategy.
|
|
41
|
+
// Note that this must be done before document list editing registers conversion in afterInit.
|
|
42
|
+
documentListEditing.registerDowncastStrategy({
|
|
43
|
+
scope: 'item',
|
|
44
|
+
attributeName: 'htmlLiAttributes',
|
|
45
|
+
setAttributeOnDowncast(writer, attributeValue, viewElement) {
|
|
46
|
+
setViewAttributes(writer, attributeValue, viewElement);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
documentListEditing.registerDowncastStrategy({
|
|
50
|
+
scope: 'list',
|
|
51
|
+
attributeName: 'htmlListAttributes',
|
|
52
|
+
setAttributeOnDowncast(writer, viewAttributes, viewElement) {
|
|
53
|
+
setViewAttributes(writer, viewAttributes, viewElement);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
dataFilter.on('register', (evt, definition) => {
|
|
57
|
+
if (!['ul', 'ol', 'li'].includes(definition.view)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
evt.stop();
|
|
61
|
+
// Do not register same converters twice.
|
|
62
|
+
if (schema.checkAttribute('$block', 'htmlListAttributes')) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
schema.extend('$block', { allowAttributes: ['htmlListAttributes', 'htmlLiAttributes'] });
|
|
66
|
+
schema.extend('$blockObject', { allowAttributes: ['htmlListAttributes', 'htmlLiAttributes'] });
|
|
67
|
+
schema.extend('$container', { allowAttributes: ['htmlListAttributes', 'htmlLiAttributes'] });
|
|
68
|
+
conversion.for('upcast').add(dispatcher => {
|
|
69
|
+
dispatcher.on('element:ul', viewToModelListAttributeConverter('htmlListAttributes', dataFilter), { priority: 'low' });
|
|
70
|
+
dispatcher.on('element:ol', viewToModelListAttributeConverter('htmlListAttributes', dataFilter), { priority: 'low' });
|
|
71
|
+
dispatcher.on('element:li', viewToModelListAttributeConverter('htmlLiAttributes', dataFilter), { priority: 'low' });
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
// Make sure that all items in a single list (items at the same level & listType) have the same properties.
|
|
75
|
+
// Note: This is almost an exact copy from DocumentListPropertiesEditing.
|
|
76
|
+
documentListEditing.on('postFixer', (evt, { listNodes, writer }) => {
|
|
77
|
+
const previousNodesByIndent = []; // Last seen nodes of lower indented lists.
|
|
78
|
+
for (const { node, previous } of listNodes) {
|
|
79
|
+
// For the first list block there is nothing to compare with.
|
|
80
|
+
if (!previous) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const nodeIndent = node.getAttribute('listIndent');
|
|
84
|
+
const previousNodeIndent = previous.getAttribute('listIndent');
|
|
85
|
+
let previousNodeInList = null; // It's like `previous` but has the same indent as current node.
|
|
86
|
+
// Let's find previous node for the same indent.
|
|
87
|
+
// We're going to need that when we get back to previous indent.
|
|
88
|
+
if (nodeIndent > previousNodeIndent) {
|
|
89
|
+
previousNodesByIndent[previousNodeIndent] = previous;
|
|
90
|
+
}
|
|
91
|
+
// Restore the one for given indent.
|
|
92
|
+
else if (nodeIndent < previousNodeIndent) {
|
|
93
|
+
previousNodeInList = previousNodesByIndent[nodeIndent];
|
|
94
|
+
previousNodesByIndent.length = nodeIndent;
|
|
95
|
+
}
|
|
96
|
+
// Same indent.
|
|
97
|
+
else {
|
|
98
|
+
previousNodeInList = previous;
|
|
99
|
+
}
|
|
100
|
+
// This is a first item of a nested list.
|
|
101
|
+
if (!previousNodeInList) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (previousNodeInList.getAttribute('listType') == node.getAttribute('listType')) {
|
|
105
|
+
const value = previousNodeInList.getAttribute('htmlListAttributes');
|
|
106
|
+
if (!isEqual(node.getAttribute('htmlListAttributes'), value)) {
|
|
107
|
+
writer.setAttribute('htmlListAttributes', value, node);
|
|
108
|
+
evt.return = true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (previousNodeInList.getAttribute('listItemId') == node.getAttribute('listItemId')) {
|
|
112
|
+
const value = previousNodeInList.getAttribute('htmlLiAttributes');
|
|
113
|
+
if (!isEqual(node.getAttribute('htmlLiAttributes'), value)) {
|
|
114
|
+
writer.setAttribute('htmlLiAttributes', value, node);
|
|
115
|
+
evt.return = true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* @inheritDoc
|
|
123
|
+
*/
|
|
124
|
+
afterInit() {
|
|
125
|
+
const editor = this.editor;
|
|
126
|
+
if (!editor.commands.get('indentList')) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
// Reset list attributes after indenting list items.
|
|
130
|
+
const indentList = editor.commands.get('indentList');
|
|
131
|
+
this.listenTo(indentList, 'afterExecute', (evt, changedBlocks) => {
|
|
132
|
+
editor.model.change(writer => {
|
|
133
|
+
for (const node of changedBlocks) {
|
|
134
|
+
// Just reset the attribute.
|
|
135
|
+
// If there is a previous indented list that this node should be merged into,
|
|
136
|
+
// the postfixer will unify all the attributes of both sub-lists.
|
|
137
|
+
writer.setAttribute('htmlListAttributes', {}, node);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
}
|
|
173
142
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
continue;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
conversionApi.writer.setAttribute( attributeName, viewAttributes || {}, item );
|
|
205
|
-
}
|
|
206
|
-
};
|
|
143
|
+
/**
|
|
144
|
+
* View-to-model conversion helper preserving allowed attributes on {@link TODO}
|
|
145
|
+
* feature model element.
|
|
146
|
+
*
|
|
147
|
+
* @returns Returns a conversion callback.
|
|
148
|
+
*/
|
|
149
|
+
function viewToModelListAttributeConverter(attributeName, dataFilter) {
|
|
150
|
+
const callback = (evt, data, conversionApi) => {
|
|
151
|
+
const viewElement = data.viewItem;
|
|
152
|
+
if (!data.modelRange) {
|
|
153
|
+
Object.assign(data, conversionApi.convertChildren(data.viewItem, data.modelCursor));
|
|
154
|
+
}
|
|
155
|
+
const viewAttributes = dataFilter.processViewAttributes(viewElement, conversionApi);
|
|
156
|
+
for (const item of data.modelRange.getItems({ shallow: true })) {
|
|
157
|
+
// Apply only to list item blocks.
|
|
158
|
+
if (!item.hasAttribute('listItemId')) {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
// Set list attributes only on same level items, those nested deeper are already handled
|
|
162
|
+
// by the recursive conversion.
|
|
163
|
+
if (item.hasAttribute(attributeName)) {
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
conversionApi.writer.setAttribute(attributeName, viewAttributes || {}, item);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
return callback;
|
|
207
170
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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, type PluginDependencies } from 'ckeditor5/src/core';
|
|
6
|
+
/**
|
|
7
|
+
* Provides the General HTML Support integration for elements which can behave like sectioning element (e.g. article) or
|
|
8
|
+
* element accepting only inline content (e.g. paragraph).
|
|
9
|
+
*
|
|
10
|
+
* The distinction between this two content models is important for choosing correct schema model and proper content conversion.
|
|
11
|
+
* As an example, it ensures that:
|
|
12
|
+
*
|
|
13
|
+
* * children elements paragraphing is enabled for sectioning elements only,
|
|
14
|
+
* * element and its content can be correctly handled by editing view (splitting and merging elements),
|
|
15
|
+
* * model element HTML is semantically correct and easier to work with.
|
|
16
|
+
*
|
|
17
|
+
* If element contains any block element, it will be treated as a sectioning element and registered using
|
|
18
|
+
* {@link module:html-support/dataschema~DataSchemaDefinition#model} and
|
|
19
|
+
* {@link module:html-support/dataschema~DataSchemaDefinition#modelSchema} in editor schema.
|
|
20
|
+
* Otherwise, it will be registered under {@link module:html-support/dataschema~DataSchemaBlockElementDefinition#paragraphLikeModel} model
|
|
21
|
+
* name with model schema accepting only inline content (inheriting from `$block`).
|
|
22
|
+
*/
|
|
23
|
+
export default class DualContentModelElementSupport extends Plugin {
|
|
24
|
+
/**
|
|
25
|
+
* @inheritDoc
|
|
26
|
+
*/
|
|
27
|
+
static get requires(): PluginDependencies;
|
|
28
|
+
/**
|
|
29
|
+
* @inheritDoc
|
|
30
|
+
*/
|
|
31
|
+
static get pluginName(): 'DualContentModelElementSupport';
|
|
32
|
+
/**
|
|
33
|
+
* @inheritDoc
|
|
34
|
+
*/
|
|
35
|
+
init(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Checks whether the given view element includes any other block element.
|
|
38
|
+
*/
|
|
39
|
+
private _hasBlockContent;
|
|
40
|
+
/**
|
|
41
|
+
* Adds attribute filtering conversion for the given data schema.
|
|
42
|
+
*/
|
|
43
|
+
private _addAttributeConversion;
|
|
44
|
+
}
|
|
45
|
+
declare module '@ckeditor/ckeditor5-core' {
|
|
46
|
+
interface PluginsMap {
|
|
47
|
+
[DualContentModelElementSupport.pluginName]: DualContentModelElementSupport;
|
|
48
|
+
}
|
|
49
|
+
}
|