@omicronenergy/oscd-ui 0.0.13 → 0.0.15
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/custom-elements.json +8243 -5766
- package/dist/action-icon/oscd-action-icon.stories.d.ts +12 -69
- package/dist/action-list/oscd-action-list.stories.d.ts +12 -33
- package/dist/action-pane/oscd-action-pane.stories.d.ts +13 -36
- package/dist/action-tree/oscd-action-tree.stories.d.ts +13 -36
- package/dist/button/OscdElevatedButton.stories.d.ts +13 -36
- package/dist/button/OscdFilledButton.stories.d.ts +13 -36
- package/dist/button/OscdFilledTonalButton.stories.d.ts +13 -36
- package/dist/button/OscdOutlinedButton.stories.d.ts +13 -36
- package/dist/button/OscdTextButton.stories.d.ts +13 -36
- package/dist/checkbox/OscdCheckbox.stories.d.ts +13 -36
- package/dist/chips/OscdAssistChip.stories.d.ts +13 -36
- package/dist/chips/OscdChipSet.stories.d.ts +13 -36
- package/dist/chips/OscdFilterChip.stories.d.ts +13 -36
- package/dist/chips/OscdInputChip.stories.d.ts +13 -36
- package/dist/chips/OscdSuggestionChip.stories.d.ts +13 -36
- package/dist/decorators/localstorage.d.ts +8 -0
- package/dist/decorators/localstorage.js +136 -0
- package/dist/decorators/localstorage.js.map +1 -0
- package/dist/decorators/localstorage.spec.d.ts +1 -0
- package/dist/decorators/localstorage.spec.js +138 -0
- package/dist/decorators/localstorage.spec.js.map +1 -0
- package/dist/dialog/OscdDialog.stories.d.ts +13 -36
- package/dist/divider/OscdDivider.stories.d.ts +13 -36
- package/dist/elevation/OscdElevation.stories.d.ts +13 -36
- package/dist/fab/OscdBrandedFab.stories.d.ts +13 -36
- package/dist/fab/OscdFab.stories.d.ts +13 -36
- package/dist/field/OscdFilledField.stories.d.ts +13 -36
- package/dist/field/OscdOutlinedField.stories.d.ts +13 -36
- package/dist/filter-button/oscd-filter-button.stories.d.ts +12 -32
- package/dist/focus/OscdFocusRing.stories.d.ts +13 -36
- package/dist/icon/OscdIcon.stories.d.ts +13 -36
- package/dist/iconbutton/OscdFilledIconButton.stories.d.ts +13 -36
- package/dist/iconbutton/OscdFilledTonalIconButton.stories.d.ts +13 -36
- package/dist/iconbutton/OscdIconButton.stories.d.ts +13 -36
- package/dist/iconbutton/OscdOutlinedIconButton.stories.d.ts +13 -36
- package/dist/labs/badge/OscdBadge.stories.d.ts +13 -36
- package/dist/labs/card/OscdElevatedCard.stories.d.ts +13 -36
- package/dist/labs/card/OscdFilledCard.stories.d.ts +13 -36
- package/dist/labs/card/OscdOutlinedCard.stories.d.ts +13 -36
- package/dist/labs/item/OscdItem.stories.d.ts +13 -36
- package/dist/labs/navigationbar/OscdNavigationBar.stories.d.ts +13 -36
- package/dist/labs/navigationtab/OscdNavigationTab.stories.d.ts +13 -36
- package/dist/labs/segmentedbutton/OscdOutlinedSegmentedButton.stories.d.ts +12 -32
- package/dist/labs/segmentedbuttonset/OscdOutlinedSegmentedButtonSet.stories.d.ts +12 -32
- package/dist/list/OscdList.stories.d.ts +13 -36
- package/dist/list/OscdListItem.stories.d.ts +13 -36
- package/dist/menu/OscdMenuItem.stories.d.ts +13 -36
- package/dist/menu/OscdSubMenu.stories.d.ts +23 -50
- package/dist/menu/OscdSubMenu.stories.js +188 -13
- package/dist/menu/OscdSubMenu.stories.js.map +1 -1
- package/dist/progress/OscdCircularProgress.stories.d.ts +13 -36
- package/dist/progress/OscdLinearProgress.stories.d.ts +13 -36
- package/dist/radio/OscdRadio.stories.d.ts +12 -32
- package/dist/ripple/OscdRipple.stories.d.ts +13 -36
- package/dist/scl-checkbox/oscd-scl-checkbox.stories.d.ts +13 -36
- package/dist/scl-icon/OscdSclIcon.stories.d.ts +13 -36
- package/dist/scl-select/oscd-scl-select.stories.d.ts +13 -36
- package/dist/scl-textfield/oscd-scl-text-field.stories.d.ts +13 -36
- package/dist/select/OscdFilledSelect.stories.d.ts +12 -32
- package/dist/select/OscdOutlinedSelect.stories.d.ts +12 -32
- package/dist/select/OscdSelectOption.stories.d.ts +12 -32
- package/dist/selection-list/oscd-selection-list.stories.d.ts +12 -32
- package/dist/selection-list/oscd-selection-list.stories.js +1 -1
- package/dist/selection-list/oscd-selection-list.stories.js.map +1 -1
- package/dist/slider/OscdSlider.stories.d.ts +13 -36
- package/dist/snackbar/OscdSnackbar.d.ts +133 -0
- package/dist/snackbar/OscdSnackbar.js +505 -0
- package/dist/snackbar/OscdSnackbar.js.map +1 -0
- package/dist/snackbar/OscdSnackbar.spec.d.ts +1 -0
- package/dist/snackbar/OscdSnackbar.spec.js +287 -0
- package/dist/snackbar/OscdSnackbar.spec.js.map +1 -0
- package/dist/snackbar/OscdSnackbar.stories.d.ts +22 -0
- package/dist/snackbar/OscdSnackbar.stories.js +214 -0
- package/dist/snackbar/OscdSnackbar.stories.js.map +1 -0
- package/dist/snackbar/oscd-snackbar.d.ts +2 -0
- package/dist/snackbar/oscd-snackbar.js +4 -0
- package/dist/snackbar/oscd-snackbar.js.map +1 -0
- package/dist/switch/OscdSwitch.stories.d.ts +13 -36
- package/dist/tabs/OscdPrimaryTab.stories.d.ts +12 -32
- package/dist/tabs/OscdSecondaryTab.stories.d.ts +12 -32
- package/dist/tabs/OscdTabs.stories.d.ts +13 -36
- package/dist/textfield/OscdFilledTextField.stories.d.ts +13 -36
- package/dist/textfield/OscdOutlinedTextField.stories.d.ts +13 -36
- package/dist/tree/OscdTree.d.ts +102 -0
- package/dist/tree/OscdTree.js +97 -0
- package/dist/tree/OscdTree.js.map +1 -0
- package/dist/tree/OscdTree.stories.d.ts +39 -0
- package/dist/tree/OscdTree.stories.js +488 -0
- package/dist/tree/OscdTree.stories.js.map +1 -0
- package/dist/tree/OscdTreeItem.d.ts +60 -0
- package/dist/tree/OscdTreeItem.js +56 -0
- package/dist/tree/OscdTreeItem.js.map +1 -0
- package/dist/tree/internal/Tree.d.ts +233 -0
- package/dist/tree/internal/Tree.js +732 -0
- package/dist/tree/internal/Tree.js.map +1 -0
- package/dist/tree/internal/TreeItem.d.ts +47 -0
- package/dist/tree/internal/TreeItem.js +257 -0
- package/dist/tree/internal/TreeItem.js.map +1 -0
- package/dist/tree/oscd-tree-item.d.ts +2 -0
- package/dist/tree/oscd-tree-item.js +4 -0
- package/dist/tree/oscd-tree-item.js.map +1 -0
- package/dist/tree/oscd-tree.d.ts +3 -0
- package/dist/tree/oscd-tree.js +5 -0
- package/dist/tree/oscd-tree.js.map +1 -0
- package/dist/tree/oscd-tree.spec.d.ts +3 -0
- package/dist/tree/oscd-tree.spec.js +144 -0
- package/dist/tree/oscd-tree.spec.js.map +1 -0
- package/dist/tree-grid/oscd-tree-grid.stories.d.ts +13 -36
- package/dist/utils/storybook/getStorybookMeta.d.ts +1 -3
- package/dist/utils/storybook/getStorybookMeta.js +10 -1
- package/dist/utils/storybook/getStorybookMeta.js.map +1 -1
- package/package.json +13 -6
- package/regenerating-library.md +4 -2
|
@@ -0,0 +1,732 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { css, html, LitElement, nothing, } from 'lit';
|
|
3
|
+
import { property, state } from 'lit/decorators.js';
|
|
4
|
+
import { ScopedElementsMixin } from '@open-wc/scoped-elements/lit-element.js';
|
|
5
|
+
import { OscdCheckbox } from '../../checkbox/OscdCheckbox.js';
|
|
6
|
+
import { OscdFocusRing } from '../../focus/OscdFocusRing.js';
|
|
7
|
+
import { OscdIcon } from '../../icon/OscdIcon.js';
|
|
8
|
+
import { OscdRipple } from '../../ripple/OscdRipple.js';
|
|
9
|
+
import { OscdTreeItem } from '../OscdTreeItem.js';
|
|
10
|
+
const fallbackRenderItem = ({ node, id, selected, active, disabled, }) => html `<oscd-tree-item
|
|
11
|
+
?selected=${selected}
|
|
12
|
+
?active=${active}
|
|
13
|
+
?disabled=${disabled}
|
|
14
|
+
>
|
|
15
|
+
<span slot="headline">${'label' in node ? String(node.label) : id}</span>
|
|
16
|
+
</oscd-tree-item>`;
|
|
17
|
+
const idSeparator = '/';
|
|
18
|
+
function childState(node) {
|
|
19
|
+
if (node.children === undefined) {
|
|
20
|
+
return 'unknown';
|
|
21
|
+
}
|
|
22
|
+
return node.children.length > 0 ? 'branch' : 'leaf';
|
|
23
|
+
}
|
|
24
|
+
function nextIndex(current, max) {
|
|
25
|
+
if (max < 0) {
|
|
26
|
+
return -1;
|
|
27
|
+
}
|
|
28
|
+
return Math.min(max, Math.max(0, current));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Internal base class for `oscd-tree`.
|
|
32
|
+
*/
|
|
33
|
+
export class Tree extends ScopedElementsMixin(LitElement) {
|
|
34
|
+
constructor() {
|
|
35
|
+
super(...arguments);
|
|
36
|
+
/**
|
|
37
|
+
* Structured tree data to render.
|
|
38
|
+
*/
|
|
39
|
+
this.data = [];
|
|
40
|
+
/**
|
|
41
|
+
* Selected node identifiers.
|
|
42
|
+
*
|
|
43
|
+
* This state is controlled by the caller and may be persisted outside the
|
|
44
|
+
* tree, but it must be scoped to the data set/context that produced the IDs.
|
|
45
|
+
* Reset or re-key persisted selected IDs when `data` changes to a different
|
|
46
|
+
* logical tree, otherwise unrelated nodes with matching IDs may appear
|
|
47
|
+
* selected.
|
|
48
|
+
*/
|
|
49
|
+
this.selectedIds = [];
|
|
50
|
+
/**
|
|
51
|
+
* Expanded node identifiers.
|
|
52
|
+
*
|
|
53
|
+
* This state is controlled by the caller and may be persisted outside the
|
|
54
|
+
* tree, but it must be scoped to the data set/context that produced the IDs.
|
|
55
|
+
* Reset or re-key persisted expanded IDs when `data` changes to a different
|
|
56
|
+
* logical tree, otherwise unrelated nodes with matching IDs may appear
|
|
57
|
+
* expanded.
|
|
58
|
+
*/
|
|
59
|
+
this.expandedIds = [];
|
|
60
|
+
/**
|
|
61
|
+
* Selection behavior.
|
|
62
|
+
*/
|
|
63
|
+
this.selectionMode = 'none';
|
|
64
|
+
/**
|
|
65
|
+
* Icon shown on the expand/collapse toggle when a branch is collapsed.
|
|
66
|
+
*
|
|
67
|
+
* Any icon name understood by `oscd-icon` (a Material Symbol name or a
|
|
68
|
+
* registered SCL icon) may be used. Defaults to `chevron_right`.
|
|
69
|
+
*/
|
|
70
|
+
this.collapseIcon = 'chevron_right';
|
|
71
|
+
/**
|
|
72
|
+
* Icon shown on the expand/collapse toggle when a branch is expanded.
|
|
73
|
+
*
|
|
74
|
+
* Any icon name understood by `oscd-icon` (a Material Symbol name or a
|
|
75
|
+
* registered SCL icon) may be used. Defaults to `expand_more`.
|
|
76
|
+
*/
|
|
77
|
+
this.expandIcon = 'expand_more';
|
|
78
|
+
/**
|
|
79
|
+
* Placement of the expand/collapse toggle within each row.
|
|
80
|
+
*
|
|
81
|
+
* `'leading'` (default) renders the toggle before the row content.
|
|
82
|
+
* `'trailing'` renders it after the content, right-aligned so the toggles
|
|
83
|
+
* line up on the trailing edge regardless of nesting depth. Keyboard
|
|
84
|
+
* expansion (`ArrowRight`/`ArrowLeft`) is unaffected by this option.
|
|
85
|
+
*/
|
|
86
|
+
this.togglePosition = 'leading';
|
|
87
|
+
}
|
|
88
|
+
willUpdate(changedProperties) {
|
|
89
|
+
if (changedProperties.has('data') ||
|
|
90
|
+
changedProperties.has('expandedIds') ||
|
|
91
|
+
changedProperties.has('selectedIds')) {
|
|
92
|
+
const rows = this.visibleRows();
|
|
93
|
+
if (!rows.length) {
|
|
94
|
+
this.activeId = undefined;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (!this.activeId || !rows.some(row => row.id === this.activeId)) {
|
|
98
|
+
this.activeId = rows[0].id;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Expands a node by ID.
|
|
104
|
+
*/
|
|
105
|
+
expand(id) {
|
|
106
|
+
if (!this.expandedIds.includes(id)) {
|
|
107
|
+
this.setExpandedIds([...this.expandedIds, id]);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Collapses a node by ID.
|
|
112
|
+
*/
|
|
113
|
+
collapse(id) {
|
|
114
|
+
if (this.expandedIds.includes(id)) {
|
|
115
|
+
this.setExpandedIds(this.expandedIds.filter(expandedId => expandedId !== id));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Toggles a node expansion state by ID.
|
|
120
|
+
*/
|
|
121
|
+
toggle(id) {
|
|
122
|
+
const row = this.visibleRows().find(candidate => candidate.id === id);
|
|
123
|
+
if (!row) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
this.toggleExpansion(row);
|
|
127
|
+
}
|
|
128
|
+
rowId(node, indexPath) {
|
|
129
|
+
return (node.id ??
|
|
130
|
+
this.getNodeId?.(node, indexPath) ??
|
|
131
|
+
indexPath.join(idSeparator));
|
|
132
|
+
}
|
|
133
|
+
visibleRows() {
|
|
134
|
+
const expandedIds = new Set(this.expandedIds);
|
|
135
|
+
const rows = [];
|
|
136
|
+
const walk = (nodes, level, parentIds, indexPath) => {
|
|
137
|
+
if (!nodes) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const ariaSetSize = nodes.length;
|
|
141
|
+
nodes.forEach((node, index) => {
|
|
142
|
+
const childIndexPath = [...indexPath, index];
|
|
143
|
+
const id = this.rowId(node, childIndexPath);
|
|
144
|
+
rows.push({
|
|
145
|
+
node,
|
|
146
|
+
id,
|
|
147
|
+
htmlId: `tree-row-${rows.length}`,
|
|
148
|
+
level,
|
|
149
|
+
parentIds,
|
|
150
|
+
ariaPositionInSet: index + 1,
|
|
151
|
+
ariaSetSize,
|
|
152
|
+
});
|
|
153
|
+
if (expandedIds.has(id) && node.children) {
|
|
154
|
+
walk(node.children, level + 1, [...parentIds, id], childIndexPath);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
walk(this.data, 1, [], []);
|
|
159
|
+
return rows;
|
|
160
|
+
}
|
|
161
|
+
renderContext(row) {
|
|
162
|
+
const selected = this.selectedIds.includes(row.id);
|
|
163
|
+
return {
|
|
164
|
+
node: row.node,
|
|
165
|
+
id: row.id,
|
|
166
|
+
level: row.level,
|
|
167
|
+
expanded: this.expandedIds.includes(row.id),
|
|
168
|
+
selected,
|
|
169
|
+
active: this.activeId === row.id,
|
|
170
|
+
childrenState: childState(row.node),
|
|
171
|
+
selectable: this.selectionMode !== 'none' && this.isRowSelectable(row),
|
|
172
|
+
disabled: this.isRowDisabled(row),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
accessibleLabel(row) {
|
|
176
|
+
if (this.getNodeLabel) {
|
|
177
|
+
return this.getNodeLabel(row.node, row.id);
|
|
178
|
+
}
|
|
179
|
+
if ('label' in row.node && row.node.label !== undefined) {
|
|
180
|
+
return String(row.node.label);
|
|
181
|
+
}
|
|
182
|
+
return row.id;
|
|
183
|
+
}
|
|
184
|
+
isRowSelectable(row) {
|
|
185
|
+
return this.isSelectable ? this.isSelectable(row.node) : true;
|
|
186
|
+
}
|
|
187
|
+
isRowDisabled(row) {
|
|
188
|
+
return this.isDisabled ? this.isDisabled(row.node) : false;
|
|
189
|
+
}
|
|
190
|
+
setExpandedIds(expandedIds) {
|
|
191
|
+
this.expandedIds = expandedIds;
|
|
192
|
+
this.dispatchEvent(new CustomEvent('expanded-ids-changed', {
|
|
193
|
+
detail: { expandedIds },
|
|
194
|
+
}));
|
|
195
|
+
}
|
|
196
|
+
setSelectedIds(selectedIds, targetNode) {
|
|
197
|
+
const previousSelectedIds = this.selectedIds;
|
|
198
|
+
this.selectedIds = selectedIds;
|
|
199
|
+
this.dispatchEvent(new CustomEvent('selected-ids-changed', {
|
|
200
|
+
detail: {
|
|
201
|
+
selectedIds,
|
|
202
|
+
previousSelectedIds,
|
|
203
|
+
targetNode,
|
|
204
|
+
},
|
|
205
|
+
}));
|
|
206
|
+
}
|
|
207
|
+
fireNodeEvent(name, row, options) {
|
|
208
|
+
const event = new CustomEvent(name, {
|
|
209
|
+
bubbles: true,
|
|
210
|
+
cancelable: options?.cancelable ?? false,
|
|
211
|
+
detail: {
|
|
212
|
+
node: row.node,
|
|
213
|
+
id: row.id,
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
return this.dispatchEvent(event);
|
|
217
|
+
}
|
|
218
|
+
toggleExpansion(row) {
|
|
219
|
+
if (this.isRowDisabled(row) || childState(row.node) === 'leaf') {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const expanded = this.expandedIds.includes(row.id);
|
|
223
|
+
if (expanded) {
|
|
224
|
+
this.setExpandedIds(this.expandedIds.filter(expandedId => expandedId !== row.id));
|
|
225
|
+
this.fireNodeEvent('node-collapse', row);
|
|
226
|
+
this.fireNodeEvent('node-toggle', row);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (!this.fireNodeEvent('node-expand', row, { cancelable: true })) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
this.setExpandedIds([...this.expandedIds, row.id]);
|
|
233
|
+
this.fireNodeEvent('node-toggle', row);
|
|
234
|
+
}
|
|
235
|
+
toggleSelection(row) {
|
|
236
|
+
if (this.selectionMode === 'none' ||
|
|
237
|
+
this.isRowDisabled(row) ||
|
|
238
|
+
!this.isRowSelectable(row)) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
if (this.selectionMode === 'single') {
|
|
242
|
+
this.setSelectedIds([row.id], row.node);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const selected = this.selectedIds.includes(row.id);
|
|
246
|
+
this.setSelectedIds(selected
|
|
247
|
+
? this.selectedIds.filter(selectedId => selectedId !== row.id)
|
|
248
|
+
: [...this.selectedIds, row.id], row.node);
|
|
249
|
+
}
|
|
250
|
+
activateRow(row) {
|
|
251
|
+
this.activeId = row.id;
|
|
252
|
+
this.fireNodeEvent('node-click', row);
|
|
253
|
+
}
|
|
254
|
+
handleRowClick(row, event) {
|
|
255
|
+
if (this.isRowDisabled(row)) {
|
|
256
|
+
event.preventDefault();
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
this.activateRow(row);
|
|
260
|
+
if (childState(row.node) !== 'leaf') {
|
|
261
|
+
this.toggleExpansion(row);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
this.toggleSelection(row);
|
|
265
|
+
}
|
|
266
|
+
handleToggleClick(row, event) {
|
|
267
|
+
event.stopPropagation();
|
|
268
|
+
this.activeId = row.id;
|
|
269
|
+
this.toggleExpansion(row);
|
|
270
|
+
}
|
|
271
|
+
handleKeyDown(row, event) {
|
|
272
|
+
const rows = this.visibleRows();
|
|
273
|
+
const rowIndex = rows.findIndex(candidate => candidate.id === row.id);
|
|
274
|
+
const lastIndex = rows.length - 1;
|
|
275
|
+
switch (event.key) {
|
|
276
|
+
case 'ArrowDown':
|
|
277
|
+
event.preventDefault();
|
|
278
|
+
this.activeId = rows[nextIndex(rowIndex + 1, lastIndex)]?.id;
|
|
279
|
+
break;
|
|
280
|
+
case 'ArrowUp':
|
|
281
|
+
event.preventDefault();
|
|
282
|
+
this.activeId = rows[nextIndex(rowIndex - 1, lastIndex)]?.id;
|
|
283
|
+
break;
|
|
284
|
+
case 'Home':
|
|
285
|
+
event.preventDefault();
|
|
286
|
+
this.activeId = rows[0]?.id;
|
|
287
|
+
break;
|
|
288
|
+
case 'End':
|
|
289
|
+
event.preventDefault();
|
|
290
|
+
this.activeId = rows[lastIndex]?.id;
|
|
291
|
+
break;
|
|
292
|
+
case 'ArrowRight':
|
|
293
|
+
event.preventDefault();
|
|
294
|
+
this.stepIn(row, rows, rowIndex);
|
|
295
|
+
break;
|
|
296
|
+
case 'ArrowLeft':
|
|
297
|
+
event.preventDefault();
|
|
298
|
+
this.stepOut(row);
|
|
299
|
+
break;
|
|
300
|
+
case 'Enter':
|
|
301
|
+
event.preventDefault();
|
|
302
|
+
this.activateRow(row);
|
|
303
|
+
this.fireNodeEvent('node-activate', row);
|
|
304
|
+
this.toggleSelection(row);
|
|
305
|
+
break;
|
|
306
|
+
case ' ':
|
|
307
|
+
event.preventDefault();
|
|
308
|
+
this.toggleSelection(row);
|
|
309
|
+
break;
|
|
310
|
+
default:
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
stepIn(row, rows, rowIndex) {
|
|
315
|
+
const state = childState(row.node);
|
|
316
|
+
if (state === 'leaf') {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (!this.expandedIds.includes(row.id)) {
|
|
320
|
+
this.toggleExpansion(row);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
const nextRow = rows[rowIndex + 1];
|
|
324
|
+
if (nextRow?.parentIds[nextRow.parentIds.length - 1] === row.id) {
|
|
325
|
+
this.activeId = nextRow.id;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
stepOut(row) {
|
|
329
|
+
if (this.expandedIds.includes(row.id)) {
|
|
330
|
+
this.toggleExpansion(row);
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
const parentId = row.parentIds[row.parentIds.length - 1];
|
|
334
|
+
if (parentId) {
|
|
335
|
+
this.activeId = parentId;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
renderSelection(row) {
|
|
339
|
+
if (this.selectionMode !== 'multiple' || !this.isRowSelectable(row)) {
|
|
340
|
+
return nothing;
|
|
341
|
+
}
|
|
342
|
+
const selected = this.selectedIds.includes(row.id);
|
|
343
|
+
return html `<span
|
|
344
|
+
part="selection"
|
|
345
|
+
class="selection"
|
|
346
|
+
aria-hidden="true"
|
|
347
|
+
data-selected=${selected ? 'true' : 'false'}
|
|
348
|
+
><oscd-checkbox
|
|
349
|
+
tabindex="-1"
|
|
350
|
+
?checked=${selected}
|
|
351
|
+
?disabled=${this.isRowDisabled(row)}
|
|
352
|
+
></oscd-checkbox
|
|
353
|
+
></span>`;
|
|
354
|
+
}
|
|
355
|
+
renderToggle(row, context) {
|
|
356
|
+
const expandable = context.childrenState !== 'leaf';
|
|
357
|
+
const expanded = context.expanded;
|
|
358
|
+
if (!expandable && this.renderLeafAccessory) {
|
|
359
|
+
const accessory = this.renderLeafAccessory(context);
|
|
360
|
+
if (accessory !== nothing && accessory != null && accessory !== false) {
|
|
361
|
+
return html `<div
|
|
362
|
+
part="accessory"
|
|
363
|
+
class="accessory"
|
|
364
|
+
@click=${(event) => event.stopPropagation()}
|
|
365
|
+
@keydown=${(event) => this.handleAccessoryKeydown(event)}
|
|
366
|
+
>
|
|
367
|
+
${accessory}
|
|
368
|
+
</div>`;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return html `<button
|
|
372
|
+
part="toggle"
|
|
373
|
+
class="toggle"
|
|
374
|
+
?disabled=${!expandable || context.disabled}
|
|
375
|
+
aria-label=${expanded ? 'Collapse' : 'Expand'}
|
|
376
|
+
tabindex="-1"
|
|
377
|
+
@click=${(event) => this.handleToggleClick(row, event)}
|
|
378
|
+
>
|
|
379
|
+
${expandable
|
|
380
|
+
? html `<oscd-icon
|
|
381
|
+
>${expanded ? this.expandIcon : this.collapseIcon}</oscd-icon
|
|
382
|
+
>`
|
|
383
|
+
: nothing}
|
|
384
|
+
</button>`;
|
|
385
|
+
}
|
|
386
|
+
// Keep Enter/Space activations of a leaf accessory (e.g. a pin button) from
|
|
387
|
+
// bubbling to the row's keyboard handler; arrow keys still bubble so tree
|
|
388
|
+
// navigation continues to work while an accessory is focused.
|
|
389
|
+
// eslint-disable-next-line class-methods-use-this
|
|
390
|
+
handleAccessoryKeydown(event) {
|
|
391
|
+
if (event.key === 'Enter' ||
|
|
392
|
+
event.key === ' ' ||
|
|
393
|
+
event.key === 'Spacebar') {
|
|
394
|
+
event.stopPropagation();
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
renderRow(row) {
|
|
398
|
+
const context = this.renderContext(row);
|
|
399
|
+
const state = context.childrenState;
|
|
400
|
+
const selected = context.selected;
|
|
401
|
+
const disabled = context.disabled;
|
|
402
|
+
const active = context.active;
|
|
403
|
+
return html `<div
|
|
404
|
+
id=${row.htmlId}
|
|
405
|
+
part="row"
|
|
406
|
+
class="row"
|
|
407
|
+
role="treeitem"
|
|
408
|
+
tabindex=${active ? '0' : '-1'}
|
|
409
|
+
aria-level=${row.level}
|
|
410
|
+
aria-posinset=${row.ariaPositionInSet}
|
|
411
|
+
aria-setsize=${row.ariaSetSize}
|
|
412
|
+
aria-label=${this.accessibleLabel(row)}
|
|
413
|
+
aria-expanded=${state === 'leaf' ? nothing : context.expanded}
|
|
414
|
+
aria-selected=${context.selectable ? selected : nothing}
|
|
415
|
+
aria-disabled=${disabled ? 'true' : nothing}
|
|
416
|
+
data-active=${active ? 'true' : 'false'}
|
|
417
|
+
data-selected=${selected ? 'true' : 'false'}
|
|
418
|
+
data-selection-mode=${this.selectionMode}
|
|
419
|
+
data-disabled=${disabled ? 'true' : 'false'}
|
|
420
|
+
style=${`--oscd-tree-row-level: ${row.level};`}
|
|
421
|
+
@click=${(event) => this.handleRowClick(row, event)}
|
|
422
|
+
@keydown=${(event) => this.handleKeyDown(row, event)}
|
|
423
|
+
>
|
|
424
|
+
<oscd-ripple for=${row.htmlId} ?disabled=${disabled}></oscd-ripple>
|
|
425
|
+
<oscd-focus-ring for=${row.htmlId} inward></oscd-focus-ring>
|
|
426
|
+
<span part="indent" class="indent" aria-hidden="true"></span>
|
|
427
|
+
${this.togglePosition === 'leading'
|
|
428
|
+
? this.renderToggle(row, context)
|
|
429
|
+
: nothing}
|
|
430
|
+
${this.renderSelection(row)}
|
|
431
|
+
<span part="content" class="content"
|
|
432
|
+
>${(this.renderItem ?? fallbackRenderItem)(context)}</span
|
|
433
|
+
>
|
|
434
|
+
${this.togglePosition === 'trailing'
|
|
435
|
+
? this.renderToggle(row, context)
|
|
436
|
+
: nothing}
|
|
437
|
+
</div>`;
|
|
438
|
+
}
|
|
439
|
+
updated() {
|
|
440
|
+
const focusedAccessory = this.renderRoot instanceof ShadowRoot
|
|
441
|
+
? this.renderRoot.activeElement?.closest('.accessory')
|
|
442
|
+
: null;
|
|
443
|
+
if (focusedAccessory) {
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
const activeRow = this.renderRoot.querySelector('.row[data-active="true"]');
|
|
447
|
+
if (activeRow && this.matches(':focus-within')) {
|
|
448
|
+
activeRow.focus();
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
render() {
|
|
452
|
+
const rows = this.visibleRows();
|
|
453
|
+
return html `<div part="tree" class="tree" role="tree">
|
|
454
|
+
${rows.map(row => this.renderRow(row))}
|
|
455
|
+
</div>`;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
Tree.scopedElements = {
|
|
459
|
+
'oscd-checkbox': OscdCheckbox,
|
|
460
|
+
'oscd-focus-ring': OscdFocusRing,
|
|
461
|
+
'oscd-icon': OscdIcon,
|
|
462
|
+
'oscd-ripple': OscdRipple,
|
|
463
|
+
'oscd-tree-item': OscdTreeItem,
|
|
464
|
+
};
|
|
465
|
+
Tree.styles = css `
|
|
466
|
+
:host {
|
|
467
|
+
display: block;
|
|
468
|
+
/*
|
|
469
|
+
* Allow the tree to shrink below its content's intrinsic (max-content)
|
|
470
|
+
* width when placed in a flex or grid container. Without this, a single
|
|
471
|
+
* long row label leaks its max-content width up the layout chain and
|
|
472
|
+
* sizes every row to it, pushing trailing toggles/accessories out of a
|
|
473
|
+
* width-constrained parent and defeating the per-row ellipsis. Keeping
|
|
474
|
+
* this on the host makes the tree a well-behaved flex/grid child by
|
|
475
|
+
* default for every consumer.
|
|
476
|
+
*/
|
|
477
|
+
min-width: 0;
|
|
478
|
+
color: var(--oscd-tree-color, var(--md-sys-color-on-surface, #1d1b20));
|
|
479
|
+
font-family: var(
|
|
480
|
+
--oscd-tree-font-family,
|
|
481
|
+
var(--oscd-text-font, sans-serif)
|
|
482
|
+
);
|
|
483
|
+
outline: none;
|
|
484
|
+
/*
|
|
485
|
+
* Drives both the per-level indentation and the leading icon column width
|
|
486
|
+
* of each row (see OscdTreeItem). Keeping these fused means a leading icon
|
|
487
|
+
* occupies exactly one indent step, so icon-less descendants align their
|
|
488
|
+
* text under an iconed ancestor's text automatically. Set it large enough
|
|
489
|
+
* to hold your leading icon comfortably (e.g. 40px) when using icons.
|
|
490
|
+
*/
|
|
491
|
+
--oscd-tree-indent-step: 24px;
|
|
492
|
+
--oscd-tree-toggle-size: 32px;
|
|
493
|
+
--oscd-tree-toggle-icon-size: 24px;
|
|
494
|
+
--oscd-tree-row-height: 44px;
|
|
495
|
+
--oscd-tree-row-shape: var(--md-sys-shape-corner-small, 4px);
|
|
496
|
+
--md-ripple-hover-color: var(
|
|
497
|
+
--oscd-tree-row-hover-state-layer-color,
|
|
498
|
+
var(--md-sys-color-on-surface, #1d1b20)
|
|
499
|
+
);
|
|
500
|
+
--md-ripple-hover-opacity: var(
|
|
501
|
+
--oscd-tree-row-hover-state-layer-opacity,
|
|
502
|
+
0.08
|
|
503
|
+
);
|
|
504
|
+
--md-ripple-pressed-color: var(
|
|
505
|
+
--oscd-tree-row-pressed-state-layer-color,
|
|
506
|
+
var(--md-sys-color-on-surface, #1d1b20)
|
|
507
|
+
);
|
|
508
|
+
--md-ripple-pressed-opacity: var(
|
|
509
|
+
--oscd-tree-row-pressed-state-layer-opacity,
|
|
510
|
+
0.12
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
.tree {
|
|
515
|
+
display: flex;
|
|
516
|
+
flex-direction: column;
|
|
517
|
+
min-width: 0;
|
|
518
|
+
gap: var(--oscd-tree-row-gap, 0);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
.row {
|
|
522
|
+
position: relative;
|
|
523
|
+
display: flex;
|
|
524
|
+
align-items: center;
|
|
525
|
+
box-sizing: border-box;
|
|
526
|
+
min-width: 0;
|
|
527
|
+
min-height: var(--oscd-tree-row-height);
|
|
528
|
+
border-radius: var(--oscd-tree-row-shape);
|
|
529
|
+
color: inherit;
|
|
530
|
+
cursor: default;
|
|
531
|
+
outline: none;
|
|
532
|
+
padding-inline-start: var(--oscd-tree-row-padding-start, 16px);
|
|
533
|
+
padding-inline-end: var(--oscd-tree-row-padding-end, 8px);
|
|
534
|
+
user-select: none;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
oscd-ripple,
|
|
538
|
+
oscd-focus-ring {
|
|
539
|
+
border-radius: var(--oscd-tree-row-shape);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
oscd-focus-ring {
|
|
543
|
+
z-index: 1;
|
|
544
|
+
--md-focus-ring-shape: var(--oscd-tree-row-shape);
|
|
545
|
+
--md-focus-ring-color: var(
|
|
546
|
+
--oscd-tree-row-focus-ring-color,
|
|
547
|
+
var(--md-sys-color-primary, #6750a4)
|
|
548
|
+
);
|
|
549
|
+
--md-focus-ring-width: var(--oscd-tree-row-focus-ring-width, 2px);
|
|
550
|
+
--md-focus-ring-duration: var(--oscd-tree-row-focus-ring-duration, 0ms);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
.row[data-disabled='true'] {
|
|
554
|
+
cursor: default;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
.row[data-selection-mode='single'][data-selected='true'] {
|
|
558
|
+
color: var(--oscd-tree-row-selected-text-color, var(--oscd-base3, #fff));
|
|
559
|
+
background: var(
|
|
560
|
+
--oscd-tree-row-selected-color,
|
|
561
|
+
var(--oscd-primary, #0b335b)
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
.row[data-selection-mode='single'][data-selected='true']:hover:not(
|
|
566
|
+
[data-disabled='true']
|
|
567
|
+
) {
|
|
568
|
+
background: var(
|
|
569
|
+
--oscd-tree-row-selected-hover-color,
|
|
570
|
+
var(--oscd-tree-row-selected-color, var(--oscd-primary, #0b335b))
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
.indent {
|
|
575
|
+
flex: 0 0
|
|
576
|
+
calc(
|
|
577
|
+
max(0, var(--oscd-tree-row-level) - 1) * var(--oscd-tree-indent-step)
|
|
578
|
+
);
|
|
579
|
+
inline-size: calc(
|
|
580
|
+
max(0, var(--oscd-tree-row-level) - 1) * var(--oscd-tree-indent-step)
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
.toggle {
|
|
585
|
+
display: inline-flex;
|
|
586
|
+
align-items: center;
|
|
587
|
+
justify-content: center;
|
|
588
|
+
flex: 0 0 var(--oscd-tree-toggle-size);
|
|
589
|
+
inline-size: var(--oscd-tree-toggle-size);
|
|
590
|
+
block-size: var(--oscd-tree-toggle-size);
|
|
591
|
+
border: 0;
|
|
592
|
+
border-radius: 50%;
|
|
593
|
+
padding: 0;
|
|
594
|
+
color: inherit;
|
|
595
|
+
background: transparent;
|
|
596
|
+
cursor: pointer;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
.toggle:disabled {
|
|
600
|
+
cursor: default;
|
|
601
|
+
opacity: 0;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
:host([toggle-position='trailing']) .toggle {
|
|
605
|
+
margin-inline-start: var(--oscd-tree-trailing-toggle-gap, 4px);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
.toggle oscd-icon {
|
|
609
|
+
--md-icon-size: var(--oscd-tree-toggle-icon-size, 24px);
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
.accessory {
|
|
613
|
+
display: inline-flex;
|
|
614
|
+
align-items: center;
|
|
615
|
+
justify-content: center;
|
|
616
|
+
flex: 0 0 var(--oscd-tree-toggle-size);
|
|
617
|
+
inline-size: var(--oscd-tree-toggle-size);
|
|
618
|
+
block-size: var(--oscd-tree-toggle-size);
|
|
619
|
+
/*
|
|
620
|
+
* Accessory visibility at rest. Defaults to fully opaque so accessories
|
|
621
|
+
* are always shown; consumers can set --oscd-tree-accessory-rest-opacity
|
|
622
|
+
* to 0 for a reveal-on-interaction pattern. Row hover and keyboard focus
|
|
623
|
+
* within the accessory always force it fully visible so it stays
|
|
624
|
+
* discoverable and keyboard-accessible.
|
|
625
|
+
*/
|
|
626
|
+
opacity: var(--oscd-tree-accessory-rest-opacity, 1);
|
|
627
|
+
transition: opacity 0.1s ease-in-out;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
.row:hover .accessory,
|
|
631
|
+
.accessory:focus-within {
|
|
632
|
+
opacity: 1;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
:host([toggle-position='trailing']) .accessory {
|
|
636
|
+
margin-inline-start: var(--oscd-tree-trailing-toggle-gap, 4px);
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
.accessory oscd-icon {
|
|
640
|
+
--md-icon-size: var(
|
|
641
|
+
--oscd-tree-accessory-icon-size,
|
|
642
|
+
var(--oscd-tree-toggle-icon-size, 24px)
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
.accessory button {
|
|
647
|
+
display: inline-flex;
|
|
648
|
+
align-items: center;
|
|
649
|
+
justify-content: center;
|
|
650
|
+
inline-size: var(--oscd-tree-toggle-size);
|
|
651
|
+
block-size: var(--oscd-tree-toggle-size);
|
|
652
|
+
border: 0;
|
|
653
|
+
border-radius: 50%;
|
|
654
|
+
padding: 0;
|
|
655
|
+
color: inherit;
|
|
656
|
+
background: transparent;
|
|
657
|
+
cursor: pointer;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
.selection {
|
|
661
|
+
display: inline-flex;
|
|
662
|
+
align-items: center;
|
|
663
|
+
justify-content: center;
|
|
664
|
+
flex: 0 0 var(--oscd-tree-selection-size, 48px);
|
|
665
|
+
inline-size: var(--oscd-tree-selection-size, 48px);
|
|
666
|
+
pointer-events: none;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
.selection oscd-checkbox {
|
|
670
|
+
pointer-events: none;
|
|
671
|
+
--md-focus-ring-width: 0;
|
|
672
|
+
--md-ripple-hover-opacity: 0;
|
|
673
|
+
--md-ripple-pressed-opacity: 0;
|
|
674
|
+
--md-checkbox-container-size: var(
|
|
675
|
+
--oscd-tree-selection-checkbox-size,
|
|
676
|
+
18px
|
|
677
|
+
);
|
|
678
|
+
--md-checkbox-icon-size: var(
|
|
679
|
+
--oscd-tree-selection-checkbox-icon-size,
|
|
680
|
+
18px
|
|
681
|
+
);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
.content {
|
|
685
|
+
display: block;
|
|
686
|
+
flex: 1 1 auto;
|
|
687
|
+
min-width: 0;
|
|
688
|
+
}
|
|
689
|
+
`;
|
|
690
|
+
__decorate([
|
|
691
|
+
property({ attribute: false })
|
|
692
|
+
], Tree.prototype, "data", void 0);
|
|
693
|
+
__decorate([
|
|
694
|
+
property({ attribute: false })
|
|
695
|
+
], Tree.prototype, "selectedIds", void 0);
|
|
696
|
+
__decorate([
|
|
697
|
+
property({ attribute: false })
|
|
698
|
+
], Tree.prototype, "expandedIds", void 0);
|
|
699
|
+
__decorate([
|
|
700
|
+
property({ attribute: false })
|
|
701
|
+
], Tree.prototype, "renderItem", void 0);
|
|
702
|
+
__decorate([
|
|
703
|
+
property({ attribute: false })
|
|
704
|
+
], Tree.prototype, "renderLeafAccessory", void 0);
|
|
705
|
+
__decorate([
|
|
706
|
+
property({ attribute: false })
|
|
707
|
+
], Tree.prototype, "getNodeId", void 0);
|
|
708
|
+
__decorate([
|
|
709
|
+
property({ attribute: false })
|
|
710
|
+
], Tree.prototype, "getNodeLabel", void 0);
|
|
711
|
+
__decorate([
|
|
712
|
+
property({ attribute: false })
|
|
713
|
+
], Tree.prototype, "isSelectable", void 0);
|
|
714
|
+
__decorate([
|
|
715
|
+
property({ attribute: false })
|
|
716
|
+
], Tree.prototype, "isDisabled", void 0);
|
|
717
|
+
__decorate([
|
|
718
|
+
property()
|
|
719
|
+
], Tree.prototype, "selectionMode", void 0);
|
|
720
|
+
__decorate([
|
|
721
|
+
property({ attribute: 'collapse-icon' })
|
|
722
|
+
], Tree.prototype, "collapseIcon", void 0);
|
|
723
|
+
__decorate([
|
|
724
|
+
property({ attribute: 'expand-icon' })
|
|
725
|
+
], Tree.prototype, "expandIcon", void 0);
|
|
726
|
+
__decorate([
|
|
727
|
+
property({ reflect: true, attribute: 'toggle-position' })
|
|
728
|
+
], Tree.prototype, "togglePosition", void 0);
|
|
729
|
+
__decorate([
|
|
730
|
+
state()
|
|
731
|
+
], Tree.prototype, "activeId", void 0);
|
|
732
|
+
//# sourceMappingURL=Tree.js.map
|