@coyalabs/bts-style 1.1.0 → 1.1.2
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.
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { slide } from 'svelte/transition';
|
|
3
|
+
import { createEventDispatcher, onMount } from 'svelte';
|
|
3
4
|
import Button from './Button.svelte';
|
|
4
5
|
import { icons } from '../icons.js';
|
|
5
6
|
|
|
7
|
+
const dispatch = createEventDispatcher();
|
|
8
|
+
|
|
6
9
|
/** @type {{ name: string, type: 'file' | 'folder', children?: any[] }[]} */
|
|
7
10
|
export let items = [];
|
|
8
11
|
|
|
@@ -14,16 +17,39 @@
|
|
|
14
17
|
|
|
15
18
|
/** @type {number} */
|
|
16
19
|
export let level = 0;
|
|
20
|
+
|
|
21
|
+
/** @type {boolean} */
|
|
22
|
+
export let topFoldersExpanded = false;
|
|
17
23
|
|
|
18
24
|
let expanded = new Set();
|
|
25
|
+
|
|
26
|
+
onMount(() => {
|
|
27
|
+
if (topFoldersExpanded && level === 0) {
|
|
28
|
+
items.forEach((item, i) => {
|
|
29
|
+
if (item.type === 'folder') {
|
|
30
|
+
expanded.add(`${level}-${i}`);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
expanded = expanded;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
19
36
|
|
|
20
37
|
/**
|
|
21
38
|
* @param {string} id
|
|
39
|
+
* @param {any} item
|
|
22
40
|
*/
|
|
23
|
-
function toggle(id) {
|
|
41
|
+
function toggle(id, item) {
|
|
24
42
|
if (expanded.has(id)) expanded.delete(id);
|
|
25
43
|
else expanded.add(id);
|
|
26
44
|
expanded = expanded;
|
|
45
|
+
dispatch('itemClick', { item, type: 'folder' });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {any} item
|
|
50
|
+
*/
|
|
51
|
+
function handleItemClick(item) {
|
|
52
|
+
dispatch('itemClick', { item, type: 'file' });
|
|
27
53
|
}
|
|
28
54
|
|
|
29
55
|
/**
|
|
@@ -98,7 +124,7 @@
|
|
|
98
124
|
{@const isNested = level > 0}
|
|
99
125
|
|
|
100
126
|
{#if item.type === 'folder'}
|
|
101
|
-
<div class="folder" on:click={() => toggle(id)} on:keydown={() => {}} role="button" tabindex="0">
|
|
127
|
+
<div class="folder" on:click={() => toggle(id, item)} on:keydown={() => {}} role="button" tabindex="0">
|
|
102
128
|
<Button
|
|
103
129
|
theme="primary"
|
|
104
130
|
icon={icons.folder}
|
|
@@ -114,20 +140,22 @@
|
|
|
114
140
|
</div>
|
|
115
141
|
{#if open && item.children}
|
|
116
142
|
<div transition:slide={{ duration: 150 }}>
|
|
117
|
-
<svelte:self items={item.children} {showCount} {itemIcon} level={level + 1} />
|
|
143
|
+
<svelte:self items={item.children} {showCount} {itemIcon} level={level + 1} on:itemClick />
|
|
118
144
|
</div>
|
|
119
145
|
{/if}
|
|
120
146
|
{:else}
|
|
121
|
-
<
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
147
|
+
<div on:click={() => handleItemClick(item)} on:keydown={() => {}} role="button" tabindex="0">
|
|
148
|
+
<Button
|
|
149
|
+
theme="secondary"
|
|
150
|
+
icon={itemIcon}
|
|
151
|
+
borderRadiusTopLeft={isNested ? '15px' : '25px'}
|
|
152
|
+
borderRadiusTopRight={isNested ? '15px' : '25px'}
|
|
153
|
+
borderRadiusBottomLeft={isNested && !isLast ? '15px' : '25px'}
|
|
154
|
+
borderRadiusBottomRight={isNested && !isLast ? '15px' : '25px'}
|
|
155
|
+
>
|
|
156
|
+
{item.name}
|
|
157
|
+
</Button>
|
|
158
|
+
</div>
|
|
131
159
|
{/if}
|
|
132
160
|
{/each}
|
|
133
161
|
</div>
|
|
@@ -8,11 +8,14 @@ type TreeDirectory = SvelteComponent<{
|
|
|
8
8
|
showCount?: boolean | undefined;
|
|
9
9
|
itemIcon?: string | null | undefined;
|
|
10
10
|
level?: number | undefined;
|
|
11
|
+
topFoldersExpanded?: boolean | undefined;
|
|
11
12
|
getState?: (() => string[]) | undefined;
|
|
12
13
|
setState?: ((state: string[]) => void) | undefined;
|
|
13
14
|
expandAll?: (() => void) | undefined;
|
|
14
15
|
collapseAll?: (() => void) | undefined;
|
|
15
16
|
}, {
|
|
17
|
+
itemClick: CustomEvent<any>;
|
|
18
|
+
} & {
|
|
16
19
|
[evt: string]: CustomEvent<any>;
|
|
17
20
|
}, {}> & {
|
|
18
21
|
$$bindings?: string | undefined;
|
|
@@ -31,11 +34,14 @@ declare const TreeDirectory: $$__sveltets_2_IsomorphicComponent<{
|
|
|
31
34
|
showCount?: boolean | undefined;
|
|
32
35
|
itemIcon?: string | null | undefined;
|
|
33
36
|
level?: number | undefined;
|
|
37
|
+
topFoldersExpanded?: boolean | undefined;
|
|
34
38
|
getState?: (() => string[]) | undefined;
|
|
35
39
|
setState?: ((state: string[]) => void) | undefined;
|
|
36
40
|
expandAll?: (() => void) | undefined;
|
|
37
41
|
collapseAll?: (() => void) | undefined;
|
|
38
42
|
}, {
|
|
43
|
+
itemClick: CustomEvent<any>;
|
|
44
|
+
} & {
|
|
39
45
|
[evt: string]: CustomEvent<any>;
|
|
40
46
|
}, {}, {
|
|
41
47
|
getState: () => string[];
|