* init Signed-off-by: Innei <i@innei.in> * feat: feed column Signed-off-by: Innei <i@innei.in> * feat: float bar Signed-off-by: Innei <tukon479@gmail.com> * feat: profile button Signed-off-by: Innei <tukon479@gmail.com> * chore: comment Signed-off-by: Innei <tukon479@gmail.com> * feat: layout Signed-off-by: Innei <tukon479@gmail.com> * feat: split mobile entry content Signed-off-by: Innei <tukon479@gmail.com> * feat: add history stack Signed-off-by: Innei <tukon479@gmail.com> * feat: return back Signed-off-by: Innei <tukon479@gmail.com> * fix: return back position Signed-off-by: Innei <tukon479@gmail.com> * feat: entry list header Signed-off-by: Innei <tukon479@gmail.com> * feat: sync selector Signed-off-by: Innei <tukon479@gmail.com> * feat: modal stack mobile Signed-off-by: Innei <tukon479@gmail.com> * fix: modal selector Signed-off-by: Innei <tukon479@gmail.com> * cleanup Signed-off-by: Innei <tukon479@gmail.com> * fix: sheet and optimize entry readers Signed-off-by: Innei <tukon479@gmail.com> * fix: scroller Signed-off-by: Innei <tukon479@gmail.com> * feat: entry contents Signed-off-by: Innei <tukon479@gmail.com> * feat: entry content Signed-off-by: Innei <tukon479@gmail.com> * update Signed-off-by: Innei <tukon479@gmail.com> * feat: user profile sheet Signed-off-by: Innei <tukon479@gmail.com> * fix: entry content header Signed-off-by: Innei <tukon479@gmail.com> * fix: entry header Signed-off-by: Innei <tukon479@gmail.com> * chore: auto-fix linting and formatting issues * fix: return back Signed-off-by: Innei <tukon479@gmail.com> * feat: image view Signed-off-by: Innei <tukon479@gmail.com> * feat: audio Signed-off-by: Innei <tukon479@gmail.com> * feat: inline player Signed-off-by: Innei <tukon479@gmail.com> * feat: pull to refresh Signed-off-by: Innei <tukon479@gmail.com> * cleanup Signed-off-by: Innei <tukon479@gmail.com> * update Signed-off-by: Innei <tukon479@gmail.com> * chore: auto-fix linting and formatting issues * chore: fix import, remove no support display * chore: auto-fix linting and formatting issues * feat: achievement modal in mobile Signed-off-by: Innei <tukon479@gmail.com> * fix: subview mobile Signed-off-by: Innei <tukon479@gmail.com> * feat: power Signed-off-by: Innei <tukon479@gmail.com> * feat: wallet mobile design Signed-off-by: Innei <tukon479@gmail.com> * feat: pwa support (#1575) Co-authored-by: hyoban <hyoban@users.noreply.github.com> * chore: auto-fix linting and formatting issues * fix import * discover * fix: border color Signed-off-by: Innei <tukon479@gmail.com> * fix: modal async Signed-off-by: Innei <tukon479@gmail.com> * feat: mobile setting Signed-off-by: Innei <tukon479@gmail.com> * fix: entry header width Signed-off-by: Innei <tukon479@gmail.com> * fix: remove unused hide filter * feat: settings Signed-off-by: Innei <tukon479@gmail.com> * feat: setting done Signed-off-by: Innei <tukon479@gmail.com> * action card * fix discover feed form * popular filter * inbox table * fix: picture masonry pull to refresh Signed-off-by: Innei <tukon479@gmail.com> * fix: scroll element Signed-off-by: Innei <tukon479@gmail.com> * fix: radio in mobile Signed-off-by: Innei <tukon479@gmail.com> * feat: to scientific notation Signed-off-by: Innei <tukon479@gmail.com> * fix: login Signed-off-by: Innei <tukon479@gmail.com> * ResponsiveSelect for action card * chore: remove theme color Signed-off-by: Innei <tukon479@gmail.com> * type check * type check * fix: setting import circular Signed-off-by: Innei <tukon479@gmail.com> * refactor: remove hijack pushState Signed-off-by: Innei <tukon479@gmail.com> * fix: float bar Signed-off-by: Innei <tukon479@gmail.com> * fix: scroll end trigger Signed-off-by: Innei <tukon479@gmail.com> * fix: dark theme color Signed-off-by: Innei <tukon479@gmail.com> * fix: overscroll-behavior only in destop Signed-off-by: Innei <tukon479@gmail.com> * fix: ux Signed-off-by: Innei <tukon479@gmail.com> * fix: color Signed-off-by: Innei <tukon479@gmail.com> * fix: list scroll area Signed-off-by: Innei <tukon479@gmail.com> * update Signed-off-by: Innei <tukon479@gmail.com> * merge * update * update favicon link * fix: reload prompt on mobile * test Signed-off-by: Innei <i@innei.in> * test Signed-off-by: Innei <i@innei.in> * fix: ios Signed-off-by: Innei <i@innei.in> * try patch precaching * try * try * build * try * try * feat: ctx menu on safari Signed-off-by: Innei <tukon479@gmail.com> * try * clear timeout Signed-off-by: Innei <tukon479@gmail.com> * try * fix * deny og * fix patch * pre cache exclude * feat: add all Signed-off-by: Innei <tukon479@gmail.com> * i18n Signed-off-by: Innei <tukon479@gmail.com> * feat: slide Signed-off-by: Innei <tukon479@gmail.com> * feat: ico Signed-off-by: Innei <tukon479@gmail.com> * fix: build Signed-off-by: Innei <tukon479@gmail.com> * test network first Signed-off-by: Innei <tukon479@gmail.com> * test Signed-off-by: Innei <tukon479@gmail.com> * fix: icon padding * test Signed-off-by: Innei <tukon479@gmail.com> * use react-ios-pwa-prompt * fix: icon path * update * fix: prompt Signed-off-by: Innei <tukon479@gmail.com> * feat: redesign toc Signed-off-by: Innei <tukon479@gmail.com> * ctx Signed-off-by: Innei <tukon479@gmail.com> * ready to prod Signed-off-by: Innei <tukon479@gmail.com> * feat: startup screen Signed-off-by: Innei <tukon479@gmail.com> * feat: floatbar Signed-off-by: Innei <tukon479@gmail.com> * fix: switch view Signed-off-by: Innei <tukon479@gmail.com> * fix: keep scroll map Signed-off-by: Innei <tukon479@gmail.com> * enable hoverOnlyWhenSupported * fix: count Signed-off-by: Innei <tukon479@gmail.com> * fix: hoverOnlyWhenSupported only in web Signed-off-by: Innei <tukon479@gmail.com> * fix Signed-off-by: Innei <tukon479@gmail.com> * chore: auto-fix linting and formatting issues --------- Signed-off-by: Innei <i@innei.in> Signed-off-by: Innei <tukon479@gmail.com> Co-authored-by: Innei <Innei@users.noreply.github.com> Co-authored-by: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Co-authored-by: hyoban <hyoban@users.noreply.github.com> Co-authored-by: lawvs <18554747+lawvs@users.noreply.github.com> Co-authored-by: lawvs <lawvs@users.noreply.github.com>
100 lines
2.9 KiB
TypeScript
100 lines
2.9 KiB
TypeScript
import { MemoedDangerousHTMLStyle } from "@follow/components/common/MemoedDangerousHTMLStyle.js"
|
|
import katexStyle from "katex/dist/katex.min.css?raw"
|
|
import { createElement, Fragment, memo, useEffect, useMemo, useRef, useState } from "react"
|
|
|
|
import { ENTRY_CONTENT_RENDER_CONTAINER_ID } from "~/constants/dom"
|
|
import { parseHtml } from "~/lib/parse-html"
|
|
import { useWrappedElementSize } from "~/providers/wrapped-element-provider"
|
|
|
|
import type { MediaInfoRecord } from "../media"
|
|
import { MediaContainerWidthProvider, MediaInfoRecordProvider } from "../media"
|
|
import { MarkdownRenderContainerRefContext } from "./context"
|
|
|
|
export type HTMLProps<A extends keyof JSX.IntrinsicElements = "div"> = {
|
|
children: string | null | undefined
|
|
as: A
|
|
|
|
accessory?: React.ReactNode
|
|
noMedia?: boolean
|
|
mediaInfo?: MediaInfoRecord
|
|
|
|
handleTranslate?: (html: HTMLElement | null) => void
|
|
} & JSX.IntrinsicElements[A] &
|
|
Partial<{
|
|
renderInlineStyle: boolean
|
|
}>
|
|
const HTMLImpl = <A extends keyof JSX.IntrinsicElements = "div">(props: HTMLProps<A>) => {
|
|
const {
|
|
children,
|
|
renderInlineStyle,
|
|
as = "div",
|
|
accessory,
|
|
noMedia,
|
|
mediaInfo,
|
|
handleTranslate: translate,
|
|
...rest
|
|
} = props
|
|
const [remarkOptions, setRemarkOptions] = useState({
|
|
renderInlineStyle,
|
|
noMedia,
|
|
})
|
|
const [shouldForceReMountKey, setShouldForceReMountKey] = useState(0)
|
|
|
|
useEffect(() => {
|
|
setRemarkOptions((options) => {
|
|
if (JSON.stringify(options) === JSON.stringify({ renderInlineStyle, noMedia })) {
|
|
return options
|
|
}
|
|
|
|
setShouldForceReMountKey((key) => key + 1)
|
|
return { ...options, renderInlineStyle, noMedia }
|
|
})
|
|
}, [renderInlineStyle, noMedia])
|
|
|
|
const [refElement, setRefElement] = useState<HTMLElement | null>(null)
|
|
|
|
const onceRef = useRef(false)
|
|
useEffect(() => {
|
|
if (onceRef.current || !refElement) {
|
|
return
|
|
}
|
|
|
|
translate?.(refElement)
|
|
onceRef.current = true
|
|
}, [translate, refElement])
|
|
|
|
const markdownElement = useMemo(
|
|
() =>
|
|
children &&
|
|
parseHtml(children, {
|
|
...remarkOptions,
|
|
}).toContent(),
|
|
[children, remarkOptions],
|
|
)
|
|
|
|
const { w: containerWidth } = useWrappedElementSize()
|
|
|
|
if (!markdownElement) return null
|
|
return (
|
|
<MarkdownRenderContainerRefContext.Provider value={refElement}>
|
|
<MediaContainerWidthProvider width={containerWidth}>
|
|
<MediaInfoRecordProvider mediaInfo={mediaInfo}>
|
|
<MemoedDangerousHTMLStyle>{katexStyle}</MemoedDangerousHTMLStyle>
|
|
{createElement(
|
|
as,
|
|
{
|
|
...rest,
|
|
id: ENTRY_CONTENT_RENDER_CONTAINER_ID,
|
|
ref: setRefElement,
|
|
},
|
|
markdownElement,
|
|
)}
|
|
</MediaInfoRecordProvider>
|
|
</MediaContainerWidthProvider>
|
|
{!!accessory && <Fragment key={shouldForceReMountKey}>{accessory}</Fragment>}
|
|
</MarkdownRenderContainerRefContext.Provider>
|
|
)
|
|
}
|
|
|
|
export const HTML = memo(HTMLImpl)
|