@ckeditor/ckeditor5-widget 46.0.2 → 46.1.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/dist/index.js +35 -10
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/utils.js +15 -3
- package/src/widget.d.ts +4 -0
- package/src/widget.js +22 -7
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, ModelTreeWalker } from '@ckeditor/ckeditor5-engine/dist/index.js';
|
6
|
+
import { MouseObserver, PointerObserver, 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';
|
@@ -323,15 +323,26 @@ import { throttle } from 'es-toolkit/compat';
|
|
323
323
|
if (options.withAriaRole !== false) {
|
324
324
|
writer.setAttribute('role', 'textbox', editable);
|
325
325
|
}
|
326
|
-
|
326
|
+
// Setting tabindex=-1 on contenteditable=false makes it focusable. It propagates focus to the editable
|
327
|
+
// element and makes it possible to highlight nested editables as focused. It's not what we want
|
328
|
+
// for read-only editables though.
|
329
|
+
// See more: https://github.com/ckeditor/ckeditor5/issues/18965
|
330
|
+
if (!editable.isReadOnly) {
|
331
|
+
writer.setAttribute('tabindex', '-1', editable);
|
332
|
+
}
|
327
333
|
if (options.label) {
|
328
334
|
writer.setAttribute('aria-label', options.label, editable);
|
329
335
|
}
|
330
336
|
// Set initial contenteditable value.
|
331
337
|
writer.setAttribute('contenteditable', editable.isReadOnly ? 'false' : 'true', editable);
|
332
338
|
// Bind the contenteditable property to element#isReadOnly.
|
333
|
-
editable.on('change:isReadOnly', (evt, property,
|
334
|
-
writer.setAttribute('contenteditable',
|
339
|
+
editable.on('change:isReadOnly', (evt, property, isReadonly)=>{
|
340
|
+
writer.setAttribute('contenteditable', isReadonly ? 'false' : 'true', editable);
|
341
|
+
if (isReadonly) {
|
342
|
+
writer.removeAttribute('tabindex', editable);
|
343
|
+
} else {
|
344
|
+
writer.setAttribute('tabindex', '-1', editable);
|
345
|
+
}
|
335
346
|
});
|
336
347
|
editable.on('change:isFocused', (evt, property, is)=>{
|
337
348
|
if (is) {
|
@@ -1586,7 +1597,9 @@ function selectionWillShrink(selection, isForward) {
|
|
1586
1597
|
});
|
1587
1598
|
// If mouse down is pressed on widget - create selection over whole widget.
|
1588
1599
|
view.addObserver(MouseObserver);
|
1600
|
+
view.addObserver(PointerObserver);
|
1589
1601
|
this.listenTo(viewDocument, 'mousedown', (...args)=>this._onMousedown(...args));
|
1602
|
+
this.listenTo(viewDocument, 'pointerdown', (...args)=>this._onPointerdown(...args));
|
1590
1603
|
// There are two keydown listeners working on different priorities. This allows other
|
1591
1604
|
// features such as WidgetTypeAround or TableKeyboard to attach their listeners in between
|
1592
1605
|
// and customize the behavior even further in different content/selection scenarios.
|
@@ -1710,10 +1723,7 @@ function selectionWillShrink(selection, isForward) {
|
|
1710
1723
|
/**
|
1711
1724
|
* Handles {@link module:engine/view/document~ViewDocument#event:mousedown mousedown} events on widget elements.
|
1712
1725
|
*/ _onMousedown(eventInfo, domEventData) {
|
1713
|
-
const
|
1714
|
-
const view = editor.editing.view;
|
1715
|
-
const viewDocument = view.document;
|
1716
|
-
let element = domEventData.target;
|
1726
|
+
const element = domEventData.target;
|
1717
1727
|
// Some of DOM elements have no view element representation so it may be null.
|
1718
1728
|
if (!element) {
|
1719
1729
|
return;
|
@@ -1723,6 +1733,20 @@ function selectionWillShrink(selection, isForward) {
|
|
1723
1733
|
if (this._selectBlockContent(element)) {
|
1724
1734
|
domEventData.preventDefault();
|
1725
1735
|
}
|
1736
|
+
}
|
1737
|
+
}
|
1738
|
+
/**
|
1739
|
+
* Handles {@link module:engine/view/document~ViewDocument#event:pointerdown pointerdown} events on widget elements.
|
1740
|
+
*/ _onPointerdown(eventInfo, domEventData) {
|
1741
|
+
if (!domEventData.domEvent.isPrimary) {
|
1742
|
+
return;
|
1743
|
+
}
|
1744
|
+
const editor = this.editor;
|
1745
|
+
const view = editor.editing.view;
|
1746
|
+
const viewDocument = view.document;
|
1747
|
+
let element = domEventData.target;
|
1748
|
+
// Some of DOM elements have no view element representation so it may be null.
|
1749
|
+
if (!element) {
|
1726
1750
|
return;
|
1727
1751
|
}
|
1728
1752
|
// If target is not a widget element - check if one of the ancestors is.
|
@@ -1743,9 +1767,10 @@ function selectionWillShrink(selection, isForward) {
|
|
1743
1767
|
}
|
1744
1768
|
}
|
1745
1769
|
}
|
1746
|
-
// On Android selection would jump to the first table cell, on other devices
|
1770
|
+
// On Android and iOS selection would jump to the first table cell, on other devices
|
1747
1771
|
// we can't block it (and don't need to) because of drag and drop support.
|
1748
|
-
|
1772
|
+
// In iOS drag and drop works anyway on a long press.
|
1773
|
+
if (env.isAndroid || env.isiOS) {
|
1749
1774
|
domEventData.preventDefault();
|
1750
1775
|
}
|
1751
1776
|
// Focus editor if is not focused already.
|