Remove usePagePath

This commit is contained in:
saberzero1 2024-10-03 22:13:46 +02:00
parent 26e0b4390b
commit 40ca67c8c6
No known key found for this signature in database
GPG Key ID: 41AEE99107640F10
3 changed files with 4 additions and 14 deletions

View File

@ -13,7 +13,6 @@ const defaultOptions = {
folderClickBehavior: "collapse",
folderDefaultState: "collapsed",
useSavedState: true,
usePagePath: false,
mapFn: (node) => {
return node
},
@ -70,8 +69,7 @@ export default ((userOpts?: Partial<Options>) => {
// Get all folders of tree. Initialize with collapsed state
// Stringify to pass json tree as data attribute ([data-tree])
const folders = fileTree.getFolderPaths(
opts.folderDefaultState === "collapsed",
currentFilePath,
opts.folderDefaultState === "collapsed"
)
jsonTree = JSON.stringify(folders)
}
@ -97,7 +95,6 @@ export default ((userOpts?: Partial<Options>) => {
data-behavior={opts.folderClickBehavior}
data-collapsed={opts.folderDefaultState}
data-savestate={opts.useSavedState}
data-pagepathstate={opts.usePagePath}
data-tree={jsonTree}
data-mobile={true}
aria-controls="explorer-content"
@ -125,7 +122,6 @@ export default ((userOpts?: Partial<Options>) => {
data-behavior={opts.folderClickBehavior}
data-collapsed={opts.folderDefaultState}
data-savestate={opts.useSavedState}
data-pagepathstate={opts.usePagePath}
data-tree={jsonTree}
data-mobile={false}
aria-controls="explorer-content"

View File

@ -16,7 +16,6 @@ export interface Options {
folderDefaultState: "collapsed" | "open"
folderClickBehavior: "collapse" | "link"
useSavedState: boolean
usePagePath: boolean
sortFn: (a: FileNode, b: FileNode) => number
filterFn: (node: FileNode) => boolean
mapFn: (node: FileNode) => void
@ -125,20 +124,16 @@ export class FileNode {
* 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)
* @param currentFile current file
* @returns array containing folder state for tree
*/
getFolderPaths(collapsed: boolean, currentFile: string): FolderState[] {
getFolderPaths(collapsed: boolean): FolderState[] {
const folderPaths: FolderState[] = []
const traverse = (node: FileNode, currentPath: string) => {
if (!node.file) {
const folderPath = joinSegments(currentPath, node.name)
const collapseState = !currentFile.includes(
folderPath.replace("'", "-").replaceAll("../", ""),
)
if (folderPath !== "") {
folderPaths.push({ path: folderPath, collapsed: collapseState || collapsed })
folderPaths.push({ path: folderPath, collapsed })
}
node.children.forEach((child) => traverse(child, folderPath))

View File

@ -88,7 +88,6 @@ function setupExplorer() {
// Convert to bool
const useSavedFolderState = explorer?.dataset.savestate === "true"
const usePagePathState = explorer?.dataset.pagepathstate === "true"
if (explorer) {
// Get config
@ -129,7 +128,7 @@ function setupExplorer() {
for (const { path, collapsed } of newExplorerState) {
currentExplorerState.push({
path,
collapsed: usePagePathState ? (oldIndex.get(path) ?? collapsed) : collapsed,
collapsed: oldIndex.get(path) ?? collapsed,
})
}