Core: Fix typings of HighlightOptions

This commit is contained in:
Fuma Nama
2024-12-16 19:58:48 +08:00
parent 9908922c17
commit 2357d402eb
3 changed files with 14 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-core': patch
---
Fix typings of `HighlightOptions`
+4 -3
View File
@@ -3,8 +3,9 @@ import {
type CodeOptionsThemes,
type ShikiTransformer,
type CodeOptionsMeta,
type HighlighterCoreOptions,
type CodeToHastOptionsCommon,
type RegexEngine,
type Awaitable,
} from 'shiki';
import type { BundledTheme } from 'shiki/themes';
import { type Components, toJsxRuntime } from 'hast-util-to-jsx-runtime';
@@ -33,9 +34,9 @@ export const defaultThemes = {
};
export type HighlightOptions = CodeToHastOptionsCommon<BundledLanguage> &
Pick<HighlighterCoreOptions, 'engine'> &
Partial<CodeOptionsThemes<BundledTheme>> &
(CodeOptionsThemes<BundledTheme> | Record<never, never>) &
CodeOptionsMeta & {
engine?: Awaitable<RegexEngine>;
components?: Partial<Components>;
};
+5 -1
View File
@@ -4,6 +4,7 @@ import {
type ReactNode,
use,
useEffect,
useMemo,
useRef,
useState,
} from 'react';
@@ -58,7 +59,10 @@ export function useShiki(
},
deps?: DependencyList,
): ReactNode {
const key = deps ? JSON.stringify(deps) : `${options.lang}:${code}`;
const key = useMemo(
() => (deps ? JSON.stringify(deps) : `${options.lang}:${code}`),
[code, deps, options.lang],
);
const shikiOptions = getHighlightOptions(options);
const currentTask = useRef<Task | undefined>({
key,