@ckeditor/ckeditor5-widget 48.2.0 → 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/widget.d.ts CHANGED
@@ -1,118 +1,118 @@
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/widget
7
- */
8
- import { Plugin } from '@ckeditor/ckeditor5-core';
9
- import { type ModelElement, type ModelNode, type ViewPosition, type ModelRange } from '@ckeditor/ckeditor5-engine';
10
- import { Delete } from '@ckeditor/ckeditor5-typing';
11
- import { WidgetTypeAround } from './widgettypearound/widgettypearound.js';
12
- import '../theme/widget.css';
6
+ * @module widget/widget
7
+ */
8
+ import { Plugin, type PluginDependenciesOf } from "@ckeditor/ckeditor5-core";
9
+ import { type ModelElement, type ModelNode, type ViewPosition, type ModelRange } from "@ckeditor/ckeditor5-engine";
10
+ import { Delete } from "@ckeditor/ckeditor5-typing";
11
+ import { WidgetTypeAround } from "./widgettypearound/widgettypearound.js";
12
+ import "../theme/widget.css";
13
13
  /**
14
- * The widget plugin. It enables base support for widgets.
15
- *
16
- * See {@glink api/widget package page} for more details and documentation.
17
- *
18
- * This plugin enables multiple behaviors required by widgets:
19
- *
20
- * * The model to view selection converter for the editing pipeline (it handles widget custom selection rendering).
21
- * If a converted selection wraps around a widget element, that selection is marked as
22
- * {@link module:engine/view/selection~ViewSelection#isFake fake}. Additionally, the `ck-widget_selected` CSS class
23
- * is added to indicate that widget has been selected.
24
- * * The mouse and keyboard events handling on and around widget elements.
25
- */
14
+ * The widget plugin. It enables base support for widgets.
15
+ *
16
+ * See {@glink api/widget package page} for more details and documentation.
17
+ *
18
+ * This plugin enables multiple behaviors required by widgets:
19
+ *
20
+ * * The model to view selection converter for the editing pipeline (it handles widget custom selection rendering).
21
+ * If a converted selection wraps around a widget element, that selection is marked as
22
+ * {@link module:engine/view/selection~ViewSelection#isFake fake}. Additionally, the `ck-widget_selected` CSS class
23
+ * is added to indicate that widget has been selected.
24
+ * * The mouse and keyboard events handling on and around widget elements.
25
+ */
26
26
  export declare class Widget extends Plugin {
27
- /**
28
- * Holds previously selected widgets.
29
- */
30
- private _previouslySelected;
31
- /**
32
- * @inheritDoc
33
- */
34
- static get pluginName(): "Widget";
35
- /**
36
- * @inheritDoc
37
- */
38
- static get isOfficialPlugin(): true;
39
- /**
40
- * @inheritDoc
41
- */
42
- static get requires(): readonly [typeof WidgetTypeAround, typeof Delete];
43
- /**
44
- * @inheritDoc
45
- */
46
- init(): void;
47
- /**
48
- * Handles {@link module:engine/view/document~ViewDocument#event:mousedown mousedown} events on widget elements.
49
- */
50
- private _onMousedown;
51
- /**
52
- * Handles {@link module:engine/view/document~ViewDocument#event:pointerdown pointerdown} events on widget elements.
53
- */
54
- private _onPointerdown;
55
- /**
56
- * Selects entire block content, e.g. on triple click it selects entire paragraph.
57
- */
58
- private _selectBlockContent;
59
- /**
60
- * Handles {@link module:engine/view/document~ViewDocument#event:keydown keydown} events and changes
61
- * the model selection when:
62
- *
63
- * * arrow key is pressed when the widget is selected,
64
- * * the selection is next to a widget and the widget should become selected upon the arrow key press.
65
- *
66
- * See {@link #_preventDefaultOnArrowKeyPress}.
67
- */
68
- private _handleSelectionChangeOnArrowKeyPress;
69
- /**
70
- * Handles {@link module:engine/view/document~ViewDocument#event:keydown keydown} events and prevents
71
- * the default browser behavior to make sure the fake selection is not being moved from a fake selection
72
- * container.
73
- *
74
- * See {@link #_handleSelectionChangeOnArrowKeyPress}.
75
- */
76
- private _preventDefaultOnArrowKeyPress;
77
- /**
78
- * Handles delete keys: backspace and delete.
79
- *
80
- * @param isForward Set to true if delete was performed in forward direction.
81
- * @returns Returns `true` if keys were handled correctly.
82
- */
83
- private _handleDelete;
84
- /**
85
- * Sets {@link module:engine/model/selection~ModelSelection document's selection} over given element.
86
- *
87
- * @internal
88
- */
89
- _setSelectionOverElement(element: ModelNode): void;
90
- /**
91
- * Checks if {@link module:engine/model/element~ModelElement element} placed next to the current
92
- * {@link module:engine/model/selection~ModelSelection model selection} exists and is marked in
93
- * {@link module:engine/model/schema~ModelSchema schema} as `object`.
94
- *
95
- * @internal
96
- * @param forward Direction of checking.
97
- */
98
- _getObjectElementNextToSelection(forward: boolean): ModelElement | null;
99
- /**
100
- * Removes CSS class from previously selected widgets.
101
- */
102
- private _clearPreviouslySelectedWidgets;
103
- /**
104
- * Moves the document selection into the next editable or block widget.
105
- */
106
- private _selectNextEditable;
107
- /**
108
- * Looks for next focus point in the document starting from the given view position and direction.
109
- * The focus point is either a block widget or an editable.
110
- *
111
- * @internal
112
- */
113
- _findNextFocusRange(startPosition: ViewPosition, direction: 'backward' | 'forward'): ModelRange | null;
114
- /**
115
- * Updates the document selection so that it selects first ancestor widget.
116
- */
117
- private _selectAncestorWidget;
27
+ /**
28
+ * Holds previously selected widgets.
29
+ */
30
+ private _previouslySelected;
31
+ /**
32
+ * @inheritDoc
33
+ */
34
+ static get pluginName(): "Widget";
35
+ /**
36
+ * @inheritDoc
37
+ */
38
+ static override get isOfficialPlugin(): true;
39
+ /**
40
+ * @inheritDoc
41
+ */
42
+ static get requires(): PluginDependenciesOf<[WidgetTypeAround, Delete]>;
43
+ /**
44
+ * @inheritDoc
45
+ */
46
+ init(): void;
47
+ /**
48
+ * Handles {@link module:engine/view/document~ViewDocument#event:mousedown mousedown} events on widget elements.
49
+ */
50
+ private _onMousedown;
51
+ /**
52
+ * Handles {@link module:engine/view/document~ViewDocument#event:pointerdown pointerdown} events on widget elements.
53
+ */
54
+ private _onPointerdown;
55
+ /**
56
+ * Selects entire block content, e.g. on triple click it selects entire paragraph.
57
+ */
58
+ private _selectBlockContent;
59
+ /**
60
+ * Handles {@link module:engine/view/document~ViewDocument#event:keydown keydown} events and changes
61
+ * the model selection when:
62
+ *
63
+ * * arrow key is pressed when the widget is selected,
64
+ * * the selection is next to a widget and the widget should become selected upon the arrow key press.
65
+ *
66
+ * See {@link #_preventDefaultOnArrowKeyPress}.
67
+ */
68
+ private _handleSelectionChangeOnArrowKeyPress;
69
+ /**
70
+ * Handles {@link module:engine/view/document~ViewDocument#event:keydown keydown} events and prevents
71
+ * the default browser behavior to make sure the fake selection is not being moved from a fake selection
72
+ * container.
73
+ *
74
+ * See {@link #_handleSelectionChangeOnArrowKeyPress}.
75
+ */
76
+ private _preventDefaultOnArrowKeyPress;
77
+ /**
78
+ * Handles delete keys: backspace and delete.
79
+ *
80
+ * @param isForward Set to true if delete was performed in forward direction.
81
+ * @returns Returns `true` if keys were handled correctly.
82
+ */
83
+ private _handleDelete;
84
+ /**
85
+ * Sets {@link module:engine/model/selection~ModelSelection document's selection} over given element.
86
+ *
87
+ * @internal
88
+ */
89
+ _setSelectionOverElement(element: ModelNode): void;
90
+ /**
91
+ * Checks if {@link module:engine/model/element~ModelElement element} placed next to the current
92
+ * {@link module:engine/model/selection~ModelSelection model selection} exists and is marked in
93
+ * {@link module:engine/model/schema~ModelSchema schema} as `object`.
94
+ *
95
+ * @internal
96
+ * @param forward Direction of checking.
97
+ */
98
+ _getObjectElementNextToSelection(forward: boolean): ModelElement | null;
99
+ /**
100
+ * Removes CSS class from previously selected widgets.
101
+ */
102
+ private _clearPreviouslySelectedWidgets;
103
+ /**
104
+ * Moves the document selection into the next editable or block widget.
105
+ */
106
+ private _selectNextEditable;
107
+ /**
108
+ * Looks for next focus point in the document starting from the given view position and direction.
109
+ * The focus point is either a block widget or an editable.
110
+ *
111
+ * @internal
112
+ */
113
+ _findNextFocusRange(startPosition: ViewPosition, direction: "backward" | "forward"): ModelRange | null;
114
+ /**
115
+ * Updates the document selection so that it selects first ancestor widget.
116
+ */
117
+ private _selectAncestorWidget;
118
118
  }
@@ -1,177 +1,174 @@
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 DecoratedMethodEvent } from '@ckeditor/ckeditor5-utils';
6
- import { WidgetResizeState } from './resizerstate.js';
7
- import type { WidgetResizerOptions } from '../widgetresize.js';
8
- declare const WidgetResizer_base: {
9
- new (): import("@ckeditor/ckeditor5-utils").Observable;
10
- prototype: import("@ckeditor/ckeditor5-utils").Observable;
11
- };
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 DecoratedMethodEvent, type ObservableMixinConstructor } from "@ckeditor/ckeditor5-utils";
6
+ import { WidgetResizeState } from "./resizerstate.js";
7
+ import type { WidgetResizerOptions } from "../widgetresize.js";
8
+ declare const WidgetResizerBase: ObservableMixinConstructor;
12
9
  /**
13
- * Represents a resizer for a single resizable object.
14
- */
15
- export declare class WidgetResizer extends /* #__PURE__ */ WidgetResizer_base {
16
- /**
17
- * Flag that indicates whether resizer can be used.
18
- *
19
- * @observable
20
- */
21
- isEnabled: boolean;
22
- /**
23
- * Flag that indicates that resizer is currently focused.
24
- *
25
- * @observable
26
- */
27
- isSelected: boolean;
28
- /**
29
- * Flag that indicates whether resizer is rendered (visible on the screen).
30
- *
31
- * @readonly
32
- * @observable
33
- */
34
- isVisible: boolean;
35
- /**
36
- * Stores the state of the resizable host geometry, such as the original width, the currently proposed height, etc.
37
- *
38
- * Note that a new state is created for each resize transaction.
39
- */
40
- private _state;
41
- /**
42
- * A view displaying the proposed new element size during the resizing.
43
- */
44
- private _sizeView;
45
- /**
46
- * Options passed to the {@link #constructor}.
47
- */
48
- private _options;
49
- /**
50
- * A wrapper that is controlled by the resizer. This is usually a widget element.
51
- */
52
- private _viewResizerWrapper;
53
- /**
54
- * The width of the resized {@link module:widget/widgetresize~WidgetResizerOptions#viewElement viewElement} before the resizing started.
55
- */
56
- private _initialViewWidth;
57
- /**
58
- * @param options Resizer options.
59
- */
60
- constructor(options: WidgetResizerOptions);
61
- /**
62
- * Stores the state of the resizable host geometry, such as the original width, the currently proposed height, etc.
63
- *
64
- * Note that a new state is created for each resize transaction.
65
- */
66
- get state(): WidgetResizeState;
67
- /**
68
- * Makes resizer visible in the UI.
69
- */
70
- show(): void;
71
- /**
72
- * Hides resizer in the UI.
73
- */
74
- hide(): void;
75
- /**
76
- * Attaches the resizer to the DOM.
77
- */
78
- attach(): void;
79
- /**
80
- * Starts the resizing process.
81
- *
82
- * Creates a new {@link #state} for the current process.
83
- *
84
- * @fires begin
85
- * @param domResizeHandle Clicked handle.
86
- */
87
- begin(domResizeHandle: HTMLElement): void;
88
- /**
89
- * Updates the proposed size based on `domEventData`.
90
- *
91
- * @fires updateSize
92
- */
93
- updateSize(domEventData: MouseEvent): void;
94
- /**
95
- * Applies the geometry proposed with the resizer.
96
- *
97
- * @fires commit
98
- */
99
- commit(): void;
100
- /**
101
- * Cancels and rejects the proposed resize dimensions, hiding the UI.
102
- *
103
- * @fires cancel
104
- */
105
- cancel(): void;
106
- /**
107
- * Destroys the resizer.
108
- */
109
- destroy(): void;
110
- /**
111
- * Redraws the resizer.
112
- *
113
- * @param handleHostRect Handle host rectangle might be given to improve performance.
114
- */
115
- redraw(handleHostRect?: Rect): void;
116
- containsHandle(domElement: HTMLElement): boolean;
117
- static isResizeHandle(domElement: HTMLElement): boolean;
118
- /**
119
- * Cleans up the context state.
120
- */
121
- private _cleanup;
122
- /**
123
- * Calculates the proposed size as the resize handles are dragged.
124
- *
125
- * @param domEventData Event data that caused the size update request. It should be used to calculate the proposed size.
126
- */
127
- private _proposeNewSize;
128
- /**
129
- * Obtains the resize host.
130
- *
131
- * Resize host is an object that receives dimensions which are the result of resizing.
132
- */
133
- private _getResizeHost;
134
- /**
135
- * Obtains the handle host.
136
- *
137
- * Handle host is an object that the handles are aligned to.
138
- *
139
- * Handle host will not always be an entire widget itself. Take an image as an example. The image widget
140
- * contains an image and a caption. Only the image should be surrounded with handles.
141
- */
142
- private _getHandleHost;
143
- /**
144
- * DOM container of the entire resize UI.
145
- *
146
- * Note that this property will have a value only after the element bound with the resizer is rendered
147
- * (otherwise `null`).
148
- */
149
- private get _domResizerWrapper();
150
- /**
151
- * Renders the resize handles in the DOM.
152
- *
153
- * @param domElement The resizer wrapper.
154
- */
155
- private _appendHandles;
156
- /**
157
- * Sets up the {@link #_sizeView} property and adds it to the passed `domElement`.
158
- */
159
- private _appendSizeUI;
10
+ * Represents a resizer for a single resizable object.
11
+ */
12
+ export declare class WidgetResizer extends WidgetResizerBase {
13
+ /**
14
+ * Flag that indicates whether resizer can be used.
15
+ *
16
+ * @observable
17
+ */
18
+ isEnabled: boolean;
19
+ /**
20
+ * Flag that indicates that resizer is currently focused.
21
+ *
22
+ * @observable
23
+ */
24
+ isSelected: boolean;
25
+ /**
26
+ * Flag that indicates whether resizer is rendered (visible on the screen).
27
+ *
28
+ * @readonly
29
+ * @observable
30
+ */
31
+ isVisible: boolean;
32
+ /**
33
+ * Stores the state of the resizable host geometry, such as the original width, the currently proposed height, etc.
34
+ *
35
+ * Note that a new state is created for each resize transaction.
36
+ */
37
+ private _state;
38
+ /**
39
+ * A view displaying the proposed new element size during the resizing.
40
+ */
41
+ private _sizeView;
42
+ /**
43
+ * Options passed to the {@link #constructor}.
44
+ */
45
+ private _options;
46
+ /**
47
+ * A wrapper that is controlled by the resizer. This is usually a widget element.
48
+ */
49
+ private _viewResizerWrapper;
50
+ /**
51
+ * The width of the resized {@link module:widget/widgetresize~WidgetResizerOptions#viewElement viewElement} before the resizing started.
52
+ */
53
+ private _initialViewWidth;
54
+ /**
55
+ * @param options Resizer options.
56
+ */
57
+ constructor(options: WidgetResizerOptions);
58
+ /**
59
+ * Stores the state of the resizable host geometry, such as the original width, the currently proposed height, etc.
60
+ *
61
+ * Note that a new state is created for each resize transaction.
62
+ */
63
+ get state(): WidgetResizeState;
64
+ /**
65
+ * Makes resizer visible in the UI.
66
+ */
67
+ show(): void;
68
+ /**
69
+ * Hides resizer in the UI.
70
+ */
71
+ hide(): void;
72
+ /**
73
+ * Attaches the resizer to the DOM.
74
+ */
75
+ attach(): void;
76
+ /**
77
+ * Starts the resizing process.
78
+ *
79
+ * Creates a new {@link #state} for the current process.
80
+ *
81
+ * @fires begin
82
+ * @param domResizeHandle Clicked handle.
83
+ */
84
+ begin(domResizeHandle: HTMLElement): void;
85
+ /**
86
+ * Updates the proposed size based on `domEventData`.
87
+ *
88
+ * @fires updateSize
89
+ */
90
+ updateSize(domEventData: MouseEvent): void;
91
+ /**
92
+ * Applies the geometry proposed with the resizer.
93
+ *
94
+ * @fires commit
95
+ */
96
+ commit(): void;
97
+ /**
98
+ * Cancels and rejects the proposed resize dimensions, hiding the UI.
99
+ *
100
+ * @fires cancel
101
+ */
102
+ cancel(): void;
103
+ /**
104
+ * Destroys the resizer.
105
+ */
106
+ destroy(): void;
107
+ /**
108
+ * Redraws the resizer.
109
+ *
110
+ * @param handleHostRect Handle host rectangle might be given to improve performance.
111
+ */
112
+ redraw(handleHostRect?: Rect): void;
113
+ containsHandle(domElement: HTMLElement): boolean;
114
+ static isResizeHandle(domElement: HTMLElement): boolean;
115
+ /**
116
+ * Cleans up the context state.
117
+ */
118
+ private _cleanup;
119
+ /**
120
+ * Calculates the proposed size as the resize handles are dragged.
121
+ *
122
+ * @param domEventData Event data that caused the size update request. It should be used to calculate the proposed size.
123
+ */
124
+ private _proposeNewSize;
125
+ /**
126
+ * Obtains the resize host.
127
+ *
128
+ * Resize host is an object that receives dimensions which are the result of resizing.
129
+ */
130
+ private _getResizeHost;
131
+ /**
132
+ * Obtains the handle host.
133
+ *
134
+ * Handle host is an object that the handles are aligned to.
135
+ *
136
+ * Handle host will not always be an entire widget itself. Take an image as an example. The image widget
137
+ * contains an image and a caption. Only the image should be surrounded with handles.
138
+ */
139
+ private _getHandleHost;
140
+ /**
141
+ * DOM container of the entire resize UI.
142
+ *
143
+ * Note that this property will have a value only after the element bound with the resizer is rendered
144
+ * (otherwise `null`).
145
+ */
146
+ private get _domResizerWrapper();
147
+ /**
148
+ * Renders the resize handles in the DOM.
149
+ *
150
+ * @param domElement The resizer wrapper.
151
+ */
152
+ private _appendHandles;
153
+ /**
154
+ * Sets up the {@link #_sizeView} property and adds it to the passed `domElement`.
155
+ */
156
+ private _appendSizeUI;
160
157
  }
161
158
  /**
162
- * @eventName ~WidgetResizer#begin
163
- */
164
- export type WidgetResizerBeginEvent = DecoratedMethodEvent<WidgetResizer, 'begin'>;
159
+ * @eventName ~WidgetResizer#begin
160
+ */
161
+ export type WidgetResizerBeginEvent = DecoratedMethodEvent<WidgetResizer, "begin">;
165
162
  /**
166
- * @eventName ~WidgetResizer#cancel
167
- */
168
- export type WidgetResizerCancelEvent = DecoratedMethodEvent<WidgetResizer, 'cancel'>;
163
+ * @eventName ~WidgetResizer#cancel
164
+ */
165
+ export type WidgetResizerCancelEvent = DecoratedMethodEvent<WidgetResizer, "cancel">;
169
166
  /**
170
- * @eventName ~WidgetResizer#commit
171
- */
172
- export type WidgetResizerCommitEvent = DecoratedMethodEvent<WidgetResizer, 'commit'>;
167
+ * @eventName ~WidgetResizer#commit
168
+ */
169
+ export type WidgetResizerCommitEvent = DecoratedMethodEvent<WidgetResizer, "commit">;
173
170
  /**
174
- * @eventName ~WidgetResizer#updateSize
175
- */
176
- export type WidgetResizerUpdateSizeEvent = DecoratedMethodEvent<WidgetResizer, 'updateSize'>;
171
+ * @eventName ~WidgetResizer#updateSize
172
+ */
173
+ export type WidgetResizerUpdateSizeEvent = DecoratedMethodEvent<WidgetResizer, "updateSize">;
177
174
  export {};