@ckeditor/ckeditor5-html-support 36.0.1 → 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,174 +2,127 @@
|
|
|
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
|
-
/**
|
|
7
|
-
* @module html-support/integrations/table
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
5
|
import { Plugin } from 'ckeditor5/src/core';
|
|
11
|
-
import { setViewAttributes } from '../conversionutils
|
|
6
|
+
import { setViewAttributes } from '../conversionutils';
|
|
12
7
|
import DataFilter from '../datafilter';
|
|
13
|
-
|
|
8
|
+
import { getDescendantElement } from './integrationutils';
|
|
14
9
|
/**
|
|
15
10
|
* Provides the General HTML Support integration with {@link module:table/table~Table Table} feature.
|
|
16
|
-
*
|
|
17
|
-
* @extends module:core/plugin~Plugin
|
|
18
11
|
*/
|
|
19
12
|
export default class TableElementSupport extends Plugin {
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
conversion.for( 'upcast' ).add( viewToModelTableAttributeConverter( dataFilter ) );
|
|
67
|
-
conversion.for( 'downcast' ).add( modelToViewTableAttributeConverter() );
|
|
68
|
-
|
|
69
|
-
evt.stop();
|
|
70
|
-
} );
|
|
71
|
-
}
|
|
13
|
+
/**
|
|
14
|
+
* @inheritDoc
|
|
15
|
+
*/
|
|
16
|
+
static get requires() {
|
|
17
|
+
return [DataFilter];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
static get pluginName() {
|
|
23
|
+
return 'TableElementSupport';
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @inheritDoc
|
|
27
|
+
*/
|
|
28
|
+
init() {
|
|
29
|
+
const editor = this.editor;
|
|
30
|
+
if (!editor.plugins.has('TableEditing')) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const schema = editor.model.schema;
|
|
34
|
+
const conversion = editor.conversion;
|
|
35
|
+
const dataFilter = editor.plugins.get(DataFilter);
|
|
36
|
+
dataFilter.on('register:figure', () => {
|
|
37
|
+
conversion.for('upcast').add(viewToModelFigureAttributeConverter(dataFilter));
|
|
38
|
+
});
|
|
39
|
+
dataFilter.on('register:table', (evt, definition) => {
|
|
40
|
+
if (definition.model !== 'table') {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
schema.extend('table', {
|
|
44
|
+
allowAttributes: [
|
|
45
|
+
'htmlAttributes',
|
|
46
|
+
// Figure, thead and tbody elements don't have model counterparts.
|
|
47
|
+
// We will be preserving attributes on table element using these attribute keys.
|
|
48
|
+
'htmlFigureAttributes', 'htmlTheadAttributes', 'htmlTbodyAttributes'
|
|
49
|
+
]
|
|
50
|
+
});
|
|
51
|
+
conversion.for('upcast').add(viewToModelTableAttributeConverter(dataFilter));
|
|
52
|
+
conversion.for('downcast').add(modelToViewTableAttributeConverter());
|
|
53
|
+
evt.stop();
|
|
54
|
+
});
|
|
55
|
+
}
|
|
72
56
|
}
|
|
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
|
-
if ( viewAttributes ) {
|
|
101
|
-
conversionApi.writer.setAttribute( attributeName, viewAttributes, data.modelRange );
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}, { priority: 'low' } );
|
|
105
|
-
};
|
|
57
|
+
/**
|
|
58
|
+
* View-to-model conversion helper preserving allowed attributes on {@link module:table/table~Table Table}
|
|
59
|
+
* feature model element.
|
|
60
|
+
*
|
|
61
|
+
* @returns Returns a conversion callback.
|
|
62
|
+
*/
|
|
63
|
+
function viewToModelTableAttributeConverter(dataFilter) {
|
|
64
|
+
return (dispatcher) => {
|
|
65
|
+
dispatcher.on('element:table', (evt, data, conversionApi) => {
|
|
66
|
+
const viewTableElement = data.viewItem;
|
|
67
|
+
preserveElementAttributes(viewTableElement, 'htmlAttributes');
|
|
68
|
+
for (const childNode of viewTableElement.getChildren()) {
|
|
69
|
+
if (childNode.is('element', 'thead')) {
|
|
70
|
+
preserveElementAttributes(childNode, 'htmlTheadAttributes');
|
|
71
|
+
}
|
|
72
|
+
if (childNode.is('element', 'tbody')) {
|
|
73
|
+
preserveElementAttributes(childNode, 'htmlTbodyAttributes');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function preserveElementAttributes(viewElement, attributeName) {
|
|
77
|
+
const viewAttributes = dataFilter.processViewAttributes(viewElement, conversionApi);
|
|
78
|
+
if (viewAttributes) {
|
|
79
|
+
conversionApi.writer.setAttribute(attributeName, viewAttributes, data.modelRange);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}, { priority: 'low' });
|
|
83
|
+
};
|
|
106
84
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
conversionApi.writer.setAttribute( 'htmlFigureAttributes', viewAttributes, data.modelRange );
|
|
127
|
-
}
|
|
128
|
-
}, { priority: 'low' } );
|
|
129
|
-
};
|
|
85
|
+
/**
|
|
86
|
+
* View-to-model conversion helper preserving allowed attributes on {@link module:table/table~Table Table}
|
|
87
|
+
* feature model element from figure view element.
|
|
88
|
+
*
|
|
89
|
+
* @returns Returns a conversion callback.
|
|
90
|
+
*/
|
|
91
|
+
function viewToModelFigureAttributeConverter(dataFilter) {
|
|
92
|
+
return (dispatcher) => {
|
|
93
|
+
dispatcher.on('element:figure', (evt, data, conversionApi) => {
|
|
94
|
+
const viewFigureElement = data.viewItem;
|
|
95
|
+
if (!data.modelRange || !viewFigureElement.hasClass('table')) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const viewAttributes = dataFilter.processViewAttributes(viewFigureElement, conversionApi);
|
|
99
|
+
if (viewAttributes) {
|
|
100
|
+
conversionApi.writer.setAttribute('htmlFigureAttributes', viewAttributes, data.modelRange);
|
|
101
|
+
}
|
|
102
|
+
}, { priority: 'low' });
|
|
103
|
+
};
|
|
130
104
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Model-to-view conversion helper applying attributes from {@link module:table/table~Table Table}
|
|
107
|
+
* feature.
|
|
108
|
+
*
|
|
109
|
+
* @returns Returns a conversion callback.
|
|
110
|
+
*/
|
|
137
111
|
function modelToViewTableAttributeConverter() {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
} );
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Returns the first view element descendant matching the given view name.
|
|
160
|
-
// Includes view element itself.
|
|
161
|
-
//
|
|
162
|
-
// @private
|
|
163
|
-
// @param {module:engine/view/downcastwriter~DowncastWriter} writer
|
|
164
|
-
// @param {module:engine/view/element~Element} containerElement
|
|
165
|
-
// @param {String} elementName
|
|
166
|
-
// @returns {module:engine/view/element~Element|null}
|
|
167
|
-
function getDescendantElement( writer, containerElement, elementName ) {
|
|
168
|
-
const range = writer.createRangeOn( containerElement );
|
|
169
|
-
|
|
170
|
-
for ( const { item } of range.getWalker() ) {
|
|
171
|
-
if ( item.is( 'element', elementName ) ) {
|
|
172
|
-
return item;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
112
|
+
return (dispatcher) => {
|
|
113
|
+
addAttributeConversionDispatcherHandler('table', 'htmlAttributes');
|
|
114
|
+
addAttributeConversionDispatcherHandler('figure', 'htmlFigureAttributes');
|
|
115
|
+
addAttributeConversionDispatcherHandler('thead', 'htmlTheadAttributes');
|
|
116
|
+
addAttributeConversionDispatcherHandler('tbody', 'htmlTbodyAttributes');
|
|
117
|
+
function addAttributeConversionDispatcherHandler(elementName, attributeName) {
|
|
118
|
+
dispatcher.on(`attribute:${attributeName}:table`, (evt, data, conversionApi) => {
|
|
119
|
+
if (!conversionApi.consumable.consume(data.item, evt.name)) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const containerElement = conversionApi.mapper.toViewElement(data.item);
|
|
123
|
+
const viewElement = getDescendantElement(conversionApi.writer, containerElement, elementName);
|
|
124
|
+
setViewAttributes(conversionApi.writer, data.attributeNewValue, viewElement);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
175
128
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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 type { DataSchemaBlockElementDefinition, DataSchemaInlineElementDefinition } from './dataschema';
|
|
6
|
+
/**
|
|
7
|
+
* @module html-support/schemadefinitions
|
|
8
|
+
*/
|
|
9
|
+
declare const _default: {
|
|
10
|
+
block: DataSchemaBlockElementDefinition[];
|
|
11
|
+
inline: DataSchemaInlineElementDefinition[];
|
|
12
|
+
};
|
|
13
|
+
export default _default;
|