mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-23 21:04:07 -06:00
Merge ac1c0a24a2 into 8d19bc3f4a
This commit is contained in:
commit
236f33beed
@ -61,7 +61,7 @@ export default ((userOpts?: Partial<Options>) => {
|
|||||||
|
|
||||||
const Explorer: QuartzComponent = ({ cfg, displayClass }: QuartzComponentProps) => {
|
const Explorer: QuartzComponent = ({ cfg, displayClass }: QuartzComponentProps) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<nav
|
||||||
class={classNames(displayClass, "explorer")}
|
class={classNames(displayClass, "explorer")}
|
||||||
data-behavior={opts.folderClickBehavior}
|
data-behavior={opts.folderClickBehavior}
|
||||||
data-collapsed={opts.folderDefaultState}
|
data-collapsed={opts.folderDefaultState}
|
||||||
@ -78,6 +78,7 @@ export default ((userOpts?: Partial<Options>) => {
|
|||||||
class="explorer-toggle mobile-explorer hide-until-loaded"
|
class="explorer-toggle mobile-explorer hide-until-loaded"
|
||||||
data-mobile={true}
|
data-mobile={true}
|
||||||
aria-controls="explorer-content"
|
aria-controls="explorer-content"
|
||||||
|
aria-label="Explorer"
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
@ -116,7 +117,7 @@ export default ((userOpts?: Partial<Options>) => {
|
|||||||
<polyline points="6 9 12 15 18 9"></polyline>
|
<polyline points="6 9 12 15 18 9"></polyline>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
<div class="explorer-content" aria-expanded={false}>
|
<div id="explorer-content">
|
||||||
<OverflowList class="explorer-ul" />
|
<OverflowList class="explorer-ul" />
|
||||||
</div>
|
</div>
|
||||||
<template id="template-file">
|
<template id="template-file">
|
||||||
@ -152,7 +153,7 @@ export default ((userOpts?: Partial<Options>) => {
|
|||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</nav>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,8 @@
|
|||||||
import { JSX } from "preact"
|
import { JSX } from "preact"
|
||||||
|
|
||||||
const OverflowList = ({
|
const OverflowList = ({ children, ...props }: JSX.HTMLAttributes<HTMLUListElement>) => {
|
||||||
children,
|
|
||||||
...props
|
|
||||||
}: JSX.HTMLAttributes<HTMLUListElement> & { id: string }) => {
|
|
||||||
return (
|
return (
|
||||||
<ul {...props} class={[props.class, "overflow"].filter(Boolean).join(" ")} id={props.id}>
|
<ul {...props} class={[props.class, "overflow"].filter(Boolean).join(" ")}>
|
||||||
{children}
|
{children}
|
||||||
<li class="overflow-end" />
|
<li class="overflow-end" />
|
||||||
</ul>
|
</ul>
|
||||||
@ -14,11 +11,11 @@ const OverflowList = ({
|
|||||||
|
|
||||||
let numExplorers = 0
|
let numExplorers = 0
|
||||||
export default () => {
|
export default () => {
|
||||||
const id = `list-${numExplorers++}`
|
const dataId = `list-${numExplorers++}`
|
||||||
|
|
||||||
return {
|
return {
|
||||||
OverflowList: (props: JSX.HTMLAttributes<HTMLUListElement>) => (
|
OverflowList: (props: JSX.HTMLAttributes<HTMLUListElement>) => (
|
||||||
<OverflowList {...props} id={id} />
|
<OverflowList {...props} data-list-id={dataId} />
|
||||||
),
|
),
|
||||||
overflowListAfterDOMLoaded: `
|
overflowListAfterDOMLoaded: `
|
||||||
document.addEventListener("nav", (e) => {
|
document.addEventListener("nav", (e) => {
|
||||||
@ -34,7 +31,7 @@ document.addEventListener("nav", (e) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const ul = document.getElementById("${id}")
|
const ul = document.querySelector("ul[data-list-id='${dataId}']")
|
||||||
if (!ul) return
|
if (!ul) return
|
||||||
|
|
||||||
const end = ul.querySelector(".overflow-end")
|
const end = ul.querySelector(".overflow-end")
|
||||||
|
|||||||
@ -34,10 +34,11 @@ export default ((opts?: Partial<Options>) => {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class={fileData.collapseToc ? "collapsed toc-header" : "toc-header"}
|
class={fileData.collapseToc ? "collapsed toc-header" : "toc-header"}
|
||||||
|
aria-labelledby="toc-heading"
|
||||||
aria-controls="toc-content"
|
aria-controls="toc-content"
|
||||||
aria-expanded={!fileData.collapseToc}
|
aria-expanded={!fileData.collapseToc}
|
||||||
>
|
>
|
||||||
<h3>{i18n(cfg.locale).components.tableOfContents.title}</h3>
|
<h3 id="toc-heading">{i18n(cfg.locale).components.tableOfContents.title}</h3>
|
||||||
<svg
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
width="24"
|
width="24"
|
||||||
@ -53,7 +54,7 @@ export default ((opts?: Partial<Options>) => {
|
|||||||
<polyline points="6 9 12 15 18 9"></polyline>
|
<polyline points="6 9 12 15 18 9"></polyline>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
<OverflowList class={fileData.collapseToc ? "collapsed toc-content" : "toc-content"}>
|
<OverflowList id="toc-content" class={fileData.collapseToc ? "collapsed" : ""}>
|
||||||
{fileData.toc.map((tocEntry) => (
|
{fileData.toc.map((tocEntry) => (
|
||||||
<li key={tocEntry.slug} class={`depth-${tocEntry.depth}`}>
|
<li key={tocEntry.slug} class={`depth-${tocEntry.depth}`}>
|
||||||
<a href={`#${tocEntry.slug}`} data-for={tocEntry.slug}>
|
<a href={`#${tocEntry.slug}`} data-for={tocEntry.slug}>
|
||||||
|
|||||||
@ -151,7 +151,7 @@ function createFolderNode(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function setupExplorer(currentSlug: FullSlug) {
|
async function setupExplorer(currentSlug: FullSlug) {
|
||||||
const allExplorers = document.querySelectorAll("div.explorer") as NodeListOf<HTMLElement>
|
const allExplorers = document.querySelectorAll("nav.explorer") as NodeListOf<HTMLElement>
|
||||||
|
|
||||||
for (const explorer of allExplorers) {
|
for (const explorer of allExplorers) {
|
||||||
const dataFns = JSON.parse(explorer.dataset.dataFns || "{}")
|
const dataFns = JSON.parse(explorer.dataset.dataFns || "{}")
|
||||||
|
|||||||
@ -27,7 +27,7 @@ function toggleToc(this: HTMLElement) {
|
|||||||
function setupToc() {
|
function setupToc() {
|
||||||
for (const toc of document.getElementsByClassName("toc")) {
|
for (const toc of document.getElementsByClassName("toc")) {
|
||||||
const button = toc.querySelector(".toc-header")
|
const button = toc.querySelector(".toc-header")
|
||||||
const content = toc.querySelector(".toc-content")
|
const content = toc.querySelector("#toc-content")
|
||||||
if (!button || !content) return
|
if (!button || !content) return
|
||||||
button.addEventListener("click", toggleToc)
|
button.addEventListener("click", toggleToc)
|
||||||
window.addCleanup(() => button.removeEventListener("click", toggleToc))
|
window.addCleanup(() => button.removeEventListener("click", toggleToc))
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hide-until-loaded ~ .explorer-content {
|
.hide-until-loaded ~ #explorer-content {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,7 +108,7 @@ button.desktop-explorer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.explorer-content {
|
#explorer-content {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
@ -215,7 +215,7 @@ li:has(> .folder-outer:not(.open)) > .folder-container > svg {
|
|||||||
&.collapsed {
|
&.collapsed {
|
||||||
flex: 0 0 34px;
|
flex: 0 0 34px;
|
||||||
|
|
||||||
& > .explorer-content {
|
& > #explorer-content {
|
||||||
transform: translateX(-100vw);
|
transform: translateX(-100vw);
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
}
|
}
|
||||||
@ -224,13 +224,13 @@ li:has(> .folder-outer:not(.open)) > .folder-container > svg {
|
|||||||
&:not(.collapsed) {
|
&:not(.collapsed) {
|
||||||
flex: 0 0 34px;
|
flex: 0 0 34px;
|
||||||
|
|
||||||
& > .explorer-content {
|
& > #explorer-content {
|
||||||
transform: translateX(0);
|
transform: translateX(0);
|
||||||
visibility: visible;
|
visibility: visible;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.explorer-content {
|
#explorer-content {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
z-index: 100;
|
z-index: 100;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|||||||
@ -38,7 +38,7 @@ button.toc-header {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ul.toc-content.overflow {
|
ul#toc-content.overflow {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
position: relative;
|
position: relative;
|
||||||
margin: 0.5rem 0;
|
margin: 0.5rem 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user