@ckeditor/ckeditor5-widget 47.6.1 → 48.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/LICENSE.md +1 -1
- package/dist/index-editor.css +484 -122
- package/dist/index.css +479 -187
- package/dist/index.css.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +26 -46
- package/lang/contexts.json +0 -12
- package/lang/translations/af.po +0 -52
- package/lang/translations/ar.po +0 -52
- package/lang/translations/ast.po +0 -52
- package/lang/translations/az.po +0 -52
- package/lang/translations/be.po +0 -52
- package/lang/translations/bg.po +0 -52
- package/lang/translations/bn.po +0 -52
- package/lang/translations/bs.po +0 -52
- package/lang/translations/ca.po +0 -52
- package/lang/translations/cs.po +0 -52
- package/lang/translations/da.po +0 -52
- package/lang/translations/de-ch.po +0 -52
- package/lang/translations/de.po +0 -52
- package/lang/translations/el.po +0 -52
- package/lang/translations/en-au.po +0 -52
- package/lang/translations/en-gb.po +0 -52
- package/lang/translations/en.po +0 -52
- package/lang/translations/eo.po +0 -52
- package/lang/translations/es-co.po +0 -52
- package/lang/translations/es.po +0 -52
- package/lang/translations/et.po +0 -52
- package/lang/translations/eu.po +0 -52
- package/lang/translations/fa.po +0 -52
- package/lang/translations/fi.po +0 -52
- package/lang/translations/fr.po +0 -52
- package/lang/translations/gl.po +0 -52
- package/lang/translations/gu.po +0 -52
- package/lang/translations/he.po +0 -52
- package/lang/translations/hi.po +0 -52
- package/lang/translations/hr.po +0 -52
- package/lang/translations/hu.po +0 -52
- package/lang/translations/hy.po +0 -52
- package/lang/translations/id.po +0 -52
- package/lang/translations/it.po +0 -52
- package/lang/translations/ja.po +0 -52
- package/lang/translations/jv.po +0 -52
- package/lang/translations/kk.po +0 -52
- package/lang/translations/km.po +0 -52
- package/lang/translations/kn.po +0 -52
- package/lang/translations/ko.po +0 -52
- package/lang/translations/ku.po +0 -52
- package/lang/translations/lt.po +0 -52
- package/lang/translations/lv.po +0 -52
- package/lang/translations/ms.po +0 -52
- package/lang/translations/nb.po +0 -52
- package/lang/translations/ne.po +0 -52
- package/lang/translations/nl.po +0 -52
- package/lang/translations/no.po +0 -52
- package/lang/translations/oc.po +0 -52
- package/lang/translations/pl.po +0 -52
- package/lang/translations/pt-br.po +0 -52
- package/lang/translations/pt.po +0 -52
- package/lang/translations/ro.po +0 -52
- package/lang/translations/ru.po +0 -52
- package/lang/translations/si.po +0 -52
- package/lang/translations/sk.po +0 -52
- package/lang/translations/sl.po +0 -52
- package/lang/translations/sq.po +0 -52
- package/lang/translations/sr-latn.po +0 -52
- package/lang/translations/sr.po +0 -52
- package/lang/translations/sv.po +0 -52
- package/lang/translations/th.po +0 -52
- package/lang/translations/ti.po +0 -52
- package/lang/translations/tk.po +0 -52
- package/lang/translations/tr.po +0 -52
- package/lang/translations/tt.po +0 -52
- package/lang/translations/ug.po +0 -52
- package/lang/translations/uk.po +0 -52
- package/lang/translations/ur.po +0 -52
- package/lang/translations/uz.po +0 -52
- package/lang/translations/vi.po +0 -52
- package/lang/translations/zh-cn.po +0 -52
- package/lang/translations/zh.po +0 -52
- package/src/augmentation.js +0 -5
- package/src/highlightstack.js +0 -126
- package/src/index.js +0 -19
- package/src/utils.js +0 -414
- package/src/verticalnavigation.js +0 -185
- package/src/widget.js +0 -727
- package/src/widgetresize/resizer.js +0 -390
- package/src/widgetresize/resizerstate.js +0 -165
- package/src/widgetresize/sizeview.js +0 -65
- package/src/widgetresize.js +0 -193
- package/src/widgettoolbarrepository.js +0 -274
- package/src/widgettypearound/utils.js +0 -60
- package/src/widgettypearound/widgettypearound.js +0 -778
- package/theme/widget.css +0 -91
- package/theme/widgetresize.css +0 -43
- package/theme/widgettypearound.css +0 -119
- /package/{src → dist}/augmentation.d.ts +0 -0
- /package/{src → dist}/highlightstack.d.ts +0 -0
- /package/{src → dist}/index.d.ts +0 -0
- /package/{src → dist}/utils.d.ts +0 -0
- /package/{src → dist}/verticalnavigation.d.ts +0 -0
- /package/{src → dist}/widget.d.ts +0 -0
- /package/{src → dist}/widgetresize/resizer.d.ts +0 -0
- /package/{src → dist}/widgetresize/resizerstate.d.ts +0 -0
- /package/{src → dist}/widgetresize/sizeview.d.ts +0 -0
- /package/{src → dist}/widgetresize.d.ts +0 -0
- /package/{src → dist}/widgettoolbarrepository.d.ts +0 -0
- /package/{src → dist}/widgettypearound/utils.d.ts +0 -0
- /package/{src → dist}/widgettypearound/widgettypearound.d.ts +0 -0
package/src/widgetresize.js
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module widget/widgetresize
|
|
7
|
-
*/
|
|
8
|
-
import { WidgetResizer } 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 'es-toolkit/compat';
|
|
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 class WidgetResize extends Plugin {
|
|
20
|
-
/**
|
|
21
|
-
* A map of resizers created using this plugin instance.
|
|
22
|
-
*/
|
|
23
|
-
_resizers = new Map();
|
|
24
|
-
_observer;
|
|
25
|
-
_redrawSelectedResizerThrottled;
|
|
26
|
-
/**
|
|
27
|
-
* @inheritDoc
|
|
28
|
-
*/
|
|
29
|
-
static get pluginName() {
|
|
30
|
-
return 'WidgetResize';
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* @inheritDoc
|
|
34
|
-
*/
|
|
35
|
-
static get isOfficialPlugin() {
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* @inheritDoc
|
|
40
|
-
*/
|
|
41
|
-
init() {
|
|
42
|
-
const editing = this.editor.editing;
|
|
43
|
-
const domDocument = global.window.document;
|
|
44
|
-
this.set('selectedResizer', null);
|
|
45
|
-
this.set('_activeResizer', null);
|
|
46
|
-
editing.view.addObserver(MouseObserver);
|
|
47
|
-
this._observer = new (DomEmitterMixin())();
|
|
48
|
-
this.listenTo(editing.view.document, 'mousedown', this._mouseDownListener.bind(this), { priority: 'high' });
|
|
49
|
-
this._observer.listenTo(domDocument, 'mousemove', this._mouseMoveListener.bind(this));
|
|
50
|
-
this._observer.listenTo(domDocument, 'mouseup', this._mouseUpListener.bind(this));
|
|
51
|
-
this._redrawSelectedResizerThrottled = throttle(() => this.redrawSelectedResizer(), 200);
|
|
52
|
-
// Redrawing on any change of the UI of the editor (including content changes).
|
|
53
|
-
this.editor.ui.on('update', this._redrawSelectedResizerThrottled);
|
|
54
|
-
// Remove view widget-resizer mappings for widgets that have been removed from the document.
|
|
55
|
-
// https://github.com/ckeditor/ckeditor5/issues/10156
|
|
56
|
-
// https://github.com/ckeditor/ckeditor5/issues/10266
|
|
57
|
-
this.editor.model.document.on('change', () => {
|
|
58
|
-
for (const [viewElement, resizer] of this._resizers) {
|
|
59
|
-
if (!viewElement.isAttached()) {
|
|
60
|
-
this._resizers.delete(viewElement);
|
|
61
|
-
resizer.destroy();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}, { priority: 'lowest' });
|
|
65
|
-
// Resizers need to be redrawn upon window resize, because new window might shrink resize host.
|
|
66
|
-
this._observer.listenTo(global.window, 'resize', this._redrawSelectedResizerThrottled);
|
|
67
|
-
const viewSelection = this.editor.editing.view.document.selection;
|
|
68
|
-
viewSelection.on('change', () => {
|
|
69
|
-
const selectedElement = viewSelection.getSelectedElement();
|
|
70
|
-
const resizer = this.getResizerByViewElement(selectedElement) || null;
|
|
71
|
-
if (resizer) {
|
|
72
|
-
this.select(resizer);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
this.deselect();
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Redraws the selected resizer if there is any selected resizer and if it is visible.
|
|
81
|
-
*/
|
|
82
|
-
redrawSelectedResizer() {
|
|
83
|
-
if (this.selectedResizer && this.selectedResizer.isVisible) {
|
|
84
|
-
this.selectedResizer.redraw();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* @inheritDoc
|
|
89
|
-
*/
|
|
90
|
-
destroy() {
|
|
91
|
-
super.destroy();
|
|
92
|
-
this._observer.stopListening();
|
|
93
|
-
for (const resizer of this._resizers.values()) {
|
|
94
|
-
resizer.destroy();
|
|
95
|
-
}
|
|
96
|
-
this._redrawSelectedResizerThrottled.cancel();
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Marks resizer as selected.
|
|
100
|
-
*/
|
|
101
|
-
select(resizer) {
|
|
102
|
-
this.deselect();
|
|
103
|
-
this.selectedResizer = resizer;
|
|
104
|
-
this.selectedResizer.isSelected = true;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Deselects currently set resizer.
|
|
108
|
-
*/
|
|
109
|
-
deselect() {
|
|
110
|
-
if (this.selectedResizer) {
|
|
111
|
-
this.selectedResizer.isSelected = false;
|
|
112
|
-
}
|
|
113
|
-
this.selectedResizer = null;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* @param options Resizer options.
|
|
117
|
-
*/
|
|
118
|
-
attachTo(options) {
|
|
119
|
-
const resizer = new WidgetResizer(options);
|
|
120
|
-
const plugins = this.editor.plugins;
|
|
121
|
-
resizer.attach();
|
|
122
|
-
if (plugins.has('WidgetToolbarRepository')) {
|
|
123
|
-
// Hiding widget toolbar to improve the performance
|
|
124
|
-
// (https://github.com/ckeditor/ckeditor5-widget/pull/112#issuecomment-564528765).
|
|
125
|
-
const widgetToolbarRepository = plugins.get('WidgetToolbarRepository');
|
|
126
|
-
resizer.on('begin', () => {
|
|
127
|
-
widgetToolbarRepository.forceDisabled('resize');
|
|
128
|
-
}, { priority: 'lowest' });
|
|
129
|
-
resizer.on('cancel', () => {
|
|
130
|
-
widgetToolbarRepository.clearForceDisabled('resize');
|
|
131
|
-
}, { priority: 'highest' });
|
|
132
|
-
resizer.on('commit', () => {
|
|
133
|
-
widgetToolbarRepository.clearForceDisabled('resize');
|
|
134
|
-
}, { priority: 'highest' });
|
|
135
|
-
}
|
|
136
|
-
this._resizers.set(options.viewElement, resizer);
|
|
137
|
-
const viewSelection = this.editor.editing.view.document.selection;
|
|
138
|
-
const selectedElement = viewSelection.getSelectedElement();
|
|
139
|
-
// If the element the resizer is created for is currently focused, it should become visible.
|
|
140
|
-
if (this.getResizerByViewElement(selectedElement) == resizer) {
|
|
141
|
-
this.select(resizer);
|
|
142
|
-
}
|
|
143
|
-
return resizer;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Returns a resizer created for a given view element (widget element).
|
|
147
|
-
*
|
|
148
|
-
* @param viewElement View element associated with the resizer.
|
|
149
|
-
*/
|
|
150
|
-
getResizerByViewElement(viewElement) {
|
|
151
|
-
return this._resizers.get(viewElement);
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Returns a resizer that contains a given resize handle.
|
|
155
|
-
*/
|
|
156
|
-
_getResizerByHandle(domResizeHandle) {
|
|
157
|
-
for (const resizer of this._resizers.values()) {
|
|
158
|
-
if (resizer.containsHandle(domResizeHandle)) {
|
|
159
|
-
return resizer;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* @param domEventData Native DOM event.
|
|
165
|
-
*/
|
|
166
|
-
_mouseDownListener(event, domEventData) {
|
|
167
|
-
const resizeHandle = domEventData.domTarget;
|
|
168
|
-
if (!WidgetResizer.isResizeHandle(resizeHandle)) {
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
this._activeResizer = this._getResizerByHandle(resizeHandle) || null;
|
|
172
|
-
if (this._activeResizer) {
|
|
173
|
-
this._activeResizer.begin(resizeHandle);
|
|
174
|
-
// Do not call other events when resizing. See: #6755.
|
|
175
|
-
event.stop();
|
|
176
|
-
domEventData.preventDefault();
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* @param domEventData Native DOM event.
|
|
181
|
-
*/
|
|
182
|
-
_mouseMoveListener(event, domEventData) {
|
|
183
|
-
if (this._activeResizer) {
|
|
184
|
-
this._activeResizer.updateSize(domEventData);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
_mouseUpListener() {
|
|
188
|
-
if (this._activeResizer) {
|
|
189
|
-
this._activeResizer.commit();
|
|
190
|
-
this._activeResizer = null;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module widget/widgettoolbarrepository
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
9
|
-
import { BalloonPanelView, ContextualBalloon, ToolbarView } from '@ckeditor/ckeditor5-ui';
|
|
10
|
-
import { CKEditorError, logWarning } from '@ckeditor/ckeditor5-utils';
|
|
11
|
-
import { isWidget } from './utils.js';
|
|
12
|
-
/**
|
|
13
|
-
* Widget toolbar repository plugin. A central point for registering widget toolbars. This plugin handles the whole
|
|
14
|
-
* toolbar rendering process and exposes a concise API.
|
|
15
|
-
*
|
|
16
|
-
* To add a toolbar for your widget use the {@link ~WidgetToolbarRepository#register `WidgetToolbarRepository#register()`} method.
|
|
17
|
-
*
|
|
18
|
-
* The following example comes from the {@link module:image/imagetoolbar~ImageToolbar} plugin:
|
|
19
|
-
*
|
|
20
|
-
* ```ts
|
|
21
|
-
* class ImageToolbar extends Plugin {
|
|
22
|
-
* static get requires() {
|
|
23
|
-
* return [ WidgetToolbarRepository ];
|
|
24
|
-
* }
|
|
25
|
-
*
|
|
26
|
-
* afterInit() {
|
|
27
|
-
* const editor = this.editor;
|
|
28
|
-
* const widgetToolbarRepository = editor.plugins.get( WidgetToolbarRepository );
|
|
29
|
-
*
|
|
30
|
-
* widgetToolbarRepository.register( 'image', {
|
|
31
|
-
* items: editor.config.get( 'image.toolbar' ),
|
|
32
|
-
* getRelatedElement: getClosestSelectedImageWidget
|
|
33
|
-
* } );
|
|
34
|
-
* }
|
|
35
|
-
* }
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export class WidgetToolbarRepository extends Plugin {
|
|
39
|
-
/**
|
|
40
|
-
* A map of toolbar definitions.
|
|
41
|
-
*/
|
|
42
|
-
_toolbarDefinitions = new Map();
|
|
43
|
-
_balloon;
|
|
44
|
-
/**
|
|
45
|
-
* @inheritDoc
|
|
46
|
-
*/
|
|
47
|
-
static get requires() {
|
|
48
|
-
return [ContextualBalloon];
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* @inheritDoc
|
|
52
|
-
*/
|
|
53
|
-
static get pluginName() {
|
|
54
|
-
return 'WidgetToolbarRepository';
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* @inheritDoc
|
|
58
|
-
*/
|
|
59
|
-
static get isOfficialPlugin() {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* @inheritDoc
|
|
64
|
-
*/
|
|
65
|
-
init() {
|
|
66
|
-
const editor = this.editor;
|
|
67
|
-
// Disables the default balloon toolbar for all widgets.
|
|
68
|
-
if (editor.plugins.has('BalloonToolbar')) {
|
|
69
|
-
const balloonToolbar = editor.plugins.get('BalloonToolbar');
|
|
70
|
-
this.listenTo(balloonToolbar, 'show', evt => {
|
|
71
|
-
if (isWidgetSelected(editor.editing.view.document.selection)) {
|
|
72
|
-
evt.stop();
|
|
73
|
-
}
|
|
74
|
-
}, { priority: 'high' });
|
|
75
|
-
}
|
|
76
|
-
this._balloon = this.editor.plugins.get('ContextualBalloon');
|
|
77
|
-
this.on('change:isEnabled', () => {
|
|
78
|
-
this._updateToolbarsVisibility();
|
|
79
|
-
});
|
|
80
|
-
this.listenTo(editor.ui, 'update', () => {
|
|
81
|
-
this._updateToolbarsVisibility();
|
|
82
|
-
});
|
|
83
|
-
// UI#update is not fired after focus is back in editor, we need to check if balloon panel should be visible.
|
|
84
|
-
this.listenTo(editor.ui.focusTracker, 'change:isFocused', () => {
|
|
85
|
-
this._updateToolbarsVisibility();
|
|
86
|
-
}, { priority: 'low' });
|
|
87
|
-
}
|
|
88
|
-
destroy() {
|
|
89
|
-
super.destroy();
|
|
90
|
-
for (const toolbarConfig of this._toolbarDefinitions.values()) {
|
|
91
|
-
toolbarConfig.view.destroy();
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Registers toolbar in the WidgetToolbarRepository. It renders it in the `ContextualBalloon` based on the value of the invoked
|
|
96
|
-
* `getRelatedElement` function. Toolbar items are gathered from `items` array.
|
|
97
|
-
* The balloon's CSS class is by default `ck-toolbar-container` and may be override with the `balloonClassName` option.
|
|
98
|
-
*
|
|
99
|
-
* Note: This method should be called in the {@link module:core/plugin~PluginInterface#afterInit `Plugin#afterInit()`}
|
|
100
|
-
* callback (or later) to make sure that the given toolbar items were already registered by other plugins.
|
|
101
|
-
*
|
|
102
|
-
* @param toolbarId An id for the toolbar. Used to
|
|
103
|
-
* @param options Detailed options
|
|
104
|
-
* @param options.ariaLabel Label used by assistive technologies to describe this toolbar element.
|
|
105
|
-
* @param options.items Array of toolbar items.
|
|
106
|
-
* @param options.getRelatedElement Callback which returns an element the toolbar should be attached to.
|
|
107
|
-
* @param options.balloonClassName CSS class for the widget balloon.
|
|
108
|
-
*/
|
|
109
|
-
register(toolbarId, { ariaLabel, items, getRelatedElement, balloonClassName = 'ck-toolbar-container', positions }) {
|
|
110
|
-
// Trying to register a toolbar without any item.
|
|
111
|
-
if (!items.length) {
|
|
112
|
-
/**
|
|
113
|
-
* When {@link module:widget/widgettoolbarrepository~WidgetToolbarRepository#register registering} a new widget toolbar, you
|
|
114
|
-
* need to provide a non-empty array with the items that will be inserted into the toolbar.
|
|
115
|
-
*
|
|
116
|
-
* If you see this error when integrating the editor, you likely forgot to configure one of the widget toolbars.
|
|
117
|
-
*
|
|
118
|
-
* See for instance:
|
|
119
|
-
*
|
|
120
|
-
* * {@link module:table/tableconfig~TableConfig#contentToolbar `config.table.contentToolbar`}
|
|
121
|
-
* * {@link module:image/imageconfig~ImageConfig#toolbar `config.image.toolbar`}
|
|
122
|
-
*
|
|
123
|
-
* @error widget-toolbar-no-items
|
|
124
|
-
* @param {string} toolbarId The id of the toolbar that has not been configured correctly.
|
|
125
|
-
*/
|
|
126
|
-
logWarning('widget-toolbar-no-items', { toolbarId });
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
const editor = this.editor;
|
|
130
|
-
const t = editor.t;
|
|
131
|
-
const toolbarView = new ToolbarView(editor.locale);
|
|
132
|
-
toolbarView.ariaLabel = ariaLabel || t('Widget toolbar');
|
|
133
|
-
if (this._toolbarDefinitions.has(toolbarId)) {
|
|
134
|
-
/**
|
|
135
|
-
* Toolbar with the given id was already added.
|
|
136
|
-
*
|
|
137
|
-
* @error widget-toolbar-duplicated
|
|
138
|
-
* @param {string} toolbarId Toolbar id.
|
|
139
|
-
*/
|
|
140
|
-
throw new CKEditorError('widget-toolbar-duplicated', this, { toolbarId });
|
|
141
|
-
}
|
|
142
|
-
const toolbarDefinition = {
|
|
143
|
-
view: toolbarView,
|
|
144
|
-
getRelatedElement,
|
|
145
|
-
balloonClassName,
|
|
146
|
-
itemsConfig: items,
|
|
147
|
-
positions,
|
|
148
|
-
initialized: false
|
|
149
|
-
};
|
|
150
|
-
// Register the toolbar so it becomes available for Alt+F10 and Esc navigation.
|
|
151
|
-
editor.ui.addToolbar(toolbarView, {
|
|
152
|
-
isContextual: true,
|
|
153
|
-
beforeFocus: () => {
|
|
154
|
-
const relatedElement = getRelatedElement(editor.editing.view.document.selection);
|
|
155
|
-
if (relatedElement) {
|
|
156
|
-
this._showToolbar(toolbarDefinition, relatedElement);
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
afterBlur: () => {
|
|
160
|
-
this._hideToolbar(toolbarDefinition);
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
this._toolbarDefinitions.set(toolbarId, toolbarDefinition);
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Iterates over stored toolbars and makes them visible or hidden.
|
|
167
|
-
*/
|
|
168
|
-
_updateToolbarsVisibility() {
|
|
169
|
-
let maxRelatedElementDepth = 0;
|
|
170
|
-
let deepestRelatedElement = null;
|
|
171
|
-
let deepestToolbarDefinition = null;
|
|
172
|
-
for (const definition of this._toolbarDefinitions.values()) {
|
|
173
|
-
const relatedElement = definition.getRelatedElement(this.editor.editing.view.document.selection);
|
|
174
|
-
if (!this.isEnabled || !relatedElement) {
|
|
175
|
-
if (this._isToolbarInBalloon(definition)) {
|
|
176
|
-
this._hideToolbar(definition);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
else if (!this.editor.ui.focusTracker.isFocused) {
|
|
180
|
-
if (this._isToolbarVisible(definition)) {
|
|
181
|
-
this._hideToolbar(definition);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
const relatedElementDepth = relatedElement.getAncestors().length;
|
|
186
|
-
// Many toolbars can express willingness to be displayed but they do not know about
|
|
187
|
-
// each other. Figure out which toolbar is deepest in the view tree to decide which
|
|
188
|
-
// should be displayed. For instance, if a selected image is inside a table cell, display
|
|
189
|
-
// the ImageToolbar rather than the TableToolbar (#60).
|
|
190
|
-
if (relatedElementDepth > maxRelatedElementDepth) {
|
|
191
|
-
maxRelatedElementDepth = relatedElementDepth;
|
|
192
|
-
deepestRelatedElement = relatedElement;
|
|
193
|
-
deepestToolbarDefinition = definition;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
if (deepestToolbarDefinition) {
|
|
198
|
-
this._showToolbar(deepestToolbarDefinition, deepestRelatedElement);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Hides the given toolbar.
|
|
203
|
-
*/
|
|
204
|
-
_hideToolbar(toolbarDefinition) {
|
|
205
|
-
this._balloon.remove(toolbarDefinition.view);
|
|
206
|
-
this.stopListening(this._balloon, 'change:visibleView');
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Shows up the toolbar if the toolbar is not visible.
|
|
210
|
-
* Otherwise, repositions the toolbar's balloon when toolbar's view is the most top view in balloon stack.
|
|
211
|
-
*
|
|
212
|
-
* It might happen here that the toolbar's view is under another view. Then do nothing as the other toolbar view
|
|
213
|
-
* should be still visible after the {@link module:ui/editorui/editorui~EditorUI#event:update}.
|
|
214
|
-
*/
|
|
215
|
-
_showToolbar(toolbarDefinition, relatedElement) {
|
|
216
|
-
if (this._isToolbarVisible(toolbarDefinition)) {
|
|
217
|
-
repositionContextualBalloon(this.editor, relatedElement, toolbarDefinition.positions);
|
|
218
|
-
}
|
|
219
|
-
else if (!this._isToolbarInBalloon(toolbarDefinition)) {
|
|
220
|
-
if (!toolbarDefinition.initialized) {
|
|
221
|
-
toolbarDefinition.initialized = true;
|
|
222
|
-
toolbarDefinition.view.fillFromConfig(toolbarDefinition.itemsConfig, this.editor.ui.componentFactory);
|
|
223
|
-
}
|
|
224
|
-
this._balloon.add({
|
|
225
|
-
view: toolbarDefinition.view,
|
|
226
|
-
position: getBalloonPositionData(this.editor, relatedElement, toolbarDefinition.positions),
|
|
227
|
-
balloonClassName: toolbarDefinition.balloonClassName
|
|
228
|
-
});
|
|
229
|
-
// Update toolbar position each time stack with toolbar view is switched to visible.
|
|
230
|
-
// This is in a case target element has changed when toolbar was in invisible stack
|
|
231
|
-
// e.g. target image was wrapped by a block quote.
|
|
232
|
-
// See https://github.com/ckeditor/ckeditor5-widget/issues/92.
|
|
233
|
-
this.listenTo(this._balloon, 'change:visibleView', () => {
|
|
234
|
-
for (const definition of this._toolbarDefinitions.values()) {
|
|
235
|
-
if (this._isToolbarVisible(definition)) {
|
|
236
|
-
const relatedElement = definition.getRelatedElement(this.editor.editing.view.document.selection);
|
|
237
|
-
repositionContextualBalloon(this.editor, relatedElement, toolbarDefinition.positions);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
_isToolbarVisible(toolbar) {
|
|
244
|
-
return this._balloon.visibleView === toolbar.view;
|
|
245
|
-
}
|
|
246
|
-
_isToolbarInBalloon(toolbar) {
|
|
247
|
-
return this._balloon.hasView(toolbar.view);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
function repositionContextualBalloon(editor, relatedElement, positions) {
|
|
251
|
-
const balloon = editor.plugins.get('ContextualBalloon');
|
|
252
|
-
const position = getBalloonPositionData(editor, relatedElement, positions);
|
|
253
|
-
balloon.updatePosition(position);
|
|
254
|
-
}
|
|
255
|
-
function getBalloonPositionData(editor, relatedElement, positions) {
|
|
256
|
-
const editingView = editor.editing.view;
|
|
257
|
-
const defaultPositions = BalloonPanelView.defaultPositions;
|
|
258
|
-
return {
|
|
259
|
-
target: editingView.domConverter.mapViewToDom(relatedElement),
|
|
260
|
-
positions: positions || [
|
|
261
|
-
defaultPositions.northArrowSouth,
|
|
262
|
-
defaultPositions.northArrowSouthWest,
|
|
263
|
-
defaultPositions.northArrowSouthEast,
|
|
264
|
-
defaultPositions.southArrowNorth,
|
|
265
|
-
defaultPositions.southArrowNorthWest,
|
|
266
|
-
defaultPositions.southArrowNorthEast,
|
|
267
|
-
defaultPositions.viewportStickyNorth
|
|
268
|
-
]
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
function isWidgetSelected(selection) {
|
|
272
|
-
const viewElement = selection.getSelectedElement();
|
|
273
|
-
return !!(viewElement && isWidget(viewElement));
|
|
274
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module widget/widgettypearound/utils
|
|
7
|
-
*/
|
|
8
|
-
import { isWidget } from '../utils.js';
|
|
9
|
-
/**
|
|
10
|
-
* The name of the type around model selection attribute responsible for
|
|
11
|
-
* displaying a fake caret next to a selected widget.
|
|
12
|
-
*
|
|
13
|
-
* @internal
|
|
14
|
-
*/
|
|
15
|
-
export const TYPE_AROUND_SELECTION_ATTRIBUTE = 'widget-type-around';
|
|
16
|
-
/**
|
|
17
|
-
* Checks if an element is a widget that qualifies to get the widget type around UI.
|
|
18
|
-
*/
|
|
19
|
-
export function isTypeAroundWidget(viewElement, modelElement, schema) {
|
|
20
|
-
return !!viewElement && isWidget(viewElement) && !schema.isInline(modelElement);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* For the passed HTML element, this helper finds the closest widget type around button ancestor.
|
|
24
|
-
*
|
|
25
|
-
* @internal
|
|
26
|
-
*/
|
|
27
|
-
export function getClosestTypeAroundDomButton(domElement) {
|
|
28
|
-
return domElement.closest('.ck-widget__type-around__button');
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* For the passed widget type around button element, this helper determines at which position
|
|
32
|
-
* the paragraph would be inserted into the content if, for instance, the button was
|
|
33
|
-
* clicked by the user.
|
|
34
|
-
*
|
|
35
|
-
* @internal
|
|
36
|
-
* @returns The position of the button.
|
|
37
|
-
*/
|
|
38
|
-
export function getTypeAroundButtonPosition(domElement) {
|
|
39
|
-
return domElement.classList.contains('ck-widget__type-around__button_before') ? 'before' : 'after';
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* For the passed HTML element, this helper returns the closest view widget ancestor.
|
|
43
|
-
*
|
|
44
|
-
* @internal
|
|
45
|
-
*/
|
|
46
|
-
export function getClosestWidgetViewElement(domElement, domConverter) {
|
|
47
|
-
const widgetDomElement = domElement.closest('.ck-widget');
|
|
48
|
-
return domConverter.mapDomToView(widgetDomElement);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* For the passed selection instance, it returns the position of the fake caret displayed next to a widget.
|
|
52
|
-
*
|
|
53
|
-
* **Note**: If the fake caret is not currently displayed, `null` is returned.
|
|
54
|
-
*
|
|
55
|
-
* @internal
|
|
56
|
-
* @returns The position of the fake caret or `null` when none is present.
|
|
57
|
-
*/
|
|
58
|
-
export function getTypeAroundFakeCaretPosition(selection) {
|
|
59
|
-
return selection.getAttribute(TYPE_AROUND_SELECTION_ATTRIBUTE);
|
|
60
|
-
}
|