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.
Files changed (84) 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/breadcrumbs.d.ts +72 -0
  16. package/dist/breadcrumbs/breadcrumbs.d.ts.map +1 -0
  17. package/dist/breadcrumbs/breadcrumbs.js +224 -0
  18. package/dist/breadcrumbs/breadcrumbs.js.map +1 -0
  19. package/dist/breadcrumbs/breadcrumbsView.d.ts +68 -0
  20. package/dist/breadcrumbs/breadcrumbsView.d.ts.map +1 -0
  21. package/dist/breadcrumbs/breadcrumbsView.js +134 -0
  22. package/dist/breadcrumbs/breadcrumbsView.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 +98 -0
  30. package/dist/contextMenu/elementContextMenu.js.map +1 -0
  31. package/dist/elementMenu.d.ts +93 -0
  32. package/dist/elementMenu.d.ts.map +1 -0
  33. package/dist/elementMenu.js +162 -0
  34. package/dist/elementMenu.js.map +1 -0
  35. package/dist/elementMenuView.d.ts +35 -0
  36. package/dist/elementMenuView.d.ts.map +1 -0
  37. package/dist/elementMenuView.js +117 -0
  38. package/dist/elementMenuView.js.map +1 -0
  39. package/dist/index.d.ts +24 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +29 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/quickInsert/icons.d.ts +16 -0
  44. package/dist/quickInsert/icons.d.ts.map +1 -0
  45. package/dist/quickInsert/icons.js +21 -0
  46. package/dist/quickInsert/icons.js.map +1 -0
  47. package/dist/quickInsert/quickInsert.d.ts +57 -0
  48. package/dist/quickInsert/quickInsert.d.ts.map +1 -0
  49. package/dist/quickInsert/quickInsert.js +106 -0
  50. package/dist/quickInsert/quickInsert.js.map +1 -0
  51. package/dist/quickInsert/quickInsertCommand.d.ts +38 -0
  52. package/dist/quickInsert/quickInsertCommand.d.ts.map +1 -0
  53. package/dist/quickInsert/quickInsertCommand.js +70 -0
  54. package/dist/quickInsert/quickInsertCommand.js.map +1 -0
  55. package/dist/quickInsert/quickInsertListView.d.ts +29 -0
  56. package/dist/quickInsert/quickInsertListView.d.ts.map +1 -0
  57. package/dist/quickInsert/quickInsertListView.js +44 -0
  58. package/dist/quickInsert/quickInsertListView.js.map +1 -0
  59. package/dist/quickInsert/quickInsertPositionCommand.d.ts +28 -0
  60. package/dist/quickInsert/quickInsertPositionCommand.d.ts.map +1 -0
  61. package/dist/quickInsert/quickInsertPositionCommand.js +54 -0
  62. package/dist/quickInsert/quickInsertPositionCommand.js.map +1 -0
  63. package/dist/quickInsert/quickInsertView.d.ts +20 -0
  64. package/dist/quickInsert/quickInsertView.d.ts.map +1 -0
  65. package/dist/quickInsert/quickInsertView.js +52 -0
  66. package/dist/quickInsert/quickInsertView.js.map +1 -0
  67. package/package.json +49 -3
  68. package/src/augmentation.ts +44 -0
  69. package/src/breadcrumbs/breadcrumbItemView.ts +74 -0
  70. package/src/breadcrumbs/breadcrumbLabelView.ts +55 -0
  71. package/src/breadcrumbs/breadcrumbs.ts +322 -0
  72. package/src/breadcrumbs/breadcrumbsView.ts +176 -0
  73. package/src/contextMenu/contextMenuObserver.ts +27 -0
  74. package/src/contextMenu/elementContextMenu.ts +116 -0
  75. package/src/elementMenu.ts +274 -0
  76. package/src/elementMenuView.ts +163 -0
  77. package/src/index.ts +54 -0
  78. package/src/quickInsert/icons.ts +26 -0
  79. package/src/quickInsert/quickInsert.ts +149 -0
  80. package/src/quickInsert/quickInsertCommand.ts +85 -0
  81. package/src/quickInsert/quickInsertListView.ts +71 -0
  82. package/src/quickInsert/quickInsertPositionCommand.ts +72 -0
  83. package/src/quickInsert/quickInsertView.ts +64 -0
  84. package/theme/menu.css +131 -0
@@ -0,0 +1,44 @@
1
+ import { ButtonView, ListItemView, ListView } from 'ckeditor5';
2
+ /**
3
+ * A list of insertable elements that can be filtered by a search query.
4
+ *
5
+ * Fires `execute` with `{ value: name }` when an item is chosen.
6
+ */
7
+ export default class QuickInsertListView extends ListView {
8
+ _entries;
9
+ constructor(locale, items) {
10
+ super(locale);
11
+ this.role = 'listbox';
12
+ this._entries = items.map(item => {
13
+ const view = new ListItemView(locale);
14
+ const button = new ButtonView(locale);
15
+ button.set({ label: item.label, withText: true, role: 'option' });
16
+ button.on('execute', () => {
17
+ this.fire('execute', { value: item.name });
18
+ });
19
+ view.children.add(button);
20
+ return { item, view, button };
21
+ });
22
+ this.items.addMany(this._entries.map(entry => entry.view));
23
+ }
24
+ /**
25
+ * Shows only the items whose label or name matches the expression. `null` shows all items.
26
+ */
27
+ filter(regExp) {
28
+ let resultsCount = 0;
29
+ for (const { item, view } of this._entries) {
30
+ view.isVisible = !regExp || regExp.test(item.label) || regExp.test(item.name);
31
+ if (view.isVisible) {
32
+ resultsCount++;
33
+ }
34
+ }
35
+ return { resultsCount, totalItemsCount: this._entries.length };
36
+ }
37
+ /**
38
+ * Returns the first item that is not filtered out.
39
+ */
40
+ getFirstVisibleItem() {
41
+ return this._entries.find(entry => entry.view.isVisible)?.item ?? null;
42
+ }
43
+ }
44
+ //# sourceMappingURL=quickInsertListView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quickInsertListView.js","sourceRoot":"","sources":["../../src/quickInsert/quickInsertListView.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,UAAU,EACV,YAAY,EACZ,QAAQ,EAIR,MAAM,WAAW,CAAC;AAUnB;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,QAAQ;IACvC,QAAQ,CAAsE;IAE/F,YAAY,MAAc,EAAE,KAAiC;QAC5D,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;QAEtB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAChC,MAAM,IAAI,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;YACtC,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;YAEtC,MAAM,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;YAClE,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;gBACzB,IAAI,CAAC,IAAI,CAA2B,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;YACtE,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YAE1B,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,MAAqB;QAClC,IAAI,YAAY,GAAG,CAAC,CAAC;QAErB,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC5C,IAAI,CAAC,SAAS,GAAG,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAE9E,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;gBACpB,YAAY,EAAE,CAAC;YAChB,CAAC;QACF,CAAC;QAED,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAChE,CAAC;IAED;;OAEG;IACI,mBAAmB;QACzB,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,IAAI,IAAI,CAAC;IACxE,CAAC;CACD"}
@@ -0,0 +1,28 @@
1
+ import { type Editor } from 'ckeditor5';
2
+ import { ElementOrPositionCommand, type ElementOrPosition } from 'ckeditor5-elements-core';
3
+ /**
4
+ * Where the quick insert menu inserts, relative to the element.
5
+ */
6
+ export type QuickInsertPlacement = 'before' | 'after';
7
+ /**
8
+ * Opens the quick insert menu for the position before or after an element, next to that element.
9
+ *
10
+ * The element is the given one, the parent of the given position, or the selected element or the parent of the
11
+ * selection (see {@link ElementOrPositionCommand}). Enabled when something can be inserted at that position.
12
+ *
13
+ * Requires the `QuickInsert` plugin, which registers it as `quickInsertBefore` and `quickInsertAfter`.
14
+ */
15
+ export default class QuickInsertPositionCommand extends ElementOrPositionCommand {
16
+ /**
17
+ * Where the quick insert menu inserts, relative to the element.
18
+ */
19
+ readonly placement: QuickInsertPlacement;
20
+ constructor(editor: Editor, placement: QuickInsertPlacement);
21
+ /**
22
+ * Opens the quick insert menu for the position before or after the element, next to the element.
23
+ */
24
+ execute(elementOrPosition?: ElementOrPosition): void;
25
+ protected _isEnabledFor(elementOrPosition?: ElementOrPosition): boolean;
26
+ private _getInsertPosition;
27
+ }
28
+ //# sourceMappingURL=quickInsertPositionCommand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quickInsertPositionCommand.d.ts","sourceRoot":"","sources":["../../src/quickInsert/quickInsertPositionCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAsB,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,KAAK,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG3F;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEtD;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,0BAA2B,SAAQ,wBAAwB;IAC/E;;OAEG;IACH,SAAgB,SAAS,EAAE,oBAAoB,CAAC;gBAEpC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,oBAAoB;IAQ3D;;OAEG;IACa,OAAO,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,IAAI;cAejD,aAAa,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,OAAO;IAYhF,OAAO,CAAC,kBAAkB;CAU1B"}
@@ -0,0 +1,54 @@
1
+ import {} from 'ckeditor5';
2
+ import { ElementOrPositionCommand } from 'ckeditor5-elements-core';
3
+ import { insertAfterIcon, insertBeforeIcon } from './icons.js';
4
+ /**
5
+ * Opens the quick insert menu for the position before or after an element, next to that element.
6
+ *
7
+ * The element is the given one, the parent of the given position, or the selected element or the parent of the
8
+ * selection (see {@link ElementOrPositionCommand}). Enabled when something can be inserted at that position.
9
+ *
10
+ * Requires the `QuickInsert` plugin, which registers it as `quickInsertBefore` and `quickInsertAfter`.
11
+ */
12
+ export default class QuickInsertPositionCommand extends ElementOrPositionCommand {
13
+ /**
14
+ * Where the quick insert menu inserts, relative to the element.
15
+ */
16
+ placement;
17
+ constructor(editor, placement) {
18
+ super(editor);
19
+ this.placement = placement;
20
+ this.title = placement === 'before' ? editor.t('Insert before') : editor.t('Insert after');
21
+ this.icon = placement === 'before' ? insertBeforeIcon : insertAfterIcon;
22
+ }
23
+ /**
24
+ * Opens the quick insert menu for the position before or after the element, next to the element.
25
+ */
26
+ execute(elementOrPosition) {
27
+ const editor = this.editor;
28
+ const element = this._getElement(elementOrPosition);
29
+ const position = this._getInsertPosition(elementOrPosition);
30
+ if (!element || !position) {
31
+ return;
32
+ }
33
+ const viewElement = editor.editing.mapper.toViewElement(element);
34
+ const domElement = viewElement && editor.editing.view.domConverter.mapViewToDom(viewElement);
35
+ editor.plugins.get('QuickInsert').open(position, domElement ?? undefined);
36
+ }
37
+ _isEnabledFor(elementOrPosition) {
38
+ const position = this._getInsertPosition(elementOrPosition);
39
+ const plugins = this.editor.plugins;
40
+ return (!!position &&
41
+ this.editor.model.canEditAt(position) &&
42
+ plugins.has('QuickInsert') &&
43
+ plugins.get('QuickInsert').getItems(position).length > 0);
44
+ }
45
+ _getInsertPosition(elementOrPosition) {
46
+ const element = this._getElement(elementOrPosition);
47
+ const model = this.editor.model;
48
+ if (!element) {
49
+ return null;
50
+ }
51
+ return this.placement === 'before' ? model.createPositionBefore(element) : model.createPositionAfter(element);
52
+ }
53
+ }
54
+ //# sourceMappingURL=quickInsertPositionCommand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quickInsertPositionCommand.js","sourceRoot":"","sources":["../../src/quickInsert/quickInsertPositionCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAA0B,MAAM,yBAAyB,CAAC;AAC3F,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAO/D;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,0BAA2B,SAAQ,wBAAwB;IAC/E;;OAEG;IACa,SAAS,CAAuB;IAEhD,YAAY,MAAc,EAAE,SAA+B;QAC1D,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC;QAC3F,IAAI,CAAC,IAAI,GAAG,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,eAAe,CAAC;IACzE,CAAC;IAED;;OAEG;IACa,OAAO,CAAC,iBAAqC;QAC5D,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;QACpD,MAAM,QAAQ,GAAG,IAAI,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,CAAC;QAE5D,IAAI,CAAC,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC3B,OAAO;QACR,CAAC;QAED,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACjE,MAAM,UAAU,GAAG,WAAW,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;QAE7F,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,UAAU,IAAI,SAAS,CAAC,CAAC;IAC3E,CAAC;IAEkB,aAAa,CAAC,iBAAqC;QACrE,MAAM,QAAQ,GAAG,IAAI,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,CAAC;QAC5D,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;QAEpC,OAAO,CACN,CAAC,CAAC,QAAQ;YACV,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC;YACrC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;YAC1B,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,MAAM,GAAG,CAAC,CACxD,CAAC;IACH,CAAC;IAEO,kBAAkB,CAAC,iBAAqC;QAC/D,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;QACpD,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QAEhC,IAAI,CAAC,OAAO,EAAE,CAAC;YACd,OAAO,IAAI,CAAC;QACb,CAAC;QAED,OAAO,IAAI,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;IAC/G,CAAC;CACD"}
@@ -0,0 +1,20 @@
1
+ import { SearchTextView, type Locale } from 'ckeditor5';
2
+ import QuickInsertListView, { type QuickInsertItem } from './quickInsertListView.js';
3
+ /**
4
+ * A search field with a filtered list of insertable elements.
5
+ *
6
+ * In the search field, Enter chooses the first matching item and the down arrow moves the focus to the list.
7
+ * Fires `execute` with `{ value: name }` when an item is chosen.
8
+ */
9
+ export default class QuickInsertView extends SearchTextView {
10
+ /**
11
+ * The list of elements.
12
+ */
13
+ readonly listView: QuickInsertListView;
14
+ constructor(locale: Locale, items: readonly QuickInsertItem[]);
15
+ /**
16
+ * Renders the view and sets up Enter (choose the first match) and the down arrow (go to the list) in the search field.
17
+ */
18
+ render(): void;
19
+ }
20
+ //# sourceMappingURL=quickInsertView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quickInsertView.d.ts","sourceRoot":"","sources":["../../src/quickInsert/quickInsertView.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAiC,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AACvF,OAAO,mBAAmB,EAAE,EAAE,KAAK,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAErF;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,cAAc;IAC1D;;OAEG;IACH,SAAgB,QAAQ,EAAE,mBAAmB,CAAC;gBAElC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,eAAe,EAAE;IAoB7D;;OAEG;IACa,MAAM,IAAI,IAAI;CAyB9B"}
@@ -0,0 +1,52 @@
1
+ import { SearchTextView } from 'ckeditor5';
2
+ import QuickInsertListView, {} from './quickInsertListView.js';
3
+ /**
4
+ * A search field with a filtered list of insertable elements.
5
+ *
6
+ * In the search field, Enter chooses the first matching item and the down arrow moves the focus to the list.
7
+ * Fires `execute` with `{ value: name }` when an item is chosen.
8
+ */
9
+ export default class QuickInsertView extends SearchTextView {
10
+ /**
11
+ * The list of elements.
12
+ */
13
+ listView;
14
+ constructor(locale, items) {
15
+ const listView = new QuickInsertListView(locale, items);
16
+ const t = locale.t;
17
+ super(locale, {
18
+ queryView: { label: t('Insert element') },
19
+ filteredView: listView,
20
+ infoView: {
21
+ text: {
22
+ notFound: { primary: t('No matching elements') },
23
+ noSearchableItems: { primary: t('No elements can be inserted here') }
24
+ }
25
+ },
26
+ class: 'ck-elements-quick-insert'
27
+ });
28
+ this.listView = listView;
29
+ listView.delegate('execute').to(this);
30
+ }
31
+ /**
32
+ * Renders the view and sets up Enter (choose the first match) and the down arrow (go to the list) in the search field.
33
+ */
34
+ render() {
35
+ super.render();
36
+ const isInQueryField = () => this.focusTracker.focusedElement === this.queryView.element;
37
+ this.keystrokes.set('enter', (data, cancel) => {
38
+ const item = isInQueryField() ? this.listView.getFirstVisibleItem() : null;
39
+ if (item) {
40
+ this.fire('execute', { value: item.name });
41
+ cancel();
42
+ }
43
+ });
44
+ this.keystrokes.set('arrowdown', (data, cancel) => {
45
+ if (isInQueryField()) {
46
+ this.listView.focusFirst();
47
+ cancel();
48
+ }
49
+ }, { priority: 'high' });
50
+ }
51
+ }
52
+ //# sourceMappingURL=quickInsertView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quickInsertView.js","sourceRoot":"","sources":["../../src/quickInsert/quickInsertView.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAA8C,MAAM,WAAW,CAAC;AACvF,OAAO,mBAAmB,EAAE,EAAwB,MAAM,0BAA0B,CAAC;AAErF;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,cAAc;IAC1D;;OAEG;IACa,QAAQ,CAAsB;IAE9C,YAAY,MAAc,EAAE,KAAiC;QAC5D,MAAM,QAAQ,GAAG,IAAI,mBAAmB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACxD,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;QAEnB,KAAK,CAAC,MAAM,EAAE;YACb,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,gBAAgB,CAAC,EAAE;YACzC,YAAY,EAAE,QAAQ;YACtB,QAAQ,EAAE;gBACT,IAAI,EAAE;oBACL,QAAQ,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,sBAAsB,CAAC,EAAE;oBAChD,iBAAiB,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,kCAAkC,CAAC,EAAE;iBACrE;aACD;YACD,KAAK,EAAE,0BAA0B;SACjC,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IAED;;OAEG;IACa,MAAM;QACrB,KAAK,CAAC,MAAM,EAAE,CAAC;QAEf,MAAM,cAAc,GAAG,GAAY,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,cAAc,KAAK,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;QAElG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE;YAC7C,MAAM,IAAI,GAAG,cAAc,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;YAE3E,IAAI,IAAI,EAAE,CAAC;gBACV,IAAI,CAAC,IAAI,CAA2B,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;gBACrE,MAAM,EAAE,CAAC;YACV,CAAC;QACF,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,UAAU,CAAC,GAAG,CAClB,WAAW,EACX,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE;YAChB,IAAI,cAAc,EAAE,EAAE,CAAC;gBACtB,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;gBAC3B,MAAM,EAAE,CAAC;YACV,CAAC;QACF,CAAC,EACD,EAAE,QAAQ,EAAE,MAAM,EAAE,CACpB,CAAC;IACH,CAAC;CACD"}
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "ckeditor5-elements-menu",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "49.0.0-alpha.4",
4
+ "description": "Element menus for CKEditor 5: the menu of an element, built from commands, and the element context menu, breadcrumbs and quick insert that open it.",
5
+ "keywords": [
6
+ "ckeditor",
7
+ "ckeditor5",
8
+ "ckeditor 5",
9
+ "ckeditor5-feature",
10
+ "ckeditor5-plugin"
11
+ ],
12
+ "license": "MIT",
13
+ "author": "Ivan Kildyushov",
14
+ "homepage": "https://ivankild.github.io/ckeditor5-elements/guide/context-menu",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/ivankild/ckeditor5-elements.git",
18
+ "directory": "packages/ckeditor5-elements-menu"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/ivankild/ckeditor5-elements/issues"
22
+ },
23
+ "type": "module",
24
+ "main": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.js"
30
+ },
31
+ "./index.css": "./theme/menu.css",
32
+ "./package.json": "./package.json"
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "src",
37
+ "theme",
38
+ "README.md"
39
+ ],
40
+ "sideEffects": [
41
+ "*.css"
42
+ ],
43
+ "dependencies": {
44
+ "ckeditor5-elements-core": "49.0.0-alpha.4"
45
+ },
46
+ "peerDependencies": {
47
+ "ckeditor5": "^49.0.0"
48
+ },
49
+ "scripts": {
50
+ "build": "tsc --build"
51
+ }
6
52
  }
@@ -0,0 +1,44 @@
1
+ import type {
2
+ Breadcrumbs,
3
+ BreadcrumbsConfig,
4
+ ElementContextMenu,
5
+ ElementMenu,
6
+ ElementMenuConfig,
7
+ QuickInsert,
8
+ QuickInsertCommand,
9
+ QuickInsertConfig,
10
+ QuickInsertPositionCommand
11
+ } from './index.js';
12
+
13
+ declare module 'ckeditor5' {
14
+ interface PluginsMap {
15
+ [ElementMenu.pluginName]: ElementMenu;
16
+ [ElementContextMenu.pluginName]: ElementContextMenu;
17
+ [Breadcrumbs.pluginName]: Breadcrumbs;
18
+ [QuickInsert.pluginName]: QuickInsert;
19
+ }
20
+
21
+ interface CommandsMap {
22
+ quickInsert: QuickInsertCommand;
23
+ quickInsertBefore: QuickInsertPositionCommand;
24
+ quickInsertAfter: QuickInsertPositionCommand;
25
+ }
26
+
27
+ interface EditorConfig {
28
+ /**
29
+ * Returns the items (commands, submenus and `'|'` separators) of the context menu of the right-clicked element.
30
+ * See {@link ElementContextMenu}.
31
+ */
32
+ elementContextMenu?: ElementMenuConfig;
33
+
34
+ /**
35
+ * The configuration of the {@link Breadcrumbs} plugin.
36
+ */
37
+ breadcrumbs?: BreadcrumbsConfig;
38
+
39
+ /**
40
+ * The configuration of the {@link QuickInsert} plugin.
41
+ */
42
+ quickInsert?: QuickInsertConfig;
43
+ }
44
+ }
@@ -0,0 +1,74 @@
1
+ import { ButtonView, type Locale, type ModelElement, type ViewElement } from 'ckeditor5';
2
+
3
+ /**
4
+ * A single breadcrumb that can be clicked: a button labelled with one element of the data view, e.g. `section.title`.
5
+ * It opens the menu of its element (`aria-haspopup`), and is `aria-expanded` while the menu is open.
6
+ */
7
+ export default class BreadcrumbItemView extends ButtonView {
8
+ /**
9
+ * The data view element this item stands for.
10
+ */
11
+ public readonly viewElement: ViewElement;
12
+
13
+ /**
14
+ * The model element the menu of this item is for.
15
+ */
16
+ public readonly modelElement: ModelElement | null;
17
+
18
+ /**
19
+ * Whether the menu of this item is open.
20
+ *
21
+ * @observable
22
+ */
23
+ declare public isExpanded: boolean;
24
+
25
+ constructor(
26
+ locale: Locale | undefined,
27
+ { label, viewElement, modelElement }: BreadcrumbItem,
28
+ { isCurrent = false }: BreadcrumbItemViewOptions = {}
29
+ ) {
30
+ super(locale);
31
+
32
+ this.viewElement = viewElement;
33
+ this.modelElement = modelElement;
34
+
35
+ this.set({ label, withText: true, isExpanded: false });
36
+
37
+ this.extendTemplate({
38
+ attributes: {
39
+ class: 'ck-elements-breadcrumbs__item',
40
+ 'aria-haspopup': 'menu',
41
+ 'aria-expanded': this.bindTemplate.to('isExpanded', value => String(value)),
42
+ ...(isCurrent ? { 'aria-current': 'location' } : {})
43
+ }
44
+ });
45
+ }
46
+ }
47
+
48
+ /**
49
+ * The options of {@link BreadcrumbItemView} and {@link BreadcrumbLabelView}.
50
+ */
51
+ export interface BreadcrumbItemViewOptions {
52
+ /**
53
+ * Whether the item is the innermost element (where the cursor is). It is marked with `aria-current="location"`.
54
+ */
55
+ isCurrent?: boolean;
56
+ }
57
+
58
+ /**
59
+ * A breadcrumb: an element of the data view, its label, and the model element it belongs to.
60
+ */
61
+ export interface BreadcrumbItem {
62
+ label: string;
63
+
64
+ /**
65
+ * The data view element (as in the editor data, e.g. `getData()`).
66
+ */
67
+ viewElement: ViewElement;
68
+
69
+ /**
70
+ * The model element of the view element: the mapped one, or for a part of a structure (e.g. a `tbody`), the closest
71
+ * mapped ancestor (the table). `null` for list items (`ul`, `li`), which come from block attributes.
72
+ */
73
+ modelElement: ModelElement | null;
74
+ }
@@ -0,0 +1,55 @@
1
+ import { View, type Locale, type ModelElement, type ViewElement } from 'ckeditor5';
2
+ import { type BreadcrumbItem, type BreadcrumbItemViewOptions } from './breadcrumbItemView.js';
3
+
4
+ /**
5
+ * A single breadcrumb that cannot be clicked: the label of one element of the data view, e.g. `section.title`.
6
+ *
7
+ * It can be focused (but is not in the Tab order), so keyboard users can reach it in a toolbar.
8
+ */
9
+ export default class BreadcrumbLabelView extends View {
10
+ /**
11
+ * The data view element this item stands for.
12
+ */
13
+ public readonly viewElement: ViewElement;
14
+
15
+ /**
16
+ * The model element of the view element, if any.
17
+ */
18
+ public readonly modelElement: ModelElement | null;
19
+
20
+ /**
21
+ * The label of the element.
22
+ *
23
+ * @observable
24
+ */
25
+ declare public label: string;
26
+
27
+ constructor(
28
+ locale: Locale | undefined,
29
+ { label, viewElement, modelElement }: BreadcrumbItem,
30
+ { isCurrent = false }: BreadcrumbItemViewOptions = {}
31
+ ) {
32
+ super(locale);
33
+
34
+ this.viewElement = viewElement;
35
+ this.modelElement = modelElement;
36
+ this.set('label', label);
37
+
38
+ this.setTemplate({
39
+ tag: 'span',
40
+ attributes: {
41
+ class: ['ck', 'ck-elements-breadcrumbs__item', 'ck-elements-breadcrumbs__label'],
42
+ tabindex: '-1',
43
+ ...(isCurrent ? { 'aria-current': 'location' } : {})
44
+ },
45
+ children: [{ text: this.bindTemplate.to('label') }]
46
+ });
47
+ }
48
+
49
+ /**
50
+ * Focuses the label.
51
+ */
52
+ public focus(): void {
53
+ this.element?.focus();
54
+ }
55
+ }