ckeditor5-elements-menu 0.0.0-stage → 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.
Files changed (89) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -2
  3. package/dist/augmentation.d.ts +30 -0
  4. package/dist/augmentation.d.ts.map +1 -0
  5. package/dist/augmentation.js +2 -0
  6. package/dist/augmentation.js.map +1 -0
  7. package/dist/breadcrumbs/breadcrumbItemView.d.ts +47 -0
  8. package/dist/breadcrumbs/breadcrumbItemView.d.ts.map +1 -0
  9. package/dist/breadcrumbs/breadcrumbItemView.js +30 -0
  10. package/dist/breadcrumbs/breadcrumbItemView.js.map +1 -0
  11. package/dist/breadcrumbs/breadcrumbLabelView.d.ts +29 -0
  12. package/dist/breadcrumbs/breadcrumbLabelView.d.ts.map +1 -0
  13. package/dist/breadcrumbs/breadcrumbLabelView.js +39 -0
  14. package/dist/breadcrumbs/breadcrumbLabelView.js.map +1 -0
  15. package/dist/breadcrumbs/breadcrumbsView.d.ts +68 -0
  16. package/dist/breadcrumbs/breadcrumbsView.d.ts.map +1 -0
  17. package/dist/breadcrumbs/breadcrumbsView.js +134 -0
  18. package/dist/breadcrumbs/breadcrumbsView.js.map +1 -0
  19. package/dist/breadcrumbs/elementBreadcrumbs.d.ts +73 -0
  20. package/dist/breadcrumbs/elementBreadcrumbs.d.ts.map +1 -0
  21. package/dist/breadcrumbs/elementBreadcrumbs.js +225 -0
  22. package/dist/breadcrumbs/elementBreadcrumbs.js.map +1 -0
  23. package/dist/contextMenu/contextMenuObserver.d.ts +19 -0
  24. package/dist/contextMenu/contextMenuObserver.d.ts.map +1 -0
  25. package/dist/contextMenu/contextMenuObserver.js +18 -0
  26. package/dist/contextMenu/contextMenuObserver.js.map +1 -0
  27. package/dist/contextMenu/elementContextMenu.d.ts +34 -0
  28. package/dist/contextMenu/elementContextMenu.d.ts.map +1 -0
  29. package/dist/contextMenu/elementContextMenu.js +88 -0
  30. package/dist/contextMenu/elementContextMenu.js.map +1 -0
  31. package/dist/domTarget.d.ts +8 -0
  32. package/dist/domTarget.d.ts.map +1 -0
  33. package/dist/domTarget.js +20 -0
  34. package/dist/domTarget.js.map +1 -0
  35. package/dist/elementMenu.d.ts +93 -0
  36. package/dist/elementMenu.d.ts.map +1 -0
  37. package/dist/elementMenu.js +140 -0
  38. package/dist/elementMenu.js.map +1 -0
  39. package/dist/elementMenuView.d.ts +40 -0
  40. package/dist/elementMenuView.d.ts.map +1 -0
  41. package/dist/elementMenuView.js +143 -0
  42. package/dist/elementMenuView.js.map +1 -0
  43. package/dist/index.d.ts +24 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +29 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/quickInsert/elementQuickInsert.d.ts +57 -0
  48. package/dist/quickInsert/elementQuickInsert.d.ts.map +1 -0
  49. package/dist/quickInsert/elementQuickInsert.js +96 -0
  50. package/dist/quickInsert/elementQuickInsert.js.map +1 -0
  51. package/dist/quickInsert/icons.d.ts +16 -0
  52. package/dist/quickInsert/icons.d.ts.map +1 -0
  53. package/dist/quickInsert/icons.js +21 -0
  54. package/dist/quickInsert/icons.js.map +1 -0
  55. package/dist/quickInsert/quickInsertCommand.d.ts +47 -0
  56. package/dist/quickInsert/quickInsertCommand.d.ts.map +1 -0
  57. package/dist/quickInsert/quickInsertCommand.js +81 -0
  58. package/dist/quickInsert/quickInsertCommand.js.map +1 -0
  59. package/dist/quickInsert/quickInsertListView.d.ts +29 -0
  60. package/dist/quickInsert/quickInsertListView.d.ts.map +1 -0
  61. package/dist/quickInsert/quickInsertListView.js +44 -0
  62. package/dist/quickInsert/quickInsertListView.js.map +1 -0
  63. package/dist/quickInsert/quickInsertPositionCommand.d.ts +33 -0
  64. package/dist/quickInsert/quickInsertPositionCommand.d.ts.map +1 -0
  65. package/dist/quickInsert/quickInsertPositionCommand.js +52 -0
  66. package/dist/quickInsert/quickInsertPositionCommand.js.map +1 -0
  67. package/dist/quickInsert/quickInsertView.d.ts +20 -0
  68. package/dist/quickInsert/quickInsertView.d.ts.map +1 -0
  69. package/dist/quickInsert/quickInsertView.js +52 -0
  70. package/dist/quickInsert/quickInsertView.js.map +1 -0
  71. package/package.json +52 -3
  72. package/src/augmentation.ts +44 -0
  73. package/src/breadcrumbs/breadcrumbItemView.ts +74 -0
  74. package/src/breadcrumbs/breadcrumbLabelView.ts +55 -0
  75. package/src/breadcrumbs/breadcrumbsView.ts +176 -0
  76. package/src/breadcrumbs/elementBreadcrumbs.ts +323 -0
  77. package/src/contextMenu/contextMenuObserver.ts +27 -0
  78. package/src/contextMenu/elementContextMenu.ts +104 -0
  79. package/src/domTarget.ts +27 -0
  80. package/src/elementMenu.ts +249 -0
  81. package/src/elementMenuView.ts +202 -0
  82. package/src/index.ts +54 -0
  83. package/src/quickInsert/elementQuickInsert.ts +135 -0
  84. package/src/quickInsert/icons.ts +26 -0
  85. package/src/quickInsert/quickInsertCommand.ts +96 -0
  86. package/src/quickInsert/quickInsertListView.ts +71 -0
  87. package/src/quickInsert/quickInsertPositionCommand.ts +68 -0
  88. package/src/quickInsert/quickInsertView.ts +64 -0
  89. package/theme/menu.css +131 -0
@@ -0,0 +1,140 @@
1
+ import { ContextualBalloon, DropdownMenuRootListView, KeystrokeHandler, Notification, Plugin, clickOutsideHandler } from 'ckeditor5';
2
+ import { isInDocument } from 'ckeditor5-elements-core';
3
+ import ElementMenuView from './elementMenuView.js';
4
+ /**
5
+ * Shows menus in a balloon: the menu of an element, built from commands, submenus and separators (see {@link open}),
6
+ * or any view, e.g. the quick insert search (see {@link show}).
7
+ *
8
+ * The element context menu, the breadcrumbs and quick insert show their menus with it. The menu of an element is
9
+ * CKEditor's dropdown menu (see {@link ElementMenuView}).
10
+ *
11
+ * Executing an item closes the menu. Esc and clicking outside close it too; Esc returns the focus to the editor, or to
12
+ * {@link ElementMenuShowOptions.returnFocusTo}.
13
+ */
14
+ export default class ElementMenu extends Plugin {
15
+ /**
16
+ * The view in the open menu, if any.
17
+ */
18
+ view = null;
19
+ _keystrokes = null;
20
+ _isObsolete = null;
21
+ _onHide = null;
22
+ static get requires() {
23
+ // The buttons of the menu report failed commands with notifications.
24
+ return [ContextualBalloon, Notification];
25
+ }
26
+ static get pluginName() {
27
+ return 'ElementMenu';
28
+ }
29
+ init() {
30
+ this.listenTo(this.editor.model.document, 'change:data', () => {
31
+ if (this._isObsolete?.()) {
32
+ this.hide();
33
+ }
34
+ });
35
+ }
36
+ /**
37
+ * Opens the menu of the element next to the target (e.g. a button, or a `DOMRect` in viewport coordinates), with
38
+ * the items from the config callback. The menu closes when the element is removed.
39
+ *
40
+ * Returns `false` when there are no items.
41
+ */
42
+ open(element, target, config, { label = this.editor.t('Element menu'), isObsolete, ...options } = {}) {
43
+ const view = new ElementMenuView(this.editor.locale, this.editor.ui.view.body, config(element, this.editor), element);
44
+ if (view.isEmpty) {
45
+ view.destroy();
46
+ return false;
47
+ }
48
+ view.ariaLabel = label;
49
+ this.show(view, target, {
50
+ ...options,
51
+ isObsolete: () => !isInDocument(element) || !!isObsolete?.()
52
+ });
53
+ return true;
54
+ }
55
+ /**
56
+ * Shows the view (e.g. a menu) next to the target (e.g. a button, or a `DOMRect` in viewport coordinates), and
57
+ * focuses it. The menu closes when the view, or an item of CKEditor's dropdown menu in it, fires `execute`.
58
+ */
59
+ show(view, target, { isObsolete, returnFocusTo, onHide } = {}) {
60
+ this.hide();
61
+ const close = () => {
62
+ // The item may have opened another menu already (e.g. "Insert before" opens quick insert).
63
+ if (this.view === view) {
64
+ this.hide();
65
+ }
66
+ };
67
+ this.listenTo(view, 'execute', close);
68
+ this.listenTo(view, 'menu:execute', close);
69
+ clickOutsideHandler({
70
+ emitter: view,
71
+ activator: () => this._balloon.visibleView === view,
72
+ // The open nested menus are in panels outside the balloon.
73
+ contextElements: () => [this._balloon.view.element, ...getOpenPanels(view)].filter(element => !!element),
74
+ callback: () => {
75
+ this.hide();
76
+ }
77
+ });
78
+ this._balloon.add({
79
+ view,
80
+ position: { target },
81
+ withArrow: false,
82
+ singleViewMode: true,
83
+ // Views that other plugins add to the balloon meanwhile (e.g. an element toolbar, when the selection moves
84
+ // into its element) go to their own stack, so they do not cover the menu.
85
+ stackId: 'elementMenu'
86
+ });
87
+ const keystrokes = new KeystrokeHandler();
88
+ // Esc in a nested menu closes only that menu.
89
+ keystrokes.set('Esc', (data, cancel) => {
90
+ this.hide();
91
+ (returnFocusTo ?? this.editor.editing.view).focus();
92
+ cancel();
93
+ });
94
+ if (view.element) {
95
+ keystrokes.listenTo(view.element);
96
+ }
97
+ this.view = view;
98
+ this._keystrokes = keystrokes;
99
+ this._isObsolete = isObsolete ?? null;
100
+ this._onHide = onHide ?? null;
101
+ view.focus();
102
+ }
103
+ /**
104
+ * Hides the open menu, if any.
105
+ */
106
+ hide() {
107
+ const view = this.view;
108
+ const onHide = this._onHide;
109
+ if (!view) {
110
+ return;
111
+ }
112
+ this._keystrokes?.destroy();
113
+ this.view = null;
114
+ this._keystrokes = null;
115
+ this._isObsolete = null;
116
+ this._onHide = null;
117
+ this.stopListening(view);
118
+ if (this._balloon.hasView(view)) {
119
+ this._balloon.remove(view);
120
+ }
121
+ view.destroy();
122
+ onHide?.();
123
+ }
124
+ destroy() {
125
+ this.hide();
126
+ super.destroy();
127
+ }
128
+ get _balloon() {
129
+ return this.editor.plugins.get(ContextualBalloon);
130
+ }
131
+ }
132
+ /**
133
+ * Returns the panels of the open nested menus of CKEditor's dropdown menu.
134
+ */
135
+ function getOpenPanels(view) {
136
+ return view instanceof DropdownMenuRootListView
137
+ ? view.menus.filter(menu => menu.isOpen).map(menu => menu.panelView.element)
138
+ : [];
139
+ }
140
+ //# sourceMappingURL=elementMenu.js.map
@@ -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,E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CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAEzB,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC;QAED,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,MAAM,EAAE,EAAE,CAAC;IACZ,CAAC;IAEe,OAAO;QACtB,IAAI,CAAC,IAAI,EAAE,CAAC;QACZ,KAAK,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAED,IAAY,QAAQ;QACnB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IACnD,CAAC;CACD;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,40 @@
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
+ * Missing items are skipped, and submenus without items, and separators at the start or the end, or repeated ones.
14
+ * Submenus are enabled when one of their items is. Right-clicking the menu does not open the native context menu.
15
+ */
16
+ export default class ElementMenuView extends DropdownMenuRootListView {
17
+ /**
18
+ * The element or position the commands are executed for.
19
+ */
20
+ readonly target: ElementOrPosition;
21
+ /**
22
+ * Whether the menu has no items: all were missing.
23
+ */
24
+ readonly isEmpty: boolean;
25
+ private readonly _commands;
26
+ private readonly _submenus;
27
+ /**
28
+ * The positions of the separators in each list, by the id of the submenu (`''` for the menu itself).
29
+ */
30
+ private readonly _separators;
31
+ constructor(locale: Locale, bodyCollection: BodyCollection, items: readonly (ElementMenuItem | null | undefined)[], target: ElementOrPosition);
32
+ /**
33
+ * Renders the menu: CKEditor builds it from the definitions; then the buttons are connected to the commands, and the
34
+ * separators are added.
35
+ */
36
+ render(): void;
37
+ private _addSeparators;
38
+ private _isEnabled;
39
+ }
40
+ //# 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;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,wBAAwB;IACpE;;OAEG;IACH,SAAgB,MAAM,EAAE,iBAAiB,CAAC;IAE1C;;OAEG;IACH,SAAgB,OAAO,EAAE,OAAO,CAAC;IAEjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAwC;IAClE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA2B;IAErD;;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;IAoB1B;;;OAGG;IACa,MAAM,IAAI,IAAI;IAqC9B,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,UAAU;CASlB"}
@@ -0,0 +1,143 @@
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
+ * Missing items are skipped, and submenus without items, and separators at the start or the end, or repeated ones.
14
+ * Submenus are enabled when one of their items is. Right-clicking the menu does not open the native context menu.
15
+ */
16
+ export default class ElementMenuView extends DropdownMenuRootListView {
17
+ /**
18
+ * The element or position the commands are executed for.
19
+ */
20
+ target;
21
+ /**
22
+ * Whether the menu has no items: all were missing.
23
+ */
24
+ isEmpty;
25
+ _commands;
26
+ _submenus;
27
+ /**
28
+ * The positions of the separators in each list, by the id of the submenu (`''` for the menu itself).
29
+ */
30
+ _separators;
31
+ constructor(locale, bodyCollection, items, target) {
32
+ const maps = { commands: new Map(), submenus: new Map(), separators: new Map() };
33
+ const menuItems = cleanItems(items);
34
+ super(locale, bodyCollection, createDefinitions(menuItems, '', maps));
35
+ this.target = target;
36
+ this.isEmpty = !menuItems.length;
37
+ this._commands = maps.commands;
38
+ this._submenus = maps.submenus;
39
+ this._separators = maps.separators;
40
+ this.menuPanelClass = 'ck-elements-menu__panel';
41
+ this.extendTemplate({
42
+ attributes: { class: 'ck-elements-menu' },
43
+ on: { contextmenu: this.bindTemplate.to(preventDefault) }
44
+ });
45
+ }
46
+ /**
47
+ * Renders the menu: CKEditor builds it from the definitions; then the buttons are connected to the commands, and the
48
+ * separators are added.
49
+ */
50
+ render() {
51
+ super.render();
52
+ for (const button of this.buttons) {
53
+ const command = this._commands.get(button.id);
54
+ if (command) {
55
+ bindButtonToCommand(button, command, { withText: true, target: this.target });
56
+ // A toggleable button with a checkable role tells assistive technology whether it is "on" with `aria-checked`.
57
+ button.role = command.isToggleable ? 'menuitemcheckbox' : 'menuitem';
58
+ }
59
+ }
60
+ for (const menu of this.menus) {
61
+ const submenu = this._submenus.get(menu.id);
62
+ if (submenu) {
63
+ menu.buttonView.icon = submenu.icon;
64
+ menu.isEnabled = this._isEnabled(submenu);
65
+ }
66
+ // The panels of nested menus are not inside the menu.
67
+ if (menu.panelView.element) {
68
+ this.listenTo(menu.panelView.element, 'contextmenu', (evt, domEvent) => {
69
+ preventDefault(domEvent);
70
+ });
71
+ }
72
+ }
73
+ this._addSeparators('', this);
74
+ for (const menu of this.menus) {
75
+ this._addSeparators(menu.id, menu.listView);
76
+ }
77
+ }
78
+ _addSeparators(id, list) {
79
+ for (const position of this._separators.get(id) ?? []) {
80
+ const separator = new ListSeparatorView(this.locale);
81
+ separator.extendTemplate({ attributes: { role: 'separator' } });
82
+ list.items.add(separator, position);
83
+ }
84
+ }
85
+ _isEnabled(item) {
86
+ if (item === '|') {
87
+ return false;
88
+ }
89
+ return item instanceof ElementOrPositionCommand
90
+ ? item.getState(this.target).isEnabled
91
+ : item.items.some(child => this._isEnabled(child));
92
+ }
93
+ }
94
+ /**
95
+ * Returns the items without missing ones, submenus without items, and separators at the start or the end, or
96
+ * repeated ones.
97
+ */
98
+ function cleanItems(items) {
99
+ const result = [];
100
+ for (const item of items) {
101
+ const cleaned = item === '|' || item instanceof ElementOrPositionCommand || !item ? item : cleanSubmenu(item);
102
+ if (!cleaned || (cleaned === '|' && (!result.length || result.at(-1) === '|'))) {
103
+ continue;
104
+ }
105
+ result.push(cleaned);
106
+ }
107
+ if (result.at(-1) === '|') {
108
+ result.pop();
109
+ }
110
+ return result;
111
+ }
112
+ function cleanSubmenu(submenu) {
113
+ const items = cleanItems(submenu.items);
114
+ return items.length ? { ...submenu, items } : null;
115
+ }
116
+ /**
117
+ * Creates CKEditor's menu definitions for the items. The ids are paths of positions (e.g. `'2.0'`). Collects the
118
+ * commands and submenus by id, and the positions of the separators by the id of their submenu.
119
+ */
120
+ function createDefinitions(items, parentId, maps) {
121
+ const definitions = [];
122
+ let position = 0;
123
+ for (const item of items) {
124
+ const id = parentId ? `${parentId}.${String(position)}` : String(position);
125
+ if (item === '|') {
126
+ maps.separators.set(parentId, [...(maps.separators.get(parentId) ?? []), position]);
127
+ }
128
+ else if (item instanceof ElementOrPositionCommand) {
129
+ maps.commands.set(id, item);
130
+ definitions.push({ id, label: item.title });
131
+ }
132
+ else {
133
+ maps.submenus.set(id, item);
134
+ definitions.push({ id, menu: item.title, children: createDefinitions(item.items, id, maps) });
135
+ }
136
+ position++;
137
+ }
138
+ return definitions;
139
+ }
140
+ function preventDefault(domEvent) {
141
+ domEvent.preventDefault();
142
+ }
143
+ //# 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;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,wBAAwB;IACpE;;OAEG;IACa,MAAM,CAAoB;IAE1C;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CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,iBAAiB,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;QAC/F,CAAC;QAED,QAAQ,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,WAAW,CAAC;AACpB,CAAC;AAED,SAAS,cAAc,CAAC,QAAe;IACtC,QAAQ,CAAC,cAAc,EAAE,CAAC;AAC3B,CAAC"}
@@ -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 ElementBreadcrumbs, type ElementBreadcrumbsConfig } from './breadcrumbs/elementBreadcrumbs.js';
12
+ export { default as ElementQuickInsert, type ElementQuickInsertConfig } from './quickInsert/elementQuickInsert.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,kBAAkB,EAAE,KAAK,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AACnH,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,KAAK,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAGnH,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 ElementBreadcrumbs } from './breadcrumbs/elementBreadcrumbs.js';
13
+ export { default as ElementQuickInsert } from './quickInsert/elementQuickInsert.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,kBAAkB,EAAiC,MAAM,qCAAqC,CAAC;AACnH,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAiC,MAAM,qCAAqC,CAAC;AAEnH,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,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 ElementQuickInsert} plugin.
7
+ */
8
+ export interface ElementQuickInsertConfig {
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 ElementQuickInsertConfig.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 ElementQuickInsert extends Plugin {
34
+ static get requires(): readonly [typeof ElementMenu];
35
+ static get pluginName(): 'ElementQuickInsert';
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
+ * Whether an element can be inserted at the target (a position, the position before an element, or the selection),
45
+ * as {@link getItems} lists them: it stops at the first one, e.g. for whether a command is enabled.
46
+ */
47
+ hasItems(elementOrPosition?: ElementOrPosition): boolean;
48
+ /**
49
+ * Opens the menu for inserting at the target (a position, the position before an element, or the selection), next
50
+ * to the given DOM target. By default, the menu is next to the element, or the selection.
51
+ *
52
+ * Returns `false` when nothing can be inserted at the target because it cannot be edited, or there is nothing to
53
+ * show the menu next to.
54
+ */
55
+ open(elementOrPosition?: ElementOrPosition, domTarget?: RectSource): boolean;
56
+ }
57
+ //# sourceMappingURL=elementQuickInsert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementQuickInsert.d.ts","sourceRoot":"","sources":["../../src/quickInsert/elementQuickInsert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,MAAM,EAAiC,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAChG,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,OAAO,WAAW,MAAM,mBAAmB,CAAC;AAG5C,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAGhE;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACxC;;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,kBAAmB,SAAQ,MAAM;IACrD,WAAkB,QAAQ,IAAI,SAAS,CAAC,OAAO,WAAW,CAAC,CAE1D;IAED,WAAkB,UAAU,IAAI,oBAAoB,CAEnD;gBAEW,MAAM,EAAE,MAAM;IAMnB,IAAI,IAAI,IAAI;IAqBnB;;;OAGG;IACI,QAAQ,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,eAAe,EAAE;IAWzE;;;OAGG;IACI,QAAQ,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,OAAO;IAM/D;;;;;;OAMG;IACI,IAAI,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,EAAE,SAAS,CAAC,EAAE,UAAU,GAAG,OAAO;CA0BnF"}
@@ -0,0 +1,96 @@
1
+ import { Plugin } from 'ckeditor5';
2
+ import { getDomTarget } from '../domTarget.js';
3
+ import ElementMenu from '../elementMenu.js';
4
+ import QuickInsertCommand from './quickInsertCommand.js';
5
+ import QuickInsertPositionCommand from './quickInsertPositionCommand.js';
6
+ import {} from './quickInsertListView.js';
7
+ import QuickInsertView from './quickInsertView.js';
8
+ /**
9
+ * Opens a menu with a search field and the elements allowed at the selection, on Alt+Enter (Option+Enter on macOS; see
10
+ * {@link ElementQuickInsertConfig.keystroke}). Choosing an element inserts it with the `quickInsert` command.
11
+ *
12
+ * The menu is shown by the `ElementMenu` plugin. The `quickInsertBefore` and `quickInsertAfter` commands (see
13
+ * {@link QuickInsertPositionCommand}) open it for the position before or after an element; list them in the
14
+ * `elementContextMenu` config, e.g. as an "Insert" submenu.
15
+ *
16
+ * The menu closes when the document changes while it is open, so it never inserts at an outdated position.
17
+ */
18
+ export default class ElementQuickInsert extends Plugin {
19
+ static get requires() {
20
+ return [ElementMenu];
21
+ }
22
+ static get pluginName() {
23
+ return 'ElementQuickInsert';
24
+ }
25
+ constructor(editor) {
26
+ super(editor);
27
+ editor.config.define('elementQuickInsert', { labels: {}, exclude: [], keystroke: 'Alt+Enter' });
28
+ }
29
+ init() {
30
+ const editor = this.editor;
31
+ const keystroke = editor.config.get('elementQuickInsert')?.keystroke;
32
+ editor.commands.add('quickInsert', new QuickInsertCommand(editor));
33
+ editor.commands.add('quickInsertBefore', new QuickInsertPositionCommand(editor, 'before', this));
34
+ editor.commands.add('quickInsertAfter', new QuickInsertPositionCommand(editor, 'after', this));
35
+ if (keystroke) {
36
+ editor.keystrokes.set(keystroke, (data, cancel) => {
37
+ if (this.open()) {
38
+ cancel();
39
+ }
40
+ });
41
+ editor.accessibility.addKeystrokeInfos({
42
+ keystrokes: [{ label: editor.t('Insert an element at the cursor'), keystroke }]
43
+ });
44
+ }
45
+ }
46
+ /**
47
+ * Returns the elements that can be inserted at the target (a position, the position before an element, or the
48
+ * selection), with their labels.
49
+ */
50
+ getItems(elementOrPosition) {
51
+ const config = this.editor.config.get('elementQuickInsert');
52
+ const labels = config?.labels ?? {};
53
+ const command = this.editor.commands.get('quickInsert');
54
+ return (command?.getAllowedElements(elementOrPosition, config?.exclude) ?? []).map(name => ({
55
+ name,
56
+ label: labels[name] ?? name
57
+ }));
58
+ }
59
+ /**
60
+ * Whether an element can be inserted at the target (a position, the position before an element, or the selection),
61
+ * as {@link getItems} lists them: it stops at the first one, e.g. for whether a command is enabled.
62
+ */
63
+ hasItems(elementOrPosition) {
64
+ const command = this.editor.commands.get('quickInsert');
65
+ return !!command?.hasAllowedElements(elementOrPosition, this.editor.config.get('elementQuickInsert')?.exclude);
66
+ }
67
+ /**
68
+ * Opens the menu for inserting at the target (a position, the position before an element, or the selection), next
69
+ * to the given DOM target. By default, the menu is next to the element, or the selection.
70
+ *
71
+ * Returns `false` when nothing can be inserted at the target because it cannot be edited, or there is nothing to
72
+ * show the menu next to.
73
+ */
74
+ open(elementOrPosition, domTarget) {
75
+ const editor = this.editor;
76
+ const command = editor.commands.get('quickInsert');
77
+ const position = command?.getInsertPosition(elementOrPosition);
78
+ const menuTarget = domTarget ?? getDomTarget(editor, elementOrPosition);
79
+ if (!command || !position || !menuTarget || !command.getState(position).isEnabled) {
80
+ return false;
81
+ }
82
+ const view = new QuickInsertView(editor.locale, this.getItems(position));
83
+ view.on('execute', (evt, { value }) => {
84
+ // Focus first: focusing reads the DOM selection, which would override the selection set by the command.
85
+ editor.editing.view.focus();
86
+ command.executeFor(position, value);
87
+ });
88
+ // The search field is labelled "Insert element".
89
+ editor.plugins.get(ElementMenu).show(view, menuTarget, {
90
+ // The position would be outdated after any change, e.g. by another user.
91
+ isObsolete: () => true
92
+ });
93
+ return true;
94
+ }
95
+ }
96
+ //# sourceMappingURL=elementQuickInsert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementQuickInsert.js","sourceRoot":"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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"}