@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,177 @@
|
|
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
|
+
import { Rect, type DecoratedMethodEvent } from '@ckeditor/ckeditor5-utils';
|
6
|
+
import ResizeState from './resizerstate.js';
|
7
|
+
import type { ResizerOptions } from '../widgetresize.js';
|
8
|
+
declare const Resizer_base: {
|
9
|
+
new (): import("@ckeditor/ckeditor5-utils").Observable;
|
10
|
+
prototype: import("@ckeditor/ckeditor5-utils").Observable;
|
11
|
+
};
|
12
|
+
/**
|
13
|
+
* Represents a resizer for a single resizable object.
|
14
|
+
*/
|
15
|
+
export default class Resizer extends /* #__PURE__ */ Resizer_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~ResizerOptions#viewElement viewElement} before the resizing started.
|
55
|
+
*/
|
56
|
+
private _initialViewWidth;
|
57
|
+
/**
|
58
|
+
* @param options Resizer options.
|
59
|
+
*/
|
60
|
+
constructor(options: ResizerOptions);
|
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(): ResizeState;
|
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;
|
160
|
+
}
|
161
|
+
/**
|
162
|
+
* @eventName ~Resizer#begin
|
163
|
+
*/
|
164
|
+
export type ResizerBeginEvent = DecoratedMethodEvent<Resizer, 'begin'>;
|
165
|
+
/**
|
166
|
+
* @eventName ~Resizer#cancel
|
167
|
+
*/
|
168
|
+
export type ResizerCancelEvent = DecoratedMethodEvent<Resizer, 'cancel'>;
|
169
|
+
/**
|
170
|
+
* @eventName ~Resizer#commit
|
171
|
+
*/
|
172
|
+
export type ResizerCommitEvent = DecoratedMethodEvent<Resizer, 'commit'>;
|
173
|
+
/**
|
174
|
+
* @eventName ~Resizer#updateSize
|
175
|
+
*/
|
176
|
+
export type ResizerUpdateSizeEvent = DecoratedMethodEvent<Resizer, 'updateSize'>;
|
177
|
+
export {};
|
@@ -0,0 +1,372 @@
|
|
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/resizer
|
7
|
+
*/
|
8
|
+
import { Template } from '@ckeditor/ckeditor5-ui';
|
9
|
+
import { Rect, ObservableMixin, compareArrays } from '@ckeditor/ckeditor5-utils';
|
10
|
+
import ResizeState from './resizerstate.js';
|
11
|
+
import SizeView from './sizeview.js';
|
12
|
+
/**
|
13
|
+
* Represents a resizer for a single resizable object.
|
14
|
+
*/
|
15
|
+
export default class Resizer extends /* #__PURE__ */ ObservableMixin() {
|
16
|
+
/**
|
17
|
+
* @param options Resizer options.
|
18
|
+
*/
|
19
|
+
constructor(options) {
|
20
|
+
super();
|
21
|
+
/**
|
22
|
+
* A wrapper that is controlled by the resizer. This is usually a widget element.
|
23
|
+
*/
|
24
|
+
this._viewResizerWrapper = null;
|
25
|
+
this._options = options;
|
26
|
+
this.set('isEnabled', true);
|
27
|
+
this.set('isSelected', false);
|
28
|
+
this.bind('isVisible').to(this, 'isEnabled', this, 'isSelected', (isEnabled, isSelected) => isEnabled && isSelected);
|
29
|
+
this.decorate('begin');
|
30
|
+
this.decorate('cancel');
|
31
|
+
this.decorate('commit');
|
32
|
+
this.decorate('updateSize');
|
33
|
+
this.on('commit', event => {
|
34
|
+
// State might not be initialized yet. In this case, prevent further handling and make sure that the resizer is
|
35
|
+
// cleaned up (#5195).
|
36
|
+
if (!this.state.proposedWidth && !this.state.proposedWidthPercents) {
|
37
|
+
this._cleanup();
|
38
|
+
event.stop();
|
39
|
+
}
|
40
|
+
}, { priority: 'high' });
|
41
|
+
}
|
42
|
+
/**
|
43
|
+
* Stores the state of the resizable host geometry, such as the original width, the currently proposed height, etc.
|
44
|
+
*
|
45
|
+
* Note that a new state is created for each resize transaction.
|
46
|
+
*/
|
47
|
+
get state() {
|
48
|
+
return this._state;
|
49
|
+
}
|
50
|
+
/**
|
51
|
+
* Makes resizer visible in the UI.
|
52
|
+
*/
|
53
|
+
show() {
|
54
|
+
const editingView = this._options.editor.editing.view;
|
55
|
+
editingView.change(writer => {
|
56
|
+
writer.removeClass('ck-hidden', this._viewResizerWrapper);
|
57
|
+
});
|
58
|
+
}
|
59
|
+
/**
|
60
|
+
* Hides resizer in the UI.
|
61
|
+
*/
|
62
|
+
hide() {
|
63
|
+
const editingView = this._options.editor.editing.view;
|
64
|
+
editingView.change(writer => {
|
65
|
+
writer.addClass('ck-hidden', this._viewResizerWrapper);
|
66
|
+
});
|
67
|
+
}
|
68
|
+
/**
|
69
|
+
* Attaches the resizer to the DOM.
|
70
|
+
*/
|
71
|
+
attach() {
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
73
|
+
const that = this;
|
74
|
+
const widgetElement = this._options.viewElement;
|
75
|
+
const editingView = this._options.editor.editing.view;
|
76
|
+
editingView.change(writer => {
|
77
|
+
const viewResizerWrapper = writer.createUIElement('div', {
|
78
|
+
class: 'ck ck-reset_all ck-widget__resizer'
|
79
|
+
}, function (domDocument) {
|
80
|
+
const domElement = this.toDomElement(domDocument);
|
81
|
+
that._appendHandles(domElement);
|
82
|
+
that._appendSizeUI(domElement);
|
83
|
+
return domElement;
|
84
|
+
});
|
85
|
+
// Append the resizer wrapper to the widget's wrapper.
|
86
|
+
writer.insert(writer.createPositionAt(widgetElement, 'end'), viewResizerWrapper);
|
87
|
+
writer.addClass('ck-widget_with-resizer', widgetElement);
|
88
|
+
this._viewResizerWrapper = viewResizerWrapper;
|
89
|
+
if (!this.isVisible) {
|
90
|
+
this.hide();
|
91
|
+
}
|
92
|
+
});
|
93
|
+
this.on('change:isVisible', () => {
|
94
|
+
if (this.isVisible) {
|
95
|
+
this.show();
|
96
|
+
this.redraw();
|
97
|
+
}
|
98
|
+
else {
|
99
|
+
this.hide();
|
100
|
+
}
|
101
|
+
});
|
102
|
+
}
|
103
|
+
/**
|
104
|
+
* Starts the resizing process.
|
105
|
+
*
|
106
|
+
* Creates a new {@link #state} for the current process.
|
107
|
+
*
|
108
|
+
* @fires begin
|
109
|
+
* @param domResizeHandle Clicked handle.
|
110
|
+
*/
|
111
|
+
begin(domResizeHandle) {
|
112
|
+
this._state = new ResizeState(this._options);
|
113
|
+
this._sizeView._bindToState(this._options, this.state);
|
114
|
+
this._initialViewWidth = this._options.viewElement.getStyle('width');
|
115
|
+
this.state.begin(domResizeHandle, this._getHandleHost(), this._getResizeHost());
|
116
|
+
}
|
117
|
+
/**
|
118
|
+
* Updates the proposed size based on `domEventData`.
|
119
|
+
*
|
120
|
+
* @fires updateSize
|
121
|
+
*/
|
122
|
+
updateSize(domEventData) {
|
123
|
+
const newSize = this._proposeNewSize(domEventData);
|
124
|
+
const editingView = this._options.editor.editing.view;
|
125
|
+
editingView.change(writer => {
|
126
|
+
const unit = this._options.unit || '%';
|
127
|
+
const newWidth = (unit === '%' ? newSize.widthPercents : newSize.width) + unit;
|
128
|
+
writer.setStyle('width', newWidth, this._options.viewElement);
|
129
|
+
});
|
130
|
+
// Get an actual image width, and:
|
131
|
+
// * reflect this size to the resize wrapper
|
132
|
+
// * apply this **real** size to the state
|
133
|
+
const domHandleHost = this._getHandleHost();
|
134
|
+
const domHandleHostRect = new Rect(domHandleHost);
|
135
|
+
const handleHostWidth = Math.round(domHandleHostRect.width);
|
136
|
+
const handleHostHeight = Math.round(domHandleHostRect.height);
|
137
|
+
// Handle max-width limitation.
|
138
|
+
const domResizeHostRect = new Rect(domHandleHost);
|
139
|
+
newSize.width = Math.round(domResizeHostRect.width);
|
140
|
+
newSize.height = Math.round(domResizeHostRect.height);
|
141
|
+
this.redraw(domHandleHostRect);
|
142
|
+
this.state.update({
|
143
|
+
...newSize,
|
144
|
+
handleHostWidth,
|
145
|
+
handleHostHeight
|
146
|
+
});
|
147
|
+
}
|
148
|
+
/**
|
149
|
+
* Applies the geometry proposed with the resizer.
|
150
|
+
*
|
151
|
+
* @fires commit
|
152
|
+
*/
|
153
|
+
commit() {
|
154
|
+
const unit = this._options.unit || '%';
|
155
|
+
const newValue = (unit === '%' ? this.state.proposedWidthPercents : this.state.proposedWidth) + unit;
|
156
|
+
// Both cleanup and onCommit callback are very likely to make view changes. Ensure that it is made in a single step.
|
157
|
+
this._options.editor.editing.view.change(() => {
|
158
|
+
this._cleanup();
|
159
|
+
this._options.onCommit(newValue);
|
160
|
+
});
|
161
|
+
}
|
162
|
+
/**
|
163
|
+
* Cancels and rejects the proposed resize dimensions, hiding the UI.
|
164
|
+
*
|
165
|
+
* @fires cancel
|
166
|
+
*/
|
167
|
+
cancel() {
|
168
|
+
this._cleanup();
|
169
|
+
}
|
170
|
+
/**
|
171
|
+
* Destroys the resizer.
|
172
|
+
*/
|
173
|
+
destroy() {
|
174
|
+
this.cancel();
|
175
|
+
}
|
176
|
+
/**
|
177
|
+
* Redraws the resizer.
|
178
|
+
*
|
179
|
+
* @param handleHostRect Handle host rectangle might be given to improve performance.
|
180
|
+
*/
|
181
|
+
redraw(handleHostRect) {
|
182
|
+
const domWrapper = this._domResizerWrapper;
|
183
|
+
// Refresh only if resizer exists in the DOM.
|
184
|
+
if (!existsInDom(domWrapper)) {
|
185
|
+
return;
|
186
|
+
}
|
187
|
+
const widgetWrapper = domWrapper.parentElement;
|
188
|
+
const handleHost = this._getHandleHost();
|
189
|
+
const resizerWrapper = this._viewResizerWrapper;
|
190
|
+
const currentDimensions = [
|
191
|
+
resizerWrapper.getStyle('width'),
|
192
|
+
resizerWrapper.getStyle('height'),
|
193
|
+
resizerWrapper.getStyle('left'),
|
194
|
+
resizerWrapper.getStyle('top')
|
195
|
+
];
|
196
|
+
let newDimensions;
|
197
|
+
if (widgetWrapper.isSameNode(handleHost)) {
|
198
|
+
const clientRect = handleHostRect || new Rect(handleHost);
|
199
|
+
newDimensions = [
|
200
|
+
clientRect.width + 'px',
|
201
|
+
clientRect.height + 'px',
|
202
|
+
undefined,
|
203
|
+
undefined
|
204
|
+
];
|
205
|
+
}
|
206
|
+
// In case a resizing host is not a widget wrapper, we need to compensate
|
207
|
+
// for any additional offsets the resize host might have. E.g. wrapper padding
|
208
|
+
// or simply another editable. By doing that the border and resizers are shown
|
209
|
+
// only around the resize host.
|
210
|
+
else {
|
211
|
+
newDimensions = [
|
212
|
+
handleHost.offsetWidth + 'px',
|
213
|
+
handleHost.offsetHeight + 'px',
|
214
|
+
handleHost.offsetLeft + 'px',
|
215
|
+
handleHost.offsetTop + 'px'
|
216
|
+
];
|
217
|
+
}
|
218
|
+
// Make changes to the view only if the resizer should actually get new dimensions.
|
219
|
+
// Otherwise, if View#change() was always called, this would cause EditorUI#update
|
220
|
+
// loops because the WidgetResize plugin listens to EditorUI#update and updates
|
221
|
+
// the resizer.
|
222
|
+
// https://github.com/ckeditor/ckeditor5/issues/7633
|
223
|
+
if (compareArrays(currentDimensions, newDimensions) !== 'same') {
|
224
|
+
this._options.editor.editing.view.change(writer => {
|
225
|
+
writer.setStyle({
|
226
|
+
width: newDimensions[0],
|
227
|
+
height: newDimensions[1],
|
228
|
+
left: newDimensions[2],
|
229
|
+
top: newDimensions[3]
|
230
|
+
}, resizerWrapper);
|
231
|
+
});
|
232
|
+
}
|
233
|
+
}
|
234
|
+
containsHandle(domElement) {
|
235
|
+
return this._domResizerWrapper.contains(domElement);
|
236
|
+
}
|
237
|
+
static isResizeHandle(domElement) {
|
238
|
+
return domElement.classList.contains('ck-widget__resizer__handle');
|
239
|
+
}
|
240
|
+
/**
|
241
|
+
* Cleans up the context state.
|
242
|
+
*/
|
243
|
+
_cleanup() {
|
244
|
+
this._sizeView._dismiss();
|
245
|
+
const editingView = this._options.editor.editing.view;
|
246
|
+
editingView.change(writer => {
|
247
|
+
writer.setStyle('width', this._initialViewWidth, this._options.viewElement);
|
248
|
+
});
|
249
|
+
}
|
250
|
+
/**
|
251
|
+
* Calculates the proposed size as the resize handles are dragged.
|
252
|
+
*
|
253
|
+
* @param domEventData Event data that caused the size update request. It should be used to calculate the proposed size.
|
254
|
+
*/
|
255
|
+
_proposeNewSize(domEventData) {
|
256
|
+
const state = this.state;
|
257
|
+
const currentCoordinates = extractCoordinates(domEventData);
|
258
|
+
const isCentered = this._options.isCentered ? this._options.isCentered(this) : true;
|
259
|
+
// Enlargement defines how much the resize host has changed in a given axis. Naturally it could be a negative number
|
260
|
+
// meaning that it has been shrunk.
|
261
|
+
//
|
262
|
+
// +----------------+--+
|
263
|
+
// | | |
|
264
|
+
// | img | |
|
265
|
+
// | /handle host | |
|
266
|
+
// +----------------+ | ^
|
267
|
+
// | | | - enlarge y
|
268
|
+
// +-------------------+ v
|
269
|
+
// <-->
|
270
|
+
// enlarge x
|
271
|
+
const enlargement = {
|
272
|
+
x: state._referenceCoordinates.x - (currentCoordinates.x + state.originalWidth),
|
273
|
+
y: (currentCoordinates.y - state.originalHeight) - state._referenceCoordinates.y
|
274
|
+
};
|
275
|
+
if (isCentered && state.activeHandlePosition.endsWith('-right')) {
|
276
|
+
enlargement.x = currentCoordinates.x - (state._referenceCoordinates.x + state.originalWidth);
|
277
|
+
}
|
278
|
+
// Objects needs to be resized twice as much in horizontal axis if centered, since enlargement is counted from
|
279
|
+
// one resized corner to your cursor. It needs to be duplicated to compensate for the other side too.
|
280
|
+
if (isCentered) {
|
281
|
+
enlargement.x *= 2;
|
282
|
+
}
|
283
|
+
// const resizeHost = this._getResizeHost();
|
284
|
+
// The size proposed by the user. It does not consider the aspect ratio.
|
285
|
+
let width = Math.abs(state.originalWidth + enlargement.x);
|
286
|
+
let height = Math.abs(state.originalHeight + enlargement.y);
|
287
|
+
// Dominant determination must take the ratio into account.
|
288
|
+
const dominant = width / state.aspectRatio > height ? 'width' : 'height';
|
289
|
+
if (dominant == 'width') {
|
290
|
+
height = width / state.aspectRatio;
|
291
|
+
}
|
292
|
+
else {
|
293
|
+
width = height * state.aspectRatio;
|
294
|
+
}
|
295
|
+
return {
|
296
|
+
width: Math.round(width),
|
297
|
+
height: Math.round(height),
|
298
|
+
widthPercents: Math.min(Math.round(state.originalWidthPercents / state.originalWidth * width * 100) / 100, 100)
|
299
|
+
};
|
300
|
+
}
|
301
|
+
/**
|
302
|
+
* Obtains the resize host.
|
303
|
+
*
|
304
|
+
* Resize host is an object that receives dimensions which are the result of resizing.
|
305
|
+
*/
|
306
|
+
_getResizeHost() {
|
307
|
+
const widgetWrapper = this._domResizerWrapper.parentElement;
|
308
|
+
return this._options.getResizeHost(widgetWrapper);
|
309
|
+
}
|
310
|
+
/**
|
311
|
+
* Obtains the handle host.
|
312
|
+
*
|
313
|
+
* Handle host is an object that the handles are aligned to.
|
314
|
+
*
|
315
|
+
* Handle host will not always be an entire widget itself. Take an image as an example. The image widget
|
316
|
+
* contains an image and a caption. Only the image should be surrounded with handles.
|
317
|
+
*/
|
318
|
+
_getHandleHost() {
|
319
|
+
const widgetWrapper = this._domResizerWrapper.parentElement;
|
320
|
+
return this._options.getHandleHost(widgetWrapper);
|
321
|
+
}
|
322
|
+
/**
|
323
|
+
* DOM container of the entire resize UI.
|
324
|
+
*
|
325
|
+
* Note that this property will have a value only after the element bound with the resizer is rendered
|
326
|
+
* (otherwise `null`).
|
327
|
+
*/
|
328
|
+
get _domResizerWrapper() {
|
329
|
+
return this._options.editor.editing.view.domConverter.mapViewToDom(this._viewResizerWrapper);
|
330
|
+
}
|
331
|
+
/**
|
332
|
+
* Renders the resize handles in the DOM.
|
333
|
+
*
|
334
|
+
* @param domElement The resizer wrapper.
|
335
|
+
*/
|
336
|
+
_appendHandles(domElement) {
|
337
|
+
const resizerPositions = ['top-left', 'top-right', 'bottom-right', 'bottom-left'];
|
338
|
+
for (const currentPosition of resizerPositions) {
|
339
|
+
domElement.appendChild((new Template({
|
340
|
+
tag: 'div',
|
341
|
+
attributes: {
|
342
|
+
class: `ck-widget__resizer__handle ${getResizerClass(currentPosition)}`
|
343
|
+
}
|
344
|
+
}).render()));
|
345
|
+
}
|
346
|
+
}
|
347
|
+
/**
|
348
|
+
* Sets up the {@link #_sizeView} property and adds it to the passed `domElement`.
|
349
|
+
*/
|
350
|
+
_appendSizeUI(domElement) {
|
351
|
+
this._sizeView = new SizeView();
|
352
|
+
// Make sure icon#element is rendered before passing to appendChild().
|
353
|
+
this._sizeView.render();
|
354
|
+
domElement.appendChild(this._sizeView.element);
|
355
|
+
}
|
356
|
+
}
|
357
|
+
/**
|
358
|
+
* @param resizerPosition Expected resizer position like `"top-left"`, `"bottom-right"`.
|
359
|
+
* @returns A prefixed HTML class name for the resizer element
|
360
|
+
*/
|
361
|
+
function getResizerClass(resizerPosition) {
|
362
|
+
return `ck-widget__resizer__handle-${resizerPosition}`;
|
363
|
+
}
|
364
|
+
function extractCoordinates(event) {
|
365
|
+
return {
|
366
|
+
x: event.pageX,
|
367
|
+
y: event.pageY
|
368
|
+
};
|
369
|
+
}
|
370
|
+
function existsInDom(element) {
|
371
|
+
return element && element.ownerDocument && element.ownerDocument.contains(element);
|
372
|
+
}
|
@@ -0,0 +1,125 @@
|
|
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
|
+
import type { ResizerOptions } from '../widgetresize.js';
|
6
|
+
declare const ResizeState_base: {
|
7
|
+
new (): import("@ckeditor/ckeditor5-utils").Observable;
|
8
|
+
prototype: import("@ckeditor/ckeditor5-utils").Observable;
|
9
|
+
};
|
10
|
+
/**
|
11
|
+
* Stores the internal state of a single resizable object.
|
12
|
+
*/
|
13
|
+
export default class ResizeState extends /* #__PURE__ */ ResizeState_base {
|
14
|
+
/**
|
15
|
+
* The position of the handle that initiated the resizing. E.g. `"top-left"`, `"bottom-right"` etc. or `null`
|
16
|
+
* if unknown.
|
17
|
+
*
|
18
|
+
* @readonly
|
19
|
+
* @observable
|
20
|
+
*/
|
21
|
+
activeHandlePosition: string | null;
|
22
|
+
/**
|
23
|
+
* The width (percents) proposed, but not committed yet, in the current resize process.
|
24
|
+
*
|
25
|
+
* @readonly
|
26
|
+
* @observable
|
27
|
+
*/
|
28
|
+
proposedWidthPercents: number | null;
|
29
|
+
/**
|
30
|
+
* The width (pixels) proposed, but not committed yet, in the current resize process.
|
31
|
+
*
|
32
|
+
* @readonly
|
33
|
+
* @observable
|
34
|
+
*/
|
35
|
+
proposedWidth: number | null;
|
36
|
+
/**
|
37
|
+
* The height (pixels) proposed, but not committed yet, in the current resize process.
|
38
|
+
*
|
39
|
+
* @readonly
|
40
|
+
* @observable
|
41
|
+
*/
|
42
|
+
proposedHeight: number | null;
|
43
|
+
/**
|
44
|
+
* @readonly
|
45
|
+
* @observable
|
46
|
+
*/
|
47
|
+
proposedHandleHostWidth: number | null;
|
48
|
+
/**
|
49
|
+
* @readonly
|
50
|
+
* @observable
|
51
|
+
*/
|
52
|
+
proposedHandleHostHeight: number | null;
|
53
|
+
/**
|
54
|
+
* The reference point of the resizer where the dragging started. It is used to measure the distance the user cursor
|
55
|
+
* traveled, so how much the image should be enlarged.
|
56
|
+
* This information is only known after the DOM was rendered, so it will be updated later.
|
57
|
+
*
|
58
|
+
* @internal
|
59
|
+
*/
|
60
|
+
_referenceCoordinates: {
|
61
|
+
x: number;
|
62
|
+
y: number;
|
63
|
+
} | null;
|
64
|
+
/**
|
65
|
+
* Resizer options.
|
66
|
+
*/
|
67
|
+
private readonly _options;
|
68
|
+
/**
|
69
|
+
* The original width (pixels) of the resized object when the resize process was started.
|
70
|
+
*
|
71
|
+
* @readonly
|
72
|
+
*/
|
73
|
+
private _originalWidth?;
|
74
|
+
/**
|
75
|
+
* The original height (pixels) of the resized object when the resize process was started.
|
76
|
+
*
|
77
|
+
* @readonly
|
78
|
+
*/
|
79
|
+
private _originalHeight?;
|
80
|
+
/**
|
81
|
+
* The original width (percents) of the resized object when the resize process was started.
|
82
|
+
*
|
83
|
+
* @readonly
|
84
|
+
*/
|
85
|
+
private _originalWidthPercents?;
|
86
|
+
/**
|
87
|
+
* A width to height ratio of the resized image.
|
88
|
+
*
|
89
|
+
* @readonly
|
90
|
+
*/
|
91
|
+
private _aspectRatio?;
|
92
|
+
/**
|
93
|
+
* @param options Resizer options.
|
94
|
+
*/
|
95
|
+
constructor(options: ResizerOptions);
|
96
|
+
/**
|
97
|
+
* The original width (pixels) of the resized object when the resize process was started.
|
98
|
+
*/
|
99
|
+
get originalWidth(): number | undefined;
|
100
|
+
/**
|
101
|
+
* The original height (pixels) of the resized object when the resize process was started.
|
102
|
+
*/
|
103
|
+
get originalHeight(): number | undefined;
|
104
|
+
/**
|
105
|
+
* The original width (percents) of the resized object when the resize process was started.
|
106
|
+
*/
|
107
|
+
get originalWidthPercents(): number | undefined;
|
108
|
+
/**
|
109
|
+
* A width to height ratio of the resized image.
|
110
|
+
*/
|
111
|
+
get aspectRatio(): number | undefined;
|
112
|
+
/**
|
113
|
+
*
|
114
|
+
* @param domResizeHandle The handle used to calculate the reference point.
|
115
|
+
*/
|
116
|
+
begin(domResizeHandle: HTMLElement, domHandleHost: HTMLElement, domResizeHost: HTMLElement): void;
|
117
|
+
update(newSize: {
|
118
|
+
width: number;
|
119
|
+
height: number;
|
120
|
+
widthPercents: number;
|
121
|
+
handleHostWidth: number;
|
122
|
+
handleHostHeight: number;
|
123
|
+
}): void;
|
124
|
+
}
|
125
|
+
export {};
|