mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-24 13:29:14 +01:00
Remove usePagePath
This commit is contained in:
@@ -13,7 +13,6 @@ const defaultOptions = {
|
|||||||
folderClickBehavior: "collapse",
|
folderClickBehavior: "collapse",
|
||||||
folderDefaultState: "collapsed",
|
folderDefaultState: "collapsed",
|
||||||
useSavedState: true,
|
useSavedState: true,
|
||||||
usePagePath: false,
|
|
||||||
mapFn: (node) => {
|
mapFn: (node) => {
|
||||||
return node
|
return node
|
||||||
},
|
},
|
||||||
@@ -70,8 +69,7 @@ export default ((userOpts?: Partial<Options>) => {
|
|||||||
// Get all folders of tree. Initialize with collapsed state
|
// Get all folders of tree. Initialize with collapsed state
|
||||||
// Stringify to pass json tree as data attribute ([data-tree])
|
// Stringify to pass json tree as data attribute ([data-tree])
|
||||||
const folders = fileTree.getFolderPaths(
|
const folders = fileTree.getFolderPaths(
|
||||||
opts.folderDefaultState === "collapsed",
|
opts.folderDefaultState === "collapsed"
|
||||||
currentFilePath,
|
|
||||||
)
|
)
|
||||||
jsonTree = JSON.stringify(folders)
|
jsonTree = JSON.stringify(folders)
|
||||||
}
|
}
|
||||||
@@ -97,7 +95,6 @@ export default ((userOpts?: Partial<Options>) => {
|
|||||||
data-behavior={opts.folderClickBehavior}
|
data-behavior={opts.folderClickBehavior}
|
||||||
data-collapsed={opts.folderDefaultState}
|
data-collapsed={opts.folderDefaultState}
|
||||||
data-savestate={opts.useSavedState}
|
data-savestate={opts.useSavedState}
|
||||||
data-pagepathstate={opts.usePagePath}
|
|
||||||
data-tree={jsonTree}
|
data-tree={jsonTree}
|
||||||
data-mobile={true}
|
data-mobile={true}
|
||||||
aria-controls="explorer-content"
|
aria-controls="explorer-content"
|
||||||
@@ -125,7 +122,6 @@ export default ((userOpts?: Partial<Options>) => {
|
|||||||
data-behavior={opts.folderClickBehavior}
|
data-behavior={opts.folderClickBehavior}
|
||||||
data-collapsed={opts.folderDefaultState}
|
data-collapsed={opts.folderDefaultState}
|
||||||
data-savestate={opts.useSavedState}
|
data-savestate={opts.useSavedState}
|
||||||
data-pagepathstate={opts.usePagePath}
|
|
||||||
data-tree={jsonTree}
|
data-tree={jsonTree}
|
||||||
data-mobile={false}
|
data-mobile={false}
|
||||||
aria-controls="explorer-content"
|
aria-controls="explorer-content"
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ export interface Options {
|
|||||||
folderDefaultState: "collapsed" | "open"
|
folderDefaultState: "collapsed" | "open"
|
||||||
folderClickBehavior: "collapse" | "link"
|
folderClickBehavior: "collapse" | "link"
|
||||||
useSavedState: boolean
|
useSavedState: boolean
|
||||||
usePagePath: boolean
|
|
||||||
sortFn: (a: FileNode, b: FileNode) => number
|
sortFn: (a: FileNode, b: FileNode) => number
|
||||||
filterFn: (node: FileNode) => boolean
|
filterFn: (node: FileNode) => boolean
|
||||||
mapFn: (node: FileNode) => void
|
mapFn: (node: FileNode) => void
|
||||||
@@ -125,20 +124,16 @@ export class FileNode {
|
|||||||
* Get folder representation with state of tree.
|
* Get folder representation with state of tree.
|
||||||
* Intended to only be called on root node before changes to the tree are made
|
* 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)
|
* @param collapsed default state of folders (collapsed by default or not)
|
||||||
* @param currentFile current file
|
|
||||||
* @returns array containing folder state for tree
|
* @returns array containing folder state for tree
|
||||||
*/
|
*/
|
||||||
getFolderPaths(collapsed: boolean, currentFile: string): FolderState[] {
|
getFolderPaths(collapsed: boolean): FolderState[] {
|
||||||
const folderPaths: FolderState[] = []
|
const folderPaths: FolderState[] = []
|
||||||
|
|
||||||
const traverse = (node: FileNode, currentPath: string) => {
|
const traverse = (node: FileNode, currentPath: string) => {
|
||||||
if (!node.file) {
|
if (!node.file) {
|
||||||
const folderPath = joinSegments(currentPath, node.name)
|
const folderPath = joinSegments(currentPath, node.name)
|
||||||
const collapseState = !currentFile.includes(
|
|
||||||
folderPath.replace("'", "-").replaceAll("../", ""),
|
|
||||||
)
|
|
||||||
if (folderPath !== "") {
|
if (folderPath !== "") {
|
||||||
folderPaths.push({ path: folderPath, collapsed: collapseState || collapsed })
|
folderPaths.push({ path: folderPath, collapsed })
|
||||||
}
|
}
|
||||||
|
|
||||||
node.children.forEach((child) => traverse(child, folderPath))
|
node.children.forEach((child) => traverse(child, folderPath))
|
||||||
|
|||||||
@@ -88,7 +88,6 @@ function setupExplorer() {
|
|||||||
|
|
||||||
// Convert to bool
|
// Convert to bool
|
||||||
const useSavedFolderState = explorer?.dataset.savestate === "true"
|
const useSavedFolderState = explorer?.dataset.savestate === "true"
|
||||||
const usePagePathState = explorer?.dataset.pagepathstate === "true"
|
|
||||||
|
|
||||||
if (explorer) {
|
if (explorer) {
|
||||||
// Get config
|
// Get config
|
||||||
@@ -129,7 +128,7 @@ function setupExplorer() {
|
|||||||
for (const { path, collapsed } of newExplorerState) {
|
for (const { path, collapsed } of newExplorerState) {
|
||||||
currentExplorerState.push({
|
currentExplorerState.push({
|
||||||
path,
|
path,
|
||||||
collapsed: usePagePathState ? (oldIndex.get(path) ?? collapsed) : collapsed,
|
collapsed: oldIndex.get(path) ?? collapsed,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user