2023-06-12 13:46:38 +07:00
|
|
|
import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
2023-06-10 13:06:02 +07:00
|
|
|
import { Fragment, jsx, jsxs } from 'preact/jsx-runtime'
|
|
|
|
import { toJsxRuntime } from "hast-util-to-jsx-runtime"
|
|
|
|
|
2023-06-18 06:05:46 +07:00
|
|
|
// @ts-ignore
|
|
|
|
import popoverScript from './scripts/popover.inline'
|
|
|
|
import popoverStyle from './styles/popover.scss'
|
|
|
|
|
|
|
|
interface Options {
|
|
|
|
enablePopover: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
const defaultOptions: Options = {
|
|
|
|
enablePopover: true
|
2023-06-10 13:06:02 +07:00
|
|
|
}
|
2023-06-12 13:46:38 +07:00
|
|
|
|
2023-06-18 06:05:46 +07:00
|
|
|
export default ((opts?: Partial<Options>) => {
|
|
|
|
function Content({ tree }: QuartzComponentProps) {
|
|
|
|
// @ts-ignore (preact makes it angry)
|
|
|
|
const content = toJsxRuntime(tree, { Fragment, jsx, jsxs, elementAttributeNameCase: 'html' })
|
|
|
|
return <article>{content}</article>
|
|
|
|
}
|
|
|
|
|
|
|
|
const enablePopover = opts?.enablePopover ?? defaultOptions.enablePopover
|
|
|
|
if (enablePopover) {
|
|
|
|
Content.afterDOMLoaded = popoverScript
|
|
|
|
Content.css = popoverStyle
|
|
|
|
}
|
|
|
|
|
|
|
|
return Content
|
|
|
|
}) satisfies QuartzComponentConstructor
|