@carbon/ibm-products
Version:
Carbon for IBM Products
84 lines (79 loc) • 2.6 kB
JavaScript
/**
* Copyright IBM Corp. 2020, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
;
var removeCellSelections = require('./removeCellSelections.js');
var uuidv4 = require('../../../global/js/utils/uuidv4.js');
// Update the data
const handleEditSubmit = _ref => {
let {
activeCellCoordinates,
cellEditorRulerRef,
columns,
previousState,
removeCellEditor,
rows,
setActiveCellCoordinates,
setCurrentMatcher,
setSelectionAreas,
spreadsheetRef,
updateData
} = _ref;
return event => {
const {
key
} = event;
const updateSelectionAreaOnCellEditSubmit = _ref2 => {
let {
type
} = _ref2;
const submitEditChanges = () => {
const prevCoords = previousState?.activeCellCoordinates;
const cellProps = rows[prevCoords?.row].cells[prevCoords?.column];
removeCellEditor();
updateData(prevCoords?.row, cellProps.column.id);
};
removeCellSelections.removeCellSelections({
spreadsheetRef
});
submitEditChanges();
const tempMatcher = uuidv4.default();
const newSelectionArea = {
row: type === 'Enter' ? activeCellCoordinates.row === rows.length - 1 ? activeCellCoordinates.row : activeCellCoordinates.row + 1 : activeCellCoordinates.row,
column: type === 'Tab' ? activeCellCoordinates.column === columns.length - 1 ? activeCellCoordinates.column : activeCellCoordinates.column + 1 : activeCellCoordinates.column
};
setSelectionAreas([{
point1: newSelectionArea,
point2: newSelectionArea,
matcher: tempMatcher,
areaCreated: false
}]);
setCurrentMatcher(tempMatcher);
cellEditorRulerRef.current.textContent = '';
};
if (key === 'Enter') {
updateSelectionAreaOnCellEditSubmit({
type: 'Enter'
});
setActiveCellCoordinates(prev => ({
...prev,
row: prev.row === rows.length - 1 ? prev.row : prev.row + 1 // do not move to next cell below if we're already in the last row
}));
}
if (key === 'Tab') {
event.preventDefault();
updateSelectionAreaOnCellEditSubmit({
type: 'Tab'
});
setActiveCellCoordinates(prev => ({
...prev,
column: prev.column === columns.length - 1 ? prev.column : prev.column + 1 // do not move to next cell below if we're already in the last column
}));
}
return;
};
};
exports.handleEditSubmit = handleEditSubmit;