rockin 0.0.19 → 0.0.21

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.
@@ -632,7 +632,8 @@ function useDataGrid({
632
632
  columnIds = [],
633
633
  columns,
634
634
  initialRows = [],
635
- getRowId = (row, index) => String(row.id ?? index)
635
+ getRowId = (row, index) => String(row.id ?? index),
636
+ maxRows = 200
636
637
  } = {}) {
637
638
  const [rows, setRows] = React3.useState(initialRows);
638
639
  const resolvedColumns = React3.useMemo(
@@ -665,8 +666,45 @@ function useDataGrid({
665
666
  [getRowId]
666
667
  );
667
668
  const updateRows = React3.useCallback(
668
- (updater) => setRows(updater),
669
- []
669
+ (updater) => setRows((current) => updater(current).slice(0, maxRows)),
670
+ [maxRows]
671
+ );
672
+ const insertRows = React3.useCallback(
673
+ (nextRows, index = rows.length) => {
674
+ setRows((current) => {
675
+ const safeIndex = Math.max(0, Math.min(index, current.length));
676
+ return [
677
+ ...current.slice(0, safeIndex),
678
+ ...nextRows,
679
+ ...current.slice(safeIndex)
680
+ ].slice(0, maxRows);
681
+ });
682
+ },
683
+ [maxRows, rows.length]
684
+ );
685
+ const deleteRows = React3.useCallback(
686
+ (rowIds) => {
687
+ const ids = new Set(rowIds);
688
+ setRows(
689
+ (current) => current.filter((row, index) => !ids.has(getRowId(row, index)))
690
+ );
691
+ },
692
+ [getRowId]
693
+ );
694
+ const moveRow = React3.useCallback(
695
+ (rowId, toIndex) => {
696
+ setRows((current) => {
697
+ const fromIndex = current.findIndex(
698
+ (row2, index) => getRowId(row2, index) === rowId
699
+ );
700
+ if (fromIndex < 0) return current;
701
+ const next = [...current];
702
+ const [row] = next.splice(fromIndex, 1);
703
+ next.splice(Math.max(0, Math.min(toIndex, next.length)), 0, row);
704
+ return next;
705
+ });
706
+ },
707
+ [getRowId]
670
708
  );
671
709
  return React3.useMemo(
672
710
  () => ({
@@ -676,7 +714,10 @@ function useDataGrid({
676
714
  getRow,
677
715
  getCellValue,
678
716
  updateCell,
679
- updateRows
717
+ updateRows,
718
+ insertRows,
719
+ deleteRows,
720
+ moveRow
680
721
  }),
681
722
  [
682
723
  getCellValue,
@@ -685,7 +726,11 @@ function useDataGrid({
685
726
  resolvedColumns,
686
727
  rows,
687
728
  updateCell,
688
- updateRows
729
+ updateRows,
730
+ insertRows,
731
+ deleteRows,
732
+ moveRow,
733
+ maxRows
689
734
  ]
690
735
  );
691
736
  }
@@ -701,24 +746,115 @@ function DataGrid({
701
746
  children,
702
747
  className
703
748
  }) {
704
- return /* @__PURE__ */ jsx7(DataGridContext.Provider, { value: grid, children: /* @__PURE__ */ jsx7("div", { className: cn7("w-full space-y-2 outline-none", className), children }) });
749
+ const rootRef = React3.useRef(null);
750
+ const [activeCell, setActiveCell] = React3.useState(null);
751
+ const [selection, setSelection] = React3.useState(null);
752
+ const contextValue = React3.useMemo(
753
+ () => ({
754
+ ...grid,
755
+ activeCell,
756
+ selection,
757
+ setActiveCell,
758
+ setSelection,
759
+ rootRef
760
+ }),
761
+ [activeCell, grid, selection]
762
+ );
763
+ function selectedCoordinates() {
764
+ if (!selection) return null;
765
+ const rowIndexes = [
766
+ grid.rows.findIndex((row, index) => grid.getRowId(row, index) === selection.anchor.rowId),
767
+ grid.rows.findIndex((row, index) => grid.getRowId(row, index) === selection.focus.rowId)
768
+ ].sort((a, b) => a - b);
769
+ const columnIndexes = [
770
+ grid.columns.findIndex((column) => column.id === selection.anchor.columnId),
771
+ grid.columns.findIndex((column) => column.id === selection.focus.columnId)
772
+ ].sort((a, b) => a - b);
773
+ if (rowIndexes.some((index) => index < 0) || columnIndexes.some((index) => index < 0)) return null;
774
+ return { rowIndexes, columnIndexes };
775
+ }
776
+ function focusCell(rowIndex, columnIndex) {
777
+ const row = grid.rows[rowIndex];
778
+ const column = grid.columns[columnIndex];
779
+ if (!row || !column) return;
780
+ const rowId = grid.getRowId(row, rowIndex);
781
+ const cell = rootRef.current?.querySelector(
782
+ `[data-grid-row-id="${CSS.escape(rowId)}"] [data-grid-column-id="${CSS.escape(column.id)}"]`
783
+ );
784
+ cell?.focus();
785
+ }
786
+ function handleCopy(event) {
787
+ const coordinates = selectedCoordinates();
788
+ if (!coordinates) return;
789
+ const value = coordinates.rowIndexes.map(
790
+ (rowIndex) => coordinates.columnIndexes.map(
791
+ (columnIndex) => String(grid.getCellValue(grid.getRowId(grid.rows[rowIndex], rowIndex), grid.columns[columnIndex].id) ?? "")
792
+ ).join(" ")
793
+ ).join("\n");
794
+ event.preventDefault();
795
+ event.clipboardData.setData("text/plain", value);
796
+ }
797
+ function handlePaste(event) {
798
+ if (!activeCell) return;
799
+ const startRow = grid.rows.findIndex(
800
+ (row, index) => grid.getRowId(row, index) === activeCell.rowId
801
+ );
802
+ const startColumn = grid.columns.findIndex(
803
+ (column) => column.id === activeCell.columnId
804
+ );
805
+ if (startRow < 0 || startColumn < 0) return;
806
+ const matrix = event.clipboardData.getData("text/plain").split(/\r?\n/).map((row) => row.split(" "));
807
+ event.preventDefault();
808
+ grid.updateRows(
809
+ (rows) => rows.map((row, rowIndex) => {
810
+ const values = matrix[rowIndex - startRow];
811
+ if (!values) return row;
812
+ const next = { ...row };
813
+ values.forEach((value, columnOffset) => {
814
+ const column = grid.columns[startColumn + columnOffset];
815
+ if (column) Object.assign(next, { [column.id]: value });
816
+ });
817
+ return next;
818
+ })
819
+ );
820
+ }
821
+ const childArray = React3.Children.toArray(children);
822
+ const headerRows = childArray.filter(
823
+ (child) => React3.isValidElement(child) && Boolean(child.props.header)
824
+ );
825
+ const bodyRows = childArray.filter(
826
+ (child) => !React3.isValidElement(child) || !child.props.header
827
+ );
828
+ return /* @__PURE__ */ jsx7(DataGridContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx7(
829
+ "div",
830
+ {
831
+ ref: rootRef,
832
+ className: cn7("w-full space-y-2 outline-none", className),
833
+ onCopy: handleCopy,
834
+ onPaste: handlePaste,
835
+ children: /* @__PURE__ */ jsxs2("table", { className: "w-full border-collapse text-sm", children: [
836
+ headerRows.length > 0 && /* @__PURE__ */ jsx7("thead", { children: headerRows }),
837
+ /* @__PURE__ */ jsx7("tbody", { children: bodyRows })
838
+ ] })
839
+ }
840
+ ) });
705
841
  }
706
842
  function DataGridRow({
707
843
  row,
708
844
  rowId,
709
845
  children,
846
+ header = false,
710
847
  className
711
848
  }) {
712
849
  const grid = useDataGridContext();
713
850
  const resolvedRowId = rowId ?? (row ? grid.getRowId(row, 0) : "");
714
851
  const resolvedRow = row ?? grid.getRow(resolvedRowId);
715
852
  return /* @__PURE__ */ jsx7(
716
- "div",
853
+ "tr",
717
854
  {
718
- className: cn7(
719
- "grid grid-cols-[repeat(var(--data-grid-columns),minmax(9rem,1fr))]",
720
- className
721
- ),
855
+ "data-grid-row-id": resolvedRowId,
856
+ "data-grid-header": header || void 0,
857
+ className: cn7("border-b last:border-0", className),
722
858
  children: resolvedRow && children
723
859
  }
724
860
  );
@@ -728,7 +864,7 @@ function DataGridColumn({
728
864
  children,
729
865
  className
730
866
  }) {
731
- return /* @__PURE__ */ jsx7("div", { className: cn7("min-w-0", className), children: children ?? column.header });
867
+ return /* @__PURE__ */ jsx7("th", { className: cn7("min-w-0 px-3 py-2 text-left", className), children: children ?? column.header });
732
868
  }
733
869
  function DataGridCell({
734
870
  row,
@@ -741,21 +877,176 @@ function DataGridCell({
741
877
  const grid = useDataGridContext();
742
878
  const resolvedRowId = rowId ?? (row ? grid.getRowId(row, 0) : "");
743
879
  const value = grid.getCellValue(resolvedRowId, columnId);
880
+ const rowIndex = grid.rows.findIndex(
881
+ (currentRow, index) => grid.getRowId(currentRow, index) === resolvedRowId
882
+ );
883
+ const columnIndex = grid.columns.findIndex((column) => column.id === columnId);
884
+ const isActive = grid.activeCell?.rowId === resolvedRowId && grid.activeCell.columnId === columnId;
885
+ const isSelected = (() => {
886
+ if (!grid.selection) return false;
887
+ const anchorRow = grid.rows.findIndex(
888
+ (currentRow, index) => grid.getRowId(currentRow, index) === grid.selection?.anchor.rowId
889
+ );
890
+ const focusRow = grid.rows.findIndex(
891
+ (currentRow, index) => grid.getRowId(currentRow, index) === grid.selection?.focus.rowId
892
+ );
893
+ const anchorColumn = grid.columns.findIndex(
894
+ (column) => column.id === grid.selection?.anchor.columnId
895
+ );
896
+ const focusColumn = grid.columns.findIndex(
897
+ (column) => column.id === grid.selection?.focus.columnId
898
+ );
899
+ return rowIndex >= Math.min(anchorRow, focusRow) && rowIndex <= Math.max(anchorRow, focusRow) && columnIndex >= Math.min(anchorColumn, focusColumn) && columnIndex <= Math.max(anchorColumn, focusColumn);
900
+ })();
901
+ function focusCell(nextRowIndex, nextColumnIndex) {
902
+ const nextRow = grid.rows[nextRowIndex];
903
+ const nextColumn = grid.columns[nextColumnIndex];
904
+ if (!nextRow || !nextColumn) return;
905
+ const nextRowId = grid.getRowId(nextRow, nextRowIndex);
906
+ grid.setActiveCell({ rowId: nextRowId, columnId: nextColumn.id });
907
+ const nextPosition = { rowId: nextRowId, columnId: nextColumn.id };
908
+ if (grid.activeCell && grid.selection?.anchor && pendingShift.current) {
909
+ grid.setSelection({ anchor: grid.selection.anchor, focus: nextPosition });
910
+ } else {
911
+ grid.setSelection({ anchor: nextPosition, focus: nextPosition });
912
+ }
913
+ const target = grid.rootRef.current?.querySelector(
914
+ `[data-grid-row-id="${CSS.escape(nextRowId)}"] [data-grid-column-id="${CSS.escape(nextColumn.id)}"]`
915
+ );
916
+ target?.focus();
917
+ }
918
+ const pendingShift = React3.useRef(false);
919
+ function fillSelection() {
920
+ if (!grid.selection) return;
921
+ const anchorRow = grid.rows.findIndex(
922
+ (currentRow, index) => grid.getRowId(currentRow, index) === grid.selection?.anchor.rowId
923
+ );
924
+ const focusRow = grid.rows.findIndex(
925
+ (currentRow, index) => grid.getRowId(currentRow, index) === grid.selection?.focus.rowId
926
+ );
927
+ const anchorColumn = grid.columns.findIndex(
928
+ (column) => column.id === grid.selection?.anchor.columnId
929
+ );
930
+ const focusColumn = grid.columns.findIndex(
931
+ (column) => column.id === grid.selection?.focus.columnId
932
+ );
933
+ if (anchorRow < 0 || focusRow < 0 || anchorColumn < 0 || focusColumn < 0) return;
934
+ const source = grid.getCellValue(
935
+ grid.getRowId(grid.rows[anchorRow], anchorRow),
936
+ grid.columns[anchorColumn].id
937
+ );
938
+ const minRow = Math.min(anchorRow, focusRow);
939
+ const maxRow = Math.max(anchorRow, focusRow);
940
+ const minColumn = Math.min(anchorColumn, focusColumn);
941
+ const maxColumn = Math.max(anchorColumn, focusColumn);
942
+ grid.updateRows(
943
+ (rows) => rows.map((row2, rowIndex2) => {
944
+ if (rowIndex2 < minRow || rowIndex2 > maxRow) return row2;
945
+ const next = { ...row2 };
946
+ for (let columnIndex2 = minColumn; columnIndex2 <= maxColumn; columnIndex2 += 1) {
947
+ Object.assign(next, { [grid.columns[columnIndex2].id]: source });
948
+ }
949
+ return next;
950
+ })
951
+ );
952
+ }
953
+ function onKeyDown(event) {
954
+ const target = event.target;
955
+ const isEditor = target.tagName === "INPUT" || target.tagName === "TEXTAREA";
956
+ if (isEditor && ["ArrowLeft", "ArrowRight"].includes(event.key)) return;
957
+ if (event.altKey && (event.key === "ArrowUp" || event.key === "ArrowDown")) {
958
+ event.preventDefault();
959
+ grid.moveRow(resolvedRowId, rowIndex + (event.key === "ArrowUp" ? -1 : 1));
960
+ return;
961
+ }
962
+ let nextRowIndex = rowIndex;
963
+ let nextColumnIndex = columnIndex;
964
+ if (event.key === "ArrowUp") nextRowIndex -= 1;
965
+ if (event.key === "ArrowDown" || event.key === "Enter") nextRowIndex += 1;
966
+ if (event.key === "ArrowLeft") nextColumnIndex -= 1;
967
+ if (event.key === "ArrowRight" || event.key === "Tab") nextColumnIndex += event.shiftKey ? -1 : 1;
968
+ if (event.key === "Home") nextColumnIndex = 0;
969
+ if (event.key === "End") nextColumnIndex = grid.columns.length - 1;
970
+ if (event.key === "PageUp") nextRowIndex = 0;
971
+ if (event.key === "PageDown") nextRowIndex = grid.rows.length - 1;
972
+ if (nextRowIndex === rowIndex && nextColumnIndex === columnIndex) return;
973
+ event.preventDefault();
974
+ pendingShift.current = event.shiftKey;
975
+ focusCell(nextRowIndex, nextColumnIndex);
976
+ pendingShift.current = false;
977
+ }
978
+ const selectionBounds = grid.selection ? {
979
+ minRow: Math.min(
980
+ grid.rows.findIndex((row2, index) => grid.getRowId(row2, index) === grid.selection?.anchor.rowId),
981
+ grid.rows.findIndex((row2, index) => grid.getRowId(row2, index) === grid.selection?.focus.rowId)
982
+ ),
983
+ maxRow: Math.max(
984
+ grid.rows.findIndex((row2, index) => grid.getRowId(row2, index) === grid.selection?.anchor.rowId),
985
+ grid.rows.findIndex((row2, index) => grid.getRowId(row2, index) === grid.selection?.focus.rowId)
986
+ ),
987
+ minColumn: Math.min(
988
+ grid.columns.findIndex((column) => column.id === grid.selection?.anchor.columnId),
989
+ grid.columns.findIndex((column) => column.id === grid.selection?.focus.columnId)
990
+ ),
991
+ maxColumn: Math.max(
992
+ grid.columns.findIndex((column) => column.id === grid.selection?.anchor.columnId),
993
+ grid.columns.findIndex((column) => column.id === grid.selection?.focus.columnId)
994
+ )
995
+ } : null;
996
+ const showFillHandle = selectionBounds && (selectionBounds.minRow !== selectionBounds.maxRow || selectionBounds.minColumn !== selectionBounds.maxColumn) && rowIndex === selectionBounds.maxRow && columnIndex === selectionBounds.maxColumn;
744
997
  return /* @__PURE__ */ jsx7(
745
998
  DataGridCellContext.Provider,
746
999
  {
747
1000
  value: { rowId: resolvedRowId, columnId, value },
748
- children: /* @__PURE__ */ jsx7(
749
- "div",
1001
+ children: /* @__PURE__ */ jsxs2(
1002
+ "td",
750
1003
  {
1004
+ "data-grid-row-id": resolvedRowId,
1005
+ "data-grid-column-id": columnId,
1006
+ tabIndex: 0,
1007
+ onFocus: () => {
1008
+ grid.setActiveCell({ rowId: resolvedRowId, columnId });
1009
+ if (!grid.selection) {
1010
+ grid.setSelection({
1011
+ anchor: { rowId: resolvedRowId, columnId },
1012
+ focus: { rowId: resolvedRowId, columnId }
1013
+ });
1014
+ }
1015
+ },
1016
+ onClick: (event) => {
1017
+ if (event.shiftKey && grid.activeCell) {
1018
+ grid.setSelection({ anchor: grid.activeCell, focus: { rowId: resolvedRowId, columnId } });
1019
+ } else {
1020
+ grid.setSelection({
1021
+ anchor: { rowId: resolvedRowId, columnId },
1022
+ focus: { rowId: resolvedRowId, columnId }
1023
+ });
1024
+ }
1025
+ grid.setActiveCell({ rowId: resolvedRowId, columnId });
1026
+ },
1027
+ onKeyDown,
751
1028
  "aria-invalid": state === "invalid" || void 0,
752
1029
  className: cn7(
753
- "min-h-9 border-r border-b px-2 py-1.5",
1030
+ "relative min-h-9 border-r border-b px-2 py-1.5 align-middle outline-none",
1031
+ isSelected && "bg-accent/40",
1032
+ isActive && "ring-2 ring-inset ring-primary",
754
1033
  state === "invalid" && "border-destructive/60 bg-destructive/10",
755
1034
  state === "pending" && "opacity-70",
756
1035
  className
757
1036
  ),
758
- children
1037
+ children: [
1038
+ children,
1039
+ showFillHandle && /* @__PURE__ */ jsx7(
1040
+ "button",
1041
+ {
1042
+ type: "button",
1043
+ "aria-label": "Fill selected cells",
1044
+ className: "absolute right-0 bottom-0 z-10 size-2 cursor-crosshair border border-background bg-primary",
1045
+ onMouseDown: (event) => event.preventDefault(),
1046
+ onClick: fillSelection
1047
+ }
1048
+ )
1049
+ ]
759
1050
  }
760
1051
  )
761
1052
  }
@@ -790,20 +1081,40 @@ function GridTextCell({
790
1081
  }
791
1082
  function GridNumberCell({
792
1083
  value,
793
- onChange
1084
+ onChange,
1085
+ min,
1086
+ max,
1087
+ step = "any",
1088
+ allowEmpty = true
794
1089
  }) {
795
1090
  const cell = useGridCell();
796
- const currentValue = value ?? (typeof cell.value === "number" ? cell.value : "");
1091
+ const currentValue = value ?? (typeof cell.value === "number" ? cell.value : String(cell.value ?? ""));
1092
+ const [invalid, setInvalid] = React3.useState(false);
797
1093
  return /* @__PURE__ */ jsx7(
798
1094
  Input,
799
1095
  {
800
- className: "h-7 w-full min-w-0 bg-transparent text-sm outline-none",
1096
+ "aria-invalid": invalid || void 0,
1097
+ className: cn7(
1098
+ "h-7 w-full min-w-0 bg-transparent text-sm outline-none",
1099
+ invalid && "border-destructive ring-2 ring-destructive/20"
1100
+ ),
801
1101
  onChange: (event) => {
1102
+ const rawValue = event.target.value;
1103
+ if (!rawValue && allowEmpty) {
1104
+ setInvalid(false);
1105
+ cell.grid.updateCell(cell.rowId, cell.columnId, "");
1106
+ return;
1107
+ }
802
1108
  const nextValue = event.target.valueAsNumber;
803
1109
  if (Number.isNaN(nextValue)) return;
1110
+ const nextInvalid = min !== void 0 && nextValue < min || max !== void 0 && nextValue > max;
1111
+ setInvalid(nextInvalid);
804
1112
  onChange?.(nextValue);
805
1113
  cell.grid.updateCell(cell.rowId, cell.columnId, nextValue);
806
1114
  },
1115
+ min,
1116
+ max,
1117
+ step,
807
1118
  type: "number",
808
1119
  value: currentValue
809
1120
  }
@@ -850,6 +1161,7 @@ function GridAsyncComboboxCell({
850
1161
  const selectedValue = value ?? String(cell.value ?? "");
851
1162
  const [query, setQuery] = React3.useState("");
852
1163
  const [options, setOptions] = React3.useState([]);
1164
+ const [selectedOption, setSelectedOption] = React3.useState(null);
853
1165
  const [isLoading, setIsLoading] = React3.useState(false);
854
1166
  const requestId = React3.useRef(0);
855
1167
  const loadOptionsRef = React3.useRef(loadOptions);
@@ -892,19 +1204,21 @@ function GridAsyncComboboxCell({
892
1204
  }
893
1205
  };
894
1206
  }, [debounceMs, minQueryLength, query, stableLoadOptions]);
1207
+ const selectedItem = options.find((option) => option.value === selectedValue) ?? (selectedOption?.value === selectedValue ? selectedOption : null);
895
1208
  return /* @__PURE__ */ jsxs2(
896
1209
  Combobox,
897
1210
  {
898
1211
  items: options,
899
- itemToStringLabel: (item) => options.find((option) => option.value === item)?.label ?? String(item ?? ""),
900
- onValueChange: (nextValue) => {
901
- if (nextValue === null) return;
902
- const option = options.find((item) => item.value === nextValue);
903
- onChange?.(nextValue, option);
904
- cell.grid.updateCell(cell.rowId, cell.columnId, nextValue);
905
- setQuery(option?.label ?? nextValue);
1212
+ itemToStringLabel: (item) => item?.label ?? "",
1213
+ itemToStringValue: (item) => item?.value ?? "",
1214
+ onValueChange: (nextOption) => {
1215
+ if (nextOption === null) return;
1216
+ setSelectedOption(nextOption);
1217
+ onChange?.(nextOption.value, nextOption);
1218
+ cell.grid.updateCell(cell.rowId, cell.columnId, nextOption.value);
1219
+ setQuery(nextOption.label);
906
1220
  },
907
- value: selectedValue,
1221
+ value: selectedItem,
908
1222
  children: [
909
1223
  /* @__PURE__ */ jsx7(
910
1224
  ComboboxInput,
@@ -919,7 +1233,7 @@ function GridAsyncComboboxCell({
919
1233
  /* @__PURE__ */ jsxs2(ComboboxContent, { children: [
920
1234
  isLoading && /* @__PURE__ */ jsx7(ComboboxEmpty, { children: "Loading..." }),
921
1235
  !isLoading && query.trim().length >= minQueryLength && options.length === 0 && /* @__PURE__ */ jsx7(ComboboxEmpty, { children: "No results found." }),
922
- /* @__PURE__ */ jsx7(ComboboxList, { children: options.map((option) => /* @__PURE__ */ jsx7(ComboboxItem, { value: option.value, children: option.label }, option.value)) })
1236
+ /* @__PURE__ */ jsx7(ComboboxList, { children: options.map((option) => /* @__PURE__ */ jsx7(ComboboxItem, { value: option, children: option.label }, option.value)) })
923
1237
  ] })
924
1238
  ]
925
1239
  }
@@ -59,6 +59,9 @@ type DataGridApi<TData extends Record<string, unknown>> = {
59
59
  getCellValue: (rowId: string, columnId: string) => DataGridValue;
60
60
  updateCell: (rowId: string, columnId: string, value: DataGridValue) => void;
61
61
  updateRows: (updater: (rows: TData[]) => TData[]) => void;
62
+ insertRows: (rows: TData[], index?: number) => void;
63
+ deleteRows: (rowIds: string[]) => void;
64
+ moveRow: (rowId: string, toIndex: number) => void;
62
65
  };
63
66
  type UseDataGridOptions<TData extends Record<string, unknown>> = {
64
67
  columnIds?: string[];
@@ -66,17 +69,19 @@ type UseDataGridOptions<TData extends Record<string, unknown>> = {
66
69
  initialRows?: TData[];
67
70
  createEmptyRow?: () => TData;
68
71
  getRowId?: (row: TData, index: number) => string;
72
+ maxRows?: number;
69
73
  };
70
- declare function useDataGrid<TData extends Record<string, unknown>>({ columnIds, columns, initialRows, getRowId, }?: UseDataGridOptions<TData>): DataGridApi<TData>;
74
+ declare function useDataGrid<TData extends Record<string, unknown>>({ columnIds, columns, initialRows, getRowId, maxRows, }?: UseDataGridOptions<TData>): DataGridApi<TData>;
71
75
  declare function DataGrid<TData extends Record<string, unknown>>({ grid, children, className, }: {
72
76
  grid: DataGridApi<TData>;
73
77
  children?: React.ReactNode;
74
78
  className?: string;
75
79
  }): React.JSX.Element;
76
- declare function DataGridRow({ row, rowId, children, className, }: {
80
+ declare function DataGridRow({ row, rowId, children, header, className, }: {
77
81
  row?: Record<string, unknown>;
78
82
  rowId?: string;
79
83
  children?: React.ReactNode;
84
+ header?: boolean;
80
85
  className?: string;
81
86
  }): React.JSX.Element;
82
87
  type DataGridColumn<TData = Record<string, unknown>> = {
@@ -103,9 +108,13 @@ declare function GridTextCell({ value, onChange, placeholder, }: {
103
108
  onChange?: (value: string) => void;
104
109
  placeholder?: string;
105
110
  }): React.JSX.Element;
106
- declare function GridNumberCell({ value, onChange, }: {
107
- value?: number;
111
+ declare function GridNumberCell({ value, onChange, min, max, step, allowEmpty, }: {
112
+ value?: number | string;
108
113
  onChange?: (value: number) => void;
114
+ min?: number;
115
+ max?: number;
116
+ step?: number | "any";
117
+ allowEmpty?: boolean;
109
118
  }): React.JSX.Element;
110
119
  declare function GridComboboxCell({ options, value, onChange, }: {
111
120
  options: GridComboboxOption[];
@@ -1,5 +1,5 @@
1
- import { D as DataGridApi } from '../data-grid-CUn4qqSF.js';
2
- export { u as useDataGrid, a as useDataTable } from '../data-grid-CUn4qqSF.js';
1
+ import { D as DataGridApi } from '../data-grid-BIjaNW_l.js';
2
+ export { u as useDataGrid, a as useDataTable } from '../data-grid-BIjaNW_l.js';
3
3
  export { NuqsAdapter } from 'nuqs/adapters/next/app';
4
4
  import 'react';
5
5
 
@@ -102,13 +102,17 @@ declare function useGridChanges<TData extends Record<string, unknown>>(grid: Dat
102
102
  initialRows?: TData[];
103
103
  }): {
104
104
  dirtyRowIds: Set<string>;
105
+ deletedRowIds: Set<string>;
105
106
  updateCell: (rowId: string, columnId: string, value: unknown) => void;
107
+ insertRows: (rows: TData[], index?: number) => void;
108
+ deleteRows: (rowIds: string[]) => void;
106
109
  getChangeSet: () => {
107
110
  created: TData[];
108
111
  updated: TData[];
109
112
  deleted: TData[];
110
113
  };
111
- reset: () => void;
114
+ reset: (rows?: TData[]) => void;
115
+ reconcile: (succeededIds: string[], failedIds?: string[]) => void;
112
116
  };
113
117
 
114
118
  export { searchFocus, useDataGridClipboard, useDataGridFillHandle, useDataGridMove, useDataTablePagination, useDataTableRows, useDataTableSearch, useFullscreen, useGridChanges, useMediaQuery, useMounted, useNative, useSearchParams };
@@ -17,7 +17,7 @@ import {
17
17
  useDataTableSearch,
18
18
  useMediaQuery,
19
19
  useMounted
20
- } from "../chunk-J2SGPPFU.js";
20
+ } from "../chunk-WVPRWHFY.js";
21
21
  import "../chunk-ATPUW3SQ.js";
22
22
 
23
23
  // src/hooks/useSearchParams.ts
@@ -283,6 +283,9 @@ import * as React2 from "react";
283
283
  function useGridChanges(grid, options = {}) {
284
284
  const initialRows = options.initialRows ?? [];
285
285
  const [dirtyRowIds, setDirtyRowIds] = React2.useState(/* @__PURE__ */ new Set());
286
+ const [deletedRowIds, setDeletedRowIds] = React2.useState(
287
+ /* @__PURE__ */ new Set()
288
+ );
286
289
  const updateCell = React2.useCallback(
287
290
  (rowId, columnId, value) => {
288
291
  grid.updateCell(rowId, columnId, value);
@@ -302,14 +305,65 @@ function useGridChanges(grid, options = {}) {
302
305
  if (initialById.has(rowId)) updated.push(row);
303
306
  else created.push(row);
304
307
  }
305
- return { created, updated, deleted: [] };
306
- }, [dirtyRowIds, grid, initialRows]);
307
- const reset = React2.useCallback(() => setDirtyRowIds(/* @__PURE__ */ new Set()), []);
308
+ const currentIds = new Set(
309
+ grid.rows.map((row, index) => grid.getRowId(row, index))
310
+ );
311
+ const deleted = initialRows.filter((row, index) => {
312
+ const rowId = grid.getRowId(row, index);
313
+ return deletedRowIds.has(rowId) || !currentIds.has(rowId);
314
+ });
315
+ return { created, updated, deleted };
316
+ }, [deletedRowIds, dirtyRowIds, grid, initialRows]);
317
+ const insertRows = React2.useCallback(
318
+ (rows, index) => {
319
+ grid.insertRows(rows, index);
320
+ setDirtyRowIds((current) => {
321
+ const next = new Set(current);
322
+ rows.forEach((row, rowIndex) => next.add(grid.getRowId(row, rowIndex)));
323
+ return next;
324
+ });
325
+ },
326
+ [grid]
327
+ );
328
+ const deleteRows = React2.useCallback(
329
+ (rowIds) => {
330
+ grid.deleteRows(rowIds);
331
+ setDeletedRowIds((current) => /* @__PURE__ */ new Set([...current, ...rowIds]));
332
+ },
333
+ [grid]
334
+ );
335
+ const reset = React2.useCallback(
336
+ (rows = initialRows) => {
337
+ grid.updateRows(() => rows);
338
+ setDirtyRowIds(/* @__PURE__ */ new Set());
339
+ setDeletedRowIds(/* @__PURE__ */ new Set());
340
+ },
341
+ [grid, initialRows]
342
+ );
343
+ const reconcile = React2.useCallback(
344
+ (succeededIds, failedIds = []) => {
345
+ const succeeded = new Set(succeededIds);
346
+ setDirtyRowIds(
347
+ (current) => new Set([...current].filter((rowId) => !succeeded.has(rowId)))
348
+ );
349
+ setDeletedRowIds(
350
+ (current) => new Set([...current].filter((rowId) => !succeeded.has(rowId)))
351
+ );
352
+ if (failedIds.length > 0) {
353
+ setDirtyRowIds((current) => /* @__PURE__ */ new Set([...current, ...failedIds]));
354
+ }
355
+ },
356
+ []
357
+ );
308
358
  return {
309
359
  dirtyRowIds,
360
+ deletedRowIds,
310
361
  updateCell,
362
+ insertRows,
363
+ deleteRows,
311
364
  getChangeSet,
312
- reset
365
+ reset,
366
+ reconcile
313
367
  };
314
368
  }
315
369
  export {
@@ -21,7 +21,7 @@ import { Combobox as Combobox$1 } from '@base-ui/react';
21
21
  import { Command as Command$1 } from 'cmdk';
22
22
  export { useCommandState } from 'cmdk';
23
23
  import { Dialog as Dialog$1 } from '@base-ui/react/dialog';
24
- export { C as CellState, b as DataGrid, D as DataGridApi, c as DataGridCell, d as DataGridClipboard, e as DataGridColumn, e as DataGridColumnDef, f as DataGridFillHandle, g as DataGridMove, h as DataGridRow, i as DataTableColumn, j as DataTableColumnDef, k as DataTableColumnResize, l as DataTableRoot, m as DataTableRootProps, G as GridAsyncComboboxCell, n as GridAsyncComboboxCellProps, o as GridComboboxCell, p as GridComboboxOption, q as GridNumberCell, r as GridTextCell, U as UseDataGridOptions } from '../data-grid-CUn4qqSF.js';
24
+ export { C as CellState, b as DataGrid, D as DataGridApi, c as DataGridCell, d as DataGridClipboard, e as DataGridColumn, e as DataGridColumnDef, f as DataGridFillHandle, g as DataGridMove, h as DataGridRow, i as DataTableColumn, j as DataTableColumnDef, k as DataTableColumnResize, l as DataTableRoot, m as DataTableRootProps, G as GridAsyncComboboxCell, n as GridAsyncComboboxCellProps, o as GridComboboxCell, p as GridComboboxOption, q as GridNumberCell, r as GridTextCell, U as UseDataGridOptions } from '../data-grid-BIjaNW_l.js';
25
25
  import { LucideIcon } from 'lucide-react';
26
26
  import { Drawer as Drawer$1 } from '@base-ui/react/drawer';
27
27
  import { Menu } from '@base-ui/react/menu';
package/dist/ui/index.js CHANGED
@@ -45,7 +45,7 @@ import {
45
45
  useDataTableSearch,
46
46
  useMediaQuery,
47
47
  useMounted
48
- } from "../chunk-J2SGPPFU.js";
48
+ } from "../chunk-WVPRWHFY.js";
49
49
  import {
50
50
  Tooltip,
51
51
  TooltipContent,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rockin",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "description": "Reusable React UI components, hooks, icons, utilities, and styles for Rock Star projects.",
5
5
  "keywords": [
6
6
  "react",