@bigbinary/neeto-atoms 1.0.85 → 1.0.87

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.
@@ -4,6 +4,7 @@ var jsxRuntime = require('react/jsx-runtime');
4
4
  var React = require('react');
5
5
  var primitives_Table = require('./primitives/Table.js');
6
6
  var utils = require('./utils-BhM0B89p.js');
7
+ var reactRouterDom = require('react-router-dom');
7
8
  var reactI18next = require('react-i18next');
8
9
  var primitives_Checkbox = require('./primitives/Checkbox.js');
9
10
  var primitives_Spinner = require('./primitives/Spinner.js');
@@ -3203,20 +3204,6 @@ const writeSortToURL = (sorting) => {
3203
3204
  }
3204
3205
  window.history.pushState({}, "", url.toString());
3205
3206
  };
3206
- const readPageFromURL = () => {
3207
- const params = new URLSearchParams(window.location.search);
3208
- const page = params.get(URL_PAGE_PARAM);
3209
- return page ? Math.max(1, parseInt(page, 10)) : 1;
3210
- };
3211
- const writePageToURL = (page) => {
3212
- const url = new URL(window.location.href);
3213
- if (page <= 1) {
3214
- url.searchParams.delete(URL_PAGE_PARAM);
3215
- } else {
3216
- url.searchParams.set(URL_PAGE_PARAM, String(page));
3217
- }
3218
- window.history.pushState({}, "", url.toString());
3219
- };
3220
3207
  const keysToRowSelection = (keys) => Object.fromEntries(keys.map((key) => [key, true]));
3221
3208
  const rowSelectionToKeys = (selection) => Object.keys(selection).filter((key) => selection[key]);
3222
3209
  const hashPathname = () => {
@@ -3360,23 +3347,41 @@ const useTablePagination = ({
3360
3347
  enableURLPagination = true
3361
3348
  }) => {
3362
3349
  const isControlled = controlledPage !== void 0;
3363
- const [internalPage, setInternalPage] = React.useState(
3364
- () => enableURLPagination ? readPageFromURL() : 1
3365
- );
3366
- const currentPage = isControlled ? controlledPage : internalPage;
3350
+ const history = reactRouterDom.useHistory();
3351
+ const location = reactRouterDom.useLocation();
3352
+ const pageFromURL = React.useMemo(() => {
3353
+ if (!enableURLPagination) return 1;
3354
+ const params = new URLSearchParams(location.search);
3355
+ const page = params.get(URL_PAGE_PARAM);
3356
+ return page ? Math.max(1, parseInt(page, 10) || 1) : 1;
3357
+ }, [location.search, enableURLPagination]);
3358
+ const [internalPage, setInternalPage] = React.useState(1);
3359
+ const currentPage = isControlled ? controlledPage : enableURLPagination ? pageFromURL : internalPage;
3367
3360
  const pageCount = Math.max(1, Math.ceil(totalCount / pageSize));
3368
3361
  const onPageChange = React.useCallback(
3369
3362
  (page) => {
3370
3363
  const clampedPage = Math.min(Math.max(1, page), pageCount);
3371
- if (!isControlled) {
3364
+ if (!isControlled && !enableURLPagination) {
3372
3365
  setInternalPage(clampedPage);
3373
3366
  }
3374
3367
  controlledOnPageChange?.(clampedPage);
3375
3368
  if (enableURLPagination) {
3376
- writePageToURL(clampedPage);
3369
+ const searchParams = new URLSearchParams(history.location.search);
3370
+ if (clampedPage <= 1) {
3371
+ searchParams.delete(URL_PAGE_PARAM);
3372
+ } else {
3373
+ searchParams.set(URL_PAGE_PARAM, String(clampedPage));
3374
+ }
3375
+ history.push({ search: searchParams.toString() });
3377
3376
  }
3378
3377
  },
3379
- [pageCount, isControlled, controlledOnPageChange, enableURLPagination]
3378
+ [
3379
+ pageCount,
3380
+ isControlled,
3381
+ controlledOnPageChange,
3382
+ enableURLPagination,
3383
+ history
3384
+ ]
3380
3385
  );
3381
3386
  React.useEffect(() => {
3382
3387
  if (currentPage > pageCount && pageCount > 0) {
@@ -4556,4 +4561,4 @@ exports.useColumnVisibility = useColumnVisibility;
4556
4561
  exports.useTablePagination = useTablePagination;
4557
4562
  exports.useTableSelection = useTableSelection;
4558
4563
  exports.useTableSort = useTableSort;
4559
- //# sourceMappingURL=DataTable-ONkM1J3v.js.map
4564
+ //# sourceMappingURL=DataTable-BNeEEAKb.js.map