@geoffcox/sterling-svelte 2.0.1 → 2.0.3
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/README.md +1 -1
- package/dist/Button.svelte +18 -14
- package/dist/Button.svelte.d.ts +0 -1
- package/dist/Callout.svelte +162 -96
- package/dist/Callout.svelte.d.ts +1 -2
- package/dist/Checkbox.svelte +34 -15
- package/dist/Checkbox.svelte.d.ts +0 -1
- package/dist/Dialog.svelte +121 -71
- package/dist/Dialog.svelte.d.ts +1 -1
- package/dist/Dropdown.svelte +106 -56
- package/dist/Dropdown.svelte.d.ts +8 -3
- package/dist/Input.svelte +54 -29
- package/dist/Input.svelte.d.ts +1 -2
- package/dist/Label.svelte +99 -55
- package/dist/Label.svelte.d.ts +4 -4
- package/dist/Link.svelte +20 -14
- package/dist/Link.svelte.d.ts +0 -1
- package/dist/List.svelte +181 -126
- package/dist/List.svelte.d.ts +0 -1
- package/dist/ListItem.svelte +36 -21
- package/dist/ListItem.svelte.d.ts +0 -1
- package/dist/Menu.svelte +67 -45
- package/dist/Menu.svelte.d.ts +0 -1
- package/dist/MenuBar.svelte +96 -65
- package/dist/MenuBar.svelte.d.ts +0 -1
- package/dist/MenuButton.svelte +102 -62
- package/dist/MenuButton.svelte.d.ts +1 -1
- package/dist/MenuItem.svelte +332 -243
- package/dist/MenuItem.svelte.d.ts +3 -3
- package/dist/MenuSeparator.svelte +7 -7
- package/dist/MenuSeparator.svelte.d.ts +0 -1
- package/dist/Pagination.svelte +267 -0
- package/dist/Pagination.svelte.d.ts +4 -0
- package/dist/Pagination.types.d.ts +24 -0
- package/dist/Pagination.types.js +1 -0
- package/dist/Popover.svelte +114 -60
- package/dist/Popover.svelte.d.ts +1 -2
- package/dist/Portal.types.d.ts +1 -4
- package/dist/Progress.svelte +40 -15
- package/dist/Progress.svelte.d.ts +0 -1
- package/dist/Radio.svelte +37 -25
- package/dist/Radio.svelte.d.ts +0 -1
- package/dist/Select.svelte +191 -125
- package/dist/Select.svelte.d.ts +8 -2
- package/dist/Slider.svelte +120 -71
- package/dist/Slider.svelte.d.ts +0 -1
- package/dist/Switch.svelte +51 -20
- package/dist/Switch.svelte.d.ts +1 -1
- package/dist/Tab.svelte +39 -24
- package/dist/Tab.svelte.d.ts +0 -1
- package/dist/TabList.svelte +176 -125
- package/dist/TabList.svelte.d.ts +0 -1
- package/dist/TextArea.svelte +83 -41
- package/dist/TextArea.svelte.d.ts +2 -3
- package/dist/Tooltip.svelte +68 -36
- package/dist/Tree.svelte +52 -24
- package/dist/Tree.svelte.d.ts +0 -1
- package/dist/TreeChevron.svelte +24 -12
- package/dist/TreeChevron.svelte.d.ts +0 -1
- package/dist/TreeItem.svelte +292 -225
- package/dist/TreeItem.svelte.d.ts +1 -1
- package/dist/actions/extraClass.d.ts +1 -0
- package/dist/actions/extraClass.js +1 -0
- package/dist/idGenerator.d.ts +1 -0
- package/dist/idGenerator.js +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/mediaQueries/prefersColorSchemeDark.d.ts +0 -1
- package/dist/mediaQueries/prefersReducedMotion.d.ts +0 -1
- package/dist/mediaQueries/usingKeyboard.d.ts +0 -1
- package/package.json +21 -22
package/dist/TreeItem.svelte
CHANGED
|
@@ -1,294 +1,361 @@
|
|
|
1
1
|
<svelte:options runes={true} />
|
|
2
2
|
|
|
3
|
-
<script lang="ts">
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
<script lang="ts">
|
|
4
|
+
import { getContext, setContext, type Snippet } from 'svelte';
|
|
5
|
+
import type { HTMLAttributes, KeyboardEventHandler, MouseEventHandler } from 'svelte/elements';
|
|
6
|
+
import type { SlideParams, TransitionConfig } from 'svelte/transition';
|
|
7
|
+
import { slide } from 'svelte/transition';
|
|
8
|
+
import { prefersReducedMotion } from './mediaQueries/prefersReducedMotion';
|
|
9
|
+
import { TREE_CONTEXT_KEY } from './Tree.constants';
|
|
10
|
+
import type { TreeContext } from './Tree.types';
|
|
11
|
+
import TreeChevron from './TreeChevron.svelte';
|
|
12
|
+
import { TREE_ITEM_CONTEXT_KEY } from './TreeItem.constants';
|
|
13
|
+
import type { TreeItemContext } from './TreeItem.types';
|
|
14
|
+
|
|
15
|
+
type Props = HTMLAttributes<HTMLDivElement> & {
|
|
16
|
+
disabled?: boolean | null | undefined;
|
|
17
|
+
icon?: Snippet;
|
|
18
|
+
label?: string | Snippet;
|
|
19
|
+
value: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
let {
|
|
23
|
+
children,
|
|
24
|
+
class: _class,
|
|
25
|
+
disabled = false,
|
|
26
|
+
icon,
|
|
27
|
+
label,
|
|
28
|
+
style,
|
|
29
|
+
value,
|
|
30
|
+
...rest
|
|
31
|
+
}: Props = $props();
|
|
32
|
+
|
|
33
|
+
const slideNoOp = (node: Element, params?: SlideParams): TransitionConfig => {
|
|
11
34
|
return { delay: 0, duration: 0 };
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
let slideMotion = $derived(!$prefersReducedMotion ? slide : slideNoOp);
|
|
38
|
+
|
|
39
|
+
const treeContext = getContext<TreeContext>(TREE_CONTEXT_KEY) || {
|
|
15
40
|
disabled: false,
|
|
16
41
|
expandedValues: [],
|
|
17
42
|
selectedValue: null
|
|
18
|
-
};
|
|
19
|
-
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const treeItemContext = getContext<TreeItemContext>(TREE_ITEM_CONTEXT_KEY) || {
|
|
20
46
|
depth: 0,
|
|
21
47
|
disabled: false
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
let _disabled = $derived(disabled || treeItemContext.disabled || treeContext.disabled);
|
|
51
|
+
|
|
52
|
+
// Using $derived would be preferred, but this helps avoid
|
|
53
|
+
// updates to every tree item when expandedValues changes.
|
|
54
|
+
let expanded = $state(treeContext.expandedValues?.includes(value));
|
|
55
|
+
$effect(() => {
|
|
28
56
|
let expandedCandidate = treeContext.expandedValues?.includes(value);
|
|
29
57
|
if (expandedCandidate !== expanded) {
|
|
30
|
-
|
|
58
|
+
expanded = expandedCandidate;
|
|
31
59
|
}
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
$
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Using $derived would be preferred, but this helps avoid
|
|
63
|
+
// updates to every list item when selectedValue changes.
|
|
64
|
+
let selected = $state(treeContext.selectedValue === value);
|
|
65
|
+
$effect(() => {
|
|
37
66
|
if (treeContext.selectedValue === value && !selected) {
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
selected = false;
|
|
67
|
+
selected = true;
|
|
68
|
+
} else if (treeContext.selectedValue !== value && selected) {
|
|
69
|
+
selected = false;
|
|
42
70
|
}
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
let
|
|
46
|
-
let
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
let treeItemRef: HTMLDivElement;
|
|
74
|
+
let itemRef: HTMLDivElement;
|
|
75
|
+
|
|
76
|
+
let treeItemChildContext: TreeItemContext = {
|
|
47
77
|
get disabled() {
|
|
48
|
-
|
|
78
|
+
return _disabled;
|
|
49
79
|
},
|
|
50
80
|
get depth() {
|
|
51
|
-
|
|
81
|
+
return treeItemContext.depth ? treeItemContext.depth + 1 : 1;
|
|
52
82
|
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
setContext<TreeItemContext>(TREE_ITEM_CONTEXT_KEY, treeItemChildContext);
|
|
86
|
+
|
|
87
|
+
const collapseItem = (index?: number) => {
|
|
56
88
|
if (!_disabled) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
89
|
+
index =
|
|
90
|
+
index ?? treeContext.expandedValues.findIndex((expandedValue) => expandedValue === value);
|
|
91
|
+
if (index !== -1) {
|
|
92
|
+
treeContext.expandedValues = [
|
|
93
|
+
...treeContext.expandedValues.slice(0, index),
|
|
94
|
+
...treeContext.expandedValues.slice(index + 1)
|
|
95
|
+
];
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
66
98
|
}
|
|
99
|
+
|
|
67
100
|
return false;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export const collapse = () => collapseItem();
|
|
104
|
+
|
|
105
|
+
const expandItem = (index?: number) => {
|
|
71
106
|
if (!_disabled) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
107
|
+
index =
|
|
108
|
+
index ?? treeContext.expandedValues.findIndex((expandedValue) => expandedValue === value);
|
|
109
|
+
if (index === -1) {
|
|
110
|
+
treeContext.expandedValues = [...treeContext.expandedValues, value];
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
78
113
|
}
|
|
114
|
+
|
|
79
115
|
return false;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export const
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export const expand = () => expandItem();
|
|
119
|
+
|
|
120
|
+
export const toggleExpanded = () => {
|
|
83
121
|
if (!_disabled && children) {
|
|
84
|
-
|
|
85
|
-
|
|
122
|
+
const index = treeContext.expandedValues.findIndex(
|
|
123
|
+
(expandedValue) => expandedValue === value
|
|
124
|
+
);
|
|
125
|
+
return index !== -1 ? collapseItem(index) : expandItem(index);
|
|
86
126
|
}
|
|
127
|
+
|
|
87
128
|
return false;
|
|
88
|
-
};
|
|
89
|
-
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const blurItem = (treeItemElement: Element) => {
|
|
90
132
|
if (!_disabled) {
|
|
91
|
-
|
|
92
|
-
|
|
133
|
+
const item = treeItemElement?.querySelector<HTMLElement>('.item');
|
|
134
|
+
item?.blur();
|
|
93
135
|
}
|
|
94
|
-
};
|
|
95
|
-
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export const blur = () => {
|
|
96
139
|
blurItem(treeItemRef);
|
|
97
|
-
};
|
|
98
|
-
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const focusItem = (treeItemElement: Element, options?: FocusOptions) => {
|
|
99
143
|
if (!_disabled) {
|
|
100
|
-
|
|
101
|
-
|
|
144
|
+
const item = treeItemElement as HTMLElement;
|
|
145
|
+
item?.focus(options);
|
|
102
146
|
}
|
|
103
|
-
};
|
|
104
|
-
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export const focus = (options?: FocusOptions) => {
|
|
105
150
|
focusItem(treeItemRef);
|
|
106
151
|
treeItemRef?.focus(options);
|
|
107
|
-
};
|
|
108
|
-
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const clickItem = (treeItemElement: Element) => {
|
|
109
155
|
if (!_disabled) {
|
|
110
|
-
|
|
111
|
-
|
|
156
|
+
const item = treeItemElement as HTMLElement;
|
|
157
|
+
item?.click();
|
|
112
158
|
}
|
|
113
|
-
};
|
|
114
|
-
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export const click = () => {
|
|
115
162
|
clickItem(treeItemRef);
|
|
116
|
-
};
|
|
117
|
-
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const selectItemByValue = (value: string) => {
|
|
118
166
|
if (!_disabled) {
|
|
119
|
-
|
|
167
|
+
treeContext.selectedValue = value;
|
|
120
168
|
}
|
|
121
|
-
};
|
|
122
|
-
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export const select = () => {
|
|
123
172
|
if (!_disabled) {
|
|
124
|
-
|
|
173
|
+
selectItemByValue(value);
|
|
125
174
|
}
|
|
126
|
-
};
|
|
127
|
-
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
export const selectParent = () => {
|
|
128
178
|
if (!_disabled) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
179
|
+
let candidate = treeItemRef.parentElement?.closest<Element>('[role="treeitem"][data-value]');
|
|
180
|
+
let candidateValue = candidate?.getAttribute('data-value');
|
|
181
|
+
|
|
182
|
+
if (candidateValue && candidate) {
|
|
183
|
+
selectItemByValue(candidateValue);
|
|
184
|
+
focusItem(candidate);
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
136
187
|
}
|
|
188
|
+
|
|
137
189
|
return false;
|
|
138
|
-
};
|
|
139
|
-
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export const selectPrevious = () => {
|
|
140
193
|
if (!_disabled) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
// look for the previous sibling
|
|
152
|
-
if (!candidateValue) {
|
|
153
|
-
candidate = previousSibling;
|
|
154
|
-
candidateValue = candidate?.getAttribute('data-value');
|
|
155
|
-
}
|
|
194
|
+
let candidate: Element | undefined | null = undefined;
|
|
195
|
+
let candidateValue: string | null | undefined = undefined;
|
|
196
|
+
|
|
197
|
+
const previousSibling = treeItemRef?.previousElementSibling;
|
|
198
|
+
if (previousSibling) {
|
|
199
|
+
// look for the last (recursive) decendant of ths previous sibling
|
|
200
|
+
const decendants = previousSibling.querySelectorAll('[role="treeitem"][data-value]');
|
|
201
|
+
if (decendants) {
|
|
202
|
+
candidate = decendants[decendants.length - 1];
|
|
203
|
+
candidateValue = candidate?.getAttribute('data-value');
|
|
156
204
|
}
|
|
157
|
-
|
|
205
|
+
|
|
206
|
+
// look for the previous sibling
|
|
158
207
|
if (!candidateValue) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
if (candidateValue && candidate) {
|
|
163
|
-
selectItemByValue(candidateValue);
|
|
164
|
-
focusItem(candidate);
|
|
165
|
-
return true;
|
|
208
|
+
candidate = previousSibling;
|
|
209
|
+
candidateValue = candidate?.getAttribute('data-value');
|
|
166
210
|
}
|
|
211
|
+
}
|
|
212
|
+
// look for the parent
|
|
213
|
+
if (!candidateValue) {
|
|
214
|
+
candidate = treeItemRef.parentElement?.closest<Element>('[role="treeitem"][data-value]');
|
|
215
|
+
candidateValue = candidate?.getAttribute('data-value');
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (candidateValue && candidate) {
|
|
219
|
+
selectItemByValue(candidateValue);
|
|
220
|
+
focusItem(candidate);
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
167
223
|
}
|
|
224
|
+
|
|
168
225
|
return false;
|
|
169
|
-
};
|
|
170
|
-
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
export const selectNext = () => {
|
|
171
229
|
if (!_disabled) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
// look for next sibling of ancestor
|
|
185
|
-
if (!candidateValue) {
|
|
186
|
-
let ancestor = treeItemRef.parentElement?.closest('[role="treeitem"][data-value]');
|
|
187
|
-
while (ancestor && !candidateValue) {
|
|
188
|
-
candidate = ancestor?.nextElementSibling;
|
|
189
|
-
candidateValue = candidate?.getAttribute('data-value');
|
|
190
|
-
ancestor = ancestor.parentElement?.closest('[role="treeitem"][data-value]');
|
|
191
|
-
}
|
|
230
|
+
let candidateValue: string | null | undefined = undefined;
|
|
231
|
+
|
|
232
|
+
// look for decendants
|
|
233
|
+
let candidate = treeItemRef.querySelector('[role="treeitem"][data-value]');
|
|
234
|
+
candidateValue = candidate?.getAttribute('data-value');
|
|
235
|
+
|
|
236
|
+
// look for next sibling
|
|
237
|
+
if (!candidateValue) {
|
|
238
|
+
candidate = treeItemRef.nextElementSibling;
|
|
239
|
+
while (candidate && candidate.getAttribute('data-value') === null) {
|
|
240
|
+
candidate = candidate.nextElementSibling;
|
|
192
241
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
242
|
+
candidateValue = candidate?.getAttribute('data-value');
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// look for next sibling of ancestor
|
|
246
|
+
if (!candidateValue) {
|
|
247
|
+
let ancestor: Element | null | undefined = treeItemRef.parentElement?.closest<Element>(
|
|
248
|
+
'[role="treeitem"][data-value]'
|
|
249
|
+
);
|
|
250
|
+
while (ancestor && !candidateValue) {
|
|
251
|
+
candidate = ancestor?.nextElementSibling;
|
|
252
|
+
candidateValue = candidate?.getAttribute('data-value');
|
|
253
|
+
ancestor = ancestor.parentElement?.closest<Element>('[role="treeitem"][data-value]');
|
|
197
254
|
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (candidateValue && candidate) {
|
|
258
|
+
selectItemByValue(candidateValue);
|
|
259
|
+
focusItem(candidate);
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
198
262
|
}
|
|
263
|
+
|
|
199
264
|
return false;
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
const onClick: MouseEventHandler<HTMLDivElement> = (event) => {
|
|
268
|
+
const eventTarget = event.target as Node;
|
|
203
269
|
if (!_disabled && itemRef.contains(eventTarget)) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
270
|
+
toggleExpanded();
|
|
271
|
+
select();
|
|
272
|
+
return;
|
|
207
273
|
}
|
|
274
|
+
|
|
208
275
|
rest.onclick?.(event);
|
|
209
|
-
};
|
|
210
|
-
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
const onKeydown: KeyboardEventHandler<HTMLDivElement> = (event) => {
|
|
211
279
|
if (!event.altKey && !event.ctrlKey && !event.shiftKey) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
280
|
+
switch (event.key) {
|
|
281
|
+
case 'Enter':
|
|
282
|
+
case ' ':
|
|
283
|
+
if (toggleExpanded()) {
|
|
284
|
+
event.preventDefault();
|
|
285
|
+
event.stopPropagation();
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
break;
|
|
289
|
+
case 'ArrowRight':
|
|
290
|
+
/*
|
|
291
|
+
When focus is on a closed item, opens the item; focus does not move.
|
|
292
|
+
When focus is on an open item, moves focus to the first child item.
|
|
293
|
+
When focus is on an end item (a tree item with no children), does nothing.
|
|
294
|
+
*/
|
|
295
|
+
if (children) {
|
|
296
|
+
if (expanded) {
|
|
297
|
+
if (selectNext()) {
|
|
298
|
+
event.preventDefault();
|
|
299
|
+
event.stopPropagation();
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
} else if (expandItem()) {
|
|
303
|
+
event.preventDefault();
|
|
304
|
+
event.stopPropagation();
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
break;
|
|
309
|
+
case 'ArrowLeft':
|
|
310
|
+
/*
|
|
311
|
+
When focus is on an open item, closes the item.
|
|
312
|
+
When focus is on a child item that is also either an end item or a closed item, moves focus to its parent item.
|
|
313
|
+
When focus is on a closed `tree`, does nothing.
|
|
314
|
+
*/
|
|
315
|
+
if (expanded && children) {
|
|
316
|
+
if (collapseItem()) {
|
|
317
|
+
event.preventDefault();
|
|
318
|
+
event.stopPropagation();
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
} else if (selectParent()) {
|
|
322
|
+
event.preventDefault();
|
|
323
|
+
event.stopPropagation();
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
break;
|
|
327
|
+
case 'ArrowUp':
|
|
328
|
+
/*
|
|
329
|
+
Moves focus to the previous item that is focusable without opening or closing a item.
|
|
330
|
+
*/
|
|
331
|
+
if (selectPrevious()) {
|
|
332
|
+
event.preventDefault();
|
|
333
|
+
event.stopPropagation();
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
break;
|
|
337
|
+
case 'ArrowDown':
|
|
338
|
+
/*
|
|
339
|
+
Moves focus to the next item that is focusable without opening or closing a item.
|
|
340
|
+
*/
|
|
341
|
+
if (selectNext()) {
|
|
342
|
+
event.preventDefault();
|
|
343
|
+
event.stopPropagation();
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
282
348
|
}
|
|
349
|
+
|
|
283
350
|
rest.onkeydown?.(event);
|
|
284
|
-
};
|
|
351
|
+
};
|
|
285
352
|
</script>
|
|
286
353
|
|
|
287
354
|
<div
|
|
288
355
|
bind:this={treeItemRef}
|
|
289
356
|
aria-selected={selected ? true : undefined}
|
|
290
357
|
aria-expanded={expanded}
|
|
291
|
-
class={
|
|
358
|
+
class={['sterling-tree-item', _class]}
|
|
292
359
|
class:disabled={_disabled}
|
|
293
360
|
class:expanded
|
|
294
361
|
class:item-disabled={disabled}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
type Params = {
|
|
2
2
|
extraClass: string | null | undefined;
|
|
3
3
|
};
|
|
4
|
+
/** @deprecated Use clsx class merging through class={['name1', 'name2']} */
|
|
4
5
|
export declare const extraClass: (node: HTMLElement, params?: Params) => {
|
|
5
6
|
update(params: Params): void;
|
|
6
7
|
destroy(): void;
|
package/dist/idGenerator.d.ts
CHANGED
package/dist/idGenerator.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -33,8 +33,8 @@ import Callout from './Callout.svelte';
|
|
|
33
33
|
import Checkbox from './Checkbox.svelte';
|
|
34
34
|
import Dialog from './Dialog.svelte';
|
|
35
35
|
import Dropdown from './Dropdown.svelte';
|
|
36
|
-
import Label from './Label.svelte';
|
|
37
36
|
import Input from './Input.svelte';
|
|
37
|
+
import Label from './Label.svelte';
|
|
38
38
|
import Link from './Link.svelte';
|
|
39
39
|
import List from './List.svelte';
|
|
40
40
|
import ListItem from './ListItem.svelte';
|
|
@@ -43,6 +43,7 @@ import MenuBar from './MenuBar.svelte';
|
|
|
43
43
|
import MenuButton from './MenuButton.svelte';
|
|
44
44
|
import MenuItem from './MenuItem.svelte';
|
|
45
45
|
import MenuSeparator from './MenuSeparator.svelte';
|
|
46
|
+
import Pagination from './Pagination.svelte';
|
|
46
47
|
import Popover from './Popover.svelte';
|
|
47
48
|
import Progress from './Progress.svelte';
|
|
48
49
|
import Radio from './Radio.svelte';
|
|
@@ -56,4 +57,4 @@ import Tooltip from './Tooltip.svelte';
|
|
|
56
57
|
import Tree from './Tree.svelte';
|
|
57
58
|
import TreeChevron from './TreeChevron.svelte';
|
|
58
59
|
import TreeItem from './TreeItem.svelte';
|
|
59
|
-
export { Button, Callout, Checkbox, Dialog, Dropdown, Input, Label, Link, List, ListItem, Menu, MenuBar, MenuButton, MenuItem, MenuSeparator, Popover, Progress, Radio, Select, Slider, Switch, Tab, TabList, TextArea, Tooltip, Tree, TreeChevron, TreeItem };
|
|
60
|
+
export { Button, Callout, Checkbox, Dialog, Dropdown, Input, Label, Link, List, ListItem, Menu, MenuBar, MenuButton, MenuItem, MenuSeparator, Pagination, Popover, Progress, Radio, Select, Slider, Switch, Tab, TabList, TextArea, Tooltip, Tree, TreeChevron, TreeItem };
|