@ckeditor/ckeditor5-html-support 38.1.1 → 38.2.0-alpha.1

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 (49) hide show
  1. package/build/html-support.js +1 -1
  2. package/package.json +3 -2
  3. package/src/augmentation.d.ts +33 -33
  4. package/src/augmentation.js +5 -5
  5. package/src/converters.d.ts +60 -56
  6. package/src/converters.js +180 -149
  7. package/src/datafilter.d.ts +304 -285
  8. package/src/datafilter.js +720 -661
  9. package/src/dataschema.d.ts +183 -179
  10. package/src/dataschema.js +196 -196
  11. package/src/fullpage.d.ts +21 -21
  12. package/src/fullpage.js +80 -80
  13. package/src/generalhtmlsupport.d.ts +98 -98
  14. package/src/generalhtmlsupport.js +240 -237
  15. package/src/generalhtmlsupportconfig.d.ts +77 -67
  16. package/src/generalhtmlsupportconfig.js +5 -5
  17. package/src/htmlcomment.d.ts +72 -72
  18. package/src/htmlcomment.js +220 -220
  19. package/src/htmlpagedataprocessor.d.ts +22 -22
  20. package/src/htmlpagedataprocessor.js +67 -67
  21. package/src/index.d.ts +25 -25
  22. package/src/index.js +14 -14
  23. package/src/integrations/codeblock.d.ts +23 -23
  24. package/src/integrations/codeblock.js +101 -101
  25. package/src/integrations/customelement.d.ts +27 -27
  26. package/src/integrations/customelement.js +146 -146
  27. package/src/integrations/documentlist.d.ts +27 -27
  28. package/src/integrations/documentlist.js +203 -203
  29. package/src/integrations/dualcontent.d.ts +45 -45
  30. package/src/integrations/dualcontent.js +119 -119
  31. package/src/integrations/heading.d.ts +31 -31
  32. package/src/integrations/heading.js +60 -60
  33. package/src/integrations/image.d.ts +26 -26
  34. package/src/integrations/image.js +172 -172
  35. package/src/integrations/integrationutils.d.ts +15 -15
  36. package/src/integrations/integrationutils.js +21 -21
  37. package/src/integrations/mediaembed.d.ts +26 -26
  38. package/src/integrations/mediaembed.js +119 -119
  39. package/src/integrations/script.d.ts +26 -26
  40. package/src/integrations/script.js +59 -59
  41. package/src/integrations/style.d.ts +26 -26
  42. package/src/integrations/style.js +59 -59
  43. package/src/integrations/table.d.ts +23 -23
  44. package/src/integrations/table.js +163 -163
  45. package/src/schemadefinitions.d.ts +13 -13
  46. package/src/schemadefinitions.js +956 -956
  47. package/src/utils.d.ts +72 -72
  48. package/src/utils.js +139 -139
  49. package/build/html-support.js.map +0 -1
@@ -1,163 +1,163 @@
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 { updateViewAttributes } from '../utils';
7
- import DataFilter from '../datafilter';
8
- import { getDescendantElement } from './integrationutils';
9
- /**
10
- * Provides the General HTML Support integration with {@link module:table/table~Table Table} feature.
11
- */
12
- export default class TableElementSupport extends Plugin {
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
- const tableUtils = editor.plugins.get('TableUtils');
37
- dataFilter.on('register:figure', () => {
38
- conversion.for('upcast').add(viewToModelFigureAttributeConverter(dataFilter));
39
- });
40
- dataFilter.on('register:table', (evt, definition) => {
41
- if (definition.model !== 'table') {
42
- return;
43
- }
44
- schema.extend('table', {
45
- allowAttributes: [
46
- 'htmlTableAttributes',
47
- // Figure, thead and tbody elements don't have model counterparts.
48
- // We will be preserving attributes on table element using these attribute keys.
49
- 'htmlFigureAttributes', 'htmlTheadAttributes', 'htmlTbodyAttributes'
50
- ]
51
- });
52
- conversion.for('upcast').add(viewToModelTableAttributeConverter(dataFilter));
53
- conversion.for('downcast').add(modelToViewTableAttributeConverter());
54
- editor.model.document.registerPostFixer(createHeadingRowsPostFixer(editor.model, tableUtils));
55
- evt.stop();
56
- });
57
- }
58
- }
59
- /**
60
- * Creates a model post-fixer for thead and tbody GHS related attributes.
61
- */
62
- function createHeadingRowsPostFixer(model, tableUtils) {
63
- return writer => {
64
- const changes = model.document.differ.getChanges();
65
- let wasFixed = false;
66
- for (const change of changes) {
67
- if (change.type != 'attribute' || change.attributeKey != 'headingRows') {
68
- continue;
69
- }
70
- const table = change.range.start.nodeAfter;
71
- const hasTHeadAttributes = table.getAttribute('htmlTheadAttributes');
72
- const hasTBodyAttributes = table.getAttribute('htmlTbodyAttributes');
73
- if (hasTHeadAttributes && !change.attributeNewValue) {
74
- writer.removeAttribute('htmlTheadAttributes', table);
75
- wasFixed = true;
76
- }
77
- else if (hasTBodyAttributes && change.attributeNewValue == tableUtils.getRows(table)) {
78
- writer.removeAttribute('htmlTbodyAttributes', table);
79
- wasFixed = true;
80
- }
81
- }
82
- return wasFixed;
83
- };
84
- }
85
- /**
86
- * View-to-model conversion helper preserving allowed attributes on {@link module:table/table~Table Table}
87
- * feature model element.
88
- *
89
- * @returns Returns a conversion callback.
90
- */
91
- function viewToModelTableAttributeConverter(dataFilter) {
92
- return (dispatcher) => {
93
- dispatcher.on('element:table', (evt, data, conversionApi) => {
94
- if (!data.modelRange) {
95
- return;
96
- }
97
- const viewTableElement = data.viewItem;
98
- preserveElementAttributes(viewTableElement, 'htmlTableAttributes');
99
- for (const childNode of viewTableElement.getChildren()) {
100
- if (childNode.is('element', 'thead')) {
101
- preserveElementAttributes(childNode, 'htmlTheadAttributes');
102
- }
103
- if (childNode.is('element', 'tbody')) {
104
- preserveElementAttributes(childNode, 'htmlTbodyAttributes');
105
- }
106
- }
107
- function preserveElementAttributes(viewElement, attributeName) {
108
- const viewAttributes = dataFilter.processViewAttributes(viewElement, conversionApi);
109
- if (viewAttributes) {
110
- conversionApi.writer.setAttribute(attributeName, viewAttributes, data.modelRange);
111
- }
112
- }
113
- }, { priority: 'low' });
114
- };
115
- }
116
- /**
117
- * View-to-model conversion helper preserving allowed attributes on {@link module:table/table~Table Table}
118
- * feature model element from figure view element.
119
- *
120
- * @returns Returns a conversion callback.
121
- */
122
- function viewToModelFigureAttributeConverter(dataFilter) {
123
- return (dispatcher) => {
124
- dispatcher.on('element:figure', (evt, data, conversionApi) => {
125
- const viewFigureElement = data.viewItem;
126
- if (!data.modelRange || !viewFigureElement.hasClass('table')) {
127
- return;
128
- }
129
- const viewAttributes = dataFilter.processViewAttributes(viewFigureElement, conversionApi);
130
- if (viewAttributes) {
131
- conversionApi.writer.setAttribute('htmlFigureAttributes', viewAttributes, data.modelRange);
132
- }
133
- }, { priority: 'low' });
134
- };
135
- }
136
- /**
137
- * Model-to-view conversion helper applying attributes from {@link module:table/table~Table Table}
138
- * feature.
139
- *
140
- * @returns Returns a conversion callback.
141
- */
142
- function modelToViewTableAttributeConverter() {
143
- return (dispatcher) => {
144
- addAttributeConversionDispatcherHandler('table', 'htmlTableAttributes');
145
- addAttributeConversionDispatcherHandler('figure', 'htmlFigureAttributes');
146
- addAttributeConversionDispatcherHandler('thead', 'htmlTheadAttributes');
147
- addAttributeConversionDispatcherHandler('tbody', 'htmlTbodyAttributes');
148
- function addAttributeConversionDispatcherHandler(elementName, attributeName) {
149
- dispatcher.on(`attribute:${attributeName}:table`, (evt, data, conversionApi) => {
150
- if (!conversionApi.consumable.test(data.item, evt.name)) {
151
- return;
152
- }
153
- const containerElement = conversionApi.mapper.toViewElement(data.item);
154
- const viewElement = getDescendantElement(conversionApi.writer, containerElement, elementName);
155
- if (!viewElement) {
156
- return;
157
- }
158
- conversionApi.consumable.consume(data.item, evt.name);
159
- updateViewAttributes(conversionApi.writer, data.attributeOldValue, data.attributeNewValue, viewElement);
160
- });
161
- }
162
- };
163
- }
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.js';
6
+ import { updateViewAttributes } from '../utils.js';
7
+ import DataFilter from '../datafilter.js';
8
+ import { getDescendantElement } from './integrationutils.js';
9
+ /**
10
+ * Provides the General HTML Support integration with {@link module:table/table~Table Table} feature.
11
+ */
12
+ export default class TableElementSupport extends Plugin {
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
+ const tableUtils = editor.plugins.get('TableUtils');
37
+ dataFilter.on('register:figure', () => {
38
+ conversion.for('upcast').add(viewToModelFigureAttributeConverter(dataFilter));
39
+ });
40
+ dataFilter.on('register:table', (evt, definition) => {
41
+ if (definition.model !== 'table') {
42
+ return;
43
+ }
44
+ schema.extend('table', {
45
+ allowAttributes: [
46
+ 'htmlTableAttributes',
47
+ // Figure, thead and tbody elements don't have model counterparts.
48
+ // We will be preserving attributes on table element using these attribute keys.
49
+ 'htmlFigureAttributes', 'htmlTheadAttributes', 'htmlTbodyAttributes'
50
+ ]
51
+ });
52
+ conversion.for('upcast').add(viewToModelTableAttributeConverter(dataFilter));
53
+ conversion.for('downcast').add(modelToViewTableAttributeConverter());
54
+ editor.model.document.registerPostFixer(createHeadingRowsPostFixer(editor.model, tableUtils));
55
+ evt.stop();
56
+ });
57
+ }
58
+ }
59
+ /**
60
+ * Creates a model post-fixer for thead and tbody GHS related attributes.
61
+ */
62
+ function createHeadingRowsPostFixer(model, tableUtils) {
63
+ return writer => {
64
+ const changes = model.document.differ.getChanges();
65
+ let wasFixed = false;
66
+ for (const change of changes) {
67
+ if (change.type != 'attribute' || change.attributeKey != 'headingRows') {
68
+ continue;
69
+ }
70
+ const table = change.range.start.nodeAfter;
71
+ const hasTHeadAttributes = table.getAttribute('htmlTheadAttributes');
72
+ const hasTBodyAttributes = table.getAttribute('htmlTbodyAttributes');
73
+ if (hasTHeadAttributes && !change.attributeNewValue) {
74
+ writer.removeAttribute('htmlTheadAttributes', table);
75
+ wasFixed = true;
76
+ }
77
+ else if (hasTBodyAttributes && change.attributeNewValue == tableUtils.getRows(table)) {
78
+ writer.removeAttribute('htmlTbodyAttributes', table);
79
+ wasFixed = true;
80
+ }
81
+ }
82
+ return wasFixed;
83
+ };
84
+ }
85
+ /**
86
+ * View-to-model conversion helper preserving allowed attributes on {@link module:table/table~Table Table}
87
+ * feature model element.
88
+ *
89
+ * @returns Returns a conversion callback.
90
+ */
91
+ function viewToModelTableAttributeConverter(dataFilter) {
92
+ return (dispatcher) => {
93
+ dispatcher.on('element:table', (evt, data, conversionApi) => {
94
+ if (!data.modelRange) {
95
+ return;
96
+ }
97
+ const viewTableElement = data.viewItem;
98
+ preserveElementAttributes(viewTableElement, 'htmlTableAttributes');
99
+ for (const childNode of viewTableElement.getChildren()) {
100
+ if (childNode.is('element', 'thead')) {
101
+ preserveElementAttributes(childNode, 'htmlTheadAttributes');
102
+ }
103
+ if (childNode.is('element', 'tbody')) {
104
+ preserveElementAttributes(childNode, 'htmlTbodyAttributes');
105
+ }
106
+ }
107
+ function preserveElementAttributes(viewElement, attributeName) {
108
+ const viewAttributes = dataFilter.processViewAttributes(viewElement, conversionApi);
109
+ if (viewAttributes) {
110
+ conversionApi.writer.setAttribute(attributeName, viewAttributes, data.modelRange);
111
+ }
112
+ }
113
+ }, { priority: 'low' });
114
+ };
115
+ }
116
+ /**
117
+ * View-to-model conversion helper preserving allowed attributes on {@link module:table/table~Table Table}
118
+ * feature model element from figure view element.
119
+ *
120
+ * @returns Returns a conversion callback.
121
+ */
122
+ function viewToModelFigureAttributeConverter(dataFilter) {
123
+ return (dispatcher) => {
124
+ dispatcher.on('element:figure', (evt, data, conversionApi) => {
125
+ const viewFigureElement = data.viewItem;
126
+ if (!data.modelRange || !viewFigureElement.hasClass('table')) {
127
+ return;
128
+ }
129
+ const viewAttributes = dataFilter.processViewAttributes(viewFigureElement, conversionApi);
130
+ if (viewAttributes) {
131
+ conversionApi.writer.setAttribute('htmlFigureAttributes', viewAttributes, data.modelRange);
132
+ }
133
+ }, { priority: 'low' });
134
+ };
135
+ }
136
+ /**
137
+ * Model-to-view conversion helper applying attributes from {@link module:table/table~Table Table}
138
+ * feature.
139
+ *
140
+ * @returns Returns a conversion callback.
141
+ */
142
+ function modelToViewTableAttributeConverter() {
143
+ return (dispatcher) => {
144
+ addAttributeConversionDispatcherHandler('table', 'htmlTableAttributes');
145
+ addAttributeConversionDispatcherHandler('figure', 'htmlFigureAttributes');
146
+ addAttributeConversionDispatcherHandler('thead', 'htmlTheadAttributes');
147
+ addAttributeConversionDispatcherHandler('tbody', 'htmlTbodyAttributes');
148
+ function addAttributeConversionDispatcherHandler(elementName, attributeName) {
149
+ dispatcher.on(`attribute:${attributeName}:table`, (evt, data, conversionApi) => {
150
+ if (!conversionApi.consumable.test(data.item, evt.name)) {
151
+ return;
152
+ }
153
+ const containerElement = conversionApi.mapper.toViewElement(data.item);
154
+ const viewElement = getDescendantElement(conversionApi.writer, containerElement, elementName);
155
+ if (!viewElement) {
156
+ return;
157
+ }
158
+ conversionApi.consumable.consume(data.item, evt.name);
159
+ updateViewAttributes(conversionApi.writer, data.attributeOldValue, data.attributeNewValue, viewElement);
160
+ });
161
+ }
162
+ };
163
+ }
@@ -1,13 +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;
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.js';
6
+ /**
7
+ * @module html-support/schemadefinitions
8
+ */
9
+ declare const _default: {
10
+ block: DataSchemaBlockElementDefinition[];
11
+ inline: DataSchemaInlineElementDefinition[];
12
+ };
13
+ export default _default;