@sveltia/ui 0.54.0 → 0.55.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.
@@ -0,0 +1,126 @@
1
+ export default Tree;
2
+ type Tree = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<KeyboardEventHandlers & MouseEventHandlers & PointerEventHandlers & FocusEventHandlers & DragEventHandlers & Props & Record<string, any>>): void;
5
+ };
6
+ /**
7
+ * A tree view widget that displays a hierarchical list of items, which can be expanded, collapsed
8
+ * and selected.
9
+ * @see https://w3c.github.io/aria/#tree
10
+ * @see https://www.w3.org/WAI/ARIA/apg/patterns/treeview/
11
+ */
12
+ declare const Tree: import("svelte").Component<import("../../typedefs").KeyboardEventHandlers & import("../../typedefs").MouseEventHandlers & import("../../typedefs").PointerEventHandlers & import("../../typedefs").FocusEventHandlers & import("../../typedefs").DragEventHandlers & {
13
+ /**
14
+ * A reference to the wrapper element.
15
+ */
16
+ element?: HTMLElement | undefined;
17
+ /**
18
+ * The `class` attribute on the wrapper element.
19
+ */
20
+ class?: string | undefined;
21
+ /**
22
+ * Whether to hide the widget. An alias of the `aria-hidden`
23
+ * attribute.
24
+ */
25
+ hidden?: boolean | undefined;
26
+ /**
27
+ * Whether to disable the widget. An alias of the `aria-disabled`
28
+ * attribute.
29
+ */
30
+ disabled?: boolean | undefined;
31
+ /**
32
+ * Whether to make the widget read-only. An alias of the
33
+ * `aria-readonly` attribute.
34
+ */
35
+ readonly?: boolean | undefined;
36
+ /**
37
+ * Whether to allow selecting more than one `<TreeItem>`. An alias
38
+ * of the `aria-multiselectable` attribute.
39
+ */
40
+ multiple?: boolean | undefined;
41
+ /**
42
+ * Whether to select an item by clicking on it.
43
+ */
44
+ clickToSelect?: boolean | undefined;
45
+ /**
46
+ * Whether to select an item as soon as it receives
47
+ * focus. Default: `true` on a single-select tree, `false` on a multi-select tree.
48
+ */
49
+ selectionFollowsFocus?: boolean | undefined;
50
+ /**
51
+ * Whether to expand or collapse a parent item when the item
52
+ * itself, rather than its chevron, is clicked or activated with the Enter key.
53
+ */
54
+ expandOnSelect?: boolean | undefined;
55
+ /**
56
+ * The `aria-label` attribute on the wrapper element. Required
57
+ * unless the `aria-labelledby` attribute is provided.
58
+ */
59
+ ariaLabel?: string | undefined;
60
+ /**
61
+ * Primary slot content.
62
+ */
63
+ children?: Snippet<[]> | undefined;
64
+ /**
65
+ * Custom `Change` event handler.
66
+ */
67
+ onChange?: ((event: CustomEvent) => void) | undefined;
68
+ } & Record<string, any>, {}, "element">;
69
+ type Props = {
70
+ /**
71
+ * A reference to the wrapper element.
72
+ */
73
+ element?: HTMLElement | undefined;
74
+ /**
75
+ * The `class` attribute on the wrapper element.
76
+ */
77
+ class?: string | undefined;
78
+ /**
79
+ * Whether to hide the widget. An alias of the `aria-hidden`
80
+ * attribute.
81
+ */
82
+ hidden?: boolean | undefined;
83
+ /**
84
+ * Whether to disable the widget. An alias of the `aria-disabled`
85
+ * attribute.
86
+ */
87
+ disabled?: boolean | undefined;
88
+ /**
89
+ * Whether to make the widget read-only. An alias of the
90
+ * `aria-readonly` attribute.
91
+ */
92
+ readonly?: boolean | undefined;
93
+ /**
94
+ * Whether to allow selecting more than one `<TreeItem>`. An alias
95
+ * of the `aria-multiselectable` attribute.
96
+ */
97
+ multiple?: boolean | undefined;
98
+ /**
99
+ * Whether to select an item by clicking on it.
100
+ */
101
+ clickToSelect?: boolean | undefined;
102
+ /**
103
+ * Whether to select an item as soon as it receives
104
+ * focus. Default: `true` on a single-select tree, `false` on a multi-select tree.
105
+ */
106
+ selectionFollowsFocus?: boolean | undefined;
107
+ /**
108
+ * Whether to expand or collapse a parent item when the item
109
+ * itself, rather than its chevron, is clicked or activated with the Enter key.
110
+ */
111
+ expandOnSelect?: boolean | undefined;
112
+ /**
113
+ * The `aria-label` attribute on the wrapper element. Required
114
+ * unless the `aria-labelledby` attribute is provided.
115
+ */
116
+ ariaLabel?: string | undefined;
117
+ /**
118
+ * Primary slot content.
119
+ */
120
+ children?: Snippet<[]> | undefined;
121
+ /**
122
+ * Custom `Change` event handler.
123
+ */
124
+ onChange?: ((event: CustomEvent) => void) | undefined;
125
+ };
126
+ import type { Snippet } from 'svelte';
@@ -250,6 +250,13 @@
250
250
  --sui-listbox-border-color: var(--sui-control-border-color);
251
251
  --sui-listbox-foreground-color: var(--sui-control-foreground-color);
252
252
  --sui-listbox-background-color: hsl(var(--sui-background-color-1-hsl));
253
+ --sui-tree-border-radius: var(--sui-control-medium-border-radius);
254
+ --sui-tree-border-color: var(--sui-control-border-color);
255
+ --sui-tree-foreground-color: var(--sui-control-foreground-color);
256
+ --sui-tree-background-color: hsl(var(--sui-background-color-1-hsl));
257
+ --sui-tree-item-border-radius: var(--sui-control-medium-border-radius);
258
+ --sui-tree-item-height: var(--sui-control-medium-height);
259
+ --sui-tree-item-indent: 16px;
253
260
  --sui-textbox-border-radius: var(--sui-control-medium-border-radius);
254
261
  --sui-textbox-height: var(--sui-control-medium-height);
255
262
  --sui-textbox-border-color: var(--sui-control-border-color);
package/dist/index.d.ts CHANGED
@@ -72,6 +72,8 @@ export { default as TextArea } from "./components/text-field/text-area.svelte";
72
72
  export { default as TextInput } from "./components/text-field/text-input.svelte";
73
73
  export { default as Toast } from "./components/toast/toast.svelte";
74
74
  export { default as Toolbar } from "./components/toolbar/toolbar.svelte";
75
+ export { default as TreeItem } from "./components/tree/tree-item.svelte";
76
+ export { default as Tree } from "./components/tree/tree.svelte";
75
77
  export { default as TruncatedText } from "./components/typography/truncated-text.svelte";
76
78
  export { default as AppShell } from "./components/util/app-shell.svelte";
77
79
  export { default as EmptyState } from "./components/util/empty-state.svelte";
package/dist/index.js CHANGED
@@ -72,6 +72,8 @@ export { default as TextArea } from './components/text-field/text-area.svelte';
72
72
  export { default as TextInput } from './components/text-field/text-input.svelte';
73
73
  export { default as Toast } from './components/toast/toast.svelte';
74
74
  export { default as Toolbar } from './components/toolbar/toolbar.svelte';
75
+ export { default as TreeItem } from './components/tree/tree-item.svelte';
76
+ export { default as Tree } from './components/tree/tree.svelte';
75
77
  export { default as TruncatedText } from './components/typography/truncated-text.svelte';
76
78
  export { default as AppShell } from './components/util/app-shell.svelte';
77
79
  export { default as EmptyState } from './components/util/empty-state.svelte';
@@ -0,0 +1,235 @@
1
+ /**
2
+ * Implement keyboard and mouse interactions for the `tree` composite widget, following the ARIA
3
+ * Tree View pattern. Unlike the other composite widgets handled by the `Group` class, a tree
4
+ * manages the focus (roving `tabindex`) and the selection separately, and it also supports
5
+ * expanding and collapsing parent nodes.
6
+ * @see https://www.w3.org/WAI/ARIA/apg/patterns/treeview/
7
+ */
8
+ export class Tree {
9
+ /**
10
+ * Initialize a new `Tree` instance.
11
+ * @param {HTMLElement} parent Parent element.
12
+ * @param {object} [options] Options.
13
+ * @param {boolean} [options.clickToSelect] Whether to select an item by clicking on it.
14
+ * @param {boolean} [options.selectionFollowsFocus] Whether to select an item as soon as it
15
+ * receives focus. Default: `true` on a single-select tree, `false` on a multi-select tree.
16
+ * @param {boolean} [options.expandOnSelect] Whether to expand or collapse a parent item when the
17
+ * item itself, rather than its chevron, is clicked or activated.
18
+ */
19
+ constructor(parent: HTMLElement, { clickToSelect, selectionFollowsFocus, expandOnSelect }?: {
20
+ clickToSelect?: boolean | undefined;
21
+ selectionFollowsFocus?: boolean | undefined;
22
+ expandOnSelect?: boolean | undefined;
23
+ } | undefined);
24
+ parent: HTMLElement;
25
+ id: string;
26
+ clickToSelect: boolean;
27
+ expandOnSelect: boolean;
28
+ /**
29
+ * Whether the selection follows the focus. `undefined` means auto detect.
30
+ * @type {boolean | undefined}
31
+ */
32
+ selectionFollowsFocusOption: boolean | undefined;
33
+ /**
34
+ * Item used as the starting point of a range selection.
35
+ * @type {HTMLElement | undefined}
36
+ */
37
+ anchor: HTMLElement | undefined;
38
+ /**
39
+ * Currently accumulated type-ahead search terms.
40
+ * @type {string}
41
+ */
42
+ typeAheadTerms: string;
43
+ /**
44
+ * Timer used to reset the type-ahead search terms.
45
+ * @type {ReturnType<typeof globalThis.setTimeout> | undefined}
46
+ */
47
+ typeAheadTimer: ReturnType<typeof globalThis.setTimeout> | undefined;
48
+ /** @type {(event: MouseEvent) => void} */
49
+ _onClick: (event: MouseEvent) => void;
50
+ /** @type {(event: KeyboardEvent) => void} */
51
+ _onKeyDown: (event: KeyboardEvent) => void;
52
+ /** @type {(event: FocusEvent) => void} */
53
+ _onFocusIn: (event: FocusEvent) => void;
54
+ observer: MutationObserver;
55
+ /**
56
+ * Activate the items.
57
+ */
58
+ activate(): void;
59
+ /**
60
+ * Whether more than one item can be selected.
61
+ * @type {boolean}
62
+ */
63
+ get multi(): boolean;
64
+ /**
65
+ * Whether an item is selected as soon as it receives focus.
66
+ * @type {boolean}
67
+ */
68
+ get selectionFollowsFocus(): boolean;
69
+ /**
70
+ * Whether the widget is disabled.
71
+ * @type {boolean}
72
+ */
73
+ get isDisabled(): boolean;
74
+ /**
75
+ * Whether the widget is read-only.
76
+ * @type {boolean}
77
+ */
78
+ get isReadOnly(): boolean;
79
+ /**
80
+ * List of all the items, including the ones within a collapsed parent, in document order.
81
+ * @type {HTMLElement[]}
82
+ */
83
+ get allItems(): HTMLElement[];
84
+ /**
85
+ * List of the items that are not hidden, either explicitly or by a collapsed ancestor.
86
+ * @type {HTMLElement[]}
87
+ */
88
+ get visibleItems(): HTMLElement[];
89
+ /**
90
+ * List of the items that can receive focus.
91
+ * @type {HTMLElement[]}
92
+ */
93
+ get activeItems(): HTMLElement[];
94
+ /**
95
+ * List of the selected items.
96
+ * @type {HTMLElement[]}
97
+ */
98
+ get selectedItems(): HTMLElement[];
99
+ /**
100
+ * Item that is currently in the tab order, which is the item that has or last had focus.
101
+ * @type {HTMLElement | undefined}
102
+ */
103
+ get currentItem(): HTMLElement | undefined;
104
+ /**
105
+ * Get the group element that contains the child items of the given item.
106
+ * @param {HTMLElement} item Parent item.
107
+ * @returns {HTMLElement | undefined} Group element, if the item has one.
108
+ */
109
+ getGroup(item: HTMLElement): HTMLElement | undefined;
110
+ /**
111
+ * Get the child items of the given item.
112
+ * @param {HTMLElement} item Parent item.
113
+ * @returns {HTMLElement[]} Child items. Empty if the item is a leaf node.
114
+ */
115
+ getChildItems(item: HTMLElement): HTMLElement[];
116
+ /**
117
+ * Get the items directly owned by the given group, ignoring any deeper descendants.
118
+ * @param {HTMLElement} group Group element or the widget root.
119
+ * @returns {HTMLElement[]} Child items.
120
+ */
121
+ getItemsInGroup(group: HTMLElement): HTMLElement[];
122
+ /**
123
+ * Get the parent item of the given item.
124
+ * @param {HTMLElement} item Item.
125
+ * @returns {HTMLElement | undefined} Parent item, if the item is not at the root level.
126
+ */
127
+ getParentItem(item: HTMLElement): HTMLElement | undefined;
128
+ /**
129
+ * Whether the given item is a parent node that can be expanded and collapsed.
130
+ * @param {HTMLElement} item Item.
131
+ * @returns {boolean} Result.
132
+ */
133
+ isParent(item: HTMLElement): boolean;
134
+ /**
135
+ * Whether the given parent item is expanded.
136
+ * @param {HTMLElement} item Item.
137
+ * @returns {boolean} Result.
138
+ */
139
+ isExpanded(item: HTMLElement): boolean;
140
+ /**
141
+ * Whether any of the ancestors of the given item is collapsed, meaning the item is not displayed.
142
+ * @param {HTMLElement} item Item.
143
+ * @returns {boolean} Result.
144
+ */
145
+ hasCollapsedAncestor(item: HTMLElement): boolean;
146
+ /**
147
+ * Get the text label of the given item, which is used for the type-ahead search.
148
+ * @param {HTMLElement} item Item.
149
+ * @returns {string} Label.
150
+ */
151
+ getLabel(item: HTMLElement): string;
152
+ /**
153
+ * Assign the element IDs, positional attributes and roving `tabindex` to the items. Called
154
+ * whenever the items are added or removed.
155
+ */
156
+ update(): void;
157
+ /**
158
+ * Scroll the given element into view if needed.
159
+ * @param {HTMLElement} element Element to be scrolled into view.
160
+ */
161
+ scrollIntoView(element: HTMLElement): void;
162
+ /**
163
+ * Move focus to the given item.
164
+ * @param {HTMLElement} item Item to be focused.
165
+ * @param {object} [options] Options.
166
+ * @param {boolean} [options.select] Whether to also select the item. Default: depends on the
167
+ * `selectionFollowsFocus` option.
168
+ */
169
+ focusItem(item: HTMLElement, { select }?: {
170
+ select?: boolean | undefined;
171
+ } | undefined): void;
172
+ /**
173
+ * Update the selection state of the given item, and notify the change if needed.
174
+ * @param {HTMLElement} item Item.
175
+ * @param {boolean} selected Whether to select the item.
176
+ */
177
+ setSelected(item: HTMLElement, selected: boolean): void;
178
+ /**
179
+ * Select the given item.
180
+ * @param {HTMLElement} item Item to be selected.
181
+ * @param {object} [options] Options.
182
+ * @param {boolean} [options.additive] Whether to toggle the item without deselecting the other
183
+ * items. Multi-select only.
184
+ * @param {boolean} [options.range] Whether to select all the items between the anchor and the
185
+ * given item. Multi-select only.
186
+ */
187
+ selectItem(item: HTMLElement, { additive, range }?: {
188
+ additive?: boolean | undefined;
189
+ range?: boolean | undefined;
190
+ } | undefined): void;
191
+ /**
192
+ * Select all the items that are currently displayed. Multi-select only.
193
+ * @param {HTMLElement} item Item that triggered the action.
194
+ */
195
+ selectAll(item: HTMLElement): void;
196
+ /**
197
+ * Expand or collapse the given parent item.
198
+ * @param {HTMLElement} item Item to be expanded or collapsed.
199
+ * @param {boolean} expanded Whether to expand the item.
200
+ */
201
+ expandItem(item: HTMLElement, expanded: boolean): void;
202
+ /**
203
+ * Expand all the sibling parent items at the same level as the given item.
204
+ * @param {HTMLElement} item Item.
205
+ */
206
+ expandSiblings(item: HTMLElement): void;
207
+ /**
208
+ * Move focus to the next item that matches the accumulated type-ahead search terms.
209
+ * @param {string} char Typed character.
210
+ * @param {HTMLElement} currentItem Currently focused item.
211
+ */
212
+ typeAhead(char: string, currentItem: HTMLElement): void;
213
+ /**
214
+ * Handle the `focusin` event on the widget. Make the newly focused item the only one in the tab
215
+ * order, so that Shift+Tab and Tab move focus out of the widget.
216
+ * @param {FocusEvent} event `focusin` event.
217
+ */
218
+ onFocusIn(event: FocusEvent): void;
219
+ /**
220
+ * Handle the `click` event on the widget.
221
+ * @param {MouseEvent} event `click` event.
222
+ */
223
+ onClick(event: MouseEvent): void;
224
+ /**
225
+ * Handle the `keydown` event on the widget.
226
+ * @param {KeyboardEvent} event `keydown` event.
227
+ */
228
+ onKeyDown(event: KeyboardEvent): void;
229
+ /**
230
+ * Clean up event listeners.
231
+ */
232
+ destroy(): void;
233
+ }
234
+ export function activateTree(params?: object | undefined): Attachment;
235
+ import type { Attachment } from 'svelte/attachments';