@keenmate/svelte-treeview 1.1.1 → 1.1.3
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 +1 -1
- package/dist/Branch.svelte +5 -2
- package/dist/TreeView.svelte +29 -31
- package/dist/TreeView.svelte.d.ts +11 -11
- package/dist/constants.js +1 -1
- package/dist/helpers/tree-helper.d.ts +5 -3
- package/dist/helpers/tree-helper.js +20 -17
- package/dist/providers/drag-drop-provider.d.ts +1 -1
- package/dist/providers/drag-drop-provider.js +1 -1
- package/dist/providers/movement-provider.d.ts +1 -1
- package/dist/providers/movement-provider.js +1 -2
- package/dist/providers/selection-provider.js +3 -3
- package/dist/types.d.ts +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,7 +68,7 @@ For more examples see `src/routes/`
|
|
|
68
68
|
| hideDisabledCheckboxes | bool | false | hides checkboxes instead of disabling, see [Selection](#selection) |
|
|
69
69
|
| loadChildrenAsync | ExpandedCallback | null | function that is called when node is expanded, see [Async loading](#async-loading) |
|
|
70
70
|
| showContextMenu | bool | false | On right click dispaly context menu defined in `context-menu` slot, see [Context menu](#context-menu) |
|
|
71
|
-
|
|
|
71
|
+
| expansionThreshold | number | 0 | Expand all nodes when there is less than number provided |
|
|
72
72
|
| customClasses | Partial<CustomizableClasses> | {} | changes classes used on same elements, see [Custom classes](#custom-classes) |
|
|
73
73
|
| filter | (node: Node) => boolean or null | null | function that is used for fitlering. It is called on every node |
|
|
74
74
|
| dragAndDrop | bool | false | enables drag and drop, see [Drag and drop](#drag-and-drop) |
|
package/dist/Branch.svelte
CHANGED
|
@@ -83,11 +83,14 @@ function getHighlighMode(node, highlightedNode, insertionType) {
|
|
|
83
83
|
class:child-menu={childDepth > 0}
|
|
84
84
|
class={childDepth === 0 ? classes.treeClass : ''}
|
|
85
85
|
>
|
|
86
|
+
<!-- TODO fix accessibility -->
|
|
87
|
+
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
|
86
88
|
{#each directChildren as node (getNodeId(node))}
|
|
87
89
|
{@const expanded = isExpanded(node, childDepth, expandTo)}
|
|
88
90
|
{@const draggable = !readonly && dragAndDrop && !node.dragDisabled}
|
|
89
91
|
{@const isCurrentlyDragged = draggedNode && node.path.startsWith(draggedNode?.path)}
|
|
90
92
|
{@const effectiveHighlight = getHighlighMode(node, highlightedNode, insertionType)}
|
|
93
|
+
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
|
91
94
|
<li
|
|
92
95
|
class:is-child={helper.nodePathIsChild(node.path)}
|
|
93
96
|
class:has-children={node.hasChildren}
|
|
@@ -105,7 +108,7 @@ function getHighlighMode(node, highlightedNode, insertionType) {
|
|
|
105
108
|
>
|
|
106
109
|
{#if effectiveHighlight == InsertionType.insertAbove}
|
|
107
110
|
<div class="insert-line-wrapper">
|
|
108
|
-
<div class="insert-line {classes.
|
|
111
|
+
<div class="insert-line {classes.insertLineClass}" />
|
|
109
112
|
</div>
|
|
110
113
|
{/if}
|
|
111
114
|
|
|
@@ -204,7 +207,7 @@ function getHighlighMode(node, highlightedNode, insertionType) {
|
|
|
204
207
|
<!-- Show line if insering -->
|
|
205
208
|
{#if effectiveHighlight === InsertionType.insertBelow}
|
|
206
209
|
<div class="insert-line-wrapper">
|
|
207
|
-
<div class="insert-line {classes.
|
|
210
|
+
<div class="insert-line {classes.insertLineClass}" />
|
|
208
211
|
</div>
|
|
209
212
|
{/if}
|
|
210
213
|
</li>
|
package/dist/TreeView.svelte
CHANGED
|
@@ -50,8 +50,8 @@ export let recursiveSelection = false;
|
|
|
50
50
|
*/
|
|
51
51
|
export let selectionMode = SelectionModes.none;
|
|
52
52
|
/**
|
|
53
|
-
* By default, in recursive mode, non-leaf checkboxes will select/
|
|
54
|
-
* If you set this to true, this
|
|
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
55
|
*/
|
|
56
56
|
export let onlyLeafCheckboxes = false; //bool
|
|
57
57
|
/**
|
|
@@ -59,7 +59,7 @@ export let onlyLeafCheckboxes = false; //bool
|
|
|
59
59
|
*/
|
|
60
60
|
export let hideDisabledCheckboxes = false; //bool
|
|
61
61
|
/**
|
|
62
|
-
* Function that will be
|
|
62
|
+
* Function that will be caged when node is expanded and useCallback is set to true
|
|
63
63
|
* It should return array of nodes that will be added to tree
|
|
64
64
|
* If it throws error, node will be collapsed,
|
|
65
65
|
* but user will be able to open it again and callback will be called
|
|
@@ -72,18 +72,18 @@ export let loadChildrenAsync = null;
|
|
|
72
72
|
export let showContextMenu = false;
|
|
73
73
|
// TODO stopped working in new version
|
|
74
74
|
/**
|
|
75
|
-
*
|
|
75
|
+
* Automatically expand nodes to this level,
|
|
76
76
|
* any user made expansion will override this.
|
|
77
77
|
*/
|
|
78
78
|
export let expandTo = 0;
|
|
79
79
|
/**
|
|
80
|
-
*
|
|
80
|
+
* Threshold for automatic expansion. If tree has less or equal nodes than this value,
|
|
81
81
|
* all nodes will be expanded. Default is 0, which means no automatic expansion
|
|
82
82
|
*/
|
|
83
|
-
export let
|
|
83
|
+
export let expansionThreshold = 0;
|
|
84
84
|
/**
|
|
85
85
|
* Classes used in tree. You can override default classes with this prop.
|
|
86
|
-
* It is recommended to use default classes and add
|
|
86
|
+
* It is recommended to use default classes and add additional styles in your css
|
|
87
87
|
*/
|
|
88
88
|
export let customClasses = {};
|
|
89
89
|
/**
|
|
@@ -100,7 +100,7 @@ export let filter = null;
|
|
|
100
100
|
*/
|
|
101
101
|
export let logger = null;
|
|
102
102
|
/*
|
|
103
|
-
* Drag and drop mode allows all nodes, that
|
|
103
|
+
* Drag and drop mode allows all nodes, that don't have dragDisabled property set to true
|
|
104
104
|
* to be dragged and dropped. By default you can only insert at same level node you are dropping on,
|
|
105
105
|
* but you can allow nesting by setting nestAllowed to true on node. If you want to disable insertion,
|
|
106
106
|
* set dropDisabled to true on node. if both is disabled, you wont be able to drop on node.
|
|
@@ -116,7 +116,7 @@ export let dropDisabledCallback = null;
|
|
|
116
116
|
*/
|
|
117
117
|
export let allowKeyboardNavigation = false;
|
|
118
118
|
let ctxMenu;
|
|
119
|
-
let
|
|
119
|
+
let expandedPaths = [];
|
|
120
120
|
let draggedNode = null;
|
|
121
121
|
let highlightedNode = null;
|
|
122
122
|
let insertionType = InsertionType.none;
|
|
@@ -128,41 +128,39 @@ $: helper = new TreeHelper({
|
|
|
128
128
|
});
|
|
129
129
|
$: dragAndDropProvider = new DragDropProvider(helper);
|
|
130
130
|
$: selectionProvider = new SelectionProvider(helper, recursiveSelection);
|
|
131
|
-
$: computedTree = computeTree(helper, selectionProvider, tree, filter, props,
|
|
131
|
+
$: computedTree = computeTree(helper, selectionProvider, tree, filter, props, expandedPaths, value);
|
|
132
132
|
$: debugLog('computedTree', computedTree);
|
|
133
133
|
export function changeAllExpansion(changeTo) {
|
|
134
|
-
debugLog('
|
|
134
|
+
debugLog('changing expansion of every node to ', changeTo ? 'expanded' : 'collapsed');
|
|
135
135
|
if (changeTo) {
|
|
136
|
-
|
|
136
|
+
expandedPaths = computedTree.map((node) => node.path);
|
|
137
137
|
}
|
|
138
138
|
else {
|
|
139
|
-
|
|
139
|
+
expandedPaths = [];
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
export function expandToNode(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
console.error('Node with path', nodePath, 'not found');
|
|
142
|
+
export function expandToNode(targetNodePath) {
|
|
143
|
+
if (!targetNodePath) {
|
|
144
|
+
console.warn('Cannot expand to node with null path');
|
|
146
145
|
return;
|
|
147
146
|
}
|
|
148
|
-
const
|
|
149
|
-
debugLog("expanding to node '" +
|
|
150
|
-
|
|
147
|
+
const parentPaths = helper.getParentsPaths(targetNodePath);
|
|
148
|
+
debugLog("expanding to node '" + targetNodePath + "'" + ' parents', parentPaths);
|
|
149
|
+
expandedPaths = uniq([...expandedPaths, ...parentPaths]);
|
|
151
150
|
}
|
|
152
151
|
export function setNodeExpansion(nodePath, changeTo) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
console.error('Node with path', nodePath, 'not found');
|
|
152
|
+
if (!nodePath) {
|
|
153
|
+
console.warn('Cannot expand node with null path');
|
|
156
154
|
return;
|
|
157
155
|
}
|
|
158
|
-
|
|
156
|
+
expandedPaths = helper.changeExpansion(nodePath, changeTo, expandedPaths);
|
|
159
157
|
}
|
|
160
158
|
export function setExpansions(expansions) {
|
|
161
159
|
if (!Array.isArray(expansions)) {
|
|
162
160
|
console.error('expansions must be an array');
|
|
163
161
|
return;
|
|
164
162
|
}
|
|
165
|
-
|
|
163
|
+
expandedPaths = expansions;
|
|
166
164
|
}
|
|
167
165
|
export function focusNode(nodePath) {
|
|
168
166
|
if (nodePath === null) {
|
|
@@ -190,7 +188,7 @@ function computeTree(helper, selectionProvider, userProvidedTree, filter, props,
|
|
|
190
188
|
const mappedTree = helper.mapTree(userProvidedTree, { ...defaultPropNames, ...props });
|
|
191
189
|
const { tree: filteredTree, count: filteredCount } = helper.searchTree(mappedTree, filter);
|
|
192
190
|
// treshold applies to nodes that match the filter, not all their parents
|
|
193
|
-
if (filteredCount <=
|
|
191
|
+
if (filteredCount <= expansionThreshold) {
|
|
194
192
|
expandedIds = uniq([...expandedIds, ...filteredTree.map((node) => node.id)]);
|
|
195
193
|
}
|
|
196
194
|
helper.markExpanded(filteredTree, expandedIds);
|
|
@@ -201,7 +199,7 @@ function computeTree(helper, selectionProvider, userProvidedTree, filter, props,
|
|
|
201
199
|
}
|
|
202
200
|
function onExpand(detail) {
|
|
203
201
|
const { node, changeTo } = detail;
|
|
204
|
-
|
|
202
|
+
expandedPaths = helper.changeExpansion(node.path, changeTo, expandedPaths);
|
|
205
203
|
debugLog("changed expansion of node '", node.id, "' to ", changeTo);
|
|
206
204
|
//trigger callback if it is present and node has useCallback property set to true
|
|
207
205
|
if (changeTo) {
|
|
@@ -229,7 +227,7 @@ function handleCallback(node) {
|
|
|
229
227
|
return;
|
|
230
228
|
}
|
|
231
229
|
debugLog('calling callback for node', node);
|
|
232
|
-
// TODO mark node as loaded and
|
|
230
|
+
// TODO mark node as loaded and don't call callback again
|
|
233
231
|
// this is now responsibility of user
|
|
234
232
|
loadChildrenAsync(node);
|
|
235
233
|
}
|
|
@@ -238,7 +236,7 @@ function onSelectionChanged(detail) {
|
|
|
238
236
|
const nodePath = node.path;
|
|
239
237
|
const changeTo = !selectionProvider.isNodeSelected(node);
|
|
240
238
|
const newValue = selectionProvider.setSelection(computedTree, nodePath, changeTo, value);
|
|
241
|
-
debugLog("changing selection of node '", nodePath, "' to ", changeTo, '
|
|
239
|
+
debugLog("changing selection of node '", nodePath, "' to ", changeTo, ' returning value ', newValue);
|
|
242
240
|
dispatch('change', newValue);
|
|
243
241
|
dispatch('selection', {
|
|
244
242
|
node: node,
|
|
@@ -272,7 +270,7 @@ function onDragEnd({ detail: { node, event, element } }) {
|
|
|
272
270
|
highlightedNode = null;
|
|
273
271
|
}
|
|
274
272
|
function onDragDrop({ detail: { node, event, element } }) {
|
|
275
|
-
// here we
|
|
273
|
+
// here we assume that highlightType is correctly calculated in handleDragOver
|
|
276
274
|
if (!dragAndDrop || draggedNode === null || insertionType === InsertionType.none) {
|
|
277
275
|
event.preventDefault();
|
|
278
276
|
return;
|
|
@@ -285,7 +283,7 @@ function onDragDrop({ detail: { node, event, element } }) {
|
|
|
285
283
|
insertType: insertionType
|
|
286
284
|
});
|
|
287
285
|
}
|
|
288
|
-
// handle
|
|
286
|
+
// handle highlighting
|
|
289
287
|
function onDragEnter({ detail: { node, event, element } }) {
|
|
290
288
|
highlightedNode = null;
|
|
291
289
|
if (!draggedNode || !dragAndDrop) {
|
|
@@ -35,14 +35,14 @@ declare const __propDef: {
|
|
|
35
35
|
* TODO find better name
|
|
36
36
|
*/ selectionMode?: SelectionModes | undefined;
|
|
37
37
|
/**
|
|
38
|
-
* By default, in recursive mode, non-leaf checkboxes will select/
|
|
39
|
-
* If you set this to true, this
|
|
38
|
+
* By default, in recursive mode, non-leaf checkboxes will select/deselect all its children
|
|
39
|
+
* If you set this to true, this behavior will be disabled and only leaf nodes will be selectable
|
|
40
40
|
*/ onlyLeafCheckboxes?: boolean | undefined;
|
|
41
41
|
/**
|
|
42
42
|
* Instead of showing disabled checkboxes, show blank space
|
|
43
43
|
*/ hideDisabledCheckboxes?: boolean | undefined;
|
|
44
44
|
/**
|
|
45
|
-
* Function that will be
|
|
45
|
+
* Function that will be caged when node is expanded and useCallback is set to true
|
|
46
46
|
* It should return array of nodes that will be added to tree
|
|
47
47
|
* If it throws error, node will be collapsed,
|
|
48
48
|
* but user will be able to open it again and callback will be called
|
|
@@ -52,16 +52,16 @@ declare const __propDef: {
|
|
|
52
52
|
* Its defined in slot context-menu
|
|
53
53
|
*/ showContextMenu?: boolean | undefined;
|
|
54
54
|
/**
|
|
55
|
-
*
|
|
55
|
+
* Automatically expand nodes to this level,
|
|
56
56
|
* any user made expansion will override this.
|
|
57
57
|
*/ expandTo?: number | undefined;
|
|
58
58
|
/**
|
|
59
|
-
*
|
|
59
|
+
* Threshold for automatic expansion. If tree has less or equal nodes than this value,
|
|
60
60
|
* all nodes will be expanded. Default is 0, which means no automatic expansion
|
|
61
|
-
*/
|
|
61
|
+
*/ expansionThreshold?: number | undefined;
|
|
62
62
|
/**
|
|
63
63
|
* Classes used in tree. You can override default classes with this prop.
|
|
64
|
-
* It is recommended to use default classes and add
|
|
64
|
+
* It is recommended to use default classes and add additional styles in your css
|
|
65
65
|
*/ customClasses?: Partial<CustomizableClasses> | undefined;
|
|
66
66
|
/**
|
|
67
67
|
* Function used to filter what nodes should be shown.
|
|
@@ -83,9 +83,9 @@ declare const __propDef: {
|
|
|
83
83
|
* If true, keyboard navigation will be enabled. Use arrow keys to navigate and space to select node.
|
|
84
84
|
*/ allowKeyboardNavigation?: boolean | undefined;
|
|
85
85
|
changeAllExpansion?: ((changeTo: boolean) => void) | undefined;
|
|
86
|
-
expandToNode?: ((
|
|
86
|
+
expandToNode?: ((targetNodePath: string) => void) | undefined;
|
|
87
87
|
setNodeExpansion?: ((nodePath: string, changeTo: boolean) => void) | undefined;
|
|
88
|
-
setExpansions?: ((expansions:
|
|
88
|
+
setExpansions?: ((expansions: string[]) => void) | undefined;
|
|
89
89
|
focusNode?: ((nodePath: string | null) => void) | undefined;
|
|
90
90
|
focusFirstNode?: (() => Node | null) | undefined;
|
|
91
91
|
};
|
|
@@ -118,9 +118,9 @@ export type TreeViewEvents = typeof __propDef.events;
|
|
|
118
118
|
export type TreeViewSlots = typeof __propDef.slots;
|
|
119
119
|
export default class TreeView extends SvelteComponent<TreeViewProps, TreeViewEvents, TreeViewSlots> {
|
|
120
120
|
get changeAllExpansion(): (changeTo: boolean) => void;
|
|
121
|
-
get expandToNode(): (
|
|
121
|
+
get expandToNode(): (targetNodePath: string) => void;
|
|
122
122
|
get setNodeExpansion(): (nodePath: string, changeTo: boolean) => void;
|
|
123
|
-
get setExpansions(): (expansions:
|
|
123
|
+
get setExpansions(): (expansions: string[]) => void;
|
|
124
124
|
get focusNode(): (nodePath: string | null) => void;
|
|
125
125
|
get focusFirstNode(): () => Node | null;
|
|
126
126
|
}
|
package/dist/constants.js
CHANGED
|
@@ -16,7 +16,7 @@ export const defaultClasses = {
|
|
|
16
16
|
nodeClass: '',
|
|
17
17
|
expandIcon: 'far fa-fw fa-plus-square',
|
|
18
18
|
collapseIcon: 'far fa-fw fa-minus-square',
|
|
19
|
-
|
|
19
|
+
insertLineClass: '',
|
|
20
20
|
nestIcon: 'fas fa-level-down-alt'
|
|
21
21
|
};
|
|
22
22
|
export const defaultConfig = {
|
|
@@ -16,15 +16,17 @@ export declare class TreeHelper {
|
|
|
16
16
|
mergeTrees(oldTree: Tree, addedTree: Tree, nodePath?: string): Node[];
|
|
17
17
|
/** toggles expansion on
|
|
18
18
|
*/
|
|
19
|
-
changeExpansion(
|
|
20
|
-
/**
|
|
19
|
+
changeExpansion(targetNodePath: string, changeTo: boolean, previousExpandedPaths: string[]): string[];
|
|
20
|
+
/**
|
|
21
|
+
* returns path of every node, that is at or above given depth level
|
|
21
22
|
*/
|
|
22
|
-
|
|
23
|
+
getNodesAbove(tree: Tree, depth: number): Node[];
|
|
23
24
|
getDepthLevel(nodePath: string): number;
|
|
24
25
|
searchTree(tree: Tree, filter: FilterFunction | null): {
|
|
25
26
|
count: number;
|
|
26
27
|
tree: Tree;
|
|
27
28
|
};
|
|
29
|
+
getParentsPaths(targetNodePath: string): string[];
|
|
28
30
|
getParents(tree: Tree, targetNode: Node): Node[];
|
|
29
31
|
/** orders nodes by priorityProp
|
|
30
32
|
*/
|
|
@@ -39,7 +39,7 @@ export class TreeHelper {
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
//#region basic
|
|
42
|
+
//#region basic helpers
|
|
43
43
|
getParentNodePath(nodePath) {
|
|
44
44
|
if (nodePath == null)
|
|
45
45
|
throw new Error('cannot get parent of root');
|
|
@@ -89,25 +89,21 @@ export class TreeHelper {
|
|
|
89
89
|
}
|
|
90
90
|
/** toggles expansion on
|
|
91
91
|
*/
|
|
92
|
-
changeExpansion(
|
|
92
|
+
changeExpansion(targetNodePath, changeTo, previousExpandedPaths) {
|
|
93
93
|
// const nodeId = node.id ?? '';
|
|
94
|
-
if (!
|
|
95
|
-
return
|
|
94
|
+
if (!targetNodePath) {
|
|
95
|
+
return previousExpandedPaths;
|
|
96
96
|
}
|
|
97
97
|
if (changeTo === true) {
|
|
98
|
-
return [...
|
|
98
|
+
return [...previousExpandedPaths, targetNodePath];
|
|
99
99
|
}
|
|
100
|
-
return
|
|
100
|
+
return previousExpandedPaths.filter((x) => x !== targetNodePath);
|
|
101
101
|
}
|
|
102
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* returns path of every node, that is at or above given depth level
|
|
103
104
|
*/
|
|
104
|
-
|
|
105
|
-
return tree
|
|
106
|
-
.filter((node) => node.expanded == undefined &&
|
|
107
|
-
node.expanded == null &&
|
|
108
|
-
node.useCallback != true &&
|
|
109
|
-
this.getDepthLevel(node.path) <= level)
|
|
110
|
-
.map((node) => node.id ?? '');
|
|
105
|
+
getNodesAbove(tree, depth) {
|
|
106
|
+
return tree.filter((node) => this.getDepthLevel(node.path) <= depth);
|
|
111
107
|
}
|
|
112
108
|
//based on number of dots
|
|
113
109
|
getDepthLevel(nodePath) {
|
|
@@ -132,10 +128,10 @@ export class TreeHelper {
|
|
|
132
128
|
const uniqueNodes = uniqueBy(resultNodes, (node) => node.path);
|
|
133
129
|
return { count: filteredNodes.length, tree: uniqueNodes };
|
|
134
130
|
}
|
|
135
|
-
|
|
131
|
+
getParentsPaths(targetNodePath) {
|
|
136
132
|
const parentsPaths = [];
|
|
137
133
|
// TODO refactor
|
|
138
|
-
let nodePath =
|
|
134
|
+
let nodePath = targetNodePath;
|
|
139
135
|
// get all parents
|
|
140
136
|
while (nodePath !== null && nodePath !== '') {
|
|
141
137
|
nodePath = this.getParentNodePath(nodePath);
|
|
@@ -144,6 +140,13 @@ export class TreeHelper {
|
|
|
144
140
|
}
|
|
145
141
|
parentsPaths.push(nodePath);
|
|
146
142
|
}
|
|
143
|
+
return parentsPaths;
|
|
144
|
+
}
|
|
145
|
+
getParents(tree, targetNode) {
|
|
146
|
+
if (!targetNode) {
|
|
147
|
+
return [];
|
|
148
|
+
}
|
|
149
|
+
const parentsPaths = this.getParentsPaths(targetNode.path);
|
|
147
150
|
//find nodes for given ids
|
|
148
151
|
const parentNodes = tree.filter((node) => parentsPaths.some((parentNodePath) => node.path === parentNodePath));
|
|
149
152
|
return parentNodes;
|
|
@@ -151,7 +154,7 @@ export class TreeHelper {
|
|
|
151
154
|
/** orders nodes by priorityProp
|
|
152
155
|
*/
|
|
153
156
|
orderByPriority(tree) {
|
|
154
|
-
// TODO
|
|
157
|
+
// TODO investigate that it really works
|
|
155
158
|
tree.sort((a, b) => (b.priority ? a.priority - b.priority : 1));
|
|
156
159
|
return tree;
|
|
157
160
|
}
|
|
@@ -3,7 +3,7 @@ import { type Node, InsertionType } from '../types.js';
|
|
|
3
3
|
export declare class DragDropProvider {
|
|
4
4
|
helper: TreeHelper;
|
|
5
5
|
constructor(treeHelper: TreeHelper);
|
|
6
|
-
getInsertionPosition(
|
|
6
|
+
getInsertionPosition(draggedNode: Node, draggedOverNode: Node, e: DragEvent, element: HTMLElement, nest: boolean): InsertionType;
|
|
7
7
|
getRelativePosition(element: Element, e: DragEvent): InsertionType;
|
|
8
8
|
isDropAllowed(draggedNode: Node, targeNode: Node): boolean;
|
|
9
9
|
}
|
|
@@ -4,7 +4,7 @@ export class DragDropProvider {
|
|
|
4
4
|
constructor(treeHelper) {
|
|
5
5
|
this.helper = treeHelper;
|
|
6
6
|
}
|
|
7
|
-
getInsertionPosition(
|
|
7
|
+
getInsertionPosition(draggedNode, draggedOverNode, e, element, nest) {
|
|
8
8
|
if (nest && draggedOverNode.nestAllowed) {
|
|
9
9
|
return InsertionType.nest;
|
|
10
10
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TreeHelper } from '../helpers/tree-helper.js';
|
|
1
|
+
import type { TreeHelper } from '../helpers/tree-helper.js';
|
|
2
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;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { TreeHelper } from '../helpers/tree-helper.js';
|
|
2
1
|
import { KeyboardMovement as MovementDirection } from '../types.js';
|
|
3
2
|
export function calculateNewFocusedNode(helper, tree, targetNode, movementDirection) {
|
|
4
3
|
// TODO this could use some refactoring
|
|
@@ -65,7 +64,7 @@ export function calculateNewFocusedNode(helper, tree, targetNode, movementDirect
|
|
|
65
64
|
return wrapReturn(targetNode);
|
|
66
65
|
}
|
|
67
66
|
const parentNode = helper.findNode(tree, parentNodePath);
|
|
68
|
-
//
|
|
67
|
+
// assertion
|
|
69
68
|
if (!parentNode) {
|
|
70
69
|
console.warn('Parent node not found, this should never happen');
|
|
71
70
|
return wrapReturn(targetNode);
|
|
@@ -113,7 +113,7 @@ export class SelectionProvider {
|
|
|
113
113
|
directChildrenStates.push(result.state);
|
|
114
114
|
}
|
|
115
115
|
});
|
|
116
|
-
// if
|
|
116
|
+
// if it doesn't have any children, mark it as selected but ignore it in upstream calculations
|
|
117
117
|
const ignore = directChildrenStates.length === 0;
|
|
118
118
|
return { ignore, state: this.computeVisualState(directChildrenStates) };
|
|
119
119
|
}
|
|
@@ -122,7 +122,7 @@ export class SelectionProvider {
|
|
|
122
122
|
tree.forEach((node) => {
|
|
123
123
|
// match itself and all children
|
|
124
124
|
if (node.path?.startsWith(parentNodePath ? parentNodePath + this.helper.config.separator : '')) {
|
|
125
|
-
//
|
|
125
|
+
//don't change if not selectable
|
|
126
126
|
if (!isSelectable(node, SelectionModes.all)) {
|
|
127
127
|
return;
|
|
128
128
|
}
|
|
@@ -148,6 +148,6 @@ export function isSelectable(node, showCheckboxes) {
|
|
|
148
148
|
if (showCheckboxes === SelectionModes.perNode) {
|
|
149
149
|
return node.checkbox === true;
|
|
150
150
|
}
|
|
151
|
-
//
|
|
151
|
+
//don't show at all
|
|
152
152
|
return false;
|
|
153
153
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -55,11 +55,11 @@ export type CustomizableClasses = {
|
|
|
55
55
|
collapseIcon: string;
|
|
56
56
|
nestIcon: string;
|
|
57
57
|
expandClass: string;
|
|
58
|
-
|
|
58
|
+
insertLineClass: string;
|
|
59
59
|
currentlyDraggedClass: string;
|
|
60
60
|
};
|
|
61
|
-
export type DragEnterCallback = (
|
|
62
|
-
export type BeforeMovedCallback = (
|
|
61
|
+
export type DragEnterCallback = (draggedNode: Node, targetNode: Node) => Promise<boolean>;
|
|
62
|
+
export type BeforeMovedCallback = (draggedNode: Node, oldParent: Node, newParent: Node, insertionType: string) => boolean;
|
|
63
63
|
export type ExpandedCallback = (node: Node) => Promise<void>;
|
|
64
64
|
export type HelperConfig = {
|
|
65
65
|
separator: string;
|