@geoffcox/sterling-svelte 0.0.16 → 0.0.18
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/{buttons/Button.svelte → Button.svelte} +27 -27
- package/{inputs/Checkbox.svelte → Checkbox.svelte} +26 -21
- package/{inputs/Checkbox.svelte.d.ts → Checkbox.svelte.d.ts} +2 -1
- package/{surfaces/Dialog.svelte → Dialog.svelte} +34 -21
- package/Field.svelte +257 -0
- package/Field.svelte.d.ts +63 -0
- package/Field.types.d.ts +1 -0
- package/Input.svelte +115 -0
- package/{inputs/Input.svelte.d.ts → Input.svelte.d.ts} +8 -3
- package/Label.svelte +51 -0
- package/Label.svelte.d.ts +41 -0
- package/List.constants.d.ts +1 -0
- package/List.constants.js +1 -0
- package/List.svelte +293 -0
- package/List.svelte.d.ts +63 -0
- package/List.types.d.ts +6 -0
- package/ListItem.svelte +89 -0
- package/ListItem.svelte.d.ts +51 -0
- package/{containers/Menu.svelte → Menu.svelte} +42 -27
- package/{containers/MenuBar.svelte → MenuBar.svelte} +13 -13
- package/{buttons/MenuButton.svelte → MenuButton.svelte} +17 -17
- package/{buttons/MenuButton.svelte.d.ts → MenuButton.svelte.d.ts} +1 -1
- package/{containers/MenuItem.svelte → MenuItem.svelte} +42 -54
- package/{containers/MenuItem.svelte.d.ts → MenuItem.svelte.d.ts} +2 -2
- package/{containers/MenuSeparator.svelte → MenuSeparator.svelte} +2 -2
- package/Menus.types.d.ts +22 -0
- package/{containers/Menus.utils.d.ts → Menus.utils.d.ts} +2 -2
- package/{containers/Menus.utils.js → Menus.utils.js} +6 -6
- package/{display/Progress.svelte → Progress.svelte} +28 -52
- package/{display/Progress.svelte.d.ts → Progress.svelte.d.ts} +1 -3
- package/Progress.types.d.ts +1 -0
- package/{inputs/Radio.svelte → Radio.svelte} +34 -29
- package/{inputs/Radio.svelte.d.ts → Radio.svelte.d.ts} +7 -2
- package/{inputs/Select.svelte → Select.svelte} +112 -130
- package/Select.svelte.d.ts +53 -0
- package/{inputs/Slider.svelte → Slider.svelte} +90 -86
- package/Slider.svelte.d.ts +51 -0
- package/{inputs/Switch.svelte → Switch.svelte} +43 -41
- package/Tab.svelte +181 -0
- package/{containers/Tab.svelte.d.ts → Tab.svelte.d.ts} +12 -15
- package/TabList.svelte +247 -0
- package/{containers/TabList.svelte.d.ts → TabList.svelte.d.ts} +21 -21
- package/TabList.types.d.ts +7 -0
- package/TextArea.svelte +113 -0
- package/{inputs/TextArea.svelte.d.ts → TextArea.svelte.d.ts} +3 -6
- package/TextArea.types.js +1 -0
- package/Tooltip.svelte +182 -0
- package/Tooltip.svelte.d.ts +24 -0
- package/Tooltip.types.d.ts +3 -0
- package/Tooltip.types.js +1 -0
- package/Tree.constants.d.ts +2 -0
- package/Tree.constants.js +2 -0
- package/Tree.svelte +114 -0
- package/Tree.svelte.d.ts +24 -0
- package/Tree.types.d.ts +28 -0
- package/Tree.types.js +1 -0
- package/{containers/TreeChevron.svelte → TreeChevron.svelte} +3 -3
- package/TreeItem.svelte +276 -0
- package/TreeItem.svelte.d.ts +65 -0
- package/{containers/TreeItem.svelte → TreeItemDisplay.svelte} +18 -18
- package/{containers/TreeItem.svelte.d.ts → TreeItemDisplay.svelte.d.ts} +11 -14
- package/{forwardEvents.js → actions/forwardEvents.js} +0 -2
- package/index.d.ts +44 -31
- package/index.js +40 -25
- package/package.json +45 -41
- package/theme/darkTheme.js +73 -74
- package/theme/lightTheme.js +76 -77
- package/containers/List.svelte +0 -249
- package/containers/List.svelte.d.ts +0 -68
- package/containers/ListItem.svelte +0 -48
- package/containers/ListItem.svelte.d.ts +0 -26
- package/containers/Menus.types.d.ts +0 -22
- package/containers/Tab.svelte +0 -327
- package/containers/TabList.svelte +0 -126
- package/containers/Tabs.types.d.ts +0 -12
- package/containers/Tree.constants.d.ts +0 -2
- package/containers/Tree.constants.js +0 -2
- package/containers/Tree.svelte +0 -222
- package/containers/Tree.svelte.d.ts +0 -50
- package/containers/Tree.types.d.ts +0 -47
- package/containers/TreeNode.svelte +0 -266
- package/containers/TreeNode.svelte.d.ts +0 -43
- package/display/Label.svelte +0 -27
- package/display/Label.svelte.d.ts +0 -20
- package/display/Progress.types.d.ts +0 -1
- package/inputs/Input.svelte +0 -129
- package/inputs/Select.svelte.d.ts +0 -62
- package/inputs/Slider.svelte.d.ts +0 -28
- package/inputs/TextArea.svelte +0 -154
- package/surfaces/CloseX.svelte +0 -5
- package/surfaces/CloseX.svelte.d.ts +0 -23
- package/surfaces/Portal.svelte +0 -14
- package/surfaces/Portal.svelte.d.ts +0 -21
- /package/{buttons/Button.svelte.d.ts → Button.svelte.d.ts} +0 -0
- /package/{buttons/Button.types.d.ts → Button.types.d.ts} +0 -0
- /package/{buttons/Button.types.js → Button.types.js} +0 -0
- /package/{surfaces/Dialog.svelte.d.ts → Dialog.svelte.d.ts} +0 -0
- /package/{containers/Menus.types.js → Field.types.js} +0 -0
- /package/{containers/Tabs.types.js → List.types.js} +0 -0
- /package/{containers/Menu.svelte.d.ts → Menu.svelte.d.ts} +0 -0
- /package/{containers/MenuBar.svelte.d.ts → MenuBar.svelte.d.ts} +0 -0
- /package/{containers/MenuItemDisplay.svelte → MenuItemDisplay.svelte} +0 -0
- /package/{containers/MenuItemDisplay.svelte.d.ts → MenuItemDisplay.svelte.d.ts} +0 -0
- /package/{containers/MenuSeparator.svelte.d.ts → MenuSeparator.svelte.d.ts} +0 -0
- /package/{containers/Menus.constants.d.ts → Menus.constants.d.ts} +0 -0
- /package/{containers/Menus.constants.js → Menus.constants.js} +0 -0
- /package/{containers/Tree.types.js → Menus.types.js} +0 -0
- /package/{display/Progress.types.js → Progress.types.js} +0 -0
- /package/{inputs/Switch.svelte.d.ts → Switch.svelte.d.ts} +0 -0
- /package/{containers/Tabs.constants.d.ts → TabList.constants.d.ts} +0 -0
- /package/{containers/Tabs.constants.js → TabList.constants.js} +0 -0
- /package/{inputs/TextArea.types.js → TabList.types.js} +0 -0
- /package/{inputs/TextArea.types.d.ts → TextArea.types.d.ts} +0 -0
- /package/{containers/TreeChevron.svelte.d.ts → TreeChevron.svelte.d.ts} +0 -0
- /package/{clickOutside.d.ts → actions/clickOutside.d.ts} +0 -0
- /package/{clickOutside.js → actions/clickOutside.js} +0 -0
- /package/{forwardEvents.d.ts → actions/forwardEvents.d.ts} +0 -0
- /package/{portal.d.ts → actions/portal.d.ts} +0 -0
- /package/{portal.js → actions/portal.js} +0 -0
package/containers/Tree.svelte
DELETED
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
<script>import { v4 as uuid } from "uuid";
|
|
2
|
-
import { createEventDispatcher, setContext } from "svelte";
|
|
3
|
-
import { writable } from "svelte/store";
|
|
4
|
-
import { treeContextKey, treeNodeContextKey } from "./Tree.constants";
|
|
5
|
-
import Label from "../display/Label.svelte";
|
|
6
|
-
import TreeNode from "./TreeNode.svelte";
|
|
7
|
-
import TreeItem from "./TreeItem.svelte";
|
|
8
|
-
const inputId = uuid();
|
|
9
|
-
let nodeIdCounter = 0;
|
|
10
|
-
const getDefaultNodeId = (node) => {
|
|
11
|
-
if (node.nodeId) {
|
|
12
|
-
return node.nodeId;
|
|
13
|
-
} else {
|
|
14
|
-
nodeIdCounter++;
|
|
15
|
-
return `node-${nodeIdCounter}`;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
export let composed = false;
|
|
19
|
-
export let disabled = false;
|
|
20
|
-
export let getNodeId = getDefaultNodeId;
|
|
21
|
-
export let nodes = void 0;
|
|
22
|
-
export let selectedNodeId = void 0;
|
|
23
|
-
export let expandedNodeIds = [];
|
|
24
|
-
const selectedNodeIdStore = writable(selectedNodeId);
|
|
25
|
-
const expandedNodeIdStore = writable(expandedNodeIds);
|
|
26
|
-
const selectedNodeEventHandlersStore = writable();
|
|
27
|
-
setContext(treeContextKey, {
|
|
28
|
-
expandedNodeIds: expandedNodeIdStore,
|
|
29
|
-
getNodeId,
|
|
30
|
-
selectedNodeId: selectedNodeIdStore,
|
|
31
|
-
selectedNodeEventHandlers: selectedNodeEventHandlersStore
|
|
32
|
-
});
|
|
33
|
-
setContext(treeNodeContextKey, { parentNodeId: void 0, depth: 0 });
|
|
34
|
-
const dispatch = createEventDispatcher();
|
|
35
|
-
const raiseExpandCollapse = (expandedNodeIds2) => {
|
|
36
|
-
dispatch("expandCollapse", { expandedNodeIds: expandedNodeIds2 });
|
|
37
|
-
};
|
|
38
|
-
const raiseSelect = (selectedNodeId2) => {
|
|
39
|
-
dispatch("select", { selectedNodeId: selectedNodeId2 });
|
|
40
|
-
};
|
|
41
|
-
$: {
|
|
42
|
-
selectedNodeIdStore.set(selectedNodeId);
|
|
43
|
-
}
|
|
44
|
-
$: {
|
|
45
|
-
selectedNodeId = $selectedNodeIdStore;
|
|
46
|
-
raiseSelect($selectedNodeIdStore);
|
|
47
|
-
}
|
|
48
|
-
$: {
|
|
49
|
-
expandedNodeIdStore.set(expandedNodeIds);
|
|
50
|
-
}
|
|
51
|
-
$: {
|
|
52
|
-
expandedNodeIds = $expandedNodeIdStore;
|
|
53
|
-
raiseExpandCollapse($expandedNodeIdStore);
|
|
54
|
-
}
|
|
55
|
-
const getAllNodeIds = (node, nodeIds) => {
|
|
56
|
-
nodeIds.push(getNodeId(node));
|
|
57
|
-
node.children?.forEach((child) => getAllNodeIds(child, nodeIds));
|
|
58
|
-
};
|
|
59
|
-
const setToggleNodeIdsToAll = () => {
|
|
60
|
-
const nodeIds = [];
|
|
61
|
-
nodes?.forEach((node) => getAllNodeIds(node, nodeIds));
|
|
62
|
-
expandedNodeIds = nodeIds;
|
|
63
|
-
};
|
|
64
|
-
export const collapseAll = () => {
|
|
65
|
-
expandedNodeIds = [];
|
|
66
|
-
};
|
|
67
|
-
export const expandAll = () => {
|
|
68
|
-
setToggleNodeIdsToAll();
|
|
69
|
-
};
|
|
70
|
-
const onKeydown = (event) => {
|
|
71
|
-
return $selectedNodeEventHandlersStore?.onKeydown?.(event);
|
|
72
|
-
};
|
|
73
|
-
</script>
|
|
74
|
-
|
|
75
|
-
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
|
76
|
-
<div
|
|
77
|
-
class="sterling-tree"
|
|
78
|
-
class:disabled
|
|
79
|
-
class:composed
|
|
80
|
-
tabindex={!disabled ? 0 : undefined}
|
|
81
|
-
on:keydown={onKeydown}
|
|
82
|
-
>
|
|
83
|
-
{#if $$slots.label}
|
|
84
|
-
<Label {disabled} for={inputId}>
|
|
85
|
-
<slot name="label" />
|
|
86
|
-
</Label>
|
|
87
|
-
{/if}
|
|
88
|
-
<div class="tree" role="tree">
|
|
89
|
-
{#if nodes}
|
|
90
|
-
{#each nodes as node}
|
|
91
|
-
<TreeNode {disabled} {node} nodeId={getNodeId(node)}>
|
|
92
|
-
<!--
|
|
93
|
-
Forward the item slot into each tree node.
|
|
94
|
-
It is cleanest to have a fragment for the TreeNode item slot to
|
|
95
|
-
capture the let params, then apply them to the Tree item slot.
|
|
96
|
-
-->
|
|
97
|
-
<svelte:fragment
|
|
98
|
-
slot="item"
|
|
99
|
-
let:disabled
|
|
100
|
-
let:expanded
|
|
101
|
-
let:hasChildren
|
|
102
|
-
let:depth
|
|
103
|
-
let:node
|
|
104
|
-
let:nodeId
|
|
105
|
-
let:selected
|
|
106
|
-
>
|
|
107
|
-
<slot
|
|
108
|
-
name="item"
|
|
109
|
-
{disabled}
|
|
110
|
-
{expanded}
|
|
111
|
-
{hasChildren}
|
|
112
|
-
{depth}
|
|
113
|
-
{node}
|
|
114
|
-
{nodeId}
|
|
115
|
-
{selected}
|
|
116
|
-
>
|
|
117
|
-
<!--
|
|
118
|
-
Svelte prevents conditionally applying slots.
|
|
119
|
-
This repeats exact same item slot default for this node
|
|
120
|
-
so the item slot is passed down the tree.
|
|
121
|
-
-->
|
|
122
|
-
<TreeItem {disabled} {expanded} {hasChildren} {depth} {node} {nodeId} {selected}>
|
|
123
|
-
<svelte:fragment
|
|
124
|
-
let:disabled
|
|
125
|
-
let:expanded
|
|
126
|
-
let:hasChildren
|
|
127
|
-
let:depth
|
|
128
|
-
let:node
|
|
129
|
-
let:nodeId
|
|
130
|
-
let:selected
|
|
131
|
-
>
|
|
132
|
-
<!-- This uses the nodeLabel slot for the TreeItem default slot. -->
|
|
133
|
-
<slot
|
|
134
|
-
name="nodeLabel"
|
|
135
|
-
{disabled}
|
|
136
|
-
{expanded}
|
|
137
|
-
{hasChildren}
|
|
138
|
-
{depth}
|
|
139
|
-
{node}
|
|
140
|
-
{nodeId}
|
|
141
|
-
{selected}>{nodeId}</slot
|
|
142
|
-
>
|
|
143
|
-
</svelte:fragment>
|
|
144
|
-
</TreeItem>
|
|
145
|
-
</slot>
|
|
146
|
-
</svelte:fragment>
|
|
147
|
-
</TreeNode>
|
|
148
|
-
{/each}
|
|
149
|
-
{/if}
|
|
150
|
-
<slot />
|
|
151
|
-
</div>
|
|
152
|
-
</div>
|
|
153
|
-
|
|
154
|
-
<style>
|
|
155
|
-
.sterling-tree {
|
|
156
|
-
background-color: var(--Common__background-color);
|
|
157
|
-
border-color: var(--Common__border-color);
|
|
158
|
-
border-radius: var(--Common__border-radius);
|
|
159
|
-
border-style: var(--Common__border-style);
|
|
160
|
-
border-width: var(--Common__border-width);
|
|
161
|
-
box-sizing: border-box;
|
|
162
|
-
color: var(--Common__color);
|
|
163
|
-
display: grid;
|
|
164
|
-
grid-template-columns: 1fr;
|
|
165
|
-
grid-template-rows: auto 1fr;
|
|
166
|
-
height: 100%;
|
|
167
|
-
margin: 0;
|
|
168
|
-
overflow: hidden;
|
|
169
|
-
padding: 0;
|
|
170
|
-
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
.sterling-tree:hover {
|
|
174
|
-
border-color: var(--Common__border-color--hover);
|
|
175
|
-
color: var(--Common__color--hover);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
.sterling-tree:focus-visible {
|
|
179
|
-
border-color: var(--Common__border-color--focus);
|
|
180
|
-
color: var(--Common__color--focus);
|
|
181
|
-
outline-color: var(--Common__outline-color);
|
|
182
|
-
outline-offset: var(--Common__outline-offset);
|
|
183
|
-
outline-style: var(--Common__outline-style);
|
|
184
|
-
outline-width: var(--Common__outline-width);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
.sterling-tree.disabled {
|
|
188
|
-
background-color: var(--Common__background-color--disabled);
|
|
189
|
-
border-color: var(---Common__border-color--disabled);
|
|
190
|
-
color: var(--Common__color--disabled);
|
|
191
|
-
cursor: not-allowed;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
.sterling-tree.composed,
|
|
195
|
-
.sterling-tree:hover.composed,
|
|
196
|
-
.sterling-tree:focus-visible.composed,
|
|
197
|
-
.sterling-tree.disabled.composed {
|
|
198
|
-
background: none;
|
|
199
|
-
border: none;
|
|
200
|
-
outline: none;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
.sterling-tree > :global(label) {
|
|
204
|
-
font-size: 0.7em;
|
|
205
|
-
margin: 0.5em 0.7em;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
.sterling-tree > :global(label):empty {
|
|
209
|
-
margin: 0;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
.tree {
|
|
213
|
-
display: flex;
|
|
214
|
-
flex-direction: column;
|
|
215
|
-
flex-wrap: nowrap;
|
|
216
|
-
grid-row: 2 / span 1;
|
|
217
|
-
overflow-x: hidden;
|
|
218
|
-
overflow-y: scroll;
|
|
219
|
-
outline: none;
|
|
220
|
-
position: relative;
|
|
221
|
-
}
|
|
222
|
-
</style>
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
import type { TreeNodeData } from './Tree.types';
|
|
3
|
-
declare class __sveltets_Render<T> {
|
|
4
|
-
props(): {
|
|
5
|
-
composed?: boolean | undefined;
|
|
6
|
-
disabled?: boolean | undefined;
|
|
7
|
-
getNodeId?: ((node: TreeNodeData<T>) => string) | undefined;
|
|
8
|
-
nodes?: TreeNodeData<T>[] | undefined;
|
|
9
|
-
selectedNodeId?: string | undefined;
|
|
10
|
-
expandedNodeIds?: string[] | undefined;
|
|
11
|
-
collapseAll?: (() => void) | undefined;
|
|
12
|
-
expandAll?: (() => void) | undefined;
|
|
13
|
-
};
|
|
14
|
-
events(): {
|
|
15
|
-
expandCollapse: CustomEvent<any>;
|
|
16
|
-
select: CustomEvent<any>;
|
|
17
|
-
} & {
|
|
18
|
-
[evt: string]: CustomEvent<any>;
|
|
19
|
-
};
|
|
20
|
-
slots(): {
|
|
21
|
-
label: {};
|
|
22
|
-
item: {
|
|
23
|
-
disabled: any;
|
|
24
|
-
expanded: any;
|
|
25
|
-
hasChildren: any;
|
|
26
|
-
depth: any;
|
|
27
|
-
node: any;
|
|
28
|
-
nodeId: any;
|
|
29
|
-
selected: any;
|
|
30
|
-
};
|
|
31
|
-
nodeLabel: {
|
|
32
|
-
disabled: any;
|
|
33
|
-
expanded: any;
|
|
34
|
-
hasChildren: any;
|
|
35
|
-
depth: any;
|
|
36
|
-
node: any;
|
|
37
|
-
nodeId: any;
|
|
38
|
-
selected: any;
|
|
39
|
-
};
|
|
40
|
-
default: {};
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
export type TreeProps<T> = ReturnType<__sveltets_Render<T>['props']>;
|
|
44
|
-
export type TreeEvents<T> = ReturnType<__sveltets_Render<T>['events']>;
|
|
45
|
-
export type TreeSlots<T> = ReturnType<__sveltets_Render<T>['slots']>;
|
|
46
|
-
export default class Tree<T> extends SvelteComponentTyped<TreeProps<T>, TreeEvents<T>, TreeSlots<T>> {
|
|
47
|
-
get collapseAll(): () => void;
|
|
48
|
-
get expandAll(): () => void;
|
|
49
|
-
}
|
|
50
|
-
export {};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { Writable } from 'svelte/store';
|
|
2
|
-
export type TreeNodeData<T> = T & {
|
|
3
|
-
nodeId?: string;
|
|
4
|
-
children?: TreeNodeData<T>[];
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* The set of event handlers forwarded from Tree
|
|
8
|
-
*/
|
|
9
|
-
export type TreeForwardedEventHandlers = {
|
|
10
|
-
onKeydown: svelte.JSX.KeyboardEventHandler<Element>;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Context for a Tree and its TreeNodes
|
|
14
|
-
*/
|
|
15
|
-
export type TreeContext<T> = {
|
|
16
|
-
/**
|
|
17
|
-
* Gets the ID for the tree node.
|
|
18
|
-
*/
|
|
19
|
-
getNodeId: (node: TreeNodeData<T>) => string;
|
|
20
|
-
/**
|
|
21
|
-
* The IDs of the expanded ttree nodes.
|
|
22
|
-
*/
|
|
23
|
-
expandedNodeIds: Writable<string[]>;
|
|
24
|
-
/**
|
|
25
|
-
* The ID of the selected tree node.
|
|
26
|
-
*/
|
|
27
|
-
selectedNodeId: Writable<string | undefined>;
|
|
28
|
-
/**
|
|
29
|
-
* The selected tree node's event handlers.
|
|
30
|
-
* The Tree will forward events to these handlers.
|
|
31
|
-
*/
|
|
32
|
-
selectedNodeEventHandlers: Writable<TreeForwardedEventHandlers>;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* The context for a TreeNode
|
|
36
|
-
*/
|
|
37
|
-
export type TreeNodeContext = {
|
|
38
|
-
/**
|
|
39
|
-
* The ID of the parent node.
|
|
40
|
-
*/
|
|
41
|
-
parentNodeId?: string;
|
|
42
|
-
/**
|
|
43
|
-
* How many levels deep this node is in the tree hierarchy.
|
|
44
|
-
* A top level item's depth is zero.
|
|
45
|
-
*/
|
|
46
|
-
depth: number;
|
|
47
|
-
};
|
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
<script>import { getContext, setContext } from "svelte";
|
|
2
|
-
import { slide } from "svelte/transition";
|
|
3
|
-
import { treeContextKey, treeNodeContextKey } from "./Tree.constants";
|
|
4
|
-
import TreeItem from "./TreeItem.svelte";
|
|
5
|
-
export let disabled = false;
|
|
6
|
-
export let nodeId;
|
|
7
|
-
export let node = void 0;
|
|
8
|
-
const { getNodeId, expandedNodeIds, selectedNodeId, selectedNodeEventHandlers } = getContext(treeContextKey);
|
|
9
|
-
const { parentNodeId, depth } = getContext(treeNodeContextKey);
|
|
10
|
-
if (nodeId && node) {
|
|
11
|
-
if (nodeId !== getNodeId(node)) {
|
|
12
|
-
throw new Error("The nodeId does not match node.nodeId.");
|
|
13
|
-
}
|
|
14
|
-
} else if (node) {
|
|
15
|
-
nodeId = getNodeId(node);
|
|
16
|
-
} else if (!nodeId) {
|
|
17
|
-
throw new Error("Both nodeId and node are missing.");
|
|
18
|
-
}
|
|
19
|
-
setContext("sterlingTreeNode", { parentNodeId: nodeId, depth: depth + 1 });
|
|
20
|
-
let treeNodeRef;
|
|
21
|
-
let itemRef;
|
|
22
|
-
$:
|
|
23
|
-
hasChildren = (node?.children?.length || 0) > 0 || $$slots.children || $$slots.default;
|
|
24
|
-
$:
|
|
25
|
-
expanded = $expandedNodeIds.includes(nodeId);
|
|
26
|
-
$:
|
|
27
|
-
selected = $selectedNodeId === nodeId;
|
|
28
|
-
const collapseNode = (index) => {
|
|
29
|
-
if (!disabled) {
|
|
30
|
-
index = index ?? $expandedNodeIds.findIndex((id) => id === nodeId);
|
|
31
|
-
if (index !== -1) {
|
|
32
|
-
expandedNodeIds.set([
|
|
33
|
-
...$expandedNodeIds.slice(0, index),
|
|
34
|
-
...$expandedNodeIds.slice(index + 1)
|
|
35
|
-
]);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
const expandNode = (index) => {
|
|
40
|
-
if (!disabled) {
|
|
41
|
-
index = index ?? $expandedNodeIds.findIndex((id) => id === nodeId);
|
|
42
|
-
if (index === -1) {
|
|
43
|
-
expandedNodeIds.set([...$expandedNodeIds, nodeId]);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
const toggleExpanded = () => {
|
|
48
|
-
if (!disabled) {
|
|
49
|
-
const index = $expandedNodeIds.findIndex((id) => id === nodeId);
|
|
50
|
-
index !== -1 ? collapseNode(index) : expandNode(index);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
const selectNodeById = (nodeId2) => {
|
|
54
|
-
if (!disabled) {
|
|
55
|
-
selectedNodeId.set(nodeId2);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
export const selectNode = () => {
|
|
59
|
-
if (!disabled) {
|
|
60
|
-
selectNodeById(nodeId);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
const selectParentNode = () => {
|
|
64
|
-
if (!disabled && parentNodeId) {
|
|
65
|
-
selectNodeById(parentNodeId);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
const selectNextNode = () => {
|
|
69
|
-
if (!disabled) {
|
|
70
|
-
let nextNodeId = void 0;
|
|
71
|
-
const decendants = treeNodeRef.getElementsByClassName("sterling-tree-node");
|
|
72
|
-
const last = decendants.length > 0 ? decendants.item(0) : void 0;
|
|
73
|
-
nextNodeId = last?.getAttribute("data-node-id");
|
|
74
|
-
if (!nextNodeId) {
|
|
75
|
-
nextNodeId = treeNodeRef.nextElementSibling?.getAttribute("data-node-id");
|
|
76
|
-
}
|
|
77
|
-
if (!nextNodeId) {
|
|
78
|
-
let ancestor = treeNodeRef.closest(".sterling-tree-node");
|
|
79
|
-
while (ancestor && !nextNodeId) {
|
|
80
|
-
nextNodeId = ancestor?.nextElementSibling?.getAttribute("data-node-id");
|
|
81
|
-
ancestor = ancestor.parentElement?.closest(".sterling-tree-node");
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
if (nextNodeId) {
|
|
85
|
-
selectNodeById(nextNodeId);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
const selectPreviousNode = () => {
|
|
90
|
-
if (!disabled) {
|
|
91
|
-
let prevNodeId = void 0;
|
|
92
|
-
const previousSibling = treeNodeRef?.previousElementSibling;
|
|
93
|
-
if (previousSibling) {
|
|
94
|
-
const decendants = previousSibling.getElementsByClassName("sterling-tree-node");
|
|
95
|
-
const last = decendants.length > 0 ? decendants.item(decendants.length - 1) : previousSibling;
|
|
96
|
-
prevNodeId = last?.getAttribute("data-node-id");
|
|
97
|
-
}
|
|
98
|
-
if (!prevNodeId) {
|
|
99
|
-
prevNodeId = parentNodeId;
|
|
100
|
-
}
|
|
101
|
-
if (prevNodeId) {
|
|
102
|
-
selectNodeById(prevNodeId);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
const onItemClick = () => {
|
|
107
|
-
toggleExpanded();
|
|
108
|
-
selectNode();
|
|
109
|
-
};
|
|
110
|
-
const onKeydown = (event) => {
|
|
111
|
-
if (!event.altKey && !event.ctrlKey && !event.shiftKey) {
|
|
112
|
-
switch (event.key) {
|
|
113
|
-
case "Enter":
|
|
114
|
-
case " ":
|
|
115
|
-
toggleExpanded();
|
|
116
|
-
event.preventDefault();
|
|
117
|
-
return false;
|
|
118
|
-
case "ArrowRight":
|
|
119
|
-
if (!expanded && hasChildren) {
|
|
120
|
-
expandNode();
|
|
121
|
-
} else {
|
|
122
|
-
selectNextNode();
|
|
123
|
-
}
|
|
124
|
-
event.preventDefault();
|
|
125
|
-
return false;
|
|
126
|
-
case "ArrowLeft":
|
|
127
|
-
if (expanded && hasChildren) {
|
|
128
|
-
collapseNode();
|
|
129
|
-
} else if (parentNodeId) {
|
|
130
|
-
selectParentNode();
|
|
131
|
-
} else {
|
|
132
|
-
selectPreviousNode();
|
|
133
|
-
}
|
|
134
|
-
event.preventDefault();
|
|
135
|
-
return false;
|
|
136
|
-
case "ArrowUp":
|
|
137
|
-
selectPreviousNode();
|
|
138
|
-
event.preventDefault();
|
|
139
|
-
return false;
|
|
140
|
-
case "ArrowDown":
|
|
141
|
-
selectNextNode();
|
|
142
|
-
event.preventDefault();
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
$: {
|
|
148
|
-
if (selected) {
|
|
149
|
-
selectedNodeEventHandlers.set({ onKeydown });
|
|
150
|
-
treeNodeRef?.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "nearest" });
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
</script>
|
|
154
|
-
|
|
155
|
-
<!--
|
|
156
|
-
@component
|
|
157
|
-
A node in a Tree displaying the item and children.
|
|
158
|
-
-->
|
|
159
|
-
<div
|
|
160
|
-
aria-selected={selected ? true : undefined}
|
|
161
|
-
aria-expanded={expanded}
|
|
162
|
-
class="sterling-tree-node"
|
|
163
|
-
class:disabled
|
|
164
|
-
bind:this={treeNodeRef}
|
|
165
|
-
data-node-id={nodeId}
|
|
166
|
-
role="treeitem"
|
|
167
|
-
>
|
|
168
|
-
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
169
|
-
<div bind:this={itemRef} class="item" class:selected on:click={onItemClick}>
|
|
170
|
-
<slot name="item" {disabled} {expanded} {hasChildren} {depth} {node} {nodeId} {selected}>
|
|
171
|
-
<TreeItem {disabled} {expanded} {hasChildren} {depth} {node} {nodeId} {selected}>
|
|
172
|
-
<svelte:fragment
|
|
173
|
-
let:disabled
|
|
174
|
-
let:expanded
|
|
175
|
-
let:hasChildren
|
|
176
|
-
let:depth
|
|
177
|
-
let:node
|
|
178
|
-
let:nodeId
|
|
179
|
-
let:selected
|
|
180
|
-
>
|
|
181
|
-
<slot name="label" {disabled} {expanded} {hasChildren} {depth} {node} {nodeId} {selected}
|
|
182
|
-
>{nodeId}</slot
|
|
183
|
-
>
|
|
184
|
-
</svelte:fragment>
|
|
185
|
-
</TreeItem>
|
|
186
|
-
</slot>
|
|
187
|
-
</div>
|
|
188
|
-
{#if expanded && hasChildren}
|
|
189
|
-
<div class="children" transition:slide={{ duration: 200 }} role="group">
|
|
190
|
-
<slot name="children">
|
|
191
|
-
{#if node?.children}
|
|
192
|
-
{#each node.children as child}
|
|
193
|
-
<svelte:self {disabled} node={child} nodeId={child.nodeId}>
|
|
194
|
-
<!--
|
|
195
|
-
Forward the item slot into each tree node.
|
|
196
|
-
It is cleanest to have a fragment for the TreeNode item slot to
|
|
197
|
-
capture the let params, then apply them to the Tree item slot.
|
|
198
|
-
-->
|
|
199
|
-
<svelte:fragment
|
|
200
|
-
slot="item"
|
|
201
|
-
let:disabled
|
|
202
|
-
let:expanded
|
|
203
|
-
let:hasChildren
|
|
204
|
-
let:depth
|
|
205
|
-
let:node
|
|
206
|
-
let:nodeId
|
|
207
|
-
let:selected
|
|
208
|
-
>
|
|
209
|
-
<slot
|
|
210
|
-
name="item"
|
|
211
|
-
{disabled}
|
|
212
|
-
{expanded}
|
|
213
|
-
{hasChildren}
|
|
214
|
-
{depth}
|
|
215
|
-
{node}
|
|
216
|
-
{nodeId}
|
|
217
|
-
{selected}
|
|
218
|
-
>
|
|
219
|
-
<!--
|
|
220
|
-
Svelte prevents conditionally applying slots.
|
|
221
|
-
This repeats exact same item slot default for this child
|
|
222
|
-
so the item slot is passed down the tree.
|
|
223
|
-
-->
|
|
224
|
-
<TreeItem {disabled} {expanded} {hasChildren} {depth} {node} {nodeId} {selected}>
|
|
225
|
-
<svelte:fragment
|
|
226
|
-
let:disabled
|
|
227
|
-
let:expanded
|
|
228
|
-
let:hasChildren
|
|
229
|
-
let:depth
|
|
230
|
-
let:node
|
|
231
|
-
let:nodeId
|
|
232
|
-
let:selected
|
|
233
|
-
>
|
|
234
|
-
<!-- This uses the label slot for the TreeItem default slot. -->
|
|
235
|
-
<slot
|
|
236
|
-
name="label"
|
|
237
|
-
{disabled}
|
|
238
|
-
{expanded}
|
|
239
|
-
{hasChildren}
|
|
240
|
-
{depth}
|
|
241
|
-
{node}
|
|
242
|
-
{nodeId}
|
|
243
|
-
{selected}>{nodeId}</slot
|
|
244
|
-
>
|
|
245
|
-
</svelte:fragment>
|
|
246
|
-
</TreeItem>
|
|
247
|
-
</slot>
|
|
248
|
-
</svelte:fragment>
|
|
249
|
-
</svelte:self>
|
|
250
|
-
{/each}
|
|
251
|
-
{/if}
|
|
252
|
-
</slot>
|
|
253
|
-
<slot />
|
|
254
|
-
</div>
|
|
255
|
-
{/if}
|
|
256
|
-
</div>
|
|
257
|
-
|
|
258
|
-
<style>
|
|
259
|
-
.item {
|
|
260
|
-
outline: none;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
.item:focus-visible {
|
|
264
|
-
border: 1px solid blue;
|
|
265
|
-
}
|
|
266
|
-
</style>
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
import type { TreeNodeData } from './Tree.types';
|
|
3
|
-
declare class __sveltets_Render<T> {
|
|
4
|
-
props(): {
|
|
5
|
-
disabled?: boolean | undefined;
|
|
6
|
-
nodeId: string;
|
|
7
|
-
node?: TreeNodeData<T> | undefined;
|
|
8
|
-
selectNode?: (() => void) | undefined;
|
|
9
|
-
};
|
|
10
|
-
events(): {} & {
|
|
11
|
-
[evt: string]: CustomEvent<any>;
|
|
12
|
-
};
|
|
13
|
-
slots(): {
|
|
14
|
-
item: {
|
|
15
|
-
disabled: any;
|
|
16
|
-
expanded: any;
|
|
17
|
-
hasChildren: any;
|
|
18
|
-
depth: any;
|
|
19
|
-
node: any;
|
|
20
|
-
nodeId: any;
|
|
21
|
-
selected: any;
|
|
22
|
-
};
|
|
23
|
-
label: {
|
|
24
|
-
disabled: any;
|
|
25
|
-
expanded: any;
|
|
26
|
-
hasChildren: any;
|
|
27
|
-
depth: any;
|
|
28
|
-
node: any;
|
|
29
|
-
nodeId: any;
|
|
30
|
-
selected: any;
|
|
31
|
-
};
|
|
32
|
-
children: {};
|
|
33
|
-
default: {};
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
export type TreeNodeProps<T> = ReturnType<__sveltets_Render<T>['props']>;
|
|
37
|
-
export type TreeNodeEvents<T> = ReturnType<__sveltets_Render<T>['events']>;
|
|
38
|
-
export type TreeNodeSlots<T> = ReturnType<__sveltets_Render<T>['slots']>;
|
|
39
|
-
/** A node in a Tree displaying the item and children. */
|
|
40
|
-
export default class TreeNode<T> extends SvelteComponentTyped<TreeNodeProps<T>, TreeNodeEvents<T>, TreeNodeSlots<T>> {
|
|
41
|
-
get selectNode(): () => void;
|
|
42
|
-
}
|
|
43
|
-
export {};
|
package/display/Label.svelte
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
<script>export let disabled = false;
|
|
2
|
-
</script>
|
|
3
|
-
|
|
4
|
-
<label class="sterling-label" class:disabled {...$$restProps}>
|
|
5
|
-
<slot />
|
|
6
|
-
</label>
|
|
7
|
-
|
|
8
|
-
<!--
|
|
9
|
-
@component
|
|
10
|
-
A styled HTML label element
|
|
11
|
-
-->
|
|
12
|
-
<style>
|
|
13
|
-
label {
|
|
14
|
-
transition: opacity 250ms;
|
|
15
|
-
font: inherit;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
label.disabled {
|
|
19
|
-
opacity: 0.5;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@media (prefers-reduced-motion) {
|
|
23
|
-
label {
|
|
24
|
-
transition: none;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
</style>
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
declare const __propDef: {
|
|
3
|
-
props: {
|
|
4
|
-
[x: string]: any;
|
|
5
|
-
disabled?: boolean | undefined;
|
|
6
|
-
};
|
|
7
|
-
events: {
|
|
8
|
-
[evt: string]: CustomEvent<any>;
|
|
9
|
-
};
|
|
10
|
-
slots: {
|
|
11
|
-
default: {};
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
export type LabelProps = typeof __propDef.props;
|
|
15
|
-
export type LabelEvents = typeof __propDef.events;
|
|
16
|
-
export type LabelSlots = typeof __propDef.slots;
|
|
17
|
-
/** A styled HTML label element */
|
|
18
|
-
export default class Label extends SvelteComponentTyped<LabelProps, LabelEvents, LabelSlots> {
|
|
19
|
-
}
|
|
20
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type ProgressColorful = 'none' | 'auto' | 'progress' | 'success' | 'warning' | 'error';
|