| @@ -1,17 +1,12 @@ | ||
| 1 | 1 | import { useEffect, useState } from '@wordpress/element'; |
| 2 | 2 | import { applyFilters } from '@wordpress/hooks'; |
| 3 | -import { getHighlighter, setCDN, Theme, setWasm } from 'shiki'; | |
| 3 | +import { getHighlighter, Lang, setCDN, Theme, setWasm } from 'shiki'; | |
| 4 | 4 | import useSWRImmutable from 'swr/immutable'; |
| 5 | 5 | import defaultThemes from '../defaultThemes.json'; |
| 6 | -import { Lang, ThemeOption } from '../types'; | |
| 7 | 6 | import { getEditorLanguage } from '../util/languages'; |
| 8 | 7 | |
| 9 | -type Params = { | |
| 10 | - theme: Theme; | |
| 11 | - lang: Lang | 'ansi'; | |
| 12 | - ready?: boolean; | |
| 13 | -}; | |
| 8 | +type Params = { theme: Theme; lang: Lang | 'ansi'; ready?: boolean }; | |
| 14 | 9 | |
| 15 | 10 | const fetcher = ({ theme, lang, ready }: Params) => { |
| 16 | 11 | if (!ready) throw new Error(); |
| 17 | 12 | const themeFiltered = applyFilters( |
| @@ -27,9 +22,9 @@ | ||
| 27 | 22 | > |
| 28 | 23 | )?.[themeFiltered]?.['alias'] as Theme; |
| 29 | 24 | |
| 30 | 25 | return getHighlighter({ |
| 31 | - langs: lang === 'plaintext' ? [] : [getEditorLanguage(lang)], | |
| 26 | + langs: [getEditorLanguage(lang)], | |
| 32 | 27 | theme: themeAlias ?? themeFiltered, |
| 33 | 28 | }); |
| 34 | 29 | }; |
| 35 | 30 | let once = false; |
| @@ -35,12 +30,8 @@ | ||
| 35 | 30 | let once = false; |
| 36 | 31 | |
| 37 | 32 | export const useTheme = ({ theme, lang, ready = true }: Params) => { |
| 38 | 33 | const [wasmLoaded, setWasmFileLoaded] = useState(false); |
| 39 | - const themes = applyFilters( | |
| 40 | - 'blocks.codeBlockPro.themes', | |
| 41 | - defaultThemes, | |
| 42 | - ) as ThemeOption; | |
| 43 | 34 | if (!once) { |
| 44 | 35 | once = true; |
| 45 | 36 | const assetDir = window.codeBlockPro?.pluginUrl + 'build/shiki/'; |
| 46 | 37 | setCDN( |
| @@ -46,9 +37,8 @@ | ||
| 46 | 37 | setCDN( |
| 47 | 38 | applyFilters('blocks.codeBlockPro.assetDir', assetDir) as string, |
| 48 | 39 | ); |
| 49 | 40 | } |
| 50 | - if (themes[theme]?.custom) theme = 'css-variables'; | |
| 51 | 41 | const { data: highlighter, error } = useSWRImmutable( |
| 52 | 42 | { theme, lang, ready: ready && wasmLoaded }, |
| 53 | 43 | fetcher, |
| 54 | 44 | ); |