frontend-plus-react 0.1.9 → 0.1.10

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.js CHANGED
@@ -1384,7 +1384,7 @@ function InputRenderer({
1384
1384
  onClose,
1385
1385
  cellFeedback,
1386
1386
  setCellFeedback,
1387
- onEnterPress,
1387
+ onKeyPress,
1388
1388
  setTableData,
1389
1389
  setLocalCellChanges,
1390
1390
  localCellChanges,
@@ -1536,14 +1536,13 @@ function InputRenderer({
1536
1536
  initialRowId
1537
1537
  ]);
1538
1538
  const handleKeyDown = useCallback3((event) => {
1539
- if (["Enter", "Tab", "ArrowDown", "ArrowUp", "ArrowRight"].includes(event.key)) {
1539
+ if (["Enter", "Tab", "ArrowDown", "ArrowUp", "ArrowRight", "ArrowLeft"].includes(event.key)) {
1540
1540
  handleCommit(editingValue, true, true);
1541
- event.preventDefault();
1542
- if (onEnterPress) {
1543
- onEnterPress(rowIdx, column.key, event.key);
1541
+ if (onKeyPress) {
1542
+ onKeyPress(rowIdx, column.key, event);
1544
1543
  }
1545
1544
  }
1546
- }, [handleCommit, editingValue, column.key, rowIdx, onEnterPress]);
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
- handleEnterKeyPressInEditor,
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
- onEnterPress: (rowIndex, columnKey, key) => handleEnterKeyPressInEditor(rowIndex, columnKey, key, allColumns),
1611
+ onKeyPress: (rowIndex, columnKey, event) => handleKeyPressInEditor(rowIndex, columnKey, event, allColumns),
1613
1612
  setTableData,
1614
1613
  setLocalCellChanges,
1615
1614
  localCellChanges,
@@ -1882,22 +1881,27 @@ var GenericDataGrid = ({
1882
1881
  }
1883
1882
  return rows;
1884
1883
  }, [tableData, filters, isFilterRowVisible]);
1885
- const handleEnterKeyPressInEditor = useCallback4((rowIndex, columnKey, key, currentColumns) => {
1884
+ const handleKeyPressInEditor = useCallback4((rowIndex, columnKey, event, currentColumns) => {
1886
1885
  if (dataGridRef.current && tableDefinition) {
1887
1886
  const currentColumnIndex = currentColumns.findIndex((col) => col.key === columnKey);
1888
1887
  const editableColumns = currentColumns.filter((col) => {
1889
1888
  const fieldDefinition = tableDefinition.fields.find((f) => f.name === col.key);
1890
1889
  return col.key !== "actionsColumn" && col.customType != "detail" && (fieldDefinition?.editable !== false && !fieldDefinition?.clientSide);
1891
1890
  });
1891
+ const { key, currentTarget } = event;
1892
+ const input = currentTarget;
1892
1893
  if (currentColumnIndex !== -1 && editableColumns.length > 0) {
1893
1894
  const editableColumnKeys = editableColumns.map((col) => col.key);
1894
1895
  let currentEditableColumnIndex = editableColumnKeys.indexOf(columnKey);
1895
- if (currentEditableColumnIndex !== -1) {
1896
+ const calcularColumnaSiguienteYHacerFoco = () => {
1896
1897
  let nextEditableColumnIndex = currentEditableColumnIndex + 1;
1897
1898
  let nextRowIndex = rowIndex;
1898
1899
  if (nextEditableColumnIndex >= editableColumns.length) {
1899
1900
  nextEditableColumnIndex = 0;
1900
1901
  nextRowIndex++;
1902
+ while (filteredRows[nextRowIndex] && filteredRows[nextRowIndex][DETAIL_ROW_INDICATOR]) {
1903
+ nextRowIndex++;
1904
+ }
1901
1905
  if (nextRowIndex >= filteredRows.length) {
1902
1906
  nextRowIndex = 0;
1903
1907
  }
@@ -1905,6 +1909,71 @@ var GenericDataGrid = ({
1905
1909
  const nextColumnKey = editableColumnKeys[nextEditableColumnIndex];
1906
1910
  const nextColumnIndex = currentColumns.findIndex((col) => col.key === nextColumnKey);
1907
1911
  dataGridRef.current?.selectCell({ rowIdx: nextRowIndex, idx: nextColumnIndex }, { enableEditor: true, shouldFocusCell: true });
1912
+ };
1913
+ const calcularColumnaAnteriorYHacerFoco = () => {
1914
+ let nextEditableColumnIndex = currentEditableColumnIndex - 1;
1915
+ let nextRowIndex = rowIndex;
1916
+ if (nextEditableColumnIndex <= 0) {
1917
+ nextEditableColumnIndex = 0;
1918
+ }
1919
+ const nextColumnKey = editableColumnKeys[nextEditableColumnIndex];
1920
+ const nextColumnIndex = currentColumns.findIndex((col) => col.key === nextColumnKey);
1921
+ dataGridRef.current?.selectCell({ rowIdx: nextRowIndex, idx: nextColumnIndex }, { enableEditor: true, shouldFocusCell: true });
1922
+ };
1923
+ const calcularFilaSiguienteYHacerFoco = () => {
1924
+ let nextRowIndex = rowIndex;
1925
+ nextRowIndex++;
1926
+ while (filteredRows[nextRowIndex] && filteredRows[nextRowIndex][DETAIL_ROW_INDICATOR]) {
1927
+ nextRowIndex++;
1928
+ }
1929
+ if (nextRowIndex >= filteredRows.length) {
1930
+ return;
1931
+ }
1932
+ dataGridRef.current?.selectCell({ rowIdx: nextRowIndex, idx: currentColumnIndex }, { enableEditor: true, shouldFocusCell: true });
1933
+ };
1934
+ const calcularFilaAnteriorYHacerFoco = () => {
1935
+ let nextRowIndex = rowIndex;
1936
+ nextRowIndex--;
1937
+ while (filteredRows[nextRowIndex] && filteredRows[nextRowIndex][DETAIL_ROW_INDICATOR]) {
1938
+ nextRowIndex--;
1939
+ }
1940
+ if (nextRowIndex < 0) {
1941
+ return;
1942
+ }
1943
+ dataGridRef.current?.selectCell({ rowIdx: nextRowIndex, idx: currentColumnIndex }, { enableEditor: true, shouldFocusCell: true });
1944
+ };
1945
+ if (currentEditableColumnIndex !== -1) {
1946
+ switch (true) {
1947
+ case ["Enter", "Tab"].includes(key): {
1948
+ calcularColumnaSiguienteYHacerFoco();
1949
+ break;
1950
+ }
1951
+ case key == "ArrowRight": {
1952
+ const cursorPosition = input.selectionStart;
1953
+ const inputValueLength = input.value.length;
1954
+ if (cursorPosition === inputValueLength) {
1955
+ calcularColumnaSiguienteYHacerFoco();
1956
+ }
1957
+ break;
1958
+ }
1959
+ case key == "ArrowLeft": {
1960
+ const cursorPosition = input.selectionStart;
1961
+ if (cursorPosition === 0) {
1962
+ calcularColumnaAnteriorYHacerFoco();
1963
+ }
1964
+ break;
1965
+ }
1966
+ case key == "ArrowUp": {
1967
+ calcularFilaAnteriorYHacerFoco();
1968
+ break;
1969
+ }
1970
+ case key == "ArrowDown": {
1971
+ calcularFilaSiguienteYHacerFoco();
1972
+ break;
1973
+ }
1974
+ default:
1975
+ break;
1976
+ }
1908
1977
  }
1909
1978
  }
1910
1979
  }
@@ -1937,7 +2006,7 @@ var GenericDataGrid = ({
1937
2006
  resizable: true,
1938
2007
  sortable: true,
1939
2008
  editable: isFieldEditable,
1940
- handleEnterKeyPressInEditor,
2009
+ handleKeyPressInEditor,
1941
2010
  flexGrow: 1,
1942
2011
  minWidth: 60,
1943
2012
  renderHeaderCell: (props) => defaultColumnHeaderCellRenderer(props, fieldDef),
@@ -2020,7 +2089,7 @@ var GenericDataGrid = ({
2020
2089
  theme.palette.error.light,
2021
2090
  theme.palette.info.light,
2022
2091
  theme.palette.action.selected,
2023
- handleEnterKeyPressInEditor,
2092
+ handleKeyPressInEditor,
2024
2093
  setTableData,
2025
2094
  localCellChanges,
2026
2095
  handleDeleteRow,
@@ -2041,16 +2110,24 @@ var GenericDataGrid = ({
2041
2110
  });
2042
2111
  };
2043
2112
  const handleCellKeyDown = (args, event) => {
2044
- if (["Tab", "Enter"].includes(event.key)) {
2113
+ if (["Enter", "Tab", "ArrowDown", "ArrowUp", "ArrowRight", "ArrowLeft"].includes(event.key)) {
2045
2114
  event.preventGridDefault();
2046
2115
  }
2047
2116
  };
2048
- const handleCellClick = useCallback4((args) => {
2049
- deselectAllOtherGrids(dataGridRef.current?.element);
2050
- args.selectCell(true);
2117
+ const handleCellMouseDown = useCallback4((_args, event) => {
2118
+ event.preventGridDefault();
2119
+ }, []);
2120
+ const handlCellDoubleClick = useCallback4((_args, event) => {
2121
+ event.preventGridDefault();
2122
+ }, []);
2123
+ const handleCellClick = useCallback4((args, _event) => {
2051
2124
  const fieldDefinition = tableDefinition?.fields.find((f) => f.name === args.column.key);
2052
2125
  const isFixedField = fixedFields?.some((f) => f.fieldName === args.column.key);
2053
2126
  const isEditable = fieldDefinition?.editable !== false && !isFixedField;
2127
+ if (isEditable) {
2128
+ deselectAllOtherGrids(dataGridRef.current?.element);
2129
+ args.selectCell(true);
2130
+ }
2054
2131
  console.log("Clicked column index:", args.column.idx);
2055
2132
  console.log("Clicked row index:", args.rowIdx);
2056
2133
  console.log("Is editable:", isEditable);
@@ -2124,6 +2201,8 @@ var GenericDataGrid = ({
2124
2201
  topSummaryRows: isFilterRowVisible ? [{ id: "filterRow" }] : void 0,
2125
2202
  summaryRowHeight: isFilterRowVisible ? 30 : 0,
2126
2203
  renderers: { noRowsFallback: /* @__PURE__ */ jsx12(EmptyRowsRenderer, {}) },
2204
+ onCellMouseDown: handleCellMouseDown,
2205
+ onCellDoubleClick: handlCellDoubleClick,
2127
2206
  onCellClick: handleCellClick,
2128
2207
  onCellKeyDown: handleCellKeyDown
2129
2208
  }