fix(settings): open settings with reactive color schemes

This commit is contained in:
t8y2 committed 2026-08-19 20:44:56 +08:00
1 parent 4e74f77cc8
commit 5011468a9a
5 files changed
+33 -11

No files matched your search

@@ -8,7 +8,7 @@ import ColorSpectrumPicker from "@/components/ui/ColorSpectrumPicker.vue";
import { Copy, Pencil, Plus, RotateCcw, Trash2 } from "@lucide/vue";
import { useI18n } from "vue-i18n";
import { useTheme } from "@/composables/useTheme";
import { DATA_GRID_TYPE_COLOR_SCHEME_AUTO_ID, type DataGridTypeColorKey, type DataGridTypeColorScheme, defaultDataGridTypeColors, normalizeDataGridTypeColors } from "@/lib/dataGrid/dataGridTypeColorScheme";
import { DATA_GRID_TYPE_COLOR_SCHEME_AUTO_ID, cloneDataGridTypeColorSchemes, type DataGridTypeColorKey, type DataGridTypeColorScheme, defaultDataGridTypeColors, normalizeDataGridTypeColors } from "@/lib/dataGrid/dataGridTypeColorScheme";
interface Props {
open: boolean;
@@ -29,9 +29,6 @@ const localSchemes = ref<DataGridTypeColorScheme[]>([]);
const activeEditId = ref(DATA_GRID_TYPE_COLOR_SCHEME_AUTO_ID);
const renamingId = ref<string | null>(null);
const renamingName = ref("");
function cloneSchemes(schemes: DataGridTypeColorScheme[]): DataGridTypeColorScheme[] {
return schemes.map((scheme) => ({ ...scheme, colors: { ...scheme.colors } }));
}
// Everything below edits this buffer only. Nothing reaches the settings store
// until Done, so Cancel just drops it.
@@ -39,7 +36,7 @@ watch(
() => props.open,
(isOpen) => {
if (!isOpen) return;
localSchemes.value = cloneSchemes(props.schemes);
localSchemes.value = cloneDataGridTypeColorSchemes(props.schemes);
activeEditId.value = props.activeSchemeId;
renamingId.value = null;
},
@@ -127,7 +124,7 @@ function confirmRename() {
function handleDone() {
emit(
"change",
cloneSchemes(localSchemes.value).map((scheme) => ({ ...scheme, colors: normalizeDataGridTypeColors(scheme.colors) })),
cloneDataGridTypeColorSchemes(localSchemes.value).map((scheme) => ({ ...scheme, colors: normalizeDataGridTypeColors(scheme.colors) })),
activeEditId.value,
);
emit("update:open", false);