feat: split data type into type+length columns with SearchableSelect, add Shiki SQL highlighting
- Separate data type input into type dropdown (SearchableSelect with allowCustom) and length input, Navicat-style - Add comprehensive DATA_TYPE_OPTIONS for all 6 database engines, validated against official docs - Add Shiki SQL syntax highlighting to the SQL preview panel - Add i18n keys for new UI elements (typePlaceholder, length, noMatchingType)
This commit is contained in:
1 parent
801434e423
commit
62b4905e54
6 files changed
+203
-5
No files matched your search
@@ -0,0 +1,55 @@
|
||||
import type { AppThemeAppearance } from "@/lib/appTheme";
|
||||
|
||||
export type SqlHighlighter = (content: string, appearance?: AppThemeAppearance) => string;
|
||||
|
||||
interface ShikiSqlHighlighterOptions {
|
||||
appearance: () => AppThemeAppearance;
|
||||
}
|
||||
|
||||
const SHIKI_THEMES = {
|
||||
dark: "github-dark",
|
||||
light: "github-light",
|
||||
} as const;
|
||||
|
||||
type ShikiHighlighter = Awaited<ReturnType<typeof import("shiki/core").createHighlighterCore>>;
|
||||
|
||||
let highlighterPromise: Promise<ShikiHighlighter> | undefined;
|
||||
|
||||
export async function createShikiSqlHighlighter(
|
||||
options: ShikiSqlHighlighterOptions,
|
||||
): Promise<SqlHighlighter> {
|
||||
const highlighter = await getShikiSqlHighlighter();
|
||||
return (content, appearance = options.appearance()) =>
|
||||
highlighter.codeToHtml(content, {
|
||||
lang: "sql",
|
||||
structure: "inline",
|
||||
theme: SHIKI_THEMES[appearance],
|
||||
});
|
||||
}
|
||||
|
||||
function getShikiSqlHighlighter(): Promise<ShikiHighlighter> {
|
||||
highlighterPromise ??= loadShikiSqlHighlighter();
|
||||
return highlighterPromise;
|
||||
}
|
||||
|
||||
async function loadShikiSqlHighlighter(): Promise<ShikiHighlighter> {
|
||||
const [
|
||||
{ createHighlighterCore },
|
||||
{ createJavaScriptRegexEngine },
|
||||
githubDark,
|
||||
githubLight,
|
||||
sql,
|
||||
] = await Promise.all([
|
||||
import("shiki/core"),
|
||||
import("shiki/engine/javascript"),
|
||||
import("shiki/themes/github-dark.mjs"),
|
||||
import("shiki/themes/github-light.mjs"),
|
||||
import("shiki/langs/sql.mjs"),
|
||||
]);
|
||||
|
||||
return createHighlighterCore({
|
||||
engine: createJavaScriptRegexEngine(),
|
||||
langs: [sql.default],
|
||||
themes: [githubDark.default, githubLight.default],
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user