@ckeditor/ckeditor5-widget 48.2.0-alpha.7 → 48.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/dist/utils.d.ts CHANGED
@@ -1,216 +1,216 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- import { Rect, type GetCallback } from '@ckeditor/ckeditor5-utils';
6
- import { type DowncastHighlightDescriptor, type MapperViewToModelPositionEvent, type ModelDocumentSelection, type ViewDowncastWriter, type Model, type ModelRange, type ModelSelection, type ViewEditableElement, type ViewElement, type ViewTypeCheckable } from '@ckeditor/ckeditor5-engine';
2
+ * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
+ */
5
+ import { Rect, type GetCallback } from "@ckeditor/ckeditor5-utils";
6
+ import { type DowncastHighlightDescriptor, type MapperViewToModelPositionEvent, type ModelDocumentSelection, type ViewDowncastWriter, type Model, type ModelRange, type ModelSelection, type ViewEditableElement, type ViewElement, type ViewTypeCheckable } from "@ckeditor/ckeditor5-engine";
7
7
  /**
8
- * CSS class added to each widget element.
9
- */
8
+ * CSS class added to each widget element.
9
+ */
10
10
  export declare const WIDGET_CLASS_NAME = "ck-widget";
11
11
  /**
12
- * CSS class added to currently selected widget element.
13
- */
12
+ * CSS class added to currently selected widget element.
13
+ */
14
14
  export declare const WIDGET_SELECTED_CLASS_NAME = "ck-widget_selected";
15
15
  /**
16
- * Returns `true` if given {@link module:engine/view/node~ViewNode} is an {@link module:engine/view/element~ViewElement} and a widget.
17
- */
16
+ * Returns `true` if given {@link module:engine/view/node~ViewNode} is an {@link module:engine/view/element~ViewElement} and a widget.
17
+ */
18
18
  export declare function isWidget(node: ViewTypeCheckable): boolean;
19
19
  /**
20
- * Converts the given {@link module:engine/view/element~ViewElement} to a widget in the following way:
21
- *
22
- * * sets the `contenteditable` attribute to `"false"`,
23
- * * adds the `ck-widget` CSS class,
24
- * * adds a custom {@link module:engine/view/element~ViewElement#getFillerOffset `getFillerOffset()`} method returning `null`,
25
- * * adds a custom property allowing to recognize widget elements by using {@link ~isWidget `isWidget()`},
26
- * * implements the {@link ~setHighlightHandling view highlight on widgets}.
27
- *
28
- * This function needs to be used in conjunction with
29
- * {@link module:engine/conversion/downcasthelpers~DowncastHelpers downcast conversion helpers}
30
- * like {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToElement `elementToElement()`}.
31
- * Moreover, typically you will want to use `toWidget()` only for `editingDowncast`, while keeping the `dataDowncast` clean.
32
- *
33
- * For example, in order to convert a `<widget>` model element to `<div class="widget">` in the view, you can define
34
- * such converters:
35
- *
36
- * ```ts
37
- * editor.conversion.for( 'editingDowncast' )
38
- * .elementToElement( {
39
- * model: 'widget',
40
- * view: ( modelItem, { writer } ) => {
41
- * const div = writer.createContainerElement( 'div', { class: 'widget' } );
42
- *
43
- * return toWidget( div, writer, { label: 'some widget' } );
44
- * }
45
- * } );
46
- *
47
- * editor.conversion.for( 'dataDowncast' )
48
- * .elementToElement( {
49
- * model: 'widget',
50
- * view: ( modelItem, { writer } ) => {
51
- * return writer.createContainerElement( 'div', { class: 'widget' } );
52
- * }
53
- * } );
54
- * ```
55
- *
56
- * See the full source code of the widget (with a nested editable) schema definition and converters in
57
- * [this sample](https://github.com/ckeditor/ckeditor5-widget/blob/master/tests/manual/widget-with-nestededitable.js).
58
- *
59
- * @param options Additional options.
60
- * @param options.label Element's label provided to the {@link ~setLabel} function. It can be passed as
61
- * a plain string or a function returning a string. It represents the widget for assistive technologies (like screen readers).
62
- * @param options.hasSelectionHandle If `true`, the widget will have a selection handle added.
63
- * @returns Returns the same element.
64
- */
20
+ * Converts the given {@link module:engine/view/element~ViewElement} to a widget in the following way:
21
+ *
22
+ * * sets the `contenteditable` attribute to `"false"`,
23
+ * * adds the `ck-widget` CSS class,
24
+ * * adds a custom {@link module:engine/view/element~ViewElement#getFillerOffset `getFillerOffset()`} method returning `null`,
25
+ * * adds a custom property allowing to recognize widget elements by using {@link ~isWidget `isWidget()`},
26
+ * * implements the {@link ~setHighlightHandling view highlight on widgets}.
27
+ *
28
+ * This function needs to be used in conjunction with
29
+ * {@link module:engine/conversion/downcasthelpers~DowncastHelpers downcast conversion helpers}
30
+ * like {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToElement `elementToElement()`}.
31
+ * Moreover, typically you will want to use `toWidget()` only for `editingDowncast`, while keeping the `dataDowncast` clean.
32
+ *
33
+ * For example, in order to convert a `<widget>` model element to `<div class="widget">` in the view, you can define
34
+ * such converters:
35
+ *
36
+ * ```ts
37
+ * editor.conversion.for( 'editingDowncast' )
38
+ * .elementToElement( {
39
+ * model: 'widget',
40
+ * view: ( modelItem, { writer } ) => {
41
+ * const div = writer.createContainerElement( 'div', { class: 'widget' } );
42
+ *
43
+ * return toWidget( div, writer, { label: 'some widget' } );
44
+ * }
45
+ * } );
46
+ *
47
+ * editor.conversion.for( 'dataDowncast' )
48
+ * .elementToElement( {
49
+ * model: 'widget',
50
+ * view: ( modelItem, { writer } ) => {
51
+ * return writer.createContainerElement( 'div', { class: 'widget' } );
52
+ * }
53
+ * } );
54
+ * ```
55
+ *
56
+ * See the full source code of the widget (with a nested editable) schema definition and converters in
57
+ * [this sample](https://github.com/ckeditor/ckeditor5-widget/blob/master/tests/manual/widget-with-nestededitable.js).
58
+ *
59
+ * @param options Additional options.
60
+ * @param options.label Element's label provided to the {@link ~setLabel} function. It can be passed as
61
+ * a plain string or a function returning a string. It represents the widget for assistive technologies (like screen readers).
62
+ * @param options.hasSelectionHandle If `true`, the widget will have a selection handle added.
63
+ * @returns Returns the same element.
64
+ */
65
65
  export declare function toWidget(element: ViewElement, writer: ViewDowncastWriter, options?: {
66
- label?: string | (() => string);
67
- hasSelectionHandle?: boolean;
66
+ label?: string | (() => string);
67
+ hasSelectionHandle?: boolean;
68
68
  }): ViewElement;
69
69
  /**
70
- * Sets highlight handling methods. Uses {@link module:widget/highlightstack~WidgetHighlightStack} to
71
- * properly determine which highlight descriptor should be used at given time.
72
- */
70
+ * Sets highlight handling methods. Uses {@link module:widget/highlightstack~WidgetHighlightStack} to
71
+ * properly determine which highlight descriptor should be used at given time.
72
+ */
73
73
  export declare function setHighlightHandling(element: ViewElement, writer: ViewDowncastWriter, add?: (element: ViewElement, descriptor: DowncastHighlightDescriptor, writer: ViewDowncastWriter) => void, remove?: (element: ViewElement, descriptor: DowncastHighlightDescriptor, writer: ViewDowncastWriter) => void): void;
74
74
  /**
75
- * Sets label for given element.
76
- * It can be passed as a plain string or a function returning a string. Function will be called each time label is retrieved by
77
- * {@link ~getLabel `getLabel()`}.
78
- */
75
+ * Sets label for given element.
76
+ * It can be passed as a plain string or a function returning a string. Function will be called each time label is retrieved by
77
+ * {@link ~getLabel `getLabel()`}.
78
+ */
79
79
  export declare function setLabel(element: ViewElement, labelOrCreator: string | (() => string)): void;
80
80
  /**
81
- * Returns the label of the provided element.
82
- */
81
+ * Returns the label of the provided element.
82
+ */
83
83
  export declare function getLabel(element: ViewElement): string;
84
84
  /**
85
- * Adds functionality to the provided {@link module:engine/view/editableelement~ViewEditableElement} to act as a widget's editable:
86
- *
87
- * * sets the `contenteditable` attribute to `true` when
88
- * {@link module:engine/view/editableelement~ViewEditableElement#isReadOnly} is `false`,
89
- * otherwise sets it to `false`,
90
- * * adds the `ck-editor__editable` and `ck-editor__nested-editable` CSS classes,
91
- * * adds the `ck-editor__nested-editable_focused` CSS class when the editable is focused and removes it when it is blurred.
92
- * * implements the {@link ~setHighlightHandling view highlight on widget's editable}.
93
- * * sets the `role` attribute to `textbox` for accessibility purposes.
94
- *
95
- * Similarly to {@link ~toWidget `toWidget()`} this function should be used in `editingDowncast` only and it is usually
96
- * used together with {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToElement `elementToElement()`}.
97
- *
98
- * For example, in order to convert a `<nested>` model element to `<div class="nested">` in the view, you can define
99
- * such converters:
100
- *
101
- * ```ts
102
- * editor.conversion.for( 'editingDowncast' )
103
- * .elementToElement( {
104
- * model: 'nested',
105
- * view: ( modelItem, { writer } ) => {
106
- * const div = writer.createEditableElement( 'div', { class: 'nested' } );
107
- *
108
- * return toWidgetEditable( nested, writer, { label: 'label for editable' } );
109
- * }
110
- * } );
111
- *
112
- * editor.conversion.for( 'dataDowncast' )
113
- * .elementToElement( {
114
- * model: 'nested',
115
- * view: ( modelItem, { writer } ) => {
116
- * return writer.createContainerElement( 'div', { class: 'nested' } );
117
- * }
118
- * } );
119
- * ```
120
- *
121
- * See the full source code of the widget (with nested editable) schema definition and converters in
122
- * [this sample](https://github.com/ckeditor/ckeditor5-widget/blob/master/tests/manual/widget-with-nestededitable.js).
123
- *
124
- * @param options Additional options.
125
- * @param options.label Editable's label used by assistive technologies (e.g. screen readers).
126
- * @param options.withAriaRole Whether to add the role="textbox" attribute on the editable. Defaults to `true`.
127
- * @returns Returns the same element that was provided in the `editable` parameter
128
- */
85
+ * Adds functionality to the provided {@link module:engine/view/editableelement~ViewEditableElement} to act as a widget's editable:
86
+ *
87
+ * * sets the `contenteditable` attribute to `true` when
88
+ * {@link module:engine/view/editableelement~ViewEditableElement#isReadOnly} is `false`,
89
+ * otherwise sets it to `false`,
90
+ * * adds the `ck-editor__editable` and `ck-editor__nested-editable` CSS classes,
91
+ * * adds the `ck-editor__nested-editable_focused` CSS class when the editable is focused and removes it when it is blurred.
92
+ * * implements the {@link ~setHighlightHandling view highlight on widget's editable}.
93
+ * * sets the `role` attribute to `textbox` for accessibility purposes.
94
+ *
95
+ * Similarly to {@link ~toWidget `toWidget()`} this function should be used in `editingDowncast` only and it is usually
96
+ * used together with {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToElement `elementToElement()`}.
97
+ *
98
+ * For example, in order to convert a `<nested>` model element to `<div class="nested">` in the view, you can define
99
+ * such converters:
100
+ *
101
+ * ```ts
102
+ * editor.conversion.for( 'editingDowncast' )
103
+ * .elementToElement( {
104
+ * model: 'nested',
105
+ * view: ( modelItem, { writer } ) => {
106
+ * const div = writer.createEditableElement( 'div', { class: 'nested' } );
107
+ *
108
+ * return toWidgetEditable( nested, writer, { label: 'label for editable' } );
109
+ * }
110
+ * } );
111
+ *
112
+ * editor.conversion.for( 'dataDowncast' )
113
+ * .elementToElement( {
114
+ * model: 'nested',
115
+ * view: ( modelItem, { writer } ) => {
116
+ * return writer.createContainerElement( 'div', { class: 'nested' } );
117
+ * }
118
+ * } );
119
+ * ```
120
+ *
121
+ * See the full source code of the widget (with nested editable) schema definition and converters in
122
+ * [this sample](https://github.com/ckeditor/ckeditor5-widget/blob/master/tests/manual/widget-with-nestededitable.js).
123
+ *
124
+ * @param options Additional options.
125
+ * @param options.label Editable's label used by assistive technologies (e.g. screen readers).
126
+ * @param options.withAriaRole Whether to add the role="textbox" attribute on the editable. Defaults to `true`.
127
+ * @returns Returns the same element that was provided in the `editable` parameter
128
+ */
129
129
  export declare function toWidgetEditable(editable: ViewEditableElement, writer: ViewDowncastWriter, options?: {
130
- label?: string;
131
- withAriaRole?: boolean;
130
+ label?: string;
131
+ withAriaRole?: boolean;
132
132
  }): ViewEditableElement;
133
133
  /**
134
- * Returns a model range which is optimal (in terms of UX) for inserting a widget block.
135
- *
136
- * For instance, if a selection is in the middle of a paragraph, the collapsed range before this paragraph
137
- * will be returned so that it is not split. If the selection is at the end of a paragraph,
138
- * the collapsed range after this paragraph will be returned.
139
- *
140
- * Note: If the selection is placed in an empty block, the range in that block will be returned. If that range
141
- * is then passed to {@link module:engine/model/model~Model#insertContent}, the block will be fully replaced
142
- * by the inserted widget block.
143
- *
144
- * @param selection The selection based on which the insertion position should be calculated.
145
- * @param model Model instance.
146
- * @returns The optimal range.
147
- */
134
+ * Returns a model range which is optimal (in terms of UX) for inserting a widget block.
135
+ *
136
+ * For instance, if a selection is in the middle of a paragraph, the collapsed range before this paragraph
137
+ * will be returned so that it is not split. If the selection is at the end of a paragraph,
138
+ * the collapsed range after this paragraph will be returned.
139
+ *
140
+ * Note: If the selection is placed in an empty block, the range in that block will be returned. If that range
141
+ * is then passed to {@link module:engine/model/model~Model#insertContent}, the block will be fully replaced
142
+ * by the inserted widget block.
143
+ *
144
+ * @param selection The selection based on which the insertion position should be calculated.
145
+ * @param model Model instance.
146
+ * @returns The optimal range.
147
+ */
148
148
  export declare function findOptimalInsertionRange(selection: ModelSelection | ModelDocumentSelection, model: Model): ModelRange;
149
149
  /**
150
- * A util to be used in order to map view positions to correct model positions when implementing a widget
151
- * which renders non-empty view element for an empty model element.
152
- *
153
- * For example:
154
- *
155
- * ```
156
- * // Model:
157
- * <placeholder type="name"></placeholder>
158
- *
159
- * // View:
160
- * <span class="placeholder">name</span>
161
- * ```
162
- *
163
- * In such case, view positions inside `<span>` cannot be correctly mapped to the model (because the model element is empty).
164
- * To handle mapping positions inside `<span class="placeholder">` to the model use this util as follows:
165
- *
166
- * ```ts
167
- * editor.editing.mapper.on(
168
- * 'viewToModelPosition',
169
- * viewToModelPositionOutsideModelElement( model, viewElement => viewElement.hasClass( 'placeholder' ) )
170
- * );
171
- * ```
172
- *
173
- * The callback will try to map the view offset of selection to an expected model position.
174
- *
175
- * 1. When the position is at the end (or in the middle) of the inline widget:
176
- *
177
- * ```
178
- * // View:
179
- * <p>foo <span class="placeholder">name|</span> bar</p>
180
- *
181
- * // Model:
182
- * <paragraph>foo <placeholder type="name"></placeholder>| bar</paragraph>
183
- * ```
184
- *
185
- * 2. When the position is at the beginning of the inline widget:
186
- *
187
- * ```
188
- * // View:
189
- * <p>foo <span class="placeholder">|name</span> bar</p>
190
- *
191
- * // Model:
192
- * <paragraph>foo |<placeholder type="name"></placeholder> bar</paragraph>
193
- * ```
194
- *
195
- * @param model Model instance on which the callback operates.
196
- * @param viewElementMatcher Function that is passed a view element and should return `true` if the custom mapping
197
- * should be applied to the given view element.
198
- */
150
+ * A util to be used in order to map view positions to correct model positions when implementing a widget
151
+ * which renders non-empty view element for an empty model element.
152
+ *
153
+ * For example:
154
+ *
155
+ * ```
156
+ * // Model:
157
+ * <placeholder type="name"></placeholder>
158
+ *
159
+ * // View:
160
+ * <span class="placeholder">name</span>
161
+ * ```
162
+ *
163
+ * In such case, view positions inside `<span>` cannot be correctly mapped to the model (because the model element is empty).
164
+ * To handle mapping positions inside `<span class="placeholder">` to the model use this util as follows:
165
+ *
166
+ * ```ts
167
+ * editor.editing.mapper.on(
168
+ * 'viewToModelPosition',
169
+ * viewToModelPositionOutsideModelElement( model, viewElement => viewElement.hasClass( 'placeholder' ) )
170
+ * );
171
+ * ```
172
+ *
173
+ * The callback will try to map the view offset of selection to an expected model position.
174
+ *
175
+ * 1. When the position is at the end (or in the middle) of the inline widget:
176
+ *
177
+ * ```
178
+ * // View:
179
+ * <p>foo <span class="placeholder">name|</span> bar</p>
180
+ *
181
+ * // Model:
182
+ * <paragraph>foo <placeholder type="name"></placeholder>| bar</paragraph>
183
+ * ```
184
+ *
185
+ * 2. When the position is at the beginning of the inline widget:
186
+ *
187
+ * ```
188
+ * // View:
189
+ * <p>foo <span class="placeholder">|name</span> bar</p>
190
+ *
191
+ * // Model:
192
+ * <paragraph>foo |<placeholder type="name"></placeholder> bar</paragraph>
193
+ * ```
194
+ *
195
+ * @param model Model instance on which the callback operates.
196
+ * @param viewElementMatcher Function that is passed a view element and should return `true` if the custom mapping
197
+ * should be applied to the given view element.
198
+ */
199
199
  export declare function viewToModelPositionOutsideModelElement(model: Model, viewElementMatcher: (element: ViewElement) => boolean): GetCallback<MapperViewToModelPositionEvent>;
200
200
  /**
201
- * Starting from a DOM resize host element (an element that receives dimensions as a result of resizing),
202
- * this helper returns the width of the found ancestor element.
203
- *
204
- * * It searches up to 5 levels of ancestors only.
205
- *
206
- * @param domResizeHost Resize host DOM element that receives dimensions as a result of resizing.
207
- * @returns Width of ancestor element in pixels or 0 if no ancestor with a computed width has been found.
208
- */
201
+ * Starting from a DOM resize host element (an element that receives dimensions as a result of resizing),
202
+ * this helper returns the width of the found ancestor element.
203
+ *
204
+ * * It searches up to 5 levels of ancestors only.
205
+ *
206
+ * @param domResizeHost Resize host DOM element that receives dimensions as a result of resizing.
207
+ * @returns Width of ancestor element in pixels or 0 if no ancestor with a computed width has been found.
208
+ */
209
209
  export declare function calculateResizeHostAncestorWidth(domResizeHost: HTMLElement): number;
210
210
  /**
211
- * Calculates a relative width of a `domResizeHost` compared to its ancestor in percents.
212
- *
213
- * @param domResizeHost Resize host DOM element.
214
- * @returns Percentage value between 0 and 100.
215
- */
211
+ * Calculates a relative width of a `domResizeHost` compared to its ancestor in percents.
212
+ *
213
+ * @param domResizeHost Resize host DOM element.
214
+ * @returns Percentage value between 0 and 100.
215
+ */
216
216
  export declare function calculateResizeHostPercentageWidth(domResizeHost: HTMLElement, resizeHostRect?: Rect): number;
@@ -1,15 +1,15 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
2
+ * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
+ */
5
5
  /**
6
- * @module widget/verticalnavigation
7
- */
8
- import { type GetCallback } from '@ckeditor/ckeditor5-utils';
9
- import type { EditingController, ViewDocumentArrowKeyEvent } from '@ckeditor/ckeditor5-engine';
6
+ * @module widget/verticalnavigation
7
+ */
8
+ import { type GetCallback } from "@ckeditor/ckeditor5-utils";
9
+ import type { EditingController, ViewDocumentArrowKeyEvent } from "@ckeditor/ckeditor5-engine";
10
10
  /**
11
- * Returns 'keydown' handler for up/down arrow keys that modifies the caret movement if it's in a text line next to an object.
12
- *
13
- * @param editing The editing controller.
14
- */
11
+ * Returns 'keydown' handler for up/down arrow keys that modifies the caret movement if it's in a text line next to an object.
12
+ *
13
+ * @param editing The editing controller.
14
+ */
15
15
  export declare function verticalWidgetNavigationHandler(editing: EditingController): GetCallback<ViewDocumentArrowKeyEvent>;