ckeditor5-elements-menu 0.0.0-stage → 49.0.0-alpha.4
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 +21 -0
- package/README.md +50 -2
- package/dist/augmentation.d.ts +30 -0
- package/dist/augmentation.d.ts.map +1 -0
- package/dist/augmentation.js +2 -0
- package/dist/augmentation.js.map +1 -0
- package/dist/breadcrumbs/breadcrumbItemView.d.ts +47 -0
- package/dist/breadcrumbs/breadcrumbItemView.d.ts.map +1 -0
- package/dist/breadcrumbs/breadcrumbItemView.js +30 -0
- package/dist/breadcrumbs/breadcrumbItemView.js.map +1 -0
- package/dist/breadcrumbs/breadcrumbLabelView.d.ts +29 -0
- package/dist/breadcrumbs/breadcrumbLabelView.d.ts.map +1 -0
- package/dist/breadcrumbs/breadcrumbLabelView.js +39 -0
- package/dist/breadcrumbs/breadcrumbLabelView.js.map +1 -0
- package/dist/breadcrumbs/breadcrumbs.d.ts +72 -0
- package/dist/breadcrumbs/breadcrumbs.d.ts.map +1 -0
- package/dist/breadcrumbs/breadcrumbs.js +224 -0
- package/dist/breadcrumbs/breadcrumbs.js.map +1 -0
- package/dist/breadcrumbs/breadcrumbsView.d.ts +68 -0
- package/dist/breadcrumbs/breadcrumbsView.d.ts.map +1 -0
- package/dist/breadcrumbs/breadcrumbsView.js +134 -0
- package/dist/breadcrumbs/breadcrumbsView.js.map +1 -0
- package/dist/contextMenu/contextMenuObserver.d.ts +19 -0
- package/dist/contextMenu/contextMenuObserver.d.ts.map +1 -0
- package/dist/contextMenu/contextMenuObserver.js +18 -0
- package/dist/contextMenu/contextMenuObserver.js.map +1 -0
- package/dist/contextMenu/elementContextMenu.d.ts +34 -0
- package/dist/contextMenu/elementContextMenu.d.ts.map +1 -0
- package/dist/contextMenu/elementContextMenu.js +98 -0
- package/dist/contextMenu/elementContextMenu.js.map +1 -0
- package/dist/elementMenu.d.ts +93 -0
- package/dist/elementMenu.d.ts.map +1 -0
- package/dist/elementMenu.js +162 -0
- package/dist/elementMenu.js.map +1 -0
- package/dist/elementMenuView.d.ts +35 -0
- package/dist/elementMenuView.d.ts.map +1 -0
- package/dist/elementMenuView.js +117 -0
- package/dist/elementMenuView.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/quickInsert/icons.d.ts +16 -0
- package/dist/quickInsert/icons.d.ts.map +1 -0
- package/dist/quickInsert/icons.js +21 -0
- package/dist/quickInsert/icons.js.map +1 -0
- package/dist/quickInsert/quickInsert.d.ts +57 -0
- package/dist/quickInsert/quickInsert.d.ts.map +1 -0
- package/dist/quickInsert/quickInsert.js +106 -0
- package/dist/quickInsert/quickInsert.js.map +1 -0
- package/dist/quickInsert/quickInsertCommand.d.ts +38 -0
- package/dist/quickInsert/quickInsertCommand.d.ts.map +1 -0
- package/dist/quickInsert/quickInsertCommand.js +70 -0
- package/dist/quickInsert/quickInsertCommand.js.map +1 -0
- package/dist/quickInsert/quickInsertListView.d.ts +29 -0
- package/dist/quickInsert/quickInsertListView.d.ts.map +1 -0
- package/dist/quickInsert/quickInsertListView.js +44 -0
- package/dist/quickInsert/quickInsertListView.js.map +1 -0
- package/dist/quickInsert/quickInsertPositionCommand.d.ts +28 -0
- package/dist/quickInsert/quickInsertPositionCommand.d.ts.map +1 -0
- package/dist/quickInsert/quickInsertPositionCommand.js +54 -0
- package/dist/quickInsert/quickInsertPositionCommand.js.map +1 -0
- package/dist/quickInsert/quickInsertView.d.ts +20 -0
- package/dist/quickInsert/quickInsertView.d.ts.map +1 -0
- package/dist/quickInsert/quickInsertView.js +52 -0
- package/dist/quickInsert/quickInsertView.js.map +1 -0
- package/package.json +49 -3
- package/src/augmentation.ts +44 -0
- package/src/breadcrumbs/breadcrumbItemView.ts +74 -0
- package/src/breadcrumbs/breadcrumbLabelView.ts +55 -0
- package/src/breadcrumbs/breadcrumbs.ts +322 -0
- package/src/breadcrumbs/breadcrumbsView.ts +176 -0
- package/src/contextMenu/contextMenuObserver.ts +27 -0
- package/src/contextMenu/elementContextMenu.ts +116 -0
- package/src/elementMenu.ts +274 -0
- package/src/elementMenuView.ts +163 -0
- package/src/index.ts +54 -0
- package/src/quickInsert/icons.ts +26 -0
- package/src/quickInsert/quickInsert.ts +149 -0
- package/src/quickInsert/quickInsertCommand.ts +85 -0
- package/src/quickInsert/quickInsertListView.ts +71 -0
- package/src/quickInsert/quickInsertPositionCommand.ts +72 -0
- package/src/quickInsert/quickInsertView.ts +64 -0
- package/theme/menu.css +131 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elementMenu.js","sourceRoot":"","sources":["../src/elementMenu.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,iBAAiB,EACjB,wBAAwB,EACxB,gBAAgB,EAChB,YAAY,EACZ,MAAM,EACN,mBAAmB,EAKnB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,wBAAwB,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACjF,OAAO,eAAe,MAAM,sBAAsB,CAAC;AA2DnD;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,MAAM;IAC9C;;OAEG;IACI,IAAI,GAAyB,IAAI,CAAC;IAEjC,WAAW,GAA4B,IAAI,CAAC;IAC5C,WAAW,GAA2B,IAAI,CAAC;IAC3C,OAAO,GAAwB,IAAI,CAAC;IAErC,MAAM,KAAK,QAAQ;QACzB,qEAAqE;QACrE,OAAO,CAAC,iBAAiB,EAAE,YAAY,CAAU,CAAC;IACnD,CAAC;IAEM,MAAM,KAAK,UAAU;QAC3B,OAAO,aAAsB,CAAC;IAC/B,CAAC;IAEM,IAAI;QACV,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,aAAa,EAAE,GAAG,EAAE;YAC7D,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE,E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AM,OAAO,GAAG,IAAI,KAAK,GAAG,IAAI,IAAI,YAAY,wBAAwB,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QAE9G,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,KAAK,GAAG,IAAI,CAAC,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;YAChF,SAAS;QACV,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACtB,CAAC;IAED,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;QAC3B,MAAM,CAAC,GAAG,EAAE,CAAC;IACd,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC;AAED,SAAS,YAAY,CAAC,OAAuB;IAC5C,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAExC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACpD,CAAC;AAED;;GAEG;AACH,SAAS,aAAa,CAAC,IAAmB;IACzC,OAAO,IAAI,YAAY,wBAAwB;QAC9C,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;QAC5E,CAAC,CAAC,EAAE,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { DropdownMenuRootListView, type BodyCollection, type Locale } from 'ckeditor5';
|
|
2
|
+
import { type ElementOrPosition } from 'ckeditor5-elements-core';
|
|
3
|
+
import { type ElementMenuItem } from './elementMenu.js';
|
|
4
|
+
/**
|
|
5
|
+
* The menu of an element: CKEditor's dropdown menu (`DropdownMenuRootListView`), built from commands, submenus and
|
|
6
|
+
* separators.
|
|
7
|
+
*
|
|
8
|
+
* CKEditor builds the menu and handles it: the nested menus (opened on click, hover, or the right arrow; placed where
|
|
9
|
+
* they fit), the keyboard, and right-to-left languages. This view only connects the buttons to the commands: they
|
|
10
|
+
* reflect the command title, icon and {@link ElementOrPositionCommand#getState state} for the target, and execute the
|
|
11
|
+
* command for it. It also adds the separators, which CKEditor's menu definitions do not have.
|
|
12
|
+
*
|
|
13
|
+
* Submenus are enabled when one of their items is. Right-clicking the menu does not open the native context menu.
|
|
14
|
+
*/
|
|
15
|
+
export default class ElementMenuView extends DropdownMenuRootListView {
|
|
16
|
+
/**
|
|
17
|
+
* The element or position the commands are executed for.
|
|
18
|
+
*/
|
|
19
|
+
readonly target: ElementOrPosition;
|
|
20
|
+
private readonly _commands;
|
|
21
|
+
private readonly _submenus;
|
|
22
|
+
/**
|
|
23
|
+
* The positions of the separators in each list, by the id of the submenu (`''` for the menu itself).
|
|
24
|
+
*/
|
|
25
|
+
private readonly _separators;
|
|
26
|
+
constructor(locale: Locale, bodyCollection: BodyCollection, items: readonly (ElementMenuItem | null | undefined)[], target: ElementOrPosition);
|
|
27
|
+
/**
|
|
28
|
+
* Renders the menu: CKEditor builds it from the definitions; then the buttons are connected to the commands, and the
|
|
29
|
+
* separators are added.
|
|
30
|
+
*/
|
|
31
|
+
render(): void;
|
|
32
|
+
private _addSeparators;
|
|
33
|
+
private _isEnabled;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=elementMenuView.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elementMenuView.d.ts","sourceRoot":"","sources":["../src/elementMenuView.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,wBAAwB,EAExB,KAAK,cAAc,EAGnB,KAAK,MAAM,EACX,MAAM,WAAW,CAAC;AACnB,OAAO,EAAiD,KAAK,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAChH,OAAO,EAAE,KAAK,eAAe,EAAuB,MAAM,kBAAkB,CAAC;AAE7E;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,wBAAwB;IACpE;;OAEG;IACH,SAAgB,MAAM,EAAE,iBAAiB,CAAC;IAE1C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAwC;IAClE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA8B;IAExD;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAwB;gBAGnD,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,cAAc,EAC9B,KAAK,EAAE,SAAS,CAAC,eAAe,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,EACtD,MAAM,EAAE,iBAAiB;IAkB1B;;;OAGG;IACa,MAAM,IAAI,IAAI;IAqC9B,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,UAAU;CASlB"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { DropdownMenuRootListView, ListSeparatorView } from 'ckeditor5';
|
|
2
|
+
import { ElementOrPositionCommand, bindButtonToCommand } from 'ckeditor5-elements-core';
|
|
3
|
+
import {} from './elementMenu.js';
|
|
4
|
+
/**
|
|
5
|
+
* The menu of an element: CKEditor's dropdown menu (`DropdownMenuRootListView`), built from commands, submenus and
|
|
6
|
+
* separators.
|
|
7
|
+
*
|
|
8
|
+
* CKEditor builds the menu and handles it: the nested menus (opened on click, hover, or the right arrow; placed where
|
|
9
|
+
* they fit), the keyboard, and right-to-left languages. This view only connects the buttons to the commands: they
|
|
10
|
+
* reflect the command title, icon and {@link ElementOrPositionCommand#getState state} for the target, and execute the
|
|
11
|
+
* command for it. It also adds the separators, which CKEditor's menu definitions do not have.
|
|
12
|
+
*
|
|
13
|
+
* Submenus are enabled when one of their items is. Right-clicking the menu does not open the native context menu.
|
|
14
|
+
*/
|
|
15
|
+
export default class ElementMenuView extends DropdownMenuRootListView {
|
|
16
|
+
/**
|
|
17
|
+
* The element or position the commands are executed for.
|
|
18
|
+
*/
|
|
19
|
+
target;
|
|
20
|
+
_commands;
|
|
21
|
+
_submenus;
|
|
22
|
+
/**
|
|
23
|
+
* The positions of the separators in each list, by the id of the submenu (`''` for the menu itself).
|
|
24
|
+
*/
|
|
25
|
+
_separators;
|
|
26
|
+
constructor(locale, bodyCollection, items, target) {
|
|
27
|
+
const maps = { commands: new Map(), submenus: new Map(), separators: new Map() };
|
|
28
|
+
super(locale, bodyCollection, createDefinitions(items, '', maps));
|
|
29
|
+
this.target = target;
|
|
30
|
+
this._commands = maps.commands;
|
|
31
|
+
this._submenus = maps.submenus;
|
|
32
|
+
this._separators = maps.separators;
|
|
33
|
+
this.menuPanelClass = 'ck-elements-menu__panel';
|
|
34
|
+
this.extendTemplate({
|
|
35
|
+
attributes: { class: 'ck-elements-menu' },
|
|
36
|
+
on: { contextmenu: this.bindTemplate.to(preventDefault) }
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Renders the menu: CKEditor builds it from the definitions; then the buttons are connected to the commands, and the
|
|
41
|
+
* separators are added.
|
|
42
|
+
*/
|
|
43
|
+
render() {
|
|
44
|
+
super.render();
|
|
45
|
+
for (const button of this.buttons) {
|
|
46
|
+
const command = this._commands.get(button.id);
|
|
47
|
+
if (command) {
|
|
48
|
+
bindButtonToCommand(button, command, { withText: true, target: this.target });
|
|
49
|
+
// A toggleable button with a checkable role tells assistive technology whether it is "on" with `aria-checked`.
|
|
50
|
+
button.role = command.isToggleable ? 'menuitemcheckbox' : 'menuitem';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
for (const menu of this.menus) {
|
|
54
|
+
const submenu = this._submenus.get(menu.id);
|
|
55
|
+
if (submenu) {
|
|
56
|
+
menu.buttonView.icon = submenu.icon;
|
|
57
|
+
menu.isEnabled = this._isEnabled(submenu);
|
|
58
|
+
}
|
|
59
|
+
// The panels of nested menus are not inside the menu.
|
|
60
|
+
if (menu.panelView.element) {
|
|
61
|
+
this.listenTo(menu.panelView.element, 'contextmenu', (evt, domEvent) => {
|
|
62
|
+
preventDefault(domEvent);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
this._addSeparators('', this);
|
|
67
|
+
for (const menu of this.menus) {
|
|
68
|
+
this._addSeparators(menu.id, menu.listView);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
_addSeparators(id, list) {
|
|
72
|
+
for (const position of this._separators.get(id) ?? []) {
|
|
73
|
+
const separator = new ListSeparatorView(this.locale);
|
|
74
|
+
separator.extendTemplate({ attributes: { role: 'separator' } });
|
|
75
|
+
list.items.add(separator, position);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
_isEnabled(item) {
|
|
79
|
+
if (item === '|') {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return item instanceof ElementOrPositionCommand
|
|
83
|
+
? item.getState(this.target).isEnabled
|
|
84
|
+
: item.items.some(child => !!child && this._isEnabled(child));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Creates CKEditor's menu definitions for the items. The ids are paths of positions (e.g. `'2.0'`). Collects the
|
|
89
|
+
* commands and submenus by id, and the positions of the separators by the id of their submenu.
|
|
90
|
+
*/
|
|
91
|
+
function createDefinitions(items, parentId, maps) {
|
|
92
|
+
const definitions = [];
|
|
93
|
+
let position = 0;
|
|
94
|
+
for (const item of items) {
|
|
95
|
+
const id = parentId ? `${parentId}.${String(position)}` : String(position);
|
|
96
|
+
if (!item) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (item === '|') {
|
|
100
|
+
maps.separators.set(parentId, [...(maps.separators.get(parentId) ?? []), position]);
|
|
101
|
+
}
|
|
102
|
+
else if (item instanceof ElementOrPositionCommand) {
|
|
103
|
+
maps.commands.set(id, item);
|
|
104
|
+
definitions.push({ id, label: item.title });
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
maps.submenus.set(id, item);
|
|
108
|
+
definitions.push({ id, menu: item.title, children: createDefinitions(item.items, id, maps) });
|
|
109
|
+
}
|
|
110
|
+
position++;
|
|
111
|
+
}
|
|
112
|
+
return definitions;
|
|
113
|
+
}
|
|
114
|
+
function preventDefault(domEvent) {
|
|
115
|
+
domEvent.preventDefault();
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=elementMenuView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elementMenuView.js","sourceRoot":"","sources":["../src/elementMenuView.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,wBAAwB,EACxB,iBAAiB,EAKjB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAA0B,MAAM,yBAAyB,CAAC;AAChH,OAAO,EAA6C,MAAM,kBAAkB,CAAC;AAE7E;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,wBAAwB;IACpE;;OAEG;IACa,MAAM,CAAoB;IAEzB,SAAS,CAAwC;IACjD,SAAS,CAA8B;IAExD;;OAEG;IACc,WAAW,CAAwB;IAEpD,YACC,MAAc,EACd,cAA8B,EAC9B,KAAsD,EACtD,MAAyB;QAEzB,MAAM,IAAI,GAAmB,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;QAEjG,KAAK,CAAC,MAAM,EAAE,cAAc,EAAE,iBAAiB,CAAC,KAAK,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;QAElE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC/B,IAAI,CAAC,SAAS,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AAc,CAAC,QAAe;IACtC,QAAQ,CAAC,cAAc,EAAE,CAAC;AAC3B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Element menus: `ElementMenu` shows the menu of an element, built from commands, submenus and separators, and the
|
|
3
|
+
* features that open it: the element context menu (a right-click, Shift+F10 or the menu key), the breadcrumbs (the
|
|
4
|
+
* element path at the selection, clickable with a menu) and quick insert (search and insert the elements allowed at a
|
|
5
|
+
* position).
|
|
6
|
+
*
|
|
7
|
+
* @module ckeditor5-elements-menu
|
|
8
|
+
*/
|
|
9
|
+
export { default as ElementMenu, type ElementMenuConfig, type ElementMenuItem, type ElementMenuShowOptions, type ElementSubmenu } from './elementMenu.js';
|
|
10
|
+
export { default as ElementContextMenu } from './contextMenu/elementContextMenu.js';
|
|
11
|
+
export { default as Breadcrumbs, type BreadcrumbsConfig } from './breadcrumbs/breadcrumbs.js';
|
|
12
|
+
export { default as QuickInsert, type QuickInsertConfig } from './quickInsert/quickInsert.js';
|
|
13
|
+
export { default as QuickInsertCommand } from './quickInsert/quickInsertCommand.js';
|
|
14
|
+
export { default as QuickInsertPositionCommand, type QuickInsertPlacement } from './quickInsert/quickInsertPositionCommand.js';
|
|
15
|
+
export { default as ElementMenuView } from './elementMenuView.js';
|
|
16
|
+
export { default as BreadcrumbsView, type BreadcrumbsViewExecuteEvent, type BreadcrumbsViewOptions } from './breadcrumbs/breadcrumbsView.js';
|
|
17
|
+
export { default as BreadcrumbItemView, type BreadcrumbItem, type BreadcrumbItemViewOptions } from './breadcrumbs/breadcrumbItemView.js';
|
|
18
|
+
export { default as BreadcrumbLabelView } from './breadcrumbs/breadcrumbLabelView.js';
|
|
19
|
+
export { default as QuickInsertView } from './quickInsert/quickInsertView.js';
|
|
20
|
+
export { default as QuickInsertListView, type QuickInsertItem } from './quickInsert/quickInsertListView.js';
|
|
21
|
+
export { default as ContextMenuObserver, type ViewDocumentContextMenuEvent } from './contextMenu/contextMenuObserver.js';
|
|
22
|
+
export { insertAfterIcon, insertBeforeIcon, insertIcon } from './quickInsert/icons.js';
|
|
23
|
+
import './augmentation.js';
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EACN,OAAO,IAAI,WAAW,EACtB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,cAAc,EACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACpF,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAC9F,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAG9F,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACpF,OAAO,EACN,OAAO,IAAI,0BAA0B,EACrC,KAAK,oBAAoB,EACzB,MAAM,6CAA6C,CAAC;AAGrD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EACN,OAAO,IAAI,eAAe,EAC1B,KAAK,2BAA2B,EAChC,KAAK,sBAAsB,EAC3B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACN,OAAO,IAAI,kBAAkB,EAC7B,KAAK,cAAc,EACnB,KAAK,yBAAyB,EAC9B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AACtF,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,KAAK,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAG5G,OAAO,EACN,OAAO,IAAI,mBAAmB,EAC9B,KAAK,4BAA4B,EACjC,MAAM,sCAAsC,CAAC;AAG9C,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEvF,OAAO,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Element menus: `ElementMenu` shows the menu of an element, built from commands, submenus and separators, and the
|
|
3
|
+
* features that open it: the element context menu (a right-click, Shift+F10 or the menu key), the breadcrumbs (the
|
|
4
|
+
* element path at the selection, clickable with a menu) and quick insert (search and insert the elements allowed at a
|
|
5
|
+
* position).
|
|
6
|
+
*
|
|
7
|
+
* @module ckeditor5-elements-menu
|
|
8
|
+
*/
|
|
9
|
+
// Plugins.
|
|
10
|
+
export { default as ElementMenu } from './elementMenu.js';
|
|
11
|
+
export { default as ElementContextMenu } from './contextMenu/elementContextMenu.js';
|
|
12
|
+
export { default as Breadcrumbs } from './breadcrumbs/breadcrumbs.js';
|
|
13
|
+
export { default as QuickInsert } from './quickInsert/quickInsert.js';
|
|
14
|
+
// Commands.
|
|
15
|
+
export { default as QuickInsertCommand } from './quickInsert/quickInsertCommand.js';
|
|
16
|
+
export { default as QuickInsertPositionCommand } from './quickInsert/quickInsertPositionCommand.js';
|
|
17
|
+
// Views.
|
|
18
|
+
export { default as ElementMenuView } from './elementMenuView.js';
|
|
19
|
+
export { default as BreadcrumbsView } from './breadcrumbs/breadcrumbsView.js';
|
|
20
|
+
export { default as BreadcrumbItemView } from './breadcrumbs/breadcrumbItemView.js';
|
|
21
|
+
export { default as BreadcrumbLabelView } from './breadcrumbs/breadcrumbLabelView.js';
|
|
22
|
+
export { default as QuickInsertView } from './quickInsert/quickInsertView.js';
|
|
23
|
+
export { default as QuickInsertListView } from './quickInsert/quickInsertListView.js';
|
|
24
|
+
// Observers.
|
|
25
|
+
export { default as ContextMenuObserver } from './contextMenu/contextMenuObserver.js';
|
|
26
|
+
// Icons.
|
|
27
|
+
export { insertAfterIcon, insertBeforeIcon, insertIcon } from './quickInsert/icons.js';
|
|
28
|
+
import './augmentation.js';
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,WAAW;AACX,OAAO,EACN,OAAO,IAAI,WAAW,EAKtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACpF,OAAO,EAAE,OAAO,IAAI,WAAW,EAA0B,MAAM,8BAA8B,CAAC;AAC9F,OAAO,EAAE,OAAO,IAAI,WAAW,EAA0B,MAAM,8BAA8B,CAAC;AAE9F,YAAY;AACZ,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACpF,OAAO,EACN,OAAO,IAAI,0BAA0B,EAErC,MAAM,6CAA6C,CAAC;AAErD,SAAS;AACT,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EACN,OAAO,IAAI,eAAe,EAG1B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACN,OAAO,IAAI,kBAAkB,EAG7B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AACtF,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAwB,MAAM,sCAAsC,CAAC;AAE5G,aAAa;AACb,OAAO,EACN,OAAO,IAAI,mBAAmB,EAE9B,MAAM,sCAAsC,CAAC;AAE9C,SAAS;AACT,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEvF,OAAO,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The icons of the quick insert commands, in the style of the CKEditor 5 icons (20×20).
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Insert element: CKEditor's own plus icon.
|
|
6
|
+
*/
|
|
7
|
+
export declare const insertIcon: string;
|
|
8
|
+
/**
|
|
9
|
+
* Insert before: a plus above a block.
|
|
10
|
+
*/
|
|
11
|
+
export declare const insertBeforeIcon: string;
|
|
12
|
+
/**
|
|
13
|
+
* Insert after: a block above a plus.
|
|
14
|
+
*/
|
|
15
|
+
export declare const insertAfterIcon: string;
|
|
16
|
+
//# sourceMappingURL=icons.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icons.d.ts","sourceRoot":"","sources":["../../src/quickInsert/icons.ts"],"names":[],"mappings":"AAEA;;GAEG;AAEH;;GAEG;AACH,eAAO,MAAM,UAAU,QAAW,CAAC;AAEnC;;GAEG;AACH,eAAO,MAAM,gBAAgB,QAGsB,CAAC;AAEpD;;GAEG;AACH,eAAO,MAAM,eAAe,QAGmB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { IconPlus } from 'ckeditor5';
|
|
2
|
+
/**
|
|
3
|
+
* The icons of the quick insert commands, in the style of the CKEditor 5 icons (20×20).
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Insert element: CKEditor's own plus icon.
|
|
7
|
+
*/
|
|
8
|
+
export const insertIcon = IconPlus;
|
|
9
|
+
/**
|
|
10
|
+
* Insert before: a plus above a block.
|
|
11
|
+
*/
|
|
12
|
+
export const insertBeforeIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path fill-rule="evenodd" d="' +
|
|
13
|
+
'M9.25 1.5h1.5v2.75h2.75v1.5h-2.75V8.5h-1.5V5.75H6.5v-1.5h2.75zM3.5 11h13a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1h-13a1 1 0 0 ' +
|
|
14
|
+
'1-1-1v-5a1 1 0 0 1 1-1zm.5 1.5v4h12v-4z"/></svg>';
|
|
15
|
+
/**
|
|
16
|
+
* Insert after: a block above a plus.
|
|
17
|
+
*/
|
|
18
|
+
export const insertAfterIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path fill-rule="evenodd" d="' +
|
|
19
|
+
'M3.5 2h13a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1h-13a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1zm.5 1.5v4h12v-4zM9.25 11h1.5v2.75h2.75v1.5' +
|
|
20
|
+
'h-2.75V18h-1.5v-2.75H6.5v-1.5h2.75z"/></svg>';
|
|
21
|
+
//# sourceMappingURL=icons.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icons.js","sourceRoot":"","sources":["../../src/quickInsert/icons.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC;;GAEG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC;AAEnC;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAC5B,2FAA2F;IAC3F,qHAAqH;IACrH,kDAAkD,CAAC;AAEpD;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAC3B,2FAA2F;IAC3F,sHAAsH;IACtH,8CAA8C,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Plugin, type Editor, type RectSource } from 'ckeditor5';
|
|
2
|
+
import type { ElementOrPosition } from 'ckeditor5-elements-core';
|
|
3
|
+
import ElementMenu from '../elementMenu.js';
|
|
4
|
+
import { type QuickInsertItem } from './quickInsertListView.js';
|
|
5
|
+
/**
|
|
6
|
+
* The configuration of the {@link QuickInsert} plugin.
|
|
7
|
+
*/
|
|
8
|
+
export interface QuickInsertConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Labels of the elements, by model name. Elements without a label are listed by their model name.
|
|
11
|
+
*/
|
|
12
|
+
labels?: Record<string, string>;
|
|
13
|
+
/**
|
|
14
|
+
* Model names of the elements that are never listed.
|
|
15
|
+
*/
|
|
16
|
+
exclude?: string[];
|
|
17
|
+
/**
|
|
18
|
+
* The keystroke that opens the menu at the selection, e.g. `'Ctrl+Space'`. Defaults to `'Alt+Enter'`
|
|
19
|
+
* (Option+Enter on macOS). `false` registers no keystroke.
|
|
20
|
+
*/
|
|
21
|
+
keystroke?: string | false;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Opens a menu with a search field and the elements allowed at the selection, on Alt+Enter (Option+Enter on macOS; see
|
|
25
|
+
* {@link QuickInsertConfig.keystroke}). Choosing an element inserts it with the `quickInsert` command.
|
|
26
|
+
*
|
|
27
|
+
* The menu is shown by the `ElementMenu` plugin. The `quickInsertBefore` and `quickInsertAfter` commands (see
|
|
28
|
+
* {@link QuickInsertPositionCommand}) open it for the position before or after an element; list them in the
|
|
29
|
+
* `elementContextMenu` config, e.g. as an "Insert" submenu.
|
|
30
|
+
*
|
|
31
|
+
* The menu closes when the document changes while it is open, so it never inserts at an outdated position.
|
|
32
|
+
*/
|
|
33
|
+
export default class QuickInsert extends Plugin {
|
|
34
|
+
static get requires(): readonly [typeof ElementMenu];
|
|
35
|
+
static get pluginName(): 'QuickInsert';
|
|
36
|
+
constructor(editor: Editor);
|
|
37
|
+
init(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Returns the elements that can be inserted at the target (a position, the position before an element, or the
|
|
40
|
+
* selection), with their labels.
|
|
41
|
+
*/
|
|
42
|
+
getItems(elementOrPosition?: ElementOrPosition): QuickInsertItem[];
|
|
43
|
+
/**
|
|
44
|
+
* Opens the menu for inserting at the target (a position, the position before an element, or the selection), next
|
|
45
|
+
* to the given DOM target. By default, the menu is next to the element, or the selection.
|
|
46
|
+
*
|
|
47
|
+
* Returns `false` when nothing can be inserted at the target because it cannot be edited, or there is nothing to
|
|
48
|
+
* show the menu next to.
|
|
49
|
+
*/
|
|
50
|
+
open(elementOrPosition?: ElementOrPosition, domTarget?: RectSource): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Returns the DOM element of the element, or the DOM range of the selection.
|
|
53
|
+
*/
|
|
54
|
+
private _getDomTarget;
|
|
55
|
+
private _getDomElement;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=quickInsert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quickInsert.d.ts","sourceRoot":"","sources":["../../src/quickInsert/quickInsert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,MAAM,EAAoD,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AACnH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,WAAW,MAAM,mBAAmB,CAAC;AAG5C,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAGhE;;GAEG;AACH,MAAM,WAAW,iBAAiB;IACjC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEhC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAEnB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;CAC3B;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,MAAM;IAC9C,WAAkB,QAAQ,IAAI,SAAS,CAAC,OAAO,WAAW,CAAC,CAE1D;IAED,WAAkB,UAAU,IAAI,aAAa,CAE5C;gBAEW,MAAM,EAAE,MAAM;IAMnB,IAAI,IAAI,IAAI;IAqBnB;;;OAGG;IACI,QAAQ,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,eAAe,EAAE;IAWzE;;;;;;OAMG;IACI,IAAI,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,EAAE,SAAS,CAAC,EAAE,UAAU,GAAG,OAAO;IA2BnF;;OAEG;IACH,OAAO,CAAC,aAAa;IAcrB,OAAO,CAAC,cAAc;CAOtB"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Plugin } from 'ckeditor5';
|
|
2
|
+
import ElementMenu from '../elementMenu.js';
|
|
3
|
+
import QuickInsertCommand from './quickInsertCommand.js';
|
|
4
|
+
import QuickInsertPositionCommand from './quickInsertPositionCommand.js';
|
|
5
|
+
import {} from './quickInsertListView.js';
|
|
6
|
+
import QuickInsertView from './quickInsertView.js';
|
|
7
|
+
/**
|
|
8
|
+
* Opens a menu with a search field and the elements allowed at the selection, on Alt+Enter (Option+Enter on macOS; see
|
|
9
|
+
* {@link QuickInsertConfig.keystroke}). Choosing an element inserts it with the `quickInsert` command.
|
|
10
|
+
*
|
|
11
|
+
* The menu is shown by the `ElementMenu` plugin. The `quickInsertBefore` and `quickInsertAfter` commands (see
|
|
12
|
+
* {@link QuickInsertPositionCommand}) open it for the position before or after an element; list them in the
|
|
13
|
+
* `elementContextMenu` config, e.g. as an "Insert" submenu.
|
|
14
|
+
*
|
|
15
|
+
* The menu closes when the document changes while it is open, so it never inserts at an outdated position.
|
|
16
|
+
*/
|
|
17
|
+
export default class QuickInsert extends Plugin {
|
|
18
|
+
static get requires() {
|
|
19
|
+
return [ElementMenu];
|
|
20
|
+
}
|
|
21
|
+
static get pluginName() {
|
|
22
|
+
return 'QuickInsert';
|
|
23
|
+
}
|
|
24
|
+
constructor(editor) {
|
|
25
|
+
super(editor);
|
|
26
|
+
editor.config.define('quickInsert', { labels: {}, exclude: [], keystroke: 'Alt+Enter' });
|
|
27
|
+
}
|
|
28
|
+
init() {
|
|
29
|
+
const editor = this.editor;
|
|
30
|
+
const keystroke = editor.config.get('quickInsert')?.keystroke;
|
|
31
|
+
editor.commands.add('quickInsert', new QuickInsertCommand(editor));
|
|
32
|
+
editor.commands.add('quickInsertBefore', new QuickInsertPositionCommand(editor, 'before'));
|
|
33
|
+
editor.commands.add('quickInsertAfter', new QuickInsertPositionCommand(editor, 'after'));
|
|
34
|
+
if (keystroke) {
|
|
35
|
+
editor.keystrokes.set(keystroke, (data, cancel) => {
|
|
36
|
+
if (this.open()) {
|
|
37
|
+
cancel();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
editor.accessibility.addKeystrokeInfos({
|
|
41
|
+
keystrokes: [{ label: editor.t('Insert an element at the cursor'), keystroke }]
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns the elements that can be inserted at the target (a position, the position before an element, or the
|
|
47
|
+
* selection), with their labels.
|
|
48
|
+
*/
|
|
49
|
+
getItems(elementOrPosition) {
|
|
50
|
+
const config = this.editor.config.get('quickInsert');
|
|
51
|
+
const labels = config?.labels ?? {};
|
|
52
|
+
const command = this.editor.commands.get('quickInsert');
|
|
53
|
+
return (command?.getAllowedElements(elementOrPosition, config?.exclude) ?? []).map(name => ({
|
|
54
|
+
name,
|
|
55
|
+
label: labels[name] ?? name
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Opens the menu for inserting at the target (a position, the position before an element, or the selection), next
|
|
60
|
+
* to the given DOM target. By default, the menu is next to the element, or the selection.
|
|
61
|
+
*
|
|
62
|
+
* Returns `false` when nothing can be inserted at the target because it cannot be edited, or there is nothing to
|
|
63
|
+
* show the menu next to.
|
|
64
|
+
*/
|
|
65
|
+
open(elementOrPosition, domTarget) {
|
|
66
|
+
const editor = this.editor;
|
|
67
|
+
const command = editor.commands.get('quickInsert');
|
|
68
|
+
const position = command?.getInsertPosition(elementOrPosition);
|
|
69
|
+
const menuTarget = domTarget ?? this._getDomTarget(elementOrPosition);
|
|
70
|
+
if (!command || !position || !menuTarget || !command.getState(position).isEnabled) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
const view = new QuickInsertView(editor.locale, this.getItems(position));
|
|
74
|
+
view.on('execute', (evt, { value }) => {
|
|
75
|
+
// Focus first: focusing reads the DOM selection, which would override the selection set by the command.
|
|
76
|
+
editor.editing.view.focus();
|
|
77
|
+
command.executeFor(position, value);
|
|
78
|
+
});
|
|
79
|
+
// The search field is labelled "Insert element".
|
|
80
|
+
editor.plugins.get(ElementMenu).show(view, menuTarget, {
|
|
81
|
+
// The position would be outdated after any change, e.g. by another user.
|
|
82
|
+
isObsolete: () => true
|
|
83
|
+
});
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Returns the DOM element of the element, or the DOM range of the selection.
|
|
88
|
+
*/
|
|
89
|
+
_getDomTarget(elementOrPosition) {
|
|
90
|
+
const editing = this.editor.editing;
|
|
91
|
+
if (elementOrPosition && !elementOrPosition.is('position')) {
|
|
92
|
+
return this._getDomElement(elementOrPosition);
|
|
93
|
+
}
|
|
94
|
+
const viewRange = elementOrPosition
|
|
95
|
+
? editing.view.createRange(editing.mapper.toViewPosition(elementOrPosition))
|
|
96
|
+
: editing.view.document.selection.getFirstRange();
|
|
97
|
+
return viewRange && editing.view.domConverter.viewRangeToDom(viewRange);
|
|
98
|
+
}
|
|
99
|
+
_getDomElement(element) {
|
|
100
|
+
const editing = this.editor.editing;
|
|
101
|
+
const viewElement = editing.mapper.toViewElement(element);
|
|
102
|
+
const domElement = viewElement && editing.view.domConverter.mapViewToDom(viewElement);
|
|
103
|
+
return domElement instanceof HTMLElement ? domElement : null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=quickInsert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quickInsert.js","sourceRoot":"","sources":["../../src/quickInsert/quickInsert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAkF,MAAM,WAAW,CAAC;AAEnH,OAAO,WAAW,MAAM,mB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AAC,CAAC;IACzE,CAAC;IAEO,cAAc,CAAC,OAAqB;QAC3C,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;QACpC,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC1D,MAAM,UAAU,GAAG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;QAEtF,OAAO,UAAU,YAAY,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC;IAC9D,CAAC;CACD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type Editor, type ModelPosition } from 'ckeditor5';
|
|
2
|
+
import { ElementOrPositionCommand, type ElementOrPosition } from 'ckeditor5-elements-core';
|
|
3
|
+
/**
|
|
4
|
+
* Inserts an element by its model name at a position, or opens the quick insert menu for that position.
|
|
5
|
+
*
|
|
6
|
+
* The target comes first, as in every {@link ElementOrPositionCommand}: a position, an element (meaning the position
|
|
7
|
+
* before it), or none (the selection).
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* editor.execute('quickInsert', position, 'heading1'); // Inserts a heading at the position.
|
|
11
|
+
* editor.execute('quickInsert'); // Opens the quick insert menu at the selection.
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Only elements that the schema allows at exactly that position are inserted (see {@link getAllowedElements}):
|
|
15
|
+
* nothing is split to make room, so e.g. a heading cannot be inserted inside a paragraph.
|
|
16
|
+
*
|
|
17
|
+
* After inserting, objects are selected; other elements get the selection inside them, in a new paragraph when they
|
|
18
|
+
* can hold blocks.
|
|
19
|
+
*/
|
|
20
|
+
export default class QuickInsertCommand extends ElementOrPositionCommand {
|
|
21
|
+
constructor(editor: Editor);
|
|
22
|
+
/**
|
|
23
|
+
* Returns the names of the model elements allowed at exactly the position (or the selection), in the order they
|
|
24
|
+
* were registered. Generic items (such as `$text` or `$block`) and the excluded names are skipped.
|
|
25
|
+
*/
|
|
26
|
+
getAllowedElements(elementOrPosition?: ElementOrPosition, exclude?: readonly string[]): string[];
|
|
27
|
+
/**
|
|
28
|
+
* Returns the position where elements are inserted for the target: the position, the position before the element,
|
|
29
|
+
* or the selection.
|
|
30
|
+
*/
|
|
31
|
+
getInsertPosition(elementOrPosition?: ElementOrPosition): ModelPosition | null;
|
|
32
|
+
/**
|
|
33
|
+
* Inserts the element named `name` at the target, when the schema allows it there. Without a name, opens the quick
|
|
34
|
+
* insert menu for the target (requires the `QuickInsert` plugin).
|
|
35
|
+
*/
|
|
36
|
+
execute(elementOrPosition?: ElementOrPosition, name?: string): void;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=quickInsertCommand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quickInsertCommand.d.ts","sourceRoot":"","sources":["../../src/quickInsert/quickInsertCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAoB,KAAK,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG7G;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,wBAAwB;gBAC3D,MAAM,EAAE,MAAM;IAO1B;;;OAGG;IACI,kBAAkB,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,EAAE,OAAO,GAAE,SAAS,MAAM,EAAO,GAAG,MAAM,EAAE;IAc3G;;;OAGG;IACI,iBAAiB,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,aAAa,GAAG,IAAI;IAIrF;;;OAGG;IACa,OAAO,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI;CAyBnF"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {} from 'ckeditor5';
|
|
2
|
+
import { ElementOrPositionCommand, selectNewElement } from 'ckeditor5-elements-core';
|
|
3
|
+
import { insertIcon } from './icons.js';
|
|
4
|
+
/**
|
|
5
|
+
* Inserts an element by its model name at a position, or opens the quick insert menu for that position.
|
|
6
|
+
*
|
|
7
|
+
* The target comes first, as in every {@link ElementOrPositionCommand}: a position, an element (meaning the position
|
|
8
|
+
* before it), or none (the selection).
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* editor.execute('quickInsert', position, 'heading1'); // Inserts a heading at the position.
|
|
12
|
+
* editor.execute('quickInsert'); // Opens the quick insert menu at the selection.
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Only elements that the schema allows at exactly that position are inserted (see {@link getAllowedElements}):
|
|
16
|
+
* nothing is split to make room, so e.g. a heading cannot be inserted inside a paragraph.
|
|
17
|
+
*
|
|
18
|
+
* After inserting, objects are selected; other elements get the selection inside them, in a new paragraph when they
|
|
19
|
+
* can hold blocks.
|
|
20
|
+
*/
|
|
21
|
+
export default class QuickInsertCommand extends ElementOrPositionCommand {
|
|
22
|
+
constructor(editor) {
|
|
23
|
+
super(editor);
|
|
24
|
+
this.title = editor.t('Insert element');
|
|
25
|
+
this.icon = insertIcon;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Returns the names of the model elements allowed at exactly the position (or the selection), in the order they
|
|
29
|
+
* were registered. Generic items (such as `$text` or `$block`) and the excluded names are skipped.
|
|
30
|
+
*/
|
|
31
|
+
getAllowedElements(elementOrPosition, exclude = []) {
|
|
32
|
+
const target = this._getPosition(elementOrPosition);
|
|
33
|
+
if (!target) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
const schema = this.editor.model.schema;
|
|
37
|
+
return Object.keys(schema.getDefinitions()).filter(name => !name.startsWith('$') && !exclude.includes(name) && schema.checkChild(target, name));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns the position where elements are inserted for the target: the position, the position before the element,
|
|
41
|
+
* or the selection.
|
|
42
|
+
*/
|
|
43
|
+
getInsertPosition(elementOrPosition) {
|
|
44
|
+
return this._getPosition(elementOrPosition);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Inserts the element named `name` at the target, when the schema allows it there. Without a name, opens the quick
|
|
48
|
+
* insert menu for the target (requires the `QuickInsert` plugin).
|
|
49
|
+
*/
|
|
50
|
+
execute(elementOrPosition, name) {
|
|
51
|
+
if (name === undefined) {
|
|
52
|
+
const plugins = this.editor.plugins;
|
|
53
|
+
if (plugins.has('QuickInsert')) {
|
|
54
|
+
plugins.get('QuickInsert').open(elementOrPosition);
|
|
55
|
+
}
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const model = this.editor.model;
|
|
59
|
+
const target = this._getPosition(elementOrPosition);
|
|
60
|
+
if (!target || !model.canEditAt(target) || !model.schema.checkChild(target, name)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
model.change(writer => {
|
|
64
|
+
const element = writer.createElement(name);
|
|
65
|
+
writer.insert(element, target);
|
|
66
|
+
selectNewElement(writer, element);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=quickInsertCommand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quickInsertCommand.js","sourceRoot":"","sources":["../../src/quickInsert/quickInsertCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAA0B,MAAM,yBAAyB,CAAC;AAC7G,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,wBAAwB;IACvE,YAAY,MAAc;QACzB,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IAAI,CAAC,K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EpD,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC;YACnF,OAAO;QACR,CAAC;QAED,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;YACrB,MAAM,OAAO,GAAG,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YAE3C,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAC/B,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;IACJ,CAAC;CACD"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ListView, type FilteredView, type Locale } from 'ckeditor5';
|
|
2
|
+
/**
|
|
3
|
+
* An element that can be inserted: its model name and the label shown in the list.
|
|
4
|
+
*/
|
|
5
|
+
export interface QuickInsertItem {
|
|
6
|
+
name: string;
|
|
7
|
+
label: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A list of insertable elements that can be filtered by a search query.
|
|
11
|
+
*
|
|
12
|
+
* Fires `execute` with `{ value: name }` when an item is chosen.
|
|
13
|
+
*/
|
|
14
|
+
export default class QuickInsertListView extends ListView implements FilteredView {
|
|
15
|
+
private readonly _entries;
|
|
16
|
+
constructor(locale: Locale, items: readonly QuickInsertItem[]);
|
|
17
|
+
/**
|
|
18
|
+
* Shows only the items whose label or name matches the expression. `null` shows all items.
|
|
19
|
+
*/
|
|
20
|
+
filter(regExp: RegExp | null): {
|
|
21
|
+
resultsCount: number;
|
|
22
|
+
totalItemsCount: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Returns the first item that is not filtered out.
|
|
26
|
+
*/
|
|
27
|
+
getFirstVisibleItem(): QuickInsertItem | null;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=quickInsertListView.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quickInsertListView.d.ts","sourceRoot":"","sources":["../../src/quickInsert/quickInsertListView.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,QAAQ,EACR,KAAK,YAAY,EAEjB,KAAK,MAAM,EACX,MAAM,WAAW,CAAC;AAEnB;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACd;AAED;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,QAAS,YAAW,YAAY;IAChF,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsE;gBAEnF,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,eAAe,EAAE;IAsB7D;;OAEG;IACI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE;IAcvF;;OAEG;IACI,mBAAmB,IAAI,eAAe,GAAG,IAAI;CAGpD"}
|