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.
- 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/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/breadcrumbs/elementBreadcrumbs.d.ts +73 -0
- package/dist/breadcrumbs/elementBreadcrumbs.d.ts.map +1 -0
- package/dist/breadcrumbs/elementBreadcrumbs.js +225 -0
- package/dist/breadcrumbs/elementBreadcrumbs.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 +88 -0
- package/dist/contextMenu/elementContextMenu.js.map +1 -0
- package/dist/domTarget.d.ts +8 -0
- package/dist/domTarget.d.ts.map +1 -0
- package/dist/domTarget.js +20 -0
- package/dist/domTarget.js.map +1 -0
- package/dist/elementMenu.d.ts +93 -0
- package/dist/elementMenu.d.ts.map +1 -0
- package/dist/elementMenu.js +140 -0
- package/dist/elementMenu.js.map +1 -0
- package/dist/elementMenuView.d.ts +40 -0
- package/dist/elementMenuView.d.ts.map +1 -0
- package/dist/elementMenuView.js +143 -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/elementQuickInsert.d.ts +57 -0
- package/dist/quickInsert/elementQuickInsert.d.ts.map +1 -0
- package/dist/quickInsert/elementQuickInsert.js +96 -0
- package/dist/quickInsert/elementQuickInsert.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/quickInsertCommand.d.ts +47 -0
- package/dist/quickInsert/quickInsertCommand.d.ts.map +1 -0
- package/dist/quickInsert/quickInsertCommand.js +81 -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 +33 -0
- package/dist/quickInsert/quickInsertPositionCommand.d.ts.map +1 -0
- package/dist/quickInsert/quickInsertPositionCommand.js +52 -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 +52 -3
- package/src/augmentation.ts +44 -0
- package/src/breadcrumbs/breadcrumbItemView.ts +74 -0
- package/src/breadcrumbs/breadcrumbLabelView.ts +55 -0
- package/src/breadcrumbs/breadcrumbsView.ts +176 -0
- package/src/breadcrumbs/elementBreadcrumbs.ts +323 -0
- package/src/contextMenu/contextMenuObserver.ts +27 -0
- package/src/contextMenu/elementContextMenu.ts +104 -0
- package/src/domTarget.ts +27 -0
- package/src/elementMenu.ts +249 -0
- package/src/elementMenuView.ts +202 -0
- package/src/index.ts +54 -0
- package/src/quickInsert/elementQuickInsert.ts +135 -0
- package/src/quickInsert/icons.ts +26 -0
- package/src/quickInsert/quickInsertCommand.ts +96 -0
- package/src/quickInsert/quickInsertListView.ts +71 -0
- package/src/quickInsert/quickInsertPositionCommand.ts +68 -0
- package/src/quickInsert/quickInsertView.ts +64 -0
- package/theme/menu.css +131 -0
|
@@ -0,0 +1,47 @@
|
|
|
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: what the quick insert menu does, when an element is chosen. The
|
|
5
|
+
* menu itself is opened by the `ElementQuickInsert` plugin, with its `open()`.
|
|
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', undefined, 'softBreak'); // Inserts a line break 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: Editor);
|
|
23
|
+
/**
|
|
24
|
+
* Returns the names of the model elements allowed at exactly the position (or the selection), in the order they
|
|
25
|
+
* were registered. Generic items (such as `$text` or `$block`) and the excluded names are skipped.
|
|
26
|
+
*/
|
|
27
|
+
getAllowedElements(elementOrPosition?: ElementOrPosition, exclude?: readonly string[]): string[];
|
|
28
|
+
/**
|
|
29
|
+
* Whether an element is allowed at exactly the position (or the selection), as {@link getAllowedElements} returns
|
|
30
|
+
* them: it stops at the first one.
|
|
31
|
+
*/
|
|
32
|
+
hasAllowedElements(elementOrPosition?: ElementOrPosition, exclude?: readonly string[]): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Returns the position where elements are inserted for the target: the position, the position before the element,
|
|
35
|
+
* or the selection.
|
|
36
|
+
*/
|
|
37
|
+
getInsertPosition(elementOrPosition?: ElementOrPosition): ModelPosition | null;
|
|
38
|
+
/**
|
|
39
|
+
* Inserts the element named `name` at the target, when the schema allows it there.
|
|
40
|
+
*/
|
|
41
|
+
execute(elementOrPosition: ElementOrPosition | undefined, name: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* Yields the names of the elements allowed at exactly the position (or the selection), one by one.
|
|
44
|
+
*/
|
|
45
|
+
private _getAllowedElements;
|
|
46
|
+
}
|
|
47
|
+
//# 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;;;;;;;;;;;;;;;;;GAiBG;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;IAI3G;;;OAGG;IACI,kBAAkB,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,EAAE,OAAO,GAAE,SAAS,MAAM,EAAO,GAAG,OAAO;IAI1G;;;OAGG;IACI,iBAAiB,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,aAAa,GAAG,IAAI;IAIrF;;OAEG;IACa,OAAO,CAAC,iBAAiB,EAAE,iBAAiB,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAgB7F;;OAEG;IACH,OAAO,CAAE,mBAAmB;CAmB5B"}
|
|
@@ -0,0 +1,81 @@
|
|
|
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: what the quick insert menu does, when an element is chosen. The
|
|
6
|
+
* menu itself is opened by the `ElementQuickInsert` plugin, with its `open()`.
|
|
7
|
+
*
|
|
8
|
+
* The target comes first, as in every {@link ElementOrPositionCommand}: a position, an element (meaning the position
|
|
9
|
+
* before it), or none (the selection).
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* editor.execute('quickInsert', position, 'heading1'); // Inserts a heading at the position.
|
|
13
|
+
* editor.execute('quickInsert', undefined, 'softBreak'); // Inserts a line break at the selection.
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Only elements that the schema allows at exactly that position are inserted (see {@link getAllowedElements}):
|
|
17
|
+
* nothing is split to make room, so e.g. a heading cannot be inserted inside a paragraph.
|
|
18
|
+
*
|
|
19
|
+
* After inserting, objects are selected; other elements get the selection inside them, in a new paragraph when they
|
|
20
|
+
* can hold blocks.
|
|
21
|
+
*/
|
|
22
|
+
export default class QuickInsertCommand extends ElementOrPositionCommand {
|
|
23
|
+
constructor(editor) {
|
|
24
|
+
super(editor);
|
|
25
|
+
this.title = editor.t('Insert element');
|
|
26
|
+
this.icon = insertIcon;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns the names of the model elements allowed at exactly the position (or the selection), in the order they
|
|
30
|
+
* were registered. Generic items (such as `$text` or `$block`) and the excluded names are skipped.
|
|
31
|
+
*/
|
|
32
|
+
getAllowedElements(elementOrPosition, exclude = []) {
|
|
33
|
+
return Array.from(this._getAllowedElements(elementOrPosition, exclude));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Whether an element is allowed at exactly the position (or the selection), as {@link getAllowedElements} returns
|
|
37
|
+
* them: it stops at the first one.
|
|
38
|
+
*/
|
|
39
|
+
hasAllowedElements(elementOrPosition, exclude = []) {
|
|
40
|
+
return !this._getAllowedElements(elementOrPosition, exclude).next().done;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Returns the position where elements are inserted for the target: the position, the position before the element,
|
|
44
|
+
* or the selection.
|
|
45
|
+
*/
|
|
46
|
+
getInsertPosition(elementOrPosition) {
|
|
47
|
+
return this._getPosition(elementOrPosition);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Inserts the element named `name` at the target, when the schema allows it there.
|
|
51
|
+
*/
|
|
52
|
+
execute(elementOrPosition, name) {
|
|
53
|
+
const model = this.editor.model;
|
|
54
|
+
const target = this._getPosition(elementOrPosition);
|
|
55
|
+
if (!target || !model.canEditAt(target) || !model.schema.checkChild(target, name)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
model.change(writer => {
|
|
59
|
+
const element = writer.createElement(name);
|
|
60
|
+
writer.insert(element, target);
|
|
61
|
+
selectNewElement(writer, element);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Yields the names of the elements allowed at exactly the position (or the selection), one by one.
|
|
66
|
+
*/
|
|
67
|
+
*_getAllowedElements(elementOrPosition, exclude) {
|
|
68
|
+
const target = this._getPosition(elementOrPosition);
|
|
69
|
+
if (!target) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const schema = this.editor.model.schema;
|
|
73
|
+
const excluded = new Set(exclude);
|
|
74
|
+
for (const name of Object.keys(schema.getDefinitions())) {
|
|
75
|
+
if (!name.startsWith('$') && !excluded.has(name) && schema.checkChild(target, name)) {
|
|
76
|
+
yield name;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# 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;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,wBAAwB;IACvE,YAAY,MAAc;QACzB,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACxB,CAAC;IAED;;;OAGG;IACI,kBAAkB,CAAC,iBAAqC,EAAE,UAA6B,EAAE;QAC/F,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC,CAAC;IACzE,CAAC;IAED;;;OAGG;IACI,kBAAkB,CAAC,iBAAqC,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AAC,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,EAAE,CAAC;YACzD,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC;gBACrF,MAAM,IAAI,CAAC;YACZ,CAAC;QACF,CAAC;IACF,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"}
|
|
@@ -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,C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ementOrPosition } from 'ckeditor5-elements-core';
|
|
3
|
+
import type ElementQuickInsert from './elementQuickInsert.js';
|
|
4
|
+
/**
|
|
5
|
+
* Where the quick insert menu inserts, relative to the element.
|
|
6
|
+
*/
|
|
7
|
+
export type QuickInsertPlacement = 'before' | 'after';
|
|
8
|
+
/**
|
|
9
|
+
* Opens the quick insert menu for the position before or after an element, next to that element.
|
|
10
|
+
*
|
|
11
|
+
* The element is the given one, the parent of the given position, or the selected element or the parent of the
|
|
12
|
+
* selection (see {@link ElementOrPositionCommand}). Enabled when something can be inserted at that position.
|
|
13
|
+
*
|
|
14
|
+
* The `ElementQuickInsert` plugin registers it as `quickInsertBefore` and `quickInsertAfter`, for its menu.
|
|
15
|
+
*/
|
|
16
|
+
export default class QuickInsertPositionCommand extends ElementOrPositionCommand {
|
|
17
|
+
/**
|
|
18
|
+
* Where the quick insert menu inserts, relative to the element.
|
|
19
|
+
*/
|
|
20
|
+
readonly placement: QuickInsertPlacement;
|
|
21
|
+
/**
|
|
22
|
+
* The plugin whose menu the command opens.
|
|
23
|
+
*/
|
|
24
|
+
private readonly _quickInsert;
|
|
25
|
+
constructor(editor: Editor, placement: QuickInsertPlacement, quickInsert: ElementQuickInsert);
|
|
26
|
+
/**
|
|
27
|
+
* Opens the quick insert menu for the position before or after the element, next to the element.
|
|
28
|
+
*/
|
|
29
|
+
execute(elementOrPosition?: ElementOrPosition): void;
|
|
30
|
+
protected _isEnabledFor(elementOrPosition?: ElementOrPosition): boolean;
|
|
31
|
+
private _getInsertPosition;
|
|
32
|
+
}
|
|
33
|
+
//# 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;AAE3F,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAC;AAG9D;;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;IAEhD;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAqB;gBAEtC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,oBAAoB,EAAE,WAAW,EAAE,kBAAkB;IAS5F;;OAEG;IACa,OAAO,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,IAAI;cASjD,aAAa,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,OAAO;IAMhF,OAAO,CAAC,kBAAkB;CAU1B"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {} from 'ckeditor5';
|
|
2
|
+
import { ElementOrPositionCommand } from 'ckeditor5-elements-core';
|
|
3
|
+
import { getDomTarget } from '../domTarget.js';
|
|
4
|
+
import { insertAfterIcon, insertBeforeIcon } from './icons.js';
|
|
5
|
+
/**
|
|
6
|
+
* Opens the quick insert menu for the position before or after an element, next to that element.
|
|
7
|
+
*
|
|
8
|
+
* The element is the given one, the parent of the given position, or the selected element or the parent of the
|
|
9
|
+
* selection (see {@link ElementOrPositionCommand}). Enabled when something can be inserted at that position.
|
|
10
|
+
*
|
|
11
|
+
* The `ElementQuickInsert` plugin registers it as `quickInsertBefore` and `quickInsertAfter`, for its menu.
|
|
12
|
+
*/
|
|
13
|
+
export default class QuickInsertPositionCommand extends ElementOrPositionCommand {
|
|
14
|
+
/**
|
|
15
|
+
* Where the quick insert menu inserts, relative to the element.
|
|
16
|
+
*/
|
|
17
|
+
placement;
|
|
18
|
+
/**
|
|
19
|
+
* The plugin whose menu the command opens.
|
|
20
|
+
*/
|
|
21
|
+
_quickInsert;
|
|
22
|
+
constructor(editor, placement, quickInsert) {
|
|
23
|
+
super(editor);
|
|
24
|
+
this.placement = placement;
|
|
25
|
+
this._quickInsert = quickInsert;
|
|
26
|
+
this.title = placement === 'before' ? editor.t('Insert before') : editor.t('Insert after');
|
|
27
|
+
this.icon = placement === 'before' ? insertBeforeIcon : insertAfterIcon;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Opens the quick insert menu for the position before or after the element, next to the element.
|
|
31
|
+
*/
|
|
32
|
+
execute(elementOrPosition) {
|
|
33
|
+
const element = this._getElement(elementOrPosition);
|
|
34
|
+
const position = this._getInsertPosition(elementOrPosition);
|
|
35
|
+
if (element && position) {
|
|
36
|
+
this._quickInsert.open(position, getDomTarget(this.editor, element) ?? undefined);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
_isEnabledFor(elementOrPosition) {
|
|
40
|
+
const position = this._getInsertPosition(elementOrPosition);
|
|
41
|
+
return !!position && this.editor.model.canEditAt(position) && this._quickInsert.hasItems(position);
|
|
42
|
+
}
|
|
43
|
+
_getInsertPosition(elementOrPosition) {
|
|
44
|
+
const element = this._getElement(elementOrPosition);
|
|
45
|
+
const model = this.editor.model;
|
|
46
|
+
if (!element) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
return this.placement === 'before' ? model.createPositionBefore(element) : model.createPositionAfter(element);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# 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,YAAY,EAAE,MAAM,iBAAiB,CAAC;A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AAI,CAAC,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACpG,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,iBAAi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|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "49.0.0",
|
|
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"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"ckeditor5-elements-actions": "49.0.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"ckeditor5": "^49.0.0"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "tsc --build"
|
|
54
|
+
}
|
|
6
55
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ElementBreadcrumbs,
|
|
3
|
+
ElementBreadcrumbsConfig,
|
|
4
|
+
ElementContextMenu,
|
|
5
|
+
ElementMenu,
|
|
6
|
+
ElementMenuConfig,
|
|
7
|
+
ElementQuickInsert,
|
|
8
|
+
QuickInsertCommand,
|
|
9
|
+
ElementQuickInsertConfig,
|
|
10
|
+
QuickInsertPositionCommand
|
|
11
|
+
} from './index.js';
|
|
12
|
+
|
|
13
|
+
declare module 'ckeditor5' {
|
|
14
|
+
interface PluginsMap {
|
|
15
|
+
[ElementMenu.pluginName]: ElementMenu;
|
|
16
|
+
[ElementContextMenu.pluginName]: ElementContextMenu;
|
|
17
|
+
[ElementBreadcrumbs.pluginName]: ElementBreadcrumbs;
|
|
18
|
+
[ElementQuickInsert.pluginName]: ElementQuickInsert;
|
|
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 ElementBreadcrumbs} plugin.
|
|
36
|
+
*/
|
|
37
|
+
elementBreadcrumbs?: ElementBreadcrumbsConfig;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The configuration of the {@link ElementQuickInsert} plugin.
|
|
41
|
+
*/
|
|
42
|
+
elementQuickInsert?: ElementQuickInsertConfig;
|
|
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
|
+
}
|