@ckeditor/ckeditor5-widget 35.2.0 → 35.3.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 +31 -23
- package/src/highlightstack.js +105 -139
- package/src/index.js +0 -1
- package/src/utils.js +127 -181
- package/src/verticalnavigation.js +144 -187
- package/src/widget.js +359 -435
- package/src/widgetresize/resizer.js +412 -505
- package/src/widgetresize/resizerstate.js +154 -176
- package/src/widgetresize/sizeview.js +79 -98
- package/src/widgetresize.js +199 -297
- package/src/widgettoolbarrepository.js +244 -296
- package/src/widgettypearound/utils.js +11 -20
- package/src/widgettypearound/widgettypearound.js +748 -876
@@ -2,163 +2,148 @@
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
4
|
*/
|
5
|
-
|
6
5
|
/**
|
7
6
|
* @module widget/widgetresize/resizerstate
|
8
7
|
*/
|
9
|
-
|
10
8
|
import Rect from '@ckeditor/ckeditor5-utils/src/dom/rect';
|
11
|
-
|
12
|
-
import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin';
|
13
|
-
import mix from '@ckeditor/ckeditor5-utils/src/mix';
|
14
|
-
|
9
|
+
import { Observable } from '@ckeditor/ckeditor5-utils/src/observablemixin';
|
15
10
|
/**
|
16
11
|
* Stores the internal state of a single resizable object.
|
17
12
|
*
|
18
13
|
*/
|
19
|
-
export default class ResizeState {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
this.proposedWidthPercents = newSize.widthPercents;
|
140
|
-
|
141
|
-
this.proposedHandleHostWidth = newSize.handleHostWidth;
|
142
|
-
this.proposedHandleHostHeight = newSize.handleHostHeight;
|
143
|
-
}
|
14
|
+
export default class ResizeState extends Observable {
|
15
|
+
/**
|
16
|
+
* @param {module:widget/widgetresize~ResizerOptions} options Resizer options.
|
17
|
+
*/
|
18
|
+
constructor(options) {
|
19
|
+
super();
|
20
|
+
/**
|
21
|
+
* The original width (pixels) of the resized object when the resize process was started.
|
22
|
+
*
|
23
|
+
* @readonly
|
24
|
+
* @member {Number} #originalWidth
|
25
|
+
*/
|
26
|
+
/**
|
27
|
+
* The original height (pixels) of the resized object when the resize process was started.
|
28
|
+
*
|
29
|
+
* @readonly
|
30
|
+
* @member {Number} #originalHeight
|
31
|
+
*/
|
32
|
+
/**
|
33
|
+
* The original width (percents) of the resized object when the resize process was started.
|
34
|
+
*
|
35
|
+
* @readonly
|
36
|
+
* @member {Number} #originalWidthPercents
|
37
|
+
*/
|
38
|
+
/**
|
39
|
+
* The position of the handle that initiated the resizing. E.g. `"top-left"`, `"bottom-right"` etc. or `null`
|
40
|
+
* if unknown.
|
41
|
+
*
|
42
|
+
* @readonly
|
43
|
+
* @observable
|
44
|
+
* @member {String|null} #activeHandlePosition
|
45
|
+
*/
|
46
|
+
this.set('activeHandlePosition', null);
|
47
|
+
/**
|
48
|
+
* The width (percents) proposed, but not committed yet, in the current resize process.
|
49
|
+
*
|
50
|
+
* @readonly
|
51
|
+
* @observable
|
52
|
+
* @member {Number|null} #proposedWidthPercents
|
53
|
+
*/
|
54
|
+
this.set('proposedWidthPercents', null);
|
55
|
+
/**
|
56
|
+
* The width (pixels) proposed, but not committed yet, in the current resize process.
|
57
|
+
*
|
58
|
+
* @readonly
|
59
|
+
* @observable
|
60
|
+
* @member {Number|null} #proposedWidthPixels
|
61
|
+
*/
|
62
|
+
this.set('proposedWidth', null);
|
63
|
+
/**
|
64
|
+
* The height (pixels) proposed, but not committed yet, in the current resize process.
|
65
|
+
*
|
66
|
+
* @readonly
|
67
|
+
* @observable
|
68
|
+
* @member {Number|null} #proposedHeightPixels
|
69
|
+
*/
|
70
|
+
this.set('proposedHeight', null);
|
71
|
+
this.set('proposedHandleHostWidth', null);
|
72
|
+
this.set('proposedHandleHostHeight', null);
|
73
|
+
/**
|
74
|
+
* A width to height ratio of the resized image.
|
75
|
+
*
|
76
|
+
* @readonly
|
77
|
+
* @member {Number} #aspectRatio
|
78
|
+
*/
|
79
|
+
/**
|
80
|
+
* @private
|
81
|
+
* @type {module:widget/widgetresize~ResizerOptions}
|
82
|
+
*/
|
83
|
+
this._options = options;
|
84
|
+
/**
|
85
|
+
* The reference point of the resizer where the dragging started. It is used to measure the distance the user cursor
|
86
|
+
* traveled, so how much the image should be enlarged.
|
87
|
+
* This information is only known after the DOM was rendered, so it will be updated later.
|
88
|
+
*
|
89
|
+
* @private
|
90
|
+
* @type {Object}
|
91
|
+
*/
|
92
|
+
this._referenceCoordinates = null;
|
93
|
+
}
|
94
|
+
get originalWidth() {
|
95
|
+
return this._originalWidth;
|
96
|
+
}
|
97
|
+
get originalHeight() {
|
98
|
+
return this._originalHeight;
|
99
|
+
}
|
100
|
+
get originalWidthPercents() {
|
101
|
+
return this._originalWidthPercents;
|
102
|
+
}
|
103
|
+
get aspectRatio() {
|
104
|
+
return this._aspectRatio;
|
105
|
+
}
|
106
|
+
/**
|
107
|
+
*
|
108
|
+
* @param {HTMLElement} domResizeHandle The handle used to calculate the reference point.
|
109
|
+
* @param {HTMLElement} domHandleHost
|
110
|
+
* @param {HTMLElement} domResizeHost
|
111
|
+
*/
|
112
|
+
begin(domResizeHandle, domHandleHost, domResizeHost) {
|
113
|
+
const clientRect = new Rect(domHandleHost);
|
114
|
+
this.activeHandlePosition = getHandlePosition(domResizeHandle);
|
115
|
+
this._referenceCoordinates = getAbsoluteBoundaryPoint(domHandleHost, getOppositePosition(this.activeHandlePosition));
|
116
|
+
this._originalWidth = clientRect.width;
|
117
|
+
this._originalHeight = clientRect.height;
|
118
|
+
this._aspectRatio = clientRect.width / clientRect.height;
|
119
|
+
const widthStyle = domResizeHost.style.width;
|
120
|
+
if (widthStyle && widthStyle.match(/^\d+(\.\d*)?%$/)) {
|
121
|
+
this._originalWidthPercents = parseFloat(widthStyle);
|
122
|
+
}
|
123
|
+
else {
|
124
|
+
this._originalWidthPercents = calculateHostPercentageWidth(domResizeHost, clientRect);
|
125
|
+
}
|
126
|
+
}
|
127
|
+
update(newSize) {
|
128
|
+
this.proposedWidth = newSize.width;
|
129
|
+
this.proposedHeight = newSize.height;
|
130
|
+
this.proposedWidthPercents = newSize.widthPercents;
|
131
|
+
this.proposedHandleHostWidth = newSize.handleHostWidth;
|
132
|
+
this.proposedHandleHostHeight = newSize.handleHostHeight;
|
133
|
+
}
|
144
134
|
}
|
145
|
-
|
146
|
-
mix( ResizeState, ObservableMixin );
|
147
|
-
|
148
135
|
// Calculates a relative width of a `domResizeHost` compared to it's parent in percents.
|
149
136
|
//
|
150
137
|
// @private
|
151
138
|
// @param {HTMLElement} domResizeHost
|
152
139
|
// @param {module:utils/dom/rect~Rect} resizeHostRect
|
153
140
|
// @returns {Number}
|
154
|
-
function calculateHostPercentageWidth(
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
return resizeHostRect.width / parentWidth * 100;
|
141
|
+
function calculateHostPercentageWidth(domResizeHost, resizeHostRect) {
|
142
|
+
const domResizeHostParent = domResizeHost.parentElement;
|
143
|
+
// Need to use computed style as it properly excludes parent's paddings from the returned value.
|
144
|
+
const parentWidth = parseFloat(domResizeHostParent.ownerDocument.defaultView.getComputedStyle(domResizeHostParent).width);
|
145
|
+
return resizeHostRect.width / parentWidth * 100;
|
160
146
|
}
|
161
|
-
|
162
147
|
// Returns coordinates of the top-left corner of an element, relative to the document's top-left corner.
|
163
148
|
//
|
164
149
|
// @private
|
@@ -167,53 +152,46 @@ function calculateHostPercentageWidth( domResizeHost, resizeHostRect ) {
|
|
167
152
|
// @returns {Object} return
|
168
153
|
// @returns {Number} return.x
|
169
154
|
// @returns {Number} return.y
|
170
|
-
function getAbsoluteBoundaryPoint(
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
return ret;
|
155
|
+
function getAbsoluteBoundaryPoint(element, resizerPosition) {
|
156
|
+
const elementRect = new Rect(element);
|
157
|
+
const positionParts = resizerPosition.split('-');
|
158
|
+
const ret = {
|
159
|
+
x: positionParts[1] == 'right' ? elementRect.right : elementRect.left,
|
160
|
+
y: positionParts[0] == 'bottom' ? elementRect.bottom : elementRect.top
|
161
|
+
};
|
162
|
+
ret.x += element.ownerDocument.defaultView.scrollX;
|
163
|
+
ret.y += element.ownerDocument.defaultView.scrollY;
|
164
|
+
return ret;
|
182
165
|
}
|
183
|
-
|
184
166
|
// @private
|
185
167
|
// @param {String} resizerPosition The expected resizer position, like `"top-left"`, `"bottom-right"`.
|
186
168
|
// @returns {String} A prefixed HTML class name for the resizer element.
|
187
|
-
function getResizerHandleClass(
|
188
|
-
|
169
|
+
function getResizerHandleClass(resizerPosition) {
|
170
|
+
return `ck-widget__resizer__handle-${resizerPosition}`;
|
189
171
|
}
|
190
|
-
|
191
172
|
// Determines the position of a given resize handle.
|
192
173
|
//
|
193
174
|
// @private
|
194
175
|
// @param {HTMLElement} domHandle Handle used to calculate the reference point.
|
195
176
|
// @returns {String|undefined} Returns a string like `"top-left"` or `undefined` if not matched.
|
196
|
-
function getHandlePosition(
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
}
|
177
|
+
function getHandlePosition(domHandle) {
|
178
|
+
const resizerPositions = ['top-left', 'top-right', 'bottom-right', 'bottom-left'];
|
179
|
+
for (const position of resizerPositions) {
|
180
|
+
if (domHandle.classList.contains(getResizerHandleClass(position))) {
|
181
|
+
return position;
|
182
|
+
}
|
183
|
+
}
|
204
184
|
}
|
205
|
-
|
206
185
|
// @private
|
207
186
|
// @param {String} position Like `"top-left"`.
|
208
187
|
// @returns {String} Inverted `position`, e.g. it returns `"bottom-right"` if `"top-left"` was given as `position`.
|
209
|
-
function getOppositePosition(
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
return `${ replacements[ parts[ 0 ] ] }-${ replacements[ parts[ 1 ] ] }`;
|
188
|
+
function getOppositePosition(position) {
|
189
|
+
const parts = position.split('-');
|
190
|
+
const replacements = {
|
191
|
+
top: 'bottom',
|
192
|
+
bottom: 'top',
|
193
|
+
left: 'right',
|
194
|
+
right: 'left'
|
195
|
+
};
|
196
|
+
return `${replacements[parts[0]]}-${replacements[parts[1]]}`;
|
219
197
|
}
|
@@ -2,13 +2,10 @@
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
4
|
*/
|
5
|
-
|
6
5
|
/**
|
7
6
|
* @module widget/widgetresize/sizeview
|
8
7
|
*/
|
9
|
-
|
10
8
|
import View from '@ckeditor/ckeditor5-ui/src/view';
|
11
|
-
|
12
9
|
/**
|
13
10
|
* A view displaying the proposed new element size during the resizing.
|
14
11
|
*
|
@@ -16,99 +13,83 @@ import View from '@ckeditor/ckeditor5-ui/src/view';
|
|
16
13
|
* @extends {module:ui/view~View}
|
17
14
|
*/
|
18
15
|
export default class SizeView extends View {
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
resizeState, 'proposedHandleHostWidth',
|
99
|
-
resizeState, 'proposedHandleHostHeight',
|
100
|
-
// If the widget is too small to contain the size label, display the label above.
|
101
|
-
( position, width, height ) => width < 50 || height < 50 ? 'above-center' : position
|
102
|
-
);
|
103
|
-
}
|
104
|
-
|
105
|
-
/**
|
106
|
-
* A method used for cleaning up. It removes the bindings and hides the view.
|
107
|
-
*
|
108
|
-
* @protected
|
109
|
-
*/
|
110
|
-
_dismiss() {
|
111
|
-
this.unbind();
|
112
|
-
this._isVisible = false;
|
113
|
-
}
|
16
|
+
constructor() {
|
17
|
+
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
|
+
const bind = this.bindTemplate;
|
44
|
+
this.setTemplate({
|
45
|
+
tag: 'div',
|
46
|
+
attributes: {
|
47
|
+
class: [
|
48
|
+
'ck',
|
49
|
+
'ck-size-view',
|
50
|
+
bind.to('_viewPosition', value => value ? `ck-orientation-${value}` : '')
|
51
|
+
],
|
52
|
+
style: {
|
53
|
+
display: bind.if('_isVisible', 'none', visible => !visible)
|
54
|
+
}
|
55
|
+
},
|
56
|
+
children: [{
|
57
|
+
text: bind.to('_label')
|
58
|
+
}]
|
59
|
+
});
|
60
|
+
}
|
61
|
+
/**
|
62
|
+
* A method used for binding the `SizeView` instance properties to the `ResizeState` instance observable properties.
|
63
|
+
*
|
64
|
+
* @protected
|
65
|
+
* @internal
|
66
|
+
* @param {module:widget/widgetresize~ResizerOptions} options
|
67
|
+
* An object defining the resizer options, used for setting the proper size label.
|
68
|
+
* @param {module:widget/widgetresize/resizerstate~ResizeState} resizeState
|
69
|
+
* The `ResizeState` class instance, used for keeping the `SizeView` state up to date.
|
70
|
+
*/
|
71
|
+
_bindToState(options, resizeState) {
|
72
|
+
this.bind('_isVisible').to(resizeState, 'proposedWidth', resizeState, 'proposedHeight', (width, height) => width !== null && height !== null);
|
73
|
+
this.bind('_label').to(resizeState, 'proposedHandleHostWidth', resizeState, 'proposedHandleHostHeight', resizeState, 'proposedWidthPercents', (width, height, widthPercents) => {
|
74
|
+
if (options.unit === 'px') {
|
75
|
+
return `${width}×${height}`;
|
76
|
+
}
|
77
|
+
else {
|
78
|
+
return `${widthPercents}%`;
|
79
|
+
}
|
80
|
+
});
|
81
|
+
this.bind('_viewPosition').to(resizeState, 'activeHandlePosition', resizeState, 'proposedHandleHostWidth', resizeState, 'proposedHandleHostHeight',
|
82
|
+
// If the widget is too small to contain the size label, display the label above.
|
83
|
+
(position, width, height) => width < 50 || height < 50 ? 'above-center' : position);
|
84
|
+
}
|
85
|
+
/**
|
86
|
+
* A method used for cleaning up. It removes the bindings and hides the view.
|
87
|
+
*
|
88
|
+
* @protected
|
89
|
+
* @internal
|
90
|
+
*/
|
91
|
+
_dismiss() {
|
92
|
+
this.unbind();
|
93
|
+
this._isVisible = false;
|
94
|
+
}
|
114
95
|
}
|