@ckeditor/ckeditor5-widget 0.0.0-nightly-20250226.0 → 0.0.0-nightly-next-20250226.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/LICENSE.md +1 -1
- package/dist/index.js +13 -15
- package/dist/index.js.map +1 -1
- package/package.json +9 -8
- package/src/highlightstack.js +1 -4
- package/src/utils.d.ts +0 -3
- package/src/utils.js +2 -2
- package/src/widget.js +4 -7
- package/src/widgetresize/resizer.js +22 -4
- package/src/widgetresize/resizerstate.js +36 -0
- package/src/widgetresize.js +7 -8
- package/src/widgettoolbarrepository.d.ts +3 -1
- package/src/widgettoolbarrepository.js +14 -15
- package/src/widgettypearound/widgettypearound.js +8 -11
- package/theme/icons/drag-handle.svg +0 -1
- package/theme/icons/return-arrow.svg +0 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ckeditor/ckeditor5-widget",
|
3
|
-
"version": "0.0.0-nightly-20250226.0",
|
3
|
+
"version": "0.0.0-nightly-next-20250226.0",
|
4
4
|
"description": "Widget API for CKEditor 5.",
|
5
5
|
"keywords": [
|
6
6
|
"ckeditor",
|
@@ -12,13 +12,14 @@
|
|
12
12
|
"type": "module",
|
13
13
|
"main": "src/index.js",
|
14
14
|
"dependencies": {
|
15
|
-
"@ckeditor/ckeditor5-core": "0.0.0-nightly-20250226.0",
|
16
|
-
"@ckeditor/ckeditor5-engine": "0.0.0-nightly-20250226.0",
|
17
|
-
"@ckeditor/ckeditor5-enter": "0.0.0-nightly-20250226.0",
|
18
|
-
"@ckeditor/ckeditor5-
|
19
|
-
"@ckeditor/ckeditor5-
|
20
|
-
"@ckeditor/ckeditor5-
|
21
|
-
"
|
15
|
+
"@ckeditor/ckeditor5-core": "0.0.0-nightly-next-20250226.0",
|
16
|
+
"@ckeditor/ckeditor5-engine": "0.0.0-nightly-next-20250226.0",
|
17
|
+
"@ckeditor/ckeditor5-enter": "0.0.0-nightly-next-20250226.0",
|
18
|
+
"@ckeditor/ckeditor5-icons": "0.0.0-nightly-next-20250226.0",
|
19
|
+
"@ckeditor/ckeditor5-ui": "0.0.0-nightly-next-20250226.0",
|
20
|
+
"@ckeditor/ckeditor5-utils": "0.0.0-nightly-next-20250226.0",
|
21
|
+
"@ckeditor/ckeditor5-typing": "0.0.0-nightly-next-20250226.0",
|
22
|
+
"es-toolkit": "1.32.0"
|
22
23
|
},
|
23
24
|
"author": "CKSource (http://cksource.com/)",
|
24
25
|
"license": "SEE LICENSE IN LICENSE.md",
|
package/src/highlightstack.js
CHANGED
@@ -18,10 +18,7 @@ import { EmitterMixin } from '@ckeditor/ckeditor5-utils';
|
|
18
18
|
* This way, highlight will be applied with the same rules it is applied on texts.
|
19
19
|
*/
|
20
20
|
export default class HighlightStack extends /* #__PURE__ */ EmitterMixin() {
|
21
|
-
|
22
|
-
super(...arguments);
|
23
|
-
this._stack = [];
|
24
|
-
}
|
21
|
+
_stack = [];
|
25
22
|
/**
|
26
23
|
* Adds highlight descriptor to the stack.
|
27
24
|
*
|
package/src/utils.d.ts
CHANGED
@@ -2,9 +2,6 @@
|
|
2
2
|
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
4
4
|
*/
|
5
|
-
/**
|
6
|
-
* @module widget/utils
|
7
|
-
*/
|
8
5
|
import { Rect, type GetCallback } from '@ckeditor/ckeditor5-utils';
|
9
6
|
import { type HighlightDescriptor, type MapperViewToModelPositionEvent, type DocumentSelection, type DowncastWriter, type Model, type Range, type Selection, type ViewEditableElement, type ViewElement, type ViewTypeCheckable } from '@ckeditor/ckeditor5-engine';
|
10
7
|
/**
|
package/src/utils.js
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
/**
|
6
6
|
* @module widget/utils
|
7
7
|
*/
|
8
|
+
import { IconDragHandle } from '@ckeditor/ckeditor5-icons';
|
8
9
|
import { Rect, CKEditorError, toArray } from '@ckeditor/ckeditor5-utils';
|
9
10
|
import { IconView } from '@ckeditor/ckeditor5-ui';
|
10
11
|
import HighlightStack from './highlightstack.js';
|
11
12
|
import { getTypeAroundFakeCaretPosition } from './widgettypearound/utils.js';
|
12
|
-
import dragHandleIcon from '../theme/icons/drag-handle.svg';
|
13
13
|
/**
|
14
14
|
* CSS class added to each widget element.
|
15
15
|
*/
|
@@ -336,7 +336,7 @@ function addSelectionHandle(widgetElement, writer) {
|
|
336
336
|
const domElement = this.toDomElement(domDocument);
|
337
337
|
// Use the IconView from the ui library.
|
338
338
|
const icon = new IconView();
|
339
|
-
icon.set('content',
|
339
|
+
icon.set('content', IconDragHandle);
|
340
340
|
// Render the icon view right away to append its #element to the selectionHandle DOM element.
|
341
341
|
icon.render();
|
342
342
|
domElement.appendChild(icon.element);
|
package/src/widget.js
CHANGED
@@ -27,13 +27,10 @@ import '../theme/widget.css';
|
|
27
27
|
* * The mouse and keyboard events handling on and around widget elements.
|
28
28
|
*/
|
29
29
|
export default class Widget extends Plugin {
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
*/
|
35
|
-
this._previouslySelected = new Set();
|
36
|
-
}
|
30
|
+
/**
|
31
|
+
* Holds previously selected widgets.
|
32
|
+
*/
|
33
|
+
_previouslySelected = new Set();
|
37
34
|
/**
|
38
35
|
* @inheritDoc
|
39
36
|
*/
|
@@ -13,15 +13,33 @@ import SizeView from './sizeview.js';
|
|
13
13
|
* Represents a resizer for a single resizable object.
|
14
14
|
*/
|
15
15
|
export default class Resizer extends /* #__PURE__ */ ObservableMixin() {
|
16
|
+
/**
|
17
|
+
* Stores the state of the resizable host geometry, such as the original width, the currently proposed height, etc.
|
18
|
+
*
|
19
|
+
* Note that a new state is created for each resize transaction.
|
20
|
+
*/
|
21
|
+
_state;
|
22
|
+
/**
|
23
|
+
* A view displaying the proposed new element size during the resizing.
|
24
|
+
*/
|
25
|
+
_sizeView;
|
26
|
+
/**
|
27
|
+
* Options passed to the {@link #constructor}.
|
28
|
+
*/
|
29
|
+
_options;
|
30
|
+
/**
|
31
|
+
* A wrapper that is controlled by the resizer. This is usually a widget element.
|
32
|
+
*/
|
33
|
+
_viewResizerWrapper = null;
|
34
|
+
/**
|
35
|
+
* The width of the resized {@link module:widget/widgetresize~ResizerOptions#viewElement viewElement} before the resizing started.
|
36
|
+
*/
|
37
|
+
_initialViewWidth;
|
16
38
|
/**
|
17
39
|
* @param options Resizer options.
|
18
40
|
*/
|
19
41
|
constructor(options) {
|
20
42
|
super();
|
21
|
-
/**
|
22
|
-
* A wrapper that is controlled by the resizer. This is usually a widget element.
|
23
|
-
*/
|
24
|
-
this._viewResizerWrapper = null;
|
25
43
|
this._options = options;
|
26
44
|
this.set('isEnabled', true);
|
27
45
|
this.set('isSelected', false);
|
@@ -11,6 +11,42 @@ import { calculateResizeHostPercentageWidth } from '../utils.js';
|
|
11
11
|
* Stores the internal state of a single resizable object.
|
12
12
|
*/
|
13
13
|
export default class ResizeState extends /* #__PURE__ */ ObservableMixin() {
|
14
|
+
/**
|
15
|
+
* The reference point of the resizer where the dragging started. It is used to measure the distance the user cursor
|
16
|
+
* traveled, so how much the image should be enlarged.
|
17
|
+
* This information is only known after the DOM was rendered, so it will be updated later.
|
18
|
+
*
|
19
|
+
* @internal
|
20
|
+
*/
|
21
|
+
_referenceCoordinates;
|
22
|
+
/**
|
23
|
+
* Resizer options.
|
24
|
+
*/
|
25
|
+
_options;
|
26
|
+
/**
|
27
|
+
* The original width (pixels) of the resized object when the resize process was started.
|
28
|
+
*
|
29
|
+
* @readonly
|
30
|
+
*/
|
31
|
+
_originalWidth;
|
32
|
+
/**
|
33
|
+
* The original height (pixels) of the resized object when the resize process was started.
|
34
|
+
*
|
35
|
+
* @readonly
|
36
|
+
*/
|
37
|
+
_originalHeight;
|
38
|
+
/**
|
39
|
+
* The original width (percents) of the resized object when the resize process was started.
|
40
|
+
*
|
41
|
+
* @readonly
|
42
|
+
*/
|
43
|
+
_originalWidthPercents;
|
44
|
+
/**
|
45
|
+
* A width to height ratio of the resized image.
|
46
|
+
*
|
47
|
+
* @readonly
|
48
|
+
*/
|
49
|
+
_aspectRatio;
|
14
50
|
/**
|
15
51
|
* @param options Resizer options.
|
16
52
|
*/
|
package/src/widgetresize.js
CHANGED
@@ -9,7 +9,7 @@ import Resizer from './widgetresize/resizer.js';
|
|
9
9
|
import { Plugin } from '@ckeditor/ckeditor5-core';
|
10
10
|
import { MouseObserver } from '@ckeditor/ckeditor5-engine';
|
11
11
|
import { DomEmitterMixin, global } from '@ckeditor/ckeditor5-utils';
|
12
|
-
import { throttle } from '
|
12
|
+
import { throttle } from 'es-toolkit/compat';
|
13
13
|
import '../theme/widgetresize.css';
|
14
14
|
/**
|
15
15
|
* The widget resize feature plugin.
|
@@ -17,13 +17,12 @@ import '../theme/widgetresize.css';
|
|
17
17
|
* Use the {@link module:widget/widgetresize~WidgetResize#attachTo} method to create a resizer for the specified widget.
|
18
18
|
*/
|
19
19
|
export default class WidgetResize extends Plugin {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
}
|
20
|
+
/**
|
21
|
+
* A map of resizers created using this plugin instance.
|
22
|
+
*/
|
23
|
+
_resizers = new Map();
|
24
|
+
_observer;
|
25
|
+
_redrawSelectedResizerThrottled;
|
27
26
|
/**
|
28
27
|
* @inheritDoc
|
29
28
|
*/
|
@@ -8,6 +8,7 @@
|
|
8
8
|
import { Plugin, type ToolbarConfigItem } from '@ckeditor/ckeditor5-core';
|
9
9
|
import type { ViewDocumentSelection, ViewElement } from '@ckeditor/ckeditor5-engine';
|
10
10
|
import { ContextualBalloon } from '@ckeditor/ckeditor5-ui';
|
11
|
+
import { type PositioningFunction } from '@ckeditor/ckeditor5-utils';
|
11
12
|
/**
|
12
13
|
* Widget toolbar repository plugin. A central point for registering widget toolbars. This plugin handles the whole
|
13
14
|
* toolbar rendering process and exposes a concise API.
|
@@ -71,11 +72,12 @@ export default class WidgetToolbarRepository extends Plugin {
|
|
71
72
|
* @param options.getRelatedElement Callback which returns an element the toolbar should be attached to.
|
72
73
|
* @param options.balloonClassName CSS class for the widget balloon.
|
73
74
|
*/
|
74
|
-
register(toolbarId: string, { ariaLabel, items, getRelatedElement, balloonClassName }: {
|
75
|
+
register(toolbarId: string, { ariaLabel, items, getRelatedElement, balloonClassName, positions }: {
|
75
76
|
ariaLabel?: string;
|
76
77
|
items: Array<ToolbarConfigItem>;
|
77
78
|
getRelatedElement: (selection: ViewDocumentSelection) => (ViewElement | null);
|
78
79
|
balloonClassName?: string;
|
80
|
+
positions?: ReadonlyArray<PositioningFunction>;
|
79
81
|
}): void;
|
80
82
|
/**
|
81
83
|
* Iterates over stored toolbars and makes them visible or hidden.
|
@@ -36,13 +36,11 @@ import { isWidget } from './utils.js';
|
|
36
36
|
* ```
|
37
37
|
*/
|
38
38
|
export default class WidgetToolbarRepository extends Plugin {
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
this._toolbarDefinitions = new Map();
|
45
|
-
}
|
39
|
+
/**
|
40
|
+
* A map of toolbar definitions.
|
41
|
+
*/
|
42
|
+
_toolbarDefinitions = new Map();
|
43
|
+
_balloon;
|
46
44
|
/**
|
47
45
|
* @inheritDoc
|
48
46
|
*/
|
@@ -107,7 +105,7 @@ export default class WidgetToolbarRepository extends Plugin {
|
|
107
105
|
* @param options.getRelatedElement Callback which returns an element the toolbar should be attached to.
|
108
106
|
* @param options.balloonClassName CSS class for the widget balloon.
|
109
107
|
*/
|
110
|
-
register(toolbarId, { ariaLabel, items, getRelatedElement, balloonClassName = 'ck-toolbar-container' }) {
|
108
|
+
register(toolbarId, { ariaLabel, items, getRelatedElement, balloonClassName = 'ck-toolbar-container', positions }) {
|
111
109
|
// Trying to register a toolbar without any item.
|
112
110
|
if (!items.length) {
|
113
111
|
/**
|
@@ -145,6 +143,7 @@ export default class WidgetToolbarRepository extends Plugin {
|
|
145
143
|
getRelatedElement,
|
146
144
|
balloonClassName,
|
147
145
|
itemsConfig: items,
|
146
|
+
positions,
|
148
147
|
initialized: false
|
149
148
|
};
|
150
149
|
// Register the toolbar so it becomes available for Alt+F10 and Esc navigation.
|
@@ -214,7 +213,7 @@ export default class WidgetToolbarRepository extends Plugin {
|
|
214
213
|
*/
|
215
214
|
_showToolbar(toolbarDefinition, relatedElement) {
|
216
215
|
if (this._isToolbarVisible(toolbarDefinition)) {
|
217
|
-
repositionContextualBalloon(this.editor, relatedElement);
|
216
|
+
repositionContextualBalloon(this.editor, relatedElement, toolbarDefinition.positions);
|
218
217
|
}
|
219
218
|
else if (!this._isToolbarInBalloon(toolbarDefinition)) {
|
220
219
|
if (!toolbarDefinition.initialized) {
|
@@ -223,7 +222,7 @@ export default class WidgetToolbarRepository extends Plugin {
|
|
223
222
|
}
|
224
223
|
this._balloon.add({
|
225
224
|
view: toolbarDefinition.view,
|
226
|
-
position: getBalloonPositionData(this.editor, relatedElement),
|
225
|
+
position: getBalloonPositionData(this.editor, relatedElement, toolbarDefinition.positions),
|
227
226
|
balloonClassName: toolbarDefinition.balloonClassName
|
228
227
|
});
|
229
228
|
// Update toolbar position each time stack with toolbar view is switched to visible.
|
@@ -234,7 +233,7 @@ export default class WidgetToolbarRepository extends Plugin {
|
|
234
233
|
for (const definition of this._toolbarDefinitions.values()) {
|
235
234
|
if (this._isToolbarVisible(definition)) {
|
236
235
|
const relatedElement = definition.getRelatedElement(this.editor.editing.view.document.selection);
|
237
|
-
repositionContextualBalloon(this.editor, relatedElement);
|
236
|
+
repositionContextualBalloon(this.editor, relatedElement, toolbarDefinition.positions);
|
238
237
|
}
|
239
238
|
}
|
240
239
|
});
|
@@ -247,17 +246,17 @@ export default class WidgetToolbarRepository extends Plugin {
|
|
247
246
|
return this._balloon.hasView(toolbar.view);
|
248
247
|
}
|
249
248
|
}
|
250
|
-
function repositionContextualBalloon(editor, relatedElement) {
|
249
|
+
function repositionContextualBalloon(editor, relatedElement, positions) {
|
251
250
|
const balloon = editor.plugins.get('ContextualBalloon');
|
252
|
-
const position = getBalloonPositionData(editor, relatedElement);
|
251
|
+
const position = getBalloonPositionData(editor, relatedElement, positions);
|
253
252
|
balloon.updatePosition(position);
|
254
253
|
}
|
255
|
-
function getBalloonPositionData(editor, relatedElement) {
|
254
|
+
function getBalloonPositionData(editor, relatedElement, positions) {
|
256
255
|
const editingView = editor.editing.view;
|
257
256
|
const defaultPositions = BalloonPanelView.defaultPositions;
|
258
257
|
return {
|
259
258
|
target: editingView.domConverter.mapViewToDom(relatedElement),
|
260
|
-
positions: [
|
259
|
+
positions: positions || [
|
261
260
|
defaultPositions.northArrowSouth,
|
262
261
|
defaultPositions.northArrowSouthWest,
|
263
262
|
defaultPositions.northArrowSouthEast,
|
@@ -7,17 +7,17 @@
|
|
7
7
|
* @module widget/widgettypearound/widgettypearound
|
8
8
|
*/
|
9
9
|
import { Plugin } from '@ckeditor/ckeditor5-core';
|
10
|
+
import { IconReturnArrow } from '@ckeditor/ckeditor5-icons';
|
10
11
|
import { Template } from '@ckeditor/ckeditor5-ui';
|
11
12
|
import { Enter } from '@ckeditor/ckeditor5-enter';
|
12
13
|
import { Delete } from '@ckeditor/ckeditor5-typing';
|
13
14
|
import { env, isForwardArrowKeyCode } from '@ckeditor/ckeditor5-utils';
|
14
15
|
import { isTypeAroundWidget, getClosestTypeAroundDomButton, getTypeAroundButtonPosition, getClosestWidgetViewElement, getTypeAroundFakeCaretPosition, TYPE_AROUND_SELECTION_ATTRIBUTE } from './utils.js';
|
15
16
|
import { isWidget } from '../utils.js';
|
16
|
-
import returnIcon from '../../theme/icons/return-arrow.svg';
|
17
17
|
import '../../theme/widgettypearound.css';
|
18
18
|
const POSSIBLE_INSERTION_POSITIONS = ['before', 'after'];
|
19
19
|
// Do the SVG parsing once and then clone the result <svg> DOM element for each new button.
|
20
|
-
const RETURN_ARROW_ICON_ELEMENT = new DOMParser().parseFromString(
|
20
|
+
const RETURN_ARROW_ICON_ELEMENT = new DOMParser().parseFromString(IconReturnArrow, 'image/svg+xml').firstChild;
|
21
21
|
const PLUGIN_DISABLED_EDITING_ROOT_CLASS = 'ck-widget__type-around_disabled';
|
22
22
|
/**
|
23
23
|
* A plugin that allows users to type around widgets where normally it is impossible to place the caret due
|
@@ -30,15 +30,12 @@ const PLUGIN_DISABLED_EDITING_ROOT_CLASS = 'ck-widget__type-around_disabled';
|
|
30
30
|
* in it so that users can type (or insert content, paste, etc.) straight away.
|
31
31
|
*/
|
32
32
|
export default class WidgetTypeAround extends Plugin {
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
*/
|
40
|
-
this._currentFakeCaretModelElement = null;
|
41
|
-
}
|
33
|
+
/**
|
34
|
+
* A reference to the model widget element that has the fake caret active
|
35
|
+
* on either side of it. It is later used to remove CSS classes associated with the fake caret
|
36
|
+
* when the widget no longer needs it.
|
37
|
+
*/
|
38
|
+
_currentFakeCaretModelElement = null;
|
42
39
|
/**
|
43
40
|
* @inheritDoc
|
44
41
|
*/
|
@@ -1 +0,0 @@
|
|
1
|
-
<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M4 0v1H1v3H0V.5A.5.5 0 0 1 .5 0H4zm8 0h3.5a.5.5 0 0 1 .5.5V4h-1V1h-3V0zM4 16H.5a.5.5 0 0 1-.5-.5V12h1v3h3v1zm8 0v-1h3v-3h1v3.5a.5.5 0 0 1-.5.5H12z"/><path fill-opacity=".256" d="M1 1h14v14H1z"/><g class="ck-icon__selected-indicator"><path d="M7 0h2v1H7V0zM0 7h1v2H0V7zm15 0h1v2h-1V7zm-8 8h2v1H7v-1z"/><path fill-opacity=".254" d="M1 1h14v14H1z"/></g></svg>
|
@@ -1 +0,0 @@
|
|
1
|
-
<svg viewBox="0 0 10 8" xmlns="http://www.w3.org/2000/svg"><path d="M9.055.263v3.972h-6.77M1 4.216l2-2.038m-2 2 2 2.038"/></svg>
|