@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/menu/Menu.svelte
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
<!-- component from https://svelte.dev/repl/3a33725c3adb4f57b46b597f9dade0c1?version=3.25.0 -->
|
|
2
|
-
|
|
3
|
-
<script>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
</script>
|
|
34
|
-
|
|
35
|
-
<svelte:body
|
|
36
|
-
|
|
37
|
-
<div transition:fade={{ duration: 100 }} bind:this={menuEl} style="top: {y}px; left: {x}px;">
|
|
38
|
-
|
|
39
|
-
</div>
|
|
40
|
-
|
|
41
|
-
<style>
|
|
42
|
-
div {
|
|
43
|
-
position: fixed;
|
|
44
|
-
display: grid;
|
|
45
|
-
border: 1px solid #0003;
|
|
46
|
-
box-shadow: 2px 2px 5px 0px #0002;
|
|
47
|
-
background: white;
|
|
48
|
-
z-index: 999;
|
|
49
|
-
}
|
|
50
|
-
</style>
|
|
1
|
+
<!-- component from https://svelte.dev/repl/3a33725c3adb4f57b46b597f9dade0c1?version=3.25.0 -->
|
|
2
|
+
|
|
3
|
+
<script lang="ts">import { run } from 'svelte/legacy';
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
import { createEventDispatcher, setContext } from "svelte";
|
|
6
|
+
import { fade } from "svelte/transition";
|
|
7
|
+
import { key } from "./menu.js";
|
|
8
|
+
let { x = $bindable(), y = $bindable(), children } = $props();
|
|
9
|
+
const dispatch = createEventDispatcher();
|
|
10
|
+
setContext(key, {
|
|
11
|
+
dispatchClick: () => dispatch("click")
|
|
12
|
+
});
|
|
13
|
+
let menuEl = $state();
|
|
14
|
+
function onPageClick(e) {
|
|
15
|
+
if (e.target === menuEl || menuEl.contains(e.target)) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
dispatch("clickoutside");
|
|
19
|
+
}
|
|
20
|
+
// whenever x and y is changed, restrict box to be within bounds
|
|
21
|
+
run(() => {
|
|
22
|
+
(() => {
|
|
23
|
+
if (!menuEl) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const rect = menuEl.getBoundingClientRect();
|
|
27
|
+
x = Math.min(window.innerWidth - rect.width, x);
|
|
28
|
+
if (y > window.innerHeight - rect.height) {
|
|
29
|
+
y -= rect.height;
|
|
30
|
+
}
|
|
31
|
+
})(x, y);
|
|
32
|
+
});
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<svelte:body onclick={onPageClick} />
|
|
36
|
+
|
|
37
|
+
<div transition:fade={{ duration: 100 }} bind:this={menuEl} style="top: {y}px; left: {x}px;">
|
|
38
|
+
{@render children?.()}
|
|
39
|
+
</div>
|
|
40
|
+
|
|
41
|
+
<style>
|
|
42
|
+
div {
|
|
43
|
+
position: fixed;
|
|
44
|
+
display: grid;
|
|
45
|
+
border: 1px solid #0003;
|
|
46
|
+
box-shadow: 2px 2px 5px 0px #0002;
|
|
47
|
+
background: white;
|
|
48
|
+
z-index: 999;
|
|
49
|
+
}
|
|
50
|
+
</style>
|
|
@@ -1,35 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
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> {
|
|
2
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
3
|
+
$$bindings?: Bindings;
|
|
4
|
+
} & Exports;
|
|
5
|
+
(internal: unknown, props: Props & {
|
|
6
|
+
$$events?: Events;
|
|
7
|
+
$$slots?: Slots;
|
|
8
|
+
}): Exports & {
|
|
9
|
+
$set?: any;
|
|
10
|
+
$on?: any;
|
|
11
|
+
};
|
|
12
|
+
z_$$bindings?: Bindings;
|
|
13
|
+
}
|
|
14
|
+
declare const Menu: $$__sveltets_2_IsomorphicComponent<{
|
|
15
|
+
x?: any;
|
|
16
|
+
y?: any;
|
|
17
|
+
children: any;
|
|
7
18
|
}, {
|
|
8
19
|
click: CustomEvent<any>;
|
|
9
20
|
clickoutside: CustomEvent<any>;
|
|
10
21
|
} & {
|
|
11
22
|
[evt: string]: CustomEvent<any>;
|
|
12
|
-
}, {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
export type MenuProps = typeof __propDef.props;
|
|
17
|
-
export type MenuEvents = typeof __propDef.events;
|
|
18
|
-
export type MenuSlots = typeof __propDef.slots;
|
|
19
|
-
import { SvelteComponent } from "svelte";
|
|
20
|
-
declare const __propDef: {
|
|
21
|
-
props: {
|
|
22
|
-
x: any;
|
|
23
|
-
y: any;
|
|
24
|
-
};
|
|
25
|
-
events: {
|
|
26
|
-
click: CustomEvent<any>;
|
|
27
|
-
clickoutside: CustomEvent<any>;
|
|
28
|
-
} & {
|
|
29
|
-
[evt: string]: CustomEvent<any>;
|
|
30
|
-
};
|
|
31
|
-
slots: {
|
|
32
|
-
default: {};
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
export {};
|
|
23
|
+
}, {}, {}, "x" | "y">;
|
|
24
|
+
type Menu = InstanceType<typeof Menu>;
|
|
25
|
+
export default Menu;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
<style>
|
|
2
|
-
hr {
|
|
3
|
-
border-top: 1px solid #0003;
|
|
4
|
-
width: 100%;
|
|
5
|
-
margin: 2px 0;
|
|
6
|
-
}
|
|
7
|
-
</style>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
<hr />
|
|
1
|
+
<style>
|
|
2
|
+
hr {
|
|
3
|
+
border-top: 1px solid #0003;
|
|
4
|
+
width: 100%;
|
|
5
|
+
margin: 2px 0;
|
|
6
|
+
}
|
|
7
|
+
</style>
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
<hr />
|
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/** @typedef {typeof __propDef.slots} MenuDividerSlots */
|
|
4
|
-
export default class MenuDivider extends SvelteComponent<{
|
|
1
|
+
export default MenuDivider;
|
|
2
|
+
type MenuDivider = SvelteComponent<{
|
|
5
3
|
[x: string]: never;
|
|
6
4
|
}, {
|
|
7
5
|
[evt: string]: CustomEvent<any>;
|
|
8
|
-
}, {}> {
|
|
9
|
-
|
|
10
|
-
export type MenuDividerProps = typeof __propDef.props;
|
|
11
|
-
export type MenuDividerEvents = typeof __propDef.events;
|
|
12
|
-
export type MenuDividerSlots = typeof __propDef.slots;
|
|
13
|
-
import { SvelteComponent } from "svelte";
|
|
14
|
-
declare const __propDef: {
|
|
15
|
-
props: {
|
|
16
|
-
[x: string]: never;
|
|
17
|
-
};
|
|
18
|
-
events: {
|
|
19
|
-
[evt: string]: CustomEvent<any>;
|
|
20
|
-
};
|
|
21
|
-
slots: {};
|
|
6
|
+
}, {}> & {
|
|
7
|
+
$$bindings?: string | undefined;
|
|
22
8
|
};
|
|
23
|
-
|
|
9
|
+
declare const MenuDivider: $$__sveltets_2_IsomorphicComponent<{
|
|
10
|
+
[x: string]: never;
|
|
11
|
+
}, {
|
|
12
|
+
[evt: string]: CustomEvent<any>;
|
|
13
|
+
}, {}, {}, string>;
|
|
14
|
+
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> {
|
|
15
|
+
new (options: import("svelte").ComponentConstructorOptions<Props>): import("svelte").SvelteComponent<Props, Events, Slots> & {
|
|
16
|
+
$$bindings?: Bindings;
|
|
17
|
+
} & Exports;
|
|
18
|
+
(internal: unknown, props: {
|
|
19
|
+
$$events?: Events;
|
|
20
|
+
$$slots?: Slots;
|
|
21
|
+
}): Exports & {
|
|
22
|
+
$set?: any;
|
|
23
|
+
$on?: any;
|
|
24
|
+
};
|
|
25
|
+
z_$$bindings?: Bindings;
|
|
26
|
+
}
|
|
@@ -1,49 +1,45 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
div.disabled:hover {
|
|
47
|
-
background: white;
|
|
48
|
-
}
|
|
49
|
-
</style>
|
|
1
|
+
<script lang="ts">// @ts-nocheck
|
|
2
|
+
import { createEventDispatcher, getContext } from "svelte";
|
|
3
|
+
import { key } from "./menu.js";
|
|
4
|
+
let { isDisabled = false, text = "", children } = $props();
|
|
5
|
+
const dispatch = createEventDispatcher();
|
|
6
|
+
const { dispatchClick } = getContext(key);
|
|
7
|
+
const handleClick = (e) => {
|
|
8
|
+
if (isDisabled) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
dispatch("click");
|
|
12
|
+
dispatchClick();
|
|
13
|
+
};
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<div class:disabled={isDisabled} onclick={handleClick} onkeydown={handleClick} role="button" tabindex="">
|
|
17
|
+
{#if text}
|
|
18
|
+
{text}
|
|
19
|
+
{:else}
|
|
20
|
+
{@render children?.()}
|
|
21
|
+
{/if}
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
<style>
|
|
25
|
+
div {
|
|
26
|
+
padding: 4px 15px;
|
|
27
|
+
cursor: default;
|
|
28
|
+
font-size: 14px;
|
|
29
|
+
display: flex;
|
|
30
|
+
align-items: center;
|
|
31
|
+
grid-gap: 5px;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
div:hover {
|
|
35
|
+
background: #0002;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
div.disabled {
|
|
39
|
+
color: #0006;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
div.disabled:hover {
|
|
43
|
+
background: white;
|
|
44
|
+
}
|
|
45
|
+
</style>
|
|
@@ -1,33 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
interface Props {
|
|
2
|
+
isDisabled?: boolean;
|
|
3
|
+
text?: string;
|
|
4
|
+
children?: import('svelte').Snippet;
|
|
5
|
+
}
|
|
6
|
+
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> {
|
|
7
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
8
|
+
$$bindings?: Bindings;
|
|
9
|
+
} & Exports;
|
|
10
|
+
(internal: unknown, props: Props & {
|
|
11
|
+
$$events?: Events;
|
|
12
|
+
$$slots?: Slots;
|
|
13
|
+
}): Exports & {
|
|
14
|
+
$set?: any;
|
|
15
|
+
$on?: any;
|
|
16
|
+
};
|
|
17
|
+
z_$$bindings?: Bindings;
|
|
18
|
+
}
|
|
19
|
+
declare const MenuOption: $$__sveltets_2_IsomorphicComponent<Props, {
|
|
8
20
|
click: CustomEvent<any>;
|
|
9
21
|
} & {
|
|
10
22
|
[evt: string]: CustomEvent<any>;
|
|
11
|
-
}, {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
export type MenuOptionProps = typeof __propDef.props;
|
|
16
|
-
export type MenuOptionEvents = typeof __propDef.events;
|
|
17
|
-
export type MenuOptionSlots = typeof __propDef.slots;
|
|
18
|
-
import { SvelteComponent } from "svelte";
|
|
19
|
-
declare const __propDef: {
|
|
20
|
-
props: {
|
|
21
|
-
isDisabled?: boolean | undefined;
|
|
22
|
-
text?: string | undefined;
|
|
23
|
-
};
|
|
24
|
-
events: {
|
|
25
|
-
click: CustomEvent<any>;
|
|
26
|
-
} & {
|
|
27
|
-
[evt: string]: CustomEvent<any>;
|
|
28
|
-
};
|
|
29
|
-
slots: {
|
|
30
|
-
default: {};
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
export {};
|
|
23
|
+
}, {}, {}, "">;
|
|
24
|
+
type MenuOption = InstanceType<typeof MenuOption>;
|
|
25
|
+
export default MenuOption;
|
package/dist/menu/menu.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const key = {}
|
|
2
|
-
|
|
3
|
-
export {
|
|
1
|
+
const key = {}
|
|
2
|
+
|
|
3
|
+
export {key}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { TreeHelper } from
|
|
2
|
-
import { type Node
|
|
1
|
+
import type { TreeHelper } from "../helpers/tree-helper.js";
|
|
2
|
+
import { InsertionType, type Node } from "../types.js";
|
|
3
3
|
export declare class DragDropProvider {
|
|
4
4
|
helper: TreeHelper;
|
|
5
5
|
constructor(treeHelper: TreeHelper);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { TreeHelper } from
|
|
2
|
-
import { KeyboardMovement as MovementDirection, type Node } from
|
|
1
|
+
import type { TreeHelper } from "../helpers/tree-helper.js";
|
|
2
|
+
import { KeyboardMovement as MovementDirection, type Node } from "../types.js";
|
|
3
3
|
export declare function calculateNewFocusedNode(helper: TreeHelper, tree: Node[], targetNode: Node, movementDirection: MovementDirection): {
|
|
4
4
|
node: Node;
|
|
5
5
|
setExpansion: boolean | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { KeyboardMovement as MovementDirection } from
|
|
1
|
+
import { KeyboardMovement as MovementDirection } from "../types.js";
|
|
2
2
|
export function calculateNewFocusedNode(helper, tree, targetNode, movementDirection) {
|
|
3
3
|
// TODO this could use some refactoring
|
|
4
4
|
const parentNodePath = helper.getParentNodePath(targetNode.path);
|
|
@@ -66,7 +66,7 @@ export function calculateNewFocusedNode(helper, tree, targetNode, movementDirect
|
|
|
66
66
|
const parentNode = helper.findNode(tree, parentNodePath);
|
|
67
67
|
// assertion
|
|
68
68
|
if (!parentNode) {
|
|
69
|
-
console.warn(
|
|
69
|
+
console.warn("Parent node not found, this should never happen");
|
|
70
70
|
return wrapReturn(targetNode);
|
|
71
71
|
}
|
|
72
72
|
return wrapReturn(parentNode);
|
|
@@ -75,13 +75,13 @@ export function calculateNewFocusedNode(helper, tree, targetNode, movementDirect
|
|
|
75
75
|
}
|
|
76
76
|
export function parseMovementDirection(key) {
|
|
77
77
|
switch (key) {
|
|
78
|
-
case
|
|
78
|
+
case "ArrowRight":
|
|
79
79
|
return MovementDirection.Right;
|
|
80
|
-
case
|
|
80
|
+
case "ArrowLeft":
|
|
81
81
|
return MovementDirection.Left;
|
|
82
|
-
case
|
|
82
|
+
case "ArrowDown":
|
|
83
83
|
return MovementDirection.Down;
|
|
84
|
-
case
|
|
84
|
+
case "ArrowUp":
|
|
85
85
|
return MovementDirection.Up;
|
|
86
86
|
default:
|
|
87
87
|
return null;
|
|
@@ -95,7 +95,8 @@ function getRelativeSibling(helper, tree, node, relativeIndex) {
|
|
|
95
95
|
const parentDirectChildren = helper.getDirectChildren(tree, parentNodePath);
|
|
96
96
|
const nodeIndex = parentDirectChildren.findIndex((x) => x.path === node.path);
|
|
97
97
|
const siblingIndex = nodeIndex + relativeIndex;
|
|
98
|
-
if (siblingIndex < 0 || siblingIndex >= parentDirectChildren.length)
|
|
98
|
+
if (siblingIndex < 0 || siblingIndex >= parentDirectChildren.length) {
|
|
99
99
|
return null;
|
|
100
|
+
}
|
|
100
101
|
return parentDirectChildren[siblingIndex];
|
|
101
102
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { TreeHelper } from
|
|
2
|
-
import {
|
|
1
|
+
import type { TreeHelper } from "../helpers/tree-helper.js";
|
|
2
|
+
import { type Node, type NodeId, SelectionModes, type Tree, type TreeVisualStates } from "../types.js";
|
|
3
3
|
export declare class SelectionProvider {
|
|
4
4
|
helper: TreeHelper;
|
|
5
5
|
recursiveMode: boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SelectionModes, VisualState } from
|
|
1
|
+
import { SelectionModes, VisualState } from "../types.js";
|
|
2
2
|
export class SelectionProvider {
|
|
3
3
|
helper;
|
|
4
4
|
recursiveMode;
|
|
@@ -9,13 +9,13 @@ export class SelectionProvider {
|
|
|
9
9
|
markSelected(tree, selectedNodeIds) {
|
|
10
10
|
const visualStates = this.computeVisualStates(tree, selectedNodeIds);
|
|
11
11
|
tree.forEach((node) => {
|
|
12
|
-
if (selectedNodeIds.includes(node.id ??
|
|
12
|
+
if (selectedNodeIds.includes(node.id ?? "")) {
|
|
13
13
|
node.selected = true;
|
|
14
14
|
node.visualState = VisualState.selected;
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
17
|
node.selected = false;
|
|
18
|
-
const visualState = visualStates[node.id ??
|
|
18
|
+
const visualState = visualStates[node.id ?? ""];
|
|
19
19
|
if (!visualState) {
|
|
20
20
|
node.visualState = VisualState.notSelected;
|
|
21
21
|
}
|
|
@@ -27,8 +27,9 @@ export class SelectionProvider {
|
|
|
27
27
|
}
|
|
28
28
|
isSelected(nodeId, visualStates, selectedNodeIds) {
|
|
29
29
|
const selected = selectedNodeIds.includes(nodeId);
|
|
30
|
-
if (selected)
|
|
30
|
+
if (selected) {
|
|
31
31
|
return true;
|
|
32
|
+
}
|
|
32
33
|
const visualState = visualStates[nodeId];
|
|
33
34
|
return visualState === VisualState.selected;
|
|
34
35
|
}
|
|
@@ -47,10 +48,10 @@ export class SelectionProvider {
|
|
|
47
48
|
else {
|
|
48
49
|
if (!node) {
|
|
49
50
|
// throw new Error('Node not found ' + nodePath);
|
|
50
|
-
console.warn(
|
|
51
|
+
console.warn("Node %s doesnt exits", nodePath);
|
|
51
52
|
return oldSelection;
|
|
52
53
|
}
|
|
53
|
-
const nodeId = node.id ??
|
|
54
|
+
const nodeId = node.id ?? "";
|
|
54
55
|
// prevent double selection
|
|
55
56
|
const filteredSelection = oldSelection.filter((x) => x !== nodeId);
|
|
56
57
|
if (changeTo === false) {
|
|
@@ -68,14 +69,15 @@ export class SelectionProvider {
|
|
|
68
69
|
rootELements.forEach((node) => {
|
|
69
70
|
if (node.hasChildren == true) {
|
|
70
71
|
const result = this.computeVisualStateRecursively(tree, node, selectedNodeIds, visualStates);
|
|
71
|
-
visualStates[node.id ??
|
|
72
|
+
visualStates[node.id ?? ""] = result.state;
|
|
72
73
|
}
|
|
73
74
|
});
|
|
74
75
|
return visualStates;
|
|
75
76
|
}
|
|
76
77
|
computeVisualState(directChildrenVisualStates) {
|
|
77
|
-
if (!directChildrenVisualStates || directChildrenVisualStates?.length == 0)
|
|
78
|
+
if (!directChildrenVisualStates || directChildrenVisualStates?.length == 0) {
|
|
78
79
|
return VisualState.selected;
|
|
80
|
+
}
|
|
79
81
|
//if every child is selected or vs=true return true
|
|
80
82
|
if (directChildrenVisualStates.every((state) => state === VisualState.selected)) {
|
|
81
83
|
return VisualState.selected;
|
|
@@ -101,14 +103,14 @@ export class SelectionProvider {
|
|
|
101
103
|
// using recustion compute from leaft nodes to root
|
|
102
104
|
directChildren.forEach((child) => {
|
|
103
105
|
if (!child.hasChildren) {
|
|
104
|
-
const childState = selectedNodeIds.includes(child.id ??
|
|
106
|
+
const childState = selectedNodeIds.includes(child.id ?? "")
|
|
105
107
|
? VisualState.selected
|
|
106
108
|
: VisualState.notSelected;
|
|
107
109
|
directChildrenStates.push(childState);
|
|
108
110
|
return;
|
|
109
111
|
}
|
|
110
112
|
const result = this.computeVisualStateRecursively(tree, child, selectedNodeIds, visualStates);
|
|
111
|
-
visualStates[child.id ??
|
|
113
|
+
visualStates[child.id ?? ""] = result.state;
|
|
112
114
|
if (!result.ignore) {
|
|
113
115
|
directChildrenStates.push(result.state);
|
|
114
116
|
}
|
|
@@ -121,7 +123,7 @@ export class SelectionProvider {
|
|
|
121
123
|
let newSelection = [...oldSelection];
|
|
122
124
|
tree.forEach((node) => {
|
|
123
125
|
// match itself and all children
|
|
124
|
-
if (node.path?.startsWith(parentNodePath ? parentNodePath + this.helper.config.separator :
|
|
126
|
+
if (node.path?.startsWith(parentNodePath ? parentNodePath + this.helper.config.separator : "")) {
|
|
125
127
|
//don't change if not selectable
|
|
126
128
|
if (!isSelectable(node, SelectionModes.all)) {
|
|
127
129
|
return;
|
|
@@ -131,9 +133,9 @@ export class SelectionProvider {
|
|
|
131
133
|
return;
|
|
132
134
|
}
|
|
133
135
|
// prevent double selection
|
|
134
|
-
newSelection = newSelection.filter((x) => x !== (node.id ??
|
|
136
|
+
newSelection = newSelection.filter((x) => x !== (node.id ?? ""));
|
|
135
137
|
if (changeTo === true) {
|
|
136
|
-
newSelection.push(node.id ??
|
|
138
|
+
newSelection.push(node.id ?? "");
|
|
137
139
|
}
|
|
138
140
|
}
|
|
139
141
|
});
|