Merge PR #1024
This commit is contained in:
1 parent
ddfbc2c3b5
commit
634e26e8e7
19 files changed
+1614
-124
No files matched your search
@@ -830,6 +830,13 @@ async function downloadWebDavSnapshot() {
|
||||
});
|
||||
}
|
||||
|
||||
const oldPassword = ref("");
|
||||
const newPassword = ref("");
|
||||
const confirmNewPassword = ref("");
|
||||
const passwordMessage = ref("");
|
||||
const passwordError = ref(false);
|
||||
const changingPassword = ref(false);
|
||||
|
||||
watch(
|
||||
() => props.open,
|
||||
async (open) => {
|
||||
@@ -868,13 +875,6 @@ onMounted(() => {
|
||||
void refreshWebDavPasswordStatus();
|
||||
});
|
||||
|
||||
const oldPassword = ref("");
|
||||
const newPassword = ref("");
|
||||
const confirmNewPassword = ref("");
|
||||
const passwordMessage = ref("");
|
||||
const passwordError = ref(false);
|
||||
const changingPassword = ref(false);
|
||||
|
||||
async function changePassword() {
|
||||
if (newPassword.value !== confirmNewPassword.value) {
|
||||
passwordMessage.value = t("auth.passwordMismatch");
|
||||
|
||||
@@ -1,27 +1,40 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onBeforeUnmount, ref, watch } from "vue";
|
||||
import { Upload, Download, RotateCcw, WandSparkles, Save } from "@lucide/vue";
|
||||
import { Upload, Download, RotateCcw, WandSparkles, Save, Copy } from "@lucide/vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import { useToast } from "@/composables/useToast";
|
||||
import { copyToClipboard } from "@/lib/clipboard";
|
||||
import {
|
||||
DEFAULT_SQL_FORMATTER_SETTINGS,
|
||||
SQL_FORMATTER_CONFIG_FORMATTER,
|
||||
SQL_FORMATTER_CONFIG_VERSION,
|
||||
normalizeSqlFormatterEditorSettings,
|
||||
normalizeSqlFormatterSettings,
|
||||
parseSqlFormatterConfig,
|
||||
serializeSqlFormatterConfig,
|
||||
sqlFormatterPlatformFromNavigator,
|
||||
syncSqlFormatterConfigDraft,
|
||||
validateSqlFormatterEditorSettings,
|
||||
type SqlFormatterCase,
|
||||
type SqlFormatterEditorShortcut,
|
||||
type SqlFormatterEditorShortcutId,
|
||||
type SqlFormatterExpressionWidth,
|
||||
type SqlFormatterIndentStyle,
|
||||
type SqlFormatterLinesBetweenQueries,
|
||||
type SqlFormatterLogicalOperatorNewline,
|
||||
type SqlFormatterOptionSettings,
|
||||
type SqlFormatterParamTypes,
|
||||
type SqlFormatterPlatform,
|
||||
type SqlFormatterSettings,
|
||||
type SqlFormatterTabWidth,
|
||||
} from "@/lib/sqlFormatterConfig";
|
||||
import { createSqlFormatterConfigKeymap, sqlFormatterConfigShortcutRows } from "@/lib/sqlFormatterConfigEditor";
|
||||
import { createSqlFormatterConfigKeymap, sqlFormatterConfigShortcutLabelKey, sqlFormatterConfigShortcutRows } from "@/lib/sqlFormatterConfigEditor";
|
||||
|
||||
type EditorViewInstance = import("@codemirror/view").EditorView;
|
||||
type CodeMirrorModules = {
|
||||
@@ -50,14 +63,21 @@ const jsonEditorRef = ref<HTMLDivElement>();
|
||||
const jsonDraft = ref(serializeSqlFormatterConfig(props.modelValue));
|
||||
const jsonValidationMessage = ref("");
|
||||
const importError = ref("");
|
||||
const advancedConfigError = ref("");
|
||||
const editorShortcutError = ref("");
|
||||
const jsonEditorLoading = ref(false);
|
||||
const jsonEditorReady = ref(false);
|
||||
const jsonEditorLoadError = ref("");
|
||||
const paramTypesDraft = ref("");
|
||||
const focusedAdvancedOption = ref<"paramTypes" | null>(null);
|
||||
|
||||
let cmView: EditorViewInstance | null = null;
|
||||
let cmModules: CodeMirrorModules | null = null;
|
||||
let keymapCompartment: import("@codemirror/state").Compartment | null = null;
|
||||
let lastValidity: boolean | null = null;
|
||||
|
||||
const settings = computed(() => normalizeSqlFormatterSettings(props.modelValue));
|
||||
const shortcutRows = computed(() => sqlFormatterConfigShortcutRows(globalThis.navigator?.platform || ""));
|
||||
const shortcutRows = computed(() => sqlFormatterConfigShortcutRows(globalThis.navigator?.platform || "", settings.value.editor));
|
||||
|
||||
const caseOptions: { value: SqlFormatterCase; labelKey: string }[] = [
|
||||
{ value: "upper", labelKey: "settings.sqlFormatterCaseUpper" },
|
||||
@@ -70,13 +90,29 @@ const logicalOperatorOptions: { value: SqlFormatterLogicalOperatorNewline; label
|
||||
{ value: "after", labelKey: "settings.sqlFormatterLogicalAfter" },
|
||||
];
|
||||
|
||||
const indentStyleOptions: { value: SqlFormatterIndentStyle; labelKey: string }[] = [
|
||||
{ value: "standard", labelKey: "settings.sqlFormatterIndentStyleStandard" },
|
||||
{ value: "tabularLeft", labelKey: "settings.sqlFormatterIndentStyleTabularLeft" },
|
||||
{ value: "tabularRight", labelKey: "settings.sqlFormatterIndentStyleTabularRight" },
|
||||
];
|
||||
|
||||
const shortcutPlatformOptions: { value: SqlFormatterPlatform; labelKey: string }[] = [
|
||||
{ value: "windows", labelKey: "settings.sqlFormatterShortcutWindows" },
|
||||
{ value: "linux", labelKey: "settings.sqlFormatterShortcutLinux" },
|
||||
{ value: "macos", labelKey: "settings.sqlFormatterShortcutMacos" },
|
||||
];
|
||||
const currentShortcutPlatform = computed(() => sqlFormatterPlatformFromNavigator(globalThis.navigator?.platform || ""));
|
||||
const currentShortcutPlatformOption = computed(() => shortcutPlatformOptions.find((option) => option.value === currentShortcutPlatform.value) ?? shortcutPlatformOptions[0]);
|
||||
|
||||
const tabWidthOptions: SqlFormatterTabWidth[] = [2, 4];
|
||||
const expressionWidthOptions: SqlFormatterExpressionWidth[] = [50, 80, 120];
|
||||
const linesBetweenQueriesOptions: SqlFormatterLinesBetweenQueries[] = [0, 1, 2];
|
||||
const sqlFormatterOptionLabelKeys: Record<keyof SqlFormatterSettings, string> = {
|
||||
const sqlFormatterOptionLabelKeys: Record<keyof SqlFormatterOptionSettings, string> = {
|
||||
keywordCase: "settings.sqlFormatterKeywordCase",
|
||||
dataTypeCase: "settings.sqlFormatterDataTypeCase",
|
||||
functionCase: "settings.sqlFormatterFunctionCase",
|
||||
identifierCase: "settings.sqlFormatterIdentifierCase",
|
||||
indentStyle: "settings.sqlFormatterIndentStyle",
|
||||
useTabs: "settings.sqlFormatterIndent",
|
||||
tabWidth: "settings.sqlFormatterTabWidth",
|
||||
logicalOperatorNewline: "settings.sqlFormatterLogicalOperatorNewline",
|
||||
@@ -84,13 +120,20 @@ const sqlFormatterOptionLabelKeys: Record<keyof SqlFormatterSettings, string> =
|
||||
linesBetweenQueries: "settings.sqlFormatterLinesBetweenQueries",
|
||||
denseOperators: "settings.sqlFormatterDenseOperators",
|
||||
newlineBeforeSemicolon: "settings.sqlFormatterNewlineBeforeSemicolon",
|
||||
paramTypes: "settings.sqlFormatterParamTypes",
|
||||
};
|
||||
const sqlFormatterConfigErrorKeys: Record<string, string> = {
|
||||
"Invalid JSON.": "settings.sqlFormatterConfigErrorInvalidJson",
|
||||
"Config must be a JSON object.": "settings.sqlFormatterConfigErrorObject",
|
||||
"Unsupported config version.": "settings.sqlFormatterConfigErrorVersion",
|
||||
"Unsupported formatter.": "settings.sqlFormatterConfigErrorFormatter",
|
||||
"Unsupported formatter option: params.": "settings.sqlFormatterConfigErrorUnsupportedParams",
|
||||
"Config options must be a JSON object.": "settings.sqlFormatterConfigErrorOptionsObject",
|
||||
"Config editor must be a JSON object.": "settings.sqlFormatterConfigErrorEditorObject",
|
||||
"Unsupported editor scope.": "settings.sqlFormatterConfigErrorEditorScope",
|
||||
"Invalid editor platforms.": "settings.sqlFormatterConfigErrorEditorPlatforms",
|
||||
"Config editor shortcuts must be an array.": "settings.sqlFormatterConfigErrorEditorShortcutsArray",
|
||||
"Invalid editor shortcut value.": "settings.sqlFormatterConfigErrorEditorShortcutValue",
|
||||
};
|
||||
|
||||
function emitValidity(value: boolean) {
|
||||
@@ -118,12 +161,27 @@ function localizeSqlFormatterConfigError(message: string): string {
|
||||
|
||||
const invalidOption = message.match(/^Invalid formatter option value: (.+)\.$/);
|
||||
if (invalidOption?.[1]) {
|
||||
const labelKey = sqlFormatterOptionLabelKeys[invalidOption[1] as keyof SqlFormatterSettings];
|
||||
const labelKey = sqlFormatterOptionLabelKeys[invalidOption[1] as keyof SqlFormatterOptionSettings];
|
||||
if (labelKey) {
|
||||
return t("settings.sqlFormatterConfigErrorInvalidOptionValue", { option: t(labelKey) });
|
||||
}
|
||||
}
|
||||
|
||||
const unknownShortcut = message.match(/^Unknown editor shortcut: (.+)\.$/);
|
||||
if (unknownShortcut?.[1]) {
|
||||
return t("settings.sqlFormatterConfigErrorUnknownEditorShortcut", { shortcut: unknownShortcut[1] });
|
||||
}
|
||||
|
||||
const invalidShortcut = message.match(/^Invalid editor shortcut value: (.+)\.$/);
|
||||
if (invalidShortcut?.[1]) {
|
||||
return t("settings.sqlFormatterConfigErrorInvalidEditorShortcut", { shortcut: invalidShortcut[1] });
|
||||
}
|
||||
|
||||
const duplicateShortcut = message.match(/^Duplicate editor shortcut: (.+)\.$/);
|
||||
if (duplicateShortcut?.[1]) {
|
||||
return t("settings.sqlFormatterConfigErrorDuplicateEditorShortcut", { shortcut: duplicateShortcut[1] });
|
||||
}
|
||||
|
||||
return t("settings.sqlFormatterConfigErrorInvalidConfig");
|
||||
}
|
||||
|
||||
@@ -144,9 +202,17 @@ function syncJsonDraft(text = jsonDraft.value): boolean {
|
||||
|
||||
function updateSettings(next: unknown) {
|
||||
importError.value = "";
|
||||
advancedConfigError.value = "";
|
||||
emit("update:modelValue", normalizeSqlFormatterSettings(next));
|
||||
}
|
||||
|
||||
function validateEditorShortcuts(value = settings.value.editor): boolean {
|
||||
const result = validateSqlFormatterEditorSettings(value);
|
||||
editorShortcutError.value = result.ok ? "" : localizeSqlFormatterConfigError(result.message);
|
||||
emitValidity(activeMode.value === "form" ? result.ok : !jsonValidationMessage.value);
|
||||
return result.ok;
|
||||
}
|
||||
|
||||
function updateOption<K extends keyof SqlFormatterSettings>(key: K, value: SqlFormatterSettings[K]) {
|
||||
updateSettings({ ...settings.value, [key]: value });
|
||||
}
|
||||
@@ -155,6 +221,14 @@ function onCaseOption(key: "keywordCase" | "functionCase" | "dataTypeCase", valu
|
||||
if (value === "upper" || value === "lower" || value === "preserve") updateOption(key, value);
|
||||
}
|
||||
|
||||
function onIdentifierCase(value: any) {
|
||||
if (value === "upper" || value === "lower" || value === "preserve") updateOption("identifierCase", value);
|
||||
}
|
||||
|
||||
function onIndentStyle(value: any) {
|
||||
if (value === "standard" || value === "tabularLeft" || value === "tabularRight") updateOption("indentStyle", value);
|
||||
}
|
||||
|
||||
function onLogicalOperatorNewline(value: any) {
|
||||
if (value === "before" || value === "after") updateOption("logicalOperatorNewline", value);
|
||||
}
|
||||
@@ -178,6 +252,93 @@ function restoreDefaults() {
|
||||
updateSettings(DEFAULT_SQL_FORMATTER_SETTINGS);
|
||||
}
|
||||
|
||||
function stringifyAdvancedOption(value: SqlFormatterParamTypes | null): string {
|
||||
return JSON.stringify(value, null, 2);
|
||||
}
|
||||
|
||||
function setAdvancedDraft(value: SqlFormatterParamTypes | null) {
|
||||
paramTypesDraft.value = stringifyAdvancedOption(value);
|
||||
}
|
||||
|
||||
function onAdvancedJsonInput(event: Event) {
|
||||
paramTypesDraft.value = (event.target as HTMLTextAreaElement).value;
|
||||
}
|
||||
|
||||
function onJsonDraftTextareaInput(event: Event) {
|
||||
const text = (event.target as HTMLTextAreaElement).value;
|
||||
jsonDraft.value = text;
|
||||
syncJsonDraft(text);
|
||||
}
|
||||
|
||||
function onAdvancedJsonFocus() {
|
||||
focusedAdvancedOption.value = "paramTypes";
|
||||
}
|
||||
|
||||
function onAdvancedJsonBlur() {
|
||||
focusedAdvancedOption.value = null;
|
||||
applyAdvancedJsonOption();
|
||||
}
|
||||
|
||||
function applyAdvancedJsonOption() {
|
||||
let parsed: unknown = null;
|
||||
const draft = paramTypesDraft.value.trim();
|
||||
if (draft) {
|
||||
try {
|
||||
parsed = JSON.parse(draft);
|
||||
} catch {
|
||||
advancedConfigError.value = localizeSqlFormatterConfigError("Invalid JSON.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const result = parseSqlFormatterConfig(
|
||||
JSON.stringify({
|
||||
version: SQL_FORMATTER_CONFIG_VERSION,
|
||||
formatter: SQL_FORMATTER_CONFIG_FORMATTER,
|
||||
options: { paramTypes: parsed },
|
||||
}),
|
||||
);
|
||||
if (!result.ok) {
|
||||
advancedConfigError.value = localizeSqlFormatterConfigError(result.message);
|
||||
return;
|
||||
}
|
||||
|
||||
updateOption("paramTypes", result.settings.paramTypes);
|
||||
setAdvancedDraft(result.settings.paramTypes);
|
||||
advancedConfigError.value = "";
|
||||
}
|
||||
|
||||
function updateEditorShortcut(id: SqlFormatterEditorShortcutId, updater: (shortcut: SqlFormatterEditorShortcut) => SqlFormatterEditorShortcut) {
|
||||
const editor = normalizeSqlFormatterEditorSettings(settings.value.editor);
|
||||
const next = {
|
||||
...settings.value,
|
||||
editor: {
|
||||
...editor,
|
||||
shortcuts: editor.shortcuts.map((shortcut) => (shortcut.id === id ? updater({ ...shortcut, keys: { ...shortcut.keys } }) : shortcut)),
|
||||
},
|
||||
};
|
||||
updateSettings(next);
|
||||
validateEditorShortcuts(next.editor);
|
||||
}
|
||||
|
||||
function updateEditorShortcutEnabled(id: SqlFormatterEditorShortcutId, enabled: boolean) {
|
||||
updateEditorShortcut(id, (shortcut) => ({ ...shortcut, enabled }));
|
||||
}
|
||||
|
||||
function updateEditorShortcutKey(id: SqlFormatterEditorShortcutId, platform: SqlFormatterPlatform, value: string) {
|
||||
updateEditorShortcut(id, (shortcut) => ({
|
||||
...shortcut,
|
||||
keys: {
|
||||
...shortcut.keys,
|
||||
[platform]: value,
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
function shortcutLabelKey(id: SqlFormatterEditorShortcutId): string {
|
||||
return sqlFormatterConfigShortcutLabelKey(id);
|
||||
}
|
||||
|
||||
function importConfig() {
|
||||
importError.value = "";
|
||||
fileInputRef.value?.click();
|
||||
@@ -215,6 +376,15 @@ function exportConfig() {
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
async function copyJsonDraft() {
|
||||
try {
|
||||
await copyToClipboard(cmView?.state.doc.toString() ?? jsonDraft.value);
|
||||
toast(t("settings.sqlFormatterCopyJsonSuccess"));
|
||||
} catch (e: any) {
|
||||
toast(t("settings.sqlFormatterCopyJsonFailed", { message: e?.message || String(e) }), 3000);
|
||||
}
|
||||
}
|
||||
|
||||
function applyJsonDraft(): boolean {
|
||||
const result = parseSqlFormatterConfig(jsonDraft.value);
|
||||
if (!result.ok) {
|
||||
@@ -255,37 +425,59 @@ async function loadCodeMirrorModules(): Promise<CodeMirrorModules> {
|
||||
function destroyJsonEditor() {
|
||||
cmView?.destroy();
|
||||
cmView = null;
|
||||
keymapCompartment = null;
|
||||
jsonEditorReady.value = false;
|
||||
jsonEditorLoadError.value = "";
|
||||
}
|
||||
|
||||
function jsonEditorKeymapExtension(modules: CodeMirrorModules) {
|
||||
const { keymap } = modules.view;
|
||||
const commands = modules.commands;
|
||||
const search = modules.search;
|
||||
const customKeymap = createSqlFormatterConfigKeymap(
|
||||
{
|
||||
indentMore: commands.indentMore,
|
||||
indentLess: commands.indentLess,
|
||||
copyLineDown: commands.copyLineDown,
|
||||
copyLineUp: commands.copyLineUp,
|
||||
deleteLine: commands.deleteLine,
|
||||
moveLineUp: commands.moveLineUp,
|
||||
moveLineDown: commands.moveLineDown,
|
||||
undo: commands.undo,
|
||||
redo: commands.redo,
|
||||
selectAll: commands.selectAll,
|
||||
openSearchPanel: search.openSearchPanel,
|
||||
},
|
||||
{
|
||||
apply: applyJsonDraft,
|
||||
formatJson: formatJsonDraft,
|
||||
},
|
||||
settings.value.editor,
|
||||
);
|
||||
return keymap.of([...customKeymap, ...search.searchKeymap, ...commands.historyKeymap, ...commands.defaultKeymap]);
|
||||
}
|
||||
|
||||
function reconfigureJsonEditorKeymap() {
|
||||
if (!cmView || !cmModules || !keymapCompartment) return;
|
||||
cmView.dispatch({
|
||||
effects: keymapCompartment.reconfigure(jsonEditorKeymapExtension(cmModules)),
|
||||
});
|
||||
}
|
||||
|
||||
async function initJsonEditor() {
|
||||
if (cmView || !jsonEditorRef.value) return;
|
||||
jsonEditorLoading.value = true;
|
||||
jsonEditorLoadError.value = "";
|
||||
try {
|
||||
const modules = await loadCodeMirrorModules();
|
||||
if (activeMode.value !== "json" || cmView || !jsonEditorRef.value) return;
|
||||
|
||||
const { EditorView, keymap, lineNumbers, highlightActiveLine, highlightActiveLineGutter } = modules.view;
|
||||
const { EditorState } = modules.state;
|
||||
const { EditorView, lineNumbers, highlightActiveLine, highlightActiveLineGutter } = modules.view;
|
||||
const { EditorState, Compartment } = modules.state;
|
||||
const { json } = modules.langJson;
|
||||
const commands = modules.commands;
|
||||
const search = modules.search;
|
||||
|
||||
const customKeymap = createSqlFormatterConfigKeymap(
|
||||
{
|
||||
indentMore: commands.indentMore,
|
||||
indentLess: commands.indentLess,
|
||||
copyLineDown: commands.copyLineDown,
|
||||
copyLineUp: commands.copyLineUp,
|
||||
deleteLine: commands.deleteLine,
|
||||
moveLineUp: commands.moveLineUp,
|
||||
moveLineDown: commands.moveLineDown,
|
||||
openSearchPanel: search.openSearchPanel,
|
||||
},
|
||||
{
|
||||
apply: applyJsonDraft,
|
||||
formatJson: formatJsonDraft,
|
||||
},
|
||||
);
|
||||
keymapCompartment = new Compartment();
|
||||
|
||||
const state = EditorState.create({
|
||||
doc: jsonDraft.value,
|
||||
@@ -296,7 +488,7 @@ async function initJsonEditor() {
|
||||
commands.history(),
|
||||
search.search({ top: true }),
|
||||
json(),
|
||||
keymap.of([...customKeymap, ...search.searchKeymap, ...commands.historyKeymap, ...commands.defaultKeymap]),
|
||||
keymapCompartment.of(jsonEditorKeymapExtension(modules)),
|
||||
EditorView.lineWrapping,
|
||||
EditorView.updateListener.of((update) => {
|
||||
if (!update.docChanged) return;
|
||||
@@ -333,11 +525,32 @@ async function initJsonEditor() {
|
||||
});
|
||||
|
||||
cmView = new EditorView({ state, parent: jsonEditorRef.value });
|
||||
jsonEditorReady.value = true;
|
||||
} catch (e: any) {
|
||||
jsonEditorReady.value = false;
|
||||
jsonEditorLoadError.value = e?.message || String(e);
|
||||
} finally {
|
||||
jsonEditorLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => settings.value.paramTypes,
|
||||
(value) => {
|
||||
if (focusedAdvancedOption.value !== "paramTypes") paramTypesDraft.value = stringifyAdvancedOption(value);
|
||||
},
|
||||
{ deep: true, immediate: true },
|
||||
);
|
||||
|
||||
watch(
|
||||
() => settings.value.editor,
|
||||
(value) => {
|
||||
validateEditorShortcuts(value);
|
||||
if (activeMode.value === "json") reconfigureJsonEditorKeymap();
|
||||
},
|
||||
{ deep: true, immediate: true },
|
||||
);
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(value) => {
|
||||
@@ -365,7 +578,7 @@ watch(
|
||||
await initJsonEditor();
|
||||
return;
|
||||
}
|
||||
emitValidity(true);
|
||||
validateEditorShortcuts();
|
||||
destroyJsonEditor();
|
||||
},
|
||||
{ immediate: true },
|
||||
@@ -405,7 +618,7 @@ onBeforeUnmount(() => {
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value="form" class="m-0 flex flex-col gap-4 pt-2">
|
||||
<div class="grid gap-4 md:grid-cols-3">
|
||||
<div class="grid gap-4 md:grid-cols-4">
|
||||
<div class="space-y-2">
|
||||
<Label>{{ t("settings.sqlFormatterKeywordCase") }}</Label>
|
||||
<Select :model-value="settings.keywordCase" @update:model-value="(value: any) => onCaseOption('keywordCase', value)">
|
||||
@@ -447,9 +660,23 @@ onBeforeUnmount(() => {
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2">
|
||||
<Label>{{ t("settings.sqlFormatterIdentifierCase") }}</Label>
|
||||
<Select :model-value="settings.identifierCase" @update:model-value="onIdentifierCase">
|
||||
<SelectTrigger class="w-full">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="option in caseOptions" :key="option.value" :value="option.value">
|
||||
{{ t(option.labelKey) }}
|
||||
</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4 md:grid-cols-[minmax(0,1fr)_10rem]">
|
||||
<div class="grid gap-4 md:grid-cols-[minmax(0,1fr)_10rem_12rem]">
|
||||
<div class="space-y-2">
|
||||
<Label>{{ t("settings.sqlFormatterIndent") }}</Label>
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
@@ -475,6 +702,20 @@ onBeforeUnmount(() => {
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2">
|
||||
<Label>{{ t("settings.sqlFormatterIndentStyle") }}</Label>
|
||||
<Select :model-value="settings.indentStyle" @update:model-value="onIndentStyle">
|
||||
<SelectTrigger class="w-full">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="option in indentStyleOptions" :key="option.value" :value="option.value">
|
||||
{{ t(option.labelKey) }}
|
||||
</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4 md:grid-cols-3">
|
||||
@@ -534,6 +775,46 @@ onBeforeUnmount(() => {
|
||||
<Switch id="sql-formatter-newline-before-semicolon" :model-value="settings.newlineBeforeSemicolon" @update:model-value="(value: boolean) => updateOption('newlineBeforeSemicolon', value)" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-3 rounded-md border border-border/70 bg-muted/10 p-3">
|
||||
<div class="text-sm font-medium">{{ t("settings.sqlFormatterAdvancedOptions") }}</div>
|
||||
<div class="space-y-2">
|
||||
<Label for="sql-formatter-param-types">{{ t("settings.sqlFormatterParamTypes") }}</Label>
|
||||
<textarea
|
||||
id="sql-formatter-param-types"
|
||||
:value="paramTypesDraft"
|
||||
spellcheck="false"
|
||||
class="min-h-28 w-full resize-y rounded-md border border-input bg-background px-3 py-2 font-mono text-xs outline-none transition-colors focus:border-ring focus:ring-1 focus:ring-ring/40"
|
||||
@input="onAdvancedJsonInput"
|
||||
@focus="onAdvancedJsonFocus"
|
||||
@blur="onAdvancedJsonBlur"
|
||||
/>
|
||||
</div>
|
||||
<p v-if="advancedConfigError" class="rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive">
|
||||
{{ advancedConfigError }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="space-y-3 rounded-md border border-border/70 bg-muted/10 p-3">
|
||||
<div class="text-sm font-medium">{{ t("settings.sqlFormatterEditorShortcuts") }}</div>
|
||||
<div class="overflow-x-auto rounded-md border bg-background">
|
||||
<div class="grid min-w-[420px] grid-cols-[minmax(10rem,1fr)_5rem_minmax(12rem,1.2fr)] items-center gap-2 border-b bg-muted/30 px-3 py-2 text-xs font-medium text-muted-foreground">
|
||||
<span>{{ t("settings.sqlFormatterShortcutAction") }}</span>
|
||||
<span class="text-center">{{ t("settings.sqlFormatterShortcutEnabled") }}</span>
|
||||
<span>{{ t(currentShortcutPlatformOption.labelKey) }}</span>
|
||||
</div>
|
||||
<div v-for="shortcut in settings.editor.shortcuts" :key="shortcut.id" class="grid min-w-[420px] grid-cols-[minmax(10rem,1fr)_5rem_minmax(12rem,1.2fr)] items-center gap-2 border-b px-3 py-2 text-xs last:border-b-0">
|
||||
<span class="min-w-0 truncate text-muted-foreground">{{ t(shortcutLabelKey(shortcut.id)) }}</span>
|
||||
<div class="flex justify-center">
|
||||
<Switch :model-value="shortcut.enabled" @update:model-value="(value: boolean) => updateEditorShortcutEnabled(shortcut.id, value)" />
|
||||
</div>
|
||||
<Input :model-value="shortcut.keys[currentShortcutPlatform]" class="h-8 font-mono text-xs" :disabled="!shortcut.enabled" @update:model-value="(value: string | number) => updateEditorShortcutKey(shortcut.id, currentShortcutPlatform, String(value))" />
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="editorShortcutError" class="rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive">
|
||||
{{ editorShortcutError }}
|
||||
</p>
|
||||
</div>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="json" class="m-0 flex min-h-0 flex-col gap-3 pt-2">
|
||||
@@ -542,6 +823,10 @@ onBeforeUnmount(() => {
|
||||
<WandSparkles class="mr-2 h-4 w-4" />
|
||||
{{ t("settings.sqlFormatterShortcutFormatJson") }}
|
||||
</Button>
|
||||
<Button type="button" variant="outline" size="sm" @click="copyJsonDraft">
|
||||
<Copy class="mr-2 h-4 w-4" />
|
||||
{{ t("settings.sqlFormatterCopyJson") }}
|
||||
</Button>
|
||||
<Button type="button" size="sm" :disabled="!!jsonValidationMessage" @click="applyJsonDraft">
|
||||
<Save class="mr-2 h-4 w-4" />
|
||||
{{ t("settings.sqlFormatterShortcutApply") }}
|
||||
@@ -549,7 +834,19 @@ onBeforeUnmount(() => {
|
||||
<span v-if="jsonEditorLoading" class="text-xs text-muted-foreground">{{ t("common.loading") }}</span>
|
||||
</div>
|
||||
|
||||
<div ref="jsonEditorRef" class="min-h-[260px]" />
|
||||
<div ref="jsonEditorRef" v-show="jsonEditorReady || jsonEditorLoading" class="min-h-[320px]" />
|
||||
|
||||
<textarea
|
||||
v-if="!jsonEditorReady && !jsonEditorLoading"
|
||||
:value="jsonDraft"
|
||||
spellcheck="false"
|
||||
class="min-h-[320px] w-full resize-y rounded-md border border-input bg-background px-3 py-2 font-mono text-xs outline-none transition-colors focus:border-ring focus:ring-1 focus:ring-ring/40"
|
||||
@input="onJsonDraftTextareaInput"
|
||||
/>
|
||||
|
||||
<p v-if="jsonEditorLoadError" class="rounded-md border border-amber-300/60 bg-amber-50 px-3 py-2 text-xs text-amber-800 dark:border-amber-400/40 dark:bg-amber-950/30 dark:text-amber-200">
|
||||
{{ t("settings.sqlFormatterJsonEditorLoadFailed", { message: jsonEditorLoadError }) }}
|
||||
</p>
|
||||
|
||||
<p v-if="jsonValidationMessage" class="rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive">
|
||||
{{ jsonValidationMessage }}
|
||||
|
||||
Reference in new issue
Block a user