ckeditor5-elements-breadcrumbs 0.0.0-stage → 49.0.0-alpha.2

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.
@@ -0,0 +1,68 @@
1
+ import { KeystrokeHandler, View, ViewCollection, type Locale } from 'ckeditor5';
2
+ import BreadcrumbItemView, { type BreadcrumbItem } from './breadcrumbItemView.js';
3
+ import BreadcrumbLabelView from './breadcrumbLabelView.js';
4
+ /**
5
+ * The options of {@link BreadcrumbsView}.
6
+ */
7
+ export interface BreadcrumbsViewOptions {
8
+ /**
9
+ * Whether the items are buttons that can be clicked, or labels. Defaults to `false`.
10
+ */
11
+ isClickable?: boolean;
12
+ }
13
+ /**
14
+ * Shows a path of elements, from the outermost to the innermost one, as a list (`<ol>`) in a `<nav>` landmark: buttons
15
+ * when the items can be clicked, labels otherwise. Items without a model element (list items) are labels too. The
16
+ * innermost item is marked with `aria-current="location"`.
17
+ *
18
+ * The left and right arrows move the focus between the items; past the first or the last one, they are left to the
19
+ * toolbar the view is in. Fires `execute` with the item when one of the buttons is clicked.
20
+ */
21
+ export default class BreadcrumbsView extends View {
22
+ /**
23
+ * The breadcrumb items: the buttons or labels, from the outermost to the innermost one.
24
+ */
25
+ readonly items: ViewCollection<BreadcrumbItemView | BreadcrumbLabelView>;
26
+ /**
27
+ * Whether the items are buttons that can be clicked, or labels.
28
+ */
29
+ readonly isClickable: boolean;
30
+ /**
31
+ * Handles the keystrokes within the breadcrumbs.
32
+ */
33
+ readonly keystrokes: KeystrokeHandler;
34
+ /**
35
+ * The list items (`<li>`) that hold the {@link items}.
36
+ */
37
+ private readonly _listItems;
38
+ constructor(locale?: Locale, { isClickable }?: BreadcrumbsViewOptions);
39
+ /**
40
+ * Replaces the items.
41
+ */
42
+ setItems(items: readonly BreadcrumbItem[]): void;
43
+ /**
44
+ * Renders the view and starts handling the keystrokes.
45
+ */
46
+ render(): void;
47
+ /**
48
+ * Focuses an item: the first one when the focus moves forward (`1`, e.g. from the previous toolbar item), the
49
+ * innermost one otherwise.
50
+ */
51
+ focus(direction?: 1 | -1): void;
52
+ /**
53
+ * Destroys the view and its keystroke handler.
54
+ */
55
+ destroy(): void;
56
+ /**
57
+ * Focuses the item before (`-1`) or after (`1`) the focused one. Returns `false` when there is none.
58
+ */
59
+ private _focusSibling;
60
+ }
61
+ /**
62
+ * Fired by {@link BreadcrumbsView} when one of its buttons is clicked.
63
+ */
64
+ export interface BreadcrumbsViewExecuteEvent {
65
+ name: 'execute';
66
+ args: [item: BreadcrumbItemView];
67
+ }
68
+ //# sourceMappingURL=breadcrumbsView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"breadcrumbsView.d.ts","sourceRoot":"","sources":["../src/breadcrumbsView.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,kBAAkB,EAAE,EAAE,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACtC;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,IAAI;IAChD;;OAEG;IACH,SAAgB,KAAK,2DAAkE;IAEvF;;OAEG;IACH,SAAgB,WAAW,EAAE,OAAO,CAAC;IAErC;;OAEG;IACH,SAAgB,UAAU,mBAA0B;IAEpD;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA0C;gBAEzD,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,WAAmB,EAAE,GAAE,sBAA2B;IAsCjF;;OAEG;IACI,QAAQ,CAAC,KAAK,EAAE,SAAS,cAAc,EAAE,GAAG,IAAI;IA0BvD;;OAEG;IACa,MAAM,IAAI,IAAI;IAQ9B;;;OAGG;IACI,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI;IAItC;;OAEG;IACa,OAAO,IAAI,IAAI;IAK/B;;OAEG;IACH,OAAO,CAAC,aAAa;CASrB;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC3C,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;CACjC"}
@@ -0,0 +1,134 @@
1
+ import { KeystrokeHandler, View, ViewCollection } from 'ckeditor5';
2
+ import BreadcrumbItemView, {} from './breadcrumbItemView.js';
3
+ import BreadcrumbLabelView from './breadcrumbLabelView.js';
4
+ /**
5
+ * Shows a path of elements, from the outermost to the innermost one, as a list (`<ol>`) in a `<nav>` landmark: buttons
6
+ * when the items can be clicked, labels otherwise. Items without a model element (list items) are labels too. The
7
+ * innermost item is marked with `aria-current="location"`.
8
+ *
9
+ * The left and right arrows move the focus between the items; past the first or the last one, they are left to the
10
+ * toolbar the view is in. Fires `execute` with the item when one of the buttons is clicked.
11
+ */
12
+ export default class BreadcrumbsView extends View {
13
+ /**
14
+ * The breadcrumb items: the buttons or labels, from the outermost to the innermost one.
15
+ */
16
+ items = new ViewCollection();
17
+ /**
18
+ * Whether the items are buttons that can be clicked, or labels.
19
+ */
20
+ isClickable;
21
+ /**
22
+ * Handles the keystrokes within the breadcrumbs.
23
+ */
24
+ keystrokes = new KeystrokeHandler();
25
+ /**
26
+ * The list items (`<li>`) that hold the {@link items}.
27
+ */
28
+ _listItems;
29
+ constructor(locale, { isClickable = false } = {}) {
30
+ super(locale);
31
+ this._listItems = this.createCollection();
32
+ this.isClickable = isClickable;
33
+ const isRtl = locale?.uiLanguageDirection === 'rtl';
34
+ this.keystrokes.set(isRtl ? 'arrowright' : 'arrowleft', (data, cancel) => {
35
+ if (this._focusSibling(-1)) {
36
+ cancel();
37
+ }
38
+ });
39
+ this.keystrokes.set(isRtl ? 'arrowleft' : 'arrowright', (data, cancel) => {
40
+ if (this._focusSibling(1)) {
41
+ cancel();
42
+ }
43
+ });
44
+ this.setTemplate({
45
+ tag: 'nav',
46
+ attributes: {
47
+ class: ['ck', 'ck-elements-breadcrumbs'],
48
+ 'aria-label': locale?.t('Element path') ?? 'Element path'
49
+ },
50
+ children: [
51
+ {
52
+ tag: 'ol',
53
+ attributes: {
54
+ class: ['ck', 'ck-elements-breadcrumbs__list']
55
+ },
56
+ children: this._listItems
57
+ }
58
+ ]
59
+ });
60
+ }
61
+ /**
62
+ * Replaces the items.
63
+ */
64
+ setItems(items) {
65
+ for (const listItem of this._listItems) {
66
+ listItem.destroy();
67
+ }
68
+ this._listItems.clear();
69
+ this.items.clear();
70
+ items.forEach((item, index) => {
71
+ const isCurrent = index === items.length - 1;
72
+ const view = this.isClickable && item.modelElement
73
+ ? new BreadcrumbItemView(this.locale, item, { isCurrent })
74
+ : new BreadcrumbLabelView(this.locale, item, { isCurrent });
75
+ if (view instanceof BreadcrumbItemView) {
76
+ view.on('execute', () => {
77
+ this.fire('execute', view);
78
+ });
79
+ }
80
+ this.items.add(view);
81
+ this._listItems.add(new BreadcrumbsListItemView(this.locale, view));
82
+ });
83
+ }
84
+ /**
85
+ * Renders the view and starts handling the keystrokes.
86
+ */
87
+ render() {
88
+ super.render();
89
+ if (this.element) {
90
+ this.keystrokes.listenTo(this.element);
91
+ }
92
+ }
93
+ /**
94
+ * Focuses an item: the first one when the focus moves forward (`1`, e.g. from the previous toolbar item), the
95
+ * innermost one otherwise.
96
+ */
97
+ focus(direction) {
98
+ (direction === 1 ? this.items.first : this.items.last)?.focus();
99
+ }
100
+ /**
101
+ * Destroys the view and its keystroke handler.
102
+ */
103
+ destroy() {
104
+ super.destroy();
105
+ this.keystrokes.destroy();
106
+ }
107
+ /**
108
+ * Focuses the item before (`-1`) or after (`1`) the focused one. Returns `false` when there is none.
109
+ */
110
+ _focusSibling(step) {
111
+ const items = Array.from(this.items);
112
+ const index = items.findIndex(item => item.element === document.activeElement);
113
+ const sibling = index === -1 ? undefined : items[index + step];
114
+ sibling?.focus();
115
+ return !!sibling;
116
+ }
117
+ }
118
+ /**
119
+ * A list item (`<li>`) of the breadcrumbs, holding a button or a label.
120
+ */
121
+ class BreadcrumbsListItemView extends View {
122
+ constructor(locale, item) {
123
+ super(locale);
124
+ // Rendering registers the item as a child, so it is destroyed with the list item.
125
+ this.setTemplate({
126
+ tag: 'li',
127
+ attributes: {
128
+ class: ['ck', 'ck-elements-breadcrumbs__list-item']
129
+ },
130
+ children: [item]
131
+ });
132
+ }
133
+ }
134
+ //# sourceMappingURL=breadcrumbsView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"breadcrumbsView.js","sourceRoot":"","sources":["../src/breadcrumbsView.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,cAAc,EAAe,MAAM,WAAW,CAAC;AAChF,OAAO,kBAAkB,EAAE,EAAuB,MAAM,yBAAyB,CAAC;AAClF,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;AAY3D;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,IAAI;IAChD;;OAEG;IACa,KAAK,GAAG,IAAI,cAAc,EAA4C,CAAC;IAEvF;;OAEG;IACa,WAAW,CAAU;IAErC;;OAEG;IACa,UAAU,GAAG,IAAI,gBAAgB,EAAE,CAAC;IAEpD;;OAEG;IACc,UAAU,CAA0C;IAErE,YAAY,MAAe,EAAE,EAAE,WAAW,GAAG,KAAK,KAA6B,EAAE;QAChF,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC1C,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAE/B,MAAM,KAAK,GAAG,MAAM,EAAE,mBAAmB,KAAK,KAAK,CAAC;QAEpD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC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OAEG;IACK,aAAa,CAAC,IAAY;QACjC,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrC,MAAM,KAAK,GAAG,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,KAAK,QAAQ,CAAC,aAAa,CAAC,CAAC;QAC/E,MAAM,OAAO,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;QAE/D,OAAO,EAAE,KAAK,EAAE,CAAC;QAEjB,OAAO,CAAC,CAAC,OAAO,CAAC;IAClB,CAAC;CACD;AAUD;;GAEG;AACH,MAAM,uBAAwB,SAAQ,IAAI;IACzC,YAAY,MAA0B,EAAE,IAA8C;QACrF,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,kFAAkF;QAClF,IAAI,CAAC,WAAW,CAAC;YAChB,GAAG,EAAE,IAAI;YACT,UAAU,EAAE;gBACX,KAAK,EAAE,CAAC,IAAI,EAAE,oCAAoC,CAAC;aACnD;YACD,QAAQ,EAAE,CAAC,IAAI,CAAC;SAChB,CAAC,CAAC;IACJ,CAAC;CACD"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Breadcrumbs: the element path at the selection, optionally clickable with a configured menu.
3
+ *
4
+ * @module ckeditor5-elements-breadcrumbs
5
+ */
6
+ export { default as Breadcrumbs, type BreadcrumbsConfig, type BreadcrumbsMenu, type BreadcrumbsMenuItems, type BreadcrumbsMenuOptions } from './breadcrumbs.js';
7
+ export { default as BreadcrumbsView, type BreadcrumbsViewExecuteEvent, type BreadcrumbsViewOptions } from './breadcrumbsView.js';
8
+ export { default as BreadcrumbItemView, type BreadcrumbItem, type BreadcrumbItemViewOptions } from './breadcrumbItemView.js';
9
+ export { default as BreadcrumbLabelView } from './breadcrumbLabelView.js';
10
+ import './augmentation.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACN,OAAO,IAAI,WAAW,EACtB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACN,OAAO,IAAI,eAAe,EAC1B,KAAK,2BAA2B,EAChC,KAAK,sBAAsB,EAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,OAAO,IAAI,kBAAkB,EAC7B,KAAK,cAAc,EACnB,KAAK,yBAAyB,EAC9B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE1E,OAAO,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Breadcrumbs: the element path at the selection, optionally clickable with a configured menu.
3
+ *
4
+ * @module ckeditor5-elements-breadcrumbs
5
+ */
6
+ // Plugins.
7
+ export { default as Breadcrumbs } from './breadcrumbs.js';
8
+ // Views.
9
+ export { default as BreadcrumbsView } from './breadcrumbsView.js';
10
+ export { default as BreadcrumbItemView } from './breadcrumbItemView.js';
11
+ export { default as BreadcrumbLabelView } from './breadcrumbLabelView.js';
12
+ import './augmentation.js';
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,WAAW;AACX,OAAO,EACN,OAAO,IAAI,WAAW,EAKtB,MAAM,kBAAkB,CAAC;AAE1B,SAAS;AACT,OAAO,EACN,OAAO,IAAI,eAAe,EAG1B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,OAAO,IAAI,kBAAkB,EAG7B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE1E,OAAO,mBAAmB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "ckeditor5-elements-breadcrumbs",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "49.0.0-alpha.2",
4
+ "description": "Breadcrumbs for CKEditor 5: the element path at the selection, as a toolbar component.",
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/breadcrumbs",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/ivankild/ckeditor5-elements.git",
18
+ "directory": "packages/ckeditor5-elements-breadcrumbs"
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/breadcrumbs.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.2"
45
+ },
46
+ "peerDependencies": {
47
+ "ckeditor5": "^49.0.0"
48
+ },
49
+ "scripts": {
50
+ "build": "tsc --build"
51
+ }
6
52
  }
@@ -0,0 +1,14 @@
1
+ import type { Breadcrumbs, BreadcrumbsConfig } from './index.js';
2
+
3
+ declare module 'ckeditor5' {
4
+ interface PluginsMap {
5
+ [Breadcrumbs.pluginName]: Breadcrumbs;
6
+ }
7
+
8
+ interface EditorConfig {
9
+ /**
10
+ * The configuration of the {@link Breadcrumbs} plugin.
11
+ */
12
+ breadcrumbs?: BreadcrumbsConfig;
13
+ }
14
+ }
@@ -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
+ }