@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
@@ -0,0 +1,169 @@
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/dataschema
7
+ */
8
+ import { Plugin, type Editor } from 'ckeditor5/src/core';
9
+ import type { AttributeProperties, SchemaItemDefinition } from 'ckeditor5/src/engine';
10
+ /**
11
+ * Holds representation of the extended HTML document type definitions to be used by the
12
+ * editor in HTML support.
13
+ *
14
+ * Data schema is represented by data schema definitions.
15
+ *
16
+ * To add new definition for block element,
17
+ * use {@link module:html-support/dataschema~DataSchema#registerBlockElement} method:
18
+ *
19
+ * ```ts
20
+ * dataSchema.registerBlockElement( {
21
+ * view: 'section',
22
+ * model: 'my-section',
23
+ * modelSchema: {
24
+ * inheritAllFrom: '$block'
25
+ * }
26
+ * } );
27
+ * ```
28
+ *
29
+ * To add new definition for inline element,
30
+ * use {@link module:html-support/dataschema~DataSchema#registerInlineElement} method:
31
+ *
32
+ * ```
33
+ * dataSchema.registerInlineElement( {
34
+ * view: 'span',
35
+ * model: 'my-span',
36
+ * attributeProperties: {
37
+ * copyOnEnter: true
38
+ * }
39
+ * } );
40
+ * ```
41
+ */
42
+ export default class DataSchema extends Plugin {
43
+ /**
44
+ * A map of registered data schema definitions.
45
+ */
46
+ private readonly _definitions;
47
+ constructor(editor: Editor);
48
+ /**
49
+ * @inheritDoc
50
+ */
51
+ static get pluginName(): 'DataSchema';
52
+ /**
53
+ * @inheritDoc
54
+ */
55
+ init(): void;
56
+ /**
57
+ * Add new data schema definition describing block element.
58
+ */
59
+ registerBlockElement(definition: DataSchemaBlockElementDefinition): void;
60
+ /**
61
+ * Add new data schema definition describing inline element.
62
+ */
63
+ registerInlineElement(definition: DataSchemaInlineElementDefinition): void;
64
+ /**
65
+ * Updates schema definition describing block element with new properties.
66
+ *
67
+ * Creates new scheme if it doesn't exist.
68
+ * Array properties are concatenated with original values.
69
+ *
70
+ * @param definition Definition update.
71
+ */
72
+ extendBlockElement(definition: DataSchemaBlockElementDefinition): void;
73
+ /**
74
+ * Updates schema definition describing inline element with new properties.
75
+ *
76
+ * Creates new scheme if it doesn't exist.
77
+ * Array properties are concatenated with original values.
78
+ *
79
+ * @param definition Definition update.
80
+ */
81
+ extendInlineElement(definition: DataSchemaInlineElementDefinition): void;
82
+ /**
83
+ * Returns all definitions matching the given view name.
84
+ *
85
+ * @param includeReferences Indicates if this method should also include definitions of referenced models.
86
+ */
87
+ getDefinitionsForView(viewName: string | RegExp, includeReferences?: boolean): Set<DataSchemaDefinition>;
88
+ /**
89
+ * Returns definitions matching the given view name.
90
+ */
91
+ private _getMatchingViewDefinitions;
92
+ /**
93
+ * Resolves all definition references registered for the given data schema definition.
94
+ *
95
+ * @param modelName Data schema model name.
96
+ */
97
+ private _getReferences;
98
+ /**
99
+ * Updates schema definition with new properties.
100
+ *
101
+ * Creates new scheme if it doesn't exist.
102
+ * Array properties are concatenated with original values.
103
+ *
104
+ * @param definition Definition update.
105
+ */
106
+ private _extendDefinition;
107
+ }
108
+ /**
109
+ * A base definition of {@link module:html-support/dataschema~DataSchema data schema}.
110
+ */
111
+ export interface DataSchemaDefinition {
112
+ /**
113
+ * Name of the model.
114
+ */
115
+ model: string;
116
+ /**
117
+ * Name of the view element.
118
+ */
119
+ view?: string;
120
+ /**
121
+ * Indicates that the definition describes object element.
122
+ */
123
+ isObject?: boolean;
124
+ /**
125
+ * The model schema item definition describing registered model.
126
+ */
127
+ modelSchema?: SchemaItemDefinition;
128
+ /**
129
+ * Indicates that the definition describes block element.
130
+ * Set by {@link module:html-support/dataschema~DataSchema#registerBlockElement} method.
131
+ */
132
+ isBlock?: boolean;
133
+ /**
134
+ * Indicates that the definition describes inline element.
135
+ */
136
+ isInline?: boolean;
137
+ }
138
+ /**
139
+ * A definition of {@link module:html-support/dataschema~DataSchema data schema} for block elements.
140
+ */
141
+ export interface DataSchemaBlockElementDefinition extends DataSchemaDefinition {
142
+ /**
143
+ * Should be used when an element can behave both as a sectioning element (e.g. article) and
144
+ * element accepting only inline content (e.g. paragraph).
145
+ * If an element contains only inline content, this option will be used as a model name.
146
+ */
147
+ paragraphLikeModel?: string;
148
+ }
149
+ /**
150
+ * A definition of {@link module:html-support/dataschema~DataSchema data schema} for inline elements.
151
+ */
152
+ export interface DataSchemaInlineElementDefinition extends DataSchemaDefinition {
153
+ /**
154
+ * Additional metadata describing the model attribute.
155
+ */
156
+ attributeProperties?: AttributeProperties;
157
+ /**
158
+ * Element priority. Decides in what order elements are wrapped by
159
+ * {@link module:engine/view/downcastwriter~DowncastWriter}.
160
+ * Set by {@link module:html-support/dataschema~DataSchema#registerInlineElement} method.
161
+ */
162
+ priority?: number;
163
+ /**
164
+ * The name of the model attribute that generates the same view element. GHS inline attribute
165
+ * will be removed from the model tree as soon as the coupled attribute is removed. See
166
+ * {@link module:html-support/datafilter~DataFilter#_registerModelPostFixer GHS post-fixer} for more details.
167
+ */
168
+ coupledAttribute?: string;
169
+ }
package/src/dataschema.js CHANGED
@@ -2,16 +2,13 @@
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/dataschema
8
7
  */
9
-
10
8
  import { Plugin } from 'ckeditor5/src/core';
11
9
  import { toArray } from 'ckeditor5/src/utils';
12
10
  import defaultConfig from './schemadefinitions';
13
11
  import { mergeWith } from 'lodash-es';
14
-
15
12
  /**
16
13
  * Holds representation of the extended HTML document type definitions to be used by the
17
14
  * editor in HTML support.
@@ -21,238 +18,155 @@ import { mergeWith } from 'lodash-es';
21
18
  * To add new definition for block element,
22
19
  * use {@link module:html-support/dataschema~DataSchema#registerBlockElement} method:
23
20
  *
24
- * dataSchema.registerBlockElement( {
25
- * view: 'section',
26
- * model: 'my-section',
27
- * modelSchema: {
28
- * inheritAllFrom: '$block'
29
- * }
30
- * } );
21
+ * ```ts
22
+ * dataSchema.registerBlockElement( {
23
+ * view: 'section',
24
+ * model: 'my-section',
25
+ * modelSchema: {
26
+ * inheritAllFrom: '$block'
27
+ * }
28
+ * } );
29
+ * ```
31
30
  *
32
31
  * To add new definition for inline element,
33
32
  * use {@link module:html-support/dataschema~DataSchema#registerInlineElement} method:
34
33
  *
35
- * dataSchema.registerInlineElement( {
36
- * view: 'span',
37
- * model: 'my-span',
38
- * attributeProperties: {
39
- * copyOnEnter: true
40
- * }
41
- * } );
42
- *
43
- * @extends module:core/plugin~Plugin
34
+ * ```
35
+ * dataSchema.registerInlineElement( {
36
+ * view: 'span',
37
+ * model: 'my-span',
38
+ * attributeProperties: {
39
+ * copyOnEnter: true
40
+ * }
41
+ * } );
42
+ * ```
44
43
  */
45
44
  export default class DataSchema extends Plugin {
46
- constructor( editor ) {
47
- super( editor );
48
-
49
- /**
50
- * A map of registered data schema definitions.
51
- *
52
- * @readonly
53
- * @private
54
- * @member {Map.<String, module:html-support/dataschema~DataSchemaDefinition>} #_definitions
55
- */
56
- this._definitions = new Map();
57
- }
58
-
59
- /**
60
- * @inheritDoc
61
- */
62
- static get pluginName() {
63
- return 'DataSchema';
64
- }
65
-
66
- /**
67
- * @inheritDoc
68
- */
69
- init() {
70
- for ( const definition of defaultConfig.block ) {
71
- this.registerBlockElement( definition );
72
- }
73
-
74
- for ( const definition of defaultConfig.inline ) {
75
- this.registerInlineElement( definition );
76
- }
77
- }
78
-
79
- /**
80
- * Add new data schema definition describing block element.
81
- *
82
- * @param {module:html-support/dataschema~DataSchemaBlockElementDefinition} definition
83
- */
84
- registerBlockElement( definition ) {
85
- this._definitions.set( definition.model, { ...definition, isBlock: true } );
86
- }
87
-
88
- /**
89
- * Add new data schema definition describing inline element.
90
- *
91
- * @param {module:html-support/dataschema~DataSchemaInlineElementDefinition} definition
92
- */
93
- registerInlineElement( definition ) {
94
- this._definitions.set( definition.model, { ...definition, isInline: true } );
95
- }
96
-
97
- /**
98
- * Updates schema definition describing block element with new properties.
99
- *
100
- * Creates new scheme if it doesn't exist.
101
- * Array properties are concatenated with original values.
102
- *
103
- * @param {module:html-support/dataschema~DataSchemaBlockElementDefinition} definition Definition update.
104
- */
105
- extendBlockElement( definition ) {
106
- this._extendDefinition( { ...definition, isBlock: true } );
107
- }
108
-
109
- /**
110
- * Updates schema definition describing inline element with new properties.
111
- *
112
- * Creates new scheme if it doesn't exist.
113
- * Array properties are concatenated with original values.
114
- *
115
- * @param {module:html-support/dataschema~DataSchemaInlineElementDefinition} definition Definition update.
116
- */
117
- extendInlineElement( definition ) {
118
- this._extendDefinition( { ...definition, isInline: true } );
119
- }
120
-
121
- /**
122
- * Returns all definitions matching the given view name.
123
- *
124
- * @param {String|RegExp} viewName
125
- * @param {Boolean} [includeReferences] Indicates if this method should also include definitions of referenced models.
126
- * @returns {Set.<module:html-support/dataschema~DataSchemaDefinition>}
127
- */
128
- getDefinitionsForView( viewName, includeReferences ) {
129
- const definitions = new Set();
130
-
131
- for ( const definition of this._getMatchingViewDefinitions( viewName ) ) {
132
- if ( includeReferences ) {
133
- for ( const reference of this._getReferences( definition.model ) ) {
134
- definitions.add( reference );
135
- }
136
- }
137
-
138
- definitions.add( definition );
139
- }
140
-
141
- return definitions;
142
- }
143
-
144
- /**
145
- * Returns definitions matching the given view name.
146
- *
147
- * @private
148
- * @param {String|RegExp} viewName
149
- * @returns {Array.<module:html-support/dataschema~DataSchemaDefinition>}
150
- */
151
- _getMatchingViewDefinitions( viewName ) {
152
- return Array.from( this._definitions.values() )
153
- .filter( def => def.view && testViewName( viewName, def.view ) );
154
- }
155
-
156
- /**
157
- * Resolves all definition references registered for the given data schema definition.
158
- *
159
- * @private
160
- * @param {String} modelName Data schema model name.
161
- * @returns {Iterable.<module:html-support/dataschema~DataSchemaDefinition>}
162
- */
163
- * _getReferences( modelName ) {
164
- const { modelSchema } = this._definitions.get( modelName );
165
-
166
- if ( !modelSchema ) {
167
- return;
168
- }
169
-
170
- const inheritProperties = [ 'inheritAllFrom', 'inheritTypesFrom', 'allowWhere', 'allowContentOf', 'allowAttributesOf' ];
171
-
172
- for ( const property of inheritProperties ) {
173
- for ( const referenceName of toArray( modelSchema[ property ] || [] ) ) {
174
- const definition = this._definitions.get( referenceName );
175
-
176
- if ( referenceName !== modelName && definition ) {
177
- yield* this._getReferences( definition.model );
178
- yield definition;
179
- }
180
- }
181
- }
182
- }
183
-
184
- /**
185
- * Updates schema definition with new properties.
186
- *
187
- * Creates new scheme if it doesn't exist.
188
- * Array properties are concatenated with original values.
189
- *
190
- * @private
191
- * @param {module:html-support/dataschema~DataSchemaDefinition} definition Definition update.
192
- */
193
- _extendDefinition( definition ) {
194
- const currentDefinition = this._definitions.get( definition.model );
195
-
196
- const mergedDefinition = mergeWith( {}, currentDefinition, definition, ( target, source ) => {
197
- return Array.isArray( target ) ? target.concat( source ) : undefined;
198
- } );
199
-
200
- this._definitions.set( definition.model, mergedDefinition );
201
- }
202
- }
203
-
204
- // Test view name against the given pattern.
205
- //
206
- // @private
207
- // @param {String|RegExp} pattern
208
- // @param {String} viewName
209
- // @returns {Boolean}
210
- function testViewName( pattern, viewName ) {
211
- if ( typeof pattern === 'string' ) {
212
- return pattern === viewName;
213
- }
214
-
215
- if ( pattern instanceof RegExp ) {
216
- return pattern.test( viewName );
217
- }
218
-
219
- return false;
45
+ constructor(editor) {
46
+ super(editor);
47
+ this._definitions = new Map();
48
+ }
49
+ /**
50
+ * @inheritDoc
51
+ */
52
+ static get pluginName() {
53
+ return 'DataSchema';
54
+ }
55
+ /**
56
+ * @inheritDoc
57
+ */
58
+ init() {
59
+ for (const definition of defaultConfig.block) {
60
+ this.registerBlockElement(definition);
61
+ }
62
+ for (const definition of defaultConfig.inline) {
63
+ this.registerInlineElement(definition);
64
+ }
65
+ }
66
+ /**
67
+ * Add new data schema definition describing block element.
68
+ */
69
+ registerBlockElement(definition) {
70
+ this._definitions.set(definition.model, { ...definition, isBlock: true });
71
+ }
72
+ /**
73
+ * Add new data schema definition describing inline element.
74
+ */
75
+ registerInlineElement(definition) {
76
+ this._definitions.set(definition.model, { ...definition, isInline: true });
77
+ }
78
+ /**
79
+ * Updates schema definition describing block element with new properties.
80
+ *
81
+ * Creates new scheme if it doesn't exist.
82
+ * Array properties are concatenated with original values.
83
+ *
84
+ * @param definition Definition update.
85
+ */
86
+ extendBlockElement(definition) {
87
+ this._extendDefinition({ ...definition, isBlock: true });
88
+ }
89
+ /**
90
+ * Updates schema definition describing inline element with new properties.
91
+ *
92
+ * Creates new scheme if it doesn't exist.
93
+ * Array properties are concatenated with original values.
94
+ *
95
+ * @param definition Definition update.
96
+ */
97
+ extendInlineElement(definition) {
98
+ this._extendDefinition({ ...definition, isInline: true });
99
+ }
100
+ /**
101
+ * Returns all definitions matching the given view name.
102
+ *
103
+ * @param includeReferences Indicates if this method should also include definitions of referenced models.
104
+ */
105
+ getDefinitionsForView(viewName, includeReferences = false) {
106
+ const definitions = new Set();
107
+ for (const definition of this._getMatchingViewDefinitions(viewName)) {
108
+ if (includeReferences) {
109
+ for (const reference of this._getReferences(definition.model)) {
110
+ definitions.add(reference);
111
+ }
112
+ }
113
+ definitions.add(definition);
114
+ }
115
+ return definitions;
116
+ }
117
+ /**
118
+ * Returns definitions matching the given view name.
119
+ */
120
+ _getMatchingViewDefinitions(viewName) {
121
+ return Array.from(this._definitions.values())
122
+ .filter(def => def.view && testViewName(viewName, def.view));
123
+ }
124
+ /**
125
+ * Resolves all definition references registered for the given data schema definition.
126
+ *
127
+ * @param modelName Data schema model name.
128
+ */
129
+ *_getReferences(modelName) {
130
+ const { modelSchema } = this._definitions.get(modelName);
131
+ if (!modelSchema) {
132
+ return;
133
+ }
134
+ const inheritProperties = ['inheritAllFrom', 'inheritTypesFrom', 'allowWhere', 'allowContentOf', 'allowAttributesOf'];
135
+ for (const property of inheritProperties) {
136
+ for (const referenceName of toArray(modelSchema[property] || [])) {
137
+ const definition = this._definitions.get(referenceName);
138
+ if (referenceName !== modelName && definition) {
139
+ yield* this._getReferences(definition.model);
140
+ yield definition;
141
+ }
142
+ }
143
+ }
144
+ }
145
+ /**
146
+ * Updates schema definition with new properties.
147
+ *
148
+ * Creates new scheme if it doesn't exist.
149
+ * Array properties are concatenated with original values.
150
+ *
151
+ * @param definition Definition update.
152
+ */
153
+ _extendDefinition(definition) {
154
+ const currentDefinition = this._definitions.get(definition.model);
155
+ const mergedDefinition = mergeWith({}, currentDefinition, definition, (target, source) => {
156
+ return Array.isArray(target) ? target.concat(source) : undefined;
157
+ });
158
+ this._definitions.set(definition.model, mergedDefinition);
159
+ }
220
160
  }
221
-
222
- /**
223
- * A base definition of {@link module:html-support/dataschema~DataSchema data schema}.
224
- *
225
- * @typedef {Object} module:html-support/dataschema~DataSchemaDefinition
226
- * @property {String} model Name of the model.
227
- * @property {String} [view] Name of the view element.
228
- * @property {Boolean} [isObject] Indicates that the definition describes object element.
229
- * @property {module:engine/model/schema~SchemaItemDefinition} [modelSchema] The model schema item definition describing registered model.
230
- */
231
-
232
161
  /**
233
- * A definition of {@link module:html-support/dataschema~DataSchema data schema} for block elements.
234
- *
235
- * @typedef {Object} module:html-support/dataschema~DataSchemaBlockElementDefinition
236
- * @property {Boolean} isBlock Indicates that the definition describes block element.
237
- * Set by {@link module:html-support/dataschema~DataSchema#registerBlockElement} method.
238
- * @property {String} [paragraphLikeModel] Should be used when an element can behave both as a sectioning element (e.g. article) and
239
- * element accepting only inline content (e.g. paragraph).
240
- * If an element contains only inline content, this option will be used as a model
241
- * name.
242
- * @extends module:html-support/dataschema~DataSchemaDefinition
243
- */
244
-
245
- /**
246
- * A definition of {@link module:html-support/dataschema~DataSchema data schema} for inline elements.
247
- *
248
- * @typedef {Object} module:html-support/dataschema~DataSchemaInlineElementDefinition
249
- * @property {module:engine/model/schema~AttributeProperties} [attributeProperties] Additional metadata describing the model attribute.
250
- * @property {Boolean} isInline Indicates that the definition describes inline element.
251
- * @property {Number} [priority] Element priority. Decides in what order elements are wrapped by
252
- * {@link module:engine/view/downcastwriter~DowncastWriter}.
253
- * Set by {@link module:html-support/dataschema~DataSchema#registerInlineElement} method.
254
- * @property {String} [coupledAttribute] The name of the model attribute that generates the same view element. GHS inline attribute
255
- * will be removed from the model tree as soon as the coupled attribute is removed. See
256
- * {@link module:html-support/datafilter~DataFilter#_registerModelPostFixer GHS post-fixer} for more details.
257
- * @extends module:html-support/dataschema~DataSchemaDefinition
162
+ * Test view name against the given pattern.
258
163
  */
164
+ function testViewName(pattern, viewName) {
165
+ if (typeof pattern === 'string') {
166
+ return pattern === viewName;
167
+ }
168
+ if (pattern instanceof RegExp) {
169
+ return pattern.test(viewName);
170
+ }
171
+ return false;
172
+ }
@@ -0,0 +1,21 @@
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/fullpage
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ /**
10
+ * The full page editing feature. It preserves the whole HTML page in the editor data.
11
+ */
12
+ export default class FullPage extends Plugin {
13
+ /**
14
+ * @inheritDoc
15
+ */
16
+ static get pluginName(): 'FullPage';
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ init(): void;
21
+ }