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