@keenmate/svelte-treeview 1.1.5 → 1.1.7
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/TreeView.svelte
CHANGED
|
@@ -129,7 +129,6 @@ $: helper = new TreeHelper({
|
|
|
129
129
|
$: dragAndDropProvider = new DragDropProvider(helper);
|
|
130
130
|
$: selectionProvider = new SelectionProvider(helper, recursiveSelection);
|
|
131
131
|
$: computedTree = computeTree(helper, selectionProvider, tree, filter, props, expandedPaths, value);
|
|
132
|
-
$: debugLog('computedTree', computedTree);
|
|
133
132
|
export function changeAllExpansion(changeTo) {
|
|
134
133
|
debugLog('changing expansion of every node to ', changeTo ? 'expanded' : 'collapsed');
|
|
135
134
|
if (changeTo) {
|
|
@@ -187,21 +186,24 @@ export function focusFirstNode() {
|
|
|
187
186
|
dispatch('focus', focusedNode);
|
|
188
187
|
return focusedNode;
|
|
189
188
|
}
|
|
190
|
-
function computeTree(helper, selectionProvider, userProvidedTree, filter, props,
|
|
189
|
+
function computeTree(helper, selectionProvider, userProvidedTree, filter, props, expandedPaths, value) {
|
|
191
190
|
if (!Array.isArray(userProvidedTree) || !Array.isArray(value)) {
|
|
192
191
|
console.error('value and tree must be arrays!!');
|
|
193
192
|
return [];
|
|
194
193
|
}
|
|
194
|
+
const start = Date.now();
|
|
195
195
|
const mappedTree = helper.mapTree(userProvidedTree, { ...defaultPropNames, ...props });
|
|
196
196
|
const { tree: filteredTree, count: filteredCount } = helper.searchTree(mappedTree, filter);
|
|
197
|
-
//
|
|
197
|
+
// threshold applies to nodes that match the filter, not all their parents
|
|
198
198
|
if (filteredCount <= expansionThreshold) {
|
|
199
|
-
|
|
199
|
+
expandedPaths = uniq([...expandedPaths, ...filteredTree.map((node) => node.path)]);
|
|
200
200
|
}
|
|
201
|
-
helper.markExpanded(filteredTree,
|
|
201
|
+
helper.markExpanded(filteredTree, expandedPaths);
|
|
202
202
|
// TODO here we could save last value and only recompute visual state if value changed
|
|
203
203
|
// or use diff to only update affected nodes
|
|
204
204
|
selectionProvider.markSelected(filteredTree, value);
|
|
205
|
+
const end = Date.now();
|
|
206
|
+
debugLog(`Tree computed in: ${end - start}`, computeTree);
|
|
205
207
|
return filteredTree;
|
|
206
208
|
}
|
|
207
209
|
function onExpand(detail) {
|
|
@@ -225,6 +227,9 @@ function onExpand(detail) {
|
|
|
225
227
|
}
|
|
226
228
|
}
|
|
227
229
|
function handleCallback(node) {
|
|
230
|
+
if (node.useCallback !== true) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
228
233
|
// only call on nodes with children
|
|
229
234
|
if (node.hasChildren !== true) {
|
|
230
235
|
return;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { type Node, type HelperConfig, type Tree, type
|
|
1
|
+
import { type Node, type HelperConfig, type Tree, type Props, type FilterFunction } from '../types.js';
|
|
2
2
|
export declare class TreeHelper {
|
|
3
3
|
config: HelperConfig;
|
|
4
4
|
constructor(config?: HelperConfig);
|
|
5
5
|
mapTree(tree: Tree, properties: Props): Node[];
|
|
6
|
-
markExpanded(tree: Tree,
|
|
6
|
+
markExpanded(tree: Tree, expandedPaths: string[]): void;
|
|
7
7
|
getParentNodePath(nodePath: string): string | null;
|
|
8
8
|
isChildrenOf(parentNodePath: string | null, childrenNodePath: string): boolean;
|
|
9
9
|
hasChildren(tree: Tree, nodePath: string): Node | undefined;
|
|
@@ -32,10 +32,10 @@ export class TreeHelper {
|
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
markExpanded(tree,
|
|
35
|
+
markExpanded(tree, expandedPaths) {
|
|
36
36
|
{
|
|
37
37
|
tree.forEach((node) => {
|
|
38
|
-
node.expanded =
|
|
38
|
+
node.expanded = expandedPaths.includes(node.path ?? '');
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
}
|