From 3d8c470c0d298f720614318fb4c14575e72bbd2e Mon Sep 17 00:00:00 2001
From: Ben Schlegel <ben5.schlegel@gmail.com>
Date: Sat, 16 Sep 2023 17:35:27 +0000
Subject: [PATCH] feat(explorer): implement `map` fn argument
---
quartz/components/ExplorerNode.tsx | 18 +++++++++++++++++-
1 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/quartz/components/ExplorerNode.tsx b/quartz/components/ExplorerNode.tsx
index 40e526a..b8d8c14 100644
--- a/quartz/components/ExplorerNode.tsx
+++ b/quartz/components/ExplorerNode.tsx
@@ -1,5 +1,5 @@
// @ts-ignore
-import { QuartzPluginData } from "vfile"
+import { QuartzPluginData } from "../plugins/vfile"
import { resolveRelative } from "../util/path"
export interface Options {
@@ -8,6 +8,8 @@
folderClickBehavior: "collapse" | "link"
useSavedState: boolean
sortFn: (a: FileNode, b: FileNode) => number
+ filterFn?: (node: FileNode) => boolean
+ mapFn?: (node: FileNode) => void
}
type DataWrapper = {
@@ -66,6 +68,10 @@
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) {
const filteredNodes: FileNode[] = []
@@ -82,6 +88,16 @@
}
/**
+ * Filter FileNode tree. Behaves similar to `Array.prototype.map()`, but modifies tree in place
+ * @param mapFn function to filter tree with
+ */
+ map(mapFn: (node: FileNode) => void) {
+ mapFn(this)
+
+ this.children.forEach((child) => child.map(mapFn))
+ }
+
+ /**
* Get folder representation with state of tree.
* Intended to only be called on root node before changes to the tree are made
* @param collapsed default state of folders (collapsed by default or not)
--
Gitblit v1.10.0