@ckeditor/ckeditor5-widget 36.0.0 → 37.0.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/package.json +23 -22
- package/src/highlightstack.d.ts +74 -0
- package/src/highlightstack.js +15 -28
- package/src/index.d.ts +9 -0
- package/src/utils.d.ts +198 -0
- package/src/utils.js +90 -107
- package/src/verticalnavigation.d.ts +15 -0
- package/src/verticalnavigation.js +35 -36
- package/src/widget.d.ts +94 -0
- package/src/widget.js +19 -41
- package/src/widgetresize/resizer.d.ts +177 -0
- package/src/widgetresize/resizer.js +15 -77
- package/src/widgetresize/resizerstate.d.ts +125 -0
- package/src/widgetresize/resizerstate.js +36 -95
- package/src/widgetresize/sizeview.d.ts +55 -0
- package/src/widgetresize/sizeview.js +2 -34
- package/src/widgetresize.d.ts +130 -0
- package/src/widgetresize.js +11 -44
- package/src/widgettoolbarrepository.d.ts +98 -0
- package/src/widgettoolbarrepository.js +29 -50
- package/src/widgettypearound/utils.d.ts +38 -0
- package/src/widgettypearound/utils.js +2 -16
- package/src/widgettypearound/widgettypearound.d.ts +232 -0
- package/src/widgettypearound/widgettypearound.js +44 -83
@@ -8,105 +8,49 @@
|
|
8
8
|
import { ObservableMixin, Rect } from '@ckeditor/ckeditor5-utils';
|
9
9
|
/**
|
10
10
|
* Stores the internal state of a single resizable object.
|
11
|
-
*
|
12
11
|
*/
|
13
12
|
export default class ResizeState extends ObservableMixin() {
|
14
13
|
/**
|
15
|
-
* @param
|
14
|
+
* @param options Resizer options.
|
16
15
|
*/
|
17
16
|
constructor(options) {
|
18
17
|
super();
|
19
|
-
/**
|
20
|
-
* The original width (pixels) of the resized object when the resize process was started.
|
21
|
-
*
|
22
|
-
* @readonly
|
23
|
-
* @member {Number} #originalWidth
|
24
|
-
*/
|
25
|
-
/**
|
26
|
-
* The original height (pixels) of the resized object when the resize process was started.
|
27
|
-
*
|
28
|
-
* @readonly
|
29
|
-
* @member {Number} #originalHeight
|
30
|
-
*/
|
31
|
-
/**
|
32
|
-
* The original width (percents) of the resized object when the resize process was started.
|
33
|
-
*
|
34
|
-
* @readonly
|
35
|
-
* @member {Number} #originalWidthPercents
|
36
|
-
*/
|
37
|
-
/**
|
38
|
-
* The position of the handle that initiated the resizing. E.g. `"top-left"`, `"bottom-right"` etc. or `null`
|
39
|
-
* if unknown.
|
40
|
-
*
|
41
|
-
* @readonly
|
42
|
-
* @observable
|
43
|
-
* @member {String|null} #activeHandlePosition
|
44
|
-
*/
|
45
18
|
this.set('activeHandlePosition', null);
|
46
|
-
/**
|
47
|
-
* The width (percents) proposed, but not committed yet, in the current resize process.
|
48
|
-
*
|
49
|
-
* @readonly
|
50
|
-
* @observable
|
51
|
-
* @member {Number|null} #proposedWidthPercents
|
52
|
-
*/
|
53
19
|
this.set('proposedWidthPercents', null);
|
54
|
-
/**
|
55
|
-
* The width (pixels) proposed, but not committed yet, in the current resize process.
|
56
|
-
*
|
57
|
-
* @readonly
|
58
|
-
* @observable
|
59
|
-
* @member {Number|null} #proposedWidthPixels
|
60
|
-
*/
|
61
20
|
this.set('proposedWidth', null);
|
62
|
-
/**
|
63
|
-
* The height (pixels) proposed, but not committed yet, in the current resize process.
|
64
|
-
*
|
65
|
-
* @readonly
|
66
|
-
* @observable
|
67
|
-
* @member {Number|null} #proposedHeightPixels
|
68
|
-
*/
|
69
21
|
this.set('proposedHeight', null);
|
70
22
|
this.set('proposedHandleHostWidth', null);
|
71
23
|
this.set('proposedHandleHostHeight', null);
|
72
|
-
/**
|
73
|
-
* A width to height ratio of the resized image.
|
74
|
-
*
|
75
|
-
* @readonly
|
76
|
-
* @member {Number} #aspectRatio
|
77
|
-
*/
|
78
|
-
/**
|
79
|
-
* @private
|
80
|
-
* @type {module:widget/widgetresize~ResizerOptions}
|
81
|
-
*/
|
82
24
|
this._options = options;
|
83
|
-
/**
|
84
|
-
* The reference point of the resizer where the dragging started. It is used to measure the distance the user cursor
|
85
|
-
* traveled, so how much the image should be enlarged.
|
86
|
-
* This information is only known after the DOM was rendered, so it will be updated later.
|
87
|
-
*
|
88
|
-
* @private
|
89
|
-
* @type {Object}
|
90
|
-
*/
|
91
25
|
this._referenceCoordinates = null;
|
92
26
|
}
|
27
|
+
/**
|
28
|
+
* The original width (pixels) of the resized object when the resize process was started.
|
29
|
+
*/
|
93
30
|
get originalWidth() {
|
94
31
|
return this._originalWidth;
|
95
32
|
}
|
33
|
+
/**
|
34
|
+
* The original height (pixels) of the resized object when the resize process was started.
|
35
|
+
*/
|
96
36
|
get originalHeight() {
|
97
37
|
return this._originalHeight;
|
98
38
|
}
|
39
|
+
/**
|
40
|
+
* The original width (percents) of the resized object when the resize process was started.
|
41
|
+
*/
|
99
42
|
get originalWidthPercents() {
|
100
43
|
return this._originalWidthPercents;
|
101
44
|
}
|
45
|
+
/**
|
46
|
+
* A width to height ratio of the resized image.
|
47
|
+
*/
|
102
48
|
get aspectRatio() {
|
103
49
|
return this._aspectRatio;
|
104
50
|
}
|
105
51
|
/**
|
106
52
|
*
|
107
|
-
* @param
|
108
|
-
* @param {HTMLElement} domHandleHost
|
109
|
-
* @param {HTMLElement} domResizeHost
|
53
|
+
* @param domResizeHandle The handle used to calculate the reference point.
|
110
54
|
*/
|
111
55
|
begin(domResizeHandle, domHandleHost, domResizeHost) {
|
112
56
|
const clientRect = new Rect(domHandleHost);
|
@@ -131,26 +75,20 @@ export default class ResizeState extends ObservableMixin() {
|
|
131
75
|
this.proposedHandleHostHeight = newSize.handleHostHeight;
|
132
76
|
}
|
133
77
|
}
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
// @param {HTMLElement} domResizeHost
|
138
|
-
// @param {module:utils/dom/rect~Rect} resizeHostRect
|
139
|
-
// @returns {Number}
|
78
|
+
/**
|
79
|
+
* Calculates a relative width of a `domResizeHost` compared to it's parent in percents.
|
80
|
+
*/
|
140
81
|
function calculateHostPercentageWidth(domResizeHost, resizeHostRect) {
|
141
82
|
const domResizeHostParent = domResizeHost.parentElement;
|
142
83
|
// Need to use computed style as it properly excludes parent's paddings from the returned value.
|
143
84
|
const parentWidth = parseFloat(domResizeHostParent.ownerDocument.defaultView.getComputedStyle(domResizeHostParent).width);
|
144
85
|
return resizeHostRect.width / parentWidth * 100;
|
145
86
|
}
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
// @returns {Object} return
|
152
|
-
// @returns {Number} return.x
|
153
|
-
// @returns {Number} return.y
|
87
|
+
/**
|
88
|
+
* Returns coordinates of the top-left corner of an element, relative to the document's top-left corner.
|
89
|
+
*
|
90
|
+
* @param resizerPosition The position of the resize handle, e.g. `"top-left"`, `"bottom-right"`.
|
91
|
+
*/
|
154
92
|
function getAbsoluteBoundaryPoint(element, resizerPosition) {
|
155
93
|
const elementRect = new Rect(element);
|
156
94
|
const positionParts = resizerPosition.split('-');
|
@@ -162,17 +100,19 @@ function getAbsoluteBoundaryPoint(element, resizerPosition) {
|
|
162
100
|
ret.y += element.ownerDocument.defaultView.scrollY;
|
163
101
|
return ret;
|
164
102
|
}
|
165
|
-
|
166
|
-
|
167
|
-
|
103
|
+
/**
|
104
|
+
* @param resizerPosition The expected resizer position, like `"top-left"`, `"bottom-right"`.
|
105
|
+
* @returns A prefixed HTML class name for the resizer element.
|
106
|
+
*/
|
168
107
|
function getResizerHandleClass(resizerPosition) {
|
169
108
|
return `ck-widget__resizer__handle-${resizerPosition}`;
|
170
109
|
}
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
110
|
+
/**
|
111
|
+
* Determines the position of a given resize handle.
|
112
|
+
*
|
113
|
+
* @param domHandle Handle used to calculate the reference point.
|
114
|
+
* @returns Returns a string like `"top-left"` or `undefined` if not matched.
|
115
|
+
*/
|
176
116
|
function getHandlePosition(domHandle) {
|
177
117
|
const resizerPositions = ['top-left', 'top-right', 'bottom-right', 'bottom-left'];
|
178
118
|
for (const position of resizerPositions) {
|
@@ -181,9 +121,10 @@ function getHandlePosition(domHandle) {
|
|
181
121
|
}
|
182
122
|
}
|
183
123
|
}
|
184
|
-
|
185
|
-
|
186
|
-
|
124
|
+
/**
|
125
|
+
* @param position Like `"top-left"`.
|
126
|
+
* @returns Inverted `position`, e.g. it returns `"bottom-right"` if `"top-left"` was given as `position`.
|
127
|
+
*/
|
187
128
|
function getOppositePosition(position) {
|
188
129
|
const parts = position.split('-');
|
189
130
|
const replacements = {
|
@@ -0,0 +1,55 @@
|
|
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 widget/widgetresize/sizeview
|
7
|
+
*/
|
8
|
+
import { View } from '@ckeditor/ckeditor5-ui';
|
9
|
+
import type { ResizerOptions } from '../widgetresize';
|
10
|
+
import type ResizeState from './resizerstate';
|
11
|
+
/**
|
12
|
+
* A view displaying the proposed new element size during the resizing.
|
13
|
+
*/
|
14
|
+
export default class SizeView extends View {
|
15
|
+
/**
|
16
|
+
* The visibility of the view defined based on the existence of the host proposed dimensions.
|
17
|
+
*
|
18
|
+
* @internal
|
19
|
+
* @observable
|
20
|
+
* @readonly
|
21
|
+
*/
|
22
|
+
_isVisible: boolean;
|
23
|
+
/**
|
24
|
+
* The text that will be displayed in the `SizeView` child.
|
25
|
+
* It can be formatted as the pixel values (e.g. 10x20) or the percentage value (e.g. 10%).
|
26
|
+
*
|
27
|
+
* @internal
|
28
|
+
* @observable
|
29
|
+
* @readonly
|
30
|
+
*/
|
31
|
+
_label: string;
|
32
|
+
/**
|
33
|
+
* The position of the view defined based on the host size and active handle position.
|
34
|
+
*
|
35
|
+
* @internal
|
36
|
+
* @observable
|
37
|
+
* @readonly
|
38
|
+
*/
|
39
|
+
_viewPosition: string;
|
40
|
+
constructor();
|
41
|
+
/**
|
42
|
+
* A method used for binding the `SizeView` instance properties to the `ResizeState` instance observable properties.
|
43
|
+
*
|
44
|
+
* @internal
|
45
|
+
* @param options An object defining the resizer options, used for setting the proper size label.
|
46
|
+
* @param resizeState The `ResizeState` class instance, used for keeping the `SizeView` state up to date.
|
47
|
+
*/
|
48
|
+
_bindToState(options: ResizerOptions, resizeState: ResizeState): void;
|
49
|
+
/**
|
50
|
+
* A method used for cleaning up. It removes the bindings and hides the view.
|
51
|
+
*
|
52
|
+
* @internal
|
53
|
+
*/
|
54
|
+
_dismiss(): void;
|
55
|
+
}
|
@@ -8,38 +8,10 @@
|
|
8
8
|
import { View } from '@ckeditor/ckeditor5-ui';
|
9
9
|
/**
|
10
10
|
* A view displaying the proposed new element size during the resizing.
|
11
|
-
*
|
12
|
-
* @protected
|
13
|
-
* @extends {module:ui/view~View}
|
14
11
|
*/
|
15
12
|
export default class SizeView extends View {
|
16
13
|
constructor() {
|
17
14
|
super();
|
18
|
-
/**
|
19
|
-
* The visibility of the view defined based on the existence of the host proposed dimensions.
|
20
|
-
*
|
21
|
-
* @private
|
22
|
-
* @observable
|
23
|
-
* @readonly
|
24
|
-
* @member {Boolean} #_isVisible
|
25
|
-
*/
|
26
|
-
/**
|
27
|
-
* The text that will be displayed in the `SizeView` child.
|
28
|
-
* It can be formatted as the pixel values (e.g. 10x20) or the percentage value (e.g. 10%).
|
29
|
-
*
|
30
|
-
* @private
|
31
|
-
* @observable
|
32
|
-
* @readonly
|
33
|
-
* @member {Boolean} #_label
|
34
|
-
*/
|
35
|
-
/**
|
36
|
-
* The position of the view defined based on the host size and active handle position.
|
37
|
-
*
|
38
|
-
* @private
|
39
|
-
* @observable
|
40
|
-
* @readonly
|
41
|
-
* @member {String} #_viewPosition
|
42
|
-
*/
|
43
15
|
const bind = this.bindTemplate;
|
44
16
|
this.setTemplate({
|
45
17
|
tag: 'div',
|
@@ -61,12 +33,9 @@ export default class SizeView extends View {
|
|
61
33
|
/**
|
62
34
|
* A method used for binding the `SizeView` instance properties to the `ResizeState` instance observable properties.
|
63
35
|
*
|
64
|
-
* @protected
|
65
36
|
* @internal
|
66
|
-
* @param
|
67
|
-
*
|
68
|
-
* @param {module:widget/widgetresize/resizerstate~ResizeState} resizeState
|
69
|
-
* The `ResizeState` class instance, used for keeping the `SizeView` state up to date.
|
37
|
+
* @param options An object defining the resizer options, used for setting the proper size label.
|
38
|
+
* @param resizeState The `ResizeState` class instance, used for keeping the `SizeView` state up to date.
|
70
39
|
*/
|
71
40
|
_bindToState(options, resizeState) {
|
72
41
|
this.bind('_isVisible').to(resizeState, 'proposedWidth', resizeState, 'proposedHeight', (width, height) => width !== null && height !== null);
|
@@ -85,7 +54,6 @@ export default class SizeView extends View {
|
|
85
54
|
/**
|
86
55
|
* A method used for cleaning up. It removes the bindings and hides the view.
|
87
56
|
*
|
88
|
-
* @protected
|
89
57
|
* @internal
|
90
58
|
*/
|
91
59
|
_dismiss() {
|
@@ -0,0 +1,130 @@
|
|
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 widget/widgetresize
|
7
|
+
*/
|
8
|
+
import Resizer from './widgetresize/resizer';
|
9
|
+
import { Plugin, type Editor } from '@ckeditor/ckeditor5-core';
|
10
|
+
import { type Element, type ViewContainerElement } from '@ckeditor/ckeditor5-engine';
|
11
|
+
import '../theme/widgetresize.css';
|
12
|
+
/**
|
13
|
+
* The widget resize feature plugin.
|
14
|
+
*
|
15
|
+
* Use the {@link module:widget/widgetresize~WidgetResize#attachTo} method to create a resizer for the specified widget.
|
16
|
+
*/
|
17
|
+
export default class WidgetResize extends Plugin {
|
18
|
+
/**
|
19
|
+
* The currently selected resizer.
|
20
|
+
*
|
21
|
+
* @observable
|
22
|
+
*/
|
23
|
+
selectedResizer: Resizer | null;
|
24
|
+
/**
|
25
|
+
* References an active resizer.
|
26
|
+
*
|
27
|
+
* Active resizer means a resizer which handle is actively used by the end user.
|
28
|
+
*
|
29
|
+
* @internal
|
30
|
+
* @observable
|
31
|
+
*/
|
32
|
+
_activeResizer: Resizer | null;
|
33
|
+
/**
|
34
|
+
* A map of resizers created using this plugin instance.
|
35
|
+
*/
|
36
|
+
private _resizers;
|
37
|
+
private _observer;
|
38
|
+
private _redrawSelectedResizerThrottled;
|
39
|
+
/**
|
40
|
+
* @inheritDoc
|
41
|
+
*/
|
42
|
+
static get pluginName(): 'WidgetResize';
|
43
|
+
/**
|
44
|
+
* @inheritDoc
|
45
|
+
*/
|
46
|
+
init(): void;
|
47
|
+
/**
|
48
|
+
* Redraws the selected resizer if there is any selected resizer and if it is visible.
|
49
|
+
*/
|
50
|
+
redrawSelectedResizer(): void;
|
51
|
+
/**
|
52
|
+
* @inheritDoc
|
53
|
+
*/
|
54
|
+
destroy(): void;
|
55
|
+
/**
|
56
|
+
* Marks resizer as selected.
|
57
|
+
*/
|
58
|
+
select(resizer: Resizer): void;
|
59
|
+
/**
|
60
|
+
* Deselects currently set resizer.
|
61
|
+
*/
|
62
|
+
deselect(): void;
|
63
|
+
/**
|
64
|
+
* @param options Resizer options.
|
65
|
+
*/
|
66
|
+
attachTo(options: ResizerOptions): Resizer;
|
67
|
+
/**
|
68
|
+
* Returns a resizer created for a given view element (widget element).
|
69
|
+
*
|
70
|
+
* @param viewElement View element associated with the resizer.
|
71
|
+
*/
|
72
|
+
getResizerByViewElement(viewElement: ViewContainerElement): Resizer | undefined;
|
73
|
+
/**
|
74
|
+
* Returns a resizer that contains a given resize handle.
|
75
|
+
*/
|
76
|
+
private _getResizerByHandle;
|
77
|
+
/**
|
78
|
+
* @param domEventData Native DOM event.
|
79
|
+
*/
|
80
|
+
private _mouseDownListener;
|
81
|
+
/**
|
82
|
+
* @param domEventData Native DOM event.
|
83
|
+
*/
|
84
|
+
private _mouseMoveListener;
|
85
|
+
private _mouseUpListener;
|
86
|
+
}
|
87
|
+
/**
|
88
|
+
* Interface describing a resizer. It allows to specify the resizing host, custom logic for calculating aspect ratio, etc.
|
89
|
+
*/
|
90
|
+
export interface ResizerOptions {
|
91
|
+
/**
|
92
|
+
* Editor instance associated with the resizer.
|
93
|
+
*/
|
94
|
+
editor: Editor;
|
95
|
+
modelElement: Element;
|
96
|
+
/**
|
97
|
+
* A view of an element to be resized. Typically it's the main widget's view instance.
|
98
|
+
*/
|
99
|
+
viewElement: ViewContainerElement;
|
100
|
+
unit?: 'px' | '%';
|
101
|
+
/**
|
102
|
+
* A callback to be executed once the resizing process is done.
|
103
|
+
*
|
104
|
+
* It receives a `Number` (`newValue`) as a parameter.
|
105
|
+
*
|
106
|
+
* For example, {@link module:image/imageresize~ImageResize} uses it to execute the resize image command
|
107
|
+
* which puts the new value into the model.
|
108
|
+
*
|
109
|
+
* ```ts
|
110
|
+
* {
|
111
|
+
* editor,
|
112
|
+
* modelElement: data.item,
|
113
|
+
* viewElement: widget,
|
114
|
+
*
|
115
|
+
* onCommit( newValue ) {
|
116
|
+
* editor.execute( 'resizeImage', { width: newValue } );
|
117
|
+
* }
|
118
|
+
* };
|
119
|
+
* ```
|
120
|
+
*/
|
121
|
+
onCommit: (newValue: string) => void;
|
122
|
+
getResizeHost: (widgetWrapper: HTMLElement) => HTMLElement;
|
123
|
+
getHandleHost: (widgetWrapper: HTMLElement) => HTMLElement;
|
124
|
+
isCentered?: (resizer: Resizer) => boolean;
|
125
|
+
}
|
126
|
+
declare module '@ckeditor/ckeditor5-core' {
|
127
|
+
interface PluginsMap {
|
128
|
+
[WidgetResize.pluginName]: WidgetResize;
|
129
|
+
}
|
130
|
+
}
|
package/src/widgetresize.js
CHANGED
@@ -15,11 +15,15 @@ import '../theme/widgetresize.css';
|
|
15
15
|
* The widget resize feature plugin.
|
16
16
|
*
|
17
17
|
* Use the {@link module:widget/widgetresize~WidgetResize#attachTo} method to create a resizer for the specified widget.
|
18
|
-
*
|
19
|
-
* @extends module:core/plugin~Plugin
|
20
|
-
* @mixes module:utils/observablemixin~ObservableMixin
|
21
18
|
*/
|
22
19
|
export default class WidgetResize extends Plugin {
|
20
|
+
constructor() {
|
21
|
+
super(...arguments);
|
22
|
+
/**
|
23
|
+
* A map of resizers created using this plugin instance.
|
24
|
+
*/
|
25
|
+
this._resizers = new Map();
|
26
|
+
}
|
23
27
|
/**
|
24
28
|
* @inheritDoc
|
25
29
|
*/
|
@@ -32,30 +36,8 @@ export default class WidgetResize extends Plugin {
|
|
32
36
|
init() {
|
33
37
|
const editing = this.editor.editing;
|
34
38
|
const domDocument = global.window.document;
|
35
|
-
/**
|
36
|
-
* The currently selected resizer.
|
37
|
-
*
|
38
|
-
* @observable
|
39
|
-
* @member {module:widget/widgetresize/resizer~Resizer|null} #selectedResizer
|
40
|
-
*/
|
41
39
|
this.set('selectedResizer', null);
|
42
|
-
/**
|
43
|
-
* References an active resizer.
|
44
|
-
*
|
45
|
-
* Active resizer means a resizer which handle is actively used by the end user.
|
46
|
-
*
|
47
|
-
* @protected
|
48
|
-
* @observable
|
49
|
-
* @member {module:widget/widgetresize/resizer~Resizer|null} #_activeResizer
|
50
|
-
*/
|
51
40
|
this.set('_activeResizer', null);
|
52
|
-
/**
|
53
|
-
* A map of resizers created using this plugin instance.
|
54
|
-
*
|
55
|
-
* @protected
|
56
|
-
* @type {Map.<module:engine/view/containerelement~ContainerElement, module:widget/widgetresize/resizer~Resizer>}
|
57
|
-
*/
|
58
|
-
this._resizers = new Map();
|
59
41
|
editing.view.addObserver(MouseObserver);
|
60
42
|
this._observer = new (DomEmitterMixin())();
|
61
43
|
this.listenTo(editing.view.document, 'mousedown', this._mouseDownListener.bind(this), { priority: 'high' });
|
@@ -110,8 +92,6 @@ export default class WidgetResize extends Plugin {
|
|
110
92
|
}
|
111
93
|
/**
|
112
94
|
* Marks resizer as selected.
|
113
|
-
*
|
114
|
-
* @param {module:widget/widgetresize/resizer~Resizer} resizer
|
115
95
|
*/
|
116
96
|
select(resizer) {
|
117
97
|
this.deselect();
|
@@ -128,8 +108,7 @@ export default class WidgetResize extends Plugin {
|
|
128
108
|
this.selectedResizer = null;
|
129
109
|
}
|
130
110
|
/**
|
131
|
-
* @param
|
132
|
-
* @returns {module:widget/widgetresize/resizer~Resizer}
|
111
|
+
* @param options Resizer options.
|
133
112
|
*/
|
134
113
|
attachTo(options) {
|
135
114
|
const resizer = new Resizer(options);
|
@@ -161,18 +140,13 @@ export default class WidgetResize extends Plugin {
|
|
161
140
|
/**
|
162
141
|
* Returns a resizer created for a given view element (widget element).
|
163
142
|
*
|
164
|
-
* @param
|
165
|
-
* @returns {module:widget/widgetresize/resizer~Resizer|undefined}
|
143
|
+
* @param viewElement View element associated with the resizer.
|
166
144
|
*/
|
167
145
|
getResizerByViewElement(viewElement) {
|
168
146
|
return this._resizers.get(viewElement);
|
169
147
|
}
|
170
148
|
/**
|
171
149
|
* Returns a resizer that contains a given resize handle.
|
172
|
-
*
|
173
|
-
* @protected
|
174
|
-
* @param {HTMLElement} domResizeHandle
|
175
|
-
* @returns {module:widget/widgetresize/resizer~Resizer}
|
176
150
|
*/
|
177
151
|
_getResizerByHandle(domResizeHandle) {
|
178
152
|
for (const resizer of this._resizers.values()) {
|
@@ -182,9 +156,7 @@ export default class WidgetResize extends Plugin {
|
|
182
156
|
}
|
183
157
|
}
|
184
158
|
/**
|
185
|
-
* @
|
186
|
-
* @param {module:utils/eventinfo~EventInfo} event
|
187
|
-
* @param {Event} domEventData Native DOM event.
|
159
|
+
* @param domEventData Native DOM event.
|
188
160
|
*/
|
189
161
|
_mouseDownListener(event, domEventData) {
|
190
162
|
const resizeHandle = domEventData.domTarget;
|
@@ -200,18 +172,13 @@ export default class WidgetResize extends Plugin {
|
|
200
172
|
}
|
201
173
|
}
|
202
174
|
/**
|
203
|
-
* @
|
204
|
-
* @param {module:utils/eventinfo~EventInfo} event
|
205
|
-
* @param {Event} domEventData Native DOM event.
|
175
|
+
* @param domEventData Native DOM event.
|
206
176
|
*/
|
207
177
|
_mouseMoveListener(event, domEventData) {
|
208
178
|
if (this._activeResizer) {
|
209
179
|
this._activeResizer.updateSize(domEventData);
|
210
180
|
}
|
211
181
|
}
|
212
|
-
/**
|
213
|
-
* @protected
|
214
|
-
*/
|
215
182
|
_mouseUpListener() {
|
216
183
|
if (this._activeResizer) {
|
217
184
|
this._activeResizer.commit();
|
@@ -0,0 +1,98 @@
|
|
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 widget/widgettoolbarrepository
|
7
|
+
*/
|
8
|
+
import { Plugin, type PluginDependencies, type ToolbarConfigItem } from '@ckeditor/ckeditor5-core';
|
9
|
+
import type { ViewDocumentSelection, ViewElement } from '@ckeditor/ckeditor5-engine';
|
10
|
+
/**
|
11
|
+
* Widget toolbar repository plugin. A central point for registering widget toolbars. This plugin handles the whole
|
12
|
+
* toolbar rendering process and exposes a concise API.
|
13
|
+
*
|
14
|
+
* To add a toolbar for your widget use the {@link ~WidgetToolbarRepository#register `WidgetToolbarRepository#register()`} method.
|
15
|
+
*
|
16
|
+
* The following example comes from the {@link module:image/imagetoolbar~ImageToolbar} plugin:
|
17
|
+
*
|
18
|
+
* ```ts
|
19
|
+
* class ImageToolbar extends Plugin {
|
20
|
+
* static get requires() {
|
21
|
+
* return [ WidgetToolbarRepository ];
|
22
|
+
* }
|
23
|
+
*
|
24
|
+
* afterInit() {
|
25
|
+
* const editor = this.editor;
|
26
|
+
* const widgetToolbarRepository = editor.plugins.get( WidgetToolbarRepository );
|
27
|
+
*
|
28
|
+
* widgetToolbarRepository.register( 'image', {
|
29
|
+
* items: editor.config.get( 'image.toolbar' ),
|
30
|
+
* getRelatedElement: getClosestSelectedImageWidget
|
31
|
+
* } );
|
32
|
+
* }
|
33
|
+
* }
|
34
|
+
* ```
|
35
|
+
*/
|
36
|
+
export default class WidgetToolbarRepository extends Plugin {
|
37
|
+
/**
|
38
|
+
* A map of toolbar definitions.
|
39
|
+
*/
|
40
|
+
private _toolbarDefinitions;
|
41
|
+
private _balloon;
|
42
|
+
/**
|
43
|
+
* @inheritDoc
|
44
|
+
*/
|
45
|
+
static get requires(): PluginDependencies;
|
46
|
+
/**
|
47
|
+
* @inheritDoc
|
48
|
+
*/
|
49
|
+
static get pluginName(): 'WidgetToolbarRepository';
|
50
|
+
/**
|
51
|
+
* @inheritDoc
|
52
|
+
*/
|
53
|
+
init(): void;
|
54
|
+
destroy(): void;
|
55
|
+
/**
|
56
|
+
* Registers toolbar in the WidgetToolbarRepository. It renders it in the `ContextualBalloon` based on the value of the invoked
|
57
|
+
* `getRelatedElement` function. Toolbar items are gathered from `items` array.
|
58
|
+
* The balloon's CSS class is by default `ck-toolbar-container` and may be override with the `balloonClassName` option.
|
59
|
+
*
|
60
|
+
* Note: This method should be called in the {@link module:core/plugin~PluginInterface#afterInit `Plugin#afterInit()`}
|
61
|
+
* callback (or later) to make sure that the given toolbar items were already registered by other plugins.
|
62
|
+
*
|
63
|
+
* @param toolbarId An id for the toolbar. Used to
|
64
|
+
* @param options.ariaLabel Label used by assistive technologies to describe this toolbar element.
|
65
|
+
* @param options.items Array of toolbar items.
|
66
|
+
* @param options.getRelatedElement Callback which returns an element the toolbar should be attached to.
|
67
|
+
* @param options.balloonClassName CSS class for the widget balloon.
|
68
|
+
*/
|
69
|
+
register(toolbarId: string, { ariaLabel, items, getRelatedElement, balloonClassName }: {
|
70
|
+
ariaLabel?: string;
|
71
|
+
items: Array<ToolbarConfigItem>;
|
72
|
+
getRelatedElement: (selection: ViewDocumentSelection) => (ViewElement | null);
|
73
|
+
balloonClassName?: string;
|
74
|
+
}): void;
|
75
|
+
/**
|
76
|
+
* Iterates over stored toolbars and makes them visible or hidden.
|
77
|
+
*/
|
78
|
+
private _updateToolbarsVisibility;
|
79
|
+
/**
|
80
|
+
* Hides the given toolbar.
|
81
|
+
*/
|
82
|
+
private _hideToolbar;
|
83
|
+
/**
|
84
|
+
* Shows up the toolbar if the toolbar is not visible.
|
85
|
+
* Otherwise, repositions the toolbar's balloon when toolbar's view is the most top view in balloon stack.
|
86
|
+
*
|
87
|
+
* It might happen here that the toolbar's view is under another view. Then do nothing as the other toolbar view
|
88
|
+
* should be still visible after the {@link module:core/editor/editorui~EditorUI#event:update}.
|
89
|
+
*/
|
90
|
+
private _showToolbar;
|
91
|
+
private _isToolbarVisible;
|
92
|
+
private _isToolbarInBalloon;
|
93
|
+
}
|
94
|
+
declare module '@ckeditor/ckeditor5-core' {
|
95
|
+
interface PluginsMap {
|
96
|
+
[WidgetToolbarRepository.pluginName]: WidgetToolbarRepository;
|
97
|
+
}
|
98
|
+
}
|