diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue
index 68f8f1615..18b40f620 100644
--- a/apps/desktop/src/components/grid/DataGrid.vue
+++ b/apps/desktop/src/components/grid/DataGrid.vue
@@ -3345,6 +3345,7 @@ const {
isSelectingAll,
selectedRange,
selectedCells,
+ selectedCellMatrix,
selectedCellCount,
hasCellSelection,
clearCellSelection,
@@ -4979,6 +4980,11 @@ const {
copySelectionCsv,
copySelectionJson,
copySelectionSqlInList,
+ copySelectionAsInsert,
+ prefetchSelectionAsInsertStatement,
+ canCopyPreparedSelectionInsert,
+ canCopySelectionAsInsert,
+ selectionInsertRowCount,
copySelectedRowsTsv,
copySelectedRowsTsvWithHeaders,
copyColumnNames,
@@ -5018,6 +5024,7 @@ const {
exportBatchSize: computed(() => settingsStore.editorSettings.exportBatchSize),
hasCellSelection,
selectedCells,
+ selectedCellMatrix,
selectedRange,
contextCell: exportContextCell,
getRowItem: (rowId: number) => visibleDisplayItems.value.find((item) => item.id === rowId),
@@ -6356,6 +6363,7 @@ function onHeaderContext(col: string, columnIndex: number) {
}
contextHeaderColumn.value = col;
contextHeaderColumnIndex.value = columnIndex;
+ void prefetchCopyStatements();
}
async function copyHeaderColumn() {
if (!contextHeaderColumn.value) return;
@@ -6568,6 +6576,12 @@ function onRowContext(rowId: number, rowIndex: number) {
}
async function prefetchCopyStatements() {
+ if (canCopySelectionAsInsert.value) {
+ await prefetchSelectionAsInsertStatement();
+ if (selectionInsertRowCount.value > 1 && canCopyPreparedSelectionInsert()) {
+ await prefetchSelectionAsInsertStatement("row-by-row");
+ }
+ }
await prefetchRowAsInsertStatement(false);
if (isMultiRow.value) {
await prefetchRowAsInsertStatement(false, "row-by-row");
@@ -7262,6 +7276,13 @@ function copySubmenu(): ContextMenuItem {
}
function selectionSubmenu(): ContextMenuItem {
+ const insertItems: ContextMenuItem[] =
+ selectedCells.value.rows.length > 1
+ ? [
+ { label: t("grid.copySelectionInsertMerged"), action: () => copySelectionAsInsert("merged"), disabled: () => !canCopySelectionAsInsert.value || !canCopyPreparedSelectionInsert("merged") },
+ { label: t("grid.copySelectionInsertRowByRow"), action: () => copySelectionAsInsert("row-by-row"), disabled: () => !canCopySelectionAsInsert.value || !canCopyPreparedSelectionInsert("row-by-row") },
+ ]
+ : [{ label: t("grid.copySelectionInsert"), action: () => copySelectionAsInsert(), disabled: () => !canCopySelectionAsInsert.value || !canCopyPreparedSelectionInsert() }];
return {
label: t("grid.selection"),
icon: SquareDashed,
@@ -7271,6 +7292,7 @@ function selectionSubmenu(): ContextMenuItem {
{ label: t("grid.copySelectionCsv"), action: copySelectionCsv },
{ label: t("grid.copySelectionJson"), action: copySelectionJson },
{ label: t("grid.copySelectionSql"), action: copySelectionSqlInList },
+ ...insertItems,
{ label: "", separator: true },
{ label: t("grid.clearSelection"), action: clearCellSelection },
],
diff --git a/apps/desktop/src/components/ui/CustomContextMenu.vue b/apps/desktop/src/components/ui/CustomContextMenu.vue
index 5ac83ccee..06967052d 100644
--- a/apps/desktop/src/components/ui/CustomContextMenu.vue
+++ b/apps/desktop/src/components/ui/CustomContextMenu.vue
@@ -7,7 +7,7 @@ import { registerGlobalContextMenu, type ContextMenuRegistration } from "@/compo
export interface ContextMenuItem {
label: string;
action?: () => void;
- disabled?: boolean;
+ disabled?: boolean | (() => boolean);
separator?: boolean;
icon?: Component;
iconClass?: string;
@@ -102,14 +102,14 @@ onMounted(() => {
});
function handleItemClick(item: ContextMenuItem) {
- if (item.disabled) return;
+ if (itemIsDisabled(item)) return;
if (item.children?.length) return; // submenu trigger — do nothing on click
close();
item.action?.();
}
function handleSubItemClick(item: ContextMenuItem) {
- if (item.disabled) return;
+ if (itemIsDisabled(item)) return;
close();
item.action?.();
}
@@ -143,7 +143,7 @@ function onItemMouseEnter(index: number, event: MouseEvent) {
lastMouseX = event.clientX;
lastMouseY = event.clientY;
const item = activeItems.value[index];
- if (!item?.children?.length || item.disabled) {
+ if (!item?.children?.length || itemIsDisabled(item)) {
// Moving to an item without children — close submenu immediately, no delay needed
activeSubIndex.value = null;
return;
@@ -240,6 +240,10 @@ function itemButtonClass(variant?: "default" | "destructive") {
];
}
+function itemIsDisabled(item: ContextMenuItem): boolean {
+ return typeof item.disabled === "function" ? item.disabled() : !!item.disabled;
+}
+
function shortcutKeys(shortcut?: string): string[] {
return shortcutDisplayKeys(shortcut);
}
@@ -264,7 +268,7 @@ onBeforeUnmount(() => {
-