@keenmate/svelte-treeview 2.0.0 → 3.0.0
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/Branch.svelte +57 -67
- package/dist/Branch.svelte.d.ts +4 -52
- package/dist/Checkbox.svelte +8 -11
- package/dist/Checkbox.svelte.d.ts +26 -22
- package/dist/TreeView.svelte +52 -156
- package/dist/TreeView.svelte.d.ts +125 -127
- package/dist/menu/ContextMenu.svelte +8 -7
- package/dist/menu/ContextMenu.svelte.d.ts +7 -20
- package/dist/menu/Menu.svelte +32 -39
- package/dist/menu/Menu.svelte.d.ts +20 -30
- package/dist/menu/MenuDivider.svelte.d.ts +22 -19
- package/dist/menu/MenuOption.svelte +15 -23
- package/dist/menu/MenuOption.svelte.d.ts +22 -30
- package/dist/types.d.ts +1 -1
- package/package.json +21 -14
package/dist/Branch.svelte
CHANGED
|
@@ -1,35 +1,18 @@
|
|
|
1
|
-
<script>import
|
|
1
|
+
<script lang="ts">import Branch from "./Branch.svelte";
|
|
2
2
|
import Checkbox from "./Checkbox.svelte";
|
|
3
3
|
import { InsertionType, SelectionModes } from "./types.js";
|
|
4
4
|
import { capturedKeys } from "./constants.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export let treeId;
|
|
8
|
-
export let recursive = false;
|
|
9
|
-
export let checkboxes = SelectionModes.none;
|
|
10
|
-
export let onlyLeafCheckboxes;
|
|
11
|
-
export let hideDisabledCheckboxes;
|
|
12
|
-
export let dragAndDrop;
|
|
13
|
-
export let verticalLines;
|
|
14
|
-
export let readonly;
|
|
15
|
-
export let expandTo;
|
|
16
|
-
export let classes;
|
|
17
|
-
export let helper;
|
|
18
|
-
export let childDepth;
|
|
19
|
-
export let branchRootNode;
|
|
20
|
-
export let draggedNode;
|
|
21
|
-
export let highlightedNode;
|
|
22
|
-
export let insertionType;
|
|
23
|
-
export let focusedNode;
|
|
24
|
-
export let allowKeyboardNavigation;
|
|
25
|
-
let liElements = {};
|
|
5
|
+
let { tree, treeId, recursive = false, checkboxes = SelectionModes.none, onlyLeafCheckboxes, hideDisabledCheckboxes, dragAndDrop, verticalLines, readonly, expandTo, classes, helper, childDepth, branchRootNode, draggedNode, highlightedNode, insertionType, focusedNode, allowKeyboardNavigation, onOpenCtxmenu = undefined, internal_onExpand = undefined, internal_onSelectionChanged = undefined, internal_onHandleDragStart = undefined, internal_onHandleDragDrop = undefined, internal_onHandleDragOver = undefined, internal_onHandleDragEnter = undefined, internal_onHandleDragEnd = undefined, internal_onHandleDragLeave = undefined, internal_onKeypress = undefined, children, nestHighlight } = $props();
|
|
6
|
+
let liElements = $state({});
|
|
26
7
|
const getNodeId = (node) => `${treeId}-${node.path}`;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
liElements[getNodeId(focusedNode)]
|
|
30
|
-
|
|
8
|
+
let directChildren = $derived(helper.getDirectChildren(tree, branchRootNode?.path ?? null));
|
|
9
|
+
$effect(() => {
|
|
10
|
+
if (focusedNode && liElements[getNodeId(focusedNode)]) {
|
|
11
|
+
liElements[getNodeId(focusedNode)].focus();
|
|
12
|
+
}
|
|
13
|
+
});
|
|
31
14
|
function setExpansion(node, changeTo) {
|
|
32
|
-
|
|
15
|
+
internal_onExpand?.({ node: node, changeTo });
|
|
33
16
|
}
|
|
34
17
|
function isExpanded(node, depth, expandToDepth) {
|
|
35
18
|
const nodeExpanded = node.expanded;
|
|
@@ -41,26 +24,31 @@ function isExpanded(node, depth, expandToDepth) {
|
|
|
41
24
|
}
|
|
42
25
|
//checkboxes
|
|
43
26
|
function selectionChanged(node) {
|
|
44
|
-
|
|
27
|
+
internal_onSelectionChanged?.({ node: node });
|
|
45
28
|
}
|
|
46
29
|
// drag and drop
|
|
47
30
|
function handleDragStart(e, node) {
|
|
48
|
-
|
|
31
|
+
internal_onHandleDragStart?.({ node: node, e: e });
|
|
49
32
|
}
|
|
50
33
|
function handleDragDrop(e, node, el) {
|
|
51
|
-
|
|
34
|
+
e.stopImmediatePropagation();
|
|
35
|
+
internal_onHandleDragDrop?.({ node: node, event: e, element: el });
|
|
52
36
|
}
|
|
53
37
|
function handleDragOver(e, node, el, nest) {
|
|
54
|
-
|
|
38
|
+
e.stopImmediatePropagation();
|
|
39
|
+
internal_onHandleDragOver?.({ node: node, event: e, element: el, nest });
|
|
55
40
|
}
|
|
56
41
|
function handleDragEnter(e, node, el) {
|
|
57
|
-
|
|
42
|
+
e.stopImmediatePropagation();
|
|
43
|
+
internal_onHandleDragEnter?.({ node: node, event: e, element: el });
|
|
58
44
|
}
|
|
59
45
|
function handleDragEnd(e, node) {
|
|
60
|
-
|
|
46
|
+
e.stopImmediatePropagation();
|
|
47
|
+
internal_onHandleDragEnd?.({ node: node, event: e });
|
|
61
48
|
}
|
|
62
49
|
function handleDragLeave(e, node, el) {
|
|
63
|
-
|
|
50
|
+
e.stopImmediatePropagation();
|
|
51
|
+
internal_onHandleDragLeave?.({ node: node, event: e, element: el });
|
|
64
52
|
}
|
|
65
53
|
function handleKeyPress(e, node) {
|
|
66
54
|
if (!capturedKeys.includes(e.key)) {
|
|
@@ -68,7 +56,7 @@ function handleKeyPress(e, node) {
|
|
|
68
56
|
}
|
|
69
57
|
e.preventDefault();
|
|
70
58
|
e.stopPropagation();
|
|
71
|
-
|
|
59
|
+
internal_onKeypress?.({ event: e, node });
|
|
72
60
|
}
|
|
73
61
|
function getHighlighMode(node, highlightedNode, insertionType) {
|
|
74
62
|
// return InsertionType.insertAbove;
|
|
@@ -77,6 +65,10 @@ function getHighlighMode(node, highlightedNode, insertionType) {
|
|
|
77
65
|
}
|
|
78
66
|
return insertionType;
|
|
79
67
|
}
|
|
68
|
+
function onContextMenu(ev, node) {
|
|
69
|
+
ev.stopImmediatePropagation();
|
|
70
|
+
onOpenCtxmenu({ ev, node });
|
|
71
|
+
}
|
|
80
72
|
</script>
|
|
81
73
|
|
|
82
74
|
<ul
|
|
@@ -85,35 +77,32 @@ function getHighlighMode(node, highlightedNode, insertionType) {
|
|
|
85
77
|
class={childDepth === 0 ? classes.treeClass : ''}
|
|
86
78
|
>
|
|
87
79
|
<!-- TODO fix accessibility -->
|
|
88
|
-
<!-- svelte-ignore
|
|
80
|
+
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
89
81
|
{#each directChildren as node (getNodeId(node))}
|
|
90
82
|
{@const expanded = isExpanded(node, childDepth, expandTo)}
|
|
91
83
|
{@const draggable = !readonly && dragAndDrop && !node.dragDisabled}
|
|
92
84
|
{@const isCurrentlyDragged = draggedNode && node.path.startsWith(draggedNode?.path)}
|
|
93
85
|
{@const effectiveHighlight = getHighlighMode(node, highlightedNode, insertionType)}
|
|
94
|
-
<!-- svelte-ignore
|
|
86
|
+
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
95
87
|
<li
|
|
96
88
|
class:is-child={helper.nodePathIsChild(node.path)}
|
|
97
89
|
class:has-children={node.hasChildren}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
handleDragOver(e, node, liElements[getNodeId(node)], false)}
|
|
104
|
-
on:dragenter|stopPropagation={(e) => handleDragEnter(e, node, liElements[getNodeId(node)])}
|
|
105
|
-
on:dragleave|stopPropagation={(e) => handleDragLeave(e, node, liElements[getNodeId(node)])}
|
|
90
|
+
oncontextmenu={e => onContextMenu(e, node)}
|
|
91
|
+
ondrop={e => handleDragDrop(e, node, liElements[getNodeId(node)])}
|
|
92
|
+
ondragover={e => handleDragOver(e, node, liElements[getNodeId(node)], false)}
|
|
93
|
+
ondragenter={e => handleDragEnter(e, node, liElements[getNodeId(node)])}
|
|
94
|
+
ondragleave={e => handleDragLeave(e, node, liElements[getNodeId(node)])}
|
|
106
95
|
bind:this={liElements[getNodeId(node)]}
|
|
107
|
-
|
|
96
|
+
onkeydown={(e) => handleKeyPress(e, node)}
|
|
108
97
|
tabindex={allowKeyboardNavigation ? 1 : -1}
|
|
109
98
|
>
|
|
110
99
|
{#if effectiveHighlight == InsertionType.insertAbove}
|
|
111
100
|
<div class="insert-line-wrapper">
|
|
112
|
-
<div class="insert-line {classes.insertLineClass}"
|
|
101
|
+
<div class="insert-line {classes.insertLineClass}"></div>
|
|
113
102
|
</div>
|
|
114
103
|
{/if}
|
|
115
104
|
|
|
116
|
-
<!-- svelte-ignore
|
|
105
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
117
106
|
<div
|
|
118
107
|
class="tree-item
|
|
119
108
|
{effectiveHighlight === InsertionType.nest ? classes.expandClass : ''}
|
|
@@ -121,20 +110,20 @@ function getHighlighMode(node, highlightedNode, insertionType) {
|
|
|
121
110
|
class:div-has-children={node.hasChildren}
|
|
122
111
|
class:hover={effectiveHighlight !== InsertionType.none}
|
|
123
112
|
{draggable}
|
|
124
|
-
|
|
125
|
-
|
|
113
|
+
ondragstart={(e) => handleDragStart(e, node)}
|
|
114
|
+
ondragend={(e) => handleDragEnd(e, node)}
|
|
126
115
|
>
|
|
127
116
|
{#if node.hasChildren}
|
|
128
117
|
<button
|
|
129
118
|
class="expansion-button arrow"
|
|
130
|
-
|
|
119
|
+
onclick={() => setExpansion(node, !expanded)}
|
|
131
120
|
type="button"
|
|
132
121
|
tabindex="-1"
|
|
133
122
|
>
|
|
134
|
-
<i class="fixed-icon arrow {expanded ? classes.collapseIcon : classes.expandIcon}"
|
|
123
|
+
<i class="fixed-icon arrow {expanded ? classes.collapseIcon : classes.expandIcon}"></i>
|
|
135
124
|
</button>
|
|
136
125
|
{:else}
|
|
137
|
-
<span class="fixed-icon"
|
|
126
|
+
<span class="fixed-icon"></span>
|
|
138
127
|
{/if}
|
|
139
128
|
|
|
140
129
|
<Checkbox
|
|
@@ -147,24 +136,23 @@ function getHighlighMode(node, highlightedNode, insertionType) {
|
|
|
147
136
|
on:select={({ detail: { node } }) => selectionChanged(node)}
|
|
148
137
|
/>
|
|
149
138
|
<span class:pointer-cursor={draggable}>
|
|
150
|
-
|
|
139
|
+
{@render children?.({node: node.originalNode,})}
|
|
151
140
|
</span>
|
|
152
141
|
|
|
153
142
|
{#if dragAndDrop && node.nestAllowed}
|
|
154
143
|
<span
|
|
155
|
-
|
|
156
|
-
handleDragOver(e, node, liElements[getNodeId(node)], true)}
|
|
144
|
+
ondragover={e => handleDragOver(e, node, liElements[getNodeId(node)], true)}
|
|
157
145
|
>
|
|
158
|
-
<i class="fixed-icon {classes.nestIcon}"
|
|
146
|
+
<i class="fixed-icon {classes.nestIcon}"></i>
|
|
159
147
|
|
|
160
148
|
{#if effectiveHighlight === InsertionType.nest}
|
|
161
|
-
|
|
149
|
+
{@render nestHighlight?.()}
|
|
162
150
|
{/if}
|
|
163
151
|
</span>
|
|
164
152
|
{/if}
|
|
165
153
|
</div>
|
|
166
154
|
{#if expanded && node.hasChildren}
|
|
167
|
-
<
|
|
155
|
+
<Branch
|
|
168
156
|
branchRootNode={node}
|
|
169
157
|
childDepth={childDepth + 1}
|
|
170
158
|
{treeId}
|
|
@@ -194,21 +182,23 @@ function getHighlighMode(node, highlightedNode, insertionType) {
|
|
|
194
182
|
on:internal-handleDragEnd
|
|
195
183
|
on:internal-handleDragLeave
|
|
196
184
|
on:internal-keypress
|
|
197
|
-
|
|
185
|
+
|
|
198
186
|
>
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
187
|
+
{#snippet children({ node: nodeNested })}
|
|
188
|
+
{@render children?.({node: nodeNested,})}
|
|
189
|
+
<!--<svelte:fragment slot="nest-highlight">-->
|
|
190
|
+
<!-- <slot name="nest-highlight" />-->
|
|
191
|
+
<!--</svelte:fragment>-->
|
|
192
|
+
{/snippet}
|
|
193
|
+
</Branch>
|
|
204
194
|
{/if}
|
|
205
195
|
{#if !expanded && node.hasChildren}
|
|
206
|
-
<ul class:child-menu={childDepth > 0}
|
|
196
|
+
<ul class:child-menu={childDepth > 0}></ul>
|
|
207
197
|
{/if}
|
|
208
198
|
<!-- Show line if insering -->
|
|
209
199
|
{#if effectiveHighlight === InsertionType.insertBelow}
|
|
210
200
|
<div class="insert-line-wrapper">
|
|
211
|
-
<div class="insert-line {classes.insertLineClass}"
|
|
201
|
+
<div class="insert-line {classes.insertLineClass}"></div>
|
|
212
202
|
</div>
|
|
213
203
|
{/if}
|
|
214
204
|
</li>
|
package/dist/Branch.svelte.d.ts
CHANGED
|
@@ -1,52 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
props: {
|
|
6
|
-
tree: Node[];
|
|
7
|
-
treeId: string;
|
|
8
|
-
recursive?: boolean | undefined;
|
|
9
|
-
checkboxes?: SelectionModes | undefined;
|
|
10
|
-
onlyLeafCheckboxes: boolean;
|
|
11
|
-
hideDisabledCheckboxes: boolean;
|
|
12
|
-
dragAndDrop: boolean;
|
|
13
|
-
verticalLines: boolean;
|
|
14
|
-
readonly: boolean;
|
|
15
|
-
expandTo: number;
|
|
16
|
-
classes: CustomizableClasses;
|
|
17
|
-
helper: TreeHelper;
|
|
18
|
-
childDepth: number;
|
|
19
|
-
branchRootNode: Node | null;
|
|
20
|
-
draggedNode: Node | null;
|
|
21
|
-
highlightedNode: Node | null;
|
|
22
|
-
insertionType: InsertionType;
|
|
23
|
-
focusedNode: Node | null;
|
|
24
|
-
allowKeyboardNavigation: boolean;
|
|
25
|
-
};
|
|
26
|
-
events: {
|
|
27
|
-
'open-ctxmenu': CustomEvent<any>;
|
|
28
|
-
'internal-expand': CustomEvent<any>;
|
|
29
|
-
'internal-selectionChanged': CustomEvent<any>;
|
|
30
|
-
'internal-handleDragStart': CustomEvent<any>;
|
|
31
|
-
'internal-handleDragDrop': CustomEvent<any>;
|
|
32
|
-
'internal-handleDragOver': CustomEvent<any>;
|
|
33
|
-
'internal-handleDragEnter': CustomEvent<any>;
|
|
34
|
-
'internal-handleDragEnd': CustomEvent<any>;
|
|
35
|
-
'internal-handleDragLeave': CustomEvent<any>;
|
|
36
|
-
'internal-keypress': CustomEvent<any>;
|
|
37
|
-
} & {
|
|
38
|
-
[evt: string]: CustomEvent<any>;
|
|
39
|
-
};
|
|
40
|
-
slots: {
|
|
41
|
-
default: {
|
|
42
|
-
node: any;
|
|
43
|
-
};
|
|
44
|
-
'nest-highlight': {};
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
export type BranchProps = typeof __propDef.props;
|
|
48
|
-
export type BranchEvents = typeof __propDef.events;
|
|
49
|
-
export type BranchSlots = typeof __propDef.slots;
|
|
50
|
-
export default class Branch extends SvelteComponent<BranchProps, BranchEvents, BranchSlots> {
|
|
51
|
-
}
|
|
52
|
-
export {};
|
|
1
|
+
import Branch from "./Branch.svelte";
|
|
2
|
+
declare const Branch: any;
|
|
3
|
+
type Branch = InstanceType<typeof Branch>;
|
|
4
|
+
export default Branch;
|
package/dist/Checkbox.svelte
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
<script>import {
|
|
1
|
+
<script lang="ts">import { createBubbler, preventDefault, stopPropagation } from 'svelte/legacy';
|
|
2
|
+
const bubble = createBubbler();
|
|
3
|
+
import { createEventDispatcher } from "svelte";
|
|
2
4
|
import { SelectionModes, VisualState } from "./types.js";
|
|
3
5
|
import { isSelectable } from "./providers/selection-provider.js";
|
|
4
|
-
|
|
5
|
-
export let recursive;
|
|
6
|
-
export let node;
|
|
7
|
-
export let onlyLeafCheckboxes;
|
|
8
|
-
export let hideDisabledCheckboxes;
|
|
9
|
-
export let readonly = false;
|
|
6
|
+
let { checkboxes, recursive, node, onlyLeafCheckboxes, hideDisabledCheckboxes, readonly = false } = $props();
|
|
10
7
|
const dispatch = createEventDispatcher();
|
|
11
8
|
function onSelect(e, node) {
|
|
12
9
|
// e.preventDefault();
|
|
@@ -22,8 +19,8 @@ function onSelect(e, node) {
|
|
|
22
19
|
tabindex="-1"
|
|
23
20
|
type="checkbox"
|
|
24
21
|
class="arrow"
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
onclick={(e) => onSelect(e, node)}
|
|
23
|
+
onkeypress={(e) => e.key === 'Enter' && onSelect(e, node)}
|
|
27
24
|
checked={node.visualState === VisualState.selected}
|
|
28
25
|
indeterminate={node.visualState === VisualState.indeterminate}
|
|
29
26
|
disabled={readonly}
|
|
@@ -33,7 +30,7 @@ function onSelect(e, node) {
|
|
|
33
30
|
tabindex="-1"
|
|
34
31
|
class="arrow"
|
|
35
32
|
type="checkbox"
|
|
36
|
-
|
|
33
|
+
onclick={null}
|
|
37
34
|
disabled={true}
|
|
38
35
|
checked={node.visualState === VisualState.selected}
|
|
39
36
|
indeterminate={node.visualState === VisualState.indeterminate}
|
|
@@ -45,7 +42,7 @@ function onSelect(e, node) {
|
|
|
45
42
|
tabindex="-1"
|
|
46
43
|
class="arrow"
|
|
47
44
|
type="checkbox"
|
|
48
|
-
|
|
45
|
+
onclick={stopPropagation(preventDefault(bubble('click')))}
|
|
49
46
|
disabled={true}
|
|
50
47
|
class:invisible={hideDisabledCheckboxes}
|
|
51
48
|
/>
|
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import { SvelteComponent } from "svelte";
|
|
2
1
|
import { type Node, SelectionModes } from "./types.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
interface Props {
|
|
3
|
+
checkboxes: SelectionModes;
|
|
4
|
+
recursive: boolean;
|
|
5
|
+
node: Node;
|
|
6
|
+
onlyLeafCheckboxes: boolean;
|
|
7
|
+
hideDisabledCheckboxes: boolean;
|
|
8
|
+
readonly?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
11
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
12
|
+
$$bindings?: Bindings;
|
|
13
|
+
} & Exports;
|
|
14
|
+
(internal: unknown, props: Props & {
|
|
15
|
+
$$events?: Events;
|
|
16
|
+
$$slots?: Slots;
|
|
17
|
+
}): Exports & {
|
|
18
|
+
$set?: any;
|
|
19
|
+
$on?: any;
|
|
17
20
|
};
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
export type CheckboxProps = typeof __propDef.props;
|
|
21
|
-
export type CheckboxEvents = typeof __propDef.events;
|
|
22
|
-
export type CheckboxSlots = typeof __propDef.slots;
|
|
23
|
-
export default class Checkbox extends SvelteComponent<CheckboxProps, CheckboxEvents, CheckboxSlots> {
|
|
21
|
+
z_$$bindings?: Bindings;
|
|
24
22
|
}
|
|
25
|
-
|
|
23
|
+
declare const Checkbox: $$__sveltets_2_IsomorphicComponent<Props, {
|
|
24
|
+
select: CustomEvent<any>;
|
|
25
|
+
} & {
|
|
26
|
+
[evt: string]: CustomEvent<any>;
|
|
27
|
+
}, {}, {}, "">;
|
|
28
|
+
type Checkbox = InstanceType<typeof Checkbox>;
|
|
29
|
+
export default Checkbox;
|