frontend-plus-react 0.1.9 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +111 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +108 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1384,7 +1384,7 @@ function InputRenderer({
|
|
|
1384
1384
|
onClose,
|
|
1385
1385
|
cellFeedback,
|
|
1386
1386
|
setCellFeedback,
|
|
1387
|
-
|
|
1387
|
+
onKeyPress,
|
|
1388
1388
|
setTableData,
|
|
1389
1389
|
setLocalCellChanges,
|
|
1390
1390
|
localCellChanges,
|
|
@@ -1535,15 +1535,14 @@ function InputRenderer({
|
|
|
1535
1535
|
localCellChanges,
|
|
1536
1536
|
initialRowId
|
|
1537
1537
|
]);
|
|
1538
|
-
const handleKeyDown = useCallback3((event) => {
|
|
1539
|
-
if (["Enter", "Tab", "ArrowDown", "ArrowUp", "ArrowRight"].includes(event.key)) {
|
|
1540
|
-
handleCommit(editingValue, true, true);
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
onEnterPress(rowIdx, column.key, event.key);
|
|
1538
|
+
const handleKeyDown = useCallback3(async (event) => {
|
|
1539
|
+
if (["Enter", "Tab", "ArrowDown", "ArrowUp", "ArrowRight", "ArrowLeft", "F4"].includes(event.key)) {
|
|
1540
|
+
await handleCommit(editingValue, true, true);
|
|
1541
|
+
if (onKeyPress) {
|
|
1542
|
+
onKeyPress(rowIdx, column.key, event, handleCommit);
|
|
1544
1543
|
}
|
|
1545
1544
|
}
|
|
1546
|
-
}, [handleCommit, editingValue, column.key, rowIdx,
|
|
1545
|
+
}, [handleCommit, editingValue, column.key, rowIdx, onKeyPress]);
|
|
1547
1546
|
const handleBlur = useCallback3(() => {
|
|
1548
1547
|
handleCommit(editingValue, true, false);
|
|
1549
1548
|
}, [handleCommit, editingValue]);
|
|
@@ -1590,7 +1589,7 @@ var allColumnsEditCellRenderer = (props, allColumns) => {
|
|
|
1590
1589
|
setTableData,
|
|
1591
1590
|
cellFeedback,
|
|
1592
1591
|
setCellFeedback,
|
|
1593
|
-
|
|
1592
|
+
handleKeyPressInEditor,
|
|
1594
1593
|
localCellChanges,
|
|
1595
1594
|
setLocalCellChanges
|
|
1596
1595
|
} = defaultColumn;
|
|
@@ -1609,7 +1608,7 @@ var allColumnsEditCellRenderer = (props, allColumns) => {
|
|
|
1609
1608
|
tableDefinition,
|
|
1610
1609
|
setCellFeedback,
|
|
1611
1610
|
cellFeedback,
|
|
1612
|
-
|
|
1611
|
+
onKeyPress: (rowIndex, columnKey, event, handleCommit) => handleKeyPressInEditor(rowIndex, columnKey, event, allColumns, handleCommit),
|
|
1613
1612
|
setTableData,
|
|
1614
1613
|
setLocalCellChanges,
|
|
1615
1614
|
localCellChanges,
|
|
@@ -1720,11 +1719,7 @@ var GenericDataGrid = ({
|
|
|
1720
1719
|
}
|
|
1721
1720
|
};
|
|
1722
1721
|
fetchDataAndDefinition();
|
|
1723
|
-
}, [
|
|
1724
|
-
tableName,
|
|
1725
|
-
/*fixedFields,*/
|
|
1726
|
-
showError
|
|
1727
|
-
]);
|
|
1722
|
+
}, [tableName, fixedFields, showError]);
|
|
1728
1723
|
useEffect(() => {
|
|
1729
1724
|
if (cellFeedback) {
|
|
1730
1725
|
if (feedbackTimerRef.current) {
|
|
@@ -1882,29 +1877,108 @@ var GenericDataGrid = ({
|
|
|
1882
1877
|
}
|
|
1883
1878
|
return rows;
|
|
1884
1879
|
}, [tableData, filters, isFilterRowVisible]);
|
|
1885
|
-
const
|
|
1880
|
+
const handleKeyPressInEditor = useCallback4((rowIndex, columnKey, event, currentColumns, handleCommit) => {
|
|
1886
1881
|
if (dataGridRef.current && tableDefinition) {
|
|
1887
1882
|
const currentColumnIndex = currentColumns.findIndex((col) => col.key === columnKey);
|
|
1888
1883
|
const editableColumns = currentColumns.filter((col) => {
|
|
1889
1884
|
const fieldDefinition = tableDefinition.fields.find((f) => f.name === col.key);
|
|
1890
1885
|
return col.key !== "actionsColumn" && col.customType != "detail" && (fieldDefinition?.editable !== false && !fieldDefinition?.clientSide);
|
|
1891
1886
|
});
|
|
1887
|
+
const { key, target } = event;
|
|
1888
|
+
const input = target;
|
|
1892
1889
|
if (currentColumnIndex !== -1 && editableColumns.length > 0) {
|
|
1893
1890
|
const editableColumnKeys = editableColumns.map((col) => col.key);
|
|
1894
1891
|
let currentEditableColumnIndex = editableColumnKeys.indexOf(columnKey);
|
|
1895
|
-
|
|
1892
|
+
const hacerFoco = ({ rowIdx, idx }) => setTimeout(() => dataGridRef.current?.selectCell({ rowIdx, idx }, { enableEditor: true, shouldFocusCell: true }), 10);
|
|
1893
|
+
const calcularColumnaSiguiente = () => {
|
|
1896
1894
|
let nextEditableColumnIndex = currentEditableColumnIndex + 1;
|
|
1897
1895
|
let nextRowIndex = rowIndex;
|
|
1898
1896
|
if (nextEditableColumnIndex >= editableColumns.length) {
|
|
1899
1897
|
nextEditableColumnIndex = 0;
|
|
1900
1898
|
nextRowIndex++;
|
|
1899
|
+
while (filteredRows[nextRowIndex] && filteredRows[nextRowIndex][DETAIL_ROW_INDICATOR]) {
|
|
1900
|
+
nextRowIndex++;
|
|
1901
|
+
}
|
|
1901
1902
|
if (nextRowIndex >= filteredRows.length) {
|
|
1902
1903
|
nextRowIndex = 0;
|
|
1903
1904
|
}
|
|
1904
1905
|
}
|
|
1905
1906
|
const nextColumnKey = editableColumnKeys[nextEditableColumnIndex];
|
|
1906
1907
|
const nextColumnIndex = currentColumns.findIndex((col) => col.key === nextColumnKey);
|
|
1907
|
-
|
|
1908
|
+
return { rowIdx: nextRowIndex, idx: nextColumnIndex };
|
|
1909
|
+
};
|
|
1910
|
+
const calcularColumnaAnterior = () => {
|
|
1911
|
+
let nextEditableColumnIndex = currentEditableColumnIndex - 1;
|
|
1912
|
+
let nextRowIndex = rowIndex;
|
|
1913
|
+
if (nextEditableColumnIndex <= 0) {
|
|
1914
|
+
nextEditableColumnIndex = 0;
|
|
1915
|
+
}
|
|
1916
|
+
const nextColumnKey = editableColumnKeys[nextEditableColumnIndex];
|
|
1917
|
+
const nextColumnIndex = currentColumns.findIndex((col) => col.key === nextColumnKey);
|
|
1918
|
+
return { rowIdx: nextRowIndex, idx: nextColumnIndex };
|
|
1919
|
+
};
|
|
1920
|
+
const calcularFilaSiguiente = () => {
|
|
1921
|
+
let nextRowIndex = rowIndex;
|
|
1922
|
+
nextRowIndex++;
|
|
1923
|
+
while (filteredRows[nextRowIndex] && filteredRows[nextRowIndex][DETAIL_ROW_INDICATOR]) {
|
|
1924
|
+
nextRowIndex++;
|
|
1925
|
+
}
|
|
1926
|
+
if (nextRowIndex >= filteredRows.length) {
|
|
1927
|
+
return { rowIdx: rowIndex, idx: currentColumnIndex };
|
|
1928
|
+
}
|
|
1929
|
+
return { rowIdx: nextRowIndex, idx: currentColumnIndex };
|
|
1930
|
+
};
|
|
1931
|
+
const calcularFilaAnterior = () => {
|
|
1932
|
+
let nextRowIndex = rowIndex;
|
|
1933
|
+
nextRowIndex--;
|
|
1934
|
+
while (filteredRows[nextRowIndex] && filteredRows[nextRowIndex][DETAIL_ROW_INDICATOR]) {
|
|
1935
|
+
nextRowIndex--;
|
|
1936
|
+
}
|
|
1937
|
+
if (nextRowIndex < 0) {
|
|
1938
|
+
return { rowIdx: rowIndex, idx: currentColumnIndex };
|
|
1939
|
+
}
|
|
1940
|
+
return { rowIdx: nextRowIndex, idx: currentColumnIndex };
|
|
1941
|
+
};
|
|
1942
|
+
if (currentEditableColumnIndex !== -1) {
|
|
1943
|
+
switch (true) {
|
|
1944
|
+
case ["Enter", "Tab"].includes(key): {
|
|
1945
|
+
hacerFoco(calcularColumnaSiguiente());
|
|
1946
|
+
break;
|
|
1947
|
+
}
|
|
1948
|
+
case key == "ArrowRight": {
|
|
1949
|
+
const cursorPosition = input.selectionStart;
|
|
1950
|
+
const inputValueLength = input.value.length;
|
|
1951
|
+
if (cursorPosition === inputValueLength) {
|
|
1952
|
+
hacerFoco(calcularColumnaSiguiente());
|
|
1953
|
+
}
|
|
1954
|
+
break;
|
|
1955
|
+
}
|
|
1956
|
+
case key == "ArrowLeft": {
|
|
1957
|
+
const cursorPosition = input.selectionStart;
|
|
1958
|
+
if (cursorPosition === 0) {
|
|
1959
|
+
hacerFoco(calcularColumnaAnterior());
|
|
1960
|
+
}
|
|
1961
|
+
break;
|
|
1962
|
+
}
|
|
1963
|
+
case key == "ArrowUp": {
|
|
1964
|
+
hacerFoco(calcularFilaAnterior());
|
|
1965
|
+
break;
|
|
1966
|
+
}
|
|
1967
|
+
case key == "ArrowDown": {
|
|
1968
|
+
hacerFoco(calcularFilaSiguiente());
|
|
1969
|
+
break;
|
|
1970
|
+
}
|
|
1971
|
+
case key == "F4": {
|
|
1972
|
+
const { rowIdx, idx } = calcularFilaSiguiente();
|
|
1973
|
+
const previousRow = tableData[rowIndex - 1];
|
|
1974
|
+
if (previousRow && !previousRow[DETAIL_ROW_INDICATOR]) {
|
|
1975
|
+
handleCommit(previousRow[columnKey], true, true).then(() => hacerFoco({ rowIdx, idx }));
|
|
1976
|
+
}
|
|
1977
|
+
break;
|
|
1978
|
+
}
|
|
1979
|
+
default:
|
|
1980
|
+
break;
|
|
1981
|
+
}
|
|
1908
1982
|
}
|
|
1909
1983
|
}
|
|
1910
1984
|
}
|
|
@@ -1937,7 +2011,7 @@ var GenericDataGrid = ({
|
|
|
1937
2011
|
resizable: true,
|
|
1938
2012
|
sortable: true,
|
|
1939
2013
|
editable: isFieldEditable,
|
|
1940
|
-
|
|
2014
|
+
handleKeyPressInEditor,
|
|
1941
2015
|
flexGrow: 1,
|
|
1942
2016
|
minWidth: 60,
|
|
1943
2017
|
renderHeaderCell: (props) => defaultColumnHeaderCellRenderer(props, fieldDef),
|
|
@@ -2020,7 +2094,7 @@ var GenericDataGrid = ({
|
|
|
2020
2094
|
theme.palette.error.light,
|
|
2021
2095
|
theme.palette.info.light,
|
|
2022
2096
|
theme.palette.action.selected,
|
|
2023
|
-
|
|
2097
|
+
handleKeyPressInEditor,
|
|
2024
2098
|
setTableData,
|
|
2025
2099
|
localCellChanges,
|
|
2026
2100
|
handleDeleteRow,
|
|
@@ -2041,16 +2115,24 @@ var GenericDataGrid = ({
|
|
|
2041
2115
|
});
|
|
2042
2116
|
};
|
|
2043
2117
|
const handleCellKeyDown = (args, event) => {
|
|
2044
|
-
if (["Tab", "
|
|
2118
|
+
if (["Enter", "Tab", "ArrowDown", "ArrowUp", "ArrowRight", "ArrowLeft"].includes(event.key)) {
|
|
2045
2119
|
event.preventGridDefault();
|
|
2046
2120
|
}
|
|
2047
2121
|
};
|
|
2048
|
-
const
|
|
2049
|
-
|
|
2050
|
-
|
|
2122
|
+
const handleCellMouseDown = useCallback4((_args, event) => {
|
|
2123
|
+
event.preventGridDefault();
|
|
2124
|
+
}, []);
|
|
2125
|
+
const handlCellDoubleClick = useCallback4((_args, event) => {
|
|
2126
|
+
event.preventGridDefault();
|
|
2127
|
+
}, []);
|
|
2128
|
+
const handleCellClick = useCallback4((args, _event) => {
|
|
2051
2129
|
const fieldDefinition = tableDefinition?.fields.find((f) => f.name === args.column.key);
|
|
2052
2130
|
const isFixedField = fixedFields?.some((f) => f.fieldName === args.column.key);
|
|
2053
2131
|
const isEditable = fieldDefinition?.editable !== false && !isFixedField;
|
|
2132
|
+
if (isEditable) {
|
|
2133
|
+
deselectAllOtherGrids(dataGridRef.current?.element);
|
|
2134
|
+
args.selectCell(true);
|
|
2135
|
+
}
|
|
2054
2136
|
console.log("Clicked column index:", args.column.idx);
|
|
2055
2137
|
console.log("Clicked row index:", args.rowIdx);
|
|
2056
2138
|
console.log("Is editable:", isEditable);
|
|
@@ -2124,6 +2206,8 @@ var GenericDataGrid = ({
|
|
|
2124
2206
|
topSummaryRows: isFilterRowVisible ? [{ id: "filterRow" }] : void 0,
|
|
2125
2207
|
summaryRowHeight: isFilterRowVisible ? 30 : 0,
|
|
2126
2208
|
renderers: { noRowsFallback: /* @__PURE__ */ jsx12(EmptyRowsRenderer, {}) },
|
|
2209
|
+
onCellMouseDown: handleCellMouseDown,
|
|
2210
|
+
onCellDoubleClick: handlCellDoubleClick,
|
|
2127
2211
|
onCellClick: handleCellClick,
|
|
2128
2212
|
onCellKeyDown: handleCellKeyDown
|
|
2129
2213
|
}
|