|
|
|
@ -848,98 +848,101 @@ export function useMultiSelect(
|
|
|
|
|
|
|
|
|
|
const selectionRowCount = Math.max(clipboardMatrix.length, selectedRange.end.row - selectedRange.start.row + 1) |
|
|
|
|
|
|
|
|
|
const pasteMatrixRows = selectionRowCount |
|
|
|
|
const pasteMatrixCols = clipboardMatrix[0].length |
|
|
|
|
|
|
|
|
|
const colsToPaste = unref(fields).slice(activeCell.col, activeCell.col + pasteMatrixCols) |
|
|
|
|
const rowsToPaste = unref(data).slice(activeCell.row, activeCell.row + selectionRowCount) |
|
|
|
|
|
|
|
|
|
const { totalRows = 0, page = 1, pageSize = 100 } = unref(paginationDataRef)! |
|
|
|
|
const totalRowsBeforeActiveCell = (page - 1) * pageSize + activeCell.row |
|
|
|
|
const availableRowsToUpdate = Math.max(0, totalRows - totalRowsBeforeActiveCell) |
|
|
|
|
const rowsToAdd = Math.max(0, selectionRowCount - availableRowsToUpdate) |
|
|
|
|
|
|
|
|
|
const rowsInCurrentPage = unref(data).length |
|
|
|
|
const rowsAffectedInCurrentPage = Math.min(selectionRowCount, rowsInCurrentPage - activeCell.row) |
|
|
|
|
const rowsAffectedInOtherPages = Math.max(0, selectionRowCount - rowsAffectedInCurrentPage) |
|
|
|
|
|
|
|
|
|
let options = { |
|
|
|
|
continue: false, |
|
|
|
|
expand: true, |
|
|
|
|
expand: rowsToAdd > 0 || rowsAffectedInOtherPages > 0 || (rowsAffectedInOtherPages > 0 && rowsToAdd > 0), |
|
|
|
|
} |
|
|
|
|
if (options.expand) { |
|
|
|
|
options = await expandRows(rowsToAdd, rowsAffectedInOtherPages) |
|
|
|
|
if (!options.continue) return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const rowToPasteLen = rowsToPaste.length |
|
|
|
|
const updatedRows: any[] = [] |
|
|
|
|
const newRows: any[] = [] |
|
|
|
|
const propsToPaste: string[] = [] |
|
|
|
|
let isInfoShown = false |
|
|
|
|
|
|
|
|
|
for (let i = 0; i < selectionRowCount; i++) { |
|
|
|
|
const clipboardRowIndex = i % clipboardMatrix.length |
|
|
|
|
let targetRow: any |
|
|
|
|
|
|
|
|
|
if (pasteMatrixRows > rowsToPaste.length) { |
|
|
|
|
rowsToPaste.push( |
|
|
|
|
...Array(pasteMatrixRows - rowsToPaste.length) |
|
|
|
|
.fill({}) |
|
|
|
|
.map(() => ({ |
|
|
|
|
if (i < availableRowsToUpdate) { |
|
|
|
|
const absoluteRowIndex = totalRowsBeforeActiveCell + i |
|
|
|
|
targetRow = |
|
|
|
|
i < unref(data).length |
|
|
|
|
? unref(data)[i] |
|
|
|
|
: { |
|
|
|
|
row: {}, |
|
|
|
|
oldRow: {}, |
|
|
|
|
rowMeta: { |
|
|
|
|
isExpandedData: true, |
|
|
|
|
isExistingRow: true, |
|
|
|
|
page: Math.floor(absoluteRowIndex / pageSize) + 1, |
|
|
|
|
rowInPage: absoluteRowIndex % pageSize, |
|
|
|
|
}, |
|
|
|
|
})), |
|
|
|
|
) |
|
|
|
|
options = await expandRows(pasteMatrixRows - rowToPasteLen) |
|
|
|
|
|
|
|
|
|
if (!options.continue) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
const propsToPaste: string[] = [] |
|
|
|
|
|
|
|
|
|
let pastedRows = 0 |
|
|
|
|
let isInfoShown = false |
|
|
|
|
|
|
|
|
|
for (let i = 0; i < pasteMatrixRows; i++) { |
|
|
|
|
const pasteRow = rowsToPaste[i] |
|
|
|
|
|
|
|
|
|
// TODO handle insert new row
|
|
|
|
|
if (!pasteRow || pasteRow.rowMeta.new) break |
|
|
|
|
|
|
|
|
|
pastedRows++ |
|
|
|
|
|
|
|
|
|
for (let j = 0; j < pasteMatrixCols; j++) { |
|
|
|
|
const pasteCol = colsToPaste[j] |
|
|
|
|
if (!isPasteable(pasteRow, pasteCol)) { |
|
|
|
|
if ((isBt(pasteCol) || isOo(pasteCol) || isMm(pasteCol)) && !isInfoShown) { |
|
|
|
|
message.info(t('msg.info.groupPasteIsNotSupportedOnLinksColumn')) |
|
|
|
|
isInfoShown = true |
|
|
|
|
updatedRows.push(targetRow) |
|
|
|
|
} else { |
|
|
|
|
targetRow = { |
|
|
|
|
row: {}, |
|
|
|
|
oldRow: {}, |
|
|
|
|
rowMeta: { |
|
|
|
|
isExistingRow: false, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
continue |
|
|
|
|
newRows.push(targetRow) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
propsToPaste.push(pasteCol.title!) |
|
|
|
|
|
|
|
|
|
for (let j = 0; j < clipboardMatrix[clipboardRowIndex].length; j++) { |
|
|
|
|
const column = colsToPaste[j] |
|
|
|
|
if (column && isPasteable(targetRow, column)) { |
|
|
|
|
propsToPaste.push(column.title!) |
|
|
|
|
const pasteValue = convertCellData( |
|
|
|
|
{ |
|
|
|
|
// Repeat the clipboard data array if the matrix is smaller than the selection
|
|
|
|
|
value: clipboardMatrix[i % clipboardMatrix.length][j], |
|
|
|
|
to: pasteCol.uidt as UITypes, |
|
|
|
|
column: pasteCol, |
|
|
|
|
value: clipboardMatrix[clipboardRowIndex][j], |
|
|
|
|
to: column.uidt as UITypes, |
|
|
|
|
column, |
|
|
|
|
appInfo: unref(appInfo), |
|
|
|
|
oldValue: pasteCol.uidt === UITypes.Attachment ? pasteRow.row[pasteCol.title!] : undefined, |
|
|
|
|
oldValue: column.uidt === UITypes.Attachment ? targetRow.row[column.title!] : undefined, |
|
|
|
|
}, |
|
|
|
|
isMysql(meta.value?.source_id), |
|
|
|
|
true, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if (pasteValue !== undefined) { |
|
|
|
|
pasteRow.row[pasteCol.title!] = pasteValue |
|
|
|
|
targetRow.row[column.title!] = pasteValue |
|
|
|
|
} |
|
|
|
|
} else if ((isBt(column) || isOo(column) || isMm(column)) && !isInfoShown) { |
|
|
|
|
message.info(t('msg.info.groupPasteIsNotSupportedOnLinksColumn')) |
|
|
|
|
isInfoShown = true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const expandedRows = rowsToPaste.filter((row) => row.rowMeta.isExpandedData) |
|
|
|
|
|
|
|
|
|
const updatedRows = rowsToPaste.filter((row) => !row.rowMeta.isExpandedData) |
|
|
|
|
|
|
|
|
|
if (options.expand) { |
|
|
|
|
await bulkUpsertRows?.(expandedRows!, updatedRows, propsToPaste) |
|
|
|
|
await bulkUpsertRows?.(newRows, updatedRows, propsToPaste) |
|
|
|
|
} else { |
|
|
|
|
await bulkUpdateRows?.(updatedRows, propsToPaste) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (scrollToCell) { |
|
|
|
|
scrollToCell(activeCell.row, activeCell.col) |
|
|
|
|
} |
|
|
|
|
if (pastedRows > 0) { |
|
|
|
|
// highlight the pasted range
|
|
|
|
|
|
|
|
|
|
selectedRange.startRange({ row: activeCell.row, col: activeCell.col }) |
|
|
|
|
selectedRange.endRange({ row: activeCell.row + pastedRows - 1, col: activeCell.col + pasteMatrixCols - 1 }) |
|
|
|
|
} |
|
|
|
|
selectedRange.endRange({ row: activeCell.row + selectionRowCount - 1, col: activeCell.col + pasteMatrixCols - 1 }) |
|
|
|
|
} else { |
|
|
|
|
if (selectedRange.isSingleCell()) { |
|
|
|
|
const rowObj = unref(data)[activeCell.row] |
|
|
|
|