@ckeditor/ckeditor5-html-support 41.1.0 → 41.3.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.
- package/build/html-support.js +1 -1
- package/dist/content-index.css +4 -0
- package/dist/editor-index.css +44 -0
- package/dist/index.css +63 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +4004 -0
- package/dist/index.js.map +1 -0
- package/dist/types/augmentation.d.ts +33 -0
- package/dist/types/converters.d.ts +60 -0
- package/dist/types/datafilter.d.ts +304 -0
- package/dist/types/dataschema.d.ts +183 -0
- package/dist/types/fullpage.d.ts +21 -0
- package/dist/types/generalhtmlsupport.d.ts +98 -0
- package/dist/types/generalhtmlsupportconfig.d.ts +77 -0
- package/dist/types/htmlcomment.d.ts +71 -0
- package/dist/types/htmlpagedataprocessor.d.ts +22 -0
- package/dist/types/index.d.ts +25 -0
- package/dist/types/integrations/codeblock.d.ts +23 -0
- package/dist/types/integrations/customelement.d.ts +27 -0
- package/dist/types/integrations/dualcontent.d.ts +45 -0
- package/dist/types/integrations/heading.d.ts +31 -0
- package/dist/types/integrations/image.d.ts +26 -0
- package/dist/types/integrations/integrationutils.d.ts +15 -0
- package/dist/types/integrations/list.d.ts +27 -0
- package/dist/types/integrations/mediaembed.d.ts +26 -0
- package/dist/types/integrations/script.d.ts +26 -0
- package/dist/types/integrations/style.d.ts +26 -0
- package/dist/types/integrations/table.d.ts +23 -0
- package/dist/types/schemadefinitions.d.ts +13 -0
- package/dist/types/utils.d.ts +72 -0
- package/lang/translations/he.po +1 -1
- package/package.json +3 -2
- package/src/datafilter.js +86 -86
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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 type { GeneralHtmlSupport, DataFilter, DataSchema, GeneralHtmlSupportConfig, CodeBlockElementSupport, CustomElementSupport, ListElementSupport, DualContentModelElementSupport, HeadingElementSupport, ImageElementSupport, MediaEmbedElementSupport, ScriptElementSupport, StyleElementSupport, TableElementSupport, HtmlComment, FullPage } from './index.js';
|
|
6
|
+
declare module '@ckeditor/ckeditor5-core' {
|
|
7
|
+
interface EditorConfig {
|
|
8
|
+
/**
|
|
9
|
+
* The configuration of the General HTML Support feature.
|
|
10
|
+
* Introduced by the {@link module:html-support/generalhtmlsupport~GeneralHtmlSupport} feature.
|
|
11
|
+
*
|
|
12
|
+
* Read more in {@link module:html-support/generalhtmlsupportconfig~GeneralHtmlSupportConfig}.
|
|
13
|
+
*/
|
|
14
|
+
htmlSupport?: GeneralHtmlSupportConfig;
|
|
15
|
+
}
|
|
16
|
+
interface PluginsMap {
|
|
17
|
+
[GeneralHtmlSupport.pluginName]: GeneralHtmlSupport;
|
|
18
|
+
[DataFilter.pluginName]: DataFilter;
|
|
19
|
+
[DataSchema.pluginName]: DataSchema;
|
|
20
|
+
[CodeBlockElementSupport.pluginName]: CodeBlockElementSupport;
|
|
21
|
+
[CustomElementSupport.pluginName]: CustomElementSupport;
|
|
22
|
+
[ListElementSupport.pluginName]: ListElementSupport;
|
|
23
|
+
[DualContentModelElementSupport.pluginName]: DualContentModelElementSupport;
|
|
24
|
+
[HeadingElementSupport.pluginName]: HeadingElementSupport;
|
|
25
|
+
[ImageElementSupport.pluginName]: ImageElementSupport;
|
|
26
|
+
[MediaEmbedElementSupport.pluginName]: MediaEmbedElementSupport;
|
|
27
|
+
[ScriptElementSupport.pluginName]: ScriptElementSupport;
|
|
28
|
+
[StyleElementSupport.pluginName]: StyleElementSupport;
|
|
29
|
+
[TableElementSupport.pluginName]: TableElementSupport;
|
|
30
|
+
[HtmlComment.pluginName]: HtmlComment;
|
|
31
|
+
[FullPage.pluginName]: FullPage;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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/converters
|
|
7
|
+
*/
|
|
8
|
+
import type { Editor } from 'ckeditor5/src/core.js';
|
|
9
|
+
import type { AttributeElement, DowncastConversionApi, DowncastDispatcher, DowncastWriter, Element, ElementCreatorFunction, UpcastConversionApi, UpcastDispatcher, ViewElement } from 'ckeditor5/src/engine.js';
|
|
10
|
+
import type DataFilter from './datafilter.js';
|
|
11
|
+
import type { DataSchemaBlockElementDefinition, DataSchemaDefinition, DataSchemaInlineElementDefinition } from './dataschema.js';
|
|
12
|
+
/**
|
|
13
|
+
* View-to-model conversion helper for object elements.
|
|
14
|
+
*
|
|
15
|
+
* Preserves object element content in `htmlContent` attribute.
|
|
16
|
+
*
|
|
17
|
+
* @returns Returns a conversion callback.
|
|
18
|
+
*/
|
|
19
|
+
export declare function viewToModelObjectConverter({ model: modelName }: DataSchemaDefinition): (viewElement: ViewElement, conversionApi: UpcastConversionApi) => Element;
|
|
20
|
+
/**
|
|
21
|
+
* Conversion helper converting an object element to an HTML object widget.
|
|
22
|
+
*
|
|
23
|
+
* @returns Returns a conversion callback.
|
|
24
|
+
*/
|
|
25
|
+
export declare function toObjectWidgetConverter(editor: Editor, { view: viewName, isInline }: DataSchemaInlineElementDefinition): ElementCreatorFunction;
|
|
26
|
+
/**
|
|
27
|
+
* Creates object view element from the given model element.
|
|
28
|
+
*/
|
|
29
|
+
export declare function createObjectView(viewName: string, modelElement: Element, writer: DowncastWriter): ViewElement;
|
|
30
|
+
/**
|
|
31
|
+
* View-to-attribute conversion helper preserving inline element attributes on `$text`.
|
|
32
|
+
*
|
|
33
|
+
* @returns Returns a conversion callback.
|
|
34
|
+
*/
|
|
35
|
+
export declare function viewToAttributeInlineConverter({ view: viewName, model: attributeKey, allowEmpty }: DataSchemaInlineElementDefinition, dataFilter: DataFilter): (dispatcher: UpcastDispatcher) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Conversion helper converting an empty inline model element to an HTML element or widget.
|
|
38
|
+
*/
|
|
39
|
+
export declare function emptyInlineModelElementToViewConverter({ model: attributeKey, view: viewName }: DataSchemaInlineElementDefinition, asWidget?: boolean): ElementCreatorFunction;
|
|
40
|
+
/**
|
|
41
|
+
* Attribute-to-view conversion helper applying attributes to view element preserved on `$text`.
|
|
42
|
+
*
|
|
43
|
+
* @returns Returns a conversion callback.
|
|
44
|
+
*/
|
|
45
|
+
export declare function attributeToViewInlineConverter({ priority, view: viewName }: DataSchemaInlineElementDefinition): (attributeValue: any, conversionApi: DowncastConversionApi) => AttributeElement | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* View-to-model conversion helper preserving allowed attributes on block element.
|
|
48
|
+
*
|
|
49
|
+
* All matched attributes will be preserved on `html*Attributes` attribute.
|
|
50
|
+
*
|
|
51
|
+
* @returns Returns a conversion callback.
|
|
52
|
+
*/
|
|
53
|
+
export declare function viewToModelBlockAttributeConverter({ view: viewName }: DataSchemaBlockElementDefinition, dataFilter: DataFilter): (dispatcher: UpcastDispatcher) => void;
|
|
54
|
+
/**
|
|
55
|
+
* Model-to-view conversion helper applying attributes preserved in `html*Attributes` attribute
|
|
56
|
+
* for block elements.
|
|
57
|
+
*
|
|
58
|
+
* @returns Returns a conversion callback.
|
|
59
|
+
*/
|
|
60
|
+
export declare function modelToViewBlockAttributeConverter({ view: viewName, model: modelName }: DataSchemaBlockElementDefinition): (dispatcher: DowncastDispatcher) => void;
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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/datafilter
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin, type Editor } from 'ckeditor5/src/core.js';
|
|
9
|
+
import { type MatcherPattern, type UpcastConversionApi, type ViewElement, type MatcherObjectPattern } from 'ckeditor5/src/engine.js';
|
|
10
|
+
import { Widget } from 'ckeditor5/src/widget.js';
|
|
11
|
+
import { default as DataSchema, type DataSchemaDefinition } from './dataschema.js';
|
|
12
|
+
import { type GHSViewAttributes } from './utils.js';
|
|
13
|
+
import '../theme/datafilter.css';
|
|
14
|
+
/**
|
|
15
|
+
* Allows to validate elements and element attributes registered by {@link module:html-support/dataschema~DataSchema}.
|
|
16
|
+
*
|
|
17
|
+
* To enable registered element in the editor, use {@link module:html-support/datafilter~DataFilter#allowElement} method:
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* dataFilter.allowElement( 'section' );
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* You can also allow or disallow specific element attributes:
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* // Allow `data-foo` attribute on `section` element.
|
|
27
|
+
* dataFilter.allowAttributes( {
|
|
28
|
+
* name: 'section',
|
|
29
|
+
* attributes: {
|
|
30
|
+
* 'data-foo': true
|
|
31
|
+
* }
|
|
32
|
+
* } );
|
|
33
|
+
*
|
|
34
|
+
* // Disallow `color` style attribute on 'section' element.
|
|
35
|
+
* dataFilter.disallowAttributes( {
|
|
36
|
+
* name: 'section',
|
|
37
|
+
* styles: {
|
|
38
|
+
* color: /[\s\S]+/
|
|
39
|
+
* }
|
|
40
|
+
* } );
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* To apply the information about allowed and disallowed attributes in custom integration plugin,
|
|
44
|
+
* use the {@link module:html-support/datafilter~DataFilter#processViewAttributes `processViewAttributes()`} method.
|
|
45
|
+
*/
|
|
46
|
+
export default class DataFilter extends Plugin {
|
|
47
|
+
/**
|
|
48
|
+
* An instance of the {@link module:html-support/dataschema~DataSchema}.
|
|
49
|
+
*/
|
|
50
|
+
private readonly _dataSchema;
|
|
51
|
+
/**
|
|
52
|
+
* {@link module:engine/view/matcher~Matcher Matcher} instance describing rules upon which
|
|
53
|
+
* content attributes should be allowed.
|
|
54
|
+
*/
|
|
55
|
+
private readonly _allowedAttributes;
|
|
56
|
+
/**
|
|
57
|
+
* {@link module:engine/view/matcher~Matcher Matcher} instance describing rules upon which
|
|
58
|
+
* content attributes should be disallowed.
|
|
59
|
+
*/
|
|
60
|
+
private readonly _disallowedAttributes;
|
|
61
|
+
/**
|
|
62
|
+
* Allowed element definitions by {@link module:html-support/datafilter~DataFilter#allowElement} method.
|
|
63
|
+
*/
|
|
64
|
+
private readonly _allowedElements;
|
|
65
|
+
/**
|
|
66
|
+
* Disallowed element names by {@link module:html-support/datafilter~DataFilter#disallowElement} method.
|
|
67
|
+
*/
|
|
68
|
+
private readonly _disallowedElements;
|
|
69
|
+
/**
|
|
70
|
+
* Indicates if {@link module:engine/controller/datacontroller~DataController editor's data controller}
|
|
71
|
+
* data has been already initialized.
|
|
72
|
+
*/
|
|
73
|
+
private _dataInitialized;
|
|
74
|
+
/**
|
|
75
|
+
* Cached map of coupled attributes. Keys are the feature attributes names
|
|
76
|
+
* and values are arrays with coupled GHS attributes names.
|
|
77
|
+
*/
|
|
78
|
+
private _coupledAttributes;
|
|
79
|
+
constructor(editor: Editor);
|
|
80
|
+
/**
|
|
81
|
+
* @inheritDoc
|
|
82
|
+
*/
|
|
83
|
+
static get pluginName(): "DataFilter";
|
|
84
|
+
/**
|
|
85
|
+
* @inheritDoc
|
|
86
|
+
*/
|
|
87
|
+
static get requires(): readonly [typeof DataSchema, typeof Widget];
|
|
88
|
+
/**
|
|
89
|
+
* Load a configuration of one or many elements, where their attributes should be allowed.
|
|
90
|
+
*
|
|
91
|
+
* **Note**: Rules will be applied just before next data pipeline data init or set.
|
|
92
|
+
*
|
|
93
|
+
* @param config Configuration of elements that should have their attributes accepted in the editor.
|
|
94
|
+
*/
|
|
95
|
+
loadAllowedConfig(config: Array<MatcherObjectPattern>): void;
|
|
96
|
+
/**
|
|
97
|
+
* Load a configuration of one or many elements, where their attributes should be disallowed.
|
|
98
|
+
*
|
|
99
|
+
* **Note**: Rules will be applied just before next data pipeline data init or set.
|
|
100
|
+
*
|
|
101
|
+
* @param config Configuration of elements that should have their attributes rejected from the editor.
|
|
102
|
+
*/
|
|
103
|
+
loadDisallowedConfig(config: Array<MatcherObjectPattern>): void;
|
|
104
|
+
/**
|
|
105
|
+
* Load a configuration of one or many elements, where when empty should be allowed.
|
|
106
|
+
*
|
|
107
|
+
* **Note**: It modifies DataSchema so must be loaded before registering filtering rules.
|
|
108
|
+
*
|
|
109
|
+
* @param config Configuration of elements that should be preserved even if empty.
|
|
110
|
+
*/
|
|
111
|
+
loadAllowedEmptyElementsConfig(config: Array<string>): void;
|
|
112
|
+
/**
|
|
113
|
+
* Allow the given element in the editor context.
|
|
114
|
+
*
|
|
115
|
+
* This method will only allow elements described by the {@link module:html-support/dataschema~DataSchema} used
|
|
116
|
+
* to create data filter.
|
|
117
|
+
*
|
|
118
|
+
* **Note**: Rules will be applied just before next data pipeline data init or set.
|
|
119
|
+
*
|
|
120
|
+
* @param viewName String or regular expression matching view name.
|
|
121
|
+
*/
|
|
122
|
+
allowElement(viewName: string | RegExp): void;
|
|
123
|
+
/**
|
|
124
|
+
* Disallow the given element in the editor context.
|
|
125
|
+
*
|
|
126
|
+
* This method will only disallow elements described by the {@link module:html-support/dataschema~DataSchema} used
|
|
127
|
+
* to create data filter.
|
|
128
|
+
*
|
|
129
|
+
* @param viewName String or regular expression matching view name.
|
|
130
|
+
*/
|
|
131
|
+
disallowElement(viewName: string | RegExp): void;
|
|
132
|
+
/**
|
|
133
|
+
* Allow the given empty element in the editor context.
|
|
134
|
+
*
|
|
135
|
+
* This method will only allow elements described by the {@link module:html-support/dataschema~DataSchema} used
|
|
136
|
+
* to create data filter.
|
|
137
|
+
*
|
|
138
|
+
* **Note**: It modifies DataSchema so must be called before registering filtering rules.
|
|
139
|
+
*
|
|
140
|
+
* @param viewName String or regular expression matching view name.
|
|
141
|
+
*/
|
|
142
|
+
allowEmptyElement(viewName: string): void;
|
|
143
|
+
/**
|
|
144
|
+
* Allow the given attributes for view element allowed by {@link #allowElement} method.
|
|
145
|
+
*
|
|
146
|
+
* @param config Pattern matching all attributes which should be allowed.
|
|
147
|
+
*/
|
|
148
|
+
allowAttributes(config: MatcherPattern): void;
|
|
149
|
+
/**
|
|
150
|
+
* Disallow the given attributes for view element allowed by {@link #allowElement} method.
|
|
151
|
+
*
|
|
152
|
+
* @param config Pattern matching all attributes which should be disallowed.
|
|
153
|
+
*/
|
|
154
|
+
disallowAttributes(config: MatcherPattern): void;
|
|
155
|
+
/**
|
|
156
|
+
* Processes all allowed and disallowed attributes on the view element by consuming them and returning the allowed ones.
|
|
157
|
+
*
|
|
158
|
+
* This method applies the configuration set up by {@link #allowAttributes `allowAttributes()`}
|
|
159
|
+
* and {@link #disallowAttributes `disallowAttributes()`} over the given view element by consuming relevant attributes.
|
|
160
|
+
* It returns the allowed attributes that were found on the given view element for further processing by integration code.
|
|
161
|
+
*
|
|
162
|
+
* ```ts
|
|
163
|
+
* dispatcher.on( 'element:myElement', ( evt, data, conversionApi ) => {
|
|
164
|
+
* // Get rid of disallowed and extract all allowed attributes from a viewElement.
|
|
165
|
+
* const viewAttributes = dataFilter.processViewAttributes( data.viewItem, conversionApi );
|
|
166
|
+
* // Do something with them, i.e. store inside a model as a dictionary.
|
|
167
|
+
* if ( viewAttributes ) {
|
|
168
|
+
* conversionApi.writer.setAttribute( 'htmlAttributesOfMyElement', viewAttributes, data.modelRange );
|
|
169
|
+
* }
|
|
170
|
+
* } );
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* @see module:engine/conversion/viewconsumable~ViewConsumable#consume
|
|
174
|
+
*
|
|
175
|
+
* @returns Object with following properties:
|
|
176
|
+
* - attributes Set with matched attribute names.
|
|
177
|
+
* - styles Set with matched style names.
|
|
178
|
+
* - classes Set with matched class names.
|
|
179
|
+
*/
|
|
180
|
+
processViewAttributes(viewElement: ViewElement, conversionApi: UpcastConversionApi): GHSViewAttributes | null;
|
|
181
|
+
/**
|
|
182
|
+
* Adds allowed element definition and fires registration event.
|
|
183
|
+
*/
|
|
184
|
+
private _addAllowedElement;
|
|
185
|
+
/**
|
|
186
|
+
* Registers elements allowed by {@link module:html-support/datafilter~DataFilter#allowElement} method
|
|
187
|
+
* once {@link module:engine/controller/datacontroller~DataController editor's data controller} is initialized.
|
|
188
|
+
*/
|
|
189
|
+
private _registerElementsAfterInit;
|
|
190
|
+
/**
|
|
191
|
+
* Registers default element handlers.
|
|
192
|
+
*/
|
|
193
|
+
private _registerElementHandlers;
|
|
194
|
+
/**
|
|
195
|
+
* Registers a model post-fixer that is removing coupled GHS attributes of inline elements. Those attributes
|
|
196
|
+
* are removed if a coupled feature attribute is removed.
|
|
197
|
+
*
|
|
198
|
+
* For example, consider following HTML:
|
|
199
|
+
*
|
|
200
|
+
* ```html
|
|
201
|
+
* <a href="foo.html" id="myId">bar</a>
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* Which would be upcasted to following text node in the model:
|
|
205
|
+
*
|
|
206
|
+
* ```html
|
|
207
|
+
* <$text linkHref="foo.html" htmlA="{ attributes: { id: 'myId' } }">bar</$text>
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* When the user removes the link from that text (using UI), only `linkHref` attribute would be removed:
|
|
211
|
+
*
|
|
212
|
+
* ```html
|
|
213
|
+
* <$text htmlA="{ attributes: { id: 'myId' } }">bar</$text>
|
|
214
|
+
* ```
|
|
215
|
+
*
|
|
216
|
+
* The `htmlA` attribute would stay in the model and would cause GHS to generate an `<a>` element.
|
|
217
|
+
* This is incorrect from UX point of view, as the user wanted to remove the whole link (not only `href`).
|
|
218
|
+
*/
|
|
219
|
+
private _registerCoupledAttributesPostFixer;
|
|
220
|
+
/**
|
|
221
|
+
* Removes `html*Attributes` attributes from incompatible elements.
|
|
222
|
+
*
|
|
223
|
+
* For example, consider the following HTML:
|
|
224
|
+
*
|
|
225
|
+
* ```html
|
|
226
|
+
* <heading2 htmlH2Attributes="...">foobar[]</heading2>
|
|
227
|
+
* ```
|
|
228
|
+
*
|
|
229
|
+
* Pressing `enter` creates a new `paragraph` element that inherits
|
|
230
|
+
* the `htmlH2Attributes` attribute from `heading2`.
|
|
231
|
+
*
|
|
232
|
+
* ```html
|
|
233
|
+
* <heading2 htmlH2Attributes="...">foobar</heading2>
|
|
234
|
+
* <paragraph htmlH2Attributes="...">[]</paragraph>
|
|
235
|
+
* ```
|
|
236
|
+
*
|
|
237
|
+
* This postfixer ensures that this doesn't happen, and that elements can
|
|
238
|
+
* only have `html*Attributes` associated with them,
|
|
239
|
+
* e.g.: `htmlPAttributes` for `<p>`, `htmlDivAttributes` for `<div>`, etc.
|
|
240
|
+
*
|
|
241
|
+
* With it enabled, pressing `enter` at the end of `<heading2>` will create
|
|
242
|
+
* a new paragraph without the `htmlH2Attributes` attribute.
|
|
243
|
+
*
|
|
244
|
+
* ```html
|
|
245
|
+
* <heading2 htmlH2Attributes="...">foobar</heading2>
|
|
246
|
+
* <paragraph>[]</paragraph>
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
private _registerAssociatedHtmlAttributesPostFixer;
|
|
250
|
+
/**
|
|
251
|
+
* Collects the map of coupled attributes. The returned map is keyed by the feature attribute name
|
|
252
|
+
* and coupled GHS attribute names are stored in the value array.
|
|
253
|
+
*/
|
|
254
|
+
private _getCoupledAttributesMap;
|
|
255
|
+
/**
|
|
256
|
+
* Fires `register` event for the given element definition.
|
|
257
|
+
*/
|
|
258
|
+
private _fireRegisterEvent;
|
|
259
|
+
/**
|
|
260
|
+
* Registers object element and attribute converters for the given data schema definition.
|
|
261
|
+
*/
|
|
262
|
+
private _registerObjectElement;
|
|
263
|
+
/**
|
|
264
|
+
* Registers block element and attribute converters for the given data schema definition.
|
|
265
|
+
*/
|
|
266
|
+
private _registerBlockElement;
|
|
267
|
+
/**
|
|
268
|
+
* Registers inline element and attribute converters for the given data schema definition.
|
|
269
|
+
*
|
|
270
|
+
* Extends `$text` model schema to allow the given definition model attribute and its properties.
|
|
271
|
+
*/
|
|
272
|
+
private _registerInlineElement;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Fired when {@link module:html-support/datafilter~DataFilter} is registering element and attribute
|
|
276
|
+
* converters for the {@link module:html-support/dataschema~DataSchemaDefinition element definition}.
|
|
277
|
+
*
|
|
278
|
+
* The event also accepts {@link module:html-support/dataschema~DataSchemaDefinition#view} value
|
|
279
|
+
* as an event namespace, e.g. `register:span`.
|
|
280
|
+
*
|
|
281
|
+
* ```ts
|
|
282
|
+
* dataFilter.on( 'register', ( evt, definition ) => {
|
|
283
|
+
* editor.model.schema.register( definition.model, definition.modelSchema );
|
|
284
|
+
* editor.conversion.elementToElement( { model: definition.model, view: definition.view } );
|
|
285
|
+
*
|
|
286
|
+
* evt.stop();
|
|
287
|
+
* } );
|
|
288
|
+
*
|
|
289
|
+
* dataFilter.on( 'register:span', ( evt, definition ) => {
|
|
290
|
+
* editor.model.schema.extend( '$text', { allowAttributes: 'htmlSpan' } );
|
|
291
|
+
*
|
|
292
|
+
* editor.conversion.for( 'upcast' ).elementToAttribute( { view: 'span', model: 'htmlSpan' } );
|
|
293
|
+
* editor.conversion.for( 'downcast' ).attributeToElement( { view: 'span', model: 'htmlSpan' } );
|
|
294
|
+
*
|
|
295
|
+
* evt.stop();
|
|
296
|
+
* }, { priority: 'high' } )
|
|
297
|
+
* ```
|
|
298
|
+
*
|
|
299
|
+
* @eventName ~DataFilter#register
|
|
300
|
+
*/
|
|
301
|
+
export interface DataFilterRegisterEvent {
|
|
302
|
+
name: 'register' | `register:${string}`;
|
|
303
|
+
args: [data: DataSchemaDefinition];
|
|
304
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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.js';
|
|
9
|
+
import type { AttributeProperties, SchemaItemDefinition } from 'ckeditor5/src/engine.js';
|
|
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
|
+
/**
|
|
48
|
+
* @inheritDoc
|
|
49
|
+
*/
|
|
50
|
+
static get pluginName(): "DataSchema";
|
|
51
|
+
/**
|
|
52
|
+
* @inheritDoc
|
|
53
|
+
*/
|
|
54
|
+
init(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Add new data schema definition describing block element.
|
|
57
|
+
*/
|
|
58
|
+
registerBlockElement(definition: DataSchemaBlockElementDefinition): void;
|
|
59
|
+
/**
|
|
60
|
+
* Add new data schema definition describing inline element.
|
|
61
|
+
*/
|
|
62
|
+
registerInlineElement(definition: DataSchemaInlineElementDefinition): void;
|
|
63
|
+
/**
|
|
64
|
+
* Updates schema definition describing block element with new properties.
|
|
65
|
+
*
|
|
66
|
+
* Creates new scheme if it doesn't exist.
|
|
67
|
+
* Array properties are concatenated with original values.
|
|
68
|
+
*
|
|
69
|
+
* @param definition Definition update.
|
|
70
|
+
*/
|
|
71
|
+
extendBlockElement(definition: DataSchemaBlockElementDefinition): void;
|
|
72
|
+
/**
|
|
73
|
+
* Updates schema definition describing inline element with new properties.
|
|
74
|
+
*
|
|
75
|
+
* Creates new scheme if it doesn't exist.
|
|
76
|
+
* Array properties are concatenated with original values.
|
|
77
|
+
*
|
|
78
|
+
* @param definition Definition update.
|
|
79
|
+
*/
|
|
80
|
+
extendInlineElement(definition: DataSchemaInlineElementDefinition): void;
|
|
81
|
+
/**
|
|
82
|
+
* Returns all definitions matching the given view name.
|
|
83
|
+
*
|
|
84
|
+
* @param includeReferences Indicates if this method should also include definitions of referenced models.
|
|
85
|
+
*/
|
|
86
|
+
getDefinitionsForView(viewName: string | RegExp, includeReferences?: boolean): Set<DataSchemaDefinition>;
|
|
87
|
+
/**
|
|
88
|
+
* Returns definitions matching the given model name.
|
|
89
|
+
*/
|
|
90
|
+
getDefinitionsForModel(modelName: string): Array<DataSchemaDefinition>;
|
|
91
|
+
/**
|
|
92
|
+
* Returns definitions matching the given view name.
|
|
93
|
+
*/
|
|
94
|
+
private _getMatchingViewDefinitions;
|
|
95
|
+
/**
|
|
96
|
+
* Resolves all definition references registered for the given data schema definition.
|
|
97
|
+
*
|
|
98
|
+
* @param modelName Data schema model name.
|
|
99
|
+
*/
|
|
100
|
+
private _getReferences;
|
|
101
|
+
/**
|
|
102
|
+
* Updates schema definition with new properties.
|
|
103
|
+
*
|
|
104
|
+
* Creates new scheme if it doesn't exist.
|
|
105
|
+
* Array properties are concatenated with original values.
|
|
106
|
+
*
|
|
107
|
+
* @param definition Definition update.
|
|
108
|
+
*/
|
|
109
|
+
private _extendDefinition;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* A base definition of {@link module:html-support/dataschema~DataSchema data schema}.
|
|
113
|
+
*/
|
|
114
|
+
export interface DataSchemaDefinition {
|
|
115
|
+
/**
|
|
116
|
+
* Name of the model.
|
|
117
|
+
*/
|
|
118
|
+
model: string;
|
|
119
|
+
/**
|
|
120
|
+
* Name of the view element.
|
|
121
|
+
*/
|
|
122
|
+
view?: string;
|
|
123
|
+
/**
|
|
124
|
+
* Indicates that the definition describes object element.
|
|
125
|
+
*/
|
|
126
|
+
isObject?: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* The model schema item definition describing registered model.
|
|
129
|
+
*/
|
|
130
|
+
modelSchema?: SchemaItemDefinition;
|
|
131
|
+
/**
|
|
132
|
+
* Indicates that the definition describes block element.
|
|
133
|
+
* Set by {@link module:html-support/dataschema~DataSchema#registerBlockElement} method.
|
|
134
|
+
*/
|
|
135
|
+
isBlock?: boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Indicates that the definition describes inline element.
|
|
138
|
+
*/
|
|
139
|
+
isInline?: boolean;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* A definition of {@link module:html-support/dataschema~DataSchema data schema} for block elements.
|
|
143
|
+
*/
|
|
144
|
+
export interface DataSchemaBlockElementDefinition extends DataSchemaDefinition {
|
|
145
|
+
/**
|
|
146
|
+
* Should be used when an element can behave both as a sectioning element (e.g. article) and
|
|
147
|
+
* element accepting only inline content (e.g. paragraph).
|
|
148
|
+
* If an element contains only inline content, this option will be used as a model name.
|
|
149
|
+
*/
|
|
150
|
+
paragraphLikeModel?: string;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* A definition of {@link module:html-support/dataschema~DataSchema data schema} for inline elements.
|
|
154
|
+
*/
|
|
155
|
+
export interface DataSchemaInlineElementDefinition extends DataSchemaDefinition {
|
|
156
|
+
/**
|
|
157
|
+
* Additional metadata describing the model attribute.
|
|
158
|
+
*/
|
|
159
|
+
attributeProperties?: AttributeProperties;
|
|
160
|
+
/**
|
|
161
|
+
* Element priority. Decides in what order elements are wrapped by
|
|
162
|
+
* {@link module:engine/view/downcastwriter~DowncastWriter}.
|
|
163
|
+
* Set by {@link module:html-support/dataschema~DataSchema#registerInlineElement} method.
|
|
164
|
+
*/
|
|
165
|
+
priority?: number;
|
|
166
|
+
/**
|
|
167
|
+
* The name of the model attribute that generates the same view element. GHS inline attribute
|
|
168
|
+
* will be removed from the model tree as soon as the coupled attribute is removed. See
|
|
169
|
+
* {@link module:html-support/datafilter~DataFilter#_registerCoupledAttributesPostFixer GHS post-fixer} for more details.
|
|
170
|
+
*/
|
|
171
|
+
coupledAttribute?: string;
|
|
172
|
+
/**
|
|
173
|
+
* Indicates that element should not be converted as a model text attribute.
|
|
174
|
+
* It is used to map view elements that do not have a separate model element but their data is stored in a model attribute.
|
|
175
|
+
* For example `<tbody>` element does not have a dedicated model element and GHS stores attributes of `<tbody>`
|
|
176
|
+
* in the `htmlTbodyAttributes` model attribute of the `table` model element.
|
|
177
|
+
*/
|
|
178
|
+
appliesToBlock?: boolean | string;
|
|
179
|
+
/**
|
|
180
|
+
* Indicates that an element should be preserved even if it has no content.
|
|
181
|
+
*/
|
|
182
|
+
allowEmpty?: boolean;
|
|
183
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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.js';
|
|
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
|
+
}
|