From 82c827a8fbccdacb830d3db6b6fd82af7eb61667 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Wed, 27 Sep 2023 00:08:00 +0800 Subject: [PATCH] chore: update unified types --- src/components/ui/DPlayer.tsx | 13 +++++++------ src/markdown/rehype-audio.ts | 2 +- src/markdown/rehype-embed.ts | 2 +- src/markdown/rehype-image.ts | 2 +- src/markdown/rehype-table.ts | 2 +- src/markdown/rehype-video.ts | 2 +- src/markdown/rehype-wrap-code.ts | 2 +- src/markdown/rehyper-external-link.ts | 2 +- src/markdown/remark-callout.ts | 6 +++--- src/markdown/remark-mermaid.ts | 6 +++--- src/markdown/remark-pangu.ts | 4 ++-- src/markdown/remark-youtube.ts | 8 ++++---- 12 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/components/ui/DPlayer.tsx b/src/components/ui/DPlayer.tsx index eaf2a717..a0576d7f 100644 --- a/src/components/ui/DPlayer.tsx +++ b/src/components/ui/DPlayer.tsx @@ -2,7 +2,6 @@ import dynamic from "next/dynamic" import { type DPlayerProps } from "rc-dplayer" -import { ReactElement } from "rehype-react/lib" import { toGateway } from "~/lib/ipfs-parser" @@ -14,12 +13,14 @@ const DPlayer = function DPlayer({ ...props }: { src?: string - children?: ReactElement[] + children?: JSX.Element[] | JSX.Element } & DPlayerProps) { - const sources = children?.filter( - (child) => - child && typeof child.type === "string" && child.type === "source", - ) + const sources = Array.isArray(children) + ? children?.filter( + (child) => + child && typeof child.type === "string" && child.type === "source", + ) + : [] if (!src) { src = (sources?.[0]?.props as DPlayerProps)?.src as string diff --git a/src/markdown/rehype-audio.ts b/src/markdown/rehype-audio.ts index 2bb77cba..ed7e5b22 100644 --- a/src/markdown/rehype-audio.ts +++ b/src/markdown/rehype-audio.ts @@ -1,4 +1,4 @@ -import { Root } from "rehype-raw" +import type { Root } from "hast" import { Plugin } from "unified" import { visit } from "unist-util-visit" diff --git a/src/markdown/rehype-embed.ts b/src/markdown/rehype-embed.ts index 866269ed..8cf45fc5 100644 --- a/src/markdown/rehype-embed.ts +++ b/src/markdown/rehype-embed.ts @@ -1,5 +1,5 @@ +import type { Root } from "hast" import { fromHtml } from "hast-util-from-html" -import { Root } from "rehype-raw" import { Plugin } from "unified" import { visit } from "unist-util-visit" diff --git a/src/markdown/rehype-image.ts b/src/markdown/rehype-image.ts index 1c2d8887..ca3fa720 100644 --- a/src/markdown/rehype-image.ts +++ b/src/markdown/rehype-image.ts @@ -1,4 +1,4 @@ -import { Root } from "rehype-raw" +import type { Root } from "hast" import { Plugin } from "unified" import { visit } from "unist-util-visit" diff --git a/src/markdown/rehype-table.ts b/src/markdown/rehype-table.ts index 30f6c838..b8f98206 100644 --- a/src/markdown/rehype-table.ts +++ b/src/markdown/rehype-table.ts @@ -1,4 +1,4 @@ -import { Root } from "rehype-raw" +import type { Root } from "hast" import { Plugin } from "unified" import { visit } from "unist-util-visit" diff --git a/src/markdown/rehype-video.ts b/src/markdown/rehype-video.ts index 69e5eead..e6c265ac 100644 --- a/src/markdown/rehype-video.ts +++ b/src/markdown/rehype-video.ts @@ -1,4 +1,4 @@ -import { Root } from "rehype-raw" +import type { Root } from "hast" import { Plugin } from "unified" import { visit } from "unist-util-visit" diff --git a/src/markdown/rehype-wrap-code.ts b/src/markdown/rehype-wrap-code.ts index 11a77b61..8028eeea 100644 --- a/src/markdown/rehype-wrap-code.ts +++ b/src/markdown/rehype-wrap-code.ts @@ -1,4 +1,4 @@ -import { Root } from "rehype-raw" +import type { Root } from "hast" import { Plugin } from "unified" import { u } from "unist-builder" import { visit } from "unist-util-visit" diff --git a/src/markdown/rehyper-external-link.ts b/src/markdown/rehyper-external-link.ts index d856b9a2..d6da2961 100644 --- a/src/markdown/rehyper-external-link.ts +++ b/src/markdown/rehyper-external-link.ts @@ -1,4 +1,4 @@ -import { Root } from "rehype-raw" +import type { Root } from "hast" import { Plugin } from "unified" import { visit } from "unist-util-visit" diff --git a/src/markdown/remark-callout.ts b/src/markdown/remark-callout.ts index 82d9d5d0..17d38a90 100644 --- a/src/markdown/remark-callout.ts +++ b/src/markdown/remark-callout.ts @@ -1,10 +1,10 @@ -import { Root } from "remark-gfm" -import { Plugin } from "unified" +import type { Root } from "mdast" +import type { Plugin } from "unified" import { visit } from "unist-util-visit" const CALLOUT_RE = /^(TIP|WARN|SUCCESS|DANGER):(\n|$)/ -export const remarkCallout: Plugin, Root> = () => (tree: Root) => { +export const remarkCallout: Plugin<[], Root> = () => (tree: Root) => { visit(tree, { type: "blockquote" }, (node, index, parent) => { if (node.type !== "blockquote") return diff --git a/src/markdown/remark-mermaid.ts b/src/markdown/remark-mermaid.ts index 7c17284f..d23015d0 100644 --- a/src/markdown/remark-mermaid.ts +++ b/src/markdown/remark-mermaid.ts @@ -1,8 +1,8 @@ -import { Root } from "remark-gfm" -import { Plugin } from "unified" +import type { Root } from "mdast" +import type { Plugin } from "unified" import { visit } from "unist-util-visit" -export const remarkMermaid: Plugin, Root> = () => (tree: Root) => { +export const remarkMermaid: Plugin<[], Root> = () => (tree: Root) => { visit(tree, (node) => { if (node.type === "code" && node.lang === "mermaid") { // @ts-ignore diff --git a/src/markdown/remark-pangu.ts b/src/markdown/remark-pangu.ts index fc4d95fe..bd1601b1 100644 --- a/src/markdown/remark-pangu.ts +++ b/src/markdown/remark-pangu.ts @@ -1,5 +1,5 @@ +import type { Root } from "mdast" import pangu from "pangu" -import type { Root } from "remark-gfm" import type { Plugin } from "unified" import { visit } from "unist-util-visit" @@ -26,7 +26,7 @@ function format(value: string) { return pangu.spacing(value) } -export const remarkPangu: Plugin, Root> = +export const remarkPangu: Plugin<[], Root> = (options = {}) => (tree: Root) => { const settings = Object.assign({}, defaultOptions, options) diff --git a/src/markdown/remark-youtube.ts b/src/markdown/remark-youtube.ts index 2501f18c..977e0911 100644 --- a/src/markdown/remark-youtube.ts +++ b/src/markdown/remark-youtube.ts @@ -1,10 +1,10 @@ -import { Root } from "remark-gfm" -import { Plugin } from "unified" +import type { Root } from "mdast" +import type { Plugin } from "unified" import { visit } from "unist-util-visit" -export const remarkYoutube: Plugin, Root> = +export const remarkYoutube: Plugin<[], Root> = () => (tree: Root, file: any) => { - visit(tree, (node) => { + visit(tree, (node: any) => { if ( node.type === "textDirective" || node.type === "leafDirective" ||