Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

refactor(grid): extract cell detail edit workflow

t8y2789740c9becd
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue
index e8d64eb0d6..488e3ff44d 100644
--- a/apps/desktop/src/components/grid/DataGrid.vue
+++ b/apps/desktop/src/components/grid/DataGrid.vue
@@ -160,8 +160,7 @@ import {
type BinaryCellDownloadMode,
} from "@/lib/dataGrid/binaryCellDownload";
import { buildBinaryHexViewRows } from "@/lib/dataGrid/binaryHexViewer";
-import { canFormatCellDetailJson, cellDetailEditorText, compactJsonText, defaultCellDetailTab, formatJsonText, isGeometryColumnType, linkedCellDetailTarget, looksLikeJsonContainerText, valueEditorActions, visibleCellDetailTabs, type CellDetailTab } from "@/lib/dataGrid/cellDetailPresentation";
-import { createJsonValueDiffSnapshot, isJsonValueDiffAvailable, type JsonValueDiffContext, type JsonValueDiffSnapshot } from "@/lib/dataGrid/jsonValueDiff";
+import { canFormatCellDetailJson, cellDetailEditorText, defaultCellDetailTab, isGeometryColumnType, linkedCellDetailTarget, looksLikeJsonContainerText, visibleCellDetailTabs, type CellDetailTab } from "@/lib/dataGrid/cellDetailPresentation";
import {
buildDataGridCellDetail,
buildDataGridColumnDetail,
@@ -322,6 +321,7 @@ import { createDataGridFilterConditionCache, useDataGridFilterBuilder, type Data
import { cloneDataGridStructuredFilterRules, loadDataGridStructuredFilterState, saveDataGridStructuredFilterState, type DataGridCachedServerColumnFilter, type DataGridStructuredFilterCacheState } from "@/lib/dataGrid/dataGridFilterBuilderPersistence";
import { useSqlHighlighter } from "@/composables/useSqlHighlighter";
import { useCellDetailEditor, type UseCellDetailEditorReturn } from "@/composables/useCellDetailEditor";
+import { useDataGridCellDetailEdit } from "@/composables/useDataGridCellDetailEdit";
import { useTheme } from "@/composables/useTheme";
import { useConnectionStore } from "@/stores/connectionStore";
import { useQueryStore } from "@/stores/queryStore";
@@ -5751,42 +5751,6 @@ watch(activeCellDetailTabs, (tabs) => {
}
});
-watch(activeCellDetailTab, (tab) => {
- if (tab === "valueEditor") {
- void startDetailEdit();
- } else {
- resetDetailEdit();
- }
-});
-
-const detailEditValue = ref("");
-const detailEditOriginalValue = ref("");
-const isEditingDetail = ref(false);
-// commitDetailEdit() intentionally re-triggers the activeCellDetail watch below to
-// re-sync the editor with the canonical committed value. Any other change to the
-// same cell's underlying data while still editing (e.g. a result refresh, or a
-// large-value hydration resolving) must not clobber the user's in-progress draft.
-let allowActiveCellDetailResync = false;
-let lastSyncedDetailCellKey: string | null = null;
-const detailValueDiffOpen = ref(false);
-const detailValueDiffSnapshot = ref<Readonly<JsonValueDiffSnapshot> | null>(null);
-const hasPendingDetailEditorDraft = computed(() => isEditingDetail.value && detailEditValue.value !== detailEditOriginalValue.value);
-const detailJsonDiffContext = computed<JsonValueDiffContext | null>(() => {
- const detail = activeCellDetail.value;
- if (!detail) return null;
- return {
- columnName: detail.column,
- columnType: detail.type,
- originalValue: detailEditOriginalValue.value,
- isEditable: detail.isEditable,
- isEditing: isEditingDetail.value,
- };
-});
-const showDetailJsonCompare = computed(() => {
- const context = detailJsonDiffContext.value;
- return !!context && isJsonValueDiffAvailable(context);
-});
-const canCompareDetailJson = computed(() => showDetailJsonCompare.value && hasPendingDetailEditorDraft.value);
const hasPendingInlineEditorDraft = computed(() => {
const cell = editingCell.value;
if (!cell) return false;
@@ -5795,26 +5759,6 @@ const hasPendingInlineEditorDraft = computed(() => {
const originalValue = inlineCellEditorText(item.data[cell.col] ?? null, cell.col);
return editValue.value !== originalValue;
});
-const hasPendingDataEditorDraft = computed(() => hasPendingDetailEditorDraft.value || hasPendingInlineEditorDraft.value);
-
-function syncPendingDataEditorDraft(pending: boolean) {
- if (props.context !== "table-data" || !props.cacheKey) return;
- const tab = queryStore.tabs.find((item) => item.id === props.cacheKey);
- if (tab?.mode === "data") tab.hasPendingDataEditorDraft = pending || undefined;
-}
-
-watch(hasPendingDataEditorDraft, syncPendingDataEditorDraft, {
- immediate: true,
- flush: "sync",
-});
-
-const activeValueEditorActions = computed(() => {
- const detail = activeCellDetail.value;
- return valueEditorActions({
- canSetNull: !!detail?.isEditable && detail.value !== null,
- canFormatJson: !!detail?.isEditable && canFormatCellDetailJson(detail.value, detail.type),
- });
-});
const detailSqlConditionCopy = ref<PreparedCopyValue>({
key: "",
@@ -5891,31 +5835,8 @@ async function prefetchDetailSqlCondition() {
}
}
-watch(activeCellDetail, (detail) => {
+watch(activeCellDetail, () => {
void prefetchDetailSqlCondition();
- if (activeCellDetailTab.value !== "valueEditor") return;
- if (!detail?.isEditable) {
- resetDetailEdit();
- return;
- }
- const cellKey = `${detail.rowId}:${detail.colIndex}`;
- const isSameCellStillEditing = isEditingDetail.value && cellKey === lastSyncedDetailCellKey;
- lastSyncedDetailCellKey = cellKey;
- if (isSameCellStillEditing && !allowActiveCellDetailResync) {
- // The row's underlying data changed (e.g. a result refresh or a large-value
- // hydration) while the user is still editing this same cell. Keep their draft.
- return;
- }
- allowActiveCellDetailResync = false;
- const value = dataGridCellEditorText({
- value: detail.value,
- databaseType: resolvedDatabaseType.value,
- columnInfo: tableColumnForGridColumn(detail.colIndex) ?? resultColumnInfoForGridColumn(detail.colIndex),
- });
- detailEditValue.value = value;
- detailEditOriginalValue.value = value;
- syncEditorFromDetailEdit();
- isEditingDetail.value = true;
});
const detailTemporalEditorConfig = computed(() => {
@@ -5980,13 +5901,65 @@ watch(valueEditorContainer, async (el) => {
}
});
-function resetDetailEdit() {
- isEditingDetail.value = false;
- detailEditValue.value = "";
- detailEditOriginalValue.value = "";
- lastSyncedDetailCellKey = null;
+const detailEdit = useDataGridCellDetailEdit({
+ activeDetail: activeCellDetail,
+ activeTab: activeCellDetailTab,
+ jsonFormatted: cellDetailJsonFormatted,
+ databaseType: resolvedDatabaseType,
+ resultRows: computed(() => props.result.rows),
+ getColumnInfo: (columnIndex) => tableColumnForGridColumn(columnIndex) ?? resultColumnInfoForGridColumn(columnIndex),
+ getRowItem,
+ hydrateLargeValueCell,
+ applyCellValue,
+ restoreCellValue,
+ syncEditor: (value, columnType) => {
+ const editor = getDetailEditor();
+ if (editor) editor.setValue(value, columnType);
+ },
+ refreshDetail: () => {
+ detailCell.value = detailCell.value ? { ...detailCell.value } : null;
+ },
+ warnFormattedJsonEdit: warnFormattedJsonEditIfNeeded,
+});
+
+const {
+ detailEditValue,
+ detailEditOriginalValue,
+ isEditingDetail,
+ detailValueDiffOpen,
+ detailValueDiffSnapshot,
+ hasPendingDetailEditorDraft,
+ showDetailJsonCompare,
+ canCompareDetailJson,
+ activeValueEditorActions,
+ resetDetailEdit,
+ syncEditorFromDetailEdit,
+ startDetailEdit,
+ commitDetailEdit,
+ cancelDetailEdit,
+ cancelValueEditorEdit,
+ commitValueEditorEdit,
+ restoreDetailOriginalValue,
+ setValueEditorNull,
+ formatValueEditorJson,
+ compactDetailJson,
+ openDetailJsonCompare,
+ setDetailNull,
+} = detailEdit;
+
+const hasPendingDataEditorDraft = computed(() => hasPendingDetailEditorDraft.value || hasPendingInlineEditorDraft.value);
+
+function syncPendingDataEditorDraft(pending: boolean) {
+ if (props.context !== "table-data" || !props.cacheKey) return;
+ const tab = queryStore.tabs.find((item) => item.id === props.cacheKey);
+ if (tab?.mode === "data") tab.hasPendingDataEditorDraft = pending || undefined;
}
+watch(hasPendingDataEditorDraft, syncPendingDataEditorDraft, {
+ immediate: true,
+ flush: "sync",
+});
+
function closeCellDetails() {
resetDetailEdit();
showCellDetail.value = false;
@@ -6007,15 +5980,6 @@ function copyMongoJsonPreview() {
if (mongoJsonPreviewFullText.value) copyText(mongoJsonPreviewFullText.value);
}
-function cellDetailEditText(detail: DataGridCellDetail): string {
- if (sideDetailJsonView.value && detail.formattedJson) return detail.formattedJson;
- return dataGridCellEditorText({
- value: detail.value,
- databaseType: props.databaseType,
- columnInfo: tableColumnForGridColumn(detail.colIndex),
- });
-}
-
function warnFormattedJsonEditIfNeeded(detail: DataGridCellDetail, force = false) {
if (!force && (!sideDetailJsonView.value || !detail.formattedJson)) return;
const count = Number(safeLocalStorageGet(FORMATTED_JSON_EDIT_WARNING_COUNT_STORAGE_KEY)) || 0;
@@ -6036,136 +6000,6 @@ function toggleCellDetailMetadataCollapsed() {
});
}
-async function startDetailEdit() {
- const initialDetail = activeCellDetail.value;
- if (!initialDetail || !initialDetail.isEditable) return;
- if (!(await hydrateLargeValueCell(initialDetail.rowId, initialDetail.colIndex))) return;
- const detail = activeCellDetail.value;
- if (!detail || !detail.isEditable) return;
- warnFormattedJsonEditIfNeeded(detail);
- const value = cellDetailEditText(detail);
- detailEditValue.value = value;
- detailEditOriginalValue.value = value;
- isEditingDetail.value = true;
-}
-
-function commitDetailEdit() {
- const detail = activeCellDetail.value;
- if (!detail || !isEditingDetail.value) return;
- isEditingDetail.value = false;
-
- const item = getRowItem(detail.rowId);
- if (!item || item.isDeleted) return;
- applyCellValue(detail.rowId, detail.colIndex, detailEditValue.value);
- detailEditOriginalValue.value = detailEditValue.value;
- // Force the activeCellDetail watch to re-run so the editor picks up the
- // canonical (possibly coerced) committed value.
- allowActiveCellDetailResync = true;
- detailCell.value = detailCell.value ? { ...detailCell.value } : null;
-}
-
-function cancelDetailEdit() {
- resetDetailEdit();
-}
-
-function syncEditorFromDetailEdit() {
- const editor = getDetailEditor();
- if (editor) {
- editor.setValue(detailEditValue.value, activeCellDetail.value?.type);
- }
-}
-
-function cancelValueEditorEdit() {
- const detail = activeCellDetail.value;
- if (!detail || !detail.isEditable) return;
- const value = dataGridCellEditorText({
- value: detail.value,
- databaseType: props.databaseType,
- columnInfo: tableColumnForGridColumn(detail.colIndex),
- });
- detailEditValue.value = value;
- detailEditOriginalValue.value = value;
- syncEditorFromDetailEdit();
- isEditingDetail.value = true;
-}
-
-function commitValueEditorEdit() {
- commitDetailEdit();
- if (activeCellDetailTab.value === "valueEditor") {
- isEditingDetail.value = true;
- }
-}
-
-function restoreDetailOriginalValue() {
- const detail = activeCellDetail.value;
- if (!detail || !detail.isEditable) return;
-
- const item = getRowItem(detail.rowId);
- if (!item || item.isDeleted) return;
-
- let restoredValue: CellValue = null;
-
- if (!item.isNew && item.sourceIndex !== undefined) {
- restoredValue = props.result.rows[item.sourceIndex]?.[detail.colIndex] ?? null;
- }
- restoreCellValue(detail.rowId, detail.colIndex);
-
- const value = dataGridCellEditorText({
- value: restoredValue,
- databaseType: props.databaseType,
- columnInfo: tableColumnForGridColumn(detail.colIndex),
- });
- detailEditValue.value = value;
- detailEditOriginalValue.value = value;
- syncEditorFromDetailEdit();
- isEditingDetail.value = activeCellDetailTab.value === "valueEditor";
- detailCell.value = { ...detailCell.value! };
-}
-
-function setValueEditorNull() {
- setDetailNull();
- detailEditValue.value = cellDetailEditorText(null);
- detailEditOriginalValue.value = detailEditValue.value;
- syncEditorFromDetailEdit();
- isEditingDetail.value = activeCellDetailTab.value === "valueEditor";
-}
-
-function formatValueEditorJson() {
- const detail = activeCellDetail.value;
- if (!detail || !canFormatCellDetailJson(detailEditValue.value, detail.type)) return;
- detailEditValue.value = formatJsonText(detailEditValue.value) ?? detailEditValue.value;
- syncEditorFromDetailEdit();
- warnFormattedJsonEditIfNeeded(detail, true);
-}
-
-function compactDetailJson() {
- const detail = activeCellDetail.value;
- if (!detail || !canFormatCellDetailJson(detailEditValue.value, detail.type)) return;
- detailEditValue.value = compactJsonText(detailEditValue.value) ?? detailEditValue.value;
- syncEditorFromDetailEdit();
-}
-
-function openDetailJsonCompare() {
- const context = detailJsonDiffContext.value;
- if (!context) return;
- const snapshot = createJsonValueDiffSnapshot({ ...context, currentValue: detailEditValue.value });
- if (!snapshot) return;
- detailValueDiffSnapshot.value = snapshot;
- detailValueDiffOpen.value = true;
-}
-
-function setDetailNull() {
- const detail = activeCellDetail.value;
- if (!detail || !detail.isEditable) return;
-
- const item = getRowItem(detail.rowId);
- if (!item || item.isDeleted) return;
-
- applyCellValue(detail.rowId, detail.colIndex, null);
- resetDetailEdit();
- detailCell.value = { ...detailCell.value! };
-}
-
function applyColumnSort(column: string, columnIndex: number, direction: "asc" | "desc" | null, mode: DataGridSortMode = "database") {
if (getIsResizing()) return;
if (mode === "local" && direction && props.result.large_value_cells?.some((cell) => cell.column_index === columnIndex)) {
diff --git a/apps/desktop/src/components/grid/__tests__/DataGridSurfaces.spec.ts b/apps/desktop/src/components/grid/__tests__/DataGridSurfaces.spec.ts
index bba66310f4..c161a4a511 100644
--- a/apps/desktop/src/components/grid/__tests__/DataGridSurfaces.spec.ts
+++ b/apps/desktop/src/components/grid/__tests__/DataGridSurfaces.spec.ts
@@ -101,6 +101,7 @@ import DataGridQueryControls from "@/components/grid/DataGridQueryControls.vue";
import DataGridSearchBar from "@/components/grid/DataGridSearchBar.vue";
const dataGridSource = readFileSync("apps/desktop/src/components/grid/DataGrid.vue", "utf8");
+const dataGridCellDetailEditSource = readFileSync("apps/desktop/src/composables/useDataGridCellDetailEdit.ts", "utf8");
const cellDetailPanelSource = readFileSync("apps/desktop/src/components/grid/DataGridCellDetailPanel.vue", "utf8");
const cellDetailHeaderSource = readFileSync("apps/desktop/src/components/grid/DataGridCellDetailHeader.vue", "utf8");
const globalsCss = readFileSync("apps/desktop/src/styles/globals.css", "utf8");
@@ -1636,8 +1637,8 @@ describe("cell detail surfaces", () => {
});
it("snapshots comparison values before opening and suppresses modal-induced blur commits", () => {
- expect(dataGridSource).toContain("detailValueDiffSnapshot.value = snapshot;");
- expect(dataGridSource).toContain("detailValueDiffOpen.value = true;");
+ expect(dataGridCellDetailEditSource).toContain("detailValueDiffSnapshot.value = snapshot;");
+ expect(dataGridCellDetailEditSource).toContain("detailValueDiffOpen.value = true;");
expect(dataGridSource).toContain("if (!detailValueDiffOpen.value) commitValueEditorEdit();");
expect(dataGridSource).toContain(':disabled="!canCompareDetailJson" @mousedown.prevent @click="openDetailJsonCompare"');
expect(dataGridSource).toContain('v-model:open="detailValueDiffOpen" :snapshot="detailValueDiffSnapshot"');
diff --git a/apps/desktop/src/composables/useDataGridCellDetailEdit.ts b/apps/desktop/src/composables/useDataGridCellDetailEdit.ts
new file mode 100644
index 0000000000..8606683b88
--- /dev/null
+++ b/apps/desktop/src/composables/useDataGridCellDetailEdit.ts
@@ -0,0 +1,245 @@
+import { computed, ref, watch, type ComputedRef, type Ref } from "vue";
+import { cellDetailEditorText, canFormatCellDetailJson, compactJsonText, formatJsonText, looksLikeJsonContainerText, valueEditorActions, type CellDetailTab } from "@/lib/dataGrid/cellDetailPresentation";
+import type { DataGridCellDetail } from "@/lib/dataGrid/dataGridDetail";
+import { dataGridCellEditorText } from "@/lib/dataGrid/dataGridCellCoercion";
+import type { CellValue } from "@/lib/dataGrid/cellValue";
+import { createJsonValueDiffSnapshot, isJsonValueDiffAvailable, type JsonValueDiffContext, type JsonValueDiffSnapshot } from "@/lib/dataGrid/jsonValueDiff";
+import type { ColumnInfo, DatabaseType } from "@/types/database";
+
+interface DetailEditRowItem {
+ sourceIndex?: number;
+ isNew: boolean;
+ isDeleted: boolean;
+}
+
+export interface UseDataGridCellDetailEditOptions {
+ activeDetail: ComputedRef<DataGridCellDetail | null>;
+ activeTab: Ref<CellDetailTab>;
+ jsonFormatted: ComputedRef<boolean>;
+ databaseType: ComputedRef<DatabaseType | undefined>;
+ resultRows: ComputedRef<readonly (readonly CellValue[])[]>;
+ getColumnInfo: (columnIndex: number) => ColumnInfo | Pick<ColumnInfo, "data_type"> | undefined;
+ getRowItem: (rowId: number) => DetailEditRowItem | undefined;
+ hydrateLargeValueCell: (rowId: number, columnIndex: number) => Promise<boolean>;
+ applyCellValue: (rowId: number, columnIndex: number, value: string | null) => void;
+ restoreCellValue: (rowId: number, columnIndex: number) => void;
+ syncEditor: (value: string, columnType?: string) => void;
+ refreshDetail: () => void;
+ warnFormattedJsonEdit: (detail: DataGridCellDetail, force?: boolean) => void;
+}
+
+export function useDataGridCellDetailEdit(options: UseDataGridCellDetailEditOptions) {
+ const detailEditValue = ref("");
+ const detailEditOriginalValue = ref("");
+ const isEditingDetail = ref(false);
+ const detailValueDiffOpen = ref(false);
+ const detailValueDiffSnapshot = ref<Readonly<JsonValueDiffSnapshot> | null>(null);
+ let allowActiveCellDetailResync = false;
+ let lastSyncedDetailCellKey: string | null = null;
+
+ const hasPendingDetailEditorDraft = computed(() => isEditingDetail.value && detailEditValue.value !== detailEditOriginalValue.value);
+ const detailJsonDiffContext = computed<JsonValueDiffContext | null>(() => {
+ const detail = options.activeDetail.value;
+ if (!detail) return null;
+ return {
+ columnName: detail.column,
+ columnType: detail.type,
+ originalValue: detailEditOriginalValue.value,
+ isEditable: detail.isEditable,
+ isEditing: isEditingDetail.value,
+ };
+ });
+ const showDetailJsonCompare = computed(() => {
+ const context = detailJsonDiffContext.value;
+ return !!context && isJsonValueDiffAvailable(context);
+ });
+ const canCompareDetailJson = computed(() => showDetailJsonCompare.value && hasPendingDetailEditorDraft.value);
+ const activeValueEditorActions = computed(() => {
+ const detail = options.activeDetail.value;
+ return valueEditorActions({
+ canSetNull: !!detail?.isEditable && detail.value !== null,
+ canFormatJson: !!detail?.isEditable && canFormatCellDetailJson(detail.value, detail.type),
+ });
+ });
+
+ function editorText(value: CellValue, columnIndex: number): string {
+ return dataGridCellEditorText({
+ value,
+ databaseType: options.databaseType.value,
+ columnInfo: options.getColumnInfo(columnIndex),
+ });
+ }
+
+ function activeDetailEditorText(detail: DataGridCellDetail): string {
+ if (options.jsonFormatted.value && detail.formattedJson) return detail.formattedJson;
+ return editorText(detail.value, detail.colIndex);
+ }
+
+ function resetDetailEdit() {
+ isEditingDetail.value = false;
+ detailEditValue.value = "";
+ detailEditOriginalValue.value = "";
+ lastSyncedDetailCellKey = null;
+ }
+
+ function syncEditorFromDetailEdit() {
+ options.syncEditor(detailEditValue.value, options.activeDetail.value?.type);
+ }
+
+ watch(options.activeTab, (tab) => {
+ if (tab === "valueEditor") {
+ void startDetailEdit();
+ } else {
+ resetDetailEdit();
+ }
+ });
+
+ watch(options.activeDetail, (detail) => {
+ if (options.activeTab.value !== "valueEditor") return;
+ if (!detail?.isEditable) {
+ resetDetailEdit();
+ return;
+ }
+ const cellKey = `${detail.rowId}:${detail.colIndex}`;
+ const isSameCellStillEditing = isEditingDetail.value && cellKey === lastSyncedDetailCellKey;
+ lastSyncedDetailCellKey = cellKey;
+ if (isSameCellStillEditing && !allowActiveCellDetailResync) return;
+ allowActiveCellDetailResync = false;
+ const value = editorText(detail.value, detail.colIndex);
+ detailEditValue.value = value;
+ detailEditOriginalValue.value = value;
+ syncEditorFromDetailEdit();
+ isEditingDetail.value = true;
+ });
+
+ async function startDetailEdit() {
+ const initialDetail = options.activeDetail.value;
+ if (!initialDetail || !initialDetail.isEditable) return;
+ if (!(await options.hydrateLargeValueCell(initialDetail.rowId, initialDetail.colIndex))) return;
+ const detail = options.activeDetail.value;
+ if (!detail || !detail.isEditable) return;
+ options.warnFormattedJsonEdit(detail);
+ const value = activeDetailEditorText(detail);
+ detailEditValue.value = value;
+ detailEditOriginalValue.value = value;
+ isEditingDetail.value = true;
+ }
+
+ function commitDetailEdit() {
+ const detail = options.activeDetail.value;
+ if (!detail || !isEditingDetail.value) return;
+ isEditingDetail.value = false;
+ const item = options.getRowItem(detail.rowId);
+ if (!item || item.isDeleted) return;
+ options.applyCellValue(detail.rowId, detail.colIndex, detailEditValue.value);
+ detailEditOriginalValue.value = detailEditValue.value;
+ allowActiveCellDetailResync = true;
+ options.refreshDetail();
+ }
+
+ function cancelDetailEdit() {
+ resetDetailEdit();
+ }
+
+ function cancelValueEditorEdit() {
+ const detail = options.activeDetail.value;
+ if (!detail || !detail.isEditable) return;
+ const value = editorText(detail.value, detail.colIndex);
+ detailEditValue.value = value;
+ detailEditOriginalValue.value = value;
+ syncEditorFromDetailEdit();
+ isEditingDetail.value = true;
+ }
+
+ function commitValueEditorEdit() {
+ commitDetailEdit();
+ if (options.activeTab.value === "valueEditor") isEditingDetail.value = true;
+ }
+
+ function restoreDetailOriginalValue() {
+ const detail = options.activeDetail.value;
+ if (!detail || !detail.isEditable) return;
+ const item = options.getRowItem(detail.rowId);
+ if (!item || item.isDeleted) return;
+ let restoredValue: CellValue = null;
+ if (!item.isNew && item.sourceIndex !== undefined) {
+ restoredValue = options.resultRows.value[item.sourceIndex]?.[detail.colIndex] ?? null;
+ }
+ options.restoreCellValue(detail.rowId, detail.colIndex);
+ const value = editorText(restoredValue, detail.colIndex);
+ detailEditValue.value = value;
+ detailEditOriginalValue.value = value;
+ syncEditorFromDetailEdit();
+ isEditingDetail.value = options.activeTab.value === "valueEditor";
+ options.refreshDetail();
+ }
+
+ function setValueEditorNull() {
+ setDetailNull();
+ detailEditValue.value = cellDetailEditorText(null);
+ detailEditOriginalValue.value = detailEditValue.value;
+ syncEditorFromDetailEdit();
+ isEditingDetail.value = options.activeTab.value === "valueEditor";
+ }
+
+ function formatValueEditorJson() {
+ const detail = options.activeDetail.value;
+ if (!detail || !canFormatCellDetailJson(detailEditValue.value, detail.type)) return;
+ detailEditValue.value = formatJsonText(detailEditValue.value) ?? detailEditValue.value;
+ syncEditorFromDetailEdit();
+ options.warnFormattedJsonEdit(detail, true);
+ }
+
+ function compactDetailJson() {
+ const detail = options.activeDetail.value;
+ if (!detail || !canFormatCellDetailJson(detailEditValue.value, detail.type)) return;
+ detailEditValue.value = compactJsonText(detailEditValue.value) ?? detailEditValue.value;
+ syncEditorFromDetailEdit();
+ }
+
+ function openDetailJsonCompare() {
+ const context = detailJsonDiffContext.value;
+ if (!context) return;
+ const snapshot = createJsonValueDiffSnapshot({ ...context, currentValue: detailEditValue.value });
+ if (!snapshot) return;
+ detailValueDiffSnapshot.value = snapshot;
+ detailValueDiffOpen.value = true;
+ }
+
+ function setDetailNull() {
+ const detail = options.activeDetail.value;
+ if (!detail || !detail.isEditable) return;
+ const item = options.getRowItem(detail.rowId);
+ if (!item || item.isDeleted) return;
+ options.applyCellValue(detail.rowId, detail.colIndex, null);
+ resetDetailEdit();
+ options.refreshDetail();
+ }
+
+ return {
+ detailEditValue,
+ detailEditOriginalValue,
+ isEditingDetail,
+ detailValueDiffOpen,
+ detailValueDiffSnapshot,
+ hasPendingDetailEditorDraft,
+ detailJsonDiffContext,
+ showDetailJsonCompare,
+ canCompareDetailJson,
+ activeValueEditorActions,
+ resetDetailEdit,
+ syncEditorFromDetailEdit,
+ startDetailEdit,
+ commitDetailEdit,
+ cancelDetailEdit,
+ cancelValueEditorEdit,
+ commitValueEditorEdit,
+ restoreDetailOriginalValue,
+ setValueEditorNull,
+ formatValueEditorJson,
+ compactDetailJson,
+ openDetailJsonCompare,
+ setDetailNull,
+ looksLikeJsonContainerText,
+ };
+}