@websolutespa/bom-mixer-hooks 1.8.0 → 1.8.2
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/CHANGELOG.md +13 -0
- package/dist/index.d.ts +20 -12
- package/dist/index.js +117 -55
- package/dist/index.mjs +115 -56
- package/package.json +1 -1
- package/src/useSearchParams/useSearchParams.ts +65 -30
- package/src/useSearchParamsEncoded/useSearchParamsEncoded.ts +45 -65
- package/src/useSearchParamsQs/useSearchParamsQs.ts +41 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @websolutespa/bom-mixer-hooks
|
|
2
2
|
|
|
3
|
+
## 1.8.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Modified: useSearchParams, useSearchParamsEncoded, useSearchParamsQs added pushParams
|
|
8
|
+
|
|
9
|
+
## 1.8.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
- @websolutespa/bom-core@1.8.5
|
|
15
|
+
|
|
3
16
|
## 1.8.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -461,21 +461,23 @@ declare function updateSearchParams(currentPath: string, params: IParams): {
|
|
|
461
461
|
[key: string]: string;
|
|
462
462
|
};
|
|
463
463
|
};
|
|
464
|
-
declare function replaceSearchParams(router: NextRouter, params: IParams): void;
|
|
465
464
|
declare function pushSearchParams(router: NextRouter, params: IParams): void;
|
|
465
|
+
declare function pushSearchParamsSilently(params: IParams): void;
|
|
466
|
+
declare function replaceSearchParams(router: NextRouter, params: IParams): void;
|
|
466
467
|
declare function replaceSearchParamsSilently(params: IParams): void;
|
|
467
|
-
declare function useSearchParams(): IUseSearchParamsResult;
|
|
468
468
|
type IParams = {
|
|
469
469
|
[key: string]: string;
|
|
470
470
|
};
|
|
471
|
-
type IUseSearchParamsValueResult = {
|
|
472
|
-
params: string | null;
|
|
473
|
-
replaceParamsSilently: (params: IParams) => void;
|
|
474
|
-
};
|
|
475
471
|
type IUseSearchParamsResult = {
|
|
476
472
|
params: IParams;
|
|
477
|
-
|
|
473
|
+
pushParams: (params: IParams) => void;
|
|
474
|
+
pushParamsSilently: (params: IParams) => void;
|
|
478
475
|
replaceParams: (params: IParams) => void;
|
|
476
|
+
replaceParamsSilently: (params: IParams) => void;
|
|
477
|
+
};
|
|
478
|
+
declare function useSearchParams(): IUseSearchParamsResult;
|
|
479
|
+
type IUseSearchParamsValueResult = Omit<IUseSearchParamsResult, 'params'> & {
|
|
480
|
+
params: string | null;
|
|
479
481
|
};
|
|
480
482
|
declare function useSearchParamsValue(key: string): IUseSearchParamsValueResult;
|
|
481
483
|
|
|
@@ -486,32 +488,38 @@ declare function updateSearchParamsEncoded(currentPath: string, value: IParamsEn
|
|
|
486
488
|
[key: string]: string;
|
|
487
489
|
};
|
|
488
490
|
};
|
|
489
|
-
declare function replaceSearchParamsEncoded(router: NextRouter, value: IParamsEncoded, key?: string): void;
|
|
490
491
|
declare function pushSearchParamsEncoded(router: NextRouter, value: IParamsEncoded, key?: string): void;
|
|
492
|
+
declare function pushSearchParamsEncodedSilently(value: IParamsEncoded, key?: string): void;
|
|
493
|
+
declare function replaceSearchParamsEncoded(router: NextRouter, value: IParamsEncoded, key?: string): void;
|
|
491
494
|
declare function replaceSearchParamsEncodedSilently(value: IParamsEncoded, key?: string): void;
|
|
492
495
|
type IParamsEncoded = {
|
|
493
496
|
[key: string]: any;
|
|
494
497
|
} | null;
|
|
495
498
|
type IUseSearchParamsEncodedResult = {
|
|
496
499
|
params: IParamsEncoded;
|
|
497
|
-
|
|
500
|
+
pushParams: (params: IParamsEncoded) => void;
|
|
501
|
+
pushParamsSilently: (params: IParamsEncoded) => void;
|
|
498
502
|
replaceParams: (params: IParamsEncoded) => void;
|
|
503
|
+
replaceParamsSilently: (params: IParamsEncoded) => void;
|
|
499
504
|
};
|
|
500
505
|
declare function useSearchParamsEncoded(key?: string): IUseSearchParamsEncodedResult;
|
|
501
506
|
|
|
502
507
|
type IParamsQs = Record<string, any>;
|
|
503
508
|
type IUseSearchParamsQsResult = {
|
|
504
509
|
params: IParamsQs;
|
|
505
|
-
|
|
510
|
+
pushParams: (params: IParamsQs) => void;
|
|
511
|
+
pushParamsSilently: (params: IParamsQs) => void;
|
|
506
512
|
replaceParams: (params: IParamsQs) => void;
|
|
513
|
+
replaceParamsSilently: (params: IParamsQs) => void;
|
|
507
514
|
};
|
|
508
515
|
declare function getSearchParamsQs(url: string, key?: string): IParamsQs;
|
|
509
516
|
declare function updateSearchParamsQs(url: string, value: IParamsQs, key?: string): {
|
|
510
517
|
pathname: string;
|
|
511
518
|
query: string;
|
|
512
519
|
};
|
|
513
|
-
declare function replaceSearchParamsQs(router: NextRouter, value: IParamsQs, key?: string): void;
|
|
514
520
|
declare function pushSearchParamsQs(router: NextRouter, value: IParamsQs, key?: string): void;
|
|
521
|
+
declare function pushSearchParamsQsSilently(value: IParamsQs, key?: string): void;
|
|
522
|
+
declare function replaceSearchParamsQs(router: NextRouter, value: IParamsQs, key?: string): void;
|
|
515
523
|
declare function replaceSearchParamsQsSilently(value: IParamsQs, key?: string): void;
|
|
516
524
|
declare function useSearchParamsQs(key?: string): IUseSearchParamsQsResult;
|
|
517
525
|
|
|
@@ -549,4 +557,4 @@ type WindowSize = {
|
|
|
549
557
|
};
|
|
550
558
|
declare function useWindowSize(): WindowSize;
|
|
551
559
|
|
|
552
|
-
export { BodyScrollOptions, ClickOutGetContainer, CurrentStateType, ElementStackItem, ExtraProvider, Filter, FilterMode, FilterParams, FilterValues, GeoLocationSensorState, IExtra, IFilter, IFilterOption, IGeolocationPositionError, ILabelContext, ILayoutContext, ILazyModulesContext, IPageContext, IPaginationInfo, IParams, IParamsEncoded, IParamsQs, IUseSearchParamsEncodedResult, IUseSearchParamsQsResult, IUseSearchParamsResult, IUseSearchParamsValueResult, KeyCode, KeyMod, KeyboardOptions, KeyboardResult, LabelProvider, LabelService, LayoutProvider, LazyModulesProvider, PageProvider, SSRState, SizeResult, SizeType, Sorting, UIReducer, UIValue, UseFiltersResultType, UseKeyboard, UseKeyboardHandler, createElementWithId, createGenericContext, detectIsBrowser, filtersToParams, getCurrentPosition, getFilteredItems, getFilters, getOwnerPaddingRight, getOwnerScrollbarWidth, getPagedItems, getPaginationInfo, getRealSize, getSearchParams, getSearchParamsEncoded, getSearchParamsQs, getUID, hasGeolocation, isElement, isPaginationInfo, localCollectionDelete, localCollectionFetch, localCollectionGet, localCollectionPatch, localCollectionPost, localCollectionPut, parseLabel, parseParams, pushSearchParams, pushSearchParamsEncoded, pushSearchParamsQs, replaceSearchParams, replaceSearchParamsEncoded, replaceSearchParamsEncodedSilently, replaceSearchParamsQs, replaceSearchParamsQsSilently, replaceSearchParamsSilently, scrollToRelativeY, scrollToSelector, scrollToY, setFilters, updateSearchParams, updateSearchParamsEncoded, updateSearchParamsQs, useApi, useApiDelete, useApiFetch, useApiGet, useApiPatch, useApiPost, useApiPut, useBodyScroll, useBreakpoint, useClickAnyWhere, useClickOut, useCollectionApi, useCollectionApiDelete, useCollectionApiGet, useCollectionApiPatch, useCollectionApiPost, useCollectionApiPut, useCurrency, useCurrentState, useDateTimeFormat, useDebounce, useDebounceCallback, useDebugChangedProps, useDomObserver, useDrawer, useElementSize, useEventListener, useExtra, useFilters, useGeolocation, useIdle, useInfiniteLoader, useIntersectionObserver, useIsomorphicLayoutEffect, useKeyboard, useLabel, useLayout, useLazyModules, useModal, useMounted, useNumber, usePage, usePagination, usePortal, usePrevious, useRealSize, useResize, useSSR, useScroll, useScrollTo, useScrolled, useSearchParams, useSearchParamsEncoded, useSearchParamsQs, useSearchParamsValue, useSorting, useSyncedRef, useUI, useUnit, useUnmountEffect, useWindowSize };
|
|
560
|
+
export { BodyScrollOptions, ClickOutGetContainer, CurrentStateType, ElementStackItem, ExtraProvider, Filter, FilterMode, FilterParams, FilterValues, GeoLocationSensorState, IExtra, IFilter, IFilterOption, IGeolocationPositionError, ILabelContext, ILayoutContext, ILazyModulesContext, IPageContext, IPaginationInfo, IParams, IParamsEncoded, IParamsQs, IUseSearchParamsEncodedResult, IUseSearchParamsQsResult, IUseSearchParamsResult, IUseSearchParamsValueResult, KeyCode, KeyMod, KeyboardOptions, KeyboardResult, LabelProvider, LabelService, LayoutProvider, LazyModulesProvider, PageProvider, SSRState, SizeResult, SizeType, Sorting, UIReducer, UIValue, UseFiltersResultType, UseKeyboard, UseKeyboardHandler, createElementWithId, createGenericContext, detectIsBrowser, filtersToParams, getCurrentPosition, getFilteredItems, getFilters, getOwnerPaddingRight, getOwnerScrollbarWidth, getPagedItems, getPaginationInfo, getRealSize, getSearchParams, getSearchParamsEncoded, getSearchParamsQs, getUID, hasGeolocation, isElement, isPaginationInfo, localCollectionDelete, localCollectionFetch, localCollectionGet, localCollectionPatch, localCollectionPost, localCollectionPut, parseLabel, parseParams, pushSearchParams, pushSearchParamsEncoded, pushSearchParamsEncodedSilently, pushSearchParamsQs, pushSearchParamsQsSilently, pushSearchParamsSilently, replaceSearchParams, replaceSearchParamsEncoded, replaceSearchParamsEncodedSilently, replaceSearchParamsQs, replaceSearchParamsQsSilently, replaceSearchParamsSilently, scrollToRelativeY, scrollToSelector, scrollToY, setFilters, updateSearchParams, updateSearchParamsEncoded, updateSearchParamsQs, useApi, useApiDelete, useApiFetch, useApiGet, useApiPatch, useApiPost, useApiPut, useBodyScroll, useBreakpoint, useClickAnyWhere, useClickOut, useCollectionApi, useCollectionApiDelete, useCollectionApiGet, useCollectionApiPatch, useCollectionApiPost, useCollectionApiPut, useCurrency, useCurrentState, useDateTimeFormat, useDebounce, useDebounceCallback, useDebugChangedProps, useDomObserver, useDrawer, useElementSize, useEventListener, useExtra, useFilters, useGeolocation, useIdle, useInfiniteLoader, useIntersectionObserver, useIsomorphicLayoutEffect, useKeyboard, useLabel, useLayout, useLazyModules, useModal, useMounted, useNumber, usePage, usePagination, usePortal, usePrevious, useRealSize, useResize, useSSR, useScroll, useScrollTo, useScrolled, useSearchParams, useSearchParamsEncoded, useSearchParamsQs, useSearchParamsValue, useSorting, useSyncedRef, useUI, useUnit, useUnmountEffect, useWindowSize };
|
package/dist/index.js
CHANGED
|
@@ -96,7 +96,10 @@ __export(src_exports, {
|
|
|
96
96
|
parseParams: () => parseParams,
|
|
97
97
|
pushSearchParams: () => pushSearchParams,
|
|
98
98
|
pushSearchParamsEncoded: () => pushSearchParamsEncoded,
|
|
99
|
+
pushSearchParamsEncodedSilently: () => pushSearchParamsEncodedSilently,
|
|
99
100
|
pushSearchParamsQs: () => pushSearchParamsQs,
|
|
101
|
+
pushSearchParamsQsSilently: () => pushSearchParamsQsSilently,
|
|
102
|
+
pushSearchParamsSilently: () => pushSearchParamsSilently,
|
|
100
103
|
replaceSearchParams: () => replaceSearchParams,
|
|
101
104
|
replaceSearchParamsEncoded: () => replaceSearchParamsEncoded,
|
|
102
105
|
replaceSearchParamsEncodedSilently: () => replaceSearchParamsEncodedSilently,
|
|
@@ -1601,13 +1604,6 @@ function useScrolled(callback = DEFAULT_CALLBACK) {
|
|
|
1601
1604
|
var import_bom_core7 = require("@websolutespa/bom-core");
|
|
1602
1605
|
var import_router = require("next/router");
|
|
1603
1606
|
var import_react31 = require("react");
|
|
1604
|
-
function replace_(params) {
|
|
1605
|
-
if (window.history) {
|
|
1606
|
-
const title = document.title;
|
|
1607
|
-
const url = `${window.location.href.split("?")[0]}?${params.toString()}`;
|
|
1608
|
-
window.history.replaceState(params.toString(), title, url);
|
|
1609
|
-
}
|
|
1610
|
-
}
|
|
1611
1607
|
function deserialize_(url) {
|
|
1612
1608
|
const components = url.split("?");
|
|
1613
1609
|
const search = components[1] || "";
|
|
@@ -1642,18 +1638,38 @@ function updateSearchParams(currentPath, params) {
|
|
|
1642
1638
|
const pathname = components[0] || "";
|
|
1643
1639
|
return { pathname, query };
|
|
1644
1640
|
}
|
|
1641
|
+
function pushSearchParams(router, params) {
|
|
1642
|
+
const { pathname, query } = updateSearchParams(router.asPath, params);
|
|
1643
|
+
router.push({ pathname, query });
|
|
1644
|
+
}
|
|
1645
|
+
function historyPushState(params) {
|
|
1646
|
+
if (window.history) {
|
|
1647
|
+
const title = document.title;
|
|
1648
|
+
const url = `${window.location.href.split("?")[0]}?${params.toString()}`;
|
|
1649
|
+
window.history.pushState(params.toString(), title, url);
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
function pushSearchParamsSilently(params) {
|
|
1653
|
+
if (import_bom_core7.isBrowser) {
|
|
1654
|
+
const searchParams = serialize_(window.location.search, params);
|
|
1655
|
+
historyPushState(searchParams);
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1645
1658
|
function replaceSearchParams(router, params) {
|
|
1646
1659
|
const { pathname, query } = updateSearchParams(router.asPath, params);
|
|
1647
1660
|
router.replace({ pathname, query });
|
|
1648
1661
|
}
|
|
1649
|
-
function
|
|
1650
|
-
|
|
1651
|
-
|
|
1662
|
+
function historyReplaceState(params) {
|
|
1663
|
+
if (window.history) {
|
|
1664
|
+
const title = document.title;
|
|
1665
|
+
const url = `${window.location.href.split("?")[0]}?${params.toString()}`;
|
|
1666
|
+
window.history.replaceState(params.toString(), title, url);
|
|
1667
|
+
}
|
|
1652
1668
|
}
|
|
1653
1669
|
function replaceSearchParamsSilently(params) {
|
|
1654
1670
|
if (import_bom_core7.isBrowser) {
|
|
1655
1671
|
const searchParams = serialize_(window.location.search, params);
|
|
1656
|
-
|
|
1672
|
+
historyReplaceState(searchParams);
|
|
1657
1673
|
}
|
|
1658
1674
|
}
|
|
1659
1675
|
function useSearchParams() {
|
|
@@ -1664,13 +1680,19 @@ function useSearchParams() {
|
|
|
1664
1680
|
return value;
|
|
1665
1681
|
}, [router.asPath]);
|
|
1666
1682
|
const params = initialValue;
|
|
1667
|
-
const
|
|
1668
|
-
|
|
1683
|
+
const pushParams = (0, import_react31.useCallback)((params2) => {
|
|
1684
|
+
pushSearchParams(router, params2);
|
|
1685
|
+
}, [router]);
|
|
1686
|
+
const pushParamsSilently = (0, import_react31.useCallback)((params2) => {
|
|
1687
|
+
pushSearchParamsSilently(params2);
|
|
1669
1688
|
}, []);
|
|
1670
1689
|
const replaceParams = (0, import_react31.useCallback)((params2) => {
|
|
1671
1690
|
replaceSearchParams(router, params2);
|
|
1672
1691
|
}, [router]);
|
|
1673
|
-
|
|
1692
|
+
const replaceParamsSilently = (0, import_react31.useCallback)((params2) => {
|
|
1693
|
+
replaceSearchParamsSilently(params2);
|
|
1694
|
+
}, []);
|
|
1695
|
+
return { params, pushParams, pushParamsSilently, replaceParams, replaceParamsSilently };
|
|
1674
1696
|
}
|
|
1675
1697
|
function useSearchParamsValue(key) {
|
|
1676
1698
|
const router = (0, import_router.useRouter)();
|
|
@@ -1680,10 +1702,19 @@ function useSearchParamsValue(key) {
|
|
|
1680
1702
|
return value;
|
|
1681
1703
|
}, [key, router.asPath]);
|
|
1682
1704
|
const params = initialValue;
|
|
1705
|
+
const pushParams = (0, import_react31.useCallback)((params2) => {
|
|
1706
|
+
pushSearchParams(router, params2);
|
|
1707
|
+
}, [router]);
|
|
1708
|
+
const pushParamsSilently = (0, import_react31.useCallback)((params2) => {
|
|
1709
|
+
pushSearchParamsSilently(params2);
|
|
1710
|
+
}, []);
|
|
1711
|
+
const replaceParams = (0, import_react31.useCallback)((params2) => {
|
|
1712
|
+
replaceSearchParams(router, params2);
|
|
1713
|
+
}, [router]);
|
|
1683
1714
|
const replaceParamsSilently = (0, import_react31.useCallback)((params2) => {
|
|
1684
1715
|
replaceSearchParamsSilently(params2);
|
|
1685
1716
|
}, []);
|
|
1686
|
-
return { params, replaceParamsSilently };
|
|
1717
|
+
return { params, pushParams, pushParamsSilently, replaceParams, replaceParamsSilently };
|
|
1687
1718
|
}
|
|
1688
1719
|
|
|
1689
1720
|
// src/useSearchParamsEncoded/useSearchParamsEncoded.ts
|
|
@@ -1691,16 +1722,6 @@ var import_bom_core8 = require("@websolutespa/bom-core");
|
|
|
1691
1722
|
var import_router2 = require("next/router");
|
|
1692
1723
|
var import_react32 = require("react");
|
|
1693
1724
|
var USE_ENCRYPTION = true;
|
|
1694
|
-
function base64ToString(base64) {
|
|
1695
|
-
if (!USE_ENCRYPTION)
|
|
1696
|
-
return base64;
|
|
1697
|
-
return import_bom_core8.isBrowser ? window.atob(base64) : Buffer.from(base64, "base64").toString();
|
|
1698
|
-
}
|
|
1699
|
-
function stringToBase64(text) {
|
|
1700
|
-
if (!USE_ENCRYPTION)
|
|
1701
|
-
return text;
|
|
1702
|
-
return import_bom_core8.isBrowser ? window.btoa(text) : Buffer.from(text).toString("base64");
|
|
1703
|
-
}
|
|
1704
1725
|
function stringToURLSearchParams(url) {
|
|
1705
1726
|
return new URLSearchParams(url);
|
|
1706
1727
|
}
|
|
@@ -1717,13 +1738,6 @@ function setURLSearchParams(url, keyOrValue, value) {
|
|
|
1717
1738
|
}
|
|
1718
1739
|
return params;
|
|
1719
1740
|
}
|
|
1720
|
-
function replace_2(params) {
|
|
1721
|
-
if (window.history) {
|
|
1722
|
-
const title = document.title;
|
|
1723
|
-
const url = `${window.location.href.split("?")[0]}?${params.toString()}`;
|
|
1724
|
-
window.history.replaceState(params.toString(), title, url);
|
|
1725
|
-
}
|
|
1726
|
-
}
|
|
1727
1741
|
function deserialize_2(url, key) {
|
|
1728
1742
|
const encoded = getURLSearchParams(url, "params");
|
|
1729
1743
|
return decode(encoded, key);
|
|
@@ -1736,7 +1750,7 @@ function serialize_2(url, value, key) {
|
|
|
1736
1750
|
function decode(encoded, key) {
|
|
1737
1751
|
let decoded = null;
|
|
1738
1752
|
if (encoded) {
|
|
1739
|
-
const json = base64ToString(encoded);
|
|
1753
|
+
const json = USE_ENCRYPTION ? (0, import_bom_core8.base64ToString)(encoded) : encoded;
|
|
1740
1754
|
decoded = JSON.parse(json);
|
|
1741
1755
|
}
|
|
1742
1756
|
if (key && decoded) {
|
|
@@ -1753,7 +1767,7 @@ function encode(params, value, key) {
|
|
|
1753
1767
|
params = Object.assign(params, value);
|
|
1754
1768
|
}
|
|
1755
1769
|
const json = JSON.stringify(params);
|
|
1756
|
-
encoded = stringToBase64(json);
|
|
1770
|
+
encoded = USE_ENCRYPTION ? (0, import_bom_core8.stringToBase64)(json) : json;
|
|
1757
1771
|
return encoded;
|
|
1758
1772
|
}
|
|
1759
1773
|
function searchParamsToObject_2(params) {
|
|
@@ -1779,18 +1793,38 @@ function updateSearchParamsEncoded(currentPath, value, key) {
|
|
|
1779
1793
|
const pathname = components[0] || "";
|
|
1780
1794
|
return { pathname, query };
|
|
1781
1795
|
}
|
|
1796
|
+
function pushSearchParamsEncoded(router, value, key) {
|
|
1797
|
+
const { pathname, query } = updateSearchParamsEncoded(router.asPath, value, key);
|
|
1798
|
+
router.push({ pathname, query });
|
|
1799
|
+
}
|
|
1800
|
+
function historyPushState2(params) {
|
|
1801
|
+
if (window.history) {
|
|
1802
|
+
const title = document.title;
|
|
1803
|
+
const url = `${window.location.href.split("?")[0]}?${params.toString()}`;
|
|
1804
|
+
window.history.pushState(params.toString(), title, url);
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
function pushSearchParamsEncodedSilently(value, key) {
|
|
1808
|
+
if (import_bom_core8.isBrowser) {
|
|
1809
|
+
const searchParams = serialize_2(window.location.search, value, key);
|
|
1810
|
+
historyPushState2(searchParams);
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1782
1813
|
function replaceSearchParamsEncoded(router, value, key) {
|
|
1783
1814
|
const { pathname, query } = updateSearchParamsEncoded(router.asPath, value, key);
|
|
1784
1815
|
router.replace({ pathname, query });
|
|
1785
1816
|
}
|
|
1786
|
-
function
|
|
1787
|
-
|
|
1788
|
-
|
|
1817
|
+
function historyReplaceState2(params) {
|
|
1818
|
+
if (window.history) {
|
|
1819
|
+
const title = document.title;
|
|
1820
|
+
const url = `${window.location.href.split("?")[0]}?${params.toString()}`;
|
|
1821
|
+
window.history.replaceState(params.toString(), title, url);
|
|
1822
|
+
}
|
|
1789
1823
|
}
|
|
1790
1824
|
function replaceSearchParamsEncodedSilently(value, key) {
|
|
1791
1825
|
if (import_bom_core8.isBrowser) {
|
|
1792
1826
|
const searchParams = serialize_2(window.location.search, value, key);
|
|
1793
|
-
|
|
1827
|
+
historyReplaceState2(searchParams);
|
|
1794
1828
|
}
|
|
1795
1829
|
}
|
|
1796
1830
|
function useSearchParamsEncoded(key) {
|
|
@@ -1800,26 +1834,25 @@ function useSearchParamsEncoded(key) {
|
|
|
1800
1834
|
return value;
|
|
1801
1835
|
}, [key, router.asPath]);
|
|
1802
1836
|
const params = initialValue;
|
|
1803
|
-
const
|
|
1804
|
-
|
|
1837
|
+
const pushParams = (0, import_react32.useCallback)((params2) => {
|
|
1838
|
+
pushSearchParamsEncoded(router, params2, key);
|
|
1839
|
+
}, [key, router]);
|
|
1840
|
+
const pushParamsSilently = (0, import_react32.useCallback)((params2) => {
|
|
1841
|
+
pushSearchParamsEncodedSilently(params2, key);
|
|
1805
1842
|
}, [key]);
|
|
1806
1843
|
const replaceParams = (0, import_react32.useCallback)((params2) => {
|
|
1807
1844
|
replaceSearchParamsEncoded(router, params2, key);
|
|
1808
1845
|
}, [key, router]);
|
|
1809
|
-
|
|
1846
|
+
const replaceParamsSilently = (0, import_react32.useCallback)((params2) => {
|
|
1847
|
+
replaceSearchParamsEncodedSilently(params2, key);
|
|
1848
|
+
}, [key]);
|
|
1849
|
+
return { params, pushParams, pushParamsSilently, replaceParams, replaceParamsSilently };
|
|
1810
1850
|
}
|
|
1811
1851
|
|
|
1812
1852
|
// src/useSearchParamsQs/useSearchParamsQs.ts
|
|
1813
1853
|
var import_bom_core9 = require("@websolutespa/bom-core");
|
|
1814
1854
|
var import_router3 = require("next/router");
|
|
1815
1855
|
var import_react33 = require("react");
|
|
1816
|
-
function replace(search) {
|
|
1817
|
-
if (window.history) {
|
|
1818
|
-
const title = document.title;
|
|
1819
|
-
const url = `${window.location.href.split("?")[0]}?${search}`;
|
|
1820
|
-
window.history.replaceState(search, title, url);
|
|
1821
|
-
}
|
|
1822
|
-
}
|
|
1823
1856
|
function deserialize(encoded, key) {
|
|
1824
1857
|
let decoded = {};
|
|
1825
1858
|
if (encoded) {
|
|
@@ -1862,18 +1895,38 @@ function updateSearchParamsQs(url, value, key) {
|
|
|
1862
1895
|
const { search, params } = serialize(components.search, value, key);
|
|
1863
1896
|
return { pathname: components.pathname, query: search };
|
|
1864
1897
|
}
|
|
1898
|
+
function pushSearchParamsQs(router, value, key) {
|
|
1899
|
+
const { pathname, query } = updateSearchParamsQs(router.asPath, value, key);
|
|
1900
|
+
router.push({ pathname, query });
|
|
1901
|
+
}
|
|
1902
|
+
function historyPushState3(search) {
|
|
1903
|
+
if (window.history) {
|
|
1904
|
+
const title = document.title;
|
|
1905
|
+
const url = `${window.location.href.split("?")[0]}?${search}`;
|
|
1906
|
+
window.history.pushState(search, title, url);
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
function pushSearchParamsQsSilently(value, key) {
|
|
1910
|
+
if (import_bom_core9.isBrowser) {
|
|
1911
|
+
const { search } = serialize(window.location.search, value, key);
|
|
1912
|
+
historyPushState3(search);
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1865
1915
|
function replaceSearchParamsQs(router, value, key) {
|
|
1866
1916
|
const { pathname, query } = updateSearchParamsQs(router.asPath, value, key);
|
|
1867
1917
|
router.replace({ pathname, query });
|
|
1868
1918
|
}
|
|
1869
|
-
function
|
|
1870
|
-
|
|
1871
|
-
|
|
1919
|
+
function historyReplaceState3(search) {
|
|
1920
|
+
if (window.history) {
|
|
1921
|
+
const title = document.title;
|
|
1922
|
+
const url = `${window.location.href.split("?")[0]}?${search}`;
|
|
1923
|
+
window.history.replaceState(search, title, url);
|
|
1924
|
+
}
|
|
1872
1925
|
}
|
|
1873
1926
|
function replaceSearchParamsQsSilently(value, key) {
|
|
1874
1927
|
if (import_bom_core9.isBrowser) {
|
|
1875
1928
|
const { search } = serialize(window.location.search, value, key);
|
|
1876
|
-
|
|
1929
|
+
historyReplaceState3(search);
|
|
1877
1930
|
}
|
|
1878
1931
|
}
|
|
1879
1932
|
function useSearchParamsQs(key) {
|
|
@@ -1883,13 +1936,19 @@ function useSearchParamsQs(key) {
|
|
|
1883
1936
|
return value;
|
|
1884
1937
|
}, [key, router.asPath]);
|
|
1885
1938
|
const params = initialValue;
|
|
1886
|
-
const
|
|
1887
|
-
|
|
1939
|
+
const pushParams = (0, import_react33.useCallback)((params2) => {
|
|
1940
|
+
pushSearchParamsQs(router, params2, key);
|
|
1941
|
+
}, [key, router]);
|
|
1942
|
+
const pushParamsSilently = (0, import_react33.useCallback)((params2) => {
|
|
1943
|
+
pushSearchParamsQsSilently(params2, key);
|
|
1888
1944
|
}, [key]);
|
|
1889
1945
|
const replaceParams = (0, import_react33.useCallback)((params2) => {
|
|
1890
1946
|
replaceSearchParamsQs(router, params2, key);
|
|
1891
1947
|
}, [key, router]);
|
|
1892
|
-
|
|
1948
|
+
const replaceParamsSilently = (0, import_react33.useCallback)((params2) => {
|
|
1949
|
+
replaceSearchParamsQsSilently(params2, key);
|
|
1950
|
+
}, [key]);
|
|
1951
|
+
return { params, pushParamsSilently, pushParams, replaceParamsSilently, replaceParams };
|
|
1893
1952
|
}
|
|
1894
1953
|
|
|
1895
1954
|
// src/useSorting/useSorting.ts
|
|
@@ -1979,7 +2038,10 @@ function useUnmountEffect(effect) {
|
|
|
1979
2038
|
parseParams,
|
|
1980
2039
|
pushSearchParams,
|
|
1981
2040
|
pushSearchParamsEncoded,
|
|
2041
|
+
pushSearchParamsEncodedSilently,
|
|
1982
2042
|
pushSearchParamsQs,
|
|
2043
|
+
pushSearchParamsQsSilently,
|
|
2044
|
+
pushSearchParamsSilently,
|
|
1983
2045
|
replaceSearchParams,
|
|
1984
2046
|
replaceSearchParamsEncoded,
|
|
1985
2047
|
replaceSearchParamsEncodedSilently,
|
package/dist/index.mjs
CHANGED
|
@@ -1465,13 +1465,6 @@ function useScrolled(callback = DEFAULT_CALLBACK) {
|
|
|
1465
1465
|
import { isBrowser as isBrowser3 } from "@websolutespa/bom-core";
|
|
1466
1466
|
import { useRouter } from "next/router";
|
|
1467
1467
|
import { useCallback as useCallback5, useMemo as useMemo5 } from "react";
|
|
1468
|
-
function replace_(params) {
|
|
1469
|
-
if (window.history) {
|
|
1470
|
-
const title = document.title;
|
|
1471
|
-
const url = `${window.location.href.split("?")[0]}?${params.toString()}`;
|
|
1472
|
-
window.history.replaceState(params.toString(), title, url);
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
1468
|
function deserialize_(url) {
|
|
1476
1469
|
const components = url.split("?");
|
|
1477
1470
|
const search = components[1] || "";
|
|
@@ -1506,18 +1499,38 @@ function updateSearchParams(currentPath, params) {
|
|
|
1506
1499
|
const pathname = components[0] || "";
|
|
1507
1500
|
return { pathname, query };
|
|
1508
1501
|
}
|
|
1502
|
+
function pushSearchParams(router, params) {
|
|
1503
|
+
const { pathname, query } = updateSearchParams(router.asPath, params);
|
|
1504
|
+
router.push({ pathname, query });
|
|
1505
|
+
}
|
|
1506
|
+
function historyPushState(params) {
|
|
1507
|
+
if (window.history) {
|
|
1508
|
+
const title = document.title;
|
|
1509
|
+
const url = `${window.location.href.split("?")[0]}?${params.toString()}`;
|
|
1510
|
+
window.history.pushState(params.toString(), title, url);
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
function pushSearchParamsSilently(params) {
|
|
1514
|
+
if (isBrowser3) {
|
|
1515
|
+
const searchParams = serialize_(window.location.search, params);
|
|
1516
|
+
historyPushState(searchParams);
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1509
1519
|
function replaceSearchParams(router, params) {
|
|
1510
1520
|
const { pathname, query } = updateSearchParams(router.asPath, params);
|
|
1511
1521
|
router.replace({ pathname, query });
|
|
1512
1522
|
}
|
|
1513
|
-
function
|
|
1514
|
-
|
|
1515
|
-
|
|
1523
|
+
function historyReplaceState(params) {
|
|
1524
|
+
if (window.history) {
|
|
1525
|
+
const title = document.title;
|
|
1526
|
+
const url = `${window.location.href.split("?")[0]}?${params.toString()}`;
|
|
1527
|
+
window.history.replaceState(params.toString(), title, url);
|
|
1528
|
+
}
|
|
1516
1529
|
}
|
|
1517
1530
|
function replaceSearchParamsSilently(params) {
|
|
1518
1531
|
if (isBrowser3) {
|
|
1519
1532
|
const searchParams = serialize_(window.location.search, params);
|
|
1520
|
-
|
|
1533
|
+
historyReplaceState(searchParams);
|
|
1521
1534
|
}
|
|
1522
1535
|
}
|
|
1523
1536
|
function useSearchParams() {
|
|
@@ -1528,13 +1541,19 @@ function useSearchParams() {
|
|
|
1528
1541
|
return value;
|
|
1529
1542
|
}, [router.asPath]);
|
|
1530
1543
|
const params = initialValue;
|
|
1531
|
-
const
|
|
1532
|
-
|
|
1544
|
+
const pushParams = useCallback5((params2) => {
|
|
1545
|
+
pushSearchParams(router, params2);
|
|
1546
|
+
}, [router]);
|
|
1547
|
+
const pushParamsSilently = useCallback5((params2) => {
|
|
1548
|
+
pushSearchParamsSilently(params2);
|
|
1533
1549
|
}, []);
|
|
1534
1550
|
const replaceParams = useCallback5((params2) => {
|
|
1535
1551
|
replaceSearchParams(router, params2);
|
|
1536
1552
|
}, [router]);
|
|
1537
|
-
|
|
1553
|
+
const replaceParamsSilently = useCallback5((params2) => {
|
|
1554
|
+
replaceSearchParamsSilently(params2);
|
|
1555
|
+
}, []);
|
|
1556
|
+
return { params, pushParams, pushParamsSilently, replaceParams, replaceParamsSilently };
|
|
1538
1557
|
}
|
|
1539
1558
|
function useSearchParamsValue(key) {
|
|
1540
1559
|
const router = useRouter();
|
|
@@ -1544,27 +1563,26 @@ function useSearchParamsValue(key) {
|
|
|
1544
1563
|
return value;
|
|
1545
1564
|
}, [key, router.asPath]);
|
|
1546
1565
|
const params = initialValue;
|
|
1566
|
+
const pushParams = useCallback5((params2) => {
|
|
1567
|
+
pushSearchParams(router, params2);
|
|
1568
|
+
}, [router]);
|
|
1569
|
+
const pushParamsSilently = useCallback5((params2) => {
|
|
1570
|
+
pushSearchParamsSilently(params2);
|
|
1571
|
+
}, []);
|
|
1572
|
+
const replaceParams = useCallback5((params2) => {
|
|
1573
|
+
replaceSearchParams(router, params2);
|
|
1574
|
+
}, [router]);
|
|
1547
1575
|
const replaceParamsSilently = useCallback5((params2) => {
|
|
1548
1576
|
replaceSearchParamsSilently(params2);
|
|
1549
1577
|
}, []);
|
|
1550
|
-
return { params, replaceParamsSilently };
|
|
1578
|
+
return { params, pushParams, pushParamsSilently, replaceParams, replaceParamsSilently };
|
|
1551
1579
|
}
|
|
1552
1580
|
|
|
1553
1581
|
// src/useSearchParamsEncoded/useSearchParamsEncoded.ts
|
|
1554
|
-
import { isBrowser as isBrowser4 } from "@websolutespa/bom-core";
|
|
1582
|
+
import { base64ToString, isBrowser as isBrowser4, stringToBase64 } from "@websolutespa/bom-core";
|
|
1555
1583
|
import { useRouter as useRouter2 } from "next/router";
|
|
1556
1584
|
import { useCallback as useCallback6, useMemo as useMemo6 } from "react";
|
|
1557
1585
|
var USE_ENCRYPTION = true;
|
|
1558
|
-
function base64ToString(base64) {
|
|
1559
|
-
if (!USE_ENCRYPTION)
|
|
1560
|
-
return base64;
|
|
1561
|
-
return isBrowser4 ? window.atob(base64) : Buffer.from(base64, "base64").toString();
|
|
1562
|
-
}
|
|
1563
|
-
function stringToBase64(text) {
|
|
1564
|
-
if (!USE_ENCRYPTION)
|
|
1565
|
-
return text;
|
|
1566
|
-
return isBrowser4 ? window.btoa(text) : Buffer.from(text).toString("base64");
|
|
1567
|
-
}
|
|
1568
1586
|
function stringToURLSearchParams(url) {
|
|
1569
1587
|
return new URLSearchParams(url);
|
|
1570
1588
|
}
|
|
@@ -1581,13 +1599,6 @@ function setURLSearchParams(url, keyOrValue, value) {
|
|
|
1581
1599
|
}
|
|
1582
1600
|
return params;
|
|
1583
1601
|
}
|
|
1584
|
-
function replace_2(params) {
|
|
1585
|
-
if (window.history) {
|
|
1586
|
-
const title = document.title;
|
|
1587
|
-
const url = `${window.location.href.split("?")[0]}?${params.toString()}`;
|
|
1588
|
-
window.history.replaceState(params.toString(), title, url);
|
|
1589
|
-
}
|
|
1590
|
-
}
|
|
1591
1602
|
function deserialize_2(url, key) {
|
|
1592
1603
|
const encoded = getURLSearchParams(url, "params");
|
|
1593
1604
|
return decode(encoded, key);
|
|
@@ -1600,7 +1611,7 @@ function serialize_2(url, value, key) {
|
|
|
1600
1611
|
function decode(encoded, key) {
|
|
1601
1612
|
let decoded = null;
|
|
1602
1613
|
if (encoded) {
|
|
1603
|
-
const json = base64ToString(encoded);
|
|
1614
|
+
const json = USE_ENCRYPTION ? base64ToString(encoded) : encoded;
|
|
1604
1615
|
decoded = JSON.parse(json);
|
|
1605
1616
|
}
|
|
1606
1617
|
if (key && decoded) {
|
|
@@ -1617,7 +1628,7 @@ function encode(params, value, key) {
|
|
|
1617
1628
|
params = Object.assign(params, value);
|
|
1618
1629
|
}
|
|
1619
1630
|
const json = JSON.stringify(params);
|
|
1620
|
-
encoded = stringToBase64(json);
|
|
1631
|
+
encoded = USE_ENCRYPTION ? stringToBase64(json) : json;
|
|
1621
1632
|
return encoded;
|
|
1622
1633
|
}
|
|
1623
1634
|
function searchParamsToObject_2(params) {
|
|
@@ -1643,18 +1654,38 @@ function updateSearchParamsEncoded(currentPath, value, key) {
|
|
|
1643
1654
|
const pathname = components[0] || "";
|
|
1644
1655
|
return { pathname, query };
|
|
1645
1656
|
}
|
|
1657
|
+
function pushSearchParamsEncoded(router, value, key) {
|
|
1658
|
+
const { pathname, query } = updateSearchParamsEncoded(router.asPath, value, key);
|
|
1659
|
+
router.push({ pathname, query });
|
|
1660
|
+
}
|
|
1661
|
+
function historyPushState2(params) {
|
|
1662
|
+
if (window.history) {
|
|
1663
|
+
const title = document.title;
|
|
1664
|
+
const url = `${window.location.href.split("?")[0]}?${params.toString()}`;
|
|
1665
|
+
window.history.pushState(params.toString(), title, url);
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
function pushSearchParamsEncodedSilently(value, key) {
|
|
1669
|
+
if (isBrowser4) {
|
|
1670
|
+
const searchParams = serialize_2(window.location.search, value, key);
|
|
1671
|
+
historyPushState2(searchParams);
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1646
1674
|
function replaceSearchParamsEncoded(router, value, key) {
|
|
1647
1675
|
const { pathname, query } = updateSearchParamsEncoded(router.asPath, value, key);
|
|
1648
1676
|
router.replace({ pathname, query });
|
|
1649
1677
|
}
|
|
1650
|
-
function
|
|
1651
|
-
|
|
1652
|
-
|
|
1678
|
+
function historyReplaceState2(params) {
|
|
1679
|
+
if (window.history) {
|
|
1680
|
+
const title = document.title;
|
|
1681
|
+
const url = `${window.location.href.split("?")[0]}?${params.toString()}`;
|
|
1682
|
+
window.history.replaceState(params.toString(), title, url);
|
|
1683
|
+
}
|
|
1653
1684
|
}
|
|
1654
1685
|
function replaceSearchParamsEncodedSilently(value, key) {
|
|
1655
1686
|
if (isBrowser4) {
|
|
1656
1687
|
const searchParams = serialize_2(window.location.search, value, key);
|
|
1657
|
-
|
|
1688
|
+
historyReplaceState2(searchParams);
|
|
1658
1689
|
}
|
|
1659
1690
|
}
|
|
1660
1691
|
function useSearchParamsEncoded(key) {
|
|
@@ -1664,26 +1695,25 @@ function useSearchParamsEncoded(key) {
|
|
|
1664
1695
|
return value;
|
|
1665
1696
|
}, [key, router.asPath]);
|
|
1666
1697
|
const params = initialValue;
|
|
1667
|
-
const
|
|
1668
|
-
|
|
1698
|
+
const pushParams = useCallback6((params2) => {
|
|
1699
|
+
pushSearchParamsEncoded(router, params2, key);
|
|
1700
|
+
}, [key, router]);
|
|
1701
|
+
const pushParamsSilently = useCallback6((params2) => {
|
|
1702
|
+
pushSearchParamsEncodedSilently(params2, key);
|
|
1669
1703
|
}, [key]);
|
|
1670
1704
|
const replaceParams = useCallback6((params2) => {
|
|
1671
1705
|
replaceSearchParamsEncoded(router, params2, key);
|
|
1672
1706
|
}, [key, router]);
|
|
1673
|
-
|
|
1707
|
+
const replaceParamsSilently = useCallback6((params2) => {
|
|
1708
|
+
replaceSearchParamsEncodedSilently(params2, key);
|
|
1709
|
+
}, [key]);
|
|
1710
|
+
return { params, pushParams, pushParamsSilently, replaceParams, replaceParamsSilently };
|
|
1674
1711
|
}
|
|
1675
1712
|
|
|
1676
1713
|
// src/useSearchParamsQs/useSearchParamsQs.ts
|
|
1677
1714
|
import { isBrowser as isBrowser5, qsDeserializeRaw, qsSerializeRaw } from "@websolutespa/bom-core";
|
|
1678
1715
|
import { useRouter as useRouter3 } from "next/router";
|
|
1679
1716
|
import { useCallback as useCallback7, useMemo as useMemo7 } from "react";
|
|
1680
|
-
function replace(search) {
|
|
1681
|
-
if (window.history) {
|
|
1682
|
-
const title = document.title;
|
|
1683
|
-
const url = `${window.location.href.split("?")[0]}?${search}`;
|
|
1684
|
-
window.history.replaceState(search, title, url);
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
1717
|
function deserialize(encoded, key) {
|
|
1688
1718
|
let decoded = {};
|
|
1689
1719
|
if (encoded) {
|
|
@@ -1726,18 +1756,38 @@ function updateSearchParamsQs(url, value, key) {
|
|
|
1726
1756
|
const { search, params } = serialize(components.search, value, key);
|
|
1727
1757
|
return { pathname: components.pathname, query: search };
|
|
1728
1758
|
}
|
|
1759
|
+
function pushSearchParamsQs(router, value, key) {
|
|
1760
|
+
const { pathname, query } = updateSearchParamsQs(router.asPath, value, key);
|
|
1761
|
+
router.push({ pathname, query });
|
|
1762
|
+
}
|
|
1763
|
+
function historyPushState3(search) {
|
|
1764
|
+
if (window.history) {
|
|
1765
|
+
const title = document.title;
|
|
1766
|
+
const url = `${window.location.href.split("?")[0]}?${search}`;
|
|
1767
|
+
window.history.pushState(search, title, url);
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
function pushSearchParamsQsSilently(value, key) {
|
|
1771
|
+
if (isBrowser5) {
|
|
1772
|
+
const { search } = serialize(window.location.search, value, key);
|
|
1773
|
+
historyPushState3(search);
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1729
1776
|
function replaceSearchParamsQs(router, value, key) {
|
|
1730
1777
|
const { pathname, query } = updateSearchParamsQs(router.asPath, value, key);
|
|
1731
1778
|
router.replace({ pathname, query });
|
|
1732
1779
|
}
|
|
1733
|
-
function
|
|
1734
|
-
|
|
1735
|
-
|
|
1780
|
+
function historyReplaceState3(search) {
|
|
1781
|
+
if (window.history) {
|
|
1782
|
+
const title = document.title;
|
|
1783
|
+
const url = `${window.location.href.split("?")[0]}?${search}`;
|
|
1784
|
+
window.history.replaceState(search, title, url);
|
|
1785
|
+
}
|
|
1736
1786
|
}
|
|
1737
1787
|
function replaceSearchParamsQsSilently(value, key) {
|
|
1738
1788
|
if (isBrowser5) {
|
|
1739
1789
|
const { search } = serialize(window.location.search, value, key);
|
|
1740
|
-
|
|
1790
|
+
historyReplaceState3(search);
|
|
1741
1791
|
}
|
|
1742
1792
|
}
|
|
1743
1793
|
function useSearchParamsQs(key) {
|
|
@@ -1747,13 +1797,19 @@ function useSearchParamsQs(key) {
|
|
|
1747
1797
|
return value;
|
|
1748
1798
|
}, [key, router.asPath]);
|
|
1749
1799
|
const params = initialValue;
|
|
1750
|
-
const
|
|
1751
|
-
|
|
1800
|
+
const pushParams = useCallback7((params2) => {
|
|
1801
|
+
pushSearchParamsQs(router, params2, key);
|
|
1802
|
+
}, [key, router]);
|
|
1803
|
+
const pushParamsSilently = useCallback7((params2) => {
|
|
1804
|
+
pushSearchParamsQsSilently(params2, key);
|
|
1752
1805
|
}, [key]);
|
|
1753
1806
|
const replaceParams = useCallback7((params2) => {
|
|
1754
1807
|
replaceSearchParamsQs(router, params2, key);
|
|
1755
1808
|
}, [key, router]);
|
|
1756
|
-
|
|
1809
|
+
const replaceParamsSilently = useCallback7((params2) => {
|
|
1810
|
+
replaceSearchParamsQsSilently(params2, key);
|
|
1811
|
+
}, [key]);
|
|
1812
|
+
return { params, pushParamsSilently, pushParams, replaceParamsSilently, replaceParams };
|
|
1757
1813
|
}
|
|
1758
1814
|
|
|
1759
1815
|
// src/useSorting/useSorting.ts
|
|
@@ -1842,7 +1898,10 @@ export {
|
|
|
1842
1898
|
parseParams,
|
|
1843
1899
|
pushSearchParams,
|
|
1844
1900
|
pushSearchParamsEncoded,
|
|
1901
|
+
pushSearchParamsEncodedSilently,
|
|
1845
1902
|
pushSearchParamsQs,
|
|
1903
|
+
pushSearchParamsQsSilently,
|
|
1904
|
+
pushSearchParamsSilently,
|
|
1846
1905
|
replaceSearchParams,
|
|
1847
1906
|
replaceSearchParamsEncoded,
|
|
1848
1907
|
replaceSearchParamsEncodedSilently,
|
package/package.json
CHANGED
|
@@ -2,14 +2,6 @@ import { isBrowser } from '@websolutespa/bom-core';
|
|
|
2
2
|
import { NextRouter, useRouter } from 'next/router';
|
|
3
3
|
import { useCallback, useMemo } from 'react';
|
|
4
4
|
|
|
5
|
-
function replace_(params: URLSearchParams) {
|
|
6
|
-
if (window.history) {
|
|
7
|
-
const title = document.title;
|
|
8
|
-
const url = `${window.location.href.split('?')[0]}?${params.toString()}`;
|
|
9
|
-
window.history.replaceState(params.toString(), title, url);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
5
|
function deserialize_(url: string): URLSearchParams {
|
|
14
6
|
const components = url.split('?');
|
|
15
7
|
const search = components[1] || '';
|
|
@@ -51,23 +43,58 @@ export function updateSearchParams(currentPath: string, params: IParams): { path
|
|
|
51
43
|
return { pathname, query };
|
|
52
44
|
}
|
|
53
45
|
|
|
46
|
+
export function pushSearchParams(router: NextRouter, params: IParams): void {
|
|
47
|
+
const { pathname, query } = updateSearchParams(router.asPath, params);
|
|
48
|
+
router.push({ pathname, query });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function historyPushState(params: URLSearchParams) {
|
|
52
|
+
if (window.history) {
|
|
53
|
+
const title = document.title;
|
|
54
|
+
const url = `${window.location.href.split('?')[0]}?${params.toString()}`;
|
|
55
|
+
window.history.pushState(params.toString(), title, url);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function pushSearchParamsSilently(params: IParams): void {
|
|
60
|
+
if (isBrowser) {
|
|
61
|
+
const searchParams = serialize_(window.location.search, params);
|
|
62
|
+
historyPushState(searchParams);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
54
66
|
export function replaceSearchParams(router: NextRouter, params: IParams): void {
|
|
55
67
|
const { pathname, query } = updateSearchParams(router.asPath, params);
|
|
56
68
|
router.replace({ pathname, query });
|
|
57
69
|
}
|
|
58
70
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
71
|
+
function historyReplaceState(params: URLSearchParams) {
|
|
72
|
+
if (window.history) {
|
|
73
|
+
const title = document.title;
|
|
74
|
+
const url = `${window.location.href.split('?')[0]}?${params.toString()}`;
|
|
75
|
+
window.history.replaceState(params.toString(), title, url);
|
|
76
|
+
}
|
|
62
77
|
}
|
|
63
78
|
|
|
64
79
|
export function replaceSearchParamsSilently(params: IParams): void {
|
|
65
80
|
if (isBrowser) {
|
|
66
81
|
const searchParams = serialize_(window.location.search, params);
|
|
67
|
-
|
|
82
|
+
historyReplaceState(searchParams);
|
|
68
83
|
}
|
|
69
84
|
}
|
|
70
85
|
|
|
86
|
+
export type IParams = {
|
|
87
|
+
[key: string]: string;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export type IUseSearchParamsResult = {
|
|
91
|
+
params: IParams;
|
|
92
|
+
pushParams: (params: IParams) => void;
|
|
93
|
+
pushParamsSilently: (params: IParams) => void;
|
|
94
|
+
replaceParams: (params: IParams) => void;
|
|
95
|
+
replaceParamsSilently: (params: IParams) => void;
|
|
96
|
+
};
|
|
97
|
+
|
|
71
98
|
export function useSearchParams(): IUseSearchParamsResult {
|
|
72
99
|
const router = useRouter();
|
|
73
100
|
|
|
@@ -79,31 +106,27 @@ export function useSearchParams(): IUseSearchParamsResult {
|
|
|
79
106
|
|
|
80
107
|
const params = initialValue;
|
|
81
108
|
|
|
82
|
-
const
|
|
83
|
-
|
|
109
|
+
const pushParams = useCallback((params: IParams) => {
|
|
110
|
+
pushSearchParams(router, params);
|
|
111
|
+
}, [router]);
|
|
112
|
+
|
|
113
|
+
const pushParamsSilently = useCallback((params: IParams) => {
|
|
114
|
+
pushSearchParamsSilently(params);
|
|
84
115
|
}, []);
|
|
85
116
|
|
|
86
117
|
const replaceParams = useCallback((params: IParams) => {
|
|
87
118
|
replaceSearchParams(router, params);
|
|
88
119
|
}, [router]);
|
|
89
120
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
export type IParams = {
|
|
94
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
95
|
-
[key: string]: string;
|
|
96
|
-
};
|
|
121
|
+
const replaceParamsSilently = useCallback((params: IParams) => {
|
|
122
|
+
replaceSearchParamsSilently(params);
|
|
123
|
+
}, []);
|
|
97
124
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
replaceParamsSilently: (params: IParams) => void
|
|
101
|
-
};
|
|
125
|
+
return { params, pushParams, pushParamsSilently, replaceParams, replaceParamsSilently };
|
|
126
|
+
}
|
|
102
127
|
|
|
103
|
-
export type
|
|
104
|
-
params:
|
|
105
|
-
replaceParamsSilently: (params: IParams) => void,
|
|
106
|
-
replaceParams: (params: IParams) => void
|
|
128
|
+
export type IUseSearchParamsValueResult = Omit<IUseSearchParamsResult, 'params'> & {
|
|
129
|
+
params: string | null;
|
|
107
130
|
};
|
|
108
131
|
|
|
109
132
|
export function useSearchParamsValue(key: string): IUseSearchParamsValueResult {
|
|
@@ -117,9 +140,21 @@ export function useSearchParamsValue(key: string): IUseSearchParamsValueResult {
|
|
|
117
140
|
|
|
118
141
|
const params = initialValue;
|
|
119
142
|
|
|
143
|
+
const pushParams = useCallback((params: IParams) => {
|
|
144
|
+
pushSearchParams(router, params);
|
|
145
|
+
}, [router]);
|
|
146
|
+
|
|
147
|
+
const pushParamsSilently = useCallback((params: IParams) => {
|
|
148
|
+
pushSearchParamsSilently(params);
|
|
149
|
+
}, []);
|
|
150
|
+
|
|
151
|
+
const replaceParams = useCallback((params: IParams) => {
|
|
152
|
+
replaceSearchParams(router, params);
|
|
153
|
+
}, [router]);
|
|
154
|
+
|
|
120
155
|
const replaceParamsSilently = useCallback((params: IParams) => {
|
|
121
156
|
replaceSearchParamsSilently(params);
|
|
122
157
|
}, []);
|
|
123
158
|
|
|
124
|
-
return { params, replaceParamsSilently };
|
|
159
|
+
return { params, pushParams, pushParamsSilently, replaceParams, replaceParamsSilently };
|
|
125
160
|
}
|
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
import { isBrowser } from '@websolutespa/bom-core';
|
|
1
|
+
import { base64ToString, isBrowser, stringToBase64 } from '@websolutespa/bom-core';
|
|
2
2
|
import { NextRouter, useRouter } from 'next/router';
|
|
3
3
|
import { useCallback, useMemo } from 'react';
|
|
4
4
|
|
|
5
5
|
const USE_ENCRYPTION = true;
|
|
6
6
|
|
|
7
|
-
function base64ToString(base64: string): string {
|
|
8
|
-
if (!USE_ENCRYPTION) return base64;
|
|
9
|
-
return isBrowser ? window.atob(base64) : Buffer.from(base64, 'base64').toString();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function stringToBase64(text: string): string {
|
|
13
|
-
if (!USE_ENCRYPTION) return text;
|
|
14
|
-
return isBrowser ? window.btoa(text) : Buffer.from(text).toString('base64');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
7
|
function stringToURLSearchParams(url: string): URLSearchParams {
|
|
18
8
|
// console.log('stringToURLSearchParams', url);
|
|
19
9
|
return new URLSearchParams(url);
|
|
@@ -40,44 +30,9 @@ function setURLSearchParams(url: string, keyOrValue: string, value: string | nul
|
|
|
40
30
|
}
|
|
41
31
|
return params;
|
|
42
32
|
// push_(params);
|
|
43
|
-
//
|
|
33
|
+
// historyReplaceState(params);
|
|
44
34
|
}
|
|
45
35
|
|
|
46
|
-
/*
|
|
47
|
-
function push_(params: URLSearchParams) {
|
|
48
|
-
if (window.history) {
|
|
49
|
-
const title = document.title;
|
|
50
|
-
const url = `${window.location.href.split('?')[0]}?${params.toString()}`;
|
|
51
|
-
window.history.pushState(params.toString(), title, url);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
function replace_(params: URLSearchParams) {
|
|
57
|
-
if (window.history) {
|
|
58
|
-
const title = document.title;
|
|
59
|
-
const url = `${window.location.href.split('?')[0]}?${params.toString()}`;
|
|
60
|
-
window.history.replaceState(params.toString(), title, url);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/*
|
|
65
|
-
function replace__(from: string, to: string) {
|
|
66
|
-
const history = window.history;
|
|
67
|
-
if (history && history.replaceState) {
|
|
68
|
-
const location = window.location;
|
|
69
|
-
const title = document.title;
|
|
70
|
-
if (location.pathname === '/') {
|
|
71
|
-
const url = location.origin + to + location.search;
|
|
72
|
-
history.replaceState(history.state, title, url);
|
|
73
|
-
} else if (location.href.indexOf(from) !== -1) {
|
|
74
|
-
const url = location.href.replace(from, to);
|
|
75
|
-
history.replaceState(history.state, title, url);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
*/
|
|
80
|
-
|
|
81
36
|
function deserialize_(url: string, key?: string) {
|
|
82
37
|
const encoded = getURLSearchParams(url, 'params');
|
|
83
38
|
return decode(encoded, key);
|
|
@@ -92,7 +47,7 @@ function serialize_(url: string, value: IParamsEncoded, key?: string): URLSearch
|
|
|
92
47
|
function decode(encoded: string | null | undefined, key?: string): IParamsEncoded {
|
|
93
48
|
let decoded = null;
|
|
94
49
|
if (encoded) {
|
|
95
|
-
const json = base64ToString(encoded);
|
|
50
|
+
const json = USE_ENCRYPTION ? base64ToString(encoded) : encoded;
|
|
96
51
|
decoded = JSON.parse(json);
|
|
97
52
|
}
|
|
98
53
|
// console.log('useSearchParamsEncoded.decode', decoded);
|
|
@@ -112,7 +67,7 @@ function encode(params: IParamsEncoded, value: IParamsEncoded, key?: string) {
|
|
|
112
67
|
}
|
|
113
68
|
// console.log('useSearchParamsEncoded.encode', params);
|
|
114
69
|
const json = JSON.stringify(params);
|
|
115
|
-
encoded = stringToBase64(json);
|
|
70
|
+
encoded = USE_ENCRYPTION ? stringToBase64(json) : json;
|
|
116
71
|
return encoded;
|
|
117
72
|
}
|
|
118
73
|
|
|
@@ -144,20 +99,43 @@ export function updateSearchParamsEncoded(currentPath: string, value: IParamsEnc
|
|
|
144
99
|
return { pathname, query };
|
|
145
100
|
}
|
|
146
101
|
|
|
102
|
+
export function pushSearchParamsEncoded(router: NextRouter, value: IParamsEncoded, key?: string): void {
|
|
103
|
+
const { pathname, query } = updateSearchParamsEncoded(router.asPath, value, key);
|
|
104
|
+
router.push({ pathname, query });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function historyPushState(params: URLSearchParams) {
|
|
108
|
+
if (window.history) {
|
|
109
|
+
const title = document.title;
|
|
110
|
+
const url = `${window.location.href.split('?')[0]}?${params.toString()}`;
|
|
111
|
+
window.history.pushState(params.toString(), title, url);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function pushSearchParamsEncodedSilently(value: IParamsEncoded, key?: string): void {
|
|
116
|
+
if (isBrowser) {
|
|
117
|
+
const searchParams = serialize_(window.location.search, value, key);
|
|
118
|
+
historyPushState(searchParams);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
147
122
|
export function replaceSearchParamsEncoded(router: NextRouter, value: IParamsEncoded, key?: string): void {
|
|
148
123
|
const { pathname, query } = updateSearchParamsEncoded(router.asPath, value, key);
|
|
149
124
|
router.replace({ pathname, query });
|
|
150
125
|
}
|
|
151
126
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
127
|
+
function historyReplaceState(params: URLSearchParams) {
|
|
128
|
+
if (window.history) {
|
|
129
|
+
const title = document.title;
|
|
130
|
+
const url = `${window.location.href.split('?')[0]}?${params.toString()}`;
|
|
131
|
+
window.history.replaceState(params.toString(), title, url);
|
|
132
|
+
}
|
|
155
133
|
}
|
|
156
134
|
|
|
157
135
|
export function replaceSearchParamsEncodedSilently(value: IParamsEncoded, key?: string): void {
|
|
158
136
|
if (isBrowser) {
|
|
159
137
|
const searchParams = serialize_(window.location.search, value, key);
|
|
160
|
-
|
|
138
|
+
historyReplaceState(searchParams);
|
|
161
139
|
}
|
|
162
140
|
}
|
|
163
141
|
|
|
@@ -167,9 +145,11 @@ export type IParamsEncoded = {
|
|
|
167
145
|
} | null;
|
|
168
146
|
|
|
169
147
|
export type IUseSearchParamsEncodedResult = {
|
|
170
|
-
params: IParamsEncoded
|
|
171
|
-
|
|
172
|
-
|
|
148
|
+
params: IParamsEncoded;
|
|
149
|
+
pushParams: (params: IParamsEncoded) => void;
|
|
150
|
+
pushParamsSilently: (params: IParamsEncoded) => void;
|
|
151
|
+
replaceParams: (params: IParamsEncoded) => void;
|
|
152
|
+
replaceParamsSilently: (params: IParamsEncoded) => void;
|
|
173
153
|
};
|
|
174
154
|
|
|
175
155
|
export function useSearchParamsEncoded(key?: string): IUseSearchParamsEncodedResult {
|
|
@@ -181,22 +161,22 @@ export function useSearchParamsEncoded(key?: string): IUseSearchParamsEncodedRes
|
|
|
181
161
|
}, [key, router.asPath]);
|
|
182
162
|
|
|
183
163
|
const params = initialValue;
|
|
184
|
-
// console.log('useSearchParamsEncoded', params);
|
|
185
|
-
// const [params, setParams_] = useState(initialValue);
|
|
186
164
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
replaceSearchParamsEncoded(router, params, key);
|
|
165
|
+
const pushParams = useCallback((params: IParamsEncoded) => {
|
|
166
|
+
pushSearchParamsEncoded(router, params, key);
|
|
190
167
|
}, [key, router]);
|
|
191
|
-
*/
|
|
192
168
|
|
|
193
|
-
const
|
|
194
|
-
|
|
169
|
+
const pushParamsSilently = useCallback((params: IParamsEncoded) => {
|
|
170
|
+
pushSearchParamsEncodedSilently(params, key);
|
|
195
171
|
}, [key]);
|
|
196
172
|
|
|
197
173
|
const replaceParams = useCallback((params: IParamsEncoded) => {
|
|
198
174
|
replaceSearchParamsEncoded(router, params, key);
|
|
199
175
|
}, [key, router]);
|
|
200
176
|
|
|
201
|
-
|
|
177
|
+
const replaceParamsSilently = useCallback((params: IParamsEncoded) => {
|
|
178
|
+
replaceSearchParamsEncodedSilently(params, key);
|
|
179
|
+
}, [key]);
|
|
180
|
+
|
|
181
|
+
return { params, pushParams, pushParamsSilently, replaceParams, replaceParamsSilently };
|
|
202
182
|
}
|
|
@@ -6,18 +6,12 @@ export type IParamsQs = Record<string, any>;
|
|
|
6
6
|
|
|
7
7
|
export type IUseSearchParamsQsResult = {
|
|
8
8
|
params: IParamsQs,
|
|
9
|
-
|
|
9
|
+
pushParams: (params: IParamsQs) => void
|
|
10
|
+
pushParamsSilently: (params: IParamsQs) => void,
|
|
10
11
|
replaceParams: (params: IParamsQs) => void
|
|
12
|
+
replaceParamsSilently: (params: IParamsQs) => void,
|
|
11
13
|
};
|
|
12
14
|
|
|
13
|
-
function replace(search: string) {
|
|
14
|
-
if (window.history) {
|
|
15
|
-
const title = document.title;
|
|
16
|
-
const url = `${window.location.href.split('?')[0]}?${search}`;
|
|
17
|
-
window.history.replaceState(search, title, url);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
15
|
function deserialize(encoded: string | null | undefined, key?: string): IParamsQs {
|
|
22
16
|
let decoded = {};
|
|
23
17
|
if (encoded) {
|
|
@@ -67,20 +61,43 @@ export function updateSearchParamsQs(url: string, value: IParamsQs, key?: string
|
|
|
67
61
|
return { pathname: components.pathname, query: search };
|
|
68
62
|
}
|
|
69
63
|
|
|
64
|
+
export function pushSearchParamsQs(router: NextRouter, value: IParamsQs, key?: string): void {
|
|
65
|
+
const { pathname, query } = updateSearchParamsQs(router.asPath, value, key);
|
|
66
|
+
router.push({ pathname, query });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function historyPushState(search: string) {
|
|
70
|
+
if (window.history) {
|
|
71
|
+
const title = document.title;
|
|
72
|
+
const url = `${window.location.href.split('?')[0]}?${search}`;
|
|
73
|
+
window.history.pushState(search, title, url);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function pushSearchParamsQsSilently(value: IParamsQs, key?: string): void {
|
|
78
|
+
if (isBrowser) {
|
|
79
|
+
const { search } = serialize(window.location.search, value, key);
|
|
80
|
+
historyPushState(search);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
70
84
|
export function replaceSearchParamsQs(router: NextRouter, value: IParamsQs, key?: string): void {
|
|
71
85
|
const { pathname, query } = updateSearchParamsQs(router.asPath, value, key);
|
|
72
86
|
router.replace({ pathname, query });
|
|
73
87
|
}
|
|
74
88
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
89
|
+
function historyReplaceState(search: string) {
|
|
90
|
+
if (window.history) {
|
|
91
|
+
const title = document.title;
|
|
92
|
+
const url = `${window.location.href.split('?')[0]}?${search}`;
|
|
93
|
+
window.history.replaceState(search, title, url);
|
|
94
|
+
}
|
|
78
95
|
}
|
|
79
96
|
|
|
80
97
|
export function replaceSearchParamsQsSilently(value: IParamsQs, key?: string): void {
|
|
81
98
|
if (isBrowser) {
|
|
82
99
|
const { search } = serialize(window.location.search, value, key);
|
|
83
|
-
|
|
100
|
+
historyReplaceState(search);
|
|
84
101
|
}
|
|
85
102
|
}
|
|
86
103
|
|
|
@@ -94,13 +111,21 @@ export function useSearchParamsQs(key?: string): IUseSearchParamsQsResult {
|
|
|
94
111
|
|
|
95
112
|
const params = initialValue;
|
|
96
113
|
|
|
97
|
-
const
|
|
98
|
-
|
|
114
|
+
const pushParams = useCallback((params: IParamsQs) => {
|
|
115
|
+
pushSearchParamsQs(router, params, key);
|
|
116
|
+
}, [key, router]);
|
|
117
|
+
|
|
118
|
+
const pushParamsSilently = useCallback((params: IParamsQs) => {
|
|
119
|
+
pushSearchParamsQsSilently(params, key);
|
|
99
120
|
}, [key]);
|
|
100
121
|
|
|
101
122
|
const replaceParams = useCallback((params: IParamsQs) => {
|
|
102
123
|
replaceSearchParamsQs(router, params, key);
|
|
103
124
|
}, [key, router]);
|
|
104
125
|
|
|
105
|
-
|
|
126
|
+
const replaceParamsSilently = useCallback((params: IParamsQs) => {
|
|
127
|
+
replaceSearchParamsQsSilently(params, key);
|
|
128
|
+
}, [key]);
|
|
129
|
+
|
|
130
|
+
return { params, pushParamsSilently, pushParams, replaceParamsSilently, replaceParams };
|
|
106
131
|
}
|