@bigbinary/neeto-atoms 1.0.75 → 1.0.76

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.
@@ -3157,6 +3157,7 @@ const SORT_DIRECTIONS = {
3157
3157
  };
3158
3158
  const STORAGE_KEY_PREFIX = "NEETOUI";
3159
3159
  const STORAGE_KEY_SUFFIX = "FIXED_COLUMNS";
3160
+ const COLUMN_SIZING_STORAGE_KEY_SUFFIX = "COLUMN_SIZING";
3160
3161
 
3161
3162
  const getSearchParams = () => new URLSearchParams(window.location.search);
3162
3163
  const readSortFromURL = () => {
@@ -3210,9 +3211,9 @@ const hashPathname = () => {
3210
3211
  }
3211
3212
  return Math.abs(hash).toString(16).toUpperCase();
3212
3213
  };
3213
- const getStorageKey = (prefix) => {
3214
+ const getStorageKey = (prefix, suffix = STORAGE_KEY_SUFFIX) => {
3214
3215
  const resolvedPrefix = prefix || hashPathname();
3215
- return `${STORAGE_KEY_PREFIX}-${resolvedPrefix}-${STORAGE_KEY_SUFFIX}`;
3216
+ return `${STORAGE_KEY_PREFIX}-${resolvedPrefix}-${suffix}`;
3216
3217
  };
3217
3218
  const readFromLocalStorage = (key) => {
3218
3219
  try {
@@ -3228,6 +3229,33 @@ const writeToLocalStorage = (key, value) => {
3228
3229
  } catch {
3229
3230
  }
3230
3231
  };
3232
+ const readSizingFromLocalStorage = (key) => {
3233
+ try {
3234
+ const stored = localStorage.getItem(key);
3235
+ if (!stored) return {};
3236
+ const parsed = JSON.parse(stored);
3237
+ if (!parsed || typeof parsed !== "object") return {};
3238
+ const result = {};
3239
+ for (const [id, size] of Object.entries(parsed)) {
3240
+ if (typeof size === "number" && Number.isFinite(size)) {
3241
+ result[id] = size;
3242
+ }
3243
+ }
3244
+ return result;
3245
+ } catch {
3246
+ return {};
3247
+ }
3248
+ };
3249
+ const writeSizingToLocalStorage = (key, value) => {
3250
+ try {
3251
+ if (Object.keys(value).length === 0) {
3252
+ localStorage.removeItem(key);
3253
+ } else {
3254
+ localStorage.setItem(key, JSON.stringify(value));
3255
+ }
3256
+ } catch {
3257
+ }
3258
+ };
3231
3259
  const getResizeColumnStyle = ({
3232
3260
  size,
3233
3261
  isSelectionCol,
@@ -3613,14 +3641,25 @@ const useColumnResize = ({
3613
3641
  hasSelectionColumn,
3614
3642
  scrollContainerRef,
3615
3643
  columnSizing,
3616
- setColumnSizing
3644
+ setColumnSizing,
3645
+ initialUserResizedIds,
3646
+ onUserResize
3617
3647
  }) => {
3618
3648
  const [containerWidth, setContainerWidth] = useState(0);
3619
- const userResizedColumnsRef = useRef(/* @__PURE__ */ new Set());
3649
+ const userResizedColumnsRef = useRef(
3650
+ new Set(initialUserResizedIds ?? [])
3651
+ );
3620
3652
  const columns = table.options.columns;
3621
- const clearUserResized = useCallback((columnId) => {
3622
- userResizedColumnsRef.current.delete(columnId);
3623
- }, []);
3653
+ const clearUserResized = useCallback(
3654
+ (columnId) => {
3655
+ userResizedColumnsRef.current.delete(columnId);
3656
+ onUserResize?.(
3657
+ table.getState().columnSizing,
3658
+ userResizedColumnsRef.current
3659
+ );
3660
+ },
3661
+ [onUserResize, table]
3662
+ );
3624
3663
  const trackUserResize = useCallback(
3625
3664
  (updaterOrValue) => {
3626
3665
  setColumnSizing((prev) => {
@@ -3630,10 +3669,11 @@ const useColumnResize = ({
3630
3669
  userResizedColumnsRef.current.add(id);
3631
3670
  }
3632
3671
  }
3672
+ onUserResize?.(next, userResizedColumnsRef.current);
3633
3673
  return next;
3634
3674
  });
3635
3675
  },
3636
- [setColumnSizing]
3676
+ [setColumnSizing, onUserResize]
3637
3677
  );
3638
3678
  useEffect(() => {
3639
3679
  const container = scrollContainerRef.current;
@@ -3706,6 +3746,56 @@ const useColumnResize = ({
3706
3746
  return { trackUserResize, lastDataColumnId, clearUserResized };
3707
3747
  };
3708
3748
 
3749
+ const resolveUpdater = (updaterOrValue, prev) => typeof updaterOrValue === "function" ? updaterOrValue(prev) : updaterOrValue;
3750
+ const useColumnSizingPersistence = ({
3751
+ enabled = true,
3752
+ persistToLocalStorage = false,
3753
+ columnSizing: controlledSizing,
3754
+ onColumnSizingChange: controlledOnChange,
3755
+ localStorageKeyPrefix
3756
+ }) => {
3757
+ const isControlled = controlledSizing !== void 0;
3758
+ const storageKey = useMemo(
3759
+ () => getStorageKey(localStorageKeyPrefix, COLUMN_SIZING_STORAGE_KEY_SUFFIX),
3760
+ [localStorageKeyPrefix]
3761
+ );
3762
+ const initialSizingRef = useRef(null);
3763
+ if (initialSizingRef.current === null) {
3764
+ initialSizingRef.current = enabled && persistToLocalStorage && !isControlled ? readSizingFromLocalStorage(storageKey) : {};
3765
+ }
3766
+ const [internalSizing, setInternalSizing] = useState(
3767
+ initialSizingRef.current
3768
+ );
3769
+ const sizing = isControlled ? controlledSizing : internalSizing;
3770
+ const setColumnSizing = useCallback(
3771
+ (updaterOrValue) => {
3772
+ if (!isControlled) {
3773
+ setInternalSizing((prev) => resolveUpdater(updaterOrValue, prev));
3774
+ }
3775
+ controlledOnChange?.(updaterOrValue);
3776
+ },
3777
+ [isControlled, controlledOnChange]
3778
+ );
3779
+ const persistUserResizedSizing = useCallback(
3780
+ (sizingState, userResizedIds) => {
3781
+ if (!enabled || !persistToLocalStorage || isControlled) return;
3782
+ const filtered = {};
3783
+ userResizedIds.forEach((id) => {
3784
+ const size = sizingState[id];
3785
+ if (typeof size === "number") filtered[id] = size;
3786
+ });
3787
+ writeSizingToLocalStorage(storageKey, filtered);
3788
+ },
3789
+ [enabled, persistToLocalStorage, isControlled, storageKey]
3790
+ );
3791
+ return {
3792
+ columnSizing: enabled ? sizing : {},
3793
+ setColumnSizing,
3794
+ initialUserResizedIds: Object.keys(initialSizingRef.current),
3795
+ persistUserResizedSizing
3796
+ };
3797
+ };
3798
+
3709
3799
  const LoadingOverlay = () => /* @__PURE__ */ jsx("div", { className: "absolute inset-0 z-10 flex items-center justify-center bg-background/50", children: /* @__PURE__ */ jsx(Spinner, { className: "size-6" }) });
3710
3800
 
3711
3801
  const EmptyState = ({ colSpan, message }) => {
@@ -4032,6 +4122,9 @@ const DataTable = ({
4032
4122
  onRowSelect,
4033
4123
  bulkSelectAllRowsProps,
4034
4124
  enableColumnResize = true,
4125
+ persistColumnSizing = false,
4126
+ columnSizing: columnSizingProp,
4127
+ onColumnSizingChange: onColumnSizingChangeProp,
4035
4128
  enableColumnFreeze = true,
4036
4129
  columnPinning: columnPinningProp,
4037
4130
  onColumnPinningChange: onColumnPinningChangeProp,
@@ -4141,7 +4234,18 @@ const DataTable = ({
4141
4234
  return { ...columnPinning, left: ["_selection", ...left] };
4142
4235
  }, [columnPinning, selectionColumn, enableColumnFreeze]);
4143
4236
  const scrollContainerRef = useRef(null);
4144
- const [columnSizing, setColumnSizing] = useState({});
4237
+ const {
4238
+ columnSizing,
4239
+ setColumnSizing,
4240
+ initialUserResizedIds,
4241
+ persistUserResizedSizing
4242
+ } = useColumnSizingPersistence({
4243
+ enabled: enableColumnResize,
4244
+ persistToLocalStorage: persistColumnSizing,
4245
+ columnSizing: columnSizingProp,
4246
+ onColumnSizingChange: onColumnSizingChangeProp,
4247
+ localStorageKeyPrefix
4248
+ });
4145
4249
  const table = useReactTable({
4146
4250
  data,
4147
4251
  columns: allColumns,
@@ -4178,7 +4282,9 @@ const DataTable = ({
4178
4282
  hasSelectionColumn: !!selectionColumn,
4179
4283
  scrollContainerRef,
4180
4284
  columnSizing,
4181
- setColumnSizing
4285
+ setColumnSizing,
4286
+ initialUserResizedIds,
4287
+ onUserResize: persistUserResizedSizing
4182
4288
  });
4183
4289
  table.setOptions((prev) => ({
4184
4290
  ...prev,
@@ -4423,4 +4529,4 @@ const DataTable = ({
4423
4529
  };
4424
4530
 
4425
4531
  export { DataTable as D, useColumnPinning as a, useColumnVisibility as b, useTablePagination as c, useTableSelection as d, useTableSort as e, useColumnOrdering as u };
4426
- //# sourceMappingURL=DataTable-DP06B8C7.js.map
4532
+ //# sourceMappingURL=DataTable-Da_EDRI8.js.map