@keenmate/svelte-treeview 1.2.12 → 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/README.md +98 -98
- package/dist/Branch.svelte +167 -176
- package/dist/Branch.svelte.d.ts +4 -52
- package/dist/Checkbox.svelte +45 -48
- package/dist/Checkbox.svelte.d.ts +27 -23
- package/dist/TreeView.svelte +101 -202
- package/dist/TreeView.svelte.d.ts +125 -126
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +25 -25
- package/dist/helpers/tree-helper.d.ts +5 -7
- package/dist/helpers/tree-helper.js +44 -40
- package/dist/index.d.ts +6 -6
- package/dist/index.js +6 -6
- package/dist/menu/ContextMenu.svelte +15 -14
- package/dist/menu/ContextMenu.svelte.d.ts +8 -21
- package/dist/menu/Menu.svelte +50 -50
- package/dist/menu/Menu.svelte.d.ts +20 -30
- package/dist/menu/MenuDivider.svelte +10 -10
- package/dist/menu/MenuDivider.svelte.d.ts +22 -19
- package/dist/menu/MenuOption.svelte +45 -49
- package/dist/menu/MenuOption.svelte.d.ts +22 -30
- package/dist/menu/menu.js +3 -3
- package/dist/providers/drag-drop-provider.d.ts +2 -2
- package/dist/providers/drag-drop-provider.js +1 -1
- package/dist/providers/movement-provider.d.ts +2 -2
- package/dist/providers/movement-provider.js +8 -7
- package/dist/providers/selection-provider.d.ts +2 -2
- package/dist/providers/selection-provider.js +15 -13
- package/dist/tree-styles.sass +121 -110
- package/dist/types.d.ts +3 -1
- package/package.json +83 -76
package/dist/Checkbox.svelte
CHANGED
|
@@ -1,53 +1,50 @@
|
|
|
1
|
-
<script>import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export let onlyLeafCheckboxes;
|
|
8
|
-
export let hideDisabledCheckboxes;
|
|
9
|
-
export let readonly = false;
|
|
1
|
+
<script lang="ts">import { createBubbler, preventDefault, stopPropagation } from 'svelte/legacy';
|
|
2
|
+
const bubble = createBubbler();
|
|
3
|
+
import { createEventDispatcher } from "svelte";
|
|
4
|
+
import { SelectionModes, VisualState } from "./types.js";
|
|
5
|
+
import { isSelectable } from "./providers/selection-provider.js";
|
|
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();
|
|
13
|
-
dispatch(
|
|
10
|
+
dispatch("select", { node });
|
|
14
11
|
return false;
|
|
15
12
|
}
|
|
16
|
-
</script>
|
|
17
|
-
|
|
18
|
-
{#if checkboxes == SelectionModes.perNode || checkboxes == SelectionModes.all}
|
|
19
|
-
{#if isSelectable(node, checkboxes)}
|
|
20
|
-
{#if !recursive || (recursive && !node.hasChildren) || !onlyLeafCheckboxes}
|
|
21
|
-
<input
|
|
22
|
-
tabindex="-1"
|
|
23
|
-
type="checkbox"
|
|
24
|
-
class="arrow"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
checked={node.visualState === VisualState.selected}
|
|
28
|
-
indeterminate={node.visualState === VisualState.indeterminate}
|
|
29
|
-
disabled={readonly}
|
|
30
|
-
/>
|
|
31
|
-
{:else}
|
|
32
|
-
<input
|
|
33
|
-
tabindex="-1"
|
|
34
|
-
class="arrow"
|
|
35
|
-
type="checkbox"
|
|
36
|
-
|
|
37
|
-
disabled={true}
|
|
38
|
-
checked={node.visualState === VisualState.selected}
|
|
39
|
-
indeterminate={node.visualState === VisualState.indeterminate}
|
|
40
|
-
class:invisible={hideDisabledCheckboxes}
|
|
41
|
-
/>
|
|
42
|
-
{/if}
|
|
43
|
-
{:else}
|
|
44
|
-
<input
|
|
45
|
-
tabindex="-1"
|
|
46
|
-
class="arrow"
|
|
47
|
-
type="checkbox"
|
|
48
|
-
|
|
49
|
-
disabled={true}
|
|
50
|
-
class:invisible={hideDisabledCheckboxes}
|
|
51
|
-
/>
|
|
52
|
-
{/if}
|
|
53
|
-
{/if}
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
{#if checkboxes == SelectionModes.perNode || checkboxes == SelectionModes.all}
|
|
16
|
+
{#if isSelectable(node, checkboxes)}
|
|
17
|
+
{#if !recursive || (recursive && !node.hasChildren) || !onlyLeafCheckboxes}
|
|
18
|
+
<input
|
|
19
|
+
tabindex="-1"
|
|
20
|
+
type="checkbox"
|
|
21
|
+
class="arrow"
|
|
22
|
+
onclick={(e) => onSelect(e, node)}
|
|
23
|
+
onkeypress={(e) => e.key === 'Enter' && onSelect(e, node)}
|
|
24
|
+
checked={node.visualState === VisualState.selected}
|
|
25
|
+
indeterminate={node.visualState === VisualState.indeterminate}
|
|
26
|
+
disabled={readonly}
|
|
27
|
+
/>
|
|
28
|
+
{:else}
|
|
29
|
+
<input
|
|
30
|
+
tabindex="-1"
|
|
31
|
+
class="arrow"
|
|
32
|
+
type="checkbox"
|
|
33
|
+
onclick={null}
|
|
34
|
+
disabled={true}
|
|
35
|
+
checked={node.visualState === VisualState.selected}
|
|
36
|
+
indeterminate={node.visualState === VisualState.indeterminate}
|
|
37
|
+
class:invisible={hideDisabledCheckboxes}
|
|
38
|
+
/>
|
|
39
|
+
{/if}
|
|
40
|
+
{:else}
|
|
41
|
+
<input
|
|
42
|
+
tabindex="-1"
|
|
43
|
+
class="arrow"
|
|
44
|
+
type="checkbox"
|
|
45
|
+
onclick={stopPropagation(preventDefault(bubble('click')))}
|
|
46
|
+
disabled={true}
|
|
47
|
+
class:invisible={hideDisabledCheckboxes}
|
|
48
|
+
/>
|
|
49
|
+
{/if}
|
|
50
|
+
{/if}
|
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { type Node, SelectionModes } from "./types.js";
|
|
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;
|
package/dist/TreeView.svelte
CHANGED
|
@@ -1,136 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Object properties where information about node is stored
|
|
25
|
-
*/
|
|
26
|
-
export let props = {};
|
|
27
|
-
/**
|
|
28
|
-
* Show vertical lines as visual guide
|
|
29
|
-
*/
|
|
30
|
-
export let verticalLines = false;
|
|
31
|
-
/**
|
|
32
|
-
* Disables drag and drop and selection, expansion is still allowed
|
|
33
|
-
*/
|
|
34
|
-
export let readonly = false;
|
|
35
|
-
/**
|
|
36
|
-
* Separator used to parse paths. It is used for getting node depth and getting parent node.
|
|
37
|
-
* Default is '.'.
|
|
38
|
-
*/
|
|
39
|
-
export let separator = '.';
|
|
40
|
-
/**
|
|
41
|
-
* only leaf nodes can be selected, non-leaf nodes only select/deselect its children.
|
|
42
|
-
* Their visual state is calculated based on their children
|
|
43
|
-
* If you set selected on non-leaf node, it will be ignored and may be deleted
|
|
44
|
-
*/
|
|
45
|
-
export let recursiveSelection = false;
|
|
46
|
-
/**
|
|
47
|
-
* Controls if checkboxes are shown and how they behave. Default is none
|
|
48
|
-
* TODO write about all the different modes
|
|
49
|
-
* TODO find better name
|
|
50
|
-
*/
|
|
51
|
-
export let selectionMode = SelectionModes.none;
|
|
52
|
-
/**
|
|
53
|
-
* By default, in recursive mode, non-leaf checkboxes will select/deselect all its children
|
|
54
|
-
* If you set this to true, this behavior will be disabled and only leaf nodes will be selectable
|
|
55
|
-
*/
|
|
56
|
-
export let onlyLeafCheckboxes = false; //bool
|
|
57
|
-
/**
|
|
58
|
-
* Instead of showing disabled checkboxes, show blank space
|
|
59
|
-
*/
|
|
60
|
-
export let hideDisabledCheckboxes = false; //bool
|
|
61
|
-
/**
|
|
62
|
-
* Function that will be caged when node is expanded and useCallback is set to true
|
|
63
|
-
* It should return array of nodes that will be added to tree
|
|
64
|
-
* If it throws error, node will be collapsed,
|
|
65
|
-
* but user will be able to open it again and callback will be called
|
|
66
|
-
*/
|
|
67
|
-
export let loadChildrenAsync = null;
|
|
68
|
-
/**
|
|
69
|
-
* Show context menu on right click.
|
|
70
|
-
* Its defined in slot context-menu
|
|
71
|
-
*/
|
|
72
|
-
export let showContextMenu = false;
|
|
73
|
-
// TODO stopped working in new version
|
|
74
|
-
/**
|
|
75
|
-
* Automatically expand nodes to this level,
|
|
76
|
-
* any user made expansion will override this.
|
|
77
|
-
*/
|
|
78
|
-
export let expandTo = 0;
|
|
79
|
-
/**
|
|
80
|
-
* Threshold for automatic expansion. If tree has less or equal nodes than this value,
|
|
81
|
-
* all nodes will be expanded. Default is 0, which means no automatic expansion
|
|
82
|
-
*/
|
|
83
|
-
export let expansionThreshold = 0;
|
|
84
|
-
/**
|
|
85
|
-
* Classes used in tree. You can override default classes with this prop.
|
|
86
|
-
* It is recommended to use default classes and add additional styles in your css
|
|
87
|
-
*/
|
|
88
|
-
export let customClasses = {};
|
|
89
|
-
/**
|
|
90
|
-
* Function used to filter what nodes should be shown.
|
|
91
|
-
* Tree automatically adds all parents for nodes.
|
|
92
|
-
* User Higher order functions for reactive search.
|
|
93
|
-
* If you want to only search leaf nodes,
|
|
94
|
-
* its your responsibility to check if its hasChildren property is false
|
|
95
|
-
*/
|
|
96
|
-
export let filter = null;
|
|
97
|
-
/**
|
|
98
|
-
* Log function that will be called when something happens in tree.
|
|
99
|
-
* Used mostly for debugging
|
|
100
|
-
*/
|
|
101
|
-
export let logger = null;
|
|
102
|
-
/*
|
|
103
|
-
* Drag and drop mode allows all nodes, that don't have dragDisabled property set to true
|
|
104
|
-
* to be dragged and dropped. By default you can only insert at same level node you are dropping on,
|
|
105
|
-
* but you can allow nesting by setting nestAllowed to true on node. If you want to disable insertion,
|
|
106
|
-
* set dropDisabled to true on node. if both is disabled, you wont be able to drop on node.
|
|
107
|
-
*/
|
|
108
|
-
export let dragAndDrop = false; //bool
|
|
109
|
-
/**
|
|
110
|
-
* Callback that will be called when user drags above node.
|
|
111
|
-
* It should return true, if drop is disabled on that node.
|
|
112
|
-
*/
|
|
113
|
-
export let dropDisabledCallback = null;
|
|
114
|
-
/**
|
|
115
|
-
* If true, keyboard navigation will be enabled. Use arrow keys to navigate and space to select node.
|
|
116
|
-
*/
|
|
117
|
-
export let allowKeyboardNavigation = false;
|
|
118
|
-
let ctxMenu;
|
|
119
|
-
let expandedPaths = [];
|
|
120
|
-
let draggedNode = null;
|
|
121
|
-
let highlightedNode = null;
|
|
122
|
-
let insertionType = InsertionType.none;
|
|
123
|
-
let focusedNode = null;
|
|
124
|
-
$: computedClasses = { ...defaultClasses, ...(customClasses ?? {}) };
|
|
125
|
-
$: dragAndDrop && console.warn('Drag and drop is not supported in this version');
|
|
126
|
-
$: helper = new TreeHelper({
|
|
127
|
-
separator
|
|
128
|
-
});
|
|
129
|
-
$: dragAndDropProvider = new DragDropProvider(helper);
|
|
130
|
-
$: selectionProvider = new SelectionProvider(helper, recursiveSelection);
|
|
131
|
-
$: computedTree = computeTree(helper, selectionProvider, tree, filter, props, expandedPaths, value);
|
|
1
|
+
<!-- @migration-task Error while migrating Svelte code: migrating this component would require adding a `$props` rune but there's already a variable named props.
|
|
2
|
+
Rename the variable and try again or migrate by hand. -->
|
|
3
|
+
<!-- @migration-task Error while migrating Svelte code: This migration would change the name of a slot (context-menu to context_menu) making the component unusable -->
|
|
4
|
+
<!-- @migration-task Error while migrating Svelte code: This migration would change the name of a slot (nest-highlight to nest_highlight) making the component unusable -->
|
|
5
|
+
<!-- @migration-task Error while migrating Svelte code: This migration would change the name of a slot (nest-highlight to nest_highlight) making the component unusable -->
|
|
6
|
+
<!-- @migration-task Error while migrating Svelte code: This migration would change the name of a slot (nest-highlight to nest_highlight) making the component unusable -->
|
|
7
|
+
<script lang="ts">import ContextMenu from "./menu/ContextMenu.svelte";
|
|
8
|
+
import { defaultClasses, defaultPropNames } from "./constants.js";
|
|
9
|
+
import { InsertionType, SelectionModes as SelectionModes } from "./types.js";
|
|
10
|
+
import { TreeHelper } from "./index.js";
|
|
11
|
+
import Branch from "./Branch.svelte";
|
|
12
|
+
import { SelectionProvider } from "./providers/selection-provider.js";
|
|
13
|
+
import { DragDropProvider } from "./providers/drag-drop-provider.js";
|
|
14
|
+
import uniq from "lodash.uniq";
|
|
15
|
+
import { calculateNewFocusedNode, parseMovementDirection } from "./providers/movement-provider.js";
|
|
16
|
+
let { treeId, tree, value = [], treeProps = {}, verticalLines = false, readonly = false, separator = ".", recursiveSelection = false, selectionMode = SelectionModes.none, onlyLeafCheckboxes = false, hideDisabledCheckboxes = false, loadChildrenAsync = null, showContextMenu = false, expandTo = 0, expansionThreshold = 0, customClasses = {}, filter = null, logger = null, nodeSorter = null, dragAndDrop = false, dropDisabledCallback = null, allowKeyboardNavigation = false, onFocus = undefined, onFocusLeave = undefined, onExpansion = undefined, onExpanded = undefined, onClosed = undefined, onChange = undefined, onSelection = undefined, onSelected = undefined, onUnselected = undefined, onMoved = undefined, children, nestHighlight, contextMenu } = $props();
|
|
17
|
+
let ctxMenu = $state();
|
|
18
|
+
let expandedPaths = $state([]);
|
|
19
|
+
let draggedNode = $state(null);
|
|
20
|
+
let highlightedNode = $state(null);
|
|
21
|
+
let insertionType = $state(InsertionType.none);
|
|
22
|
+
let focusedNode = $state(null);
|
|
132
23
|
export function changeAllExpansion(changeTo) {
|
|
133
|
-
debugLog(
|
|
24
|
+
debugLog("changing expansion of every node to ", changeTo ? "expanded" : "collapsed");
|
|
134
25
|
if (changeTo) {
|
|
135
26
|
expandedPaths = computedTree.map((node) => node.path);
|
|
136
27
|
}
|
|
@@ -140,11 +31,11 @@ export function changeAllExpansion(changeTo) {
|
|
|
140
31
|
}
|
|
141
32
|
export function expandToNode(targetNodePath) {
|
|
142
33
|
if (!targetNodePath) {
|
|
143
|
-
console.warn(
|
|
34
|
+
console.warn("Cannot expand to node with null path");
|
|
144
35
|
return;
|
|
145
36
|
}
|
|
146
37
|
const parentPaths = helper.getParentsPaths(targetNodePath);
|
|
147
|
-
debugLog("expanding to node '" + targetNodePath + "'" +
|
|
38
|
+
debugLog("expanding to node '" + targetNodePath + "'" + " parents", parentPaths);
|
|
148
39
|
expandedPaths = uniq([...expandedPaths, ...parentPaths]);
|
|
149
40
|
}
|
|
150
41
|
/**
|
|
@@ -153,7 +44,7 @@ export function expandToNode(targetNodePath) {
|
|
|
153
44
|
*/
|
|
154
45
|
export function setNodeExpansion(nodePath, changeTo) {
|
|
155
46
|
if (!nodePath) {
|
|
156
|
-
console.warn(
|
|
47
|
+
console.warn("Cannot expand node with null path");
|
|
157
48
|
return;
|
|
158
49
|
}
|
|
159
50
|
if (changeTo === null) {
|
|
@@ -163,7 +54,7 @@ export function setNodeExpansion(nodePath, changeTo) {
|
|
|
163
54
|
}
|
|
164
55
|
export function setExpansions(expansions) {
|
|
165
56
|
if (!Array.isArray(expansions)) {
|
|
166
|
-
console.error(
|
|
57
|
+
console.error("expansions must be an array");
|
|
167
58
|
return;
|
|
168
59
|
}
|
|
169
60
|
expandedPaths = expansions;
|
|
@@ -183,12 +74,23 @@ export function focusFirstNode() {
|
|
|
183
74
|
return null;
|
|
184
75
|
}
|
|
185
76
|
focusedNode = rootChildren[0];
|
|
186
|
-
|
|
77
|
+
onFocus?.(focusedNode);
|
|
187
78
|
return focusedNode;
|
|
188
79
|
}
|
|
80
|
+
let computedClasses = $derived({ ...defaultClasses, ...(customClasses ?? {}) });
|
|
81
|
+
$effect(() => {
|
|
82
|
+
dragAndDrop && console.warn("Drag and drop is not supported in this version");
|
|
83
|
+
});
|
|
84
|
+
let helper = $derived(new TreeHelper({
|
|
85
|
+
separator,
|
|
86
|
+
nodeSorter
|
|
87
|
+
}));
|
|
88
|
+
let dragAndDropProvider = $derived(new DragDropProvider(helper));
|
|
89
|
+
let selectionProvider = $derived(new SelectionProvider(helper, recursiveSelection));
|
|
90
|
+
let computedTree = $derived(computeTree(helper, selectionProvider, tree, filter, treeProps, expandedPaths, value));
|
|
189
91
|
function computeTree(helper, selectionProvider, userProvidedTree, filter, props, expandedPaths, value) {
|
|
190
92
|
if (!Array.isArray(userProvidedTree) || !Array.isArray(value)) {
|
|
191
|
-
console.error(
|
|
93
|
+
console.error("value and tree must be arrays!!");
|
|
192
94
|
return [];
|
|
193
95
|
}
|
|
194
96
|
const start = Date.now();
|
|
@@ -215,15 +117,15 @@ function onExpand(detail) {
|
|
|
215
117
|
handleCallback(node);
|
|
216
118
|
}
|
|
217
119
|
//expansion events
|
|
218
|
-
|
|
120
|
+
onExpansion?.({
|
|
219
121
|
node: node,
|
|
220
122
|
value: changeTo
|
|
221
123
|
});
|
|
222
124
|
if (changeTo) {
|
|
223
|
-
|
|
125
|
+
onExpanded?.(node);
|
|
224
126
|
}
|
|
225
127
|
else {
|
|
226
|
-
|
|
128
|
+
onClosed?.(node);
|
|
227
129
|
}
|
|
228
130
|
}
|
|
229
131
|
function handleCallback(node) {
|
|
@@ -235,10 +137,10 @@ function handleCallback(node) {
|
|
|
235
137
|
return;
|
|
236
138
|
}
|
|
237
139
|
if (loadChildrenAsync == null) {
|
|
238
|
-
console.warn(
|
|
140
|
+
console.warn("loadChildrenAsync is not set, but useCallback is set to true on node with path", node.path);
|
|
239
141
|
return;
|
|
240
142
|
}
|
|
241
|
-
debugLog(
|
|
143
|
+
debugLog("calling callback for node", node);
|
|
242
144
|
// TODO mark node as loaded and don't call callback again
|
|
243
145
|
// this is now responsibility of user
|
|
244
146
|
loadChildrenAsync(node);
|
|
@@ -248,23 +150,24 @@ function onSelectionChanged(detail) {
|
|
|
248
150
|
const nodePath = node.path;
|
|
249
151
|
const changeTo = !selectionProvider.isNodeSelected(node);
|
|
250
152
|
const newValue = selectionProvider.setSelection(computedTree, nodePath, changeTo, value);
|
|
251
|
-
debugLog("changing selection of node '", nodePath, "' to ", changeTo,
|
|
252
|
-
|
|
253
|
-
|
|
153
|
+
debugLog("changing selection of node '", nodePath, "' to ", changeTo, " returning value ", newValue);
|
|
154
|
+
onChange?.(newValue);
|
|
155
|
+
onSelection?.({
|
|
254
156
|
node: node,
|
|
255
157
|
value: changeTo
|
|
256
158
|
});
|
|
257
159
|
if (changeTo) {
|
|
258
|
-
|
|
160
|
+
onSelected?.({ node, value: newValue });
|
|
259
161
|
}
|
|
260
162
|
else {
|
|
261
|
-
|
|
163
|
+
onUnselected?.({ node, value: newValue });
|
|
262
164
|
}
|
|
263
165
|
}
|
|
264
166
|
function openContextMenu(ce) {
|
|
265
167
|
const { e, node } = ce.detail;
|
|
266
|
-
if (!showContextMenu)
|
|
168
|
+
if (!showContextMenu) {
|
|
267
169
|
return;
|
|
170
|
+
}
|
|
268
171
|
e.preventDefault();
|
|
269
172
|
ctxMenu.onRightClick(e, node);
|
|
270
173
|
}
|
|
@@ -288,8 +191,8 @@ function onDragDrop({ detail: { node, event, element } }) {
|
|
|
288
191
|
return;
|
|
289
192
|
}
|
|
290
193
|
highlightedNode = null;
|
|
291
|
-
debugLog(
|
|
292
|
-
|
|
194
|
+
debugLog("DROPPED: ", draggedNode, "on", node);
|
|
195
|
+
onMoved?.({
|
|
293
196
|
node: draggedNode,
|
|
294
197
|
target: node,
|
|
295
198
|
insertType: insertionType
|
|
@@ -305,7 +208,7 @@ function onDragEnter({ detail: { node, event, element } }) {
|
|
|
305
208
|
if (!dragAndDropProvider.isDropAllowed(draggedNode, node)) {
|
|
306
209
|
return;
|
|
307
210
|
}
|
|
308
|
-
if (typeof dropDisabledCallback ===
|
|
211
|
+
if (typeof dropDisabledCallback === "function") {
|
|
309
212
|
// possible bug, if the promise is resolved, when user is over another node
|
|
310
213
|
dropDisabledCallback(draggedNode, node).then((dropDisabled) => {
|
|
311
214
|
if (!dropDisabled) {
|
|
@@ -343,19 +246,19 @@ function onKeyPress(detail) {
|
|
|
343
246
|
if (setExpansion !== null) {
|
|
344
247
|
onExpand({ node: node, changeTo: setExpansion });
|
|
345
248
|
}
|
|
346
|
-
|
|
249
|
+
onFocus?.(node);
|
|
347
250
|
return;
|
|
348
251
|
}
|
|
349
|
-
if (event.key ===
|
|
252
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
350
253
|
onSelectionChanged({ node: targetNode });
|
|
351
254
|
return;
|
|
352
255
|
}
|
|
353
|
-
if (event.key ===
|
|
256
|
+
if (event.key === "Escape") {
|
|
354
257
|
focusedNode = null;
|
|
355
258
|
if (document.activeElement instanceof HTMLElement) {
|
|
356
259
|
document.activeElement.blur();
|
|
357
260
|
}
|
|
358
|
-
|
|
261
|
+
onFocusLeave?.();
|
|
359
262
|
return;
|
|
360
263
|
}
|
|
361
264
|
}
|
|
@@ -364,51 +267,47 @@ function debugLog(...data) {
|
|
|
364
267
|
logger(...data);
|
|
365
268
|
}
|
|
366
269
|
}
|
|
367
|
-
</script>
|
|
368
|
-
|
|
369
|
-
<Branch
|
|
370
|
-
branchRootNode={null}
|
|
371
|
-
{treeId}
|
|
372
|
-
checkboxes={selectionMode}
|
|
373
|
-
tree={computedTree}
|
|
374
|
-
recursive={recursiveSelection}
|
|
375
|
-
{onlyLeafCheckboxes}
|
|
376
|
-
{hideDisabledCheckboxes}
|
|
377
|
-
{expandTo}
|
|
378
|
-
{dragAndDrop}
|
|
379
|
-
{readonly}
|
|
380
|
-
{helper}
|
|
381
|
-
classes={computedClasses}
|
|
382
|
-
{verticalLines}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
{
|
|
386
|
-
{
|
|
387
|
-
{
|
|
388
|
-
{
|
|
389
|
-
{
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
<slot name="context-menu" {node} />
|
|
409
|
-
</svelte:fragment>
|
|
410
|
-
</ContextMenu>
|
|
411
|
-
|
|
270
|
+
</script>
|
|
271
|
+
|
|
272
|
+
<Branch
|
|
273
|
+
branchRootNode={null}
|
|
274
|
+
{treeId}
|
|
275
|
+
checkboxes={selectionMode}
|
|
276
|
+
tree={computedTree}
|
|
277
|
+
recursive={recursiveSelection}
|
|
278
|
+
{onlyLeafCheckboxes}
|
|
279
|
+
{hideDisabledCheckboxes}
|
|
280
|
+
{expandTo}
|
|
281
|
+
{dragAndDrop}
|
|
282
|
+
{readonly}
|
|
283
|
+
{helper}
|
|
284
|
+
classes={computedClasses}
|
|
285
|
+
{verticalLines}
|
|
286
|
+
childDepth={0}
|
|
287
|
+
{insertionType}
|
|
288
|
+
{highlightedNode}
|
|
289
|
+
{draggedNode}
|
|
290
|
+
{focusedNode}
|
|
291
|
+
{allowKeyboardNavigation}
|
|
292
|
+
{children}
|
|
293
|
+
{nestHighlight}
|
|
294
|
+
internal_onHandleDragStart={onDragStart}
|
|
295
|
+
internal_onHandleDragDrop={onDragDrop}
|
|
296
|
+
internal_onHandleDragOver={onDragOver}
|
|
297
|
+
internal_onHandleDragEnter={onDragEnter}
|
|
298
|
+
internal_onHandleDragEnd={onDragEnd}
|
|
299
|
+
internal_onHandleDragLeave={onDragLeave}
|
|
300
|
+
internal_onKeypress={(e) => onKeyPress(e.detail)}
|
|
301
|
+
internal_onExpand={(e) => onExpand(e.detail)}
|
|
302
|
+
internal_onSelectionChanged={(e) => onSelectionChanged(e.detail)}
|
|
303
|
+
onOpenCtxmenu={openContextMenu}
|
|
304
|
+
/>
|
|
305
|
+
<ContextMenu bind:this={ctxMenu}>
|
|
306
|
+
{#snippet children({node})}
|
|
307
|
+
{@render contextMenu?.({node})}
|
|
308
|
+
{/snippet}
|
|
309
|
+
</ContextMenu>
|
|
310
|
+
|
|
412
311
|
<style global>:global(.treeview) {
|
|
413
312
|
padding: 0;
|
|
414
313
|
}
|
|
@@ -524,4 +423,4 @@ function debugLog(...data) {
|
|
|
524
423
|
text-align: center;
|
|
525
424
|
width: 1.25em;
|
|
526
425
|
min-width: 1.25em;
|
|
527
|
-
}</style>
|
|
426
|
+
}</style>
|