@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,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.js';
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
- * @inheritDoc
22
- */
23
- static get requires() {
24
- return [ DataFilter ];
25
- }
26
-
27
- /**
28
- * @inheritDoc
29
- */
30
- static get pluginName() {
31
- return 'TableElementSupport';
32
- }
33
-
34
- /**
35
- * @inheritDoc
36
- */
37
- init() {
38
- const editor = this.editor;
39
-
40
- if ( !editor.plugins.has( 'TableEditing' ) ) {
41
- return;
42
- }
43
-
44
- const schema = editor.model.schema;
45
- const conversion = editor.conversion;
46
- const dataFilter = editor.plugins.get( DataFilter );
47
-
48
- dataFilter.on( 'register:figure', ( ) => {
49
- conversion.for( 'upcast' ).add( viewToModelFigureAttributeConverter( dataFilter ) );
50
- } );
51
-
52
- dataFilter.on( 'register:table', ( evt, definition ) => {
53
- if ( definition.model !== 'table' ) {
54
- return;
55
- }
56
-
57
- schema.extend( 'table', {
58
- allowAttributes: [
59
- 'htmlAttributes',
60
- // Figure, thead and tbody elements don't have model counterparts.
61
- // We will be preserving attributes on table element using these attribute keys.
62
- 'htmlFigureAttributes', 'htmlTheadAttributes', 'htmlTbodyAttributes'
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
- // View-to-model conversion helper preserving allowed attributes on {@link module:table/table~Table Table}
75
- // feature model element.
76
- //
77
- // @private
78
- // @param {module:html-support/datafilter~DataFilter} dataFilter
79
- // @returns {Function} Returns a conversion callback.
80
- function viewToModelTableAttributeConverter( dataFilter ) {
81
- return dispatcher => {
82
- dispatcher.on( 'element:table', ( evt, data, conversionApi ) => {
83
- const viewTableElement = data.viewItem;
84
-
85
- preserveElementAttributes( viewTableElement, 'htmlAttributes' );
86
-
87
- for ( const childNode of viewTableElement.getChildren() ) {
88
- if ( childNode.is( 'element', 'thead' ) ) {
89
- preserveElementAttributes( childNode, 'htmlTheadAttributes' );
90
- }
91
-
92
- if ( childNode.is( 'element', 'tbody' ) ) {
93
- preserveElementAttributes( childNode, 'htmlTbodyAttributes' );
94
- }
95
- }
96
-
97
- function preserveElementAttributes( viewElement, attributeName ) {
98
- const viewAttributes = dataFilter.processViewAttributes( viewElement, conversionApi );
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
- // View-to-model conversion helper preserving allowed attributes on {@link module:table/table~Table Table}
109
- // feature model element from figure view element.
110
- //
111
- // @private
112
- // @param {module:html-support/datafilter~DataFilter} dataFilter
113
- // @returns {Function} Returns a conversion callback.
114
- function viewToModelFigureAttributeConverter( dataFilter ) {
115
- return dispatcher => {
116
- dispatcher.on( 'element:figure', ( evt, data, conversionApi ) => {
117
- const viewFigureElement = data.viewItem;
118
-
119
- if ( !data.modelRange || !viewFigureElement.hasClass( 'table' ) ) {
120
- return;
121
- }
122
-
123
- const viewAttributes = dataFilter.processViewAttributes( viewFigureElement, conversionApi );
124
-
125
- if ( viewAttributes ) {
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
- // Model-to-view conversion helper applying attributes from {@link module:table/table~Table Table}
133
- // feature.
134
- //
135
- // @private
136
- // @returns {Function} Returns a conversion callback.
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
- return dispatcher => {
139
- addAttributeConversionDispatcherHandler( 'table', 'htmlAttributes' );
140
- addAttributeConversionDispatcherHandler( 'figure', 'htmlFigureAttributes' );
141
- addAttributeConversionDispatcherHandler( 'thead', 'htmlTheadAttributes' );
142
- addAttributeConversionDispatcherHandler( 'tbody', 'htmlTbodyAttributes' );
143
-
144
- function addAttributeConversionDispatcherHandler( elementName, attributeName ) {
145
- dispatcher.on( `attribute:${ attributeName }:table`, ( evt, data, conversionApi ) => {
146
- if ( !conversionApi.consumable.consume( data.item, evt.name ) ) {
147
- return;
148
- }
149
-
150
- const containerElement = conversionApi.mapper.toViewElement( data.item );
151
- const viewElement = getDescendantElement( conversionApi.writer, containerElement, elementName );
152
-
153
- setViewAttributes( conversionApi.writer, data.attributeNewValue, viewElement );
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;