@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,20 +2,10 @@
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/dualcontent
8
- */
9
-
10
5
  import { Plugin } from 'ckeditor5/src/core';
11
6
  import { priorities } from 'ckeditor5/src/utils';
12
- import {
13
- modelToViewBlockAttributeConverter,
14
- viewToModelBlockAttributeConverter
15
- } from '../converters';
16
-
7
+ import { modelToViewBlockAttributeConverter, viewToModelBlockAttributeConverter } from '../converters';
17
8
  import DataFilter from '../datafilter';
18
-
19
9
  /**
20
10
  * Provides the General HTML Support integration for elements which can behave like sectioning element (e.g. article) or
21
11
  * element accepting only inline content (e.g. paragraph).
@@ -32,123 +22,97 @@ import DataFilter from '../datafilter';
32
22
  * {@link module:html-support/dataschema~DataSchemaDefinition#modelSchema} in editor schema.
33
23
  * Otherwise, it will be registered under {@link module:html-support/dataschema~DataSchemaBlockElementDefinition#paragraphLikeModel} model
34
24
  * name with model schema accepting only inline content (inheriting from `$block`).
35
- *
36
- * @extends module:core/plugin~Plugin
37
25
  */
38
26
  export default class DualContentModelElementSupport extends Plugin {
39
- /**
40
- * @inheritDoc
41
- */
42
- static get requires() {
43
- return [ DataFilter ];
44
- }
45
-
46
- /**
47
- * @inheritDoc
48
- */
49
- static get pluginName() {
50
- return 'DualContentModelElementSupport';
51
- }
52
-
53
- /**
54
- * @inheritDoc
55
- */
56
- init() {
57
- const dataFilter = this.editor.plugins.get( DataFilter );
58
-
59
- dataFilter.on( 'register', ( evt, definition ) => {
60
- const editor = this.editor;
61
- const schema = editor.model.schema;
62
- const conversion = editor.conversion;
63
-
64
- if ( !definition.paragraphLikeModel ) {
65
- return;
66
- }
67
-
68
- // Can only apply to newly registered features.
69
- if ( schema.isRegistered( definition.model ) || schema.isRegistered( definition.paragraphLikeModel ) ) {
70
- return;
71
- }
72
-
73
- const paragraphLikeModelDefinition = {
74
- model: definition.paragraphLikeModel,
75
- view: definition.view
76
- };
77
-
78
- schema.register( definition.model, definition.modelSchema );
79
- schema.register( paragraphLikeModelDefinition.model, {
80
- inheritAllFrom: '$block'
81
- } );
82
-
83
- conversion.for( 'upcast' ).elementToElement( {
84
- view: definition.view,
85
- model: ( viewElement, { writer } ) => {
86
- if ( this._hasBlockContent( viewElement ) ) {
87
- return writer.createElement( definition.model );
88
- }
89
-
90
- return writer.createElement( paragraphLikeModelDefinition.model );
91
- },
92
- // With a `low` priority, `paragraph` plugin auto-paragraphing mechanism is executed. Make sure
93
- // this listener is called before it. If not, some elements will be transformed into a paragraph.
94
- converterPriority: priorities.get( 'low' ) + 1
95
- } );
96
-
97
- conversion.for( 'downcast' ).elementToElement( {
98
- view: definition.view,
99
- model: definition.model
100
- } );
101
- this._addAttributeConversion( definition );
102
-
103
- conversion.for( 'downcast' ).elementToElement( {
104
- view: paragraphLikeModelDefinition.view,
105
- model: paragraphLikeModelDefinition.model
106
- } );
107
- this._addAttributeConversion( paragraphLikeModelDefinition );
108
-
109
- evt.stop();
110
- } );
111
- }
112
-
113
- /**
114
- * Checks whether the given view element includes any other block element.
115
- *
116
- * @private
117
- * @param {module:engine/view/element~Element} viewElement
118
- * @returns {Boolean}
119
- */
120
- _hasBlockContent( viewElement ) {
121
- const view = this.editor.editing.view;
122
- const blockElements = view.domConverter.blockElements;
123
-
124
- // Traversing the viewElement subtree looking for block elements.
125
- // Especially for the cases like <div><a href="#"><p>foo</p></a></div>.
126
- // https://github.com/ckeditor/ckeditor5/issues/11513
127
- for ( const viewItem of view.createRangeIn( viewElement ).getItems() ) {
128
- if ( viewItem.is( 'element' ) && blockElements.includes( viewItem.name ) ) {
129
- return true;
130
- }
131
- }
132
-
133
- return false;
134
- }
135
-
136
- /**
137
- * Adds attribute filtering conversion for the given data schema.
138
- *
139
- * @private
140
- * @param {module:html-support/dataschema~DataSchemaBlockElementDefinition} definition
141
- */
142
- _addAttributeConversion( definition ) {
143
- const editor = this.editor;
144
- const conversion = editor.conversion;
145
- const dataFilter = editor.plugins.get( DataFilter );
146
-
147
- editor.model.schema.extend( definition.model, {
148
- allowAttributes: 'htmlAttributes'
149
- } );
150
-
151
- conversion.for( 'upcast' ).add( viewToModelBlockAttributeConverter( definition, dataFilter ) );
152
- conversion.for( 'downcast' ).add( modelToViewBlockAttributeConverter( definition ) );
153
- }
27
+ /**
28
+ * @inheritDoc
29
+ */
30
+ static get requires() {
31
+ return [DataFilter];
32
+ }
33
+ /**
34
+ * @inheritDoc
35
+ */
36
+ static get pluginName() {
37
+ return 'DualContentModelElementSupport';
38
+ }
39
+ /**
40
+ * @inheritDoc
41
+ */
42
+ init() {
43
+ const dataFilter = this.editor.plugins.get(DataFilter);
44
+ dataFilter.on('register', (evt, definition) => {
45
+ const blockDefinition = definition;
46
+ const editor = this.editor;
47
+ const schema = editor.model.schema;
48
+ const conversion = editor.conversion;
49
+ if (!blockDefinition.paragraphLikeModel) {
50
+ return;
51
+ }
52
+ // Can only apply to newly registered features.
53
+ if (schema.isRegistered(blockDefinition.model) || schema.isRegistered(blockDefinition.paragraphLikeModel)) {
54
+ return;
55
+ }
56
+ const paragraphLikeModelDefinition = {
57
+ model: blockDefinition.paragraphLikeModel,
58
+ view: blockDefinition.view
59
+ };
60
+ schema.register(blockDefinition.model, blockDefinition.modelSchema);
61
+ schema.register(paragraphLikeModelDefinition.model, {
62
+ inheritAllFrom: '$block'
63
+ });
64
+ conversion.for('upcast').elementToElement({
65
+ view: blockDefinition.view,
66
+ model: (viewElement, { writer }) => {
67
+ if (this._hasBlockContent(viewElement)) {
68
+ return writer.createElement(blockDefinition.model);
69
+ }
70
+ return writer.createElement(paragraphLikeModelDefinition.model);
71
+ },
72
+ // With a `low` priority, `paragraph` plugin auto-paragraphing mechanism is executed. Make sure
73
+ // this listener is called before it. If not, some elements will be transformed into a paragraph.
74
+ converterPriority: priorities.get('low') + 0.5
75
+ });
76
+ conversion.for('downcast').elementToElement({
77
+ view: blockDefinition.view,
78
+ model: blockDefinition.model
79
+ });
80
+ this._addAttributeConversion(blockDefinition);
81
+ conversion.for('downcast').elementToElement({
82
+ view: paragraphLikeModelDefinition.view,
83
+ model: paragraphLikeModelDefinition.model
84
+ });
85
+ this._addAttributeConversion(paragraphLikeModelDefinition);
86
+ evt.stop();
87
+ });
88
+ }
89
+ /**
90
+ * Checks whether the given view element includes any other block element.
91
+ */
92
+ _hasBlockContent(viewElement) {
93
+ const view = this.editor.editing.view;
94
+ const blockElements = view.domConverter.blockElements;
95
+ // Traversing the viewElement subtree looking for block elements.
96
+ // Especially for the cases like <div><a href="#"><p>foo</p></a></div>.
97
+ // https://github.com/ckeditor/ckeditor5/issues/11513
98
+ for (const viewItem of view.createRangeIn(viewElement).getItems()) {
99
+ if (viewItem.is('element') && blockElements.includes(viewItem.name)) {
100
+ return true;
101
+ }
102
+ }
103
+ return false;
104
+ }
105
+ /**
106
+ * Adds attribute filtering conversion for the given data schema.
107
+ */
108
+ _addAttributeConversion(definition) {
109
+ const editor = this.editor;
110
+ const conversion = editor.conversion;
111
+ const dataFilter = editor.plugins.get(DataFilter);
112
+ editor.model.schema.extend(definition.model, {
113
+ allowAttributes: 'htmlAttributes'
114
+ });
115
+ conversion.for('upcast').add(viewToModelBlockAttributeConverter(definition, dataFilter));
116
+ conversion.for('downcast').add(modelToViewBlockAttributeConverter(definition));
117
+ }
154
118
  }
@@ -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/heading
7
+ */
8
+ import { Plugin, type PluginDependencies } from 'ckeditor5/src/core';
9
+ /**
10
+ * Provides the General HTML Support integration with {@link module:heading/heading~Heading Heading} feature.
11
+ */
12
+ export default class HeadingElementSupport extends Plugin {
13
+ /**
14
+ * @inheritDoc
15
+ */
16
+ static get requires(): PluginDependencies;
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ static get pluginName(): 'HeadingElementSupport';
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ init(): void;
25
+ }
26
+ declare module '@ckeditor/ckeditor5-core' {
27
+ interface PluginsMap {
28
+ [HeadingElementSupport.pluginName]: HeadingElementSupport;
29
+ }
30
+ }
@@ -2,67 +2,54 @@
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/heading
8
7
  */
9
-
10
8
  import { Plugin } from 'ckeditor5/src/core';
11
-
12
9
  import DataSchema from '../dataschema';
13
-
14
10
  /**
15
11
  * Provides the General HTML Support integration with {@link module:heading/heading~Heading Heading} feature.
16
- *
17
- * @extends module:core/plugin~Plugin
18
12
  */
19
13
  export default class HeadingElementSupport extends Plugin {
20
- /**
21
- * @inheritDoc
22
- */
23
- static get requires() {
24
- return [ DataSchema ];
25
- }
26
-
27
- /**
28
- * @inheritDoc
29
- */
30
- static get pluginName() {
31
- return 'HeadingElementSupport';
32
- }
33
-
34
- /**
35
- * @inheritDoc
36
- */
37
- init() {
38
- const editor = this.editor;
39
-
40
- if ( !editor.plugins.has( 'HeadingEditing' ) ) {
41
- return;
42
- }
43
-
44
- const dataSchema = editor.plugins.get( DataSchema );
45
- const options = editor.config.get( 'heading.options' );
46
- const headerModels = [];
47
-
48
- // We are registering all elements supported by HeadingEditing
49
- // to enable custom attributes for those elements.
50
- for ( const option of options ) {
51
- if ( 'model' in option && 'view' in option ) {
52
- dataSchema.registerBlockElement( {
53
- view: option.view,
54
- model: option.model
55
- } );
56
-
57
- headerModels.push( option.model );
58
- }
59
- }
60
-
61
- dataSchema.extendBlockElement( {
62
- model: 'htmlHgroup',
63
- modelSchema: {
64
- allowChildren: headerModels
65
- }
66
- } );
67
- }
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ static get requires() {
18
+ return [DataSchema];
19
+ }
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ static get pluginName() {
24
+ return 'HeadingElementSupport';
25
+ }
26
+ /**
27
+ * @inheritDoc
28
+ */
29
+ init() {
30
+ const editor = this.editor;
31
+ if (!editor.plugins.has('HeadingEditing')) {
32
+ return;
33
+ }
34
+ const dataSchema = editor.plugins.get(DataSchema);
35
+ const options = editor.config.get('heading.options');
36
+ const headerModels = [];
37
+ // We are registering all elements supported by HeadingEditing
38
+ // to enable custom attributes for those elements.
39
+ for (const option of options) {
40
+ if ('model' in option && 'view' in option) {
41
+ dataSchema.registerBlockElement({
42
+ view: option.view,
43
+ model: option.model
44
+ });
45
+ headerModels.push(option.model);
46
+ }
47
+ }
48
+ dataSchema.extendBlockElement({
49
+ model: 'htmlHgroup',
50
+ modelSchema: {
51
+ allowChildren: headerModels
52
+ }
53
+ });
54
+ }
68
55
  }
@@ -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/image
7
+ */
8
+ import { Plugin, type PluginDependencies } from 'ckeditor5/src/core';
9
+ /**
10
+ * Provides the General HTML Support integration with the {@link module:image/image~Image Image} feature.
11
+ */
12
+ export default class ImageElementSupport extends Plugin {
13
+ /**
14
+ * @inheritDoc
15
+ */
16
+ static get requires(): PluginDependencies;
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ static get pluginName(): 'ImageElementSupport';
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ init(): void;
25
+ }
26
+ declare module '@ckeditor/ckeditor5-core' {
27
+ interface PluginsMap {
28
+ [ImageElementSupport.pluginName]: ImageElementSupport;
29
+ }
30
+ }