@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.
Files changed (46) hide show
  1. package/build/html-support.js +1 -1
  2. package/package.json +42 -36
  3. package/src/conversionutils.d.ts +42 -0
  4. package/src/conversionutils.js +57 -77
  5. package/src/converters.d.ts +56 -0
  6. package/src/converters.js +104 -156
  7. package/src/datafilter.d.ts +255 -0
  8. package/src/datafilter.js +566 -782
  9. package/src/dataschema.d.ts +174 -0
  10. package/src/dataschema.js +143 -229
  11. package/src/fullpage.d.ts +26 -0
  12. package/src/fullpage.js +65 -86
  13. package/src/generalhtmlsupport.d.ts +93 -0
  14. package/src/generalhtmlsupport.js +244 -327
  15. package/src/generalhtmlsupportconfig.d.ts +76 -0
  16. package/src/generalhtmlsupportconfig.js +5 -0
  17. package/src/htmlcomment.d.ts +77 -0
  18. package/src/htmlcomment.js +175 -239
  19. package/src/htmlpagedataprocessor.d.ts +22 -0
  20. package/src/htmlpagedataprocessor.js +53 -76
  21. package/src/index.d.ts +13 -0
  22. package/src/index.js +0 -2
  23. package/src/integrations/codeblock.d.ts +27 -0
  24. package/src/integrations/codeblock.js +87 -115
  25. package/src/integrations/customelement.d.ts +30 -0
  26. package/src/integrations/customelement.js +127 -160
  27. package/src/integrations/documentlist.d.ts +31 -0
  28. package/src/integrations/documentlist.js +154 -191
  29. package/src/integrations/dualcontent.d.ts +49 -0
  30. package/src/integrations/dualcontent.js +92 -128
  31. package/src/integrations/heading.d.ts +30 -0
  32. package/src/integrations/heading.js +41 -54
  33. package/src/integrations/image.d.ts +30 -0
  34. package/src/integrations/image.js +154 -212
  35. package/src/integrations/integrationutils.d.ts +15 -0
  36. package/src/integrations/integrationutils.js +21 -0
  37. package/src/integrations/mediaembed.d.ts +30 -0
  38. package/src/integrations/mediaembed.js +101 -147
  39. package/src/integrations/script.d.ts +30 -0
  40. package/src/integrations/script.js +45 -67
  41. package/src/integrations/style.d.ts +30 -0
  42. package/src/integrations/style.js +45 -67
  43. package/src/integrations/table.d.ts +27 -0
  44. package/src/integrations/table.js +113 -160
  45. package/src/schemadefinitions.d.ts +13 -0
  46. package/src/schemadefinitions.js +846 -835
@@ -2,229 +2,171 @@
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/image
8
7
  */
9
-
10
8
  import { Plugin } from 'ckeditor5/src/core';
11
-
12
9
  import DataFilter from '../datafilter';
13
- import {
14
- setViewAttributes,
15
- updateViewAttributes
16
- } from '../conversionutils.js';
17
-
10
+ import { setViewAttributes, updateViewAttributes } from '../conversionutils';
11
+ import { getDescendantElement } from './integrationutils';
18
12
  /**
19
13
  * Provides the General HTML Support integration with the {@link module:image/image~Image Image} feature.
20
- *
21
- * @extends module:core/plugin~Plugin
22
14
  */
23
15
  export default class ImageElementSupport extends Plugin {
24
- /**
25
- * @inheritDoc
26
- */
27
- static get requires() {
28
- return [ DataFilter ];
29
- }
30
-
31
- /**
32
- * @inheritDoc
33
- */
34
- static get pluginName() {
35
- return 'ImageElementSupport';
36
- }
37
-
38
- /**
39
- * @inheritDoc
40
- */
41
- init() {
42
- const editor = this.editor;
43
-
44
- // At least one image plugin should be loaded for the integration to work properly.
45
- if ( !editor.plugins.has( 'ImageInlineEditing' ) && !editor.plugins.has( 'ImageBlockEditing' ) ) {
46
- return;
47
- }
48
-
49
- const schema = editor.model.schema;
50
- const conversion = editor.conversion;
51
- const dataFilter = editor.plugins.get( DataFilter );
52
-
53
- dataFilter.on( 'register:figure', () => {
54
- conversion.for( 'upcast' ).add( viewToModelFigureAttributeConverter( dataFilter ) );
55
- } );
56
-
57
- dataFilter.on( 'register:img', ( evt, definition ) => {
58
- if ( definition.model !== 'imageBlock' && definition.model !== 'imageInline' ) {
59
- return;
60
- }
61
-
62
- if ( schema.isRegistered( 'imageBlock' ) ) {
63
- schema.extend( 'imageBlock', {
64
- allowAttributes: [
65
- 'htmlAttributes',
66
- // Figure and Link don't have model counterpart.
67
- // We will preserve attributes on image model element using these attribute keys.
68
- 'htmlFigureAttributes',
69
- 'htmlLinkAttributes'
70
- ]
71
- } );
72
- }
73
-
74
- if ( schema.isRegistered( 'imageInline' ) ) {
75
- schema.extend( 'imageInline', {
76
- allowAttributes: [
77
- // `htmlA` is needed for standard GHS link integration.
78
- 'htmlA',
79
- 'htmlAttributes'
80
- ]
81
- } );
82
- }
83
-
84
- conversion.for( 'upcast' ).add( viewToModelImageAttributeConverter( dataFilter ) );
85
- conversion.for( 'downcast' ).add( modelToViewImageAttributeConverter() );
86
-
87
- evt.stop();
88
- } );
89
- }
16
+ /**
17
+ * @inheritDoc
18
+ */
19
+ static get requires() {
20
+ return [DataFilter];
21
+ }
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ static get pluginName() {
26
+ return 'ImageElementSupport';
27
+ }
28
+ /**
29
+ * @inheritDoc
30
+ */
31
+ init() {
32
+ const editor = this.editor;
33
+ // At least one image plugin should be loaded for the integration to work properly.
34
+ if (!editor.plugins.has('ImageInlineEditing') && !editor.plugins.has('ImageBlockEditing')) {
35
+ return;
36
+ }
37
+ const schema = editor.model.schema;
38
+ const conversion = editor.conversion;
39
+ const dataFilter = editor.plugins.get(DataFilter);
40
+ dataFilter.on('register:figure', () => {
41
+ conversion.for('upcast').add(viewToModelFigureAttributeConverter(dataFilter));
42
+ });
43
+ dataFilter.on('register:img', (evt, definition) => {
44
+ if (definition.model !== 'imageBlock' && definition.model !== 'imageInline') {
45
+ return;
46
+ }
47
+ if (schema.isRegistered('imageBlock')) {
48
+ schema.extend('imageBlock', {
49
+ allowAttributes: [
50
+ 'htmlAttributes',
51
+ // Figure and Link don't have model counterpart.
52
+ // We will preserve attributes on image model element using these attribute keys.
53
+ 'htmlFigureAttributes',
54
+ 'htmlLinkAttributes'
55
+ ]
56
+ });
57
+ }
58
+ if (schema.isRegistered('imageInline')) {
59
+ schema.extend('imageInline', {
60
+ allowAttributes: [
61
+ // `htmlA` is needed for standard GHS link integration.
62
+ 'htmlA',
63
+ 'htmlAttributes'
64
+ ]
65
+ });
66
+ }
67
+ conversion.for('upcast').add(viewToModelImageAttributeConverter(dataFilter));
68
+ conversion.for('downcast').add(modelToViewImageAttributeConverter());
69
+ evt.stop();
70
+ });
71
+ }
90
72
  }
91
-
92
- // View-to-model conversion helper preserving allowed attributes on the {@link module:image/image~Image Image}
93
- // feature model element.
94
- //
95
- // @private
96
- // @param {module:html-support/datafilter~DataFilter} dataFilter
97
- // @returns {Function} Returns a conversion callback.
98
- function viewToModelImageAttributeConverter( dataFilter ) {
99
- return dispatcher => {
100
- dispatcher.on( 'element:img', ( evt, data, conversionApi ) => {
101
- if ( !data.modelRange ) {
102
- return;
103
- }
104
-
105
- const viewImageElement = data.viewItem;
106
- const viewContainerElement = viewImageElement.parent;
107
-
108
- preserveElementAttributes( viewImageElement, 'htmlAttributes' );
109
-
110
- if ( viewContainerElement.is( 'element', 'a' ) ) {
111
- preserveLinkAttributes( viewContainerElement );
112
- }
113
-
114
- function preserveElementAttributes( viewElement, attributeName ) {
115
- const viewAttributes = dataFilter.processViewAttributes( viewElement, conversionApi );
116
-
117
- if ( viewAttributes ) {
118
- conversionApi.writer.setAttribute( attributeName, viewAttributes, data.modelRange );
119
- }
120
- }
121
-
122
- function preserveLinkAttributes( viewContainerElement ) {
123
- if ( data.modelRange && data.modelRange.getContainedElement().is( 'element', 'imageBlock' ) ) {
124
- preserveElementAttributes( viewContainerElement, 'htmlLinkAttributes' );
125
- }
126
- }
127
- }, { priority: 'low' } );
128
- };
73
+ /**
74
+ * View-to-model conversion helper preserving allowed attributes on the {@link module:image/image~Image Image}
75
+ * feature model element.
76
+ *
77
+ * @returns Returns a conversion callback.
78
+ */
79
+ function viewToModelImageAttributeConverter(dataFilter) {
80
+ return (dispatcher) => {
81
+ dispatcher.on('element:img', (evt, data, conversionApi) => {
82
+ if (!data.modelRange) {
83
+ return;
84
+ }
85
+ const viewImageElement = data.viewItem;
86
+ const viewContainerElement = viewImageElement.parent;
87
+ preserveElementAttributes(viewImageElement, 'htmlAttributes');
88
+ if (viewContainerElement.is('element', 'a')) {
89
+ preserveLinkAttributes(viewContainerElement);
90
+ }
91
+ function preserveElementAttributes(viewElement, attributeName) {
92
+ const viewAttributes = dataFilter.processViewAttributes(viewElement, conversionApi);
93
+ if (viewAttributes) {
94
+ conversionApi.writer.setAttribute(attributeName, viewAttributes, data.modelRange);
95
+ }
96
+ }
97
+ function preserveLinkAttributes(viewContainerElement) {
98
+ if (data.modelRange && data.modelRange.getContainedElement().is('element', 'imageBlock')) {
99
+ preserveElementAttributes(viewContainerElement, 'htmlLinkAttributes');
100
+ }
101
+ }
102
+ }, { priority: 'low' });
103
+ };
129
104
  }
130
-
131
- // View-to-model conversion helper preserving allowed attributes on {@link module:image/image~Image Image}
132
- // feature model element from figure view element.
133
- //
134
- // @private
135
- // @param {module:html-support/datafilter~DataFilter} dataFilter
136
- // @returns {Function} Returns a conversion callback.
137
- function viewToModelFigureAttributeConverter( dataFilter ) {
138
- return dispatcher => {
139
- dispatcher.on( 'element:figure', ( evt, data, conversionApi ) => {
140
- const viewFigureElement = data.viewItem;
141
-
142
- if ( !data.modelRange || !viewFigureElement.hasClass( 'image' ) ) {
143
- return;
144
- }
145
-
146
- const viewAttributes = dataFilter.processViewAttributes( viewFigureElement, conversionApi );
147
-
148
- if ( viewAttributes ) {
149
- conversionApi.writer.setAttribute( 'htmlFigureAttributes', viewAttributes, data.modelRange );
150
- }
151
- }, { priority: 'low' } );
152
- };
105
+ /**
106
+ * View-to-model conversion helper preserving allowed attributes on {@link module:image/image~Image Image}
107
+ * feature model element from figure view element.
108
+ *
109
+ * @returns Returns a conversion callback.
110
+ */
111
+ function viewToModelFigureAttributeConverter(dataFilter) {
112
+ return (dispatcher) => {
113
+ dispatcher.on('element:figure', (evt, data, conversionApi) => {
114
+ const viewFigureElement = data.viewItem;
115
+ if (!data.modelRange || !viewFigureElement.hasClass('image')) {
116
+ return;
117
+ }
118
+ const viewAttributes = dataFilter.processViewAttributes(viewFigureElement, conversionApi);
119
+ if (viewAttributes) {
120
+ conversionApi.writer.setAttribute('htmlFigureAttributes', viewAttributes, data.modelRange);
121
+ }
122
+ }, { priority: 'low' });
123
+ };
153
124
  }
154
-
155
- // A model-to-view conversion helper applying attributes from the {@link module:image/image~Image Image}
156
- // feature.
157
- //
158
- // @private
159
- // @returns {Function} Returns a conversion callback.
125
+ /**
126
+ * A model-to-view conversion helper applying attributes from the {@link module:image/image~Image Image}
127
+ * feature.
128
+ * @returns Returns a conversion callback.
129
+ */
160
130
  function modelToViewImageAttributeConverter() {
161
- return dispatcher => {
162
- addInlineAttributeConversion( 'htmlAttributes' );
163
-
164
- addBlockAttributeConversion( 'img', 'htmlAttributes' );
165
- addBlockAttributeConversion( 'figure', 'htmlFigureAttributes' );
166
- addBlockAttributeConversion( 'a', 'htmlLinkAttributes' );
167
-
168
- function addInlineAttributeConversion( attributeName ) {
169
- dispatcher.on( `attribute:${ attributeName }:imageInline`, ( evt, data, conversionApi ) => {
170
- if ( !conversionApi.consumable.consume( data.item, evt.name ) ) {
171
- return;
172
- }
173
-
174
- const { attributeOldValue, attributeNewValue } = data;
175
- const viewElement = conversionApi.mapper.toViewElement( data.item );
176
-
177
- updateViewAttributes( conversionApi.writer, attributeOldValue, attributeNewValue, viewElement );
178
- }, { priority: 'low' } );
179
- }
180
-
181
- function addBlockAttributeConversion( elementName, attributeName ) {
182
- dispatcher.on( `attribute:${ attributeName }:imageBlock`, ( evt, data, conversionApi ) => {
183
- if ( !conversionApi.consumable.test( data.item, evt.name ) ) {
184
- return;
185
- }
186
-
187
- const { attributeOldValue, attributeNewValue } = data;
188
- const containerElement = conversionApi.mapper.toViewElement( data.item );
189
- const viewElement = getDescendantElement( conversionApi.writer, containerElement, elementName );
190
-
191
- if ( viewElement ) {
192
- updateViewAttributes( conversionApi.writer, attributeOldValue, attributeNewValue, viewElement );
193
- conversionApi.consumable.consume( data.item, evt.name );
194
- }
195
- }, { priority: 'low' } );
196
-
197
- if ( elementName === 'a' ) {
198
- // To have a link element in the view, we need to attach a converter to the `linkHref` attribute as well.
199
- dispatcher.on( 'attribute:linkHref:imageBlock', ( evt, data, conversionApi ) => {
200
- if ( !conversionApi.consumable.consume( data.item, 'attribute:htmlLinkAttributes:imageBlock' ) ) {
201
- return;
202
- }
203
-
204
- const containerElement = conversionApi.mapper.toViewElement( data.item );
205
- const viewElement = getDescendantElement( conversionApi.writer, containerElement, 'a' );
206
-
207
- setViewAttributes( conversionApi.writer, data.item.getAttribute( 'htmlLinkAttributes' ), viewElement );
208
- }, { priority: 'low' } );
209
- }
210
- }
211
- };
212
- }
213
-
214
- // Returns the first view element descendant matching the given view name.
215
- // Includes view element itself.
216
- //
217
- // @private
218
- // @param {module:engine/view/downcastwriter~DowncastWriter} writer
219
- // @param {module:engine/view/element~Element} containerElement
220
- // @param {String} elementName
221
- // @returns {module:engine/view/element~Element|null}
222
- function getDescendantElement( writer, containerElement, elementName ) {
223
- const range = writer.createRangeOn( containerElement );
224
-
225
- for ( const { item } of range.getWalker() ) {
226
- if ( item.is( 'element', elementName ) ) {
227
- return item;
228
- }
229
- }
131
+ return (dispatcher) => {
132
+ addInlineAttributeConversion('htmlAttributes');
133
+ addBlockAttributeConversion('img', 'htmlAttributes');
134
+ addBlockAttributeConversion('figure', 'htmlFigureAttributes');
135
+ addBlockAttributeConversion('a', 'htmlLinkAttributes');
136
+ function addInlineAttributeConversion(attributeName) {
137
+ dispatcher.on(`attribute:${attributeName}:imageInline`, (evt, data, conversionApi) => {
138
+ if (!conversionApi.consumable.consume(data.item, evt.name)) {
139
+ return;
140
+ }
141
+ const { attributeOldValue, attributeNewValue } = data;
142
+ const viewElement = conversionApi.mapper.toViewElement(data.item);
143
+ updateViewAttributes(conversionApi.writer, attributeOldValue, attributeNewValue, viewElement);
144
+ }, { priority: 'low' });
145
+ }
146
+ function addBlockAttributeConversion(elementName, attributeName) {
147
+ dispatcher.on(`attribute:${attributeName}:imageBlock`, (evt, data, conversionApi) => {
148
+ if (!conversionApi.consumable.test(data.item, evt.name)) {
149
+ return;
150
+ }
151
+ const { attributeOldValue, attributeNewValue } = data;
152
+ const containerElement = conversionApi.mapper.toViewElement(data.item);
153
+ const viewElement = getDescendantElement(conversionApi.writer, containerElement, elementName);
154
+ if (viewElement) {
155
+ updateViewAttributes(conversionApi.writer, attributeOldValue, attributeNewValue, viewElement);
156
+ conversionApi.consumable.consume(data.item, evt.name);
157
+ }
158
+ }, { priority: 'low' });
159
+ if (elementName === 'a') {
160
+ // To have a link element in the view, we need to attach a converter to the `linkHref` attribute as well.
161
+ dispatcher.on('attribute:linkHref:imageBlock', (evt, data, conversionApi) => {
162
+ if (!conversionApi.consumable.consume(data.item, 'attribute:htmlLinkAttributes:imageBlock')) {
163
+ return;
164
+ }
165
+ const containerElement = conversionApi.mapper.toViewElement(data.item);
166
+ const viewElement = getDescendantElement(conversionApi.writer, containerElement, 'a');
167
+ setViewAttributes(conversionApi.writer, data.item.getAttribute('htmlLinkAttributes'), viewElement);
168
+ }, { priority: 'low' });
169
+ }
170
+ }
171
+ };
230
172
  }
@@ -0,0 +1,15 @@
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 { DowncastWriter, ViewElement } from 'ckeditor5/src/engine';
6
+ /**
7
+ * @module html-support/integrations/integrationutils
8
+ */
9
+ /**
10
+ * Returns the first view element descendant matching the given view name.
11
+ * Includes view element itself.
12
+ *
13
+ * @internal
14
+ */
15
+ export declare function getDescendantElement(writer: DowncastWriter, containerElement: ViewElement, elementName: string): ViewElement | undefined;
@@ -0,0 +1,21 @@
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/integrationutils
7
+ */
8
+ /**
9
+ * Returns the first view element descendant matching the given view name.
10
+ * Includes view element itself.
11
+ *
12
+ * @internal
13
+ */
14
+ export function getDescendantElement(writer, containerElement, elementName) {
15
+ const range = writer.createRangeOn(containerElement);
16
+ for (const { item } of range.getWalker()) {
17
+ if (item.is('element', elementName)) {
18
+ return item;
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,30 @@
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/mediaembed
7
+ */
8
+ import { Plugin, type PluginDependencies } from 'ckeditor5/src/core';
9
+ /**
10
+ * Provides the General HTML Support integration with {@link module:media-embed/mediaembed~MediaEmbed Media Embed} feature.
11
+ */
12
+ export default class MediaEmbedElementSupport extends Plugin {
13
+ /**
14
+ * @inheritDoc
15
+ */
16
+ static get requires(): PluginDependencies;
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ static get pluginName(): 'MediaEmbedElementSupport';
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ init(): void;
25
+ }
26
+ declare module '@ckeditor/ckeditor5-core' {
27
+ interface PluginsMap {
28
+ [MediaEmbedElementSupport.pluginName]: MediaEmbedElementSupport;
29
+ }
30
+ }