@vonage/vivid 3.28.2 → 3.30.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/custom-elements.json +400 -2
- package/index.js +13 -12
- package/lib/components.d.ts +1 -0
- package/lib/icon/icon.d.ts +1 -1
- package/lib/menu/menu.d.ts +1 -1
- package/lib/split-button/definition.d.ts +2 -0
- package/lib/split-button/index.d.ts +1 -0
- package/lib/split-button/split-button.d.ts +25 -0
- package/lib/split-button/split-button.template.d.ts +4 -0
- package/listbox/index.js +1 -1
- package/package.json +1 -1
- package/shared/definition.js +1 -1
- package/shared/definition10.js +1 -1
- package/shared/definition11.js +1 -1
- package/shared/definition12.js +1 -1
- package/shared/definition14.js +1 -1
- package/shared/definition15.js +1 -1
- package/shared/definition16.js +1 -1
- package/shared/definition17.js +1 -1
- package/shared/definition18.js +1 -1
- package/shared/definition19.js +1 -1
- package/shared/definition2.js +1 -1
- package/shared/definition21.js +1 -1
- package/shared/definition22.js +2 -2
- package/shared/definition23.js +1 -1
- package/shared/definition24.js +1 -1
- package/shared/definition25.js +1 -1
- package/shared/definition26.js +1 -1
- package/shared/definition27.js +1 -1
- package/shared/definition28.js +1 -1
- package/shared/definition30.js +7 -2
- package/shared/definition31.js +1 -1
- package/shared/definition33.js +1 -1
- package/shared/definition34.js +1 -1
- package/shared/definition35.js +1 -1
- package/shared/definition36.js +1 -1
- package/shared/definition37.js +1 -1
- package/shared/definition38.js +1 -1
- package/shared/definition39.js +1 -1
- package/shared/definition4.js +1 -1
- package/shared/definition40.js +1 -1
- package/shared/definition41.js +1 -1
- package/shared/definition42.js +1 -1
- package/shared/definition44.js +91 -126
- package/shared/definition45.js +123 -49
- package/shared/definition46.js +56 -16
- package/shared/definition47.js +16 -483
- package/shared/definition48.js +476 -96
- package/shared/definition49.js +108 -16
- package/shared/definition5.js +1 -1
- package/shared/definition50.js +15 -270
- package/shared/definition51.js +245 -89
- package/shared/definition52.js +113 -120
- package/shared/definition53.js +91 -82
- package/shared/definition54.js +111 -65
- package/shared/definition55.js +64 -291
- package/shared/definition56.js +303 -0
- package/shared/definition6.js +1 -1
- package/shared/definition7.js +1 -1
- package/shared/definition9.js +1 -1
- package/shared/form-elements.js +1 -1
- package/shared/icon.js +1 -1
- package/shared/patterns/form-elements/form-elements.d.ts +4 -4
- package/shared/text-field.js +1 -1
- package/split-button/index.js +15 -0
- package/styles/core/all.css +1 -1
- package/styles/core/theme.css +1 -1
- package/styles/core/typography.css +1 -1
- package/styles/tokens/theme-dark.css +4 -4
- package/styles/tokens/theme-light.css +4 -4
- package/switch/index.js +1 -1
- package/tab/index.js +1 -1
- package/tab-panel/index.js +1 -1
- package/tabs/index.js +3 -3
- package/tag/index.js +1 -1
- package/tag-group/index.js +1 -1
- package/text-area/index.js +1 -1
- package/text-field/index.js +1 -1
- package/toggletip/index.js +1 -1
- package/tooltip/index.js +1 -1
- package/tree-item/index.js +1 -1
- package/tree-view/index.js +1 -1
- package/vivid.api.json +287 -0
package/shared/definition55.js
CHANGED
|
@@ -1,303 +1,76 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { _ as __decorate, a as attr, b as __metadata, h as html, r as registerFactory } from './index.js';
|
|
2
|
+
import { i as iconRegistries } from './definition3.js';
|
|
3
|
+
import { f as focusRegistries } from './definition4.js';
|
|
4
|
+
import { b as AffixIcon, a as affixIconTemplateFactory } from './affix.js';
|
|
5
|
+
import { T as TreeItem$1 } from './tree-item.js';
|
|
6
|
+
import { a as applyMixins } from './apply-mixins.js';
|
|
7
|
+
import { I as Icon } from './icon.js';
|
|
8
|
+
import { f as focusTemplateFactory } from './focus2.js';
|
|
9
|
+
import { e as elements } from './node-observation.js';
|
|
10
|
+
import { c as children } from './children.js';
|
|
11
|
+
import { w as when } from './when.js';
|
|
6
12
|
import { s as slotted } from './slotted.js';
|
|
7
13
|
import { c as classNames } from './class-names.js';
|
|
14
|
+
import { r as ref } from './ref.js';
|
|
8
15
|
|
|
9
|
-
|
|
10
|
-
* A Tree view Custom HTML Element.
|
|
11
|
-
* Implements the {@link https://w3c.github.io/aria-practices/#TreeView | ARIA TreeView }.
|
|
12
|
-
*
|
|
13
|
-
* @slot - The default slot for tree items
|
|
14
|
-
*
|
|
15
|
-
* @public
|
|
16
|
-
*/
|
|
17
|
-
class TreeView$1 extends FoundationElement {
|
|
18
|
-
constructor() {
|
|
19
|
-
super(...arguments);
|
|
20
|
-
/**
|
|
21
|
-
* The tree item that is designated to be in the tab queue.
|
|
22
|
-
*
|
|
23
|
-
* @internal
|
|
24
|
-
*/
|
|
25
|
-
this.currentFocused = null;
|
|
26
|
-
/**
|
|
27
|
-
* Handle focus events
|
|
28
|
-
*
|
|
29
|
-
* @internal
|
|
30
|
-
*/
|
|
31
|
-
this.handleFocus = (e) => {
|
|
32
|
-
if (this.slottedTreeItems.length < 1) {
|
|
33
|
-
// no child items, nothing to do
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
if (e.target === this) {
|
|
37
|
-
if (this.currentFocused === null) {
|
|
38
|
-
this.currentFocused = this.getValidFocusableItem();
|
|
39
|
-
}
|
|
40
|
-
if (this.currentFocused !== null) {
|
|
41
|
-
TreeItem.focusItem(this.currentFocused);
|
|
42
|
-
}
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
if (this.contains(e.target)) {
|
|
46
|
-
this.setAttribute("tabindex", "-1");
|
|
47
|
-
this.currentFocused = e.target;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* Handle blur events
|
|
52
|
-
*
|
|
53
|
-
* @internal
|
|
54
|
-
*/
|
|
55
|
-
this.handleBlur = (e) => {
|
|
56
|
-
if (e.target instanceof HTMLElement &&
|
|
57
|
-
(e.relatedTarget === null || !this.contains(e.relatedTarget))) {
|
|
58
|
-
this.setAttribute("tabindex", "0");
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* KeyDown handler
|
|
63
|
-
*
|
|
64
|
-
* @internal
|
|
65
|
-
*/
|
|
66
|
-
this.handleKeyDown = (e) => {
|
|
67
|
-
if (e.defaultPrevented) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (this.slottedTreeItems.length < 1) {
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
const treeItems = this.getVisibleNodes();
|
|
74
|
-
switch (e.key) {
|
|
75
|
-
case keyHome:
|
|
76
|
-
if (treeItems.length) {
|
|
77
|
-
TreeItem.focusItem(treeItems[0]);
|
|
78
|
-
}
|
|
79
|
-
return;
|
|
80
|
-
case keyEnd:
|
|
81
|
-
if (treeItems.length) {
|
|
82
|
-
TreeItem.focusItem(treeItems[treeItems.length - 1]);
|
|
83
|
-
}
|
|
84
|
-
return;
|
|
85
|
-
case keyArrowLeft:
|
|
86
|
-
if (e.target && this.isFocusableElement(e.target)) {
|
|
87
|
-
const item = e.target;
|
|
88
|
-
if (item instanceof TreeItem &&
|
|
89
|
-
item.childItemLength() > 0 &&
|
|
90
|
-
item.expanded) {
|
|
91
|
-
item.expanded = false;
|
|
92
|
-
}
|
|
93
|
-
else if (item instanceof TreeItem &&
|
|
94
|
-
item.parentElement instanceof TreeItem) {
|
|
95
|
-
TreeItem.focusItem(item.parentElement);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return false;
|
|
99
|
-
case keyArrowRight:
|
|
100
|
-
if (e.target && this.isFocusableElement(e.target)) {
|
|
101
|
-
const item = e.target;
|
|
102
|
-
if (item instanceof TreeItem &&
|
|
103
|
-
item.childItemLength() > 0 &&
|
|
104
|
-
!item.expanded) {
|
|
105
|
-
item.expanded = true;
|
|
106
|
-
}
|
|
107
|
-
else if (item instanceof TreeItem && item.childItemLength() > 0) {
|
|
108
|
-
this.focusNextNode(1, e.target);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return;
|
|
112
|
-
case keyArrowDown:
|
|
113
|
-
if (e.target && this.isFocusableElement(e.target)) {
|
|
114
|
-
this.focusNextNode(1, e.target);
|
|
115
|
-
}
|
|
116
|
-
return;
|
|
117
|
-
case keyArrowUp:
|
|
118
|
-
if (e.target && this.isFocusableElement(e.target)) {
|
|
119
|
-
this.focusNextNode(-1, e.target);
|
|
120
|
-
}
|
|
121
|
-
return;
|
|
122
|
-
case keyEnter:
|
|
123
|
-
// In single-select trees where selection does not follow focus (see note below),
|
|
124
|
-
// the default action is typically to select the focused node.
|
|
125
|
-
this.handleClick(e);
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
// don't prevent default if we took no action
|
|
129
|
-
return true;
|
|
130
|
-
};
|
|
131
|
-
/**
|
|
132
|
-
* Handles the selected-changed events bubbling up
|
|
133
|
-
* from child tree items
|
|
134
|
-
*
|
|
135
|
-
* @internal
|
|
136
|
-
*/
|
|
137
|
-
this.handleSelectedChange = (e) => {
|
|
138
|
-
if (e.defaultPrevented) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
if (!(e.target instanceof Element) || !isTreeItemElement(e.target)) {
|
|
142
|
-
return true;
|
|
143
|
-
}
|
|
144
|
-
const item = e.target;
|
|
145
|
-
if (item.selected) {
|
|
146
|
-
if (this.currentSelected && this.currentSelected !== item) {
|
|
147
|
-
this.currentSelected.selected = false;
|
|
148
|
-
}
|
|
149
|
-
// new selected item
|
|
150
|
-
this.currentSelected = item;
|
|
151
|
-
}
|
|
152
|
-
else if (!item.selected && this.currentSelected === item) {
|
|
153
|
-
// selected item deselected
|
|
154
|
-
this.currentSelected = null;
|
|
155
|
-
}
|
|
156
|
-
return;
|
|
157
|
-
};
|
|
158
|
-
/**
|
|
159
|
-
* Updates the tree view when slottedTreeItems changes
|
|
160
|
-
*/
|
|
161
|
-
this.setItems = () => {
|
|
162
|
-
// force single selection
|
|
163
|
-
// defaults to first one found
|
|
164
|
-
const selectedItem = this.treeView.querySelector("[aria-selected='true']");
|
|
165
|
-
this.currentSelected = selectedItem;
|
|
166
|
-
// invalidate the current focused item if it is no longer valid
|
|
167
|
-
if (this.currentFocused === null || !this.contains(this.currentFocused)) {
|
|
168
|
-
this.currentFocused = this.getValidFocusableItem();
|
|
169
|
-
}
|
|
170
|
-
// toggle properties on child elements
|
|
171
|
-
this.nested = this.checkForNestedItems();
|
|
172
|
-
const treeItems = this.getVisibleNodes();
|
|
173
|
-
treeItems.forEach(node => {
|
|
174
|
-
if (isTreeItemElement(node)) {
|
|
175
|
-
node.nested = this.nested;
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
};
|
|
179
|
-
/**
|
|
180
|
-
* check if the item is focusable
|
|
181
|
-
*/
|
|
182
|
-
this.isFocusableElement = (el) => {
|
|
183
|
-
return isTreeItemElement(el);
|
|
184
|
-
};
|
|
185
|
-
this.isSelectedElement = (el) => {
|
|
186
|
-
return el.selected;
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
slottedTreeItemsChanged() {
|
|
190
|
-
if (this.$fastController.isConnected) {
|
|
191
|
-
// update for slotted children change
|
|
192
|
-
this.setItems();
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
connectedCallback() {
|
|
196
|
-
super.connectedCallback();
|
|
197
|
-
this.setAttribute("tabindex", "0");
|
|
198
|
-
DOM.queueUpdate(() => {
|
|
199
|
-
this.setItems();
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Handles click events bubbling up
|
|
204
|
-
*
|
|
205
|
-
* @internal
|
|
206
|
-
*/
|
|
207
|
-
handleClick(e) {
|
|
208
|
-
if (e.defaultPrevented) {
|
|
209
|
-
// handled, do nothing
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
if (!(e.target instanceof Element) || !isTreeItemElement(e.target)) {
|
|
213
|
-
// not a tree item, ignore
|
|
214
|
-
return true;
|
|
215
|
-
}
|
|
216
|
-
const item = e.target;
|
|
217
|
-
if (!item.disabled) {
|
|
218
|
-
item.selected = !item.selected;
|
|
219
|
-
}
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Move focus to a tree item based on its offset from the provided item
|
|
224
|
-
*/
|
|
225
|
-
focusNextNode(delta, item) {
|
|
226
|
-
const visibleNodes = this.getVisibleNodes();
|
|
227
|
-
if (!visibleNodes) {
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
const focusItem = visibleNodes[visibleNodes.indexOf(item) + delta];
|
|
231
|
-
if (isHTMLElement(focusItem)) {
|
|
232
|
-
TreeItem.focusItem(focusItem);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* checks if there are any nested tree items
|
|
237
|
-
*/
|
|
238
|
-
getValidFocusableItem() {
|
|
239
|
-
const treeItems = this.getVisibleNodes();
|
|
240
|
-
// default to selected element if there is one
|
|
241
|
-
let focusIndex = treeItems.findIndex(this.isSelectedElement);
|
|
242
|
-
if (focusIndex === -1) {
|
|
243
|
-
// otherwise first focusable tree item
|
|
244
|
-
focusIndex = treeItems.findIndex(this.isFocusableElement);
|
|
245
|
-
}
|
|
246
|
-
if (focusIndex !== -1) {
|
|
247
|
-
return treeItems[focusIndex];
|
|
248
|
-
}
|
|
249
|
-
return null;
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* checks if there are any nested tree items
|
|
253
|
-
*/
|
|
254
|
-
checkForNestedItems() {
|
|
255
|
-
return this.slottedTreeItems.some((node) => {
|
|
256
|
-
return isTreeItemElement(node) && node.querySelector("[role='treeitem']");
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
getVisibleNodes() {
|
|
260
|
-
return getDisplayedNodes(this, "[role='treeitem']") || [];
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
__decorate([
|
|
264
|
-
attr({ attribute: "render-collapsed-nodes" })
|
|
265
|
-
], TreeView$1.prototype, "renderCollapsedNodes", void 0);
|
|
266
|
-
__decorate([
|
|
267
|
-
observable
|
|
268
|
-
], TreeView$1.prototype, "currentSelected", void 0);
|
|
269
|
-
__decorate([
|
|
270
|
-
observable
|
|
271
|
-
], TreeView$1.prototype, "slottedTreeItems", void 0);
|
|
272
|
-
|
|
273
|
-
var css_248z = ".control {\n position: relative;\n display: flex;\n flex-direction: column;\n gap: 4px;\n}";
|
|
16
|
+
var css_248z = "/**\n * Do not edit directly\n * Generated on Mon, 14 Aug 2023 13:17:40 GMT\n */\n@supports selector(:focus-visible) {\n :host(:focus) {\n outline: none;\n }\n}\n.control {\n position: relative;\n display: inline-flex;\n box-sizing: border-box;\n align-items: center;\n background-color: var(--_appearance-color-fill);\n border-radius: 6px;\n box-shadow: inset 0 0 0 1px var(--_appearance-color-outline);\n color: var(--_appearance-color-text);\n font: var(--vvd-typography-base);\n gap: 12px;\n hyphens: auto;\n inline-size: 100%;\n min-block-size: calc(1px * (40 + 4 * clamp(-1, var(--vvd-size-density, 0), 2)));\n padding-inline: 16px;\n text-decoration: none;\n vertical-align: middle;\n word-break: break-word;\n}\n.control {\n --_appearance-color-text: var(--_connotation-color-primary);\n --_appearance-color-fill: transparent;\n --_appearance-color-outline: transparent;\n}\n.control:where(:disabled, .disabled) {\n --_appearance-color-text: var(--vvd-color-neutral-300);\n --_appearance-color-fill: transparent;\n --_appearance-color-outline: transparent;\n}\n.control:where(:hover, .hover):where(:not(:disabled, .disabled, .readonly)) {\n --_appearance-color-text: var(--_connotation-color-primary);\n --_appearance-color-fill: var(--_connotation-color-faint);\n --_appearance-color-outline: transparent;\n}\n.control:where(:active, .active):where(:not(:disabled, .disabled)) {\n --_appearance-color-text: var(--_connotation-color-primary);\n --_appearance-color-fill: var(--_connotation-color-soft);\n --_appearance-color-outline: transparent;\n}\n.control:where(.selected, [aria-current]):where(:not(:disabled, .disabled, :hover, .hover)) {\n --_appearance-color-text: var(--_connotation-color-primary-text);\n --_appearance-color-fill: var(--_connotation-color-primary);\n --_appearance-color-outline: transparent;\n}\n.control:where(.selected, [aria-current]):where(:hover, .hover) {\n --_appearance-color-text: var(--_connotation-color-primary-text);\n --_appearance-color-fill: var(--_connotation-color-primary-increment);\n --_appearance-color-outline: transparent;\n}\n.control {\n /* @cssprop [--vvd-tree-item-accent-primary=var(--vvd-color-canvas-text)] */\n --_connotation-color-primary: var(--vvd-tree-item-accent-primary, var(--vvd-color-canvas-text));\n /* @cssprop [--vvd-tree-item-accent-primary-text=var(--vvd-color-canvas)] */\n --_connotation-color-primary-text: var(--vvd-tree-item-accent-primary-text, var(--vvd-color-canvas));\n /* @cssprop [--vvd-tree-item-accent-primary-increment=var(--vvd-color-neutral-800)] */\n --_connotation-color-primary-increment: var(--vvd-tree-item-accent-primary-increment, var(--vvd-color-neutral-800));\n /* @cssprop [--vvd-tree-item-accent-faint=var(--vvd-color-neutral-50)] */\n --_connotation-color-faint: var(--vvd-tree-item-accent-faint, var(--vvd-color-neutral-50));\n /* @cssprop [--vvd-tree-item-accent-soft=var(--vvd-color-neutral-100)] */\n --_connotation-color-soft: var(--vvd-tree-item-accent-soft, var(--vvd-color-neutral-100));\n}\n@supports selector(:focus-visible) {\n .control:focus {\n outline: none;\n }\n}\n@supports (user-select: none) {\n .control {\n user-select: none;\n }\n}\n.control:not(.disabled) {\n cursor: pointer;\n}\n.control.disabled {\n cursor: not-allowed;\n pointer-events: none;\n}\n.control .text {\n font: var(--vvd-typography-base);\n}\n\n.expandCollapseButton {\n display: flex;\n align-items: center;\n border-radius: 6px;\n font-size: 20px;\n}\n.expandCollapseButton .expandCollapseIcon {\n margin: 4px;\n}\n.expandCollapseButton:hover {\n background-color: var(--vvd-color-neutral-100);\n}\n\n.items {\n display: flex;\n flex-direction: column;\n gap: 4px;\n margin-block: 4px;\n padding-inline-start: 48px;\n}\n\n:host(:not(:focus-visible)) .focus-indicator {\n display: none;\n}\n\n.icon {\n font-size: 20px;\n line-height: 1;\n}\n.control:not(.disabled, .selected) .icon {\n color: var(--vvd-color-neutral-600);\n}";
|
|
274
17
|
|
|
275
|
-
class
|
|
18
|
+
class TreeItem extends TreeItem$1 {}
|
|
19
|
+
__decorate([attr, __metadata("design:type", String)], TreeItem.prototype, "text", void 0);
|
|
20
|
+
applyMixins(TreeItem, AffixIcon);
|
|
276
21
|
|
|
277
|
-
const getClasses =
|
|
278
|
-
|
|
22
|
+
const getClasses = ({
|
|
23
|
+
disabled,
|
|
24
|
+
selected
|
|
25
|
+
}) => classNames('control', ['disabled', disabled], ['selected', Boolean(selected)]);
|
|
26
|
+
const expandCollapseButton = context => {
|
|
27
|
+
const iconTag = context.tagFor(Icon);
|
|
28
|
+
return html`
|
|
29
|
+
<div aria-hidden="true"
|
|
30
|
+
class="expandCollapseButton"
|
|
31
|
+
@click="${(x, c) => x.handleExpandCollapseButtonClick(c.event)}"
|
|
32
|
+
${ref('expandCollapseButton')}
|
|
33
|
+
>
|
|
34
|
+
<${iconTag} class="expandCollapseIcon" name="${x => x.expanded ? 'chevron-down-line' : 'chevron-right-line'}"></${iconTag}>
|
|
35
|
+
</div>`;
|
|
36
|
+
};
|
|
37
|
+
const TreeItemTemplate = context => {
|
|
38
|
+
const affixIconTemplate = affixIconTemplateFactory(context);
|
|
39
|
+
const focusTemplate = focusTemplateFactory(context);
|
|
279
40
|
return html`
|
|
280
41
|
<template
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
42
|
+
role="treeitem"
|
|
43
|
+
slot="${x => x.isNestedItem() ? 'item' : void 0}"
|
|
44
|
+
tabindex="-1"
|
|
45
|
+
aria-expanded="${x => x.childItems && x.childItems.length > 0 ? x.expanded : void 0}"
|
|
46
|
+
aria-selected="${x => x.selected}"
|
|
47
|
+
aria-disabled="${x => x.disabled}"
|
|
48
|
+
@focusin="${(x, c) => x.handleFocus(c.event)}"
|
|
49
|
+
@focusout="${(x, c) => x.handleBlur(c.event)}"
|
|
50
|
+
${children({
|
|
51
|
+
property: 'childItems',
|
|
52
|
+
filter: elements()
|
|
53
|
+
})}
|
|
54
|
+
>
|
|
55
|
+
<div class="${getClasses}">
|
|
56
|
+
${() => focusTemplate}
|
|
57
|
+
${when(x => x.childItems && x.childItems.length > 0, expandCollapseButton(context))}
|
|
58
|
+
${x => affixIconTemplate(x.icon)}
|
|
59
|
+
${x => x.text}
|
|
60
|
+
</div>
|
|
61
|
+
${when(x => x.childItems && x.childItems.length > 0 && x.expanded, html`
|
|
62
|
+
<div role="group" class="items">
|
|
63
|
+
<slot name="item" ${slotted('items')}></slot>
|
|
64
|
+
</div>`)}
|
|
65
|
+
</template>`;
|
|
293
66
|
};
|
|
294
67
|
|
|
295
|
-
const
|
|
296
|
-
baseName: 'tree-
|
|
297
|
-
template:
|
|
68
|
+
const treeItemDefinition = TreeItem.compose({
|
|
69
|
+
baseName: 'tree-item',
|
|
70
|
+
template: TreeItemTemplate,
|
|
298
71
|
styles: css_248z
|
|
299
72
|
});
|
|
300
|
-
const
|
|
301
|
-
const
|
|
73
|
+
const treeItemRegistries = [treeItemDefinition(), ...iconRegistries, ...focusRegistries];
|
|
74
|
+
const registerTreeItem = registerFactory(treeItemRegistries);
|
|
302
75
|
|
|
303
|
-
export {
|
|
76
|
+
export { treeItemRegistries as a, registerTreeItem as r, treeItemDefinition as t };
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { F as FoundationElement, D as DOM, _ as __decorate, a as attr, o as observable, h as html, r as registerFactory } from './index.js';
|
|
2
|
+
import { T as TreeItem, i as isTreeItemElement } from './tree-item.js';
|
|
3
|
+
import { i as isHTMLElement, g as getDisplayedNodes } from './dom.js';
|
|
4
|
+
import { d as keyEnter, c as keyArrowUp, b as keyArrowDown, h as keyArrowRight, i as keyArrowLeft, k as keyEnd, a as keyHome } from './key-codes.js';
|
|
5
|
+
import { r as ref } from './ref.js';
|
|
6
|
+
import { s as slotted } from './slotted.js';
|
|
7
|
+
import { c as classNames } from './class-names.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A Tree view Custom HTML Element.
|
|
11
|
+
* Implements the {@link https://w3c.github.io/aria-practices/#TreeView | ARIA TreeView }.
|
|
12
|
+
*
|
|
13
|
+
* @slot - The default slot for tree items
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
class TreeView$1 extends FoundationElement {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(...arguments);
|
|
20
|
+
/**
|
|
21
|
+
* The tree item that is designated to be in the tab queue.
|
|
22
|
+
*
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
this.currentFocused = null;
|
|
26
|
+
/**
|
|
27
|
+
* Handle focus events
|
|
28
|
+
*
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
this.handleFocus = (e) => {
|
|
32
|
+
if (this.slottedTreeItems.length < 1) {
|
|
33
|
+
// no child items, nothing to do
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (e.target === this) {
|
|
37
|
+
if (this.currentFocused === null) {
|
|
38
|
+
this.currentFocused = this.getValidFocusableItem();
|
|
39
|
+
}
|
|
40
|
+
if (this.currentFocused !== null) {
|
|
41
|
+
TreeItem.focusItem(this.currentFocused);
|
|
42
|
+
}
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (this.contains(e.target)) {
|
|
46
|
+
this.setAttribute("tabindex", "-1");
|
|
47
|
+
this.currentFocused = e.target;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Handle blur events
|
|
52
|
+
*
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
this.handleBlur = (e) => {
|
|
56
|
+
if (e.target instanceof HTMLElement &&
|
|
57
|
+
(e.relatedTarget === null || !this.contains(e.relatedTarget))) {
|
|
58
|
+
this.setAttribute("tabindex", "0");
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* KeyDown handler
|
|
63
|
+
*
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
this.handleKeyDown = (e) => {
|
|
67
|
+
if (e.defaultPrevented) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (this.slottedTreeItems.length < 1) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
const treeItems = this.getVisibleNodes();
|
|
74
|
+
switch (e.key) {
|
|
75
|
+
case keyHome:
|
|
76
|
+
if (treeItems.length) {
|
|
77
|
+
TreeItem.focusItem(treeItems[0]);
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
case keyEnd:
|
|
81
|
+
if (treeItems.length) {
|
|
82
|
+
TreeItem.focusItem(treeItems[treeItems.length - 1]);
|
|
83
|
+
}
|
|
84
|
+
return;
|
|
85
|
+
case keyArrowLeft:
|
|
86
|
+
if (e.target && this.isFocusableElement(e.target)) {
|
|
87
|
+
const item = e.target;
|
|
88
|
+
if (item instanceof TreeItem &&
|
|
89
|
+
item.childItemLength() > 0 &&
|
|
90
|
+
item.expanded) {
|
|
91
|
+
item.expanded = false;
|
|
92
|
+
}
|
|
93
|
+
else if (item instanceof TreeItem &&
|
|
94
|
+
item.parentElement instanceof TreeItem) {
|
|
95
|
+
TreeItem.focusItem(item.parentElement);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
case keyArrowRight:
|
|
100
|
+
if (e.target && this.isFocusableElement(e.target)) {
|
|
101
|
+
const item = e.target;
|
|
102
|
+
if (item instanceof TreeItem &&
|
|
103
|
+
item.childItemLength() > 0 &&
|
|
104
|
+
!item.expanded) {
|
|
105
|
+
item.expanded = true;
|
|
106
|
+
}
|
|
107
|
+
else if (item instanceof TreeItem && item.childItemLength() > 0) {
|
|
108
|
+
this.focusNextNode(1, e.target);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return;
|
|
112
|
+
case keyArrowDown:
|
|
113
|
+
if (e.target && this.isFocusableElement(e.target)) {
|
|
114
|
+
this.focusNextNode(1, e.target);
|
|
115
|
+
}
|
|
116
|
+
return;
|
|
117
|
+
case keyArrowUp:
|
|
118
|
+
if (e.target && this.isFocusableElement(e.target)) {
|
|
119
|
+
this.focusNextNode(-1, e.target);
|
|
120
|
+
}
|
|
121
|
+
return;
|
|
122
|
+
case keyEnter:
|
|
123
|
+
// In single-select trees where selection does not follow focus (see note below),
|
|
124
|
+
// the default action is typically to select the focused node.
|
|
125
|
+
this.handleClick(e);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
// don't prevent default if we took no action
|
|
129
|
+
return true;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Handles the selected-changed events bubbling up
|
|
133
|
+
* from child tree items
|
|
134
|
+
*
|
|
135
|
+
* @internal
|
|
136
|
+
*/
|
|
137
|
+
this.handleSelectedChange = (e) => {
|
|
138
|
+
if (e.defaultPrevented) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (!(e.target instanceof Element) || !isTreeItemElement(e.target)) {
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
const item = e.target;
|
|
145
|
+
if (item.selected) {
|
|
146
|
+
if (this.currentSelected && this.currentSelected !== item) {
|
|
147
|
+
this.currentSelected.selected = false;
|
|
148
|
+
}
|
|
149
|
+
// new selected item
|
|
150
|
+
this.currentSelected = item;
|
|
151
|
+
}
|
|
152
|
+
else if (!item.selected && this.currentSelected === item) {
|
|
153
|
+
// selected item deselected
|
|
154
|
+
this.currentSelected = null;
|
|
155
|
+
}
|
|
156
|
+
return;
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* Updates the tree view when slottedTreeItems changes
|
|
160
|
+
*/
|
|
161
|
+
this.setItems = () => {
|
|
162
|
+
// force single selection
|
|
163
|
+
// defaults to first one found
|
|
164
|
+
const selectedItem = this.treeView.querySelector("[aria-selected='true']");
|
|
165
|
+
this.currentSelected = selectedItem;
|
|
166
|
+
// invalidate the current focused item if it is no longer valid
|
|
167
|
+
if (this.currentFocused === null || !this.contains(this.currentFocused)) {
|
|
168
|
+
this.currentFocused = this.getValidFocusableItem();
|
|
169
|
+
}
|
|
170
|
+
// toggle properties on child elements
|
|
171
|
+
this.nested = this.checkForNestedItems();
|
|
172
|
+
const treeItems = this.getVisibleNodes();
|
|
173
|
+
treeItems.forEach(node => {
|
|
174
|
+
if (isTreeItemElement(node)) {
|
|
175
|
+
node.nested = this.nested;
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* check if the item is focusable
|
|
181
|
+
*/
|
|
182
|
+
this.isFocusableElement = (el) => {
|
|
183
|
+
return isTreeItemElement(el);
|
|
184
|
+
};
|
|
185
|
+
this.isSelectedElement = (el) => {
|
|
186
|
+
return el.selected;
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
slottedTreeItemsChanged() {
|
|
190
|
+
if (this.$fastController.isConnected) {
|
|
191
|
+
// update for slotted children change
|
|
192
|
+
this.setItems();
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
connectedCallback() {
|
|
196
|
+
super.connectedCallback();
|
|
197
|
+
this.setAttribute("tabindex", "0");
|
|
198
|
+
DOM.queueUpdate(() => {
|
|
199
|
+
this.setItems();
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Handles click events bubbling up
|
|
204
|
+
*
|
|
205
|
+
* @internal
|
|
206
|
+
*/
|
|
207
|
+
handleClick(e) {
|
|
208
|
+
if (e.defaultPrevented) {
|
|
209
|
+
// handled, do nothing
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (!(e.target instanceof Element) || !isTreeItemElement(e.target)) {
|
|
213
|
+
// not a tree item, ignore
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
const item = e.target;
|
|
217
|
+
if (!item.disabled) {
|
|
218
|
+
item.selected = !item.selected;
|
|
219
|
+
}
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Move focus to a tree item based on its offset from the provided item
|
|
224
|
+
*/
|
|
225
|
+
focusNextNode(delta, item) {
|
|
226
|
+
const visibleNodes = this.getVisibleNodes();
|
|
227
|
+
if (!visibleNodes) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const focusItem = visibleNodes[visibleNodes.indexOf(item) + delta];
|
|
231
|
+
if (isHTMLElement(focusItem)) {
|
|
232
|
+
TreeItem.focusItem(focusItem);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* checks if there are any nested tree items
|
|
237
|
+
*/
|
|
238
|
+
getValidFocusableItem() {
|
|
239
|
+
const treeItems = this.getVisibleNodes();
|
|
240
|
+
// default to selected element if there is one
|
|
241
|
+
let focusIndex = treeItems.findIndex(this.isSelectedElement);
|
|
242
|
+
if (focusIndex === -1) {
|
|
243
|
+
// otherwise first focusable tree item
|
|
244
|
+
focusIndex = treeItems.findIndex(this.isFocusableElement);
|
|
245
|
+
}
|
|
246
|
+
if (focusIndex !== -1) {
|
|
247
|
+
return treeItems[focusIndex];
|
|
248
|
+
}
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* checks if there are any nested tree items
|
|
253
|
+
*/
|
|
254
|
+
checkForNestedItems() {
|
|
255
|
+
return this.slottedTreeItems.some((node) => {
|
|
256
|
+
return isTreeItemElement(node) && node.querySelector("[role='treeitem']");
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
getVisibleNodes() {
|
|
260
|
+
return getDisplayedNodes(this, "[role='treeitem']") || [];
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
__decorate([
|
|
264
|
+
attr({ attribute: "render-collapsed-nodes" })
|
|
265
|
+
], TreeView$1.prototype, "renderCollapsedNodes", void 0);
|
|
266
|
+
__decorate([
|
|
267
|
+
observable
|
|
268
|
+
], TreeView$1.prototype, "currentSelected", void 0);
|
|
269
|
+
__decorate([
|
|
270
|
+
observable
|
|
271
|
+
], TreeView$1.prototype, "slottedTreeItems", void 0);
|
|
272
|
+
|
|
273
|
+
var css_248z = ".control {\n position: relative;\n display: flex;\n flex-direction: column;\n gap: 4px;\n}";
|
|
274
|
+
|
|
275
|
+
class TreeView extends TreeView$1 {}
|
|
276
|
+
|
|
277
|
+
const getClasses = _ => classNames('control');
|
|
278
|
+
const TreeViewTemplate = () => {
|
|
279
|
+
return html`
|
|
280
|
+
<template
|
|
281
|
+
role="tree"
|
|
282
|
+
${ref('treeView')}
|
|
283
|
+
@keydown="${(x, c) => x.handleKeyDown(c.event)}"
|
|
284
|
+
@focusin="${(x, c) => x.handleFocus(c.event)}"
|
|
285
|
+
@focusout="${(x, c) => x.handleBlur(c.event)}"
|
|
286
|
+
@click="${(x, c) => x.handleClick(c.event)}"
|
|
287
|
+
@selected-change="${(x, c) => x.handleSelectedChange(c.event)}"
|
|
288
|
+
>
|
|
289
|
+
<div class="${getClasses}">
|
|
290
|
+
<slot ${slotted('slottedTreeItems')}></slot>
|
|
291
|
+
</div>
|
|
292
|
+
</template>`;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
const treeViewDefinition = TreeView.compose({
|
|
296
|
+
baseName: 'tree-view',
|
|
297
|
+
template: TreeViewTemplate,
|
|
298
|
+
styles: css_248z
|
|
299
|
+
});
|
|
300
|
+
const treeViewRegistries = [treeViewDefinition()];
|
|
301
|
+
const registerTreeView = registerFactory(treeViewRegistries);
|
|
302
|
+
|
|
303
|
+
export { treeViewRegistries as a, registerTreeView as r, treeViewDefinition as t };
|