@skeletonlabs/skeleton 1.11.0-dev.bc9e3e82 → 1.11.0-dev.fa91c649
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/dist/components/TreeView/TreeView.svelte +71 -2
- package/dist/components/TreeView/TreeView.svelte.d.ts +19 -0
- package/dist/components/TreeView/TreeViewDataDrivenItem.svelte +70 -0
- package/dist/components/TreeView/TreeViewDataDrivenItem.svelte.d.ts +25 -0
- package/dist/components/TreeView/TreeViewItem.svelte +198 -10
- package/dist/components/TreeView/TreeViewItem.svelte.d.ts +90 -2
- package/dist/components/TreeView/types.d.ts +18 -0
- package/dist/components/TreeView/types.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
<script>import { setContext } from "svelte";
|
|
2
|
+
import TreeViewDataDrivenItem from "./TreeViewDataDrivenItem.svelte";
|
|
3
|
+
export let selection = false;
|
|
4
|
+
export let multiple = false;
|
|
5
|
+
export let nodes = [];
|
|
2
6
|
export let width = "w-full";
|
|
3
7
|
export let spacing = "space-y-1";
|
|
8
|
+
export let open = false;
|
|
9
|
+
export let disabled = false;
|
|
4
10
|
export let padding = "py-4 px-4";
|
|
5
11
|
export let indent = "ml-4";
|
|
6
12
|
export let hover = "hover:variant-soft";
|
|
@@ -12,6 +18,56 @@ export let regionSummary = "";
|
|
|
12
18
|
export let regionSymbol = "";
|
|
13
19
|
export let regionChildren = "";
|
|
14
20
|
export let labelledby = "";
|
|
21
|
+
export function expandAll() {
|
|
22
|
+
const detailsElements = [...tree.querySelectorAll("details.tree-item")];
|
|
23
|
+
detailsElements.forEach((details) => {
|
|
24
|
+
if (!details.open) {
|
|
25
|
+
const summary = details.querySelector("summary.tree-item-summary");
|
|
26
|
+
if (summary)
|
|
27
|
+
summary.click();
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export function collapseAll() {
|
|
32
|
+
const detailsElements = [...tree.querySelectorAll("details.tree-item")];
|
|
33
|
+
detailsElements.forEach((details) => {
|
|
34
|
+
if (details.open) {
|
|
35
|
+
const summary = details.querySelector("summary.tree-item-summary");
|
|
36
|
+
if (summary)
|
|
37
|
+
summary.click();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
export function selectAll() {
|
|
42
|
+
const detailsElements = [...tree.querySelectorAll("details.tree-item")];
|
|
43
|
+
detailsElements.forEach((details) => {
|
|
44
|
+
const input = details.querySelector('input[type="checkbox"].tree-item-checkbox');
|
|
45
|
+
if (!input)
|
|
46
|
+
return;
|
|
47
|
+
if (!input.checked) {
|
|
48
|
+
setTimeout(() => {
|
|
49
|
+
input.click();
|
|
50
|
+
}, 5);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
export function deselectAll() {
|
|
55
|
+
const detailsElements = [...tree.querySelectorAll("details.tree-item")];
|
|
56
|
+
detailsElements.forEach((details) => {
|
|
57
|
+
const input = details.querySelector('input[type="checkbox"].tree-item-checkbox');
|
|
58
|
+
if (!input)
|
|
59
|
+
return;
|
|
60
|
+
if (input.checked) {
|
|
61
|
+
setTimeout(() => {
|
|
62
|
+
input.click();
|
|
63
|
+
}, 5);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
setContext("open", open);
|
|
68
|
+
setContext("selection", selection);
|
|
69
|
+
setContext("multiple", multiple);
|
|
70
|
+
setContext("disabled", disabled);
|
|
15
71
|
setContext("padding", padding);
|
|
16
72
|
setContext("indent", indent);
|
|
17
73
|
setContext("hover", hover);
|
|
@@ -24,8 +80,21 @@ setContext("regionSymbol", regionSymbol);
|
|
|
24
80
|
setContext("regionChildren", regionChildren);
|
|
25
81
|
$:
|
|
26
82
|
classesBase = `${width} ${spacing} ${$$props.class ?? ""}`;
|
|
83
|
+
let tree;
|
|
27
84
|
</script>
|
|
28
85
|
|
|
29
|
-
<div
|
|
30
|
-
|
|
86
|
+
<div
|
|
87
|
+
bind:this={tree}
|
|
88
|
+
class="tree {classesBase}"
|
|
89
|
+
data-testid="tree"
|
|
90
|
+
role="tree"
|
|
91
|
+
aria-multiselectable={multiple}
|
|
92
|
+
aria-label={labelledby}
|
|
93
|
+
aria-disabled={disabled}
|
|
94
|
+
>
|
|
95
|
+
{#if nodes && nodes.length > 0}
|
|
96
|
+
<TreeViewDataDrivenItem bind:nodes />
|
|
97
|
+
{:else}
|
|
98
|
+
<slot />
|
|
99
|
+
{/if}
|
|
31
100
|
</div>
|
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { TreeViewNode } from '../../index.js';
|
|
2
3
|
declare const __propDef: {
|
|
3
4
|
props: {
|
|
4
5
|
[x: string]: any;
|
|
6
|
+
/** Enable tree-view selection.*/
|
|
7
|
+
selection?: boolean | undefined;
|
|
8
|
+
/** Enable selection of multiple items.*/
|
|
9
|
+
multiple?: boolean | undefined;
|
|
10
|
+
/** Provide data-driven nodes.*/
|
|
11
|
+
nodes?: TreeViewNode[] | undefined;
|
|
5
12
|
/** Provide classes to set the tree width.*/
|
|
6
13
|
width?: string | undefined;
|
|
7
14
|
/** Provide classes to set the vertical spacing between items.*/
|
|
8
15
|
spacing?: string | undefined;
|
|
16
|
+
/** Set open by default on load.*/
|
|
17
|
+
open?: boolean | undefined;
|
|
18
|
+
/** Set the tree disabled state*/
|
|
19
|
+
disabled?: boolean | undefined;
|
|
9
20
|
/** Provide classes to set the tree item padding styles.*/
|
|
10
21
|
padding?: string | undefined;
|
|
11
22
|
/** Provide classes to set the tree children indentation*/
|
|
@@ -27,6 +38,10 @@ declare const __propDef: {
|
|
|
27
38
|
regionChildren?: string | undefined;
|
|
28
39
|
/** Provide the ARIA labelledby value.*/
|
|
29
40
|
labelledby?: string | undefined;
|
|
41
|
+
expandAll?: (() => void) | undefined;
|
|
42
|
+
collapseAll?: (() => void) | undefined;
|
|
43
|
+
selectAll?: (() => void) | undefined;
|
|
44
|
+
deselectAll?: (() => void) | undefined;
|
|
30
45
|
};
|
|
31
46
|
events: {
|
|
32
47
|
[evt: string]: CustomEvent<any>;
|
|
@@ -39,5 +54,9 @@ export type TreeViewProps = typeof __propDef.props;
|
|
|
39
54
|
export type TreeViewEvents = typeof __propDef.events;
|
|
40
55
|
export type TreeViewSlots = typeof __propDef.slots;
|
|
41
56
|
export default class TreeView extends SvelteComponentTyped<TreeViewProps, TreeViewEvents, TreeViewSlots> {
|
|
57
|
+
get expandAll(): () => void;
|
|
58
|
+
get collapseAll(): () => void;
|
|
59
|
+
get selectAll(): () => void;
|
|
60
|
+
get deselectAll(): () => void;
|
|
42
61
|
}
|
|
43
62
|
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<script>import { createEventDispatcher, getContext, onMount } from "svelte";
|
|
2
|
+
import TreeViewDataDrivenItem from "./TreeViewDataDrivenItem.svelte";
|
|
3
|
+
import TreeViewItem from "./TreeViewItem.svelte";
|
|
4
|
+
const dispatch = createEventDispatcher();
|
|
5
|
+
export let nodes = [];
|
|
6
|
+
export let selection = getContext("selection");
|
|
7
|
+
export let multiple = getContext("multiple");
|
|
8
|
+
let group;
|
|
9
|
+
let name = "";
|
|
10
|
+
onMount(() => {
|
|
11
|
+
name = String(Math.random());
|
|
12
|
+
if (selection) {
|
|
13
|
+
group = multiple ? [] : "";
|
|
14
|
+
nodes.forEach((node) => {
|
|
15
|
+
if (!node.checked)
|
|
16
|
+
return;
|
|
17
|
+
if (multiple) {
|
|
18
|
+
if (!Array.isArray(group))
|
|
19
|
+
return;
|
|
20
|
+
group.push(node.value);
|
|
21
|
+
} else {
|
|
22
|
+
group = node.value;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
function onCheckChange() {
|
|
28
|
+
nodes.forEach((node) => {
|
|
29
|
+
if (multiple) {
|
|
30
|
+
if (!Array.isArray(group))
|
|
31
|
+
return;
|
|
32
|
+
node.checked = group.includes(node.value);
|
|
33
|
+
} else {
|
|
34
|
+
node.checked = group === node.value;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
nodes = nodes;
|
|
38
|
+
dispatch("change");
|
|
39
|
+
}
|
|
40
|
+
export let parents = [];
|
|
41
|
+
let children = [];
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
{#if nodes && nodes.length > 0}
|
|
45
|
+
{#each nodes as node, i}
|
|
46
|
+
<TreeViewItem
|
|
47
|
+
bind:this={parents[i]}
|
|
48
|
+
bind:open={node.open}
|
|
49
|
+
hideLead={!node.lead}
|
|
50
|
+
hideChildren={!node.children || node.children.length === 0}
|
|
51
|
+
bind:disabled={node.disabled}
|
|
52
|
+
bind:group
|
|
53
|
+
bind:name
|
|
54
|
+
bind:indeterminate={node.indeterminate}
|
|
55
|
+
bind:value={node.value}
|
|
56
|
+
bind:children={children[i]}
|
|
57
|
+
on:change={onCheckChange}
|
|
58
|
+
on:click
|
|
59
|
+
on:toggle
|
|
60
|
+
>
|
|
61
|
+
{@html node.content}
|
|
62
|
+
<svelte:fragment slot="lead">
|
|
63
|
+
{@html node.lead}
|
|
64
|
+
</svelte:fragment>
|
|
65
|
+
<svelte:fragment slot="children">
|
|
66
|
+
<TreeViewDataDrivenItem nodes={node.children} on:change={onCheckChange} bind:parents={children[i]} />
|
|
67
|
+
</svelte:fragment>
|
|
68
|
+
</TreeViewItem>
|
|
69
|
+
{/each}
|
|
70
|
+
{/if}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import TreeViewItem from './TreeViewItem.svelte';
|
|
3
|
+
import type { TreeViewNode } from './types.js';
|
|
4
|
+
declare const __propDef: {
|
|
5
|
+
props: {
|
|
6
|
+
/** Provide data-driven nodes. */ nodes?: TreeViewNode[] | undefined;
|
|
7
|
+
/** Enable tree-view selection */ selection?: boolean | undefined;
|
|
8
|
+
/** Enable selection of multiple items. */ multiple?: boolean | undefined;
|
|
9
|
+
parents?: TreeViewItem[] | undefined;
|
|
10
|
+
};
|
|
11
|
+
events: {
|
|
12
|
+
click: MouseEvent;
|
|
13
|
+
toggle: CustomEvent<any>;
|
|
14
|
+
change: CustomEvent<any>;
|
|
15
|
+
} & {
|
|
16
|
+
[evt: string]: CustomEvent<any>;
|
|
17
|
+
};
|
|
18
|
+
slots: {};
|
|
19
|
+
};
|
|
20
|
+
export type TreeViewDataDrivenItemProps = typeof __propDef.props;
|
|
21
|
+
export type TreeViewDataDrivenItemEvents = typeof __propDef.events;
|
|
22
|
+
export type TreeViewDataDrivenItemSlots = typeof __propDef.slots;
|
|
23
|
+
export default class TreeViewDataDrivenItem extends SvelteComponentTyped<TreeViewDataDrivenItemProps, TreeViewDataDrivenItemEvents, TreeViewDataDrivenItemSlots> {
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
+
<!-- To access props and events using reference -->
|
|
2
|
+
<svelte:options accessors />
|
|
3
|
+
|
|
1
4
|
<script>import { getContext, createEventDispatcher } from "svelte";
|
|
2
|
-
export let
|
|
5
|
+
export let group = void 0;
|
|
6
|
+
export let name = void 0;
|
|
7
|
+
export let value = void 0;
|
|
8
|
+
export let children = [];
|
|
3
9
|
export let spacing = "space-x-4";
|
|
10
|
+
export let open = getContext("open");
|
|
11
|
+
export let selection = getContext("selection");
|
|
12
|
+
export let multiple = getContext("multiple");
|
|
13
|
+
export let disabled = getContext("disabled");
|
|
14
|
+
export let indeterminate = false;
|
|
4
15
|
export let padding = getContext("padding");
|
|
5
16
|
export let indent = getContext("indent");
|
|
6
17
|
export let hover = getContext("hover");
|
|
@@ -8,22 +19,187 @@ export let rounded = getContext("rounded");
|
|
|
8
19
|
export let caretOpen = getContext("caretOpen");
|
|
9
20
|
export let caretClosed = getContext("caretClosed");
|
|
10
21
|
export let hyphenOpacity = getContext("hyphenOpacity");
|
|
11
|
-
export let regionSummary = "";
|
|
22
|
+
export let regionSummary = getContext("regionSummary");
|
|
12
23
|
export let regionSymbol = getContext("regionSymbol");
|
|
13
24
|
export let regionChildren = getContext("regionChildren");
|
|
25
|
+
export let hideLead = false;
|
|
26
|
+
export let hideChildren = false;
|
|
27
|
+
let checked = false;
|
|
28
|
+
let treeItem;
|
|
29
|
+
let childrenDiv;
|
|
30
|
+
function onSummaryClick(event) {
|
|
31
|
+
if (disabled)
|
|
32
|
+
event.preventDefault();
|
|
33
|
+
}
|
|
34
|
+
$:
|
|
35
|
+
if (multiple)
|
|
36
|
+
updateCheckbox(group);
|
|
37
|
+
$:
|
|
38
|
+
if (multiple)
|
|
39
|
+
updateGroup(checked);
|
|
40
|
+
function updateCheckbox(group2) {
|
|
41
|
+
if (!Array.isArray(group2))
|
|
42
|
+
return;
|
|
43
|
+
checked = group2.indexOf(value) >= 0;
|
|
44
|
+
}
|
|
45
|
+
function updateGroup(checked2) {
|
|
46
|
+
if (!Array.isArray(group))
|
|
47
|
+
return;
|
|
48
|
+
const index = group.indexOf(value);
|
|
49
|
+
if (checked2) {
|
|
50
|
+
if (index < 0) {
|
|
51
|
+
group = [...group, value];
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
if (index >= 0) {
|
|
55
|
+
group.splice(index, 1);
|
|
56
|
+
group = group;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function onChildValueChange(event, child) {
|
|
61
|
+
if (multiple) {
|
|
62
|
+
if (!Array.isArray(group))
|
|
63
|
+
return;
|
|
64
|
+
const childrenValues = children.map((c) => c.value);
|
|
65
|
+
const index = group.indexOf(value);
|
|
66
|
+
if (childrenValues.every((c) => Array.isArray(child.group) && child.group.includes(c))) {
|
|
67
|
+
if (index < 0) {
|
|
68
|
+
indeterminate = false;
|
|
69
|
+
group = [...group, value];
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
if (index >= 0) {
|
|
73
|
+
group.splice(index, 1);
|
|
74
|
+
group = group;
|
|
75
|
+
}
|
|
76
|
+
indeterminate = childrenValues.some((c) => Array.isArray(child.group) && child.group.includes(c));
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
if (event.currentTarget.checked && group !== value) {
|
|
80
|
+
group = value;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function onGroupValueChange(_group) {
|
|
85
|
+
if (!children || children.length === 0 || indeterminate)
|
|
86
|
+
return;
|
|
87
|
+
if (multiple) {
|
|
88
|
+
if (!Array.isArray(_group))
|
|
89
|
+
return;
|
|
90
|
+
const index = _group.indexOf(value);
|
|
91
|
+
const checkChild = (child) => {
|
|
92
|
+
if (!child || !Array.isArray(child.group))
|
|
93
|
+
return;
|
|
94
|
+
if (child.group.indexOf(child.value) < 0) {
|
|
95
|
+
child.group.push(child.value);
|
|
96
|
+
child.group = child.group;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const uncheckChild = (child) => {
|
|
100
|
+
if (!child || !Array.isArray(child.group))
|
|
101
|
+
return;
|
|
102
|
+
const childIndex = child.group.indexOf(child.value);
|
|
103
|
+
if (childIndex >= 0) {
|
|
104
|
+
child.group.splice(childIndex, 1);
|
|
105
|
+
child.group = child.group;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
children.forEach(index >= 0 ? checkChild : uncheckChild);
|
|
109
|
+
} else {
|
|
110
|
+
if (_group !== value) {
|
|
111
|
+
children.forEach((child) => {
|
|
112
|
+
child.group = [];
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
$:
|
|
118
|
+
onGroupValueChange(group);
|
|
14
119
|
const dispatch = createEventDispatcher();
|
|
15
120
|
$:
|
|
16
121
|
dispatch("toggle", { open });
|
|
122
|
+
$:
|
|
123
|
+
children.forEach((child) => {
|
|
124
|
+
if (child)
|
|
125
|
+
child.$on("change", (event) => onChildValueChange(event, child));
|
|
126
|
+
});
|
|
127
|
+
function onKeyDown(event) {
|
|
128
|
+
function getRootTree() {
|
|
129
|
+
let currentElement = treeItem;
|
|
130
|
+
while (currentElement !== null) {
|
|
131
|
+
if (currentElement.classList.contains("tree"))
|
|
132
|
+
return currentElement;
|
|
133
|
+
currentElement = currentElement.parentElement;
|
|
134
|
+
}
|
|
135
|
+
return void 0;
|
|
136
|
+
}
|
|
137
|
+
let rootTree = void 0;
|
|
138
|
+
let lastVisibleElement = null;
|
|
139
|
+
switch (event.code) {
|
|
140
|
+
case "ArrowRight":
|
|
141
|
+
if (!open)
|
|
142
|
+
open = true;
|
|
143
|
+
else if ($$slots.children && !hideChildren) {
|
|
144
|
+
const child = childrenDiv.querySelector("details>summary");
|
|
145
|
+
if (child)
|
|
146
|
+
child.focus();
|
|
147
|
+
}
|
|
148
|
+
break;
|
|
149
|
+
case "ArrowLeft":
|
|
150
|
+
if (open)
|
|
151
|
+
open = false;
|
|
152
|
+
else {
|
|
153
|
+
const parent = treeItem.parentElement?.parentElement;
|
|
154
|
+
if (parent && parent.tagName === "DETAILS")
|
|
155
|
+
parent.querySelector("summary").focus();
|
|
156
|
+
}
|
|
157
|
+
break;
|
|
158
|
+
case "Home":
|
|
159
|
+
event.preventDefault();
|
|
160
|
+
rootTree = getRootTree();
|
|
161
|
+
if (rootTree)
|
|
162
|
+
rootTree?.querySelector("summary")?.focus();
|
|
163
|
+
break;
|
|
164
|
+
case "End":
|
|
165
|
+
event.preventDefault();
|
|
166
|
+
rootTree = getRootTree();
|
|
167
|
+
if (rootTree) {
|
|
168
|
+
const detailsElements = rootTree?.querySelectorAll("details");
|
|
169
|
+
if (!detailsElements)
|
|
170
|
+
return;
|
|
171
|
+
for (let i = detailsElements.length - 1; i >= 0; i--) {
|
|
172
|
+
const details = detailsElements[i];
|
|
173
|
+
if (details.parentElement?.classList?.contains("tree") || details.parentElement?.parentElement?.getAttribute("open") !== null) {
|
|
174
|
+
lastVisibleElement = details;
|
|
175
|
+
break;
|
|
176
|
+
} else if (details.parentElement?.parentElement?.tagName !== "details") {
|
|
177
|
+
lastVisibleElement = details.parentElement.parentElement;
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (lastVisibleElement) {
|
|
182
|
+
const summary = lastVisibleElement.querySelector("summary");
|
|
183
|
+
if (summary)
|
|
184
|
+
summary.focus();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
17
190
|
const cBase = "";
|
|
18
|
-
const cSummary = "list-none flex items-center cursor-pointer";
|
|
191
|
+
const cSummary = "list-none [&::-webkit-details-marker]:hidden flex items-center cursor-pointer";
|
|
19
192
|
const cSymbol = "fill-current w-3 text-center transition-transform duration-[200ms]";
|
|
20
193
|
const cChildren = "";
|
|
194
|
+
const cDisabled = "opacity-50 !cursor-not-allowed";
|
|
195
|
+
$:
|
|
196
|
+
classesCaretState = open && $$slots.children && !hideChildren ? caretOpen : caretClosed;
|
|
21
197
|
$:
|
|
22
|
-
|
|
198
|
+
classesDisabled = disabled ? cDisabled : "";
|
|
23
199
|
$:
|
|
24
200
|
classesBase = `${cBase} ${$$props.class ?? ""}`;
|
|
25
201
|
$:
|
|
26
|
-
classesSummary = `${cSummary} ${spacing} ${rounded} ${padding} ${hover} ${regionSummary}`;
|
|
202
|
+
classesSummary = `${cSummary} ${classesDisabled} ${spacing} ${rounded} ${padding} ${hover} ${regionSummary}`;
|
|
27
203
|
$:
|
|
28
204
|
classesSymbol = `${cSymbol} ${classesCaret} ${regionSymbol}`;
|
|
29
205
|
$:
|
|
@@ -34,19 +210,21 @@ $:
|
|
|
34
210
|
classesChildren = `${cChildren} ${indent} ${regionChildren}`;
|
|
35
211
|
</script>
|
|
36
212
|
|
|
37
|
-
<details bind:open class="tree-item {classesBase}" data-testid="tree-item">
|
|
213
|
+
<details bind:this={treeItem} bind:open class="tree-item {classesBase}" data-testid="tree-item" aria-disabled={disabled}>
|
|
38
214
|
<summary
|
|
39
215
|
class="tree-item-summary {classesSummary}"
|
|
40
216
|
role="treeitem"
|
|
41
|
-
aria-selected=
|
|
217
|
+
aria-selected={selection ? checked : undefined}
|
|
42
218
|
aria-expanded={$$slots.children ? open : undefined}
|
|
219
|
+
on:click={onSummaryClick}
|
|
43
220
|
on:click
|
|
221
|
+
on:keydown={onKeyDown}
|
|
44
222
|
on:keydown
|
|
45
223
|
on:keyup
|
|
46
224
|
>
|
|
47
225
|
<!-- Symbol -->
|
|
48
226
|
<div class="tree-summary-symbol {classesSymbol}">
|
|
49
|
-
{#if $$slots.children}
|
|
227
|
+
{#if $$slots.children && !hideChildren}
|
|
50
228
|
<!-- SVG Caret -->
|
|
51
229
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">
|
|
52
230
|
<path
|
|
@@ -59,8 +237,18 @@ $:
|
|
|
59
237
|
</svg>
|
|
60
238
|
{/if}
|
|
61
239
|
</div>
|
|
240
|
+
|
|
241
|
+
<!-- Selection -->
|
|
242
|
+
{#if selection && name && group !== undefined}
|
|
243
|
+
{#if multiple}
|
|
244
|
+
<input class="checkbox tree-item-checkbox" type="checkbox" {name} {value} bind:checked bind:indeterminate on:click on:change />
|
|
245
|
+
{:else}
|
|
246
|
+
<input class="radio tree-item-radio" type="radio" bind:group {name} {value} on:click on:change />
|
|
247
|
+
{/if}
|
|
248
|
+
{/if}
|
|
249
|
+
|
|
62
250
|
<!-- Slot: Lead -->
|
|
63
|
-
{#if $$slots.lead}
|
|
251
|
+
{#if $$slots.lead && !hideLead}
|
|
64
252
|
<div class="tree-item-lead">
|
|
65
253
|
<slot name="lead" />
|
|
66
254
|
</div>
|
|
@@ -70,7 +258,7 @@ $:
|
|
|
70
258
|
<slot />
|
|
71
259
|
</div>
|
|
72
260
|
</summary>
|
|
73
|
-
<div class="tree-item-children {classesChildren}" role="group">
|
|
261
|
+
<div bind:this={childrenDiv} class="tree-item-children {classesChildren}" role="group">
|
|
74
262
|
<slot name="children" />
|
|
75
263
|
</div>
|
|
76
264
|
</details>
|
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { TreeViewItem } from '../../index.js';
|
|
2
3
|
declare const __propDef: {
|
|
3
4
|
props: {
|
|
4
5
|
[x: string]: any;
|
|
5
|
-
/** Set
|
|
6
|
-
|
|
6
|
+
/** Set the radio group binding value.*/
|
|
7
|
+
group?: unknown;
|
|
8
|
+
/** Set a unique name value for the input.*/
|
|
9
|
+
name?: string | undefined;
|
|
10
|
+
/** Set the input's value.*/
|
|
11
|
+
value?: unknown;
|
|
12
|
+
/** Provide children references to support relational checking.*/
|
|
13
|
+
children?: TreeViewItem[] | undefined;
|
|
7
14
|
/** Provide classes to set the horizontal spacing.*/
|
|
8
15
|
spacing?: string | undefined;
|
|
16
|
+
/** Set open by default on load.*/
|
|
17
|
+
open?: boolean | undefined;
|
|
18
|
+
/** Enable tree-view selection*/
|
|
19
|
+
selection?: boolean | undefined;
|
|
20
|
+
/** Enable selection of multiple items.*/
|
|
21
|
+
multiple?: boolean | undefined;
|
|
22
|
+
/** Set the tree item disabled state*/
|
|
23
|
+
disabled?: boolean | undefined;
|
|
24
|
+
/** Set the check state to indeterminate(-).*/
|
|
25
|
+
indeterminate?: boolean | undefined;
|
|
9
26
|
/** Provide classes to set the tree item padding styles.*/
|
|
10
27
|
padding?: string | undefined;
|
|
11
28
|
/** Provide classes to set the tree children indentation*/
|
|
@@ -25,11 +42,16 @@ declare const __propDef: {
|
|
|
25
42
|
regionSymbol?: string | undefined;
|
|
26
43
|
/** Provide arbitrary classes to the children region.*/
|
|
27
44
|
regionChildren?: string | undefined;
|
|
45
|
+
/** Don't use this prop, workaround until svelte implements conditional slots*/
|
|
46
|
+
hideLead?: boolean | undefined;
|
|
47
|
+
/** Don't use this prop, workaround until svelte implements conditional slots*/
|
|
48
|
+
hideChildren?: boolean | undefined;
|
|
28
49
|
};
|
|
29
50
|
events: {
|
|
30
51
|
click: MouseEvent;
|
|
31
52
|
keydown: KeyboardEvent;
|
|
32
53
|
keyup: KeyboardEvent;
|
|
54
|
+
change: Event;
|
|
33
55
|
toggle: CustomEvent<any>;
|
|
34
56
|
} & {
|
|
35
57
|
[evt: string]: CustomEvent<any>;
|
|
@@ -44,5 +66,71 @@ export type TreeViewItemProps = typeof __propDef.props;
|
|
|
44
66
|
export type TreeViewItemEvents = typeof __propDef.events;
|
|
45
67
|
export type TreeViewItemSlots = typeof __propDef.slots;
|
|
46
68
|
export default class TreeViewItem extends SvelteComponentTyped<TreeViewItemProps, TreeViewItemEvents, TreeViewItemSlots> {
|
|
69
|
+
get group(): unknown;
|
|
70
|
+
/**accessor*/
|
|
71
|
+
set group(_: unknown);
|
|
72
|
+
get name(): string | undefined;
|
|
73
|
+
/**accessor*/
|
|
74
|
+
set name(_: string | undefined);
|
|
75
|
+
get value(): unknown;
|
|
76
|
+
/**accessor*/
|
|
77
|
+
set value(_: unknown);
|
|
78
|
+
get children(): TreeViewItem[] | undefined;
|
|
79
|
+
/**accessor*/
|
|
80
|
+
set children(_: TreeViewItem[] | undefined);
|
|
81
|
+
get spacing(): string | undefined;
|
|
82
|
+
/**accessor*/
|
|
83
|
+
set spacing(_: string | undefined);
|
|
84
|
+
get open(): boolean | undefined;
|
|
85
|
+
/**accessor*/
|
|
86
|
+
set open(_: boolean | undefined);
|
|
87
|
+
get selection(): boolean | undefined;
|
|
88
|
+
/**accessor*/
|
|
89
|
+
set selection(_: boolean | undefined);
|
|
90
|
+
get multiple(): boolean | undefined;
|
|
91
|
+
/**accessor*/
|
|
92
|
+
set multiple(_: boolean | undefined);
|
|
93
|
+
get disabled(): boolean | undefined;
|
|
94
|
+
/**accessor*/
|
|
95
|
+
set disabled(_: boolean | undefined);
|
|
96
|
+
get indeterminate(): boolean | undefined;
|
|
97
|
+
/**accessor*/
|
|
98
|
+
set indeterminate(_: boolean | undefined);
|
|
99
|
+
get padding(): string | undefined;
|
|
100
|
+
/**accessor*/
|
|
101
|
+
set padding(_: string | undefined);
|
|
102
|
+
get indent(): string | undefined;
|
|
103
|
+
/**accessor*/
|
|
104
|
+
set indent(_: string | undefined);
|
|
105
|
+
get hover(): string | undefined;
|
|
106
|
+
/**accessor*/
|
|
107
|
+
set hover(_: string | undefined);
|
|
108
|
+
get rounded(): string | undefined;
|
|
109
|
+
/**accessor*/
|
|
110
|
+
set rounded(_: string | undefined);
|
|
111
|
+
get caretOpen(): string | undefined;
|
|
112
|
+
/**accessor*/
|
|
113
|
+
set caretOpen(_: string | undefined);
|
|
114
|
+
get caretClosed(): string | undefined;
|
|
115
|
+
/**accessor*/
|
|
116
|
+
set caretClosed(_: string | undefined);
|
|
117
|
+
get hyphenOpacity(): string | undefined;
|
|
118
|
+
/**accessor*/
|
|
119
|
+
set hyphenOpacity(_: string | undefined);
|
|
120
|
+
get regionSummary(): string | undefined;
|
|
121
|
+
/**accessor*/
|
|
122
|
+
set regionSummary(_: string | undefined);
|
|
123
|
+
get regionSymbol(): string | undefined;
|
|
124
|
+
/**accessor*/
|
|
125
|
+
set regionSymbol(_: string | undefined);
|
|
126
|
+
get regionChildren(): string | undefined;
|
|
127
|
+
/**accessor*/
|
|
128
|
+
set regionChildren(_: string | undefined);
|
|
129
|
+
get hideLead(): boolean | undefined;
|
|
130
|
+
/**accessor*/
|
|
131
|
+
set hideLead(_: boolean | undefined);
|
|
132
|
+
get hideChildren(): boolean | undefined;
|
|
133
|
+
/**accessor*/
|
|
134
|
+
set hideChildren(_: boolean | undefined);
|
|
47
135
|
}
|
|
48
136
|
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface TreeViewNode {
|
|
2
|
+
/** Main content. accepts HTML. */
|
|
3
|
+
content: string;
|
|
4
|
+
/** Lead content. accepts HTML. */
|
|
5
|
+
lead?: string;
|
|
6
|
+
/** Set open by default on load. */
|
|
7
|
+
open?: boolean;
|
|
8
|
+
/** Set the tree disabled state. */
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
/** children nodes. */
|
|
11
|
+
children?: TreeViewNode[];
|
|
12
|
+
/** Set the input's value. */
|
|
13
|
+
value?: unknown;
|
|
14
|
+
/** input checked */
|
|
15
|
+
checked?: boolean;
|
|
16
|
+
/** input is set to indeterminate, only availabe in multiple selection mode. */
|
|
17
|
+
indeterminate?: boolean;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export type { ToastSettings } from './utilities/Toast/types.js';
|
|
|
6
6
|
export type { TableSource } from './components/Table/types.js';
|
|
7
7
|
export type { PaginationSettings } from './components/Paginator/types.js';
|
|
8
8
|
export type { PopupSettings } from './utilities/Popup/types.js';
|
|
9
|
+
export type { TreeViewNode } from './components/TreeView/types.js';
|
|
9
10
|
export type CssClasses = string;
|
|
10
11
|
export type SvelteEvent<E extends Event = Event, T extends EventTarget = Element> = E & {
|
|
11
12
|
currentTarget: EventTarget & T;
|
|
@@ -55,6 +56,7 @@ export { default as TabAnchor } from './components/Tab/TabAnchor.svelte';
|
|
|
55
56
|
export { default as TableOfContents } from './components/TableOfContents/TableOfContents.svelte';
|
|
56
57
|
export { default as TreeView } from './components/TreeView/TreeView.svelte';
|
|
57
58
|
export { default as TreeViewItem } from './components/TreeView/TreeViewItem.svelte';
|
|
59
|
+
export { default as TreeViewDataDrivenItem } from './components/TreeView/TreeViewDataDrivenItem.svelte';
|
|
58
60
|
export { default as CodeBlock } from './utilities/CodeBlock/CodeBlock.svelte';
|
|
59
61
|
export { default as Modal } from './utilities/Modal/Modal.svelte';
|
|
60
62
|
export { default as Drawer } from './utilities/Drawer/Drawer.svelte';
|
package/dist/index.js
CHANGED
|
@@ -61,6 +61,7 @@ export { default as TabAnchor } from './components/Tab/TabAnchor.svelte';
|
|
|
61
61
|
export { default as TableOfContents } from './components/TableOfContents/TableOfContents.svelte';
|
|
62
62
|
export { default as TreeView } from './components/TreeView/TreeView.svelte';
|
|
63
63
|
export { default as TreeViewItem } from './components/TreeView/TreeViewItem.svelte';
|
|
64
|
+
export { default as TreeViewDataDrivenItem } from './components/TreeView/TreeViewDataDrivenItem.svelte';
|
|
64
65
|
// Utility Components
|
|
65
66
|
export { default as CodeBlock } from './utilities/CodeBlock/CodeBlock.svelte';
|
|
66
67
|
export { default as Modal } from './utilities/Modal/Modal.svelte';
|