@skeletonlabs/skeleton 2.0.0-rc.2 → 2.0.0-rc.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/dist/components/TreeView/TreeView.svelte +3 -29
- package/dist/components/TreeView/TreeView.svelte.d.ts +6 -4
- package/dist/components/TreeView/TreeViewDataDrivenItem.svelte +43 -23
- package/dist/components/TreeView/TreeViewDataDrivenItem.svelte.d.ts +4 -2
- package/dist/components/TreeView/TreeViewItem.svelte +61 -39
- package/dist/components/TreeView/TreeViewItem.svelte.d.ts +5 -0
- package/package.json +1 -1
|
@@ -19,7 +19,7 @@ export let regionSymbol = "";
|
|
|
19
19
|
export let regionChildren = "";
|
|
20
20
|
export let labelledby = "";
|
|
21
21
|
export function expandAll() {
|
|
22
|
-
const detailsElements =
|
|
22
|
+
const detailsElements = tree.querySelectorAll("details.tree-item");
|
|
23
23
|
detailsElements.forEach((details) => {
|
|
24
24
|
if (!details.open) {
|
|
25
25
|
const summary = details.querySelector("summary.tree-item-summary");
|
|
@@ -29,7 +29,7 @@ export function expandAll() {
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
export function collapseAll() {
|
|
32
|
-
const detailsElements =
|
|
32
|
+
const detailsElements = tree.querySelectorAll("details.tree-item");
|
|
33
33
|
detailsElements.forEach((details) => {
|
|
34
34
|
if (details.open) {
|
|
35
35
|
const summary = details.querySelector("summary.tree-item-summary");
|
|
@@ -38,32 +38,6 @@ export function collapseAll() {
|
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
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
41
|
setContext("open", open);
|
|
68
42
|
setContext("selection", selection);
|
|
69
43
|
setContext("multiple", multiple);
|
|
@@ -93,7 +67,7 @@ let tree;
|
|
|
93
67
|
aria-disabled={disabled}
|
|
94
68
|
>
|
|
95
69
|
{#if nodes && nodes.length > 0}
|
|
96
|
-
<TreeViewDataDrivenItem bind:nodes />
|
|
70
|
+
<TreeViewDataDrivenItem bind:nodes on:change on:click on:toggle on:keydown on:keyup />
|
|
97
71
|
{:else}
|
|
98
72
|
<slot />
|
|
99
73
|
{/if}
|
|
@@ -40,10 +40,14 @@ declare const __propDef: {
|
|
|
40
40
|
labelledby?: string | undefined;
|
|
41
41
|
expandAll?: (() => void) | undefined;
|
|
42
42
|
collapseAll?: (() => void) | undefined;
|
|
43
|
-
selectAll?: (() => void) | undefined;
|
|
44
|
-
deselectAll?: (() => void) | undefined;
|
|
45
43
|
};
|
|
46
44
|
events: {
|
|
45
|
+
change: Event;
|
|
46
|
+
click: MouseEvent;
|
|
47
|
+
toggle: CustomEvent<any>;
|
|
48
|
+
keydown: KeyboardEvent;
|
|
49
|
+
keyup: KeyboardEvent;
|
|
50
|
+
} & {
|
|
47
51
|
[evt: string]: CustomEvent<any>;
|
|
48
52
|
};
|
|
49
53
|
slots: {
|
|
@@ -56,7 +60,5 @@ export type TreeViewSlots = typeof __propDef.slots;
|
|
|
56
60
|
export default class TreeView extends SvelteComponentTyped<TreeViewProps, TreeViewEvents, TreeViewSlots> {
|
|
57
61
|
get expandAll(): () => void;
|
|
58
62
|
get collapseAll(): () => void;
|
|
59
|
-
get selectAll(): () => void;
|
|
60
|
-
get deselectAll(): () => void;
|
|
61
63
|
}
|
|
62
64
|
export {};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
<script>import {
|
|
1
|
+
<script>import { getContext, onMount } from "svelte";
|
|
2
2
|
import TreeViewDataDrivenItem from "./TreeViewDataDrivenItem.svelte";
|
|
3
3
|
import TreeViewItem from "./TreeViewItem.svelte";
|
|
4
|
-
const dispatch = createEventDispatcher();
|
|
5
4
|
export let nodes = [];
|
|
6
5
|
export let selection = getContext("selection");
|
|
7
6
|
export let multiple = getContext("multiple");
|
|
@@ -11,40 +10,58 @@ onMount(() => {
|
|
|
11
10
|
name = String(Math.random());
|
|
12
11
|
if (selection) {
|
|
13
12
|
group = multiple ? [] : "";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return;
|
|
17
|
-
if (multiple) {
|
|
13
|
+
if (multiple) {
|
|
14
|
+
nodes.forEach((node) => {
|
|
18
15
|
if (!Array.isArray(group))
|
|
19
16
|
return;
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
if (node.children && node.children.length > 0) {
|
|
18
|
+
if (node.children.some((c) => c.indeterminate)) {
|
|
19
|
+
node.indeterminate = true;
|
|
20
|
+
} else if (node.children.every((c) => c.checked)) {
|
|
21
|
+
node.indeterminate = false;
|
|
22
|
+
group.push(node.value);
|
|
23
|
+
group = group;
|
|
24
|
+
} else if (node.children.some((c) => c.checked)) {
|
|
25
|
+
node.indeterminate = true;
|
|
26
|
+
} else {
|
|
27
|
+
node.indeterminate = false;
|
|
28
|
+
node.checked = false;
|
|
29
|
+
}
|
|
30
|
+
} else if (node.checked) {
|
|
31
|
+
group.push(node.value);
|
|
32
|
+
group = group;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
} else {
|
|
36
|
+
nodes.forEach((node) => {
|
|
37
|
+
if (!node.checked)
|
|
38
|
+
return;
|
|
22
39
|
group = node.value;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
25
42
|
}
|
|
26
43
|
});
|
|
27
|
-
function
|
|
28
|
-
|
|
29
|
-
|
|
44
|
+
function onGroupChange() {
|
|
45
|
+
if (multiple) {
|
|
46
|
+
nodes.forEach((node) => {
|
|
30
47
|
if (!Array.isArray(group))
|
|
31
48
|
return;
|
|
32
49
|
node.checked = group.includes(node.value);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
50
|
+
});
|
|
51
|
+
} else {
|
|
52
|
+
nodes.forEach((node) => {
|
|
53
|
+
node.checked = node.value === group;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
39
56
|
}
|
|
40
|
-
export let
|
|
57
|
+
export let treeItems = [];
|
|
41
58
|
let children = [];
|
|
42
59
|
</script>
|
|
43
60
|
|
|
44
61
|
{#if nodes && nodes.length > 0}
|
|
45
62
|
{#each nodes as node, i}
|
|
46
63
|
<TreeViewItem
|
|
47
|
-
bind:this={
|
|
64
|
+
bind:this={treeItems[i]}
|
|
48
65
|
bind:open={node.open}
|
|
49
66
|
hideLead={!node.lead}
|
|
50
67
|
hideChildren={!node.children || node.children.length === 0}
|
|
@@ -54,16 +71,19 @@ let children = [];
|
|
|
54
71
|
bind:indeterminate={node.indeterminate}
|
|
55
72
|
bind:value={node.value}
|
|
56
73
|
bind:children={children[i]}
|
|
57
|
-
on:change={
|
|
74
|
+
on:change={onGroupChange}
|
|
75
|
+
on:change
|
|
58
76
|
on:click
|
|
59
77
|
on:toggle
|
|
78
|
+
on:keydown
|
|
79
|
+
on:keyup
|
|
60
80
|
>
|
|
61
81
|
{@html node.content}
|
|
62
82
|
<svelte:fragment slot="lead">
|
|
63
83
|
{@html node.lead}
|
|
64
84
|
</svelte:fragment>
|
|
65
85
|
<svelte:fragment slot="children">
|
|
66
|
-
<TreeViewDataDrivenItem nodes={node.children}
|
|
86
|
+
<TreeViewDataDrivenItem bind:nodes={node.children} bind:treeItems={children[i]} />
|
|
67
87
|
</svelte:fragment>
|
|
68
88
|
</TreeViewItem>
|
|
69
89
|
{/each}
|
|
@@ -6,12 +6,14 @@ declare const __propDef: {
|
|
|
6
6
|
/** Provide data-driven nodes. */ nodes?: TreeViewNode[] | undefined;
|
|
7
7
|
/** Enable tree-view selection */ selection?: boolean | undefined;
|
|
8
8
|
/** Enable selection of multiple items. */ multiple?: boolean | undefined;
|
|
9
|
-
|
|
9
|
+
treeItems?: TreeViewItem[] | undefined;
|
|
10
10
|
};
|
|
11
11
|
events: {
|
|
12
|
+
change: Event;
|
|
12
13
|
click: MouseEvent;
|
|
13
14
|
toggle: CustomEvent<any>;
|
|
14
|
-
|
|
15
|
+
keydown: KeyboardEvent;
|
|
16
|
+
keyup: KeyboardEvent;
|
|
15
17
|
} & {
|
|
16
18
|
[evt: string]: CustomEvent<any>;
|
|
17
19
|
};
|
|
@@ -48,7 +48,8 @@ function updateGroup(checked2) {
|
|
|
48
48
|
const index = group.indexOf(value);
|
|
49
49
|
if (checked2) {
|
|
50
50
|
if (index < 0) {
|
|
51
|
-
group
|
|
51
|
+
group.push(value);
|
|
52
|
+
group = group;
|
|
52
53
|
}
|
|
53
54
|
} else {
|
|
54
55
|
if (index >= 0) {
|
|
@@ -57,72 +58,83 @@ function updateGroup(checked2) {
|
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
|
-
function onChildValueChange(
|
|
61
|
+
function onChildValueChange() {
|
|
61
62
|
if (multiple) {
|
|
62
63
|
if (!Array.isArray(group))
|
|
63
64
|
return;
|
|
64
65
|
const childrenValues = children.map((c) => c.value);
|
|
66
|
+
const childrenGroup = children[0].group;
|
|
65
67
|
const index = group.indexOf(value);
|
|
66
|
-
if (
|
|
68
|
+
if (children.some((c) => c.indeterminate)) {
|
|
69
|
+
indeterminate = true;
|
|
70
|
+
} else if (childrenValues.every((c) => Array.isArray(childrenGroup) && childrenGroup.includes(c))) {
|
|
71
|
+
indeterminate = false;
|
|
67
72
|
if (index < 0) {
|
|
68
|
-
|
|
69
|
-
group =
|
|
73
|
+
group.push(value);
|
|
74
|
+
group = group;
|
|
70
75
|
}
|
|
76
|
+
} else if (childrenValues.some((c) => Array.isArray(childrenGroup) && childrenGroup.includes(c))) {
|
|
77
|
+
indeterminate = true;
|
|
71
78
|
} else {
|
|
79
|
+
indeterminate = false;
|
|
72
80
|
if (index >= 0) {
|
|
73
81
|
group.splice(index, 1);
|
|
74
82
|
group = group;
|
|
75
83
|
}
|
|
76
|
-
indeterminate = childrenValues.some((c) => Array.isArray(child.group) && child.group.includes(c));
|
|
77
84
|
}
|
|
78
85
|
} else {
|
|
79
|
-
if (
|
|
86
|
+
if (group !== value) {
|
|
80
87
|
group = value;
|
|
81
88
|
}
|
|
82
89
|
}
|
|
90
|
+
dispatch("change");
|
|
83
91
|
}
|
|
84
|
-
function
|
|
85
|
-
if (!children || children.length === 0
|
|
92
|
+
export function onParentChange() {
|
|
93
|
+
if (!multiple || !children || children.length === 0)
|
|
86
94
|
return;
|
|
87
|
-
if (
|
|
88
|
-
|
|
95
|
+
if (!Array.isArray(group))
|
|
96
|
+
return;
|
|
97
|
+
const index = group.indexOf(value);
|
|
98
|
+
const checkChild = (child) => {
|
|
99
|
+
if (!child || !Array.isArray(child.group))
|
|
89
100
|
return;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
101
|
+
child.indeterminate = false;
|
|
102
|
+
if (child.group.indexOf(child.value) < 0) {
|
|
103
|
+
child.group.push(child.value);
|
|
104
|
+
child.group = child.group;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const uncheckChild = (child) => {
|
|
108
|
+
if (!child || !Array.isArray(child.group))
|
|
109
|
+
return;
|
|
110
|
+
child.indeterminate = false;
|
|
111
|
+
const childIndex = child.group.indexOf(child.value);
|
|
112
|
+
if (childIndex >= 0) {
|
|
113
|
+
child.group.splice(childIndex, 1);
|
|
114
|
+
child.group = child.group;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
children.forEach((child) => {
|
|
118
|
+
index >= 0 ? checkChild(child) : uncheckChild(child);
|
|
119
|
+
child.onParentChange();
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
$:
|
|
123
|
+
if (!multiple && group) {
|
|
124
|
+
if (group !== value) {
|
|
111
125
|
children.forEach((child) => {
|
|
112
|
-
child
|
|
126
|
+
if (child)
|
|
127
|
+
child.group = [];
|
|
113
128
|
});
|
|
114
129
|
}
|
|
115
130
|
}
|
|
116
|
-
}
|
|
117
|
-
$:
|
|
118
|
-
onGroupValueChange(group);
|
|
119
131
|
const dispatch = createEventDispatcher();
|
|
120
132
|
$:
|
|
121
133
|
dispatch("toggle", { open });
|
|
122
134
|
$:
|
|
123
135
|
children.forEach((child) => {
|
|
124
136
|
if (child)
|
|
125
|
-
child.$on("change", (
|
|
137
|
+
child.$on("change", () => onChildValueChange());
|
|
126
138
|
});
|
|
127
139
|
function onKeyDown(event) {
|
|
128
140
|
function getRootTree() {
|
|
@@ -152,7 +164,7 @@ function onKeyDown(event) {
|
|
|
152
164
|
else {
|
|
153
165
|
const parent = treeItem.parentElement?.parentElement;
|
|
154
166
|
if (parent && parent.tagName === "DETAILS")
|
|
155
|
-
parent.querySelector("summary")
|
|
167
|
+
parent.querySelector("summary")?.focus();
|
|
156
168
|
}
|
|
157
169
|
break;
|
|
158
170
|
case "Home":
|
|
@@ -241,7 +253,17 @@ $:
|
|
|
241
253
|
<!-- Selection -->
|
|
242
254
|
{#if selection && name && group !== undefined}
|
|
243
255
|
{#if multiple}
|
|
244
|
-
<input
|
|
256
|
+
<input
|
|
257
|
+
class="checkbox tree-item-checkbox"
|
|
258
|
+
type="checkbox"
|
|
259
|
+
{name}
|
|
260
|
+
{value}
|
|
261
|
+
bind:checked
|
|
262
|
+
bind:indeterminate
|
|
263
|
+
on:click
|
|
264
|
+
on:change
|
|
265
|
+
on:change={onParentChange}
|
|
266
|
+
/>
|
|
245
267
|
{:else}
|
|
246
268
|
<input class="radio tree-item-radio" type="radio" bind:group {name} {value} on:click on:change />
|
|
247
269
|
{/if}
|
|
@@ -46,6 +46,7 @@ declare const __propDef: {
|
|
|
46
46
|
hideLead?: boolean | undefined;
|
|
47
47
|
/** Don't use this prop, workaround until svelte implements conditional slots*/
|
|
48
48
|
hideChildren?: boolean | undefined;
|
|
49
|
+
onParentChange?: (() => void) | undefined;
|
|
49
50
|
};
|
|
50
51
|
events: {
|
|
51
52
|
click: MouseEvent;
|
|
@@ -66,6 +67,7 @@ export type TreeViewItemProps = typeof __propDef.props;
|
|
|
66
67
|
export type TreeViewItemEvents = typeof __propDef.events;
|
|
67
68
|
export type TreeViewItemSlots = typeof __propDef.slots;
|
|
68
69
|
export default class TreeViewItem extends SvelteComponentTyped<TreeViewItemProps, TreeViewItemEvents, TreeViewItemSlots> {
|
|
70
|
+
get onParentChange(): () => void;
|
|
69
71
|
get group(): unknown;
|
|
70
72
|
/**accessor*/
|
|
71
73
|
set group(_: unknown);
|
|
@@ -132,5 +134,8 @@ export default class TreeViewItem extends SvelteComponentTyped<TreeViewItemProps
|
|
|
132
134
|
get hideChildren(): boolean | undefined;
|
|
133
135
|
/**accessor*/
|
|
134
136
|
set hideChildren(_: boolean | undefined);
|
|
137
|
+
get undefined(): any;
|
|
138
|
+
/**accessor*/
|
|
139
|
+
set undefined(_: any);
|
|
135
140
|
}
|
|
136
141
|
export {};
|