@keenmate/svelte-treeview 1.0.0-beta.0 → 1.0.0-beta.1
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 +38 -38
- package/dist/Branch.svelte +126 -132
- package/dist/Checkbox.svelte +30 -52
- package/dist/Checkbox.svelte.d.ts +0 -2
- package/dist/TreeView.svelte +65 -69
- package/dist/TreeView.svelte.d.ts +12 -12
- package/dist/constants.js +2 -6
- package/dist/helpers/tree-helper.d.ts +12 -19
- package/dist/helpers/tree-helper.js +52 -54
- package/dist/menu/ContextMenu.svelte +27 -33
- package/dist/menu/ContextMenu.svelte.d.ts +8 -18
- package/dist/menu/Menu.svelte +51 -50
- package/dist/menu/MenuDivider.svelte +11 -10
- package/dist/menu/MenuOption.svelte +50 -49
- package/dist/menu/menu.js +2 -2
- package/dist/providers/drag-drop-provider.d.ts +0 -29
- package/dist/providers/drag-drop-provider.js +186 -163
- package/dist/providers/selection-provider.d.ts +4 -6
- package/dist/providers/selection-provider.js +43 -31
- package/dist/tree-styles.sass +105 -105
- package/dist/types.d.ts +29 -8
- package/package.json +71 -71
- package/dist/helpers/property-helper.d.ts +0 -31
- package/dist/helpers/property-helper.js +0 -94
- package/dist/stores/drag-and-drop-store.d.ts +0 -13
- package/dist/stores/drag-and-drop-store.js +0 -23
package/dist/menu/Menu.svelte
CHANGED
|
@@ -1,50 +1,51 @@
|
|
|
1
|
-
<!-- component from https://svelte.dev/repl/3a33725c3adb4f57b46b597f9dade0c1?version=3.25.0 -->
|
|
2
|
-
|
|
3
|
-
<script>
|
|
4
|
-
// @ts-nocheck
|
|
5
|
-
|
|
6
|
-
import { onMount, setContext, createEventDispatcher } from 'svelte';
|
|
7
|
-
import { fade } from 'svelte/transition';
|
|
8
|
-
import { key } from './menu.js';
|
|
9
|
-
|
|
10
|
-
export let x;
|
|
11
|
-
export let y;
|
|
12
|
-
|
|
13
|
-
// whenever x and y is changed, restrict box to be within bounds
|
|
14
|
-
$: (() => {
|
|
15
|
-
if (!menuEl) return;
|
|
16
|
-
|
|
17
|
-
const rect = menuEl.getBoundingClientRect();
|
|
18
|
-
x = Math.min(window.innerWidth - rect.width, x);
|
|
19
|
-
if (y > window.innerHeight - rect.height) y -= rect.height;
|
|
20
|
-
})(x, y);
|
|
21
|
-
|
|
22
|
-
const dispatch = createEventDispatcher();
|
|
23
|
-
|
|
24
|
-
setContext(key, {
|
|
25
|
-
dispatchClick: () => dispatch('click')
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
let menuEl;
|
|
29
|
-
function onPageClick(e) {
|
|
30
|
-
if (e.target === menuEl || menuEl.contains(e.target)) return;
|
|
31
|
-
dispatch('clickoutside');
|
|
32
|
-
}
|
|
33
|
-
</script>
|
|
34
|
-
|
|
35
|
-
<svelte:body on:click={onPageClick} />
|
|
36
|
-
|
|
37
|
-
<div transition:fade={{ duration: 100 }} bind:this={menuEl} style="top: {y}px; left: {x}px;">
|
|
38
|
-
<slot />
|
|
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
|
-
|
|
1
|
+
<!-- component from https://svelte.dev/repl/3a33725c3adb4f57b46b597f9dade0c1?version=3.25.0 -->
|
|
2
|
+
|
|
3
|
+
<script>
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
|
|
6
|
+
import { onMount, setContext, createEventDispatcher } from 'svelte';
|
|
7
|
+
import { fade } from 'svelte/transition';
|
|
8
|
+
import { key } from './menu.js';
|
|
9
|
+
|
|
10
|
+
export let x;
|
|
11
|
+
export let y;
|
|
12
|
+
|
|
13
|
+
// whenever x and y is changed, restrict box to be within bounds
|
|
14
|
+
$: (() => {
|
|
15
|
+
if (!menuEl) return;
|
|
16
|
+
|
|
17
|
+
const rect = menuEl.getBoundingClientRect();
|
|
18
|
+
x = Math.min(window.innerWidth - rect.width, x);
|
|
19
|
+
if (y > window.innerHeight - rect.height) y -= rect.height;
|
|
20
|
+
})(x, y);
|
|
21
|
+
|
|
22
|
+
const dispatch = createEventDispatcher();
|
|
23
|
+
|
|
24
|
+
setContext(key, {
|
|
25
|
+
dispatchClick: () => dispatch('click')
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
let menuEl;
|
|
29
|
+
function onPageClick(e) {
|
|
30
|
+
if (e.target === menuEl || menuEl.contains(e.target)) return;
|
|
31
|
+
dispatch('clickoutside');
|
|
32
|
+
}
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<svelte:body on:click={onPageClick} />
|
|
36
|
+
|
|
37
|
+
<div transition:fade={{ duration: 100 }} bind:this={menuEl} style="top: {y}px; left: {x}px;">
|
|
38
|
+
<slot />
|
|
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
|
+
|
|
51
|
+
</style>
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
<style>
|
|
2
|
-
hr {
|
|
3
|
-
border-top: 1px solid #0003;
|
|
4
|
-
width: 100%;
|
|
5
|
-
margin: 2px 0;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
<style>
|
|
2
|
+
hr {
|
|
3
|
+
border-top: 1px solid #0003;
|
|
4
|
+
width: 100%;
|
|
5
|
+
margin: 2px 0;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
</style>
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
<hr />
|
|
@@ -1,49 +1,50 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
// @ts-nocheck
|
|
3
|
-
|
|
4
|
-
import { onMount, getContext } from 'svelte';
|
|
5
|
-
import { key } from './menu.js';
|
|
6
|
-
|
|
7
|
-
export let isDisabled = false;
|
|
8
|
-
export let text = '';
|
|
9
|
-
|
|
10
|
-
import { createEventDispatcher } from 'svelte';
|
|
11
|
-
const dispatch = createEventDispatcher();
|
|
12
|
-
|
|
13
|
-
const { dispatchClick } = getContext(key);
|
|
14
|
-
|
|
15
|
-
const handleClick = (e) => {
|
|
16
|
-
if (isDisabled) return;
|
|
17
|
-
|
|
18
|
-
dispatch('click');
|
|
19
|
-
dispatchClick();
|
|
20
|
-
};
|
|
21
|
-
</script>
|
|
22
|
-
|
|
23
|
-
<div class:disabled={isDisabled} on:click={handleClick} on:keydown={handleClick} role="button" tabindex="">
|
|
24
|
-
{#if text}
|
|
25
|
-
{text}
|
|
26
|
-
{:else}
|
|
27
|
-
<slot />
|
|
28
|
-
{/if}
|
|
29
|
-
</div>
|
|
30
|
-
|
|
31
|
-
<style>
|
|
32
|
-
div {
|
|
33
|
-
padding: 4px 15px;
|
|
34
|
-
cursor: default;
|
|
35
|
-
font-size: 14px;
|
|
36
|
-
display: flex;
|
|
37
|
-
align-items: center;
|
|
38
|
-
grid-gap: 5px;
|
|
39
|
-
}
|
|
40
|
-
div:hover {
|
|
41
|
-
background: #0002;
|
|
42
|
-
}
|
|
43
|
-
div.disabled {
|
|
44
|
-
color: #0006;
|
|
45
|
-
}
|
|
46
|
-
div.disabled:hover {
|
|
47
|
-
background: white;
|
|
48
|
-
}
|
|
49
|
-
|
|
1
|
+
<script>
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
|
|
4
|
+
import { onMount, getContext } from 'svelte';
|
|
5
|
+
import { key } from './menu.js';
|
|
6
|
+
|
|
7
|
+
export let isDisabled = false;
|
|
8
|
+
export let text = '';
|
|
9
|
+
|
|
10
|
+
import { createEventDispatcher } from 'svelte';
|
|
11
|
+
const dispatch = createEventDispatcher();
|
|
12
|
+
|
|
13
|
+
const { dispatchClick } = getContext(key);
|
|
14
|
+
|
|
15
|
+
const handleClick = (e) => {
|
|
16
|
+
if (isDisabled) return;
|
|
17
|
+
|
|
18
|
+
dispatch('click');
|
|
19
|
+
dispatchClick();
|
|
20
|
+
};
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<div class:disabled={isDisabled} on:click={handleClick} on:keydown={handleClick} role="button" tabindex="">
|
|
24
|
+
{#if text}
|
|
25
|
+
{text}
|
|
26
|
+
{:else}
|
|
27
|
+
<slot />
|
|
28
|
+
{/if}
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<style>
|
|
32
|
+
div {
|
|
33
|
+
padding: 4px 15px;
|
|
34
|
+
cursor: default;
|
|
35
|
+
font-size: 14px;
|
|
36
|
+
display: flex;
|
|
37
|
+
align-items: center;
|
|
38
|
+
grid-gap: 5px;
|
|
39
|
+
}
|
|
40
|
+
div:hover {
|
|
41
|
+
background: #0002;
|
|
42
|
+
}
|
|
43
|
+
div.disabled {
|
|
44
|
+
color: #0006;
|
|
45
|
+
}
|
|
46
|
+
div.disabled:hover {
|
|
47
|
+
background: white;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
</style>
|
package/dist/menu/menu.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const key = {};
|
|
2
|
-
|
|
1
|
+
const key = {};
|
|
2
|
+
|
|
3
3
|
export { key };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { PropertyHelper } from '../helpers/property-helper.js';
|
|
2
|
-
import type { TreeHelper } from '../helpers/tree-helper.js';
|
|
3
|
-
import { InsertionType, type Node, type NodePath, type Tree } from '../types.js';
|
|
4
|
-
export declare class DragDropProvider {
|
|
5
|
-
helper: TreeHelper;
|
|
6
|
-
props: PropertyHelper;
|
|
7
|
-
separator: string;
|
|
8
|
-
constructor(treeHelper: TreeHelper);
|
|
9
|
-
path(node: Node): NodePath;
|
|
10
|
-
/**
|
|
11
|
-
* moves node from one parent to another
|
|
12
|
-
* @param {Object[]} tree - tree
|
|
13
|
-
* @param {nodePath} movedNodePath - nodepath of moved(dragged) node
|
|
14
|
-
* @param {nodePath} targetNodePath - nodepath of node where it should be moved ( either bellow it in priority or as child)
|
|
15
|
-
* @param {int} insType - if true, it will insert moved node as child of target node, if false, it will insert it bellow it in priority
|
|
16
|
-
* @param {boolean} recalculateNodePath - wont recalculare id of moved node, used when last part of nodePath is always unique
|
|
17
|
-
*/
|
|
18
|
-
moveNode(tree: Node[], movedNodePath: NodePath, targetNodePath: NodePath, insType: InsertionType, recalculateNodePath: boolean): Node[];
|
|
19
|
-
calculateNewNodePath(tree: Tree, parentNodePath: NodePath, movedNodePath: NodePath, recalculateNodePath: boolean): string;
|
|
20
|
-
updatePriority(tree: Tree, node: Node, parentNodePath: NodePath, newNodePath: NodePath, targetNode: Node, insType: InsertionType): void;
|
|
21
|
-
/** recomputes all priorities after inserted priority.F
|
|
22
|
-
* Also changes all priorities to be one apart (1,5,6 => 1,2,3)
|
|
23
|
-
*/
|
|
24
|
-
recalculatesPriorities(tree: Tree, parentNode: NodePath, movedNodePath: NodePath, insertedPriority?: number): void;
|
|
25
|
-
/** return biggest value of nodepath number that children are using +1 */
|
|
26
|
-
getNextNodeId(tree: Tree, parentPath: NodePath): string;
|
|
27
|
-
getInsertionPosition(e: DragEvent, element: HTMLElement): InsertionType;
|
|
28
|
-
getNodeIdFromPath(nodePath: NodePath): string | null;
|
|
29
|
-
}
|
|
@@ -1,163 +1,186 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// import type { PropertyHelper } from '../helpers/property-helper.js';
|
|
3
|
+
// import type { TreeHelper } from '../helpers/tree-helper.js';
|
|
4
|
+
// import { InsertionType, type Node, type NodePath, type Tree } from '../types.js';
|
|
5
|
+
// export class DragDropProvider {
|
|
6
|
+
// helper: TreeHelper;
|
|
7
|
+
// props: PropertyHelper;
|
|
8
|
+
// separator: string;
|
|
9
|
+
// constructor(treeHelper: TreeHelper) {
|
|
10
|
+
// this.helper = treeHelper;
|
|
11
|
+
// this.props = treeHelper.props;
|
|
12
|
+
// this.separator = this.helper.config.separator ?? '.';
|
|
13
|
+
// }
|
|
14
|
+
// path(node: Node) {
|
|
15
|
+
// return this.helper.path(node);
|
|
16
|
+
// }
|
|
17
|
+
// /**
|
|
18
|
+
// * moves node from one parent to another
|
|
19
|
+
// * @param {Object[]} tree - tree
|
|
20
|
+
// * @param {nodePath} movedNodePath - nodepath of moved(dragged) node
|
|
21
|
+
// * @param {nodePath} targetNodePath - nodepath of node where it should be moved ( either bellow it in priority or as child)
|
|
22
|
+
// * @param {int} insType - if true, it will insert moved node as child of target node, if false, it will insert it bellow it in priority
|
|
23
|
+
// * @param {boolean} recalculateNodePath - wont recalculare id of moved node, used when last part of nodePath is always unique
|
|
24
|
+
// */
|
|
25
|
+
// moveNode(
|
|
26
|
+
// tree: Node[],
|
|
27
|
+
// movedNodePath: NodePath,
|
|
28
|
+
// targetNodePath: NodePath,
|
|
29
|
+
// insType: InsertionType,
|
|
30
|
+
// recalculateNodePath: boolean
|
|
31
|
+
// ): Node[] {
|
|
32
|
+
// // cannot move root node
|
|
33
|
+
// if (!movedNodePath) return tree;
|
|
34
|
+
// const isNesting = insType === InsertionType.nest;
|
|
35
|
+
// // if you are not isNestinging, you want to be on same level
|
|
36
|
+
// //so you will have same parent as target node
|
|
37
|
+
// const parentNodePath = isNesting
|
|
38
|
+
// ? targetNodePath
|
|
39
|
+
// : this.helper.getParentNodePath(targetNodePath);
|
|
40
|
+
// //trying to move parent to child
|
|
41
|
+
// if (parentNodePath?.startsWith(movedNodePath)) {
|
|
42
|
+
// return tree;
|
|
43
|
+
// }
|
|
44
|
+
// const changedParent = this.helper.getParentNodePath(movedNodePath) !== parentNodePath;
|
|
45
|
+
// let newNodePath = movedNodePath;
|
|
46
|
+
// //dont create new node if you only moved inside same parent
|
|
47
|
+
// if (changedParent) {
|
|
48
|
+
// newNodePath = this.calculateNewNodePath(
|
|
49
|
+
// tree,
|
|
50
|
+
// parentNodePath,
|
|
51
|
+
// movedNodePath,
|
|
52
|
+
// recalculateNodePath
|
|
53
|
+
// );
|
|
54
|
+
// }
|
|
55
|
+
// //* find target node
|
|
56
|
+
// const targetNode = this.helper.findNode(tree, targetNodePath);
|
|
57
|
+
// if (!targetNode) return tree;
|
|
58
|
+
// let movedNode;
|
|
59
|
+
// //move nodes
|
|
60
|
+
// tree = tree.map((node) => {
|
|
61
|
+
// //make sure that parent's haschild is set to true, so that children are visible
|
|
62
|
+
// if (this.path(node) == parentNodePath) {
|
|
63
|
+
// this.props.setHasChildren(node, true);
|
|
64
|
+
// this.props.setExpanded(node, true);
|
|
65
|
+
// }
|
|
66
|
+
// //move moved nodes to new location ( if location is being changed)
|
|
67
|
+
// if (changedParent && this.path(node)?.startsWith(movedNodePath)) {
|
|
68
|
+
// //replace old parent with new one
|
|
69
|
+
// const newPath = this.path(node)?.replace(movedNodePath, newNodePath) ?? null;
|
|
70
|
+
// this.props.setPath(node, newPath);
|
|
71
|
+
// }
|
|
72
|
+
// //if it is moved node
|
|
73
|
+
// if (this.path(node) === newNodePath) {
|
|
74
|
+
// movedNode = node;
|
|
75
|
+
// //? not sure if this is best
|
|
76
|
+
// this.updatePriority(tree, movedNode, parentNodePath, newNodePath, targetNode, insType);
|
|
77
|
+
// }
|
|
78
|
+
// return node;
|
|
79
|
+
// });
|
|
80
|
+
// if (!movedNode) return tree;
|
|
81
|
+
// //* insert node at right possition of array
|
|
82
|
+
// const oldIndex = tree.findIndex((x) => this.path(x) == newNodePath);
|
|
83
|
+
// tree.splice(oldIndex, 1);
|
|
84
|
+
// const index = tree.findIndex((x) => this.path(x) == this.path(targetNode));
|
|
85
|
+
// tree.splice(index + (insType == InsertionType.above ? 0 : 1), 0, movedNode);
|
|
86
|
+
// //TODO maybe add option to setting this.hasChildren to false when moved last children
|
|
87
|
+
// //hide plus icon if parent of moved node doesnt have any more children
|
|
88
|
+
// const oldParent = this.helper.findNode(tree, this.helper.getParentNodePath(movedNodePath));
|
|
89
|
+
// if (!oldParent) return tree;
|
|
90
|
+
// //moved last node
|
|
91
|
+
// const oldParentHasChildren = this.helper.allCHildren(tree, this.path(oldParent)).length;
|
|
92
|
+
// if (oldParent && !oldParentHasChildren) {
|
|
93
|
+
// this.props.setHasChildren(oldParent, false);
|
|
94
|
+
// }
|
|
95
|
+
// return tree;
|
|
96
|
+
// }
|
|
97
|
+
// calculateNewNodePath(
|
|
98
|
+
// tree: Tree,
|
|
99
|
+
// parentNodePath: NodePath,
|
|
100
|
+
// movedNodePath: NodePath,
|
|
101
|
+
// recalculateNodePath: boolean
|
|
102
|
+
// ) {
|
|
103
|
+
// //node id is last part of nodePath
|
|
104
|
+
// let nodeId;
|
|
105
|
+
// if (recalculateNodePath) {
|
|
106
|
+
// nodeId = this.getNextNodeId(tree, parentNodePath);
|
|
107
|
+
// } else {
|
|
108
|
+
// //get last segment of path
|
|
109
|
+
// // nodeId = this.helper.getNodeIdFromPath(movedNodePath);
|
|
110
|
+
// }
|
|
111
|
+
// if (parentNodePath === null) return nodeId as string;
|
|
112
|
+
// return `${parentNodePath}${this.separator}${nodeId}`;
|
|
113
|
+
// }
|
|
114
|
+
// updatePriority(
|
|
115
|
+
// tree: Tree,
|
|
116
|
+
// node: Node,
|
|
117
|
+
// parentNodePath: NodePath,
|
|
118
|
+
// newNodePath: NodePath,
|
|
119
|
+
// targetNode: Node,
|
|
120
|
+
// insType: InsertionType
|
|
121
|
+
// ) {
|
|
122
|
+
// const isNesting = insType == InsertionType.nest;
|
|
123
|
+
// if (isNesting || this.props.priority(targetNode) != null) {
|
|
124
|
+
// let newpriority = 0;
|
|
125
|
+
// if (!isNesting) {
|
|
126
|
+
// //calculate next
|
|
127
|
+
// newpriority = this.props.priority(targetNode) ?? 0;
|
|
128
|
+
// if (insType == InsertionType.below) {
|
|
129
|
+
// newpriority += 1;
|
|
130
|
+
// } else {
|
|
131
|
+
// //targetNode[this.props.priority] -= 1;
|
|
132
|
+
// }
|
|
133
|
+
// }
|
|
134
|
+
// this.recalculatesPriorities(tree, parentNodePath, newNodePath, newpriority);
|
|
135
|
+
// this.props.setPriority(targetNode, newpriority);
|
|
136
|
+
// } else {
|
|
137
|
+
// //so old priority doesnt mess up orderring
|
|
138
|
+
// this.props.setPriority(targetNode, undefined);
|
|
139
|
+
// }
|
|
140
|
+
// }
|
|
141
|
+
// /** recomputes all priorities after inserted priority.F
|
|
142
|
+
// * Also changes all priorities to be one apart (1,5,6 => 1,2,3)
|
|
143
|
+
// */
|
|
144
|
+
// //? maybe it will recalculate properly if dont set insertedPriority
|
|
145
|
+
// recalculatesPriorities(
|
|
146
|
+
// tree: Tree,
|
|
147
|
+
// parentNode: NodePath,
|
|
148
|
+
// movedNodePath: NodePath,
|
|
149
|
+
// insertedPriority = -1
|
|
150
|
+
// ) {
|
|
151
|
+
// let nextPriority = insertedPriority + 1;
|
|
152
|
+
// this.helper.orderByPriority(this.helper.allCHildren(tree, parentNode)).forEach((node) => {
|
|
153
|
+
// if (this.props.priority(node) >= insertedPriority && this.path(node) != movedNodePath) {
|
|
154
|
+
// this.props.setPriority(node, nextPriority++);
|
|
155
|
+
// }
|
|
156
|
+
// });
|
|
157
|
+
// }
|
|
158
|
+
// /** return biggest value of nodepath number that children are using +1 */
|
|
159
|
+
// getNextNodeId(tree: Tree, parentPath: NodePath) {
|
|
160
|
+
// let max = 0;
|
|
161
|
+
// //findes biggest nodeNumber for
|
|
162
|
+
// this.helper.allCHildren(tree, parentPath).forEach((node) => {
|
|
163
|
+
// const parent = this.helper.getParentNodePath(this.path(node));
|
|
164
|
+
// if (parent === parentPath) {
|
|
165
|
+
// const num = parseInt(this.path(node)?.substring(parent ? parent.length + 1 : 0) ?? '0');
|
|
166
|
+
// max = Math.max(max, num);
|
|
167
|
+
// }
|
|
168
|
+
// });
|
|
169
|
+
// return (max + 1).toString();
|
|
170
|
+
// }
|
|
171
|
+
// getInsertionPosition(e: DragEvent, element: HTMLElement): InsertionType {
|
|
172
|
+
// const targetCords = element.getBoundingClientRect();
|
|
173
|
+
// const half = targetCords.bottom - targetCords.height / 2;
|
|
174
|
+
// if (e.y < half) {
|
|
175
|
+
// return InsertionType.below;
|
|
176
|
+
// }
|
|
177
|
+
// return InsertionType.above;
|
|
178
|
+
// }
|
|
179
|
+
// getNodeIdFromPath(nodePath: NodePath) {
|
|
180
|
+
// if (nodePath == null) {
|
|
181
|
+
// console.warn('getting node id of null node path');
|
|
182
|
+
// return null;
|
|
183
|
+
// }
|
|
184
|
+
// return nodePath?.split(this.helper.config.separator).slice(-1)[0];
|
|
185
|
+
// }
|
|
186
|
+
// }
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
import type { PropertyHelper } from '../helpers/property-helper.js';
|
|
2
1
|
import type { TreeHelper } from '../helpers/tree-helper.js';
|
|
3
|
-
import { SelectionModes, type
|
|
2
|
+
import { SelectionModes, type NodePath, type Tree, type TreeVisualStates, type Node, type NodeId } from '../types.js';
|
|
4
3
|
export declare class SelectionProvider {
|
|
5
4
|
helper: TreeHelper;
|
|
6
|
-
props: PropertyHelper;
|
|
7
5
|
recursiveMode: boolean;
|
|
8
6
|
constructor(treeHelper: TreeHelper, recursive: boolean);
|
|
9
|
-
|
|
7
|
+
markSelected(tree: Tree, selectedNodeIds: NodeId[]): void;
|
|
10
8
|
isNodeSelected(node: Node): boolean;
|
|
11
9
|
isSelected(nodeId: string, visualStates: TreeVisualStates, selectedNodeIds: NodeId[]): boolean;
|
|
12
|
-
getSelectableDirectChildren(tree: Tree, parentNodePath: string | null):
|
|
10
|
+
getSelectableDirectChildren(tree: Tree, parentNodePath: string | null): Node[];
|
|
13
11
|
setSelection(tree: Tree, nodePath: NodePath, changeTo: boolean, oldSelection: NodeId[]): NodeId[];
|
|
14
12
|
/** Computes visual states for all nodes. Used for computing initial visual states when tree changes */
|
|
15
13
|
computeVisualStates(tree: Tree, selectedNodeIds: (string | number)[]): TreeVisualStates;
|
|
16
|
-
isSelectable(node: Node, showCheckboxes: SelectionModes): boolean;
|
|
17
14
|
private computeVisualState;
|
|
18
15
|
/**
|
|
19
16
|
* Computes visual state from leaf to node
|
|
@@ -25,3 +22,4 @@ export declare class SelectionProvider {
|
|
|
25
22
|
private computeVisualStateRecursively;
|
|
26
23
|
private changeSelectedRecursively;
|
|
27
24
|
}
|
|
25
|
+
export declare function isSelectable(node: Node, showCheckboxes: SelectionModes): boolean;
|