ckeditor5-elements-interaction 49.0.0-alpha.4 → 49.0.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/README.md +2 -2
- package/dist/augmentation.d.ts +2 -2
- package/dist/augmentation.d.ts.map +1 -1
- package/dist/elementClickable.d.ts +2 -2
- package/dist/elementClickable.js +3 -3
- package/dist/elementClickable.js.map +1 -1
- package/dist/elementSelectable.d.ts +3 -3
- package/dist/elementSelectable.d.ts.map +1 -1
- package/dist/elementSelectable.js +16 -12
- package/dist/elementSelectable.js.map +1 -1
- package/dist/navigation.d.ts.map +1 -1
- package/dist/navigation.js +4 -3
- package/dist/navigation.js.map +1 -1
- package/package.json +2 -2
- package/src/augmentation.ts +2 -2
- package/src/elementClickable.ts +3 -3
- package/src/elementSelectable.ts +21 -12
- package/src/navigation.ts +4 -7
package/README.md
CHANGED
|
@@ -24,8 +24,8 @@ import { ElementClickable, ElementSelectable } from 'ckeditor5-elements';
|
|
|
24
24
|
|
|
25
25
|
// In the editor config:
|
|
26
26
|
plugins: [..., ElementSelectable, ElementClickable],
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
elementSelectable: ['callout', 'divider', element => element.hasAttribute('card')],
|
|
28
|
+
elementClickable: [
|
|
29
29
|
// By name. The default event is `click`.
|
|
30
30
|
{ element: 'imageBlock', callback: (element, editor) => console.log(element.getAttribute('src')) },
|
|
31
31
|
// By a filter, on double click.
|
package/dist/augmentation.d.ts
CHANGED
|
@@ -9,11 +9,11 @@ declare module 'ckeditor5' {
|
|
|
9
9
|
* The elements that can be selected as a whole: names of model elements, or filter functions. See
|
|
10
10
|
* {@link ElementSelectable}.
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
elementSelectable?: ElementSelectableMatcher[];
|
|
13
13
|
/**
|
|
14
14
|
* The elements that react to clicks and double clicks. See {@link ElementClickable}.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
elementClickable?: ElementClickableDefinition[];
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
//# sourceMappingURL=augmentation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"augmentation.d.ts","sourceRoot":"","sources":["../src/augmentation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,gBAAgB,EAChB,0BAA0B,EAC1B,iBAAiB,EACjB,wBAAwB,EACxB,MAAM,YAAY,CAAC;AAEpB,OAAO,QAAQ,WAAW,CAAC;IAC1B,UAAU,UAAU;QACnB,CAAC,iBAAiB,CAAC,UAAU,CAAC,EAAE,iBAAiB,CAAC;QAClD,CAAC,gBAAgB,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAC;KAChD;IAED,UAAU,YAAY;QACrB;;;WAGG;QACH,
|
|
1
|
+
{"version":3,"file":"augmentation.d.ts","sourceRoot":"","sources":["../src/augmentation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,gBAAgB,EAChB,0BAA0B,EAC1B,iBAAiB,EACjB,wBAAwB,EACxB,MAAM,YAAY,CAAC;AAEpB,OAAO,QAAQ,WAAW,CAAC;IAC1B,UAAU,UAAU;QACnB,CAAC,iBAAiB,CAAC,UAAU,CAAC,EAAE,iBAAiB,CAAC;QAClD,CAAC,gBAAgB,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAC;KAChD;IAED,UAAU,YAAY;QACrB;;;WAGG;QACH,iBAAiB,CAAC,EAAE,wBAAwB,EAAE,CAAC;QAE/C;;WAEG;QACH,gBAAgB,CAAC,EAAE,0BAA0B,EAAE,CAAC;KAChD;CACD"}
|
|
@@ -24,11 +24,11 @@ export interface ElementClickableDefinition {
|
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Calls a function when an element is clicked or double-clicked, with the model element. Elements are matched by name or
|
|
27
|
-
* by a filter function, and the definitions are the `
|
|
27
|
+
* by a filter function, and the definitions are the `elementClickable` editor config option (see
|
|
28
28
|
* {@link ElementClickableDefinition}):
|
|
29
29
|
*
|
|
30
30
|
* ```ts
|
|
31
|
-
*
|
|
31
|
+
* elementClickable: [
|
|
32
32
|
* { element: 'imageBlock', callback: (element, editor) => console.log(element.getAttribute('src')) },
|
|
33
33
|
* { element: element => element.name.startsWith('heading'), event: 'dblclick', callback: edit }
|
|
34
34
|
* ];
|
package/dist/elementClickable.js
CHANGED
|
@@ -3,11 +3,11 @@ import { getElementsAround, matchesElement } from 'ckeditor5-elements-core';
|
|
|
3
3
|
import DoubleClickObserver, {} from './doubleClickObserver.js';
|
|
4
4
|
/**
|
|
5
5
|
* Calls a function when an element is clicked or double-clicked, with the model element. Elements are matched by name or
|
|
6
|
-
* by a filter function, and the definitions are the `
|
|
6
|
+
* by a filter function, and the definitions are the `elementClickable` editor config option (see
|
|
7
7
|
* {@link ElementClickableDefinition}):
|
|
8
8
|
*
|
|
9
9
|
* ```ts
|
|
10
|
-
*
|
|
10
|
+
* elementClickable: [
|
|
11
11
|
* { element: 'imageBlock', callback: (element, editor) => console.log(element.getAttribute('src')) },
|
|
12
12
|
* { element: element => element.name.startsWith('heading'), event: 'dblclick', callback: edit }
|
|
13
13
|
* ];
|
|
@@ -43,7 +43,7 @@ export default class ElementClickable extends Plugin {
|
|
|
43
43
|
*/
|
|
44
44
|
find(viewElement, event = 'click') {
|
|
45
45
|
const mapper = this.editor.editing.mapper;
|
|
46
|
-
const definitions = (this.editor.config.get('
|
|
46
|
+
const definitions = (this.editor.config.get('elementClickable') ?? []).filter(definition => (definition.event ?? 'click') === event);
|
|
47
47
|
for (const { element } of getElementsAround(mapper, viewElement)) {
|
|
48
48
|
const definition = definitions.find(({ element: matcher }) => matchesElement(matcher, element));
|
|
49
49
|
if (definition) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"elementClickable.js","sourceRoot":"","sources":["../src/elementClickable.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,aAAa,EACb,MAAM,EAKN,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE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,CAAC,MAAM,CAAC;QAC1C,MAAM,WAAW,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAC5E,UAAU,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,KAAK,CACrD,CAAC;QAEF,KAAK,MAAM,EAAE,OAAO,EAAE,IAAI,iBAAiB,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,CAAC;YAClE,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;YAEhG,IAAI,UAAU,EAAE,CAAC;gBAChB,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;YAChC,CAAC;QACF,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;IAEO,OAAO,CAAC,KAA4B,EAAE,MAAmB,EAAE,QAAoB;QACtF,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAE/D,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAClE,CAAC;CACD"}
|
|
@@ -8,10 +8,10 @@ export type ElementSelectableMatcher = ElementMatcher;
|
|
|
8
8
|
/**
|
|
9
9
|
* Makes elements selectable as a whole, which is what CKEditor's widgets do, without them: it does not change the view
|
|
10
10
|
* of the element, and does not need the `Widget` plugin. The elements are matched by name or by a filter function, and
|
|
11
|
-
* they are the `
|
|
11
|
+
* they are the `elementSelectable` editor config option:
|
|
12
12
|
*
|
|
13
13
|
* ```ts
|
|
14
|
-
*
|
|
14
|
+
* elementSelectable: ['callout', 'divider', element => element.hasAttribute('card')];
|
|
15
15
|
* ```
|
|
16
16
|
*
|
|
17
17
|
* An element is selected (the model selection is *on* it, and the view has a fake selection and the
|
|
@@ -40,7 +40,7 @@ export default class ElementSelectable extends Plugin {
|
|
|
40
40
|
init(): void;
|
|
41
41
|
afterInit(): void;
|
|
42
42
|
/**
|
|
43
|
-
* Makes more elements selectable, as the `
|
|
43
|
+
* Makes more elements selectable, as the `elementSelectable` option does: a name of a model element, or a filter.
|
|
44
44
|
* Used by features that add elements, e.g. the element schema.
|
|
45
45
|
*/
|
|
46
46
|
add(...matchers: ElementSelectableMatcher[]): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"elementSelectable.d.ts","sourceRoot":"","sources":["../src/elementSelectable.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,MAAM,EAKN,KAAK,YAAY,EAKjB,MAAM,WAAW,CAAC;AACnB,OAAO,
|
|
1
|
+
{"version":3,"file":"elementSelectable.d.ts","sourceRoot":"","sources":["../src/elementSelectable.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,MAAM,EAKN,KAAK,YAAY,EAKjB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAyD,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGrH;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG,cAAc,CAAC;AAOtD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,MAAM;IACpD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAkC;IAC5D,OAAO,CAAC,SAAS,CAA4B;IAE7C,WAAkB,UAAU,IAAI,mBAAmB,CAElD;IAEM,IAAI,IAAI,IAAI;IAoFZ,SAAS,IAAI,IAAI;IAaxB;;;OAGG;IACI,GAAG,CAAC,GAAG,QAAQ,EAAE,wBAAwB,EAAE,GAAG,IAAI;IAKzD;;OAEG;IACI,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO;IAInD;;OAEG;IACH,OAAO,CAAC,OAAO;IAMf;;OAEG;IACH,OAAO,CAAC,eAAe;IAUvB;;;OAGG;IACH,OAAO,CAAC,aAAa;IAUrB;;OAEG;IACH,OAAO,CAAC,eAAe;IAiCvB;;OAEG;IACH,OAAO,CAAC,WAAW;IAInB;;OAEG;IACH,OAAO,CAAC,KAAK;CAeb"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MouseObserver, Plugin, keyCodes, isArrowKeyCode, isForwardArrowKeyCode } from 'ckeditor5';
|
|
2
|
-
import { getElementsAround, matchesElement } from 'ckeditor5-elements-core';
|
|
2
|
+
import { getElementsAround, keyboardPriorities, matchesElement } from 'ckeditor5-elements-core';
|
|
3
3
|
import { findLeaveTarget, findSelectableAfterStep, findSelectableAround } from './navigation.js';
|
|
4
4
|
/**
|
|
5
5
|
* The class of the selected element in the editing view.
|
|
@@ -8,10 +8,10 @@ const SELECTED_CLASS = 'ck-elements-selected';
|
|
|
8
8
|
/**
|
|
9
9
|
* Makes elements selectable as a whole, which is what CKEditor's widgets do, without them: it does not change the view
|
|
10
10
|
* of the element, and does not need the `Widget` plugin. The elements are matched by name or by a filter function, and
|
|
11
|
-
* they are the `
|
|
11
|
+
* they are the `elementSelectable` editor config option:
|
|
12
12
|
*
|
|
13
13
|
* ```ts
|
|
14
|
-
*
|
|
14
|
+
* elementSelectable: ['callout', 'divider', element => element.hasAttribute('card')];
|
|
15
15
|
* ```
|
|
16
16
|
*
|
|
17
17
|
* An element is selected (the model selection is *on* it, and the view has a fake selection and the
|
|
@@ -43,7 +43,7 @@ export default class ElementSelectable extends Plugin {
|
|
|
43
43
|
const editor = this.editor;
|
|
44
44
|
const view = editor.editing.view;
|
|
45
45
|
const viewDocument = view.document;
|
|
46
|
-
this._matchers.push(...(editor.config.get('
|
|
46
|
+
this._matchers.push(...(editor.config.get('elementSelectable') ?? []));
|
|
47
47
|
// The selection of an element is a fake one, as for widgets: the browser does not draw the selection on its own.
|
|
48
48
|
editor.editing.downcastDispatcher.on('selection', (evt, data, conversionApi) => {
|
|
49
49
|
const element = data.selection.getSelectedElement();
|
|
@@ -68,9 +68,9 @@ export default class ElementSelectable extends Plugin {
|
|
|
68
68
|
this._select(element);
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
|
-
// The arrow keys are handled on `keydown`,
|
|
72
|
-
// from the selection, and CKEditor's widgets (loaded by other features, e.g. the clipboard) handle it for
|
|
73
|
-
// object, in a context that is reached before this plugin could.
|
|
71
|
+
// The arrow keys are handled on `keydown`, before CKEditor's widgets, and not as the `arrowKey` event: that one
|
|
72
|
+
// bubbles from the selection, and CKEditor's widgets (loaded by other features, e.g. the clipboard) handle it for
|
|
73
|
+
// every object, in a context that is reached before this plugin could.
|
|
74
74
|
this.listenTo(viewDocument, 'keydown', (evt, data) => {
|
|
75
75
|
const isPlain = !data.shiftKey && !data.ctrlKey && !data.altKey && !data.metaKey;
|
|
76
76
|
if (this.isEnabled &&
|
|
@@ -80,8 +80,8 @@ export default class ElementSelectable extends Plugin {
|
|
|
80
80
|
data.preventDefault();
|
|
81
81
|
evt.stop();
|
|
82
82
|
}
|
|
83
|
-
}, { priority:
|
|
84
|
-
// Esc
|
|
83
|
+
}, { priority: keyboardPriorities.selectable });
|
|
84
|
+
// Esc goes after what else uses it, e.g. closing a balloon. Editor keystrokes (`cancel()`)
|
|
85
85
|
// do not stop this event, they prevent the default action of the DOM event: then Esc is handled already.
|
|
86
86
|
this.listenTo(viewDocument, 'keydown', (evt, data) => {
|
|
87
87
|
const isFree = data.keystroke === keyCodes.esc && !data.domEvent.defaultPrevented;
|
|
@@ -91,13 +91,17 @@ export default class ElementSelectable extends Plugin {
|
|
|
91
91
|
data.preventDefault();
|
|
92
92
|
evt.stop();
|
|
93
93
|
}
|
|
94
|
-
}, { priority:
|
|
94
|
+
}, { priority: keyboardPriorities.selectableEsc });
|
|
95
95
|
}
|
|
96
96
|
afterInit() {
|
|
97
|
-
|
|
97
|
+
// Before the data is loaded, once all the elements are registered: also the ones that other plugins register in
|
|
98
|
+
// `afterInit()`, e.g. the element schema, whichever plugin comes first.
|
|
99
|
+
this.listenTo(this.editor.data, 'init', () => {
|
|
100
|
+
this._makeSelectable(this._matchers);
|
|
101
|
+
}, { priority: 'high' });
|
|
98
102
|
}
|
|
99
103
|
/**
|
|
100
|
-
* Makes more elements selectable, as the `
|
|
104
|
+
* Makes more elements selectable, as the `elementSelectable` option does: a name of a model element, or a filter.
|
|
101
105
|
* Used by features that add elements, e.g. the element schema.
|
|
102
106
|
*/
|
|
103
107
|
add(...matchers) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"elementSelectable.js","sourceRoot":"","sources":["../src/elementSelectable.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,aAAa,EACb,MAAM,EACN,QAAQ,EACR,cAAc,EACd,qBAAqB,EAOrB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAuB,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"elementSelectable.js","sourceRoot":"","sources":["../src/elementSelectable.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,aAAa,EACb,MAAM,EACN,QAAQ,EACR,cAAc,EACd,qBAAqB,EAOrB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,cAAc,EAAuB,MAAM,yBAAyB,CAAC;AACrH,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAQjG;;GAEG;AACH,MAAM,cAAc,GAAG,sBAAsB,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,MAAM;IACnC,SAAS,GAA+B,EAAE,CAAC;IACpD,SAAS,GAAuB,IAAI,CAAC;IAEtC,MAAM,KAAK,UAAU;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M,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;QAC1C,MAAM,OAAO,GAAG,QAAQ,IAAI,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAC5D,MAAM,MAAM,GAAG,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;QAEvE,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,KAAK,MAAM,EAAE,CAAC;YACjD,MAAM,CAAC,WAAW,CAAC,cAAc,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QACpD,CAAC;QAED,IAAI,MAAM,EAAE,CAAC;YACZ,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;QACzC,CAAC;QAED,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC;IACzB,CAAC;CACD"}
|
package/dist/navigation.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../src/navigation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,sBAAsB,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../src/navigation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,sBAAsB,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAGzG;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC;AAE9D;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACtC,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,cAAc,GAAG,sBAAsB,EAClD,SAAS,EAAE,OAAO,EAClB,YAAY,EAAE,YAAY,GACxB,YAAY,GAAG,IAAI,CAuBrB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC9B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,YAAY,EACrB,SAAS,EAAE,OAAO,EAClB,YAAY,EAAE,YAAY,GACxB,UAAU,GAAG,IAAI,CAOnB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CACnC,SAAS,EAAE,cAAc,GAAG,sBAAsB,EAClD,YAAY,EAAE,YAAY,GACxB,YAAY,GAAG,IAAI,CAUrB"}
|
package/dist/navigation.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getAncestorElements } from 'ckeditor5-elements-core';
|
|
1
2
|
/**
|
|
2
3
|
* Returns the selectable element that the cursor reaches with one step in the direction, as the arrow key moves it, or
|
|
3
4
|
* `null`: the next element is not selectable, or the step stays in the text. The step is CKEditor's: a character in the
|
|
@@ -38,9 +39,9 @@ export function findLeaveTarget(model, element, isForward, isSelectable) {
|
|
|
38
39
|
*/
|
|
39
40
|
export function findSelectableAround(selection, isSelectable) {
|
|
40
41
|
const selected = selection.getSelectedElement();
|
|
41
|
-
for (
|
|
42
|
-
if (isSelectable(
|
|
43
|
-
return
|
|
42
|
+
for (const element of getAncestorElements(selected ? selected.parent : selection.getFirstPosition()?.parent)) {
|
|
43
|
+
if (isSelectable(element)) {
|
|
44
|
+
return element;
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
return null;
|
package/dist/navigation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation.js","sourceRoot":"","sources":["../src/navigation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"navigation.js","sourceRoot":"","sources":["../src/navigation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAO9D;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CACtC,KAAY,EACZ,SAAkD,EAClD,SAAk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AC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IACjF,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC;IAEvE,OAAO,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,YAAY,CAAC,SAAS,CAAC;QACzD,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC;QAChC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,wBAAwB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;AACxF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CACnC,SAAkD,EAClD,YAA0B;IAE1B,MAAM,QAAQ,GAAG,SAAS,CAAC,kBAAkB,EAAE,CAAC;IAEhD,KAAK,MAAM,OAAO,IAAI,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,gBAAgB,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC;QAC9G,IAAI,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3B,OAAO,OAAO,CAAC;QAChB,CAAC;IACF,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ckeditor5-elements-interaction",
|
|
3
|
-
"version": "49.0.0
|
|
3
|
+
"version": "49.0.0",
|
|
4
4
|
"description": "Element interaction for CKEditor 5, without CKEditor's widgets: select an element as a whole by a click or by the arrow keys, and react to clicks and double clicks on elements.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ckeditor",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"*.css"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"ckeditor5-elements-core": "49.0.0
|
|
44
|
+
"ckeditor5-elements-core": "49.0.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"ckeditor5": "^49.0.0"
|
package/src/augmentation.ts
CHANGED
|
@@ -16,11 +16,11 @@ declare module 'ckeditor5' {
|
|
|
16
16
|
* The elements that can be selected as a whole: names of model elements, or filter functions. See
|
|
17
17
|
* {@link ElementSelectable}.
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
elementSelectable?: ElementSelectableMatcher[];
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* The elements that react to clicks and double clicks. See {@link ElementClickable}.
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
elementClickable?: ElementClickableDefinition[];
|
|
25
25
|
}
|
|
26
26
|
}
|
package/src/elementClickable.ts
CHANGED
|
@@ -37,11 +37,11 @@ export interface ElementClickableDefinition {
|
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* Calls a function when an element is clicked or double-clicked, with the model element. Elements are matched by name or
|
|
40
|
-
* by a filter function, and the definitions are the `
|
|
40
|
+
* by a filter function, and the definitions are the `elementClickable` editor config option (see
|
|
41
41
|
* {@link ElementClickableDefinition}):
|
|
42
42
|
*
|
|
43
43
|
* ```ts
|
|
44
|
-
*
|
|
44
|
+
* elementClickable: [
|
|
45
45
|
* { element: 'imageBlock', callback: (element, editor) => console.log(element.getAttribute('src')) },
|
|
46
46
|
* { element: element => element.name.startsWith('heading'), event: 'dblclick', callback: edit }
|
|
47
47
|
* ];
|
|
@@ -94,7 +94,7 @@ export default class ElementClickable extends Plugin {
|
|
|
94
94
|
event: ElementClickableEvent = 'click'
|
|
95
95
|
): { element: ModelElement; definition: ElementClickableDefinition } | null {
|
|
96
96
|
const mapper = this.editor.editing.mapper;
|
|
97
|
-
const definitions = (this.editor.config.get('
|
|
97
|
+
const definitions = (this.editor.config.get('elementClickable') ?? []).filter(
|
|
98
98
|
definition => (definition.event ?? 'click') === event
|
|
99
99
|
);
|
|
100
100
|
|
package/src/elementSelectable.ts
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
type ViewDowncastWriter,
|
|
12
12
|
type ViewElement
|
|
13
13
|
} from 'ckeditor5';
|
|
14
|
-
import { getElementsAround, matchesElement, type ElementMatcher } from 'ckeditor5-elements-core';
|
|
14
|
+
import { getElementsAround, keyboardPriorities, matchesElement, type ElementMatcher } from 'ckeditor5-elements-core';
|
|
15
15
|
import { findLeaveTarget, findSelectableAfterStep, findSelectableAround } from './navigation.js';
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -28,10 +28,10 @@ const SELECTED_CLASS = 'ck-elements-selected';
|
|
|
28
28
|
/**
|
|
29
29
|
* Makes elements selectable as a whole, which is what CKEditor's widgets do, without them: it does not change the view
|
|
30
30
|
* of the element, and does not need the `Widget` plugin. The elements are matched by name or by a filter function, and
|
|
31
|
-
* they are the `
|
|
31
|
+
* they are the `elementSelectable` editor config option:
|
|
32
32
|
*
|
|
33
33
|
* ```ts
|
|
34
|
-
*
|
|
34
|
+
* elementSelectable: ['callout', 'divider', element => element.hasAttribute('card')];
|
|
35
35
|
* ```
|
|
36
36
|
*
|
|
37
37
|
* An element is selected (the model selection is *on* it, and the view has a fake selection and the
|
|
@@ -66,7 +66,7 @@ export default class ElementSelectable extends Plugin {
|
|
|
66
66
|
const view = editor.editing.view;
|
|
67
67
|
const viewDocument = view.document;
|
|
68
68
|
|
|
69
|
-
this._matchers.push(...(editor.config.get('
|
|
69
|
+
this._matchers.push(...(editor.config.get('elementSelectable') ?? []));
|
|
70
70
|
|
|
71
71
|
// The selection of an element is a fake one, as for widgets: the browser does not draw the selection on its own.
|
|
72
72
|
editor.editing.downcastDispatcher.on<DowncastSelectionEvent>('selection', (evt, data, conversionApi) => {
|
|
@@ -101,9 +101,9 @@ export default class ElementSelectable extends Plugin {
|
|
|
101
101
|
}
|
|
102
102
|
});
|
|
103
103
|
|
|
104
|
-
// The arrow keys are handled on `keydown`,
|
|
105
|
-
// from the selection, and CKEditor's widgets (loaded by other features, e.g. the clipboard) handle it for
|
|
106
|
-
// object, in a context that is reached before this plugin could.
|
|
104
|
+
// The arrow keys are handled on `keydown`, before CKEditor's widgets, and not as the `arrowKey` event: that one
|
|
105
|
+
// bubbles from the selection, and CKEditor's widgets (loaded by other features, e.g. the clipboard) handle it for
|
|
106
|
+
// every object, in a context that is reached before this plugin could.
|
|
107
107
|
this.listenTo<ViewDocumentKeyDownEvent>(
|
|
108
108
|
viewDocument,
|
|
109
109
|
'keydown',
|
|
@@ -123,10 +123,10 @@ export default class ElementSelectable extends Plugin {
|
|
|
123
123
|
evt.stop();
|
|
124
124
|
}
|
|
125
125
|
},
|
|
126
|
-
{ priority:
|
|
126
|
+
{ priority: keyboardPriorities.selectable }
|
|
127
127
|
);
|
|
128
128
|
|
|
129
|
-
// Esc
|
|
129
|
+
// Esc goes after what else uses it, e.g. closing a balloon. Editor keystrokes (`cancel()`)
|
|
130
130
|
// do not stop this event, they prevent the default action of the DOM event: then Esc is handled already.
|
|
131
131
|
this.listenTo<ViewDocumentKeyDownEvent>(
|
|
132
132
|
viewDocument,
|
|
@@ -141,16 +141,25 @@ export default class ElementSelectable extends Plugin {
|
|
|
141
141
|
evt.stop();
|
|
142
142
|
}
|
|
143
143
|
},
|
|
144
|
-
{ priority:
|
|
144
|
+
{ priority: keyboardPriorities.selectableEsc }
|
|
145
145
|
);
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
public afterInit(): void {
|
|
149
|
-
|
|
149
|
+
// Before the data is loaded, once all the elements are registered: also the ones that other plugins register in
|
|
150
|
+
// `afterInit()`, e.g. the element schema, whichever plugin comes first.
|
|
151
|
+
this.listenTo(
|
|
152
|
+
this.editor.data,
|
|
153
|
+
'init',
|
|
154
|
+
() => {
|
|
155
|
+
this._makeSelectable(this._matchers);
|
|
156
|
+
},
|
|
157
|
+
{ priority: 'high' }
|
|
158
|
+
);
|
|
150
159
|
}
|
|
151
160
|
|
|
152
161
|
/**
|
|
153
|
-
* Makes more elements selectable, as the `
|
|
162
|
+
* Makes more elements selectable, as the `elementSelectable` option does: a name of a model element, or a filter.
|
|
154
163
|
* Used by features that add elements, e.g. the element schema.
|
|
155
164
|
*/
|
|
156
165
|
public add(...matchers: ElementSelectableMatcher[]): void {
|
package/src/navigation.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Model, ModelDocumentSelection, ModelElement, ModelRange, ModelSelection } from 'ckeditor5';
|
|
2
|
+
import { getAncestorElements } from 'ckeditor5-elements-core';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Whether an element can be selected as a whole.
|
|
@@ -68,13 +69,9 @@ export function findSelectableAround(
|
|
|
68
69
|
): ModelElement | null {
|
|
69
70
|
const selected = selection.getSelectedElement();
|
|
70
71
|
|
|
71
|
-
for (
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
node = node.parent
|
|
75
|
-
) {
|
|
76
|
-
if (isSelectable(node)) {
|
|
77
|
-
return node;
|
|
72
|
+
for (const element of getAncestorElements(selected ? selected.parent : selection.getFirstPosition()?.parent)) {
|
|
73
|
+
if (isSelectable(element)) {
|
|
74
|
+
return element;
|
|
78
75
|
}
|
|
79
76
|
}
|
|
80
77
|
|