@bigbinary/neeto-atoms 1.0.128 → 1.0.129

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.
@@ -8019,14 +8019,28 @@ const SelectionCheckbox = ({
8019
8019
  ariaLabel
8020
8020
  }) => {
8021
8021
  const { t } = reactI18next.useTranslation();
8022
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
8023
- primitives_Checkbox.Checkbox,
8022
+ const shiftKeyRef = React.useRef(false);
8023
+ return /* @__PURE__ */ jsxRuntime.jsx(
8024
+ "div",
8024
8025
  {
8025
- checked,
8026
- onCheckedChange,
8027
- "aria-label": ariaLabel ?? t("neetoatoms.dataTable.selectRow", "Select row")
8026
+ className: "flex w-full items-center justify-center",
8027
+ onMouseDown: (event) => {
8028
+ if (event.shiftKey) event.preventDefault();
8029
+ },
8030
+ children: /* @__PURE__ */ jsxRuntime.jsx(
8031
+ primitives_Checkbox.Checkbox,
8032
+ {
8033
+ checked,
8034
+ "aria-label": ariaLabel ?? t("neetoatoms.dataTable.selectRow", "Select row"),
8035
+ onCheckedChange: (value) => onCheckedChange(!!value, shiftKeyRef.current),
8036
+ onClick: (event) => {
8037
+ shiftKeyRef.current = event.shiftKey;
8038
+ if (event.shiftKey) event.currentTarget.focus();
8039
+ }
8040
+ }
8041
+ )
8028
8042
  }
8029
- ) });
8043
+ );
8030
8044
  };
8031
8045
 
8032
8046
  const useTableSelection = ({
@@ -8055,7 +8069,8 @@ const useTableSelection = ({
8055
8069
  }
8056
8070
  if (onRowSelect) {
8057
8071
  const keys = rowSelectionToKeys(newSelection);
8058
- const selectedRows = data.filter((row) => keys.includes(getRowId(row)));
8072
+ const keySet = new Set(keys);
8073
+ const selectedRows = data.filter((row) => keySet.has(getRowId(row)));
8059
8074
  onRowSelect(keys, selectedRows);
8060
8075
  }
8061
8076
  },
@@ -8067,25 +8082,66 @@ const useTableSelection = ({
8067
8082
  return;
8068
8083
  }
8069
8084
  }, []);
8085
+ const rangeAnchorRef = React.useRef(null);
8086
+ const onRowCheckedChange = React.useCallback(
8087
+ ({
8088
+ row,
8089
+ table,
8090
+ checked,
8091
+ shiftKey
8092
+ }) => {
8093
+ const rows = table.getRowModel().rows;
8094
+ const currentIndex = rows.findIndex(({ id }) => id === row.id);
8095
+ const anchorIndex = rows.findIndex(
8096
+ ({ id }) => id === rangeAnchorRef.current
8097
+ );
8098
+ const currentSelection = table.getState().rowSelection;
8099
+ const hasSelectionOnPage = rows.some(({ id }) => currentSelection[id]);
8100
+ const isRangeSelection = shiftKey && anchorIndex !== -1 && currentIndex !== -1 && hasSelectionOnPage;
8101
+ if (!isRangeSelection) {
8102
+ rangeAnchorRef.current = checked && row.getCanSelect() ? row.id : null;
8103
+ row.toggleSelected(checked);
8104
+ return;
8105
+ }
8106
+ const startIndex = Math.min(anchorIndex, currentIndex);
8107
+ const endIndex = Math.max(anchorIndex, currentIndex);
8108
+ const rangeRows = rows.slice(startIndex, endIndex + 1).filter((rangeRow) => rangeRow.getCanSelect());
8109
+ const shouldSelect = rangeRows.some(({ id }) => !currentSelection[id]);
8110
+ const nextSelection = { ...currentSelection };
8111
+ rangeRows.forEach(({ id }) => {
8112
+ if (shouldSelect) {
8113
+ nextSelection[id] = true;
8114
+ } else {
8115
+ delete nextSelection[id];
8116
+ }
8117
+ });
8118
+ rangeAnchorRef.current = shouldSelect ? rows[endIndex].id : null;
8119
+ table.setRowSelection(nextSelection);
8120
+ },
8121
+ []
8122
+ );
8070
8123
  const selectionColumn = React.useMemo(() => {
8071
8124
  if (!enableRowSelection) return null;
8072
8125
  return {
8073
8126
  id: "_selection",
8074
8127
  header: ({ table }) => SelectionCheckbox({
8075
8128
  checked: table.getIsAllPageRowsSelected() || table.getIsSomePageRowsSelected() && "indeterminate",
8076
- onCheckedChange: (value) => table.toggleAllPageRowsSelected(!!value),
8129
+ onCheckedChange: (value) => {
8130
+ rangeAnchorRef.current = null;
8131
+ table.toggleAllPageRowsSelected(!!value);
8132
+ },
8077
8133
  ariaLabel: "Select all"
8078
8134
  }),
8079
- cell: ({ row }) => SelectionCheckbox({
8135
+ cell: ({ row, table }) => SelectionCheckbox({
8080
8136
  checked: row.getIsSelected(),
8081
- onCheckedChange: (value) => row.toggleSelected(!!value),
8137
+ onCheckedChange: (value, shiftKey) => onRowCheckedChange({ row, table, checked: value, shiftKey }),
8082
8138
  ariaLabel: "Select row"
8083
8139
  }),
8084
8140
  size: 56,
8085
8141
  enableSorting: false,
8086
8142
  enableResizing: false
8087
8143
  };
8088
- }, [enableRowSelection]);
8144
+ }, [enableRowSelection, onRowCheckedChange]);
8089
8145
  return {
8090
8146
  rowSelection,
8091
8147
  onRowSelectionChange,
@@ -9330,4 +9386,4 @@ exports.useColumnVisibility = useColumnVisibility;
9330
9386
  exports.useTablePagination = useTablePagination;
9331
9387
  exports.useTableSelection = useTableSelection;
9332
9388
  exports.useTableSort = useTableSort;
9333
- //# sourceMappingURL=DataTable-dKha6uAk.js.map
9389
+ //# sourceMappingURL=DataTable-BXNU34g-.js.map