Jacky Zhao
2023-09-20 16d33fb77193710bede887d6a177d2144b78fb67
quartz/components/Explorer.tsx
@@ -6,15 +6,15 @@
import { ExplorerNode, FileNode, Options } from "./ExplorerNode"
// Options interface defined in `ExplorerNode` to avoid circular dependency
const defaultOptions = (): Options => ({
const defaultOptions = {
  title: "Explorer",
  folderClickBehavior: "collapse",
  folderDefaultState: "collapsed",
  useSavedState: true,
  // Sort order: folders first, then files. Sort folders and files alphabetically
  sortFn: (a, b) => {
    // Sort order: folders first, then files. Sort folders and files alphabetically
    if ((!a.file && !b.file) || (a.file && b.file)) {
      return a.name.localeCompare(b.name)
      return a.displayName.localeCompare(b.displayName)
    }
    if (a.file && !b.file) {
      return 1
@@ -22,12 +22,14 @@
      return -1
    }
  },
  filterFn: (node) => node.name !== "tags",
  order: ["filter", "map", "sort"],
})
} satisfies Options
export default ((userOpts?: Partial<Options>) => {
  function Explorer({ allFiles, displayClass, fileData }: QuartzComponentProps) {
    // Parse config
    const opts: Options = { ...defaultOptions(), ...userOpts }
    const opts: Options = { ...defaultOptions, ...userOpts }
    // Construct tree from allFiles
    const fileTree = new FileNode("")
@@ -78,7 +80,7 @@
          data-savestate={opts.useSavedState}
          data-tree={jsonTree}
        >
          <h3>{opts.title}</h3>
          <h1>{opts.title}</h1>
          <svg
            xmlns="http://www.w3.org/2000/svg"
            width="14"
@@ -95,8 +97,9 @@
          </svg>
        </button>
        <div id="explorer-content">
          <ul class="overflow">
          <ul class="overflow" id="explorer-ul">
            <ExplorerNode node={fileTree} opts={opts} fileData={fileData} />
            <li id="explorer-end" />
          </ul>
        </div>
      </div>