@ckeditor/ckeditor5-widget 0.0.0-internal-20241017.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.
Potentially problematic release.
This version of @ckeditor/ckeditor5-widget might be problematic. Click here for more details.
- package/CHANGELOG.md +4 -0
- package/LICENSE.md +21 -0
- package/README.md +22 -0
- package/dist/augmentation.d.ts +17 -0
- package/dist/highlightstack.d.ts +78 -0
- package/dist/index-content.css +4 -0
- package/dist/index-editor.css +183 -0
- package/dist/index.css +257 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +3054 -0
- package/dist/index.js.map +1 -0
- package/dist/translations/ar.d.ts +8 -0
- package/dist/translations/ar.js +5 -0
- package/dist/translations/ar.umd.js +11 -0
- package/dist/translations/az.d.ts +8 -0
- package/dist/translations/az.js +5 -0
- package/dist/translations/az.umd.js +11 -0
- package/dist/translations/bg.d.ts +8 -0
- package/dist/translations/bg.js +5 -0
- package/dist/translations/bg.umd.js +11 -0
- package/dist/translations/bn.d.ts +8 -0
- package/dist/translations/bn.js +5 -0
- package/dist/translations/bn.umd.js +11 -0
- package/dist/translations/ca.d.ts +8 -0
- package/dist/translations/ca.js +5 -0
- package/dist/translations/ca.umd.js +11 -0
- package/dist/translations/cs.d.ts +8 -0
- package/dist/translations/cs.js +5 -0
- package/dist/translations/cs.umd.js +11 -0
- package/dist/translations/da.d.ts +8 -0
- package/dist/translations/da.js +5 -0
- package/dist/translations/da.umd.js +11 -0
- package/dist/translations/de-ch.d.ts +8 -0
- package/dist/translations/de-ch.js +5 -0
- package/dist/translations/de-ch.umd.js +11 -0
- package/dist/translations/de.d.ts +8 -0
- package/dist/translations/de.js +5 -0
- package/dist/translations/de.umd.js +11 -0
- package/dist/translations/el.d.ts +8 -0
- package/dist/translations/el.js +5 -0
- package/dist/translations/el.umd.js +11 -0
- package/dist/translations/en-au.d.ts +8 -0
- package/dist/translations/en-au.js +5 -0
- package/dist/translations/en-au.umd.js +11 -0
- package/dist/translations/en.d.ts +8 -0
- package/dist/translations/en.js +5 -0
- package/dist/translations/en.umd.js +11 -0
- package/dist/translations/es.d.ts +8 -0
- package/dist/translations/es.js +5 -0
- package/dist/translations/es.umd.js +11 -0
- package/dist/translations/et.d.ts +8 -0
- package/dist/translations/et.js +5 -0
- package/dist/translations/et.umd.js +11 -0
- package/dist/translations/fa.d.ts +8 -0
- package/dist/translations/fa.js +5 -0
- package/dist/translations/fa.umd.js +11 -0
- package/dist/translations/fi.d.ts +8 -0
- package/dist/translations/fi.js +5 -0
- package/dist/translations/fi.umd.js +11 -0
- package/dist/translations/fr.d.ts +8 -0
- package/dist/translations/fr.js +5 -0
- package/dist/translations/fr.umd.js +11 -0
- package/dist/translations/gl.d.ts +8 -0
- package/dist/translations/gl.js +5 -0
- package/dist/translations/gl.umd.js +11 -0
- package/dist/translations/he.d.ts +8 -0
- package/dist/translations/he.js +5 -0
- package/dist/translations/he.umd.js +11 -0
- package/dist/translations/hi.d.ts +8 -0
- package/dist/translations/hi.js +5 -0
- package/dist/translations/hi.umd.js +11 -0
- package/dist/translations/hr.d.ts +8 -0
- package/dist/translations/hr.js +5 -0
- package/dist/translations/hr.umd.js +11 -0
- package/dist/translations/hu.d.ts +8 -0
- package/dist/translations/hu.js +5 -0
- package/dist/translations/hu.umd.js +11 -0
- package/dist/translations/id.d.ts +8 -0
- package/dist/translations/id.js +5 -0
- package/dist/translations/id.umd.js +11 -0
- package/dist/translations/it.d.ts +8 -0
- package/dist/translations/it.js +5 -0
- package/dist/translations/it.umd.js +11 -0
- package/dist/translations/ja.d.ts +8 -0
- package/dist/translations/ja.js +5 -0
- package/dist/translations/ja.umd.js +11 -0
- package/dist/translations/ko.d.ts +8 -0
- package/dist/translations/ko.js +5 -0
- package/dist/translations/ko.umd.js +11 -0
- package/dist/translations/ku.d.ts +8 -0
- package/dist/translations/ku.js +5 -0
- package/dist/translations/ku.umd.js +11 -0
- package/dist/translations/lt.d.ts +8 -0
- package/dist/translations/lt.js +5 -0
- package/dist/translations/lt.umd.js +11 -0
- package/dist/translations/lv.d.ts +8 -0
- package/dist/translations/lv.js +5 -0
- package/dist/translations/lv.umd.js +11 -0
- package/dist/translations/ms.d.ts +8 -0
- package/dist/translations/ms.js +5 -0
- package/dist/translations/ms.umd.js +11 -0
- package/dist/translations/nl.d.ts +8 -0
- package/dist/translations/nl.js +5 -0
- package/dist/translations/nl.umd.js +11 -0
- package/dist/translations/no.d.ts +8 -0
- package/dist/translations/no.js +5 -0
- package/dist/translations/no.umd.js +11 -0
- package/dist/translations/pl.d.ts +8 -0
- package/dist/translations/pl.js +5 -0
- package/dist/translations/pl.umd.js +11 -0
- package/dist/translations/pt-br.d.ts +8 -0
- package/dist/translations/pt-br.js +5 -0
- package/dist/translations/pt-br.umd.js +11 -0
- package/dist/translations/pt.d.ts +8 -0
- package/dist/translations/pt.js +5 -0
- package/dist/translations/pt.umd.js +11 -0
- package/dist/translations/ro.d.ts +8 -0
- package/dist/translations/ro.js +5 -0
- package/dist/translations/ro.umd.js +11 -0
- package/dist/translations/ru.d.ts +8 -0
- package/dist/translations/ru.js +5 -0
- package/dist/translations/ru.umd.js +11 -0
- package/dist/translations/sk.d.ts +8 -0
- package/dist/translations/sk.js +5 -0
- package/dist/translations/sk.umd.js +11 -0
- package/dist/translations/sq.d.ts +8 -0
- package/dist/translations/sq.js +5 -0
- package/dist/translations/sq.umd.js +11 -0
- package/dist/translations/sr-latn.d.ts +8 -0
- package/dist/translations/sr-latn.js +5 -0
- package/dist/translations/sr-latn.umd.js +11 -0
- package/dist/translations/sr.d.ts +8 -0
- package/dist/translations/sr.js +5 -0
- package/dist/translations/sr.umd.js +11 -0
- package/dist/translations/sv.d.ts +8 -0
- package/dist/translations/sv.js +5 -0
- package/dist/translations/sv.umd.js +11 -0
- package/dist/translations/th.d.ts +8 -0
- package/dist/translations/th.js +5 -0
- package/dist/translations/th.umd.js +11 -0
- package/dist/translations/tk.d.ts +8 -0
- package/dist/translations/tk.js +5 -0
- package/dist/translations/tk.umd.js +11 -0
- package/dist/translations/tr.d.ts +8 -0
- package/dist/translations/tr.js +5 -0
- package/dist/translations/tr.umd.js +11 -0
- package/dist/translations/uk.d.ts +8 -0
- package/dist/translations/uk.js +5 -0
- package/dist/translations/uk.umd.js +11 -0
- package/dist/translations/ur.d.ts +8 -0
- package/dist/translations/ur.js +5 -0
- package/dist/translations/ur.umd.js +11 -0
- package/dist/translations/uz.d.ts +8 -0
- package/dist/translations/uz.js +5 -0
- package/dist/translations/uz.umd.js +11 -0
- package/dist/translations/vi.d.ts +8 -0
- package/dist/translations/vi.js +5 -0
- package/dist/translations/vi.umd.js +11 -0
- package/dist/translations/zh-cn.d.ts +8 -0
- package/dist/translations/zh-cn.js +5 -0
- package/dist/translations/zh-cn.umd.js +11 -0
- package/dist/translations/zh.d.ts +8 -0
- package/dist/translations/zh.js +5 -0
- package/dist/translations/zh.umd.js +11 -0
- package/dist/utils.d.ts +219 -0
- package/dist/verticalnavigation.d.ts +19 -0
- package/dist/widget.d.ts +111 -0
- package/dist/widgetresize/resizer.d.ts +181 -0
- package/dist/widgetresize/resizerstate.d.ts +129 -0
- package/dist/widgetresize/sizeview.d.ts +59 -0
- package/dist/widgetresize.d.ts +133 -0
- package/dist/widgettoolbarrepository.d.ts +102 -0
- package/dist/widgettypearound/utils.d.ts +42 -0
- package/dist/widgettypearound/widgettypearound.d.ts +237 -0
- package/lang/contexts.json +12 -0
- package/lang/translations/ar.po +58 -0
- package/lang/translations/az.po +58 -0
- package/lang/translations/bg.po +58 -0
- package/lang/translations/bn.po +58 -0
- package/lang/translations/ca.po +58 -0
- package/lang/translations/cs.po +58 -0
- package/lang/translations/da.po +58 -0
- package/lang/translations/de-ch.po +58 -0
- package/lang/translations/de.po +58 -0
- package/lang/translations/el.po +58 -0
- package/lang/translations/en-au.po +58 -0
- package/lang/translations/en.po +58 -0
- package/lang/translations/es.po +58 -0
- package/lang/translations/et.po +58 -0
- package/lang/translations/fa.po +58 -0
- package/lang/translations/fi.po +58 -0
- package/lang/translations/fr.po +58 -0
- package/lang/translations/gl.po +58 -0
- package/lang/translations/he.po +58 -0
- package/lang/translations/hi.po +58 -0
- package/lang/translations/hr.po +58 -0
- package/lang/translations/hu.po +58 -0
- package/lang/translations/id.po +58 -0
- package/lang/translations/it.po +58 -0
- package/lang/translations/ja.po +58 -0
- package/lang/translations/ko.po +58 -0
- package/lang/translations/ku.po +58 -0
- package/lang/translations/lt.po +58 -0
- package/lang/translations/lv.po +58 -0
- package/lang/translations/ms.po +58 -0
- package/lang/translations/nl.po +58 -0
- package/lang/translations/no.po +58 -0
- package/lang/translations/pl.po +58 -0
- package/lang/translations/pt-br.po +58 -0
- package/lang/translations/pt.po +58 -0
- package/lang/translations/ro.po +58 -0
- package/lang/translations/ru.po +58 -0
- package/lang/translations/sk.po +58 -0
- package/lang/translations/sq.po +58 -0
- package/lang/translations/sr-latn.po +58 -0
- package/lang/translations/sr.po +58 -0
- package/lang/translations/sv.po +58 -0
- package/lang/translations/th.po +58 -0
- package/lang/translations/tk.po +58 -0
- package/lang/translations/tr.po +58 -0
- package/lang/translations/uk.po +58 -0
- package/lang/translations/ur.po +58 -0
- package/lang/translations/uz.po +58 -0
- package/lang/translations/vi.po +58 -0
- package/lang/translations/zh-cn.po +58 -0
- package/lang/translations/zh.po +58 -0
- package/package.json +42 -0
- package/src/augmentation.d.ts +13 -0
- package/src/augmentation.js +5 -0
- package/src/highlightstack.d.ts +74 -0
- package/src/highlightstack.js +129 -0
- package/src/index.d.ts +13 -0
- package/src/index.js +13 -0
- package/src/utils.d.ts +215 -0
- package/src/utils.js +396 -0
- package/src/verticalnavigation.d.ts +15 -0
- package/src/verticalnavigation.js +196 -0
- package/src/widget.d.ts +107 -0
- package/src/widget.js +603 -0
- package/src/widgetresize/resizer.d.ts +177 -0
- package/src/widgetresize/resizer.js +372 -0
- package/src/widgetresize/resizerstate.d.ts +125 -0
- package/src/widgetresize/resizerstate.js +129 -0
- package/src/widgetresize/sizeview.d.ts +55 -0
- package/src/widgetresize/sizeview.js +63 -0
- package/src/widgetresize.d.ts +129 -0
- package/src/widgetresize.js +194 -0
- package/src/widgettoolbarrepository.d.ts +98 -0
- package/src/widgettoolbarrepository.js +274 -0
- package/src/widgettypearound/utils.d.ts +38 -0
- package/src/widgettypearound/utils.js +52 -0
- package/src/widgettypearound/widgettypearound.d.ts +233 -0
- package/src/widgettypearound/widgettypearound.js +779 -0
- package/theme/icons/drag-handle.svg +1 -0
- package/theme/icons/return-arrow.svg +1 -0
- package/theme/widget.css +91 -0
- package/theme/widgetresize.css +43 -0
- package/theme/widgettypearound.css +113 -0
@@ -0,0 +1,129 @@
|
|
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 widget/widgetresize/resizerstate
|
7
|
+
*/
|
8
|
+
import { ObservableMixin, Rect } from '@ckeditor/ckeditor5-utils';
|
9
|
+
import { calculateResizeHostPercentageWidth } from '../utils.js';
|
10
|
+
/**
|
11
|
+
* Stores the internal state of a single resizable object.
|
12
|
+
*/
|
13
|
+
export default class ResizeState extends /* #__PURE__ */ ObservableMixin() {
|
14
|
+
/**
|
15
|
+
* @param options Resizer options.
|
16
|
+
*/
|
17
|
+
constructor(options) {
|
18
|
+
super();
|
19
|
+
this.set('activeHandlePosition', null);
|
20
|
+
this.set('proposedWidthPercents', null);
|
21
|
+
this.set('proposedWidth', null);
|
22
|
+
this.set('proposedHeight', null);
|
23
|
+
this.set('proposedHandleHostWidth', null);
|
24
|
+
this.set('proposedHandleHostHeight', null);
|
25
|
+
this._options = options;
|
26
|
+
this._referenceCoordinates = null;
|
27
|
+
}
|
28
|
+
/**
|
29
|
+
* The original width (pixels) of the resized object when the resize process was started.
|
30
|
+
*/
|
31
|
+
get originalWidth() {
|
32
|
+
return this._originalWidth;
|
33
|
+
}
|
34
|
+
/**
|
35
|
+
* The original height (pixels) of the resized object when the resize process was started.
|
36
|
+
*/
|
37
|
+
get originalHeight() {
|
38
|
+
return this._originalHeight;
|
39
|
+
}
|
40
|
+
/**
|
41
|
+
* The original width (percents) of the resized object when the resize process was started.
|
42
|
+
*/
|
43
|
+
get originalWidthPercents() {
|
44
|
+
return this._originalWidthPercents;
|
45
|
+
}
|
46
|
+
/**
|
47
|
+
* A width to height ratio of the resized image.
|
48
|
+
*/
|
49
|
+
get aspectRatio() {
|
50
|
+
return this._aspectRatio;
|
51
|
+
}
|
52
|
+
/**
|
53
|
+
*
|
54
|
+
* @param domResizeHandle The handle used to calculate the reference point.
|
55
|
+
*/
|
56
|
+
begin(domResizeHandle, domHandleHost, domResizeHost) {
|
57
|
+
const clientRect = new Rect(domHandleHost);
|
58
|
+
this.activeHandlePosition = getHandlePosition(domResizeHandle);
|
59
|
+
this._referenceCoordinates = getAbsoluteBoundaryPoint(domHandleHost, getOppositePosition(this.activeHandlePosition));
|
60
|
+
this._originalWidth = clientRect.width;
|
61
|
+
this._originalHeight = clientRect.height;
|
62
|
+
this._aspectRatio = clientRect.width / clientRect.height;
|
63
|
+
const widthStyle = domResizeHost.style.width;
|
64
|
+
if (widthStyle && widthStyle.match(/^\d+(\.\d*)?%$/)) {
|
65
|
+
this._originalWidthPercents = parseFloat(widthStyle);
|
66
|
+
}
|
67
|
+
else {
|
68
|
+
this._originalWidthPercents = calculateResizeHostPercentageWidth(domResizeHost, clientRect);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
update(newSize) {
|
72
|
+
this.proposedWidth = newSize.width;
|
73
|
+
this.proposedHeight = newSize.height;
|
74
|
+
this.proposedWidthPercents = newSize.widthPercents;
|
75
|
+
this.proposedHandleHostWidth = newSize.handleHostWidth;
|
76
|
+
this.proposedHandleHostHeight = newSize.handleHostHeight;
|
77
|
+
}
|
78
|
+
}
|
79
|
+
/**
|
80
|
+
* Returns coordinates of the top-left corner of an element, relative to the document's top-left corner.
|
81
|
+
*
|
82
|
+
* @param resizerPosition The position of the resize handle, e.g. `"top-left"`, `"bottom-right"`.
|
83
|
+
*/
|
84
|
+
function getAbsoluteBoundaryPoint(element, resizerPosition) {
|
85
|
+
const elementRect = new Rect(element);
|
86
|
+
const positionParts = resizerPosition.split('-');
|
87
|
+
const ret = {
|
88
|
+
x: positionParts[1] == 'right' ? elementRect.right : elementRect.left,
|
89
|
+
y: positionParts[0] == 'bottom' ? elementRect.bottom : elementRect.top
|
90
|
+
};
|
91
|
+
ret.x += element.ownerDocument.defaultView.scrollX;
|
92
|
+
ret.y += element.ownerDocument.defaultView.scrollY;
|
93
|
+
return ret;
|
94
|
+
}
|
95
|
+
/**
|
96
|
+
* @param resizerPosition The expected resizer position, like `"top-left"`, `"bottom-right"`.
|
97
|
+
* @returns A prefixed HTML class name for the resizer element.
|
98
|
+
*/
|
99
|
+
function getResizerHandleClass(resizerPosition) {
|
100
|
+
return `ck-widget__resizer__handle-${resizerPosition}`;
|
101
|
+
}
|
102
|
+
/**
|
103
|
+
* Determines the position of a given resize handle.
|
104
|
+
*
|
105
|
+
* @param domHandle Handle used to calculate the reference point.
|
106
|
+
* @returns Returns a string like `"top-left"` or `undefined` if not matched.
|
107
|
+
*/
|
108
|
+
function getHandlePosition(domHandle) {
|
109
|
+
const resizerPositions = ['top-left', 'top-right', 'bottom-right', 'bottom-left'];
|
110
|
+
for (const position of resizerPositions) {
|
111
|
+
if (domHandle.classList.contains(getResizerHandleClass(position))) {
|
112
|
+
return position;
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}
|
116
|
+
/**
|
117
|
+
* @param position Like `"top-left"`.
|
118
|
+
* @returns Inverted `position`, e.g. it returns `"bottom-right"` if `"top-left"` was given as `position`.
|
119
|
+
*/
|
120
|
+
function getOppositePosition(position) {
|
121
|
+
const parts = position.split('-');
|
122
|
+
const replacements = {
|
123
|
+
top: 'bottom',
|
124
|
+
bottom: 'top',
|
125
|
+
left: 'right',
|
126
|
+
right: 'left'
|
127
|
+
};
|
128
|
+
return `${replacements[parts[0]]}-${replacements[parts[1]]}`;
|
129
|
+
}
|
@@ -0,0 +1,55 @@
|
|
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 widget/widgetresize/sizeview
|
7
|
+
*/
|
8
|
+
import { View } from '@ckeditor/ckeditor5-ui';
|
9
|
+
import type { ResizerOptions } from '../widgetresize.js';
|
10
|
+
import type ResizeState from './resizerstate.js';
|
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
|
+
}
|
@@ -0,0 +1,63 @@
|
|
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 widget/widgetresize/sizeview
|
7
|
+
*/
|
8
|
+
import { View } from '@ckeditor/ckeditor5-ui';
|
9
|
+
/**
|
10
|
+
* A view displaying the proposed new element size during the resizing.
|
11
|
+
*/
|
12
|
+
export default class SizeView extends View {
|
13
|
+
constructor() {
|
14
|
+
super();
|
15
|
+
const bind = this.bindTemplate;
|
16
|
+
this.setTemplate({
|
17
|
+
tag: 'div',
|
18
|
+
attributes: {
|
19
|
+
class: [
|
20
|
+
'ck',
|
21
|
+
'ck-size-view',
|
22
|
+
bind.to('_viewPosition', value => value ? `ck-orientation-${value}` : '')
|
23
|
+
],
|
24
|
+
style: {
|
25
|
+
display: bind.if('_isVisible', 'none', visible => !visible)
|
26
|
+
}
|
27
|
+
},
|
28
|
+
children: [{
|
29
|
+
text: bind.to('_label')
|
30
|
+
}]
|
31
|
+
});
|
32
|
+
}
|
33
|
+
/**
|
34
|
+
* A method used for binding the `SizeView` instance properties to the `ResizeState` instance observable properties.
|
35
|
+
*
|
36
|
+
* @internal
|
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.
|
39
|
+
*/
|
40
|
+
_bindToState(options, resizeState) {
|
41
|
+
this.bind('_isVisible').to(resizeState, 'proposedWidth', resizeState, 'proposedHeight', (width, height) => width !== null && height !== null);
|
42
|
+
this.bind('_label').to(resizeState, 'proposedHandleHostWidth', resizeState, 'proposedHandleHostHeight', resizeState, 'proposedWidthPercents', (width, height, widthPercents) => {
|
43
|
+
if (options.unit === 'px') {
|
44
|
+
return `${width}×${height}`;
|
45
|
+
}
|
46
|
+
else {
|
47
|
+
return `${widthPercents}%`;
|
48
|
+
}
|
49
|
+
});
|
50
|
+
this.bind('_viewPosition').to(resizeState, 'activeHandlePosition', resizeState, 'proposedHandleHostWidth', resizeState, 'proposedHandleHostHeight',
|
51
|
+
// If the widget is too small to contain the size label, display the label above.
|
52
|
+
(position, width, height) => width < 50 || height < 50 ? 'above-center' : position);
|
53
|
+
}
|
54
|
+
/**
|
55
|
+
* A method used for cleaning up. It removes the bindings and hides the view.
|
56
|
+
*
|
57
|
+
* @internal
|
58
|
+
*/
|
59
|
+
_dismiss() {
|
60
|
+
this.unbind();
|
61
|
+
this._isVisible = false;
|
62
|
+
}
|
63
|
+
}
|
@@ -0,0 +1,129 @@
|
|
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 widget/widgetresize
|
7
|
+
*/
|
8
|
+
import Resizer from './widgetresize/resizer.js';
|
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
|
+
static get isOfficialPlugin(): true;
|
47
|
+
/**
|
48
|
+
* @inheritDoc
|
49
|
+
*/
|
50
|
+
init(): void;
|
51
|
+
/**
|
52
|
+
* Redraws the selected resizer if there is any selected resizer and if it is visible.
|
53
|
+
*/
|
54
|
+
redrawSelectedResizer(): void;
|
55
|
+
/**
|
56
|
+
* @inheritDoc
|
57
|
+
*/
|
58
|
+
destroy(): void;
|
59
|
+
/**
|
60
|
+
* Marks resizer as selected.
|
61
|
+
*/
|
62
|
+
select(resizer: Resizer): void;
|
63
|
+
/**
|
64
|
+
* Deselects currently set resizer.
|
65
|
+
*/
|
66
|
+
deselect(): void;
|
67
|
+
/**
|
68
|
+
* @param options Resizer options.
|
69
|
+
*/
|
70
|
+
attachTo(options: ResizerOptions): Resizer;
|
71
|
+
/**
|
72
|
+
* Returns a resizer created for a given view element (widget element).
|
73
|
+
*
|
74
|
+
* @param viewElement View element associated with the resizer.
|
75
|
+
*/
|
76
|
+
getResizerByViewElement(viewElement: ViewContainerElement): Resizer | undefined;
|
77
|
+
/**
|
78
|
+
* Returns a resizer that contains a given resize handle.
|
79
|
+
*/
|
80
|
+
private _getResizerByHandle;
|
81
|
+
/**
|
82
|
+
* @param domEventData Native DOM event.
|
83
|
+
*/
|
84
|
+
private _mouseDownListener;
|
85
|
+
/**
|
86
|
+
* @param domEventData Native DOM event.
|
87
|
+
*/
|
88
|
+
private _mouseMoveListener;
|
89
|
+
private _mouseUpListener;
|
90
|
+
}
|
91
|
+
/**
|
92
|
+
* Interface describing a resizer. It allows to specify the resizing host, custom logic for calculating aspect ratio, etc.
|
93
|
+
*/
|
94
|
+
export interface ResizerOptions {
|
95
|
+
/**
|
96
|
+
* Editor instance associated with the resizer.
|
97
|
+
*/
|
98
|
+
editor: Editor;
|
99
|
+
modelElement: Element;
|
100
|
+
/**
|
101
|
+
* A view of an element to be resized. Typically it's the main widget's view instance.
|
102
|
+
*/
|
103
|
+
viewElement: ViewContainerElement;
|
104
|
+
unit?: 'px' | '%';
|
105
|
+
/**
|
106
|
+
* A callback to be executed once the resizing process is done.
|
107
|
+
*
|
108
|
+
* It receives a `Number` (`newValue`) as a parameter.
|
109
|
+
*
|
110
|
+
* For example, {@link module:image/imageresize~ImageResize} uses it to execute the resize image command
|
111
|
+
* which puts the new value into the model.
|
112
|
+
*
|
113
|
+
* ```ts
|
114
|
+
* {
|
115
|
+
* editor,
|
116
|
+
* modelElement: data.item,
|
117
|
+
* viewElement: widget,
|
118
|
+
*
|
119
|
+
* onCommit( newValue ) {
|
120
|
+
* editor.execute( 'resizeImage', { width: newValue } );
|
121
|
+
* }
|
122
|
+
* };
|
123
|
+
* ```
|
124
|
+
*/
|
125
|
+
onCommit: (newValue: string) => void;
|
126
|
+
getResizeHost: (widgetWrapper: HTMLElement) => HTMLElement;
|
127
|
+
getHandleHost: (widgetWrapper: HTMLElement) => HTMLElement;
|
128
|
+
isCentered?: (resizer: Resizer) => boolean;
|
129
|
+
}
|
@@ -0,0 +1,194 @@
|
|
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 widget/widgetresize
|
7
|
+
*/
|
8
|
+
import Resizer from './widgetresize/resizer.js';
|
9
|
+
import { Plugin } from '@ckeditor/ckeditor5-core';
|
10
|
+
import { MouseObserver } from '@ckeditor/ckeditor5-engine';
|
11
|
+
import { DomEmitterMixin, global } from '@ckeditor/ckeditor5-utils';
|
12
|
+
import { throttle } from 'lodash-es';
|
13
|
+
import '../theme/widgetresize.css';
|
14
|
+
/**
|
15
|
+
* The widget resize feature plugin.
|
16
|
+
*
|
17
|
+
* Use the {@link module:widget/widgetresize~WidgetResize#attachTo} method to create a resizer for the specified widget.
|
18
|
+
*/
|
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
|
+
}
|
27
|
+
/**
|
28
|
+
* @inheritDoc
|
29
|
+
*/
|
30
|
+
static get pluginName() {
|
31
|
+
return 'WidgetResize';
|
32
|
+
}
|
33
|
+
/**
|
34
|
+
* @inheritDoc
|
35
|
+
*/
|
36
|
+
static get isOfficialPlugin() {
|
37
|
+
return true;
|
38
|
+
}
|
39
|
+
/**
|
40
|
+
* @inheritDoc
|
41
|
+
*/
|
42
|
+
init() {
|
43
|
+
const editing = this.editor.editing;
|
44
|
+
const domDocument = global.window.document;
|
45
|
+
this.set('selectedResizer', null);
|
46
|
+
this.set('_activeResizer', null);
|
47
|
+
editing.view.addObserver(MouseObserver);
|
48
|
+
this._observer = new (DomEmitterMixin())();
|
49
|
+
this.listenTo(editing.view.document, 'mousedown', this._mouseDownListener.bind(this), { priority: 'high' });
|
50
|
+
this._observer.listenTo(domDocument, 'mousemove', this._mouseMoveListener.bind(this));
|
51
|
+
this._observer.listenTo(domDocument, 'mouseup', this._mouseUpListener.bind(this));
|
52
|
+
this._redrawSelectedResizerThrottled = throttle(() => this.redrawSelectedResizer(), 200);
|
53
|
+
// Redrawing on any change of the UI of the editor (including content changes).
|
54
|
+
this.editor.ui.on('update', this._redrawSelectedResizerThrottled);
|
55
|
+
// Remove view widget-resizer mappings for widgets that have been removed from the document.
|
56
|
+
// https://github.com/ckeditor/ckeditor5/issues/10156
|
57
|
+
// https://github.com/ckeditor/ckeditor5/issues/10266
|
58
|
+
this.editor.model.document.on('change', () => {
|
59
|
+
for (const [viewElement, resizer] of this._resizers) {
|
60
|
+
if (!viewElement.isAttached()) {
|
61
|
+
this._resizers.delete(viewElement);
|
62
|
+
resizer.destroy();
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}, { priority: 'lowest' });
|
66
|
+
// Resizers need to be redrawn upon window resize, because new window might shrink resize host.
|
67
|
+
this._observer.listenTo(global.window, 'resize', this._redrawSelectedResizerThrottled);
|
68
|
+
const viewSelection = this.editor.editing.view.document.selection;
|
69
|
+
viewSelection.on('change', () => {
|
70
|
+
const selectedElement = viewSelection.getSelectedElement();
|
71
|
+
const resizer = this.getResizerByViewElement(selectedElement) || null;
|
72
|
+
if (resizer) {
|
73
|
+
this.select(resizer);
|
74
|
+
}
|
75
|
+
else {
|
76
|
+
this.deselect();
|
77
|
+
}
|
78
|
+
});
|
79
|
+
}
|
80
|
+
/**
|
81
|
+
* Redraws the selected resizer if there is any selected resizer and if it is visible.
|
82
|
+
*/
|
83
|
+
redrawSelectedResizer() {
|
84
|
+
if (this.selectedResizer && this.selectedResizer.isVisible) {
|
85
|
+
this.selectedResizer.redraw();
|
86
|
+
}
|
87
|
+
}
|
88
|
+
/**
|
89
|
+
* @inheritDoc
|
90
|
+
*/
|
91
|
+
destroy() {
|
92
|
+
super.destroy();
|
93
|
+
this._observer.stopListening();
|
94
|
+
for (const resizer of this._resizers.values()) {
|
95
|
+
resizer.destroy();
|
96
|
+
}
|
97
|
+
this._redrawSelectedResizerThrottled.cancel();
|
98
|
+
}
|
99
|
+
/**
|
100
|
+
* Marks resizer as selected.
|
101
|
+
*/
|
102
|
+
select(resizer) {
|
103
|
+
this.deselect();
|
104
|
+
this.selectedResizer = resizer;
|
105
|
+
this.selectedResizer.isSelected = true;
|
106
|
+
}
|
107
|
+
/**
|
108
|
+
* Deselects currently set resizer.
|
109
|
+
*/
|
110
|
+
deselect() {
|
111
|
+
if (this.selectedResizer) {
|
112
|
+
this.selectedResizer.isSelected = false;
|
113
|
+
}
|
114
|
+
this.selectedResizer = null;
|
115
|
+
}
|
116
|
+
/**
|
117
|
+
* @param options Resizer options.
|
118
|
+
*/
|
119
|
+
attachTo(options) {
|
120
|
+
const resizer = new Resizer(options);
|
121
|
+
const plugins = this.editor.plugins;
|
122
|
+
resizer.attach();
|
123
|
+
if (plugins.has('WidgetToolbarRepository')) {
|
124
|
+
// Hiding widget toolbar to improve the performance
|
125
|
+
// (https://github.com/ckeditor/ckeditor5-widget/pull/112#issuecomment-564528765).
|
126
|
+
const widgetToolbarRepository = plugins.get('WidgetToolbarRepository');
|
127
|
+
resizer.on('begin', () => {
|
128
|
+
widgetToolbarRepository.forceDisabled('resize');
|
129
|
+
}, { priority: 'lowest' });
|
130
|
+
resizer.on('cancel', () => {
|
131
|
+
widgetToolbarRepository.clearForceDisabled('resize');
|
132
|
+
}, { priority: 'highest' });
|
133
|
+
resizer.on('commit', () => {
|
134
|
+
widgetToolbarRepository.clearForceDisabled('resize');
|
135
|
+
}, { priority: 'highest' });
|
136
|
+
}
|
137
|
+
this._resizers.set(options.viewElement, resizer);
|
138
|
+
const viewSelection = this.editor.editing.view.document.selection;
|
139
|
+
const selectedElement = viewSelection.getSelectedElement();
|
140
|
+
// If the element the resizer is created for is currently focused, it should become visible.
|
141
|
+
if (this.getResizerByViewElement(selectedElement) == resizer) {
|
142
|
+
this.select(resizer);
|
143
|
+
}
|
144
|
+
return resizer;
|
145
|
+
}
|
146
|
+
/**
|
147
|
+
* Returns a resizer created for a given view element (widget element).
|
148
|
+
*
|
149
|
+
* @param viewElement View element associated with the resizer.
|
150
|
+
*/
|
151
|
+
getResizerByViewElement(viewElement) {
|
152
|
+
return this._resizers.get(viewElement);
|
153
|
+
}
|
154
|
+
/**
|
155
|
+
* Returns a resizer that contains a given resize handle.
|
156
|
+
*/
|
157
|
+
_getResizerByHandle(domResizeHandle) {
|
158
|
+
for (const resizer of this._resizers.values()) {
|
159
|
+
if (resizer.containsHandle(domResizeHandle)) {
|
160
|
+
return resizer;
|
161
|
+
}
|
162
|
+
}
|
163
|
+
}
|
164
|
+
/**
|
165
|
+
* @param domEventData Native DOM event.
|
166
|
+
*/
|
167
|
+
_mouseDownListener(event, domEventData) {
|
168
|
+
const resizeHandle = domEventData.domTarget;
|
169
|
+
if (!Resizer.isResizeHandle(resizeHandle)) {
|
170
|
+
return;
|
171
|
+
}
|
172
|
+
this._activeResizer = this._getResizerByHandle(resizeHandle) || null;
|
173
|
+
if (this._activeResizer) {
|
174
|
+
this._activeResizer.begin(resizeHandle);
|
175
|
+
// Do not call other events when resizing. See: #6755.
|
176
|
+
event.stop();
|
177
|
+
domEventData.preventDefault();
|
178
|
+
}
|
179
|
+
}
|
180
|
+
/**
|
181
|
+
* @param domEventData Native DOM event.
|
182
|
+
*/
|
183
|
+
_mouseMoveListener(event, domEventData) {
|
184
|
+
if (this._activeResizer) {
|
185
|
+
this._activeResizer.updateSize(domEventData);
|
186
|
+
}
|
187
|
+
}
|
188
|
+
_mouseUpListener() {
|
189
|
+
if (this._activeResizer) {
|
190
|
+
this._activeResizer.commit();
|
191
|
+
this._activeResizer = null;
|
192
|
+
}
|
193
|
+
}
|
194
|
+
}
|
@@ -0,0 +1,98 @@
|
|
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 widget/widgettoolbarrepository
|
7
|
+
*/
|
8
|
+
import { Plugin, type ToolbarConfigItem } from '@ckeditor/ckeditor5-core';
|
9
|
+
import type { ViewDocumentSelection, ViewElement } from '@ckeditor/ckeditor5-engine';
|
10
|
+
import { ContextualBalloon } from '@ckeditor/ckeditor5-ui';
|
11
|
+
/**
|
12
|
+
* Widget toolbar repository plugin. A central point for registering widget toolbars. This plugin handles the whole
|
13
|
+
* toolbar rendering process and exposes a concise API.
|
14
|
+
*
|
15
|
+
* To add a toolbar for your widget use the {@link ~WidgetToolbarRepository#register `WidgetToolbarRepository#register()`} method.
|
16
|
+
*
|
17
|
+
* The following example comes from the {@link module:image/imagetoolbar~ImageToolbar} plugin:
|
18
|
+
*
|
19
|
+
* ```ts
|
20
|
+
* class ImageToolbar extends Plugin {
|
21
|
+
* static get requires() {
|
22
|
+
* return [ WidgetToolbarRepository ];
|
23
|
+
* }
|
24
|
+
*
|
25
|
+
* afterInit() {
|
26
|
+
* const editor = this.editor;
|
27
|
+
* const widgetToolbarRepository = editor.plugins.get( WidgetToolbarRepository );
|
28
|
+
*
|
29
|
+
* widgetToolbarRepository.register( 'image', {
|
30
|
+
* items: editor.config.get( 'image.toolbar' ),
|
31
|
+
* getRelatedElement: getClosestSelectedImageWidget
|
32
|
+
* } );
|
33
|
+
* }
|
34
|
+
* }
|
35
|
+
* ```
|
36
|
+
*/
|
37
|
+
export default class WidgetToolbarRepository extends Plugin {
|
38
|
+
/**
|
39
|
+
* A map of toolbar definitions.
|
40
|
+
*/
|
41
|
+
private _toolbarDefinitions;
|
42
|
+
private _balloon;
|
43
|
+
/**
|
44
|
+
* @inheritDoc
|
45
|
+
*/
|
46
|
+
static get requires(): readonly [typeof ContextualBalloon];
|
47
|
+
/**
|
48
|
+
* @inheritDoc
|
49
|
+
*/
|
50
|
+
static get pluginName(): "WidgetToolbarRepository";
|
51
|
+
/**
|
52
|
+
* @inheritDoc
|
53
|
+
*/
|
54
|
+
static get isOfficialPlugin(): true;
|
55
|
+
/**
|
56
|
+
* @inheritDoc
|
57
|
+
*/
|
58
|
+
init(): void;
|
59
|
+
destroy(): void;
|
60
|
+
/**
|
61
|
+
* Registers toolbar in the WidgetToolbarRepository. It renders it in the `ContextualBalloon` based on the value of the invoked
|
62
|
+
* `getRelatedElement` function. Toolbar items are gathered from `items` array.
|
63
|
+
* The balloon's CSS class is by default `ck-toolbar-container` and may be override with the `balloonClassName` option.
|
64
|
+
*
|
65
|
+
* Note: This method should be called in the {@link module:core/plugin~PluginInterface#afterInit `Plugin#afterInit()`}
|
66
|
+
* callback (or later) to make sure that the given toolbar items were already registered by other plugins.
|
67
|
+
*
|
68
|
+
* @param toolbarId An id for the toolbar. Used to
|
69
|
+
* @param options.ariaLabel Label used by assistive technologies to describe this toolbar element.
|
70
|
+
* @param options.items Array of toolbar items.
|
71
|
+
* @param options.getRelatedElement Callback which returns an element the toolbar should be attached to.
|
72
|
+
* @param options.balloonClassName CSS class for the widget balloon.
|
73
|
+
*/
|
74
|
+
register(toolbarId: string, { ariaLabel, items, getRelatedElement, balloonClassName }: {
|
75
|
+
ariaLabel?: string;
|
76
|
+
items: Array<ToolbarConfigItem>;
|
77
|
+
getRelatedElement: (selection: ViewDocumentSelection) => (ViewElement | null);
|
78
|
+
balloonClassName?: string;
|
79
|
+
}): void;
|
80
|
+
/**
|
81
|
+
* Iterates over stored toolbars and makes them visible or hidden.
|
82
|
+
*/
|
83
|
+
private _updateToolbarsVisibility;
|
84
|
+
/**
|
85
|
+
* Hides the given toolbar.
|
86
|
+
*/
|
87
|
+
private _hideToolbar;
|
88
|
+
/**
|
89
|
+
* Shows up the toolbar if the toolbar is not visible.
|
90
|
+
* Otherwise, repositions the toolbar's balloon when toolbar's view is the most top view in balloon stack.
|
91
|
+
*
|
92
|
+
* It might happen here that the toolbar's view is under another view. Then do nothing as the other toolbar view
|
93
|
+
* should be still visible after the {@link module:ui/editorui/editorui~EditorUI#event:update}.
|
94
|
+
*/
|
95
|
+
private _showToolbar;
|
96
|
+
private _isToolbarVisible;
|
97
|
+
private _isToolbarInBalloon;
|
98
|
+
}
|