@geoffcox/sterling-svelte 0.0.31 → 1.0.1
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/@types/clickOutside.d.ts +11 -7
- package/Button.svelte +11 -183
- package/Button.svelte.d.ts +2 -6
- package/Callout.svelte +107 -146
- package/Callout.svelte.d.ts +1 -1
- package/Checkbox.svelte +15 -177
- package/Checkbox.svelte.d.ts +2 -2
- package/ColorPicker.svelte +204 -223
- package/ColorPicker.svelte.d.ts +1 -2
- package/Dialog.svelte +90 -187
- package/Dialog.svelte.d.ts +2 -1
- package/Dropdown.svelte +52 -220
- package/Dropdown.svelte.d.ts +4 -8
- package/HexColorSliders.svelte +77 -145
- package/HexColorSliders.svelte.d.ts +28 -1
- package/HslColorSliders.svelte +99 -179
- package/HslColorSliders.svelte.d.ts +28 -1
- package/Input.svelte +27 -136
- package/Input.svelte.d.ts +2 -3
- package/Label.constants.d.ts +1 -0
- package/Label.constants.js +1 -0
- package/Label.svelte +96 -169
- package/Label.svelte.d.ts +6 -1
- package/Label.types.d.ts +3 -1
- package/Link.svelte +9 -106
- package/Link.svelte.d.ts +0 -1
- package/List.svelte +142 -230
- package/List.svelte.d.ts +2 -3
- package/List.types.d.ts +6 -1
- package/ListItem.svelte +25 -94
- package/ListItem.svelte.d.ts +2 -0
- package/Menu.svelte +48 -65
- package/Menu.svelte.d.ts +4 -1
- package/MenuBar.svelte +84 -86
- package/MenuBar.svelte.d.ts +4 -1
- package/MenuButton.svelte +66 -73
- package/MenuButton.svelte.d.ts +7 -3
- package/MenuItem.svelte +256 -288
- package/MenuItem.svelte.d.ts +2 -2
- package/MenuItemDisplay.svelte +12 -116
- package/MenuItemDisplay.svelte.d.ts +21 -7
- package/MenuSeparator.svelte +6 -45
- package/MenuSeparator.svelte.d.ts +8 -78
- package/Popover.constants.d.ts +1 -1
- package/Popover.constants.js +1 -1
- package/Popover.svelte +66 -80
- package/Popover.svelte.d.ts +5 -1
- package/Progress.svelte +28 -126
- package/Progress.svelte.d.ts +4 -3
- package/Radio.svelte +49 -192
- package/Radio.svelte.d.ts +2 -2
- package/RgbColorSliders.svelte +48 -137
- package/RgbColorSliders.svelte.d.ts +5 -5
- package/Select.svelte +122 -250
- package/Select.svelte.d.ts +6 -2
- package/Slider.svelte +90 -259
- package/Slider.svelte.d.ts +1 -2
- package/Switch.svelte +24 -259
- package/Switch.svelte.d.ts +3 -1
- package/Tab.svelte +27 -175
- package/Tab.svelte.d.ts +6 -4
- package/TabList.svelte +146 -171
- package/TabList.svelte.d.ts +3 -2
- package/TabList.types.d.ts +6 -1
- package/TextArea.svelte +32 -129
- package/TextArea.svelte.d.ts +1 -1
- package/Tooltip.svelte +46 -47
- package/Tooltip.svelte.d.ts +8 -3
- package/Tree.constants.d.ts +0 -1
- package/Tree.constants.js +0 -1
- package/Tree.svelte +35 -119
- package/Tree.svelte.d.ts +4 -4
- package/Tree.types.d.ts +1 -3
- package/TreeChevron.svelte +18 -98
- package/TreeChevron.svelte.d.ts +1 -0
- package/TreeItem.constants.d.ts +1 -0
- package/TreeItem.constants.js +1 -0
- package/TreeItem.svelte +251 -211
- package/TreeItem.svelte.d.ts +7 -3
- package/TreeItem.types.d.ts +1 -1
- package/TreeItemDisplay.svelte +20 -104
- package/TreeItemDisplay.svelte.d.ts +2 -2
- package/actions/applyLightDarkMode.d.ts +10 -0
- package/actions/applyLightDarkMode.js +36 -0
- package/actions/forwardEvents.js +3 -3
- package/css/Button.base.css +74 -0
- package/css/Button.colorful.css +17 -0
- package/css/Button.css +7 -0
- package/css/Button.secondary.colorful.css +15 -0
- package/css/Button.secondary.css +11 -0
- package/css/Button.shapes.css +14 -0
- package/css/Button.tool.colorful.css +13 -0
- package/css/Button.tool.css +18 -0
- package/css/Callout.base.css +43 -0
- package/css/Callout.colorful.css +5 -0
- package/css/Callout.css +2 -0
- package/css/Checkbox.base.css +145 -0
- package/css/Checkbox.colorful.css +17 -0
- package/css/Checkbox.css +2 -0
- package/css/ColorPicker.base.css +23 -0
- package/css/ColorPicker.css +1 -0
- package/css/Dialog.base.css +116 -0
- package/css/Dialog.css +1 -0
- package/css/Dropdown.base.css +147 -0
- package/css/Dropdown.colorful.css +23 -0
- package/css/Dropdown.css +2 -0
- package/css/HexColorSliders.base.css +106 -0
- package/css/HexColorSliders.css +1 -0
- package/css/HslColorSliders.base.css +124 -0
- package/css/HslColorSliders.css +1 -0
- package/css/Input.base.css +100 -0
- package/css/Input.colorful.css +22 -0
- package/css/Input.composed.css +8 -0
- package/css/Input.css +3 -0
- package/css/Label.base.css +119 -0
- package/css/Label.boxed.colorful.css +21 -0
- package/css/Label.boxed.css +31 -0
- package/css/Label.colorful.css +3 -0
- package/css/Label.css +4 -0
- package/css/Link.base.css +52 -0
- package/css/Link.colorful.css +15 -0
- package/css/Link.css +6 -0
- package/css/Link.ghost.colorful.css +7 -0
- package/css/Link.ghost.css +11 -0
- package/css/Link.undecorated.colorful.css +6 -0
- package/css/Link.undecorated.css +6 -0
- package/css/List.base.css +98 -0
- package/css/List.css +1 -0
- package/css/ListItem.base.css +59 -0
- package/css/ListItem.css +1 -0
- package/css/Menu.base.css +21 -0
- package/css/Menu.css +1 -0
- package/css/MenuBar.base.css +9 -0
- package/css/MenuBar.css +1 -0
- package/css/MenuButton.base.css +13 -0
- package/css/MenuButton.css +1 -0
- package/css/MenuItem.base.css +48 -0
- package/css/MenuItem.css +1 -0
- package/css/MenuItemDisplay.base.css +104 -0
- package/css/MenuItemDisplay.css +1 -0
- package/css/MenuSeparator.base.css +5 -0
- package/css/MenuSeparator.css +1 -0
- package/css/Popover copy.css +21 -0
- package/css/Popover.css +21 -0
- package/css/Progress.base.css +99 -0
- package/css/Progress.css +1 -0
- package/css/Radio.base.css +135 -0
- package/css/Radio.colorful.css +18 -0
- package/css/Radio.css +2 -0
- package/css/RgbColorSliders.base.css +94 -0
- package/css/RgbColorSliders.css +1 -0
- package/css/Select.base.css +127 -0
- package/css/Select.colorful.css +24 -0
- package/css/Select.composed.css +12 -0
- package/css/Select.css +3 -0
- package/css/Slider.base.css +182 -0
- package/css/Slider.colorful.css +11 -0
- package/css/Slider.composed.css +8 -0
- package/css/Slider.css +3 -0
- package/css/Switch.base.css +193 -0
- package/css/Switch.colorful.css +39 -0
- package/css/Switch.css +2 -0
- package/css/Tab.base.css +135 -0
- package/css/Tab.colorful.css +13 -0
- package/css/Tab.css +2 -0
- package/css/TabList.base.css +34 -0
- package/css/TabList.css +1 -0
- package/css/TextArea.base.css +85 -0
- package/css/TextArea.colorful.css +17 -0
- package/css/TextArea.composed.css +8 -0
- package/css/TextArea.css +3 -0
- package/css/Tooltip.base.css +6 -0
- package/css/Tooltip.css +1 -0
- package/css/Tree.base.css +74 -0
- package/css/Tree.composed.css +8 -0
- package/css/Tree.css +2 -0
- package/css/TreeChevron.base.css +86 -0
- package/css/TreeChevron.css +1 -0
- package/css/TreeItem.base.css +3 -0
- package/css/TreeItem.css +1 -0
- package/css/TreeItemDisplay.base.css +74 -0
- package/css/TreeItemDisplay.colorful.css +9 -0
- package/css/TreeItemDisplay.css +1 -0
- package/css/dark-mode.css +134 -0
- package/css/light-mode.css +134 -0
- package/css/sterling.css +37 -0
- package/index.d.ts +9 -13
- package/index.js +8 -12
- package/mediaQueries/prefersColorSchemeDark.d.ts +2 -0
- package/mediaQueries/prefersColorSchemeDark.js +10 -0
- package/{stores → mediaQueries}/prefersReducedMotion.d.ts +1 -0
- package/{stores → mediaQueries}/usingKeyboard.d.ts +1 -0
- package/package.json +121 -13
- package/Link.constants.d.ts +0 -1
- package/Link.constants.js +0 -1
- package/Link.types.d.ts +0 -4
- package/Link.types.js +0 -1
- package/theme/applyDarkTheme.d.ts +0 -7
- package/theme/applyDarkTheme.js +0 -11
- package/theme/applyLightTheme.d.ts +0 -7
- package/theme/applyLightTheme.js +0 -11
- package/theme/applyTheme.d.ts +0 -7
- package/theme/applyTheme.js +0 -20
- package/theme/colors.d.ts +0 -54
- package/theme/colors.js +0 -82
- package/theme/darkTheme.d.ts +0 -2
- package/theme/darkTheme.js +0 -142
- package/theme/lightTheme.d.ts +0 -2
- package/theme/lightTheme.js +0 -119
- package/theme/toggleDarkTheme.d.ts +0 -18
- package/theme/toggleDarkTheme.js +0 -53
- package/theme/types.d.ts +0 -21
- package/theme/types.js +0 -1
- /package/{stores → mediaQueries}/prefersReducedMotion.js +0 -0
- /package/{stores → mediaQueries}/usingKeyboard.js +0 -0
package/TreeItem.svelte
CHANGED
|
@@ -1,258 +1,294 @@
|
|
|
1
|
-
<script>import { getContext, setContext } from
|
|
2
|
-
import { slide } from
|
|
3
|
-
import { TREE_CONTEXT_KEY
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
1
|
+
<script>import { getContext, setContext } from 'svelte';
|
|
2
|
+
import { slide } from 'svelte/transition';
|
|
3
|
+
import { TREE_CONTEXT_KEY } from './Tree.constants';
|
|
4
|
+
import { TREE_ITEM_CONTEXT_KEY } from './TreeItem.constants';
|
|
5
|
+
import TreeItemDisplay from './TreeItemDisplay.svelte';
|
|
6
|
+
import { readable, writable } from 'svelte/store';
|
|
7
|
+
import { prefersReducedMotion } from './mediaQueries/prefersReducedMotion';
|
|
8
|
+
// ----- Props ----
|
|
9
|
+
/** When true, the item is disabled. */
|
|
7
10
|
export let disabled = false;
|
|
8
|
-
|
|
11
|
+
/** The text for the item. Not used when either the item or label slots are filled. */
|
|
12
|
+
export let text = undefined;
|
|
13
|
+
/** The value uniquely identifying this item within the tree. */
|
|
9
14
|
export let value;
|
|
15
|
+
/** Additional class names to apply. */
|
|
16
|
+
export let variant = '';
|
|
17
|
+
// ----- Animation ----- //
|
|
10
18
|
const slidNoOp = (node, params) => {
|
|
11
|
-
|
|
19
|
+
return { delay: 0, duration: 0 };
|
|
12
20
|
};
|
|
13
|
-
$:
|
|
14
|
-
|
|
15
|
-
const {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
selectedValue
|
|
20
|
-
} = getContext(TREE_CONTEXT_KEY);
|
|
21
|
-
const { depth = 0 } = getContext(TREE_ITEM_CONTEXT_KEY) || {
|
|
22
|
-
colorful: readable(false),
|
|
23
|
-
disabled: readable(false),
|
|
24
|
-
expandedValues: readable([]),
|
|
25
|
-
selectedValue: readable(void 0)
|
|
21
|
+
$: slideMotion = !$prefersReducedMotion ? slide : slidNoOp;
|
|
22
|
+
// ----- Get Context ----- //
|
|
23
|
+
const { disabled: treeDisabled, expandedValues, selectedValue } = getContext(TREE_CONTEXT_KEY);
|
|
24
|
+
const { depth, disabled: parentDisabled } = getContext(TREE_ITEM_CONTEXT_KEY) || {
|
|
25
|
+
depth: readable(0),
|
|
26
|
+
disabled: readable(false)
|
|
26
27
|
};
|
|
28
|
+
// ----- State ----- //
|
|
27
29
|
let treeItemRef;
|
|
28
|
-
$:
|
|
29
|
-
|
|
30
|
-
$:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
$:
|
|
35
|
-
_disabled = disabled || $treeDisabled;
|
|
36
|
-
const disabledStore = writable(disabled);
|
|
30
|
+
$: hasChildren = $$slots.default;
|
|
31
|
+
$: expanded = $expandedValues.includes(value);
|
|
32
|
+
$: selected = $selectedValue === value;
|
|
33
|
+
$: _disabled = disabled || $parentDisabled || $treeDisabled;
|
|
34
|
+
const depthStore = writable($depth);
|
|
35
|
+
const disabledStore = writable(_disabled);
|
|
37
36
|
$: {
|
|
38
|
-
|
|
37
|
+
depthStore.set($depth + 1);
|
|
39
38
|
}
|
|
39
|
+
$: {
|
|
40
|
+
disabledStore.set(_disabled);
|
|
41
|
+
}
|
|
42
|
+
// ----- Expand/Collapse ----- //
|
|
40
43
|
const collapseItem = (index) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
if (!_disabled) {
|
|
45
|
+
index = index ?? $expandedValues.findIndex((expandedValue) => expandedValue === value);
|
|
46
|
+
if (index !== -1) {
|
|
47
|
+
expandedValues.set([
|
|
48
|
+
...$expandedValues.slice(0, index),
|
|
49
|
+
...$expandedValues.slice(index + 1)
|
|
50
|
+
]);
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
49
53
|
}
|
|
50
|
-
|
|
51
|
-
return false;
|
|
54
|
+
return false;
|
|
52
55
|
};
|
|
53
56
|
export const collapse = () => collapseItem();
|
|
54
57
|
const expandItem = (index) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
if (!_disabled) {
|
|
59
|
+
index = index ?? $expandedValues.findIndex((expandedValue) => expandedValue === value);
|
|
60
|
+
if (index === -1) {
|
|
61
|
+
expandedValues.set([...$expandedValues, value]);
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
60
64
|
}
|
|
61
|
-
|
|
62
|
-
return false;
|
|
65
|
+
return false;
|
|
63
66
|
};
|
|
64
67
|
export const expand = () => expandItem();
|
|
65
68
|
export const toggleExpanded = () => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
if (!_disabled) {
|
|
70
|
+
const index = $expandedValues.findIndex((expandedValue) => expandedValue === value);
|
|
71
|
+
return index !== -1 ? collapseItem(index) : expandItem(index);
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
71
74
|
};
|
|
75
|
+
// ----- Focus ----- //
|
|
72
76
|
const blurItem = (treeItemElement) => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
if (!_disabled) {
|
|
78
|
+
const item = treeItemElement?.querySelector('.item');
|
|
79
|
+
item?.blur();
|
|
80
|
+
}
|
|
77
81
|
};
|
|
78
82
|
export const blur = () => {
|
|
79
|
-
|
|
83
|
+
blurItem(treeItemRef);
|
|
80
84
|
};
|
|
81
85
|
const focusItem = (treeItemElement, options) => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
if (!_disabled) {
|
|
87
|
+
const item = treeItemElement?.querySelector('.item');
|
|
88
|
+
item?.focus(options);
|
|
89
|
+
}
|
|
86
90
|
};
|
|
87
91
|
export const focus = (options) => {
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
focusItem(treeItemRef);
|
|
93
|
+
treeItemRef?.focus(options);
|
|
90
94
|
};
|
|
95
|
+
// ----- Click ----- //
|
|
91
96
|
const clickItem = (treeItemElement) => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
if (!_disabled) {
|
|
98
|
+
const item = treeItemElement?.querySelector('.item');
|
|
99
|
+
item?.click();
|
|
100
|
+
}
|
|
96
101
|
};
|
|
97
102
|
export const click = () => {
|
|
98
|
-
|
|
103
|
+
clickItem(treeItemRef);
|
|
99
104
|
};
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
105
|
+
// ----- Selection ----- //
|
|
106
|
+
const selectItemByValue = (value) => {
|
|
107
|
+
if (!_disabled) {
|
|
108
|
+
selectedValue.set(value);
|
|
109
|
+
}
|
|
104
110
|
};
|
|
105
111
|
export const select = () => {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
112
|
+
if (!_disabled) {
|
|
113
|
+
selectItemByValue(value);
|
|
114
|
+
}
|
|
109
115
|
};
|
|
110
116
|
export const selectParent = () => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
if (!_disabled) {
|
|
118
|
+
let candidate = treeItemRef.parentElement?.closest('[role="treeitem"][data-value]');
|
|
119
|
+
let candidateValue = candidate?.getAttribute('data-value');
|
|
120
|
+
if (candidateValue && candidate) {
|
|
121
|
+
selectItemByValue(candidateValue);
|
|
122
|
+
focusItem(candidate);
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
118
125
|
}
|
|
119
|
-
|
|
120
|
-
return false;
|
|
126
|
+
return false;
|
|
121
127
|
};
|
|
122
128
|
export const selectPrevious = () => {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
129
|
+
if (!_disabled) {
|
|
130
|
+
let candidate = undefined;
|
|
131
|
+
let candidateValue = undefined;
|
|
132
|
+
const previousSibling = treeItemRef?.previousElementSibling;
|
|
133
|
+
if (previousSibling) {
|
|
134
|
+
// look for the last (recursive) decendant of ths previous sibling
|
|
135
|
+
const decendants = previousSibling.querySelectorAll('[role="treeitem"][data-value]');
|
|
136
|
+
if (decendants) {
|
|
137
|
+
candidate = decendants[decendants.length - 1];
|
|
138
|
+
candidateValue = candidate?.getAttribute('data-value');
|
|
139
|
+
}
|
|
140
|
+
// look for the previous sibling
|
|
141
|
+
if (!candidateValue) {
|
|
142
|
+
candidate = previousSibling;
|
|
143
|
+
candidateValue = candidate?.getAttribute('data-value');
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// look for the parent
|
|
147
|
+
if (!candidateValue) {
|
|
148
|
+
candidate = treeItemRef.parentElement?.closest('[role="treeitem"][data-value]');
|
|
149
|
+
candidateValue = candidate?.getAttribute('data-value');
|
|
150
|
+
}
|
|
151
|
+
if (candidateValue && candidate) {
|
|
152
|
+
selectItemByValue(candidateValue);
|
|
153
|
+
focusItem(candidate);
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
146
156
|
}
|
|
147
|
-
|
|
148
|
-
return false;
|
|
157
|
+
return false;
|
|
149
158
|
};
|
|
150
159
|
export const selectNext = () => {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
160
|
+
if (!_disabled) {
|
|
161
|
+
let candidateValue = undefined;
|
|
162
|
+
// look for decendants
|
|
163
|
+
let candidate = treeItemRef.querySelector('[role="treeitem"][data-value]');
|
|
164
|
+
candidateValue = candidate?.getAttribute('data-value');
|
|
165
|
+
// look for next sibling
|
|
166
|
+
if (!candidateValue) {
|
|
167
|
+
candidate = treeItemRef.nextElementSibling;
|
|
168
|
+
while (candidate && candidate.getAttribute('data-value') === null) {
|
|
169
|
+
candidate = candidate.nextElementSibling;
|
|
170
|
+
}
|
|
171
|
+
candidateValue = candidate?.getAttribute('data-value');
|
|
172
|
+
}
|
|
173
|
+
// look for next sibling of ancestor
|
|
174
|
+
if (!candidateValue) {
|
|
175
|
+
let ancestor = treeItemRef.parentElement?.closest('[role="treeitem"][data-value]');
|
|
176
|
+
while (ancestor && !candidateValue) {
|
|
177
|
+
candidate = ancestor?.nextElementSibling;
|
|
178
|
+
candidateValue = candidate?.getAttribute('data-value');
|
|
179
|
+
ancestor = ancestor.parentElement?.closest('[role="treeitem"][data-value]');
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (candidateValue && candidate) {
|
|
183
|
+
selectItemByValue(candidateValue);
|
|
184
|
+
focusItem(candidate);
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
176
187
|
}
|
|
177
|
-
|
|
178
|
-
return false;
|
|
188
|
+
return false;
|
|
179
189
|
};
|
|
190
|
+
// ----- Event Handlers ----- //
|
|
180
191
|
const onClick = () => {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
192
|
+
if (!_disabled) {
|
|
193
|
+
toggleExpanded();
|
|
194
|
+
select();
|
|
195
|
+
}
|
|
185
196
|
};
|
|
186
197
|
const onKeydown = (event) => {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
198
|
+
if (!event.altKey && !event.ctrlKey && !event.shiftKey) {
|
|
199
|
+
switch (event.key) {
|
|
200
|
+
case 'Enter':
|
|
201
|
+
case ' ':
|
|
202
|
+
if (toggleExpanded()) {
|
|
203
|
+
event.preventDefault();
|
|
204
|
+
event.stopPropagation();
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
break;
|
|
208
|
+
case 'ArrowRight':
|
|
209
|
+
/*
|
|
210
|
+
When focus is on a closed item, opens the item; focus does not move.
|
|
211
|
+
When focus is on an open item, moves focus to the first child item.
|
|
212
|
+
When focus is on an end item (a tree item with no children), does nothing.
|
|
213
|
+
*/
|
|
214
|
+
if (hasChildren) {
|
|
215
|
+
if (expanded) {
|
|
216
|
+
if (selectNext()) {
|
|
217
|
+
event.preventDefault();
|
|
218
|
+
event.stopPropagation();
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
else if (expandItem()) {
|
|
223
|
+
event.preventDefault();
|
|
224
|
+
event.stopPropagation();
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
break;
|
|
229
|
+
case 'ArrowLeft':
|
|
230
|
+
/*
|
|
231
|
+
When focus is on an open item, closes the item.
|
|
232
|
+
When focus is on a child item that is also either an end item or a closed item, moves focus to its parent item.
|
|
233
|
+
When focus is on a closed `tree`, does nothing.
|
|
234
|
+
*/
|
|
235
|
+
if (hasChildren && expanded) {
|
|
236
|
+
if (collapseItem()) {
|
|
237
|
+
event.preventDefault();
|
|
238
|
+
event.stopPropagation();
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
else if (selectParent()) {
|
|
243
|
+
event.preventDefault();
|
|
244
|
+
event.stopPropagation();
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
break;
|
|
248
|
+
case 'ArrowUp':
|
|
249
|
+
/*
|
|
250
|
+
Moves focus to the previous item that is focusable without opening or closing a item.
|
|
251
|
+
*/
|
|
252
|
+
if (selectPrevious()) {
|
|
253
|
+
event.preventDefault();
|
|
254
|
+
event.stopPropagation();
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
break;
|
|
258
|
+
case 'ArrowDown':
|
|
259
|
+
/*
|
|
260
|
+
Moves focus to the next item that is focusable without opening or closing a item.
|
|
261
|
+
*/
|
|
262
|
+
if (selectNext()) {
|
|
263
|
+
event.preventDefault();
|
|
264
|
+
event.stopPropagation();
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
break;
|
|
210
268
|
}
|
|
211
|
-
break;
|
|
212
|
-
case "ArrowLeft":
|
|
213
|
-
if (hasChildren && expanded) {
|
|
214
|
-
if (collapseItem()) {
|
|
215
|
-
event.preventDefault();
|
|
216
|
-
event.stopPropagation();
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
|
-
} else if (selectParent()) {
|
|
220
|
-
event.preventDefault();
|
|
221
|
-
event.stopPropagation();
|
|
222
|
-
return false;
|
|
223
|
-
}
|
|
224
|
-
break;
|
|
225
|
-
case "ArrowUp":
|
|
226
|
-
if (selectPrevious()) {
|
|
227
|
-
event.preventDefault();
|
|
228
|
-
event.stopPropagation();
|
|
229
|
-
return false;
|
|
230
|
-
}
|
|
231
|
-
break;
|
|
232
|
-
case "ArrowDown":
|
|
233
|
-
if (selectNext()) {
|
|
234
|
-
event.preventDefault();
|
|
235
|
-
event.stopPropagation();
|
|
236
|
-
return false;
|
|
237
|
-
}
|
|
238
|
-
break;
|
|
239
269
|
}
|
|
240
|
-
}
|
|
241
270
|
};
|
|
242
|
-
|
|
271
|
+
// ----- Set Context ----- //
|
|
272
|
+
setContext(TREE_ITEM_CONTEXT_KEY, {
|
|
273
|
+
depth: depthStore,
|
|
274
|
+
disabled: disabledStore
|
|
275
|
+
});
|
|
243
276
|
</script>
|
|
244
277
|
|
|
245
278
|
<!--
|
|
246
279
|
@component
|
|
247
280
|
A item in a Tree displaying the item and children.
|
|
248
281
|
-->
|
|
282
|
+
<!-- svelte-ignore a11y-interactive-supports-focus -->
|
|
249
283
|
<div
|
|
250
284
|
aria-selected={selected ? true : undefined}
|
|
251
285
|
aria-expanded={expanded}
|
|
252
286
|
bind:this={treeItemRef}
|
|
253
|
-
class=
|
|
254
|
-
class:colorful={$colorful}
|
|
287
|
+
class={`sterling-tree-item ${variant}`}
|
|
255
288
|
class:disabled={_disabled}
|
|
289
|
+
class:item-disabled={disabled}
|
|
290
|
+
class:parent-disabled={$parentDisabled}
|
|
291
|
+
class:tree-disabled={$treeDisabled}
|
|
256
292
|
data-value={value}
|
|
257
293
|
role="treeitem"
|
|
258
294
|
on:blur
|
|
@@ -288,42 +324,52 @@ A item in a Tree displaying the item and children.
|
|
|
288
324
|
on:wheel|passive
|
|
289
325
|
{...$$restProps}
|
|
290
326
|
>
|
|
291
|
-
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
|
292
327
|
<div
|
|
328
|
+
aria-selected={selected ? true : undefined}
|
|
293
329
|
class="item"
|
|
294
330
|
class:selected
|
|
331
|
+
role="treeitem"
|
|
295
332
|
tabindex={selected ? 0 : -1}
|
|
296
333
|
on:click={onClick}
|
|
297
334
|
on:keydown={onKeydown}
|
|
298
335
|
>
|
|
299
|
-
<slot
|
|
336
|
+
<slot
|
|
337
|
+
name="item"
|
|
338
|
+
{depth}
|
|
339
|
+
disabled={_disabled}
|
|
340
|
+
{expanded}
|
|
341
|
+
{hasChildren}
|
|
342
|
+
{selected}
|
|
343
|
+
{value}
|
|
344
|
+
{variant}
|
|
345
|
+
>
|
|
300
346
|
<TreeItemDisplay
|
|
301
|
-
|
|
302
|
-
{
|
|
303
|
-
disabled={_disabled}
|
|
347
|
+
depth={$depth}
|
|
348
|
+
disabled={_disabled && !$treeDisabled}
|
|
304
349
|
{expanded}
|
|
305
350
|
{hasChildren}
|
|
306
351
|
{selected}
|
|
307
352
|
{value}
|
|
353
|
+
{variant}
|
|
308
354
|
>
|
|
309
355
|
<svelte:fragment
|
|
310
|
-
let:colorful
|
|
311
356
|
let:depth
|
|
312
357
|
let:disabled
|
|
313
358
|
let:expanded
|
|
314
359
|
let:hasChildren
|
|
315
360
|
let:selected
|
|
316
361
|
let:value
|
|
362
|
+
let:variant
|
|
317
363
|
>
|
|
318
364
|
<slot
|
|
319
365
|
name="label"
|
|
320
|
-
{colorful}
|
|
321
366
|
{depth}
|
|
322
367
|
{disabled}
|
|
323
368
|
{expanded}
|
|
324
369
|
{hasChildren}
|
|
325
370
|
{selected}
|
|
326
|
-
{value}
|
|
371
|
+
{value}
|
|
372
|
+
{variant}>{text || value}</slot
|
|
327
373
|
>
|
|
328
374
|
</svelte:fragment>
|
|
329
375
|
</TreeItemDisplay>
|
|
@@ -331,13 +377,7 @@ A item in a Tree displaying the item and children.
|
|
|
331
377
|
</div>
|
|
332
378
|
{#if expanded && hasChildren}
|
|
333
379
|
<div class="children" transition:slideMotion|global={{ duration: 200 }} role="group">
|
|
334
|
-
<slot {depth} {selected} {value} />
|
|
380
|
+
<slot depth={$depth} disabled={_disabled} {selected} {value} {variant} />
|
|
335
381
|
</div>
|
|
336
382
|
{/if}
|
|
337
383
|
</div>
|
|
338
|
-
|
|
339
|
-
<style>
|
|
340
|
-
.item {
|
|
341
|
-
outline: none;
|
|
342
|
-
}
|
|
343
|
-
</style>
|
package/TreeItem.svelte.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ declare const __propDef: {
|
|
|
5
5
|
disabled?: boolean | undefined;
|
|
6
6
|
text?: string | undefined;
|
|
7
7
|
value: string;
|
|
8
|
+
variant?: string | undefined;
|
|
8
9
|
collapse?: (() => boolean) | undefined;
|
|
9
10
|
expand?: (() => boolean) | undefined;
|
|
10
11
|
toggleExpanded?: (() => boolean) | undefined;
|
|
@@ -53,26 +54,29 @@ declare const __propDef: {
|
|
|
53
54
|
};
|
|
54
55
|
slots: {
|
|
55
56
|
item: {
|
|
56
|
-
depth: number
|
|
57
|
+
depth: import("svelte/store").Readable<number>;
|
|
57
58
|
disabled: boolean;
|
|
58
59
|
expanded: boolean;
|
|
59
60
|
hasChildren: boolean;
|
|
60
61
|
selected: boolean;
|
|
61
62
|
value: string;
|
|
63
|
+
variant: string;
|
|
62
64
|
};
|
|
63
65
|
label: {
|
|
64
|
-
|
|
65
|
-
depth: number;
|
|
66
|
+
depth: import("svelte/store").Readable<number>;
|
|
66
67
|
disabled: boolean;
|
|
67
68
|
expanded: boolean;
|
|
68
69
|
hasChildren: boolean;
|
|
69
70
|
selected: boolean;
|
|
70
71
|
value: string;
|
|
72
|
+
variant: string;
|
|
71
73
|
};
|
|
72
74
|
default: {
|
|
73
75
|
depth: number;
|
|
76
|
+
disabled: boolean;
|
|
74
77
|
selected: boolean;
|
|
75
78
|
value: string;
|
|
79
|
+
variant: string;
|
|
76
80
|
};
|
|
77
81
|
};
|
|
78
82
|
};
|
package/TreeItem.types.d.ts
CHANGED