bolt-table 0.1.20 → 0.1.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.
package/dist/index.d.mts CHANGED
@@ -357,6 +357,8 @@ interface TableBodyProps {
357
357
  normalizedSelectedKeys?: string[];
358
358
  /** Returns the string key for a given row record and index */
359
359
  getRowKey?: (record: DataRecord, index: number) => string;
360
+ /** Returns the original-typed key for a given row record and index */
361
+ getRawRowKey?: (record: DataRecord, index: number) => React$1.Key;
360
362
  /** Expandable row configuration */
361
363
  expandable?: ExpandableConfig<DataRecord>;
362
364
  /** Set of currently expanded row keys */
package/dist/index.d.ts CHANGED
@@ -357,6 +357,8 @@ interface TableBodyProps {
357
357
  normalizedSelectedKeys?: string[];
358
358
  /** Returns the string key for a given row record and index */
359
359
  getRowKey?: (record: DataRecord, index: number) => string;
360
+ /** Returns the original-typed key for a given row record and index */
361
+ getRawRowKey?: (record: DataRecord, index: number) => React$1.Key;
360
362
  /** Expandable row configuration */
361
363
  expandable?: ExpandableConfig<DataRecord>;
362
364
  /** Set of currently expanded row keys */
package/dist/index.js CHANGED
@@ -872,6 +872,7 @@ var Cell = import_react3.default.memo(
872
872
  rowKey,
873
873
  allData,
874
874
  getRowKey,
875
+ getRawRowKey,
875
876
  accentColor,
876
877
  isLoading
877
878
  }) => {
@@ -914,6 +915,7 @@ var Cell = import_react3.default.memo(
914
915
  const checkboxProps = rowSelection.getCheckboxProps?.(record) ?? {
915
916
  disabled: false
916
917
  };
918
+ const rawKey = getRawRowKey ? getRawRowKey(record, rowIndex) : rowKey;
917
919
  const content2 = rowSelection.type === "radio" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
918
920
  "input",
919
921
  {
@@ -923,7 +925,7 @@ var Cell = import_react3.default.memo(
923
925
  onChange: (e) => {
924
926
  e.stopPropagation();
925
927
  rowSelection.onSelect?.(record, true, [record], e.nativeEvent);
926
- rowSelection.onChange?.([rowKey], [record], { type: "single" });
928
+ rowSelection.onChange?.([rawKey], [record], { type: "single" });
927
929
  },
928
930
  style: { cursor: "pointer", accentColor }
929
931
  }
@@ -935,15 +937,12 @@ var Cell = import_react3.default.memo(
935
937
  disabled: checkboxProps.disabled,
936
938
  onChange: (e) => {
937
939
  e.stopPropagation();
938
- const currentKeys = (rowSelection.selectedRowKeys ?? []).map(
939
- (k) => String(k)
940
- );
941
- const newSelected = isSelected ? currentKeys.filter((k) => k !== rowKey) : [...currentKeys, rowKey];
942
- const newSelectedRows = (allData ?? []).filter(
943
- (row, idx) => newSelected.includes(
944
- getRowKey ? getRowKey(row, idx) : String(idx)
945
- )
946
- );
940
+ const currentKeys = rowSelection.selectedRowKeys ?? [];
941
+ const newSelected = isSelected ? currentKeys.filter((k) => String(k) !== rowKey) : [...currentKeys, rawKey];
942
+ const newSelectedRows = (allData ?? []).filter((row, idx) => {
943
+ const rk = getRowKey ? getRowKey(row, idx) : String(idx);
944
+ return newSelected.some((k) => String(k) === rk);
945
+ });
947
946
  rowSelection.onSelect?.(
948
947
  record,
949
948
  !isSelected,
@@ -1082,6 +1081,7 @@ var TableBody = ({
1082
1081
  rowSelection,
1083
1082
  normalizedSelectedKeys = [],
1084
1083
  getRowKey,
1084
+ getRawRowKey,
1085
1085
  expandable,
1086
1086
  resolvedExpandedKeys,
1087
1087
  rowHeight = 40,
@@ -1209,6 +1209,7 @@ var TableBody = ({
1209
1209
  rowKey,
1210
1210
  allData: allDataForSelection,
1211
1211
  getRowKey,
1212
+ getRawRowKey,
1212
1213
  accentColor,
1213
1214
  isLoading: isRowShimmer,
1214
1215
  recordFingerprint
@@ -1390,6 +1391,7 @@ var TableBody = ({
1390
1391
  rowKey: rk,
1391
1392
  allData: allDataForSelection,
1392
1393
  getRowKey,
1394
+ getRawRowKey,
1393
1395
  accentColor,
1394
1396
  isLoading: false,
1395
1397
  recordFingerprint
@@ -1514,6 +1516,7 @@ var TableBody = ({
1514
1516
  rowKey: rk,
1515
1517
  allData: allDataForSelection,
1516
1518
  getRowKey,
1519
+ getRawRowKey,
1517
1520
  accentColor,
1518
1521
  isLoading: false,
1519
1522
  recordFingerprint
@@ -1690,6 +1693,23 @@ function BoltTable({
1690
1693
  },
1691
1694
  [rowKey]
1692
1695
  );
1696
+ const getRawRowKey = (0, import_react4.useCallback)(
1697
+ (record, index) => {
1698
+ if (record == null) return index;
1699
+ try {
1700
+ if (typeof rowKey === "function") return rowKey(record);
1701
+ if (typeof rowKey === "string") {
1702
+ const val = record[rowKey];
1703
+ if (typeof val === "number" || typeof val === "string") return val;
1704
+ return val != null ? String(val) : index;
1705
+ }
1706
+ } catch {
1707
+ return index;
1708
+ }
1709
+ return index;
1710
+ },
1711
+ [rowKey]
1712
+ );
1693
1713
  const normalizedSelectedKeys = (0, import_react4.useMemo)(
1694
1714
  () => {
1695
1715
  const keys = rowSelection?.selectedRowKeys;
@@ -2714,7 +2734,7 @@ function BoltTable({
2714
2734
  onChange: (e) => {
2715
2735
  if (e.target.checked) {
2716
2736
  const allKeys = data.map(
2717
- (row, idx) => getRowKey(row, idx)
2737
+ (row, idx) => getRawRowKey(row, idx)
2718
2738
  );
2719
2739
  rowSelection.onSelectAll?.(
2720
2740
  true,
@@ -2843,6 +2863,7 @@ function BoltTable({
2843
2863
  rowSelection: !showShimmer ? rowSelection : void 0,
2844
2864
  normalizedSelectedKeys,
2845
2865
  getRowKey,
2866
+ getRawRowKey,
2846
2867
  expandable: !showShimmer ? expandable : void 0,
2847
2868
  resolvedExpandedKeys,
2848
2869
  rowHeight,
package/dist/index.mjs CHANGED
@@ -838,6 +838,7 @@ var Cell = React3.memo(
838
838
  rowKey,
839
839
  allData,
840
840
  getRowKey,
841
+ getRawRowKey,
841
842
  accentColor,
842
843
  isLoading
843
844
  }) => {
@@ -880,6 +881,7 @@ var Cell = React3.memo(
880
881
  const checkboxProps = rowSelection.getCheckboxProps?.(record) ?? {
881
882
  disabled: false
882
883
  };
884
+ const rawKey = getRawRowKey ? getRawRowKey(record, rowIndex) : rowKey;
883
885
  const content2 = rowSelection.type === "radio" ? /* @__PURE__ */ jsx4(
884
886
  "input",
885
887
  {
@@ -889,7 +891,7 @@ var Cell = React3.memo(
889
891
  onChange: (e) => {
890
892
  e.stopPropagation();
891
893
  rowSelection.onSelect?.(record, true, [record], e.nativeEvent);
892
- rowSelection.onChange?.([rowKey], [record], { type: "single" });
894
+ rowSelection.onChange?.([rawKey], [record], { type: "single" });
893
895
  },
894
896
  style: { cursor: "pointer", accentColor }
895
897
  }
@@ -901,15 +903,12 @@ var Cell = React3.memo(
901
903
  disabled: checkboxProps.disabled,
902
904
  onChange: (e) => {
903
905
  e.stopPropagation();
904
- const currentKeys = (rowSelection.selectedRowKeys ?? []).map(
905
- (k) => String(k)
906
- );
907
- const newSelected = isSelected ? currentKeys.filter((k) => k !== rowKey) : [...currentKeys, rowKey];
908
- const newSelectedRows = (allData ?? []).filter(
909
- (row, idx) => newSelected.includes(
910
- getRowKey ? getRowKey(row, idx) : String(idx)
911
- )
912
- );
906
+ const currentKeys = rowSelection.selectedRowKeys ?? [];
907
+ const newSelected = isSelected ? currentKeys.filter((k) => String(k) !== rowKey) : [...currentKeys, rawKey];
908
+ const newSelectedRows = (allData ?? []).filter((row, idx) => {
909
+ const rk = getRowKey ? getRowKey(row, idx) : String(idx);
910
+ return newSelected.some((k) => String(k) === rk);
911
+ });
913
912
  rowSelection.onSelect?.(
914
913
  record,
915
914
  !isSelected,
@@ -1048,6 +1047,7 @@ var TableBody = ({
1048
1047
  rowSelection,
1049
1048
  normalizedSelectedKeys = [],
1050
1049
  getRowKey,
1050
+ getRawRowKey,
1051
1051
  expandable,
1052
1052
  resolvedExpandedKeys,
1053
1053
  rowHeight = 40,
@@ -1175,6 +1175,7 @@ var TableBody = ({
1175
1175
  rowKey,
1176
1176
  allData: allDataForSelection,
1177
1177
  getRowKey,
1178
+ getRawRowKey,
1178
1179
  accentColor,
1179
1180
  isLoading: isRowShimmer,
1180
1181
  recordFingerprint
@@ -1356,6 +1357,7 @@ var TableBody = ({
1356
1357
  rowKey: rk,
1357
1358
  allData: allDataForSelection,
1358
1359
  getRowKey,
1360
+ getRawRowKey,
1359
1361
  accentColor,
1360
1362
  isLoading: false,
1361
1363
  recordFingerprint
@@ -1480,6 +1482,7 @@ var TableBody = ({
1480
1482
  rowKey: rk,
1481
1483
  allData: allDataForSelection,
1482
1484
  getRowKey,
1485
+ getRawRowKey,
1483
1486
  accentColor,
1484
1487
  isLoading: false,
1485
1488
  recordFingerprint
@@ -1656,6 +1659,23 @@ function BoltTable({
1656
1659
  },
1657
1660
  [rowKey]
1658
1661
  );
1662
+ const getRawRowKey = useCallback(
1663
+ (record, index) => {
1664
+ if (record == null) return index;
1665
+ try {
1666
+ if (typeof rowKey === "function") return rowKey(record);
1667
+ if (typeof rowKey === "string") {
1668
+ const val = record[rowKey];
1669
+ if (typeof val === "number" || typeof val === "string") return val;
1670
+ return val != null ? String(val) : index;
1671
+ }
1672
+ } catch {
1673
+ return index;
1674
+ }
1675
+ return index;
1676
+ },
1677
+ [rowKey]
1678
+ );
1659
1679
  const normalizedSelectedKeys = useMemo2(
1660
1680
  () => {
1661
1681
  const keys = rowSelection?.selectedRowKeys;
@@ -2680,7 +2700,7 @@ function BoltTable({
2680
2700
  onChange: (e) => {
2681
2701
  if (e.target.checked) {
2682
2702
  const allKeys = data.map(
2683
- (row, idx) => getRowKey(row, idx)
2703
+ (row, idx) => getRawRowKey(row, idx)
2684
2704
  );
2685
2705
  rowSelection.onSelectAll?.(
2686
2706
  true,
@@ -2809,6 +2829,7 @@ function BoltTable({
2809
2829
  rowSelection: !showShimmer ? rowSelection : void 0,
2810
2830
  normalizedSelectedKeys,
2811
2831
  getRowKey,
2832
+ getRawRowKey,
2812
2833
  expandable: !showShimmer ? expandable : void 0,
2813
2834
  resolvedExpandedKeys,
2814
2835
  rowHeight,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bolt-table",
3
- "version": "0.1.20",
3
+ "version": "0.1.21",
4
4
  "description": "Virtualized React table with column drag & drop, pinning, resizing, sorting, filtering, and pagination.",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",