@websolutespa/bom-mixer-hooks 1.2.1 → 1.4.0

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 CHANGED
@@ -1,56 +1,69 @@
1
- # @websolutespa/bom-mixer-hooks
2
-
3
- ## 1.2.1
4
-
5
- ### Patch Changes
6
-
7
- - Added: LabelService.
8
- - Modified: useLabels, useScrollTo.
9
-
10
- ## 1.2.0
11
-
12
- ### Minor Changes
13
-
14
- - Updating: next 13.
15
-
16
- ## 1.1.0
17
-
18
- ### Minor Changes
19
-
20
- - Modified: useHttp, useApi.
21
-
22
- ## 1.0.0
23
-
24
- ### Minor Changes
25
-
26
- - Added: useScrolled.
27
-
28
- ## 0.2.2
29
-
30
- ### Patch Changes
31
-
32
- - Modified: useBreakpoint theme mediaQuery.
33
-
34
- ## 0.2.1
35
-
36
- ### Patch Changes
37
-
38
- - Added: source files.
39
-
40
- ## 0.2.0
41
-
42
- ### Minor Changes
43
-
44
- - Added: splat routes.
45
-
46
- ## 0.1.0
47
-
48
- ### Minor Changes
49
-
50
- - Added: @websolutespa/bom-core.
51
-
52
- ## 0.0.2
53
-
54
- ### Patch Changes
55
-
56
- - Added: first release.
1
+ # @websolutespa/bom-mixer-hooks
2
+
3
+ ## 1.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added useLazyModules.
8
+
9
+ ## 1.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Added: useSearchParamsQs.
14
+ - Modified: useSearchParamsEncoded, useSearchParams, useScrollTo.
15
+
16
+ ## 1.2.1
17
+
18
+ ### Patch Changes
19
+
20
+ - Added: LabelService.
21
+ - Modified: useLabels, useScrollTo.
22
+
23
+ ## 1.2.0
24
+
25
+ ### Minor Changes
26
+
27
+ - Updating: next 13.
28
+
29
+ ## 1.1.0
30
+
31
+ ### Minor Changes
32
+
33
+ - Modified: useHttp, useApi.
34
+
35
+ ## 1.0.0
36
+
37
+ ### Minor Changes
38
+
39
+ - Added: useScrolled.
40
+
41
+ ## 0.2.2
42
+
43
+ ### Patch Changes
44
+
45
+ - Modified: useBreakpoint theme mediaQuery.
46
+
47
+ ## 0.2.1
48
+
49
+ ### Patch Changes
50
+
51
+ - Added: source files.
52
+
53
+ ## 0.2.0
54
+
55
+ ### Minor Changes
56
+
57
+ - Added: splat routes.
58
+
59
+ ## 0.1.0
60
+
61
+ ### Minor Changes
62
+
63
+ - Added: @websolutespa/bom-core.
64
+
65
+ ## 0.0.2
66
+
67
+ ### Patch Changes
68
+
69
+ - Added: first release.
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ import * as zustand_middleware from 'zustand/middleware';
6
6
  import { StateStorage } from 'zustand/middleware';
7
7
  import * as zustand from 'zustand';
8
8
  import { ISchema, IEquatable, ILabel, ILocalizable, ILayout, IPage } from '@websolutespa/bom-core';
9
- import { ICartItem, ICartAddItem, IAddressOptions, ICheckoutPartial, IFeatureType, IUser } from '@websolutespa/bom-mixer-models';
9
+ import { ICartItem, ICartAddItem, IAddressOptions, ICheckoutPartial, IFeatureType, ILazyModules, IUser } from '@websolutespa/bom-mixer-models';
10
10
  import { NextRouter } from 'next/router';
11
11
 
12
12
  declare function useApiFetch<T = unknown>(pathname: string, options?: ApiRequestOptions): [T | undefined, boolean, any, React$1.Dispatch<any>];
@@ -252,7 +252,7 @@ declare function useGeolocation(options?: PositionOptions): GeoLocationSensorSta
252
252
 
253
253
  declare function useIdle(delay?: number, immediate?: boolean): boolean;
254
254
 
255
- declare function useInfiniteLoader(items: any[], perPage?: number, delayInMs?: number): [any[], () => void, boolean];
255
+ declare function useInfiniteLoader<T = any>(items: T[], perPage?: number, delayInMs?: number): [T[], () => void, boolean];
256
256
 
257
257
  declare const useIsomorphicLayoutEffect: typeof useEffect;
258
258
 
@@ -392,6 +392,13 @@ declare function LayoutProvider({ children, layout }: {
392
392
  layout: ILayout;
393
393
  }): react_jsx_runtime.JSX.Element;
394
394
 
395
+ type ILazyModulesContext = ILazyModules;
396
+ declare const useLazyModules: () => ILazyModules;
397
+ declare function LazyModulesProvider({ children, modules }: {
398
+ children?: React__default.ReactNode;
399
+ modules: ILazyModules;
400
+ }): react_jsx_runtime.JSX.Element;
401
+
395
402
  declare function useModal(): [modal: UIValue, open: (value?: string) => void, close: () => void];
396
403
 
397
404
  declare function useMounted(): boolean;
@@ -461,7 +468,6 @@ declare function scrollToY(y?: number): void;
461
468
 
462
469
  declare function useScrolled(callback?: (top: number, left: number) => boolean): boolean;
463
470
 
464
- declare const isBrowser: boolean;
465
471
  declare function getSearchParams(url: string, key?: string): IParams | string | null;
466
472
  declare function updateSearchParams(currentPath: string, params: IParams): {
467
473
  pathname: string;
@@ -473,21 +479,20 @@ declare function replaceSearchParams(router: NextRouter, params: IParams): void;
473
479
  declare function pushSearchParams(router: NextRouter, params: IParams): void;
474
480
  declare function replaceSearchParamsSilently(params: IParams): void;
475
481
  declare function useSearchParams(): IUseSearchParamsResult;
476
- declare function useSearchParamsValue(key: string): IUseSearchParamsValueResult;
477
- type IUseSearchParamsResult = {
478
- params: IParams;
479
- replaceParamsSilently: (params: IParams) => void;
480
- replaceParams: (params: IParams) => void;
482
+ type IParams = {
483
+ [key: string]: string;
481
484
  };
482
485
  type IUseSearchParamsValueResult = {
483
486
  params: string | null;
484
487
  replaceParamsSilently: (params: IParams) => void;
485
488
  };
486
- type IParams = {
487
- [key: string]: string;
489
+ type IUseSearchParamsResult = {
490
+ params: IParams;
491
+ replaceParamsSilently: (params: IParams) => void;
492
+ replaceParams: (params: IParams) => void;
488
493
  };
494
+ declare function useSearchParamsValue(key: string): IUseSearchParamsValueResult;
489
495
 
490
- declare function decode(encoded: string | null | undefined, key?: string): IParamsEncoded;
491
496
  declare function getSearchParamsEncoded(url: string, key?: string): {} | null;
492
497
  declare function updateSearchParamsEncoded(currentPath: string, value: IParamsEncoded, key?: string): {
493
498
  pathname: string;
@@ -498,15 +503,33 @@ declare function updateSearchParamsEncoded(currentPath: string, value: IParamsEn
498
503
  declare function replaceSearchParamsEncoded(router: NextRouter, value: IParamsEncoded, key?: string): void;
499
504
  declare function pushSearchParamsEncoded(router: NextRouter, value: IParamsEncoded, key?: string): void;
500
505
  declare function replaceSearchParamsEncodedSilently(value: IParamsEncoded, key?: string): void;
501
- declare function useSearchParamsEncoded(key?: string): IUseSearchParamsEncodedResult;
506
+ type IParamsEncoded = {
507
+ [key: string]: any;
508
+ } | null;
502
509
  type IUseSearchParamsEncodedResult = {
503
510
  params: IParamsEncoded;
504
511
  replaceParamsSilently: (params: IParamsEncoded) => void;
505
512
  replaceParams: (params: IParamsEncoded) => void;
506
513
  };
507
- type IParamsEncoded = {
508
- [key: string]: any;
509
- } | null;
514
+ declare function useSearchParamsEncoded(key?: string): IUseSearchParamsEncodedResult;
515
+
516
+ declare function getSearchParamsQs(url: string, key?: string): {} | null;
517
+ declare function updateSearchParamsQs(currentPath: string, value: IParamsQs, key?: string): {
518
+ pathname: string;
519
+ query: {
520
+ [key: string]: string;
521
+ };
522
+ };
523
+ declare function replaceSearchParamsQs(router: NextRouter, value: IParamsQs, key?: string): void;
524
+ declare function pushSearchParamsQs(router: NextRouter, value: IParamsQs, key?: string): void;
525
+ declare function replaceSearchParamsQsSilently(value: IParamsQs, key?: string): void;
526
+ type IParamsQs = {};
527
+ type IUseSearchParamsQsResult = {
528
+ params: Record<string, any> | null;
529
+ replaceParamsSilently: (params: IParamsQs) => void;
530
+ replaceParams: (params: IParamsQs) => void;
531
+ };
532
+ declare function useSearchParamsQs(key?: string): IUseSearchParamsQsResult;
510
533
 
511
534
  type Sorting<T> = {
512
535
  items: T[];
@@ -555,4 +578,4 @@ type WindowSize = {
555
578
  };
556
579
  declare function useWindowSize(): WindowSize;
557
580
 
558
- export { BodyScrollOptions, CartContext, CartProvider, CheckoutContext, CheckoutProvider, ClickOutGetContainer, CurrentStateType, ElementStackItem, Filter, FilterMode, FilterParams, FilterValues, GeoLocationSensorState, IFilter, IFilterOption, IGeolocationPositionError, ILabelContext, ILayoutContext, IPageContext, IPaginationInfo, IParams, IParamsEncoded, IUseSearchParamsEncodedResult, IUseSearchParamsResult, IUseSearchParamsValueResult, KeyCode, KeyMod, KeyboardOptions, KeyboardResult, LabelProvider, LabelService, LayoutProvider, PageProvider, SSRState, SizeResult, SizeType, Sorting, UIReducer, UIValue, UseFiltersResultType, UseKeyboard, UseKeyboardHandler, createElementWithId, createGenericContext, decode, detectIsBrowser, filtersToParams, getCurrentPosition, getFilteredItems, getFilters, getOwnerPaddingRight, getOwnerScrollbarWidth, getPagedItems, getRealSize, getSearchParams, getSearchParamsEncoded, getUID, hasGeolocation, isBrowser, parseLabel, parseParams, pushSearchParams, pushSearchParamsEncoded, replaceSearchParams, replaceSearchParamsEncoded, replaceSearchParamsEncodedSilently, replaceSearchParamsSilently, scrollToRelativeY, scrollToSelector, scrollToY, setFilters, updateSearchParams, updateSearchParamsEncoded, useApi, useApiDelete, useApiFetch, useApiGet, useApiPatch, useApiPost, useApiPut, useBodyScroll, useBreakpoint, useCart, useCheckout, useClickAnyWhere, useClickOut, useCurrency, useCurrentState, useDateTimeFormat, useDebounce, useDebounceCallback, useDebugChangedProps, useDomObserver, useDrawer, useElementSize, useEventListener, useFilters, useGeolocation, useIdle, useInfiniteLoader, useIsomorphicLayoutEffect, useKeyboard, useLabel, useLayout, useModal, useMounted, useNumber, usePage, usePagination, usePortal, usePrevious, useRealSize, useResize, useSSR, useScroll, useScrollTo, useScrolled, useSearchParams, useSearchParamsEncoded, useSearchParamsValue, useSorting, useSwiperIndex, useSyncedRef, useUI, useUnit, useUnmountEffect, useUser, useWindowSize };
581
+ export { BodyScrollOptions, CartContext, CartProvider, CheckoutContext, CheckoutProvider, ClickOutGetContainer, CurrentStateType, ElementStackItem, Filter, FilterMode, FilterParams, FilterValues, GeoLocationSensorState, 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, getRealSize, getSearchParams, getSearchParamsEncoded, getSearchParamsQs, getUID, hasGeolocation, 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, useCart, useCheckout, useClickAnyWhere, useClickOut, useCurrency, useCurrentState, useDateTimeFormat, useDebounce, useDebounceCallback, useDebugChangedProps, useDomObserver, useDrawer, useElementSize, useEventListener, useFilters, useGeolocation, useIdle, useInfiniteLoader, useIsomorphicLayoutEffect, useKeyboard, useLabel, useLayout, useLazyModules, useModal, useMounted, useNumber, usePage, usePagination, usePortal, usePrevious, useRealSize, useResize, useSSR, useScroll, useScrollTo, useScrolled, useSearchParams, useSearchParamsEncoded, useSearchParamsQs, useSearchParamsValue, useSorting, useSwiperIndex, useSyncedRef, useUI, useUnit, useUnmountEffect, useUser, useWindowSize };
package/dist/index.js CHANGED
@@ -80,10 +80,10 @@ __export(src_exports, {
80
80
  LabelProvider: () => LabelProvider,
81
81
  LabelService: () => LabelService,
82
82
  LayoutProvider: () => LayoutProvider,
83
+ LazyModulesProvider: () => LazyModulesProvider,
83
84
  PageProvider: () => PageProvider,
84
85
  createElementWithId: () => createElementWithId,
85
86
  createGenericContext: () => createGenericContext,
86
- decode: () => decode,
87
87
  detectIsBrowser: () => detectIsBrowser,
88
88
  filtersToParams: () => filtersToParams,
89
89
  getCurrentPosition: () => getCurrentPosition,
@@ -95,16 +95,19 @@ __export(src_exports, {
95
95
  getRealSize: () => getRealSize,
96
96
  getSearchParams: () => getSearchParams,
97
97
  getSearchParamsEncoded: () => getSearchParamsEncoded,
98
+ getSearchParamsQs: () => getSearchParamsQs,
98
99
  getUID: () => getUID,
99
100
  hasGeolocation: () => hasGeolocation,
100
- isBrowser: () => isBrowser,
101
101
  parseLabel: () => parseLabel,
102
102
  parseParams: () => parseParams,
103
103
  pushSearchParams: () => pushSearchParams,
104
104
  pushSearchParamsEncoded: () => pushSearchParamsEncoded,
105
+ pushSearchParamsQs: () => pushSearchParamsQs,
105
106
  replaceSearchParams: () => replaceSearchParams,
106
107
  replaceSearchParamsEncoded: () => replaceSearchParamsEncoded,
107
108
  replaceSearchParamsEncodedSilently: () => replaceSearchParamsEncodedSilently,
109
+ replaceSearchParamsQs: () => replaceSearchParamsQs,
110
+ replaceSearchParamsQsSilently: () => replaceSearchParamsQsSilently,
108
111
  replaceSearchParamsSilently: () => replaceSearchParamsSilently,
109
112
  scrollToRelativeY: () => scrollToRelativeY,
110
113
  scrollToSelector: () => scrollToSelector,
@@ -112,6 +115,7 @@ __export(src_exports, {
112
115
  setFilters: () => setFilters,
113
116
  updateSearchParams: () => updateSearchParams,
114
117
  updateSearchParamsEncoded: () => updateSearchParamsEncoded,
118
+ updateSearchParamsQs: () => updateSearchParamsQs,
115
119
  useApi: () => useApi,
116
120
  useApiDelete: () => useApiDelete,
117
121
  useApiFetch: () => useApiFetch,
@@ -143,6 +147,7 @@ __export(src_exports, {
143
147
  useKeyboard: () => useKeyboard,
144
148
  useLabel: () => useLabel,
145
149
  useLayout: () => useLayout,
150
+ useLazyModules: () => useLazyModules,
146
151
  useModal: () => useModal,
147
152
  useMounted: () => useMounted,
148
153
  useNumber: () => useNumber,
@@ -158,6 +163,7 @@ __export(src_exports, {
158
163
  useScrolled: () => useScrolled,
159
164
  useSearchParams: () => useSearchParams,
160
165
  useSearchParamsEncoded: () => useSearchParamsEncoded,
166
+ useSearchParamsQs: () => useSearchParamsQs,
161
167
  useSearchParamsValue: () => useSearchParamsValue,
162
168
  useSorting: () => useSorting,
163
169
  useSwiperIndex: () => useSwiperIndex,
@@ -334,8 +340,9 @@ var import_react6 = require("react");
334
340
  var import_react5 = require("react");
335
341
 
336
342
  // src/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.ts
343
+ var import_bom_core2 = require("@websolutespa/bom-core");
337
344
  var import_react4 = require("react");
338
- var useIsomorphicLayoutEffect = typeof window !== "undefined" ? import_react4.useLayoutEffect : import_react4.useEffect;
345
+ var useIsomorphicLayoutEffect = import_bom_core2.isBrowser ? import_react4.useLayoutEffect : import_react4.useEffect;
339
346
 
340
347
  // src/useEventListener/useEventListener.ts
341
348
  function useEventListener_(eventName, handler, element, options) {
@@ -1379,6 +1386,13 @@ function parseParams(label, params) {
1379
1386
  });
1380
1387
  }
1381
1388
 
1389
+ // src/useLazyModules/useLazyModules.tsx
1390
+ var import_jsx_runtime5 = require("react/jsx-runtime");
1391
+ var [useLazyModules, LazyModulesContextProvider] = createGenericContext({});
1392
+ function LazyModulesProvider({ children, modules }) {
1393
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(LazyModulesContextProvider, { value: modules, children });
1394
+ }
1395
+
1382
1396
  // src/useModal/useModal.ts
1383
1397
  function useModal() {
1384
1398
  const modal = useUI((state) => state.views.modal);
@@ -1406,10 +1420,10 @@ function useMounted() {
1406
1420
  }
1407
1421
 
1408
1422
  // src/usePage/usePage.tsx
1409
- var import_jsx_runtime5 = require("react/jsx-runtime");
1423
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1410
1424
  var [usePage, PageContextProvider] = createGenericContext();
1411
1425
  function PageProvider({ children, page }) {
1412
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PageContextProvider, { value: page, children });
1426
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(PageContextProvider, { value: page, children });
1413
1427
  }
1414
1428
 
1415
1429
  // src/usePagination/pagination.service.ts
@@ -1458,9 +1472,9 @@ function usePagination($items, $page = 1, $perPage = 15) {
1458
1472
  var import_react27 = require("react");
1459
1473
  var namespace = "theme";
1460
1474
  function usePortal(name = getUID(), getContainer) {
1461
- const { isBrowser: isBrowser2 } = useSSR();
1475
+ const { isBrowser: isBrowser6 } = useSSR();
1462
1476
  const id = `${namespace}-${name}`;
1463
- const [portal, setPortal] = (0, import_react27.useState)(isBrowser2 ? createElementWithId(id) : null);
1477
+ const [portal, setPortal] = (0, import_react27.useState)(isBrowser6 ? createElementWithId(id) : null);
1464
1478
  (0, import_react27.useEffect)(() => {
1465
1479
  const container = typeof getContainer === "function" ? getContainer() : null;
1466
1480
  const parentElement = container || document.body;
@@ -1552,6 +1566,7 @@ function useScroll() {
1552
1566
  }
1553
1567
 
1554
1568
  // src/useScrollTo/useScrollTo.ts
1569
+ var import_bom_core3 = require("@websolutespa/bom-core");
1555
1570
  var import_framer_motion = require("framer-motion");
1556
1571
  function useScrollTo(offset = 0) {
1557
1572
  const scrollToHash = (event) => {
@@ -1564,7 +1579,7 @@ function useScrollTo(offset = 0) {
1564
1579
  return scrollToHash;
1565
1580
  }
1566
1581
  function scrollToSelector(selector, offset = 0) {
1567
- if (selector && typeof window !== "undefined") {
1582
+ if (selector && import_bom_core3.isBrowser) {
1568
1583
  const element = document.querySelector(selector);
1569
1584
  if (element) {
1570
1585
  const rect = element.getBoundingClientRect();
@@ -1607,9 +1622,9 @@ function useScrolled(callback = DEFAULT_CALLBACK) {
1607
1622
  }
1608
1623
 
1609
1624
  // src/useSearchParams/useSearchParams.ts
1625
+ var import_bom_core4 = require("@websolutespa/bom-core");
1610
1626
  var import_router = require("next/router");
1611
1627
  var import_react32 = require("react");
1612
- var isBrowser = typeof window !== "undefined";
1613
1628
  function replace_(params) {
1614
1629
  if (window.history) {
1615
1630
  const title = document.title;
@@ -1660,7 +1675,7 @@ function pushSearchParams(router, params) {
1660
1675
  router.push({ pathname, query });
1661
1676
  }
1662
1677
  function replaceSearchParamsSilently(params) {
1663
- if (isBrowser) {
1678
+ if (import_bom_core4.isBrowser) {
1664
1679
  const searchParams = serialize_(window.location.search, params);
1665
1680
  replace_(searchParams);
1666
1681
  }
@@ -1696,18 +1711,19 @@ function useSearchParamsValue(key) {
1696
1711
  }
1697
1712
 
1698
1713
  // src/useSearchParamsEncoded/useSearchParamsEncoded.ts
1714
+ var import_bom_core5 = require("@websolutespa/bom-core");
1699
1715
  var import_router2 = require("next/router");
1700
1716
  var import_react33 = require("react");
1701
1717
  var USE_ENCRYPTION = true;
1702
1718
  function base64ToString(base64) {
1703
1719
  if (!USE_ENCRYPTION)
1704
1720
  return base64;
1705
- return isBrowser ? window.atob(base64) : Buffer.from(base64, "base64").toString();
1721
+ return import_bom_core5.isBrowser ? window.atob(base64) : Buffer.from(base64, "base64").toString();
1706
1722
  }
1707
1723
  function stringToBase64(text) {
1708
1724
  if (!USE_ENCRYPTION)
1709
1725
  return text;
1710
- return isBrowser ? window.btoa(text) : Buffer.from(text).toString("base64");
1726
+ return import_bom_core5.isBrowser ? window.btoa(text) : Buffer.from(text).toString("base64");
1711
1727
  }
1712
1728
  function stringToURLSearchParams(url) {
1713
1729
  return new URLSearchParams(url);
@@ -1796,7 +1812,7 @@ function pushSearchParamsEncoded(router, value, key) {
1796
1812
  router.push({ pathname, query });
1797
1813
  }
1798
1814
  function replaceSearchParamsEncodedSilently(value, key) {
1799
- if (isBrowser) {
1815
+ if (import_bom_core5.isBrowser) {
1800
1816
  const searchParams = serialize_2(window.location.search, value, key);
1801
1817
  replace_2(searchParams);
1802
1818
  }
@@ -1817,13 +1833,123 @@ function useSearchParamsEncoded(key) {
1817
1833
  return { params, replaceParamsSilently, replaceParams };
1818
1834
  }
1819
1835
 
1820
- // src/useSorting/useSorting.ts
1836
+ // src/useSearchParamsQs/useSearchParamsQs.ts
1837
+ var import_bom_core6 = require("@websolutespa/bom-core");
1838
+ var import_router3 = require("next/router");
1821
1839
  var import_react34 = require("react");
1840
+ function decode2(encoded, key) {
1841
+ let decoded = null;
1842
+ if (encoded) {
1843
+ decoded = (0, import_bom_core6.qsDeserializeRaw)(encoded);
1844
+ }
1845
+ if (key && decoded) {
1846
+ decoded = decoded[key];
1847
+ }
1848
+ return decoded || null;
1849
+ }
1850
+ function encode2(params, value, key) {
1851
+ if (key) {
1852
+ params = __spreadProps(__spreadValues({}, params), { [key]: value });
1853
+ } else if (typeof value === "object") {
1854
+ params = __spreadValues(__spreadValues({}, params), value);
1855
+ } else {
1856
+ params = __spreadValues({}, params);
1857
+ }
1858
+ const encoded = (0, import_bom_core6.qsSerializeRaw)(params);
1859
+ return encoded;
1860
+ }
1861
+ function stringToURLSearchParams2(url) {
1862
+ return new URLSearchParams(url);
1863
+ }
1864
+ function getURLSearchParams2(url, key) {
1865
+ const params = stringToURLSearchParams2(url);
1866
+ return params.get(key);
1867
+ }
1868
+ function setURLSearchParams2(url, keyOrValue, value) {
1869
+ const params = stringToURLSearchParams2(url);
1870
+ if (value != null) {
1871
+ params.set(keyOrValue, value);
1872
+ } else {
1873
+ params.set(keyOrValue, "");
1874
+ }
1875
+ return params;
1876
+ }
1877
+ function replace_3(params) {
1878
+ if (window.history) {
1879
+ const title = document.title;
1880
+ const url = `${window.location.href.split("?")[0]}?${params.toString()}`;
1881
+ window.history.replaceState(params.toString(), title, url);
1882
+ }
1883
+ }
1884
+ function deserialize_3(url, key) {
1885
+ const encoded = getURLSearchParams2(url, "params");
1886
+ return decode2(encoded, key);
1887
+ }
1888
+ function serialize_3(url, value, key) {
1889
+ const params = deserialize_3(url);
1890
+ const encoded = encode2(params, value, key);
1891
+ return setURLSearchParams2(url, "params", encoded);
1892
+ }
1893
+ function searchParamsToObject_3(params) {
1894
+ const entries = params.entries();
1895
+ const result = {};
1896
+ for (const [key, value] of entries) {
1897
+ result[key] = value;
1898
+ }
1899
+ return result;
1900
+ }
1901
+ function getSearchParamsQs(url, key) {
1902
+ const components = url.split("?");
1903
+ const search = components[1] || "";
1904
+ const searchParams = new URLSearchParams(search);
1905
+ const params = searchParams.get("params");
1906
+ const value = params ? decode2(params, key) : null;
1907
+ return value;
1908
+ }
1909
+ function updateSearchParamsQs(currentPath, value, key) {
1910
+ const components = currentPath.split("?");
1911
+ const searchParams = serialize_3(components[1] || "", value, key);
1912
+ const query = searchParamsToObject_3(searchParams);
1913
+ const pathname = components[0] || "";
1914
+ return { pathname, query };
1915
+ }
1916
+ function replaceSearchParamsQs(router, value, key) {
1917
+ const { pathname, query } = updateSearchParamsQs(router.asPath, value, key);
1918
+ router.replace({ pathname, query });
1919
+ }
1920
+ function pushSearchParamsQs(router, value, key) {
1921
+ const { pathname, query } = updateSearchParamsQs(router.asPath, value, key);
1922
+ router.push({ pathname, query });
1923
+ }
1924
+ function replaceSearchParamsQsSilently(value, key) {
1925
+ if (import_bom_core6.isBrowser) {
1926
+ const searchParams = serialize_3(window.location.search, value, key);
1927
+ replace_3(searchParams);
1928
+ }
1929
+ }
1930
+ function useSearchParamsQs(key) {
1931
+ const router = (0, import_router3.useRouter)();
1932
+ const initialValue = (0, import_react34.useMemo)(() => {
1933
+ const value = getSearchParamsQs(router.asPath, key);
1934
+ return value;
1935
+ }, [key, router.asPath]);
1936
+ const params = initialValue;
1937
+ const replaceParamsSilently = (0, import_react34.useCallback)((params2) => {
1938
+ replaceSearchParamsQsSilently(params2, key);
1939
+ }, [key]);
1940
+ const replaceParams = (0, import_react34.useCallback)((params2) => {
1941
+ replaceSearchParamsQs(router, params2, key);
1942
+ }, [key, router]);
1943
+ return { params, replaceParamsSilently, replaceParams };
1944
+ }
1945
+
1946
+ // src/useSorting/useSorting.ts
1947
+ var import_react35 = require("react");
1822
1948
  function useSorting(items_, callback_, sort_) {
1823
- const [sort, setSort] = (0, import_react34.useState)(sort_);
1824
- const [items, setItems] = (0, import_react34.useState)(callback_(items_.slice(), sort));
1825
- const isInitialMount = (0, import_react34.useRef)(true);
1826
- (0, import_react34.useEffect)(() => {
1949
+ const [sort, setSort] = (0, import_react35.useState)(sort_);
1950
+ const [items, setItems] = (0, import_react35.useState)(callback_(items_.slice(), sort));
1951
+ const isInitialMount = (0, import_react35.useRef)(true);
1952
+ (0, import_react35.useEffect)(() => {
1827
1953
  if (isInitialMount.current) {
1828
1954
  isInitialMount.current = false;
1829
1955
  } else {
@@ -1839,18 +1965,18 @@ function useSorting(items_, callback_, sort_) {
1839
1965
  }
1840
1966
 
1841
1967
  // src/useSwiperIndex/useSwiperIndex.ts
1842
- var import_react35 = require("react");
1843
- var import_react36 = require("swiper/react");
1968
+ var import_react36 = require("react");
1969
+ var import_react37 = require("swiper/react");
1844
1970
  function useSwiperIndex() {
1845
- const swiper = (0, import_react36.useSwiper)();
1846
- const [index, setIndex] = (0, import_react35.useState)(swiper.realIndex);
1847
- const slideTo = (0, import_react35.useCallback)((index2) => {
1971
+ const swiper = (0, import_react37.useSwiper)();
1972
+ const [index, setIndex] = (0, import_react36.useState)(swiper.realIndex);
1973
+ const slideTo = (0, import_react36.useCallback)((index2) => {
1848
1974
  swiper.slideTo(index2);
1849
1975
  }, [swiper]);
1850
1976
  const onSlideChange = (swiper2) => {
1851
1977
  setIndex(swiper2.realIndex);
1852
1978
  };
1853
- (0, import_react35.useEffect)(() => {
1979
+ (0, import_react36.useEffect)(() => {
1854
1980
  if (swiper) {
1855
1981
  swiper.on("slideChange", onSlideChange);
1856
1982
  }
@@ -1864,11 +1990,11 @@ function useSwiperIndex() {
1864
1990
  }
1865
1991
 
1866
1992
  // src/useSyncedRef/useSyncedRef.ts
1867
- var import_react37 = require("react");
1993
+ var import_react38 = require("react");
1868
1994
  function useSyncedRef(value) {
1869
- const ref = (0, import_react37.useRef)(value);
1995
+ const ref = (0, import_react38.useRef)(value);
1870
1996
  ref.current = value;
1871
- return (0, import_react37.useMemo)(() => Object.freeze({
1997
+ return (0, import_react38.useMemo)(() => Object.freeze({
1872
1998
  get current() {
1873
1999
  return ref.current;
1874
2000
  }
@@ -1881,10 +2007,10 @@ function useUnit(unit = "kilometer", locale) {
1881
2007
  }
1882
2008
 
1883
2009
  // src/useUnmountEffect/useUnmountEffect.ts
1884
- var import_react38 = require("react");
2010
+ var import_react39 = require("react");
1885
2011
  function useUnmountEffect(effect) {
1886
2012
  const effectRef = useSyncedRef(effect);
1887
- (0, import_react38.useEffect)(() => () => {
2013
+ (0, import_react39.useEffect)(() => () => {
1888
2014
  effectRef.current();
1889
2015
  }, []);
1890
2016
  }
@@ -1909,10 +2035,10 @@ var useUser = (0, import_zustand4.create)((set) => ({
1909
2035
  LabelProvider,
1910
2036
  LabelService,
1911
2037
  LayoutProvider,
2038
+ LazyModulesProvider,
1912
2039
  PageProvider,
1913
2040
  createElementWithId,
1914
2041
  createGenericContext,
1915
- decode,
1916
2042
  detectIsBrowser,
1917
2043
  filtersToParams,
1918
2044
  getCurrentPosition,
@@ -1924,16 +2050,19 @@ var useUser = (0, import_zustand4.create)((set) => ({
1924
2050
  getRealSize,
1925
2051
  getSearchParams,
1926
2052
  getSearchParamsEncoded,
2053
+ getSearchParamsQs,
1927
2054
  getUID,
1928
2055
  hasGeolocation,
1929
- isBrowser,
1930
2056
  parseLabel,
1931
2057
  parseParams,
1932
2058
  pushSearchParams,
1933
2059
  pushSearchParamsEncoded,
2060
+ pushSearchParamsQs,
1934
2061
  replaceSearchParams,
1935
2062
  replaceSearchParamsEncoded,
1936
2063
  replaceSearchParamsEncodedSilently,
2064
+ replaceSearchParamsQs,
2065
+ replaceSearchParamsQsSilently,
1937
2066
  replaceSearchParamsSilently,
1938
2067
  scrollToRelativeY,
1939
2068
  scrollToSelector,
@@ -1941,6 +2070,7 @@ var useUser = (0, import_zustand4.create)((set) => ({
1941
2070
  setFilters,
1942
2071
  updateSearchParams,
1943
2072
  updateSearchParamsEncoded,
2073
+ updateSearchParamsQs,
1944
2074
  useApi,
1945
2075
  useApiDelete,
1946
2076
  useApiFetch,
@@ -1972,6 +2102,7 @@ var useUser = (0, import_zustand4.create)((set) => ({
1972
2102
  useKeyboard,
1973
2103
  useLabel,
1974
2104
  useLayout,
2105
+ useLazyModules,
1975
2106
  useModal,
1976
2107
  useMounted,
1977
2108
  useNumber,
@@ -1987,6 +2118,7 @@ var useUser = (0, import_zustand4.create)((set) => ({
1987
2118
  useScrolled,
1988
2119
  useSearchParams,
1989
2120
  useSearchParamsEncoded,
2121
+ useSearchParamsQs,
1990
2122
  useSearchParamsValue,
1991
2123
  useSorting,
1992
2124
  useSwiperIndex,