@ckeditor/ckeditor5-html-support 38.0.1 → 38.1.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/build/html-support.js.map +1 -0
  3. package/package.json +2 -45
  4. package/src/augmentation.d.ts +33 -33
  5. package/src/augmentation.js +5 -5
  6. package/src/converters.d.ts +56 -56
  7. package/src/converters.js +149 -148
  8. package/src/datafilter.d.ts +285 -255
  9. package/src/datafilter.js +661 -608
  10. package/src/dataschema.d.ts +179 -179
  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 +237 -237
  16. package/src/generalhtmlsupportconfig.d.ts +67 -67
  17. package/src/generalhtmlsupportconfig.js +5 -5
  18. package/src/htmlcomment.d.ts +72 -72
  19. package/src/htmlcomment.js +220 -188
  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 +203 -170
  30. package/src/integrations/dualcontent.d.ts +45 -45
  31. package/src/integrations/dualcontent.js +119 -118
  32. package/src/integrations/heading.d.ts +31 -35
  33. package/src/integrations/heading.js +60 -75
  34. package/src/integrations/image.d.ts +26 -26
  35. package/src/integrations/image.js +172 -172
  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 +956 -952
  48. package/src/utils.d.ts +72 -61
  49. package/src/utils.js +139 -124
package/src/dataschema.js CHANGED
@@ -1,196 +1,196 @@
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 } from 'ckeditor5/src/core';
9
- import { toArray } from 'ckeditor5/src/utils';
10
- import defaultConfig from './schemadefinitions';
11
- import { mergeWith } from 'lodash-es';
12
- /**
13
- * Holds representation of the extended HTML document type definitions to be used by the
14
- * editor in HTML support.
15
- *
16
- * Data schema is represented by data schema definitions.
17
- *
18
- * To add new definition for block element,
19
- * use {@link module:html-support/dataschema~DataSchema#registerBlockElement} method:
20
- *
21
- * ```ts
22
- * dataSchema.registerBlockElement( {
23
- * view: 'section',
24
- * model: 'my-section',
25
- * modelSchema: {
26
- * inheritAllFrom: '$block'
27
- * }
28
- * } );
29
- * ```
30
- *
31
- * To add new definition for inline element,
32
- * use {@link module:html-support/dataschema~DataSchema#registerInlineElement} method:
33
- *
34
- * ```
35
- * dataSchema.registerInlineElement( {
36
- * view: 'span',
37
- * model: 'my-span',
38
- * attributeProperties: {
39
- * copyOnEnter: true
40
- * }
41
- * } );
42
- * ```
43
- */
44
- export default class DataSchema extends Plugin {
45
- constructor() {
46
- super(...arguments);
47
- /**
48
- * A map of registered data schema definitions.
49
- */
50
- this._definitions = [];
51
- }
52
- /**
53
- * @inheritDoc
54
- */
55
- static get pluginName() {
56
- return 'DataSchema';
57
- }
58
- /**
59
- * @inheritDoc
60
- */
61
- init() {
62
- for (const definition of defaultConfig.block) {
63
- this.registerBlockElement(definition);
64
- }
65
- for (const definition of defaultConfig.inline) {
66
- this.registerInlineElement(definition);
67
- }
68
- }
69
- /**
70
- * Add new data schema definition describing block element.
71
- */
72
- registerBlockElement(definition) {
73
- this._definitions.push({ ...definition, isBlock: true });
74
- }
75
- /**
76
- * Add new data schema definition describing inline element.
77
- */
78
- registerInlineElement(definition) {
79
- this._definitions.push({ ...definition, isInline: true });
80
- }
81
- /**
82
- * Updates schema definition describing block element with new properties.
83
- *
84
- * Creates new scheme if it doesn't exist.
85
- * Array properties are concatenated with original values.
86
- *
87
- * @param definition Definition update.
88
- */
89
- extendBlockElement(definition) {
90
- this._extendDefinition({ ...definition, isBlock: true });
91
- }
92
- /**
93
- * Updates schema definition describing inline element with new properties.
94
- *
95
- * Creates new scheme if it doesn't exist.
96
- * Array properties are concatenated with original values.
97
- *
98
- * @param definition Definition update.
99
- */
100
- extendInlineElement(definition) {
101
- this._extendDefinition({ ...definition, isInline: true });
102
- }
103
- /**
104
- * Returns all definitions matching the given view name.
105
- *
106
- * @param includeReferences Indicates if this method should also include definitions of referenced models.
107
- */
108
- getDefinitionsForView(viewName, includeReferences = false) {
109
- const definitions = new Set();
110
- for (const definition of this._getMatchingViewDefinitions(viewName)) {
111
- if (includeReferences) {
112
- for (const reference of this._getReferences(definition.model)) {
113
- definitions.add(reference);
114
- }
115
- }
116
- definitions.add(definition);
117
- }
118
- return definitions;
119
- }
120
- /**
121
- * Returns definitions matching the given model name.
122
- */
123
- getDefinitionsForModel(modelName) {
124
- return this._definitions.filter(definition => definition.model == modelName);
125
- }
126
- /**
127
- * Returns definitions matching the given view name.
128
- */
129
- _getMatchingViewDefinitions(viewName) {
130
- return this._definitions.filter(def => def.view && testViewName(viewName, def.view));
131
- }
132
- /**
133
- * Resolves all definition references registered for the given data schema definition.
134
- *
135
- * @param modelName Data schema model name.
136
- */
137
- *_getReferences(modelName) {
138
- const inheritProperties = [
139
- 'inheritAllFrom',
140
- 'inheritTypesFrom',
141
- 'allowWhere',
142
- 'allowContentOf',
143
- 'allowAttributesOf'
144
- ];
145
- const definitions = this._definitions.filter(definition => definition.model == modelName);
146
- for (const { modelSchema } of definitions) {
147
- if (!modelSchema) {
148
- continue;
149
- }
150
- for (const property of inheritProperties) {
151
- for (const referenceName of toArray(modelSchema[property] || [])) {
152
- const definitions = this._definitions.filter(definition => definition.model == referenceName);
153
- for (const definition of definitions) {
154
- if (referenceName !== modelName) {
155
- yield* this._getReferences(definition.model);
156
- yield definition;
157
- }
158
- }
159
- }
160
- }
161
- }
162
- }
163
- /**
164
- * Updates schema definition with new properties.
165
- *
166
- * Creates new scheme if it doesn't exist.
167
- * Array properties are concatenated with original values.
168
- *
169
- * @param definition Definition update.
170
- */
171
- _extendDefinition(definition) {
172
- const currentDefinitions = Array.from(this._definitions.entries())
173
- .filter(([, currentDefinition]) => currentDefinition.model == definition.model);
174
- if (currentDefinitions.length == 0) {
175
- this._definitions.push(definition);
176
- return;
177
- }
178
- for (const [idx, currentDefinition] of currentDefinitions) {
179
- this._definitions[idx] = mergeWith({}, currentDefinition, definition, (target, source) => {
180
- return Array.isArray(target) ? target.concat(source) : undefined;
181
- });
182
- }
183
- }
184
- }
185
- /**
186
- * Test view name against the given pattern.
187
- */
188
- function testViewName(pattern, viewName) {
189
- if (typeof pattern === 'string') {
190
- return pattern === viewName;
191
- }
192
- if (pattern instanceof RegExp) {
193
- return pattern.test(viewName);
194
- }
195
- return false;
196
- }
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 } from 'ckeditor5/src/core';
9
+ import { toArray } from 'ckeditor5/src/utils';
10
+ import defaultConfig from './schemadefinitions';
11
+ import { mergeWith } from 'lodash-es';
12
+ /**
13
+ * Holds representation of the extended HTML document type definitions to be used by the
14
+ * editor in HTML support.
15
+ *
16
+ * Data schema is represented by data schema definitions.
17
+ *
18
+ * To add new definition for block element,
19
+ * use {@link module:html-support/dataschema~DataSchema#registerBlockElement} method:
20
+ *
21
+ * ```ts
22
+ * dataSchema.registerBlockElement( {
23
+ * view: 'section',
24
+ * model: 'my-section',
25
+ * modelSchema: {
26
+ * inheritAllFrom: '$block'
27
+ * }
28
+ * } );
29
+ * ```
30
+ *
31
+ * To add new definition for inline element,
32
+ * use {@link module:html-support/dataschema~DataSchema#registerInlineElement} method:
33
+ *
34
+ * ```
35
+ * dataSchema.registerInlineElement( {
36
+ * view: 'span',
37
+ * model: 'my-span',
38
+ * attributeProperties: {
39
+ * copyOnEnter: true
40
+ * }
41
+ * } );
42
+ * ```
43
+ */
44
+ export default class DataSchema extends Plugin {
45
+ constructor() {
46
+ super(...arguments);
47
+ /**
48
+ * A map of registered data schema definitions.
49
+ */
50
+ this._definitions = [];
51
+ }
52
+ /**
53
+ * @inheritDoc
54
+ */
55
+ static get pluginName() {
56
+ return 'DataSchema';
57
+ }
58
+ /**
59
+ * @inheritDoc
60
+ */
61
+ init() {
62
+ for (const definition of defaultConfig.block) {
63
+ this.registerBlockElement(definition);
64
+ }
65
+ for (const definition of defaultConfig.inline) {
66
+ this.registerInlineElement(definition);
67
+ }
68
+ }
69
+ /**
70
+ * Add new data schema definition describing block element.
71
+ */
72
+ registerBlockElement(definition) {
73
+ this._definitions.push({ ...definition, isBlock: true });
74
+ }
75
+ /**
76
+ * Add new data schema definition describing inline element.
77
+ */
78
+ registerInlineElement(definition) {
79
+ this._definitions.push({ ...definition, isInline: true });
80
+ }
81
+ /**
82
+ * Updates schema definition describing block element with new properties.
83
+ *
84
+ * Creates new scheme if it doesn't exist.
85
+ * Array properties are concatenated with original values.
86
+ *
87
+ * @param definition Definition update.
88
+ */
89
+ extendBlockElement(definition) {
90
+ this._extendDefinition({ ...definition, isBlock: true });
91
+ }
92
+ /**
93
+ * Updates schema definition describing inline element with new properties.
94
+ *
95
+ * Creates new scheme if it doesn't exist.
96
+ * Array properties are concatenated with original values.
97
+ *
98
+ * @param definition Definition update.
99
+ */
100
+ extendInlineElement(definition) {
101
+ this._extendDefinition({ ...definition, isInline: true });
102
+ }
103
+ /**
104
+ * Returns all definitions matching the given view name.
105
+ *
106
+ * @param includeReferences Indicates if this method should also include definitions of referenced models.
107
+ */
108
+ getDefinitionsForView(viewName, includeReferences = false) {
109
+ const definitions = new Set();
110
+ for (const definition of this._getMatchingViewDefinitions(viewName)) {
111
+ if (includeReferences) {
112
+ for (const reference of this._getReferences(definition.model)) {
113
+ definitions.add(reference);
114
+ }
115
+ }
116
+ definitions.add(definition);
117
+ }
118
+ return definitions;
119
+ }
120
+ /**
121
+ * Returns definitions matching the given model name.
122
+ */
123
+ getDefinitionsForModel(modelName) {
124
+ return this._definitions.filter(definition => definition.model == modelName);
125
+ }
126
+ /**
127
+ * Returns definitions matching the given view name.
128
+ */
129
+ _getMatchingViewDefinitions(viewName) {
130
+ return this._definitions.filter(def => def.view && testViewName(viewName, def.view));
131
+ }
132
+ /**
133
+ * Resolves all definition references registered for the given data schema definition.
134
+ *
135
+ * @param modelName Data schema model name.
136
+ */
137
+ *_getReferences(modelName) {
138
+ const inheritProperties = [
139
+ 'inheritAllFrom',
140
+ 'inheritTypesFrom',
141
+ 'allowWhere',
142
+ 'allowContentOf',
143
+ 'allowAttributesOf'
144
+ ];
145
+ const definitions = this._definitions.filter(definition => definition.model == modelName);
146
+ for (const { modelSchema } of definitions) {
147
+ if (!modelSchema) {
148
+ continue;
149
+ }
150
+ for (const property of inheritProperties) {
151
+ for (const referenceName of toArray(modelSchema[property] || [])) {
152
+ const definitions = this._definitions.filter(definition => definition.model == referenceName);
153
+ for (const definition of definitions) {
154
+ if (referenceName !== modelName) {
155
+ yield* this._getReferences(definition.model);
156
+ yield definition;
157
+ }
158
+ }
159
+ }
160
+ }
161
+ }
162
+ }
163
+ /**
164
+ * Updates schema definition with new properties.
165
+ *
166
+ * Creates new scheme if it doesn't exist.
167
+ * Array properties are concatenated with original values.
168
+ *
169
+ * @param definition Definition update.
170
+ */
171
+ _extendDefinition(definition) {
172
+ const currentDefinitions = Array.from(this._definitions.entries())
173
+ .filter(([, currentDefinition]) => currentDefinition.model == definition.model);
174
+ if (currentDefinitions.length == 0) {
175
+ this._definitions.push(definition);
176
+ return;
177
+ }
178
+ for (const [idx, currentDefinition] of currentDefinitions) {
179
+ this._definitions[idx] = mergeWith({}, currentDefinition, definition, (target, source) => {
180
+ return Array.isArray(target) ? target.concat(source) : undefined;
181
+ });
182
+ }
183
+ }
184
+ }
185
+ /**
186
+ * Test view name against the given pattern.
187
+ */
188
+ function testViewName(pattern, viewName) {
189
+ if (typeof pattern === 'string') {
190
+ return pattern === viewName;
191
+ }
192
+ if (pattern instanceof RegExp) {
193
+ return pattern.test(viewName);
194
+ }
195
+ return false;
196
+ }
package/src/fullpage.d.ts CHANGED
@@ -1,21 +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
- }
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
+ }
package/src/fullpage.js CHANGED
@@ -1,80 +1,80 @@
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
- import { UpcastWriter } from 'ckeditor5/src/engine';
10
- import HtmlPageDataProcessor from './htmlpagedataprocessor';
11
- /**
12
- * The full page editing feature. It preserves the whole HTML page in the editor data.
13
- */
14
- export default class FullPage extends Plugin {
15
- /**
16
- * @inheritDoc
17
- */
18
- static get pluginName() {
19
- return 'FullPage';
20
- }
21
- /**
22
- * @inheritDoc
23
- */
24
- init() {
25
- const editor = this.editor;
26
- const properties = ['$fullPageDocument', '$fullPageDocType', '$fullPageXmlDeclaration'];
27
- editor.data.processor = new HtmlPageDataProcessor(editor.data.viewDocument);
28
- editor.model.schema.extend('$root', {
29
- allowAttributes: properties
30
- });
31
- // Apply custom properties from view document fragment to the model root attributes.
32
- editor.data.on('toModel', (evt, [viewElementOrFragment]) => {
33
- const root = editor.model.document.getRoot();
34
- editor.model.change(writer => {
35
- for (const name of properties) {
36
- const value = viewElementOrFragment.getCustomProperty(name);
37
- if (value) {
38
- writer.setAttribute(name, value, root);
39
- }
40
- }
41
- });
42
- }, { priority: 'low' });
43
- // Apply root attributes to the view document fragment.
44
- editor.data.on('toView', (evt, [modelElementOrFragment]) => {
45
- if (!modelElementOrFragment.is('rootElement')) {
46
- return;
47
- }
48
- const root = modelElementOrFragment;
49
- const viewFragment = evt.return;
50
- if (!root.hasAttribute('$fullPageDocument')) {
51
- return;
52
- }
53
- const writer = new UpcastWriter(viewFragment.document);
54
- for (const name of properties) {
55
- const value = root.getAttribute(name);
56
- if (value) {
57
- writer.setCustomProperty(name, value, viewFragment);
58
- }
59
- }
60
- }, { priority: 'low' });
61
- // Clear root attributes related to full page editing on editor content reset.
62
- editor.data.on('set', () => {
63
- const root = editor.model.document.getRoot();
64
- editor.model.change(writer => {
65
- for (const name of properties) {
66
- if (root.hasAttribute(name)) {
67
- writer.removeAttribute(name, root);
68
- }
69
- }
70
- });
71
- }, { priority: 'high' });
72
- // Make sure that document is returned even if there is no content in the page body.
73
- editor.data.on('get', (evt, args) => {
74
- if (!args[0]) {
75
- args[0] = {};
76
- }
77
- args[0].trim = false;
78
- }, { priority: 'high' });
79
- }
80
- }
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
+ import { UpcastWriter } from 'ckeditor5/src/engine';
10
+ import HtmlPageDataProcessor from './htmlpagedataprocessor';
11
+ /**
12
+ * The full page editing feature. It preserves the whole HTML page in the editor data.
13
+ */
14
+ export default class FullPage extends Plugin {
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ static get pluginName() {
19
+ return 'FullPage';
20
+ }
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ init() {
25
+ const editor = this.editor;
26
+ const properties = ['$fullPageDocument', '$fullPageDocType', '$fullPageXmlDeclaration'];
27
+ editor.data.processor = new HtmlPageDataProcessor(editor.data.viewDocument);
28
+ editor.model.schema.extend('$root', {
29
+ allowAttributes: properties
30
+ });
31
+ // Apply custom properties from view document fragment to the model root attributes.
32
+ editor.data.on('toModel', (evt, [viewElementOrFragment]) => {
33
+ const root = editor.model.document.getRoot();
34
+ editor.model.change(writer => {
35
+ for (const name of properties) {
36
+ const value = viewElementOrFragment.getCustomProperty(name);
37
+ if (value) {
38
+ writer.setAttribute(name, value, root);
39
+ }
40
+ }
41
+ });
42
+ }, { priority: 'low' });
43
+ // Apply root attributes to the view document fragment.
44
+ editor.data.on('toView', (evt, [modelElementOrFragment]) => {
45
+ if (!modelElementOrFragment.is('rootElement')) {
46
+ return;
47
+ }
48
+ const root = modelElementOrFragment;
49
+ const viewFragment = evt.return;
50
+ if (!root.hasAttribute('$fullPageDocument')) {
51
+ return;
52
+ }
53
+ const writer = new UpcastWriter(viewFragment.document);
54
+ for (const name of properties) {
55
+ const value = root.getAttribute(name);
56
+ if (value) {
57
+ writer.setCustomProperty(name, value, viewFragment);
58
+ }
59
+ }
60
+ }, { priority: 'low' });
61
+ // Clear root attributes related to full page editing on editor content reset.
62
+ editor.data.on('set', () => {
63
+ const root = editor.model.document.getRoot();
64
+ editor.model.change(writer => {
65
+ for (const name of properties) {
66
+ if (root.hasAttribute(name)) {
67
+ writer.removeAttribute(name, root);
68
+ }
69
+ }
70
+ });
71
+ }, { priority: 'high' });
72
+ // Make sure that document is returned even if there is no content in the page body.
73
+ editor.data.on('get', (evt, args) => {
74
+ if (!args[0]) {
75
+ args[0] = {};
76
+ }
77
+ args[0].trim = false;
78
+ }, { priority: 'high' });
79
+ }
80
+ }