import { BaseControl, ExternalLink } from '@wordpress/components'; import { applyFilters } from '@wordpress/hooks'; import { sprintf, __ } from '@wordpress/i18n'; import { Theme } from 'shiki'; import defaultThemes from '../../defaultThemes.json'; import { useSettingsStore } from '../../state/settings'; import { CustomStyles, HelpUrl, Lang, ThemeOption } from '../../types'; import { getPriorityThemes } from '../../util/themes'; import { ThemePreview } from '../components/ThemePreview'; type ThemeSelectProps = { theme: Theme; language: Lang; code: string; fontSize: string; lineHeight: string; fontFamily: string; search: string; clampFonts: boolean; tabSize: number; onClick: (slug: Theme) => void; }; export const ThemeSelect = (props: ThemeSelectProps) => { const { hiddenThemes } = useSettingsStore(); const themes = applyFilters( 'blocks.codeBlockPro.themes', defaultThemes, ) as ThemeOption; const themesSorted = Object.entries(themes) .filter(([slug]) => !hiddenThemes.includes(slug)) .filter(([slug]) => slug.includes(props.search.toLocaleLowerCase())) .map(([slug, data]) => ({ slug, ...data })) // Put priority themes at the top .sort((a, b) => (a.priority === b.priority ? 0 : a.priority ? -1 : 1)) // then put custom themes above that .sort((a, b) => (a.custom === b.custom ? 0 : a.custom ? -1 : 1)); const priorityThemes = getPriorityThemes(); return (