igniteui-webcomponents 3.1.0 → 3.2.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/CHANGELOG.md +16 -0
- package/README.md +6 -1
- package/components/button/button-base.d.ts +5 -0
- package/components/button/button-base.js +4 -0
- package/components/button/button-base.js.map +1 -1
- package/components/button/icon-button.js +10 -8
- package/components/button/icon-button.js.map +1 -1
- package/components/button/themes/button/light/button.base.css.js +1 -1
- package/components/button/themes/button/light/button.base.css.js.map +1 -1
- package/components/button/themes/button/light/button.material.css.js +1 -1
- package/components/button/themes/button/light/button.material.css.js.map +1 -1
- package/components/button/themes/icon-button/light/icon-button.base.css.js +1 -1
- package/components/button/themes/icon-button/light/icon-button.base.css.js.map +1 -1
- package/components/button/themes/icon-button/light/icon-button.bootstrap.css.js +1 -1
- package/components/button/themes/icon-button/light/icon-button.bootstrap.css.js.map +1 -1
- package/components/button/themes/icon-button/light/icon-button.fluent.css.js +1 -1
- package/components/button/themes/icon-button/light/icon-button.fluent.css.js.map +1 -1
- package/components/button/themes/icon-button/light/icon-button.indigo.css.js +1 -1
- package/components/button/themes/icon-button/light/icon-button.indigo.css.js.map +1 -1
- package/components/button/themes/icon-button/light/icon-button.material.css.js +1 -1
- package/components/button/themes/icon-button/light/icon-button.material.css.js.map +1 -1
- package/components/calendar/common/calendar-base.js +16 -12
- package/components/calendar/common/calendar-base.js.map +1 -1
- package/components/checkbox/themes/light/switch.base.css.js +1 -1
- package/components/checkbox/themes/light/switch.base.css.js.map +1 -1
- package/components/common/definitions/defineAllComponents.js +8 -0
- package/components/common/definitions/defineAllComponents.js.map +1 -1
- package/components/expansion-panel/expansion-panel.d.ts +72 -0
- package/components/expansion-panel/expansion-panel.js +167 -0
- package/components/expansion-panel/expansion-panel.js.map +1 -0
- package/components/expansion-panel/themes/light/expansion-panel.base.css.d.ts +1 -0
- package/components/expansion-panel/themes/light/expansion-panel.base.css.js +3 -0
- package/components/expansion-panel/themes/light/expansion-panel.base.css.js.map +1 -0
- package/components/expansion-panel/themes/light/expansion-panel.bootstrap.css.d.ts +1 -0
- package/components/expansion-panel/themes/light/expansion-panel.bootstrap.css.js +3 -0
- package/components/expansion-panel/themes/light/expansion-panel.bootstrap.css.js.map +1 -0
- package/components/expansion-panel/themes/light/expansion-panel.fluent.css.d.ts +1 -0
- package/components/expansion-panel/themes/light/expansion-panel.fluent.css.js +3 -0
- package/components/expansion-panel/themes/light/expansion-panel.fluent.css.js.map +1 -0
- package/components/expansion-panel/themes/light/expansion-panel.indigo.css.d.ts +1 -0
- package/components/expansion-panel/themes/light/expansion-panel.indigo.css.js +3 -0
- package/components/expansion-panel/themes/light/expansion-panel.indigo.css.js.map +1 -0
- package/components/form/form.js +10 -2
- package/components/form/form.js.map +1 -1
- package/components/icon/icon.registry.js +3 -0
- package/components/icon/icon.registry.js.map +1 -1
- package/components/input/themes/light/input.base.css.js +1 -1
- package/components/input/themes/light/input.base.css.js.map +1 -1
- package/components/list/themes/light/list.base.css.js +1 -1
- package/components/list/themes/light/list.base.css.js.map +1 -1
- package/components/mask-input/mask-input.d.ts +102 -0
- package/components/mask-input/mask-input.js +260 -0
- package/components/mask-input/mask-input.js.map +1 -0
- package/components/mask-input/mask-parser.d.ts +30 -0
- package/components/mask-input/mask-parser.js +167 -0
- package/components/mask-input/mask-parser.js.map +1 -0
- package/components/nav-drawer/nav-drawer-item.d.ts +1 -0
- package/components/nav-drawer/nav-drawer-item.js +5 -2
- package/components/nav-drawer/nav-drawer-item.js.map +1 -1
- package/components/nav-drawer/styles/indigo/nav-drawer-item.indigo.css.js +1 -1
- package/components/nav-drawer/styles/indigo/nav-drawer-item.indigo.css.js.map +1 -1
- package/components/nav-drawer/styles/nav-drawer-item.base.css.js +1 -1
- package/components/nav-drawer/styles/nav-drawer-item.base.css.js.map +1 -1
- package/components/nav-drawer/styles/nav-drawer.base.css.js +1 -1
- package/components/nav-drawer/styles/nav-drawer.base.css.js.map +1 -1
- package/components/navbar/navbar.js +2 -1
- package/components/navbar/navbar.js.map +1 -1
- package/components/navbar/themes/light/navbar.base.css.js +1 -1
- package/components/navbar/themes/light/navbar.base.css.js.map +1 -1
- package/components/navbar/themes/light/navbar.bootstrap.css.js +1 -1
- package/components/navbar/themes/light/navbar.bootstrap.css.js.map +1 -1
- package/components/navbar/themes/light/navbar.fluent.css.d.ts +1 -0
- package/components/navbar/themes/light/navbar.fluent.css.js +3 -0
- package/components/navbar/themes/light/navbar.fluent.css.js.map +1 -0
- package/components/rating/rating.base.css.js +1 -1
- package/components/rating/rating.base.css.js.map +1 -1
- package/components/rating/rating.fluent.css.js +1 -1
- package/components/rating/rating.fluent.css.js.map +1 -1
- package/components/rating/rating.js +1 -1
- package/components/rating/rating.js.map +1 -1
- package/components/toggle/toggle.directive.js +5 -4
- package/components/toggle/toggle.directive.js.map +1 -1
- package/components/tree/themes/dark/tree-item.bootstrap.css.d.ts +1 -0
- package/components/tree/themes/dark/tree-item.bootstrap.css.js +3 -0
- package/components/tree/themes/dark/tree-item.bootstrap.css.js.map +1 -0
- package/components/tree/themes/dark/tree-item.fluent.css.d.ts +1 -0
- package/components/tree/themes/dark/tree-item.fluent.css.js +3 -0
- package/components/tree/themes/dark/tree-item.fluent.css.js.map +1 -0
- package/components/tree/themes/dark/tree-item.indigo.css.d.ts +1 -0
- package/components/tree/themes/dark/tree-item.indigo.css.js +3 -0
- package/components/tree/themes/dark/tree-item.indigo.css.js.map +1 -0
- package/components/tree/themes/light/tree-item.base.css.d.ts +1 -0
- package/components/tree/themes/light/tree-item.base.css.js +3 -0
- package/components/tree/themes/light/tree-item.base.css.js.map +1 -0
- package/components/tree/themes/light/tree-item.bootstrap.css.d.ts +1 -0
- package/components/tree/themes/light/tree-item.bootstrap.css.js +3 -0
- package/components/tree/themes/light/tree-item.bootstrap.css.js.map +1 -0
- package/components/tree/themes/light/tree-item.fluent.css.d.ts +1 -0
- package/components/tree/themes/light/tree-item.fluent.css.js +3 -0
- package/components/tree/themes/light/tree-item.fluent.css.js.map +1 -0
- package/components/tree/themes/light/tree-item.indigo.css.d.ts +1 -0
- package/components/tree/themes/light/tree-item.indigo.css.js +3 -0
- package/components/tree/themes/light/tree-item.indigo.css.js.map +1 -0
- package/components/tree/themes/light/tree.base.css.d.ts +1 -0
- package/components/tree/themes/light/tree.base.css.js +3 -0
- package/components/tree/themes/light/tree.base.css.js.map +1 -0
- package/components/tree/tree-item.d.ts +116 -0
- package/components/tree/tree-item.js +447 -0
- package/components/tree/tree-item.js.map +1 -0
- package/components/tree/tree.common.d.ts +17 -0
- package/components/tree/tree.common.js +2 -0
- package/components/tree/tree.common.js.map +1 -0
- package/components/tree/tree.d.ts +71 -0
- package/components/tree/tree.js +139 -0
- package/components/tree/tree.js.map +1 -0
- package/components/tree/tree.navigation.d.ts +41 -0
- package/components/tree/tree.navigation.js +260 -0
- package/components/tree/tree.navigation.js.map +1 -0
- package/components/tree/tree.selection.d.ts +55 -0
- package/components/tree/tree.selection.js +265 -0
- package/components/tree/tree.selection.js.map +1 -0
- package/custom-elements.json +632 -2
- package/index.d.ts +4 -0
- package/index.js +4 -0
- package/index.js.map +1 -1
- package/package.json +2 -2
- package/themes/dark/bootstrap.css +1 -1
- package/themes/dark/fluent.css +1 -1
- package/themes/dark/indigo.css +1 -1
- package/themes/light/bootstrap.css +1 -1
- package/themes/light/fluent.css +1 -1
- package/vscode-html-custom-data.json +313 -45
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type IgcTreeItemComponent from './tree-item.js';
|
|
2
|
+
export interface IgcTreeEventMap {
|
|
3
|
+
igcSelection: CustomEvent<{
|
|
4
|
+
newSelection: IgcTreeItemComponent[];
|
|
5
|
+
}>;
|
|
6
|
+
igcItemExpanding: CustomEvent<IgcTreeItemComponent>;
|
|
7
|
+
igcItemExpanded: CustomEvent<IgcTreeItemComponent>;
|
|
8
|
+
igcItemCollapsing: CustomEvent<IgcTreeItemComponent>;
|
|
9
|
+
igcItemCollapsed: CustomEvent<IgcTreeItemComponent>;
|
|
10
|
+
igcActiveItem: CustomEvent<IgcTreeItemComponent>;
|
|
11
|
+
}
|
|
12
|
+
export interface IgcSelectionEventArgs {
|
|
13
|
+
detail: {
|
|
14
|
+
readonly newSelection: IgcTreeItemComponent[];
|
|
15
|
+
};
|
|
16
|
+
cancelable: boolean;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.common.js","sourceRoot":"","sources":["../../../src/components/tree/tree.common.ts"],"names":[],"mappings":"","sourcesContent":["import type IgcTreeItemComponent from './tree-item.js';\n\nexport interface IgcTreeEventMap {\n igcSelection: CustomEvent<{ newSelection: IgcTreeItemComponent[] }>;\n igcItemExpanding: CustomEvent<IgcTreeItemComponent>;\n igcItemExpanded: CustomEvent<IgcTreeItemComponent>;\n igcItemCollapsing: CustomEvent<IgcTreeItemComponent>;\n igcItemCollapsed: CustomEvent<IgcTreeItemComponent>;\n igcActiveItem: CustomEvent<IgcTreeItemComponent>;\n}\nexport interface IgcSelectionEventArgs {\n detail: { readonly newSelection: IgcTreeItemComponent[] };\n cancelable: boolean;\n}\n"]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import { Constructor } from '../common/mixins/constructor.js';
|
|
3
|
+
import IgcTreeItemComponent from './tree-item.js';
|
|
4
|
+
import { IgcTreeEventMap } from './tree.common.js';
|
|
5
|
+
import { IgcTreeNavigationService } from './tree.navigation.js';
|
|
6
|
+
import { IgcTreeSelectionService } from './tree.selection.js';
|
|
7
|
+
declare type Direction = 'ltr' | 'rtl' | 'auto';
|
|
8
|
+
declare const IgcTreeComponent_base: Constructor<import("../common/mixins/sizable.js").SizableInterface> & Constructor<import("../common/mixins/event-emitter.js").EventEmitterInterface<IgcTreeEventMap>> & Constructor<LitElement>;
|
|
9
|
+
/**
|
|
10
|
+
* The tree allows users to represent hierarchical data in a tree-view structure,
|
|
11
|
+
* maintaining parent-child relationships, as well as to define static tree-view structure without a corresponding data model.
|
|
12
|
+
*
|
|
13
|
+
* @element igc-tree
|
|
14
|
+
*
|
|
15
|
+
* @slot - Renders the tree items inside default slot.
|
|
16
|
+
*
|
|
17
|
+
* @fires igcSelection - Emitted when item selection is changing, before the selection completes.
|
|
18
|
+
* @fires igcItemCollapsed - Emitted when tree item is collapsed.
|
|
19
|
+
* @fires igcItemCollapsing - Emitted when tree item is about to collapse.
|
|
20
|
+
* @fires igcItemExpanded - Emitted when tree item is expanded.
|
|
21
|
+
* @fires igcItemExpanding - Emitted when tree item is about to expand.
|
|
22
|
+
* @fires igcItemActivated - Emitted when the tree's `active` item changes.
|
|
23
|
+
*/
|
|
24
|
+
export default class IgcTreeComponent extends IgcTreeComponent_base {
|
|
25
|
+
/** @private */
|
|
26
|
+
static readonly tagName = "igc-tree";
|
|
27
|
+
/** @private */
|
|
28
|
+
static styles: import("lit").CSSResult;
|
|
29
|
+
/** @private */
|
|
30
|
+
selectionService: IgcTreeSelectionService;
|
|
31
|
+
/** @private */
|
|
32
|
+
navService: IgcTreeNavigationService;
|
|
33
|
+
/** Whether a single or multiple of a parent's child items can be expanded. */
|
|
34
|
+
singleBranchExpand: boolean;
|
|
35
|
+
/** The selection state of the tree. */
|
|
36
|
+
selection: 'none' | 'multiple' | 'cascade';
|
|
37
|
+
/** The direction attribute of the control. */
|
|
38
|
+
dir: Direction;
|
|
39
|
+
protected onDirChange(): void;
|
|
40
|
+
protected onSizeChange(): void;
|
|
41
|
+
protected selectionModeChange(): void;
|
|
42
|
+
protected singleBranchExpandChange(): void;
|
|
43
|
+
constructor();
|
|
44
|
+
connectedCallback(): void;
|
|
45
|
+
/** Returns all of the tree's items. */
|
|
46
|
+
get items(): Array<IgcTreeItemComponent>;
|
|
47
|
+
private handleKeydown;
|
|
48
|
+
/** @private */
|
|
49
|
+
expandToItem(item: IgcTreeItemComponent): void;
|
|
50
|
+
/** Select all items if the items collection is empty. Otherwise, select the items in the items collection. */
|
|
51
|
+
select(items?: IgcTreeItemComponent[]): void;
|
|
52
|
+
/** Deselect all items if the items collection is empty. Otherwise, deselect the items in the items collection. */
|
|
53
|
+
deselect(items?: IgcTreeItemComponent[]): void;
|
|
54
|
+
/**
|
|
55
|
+
* Expands all of the passed items.
|
|
56
|
+
* If no items are passed, expands ALL items.
|
|
57
|
+
*/
|
|
58
|
+
expand(items?: IgcTreeItemComponent[]): void;
|
|
59
|
+
/**
|
|
60
|
+
* Collapses all of the passed items.
|
|
61
|
+
* If no items are passed, collapses ALL items.
|
|
62
|
+
*/
|
|
63
|
+
collapse(items?: IgcTreeItemComponent[]): void;
|
|
64
|
+
protected render(): import("lit-html").TemplateResult<1>;
|
|
65
|
+
}
|
|
66
|
+
declare global {
|
|
67
|
+
interface HTMLElementTagNameMap {
|
|
68
|
+
'igc-tree': IgcTreeComponent;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export {};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { html, LitElement } from 'lit';
|
|
8
|
+
import { property } from 'lit/decorators.js';
|
|
9
|
+
import { watch } from '../common/decorators/watch.js';
|
|
10
|
+
import { styles } from './themes/light/tree.base.css.js';
|
|
11
|
+
import { EventEmitterMixin } from '../common/mixins/event-emitter.js';
|
|
12
|
+
import { SizableMixin } from '../common/mixins/sizable.js';
|
|
13
|
+
import { IgcTreeNavigationService } from './tree.navigation.js';
|
|
14
|
+
import { IgcTreeSelectionService } from './tree.selection.js';
|
|
15
|
+
export default class IgcTreeComponent extends SizableMixin(EventEmitterMixin(LitElement)) {
|
|
16
|
+
constructor() {
|
|
17
|
+
super();
|
|
18
|
+
this.singleBranchExpand = false;
|
|
19
|
+
this.selection = 'none';
|
|
20
|
+
this.dir = 'auto';
|
|
21
|
+
this.selectionService = new IgcTreeSelectionService(this);
|
|
22
|
+
this.navService = new IgcTreeNavigationService(this, this.selectionService);
|
|
23
|
+
}
|
|
24
|
+
onDirChange() {
|
|
25
|
+
var _a;
|
|
26
|
+
(_a = this.items) === null || _a === void 0 ? void 0 : _a.forEach((item) => {
|
|
27
|
+
item.requestUpdate();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
onSizeChange() {
|
|
31
|
+
var _a, _b, _c;
|
|
32
|
+
(_a = this.items) === null || _a === void 0 ? void 0 : _a.forEach((item) => {
|
|
33
|
+
item.requestUpdate();
|
|
34
|
+
});
|
|
35
|
+
(_c = (_b = this.navService.activeItem) === null || _b === void 0 ? void 0 : _b.wrapper) === null || _c === void 0 ? void 0 : _c.scrollIntoView({
|
|
36
|
+
behavior: 'smooth',
|
|
37
|
+
block: 'nearest',
|
|
38
|
+
inline: 'nearest',
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
selectionModeChange() {
|
|
42
|
+
var _a;
|
|
43
|
+
this.selectionService.clearItemsSelection();
|
|
44
|
+
(_a = this.items) === null || _a === void 0 ? void 0 : _a.forEach((item) => {
|
|
45
|
+
item.requestUpdate();
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
singleBranchExpandChange() {
|
|
49
|
+
if (this.singleBranchExpand) {
|
|
50
|
+
if (this.navService.activeItem) {
|
|
51
|
+
const path = this.navService.activeItem.path;
|
|
52
|
+
const remainExpanded = new Set(path.splice(0, path.length - 1));
|
|
53
|
+
this.items.forEach((item) => {
|
|
54
|
+
if (!remainExpanded.has(item)) {
|
|
55
|
+
item.collapseWithEvent();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
this.items.forEach((item) => item.collapseWithEvent());
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
connectedCallback() {
|
|
65
|
+
super.connectedCallback();
|
|
66
|
+
this.setAttribute('role', 'tree');
|
|
67
|
+
this.addEventListener('keydown', this.handleKeydown);
|
|
68
|
+
this.items.forEach((i) => {
|
|
69
|
+
i.init = true;
|
|
70
|
+
});
|
|
71
|
+
const firstNotDisabledItem = this.items.find((i) => !i.disabled);
|
|
72
|
+
if (firstNotDisabledItem) {
|
|
73
|
+
firstNotDisabledItem.tabIndex = 0;
|
|
74
|
+
this.navService.focusItem(firstNotDisabledItem);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
get items() {
|
|
78
|
+
return Array.from(this.querySelectorAll(`igc-tree-item`));
|
|
79
|
+
}
|
|
80
|
+
handleKeydown(event) {
|
|
81
|
+
this.navService.handleKeydown(event);
|
|
82
|
+
}
|
|
83
|
+
expandToItem(item) {
|
|
84
|
+
if (item && item.parent) {
|
|
85
|
+
item.path.forEach((i) => {
|
|
86
|
+
if (i !== item && !i.expanded) {
|
|
87
|
+
i.expanded = true;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
select(items) {
|
|
93
|
+
if (!items) {
|
|
94
|
+
items =
|
|
95
|
+
this.selection === 'cascade'
|
|
96
|
+
? this.items.filter((item) => item.level === 0)
|
|
97
|
+
: this.items;
|
|
98
|
+
}
|
|
99
|
+
this.selectionService.selectItemsWithNoEvent(items);
|
|
100
|
+
}
|
|
101
|
+
deselect(items) {
|
|
102
|
+
this.selectionService.deselectItemsWithNoEvent(items);
|
|
103
|
+
}
|
|
104
|
+
expand(items) {
|
|
105
|
+
items = items || this.items;
|
|
106
|
+
items.forEach((item) => (item.expanded = true));
|
|
107
|
+
}
|
|
108
|
+
collapse(items) {
|
|
109
|
+
items = items || this.items;
|
|
110
|
+
items.forEach((item) => (item.expanded = false));
|
|
111
|
+
}
|
|
112
|
+
render() {
|
|
113
|
+
return html `<slot></slot>`;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
IgcTreeComponent.tagName = 'igc-tree';
|
|
117
|
+
IgcTreeComponent.styles = styles;
|
|
118
|
+
__decorate([
|
|
119
|
+
property({ attribute: 'single-branch-expand', reflect: true, type: Boolean })
|
|
120
|
+
], IgcTreeComponent.prototype, "singleBranchExpand", void 0);
|
|
121
|
+
__decorate([
|
|
122
|
+
property({ reflect: true })
|
|
123
|
+
], IgcTreeComponent.prototype, "selection", void 0);
|
|
124
|
+
__decorate([
|
|
125
|
+
property({ reflect: true })
|
|
126
|
+
], IgcTreeComponent.prototype, "dir", void 0);
|
|
127
|
+
__decorate([
|
|
128
|
+
watch('dir')
|
|
129
|
+
], IgcTreeComponent.prototype, "onDirChange", null);
|
|
130
|
+
__decorate([
|
|
131
|
+
watch('size', { waitUntilFirstUpdate: true })
|
|
132
|
+
], IgcTreeComponent.prototype, "onSizeChange", null);
|
|
133
|
+
__decorate([
|
|
134
|
+
watch('selection', { waitUntilFirstUpdate: true })
|
|
135
|
+
], IgcTreeComponent.prototype, "selectionModeChange", null);
|
|
136
|
+
__decorate([
|
|
137
|
+
watch('singleBranchExpand')
|
|
138
|
+
], IgcTreeComponent.prototype, "singleBranchExpandChange", null);
|
|
139
|
+
//# sourceMappingURL=tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.js","sourceRoot":"","sources":["../../../src/components/tree/tree.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,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EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC;IAClD,CAAC;IAMM,QAAQ,CAAC,KAA8B;QAC5C,KAAK,GAAG,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC;QAC5B,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC;IACnD,CAAC;IAEkB,MAAM;QACvB,OAAO,IAAI,CAAA,eAAe,CAAC;IAC7B,CAAC;;AAjJsB,wBAAO,GAAG,UAAU,CAAC;AAE9B,uBAAM,GAAG,MAAM,CAAC;AAS9B;IADC,QAAQ,CAAC,EAAE,SAAS,EAAE,sBAAsB,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;4DAC5C;AAIlC;IADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;mDAC+B;AAI3D;IADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;6CACY;AAGxC;IADC,KAAK,CAAC,KAAK,CAAC;mDAKZ;AAGD;IADC,KAAK,CAAC,MAAM,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;oDAU7C;AAGD;IADC,KAAK,CAAC,WAAW,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;2DAMlD;AAGD;IADC,KAAK,CAAC,oBAAoB,CAAC;gEAgB3B","sourcesContent":["import { html, LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { watch } from '../common/decorators/watch.js';\nimport { styles } from './themes/light/tree.base.css.js';\nimport { Constructor } from '../common/mixins/constructor.js';\nimport { EventEmitterMixin } from '../common/mixins/event-emitter.js';\nimport { SizableMixin } from '../common/mixins/sizable.js';\nimport IgcTreeItemComponent from './tree-item.js';\nimport { IgcTreeEventMap } from './tree.common.js';\nimport { IgcTreeNavigationService } from './tree.navigation.js';\nimport { IgcTreeSelectionService } from './tree.selection.js';\n\ntype Direction = 'ltr' | 'rtl' | 'auto';\n\n/**\n * The tree allows users to represent hierarchical data in a tree-view structure,\n * maintaining parent-child relationships, as well as to define static tree-view structure without a corresponding data model.\n *\n * @element igc-tree\n *\n * @slot - Renders the tree items inside default slot.\n *\n * @fires igcSelection - Emitted when item selection is changing, before the selection completes.\n * @fires igcItemCollapsed - Emitted when tree item is collapsed.\n * @fires igcItemCollapsing - Emitted when tree item is about to collapse.\n * @fires igcItemExpanded - Emitted when tree item is expanded.\n * @fires igcItemExpanding - Emitted when tree item is about to expand.\n * @fires igcItemActivated - Emitted when the tree's `active` item changes.\n */\nexport default class IgcTreeComponent extends SizableMixin(\n EventEmitterMixin<IgcTreeEventMap, Constructor<LitElement>>(LitElement)\n) {\n /** @private */\n public static readonly tagName = 'igc-tree';\n /** @private */\n public static styles = styles;\n\n /** @private */\n public selectionService!: IgcTreeSelectionService;\n /** @private */\n public navService!: IgcTreeNavigationService;\n\n /** Whether a single or multiple of a parent's child items can be expanded. */\n @property({ attribute: 'single-branch-expand', reflect: true, type: Boolean })\n public singleBranchExpand = false;\n\n /** The selection state of the tree. */\n @property({ reflect: true })\n public selection: 'none' | 'multiple' | 'cascade' = 'none';\n\n /** The direction attribute of the control. */\n @property({ reflect: true })\n public override dir: Direction = 'auto';\n\n @watch('dir')\n protected onDirChange(): void {\n this.items?.forEach((item: IgcTreeItemComponent) => {\n item.requestUpdate();\n });\n }\n\n @watch('size', { waitUntilFirstUpdate: true })\n protected onSizeChange(): void {\n this.items?.forEach((item: IgcTreeItemComponent) => {\n item.requestUpdate();\n });\n this.navService.activeItem?.wrapper?.scrollIntoView({\n behavior: 'smooth',\n block: 'nearest',\n inline: 'nearest',\n });\n }\n\n @watch('selection', { waitUntilFirstUpdate: true })\n protected selectionModeChange(): void {\n this.selectionService.clearItemsSelection();\n this.items?.forEach((item: IgcTreeItemComponent) => {\n item.requestUpdate();\n });\n }\n\n @watch('singleBranchExpand')\n protected singleBranchExpandChange(): void {\n if (this.singleBranchExpand) {\n // if activeItem -> do not collapse its branch\n if (this.navService.activeItem) {\n const path = this.navService.activeItem.path;\n const remainExpanded = new Set(path.splice(0, path.length - 1));\n this.items.forEach((item) => {\n if (!remainExpanded.has(item)) {\n item.collapseWithEvent();\n }\n });\n } else {\n this.items.forEach((item) => item.collapseWithEvent());\n }\n }\n }\n\n constructor() {\n super();\n this.selectionService = new IgcTreeSelectionService(this);\n this.navService = new IgcTreeNavigationService(this, this.selectionService);\n }\n\n public override connectedCallback(): void {\n super.connectedCallback();\n this.setAttribute('role', 'tree');\n this.addEventListener('keydown', this.handleKeydown);\n // set init to true for all items which are rendered along with the tree\n this.items.forEach((i: IgcTreeItemComponent) => {\n i.init = true;\n });\n const firstNotDisabledItem = this.items.find(\n (i: IgcTreeItemComponent) => !i.disabled\n );\n if (firstNotDisabledItem) {\n firstNotDisabledItem.tabIndex = 0;\n this.navService.focusItem(firstNotDisabledItem);\n }\n }\n\n /** Returns all of the tree's items. */\n public get items(): Array<IgcTreeItemComponent> {\n return Array.from(this.querySelectorAll(`igc-tree-item`));\n }\n\n private handleKeydown(event: KeyboardEvent) {\n this.navService.handleKeydown(event);\n }\n\n /** @private */\n public expandToItem(item: IgcTreeItemComponent): void {\n if (item && item.parent) {\n item.path.forEach((i) => {\n if (i !== item && !i.expanded) {\n i.expanded = true;\n }\n });\n }\n }\n\n /** Select all items if the items collection is empty. Otherwise, select the items in the items collection. */\n public select(items?: IgcTreeItemComponent[]): void {\n if (!items) {\n items =\n this.selection === 'cascade'\n ? this.items.filter((item: IgcTreeItemComponent) => item.level === 0)\n : this.items;\n }\n this.selectionService.selectItemsWithNoEvent(items);\n }\n\n /** Deselect all items if the items collection is empty. Otherwise, deselect the items in the items collection. */\n public deselect(items?: IgcTreeItemComponent[]): void {\n this.selectionService.deselectItemsWithNoEvent(items);\n }\n\n /**\n * Expands all of the passed items.\n * If no items are passed, expands ALL items.\n */\n public expand(items?: IgcTreeItemComponent[]): void {\n items = items || this.items;\n items.forEach((item) => (item.expanded = true));\n }\n\n /**\n * Collapses all of the passed items.\n * If no items are passed, collapses ALL items.\n */\n public collapse(items?: IgcTreeItemComponent[]): void {\n items = items || this.items;\n items.forEach((item) => (item.expanded = false));\n }\n\n protected override render() {\n return html`<slot></slot>`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'igc-tree': IgcTreeComponent;\n }\n}\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import IgcTreeComponent from './tree.js';
|
|
2
|
+
import IgcTreeItemComponent from './tree-item.js';
|
|
3
|
+
import { IgcTreeSelectionService } from './tree.selection.js';
|
|
4
|
+
export declare const NAVIGATION_KEYS: Set<string>;
|
|
5
|
+
export declare class IgcTreeNavigationService {
|
|
6
|
+
private tree;
|
|
7
|
+
private selectionService;
|
|
8
|
+
private _focusedItem;
|
|
9
|
+
private _lastFocusedItem;
|
|
10
|
+
private _activeItem;
|
|
11
|
+
private _visibleChildren;
|
|
12
|
+
private _invisibleChildren;
|
|
13
|
+
private _disabledChildren;
|
|
14
|
+
constructor(tree: IgcTreeComponent, selectionService: IgcTreeSelectionService);
|
|
15
|
+
updateVisChild(): void;
|
|
16
|
+
get focusedItem(): IgcTreeItemComponent | null;
|
|
17
|
+
focusItem(value: IgcTreeItemComponent | null, shouldFocus?: boolean): void;
|
|
18
|
+
get activeItem(): IgcTreeItemComponent | null;
|
|
19
|
+
setActiveItem(value: IgcTreeItemComponent | null, shouldEmit?: boolean): void;
|
|
20
|
+
get visibleChildren(): IgcTreeItemComponent[];
|
|
21
|
+
update_disabled_cache(item: IgcTreeItemComponent): void;
|
|
22
|
+
delete_item(item: IgcTreeItemComponent): void;
|
|
23
|
+
update_visible_cache(item: IgcTreeItemComponent, expanded: boolean, shouldUpdateNestedChildren?: boolean, shouldUpdate?: boolean): void;
|
|
24
|
+
/**
|
|
25
|
+
* Sets the item as focused (and active)
|
|
26
|
+
*
|
|
27
|
+
* @param item target item
|
|
28
|
+
* @param isActive if true, sets the item as active
|
|
29
|
+
*/
|
|
30
|
+
setFocusedAndActiveItem(item: IgcTreeItemComponent, isActive?: boolean, shouldFocus?: boolean): void;
|
|
31
|
+
/** Handler for keydown events. Used in tree.component.ts */
|
|
32
|
+
handleKeydown(event: KeyboardEvent): void;
|
|
33
|
+
private handleNavigation;
|
|
34
|
+
private handleArrowLeft;
|
|
35
|
+
private handleArrowRight;
|
|
36
|
+
private handleUpDownArrow;
|
|
37
|
+
private handleAsterisk;
|
|
38
|
+
private handleSpace;
|
|
39
|
+
/** Gets the next visible item in the given direction - 1 -> next, -1 -> previous */
|
|
40
|
+
private getVisibleItem;
|
|
41
|
+
}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
export const NAVIGATION_KEYS = new Set([
|
|
2
|
+
'down',
|
|
3
|
+
'up',
|
|
4
|
+
'left',
|
|
5
|
+
'right',
|
|
6
|
+
'arrowdown',
|
|
7
|
+
'arrowup',
|
|
8
|
+
'arrowleft',
|
|
9
|
+
'arrowright',
|
|
10
|
+
'home',
|
|
11
|
+
'end',
|
|
12
|
+
'space',
|
|
13
|
+
'spacebar',
|
|
14
|
+
' ',
|
|
15
|
+
]);
|
|
16
|
+
export class IgcTreeNavigationService {
|
|
17
|
+
constructor(tree, selectionService) {
|
|
18
|
+
this._focusedItem = null;
|
|
19
|
+
this._lastFocusedItem = null;
|
|
20
|
+
this._activeItem = null;
|
|
21
|
+
this._visibleChildren = [];
|
|
22
|
+
this._invisibleChildren = new Set();
|
|
23
|
+
this._disabledChildren = new Set();
|
|
24
|
+
this.tree = tree;
|
|
25
|
+
this.selectionService = selectionService;
|
|
26
|
+
}
|
|
27
|
+
updateVisChild() {
|
|
28
|
+
var _a;
|
|
29
|
+
this._visibleChildren = ((_a = this.tree) === null || _a === void 0 ? void 0 : _a.items)
|
|
30
|
+
? this.tree.items.filter((i) => !(this._invisibleChildren.has(i) || this._disabledChildren.has(i)))
|
|
31
|
+
: [];
|
|
32
|
+
}
|
|
33
|
+
get focusedItem() {
|
|
34
|
+
return this._focusedItem;
|
|
35
|
+
}
|
|
36
|
+
focusItem(value, shouldFocus = true) {
|
|
37
|
+
var _a;
|
|
38
|
+
if (this._focusedItem === value) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
this._lastFocusedItem = this._focusedItem;
|
|
42
|
+
if (this._lastFocusedItem) {
|
|
43
|
+
this._lastFocusedItem.removeAttribute('tabindex');
|
|
44
|
+
}
|
|
45
|
+
this._focusedItem = value;
|
|
46
|
+
if (this._focusedItem !== null && shouldFocus) {
|
|
47
|
+
this._focusedItem.tabIndex = 0;
|
|
48
|
+
this._focusedItem.focus({
|
|
49
|
+
preventScroll: true,
|
|
50
|
+
});
|
|
51
|
+
(_a = this._focusedItem.wrapper) === null || _a === void 0 ? void 0 : _a.scrollIntoView({
|
|
52
|
+
behavior: 'smooth',
|
|
53
|
+
block: 'nearest',
|
|
54
|
+
inline: 'nearest',
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
get activeItem() {
|
|
59
|
+
return this._activeItem;
|
|
60
|
+
}
|
|
61
|
+
setActiveItem(value, shouldEmit = true) {
|
|
62
|
+
if (this._activeItem === value) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (this._activeItem && value) {
|
|
66
|
+
this._activeItem.active = false;
|
|
67
|
+
}
|
|
68
|
+
this._activeItem = value;
|
|
69
|
+
if (this._activeItem) {
|
|
70
|
+
this._activeItem.active = true;
|
|
71
|
+
}
|
|
72
|
+
if (shouldEmit && this._activeItem) {
|
|
73
|
+
this.tree.emitEvent('igcActiveItem', { detail: this._activeItem });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
get visibleChildren() {
|
|
77
|
+
return this._visibleChildren;
|
|
78
|
+
}
|
|
79
|
+
update_disabled_cache(item) {
|
|
80
|
+
if (item.disabled) {
|
|
81
|
+
this._disabledChildren.add(item);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
this._disabledChildren.delete(item);
|
|
85
|
+
}
|
|
86
|
+
this.updateVisChild();
|
|
87
|
+
}
|
|
88
|
+
delete_item(item) {
|
|
89
|
+
if (this.activeItem === item) {
|
|
90
|
+
this.setActiveItem(null);
|
|
91
|
+
}
|
|
92
|
+
if (this.focusedItem === item) {
|
|
93
|
+
this.focusItem(null, false);
|
|
94
|
+
const firstNotDisableItem = this.tree.items.find((i) => !i.disabled);
|
|
95
|
+
if (firstNotDisableItem) {
|
|
96
|
+
firstNotDisableItem.tabIndex = 0;
|
|
97
|
+
this.focusItem(firstNotDisableItem, false);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
update_visible_cache(item, expanded, shouldUpdateNestedChildren = true, shouldUpdate = true) {
|
|
102
|
+
var _a, _b;
|
|
103
|
+
if (expanded && !this._invisibleChildren.has(item)) {
|
|
104
|
+
(_a = item.getChildren()) === null || _a === void 0 ? void 0 : _a.forEach((child) => {
|
|
105
|
+
this._invisibleChildren.delete(child);
|
|
106
|
+
if (shouldUpdateNestedChildren) {
|
|
107
|
+
this.update_visible_cache(child, child.expanded, true, false);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
(_b = item
|
|
113
|
+
.getChildren({ flatten: true })) === null || _b === void 0 ? void 0 : _b.forEach((c) => this._invisibleChildren.add(c));
|
|
114
|
+
}
|
|
115
|
+
if (shouldUpdate) {
|
|
116
|
+
this.updateVisChild();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
setFocusedAndActiveItem(item, isActive = true, shouldFocus = true) {
|
|
120
|
+
if (isActive) {
|
|
121
|
+
this.setActiveItem(item);
|
|
122
|
+
}
|
|
123
|
+
this.focusItem(item, shouldFocus);
|
|
124
|
+
}
|
|
125
|
+
handleKeydown(event) {
|
|
126
|
+
const key = event.key.toLowerCase();
|
|
127
|
+
if (!this.focusedItem) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (!(NAVIGATION_KEYS.has(key) || key === '*')) {
|
|
131
|
+
if (key === 'enter') {
|
|
132
|
+
this.setActiveItem(this.focusedItem);
|
|
133
|
+
}
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
this.handleNavigation(event);
|
|
138
|
+
}
|
|
139
|
+
handleNavigation(event) {
|
|
140
|
+
switch (event.key.toLowerCase()) {
|
|
141
|
+
case 'home':
|
|
142
|
+
this.setFocusedAndActiveItem(this.visibleChildren[0]);
|
|
143
|
+
break;
|
|
144
|
+
case 'end':
|
|
145
|
+
this.setFocusedAndActiveItem(this.visibleChildren[this.visibleChildren.length - 1]);
|
|
146
|
+
break;
|
|
147
|
+
case 'arrowleft':
|
|
148
|
+
case 'left':
|
|
149
|
+
if (this.tree.dir === 'rtl') {
|
|
150
|
+
this.handleArrowRight();
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
this.handleArrowLeft();
|
|
154
|
+
}
|
|
155
|
+
break;
|
|
156
|
+
case 'arrowright':
|
|
157
|
+
case 'right':
|
|
158
|
+
if (this.tree.dir === 'rtl') {
|
|
159
|
+
this.handleArrowLeft();
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
this.handleArrowRight();
|
|
163
|
+
}
|
|
164
|
+
break;
|
|
165
|
+
case 'arrowup':
|
|
166
|
+
case 'up':
|
|
167
|
+
this.handleUpDownArrow(true, event);
|
|
168
|
+
break;
|
|
169
|
+
case 'arrowdown':
|
|
170
|
+
case 'down':
|
|
171
|
+
this.handleUpDownArrow(false, event);
|
|
172
|
+
break;
|
|
173
|
+
case '*':
|
|
174
|
+
this.handleAsterisk();
|
|
175
|
+
break;
|
|
176
|
+
case ' ':
|
|
177
|
+
case 'spacebar':
|
|
178
|
+
case 'space':
|
|
179
|
+
this.handleSpace(event.shiftKey);
|
|
180
|
+
break;
|
|
181
|
+
default:
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
handleArrowLeft() {
|
|
186
|
+
var _a, _b, _c;
|
|
187
|
+
if (((_a = this.focusedItem) === null || _a === void 0 ? void 0 : _a.expanded) && ((_b = this.focusedItem.getChildren()) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
188
|
+
this.setActiveItem(this.focusedItem);
|
|
189
|
+
this.focusedItem.collapseWithEvent();
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
const parentItem = (_c = this.focusedItem) === null || _c === void 0 ? void 0 : _c.parent;
|
|
193
|
+
if (parentItem && !parentItem.disabled) {
|
|
194
|
+
this.setFocusedAndActiveItem(parentItem);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
handleArrowRight() {
|
|
199
|
+
var _a, _b;
|
|
200
|
+
if (((_a = this.focusedItem.getChildren()) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
201
|
+
if (!((_b = this.focusedItem) === null || _b === void 0 ? void 0 : _b.expanded)) {
|
|
202
|
+
this.setActiveItem(this.focusedItem);
|
|
203
|
+
this.focusedItem.expandWithEvent();
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
const firstChild = this.focusedItem
|
|
207
|
+
.getChildren()
|
|
208
|
+
.find((item) => !item.disabled);
|
|
209
|
+
if (firstChild) {
|
|
210
|
+
this.setFocusedAndActiveItem(firstChild);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
handleUpDownArrow(isUp, event) {
|
|
216
|
+
const next = this.getVisibleItem(this.focusedItem, isUp ? -1 : 1);
|
|
217
|
+
if (next === this.focusedItem) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (event.ctrlKey) {
|
|
221
|
+
this.setFocusedAndActiveItem(next, false);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
this.setFocusedAndActiveItem(next);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
handleAsterisk() {
|
|
228
|
+
var _a, _b, _c;
|
|
229
|
+
const items = ((_a = this.focusedItem) === null || _a === void 0 ? void 0 : _a.parent)
|
|
230
|
+
? (_b = this.focusedItem.parent) === null || _b === void 0 ? void 0 : _b.getChildren()
|
|
231
|
+
: (_c = this.tree.items) === null || _c === void 0 ? void 0 : _c.filter((item) => item.level === 0);
|
|
232
|
+
items === null || items === void 0 ? void 0 : items.forEach((item) => {
|
|
233
|
+
if (!item.disabled && !item.expanded && item.hasChildren) {
|
|
234
|
+
item.expandWithEvent();
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
handleSpace(shiftKey = false) {
|
|
239
|
+
if (this.tree.selection === 'none') {
|
|
240
|
+
this.setActiveItem(this.focusedItem);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
this.setActiveItem(this.focusedItem);
|
|
244
|
+
if (shiftKey) {
|
|
245
|
+
this.selectionService.selectMultipleItems(this.focusedItem);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
if (this.focusedItem.selected) {
|
|
249
|
+
this.selectionService.deselectItem(this.focusedItem);
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
this.selectionService.selectItem(this.focusedItem);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
getVisibleItem(item, dir = 1) {
|
|
256
|
+
const itemIndex = this.visibleChildren.indexOf(item);
|
|
257
|
+
return this.visibleChildren[itemIndex + dir] || item;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
//# sourceMappingURL=tree.navigation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.navigation.js","sourceRoot":"","sources":["../../../src/components/tree/tree.navigation.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IACrC,MAAM;IACN,IAAI;IACJ,MAAM;IACN,OAAO;IACP,W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tree.js';\nimport IgcTreeItemComponent from './tree-item.js';\nimport { IgcTreeSelectionService } from './tree.selection.js';\n\nexport const NAVIGATION_KEYS = new Set([\n 'down',\n 'up',\n 'left',\n 'right',\n 'arrowdown',\n 'arrowup',\n 'arrowleft',\n 'arrowright',\n 'home',\n 'end',\n 'space',\n 'spacebar',\n ' ',\n]);\n\nexport class IgcTreeNavigationService {\n private tree!: IgcTreeComponent;\n private selectionService!: IgcTreeSelectionService;\n\n private _focusedItem: IgcTreeItemComponent | null = null;\n\n private _lastFocusedItem: IgcTreeItemComponent | null = null;\n private _activeItem: IgcTreeItemComponent | null = null;\n\n private _visibleChildren: IgcTreeItemComponent[] = [];\n private _invisibleChildren: Set<IgcTreeItemComponent> = new Set();\n private _disabledChildren: Set<IgcTreeItemComponent> = new Set();\n\n constructor(\n tree: IgcTreeComponent,\n selectionService: IgcTreeSelectionService\n ) {\n this.tree = tree;\n this.selectionService = selectionService;\n }\n\n public updateVisChild(): void {\n this._visibleChildren = this.tree?.items\n ? this.tree.items.filter(\n (i: IgcTreeItemComponent) =>\n !(this._invisibleChildren.has(i) || this._disabledChildren.has(i))\n )\n : [];\n }\n\n public get focusedItem(): IgcTreeItemComponent | null {\n return this._focusedItem;\n }\n\n public focusItem(value: IgcTreeItemComponent | null, shouldFocus = true) {\n if (this._focusedItem === value) {\n return;\n }\n this._lastFocusedItem = this._focusedItem;\n if (this._lastFocusedItem) {\n this._lastFocusedItem.removeAttribute('tabindex');\n }\n this._focusedItem = value;\n if (this._focusedItem !== null && shouldFocus) {\n this._focusedItem.tabIndex = 0;\n this._focusedItem.focus({\n preventScroll: true,\n });\n this._focusedItem.wrapper?.scrollIntoView({\n behavior: 'smooth',\n block: 'nearest',\n inline: 'nearest',\n });\n }\n }\n\n public get activeItem(): IgcTreeItemComponent | null {\n return this._activeItem;\n }\n\n public setActiveItem(value: IgcTreeItemComponent | null, shouldEmit = true) {\n if (this._activeItem === value) {\n return;\n }\n if (this._activeItem && value) {\n this._activeItem.active = false;\n }\n this._activeItem = value;\n if (this._activeItem) {\n this._activeItem.active = true;\n }\n if (shouldEmit && this._activeItem) {\n this.tree.emitEvent('igcActiveItem', { detail: this._activeItem });\n }\n }\n\n public get visibleChildren(): IgcTreeItemComponent[] {\n return this._visibleChildren;\n }\n\n public update_disabled_cache(item: IgcTreeItemComponent): void {\n if (item.disabled) {\n this._disabledChildren.add(item);\n } else {\n this._disabledChildren.delete(item);\n }\n this.updateVisChild();\n }\n\n public delete_item(item: IgcTreeItemComponent) {\n if (this.activeItem === item) {\n this.setActiveItem(null);\n }\n if (this.focusedItem === item) {\n this.focusItem(null, false);\n const firstNotDisableItem = this.tree.items.find(\n (i: IgcTreeItemComponent) => !i.disabled\n );\n if (firstNotDisableItem) {\n firstNotDisableItem.tabIndex = 0;\n this.focusItem(firstNotDisableItem, false);\n }\n }\n }\n\n public update_visible_cache(\n item: IgcTreeItemComponent,\n expanded: boolean,\n shouldUpdateNestedChildren = true,\n shouldUpdate = true\n ): void {\n if (expanded && !this._invisibleChildren.has(item)) {\n item.getChildren()?.forEach((child: IgcTreeItemComponent) => {\n this._invisibleChildren.delete(child);\n if (shouldUpdateNestedChildren) {\n this.update_visible_cache(child, child.expanded, true, false);\n }\n });\n } else {\n item\n .getChildren({ flatten: true })\n ?.forEach((c: IgcTreeItemComponent) => this._invisibleChildren.add(c));\n }\n\n if (shouldUpdate) {\n this.updateVisChild();\n }\n }\n\n /**\n * Sets the item as focused (and active)\n *\n * @param item target item\n * @param isActive if true, sets the item as active\n */\n public setFocusedAndActiveItem(\n item: IgcTreeItemComponent,\n isActive = true,\n shouldFocus = true\n ): void {\n if (isActive) {\n this.setActiveItem(item);\n }\n this.focusItem(item, shouldFocus);\n }\n\n /** Handler for keydown events. Used in tree.component.ts */\n public handleKeydown(event: KeyboardEvent) {\n const key = event.key.toLowerCase();\n if (!this.focusedItem) {\n return;\n }\n if (!(NAVIGATION_KEYS.has(key) || key === '*')) {\n if (key === 'enter') {\n this.setActiveItem(this.focusedItem);\n }\n return;\n }\n event.preventDefault();\n this.handleNavigation(event);\n }\n\n private handleNavigation(event: KeyboardEvent) {\n switch (event.key.toLowerCase()) {\n case 'home':\n this.setFocusedAndActiveItem(this.visibleChildren[0]);\n break;\n case 'end':\n this.setFocusedAndActiveItem(\n this.visibleChildren[this.visibleChildren.length - 1]\n );\n break;\n case 'arrowleft':\n case 'left':\n if (this.tree.dir === 'rtl') {\n this.handleArrowRight();\n } else {\n this.handleArrowLeft();\n }\n break;\n case 'arrowright':\n case 'right':\n if (this.tree.dir === 'rtl') {\n this.handleArrowLeft();\n } else {\n this.handleArrowRight();\n }\n break;\n case 'arrowup':\n case 'up':\n this.handleUpDownArrow(true, event);\n break;\n case 'arrowdown':\n case 'down':\n this.handleUpDownArrow(false, event);\n break;\n case '*':\n this.handleAsterisk();\n break;\n case ' ':\n case 'spacebar':\n case 'space':\n this.handleSpace(event.shiftKey);\n break;\n default:\n return;\n }\n }\n\n private handleArrowLeft(): void {\n if (this.focusedItem?.expanded && this.focusedItem.getChildren()?.length) {\n this.setActiveItem(this.focusedItem);\n this.focusedItem.collapseWithEvent();\n } else {\n const parentItem = this.focusedItem?.parent;\n if (parentItem && !parentItem.disabled) {\n this.setFocusedAndActiveItem(parentItem);\n }\n }\n }\n\n private handleArrowRight(): void {\n if (this.focusedItem!.getChildren()?.length > 0) {\n if (!this.focusedItem?.expanded) {\n this.setActiveItem(this.focusedItem);\n this.focusedItem!.expandWithEvent();\n } else {\n const firstChild = this.focusedItem\n .getChildren()\n .find((item: IgcTreeItemComponent) => !item.disabled);\n if (firstChild) {\n this.setFocusedAndActiveItem(firstChild);\n }\n }\n }\n }\n\n private handleUpDownArrow(isUp: boolean, event: KeyboardEvent): void {\n const next = this.getVisibleItem(this.focusedItem!, isUp ? -1 : 1);\n if (next === this.focusedItem) {\n return;\n }\n\n if (event.ctrlKey) {\n this.setFocusedAndActiveItem(next, false);\n } else {\n this.setFocusedAndActiveItem(next);\n }\n }\n\n private handleAsterisk(): void {\n const items = this.focusedItem?.parent\n ? this.focusedItem!.parent?.getChildren()\n : this.tree.items?.filter(\n (item: IgcTreeItemComponent) => item.level === 0\n );\n items?.forEach((item: IgcTreeItemComponent) => {\n if (!item.disabled && !item.expanded && item.hasChildren) {\n item.expandWithEvent();\n }\n });\n }\n\n private handleSpace(shiftKey = false): void {\n if (this.tree.selection === 'none') {\n this.setActiveItem(this.focusedItem);\n return;\n }\n\n this.setActiveItem(this.focusedItem);\n if (shiftKey) {\n this.selectionService.selectMultipleItems(this.focusedItem!);\n return;\n }\n\n if (this.focusedItem!.selected) {\n this.selectionService.deselectItem(this.focusedItem!);\n } else {\n this.selectionService.selectItem(this.focusedItem!);\n }\n }\n\n /** Gets the next visible item in the given direction - 1 -> next, -1 -> previous */\n private getVisibleItem(\n item: IgcTreeItemComponent,\n dir: 1 | -1 = 1\n ): IgcTreeItemComponent {\n const itemIndex = this.visibleChildren.indexOf(item);\n return this.visibleChildren[itemIndex + dir] || item;\n }\n}\n"]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import IgcTreeComponent from './tree.js';
|
|
2
|
+
import IgcTreeItemComponent from './tree-item.js';
|
|
3
|
+
export declare class IgcTreeSelectionService {
|
|
4
|
+
private tree;
|
|
5
|
+
private itemSelection;
|
|
6
|
+
private indeterminateItems;
|
|
7
|
+
private itemsToBeSelected;
|
|
8
|
+
private itemsToBeIndeterminate;
|
|
9
|
+
constructor(tree: IgcTreeComponent);
|
|
10
|
+
/** Select range from last selected item to the current specified item. */
|
|
11
|
+
selectMultipleItems(item: IgcTreeItemComponent): void;
|
|
12
|
+
/** Select the specified item and emit event. */
|
|
13
|
+
selectItem(item: IgcTreeItemComponent): void;
|
|
14
|
+
/** Deselect the specified item and emit event. */
|
|
15
|
+
deselectItem(item: IgcTreeItemComponent): void;
|
|
16
|
+
/** Clears item selection */
|
|
17
|
+
clearItemsSelection(): void;
|
|
18
|
+
isItemSelected(item: IgcTreeItemComponent): boolean;
|
|
19
|
+
isItemIndeterminate(item: IgcTreeItemComponent): boolean;
|
|
20
|
+
/** Called on item`s disconnectedCallback */
|
|
21
|
+
ensureStateOnItemDelete(item: IgcTreeItemComponent): void;
|
|
22
|
+
/** Retrigger the selection state of the item. */
|
|
23
|
+
retriggerItemState(item: IgcTreeItemComponent): void;
|
|
24
|
+
private emitItemSelectionEvent;
|
|
25
|
+
/** Select specified items. No event is emitted. */
|
|
26
|
+
selectItemsWithNoEvent(items: IgcTreeItemComponent[]): void;
|
|
27
|
+
/** Deselect specified items. No event is emitted. */
|
|
28
|
+
deselectItemsWithNoEvent(items?: IgcTreeItemComponent[], onDelete?: boolean): void;
|
|
29
|
+
private emitCascadeItemSelectionEvent;
|
|
30
|
+
private cascadeSelectItemsWithNoEvent;
|
|
31
|
+
private cascadeDeselectItemsWithNoEvent;
|
|
32
|
+
/**
|
|
33
|
+
* populates the itemsToBeSelected and itemsToBeIndeterminate sets
|
|
34
|
+
* with the items which will be eventually in selected/indeterminate state
|
|
35
|
+
*/
|
|
36
|
+
private calculateItemsNewSelectionState;
|
|
37
|
+
/** Ensures proper selection state for all predescessors and descendants during a selection event */
|
|
38
|
+
private cascadeSelectionState;
|
|
39
|
+
/**
|
|
40
|
+
* recursively handle the selection state of the direct and indirect parents
|
|
41
|
+
*/
|
|
42
|
+
private handleParentSelectionState;
|
|
43
|
+
/**
|
|
44
|
+
* Handle the selection state of a given item based the selection states of its direct children
|
|
45
|
+
*/
|
|
46
|
+
private handleItemSelectionState;
|
|
47
|
+
/** Emits the `selectedChange` event for each item affected by the selection */
|
|
48
|
+
private updateItemsState;
|
|
49
|
+
/** Returns array of the selected items. */
|
|
50
|
+
private getSelectedItems;
|
|
51
|
+
/** Returns array of the items in indeterminate state. */
|
|
52
|
+
private getIndeterminateItems;
|
|
53
|
+
private areEqualCollections;
|
|
54
|
+
private selectDeselectItem;
|
|
55
|
+
}
|