mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-26 08:45:59 +00:00
paste - single cell variant
This commit is contained in:
@@ -34,6 +34,7 @@ import {
|
|||||||
changeSetInsertNewRow,
|
changeSetInsertNewRow,
|
||||||
deleteChangeSetRows,
|
deleteChangeSetRows,
|
||||||
batchUpdateChangeSet,
|
batchUpdateChangeSet,
|
||||||
|
setChangeSetValue,
|
||||||
} from '@dbgate/datalib';
|
} from '@dbgate/datalib';
|
||||||
import { scriptToSql } from '@dbgate/sqltree';
|
import { scriptToSql } from '@dbgate/sqltree';
|
||||||
import { sleep } from '../utility/common';
|
import { sleep } from '../utility/common';
|
||||||
@@ -300,6 +301,11 @@ export default function DataGridCore(props) {
|
|||||||
[columnSizes, firstVisibleColumnScrollIndex, gridScrollAreaWidth, columns]
|
[columnSizes, firstVisibleColumnScrollIndex, gridScrollAreaWidth, columns]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const realColumnUniqueNames = React.useMemo(
|
||||||
|
() => _.range(columnSizes.realCount).map(realIndex => columns[columnSizes.realToModel(realIndex)].uniqueName),
|
||||||
|
[columnSizes, columns]
|
||||||
|
);
|
||||||
|
|
||||||
if (!loadedRows || !columns) return null;
|
if (!loadedRows || !columns) return null;
|
||||||
const insertedRows = getChangeSetInsertedRows(changeSet, display.baseTable);
|
const insertedRows = getChangeSetInsertedRows(changeSet, display.baseTable);
|
||||||
const rowCountNewIncluded = loadedRows.length + insertedRows.length;
|
const rowCountNewIncluded = loadedRows.length + insertedRows.length;
|
||||||
@@ -345,14 +351,47 @@ export default function DataGridCore(props) {
|
|||||||
function handlePaste(event) {
|
function handlePaste(event) {
|
||||||
var pastedText = undefined;
|
var pastedText = undefined;
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (window.clipboardData && window.clipboardData.getData) { // IE
|
if (window.clipboardData && window.clipboardData.getData) {
|
||||||
// @ts-ignore
|
// IE
|
||||||
pastedText = window.clipboardData.getData('Text');
|
// @ts-ignore
|
||||||
|
pastedText = window.clipboardData.getData('Text');
|
||||||
} else if (event.clipboardData && event.clipboardData.getData) {
|
} else if (event.clipboardData && event.clipboardData.getData) {
|
||||||
pastedText = event.clipboardData.getData('text/plain');
|
pastedText = event.clipboardData.getData('text/plain');
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
console.log(pastedText); // Process and handle text...
|
const rows = pastedText.replace(/\r/g, '').split('\n');
|
||||||
|
let chs = changeSet;
|
||||||
|
let allRows = loadedAndInsertedRows;
|
||||||
|
|
||||||
|
if (selectedCells.length <= 1) {
|
||||||
|
if (isRegularCell(currentCell)) {
|
||||||
|
let rowIndex = currentCell[0];
|
||||||
|
for (const rowData of rows) {
|
||||||
|
if (rowIndex >= allRows.length) {
|
||||||
|
chs = changeSetInsertNewRow(chs, display.baseTable);
|
||||||
|
allRows = [...loadedRows, ...getChangeSetInsertedRows(chs, display.baseTable)];
|
||||||
|
}
|
||||||
|
let colIndex = currentCell[1];
|
||||||
|
const cells = rowData.split('\t');
|
||||||
|
const row = allRows[rowIndex];
|
||||||
|
for (const cell of cells) {
|
||||||
|
chs = setChangeSetValue(
|
||||||
|
chs,
|
||||||
|
display.getChangeSetField(
|
||||||
|
row,
|
||||||
|
realColumnUniqueNames[colIndex],
|
||||||
|
rowIndex >= loadedRows.length ? rowIndex - loadedRows.length : null
|
||||||
|
),
|
||||||
|
cell
|
||||||
|
);
|
||||||
|
colIndex += 1;
|
||||||
|
}
|
||||||
|
rowIndex += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setChangeSet(chs);
|
||||||
}
|
}
|
||||||
|
|
||||||
function copyToClipboard() {
|
function copyToClipboard() {
|
||||||
@@ -364,7 +403,7 @@ export default function DataGridCore(props) {
|
|||||||
.sort();
|
.sort();
|
||||||
const rowData = loadedAndInsertedRows[rowIndex];
|
const rowData = loadedAndInsertedRows[rowIndex];
|
||||||
const line = colIndexes
|
const line = colIndexes
|
||||||
.map(columnUniqueName)
|
.map(col => realColumnUniqueNames[col])
|
||||||
.map(col => (rowData[col] == null ? '' : rowData[col]))
|
.map(col => (rowData[col] == null ? '' : rowData[col]))
|
||||||
.join('\t');
|
.join('\t');
|
||||||
return line;
|
return line;
|
||||||
@@ -388,10 +427,6 @@ export default function DataGridCore(props) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function columnUniqueName(columnIndex) {
|
|
||||||
return columns[columnSizes.realToModel(columnIndex)].uniqueName;
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleGridMouseUp(event) {
|
function handleGridMouseUp(event) {
|
||||||
if (dragStartCell) {
|
if (dragStartCell) {
|
||||||
const cell = cellFromEvent(event);
|
const cell = cellFromEvent(event);
|
||||||
@@ -404,7 +439,7 @@ export default function DataGridCore(props) {
|
|||||||
if (_.isNumber(currentRowNumber)) {
|
if (_.isNumber(currentRowNumber)) {
|
||||||
const rowIndexes = _.uniq((autofillSelectedCells || []).map(x => x[0])).filter(x => x != currentRowNumber);
|
const rowIndexes = _.uniq((autofillSelectedCells || []).map(x => x[0])).filter(x => x != currentRowNumber);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const colNames = selectedCells.map(cell => columnUniqueName(cell[1]));
|
const colNames = selectedCells.map(cell => realColumnUniqueNames[cell[1]]);
|
||||||
const changeObject = _.pick(loadedAndInsertedRows[currentRowNumber], colNames);
|
const changeObject = _.pick(loadedAndInsertedRows[currentRowNumber], colNames);
|
||||||
setChangeSet(
|
setChangeSet(
|
||||||
batchUpdateChangeSet(
|
batchUpdateChangeSet(
|
||||||
@@ -722,7 +757,13 @@ export default function DataGridCore(props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<GridContainer ref={containerRef}>
|
<GridContainer ref={containerRef}>
|
||||||
<FocusField type="text" ref={focusFieldRef} onKeyDown={handleGridKeyDown} onCopy={handleCopy} onPaste={handlePaste} />
|
<FocusField
|
||||||
|
type="text"
|
||||||
|
ref={focusFieldRef}
|
||||||
|
onKeyDown={handleGridKeyDown}
|
||||||
|
onCopy={handleCopy}
|
||||||
|
onPaste={handlePaste}
|
||||||
|
/>
|
||||||
<Table
|
<Table
|
||||||
onMouseDown={handleGridMouseDown}
|
onMouseDown={handleGridMouseDown}
|
||||||
onMouseMove={handleGridMouseMove}
|
onMouseMove={handleGridMouseMove}
|
||||||
|
|||||||
Reference in New Issue
Block a user