@websolutespa/bom-mixer-hooks 1.8.3 → 1.8.5
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 +12 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +19 -10
- package/dist/index.mjs +19 -10
- package/package.json +1 -1
- package/src/usePageLoading/usePageLoading.ts +22 -6
- package/src/useSearchParams/useSearchParams.ts +2 -2
- package/src/useSearchParamsQs/useSearchParamsQs.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @websolutespa/bom-mixer-hooks
|
|
2
2
|
|
|
3
|
+
## 1.8.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Modified: useSearchParams, useSearchParamsEncoded, useSearchParamsQs scroll false
|
|
8
|
+
|
|
9
|
+
## 1.8.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Modified: usePageLoading, shallow routes do not fire loading state
|
|
14
|
+
|
|
3
15
|
## 1.8.3
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -396,6 +396,9 @@ declare function PageProvider({ children, page }: {
|
|
|
396
396
|
page: IPage;
|
|
397
397
|
}): react_jsx_runtime.JSX.Element;
|
|
398
398
|
|
|
399
|
+
type IPageRouteOptions = {
|
|
400
|
+
shallow: boolean;
|
|
401
|
+
};
|
|
399
402
|
type IPageRoute = {
|
|
400
403
|
pathname: string;
|
|
401
404
|
query: Record<string, string>;
|
|
@@ -571,4 +574,4 @@ type WindowSize = {
|
|
|
571
574
|
};
|
|
572
575
|
declare function useWindowSize(): WindowSize;
|
|
573
576
|
|
|
574
|
-
export { BodyScrollOptions, ClickOutGetContainer, CurrentStateType, ElementStackItem, ExtraProvider, Filter, FilterMode, FilterParams, FilterValues, GeoLocationSensorState, IExtra, IFilter, IFilterOption, IGeolocationPositionError, ILabelContext, ILayoutContext, ILazyModulesContext, IPageContext, IPageRoute, 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, usePageLoading, usePagination, usePortal, usePrevious, useRealSize, useResize, useSSR, useScroll, useScrollTo, useScrolled, useSearchParams, useSearchParamsEncoded, useSearchParamsQs, useSearchParamsValue, useSorting, useSyncedRef, useUI, useUnit, useUnmountEffect, useWindowSize };
|
|
577
|
+
export { BodyScrollOptions, ClickOutGetContainer, CurrentStateType, ElementStackItem, ExtraProvider, Filter, FilterMode, FilterParams, FilterValues, GeoLocationSensorState, IExtra, IFilter, IFilterOption, IGeolocationPositionError, ILabelContext, ILayoutContext, ILazyModulesContext, IPageContext, IPageRoute, IPageRouteOptions, 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, usePageLoading, usePagination, usePortal, usePrevious, useRealSize, useResize, useSSR, useScroll, useScrollTo, useScrolled, useSearchParams, useSearchParamsEncoded, useSearchParamsQs, useSearchParamsValue, useSorting, useSyncedRef, useUI, useUnit, useUnmountEffect, useWindowSize };
|
package/dist/index.js
CHANGED
|
@@ -1420,22 +1420,31 @@ function usePageLoading(options = { loading: false }) {
|
|
|
1420
1420
|
const [previousPageRoute, setPreviousPageRoute] = (0, import_react25.useState)();
|
|
1421
1421
|
(0, import_react25.useEffect)(() => {
|
|
1422
1422
|
let previousRoute;
|
|
1423
|
-
const onRouteChangeStart = () => {
|
|
1423
|
+
const onRouteChangeStart = (route, options2) => {
|
|
1424
1424
|
const pageRoute2 = previousRoute ? getPageRoute(previousRoute) : void 0;
|
|
1425
|
-
setLoading(true);
|
|
1426
|
-
setPreviousPageRoute(pageRoute2);
|
|
1427
1425
|
setError();
|
|
1426
|
+
setPreviousPageRoute(pageRoute2);
|
|
1427
|
+
if (options2 == null ? void 0 : options2.shallow) {
|
|
1428
|
+
return;
|
|
1429
|
+
}
|
|
1430
|
+
setLoading(true);
|
|
1428
1431
|
};
|
|
1429
|
-
const onRouteChangeComplete = (route) => {
|
|
1432
|
+
const onRouteChangeComplete = (route, options2) => {
|
|
1430
1433
|
const pageRoute2 = getPageRoute(route);
|
|
1431
1434
|
setPageRoute(pageRoute2);
|
|
1432
1435
|
previousRoute = route;
|
|
1436
|
+
if (options2 == null ? void 0 : options2.shallow) {
|
|
1437
|
+
return;
|
|
1438
|
+
}
|
|
1433
1439
|
setLoading(false);
|
|
1434
1440
|
};
|
|
1435
|
-
const onRouteChangeError = (error2) => {
|
|
1441
|
+
const onRouteChangeError = (error2, route, options2) => {
|
|
1436
1442
|
console.log("usePageLoading.onRouteChangeError", error2);
|
|
1437
|
-
setLoading(false);
|
|
1438
1443
|
setError(error2);
|
|
1444
|
+
if (options2 == null ? void 0 : options2.shallow) {
|
|
1445
|
+
return;
|
|
1446
|
+
}
|
|
1447
|
+
setLoading(false);
|
|
1439
1448
|
};
|
|
1440
1449
|
import_router.Router.events.on("routeChangeStart", onRouteChangeStart);
|
|
1441
1450
|
import_router.Router.events.on("routeChangeComplete", onRouteChangeComplete);
|
|
@@ -1697,7 +1706,7 @@ function pushSearchParams(router, params) {
|
|
|
1697
1706
|
}
|
|
1698
1707
|
function pushSearchParamsSilently(router, params) {
|
|
1699
1708
|
const { pathname, query } = updateSearchParams(router.asPath, params);
|
|
1700
|
-
router.push({ pathname, query }, void 0, { shallow: true });
|
|
1709
|
+
router.push({ pathname, query }, void 0, { shallow: true, scroll: false });
|
|
1701
1710
|
}
|
|
1702
1711
|
function replaceSearchParams(router, params) {
|
|
1703
1712
|
const { pathname, query } = updateSearchParams(router.asPath, params);
|
|
@@ -1705,7 +1714,7 @@ function replaceSearchParams(router, params) {
|
|
|
1705
1714
|
}
|
|
1706
1715
|
function replaceSearchParamsSilently(router, params) {
|
|
1707
1716
|
const { pathname, query } = updateSearchParams(router.asPath, params);
|
|
1708
|
-
router.replace({ pathname, query }, void 0, { shallow: true });
|
|
1717
|
+
router.replace({ pathname, query }, void 0, { shallow: true, scroll: false });
|
|
1709
1718
|
}
|
|
1710
1719
|
function useSearchParams() {
|
|
1711
1720
|
const router = (0, import_router2.useRouter)();
|
|
@@ -1904,7 +1913,7 @@ function pushSearchParamsQs(router, value, key) {
|
|
|
1904
1913
|
}
|
|
1905
1914
|
function pushSearchParamsQsSilently(router, value, key) {
|
|
1906
1915
|
const { pathname, query } = updateSearchParamsQs(router.asPath, value, key);
|
|
1907
|
-
router.push({ pathname, query }, void 0, { shallow: true });
|
|
1916
|
+
router.push({ pathname, query }, void 0, { shallow: true, scroll: false });
|
|
1908
1917
|
}
|
|
1909
1918
|
function replaceSearchParamsQs(router, value, key) {
|
|
1910
1919
|
const { pathname, query } = updateSearchParamsQs(router.asPath, value, key);
|
|
@@ -1912,7 +1921,7 @@ function replaceSearchParamsQs(router, value, key) {
|
|
|
1912
1921
|
}
|
|
1913
1922
|
function replaceSearchParamsQsSilently(router, value, key) {
|
|
1914
1923
|
const { pathname, query } = updateSearchParamsQs(router.asPath, value, key);
|
|
1915
|
-
router.replace({ pathname, query }, void 0, { shallow: true });
|
|
1924
|
+
router.replace({ pathname, query }, void 0, { shallow: true, scroll: false });
|
|
1916
1925
|
}
|
|
1917
1926
|
function useSearchParamsQs(key) {
|
|
1918
1927
|
const router = (0, import_router4.useRouter)();
|
package/dist/index.mjs
CHANGED
|
@@ -1280,22 +1280,31 @@ function usePageLoading(options = { loading: false }) {
|
|
|
1280
1280
|
const [previousPageRoute, setPreviousPageRoute] = useState14();
|
|
1281
1281
|
useEffect19(() => {
|
|
1282
1282
|
let previousRoute;
|
|
1283
|
-
const onRouteChangeStart = () => {
|
|
1283
|
+
const onRouteChangeStart = (route, options2) => {
|
|
1284
1284
|
const pageRoute2 = previousRoute ? getPageRoute(previousRoute) : void 0;
|
|
1285
|
-
setLoading(true);
|
|
1286
|
-
setPreviousPageRoute(pageRoute2);
|
|
1287
1285
|
setError();
|
|
1286
|
+
setPreviousPageRoute(pageRoute2);
|
|
1287
|
+
if (options2 == null ? void 0 : options2.shallow) {
|
|
1288
|
+
return;
|
|
1289
|
+
}
|
|
1290
|
+
setLoading(true);
|
|
1288
1291
|
};
|
|
1289
|
-
const onRouteChangeComplete = (route) => {
|
|
1292
|
+
const onRouteChangeComplete = (route, options2) => {
|
|
1290
1293
|
const pageRoute2 = getPageRoute(route);
|
|
1291
1294
|
setPageRoute(pageRoute2);
|
|
1292
1295
|
previousRoute = route;
|
|
1296
|
+
if (options2 == null ? void 0 : options2.shallow) {
|
|
1297
|
+
return;
|
|
1298
|
+
}
|
|
1293
1299
|
setLoading(false);
|
|
1294
1300
|
};
|
|
1295
|
-
const onRouteChangeError = (error2) => {
|
|
1301
|
+
const onRouteChangeError = (error2, route, options2) => {
|
|
1296
1302
|
console.log("usePageLoading.onRouteChangeError", error2);
|
|
1297
|
-
setLoading(false);
|
|
1298
1303
|
setError(error2);
|
|
1304
|
+
if (options2 == null ? void 0 : options2.shallow) {
|
|
1305
|
+
return;
|
|
1306
|
+
}
|
|
1307
|
+
setLoading(false);
|
|
1299
1308
|
};
|
|
1300
1309
|
Router.events.on("routeChangeStart", onRouteChangeStart);
|
|
1301
1310
|
Router.events.on("routeChangeComplete", onRouteChangeComplete);
|
|
@@ -1557,7 +1566,7 @@ function pushSearchParams(router, params) {
|
|
|
1557
1566
|
}
|
|
1558
1567
|
function pushSearchParamsSilently(router, params) {
|
|
1559
1568
|
const { pathname, query } = updateSearchParams(router.asPath, params);
|
|
1560
|
-
router.push({ pathname, query }, void 0, { shallow: true });
|
|
1569
|
+
router.push({ pathname, query }, void 0, { shallow: true, scroll: false });
|
|
1561
1570
|
}
|
|
1562
1571
|
function replaceSearchParams(router, params) {
|
|
1563
1572
|
const { pathname, query } = updateSearchParams(router.asPath, params);
|
|
@@ -1565,7 +1574,7 @@ function replaceSearchParams(router, params) {
|
|
|
1565
1574
|
}
|
|
1566
1575
|
function replaceSearchParamsSilently(router, params) {
|
|
1567
1576
|
const { pathname, query } = updateSearchParams(router.asPath, params);
|
|
1568
|
-
router.replace({ pathname, query }, void 0, { shallow: true });
|
|
1577
|
+
router.replace({ pathname, query }, void 0, { shallow: true, scroll: false });
|
|
1569
1578
|
}
|
|
1570
1579
|
function useSearchParams() {
|
|
1571
1580
|
const router = useRouter();
|
|
@@ -1764,7 +1773,7 @@ function pushSearchParamsQs(router, value, key) {
|
|
|
1764
1773
|
}
|
|
1765
1774
|
function pushSearchParamsQsSilently(router, value, key) {
|
|
1766
1775
|
const { pathname, query } = updateSearchParamsQs(router.asPath, value, key);
|
|
1767
|
-
router.push({ pathname, query }, void 0, { shallow: true });
|
|
1776
|
+
router.push({ pathname, query }, void 0, { shallow: true, scroll: false });
|
|
1768
1777
|
}
|
|
1769
1778
|
function replaceSearchParamsQs(router, value, key) {
|
|
1770
1779
|
const { pathname, query } = updateSearchParamsQs(router.asPath, value, key);
|
|
@@ -1772,7 +1781,7 @@ function replaceSearchParamsQs(router, value, key) {
|
|
|
1772
1781
|
}
|
|
1773
1782
|
function replaceSearchParamsQsSilently(router, value, key) {
|
|
1774
1783
|
const { pathname, query } = updateSearchParamsQs(router.asPath, value, key);
|
|
1775
|
-
router.replace({ pathname, query }, void 0, { shallow: true });
|
|
1784
|
+
router.replace({ pathname, query }, void 0, { shallow: true, scroll: false });
|
|
1776
1785
|
}
|
|
1777
1786
|
function useSearchParamsQs(key) {
|
|
1778
1787
|
const router = useRouter3();
|
package/package.json
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Router } from 'next/router';
|
|
2
2
|
import { useEffect, useState } from 'react';
|
|
3
3
|
|
|
4
|
+
export type IPageRouteOptions = {
|
|
5
|
+
shallow: boolean;
|
|
6
|
+
};
|
|
7
|
+
|
|
4
8
|
export type IPageRoute = {
|
|
5
9
|
pathname: string;
|
|
6
10
|
query: Record<string, string>;
|
|
@@ -31,24 +35,36 @@ export function usePageLoading(options: { loading: boolean } = { loading: false
|
|
|
31
35
|
|
|
32
36
|
useEffect(() => {
|
|
33
37
|
let previousRoute: string | undefined;
|
|
34
|
-
const onRouteChangeStart = () => {
|
|
38
|
+
const onRouteChangeStart = (route: string, options: IPageRouteOptions) => {
|
|
35
39
|
const pageRoute = previousRoute ? getPageRoute(previousRoute) : undefined;
|
|
36
40
|
// console.log('usePageLoading.onRouteChangeStart', pageRoute, previousRoute);
|
|
37
|
-
setLoading(true);
|
|
38
|
-
setPreviousPageRoute(pageRoute);
|
|
39
41
|
setError();
|
|
42
|
+
setPreviousPageRoute(pageRoute);
|
|
43
|
+
// shallow routes do not fire loading state
|
|
44
|
+
if (options?.shallow) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
setLoading(true);
|
|
40
48
|
};
|
|
41
|
-
const onRouteChangeComplete = (route: string) => {
|
|
49
|
+
const onRouteChangeComplete = (route: string, options: IPageRouteOptions) => {
|
|
42
50
|
const pageRoute = getPageRoute(route);
|
|
43
51
|
// console.log('usePageLoading.onRouteChangeComplete', pageRoute);
|
|
44
52
|
setPageRoute(pageRoute);
|
|
45
53
|
previousRoute = route;
|
|
54
|
+
// shallow routes do not fire loading state
|
|
55
|
+
if (options?.shallow) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
46
58
|
setLoading(false);
|
|
47
59
|
};
|
|
48
|
-
const onRouteChangeError = (error: Error) => {
|
|
60
|
+
const onRouteChangeError = (error: Error, route: string, options: IPageRouteOptions) => {
|
|
49
61
|
console.log('usePageLoading.onRouteChangeError', error);
|
|
50
|
-
setLoading(false);
|
|
51
62
|
setError(error);
|
|
63
|
+
// shallow routes do not fire loading state
|
|
64
|
+
if (options?.shallow) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
setLoading(false);
|
|
52
68
|
};
|
|
53
69
|
Router.events.on('routeChangeStart', onRouteChangeStart);
|
|
54
70
|
Router.events.on('routeChangeComplete', onRouteChangeComplete);
|
|
@@ -49,7 +49,7 @@ export function pushSearchParams(router: NextRouter, params: IParams): void {
|
|
|
49
49
|
|
|
50
50
|
export function pushSearchParamsSilently(router: NextRouter, params: IParams): void {
|
|
51
51
|
const { pathname, query } = updateSearchParams(router.asPath, params);
|
|
52
|
-
router.push({ pathname, query }, undefined, { shallow: true });
|
|
52
|
+
router.push({ pathname, query }, undefined, { shallow: true, scroll: false });
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
export function replaceSearchParams(router: NextRouter, params: IParams): void {
|
|
@@ -59,7 +59,7 @@ export function replaceSearchParams(router: NextRouter, params: IParams): void {
|
|
|
59
59
|
|
|
60
60
|
export function replaceSearchParamsSilently(router: NextRouter, params: IParams): void {
|
|
61
61
|
const { pathname, query } = updateSearchParams(router.asPath, params);
|
|
62
|
-
router.replace({ pathname, query }, undefined, { shallow: true });
|
|
62
|
+
router.replace({ pathname, query }, undefined, { shallow: true, scroll: false });
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
export type IParams = {
|
|
@@ -68,7 +68,7 @@ export function pushSearchParamsQs(router: NextRouter, value: IParamsQs, key?: s
|
|
|
68
68
|
|
|
69
69
|
export function pushSearchParamsQsSilently(router: NextRouter, value: IParamsQs, key?: string): void {
|
|
70
70
|
const { pathname, query } = updateSearchParamsQs(router.asPath, value, key);
|
|
71
|
-
router.push({ pathname, query }, undefined, { shallow: true });
|
|
71
|
+
router.push({ pathname, query }, undefined, { shallow: true, scroll: false });
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
export function replaceSearchParamsQs(router: NextRouter, value: IParamsQs, key?: string): void {
|
|
@@ -78,7 +78,7 @@ export function replaceSearchParamsQs(router: NextRouter, value: IParamsQs, key?
|
|
|
78
78
|
|
|
79
79
|
export function replaceSearchParamsQsSilently(router: NextRouter, value: IParamsQs, key?: string): void {
|
|
80
80
|
const { pathname, query } = updateSearchParamsQs(router.asPath, value, key);
|
|
81
|
-
router.replace({ pathname, query }, undefined, { shallow: true });
|
|
81
|
+
router.replace({ pathname, query }, undefined, { shallow: true, scroll: false });
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
export function useSearchParamsQs(key?: string): IUseSearchParamsQsResult {
|