feat(explorer): integrate filter option
This commit is contained in:
parent
036a33f70b
commit
31d16fbd2c
@ -35,6 +35,11 @@ export default ((userOpts?: Partial<Options>) => {
|
|||||||
// Sort tree (folders first, then files (alphabetic))
|
// Sort tree (folders first, then files (alphabetic))
|
||||||
fileTree.sort(opts.sortFn!)
|
fileTree.sort(opts.sortFn!)
|
||||||
|
|
||||||
|
// If provided, apply filter function to fileTree
|
||||||
|
if (opts.filterFn) {
|
||||||
|
fileTree.filter(opts.filterFn)
|
||||||
|
}
|
||||||
|
|
||||||
// Get all folders of tree. Initialize with collapsed state
|
// Get all folders of tree. Initialize with collapsed state
|
||||||
const folders = fileTree.getFolderPaths(opts.folderDefaultState === "collapsed")
|
const folders = fileTree.getFolderPaths(opts.folderDefaultState === "collapsed")
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ export interface Options {
|
|||||||
folderClickBehavior: "collapse" | "link"
|
folderClickBehavior: "collapse" | "link"
|
||||||
useSavedState: boolean
|
useSavedState: boolean
|
||||||
sortFn: (a: FileNode, b: FileNode) => number
|
sortFn: (a: FileNode, b: FileNode) => number
|
||||||
|
filterFn?: (node: FileNode) => boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
type DataWrapper = {
|
type DataWrapper = {
|
||||||
@ -66,6 +67,10 @@ export class FileNode {
|
|||||||
this.children.forEach((e) => e.print(depth + 1))
|
this.children.forEach((e) => e.print(depth + 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter FileNode tree. Behaves similar to `Array.prototype.filter()`, but modifies tree in place
|
||||||
|
* @param filterFn function to filter tree with
|
||||||
|
*/
|
||||||
filter(filterFn: (node: FileNode) => boolean) {
|
filter(filterFn: (node: FileNode) => boolean) {
|
||||||
const filteredNodes: FileNode[] = []
|
const filteredNodes: FileNode[] = []
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user