@keenmate/svelte-treeview 0.3.1 → 0.3.2

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.
@@ -73,6 +73,15 @@ export let expandTo = 0;
73
73
  * It is recommended to use default classes and add aditinal styles in your css
74
74
  */
75
75
  export let customClasses = defaultClasses;
76
+ // use any so use doesnt have to cast from unknown
77
+ /**
78
+ * Function used to filter what nodes should be shown.
79
+ * Tree automatically adds all parents for nodes.
80
+ * User Higher order functions for reactive search.
81
+ * If you want to only search leaf nodes,
82
+ * its your responsibility to check if its hasChildren property is false
83
+ */
84
+ export let filter = (_) => true;
76
85
  /**
77
86
  * Log function that will be called when something happens in tree.
78
87
  * Used mostly for debugging
@@ -109,10 +118,11 @@ $: helper = new TreeHelper(propHelper, {
109
118
  checkboxes: selectionMode,
110
119
  separator
111
120
  });
121
+ $: filteredTree = helper.searchTree(tree, filter);
112
122
  // compute vissual tree still caleed twice, because if we force update changes tree
113
123
  // which fires this event again
114
124
  // TODO fix computeVisualTree beiing called twice
115
- $: recursiveSelection && selectionMode !== SelectionModes.none && computeVisualTree(tree),
125
+ $: recursiveSelection && selectionMode !== SelectionModes.none && computeVisualTree(filteredTree),
116
126
  forceUpdate();
117
127
  //if insert is disabled => nest right away and never nest if its disabled
118
128
  $: canNest =
@@ -371,7 +381,7 @@ function highlightInsert(node, highlitedNode, validTarget, canNest) {
371
381
  branchRootNode={null}
372
382
  {treeId}
373
383
  checkboxes={selectionMode}
374
- {tree}
384
+ tree={filteredTree}
375
385
  recursive={recursiveSelection}
376
386
  {onlyLeafCheckboxes}
377
387
  {hideDisabledCheckboxes}
@@ -56,6 +56,13 @@ declare const __propDef: {
56
56
  * Classes used in tree. You can override default classes with this prop.
57
57
  * It is recommended to use default classes and add aditinal styles in your css
58
58
  */ customClasses?: CustomizableClasses | undefined;
59
+ /**
60
+ * Function used to filter what nodes should be shown.
61
+ * Tree automatically adds all parents for nodes.
62
+ * User Higher order functions for reactive search.
63
+ * If you want to only search leaf nodes,
64
+ * its your responsibility to check if its hasChildren property is false
65
+ */ filter?: ((node: any) => boolean) | undefined;
59
66
  /**
60
67
  * Log function that will be called when something happens in tree.
61
68
  * Used mostly for debugging
@@ -29,6 +29,6 @@ export declare class TreeHelper {
29
29
  */
30
30
  expandToLevel(tree: Node[], level: number): unknown[];
31
31
  getDepthLevel(nodePath: NodePath): number;
32
- searchTree(tree: Node[], filter: (node: Node) => boolean, leafesOnly: boolean): unknown[];
32
+ searchTree(tree: Node[], filter: (node: unknown) => boolean): unknown[];
33
33
  getParents(tree: Node[], node: Node): unknown[];
34
34
  }
@@ -101,16 +101,11 @@ export class TreeHelper {
101
101
  return nodePath.split(separator).length - 1;
102
102
  }
103
103
  //#endregion
104
- searchTree(tree, filter, leafesOnly) {
105
- let filteredNodes;
106
- if (leafesOnly) {
107
- filteredNodes = this.getAllLeafNodes(tree).filter(filter);
108
- }
109
- else {
110
- filteredNodes = tree.filter(filter);
111
- }
104
+ searchTree(tree, filter) {
105
+ const filteredNodes = tree.filter(filter);
112
106
  const resultNodes = [];
113
- //console.log("matching nodes length:" + matchingPathes.length)
107
+ // add all parents from each node
108
+ // needed so that tree can be rendered
114
109
  filteredNodes.forEach((node) => {
115
110
  resultNodes.push(node);
116
111
  const parentNodes = this.getParents(tree, node);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keenmate/svelte-treeview",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package",