@skeletonlabs/skeleton 2.3.0-dev.853e711a → 2.4.0-dev.df5caa19
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/RecursiveTreeView.svelte +21 -2
- package/dist/components/TreeView/RecursiveTreeView.svelte.d.ts +5 -0
- package/dist/components/TreeView/RecursiveTreeViewItem.svelte +48 -21
- package/dist/components/TreeView/RecursiveTreeViewItem.svelte.d.ts +3 -0
- package/dist/components/TreeView/TreeViewItem.svelte +9 -13
- package/dist/components/TreeView/types.d.ts +9 -4
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<script>import { setContext } from "svelte";
|
|
1
|
+
<script>import { createEventDispatcher, setContext } from "svelte";
|
|
2
2
|
import RecursiveTreeViewItem from "./RecursiveTreeViewItem.svelte";
|
|
3
3
|
export let selection = false;
|
|
4
4
|
export let multiple = false;
|
|
@@ -38,6 +38,17 @@ setContext("hyphenOpacity", hyphenOpacity);
|
|
|
38
38
|
setContext("regionSummary", regionSummary);
|
|
39
39
|
setContext("regionSymbol", regionSymbol);
|
|
40
40
|
setContext("regionChildren", regionChildren);
|
|
41
|
+
const dispatch = createEventDispatcher();
|
|
42
|
+
function onClick(event) {
|
|
43
|
+
dispatch("click", {
|
|
44
|
+
id: event.detail.id
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function onToggle(event) {
|
|
48
|
+
dispatch("toggle", {
|
|
49
|
+
id: event.detail.id
|
|
50
|
+
});
|
|
51
|
+
}
|
|
41
52
|
$:
|
|
42
53
|
classesBase = `${width} ${spacing} ${$$props.class ?? ""}`;
|
|
43
54
|
</script>
|
|
@@ -51,6 +62,14 @@ $:
|
|
|
51
62
|
aria-disabled={disabled}
|
|
52
63
|
>
|
|
53
64
|
{#if nodes && nodes.length > 0}
|
|
54
|
-
<RecursiveTreeViewItem
|
|
65
|
+
<RecursiveTreeViewItem
|
|
66
|
+
{nodes}
|
|
67
|
+
bind:expandedNodes
|
|
68
|
+
bind:disabledNodes
|
|
69
|
+
bind:checkedNodes
|
|
70
|
+
bind:indeterminateNodes
|
|
71
|
+
on:click={onClick}
|
|
72
|
+
on:toggle={onToggle}
|
|
73
|
+
/>
|
|
55
74
|
{/if}
|
|
56
75
|
</div>
|
|
@@ -50,6 +50,11 @@ declare const __propDef: {
|
|
|
50
50
|
labelledby?: string | undefined;
|
|
51
51
|
};
|
|
52
52
|
events: {
|
|
53
|
+
/** {{id:string}} click - Fires on tree item click*/
|
|
54
|
+
click: CustomEvent<any>;
|
|
55
|
+
/** {{id:string}} toggle - Fires on tree item toggle*/
|
|
56
|
+
toggle: CustomEvent<any>;
|
|
57
|
+
} & {
|
|
53
58
|
[evt: string]: CustomEvent<any>;
|
|
54
59
|
};
|
|
55
60
|
slots: {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script>import TreeViewItem from "./TreeViewItem.svelte";
|
|
2
2
|
import RecursiveTreeViewItem from "./RecursiveTreeViewItem.svelte";
|
|
3
|
-
import { getContext, onMount
|
|
3
|
+
import { createEventDispatcher, getContext, onMount } from "svelte";
|
|
4
4
|
export let nodes = [];
|
|
5
5
|
export let expandedNodes = [];
|
|
6
6
|
export let disabledNodes = [];
|
|
@@ -9,9 +9,9 @@ export let indeterminateNodes = [];
|
|
|
9
9
|
let selection = getContext("selection");
|
|
10
10
|
let multiple = getContext("multiple");
|
|
11
11
|
let relational = getContext("relational");
|
|
12
|
-
let
|
|
13
|
-
let group;
|
|
12
|
+
let group = multiple ? [] : "";
|
|
14
13
|
let name = "";
|
|
14
|
+
const dispatch = createEventDispatcher();
|
|
15
15
|
function toggleNode(node, open) {
|
|
16
16
|
if (!node.children?.length)
|
|
17
17
|
return;
|
|
@@ -51,27 +51,29 @@ function checkNode(node, checked, indeterminate) {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
|
|
54
|
+
if (selection) {
|
|
55
|
+
if (multiple) {
|
|
56
|
+
nodes.forEach((node) => {
|
|
57
|
+
if (!Array.isArray(group))
|
|
58
|
+
return;
|
|
59
|
+
if (checkedNodes.includes(node.id) && !group.includes(node.id)) {
|
|
60
|
+
group.push(node.id);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
group = group;
|
|
64
|
+
} else {
|
|
65
|
+
nodes.forEach((node) => {
|
|
66
|
+
if (checkedNodes.includes(node.id) && group !== node.id) {
|
|
67
|
+
group = node.id;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
55
72
|
onMount(async () => {
|
|
56
73
|
if (selection) {
|
|
57
74
|
name = String(Math.random());
|
|
58
|
-
if (group === void 0) {
|
|
59
|
-
if (multiple) {
|
|
60
|
-
group = [];
|
|
61
|
-
nodes.forEach((node) => {
|
|
62
|
-
if (checkedNodes.includes(node.id) && Array.isArray(group))
|
|
63
|
-
group.push(node.id);
|
|
64
|
-
});
|
|
65
|
-
group = group;
|
|
66
|
-
} else if (!nodes.some((node) => checkedNodes.includes(node.id))) {
|
|
67
|
-
group = "";
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
75
|
if (!relational)
|
|
71
76
|
treeItems = [];
|
|
72
|
-
checkedNodes = [];
|
|
73
|
-
await tick();
|
|
74
|
-
checkedNodes = [...tempCheckedNodes];
|
|
75
77
|
}
|
|
76
78
|
});
|
|
77
79
|
export let treeItems = [];
|
|
@@ -94,10 +96,27 @@ let children = [];
|
|
|
94
96
|
indeterminate={indeterminateNodes.includes(node.id)}
|
|
95
97
|
on:toggle={(e) => toggleNode(node, e.detail.open)}
|
|
96
98
|
on:groupChange={(e) => checkNode(node, e.detail.checked, e.detail.indeterminate)}
|
|
99
|
+
on:click={() =>
|
|
100
|
+
dispatch('click', {
|
|
101
|
+
id: node.id
|
|
102
|
+
})}
|
|
103
|
+
on:toggle={() => {
|
|
104
|
+
dispatch('toggle', {
|
|
105
|
+
id: node.id
|
|
106
|
+
});
|
|
107
|
+
}}
|
|
97
108
|
>
|
|
98
|
-
{
|
|
109
|
+
{#if typeof node.content === 'string'}
|
|
110
|
+
{@html node.content}
|
|
111
|
+
{:else}
|
|
112
|
+
<svelte:component this={node.content} {...node.contentProps} />
|
|
113
|
+
{/if}
|
|
99
114
|
<svelte:fragment slot="lead">
|
|
100
|
-
{
|
|
115
|
+
{#if typeof node.lead === 'string'}
|
|
116
|
+
{@html node.lead}
|
|
117
|
+
{:else}
|
|
118
|
+
<svelte:component this={node.lead} {...node.leadProps} />
|
|
119
|
+
{/if}
|
|
101
120
|
</svelte:fragment>
|
|
102
121
|
<svelte:fragment slot="children">
|
|
103
122
|
<RecursiveTreeViewItem
|
|
@@ -107,6 +126,14 @@ let children = [];
|
|
|
107
126
|
bind:checkedNodes
|
|
108
127
|
bind:indeterminateNodes
|
|
109
128
|
bind:treeItems={children[i]}
|
|
129
|
+
on:click={(e) =>
|
|
130
|
+
dispatch('click', {
|
|
131
|
+
id: e.detail.id
|
|
132
|
+
})}
|
|
133
|
+
on:toggle={(e) =>
|
|
134
|
+
dispatch('toggle', {
|
|
135
|
+
id: e.detail.id
|
|
136
|
+
})}
|
|
110
137
|
/>
|
|
111
138
|
</svelte:fragment>
|
|
112
139
|
</TreeViewItem>
|
|
@@ -37,23 +37,12 @@ $:
|
|
|
37
37
|
$:
|
|
38
38
|
if (multiple)
|
|
39
39
|
updateGroup(checked, indeterminate);
|
|
40
|
-
$:
|
|
41
|
-
if (!multiple)
|
|
42
|
-
updateRadio(group);
|
|
43
|
-
$:
|
|
44
|
-
if (!multiple)
|
|
45
|
-
updateRadioGroup(checked);
|
|
46
|
-
let initUpdate = true;
|
|
47
40
|
function updateCheckbox(group2, indeterminate2) {
|
|
48
41
|
if (!Array.isArray(group2))
|
|
49
42
|
return;
|
|
50
43
|
checked = group2.indexOf(value) >= 0;
|
|
51
44
|
dispatch("groupChange", { checked, indeterminate: indeterminate2 });
|
|
52
45
|
dispatch("childChange");
|
|
53
|
-
if (initUpdate) {
|
|
54
|
-
onParentChange();
|
|
55
|
-
initUpdate = false;
|
|
56
|
-
}
|
|
57
46
|
}
|
|
58
47
|
function updateGroup(checked2, indeterminate2) {
|
|
59
48
|
if (!Array.isArray(group))
|
|
@@ -63,16 +52,23 @@ function updateGroup(checked2, indeterminate2) {
|
|
|
63
52
|
if (index < 0) {
|
|
64
53
|
group.push(value);
|
|
65
54
|
group = group;
|
|
66
|
-
onParentChange();
|
|
67
55
|
}
|
|
68
56
|
} else {
|
|
69
57
|
if (index >= 0) {
|
|
70
58
|
group.splice(index, 1);
|
|
71
59
|
group = group;
|
|
72
|
-
onParentChange();
|
|
73
60
|
}
|
|
74
61
|
}
|
|
62
|
+
if (!indeterminate2) {
|
|
63
|
+
onParentChange();
|
|
64
|
+
}
|
|
75
65
|
}
|
|
66
|
+
$:
|
|
67
|
+
if (!multiple)
|
|
68
|
+
updateRadio(group);
|
|
69
|
+
$:
|
|
70
|
+
if (!multiple)
|
|
71
|
+
updateRadioGroup(checked);
|
|
76
72
|
function updateRadio(group2) {
|
|
77
73
|
checked = group2 === value;
|
|
78
74
|
dispatch("groupChange", { checked, indeterminate: false });
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
import type { ComponentType } from 'svelte';
|
|
1
2
|
export interface TreeViewNode {
|
|
2
3
|
/** Nodes Unique ID */
|
|
3
4
|
id: string;
|
|
4
|
-
/** Main content. accepts HTML. */
|
|
5
|
-
content: string;
|
|
6
|
-
/**
|
|
7
|
-
|
|
5
|
+
/** Main content. accepts HTML or svelte component. */
|
|
6
|
+
content: string | ComponentType;
|
|
7
|
+
/** Main content props. only used when the Content is a svelte component. */
|
|
8
|
+
contentProps?: object;
|
|
9
|
+
/** Lead content. accepts HTML or svelte component. */
|
|
10
|
+
lead?: string | ComponentType;
|
|
11
|
+
/** lead props. only used when the Lead is a svelte component. */
|
|
12
|
+
leadProps?: object;
|
|
8
13
|
/** children nodes. */
|
|
9
14
|
children?: TreeViewNode[];
|
|
10
15
|
/** Set the input's value. */
|