@ckeditor/ckeditor5-html-support 40.0.0 → 40.1.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 (50) hide show
  1. package/LICENSE.md +4 -4
  2. package/build/html-support.js +1 -1
  3. package/package.json +2 -2
  4. package/src/augmentation.d.ts +33 -33
  5. package/src/augmentation.js +5 -5
  6. package/src/converters.d.ts +60 -60
  7. package/src/converters.js +180 -180
  8. package/src/datafilter.d.ts +304 -304
  9. package/src/datafilter.js +720 -720
  10. package/src/dataschema.d.ts +183 -183
  11. package/src/dataschema.js +196 -196
  12. package/src/fullpage.d.ts +21 -21
  13. package/src/fullpage.js +80 -80
  14. package/src/generalhtmlsupport.d.ts +98 -98
  15. package/src/generalhtmlsupport.js +240 -240
  16. package/src/generalhtmlsupportconfig.d.ts +77 -77
  17. package/src/generalhtmlsupportconfig.js +5 -5
  18. package/src/htmlcomment.d.ts +71 -71
  19. package/src/htmlcomment.js +218 -218
  20. package/src/htmlpagedataprocessor.d.ts +22 -22
  21. package/src/htmlpagedataprocessor.js +67 -67
  22. package/src/index.d.ts +25 -25
  23. package/src/index.js +14 -14
  24. package/src/integrations/codeblock.d.ts +23 -23
  25. package/src/integrations/codeblock.js +101 -101
  26. package/src/integrations/customelement.d.ts +27 -27
  27. package/src/integrations/customelement.js +146 -146
  28. package/src/integrations/documentlist.d.ts +27 -27
  29. package/src/integrations/documentlist.js +178 -178
  30. package/src/integrations/dualcontent.d.ts +45 -45
  31. package/src/integrations/dualcontent.js +119 -119
  32. package/src/integrations/heading.d.ts +31 -31
  33. package/src/integrations/heading.js +60 -60
  34. package/src/integrations/image.d.ts +26 -26
  35. package/src/integrations/image.js +189 -189
  36. package/src/integrations/integrationutils.d.ts +15 -15
  37. package/src/integrations/integrationutils.js +21 -21
  38. package/src/integrations/mediaembed.d.ts +26 -26
  39. package/src/integrations/mediaembed.js +119 -119
  40. package/src/integrations/script.d.ts +26 -26
  41. package/src/integrations/script.js +59 -59
  42. package/src/integrations/style.d.ts +26 -26
  43. package/src/integrations/style.js +59 -59
  44. package/src/integrations/table.d.ts +23 -23
  45. package/src/integrations/table.js +163 -163
  46. package/src/schemadefinitions.d.ts +13 -13
  47. package/src/schemadefinitions.js +953 -956
  48. package/src/utils.d.ts +72 -72
  49. package/src/utils.js +139 -139
  50. package/build/html-support.js.map +0 -1
@@ -1,146 +1,146 @@
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/customelement
7
- */
8
- /* globals document */
9
- import { Plugin } from 'ckeditor5/src/core';
10
- import { UpcastWriter } from 'ckeditor5/src/engine';
11
- import DataSchema from '../dataschema';
12
- import DataFilter from '../datafilter';
13
- import { setViewAttributes } from '../utils';
14
- /**
15
- * Provides the General HTML Support for custom elements (not registered in the {@link module:html-support/dataschema~DataSchema}).
16
- */
17
- export default class CustomElementSupport extends Plugin {
18
- /**
19
- * @inheritDoc
20
- */
21
- static get requires() {
22
- return [DataFilter, DataSchema];
23
- }
24
- /**
25
- * @inheritDoc
26
- */
27
- static get pluginName() {
28
- return 'CustomElementSupport';
29
- }
30
- /**
31
- * @inheritDoc
32
- */
33
- init() {
34
- const dataFilter = this.editor.plugins.get(DataFilter);
35
- const dataSchema = this.editor.plugins.get(DataSchema);
36
- dataFilter.on('register:$customElement', (evt, definition) => {
37
- evt.stop();
38
- const editor = this.editor;
39
- const schema = editor.model.schema;
40
- const conversion = editor.conversion;
41
- const unsafeElements = editor.editing.view.domConverter.unsafeElements;
42
- const preLikeElements = editor.data.htmlProcessor.domConverter.preElements;
43
- schema.register(definition.model, definition.modelSchema);
44
- schema.extend(definition.model, {
45
- allowAttributes: ['htmlElementName', 'htmlCustomElementAttributes', 'htmlContent'],
46
- isContent: true
47
- });
48
- // Being executed on the low priority, it will catch all elements that were not caught by other converters.
49
- conversion.for('upcast').elementToElement({
50
- view: /.*/,
51
- model: (viewElement, conversionApi) => {
52
- // Do not try to convert $comment fake element.
53
- if (viewElement.name == '$comment') {
54
- return null;
55
- }
56
- if (!isValidElementName(viewElement.name)) {
57
- return null;
58
- }
59
- // Allow for fallback only if this element is not defined in data schema to make sure
60
- // that this will handle only custom elements not registered in the data schema.
61
- if (dataSchema.getDefinitionsForView(viewElement.name).size) {
62
- return null;
63
- }
64
- // Make sure that this element will not render in the editing view.
65
- if (!unsafeElements.includes(viewElement.name)) {
66
- unsafeElements.push(viewElement.name);
67
- }
68
- // Make sure that whitespaces will not be trimmed or replaced by nbsps while stringify content.
69
- if (!preLikeElements.includes(viewElement.name)) {
70
- preLikeElements.push(viewElement.name);
71
- }
72
- const modelElement = conversionApi.writer.createElement(definition.model, {
73
- htmlElementName: viewElement.name
74
- });
75
- const htmlAttributes = dataFilter.processViewAttributes(viewElement, conversionApi);
76
- if (htmlAttributes) {
77
- conversionApi.writer.setAttribute('htmlCustomElementAttributes', htmlAttributes, modelElement);
78
- }
79
- // Store the whole element in the attribute so that DomConverter will be able to use the pre like element context.
80
- const viewWriter = new UpcastWriter(viewElement.document);
81
- const documentFragment = viewWriter.createDocumentFragment(viewElement);
82
- const htmlContent = editor.data.processor.toData(documentFragment);
83
- conversionApi.writer.setAttribute('htmlContent', htmlContent, modelElement);
84
- // Consume the content of the element.
85
- for (const { item } of editor.editing.view.createRangeIn(viewElement)) {
86
- conversionApi.consumable.consume(item, { name: true });
87
- }
88
- return modelElement;
89
- },
90
- converterPriority: 'low'
91
- });
92
- // Because this element is unsafe (DomConverter#unsafeElements), it will render as a transparent <span> but it must
93
- // be rendered anyway for the mapping between the model and the view to exist.
94
- conversion.for('editingDowncast').elementToElement({
95
- model: {
96
- name: definition.model,
97
- attributes: ['htmlElementName', 'htmlCustomElementAttributes', 'htmlContent']
98
- },
99
- view: (modelElement, { writer }) => {
100
- const viewName = modelElement.getAttribute('htmlElementName');
101
- const viewElement = writer.createRawElement(viewName);
102
- if (modelElement.hasAttribute('htmlCustomElementAttributes')) {
103
- setViewAttributes(writer, modelElement.getAttribute('htmlCustomElementAttributes'), viewElement);
104
- }
105
- return viewElement;
106
- }
107
- });
108
- conversion.for('dataDowncast').elementToElement({
109
- model: {
110
- name: definition.model,
111
- attributes: ['htmlElementName', 'htmlCustomElementAttributes', 'htmlContent']
112
- },
113
- view: (modelElement, { writer }) => {
114
- const viewName = modelElement.getAttribute('htmlElementName');
115
- const htmlContent = modelElement.getAttribute('htmlContent');
116
- const viewElement = writer.createRawElement(viewName, null, (domElement, domConverter) => {
117
- domConverter.setContentOf(domElement, htmlContent);
118
- // Unwrap the custom element content (it was stored in the attribute as the whole custom element).
119
- // See the upcast conversion for the "htmlContent" attribute to learn more.
120
- const customElement = domElement.firstChild;
121
- customElement.remove();
122
- while (customElement.firstChild) {
123
- domElement.appendChild(customElement.firstChild);
124
- }
125
- });
126
- if (modelElement.hasAttribute('htmlCustomElementAttributes')) {
127
- setViewAttributes(writer, modelElement.getAttribute('htmlCustomElementAttributes'), viewElement);
128
- }
129
- return viewElement;
130
- }
131
- });
132
- });
133
- }
134
- }
135
- /**
136
- * Returns true if name is valid for a DOM element name.
137
- */
138
- function isValidElementName(name) {
139
- try {
140
- document.createElement(name);
141
- }
142
- catch (error) {
143
- return false;
144
- }
145
- return true;
146
- }
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/customelement
7
+ */
8
+ /* globals document */
9
+ import { Plugin } from 'ckeditor5/src/core';
10
+ import { UpcastWriter } from 'ckeditor5/src/engine';
11
+ import DataSchema from '../dataschema';
12
+ import DataFilter from '../datafilter';
13
+ import { setViewAttributes } from '../utils';
14
+ /**
15
+ * Provides the General HTML Support for custom elements (not registered in the {@link module:html-support/dataschema~DataSchema}).
16
+ */
17
+ export default class CustomElementSupport extends Plugin {
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ static get requires() {
22
+ return [DataFilter, DataSchema];
23
+ }
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ static get pluginName() {
28
+ return 'CustomElementSupport';
29
+ }
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ init() {
34
+ const dataFilter = this.editor.plugins.get(DataFilter);
35
+ const dataSchema = this.editor.plugins.get(DataSchema);
36
+ dataFilter.on('register:$customElement', (evt, definition) => {
37
+ evt.stop();
38
+ const editor = this.editor;
39
+ const schema = editor.model.schema;
40
+ const conversion = editor.conversion;
41
+ const unsafeElements = editor.editing.view.domConverter.unsafeElements;
42
+ const preLikeElements = editor.data.htmlProcessor.domConverter.preElements;
43
+ schema.register(definition.model, definition.modelSchema);
44
+ schema.extend(definition.model, {
45
+ allowAttributes: ['htmlElementName', 'htmlCustomElementAttributes', 'htmlContent'],
46
+ isContent: true
47
+ });
48
+ // Being executed on the low priority, it will catch all elements that were not caught by other converters.
49
+ conversion.for('upcast').elementToElement({
50
+ view: /.*/,
51
+ model: (viewElement, conversionApi) => {
52
+ // Do not try to convert $comment fake element.
53
+ if (viewElement.name == '$comment') {
54
+ return null;
55
+ }
56
+ if (!isValidElementName(viewElement.name)) {
57
+ return null;
58
+ }
59
+ // Allow for fallback only if this element is not defined in data schema to make sure
60
+ // that this will handle only custom elements not registered in the data schema.
61
+ if (dataSchema.getDefinitionsForView(viewElement.name).size) {
62
+ return null;
63
+ }
64
+ // Make sure that this element will not render in the editing view.
65
+ if (!unsafeElements.includes(viewElement.name)) {
66
+ unsafeElements.push(viewElement.name);
67
+ }
68
+ // Make sure that whitespaces will not be trimmed or replaced by nbsps while stringify content.
69
+ if (!preLikeElements.includes(viewElement.name)) {
70
+ preLikeElements.push(viewElement.name);
71
+ }
72
+ const modelElement = conversionApi.writer.createElement(definition.model, {
73
+ htmlElementName: viewElement.name
74
+ });
75
+ const htmlAttributes = dataFilter.processViewAttributes(viewElement, conversionApi);
76
+ if (htmlAttributes) {
77
+ conversionApi.writer.setAttribute('htmlCustomElementAttributes', htmlAttributes, modelElement);
78
+ }
79
+ // Store the whole element in the attribute so that DomConverter will be able to use the pre like element context.
80
+ const viewWriter = new UpcastWriter(viewElement.document);
81
+ const documentFragment = viewWriter.createDocumentFragment(viewElement);
82
+ const htmlContent = editor.data.processor.toData(documentFragment);
83
+ conversionApi.writer.setAttribute('htmlContent', htmlContent, modelElement);
84
+ // Consume the content of the element.
85
+ for (const { item } of editor.editing.view.createRangeIn(viewElement)) {
86
+ conversionApi.consumable.consume(item, { name: true });
87
+ }
88
+ return modelElement;
89
+ },
90
+ converterPriority: 'low'
91
+ });
92
+ // Because this element is unsafe (DomConverter#unsafeElements), it will render as a transparent <span> but it must
93
+ // be rendered anyway for the mapping between the model and the view to exist.
94
+ conversion.for('editingDowncast').elementToElement({
95
+ model: {
96
+ name: definition.model,
97
+ attributes: ['htmlElementName', 'htmlCustomElementAttributes', 'htmlContent']
98
+ },
99
+ view: (modelElement, { writer }) => {
100
+ const viewName = modelElement.getAttribute('htmlElementName');
101
+ const viewElement = writer.createRawElement(viewName);
102
+ if (modelElement.hasAttribute('htmlCustomElementAttributes')) {
103
+ setViewAttributes(writer, modelElement.getAttribute('htmlCustomElementAttributes'), viewElement);
104
+ }
105
+ return viewElement;
106
+ }
107
+ });
108
+ conversion.for('dataDowncast').elementToElement({
109
+ model: {
110
+ name: definition.model,
111
+ attributes: ['htmlElementName', 'htmlCustomElementAttributes', 'htmlContent']
112
+ },
113
+ view: (modelElement, { writer }) => {
114
+ const viewName = modelElement.getAttribute('htmlElementName');
115
+ const htmlContent = modelElement.getAttribute('htmlContent');
116
+ const viewElement = writer.createRawElement(viewName, null, (domElement, domConverter) => {
117
+ domConverter.setContentOf(domElement, htmlContent);
118
+ // Unwrap the custom element content (it was stored in the attribute as the whole custom element).
119
+ // See the upcast conversion for the "htmlContent" attribute to learn more.
120
+ const customElement = domElement.firstChild;
121
+ customElement.remove();
122
+ while (customElement.firstChild) {
123
+ domElement.appendChild(customElement.firstChild);
124
+ }
125
+ });
126
+ if (modelElement.hasAttribute('htmlCustomElementAttributes')) {
127
+ setViewAttributes(writer, modelElement.getAttribute('htmlCustomElementAttributes'), viewElement);
128
+ }
129
+ return viewElement;
130
+ }
131
+ });
132
+ });
133
+ }
134
+ }
135
+ /**
136
+ * Returns true if name is valid for a DOM element name.
137
+ */
138
+ function isValidElementName(name) {
139
+ try {
140
+ document.createElement(name);
141
+ }
142
+ catch (error) {
143
+ return false;
144
+ }
145
+ return true;
146
+ }
@@ -1,27 +1,27 @@
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 DataFilter from '../datafilter';
7
- /**
8
- * Provides the General HTML Support integration with the {@link module:list/documentlist~DocumentList Document List} feature.
9
- */
10
- export default class DocumentListElementSupport extends Plugin {
11
- /**
12
- * @inheritDoc
13
- */
14
- static get requires(): readonly [typeof DataFilter];
15
- /**
16
- * @inheritDoc
17
- */
18
- static get pluginName(): "DocumentListElementSupport";
19
- /**
20
- * @inheritDoc
21
- */
22
- init(): void;
23
- /**
24
- * @inheritDoc
25
- */
26
- afterInit(): void;
27
- }
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 DataFilter from '../datafilter';
7
+ /**
8
+ * Provides the General HTML Support integration with the {@link module:list/documentlist~DocumentList Document List} feature.
9
+ */
10
+ export default class DocumentListElementSupport extends Plugin {
11
+ /**
12
+ * @inheritDoc
13
+ */
14
+ static get requires(): readonly [typeof DataFilter];
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ static get pluginName(): "DocumentListElementSupport";
19
+ /**
20
+ * @inheritDoc
21
+ */
22
+ init(): void;
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ afterInit(): void;
27
+ }