@ckeditor/ckeditor5-widget 45.2.1 → 46.0.0-alpha.1
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/dist/index.js +42 -31
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/src/highlightstack.d.ts +14 -14
- package/src/highlightstack.js +3 -3
- package/src/index.d.ts +11 -5
- package/src/index.js +11 -5
- package/src/utils.d.ts +12 -11
- package/src/utils.js +10 -9
- package/src/verticalnavigation.d.ts +1 -1
- package/src/verticalnavigation.js +1 -1
- package/src/widget.d.ts +13 -13
- package/src/widget.js +14 -14
- package/src/widgetresize/resizer.d.ts +15 -15
- package/src/widgetresize/resizer.js +5 -5
- package/src/widgetresize/resizerstate.d.ts +4 -4
- package/src/widgetresize/resizerstate.js +1 -1
- package/src/widgetresize/sizeview.d.ts +6 -4
- package/src/widgetresize/sizeview.js +3 -1
- package/src/widgetresize.d.ts +11 -11
- package/src/widgetresize.js +4 -4
- package/src/widgettoolbarrepository.d.ts +1 -1
- package/src/widgettoolbarrepository.js +1 -1
- package/src/widgettypearound/utils.d.ts +12 -4
- package/src/widgettypearound/utils.js +8 -0
- package/src/widgettypearound/widgettypearound.d.ts +2 -2
- package/src/widgettypearound/widgettypearound.js +2 -2
package/dist/index.js
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
4
4
|
*/
|
5
5
|
import { Plugin } from '@ckeditor/ckeditor5-core/dist/index.js';
|
6
|
-
import { MouseObserver,
|
6
|
+
import { MouseObserver, ModelTreeWalker } from '@ckeditor/ckeditor5-engine/dist/index.js';
|
7
7
|
import { Delete } from '@ckeditor/ckeditor5-typing/dist/index.js';
|
8
8
|
import { EmitterMixin, Rect, CKEditorError, toArray, isForwardArrowKeyCode, env, keyCodes, getLocalizedArrowKeyCodeDirection, getRangeFromMouseEvent, logWarning, ObservableMixin, compareArrays, global, DomEmitterMixin } from '@ckeditor/ckeditor5-utils/dist/index.js';
|
9
9
|
import { IconDragHandle, IconReturnArrow } from '@ckeditor/ckeditor5-icons/dist/index.js';
|
@@ -18,10 +18,10 @@ import { throttle } from 'es-toolkit/compat';
|
|
18
18
|
*
|
19
19
|
* * highlight with highest priority should be applied,
|
20
20
|
* * if two highlights have same priority - sort by CSS class provided in
|
21
|
-
* {@link module:engine/conversion/downcasthelpers~
|
21
|
+
* {@link module:engine/conversion/downcasthelpers~DowncastHighlightDescriptor}.
|
22
22
|
*
|
23
23
|
* This way, highlight will be applied with the same rules it is applied on texts.
|
24
|
-
*/ class
|
24
|
+
*/ class WidgetHighlightStack extends /* #__PURE__ */ EmitterMixin() {
|
25
25
|
_stack = [];
|
26
26
|
/**
|
27
27
|
* Adds highlight descriptor to the stack.
|
@@ -115,7 +115,7 @@ import { throttle } from 'es-toolkit/compat';
|
|
115
115
|
return classesToString(a.classes) > classesToString(b.classes);
|
116
116
|
}
|
117
117
|
/**
|
118
|
-
* Converts CSS classes passed with {@link module:engine/conversion/downcasthelpers~
|
118
|
+
* Converts CSS classes passed with {@link module:engine/conversion/downcasthelpers~DowncastHighlightDescriptor} to
|
119
119
|
* sorted string.
|
120
120
|
*/ function classesToString(classes) {
|
121
121
|
return Array.isArray(classes) ? classes.sort().join(',') : classes;
|
@@ -128,7 +128,7 @@ import { throttle } from 'es-toolkit/compat';
|
|
128
128
|
* CSS class added to currently selected widget element.
|
129
129
|
*/ const WIDGET_SELECTED_CLASS_NAME = 'ck-widget_selected';
|
130
130
|
/**
|
131
|
-
* Returns `true` if given {@link module:engine/view/node~
|
131
|
+
* Returns `true` if given {@link module:engine/view/node~ViewNode} is an {@link module:engine/view/element~ViewElement} and a widget.
|
132
132
|
*/ function isWidget(node) {
|
133
133
|
if (!node.is('element')) {
|
134
134
|
return false;
|
@@ -136,11 +136,11 @@ import { throttle } from 'es-toolkit/compat';
|
|
136
136
|
return !!node.getCustomProperty('widget');
|
137
137
|
}
|
138
138
|
/**
|
139
|
-
* Converts the given {@link module:engine/view/element~
|
139
|
+
* Converts the given {@link module:engine/view/element~ViewElement} to a widget in the following way:
|
140
140
|
*
|
141
141
|
* * sets the `contenteditable` attribute to `"false"`,
|
142
142
|
* * adds the `ck-widget` CSS class,
|
143
|
-
* * adds a custom {@link module:engine/view/element~
|
143
|
+
* * adds a custom {@link module:engine/view/element~ViewElement#getFillerOffset `getFillerOffset()`} method returning `null`,
|
144
144
|
* * adds a custom property allowing to recognize widget elements by using {@link ~isWidget `isWidget()`},
|
145
145
|
* * implements the {@link ~setHighlightHandling view highlight on widgets}.
|
146
146
|
*
|
@@ -183,7 +183,7 @@ import { throttle } from 'es-toolkit/compat';
|
|
183
183
|
*/ function toWidget(element, writer, options = {}) {
|
184
184
|
if (!element.is('containerElement')) {
|
185
185
|
/**
|
186
|
-
* The element passed to `toWidget()` must be a {@link module:engine/view/containerelement~
|
186
|
+
* The element passed to `toWidget()` must be a {@link module:engine/view/containerelement~ViewContainerElement}
|
187
187
|
* instance.
|
188
188
|
*
|
189
189
|
* @error widget-to-widget-wrong-element-type
|
@@ -233,10 +233,10 @@ import { throttle } from 'es-toolkit/compat';
|
|
233
233
|
}
|
234
234
|
}
|
235
235
|
/**
|
236
|
-
* Sets highlight handling methods. Uses {@link module:widget/highlightstack~
|
236
|
+
* Sets highlight handling methods. Uses {@link module:widget/highlightstack~WidgetHighlightStack} to
|
237
237
|
* properly determine which highlight descriptor should be used at given time.
|
238
238
|
*/ function setHighlightHandling(element, writer, add = addHighlight, remove = removeHighlight) {
|
239
|
-
const stack = new
|
239
|
+
const stack = new WidgetHighlightStack();
|
240
240
|
stack.on('change:top', (evt, data)=>{
|
241
241
|
if (data.oldDescriptor) {
|
242
242
|
remove(element, data.oldDescriptor, data.writer);
|
@@ -271,9 +271,10 @@ import { throttle } from 'es-toolkit/compat';
|
|
271
271
|
}, '');
|
272
272
|
}
|
273
273
|
/**
|
274
|
-
* Adds functionality to the provided {@link module:engine/view/editableelement~
|
274
|
+
* Adds functionality to the provided {@link module:engine/view/editableelement~ViewEditableElement} to act as a widget's editable:
|
275
275
|
*
|
276
|
-
* * sets the `contenteditable` attribute to `true` when
|
276
|
+
* * sets the `contenteditable` attribute to `true` when
|
277
|
+
* {@link module:engine/view/editableelement~ViewEditableElement#isReadOnly} is `false`,
|
277
278
|
* otherwise sets it to `false`,
|
278
279
|
* * adds the `ck-editor__editable` and `ck-editor__nested-editable` CSS classes,
|
279
280
|
* * adds the `ck-editor__nested-editable_focused` CSS class when the editable is focused and removes it when it is blurred.
|
@@ -504,6 +505,8 @@ import { throttle } from 'es-toolkit/compat';
|
|
504
505
|
/**
|
505
506
|
* The name of the type around model selection attribute responsible for
|
506
507
|
* displaying a fake caret next to a selected widget.
|
508
|
+
*
|
509
|
+
* @internal
|
507
510
|
*/ const TYPE_AROUND_SELECTION_ATTRIBUTE = 'widget-type-around';
|
508
511
|
/**
|
509
512
|
* Checks if an element is a widget that qualifies to get the widget type around UI.
|
@@ -512,6 +515,8 @@ import { throttle } from 'es-toolkit/compat';
|
|
512
515
|
}
|
513
516
|
/**
|
514
517
|
* For the passed HTML element, this helper finds the closest widget type around button ancestor.
|
518
|
+
*
|
519
|
+
* @internal
|
515
520
|
*/ function getClosestTypeAroundDomButton(domElement) {
|
516
521
|
return domElement.closest('.ck-widget__type-around__button');
|
517
522
|
}
|
@@ -520,12 +525,15 @@ import { throttle } from 'es-toolkit/compat';
|
|
520
525
|
* the paragraph would be inserted into the content if, for instance, the button was
|
521
526
|
* clicked by the user.
|
522
527
|
*
|
528
|
+
* @internal
|
523
529
|
* @returns The position of the button.
|
524
530
|
*/ function getTypeAroundButtonPosition(domElement) {
|
525
531
|
return domElement.classList.contains('ck-widget__type-around__button_before') ? 'before' : 'after';
|
526
532
|
}
|
527
533
|
/**
|
528
534
|
* For the passed HTML element, this helper returns the closest view widget ancestor.
|
535
|
+
*
|
536
|
+
* @internal
|
529
537
|
*/ function getClosestWidgetViewElement(domElement, domConverter) {
|
530
538
|
const widgetDomElement = domElement.closest('.ck-widget');
|
531
539
|
return domConverter.mapDomToView(widgetDomElement);
|
@@ -535,6 +543,7 @@ import { throttle } from 'es-toolkit/compat';
|
|
535
543
|
*
|
536
544
|
* **Note**: If the fake caret is not currently displayed, `null` is returned.
|
537
545
|
*
|
546
|
+
* @internal
|
538
547
|
* @returns The position of the fake caret or `null` when none is present.
|
539
548
|
*/ function getTypeAroundFakeCaretPosition(selection) {
|
540
549
|
return selection.getAttribute(TYPE_AROUND_SELECTION_ATTRIBUTE);
|
@@ -685,7 +694,7 @@ const PLUGIN_DISABLED_EDITING_ROOT_CLASS = 'ck-widget__type-around_disabled';
|
|
685
694
|
* Creates a listener in the editing conversion pipeline that injects the widget type around
|
686
695
|
* UI into every single widget instance created in the editor.
|
687
696
|
*
|
688
|
-
* The UI is delivered as a {@link module:engine/view/uielement~
|
697
|
+
* The UI is delivered as a {@link module:engine/view/uielement~ViewUIElement}
|
689
698
|
* wrapper which renders DOM buttons that users can use to insert paragraphs.
|
690
699
|
*/ _enableTypeAroundUIInjection() {
|
691
700
|
const editor = this.editor;
|
@@ -1287,7 +1296,7 @@ function injectFakeCaret(wrapperDomElement) {
|
|
1287
1296
|
* Returns 'keydown' handler for up/down arrow keys that modifies the caret movement if it's in a text line next to an object.
|
1288
1297
|
*
|
1289
1298
|
* @param editing The editing controller.
|
1290
|
-
*/ function
|
1299
|
+
*/ function verticalWidgetNavigationHandler(editing) {
|
1291
1300
|
const model = editing.model;
|
1292
1301
|
return (evt, data)=>{
|
1293
1302
|
const arrowUpPressed = data.keyCode == keyCodes.arrowup;
|
@@ -1477,7 +1486,7 @@ function selectionWillShrink(selection, isForward) {
|
|
1477
1486
|
*
|
1478
1487
|
* * The model to view selection converter for the editing pipeline (it handles widget custom selection rendering).
|
1479
1488
|
* If a converted selection wraps around a widget element, that selection is marked as
|
1480
|
-
* {@link module:engine/view/selection~
|
1489
|
+
* {@link module:engine/view/selection~ViewSelection#isFake fake}. Additionally, the `ck-widget_selected` CSS class
|
1481
1490
|
* is added to indicate that widget has been selected.
|
1482
1491
|
* * The mouse and keyboard events handling on and around widget elements.
|
1483
1492
|
*/ class Widget extends Plugin {
|
@@ -1602,7 +1611,7 @@ function selectionWillShrink(selection, isForward) {
|
|
1602
1611
|
}, {
|
1603
1612
|
context: '$root'
|
1604
1613
|
});
|
1605
|
-
this.listenTo(viewDocument, 'arrowKey',
|
1614
|
+
this.listenTo(viewDocument, 'arrowKey', verticalWidgetNavigationHandler(this.editor.editing), {
|
1606
1615
|
context: '$text'
|
1607
1616
|
});
|
1608
1617
|
// Handle custom delete behaviour.
|
@@ -1699,7 +1708,7 @@ function selectionWillShrink(selection, isForward) {
|
|
1699
1708
|
});
|
1700
1709
|
}
|
1701
1710
|
/**
|
1702
|
-
* Handles {@link module:engine/view/document~
|
1711
|
+
* Handles {@link module:engine/view/document~ViewDocument#event:mousedown mousedown} events on widget elements.
|
1703
1712
|
*/ _onMousedown(eventInfo, domEventData) {
|
1704
1713
|
const editor = this.editor;
|
1705
1714
|
const view = editor.editing.view;
|
@@ -1768,7 +1777,7 @@ function selectionWillShrink(selection, isForward) {
|
|
1768
1777
|
return true;
|
1769
1778
|
}
|
1770
1779
|
/**
|
1771
|
-
* Handles {@link module:engine/view/document~
|
1780
|
+
* Handles {@link module:engine/view/document~ViewDocument#event:keydown keydown} events and changes
|
1772
1781
|
* the model selection when:
|
1773
1782
|
*
|
1774
1783
|
* * arrow key is pressed when the widget is selected,
|
@@ -1830,7 +1839,7 @@ function selectionWillShrink(selection, isForward) {
|
|
1830
1839
|
}
|
1831
1840
|
}
|
1832
1841
|
/**
|
1833
|
-
* Handles {@link module:engine/view/document~
|
1842
|
+
* Handles {@link module:engine/view/document~ViewDocument#event:keydown keydown} events and prevents
|
1834
1843
|
* the default browser behavior to make sure the fake selection is not being moved from a fake selection
|
1835
1844
|
* container.
|
1836
1845
|
*
|
@@ -1877,7 +1886,7 @@ function selectionWillShrink(selection, isForward) {
|
|
1877
1886
|
}
|
1878
1887
|
}
|
1879
1888
|
/**
|
1880
|
-
* Sets {@link module:engine/model/selection~
|
1889
|
+
* Sets {@link module:engine/model/selection~ModelSelection document's selection} over given element.
|
1881
1890
|
*
|
1882
1891
|
* @internal
|
1883
1892
|
*/ _setSelectionOverElement(element) {
|
@@ -1886,9 +1895,9 @@ function selectionWillShrink(selection, isForward) {
|
|
1886
1895
|
});
|
1887
1896
|
}
|
1888
1897
|
/**
|
1889
|
-
* Checks if {@link module:engine/model/element~
|
1890
|
-
* {@link module:engine/model/selection~
|
1891
|
-
* {@link module:engine/model/schema~
|
1898
|
+
* Checks if {@link module:engine/model/element~ModelElement element} placed next to the current
|
1899
|
+
* {@link module:engine/model/selection~ModelSelection model selection} exists and is marked in
|
1900
|
+
* {@link module:engine/model/schema~ModelSchema schema} as `object`.
|
1892
1901
|
*
|
1893
1902
|
* @internal
|
1894
1903
|
* @param forward Direction of checking.
|
@@ -2051,7 +2060,7 @@ function selectionWillShrink(selection, isForward) {
|
|
2051
2060
|
/**
|
2052
2061
|
* Returns next text block where could put selection.
|
2053
2062
|
*/ function findNextTextBlock(position, schema) {
|
2054
|
-
const treeWalker = new
|
2063
|
+
const treeWalker = new ModelTreeWalker({
|
2055
2064
|
startPosition: position
|
2056
2065
|
});
|
2057
2066
|
for (const { item } of treeWalker){
|
@@ -2326,7 +2335,7 @@ function isWidgetSelected(selection) {
|
|
2326
2335
|
|
2327
2336
|
/**
|
2328
2337
|
* Stores the internal state of a single resizable object.
|
2329
|
-
*/ class
|
2338
|
+
*/ class WidgetResizeState extends /* #__PURE__ */ ObservableMixin() {
|
2330
2339
|
/**
|
2331
2340
|
* The reference point of the resizer where the dragging started. It is used to measure the distance the user cursor
|
2332
2341
|
* traveled, so how much the image should be enlarged.
|
@@ -2470,6 +2479,8 @@ function isWidgetSelected(selection) {
|
|
2470
2479
|
|
2471
2480
|
/**
|
2472
2481
|
* A view displaying the proposed new element size during the resizing.
|
2482
|
+
*
|
2483
|
+
* @internal
|
2473
2484
|
*/ class SizeView extends View {
|
2474
2485
|
constructor(){
|
2475
2486
|
super();
|
@@ -2523,7 +2534,7 @@ function isWidgetSelected(selection) {
|
|
2523
2534
|
|
2524
2535
|
/**
|
2525
2536
|
* Represents a resizer for a single resizable object.
|
2526
|
-
*/ class
|
2537
|
+
*/ class WidgetResizer extends /* #__PURE__ */ ObservableMixin() {
|
2527
2538
|
/**
|
2528
2539
|
* Stores the state of the resizable host geometry, such as the original width, the currently proposed height, etc.
|
2529
2540
|
*
|
@@ -2539,7 +2550,7 @@ function isWidgetSelected(selection) {
|
|
2539
2550
|
* A wrapper that is controlled by the resizer. This is usually a widget element.
|
2540
2551
|
*/ _viewResizerWrapper = null;
|
2541
2552
|
/**
|
2542
|
-
* The width of the resized {@link module:widget/widgetresize~
|
2553
|
+
* The width of the resized {@link module:widget/widgetresize~WidgetResizerOptions#viewElement viewElement} before the resizing started.
|
2543
2554
|
*/ _initialViewWidth;
|
2544
2555
|
/**
|
2545
2556
|
* @param options Resizer options.
|
@@ -2628,7 +2639,7 @@ function isWidgetSelected(selection) {
|
|
2628
2639
|
* @fires begin
|
2629
2640
|
* @param domResizeHandle Clicked handle.
|
2630
2641
|
*/ begin(domResizeHandle) {
|
2631
|
-
this._state = new
|
2642
|
+
this._state = new WidgetResizeState(this._options);
|
2632
2643
|
this._sizeView._bindToState(this._options, this.state);
|
2633
2644
|
this._initialViewWidth = this._options.viewElement.getStyle('width');
|
2634
2645
|
this.state.begin(domResizeHandle, this._getHandleHost(), this._getResizeHost());
|
@@ -2974,7 +2985,7 @@ function existsInDom(element) {
|
|
2974
2985
|
/**
|
2975
2986
|
* @param options Resizer options.
|
2976
2987
|
*/ attachTo(options) {
|
2977
|
-
const resizer = new
|
2988
|
+
const resizer = new WidgetResizer(options);
|
2978
2989
|
const plugins = this.editor.plugins;
|
2979
2990
|
resizer.attach();
|
2980
2991
|
if (plugins.has('WidgetToolbarRepository')) {
|
@@ -3026,7 +3037,7 @@ function existsInDom(element) {
|
|
3026
3037
|
* @param domEventData Native DOM event.
|
3027
3038
|
*/ _mouseDownListener(event, domEventData) {
|
3028
3039
|
const resizeHandle = domEventData.domTarget;
|
3029
|
-
if (!
|
3040
|
+
if (!WidgetResizer.isResizeHandle(resizeHandle)) {
|
3030
3041
|
return;
|
3031
3042
|
}
|
3032
3043
|
this._activeResizer = this._getResizerByHandle(resizeHandle) || null;
|
@@ -3052,5 +3063,5 @@ function existsInDom(element) {
|
|
3052
3063
|
}
|
3053
3064
|
}
|
3054
3065
|
|
3055
|
-
export { WIDGET_CLASS_NAME, WIDGET_SELECTED_CLASS_NAME, Widget, WidgetResize, WidgetToolbarRepository, WidgetTypeAround, calculateResizeHostAncestorWidth, calculateResizeHostPercentageWidth, findOptimalInsertionRange, getLabel, isWidget, setHighlightHandling, setLabel, toWidget, toWidgetEditable, viewToModelPositionOutsideModelElement };
|
3066
|
+
export { WIDGET_CLASS_NAME, WIDGET_SELECTED_CLASS_NAME, Widget, WidgetHighlightStack, WidgetResize, WidgetResizeState, WidgetResizer, WidgetToolbarRepository, WidgetTypeAround, TYPE_AROUND_SELECTION_ATTRIBUTE as _WIDGET_TYPE_AROUND_SELECTION_ATTRIBUTE, SizeView as _WidgetSizeView, getClosestTypeAroundDomButton as _getClosestWidgetTypeAroundDomButton, getClosestWidgetViewElement as _getClosestWidgetViewElement, getTypeAroundButtonPosition as _getWidgetTypeAroundButtonPosition, getTypeAroundFakeCaretPosition as _getWidgetTypeAroundFakeCaretPosition, calculateResizeHostAncestorWidth, calculateResizeHostPercentageWidth, findOptimalInsertionRange, getLabel, isTypeAroundWidget, isWidget, setHighlightHandling, setLabel, toWidget, toWidgetEditable, verticalWidgetNavigationHandler, viewToModelPositionOutsideModelElement };
|
3056
3067
|
//# sourceMappingURL=index.js.map
|