componentes-sinco 1.3.5 → 1.3.6

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
@@ -5160,7 +5160,7 @@ var SCCard = ({ width, title, image, iconTitle, actionsTitle, subtitle, dividerH
5160
5160
  };
5161
5161
 
5162
5162
  // src/Components/SCDataGrid.tsx
5163
- import React44, { useEffect as useEffect19, useState as useState25 } from "react";
5163
+ import React44, { useEffect as useEffect19, useState as useState25, useRef as useRef7 } from "react";
5164
5164
  import { DataGridPro, useGridApiRef } from "@mui/x-data-grid-pro";
5165
5165
  import { LicenseInfo as LicenseInfo2 } from "@mui/x-license";
5166
5166
  import { Button as Button19, TextField as TextField7 } from "@mui/material";
@@ -5334,7 +5334,7 @@ function SCDataGridInitial({ data, columns, getRowId, groupColumns, titleRowsPag
5334
5334
  const [insertRowValues, setInsertRowValues] = useState25({});
5335
5335
  const INSERT_ROW_ID = "__sc-datagrid-insert-row__";
5336
5336
  const resolvedGetRowId = (row) => (row == null ? void 0 : row.__isInsertRow) ? INSERT_ROW_ID : getRowId ? getRowId(row) : row.id;
5337
- const pinnedRows = showInsertRow ? { bottom: [{ __isInsertRow: true }] } : void 0;
5337
+ const pinnedRows = showInsertRow ? { bottom: [__spreadValues({ __isInsertRow: true }, insertRowValues)] } : void 0;
5338
5338
  const normalizedInsertRowFields = (insertRowFields && insertRowFields.length > 0 ? insertRowFields : [(_a = columns[0]) == null ? void 0 : _a.field]).map((item) => typeof item === "string" ? { field: item } : item);
5339
5339
  const insertRowTargetFields = normalizedInsertRowFields.map((item) => item.field);
5340
5340
  const isInsertRowValueFilled = (value) => value !== void 0 && value !== null && (typeof value !== "string" || value.trim() !== "");
@@ -5351,6 +5351,10 @@ function SCDataGridInitial({ data, columns, getRowId, groupColumns, titleRowsPag
5351
5351
  setInsertRowValues({});
5352
5352
  onAddRow && onAddRow(newRow);
5353
5353
  };
5354
+ const hasInsertRowValueRef = useRef7(hasInsertRowValue);
5355
+ hasInsertRowValueRef.current = hasInsertRowValue;
5356
+ const handleAddInsertRowRef = useRef7(handleAddInsertRow);
5357
+ handleAddInsertRowRef.current = handleAddInsertRow;
5354
5358
  useEffect19(() => {
5355
5359
  var _a2;
5356
5360
  if (setSelectedRow) {
@@ -5424,11 +5428,12 @@ function SCDataGridInitial({ data, columns, getRowId, groupColumns, titleRowsPag
5424
5428
  }
5425
5429
  }
5426
5430
  };
5427
- const processedColumns = columns.map((col, index) => {
5431
+ const processedColumns = React44.useMemo(() => columns.map((col, index) => {
5428
5432
  const baseCol = col.width !== void 0 || col.flex !== void 0 ? col : __spreadProps(__spreadValues({}, col), { flex: 1 });
5429
5433
  if (!showInsertRow) return baseCol;
5430
5434
  const isLastColumn = index === columns.length - 1;
5431
5435
  const isInputField = !isLastColumn && insertRowTargetFields.includes(baseCol.field);
5436
+ const fieldConfig = normalizedInsertRowFields.find((item) => item.field === baseCol.field);
5432
5437
  const originalRenderCell = baseCol.renderCell;
5433
5438
  return __spreadProps(__spreadValues({}, baseCol), {
5434
5439
  renderCell: (params) => {
@@ -5436,11 +5441,10 @@ function SCDataGridInitial({ data, columns, getRowId, groupColumns, titleRowsPag
5436
5441
  return originalRenderCell ? originalRenderCell(params) : params.formattedValue;
5437
5442
  }
5438
5443
  if (isInputField) {
5439
- const fieldConfig = normalizedInsertRowFields.find((item) => item.field === baseCol.field);
5440
5444
  const setFieldValue = (newValue) => setInsertRowValues((prev) => __spreadProps(__spreadValues({}, prev), { [baseCol.field]: newValue }));
5441
5445
  if (fieldConfig == null ? void 0 : fieldConfig.renderCell) {
5442
5446
  return fieldConfig.renderCell({
5443
- value: insertRowValues[baseCol.field],
5447
+ value: params.value,
5444
5448
  onChange: setFieldValue,
5445
5449
  field: baseCol.field
5446
5450
  });
@@ -5451,10 +5455,11 @@ function SCDataGridInitial({ data, columns, getRowId, groupColumns, titleRowsPag
5451
5455
  variant: "outlined",
5452
5456
  size: "small",
5453
5457
  placeholder: (fieldConfig == null ? void 0 : fieldConfig.placeholder) || baseCol.headerName || `Escribir ${baseCol.field}`,
5454
- value: insertRowValues[baseCol.field] || "",
5458
+ value: params.value || "",
5455
5459
  onChange: (e) => setFieldValue(e.target.value),
5456
5460
  onKeyDown: (e) => {
5457
- if (e.key === "Enter") handleAddInsertRow();
5461
+ e.stopPropagation();
5462
+ if (e.key === "Enter") handleAddInsertRowRef.current();
5458
5463
  },
5459
5464
  sx: { width: "100%", "& .MuiOutlinedInput-root": { height: "32px" } }
5460
5465
  }
@@ -5466,8 +5471,8 @@ function SCDataGridInitial({ data, columns, getRowId, groupColumns, titleRowsPag
5466
5471
  {
5467
5472
  variant: "contained",
5468
5473
  size: "small",
5469
- disabled: !hasInsertRowValue(),
5470
- onClick: handleAddInsertRow
5474
+ disabled: !hasInsertRowValueRef.current(),
5475
+ onClick: () => handleAddInsertRowRef.current()
5471
5476
  },
5472
5477
  "Agregar"
5473
5478
  );
@@ -5475,7 +5480,7 @@ function SCDataGridInitial({ data, columns, getRowId, groupColumns, titleRowsPag
5475
5480
  return null;
5476
5481
  }
5477
5482
  });
5478
- });
5483
+ }), [columns, showInsertRow, insertRowFields]);
5479
5484
  const columnVisibilityModel = {};
5480
5485
  processedColumns.forEach((col) => {
5481
5486
  if (col.hide === true) {