@websolutespa/bom-mixer-hooks 1.4.2 → 1.7.1

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,89 +1,105 @@
1
- # @websolutespa/bom-mixer-hooks
2
-
3
- ## 1.4.2
4
-
5
- ### Patch Changes
6
-
7
- - Modified: IFeatureType
8
- - Updated dependencies
9
- - @websolutespa/bom-mixer-models@1.5.4
10
- - @websolutespa/bom-mixer-store@1.4.3
11
- - @websolutespa/bom-core@0.6.5
12
-
13
- ## 1.4.1
14
-
15
- ### Patch Changes
16
-
17
- - Added: useCollectionApi, useExtra
18
- - Modified: usePagination, useSearchParamsQs
19
- - Updated dependencies
20
- - @websolutespa/bom-mixer-models@1.5.2
21
- - @websolutespa/bom-core@0.6.2
22
-
23
- ## 1.4.0
24
-
25
- ### Minor Changes
26
-
27
- - Added useLazyModules
28
-
29
- ## 1.3.0
30
-
31
- ### Minor Changes
32
-
33
- - Added: useSearchParamsQs
34
- - Modified: useSearchParamsEncoded, useSearchParams, useScrollTo
35
-
36
- ## 1.2.1
37
-
38
- ### Patch Changes
39
-
40
- - Added: LabelService
41
- - Modified: useLabels, useScrollTo
42
-
43
- ## 1.2.0
44
-
45
- ### Minor Changes
46
-
47
- - Updating: next 13
48
-
49
- ## 1.1.0
50
-
51
- ### Minor Changes
52
-
53
- - Modified: useHttp, useApi
54
-
55
- ## 1.0.0
56
-
57
- ### Minor Changes
58
-
59
- - Added: useScrolled
60
-
61
- ## 0.2.2
62
-
63
- ### Patch Changes
64
-
65
- - Modified: useBreakpoint theme mediaQuery
66
-
67
- ## 0.2.1
68
-
69
- ### Patch Changes
70
-
71
- - Added: source files
72
-
73
- ## 0.2.0
74
-
75
- ### Minor Changes
76
-
77
- - Added: splat routes
78
-
79
- ## 0.1.0
80
-
81
- ### Minor Changes
82
-
83
- - Added: @websolutespa/bom-core
84
-
85
- ## 0.0.2
86
-
87
- ### Patch Changes
88
-
89
- - Added: first release
1
+ # @websolutespa/bom-mixer-hooks
2
+
3
+ ## 1.7.1
4
+
5
+ ### Patch Changes
6
+
7
+ - aa41666: Added: useIntersectionObserver
8
+
9
+ ## 1.7.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 28e86bd: Modified: IPage, Store services & decorators
14
+ - Updated dependencies [28e86bd]
15
+ - @websolutespa/bom-mixer-models@1.7.0
16
+ - @websolutespa/bom-mixer-store@1.7.0
17
+ - @websolutespa/bom-core@1.7.0
18
+
19
+ ## 1.4.2
20
+
21
+ ### Patch Changes
22
+
23
+ - Modified: IFeatureType
24
+ - Updated dependencies
25
+ - @websolutespa/bom-mixer-models@1.5.4
26
+ - @websolutespa/bom-mixer-store@1.4.3
27
+ - @websolutespa/bom-core@0.6.5
28
+
29
+ ## 1.4.1
30
+
31
+ ### Patch Changes
32
+
33
+ - Added: useCollectionApi, useExtra
34
+ - Modified: usePagination, useSearchParamsQs
35
+ - Updated dependencies
36
+ - @websolutespa/bom-mixer-models@1.5.2
37
+ - @websolutespa/bom-core@0.6.2
38
+
39
+ ## 1.4.0
40
+
41
+ ### Minor Changes
42
+
43
+ - Added useLazyModules
44
+
45
+ ## 1.3.0
46
+
47
+ ### Minor Changes
48
+
49
+ - Added: useSearchParamsQs
50
+ - Modified: useSearchParamsEncoded, useSearchParams, useScrollTo
51
+
52
+ ## 1.2.1
53
+
54
+ ### Patch Changes
55
+
56
+ - Added: LabelService
57
+ - Modified: useLabels, useScrollTo
58
+
59
+ ## 1.2.0
60
+
61
+ ### Minor Changes
62
+
63
+ - Updating: next 13
64
+
65
+ ## 1.1.0
66
+
67
+ ### Minor Changes
68
+
69
+ - Modified: useHttp, useApi
70
+
71
+ ## 1.0.0
72
+
73
+ ### Minor Changes
74
+
75
+ - Added: useScrolled
76
+
77
+ ## 0.2.2
78
+
79
+ ### Patch Changes
80
+
81
+ - Modified: useBreakpoint theme mediaQuery
82
+
83
+ ## 0.2.1
84
+
85
+ ### Patch Changes
86
+
87
+ - Added: source files
88
+
89
+ ## 0.2.0
90
+
91
+ ### Minor Changes
92
+
93
+ - Added: splat routes
94
+
95
+ ## 0.1.0
96
+
97
+ ### Minor Changes
98
+
99
+ - Added: @websolutespa/bom-core
100
+
101
+ ## 0.0.2
102
+
103
+ ### Patch Changes
104
+
105
+ - Added: first release
package/dist/index.d.ts CHANGED
@@ -300,6 +300,9 @@ declare function useIdle(delay?: number, immediate?: boolean): boolean;
300
300
 
301
301
  declare function useInfiniteLoader<T = any>(items: T[], perPage?: number, delayInMs?: number): [T[], () => void, boolean];
302
302
 
303
+ declare function useIntersectionObserver(ref: MutableRefObject<Node | undefined>, options?: IntersectionObserverInit): boolean;
304
+ declare function isElement(node?: Node): node is Element;
305
+
303
306
  declare const useIsomorphicLayoutEffect: typeof useEffect;
304
307
 
305
308
  /**
@@ -452,7 +455,7 @@ declare function useMounted(): boolean;
452
455
  declare function useNumber(options?: Intl.NumberFormatOptions, locale?: string): (value: number) => string;
453
456
 
454
457
  type IPageContext = IPage;
455
- declare const usePage: () => NonNullable<IPage>;
458
+ declare const usePage: () => NonNullable<IPageContext>;
456
459
  declare function PageProvider({ children, page }: {
457
460
  children?: react__default.ReactNode;
458
461
  page: IPage;
@@ -624,4 +627,4 @@ type WindowSize = {
624
627
  };
625
628
  declare function useWindowSize(): WindowSize;
626
629
 
627
- export { BodyScrollOptions, CartContext, CartProvider, CheckoutContext, CheckoutProvider, 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, 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, useCart, useCheckout, useClickAnyWhere, useClickOut, useCollectionApi, useCollectionApiDelete, useCollectionApiGet, useCollectionApiPatch, useCollectionApiPost, useCollectionApiPut, useCurrency, useCurrentState, useDateTimeFormat, useDebounce, useDebounceCallback, useDebugChangedProps, useDomObserver, useDrawer, useElementSize, useEventListener, useExtra, 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 };
630
+ export { BodyScrollOptions, CartContext, CartProvider, CheckoutContext, CheckoutProvider, 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, useCart, useCheckout, 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, useSwiperIndex, useSyncedRef, useUI, useUnit, useUnmountEffect, useUser, useWindowSize };
package/dist/index.js CHANGED
@@ -100,6 +100,7 @@ __export(src_exports, {
100
100
  getSearchParamsQs: () => getSearchParamsQs,
101
101
  getUID: () => getUID,
102
102
  hasGeolocation: () => hasGeolocation,
103
+ isElement: () => isElement,
103
104
  isPaginationInfo: () => isPaginationInfo,
104
105
  localCollectionDelete: () => localCollectionDelete,
105
106
  localCollectionFetch: () => localCollectionFetch,
@@ -159,6 +160,7 @@ __export(src_exports, {
159
160
  useGeolocation: () => useGeolocation,
160
161
  useIdle: () => useIdle,
161
162
  useInfiniteLoader: () => useInfiniteLoader,
163
+ useIntersectionObserver: () => useIntersectionObserver,
162
164
  useIsomorphicLayoutEffect: () => useIsomorphicLayoutEffect,
163
165
  useKeyboard: () => useKeyboard,
164
166
  useLabel: () => useLabel,
@@ -1258,8 +1260,43 @@ function useInfiniteLoader(items, perPage = 12, delayInMs = 100) {
1258
1260
  return [visibleItems, loadMore, hasMore];
1259
1261
  }
1260
1262
 
1263
+ // src/useIntersectionObserver/useIntersectionObserver.ts
1264
+ var import_react23 = require("react");
1265
+ function useIntersectionObserver(ref, options = {}) {
1266
+ const {
1267
+ threshold = 1,
1268
+ root = null,
1269
+ rootMargin = "0px"
1270
+ } = options;
1271
+ const [entry, setEntry] = (0, import_react23.useState)();
1272
+ const previousObserver = (0, import_react23.useRef)();
1273
+ const init = (0, import_react23.useCallback)((node) => {
1274
+ if (previousObserver.current) {
1275
+ previousObserver.current.disconnect();
1276
+ previousObserver.current = void 0;
1277
+ }
1278
+ if (isElement(node)) {
1279
+ const observer = new IntersectionObserver(([entry2]) => {
1280
+ setEntry(entry2);
1281
+ }, { threshold, root, rootMargin });
1282
+ observer.observe(node);
1283
+ previousObserver.current = observer;
1284
+ }
1285
+ }, [threshold, root, rootMargin]);
1286
+ (0, import_react23.useEffect)(() => {
1287
+ if (ref.current) {
1288
+ init(ref.current);
1289
+ }
1290
+ }, [init, ref]);
1291
+ const isIntersecting = entry ? entry.isIntersecting : false;
1292
+ return isIntersecting;
1293
+ }
1294
+ function isElement(node) {
1295
+ return (node == null ? void 0 : node.nodeType) === Node.ELEMENT_NODE;
1296
+ }
1297
+
1261
1298
  // src/useKeyboard/useKeyboard.ts
1262
- var import_react24 = require("react");
1299
+ var import_react25 = require("react");
1263
1300
 
1264
1301
  // src/useKeyboard/codes.ts
1265
1302
  var KeyCode = /* @__PURE__ */ ((KeyCode2) => {
@@ -1350,15 +1387,15 @@ var KeyMod = /* @__PURE__ */ ((KeyMod2) => {
1350
1387
  })(KeyMod || {});
1351
1388
 
1352
1389
  // src/useSSR/useSSR.ts
1353
- var import_react23 = require("react");
1390
+ var import_react24 = require("react");
1354
1391
  var detectIsBrowser = () => {
1355
1392
  return Boolean(
1356
1393
  typeof window !== "undefined" && window.document && window.document.createElement
1357
1394
  );
1358
1395
  };
1359
1396
  function useSSR() {
1360
- const [browser, setBrowser] = (0, import_react23.useState)(false);
1361
- (0, import_react23.useEffect)(() => {
1397
+ const [browser, setBrowser] = (0, import_react24.useState)(false);
1398
+ (0, import_react24.useEffect)(() => {
1362
1399
  setBrowser(detectIsBrowser());
1363
1400
  }, []);
1364
1401
  return {
@@ -1428,7 +1465,7 @@ var useKeyboard = (handler, keyBindings, options = {}) => {
1428
1465
  }
1429
1466
  handler && handler(event2);
1430
1467
  };
1431
- (0, import_react24.useEffect)(() => {
1468
+ (0, import_react25.useEffect)(() => {
1432
1469
  if (!disableGlobalEvent) {
1433
1470
  document.addEventListener(event, eventHandler);
1434
1471
  }
@@ -1516,10 +1553,10 @@ function useModal() {
1516
1553
  }
1517
1554
 
1518
1555
  // src/useMounted/useMounted.ts
1519
- var import_react25 = require("react");
1556
+ var import_react26 = require("react");
1520
1557
  function useMounted() {
1521
- const [mounted, setMounted] = (0, import_react25.useState)(false);
1522
- (0, import_react25.useEffect)(() => {
1558
+ const [mounted, setMounted] = (0, import_react26.useState)(false);
1559
+ (0, import_react26.useEffect)(() => {
1523
1560
  setMounted(true);
1524
1561
  }, []);
1525
1562
  return mounted;
@@ -1550,14 +1587,14 @@ function getPaginationInfo(items, page = 1, perPage = 15) {
1550
1587
  }
1551
1588
 
1552
1589
  // src/usePagination/usePagination.ts
1553
- var import_react26 = require("react");
1590
+ var import_react27 = require("react");
1554
1591
  function usePagination($items, $page = 1, $perPage = 15) {
1555
1592
  const total = $items.length;
1556
- const [page, setPage] = (0, import_react26.useState)($page);
1557
- const [perPage, setPerPage_] = (0, import_react26.useState)($perPage);
1558
- const [items, setItems] = (0, import_react26.useState)(getPagedItems($items, $page, $perPage));
1593
+ const [page, setPage] = (0, import_react27.useState)($page);
1594
+ const [perPage, setPerPage_] = (0, import_react27.useState)($perPage);
1595
+ const [items, setItems] = (0, import_react27.useState)(getPagedItems($items, $page, $perPage));
1559
1596
  const pages = Math.ceil(total / perPage);
1560
- (0, import_react26.useEffect)(() => {
1597
+ (0, import_react27.useEffect)(() => {
1561
1598
  setItems(getPagedItems($items, page, perPage));
1562
1599
  }, [$items]);
1563
1600
  function goToPage(page2) {
@@ -1585,13 +1622,13 @@ function usePagination($items, $page = 1, $perPage = 15) {
1585
1622
  }
1586
1623
 
1587
1624
  // src/usePortal/usePortal.ts
1588
- var import_react27 = require("react");
1625
+ var import_react28 = require("react");
1589
1626
  var namespace = "theme";
1590
1627
  function usePortal(name = getUID(), getContainer) {
1591
1628
  const { isBrowser: isBrowser6 } = useSSR();
1592
1629
  const id = `${namespace}-${name}`;
1593
- const [portal, setPortal] = (0, import_react27.useState)(isBrowser6 ? createElementWithId(id) : null);
1594
- (0, import_react27.useEffect)(() => {
1630
+ const [portal, setPortal] = (0, import_react28.useState)(isBrowser6 ? createElementWithId(id) : null);
1631
+ (0, import_react28.useEffect)(() => {
1595
1632
  const container = typeof getContainer === "function" ? getContainer() : null;
1596
1633
  const parentElement = container || document.body;
1597
1634
  const element = parentElement.querySelector(`#${id}`) || createElementWithId(id);
@@ -1612,24 +1649,24 @@ function getUID() {
1612
1649
  }
1613
1650
 
1614
1651
  // src/usePrevious/usePrevious.ts
1615
- var import_react28 = require("react");
1652
+ var import_react29 = require("react");
1616
1653
  function usePrevious(state) {
1617
- const ref = (0, import_react28.useRef)(null);
1618
- (0, import_react28.useEffect)(() => {
1654
+ const ref = (0, import_react29.useRef)(null);
1655
+ (0, import_react29.useEffect)(() => {
1619
1656
  ref.current = state;
1620
1657
  });
1621
1658
  return ref.current;
1622
1659
  }
1623
1660
 
1624
1661
  // src/useRealSize/useRealSize.ts
1625
- var import_react29 = require("react");
1662
+ var import_react30 = require("react");
1626
1663
  function useRealSize(ref) {
1627
- const [state, setState] = (0, import_react29.useState)({ width: 0, height: 0 });
1664
+ const [state, setState] = (0, import_react30.useState)({ width: 0, height: 0 });
1628
1665
  const update = () => {
1629
1666
  const { width, height } = getRealSize(ref.current);
1630
1667
  setState({ width, height });
1631
1668
  };
1632
- (0, import_react29.useEffect)(() => update(), [ref.current]);
1669
+ (0, import_react30.useEffect)(() => update(), [ref.current]);
1633
1670
  return [state, update];
1634
1671
  }
1635
1672
  function getRealSize(element) {
@@ -1664,9 +1701,9 @@ function useResize(callback, immediate = true) {
1664
1701
  }
1665
1702
 
1666
1703
  // src/useScroll/useScroll.ts
1667
- var import_react30 = require("react");
1704
+ var import_react31 = require("react");
1668
1705
  function useScroll() {
1669
- const [scroll, setScroll] = (0, import_react30.useState)({ left: 0, top: 0 });
1706
+ const [scroll, setScroll] = (0, import_react31.useState)({ left: 0, top: 0 });
1670
1707
  const onScroll = () => {
1671
1708
  const left = window.scrollX;
1672
1709
  const top = window.scrollY;
@@ -1718,12 +1755,12 @@ function scrollToY(y = 0) {
1718
1755
  }
1719
1756
 
1720
1757
  // src/useScrolled/useScrolled.ts
1721
- var import_react31 = require("react");
1758
+ var import_react32 = require("react");
1722
1759
  var DEFAULT_CALLBACK = (top, left) => {
1723
1760
  return top > 0;
1724
1761
  };
1725
1762
  function useScrolled(callback = DEFAULT_CALLBACK) {
1726
- const [scrolled, setScrolled] = (0, import_react31.useState)(false);
1763
+ const [scrolled, setScrolled] = (0, import_react32.useState)(false);
1727
1764
  const onScrolled = () => {
1728
1765
  const scrolled_ = callback(window.scrollY, window.scrollX);
1729
1766
  if (scrolled !== scrolled_) {
@@ -1740,7 +1777,7 @@ function useScrolled(callback = DEFAULT_CALLBACK) {
1740
1777
  // src/useSearchParams/useSearchParams.ts
1741
1778
  var import_bom_core7 = require("@websolutespa/bom-core");
1742
1779
  var import_router = require("next/router");
1743
- var import_react32 = require("react");
1780
+ var import_react33 = require("react");
1744
1781
  function replace_(params) {
1745
1782
  if (window.history) {
1746
1783
  const title = document.title;
@@ -1798,29 +1835,29 @@ function replaceSearchParamsSilently(params) {
1798
1835
  }
1799
1836
  function useSearchParams() {
1800
1837
  const router = (0, import_router.useRouter)();
1801
- const initialValue = (0, import_react32.useMemo)(() => {
1838
+ const initialValue = (0, import_react33.useMemo)(() => {
1802
1839
  const params2 = deserialize_(router.asPath);
1803
1840
  const value = Object.fromEntries(params2);
1804
1841
  return value;
1805
1842
  }, [router.asPath]);
1806
1843
  const params = initialValue;
1807
- const replaceParamsSilently = (0, import_react32.useCallback)((params2) => {
1844
+ const replaceParamsSilently = (0, import_react33.useCallback)((params2) => {
1808
1845
  replaceSearchParamsSilently(params2);
1809
1846
  }, []);
1810
- const replaceParams = (0, import_react32.useCallback)((params2) => {
1847
+ const replaceParams = (0, import_react33.useCallback)((params2) => {
1811
1848
  replaceSearchParams(router, params2);
1812
1849
  }, [router]);
1813
1850
  return { params, replaceParamsSilently, replaceParams };
1814
1851
  }
1815
1852
  function useSearchParamsValue(key) {
1816
1853
  const router = (0, import_router.useRouter)();
1817
- const initialValue = (0, import_react32.useMemo)(() => {
1854
+ const initialValue = (0, import_react33.useMemo)(() => {
1818
1855
  const params2 = deserialize_(router.asPath);
1819
1856
  const value = params2.get(key);
1820
1857
  return value;
1821
1858
  }, [key, router.asPath]);
1822
1859
  const params = initialValue;
1823
- const replaceParamsSilently = (0, import_react32.useCallback)((params2) => {
1860
+ const replaceParamsSilently = (0, import_react33.useCallback)((params2) => {
1824
1861
  replaceSearchParamsSilently(params2);
1825
1862
  }, []);
1826
1863
  return { params, replaceParamsSilently };
@@ -1829,7 +1866,7 @@ function useSearchParamsValue(key) {
1829
1866
  // src/useSearchParamsEncoded/useSearchParamsEncoded.ts
1830
1867
  var import_bom_core8 = require("@websolutespa/bom-core");
1831
1868
  var import_router2 = require("next/router");
1832
- var import_react33 = require("react");
1869
+ var import_react34 = require("react");
1833
1870
  var USE_ENCRYPTION = true;
1834
1871
  function base64ToString(base64) {
1835
1872
  if (!USE_ENCRYPTION)
@@ -1935,15 +1972,15 @@ function replaceSearchParamsEncodedSilently(value, key) {
1935
1972
  }
1936
1973
  function useSearchParamsEncoded(key) {
1937
1974
  const router = (0, import_router2.useRouter)();
1938
- const initialValue = (0, import_react33.useMemo)(() => {
1975
+ const initialValue = (0, import_react34.useMemo)(() => {
1939
1976
  const value = getSearchParamsEncoded(router.asPath, key);
1940
1977
  return value;
1941
1978
  }, [key, router.asPath]);
1942
1979
  const params = initialValue;
1943
- const replaceParamsSilently = (0, import_react33.useCallback)((params2) => {
1980
+ const replaceParamsSilently = (0, import_react34.useCallback)((params2) => {
1944
1981
  replaceSearchParamsEncodedSilently(params2, key);
1945
1982
  }, [key]);
1946
- const replaceParams = (0, import_react33.useCallback)((params2) => {
1983
+ const replaceParams = (0, import_react34.useCallback)((params2) => {
1947
1984
  replaceSearchParamsEncoded(router, params2, key);
1948
1985
  }, [key, router]);
1949
1986
  return { params, replaceParamsSilently, replaceParams };
@@ -1952,7 +1989,7 @@ function useSearchParamsEncoded(key) {
1952
1989
  // src/useSearchParamsQs/useSearchParamsQs.ts
1953
1990
  var import_bom_core9 = require("@websolutespa/bom-core");
1954
1991
  var import_router3 = require("next/router");
1955
- var import_react34 = require("react");
1992
+ var import_react35 = require("react");
1956
1993
  function replace(search) {
1957
1994
  if (window.history) {
1958
1995
  const title = document.title;
@@ -2018,27 +2055,27 @@ function replaceSearchParamsQsSilently(value, key) {
2018
2055
  }
2019
2056
  function useSearchParamsQs(key) {
2020
2057
  const router = (0, import_router3.useRouter)();
2021
- const initialValue = (0, import_react34.useMemo)(() => {
2058
+ const initialValue = (0, import_react35.useMemo)(() => {
2022
2059
  const value = getSearchParamsQs(router.asPath, key);
2023
2060
  return value;
2024
2061
  }, [key, router.asPath]);
2025
2062
  const params = initialValue;
2026
- const replaceParamsSilently = (0, import_react34.useCallback)((params2) => {
2063
+ const replaceParamsSilently = (0, import_react35.useCallback)((params2) => {
2027
2064
  replaceSearchParamsQsSilently(params2, key);
2028
2065
  }, [key]);
2029
- const replaceParams = (0, import_react34.useCallback)((params2) => {
2066
+ const replaceParams = (0, import_react35.useCallback)((params2) => {
2030
2067
  replaceSearchParamsQs(router, params2, key);
2031
2068
  }, [key, router]);
2032
2069
  return { params, replaceParamsSilently, replaceParams };
2033
2070
  }
2034
2071
 
2035
2072
  // src/useSorting/useSorting.ts
2036
- var import_react35 = require("react");
2073
+ var import_react36 = require("react");
2037
2074
  function useSorting(items_, callback_, sort_) {
2038
- const [sort, setSort] = (0, import_react35.useState)(sort_);
2039
- const [items, setItems] = (0, import_react35.useState)(callback_(items_.slice(), sort));
2040
- const isInitialMount = (0, import_react35.useRef)(true);
2041
- (0, import_react35.useEffect)(() => {
2075
+ const [sort, setSort] = (0, import_react36.useState)(sort_);
2076
+ const [items, setItems] = (0, import_react36.useState)(callback_(items_.slice(), sort));
2077
+ const isInitialMount = (0, import_react36.useRef)(true);
2078
+ (0, import_react36.useEffect)(() => {
2042
2079
  if (isInitialMount.current) {
2043
2080
  isInitialMount.current = false;
2044
2081
  } else {
@@ -2054,18 +2091,18 @@ function useSorting(items_, callback_, sort_) {
2054
2091
  }
2055
2092
 
2056
2093
  // src/useSwiperIndex/useSwiperIndex.ts
2057
- var import_react36 = require("react");
2058
- var import_react37 = require("swiper/react");
2094
+ var import_react37 = require("react");
2095
+ var import_react38 = require("swiper/react");
2059
2096
  function useSwiperIndex() {
2060
- const swiper = (0, import_react37.useSwiper)();
2061
- const [index, setIndex] = (0, import_react36.useState)(swiper.realIndex);
2062
- const slideTo = (0, import_react36.useCallback)((index2) => {
2097
+ const swiper = (0, import_react38.useSwiper)();
2098
+ const [index, setIndex] = (0, import_react37.useState)(swiper.realIndex);
2099
+ const slideTo = (0, import_react37.useCallback)((index2) => {
2063
2100
  swiper.slideTo(index2);
2064
2101
  }, [swiper]);
2065
2102
  const onSlideChange = (swiper2) => {
2066
2103
  setIndex(swiper2.realIndex);
2067
2104
  };
2068
- (0, import_react36.useEffect)(() => {
2105
+ (0, import_react37.useEffect)(() => {
2069
2106
  if (swiper) {
2070
2107
  swiper.on("slideChange", onSlideChange);
2071
2108
  }
@@ -2079,11 +2116,11 @@ function useSwiperIndex() {
2079
2116
  }
2080
2117
 
2081
2118
  // src/useSyncedRef/useSyncedRef.ts
2082
- var import_react38 = require("react");
2119
+ var import_react39 = require("react");
2083
2120
  function useSyncedRef(value) {
2084
- const ref = (0, import_react38.useRef)(value);
2121
+ const ref = (0, import_react39.useRef)(value);
2085
2122
  ref.current = value;
2086
- return (0, import_react38.useMemo)(() => Object.freeze({
2123
+ return (0, import_react39.useMemo)(() => Object.freeze({
2087
2124
  get current() {
2088
2125
  return ref.current;
2089
2126
  }
@@ -2096,10 +2133,10 @@ function useUnit(unit = "kilometer", locale) {
2096
2133
  }
2097
2134
 
2098
2135
  // src/useUnmountEffect/useUnmountEffect.ts
2099
- var import_react39 = require("react");
2136
+ var import_react40 = require("react");
2100
2137
  function useUnmountEffect(effect) {
2101
2138
  const effectRef = useSyncedRef(effect);
2102
- (0, import_react39.useEffect)(() => () => {
2139
+ (0, import_react40.useEffect)(() => () => {
2103
2140
  effectRef.current();
2104
2141
  }, []);
2105
2142
  }
@@ -2144,6 +2181,7 @@ var useUser = (0, import_zustand4.create)((set) => ({
2144
2181
  getSearchParamsQs,
2145
2182
  getUID,
2146
2183
  hasGeolocation,
2184
+ isElement,
2147
2185
  isPaginationInfo,
2148
2186
  localCollectionDelete,
2149
2187
  localCollectionFetch,
@@ -2203,6 +2241,7 @@ var useUser = (0, import_zustand4.create)((set) => ({
2203
2241
  useGeolocation,
2204
2242
  useIdle,
2205
2243
  useInfiniteLoader,
2244
+ useIntersectionObserver,
2206
2245
  useIsomorphicLayoutEffect,
2207
2246
  useKeyboard,
2208
2247
  useLabel,
package/dist/index.mjs CHANGED
@@ -1116,8 +1116,43 @@ function useInfiniteLoader(items, perPage = 12, delayInMs = 100) {
1116
1116
  return [visibleItems, loadMore, hasMore];
1117
1117
  }
1118
1118
 
1119
+ // src/useIntersectionObserver/useIntersectionObserver.ts
1120
+ import { useCallback as useCallback4, useEffect as useEffect15, useRef as useRef10, useState as useState11 } from "react";
1121
+ function useIntersectionObserver(ref, options = {}) {
1122
+ const {
1123
+ threshold = 1,
1124
+ root = null,
1125
+ rootMargin = "0px"
1126
+ } = options;
1127
+ const [entry, setEntry] = useState11();
1128
+ const previousObserver = useRef10();
1129
+ const init = useCallback4((node) => {
1130
+ if (previousObserver.current) {
1131
+ previousObserver.current.disconnect();
1132
+ previousObserver.current = void 0;
1133
+ }
1134
+ if (isElement(node)) {
1135
+ const observer = new IntersectionObserver(([entry2]) => {
1136
+ setEntry(entry2);
1137
+ }, { threshold, root, rootMargin });
1138
+ observer.observe(node);
1139
+ previousObserver.current = observer;
1140
+ }
1141
+ }, [threshold, root, rootMargin]);
1142
+ useEffect15(() => {
1143
+ if (ref.current) {
1144
+ init(ref.current);
1145
+ }
1146
+ }, [init, ref]);
1147
+ const isIntersecting = entry ? entry.isIntersecting : false;
1148
+ return isIntersecting;
1149
+ }
1150
+ function isElement(node) {
1151
+ return (node == null ? void 0 : node.nodeType) === Node.ELEMENT_NODE;
1152
+ }
1153
+
1119
1154
  // src/useKeyboard/useKeyboard.ts
1120
- import { useEffect as useEffect16 } from "react";
1155
+ import { useEffect as useEffect17 } from "react";
1121
1156
 
1122
1157
  // src/useKeyboard/codes.ts
1123
1158
  var KeyCode = /* @__PURE__ */ ((KeyCode2) => {
@@ -1208,15 +1243,15 @@ var KeyMod = /* @__PURE__ */ ((KeyMod2) => {
1208
1243
  })(KeyMod || {});
1209
1244
 
1210
1245
  // src/useSSR/useSSR.ts
1211
- import { useEffect as useEffect15, useState as useState11 } from "react";
1246
+ import { useEffect as useEffect16, useState as useState12 } from "react";
1212
1247
  var detectIsBrowser = () => {
1213
1248
  return Boolean(
1214
1249
  typeof window !== "undefined" && window.document && window.document.createElement
1215
1250
  );
1216
1251
  };
1217
1252
  function useSSR() {
1218
- const [browser, setBrowser] = useState11(false);
1219
- useEffect15(() => {
1253
+ const [browser, setBrowser] = useState12(false);
1254
+ useEffect16(() => {
1220
1255
  setBrowser(detectIsBrowser());
1221
1256
  }, []);
1222
1257
  return {
@@ -1286,7 +1321,7 @@ var useKeyboard = (handler, keyBindings, options = {}) => {
1286
1321
  }
1287
1322
  handler && handler(event2);
1288
1323
  };
1289
- useEffect16(() => {
1324
+ useEffect17(() => {
1290
1325
  if (!disableGlobalEvent) {
1291
1326
  document.addEventListener(event, eventHandler);
1292
1327
  }
@@ -1374,10 +1409,10 @@ function useModal() {
1374
1409
  }
1375
1410
 
1376
1411
  // src/useMounted/useMounted.ts
1377
- import { useEffect as useEffect17, useState as useState12 } from "react";
1412
+ import { useEffect as useEffect18, useState as useState13 } from "react";
1378
1413
  function useMounted() {
1379
- const [mounted, setMounted] = useState12(false);
1380
- useEffect17(() => {
1414
+ const [mounted, setMounted] = useState13(false);
1415
+ useEffect18(() => {
1381
1416
  setMounted(true);
1382
1417
  }, []);
1383
1418
  return mounted;
@@ -1408,14 +1443,14 @@ function getPaginationInfo(items, page = 1, perPage = 15) {
1408
1443
  }
1409
1444
 
1410
1445
  // src/usePagination/usePagination.ts
1411
- import { useEffect as useEffect18, useState as useState13 } from "react";
1446
+ import { useEffect as useEffect19, useState as useState14 } from "react";
1412
1447
  function usePagination($items, $page = 1, $perPage = 15) {
1413
1448
  const total = $items.length;
1414
- const [page, setPage] = useState13($page);
1415
- const [perPage, setPerPage_] = useState13($perPage);
1416
- const [items, setItems] = useState13(getPagedItems($items, $page, $perPage));
1449
+ const [page, setPage] = useState14($page);
1450
+ const [perPage, setPerPage_] = useState14($perPage);
1451
+ const [items, setItems] = useState14(getPagedItems($items, $page, $perPage));
1417
1452
  const pages = Math.ceil(total / perPage);
1418
- useEffect18(() => {
1453
+ useEffect19(() => {
1419
1454
  setItems(getPagedItems($items, page, perPage));
1420
1455
  }, [$items]);
1421
1456
  function goToPage(page2) {
@@ -1443,13 +1478,13 @@ function usePagination($items, $page = 1, $perPage = 15) {
1443
1478
  }
1444
1479
 
1445
1480
  // src/usePortal/usePortal.ts
1446
- import { useEffect as useEffect19, useState as useState14 } from "react";
1481
+ import { useEffect as useEffect20, useState as useState15 } from "react";
1447
1482
  var namespace = "theme";
1448
1483
  function usePortal(name = getUID(), getContainer) {
1449
1484
  const { isBrowser: isBrowser6 } = useSSR();
1450
1485
  const id = `${namespace}-${name}`;
1451
- const [portal, setPortal] = useState14(isBrowser6 ? createElementWithId(id) : null);
1452
- useEffect19(() => {
1486
+ const [portal, setPortal] = useState15(isBrowser6 ? createElementWithId(id) : null);
1487
+ useEffect20(() => {
1453
1488
  const container = typeof getContainer === "function" ? getContainer() : null;
1454
1489
  const parentElement = container || document.body;
1455
1490
  const element = parentElement.querySelector(`#${id}`) || createElementWithId(id);
@@ -1470,24 +1505,24 @@ function getUID() {
1470
1505
  }
1471
1506
 
1472
1507
  // src/usePrevious/usePrevious.ts
1473
- import { useEffect as useEffect20, useRef as useRef10 } from "react";
1508
+ import { useEffect as useEffect21, useRef as useRef11 } from "react";
1474
1509
  function usePrevious(state) {
1475
- const ref = useRef10(null);
1476
- useEffect20(() => {
1510
+ const ref = useRef11(null);
1511
+ useEffect21(() => {
1477
1512
  ref.current = state;
1478
1513
  });
1479
1514
  return ref.current;
1480
1515
  }
1481
1516
 
1482
1517
  // src/useRealSize/useRealSize.ts
1483
- import { useEffect as useEffect21, useState as useState15 } from "react";
1518
+ import { useEffect as useEffect22, useState as useState16 } from "react";
1484
1519
  function useRealSize(ref) {
1485
- const [state, setState] = useState15({ width: 0, height: 0 });
1520
+ const [state, setState] = useState16({ width: 0, height: 0 });
1486
1521
  const update = () => {
1487
1522
  const { width, height } = getRealSize(ref.current);
1488
1523
  setState({ width, height });
1489
1524
  };
1490
- useEffect21(() => update(), [ref.current]);
1525
+ useEffect22(() => update(), [ref.current]);
1491
1526
  return [state, update];
1492
1527
  }
1493
1528
  function getRealSize(element) {
@@ -1522,9 +1557,9 @@ function useResize(callback, immediate = true) {
1522
1557
  }
1523
1558
 
1524
1559
  // src/useScroll/useScroll.ts
1525
- import { useState as useState16 } from "react";
1560
+ import { useState as useState17 } from "react";
1526
1561
  function useScroll() {
1527
- const [scroll, setScroll] = useState16({ left: 0, top: 0 });
1562
+ const [scroll, setScroll] = useState17({ left: 0, top: 0 });
1528
1563
  const onScroll = () => {
1529
1564
  const left = window.scrollX;
1530
1565
  const top = window.scrollY;
@@ -1576,12 +1611,12 @@ function scrollToY(y = 0) {
1576
1611
  }
1577
1612
 
1578
1613
  // src/useScrolled/useScrolled.ts
1579
- import { useState as useState17 } from "react";
1614
+ import { useState as useState18 } from "react";
1580
1615
  var DEFAULT_CALLBACK = (top, left) => {
1581
1616
  return top > 0;
1582
1617
  };
1583
1618
  function useScrolled(callback = DEFAULT_CALLBACK) {
1584
- const [scrolled, setScrolled] = useState17(false);
1619
+ const [scrolled, setScrolled] = useState18(false);
1585
1620
  const onScrolled = () => {
1586
1621
  const scrolled_ = callback(window.scrollY, window.scrollX);
1587
1622
  if (scrolled !== scrolled_) {
@@ -1598,7 +1633,7 @@ function useScrolled(callback = DEFAULT_CALLBACK) {
1598
1633
  // src/useSearchParams/useSearchParams.ts
1599
1634
  import { isBrowser as isBrowser3 } from "@websolutespa/bom-core";
1600
1635
  import { useRouter } from "next/router";
1601
- import { useCallback as useCallback4, useMemo as useMemo5 } from "react";
1636
+ import { useCallback as useCallback5, useMemo as useMemo5 } from "react";
1602
1637
  function replace_(params) {
1603
1638
  if (window.history) {
1604
1639
  const title = document.title;
@@ -1662,10 +1697,10 @@ function useSearchParams() {
1662
1697
  return value;
1663
1698
  }, [router.asPath]);
1664
1699
  const params = initialValue;
1665
- const replaceParamsSilently = useCallback4((params2) => {
1700
+ const replaceParamsSilently = useCallback5((params2) => {
1666
1701
  replaceSearchParamsSilently(params2);
1667
1702
  }, []);
1668
- const replaceParams = useCallback4((params2) => {
1703
+ const replaceParams = useCallback5((params2) => {
1669
1704
  replaceSearchParams(router, params2);
1670
1705
  }, [router]);
1671
1706
  return { params, replaceParamsSilently, replaceParams };
@@ -1678,7 +1713,7 @@ function useSearchParamsValue(key) {
1678
1713
  return value;
1679
1714
  }, [key, router.asPath]);
1680
1715
  const params = initialValue;
1681
- const replaceParamsSilently = useCallback4((params2) => {
1716
+ const replaceParamsSilently = useCallback5((params2) => {
1682
1717
  replaceSearchParamsSilently(params2);
1683
1718
  }, []);
1684
1719
  return { params, replaceParamsSilently };
@@ -1687,7 +1722,7 @@ function useSearchParamsValue(key) {
1687
1722
  // src/useSearchParamsEncoded/useSearchParamsEncoded.ts
1688
1723
  import { isBrowser as isBrowser4 } from "@websolutespa/bom-core";
1689
1724
  import { useRouter as useRouter2 } from "next/router";
1690
- import { useCallback as useCallback5, useMemo as useMemo6 } from "react";
1725
+ import { useCallback as useCallback6, useMemo as useMemo6 } from "react";
1691
1726
  var USE_ENCRYPTION = true;
1692
1727
  function base64ToString(base64) {
1693
1728
  if (!USE_ENCRYPTION)
@@ -1798,10 +1833,10 @@ function useSearchParamsEncoded(key) {
1798
1833
  return value;
1799
1834
  }, [key, router.asPath]);
1800
1835
  const params = initialValue;
1801
- const replaceParamsSilently = useCallback5((params2) => {
1836
+ const replaceParamsSilently = useCallback6((params2) => {
1802
1837
  replaceSearchParamsEncodedSilently(params2, key);
1803
1838
  }, [key]);
1804
- const replaceParams = useCallback5((params2) => {
1839
+ const replaceParams = useCallback6((params2) => {
1805
1840
  replaceSearchParamsEncoded(router, params2, key);
1806
1841
  }, [key, router]);
1807
1842
  return { params, replaceParamsSilently, replaceParams };
@@ -1810,7 +1845,7 @@ function useSearchParamsEncoded(key) {
1810
1845
  // src/useSearchParamsQs/useSearchParamsQs.ts
1811
1846
  import { isBrowser as isBrowser5, qsDeserializeRaw, qsSerializeRaw } from "@websolutespa/bom-core";
1812
1847
  import { useRouter as useRouter3 } from "next/router";
1813
- import { useCallback as useCallback6, useMemo as useMemo7 } from "react";
1848
+ import { useCallback as useCallback7, useMemo as useMemo7 } from "react";
1814
1849
  function replace(search) {
1815
1850
  if (window.history) {
1816
1851
  const title = document.title;
@@ -1881,22 +1916,22 @@ function useSearchParamsQs(key) {
1881
1916
  return value;
1882
1917
  }, [key, router.asPath]);
1883
1918
  const params = initialValue;
1884
- const replaceParamsSilently = useCallback6((params2) => {
1919
+ const replaceParamsSilently = useCallback7((params2) => {
1885
1920
  replaceSearchParamsQsSilently(params2, key);
1886
1921
  }, [key]);
1887
- const replaceParams = useCallback6((params2) => {
1922
+ const replaceParams = useCallback7((params2) => {
1888
1923
  replaceSearchParamsQs(router, params2, key);
1889
1924
  }, [key, router]);
1890
1925
  return { params, replaceParamsSilently, replaceParams };
1891
1926
  }
1892
1927
 
1893
1928
  // src/useSorting/useSorting.ts
1894
- import { useEffect as useEffect22, useRef as useRef11, useState as useState18 } from "react";
1929
+ import { useEffect as useEffect23, useRef as useRef12, useState as useState19 } from "react";
1895
1930
  function useSorting(items_, callback_, sort_) {
1896
- const [sort, setSort] = useState18(sort_);
1897
- const [items, setItems] = useState18(callback_(items_.slice(), sort));
1898
- const isInitialMount = useRef11(true);
1899
- useEffect22(() => {
1931
+ const [sort, setSort] = useState19(sort_);
1932
+ const [items, setItems] = useState19(callback_(items_.slice(), sort));
1933
+ const isInitialMount = useRef12(true);
1934
+ useEffect23(() => {
1900
1935
  if (isInitialMount.current) {
1901
1936
  isInitialMount.current = false;
1902
1937
  } else {
@@ -1912,18 +1947,18 @@ function useSorting(items_, callback_, sort_) {
1912
1947
  }
1913
1948
 
1914
1949
  // src/useSwiperIndex/useSwiperIndex.ts
1915
- import { useCallback as useCallback7, useEffect as useEffect23, useState as useState19 } from "react";
1950
+ import { useCallback as useCallback8, useEffect as useEffect24, useState as useState20 } from "react";
1916
1951
  import { useSwiper } from "swiper/react";
1917
1952
  function useSwiperIndex() {
1918
1953
  const swiper = useSwiper();
1919
- const [index, setIndex] = useState19(swiper.realIndex);
1920
- const slideTo = useCallback7((index2) => {
1954
+ const [index, setIndex] = useState20(swiper.realIndex);
1955
+ const slideTo = useCallback8((index2) => {
1921
1956
  swiper.slideTo(index2);
1922
1957
  }, [swiper]);
1923
1958
  const onSlideChange = (swiper2) => {
1924
1959
  setIndex(swiper2.realIndex);
1925
1960
  };
1926
- useEffect23(() => {
1961
+ useEffect24(() => {
1927
1962
  if (swiper) {
1928
1963
  swiper.on("slideChange", onSlideChange);
1929
1964
  }
@@ -1937,9 +1972,9 @@ function useSwiperIndex() {
1937
1972
  }
1938
1973
 
1939
1974
  // src/useSyncedRef/useSyncedRef.ts
1940
- import { useMemo as useMemo8, useRef as useRef12 } from "react";
1975
+ import { useMemo as useMemo8, useRef as useRef13 } from "react";
1941
1976
  function useSyncedRef(value) {
1942
- const ref = useRef12(value);
1977
+ const ref = useRef13(value);
1943
1978
  ref.current = value;
1944
1979
  return useMemo8(() => Object.freeze({
1945
1980
  get current() {
@@ -1954,10 +1989,10 @@ function useUnit(unit = "kilometer", locale) {
1954
1989
  }
1955
1990
 
1956
1991
  // src/useUnmountEffect/useUnmountEffect.ts
1957
- import { useEffect as useEffect24 } from "react";
1992
+ import { useEffect as useEffect25 } from "react";
1958
1993
  function useUnmountEffect(effect) {
1959
1994
  const effectRef = useSyncedRef(effect);
1960
- useEffect24(() => () => {
1995
+ useEffect25(() => () => {
1961
1996
  effectRef.current();
1962
1997
  }, []);
1963
1998
  }
@@ -2001,6 +2036,7 @@ export {
2001
2036
  getSearchParamsQs,
2002
2037
  getUID,
2003
2038
  hasGeolocation,
2039
+ isElement,
2004
2040
  isPaginationInfo,
2005
2041
  localCollectionDelete,
2006
2042
  localCollectionFetch,
@@ -2060,6 +2096,7 @@ export {
2060
2096
  useGeolocation,
2061
2097
  useIdle,
2062
2098
  useInfiniteLoader,
2099
+ useIntersectionObserver,
2063
2100
  useIsomorphicLayoutEffect,
2064
2101
  useKeyboard,
2065
2102
  useLabel,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-mixer-hooks",
3
- "version": "1.4.2",
3
+ "version": "1.7.1",
4
4
  "description": "Mixer Hooks module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
package/src/index.ts CHANGED
@@ -26,6 +26,7 @@ export * from './useGeolocation/geolocation.service';
26
26
  export * from './useGeolocation/useGeolocation';
27
27
  export * from './useIdle/useIdle';
28
28
  export * from './useInfiniteLoader/useInfiniteLoader';
29
+ export * from './useIntersectionObserver/useIntersectionObserver';
29
30
  export * from './useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';
30
31
  export * from './useKeyboard/useKeyboard';
31
32
  export * from './useLabel/useLabel';
@@ -67,7 +67,7 @@ describe('useApi', () => {
67
67
  STORE_API: '/bowl/api',
68
68
  STORE_STRATEGY: 'mock',
69
69
  STORE_BEARER: 'STORE_BEARER',
70
- SECRET_COOKIE_PASSWORD: 'SECRET_COOKIE_PASSWORD',
70
+ SECRET_COOKIE_PASSWORD: 'SECRET_COOKIE_PASSWORD_32_CHARS_LONG',
71
71
  HOOKS_SECRET: 'HOOKS_SECRET',
72
72
  };
73
73
  });
@@ -68,7 +68,7 @@ describe('useCollectionApi', () => {
68
68
  STORE_API: '/bowl/api',
69
69
  STORE_STRATEGY: 'mock',
70
70
  STORE_BEARER: 'STORE_BEARER',
71
- SECRET_COOKIE_PASSWORD: 'SECRET_COOKIE_PASSWORD',
71
+ SECRET_COOKIE_PASSWORD: 'SECRET_COOKIE_PASSWORD_32_CHARS_LONG',
72
72
  HOOKS_SECRET: 'HOOKS_SECRET',
73
73
  };
74
74
  });
@@ -58,7 +58,7 @@ describe('useHttp', () => {
58
58
  STORE_API: '/bowl/api',
59
59
  STORE_STRATEGY: 'mock',
60
60
  STORE_BEARER: 'STORE_BEARER',
61
- SECRET_COOKIE_PASSWORD: 'SECRET_COOKIE_PASSWORD',
61
+ SECRET_COOKIE_PASSWORD: 'SECRET_COOKIE_PASSWORD_32_CHARS_LONG',
62
62
  HOOKS_SECRET: 'HOOKS_SECRET',
63
63
  };
64
64
  });
@@ -0,0 +1,38 @@
1
+ import { MutableRefObject, useCallback, useEffect, useRef, useState } from 'react';
2
+
3
+ export function useIntersectionObserver(
4
+ ref: MutableRefObject<Node | undefined>,
5
+ options: IntersectionObserverInit = {}): boolean {
6
+ const {
7
+ threshold = 1,
8
+ root = null,
9
+ rootMargin = '0px',
10
+ } = options;
11
+ const [entry, setEntry] = useState<IntersectionObserverEntry>();
12
+ const previousObserver = useRef<IntersectionObserver>();
13
+ const init = useCallback((node?: Node) => {
14
+ if (previousObserver.current) {
15
+ previousObserver.current.disconnect();
16
+ previousObserver.current = undefined;
17
+ }
18
+ if (isElement(node)) {
19
+ const observer = new IntersectionObserver(([entry]) => {
20
+ setEntry(entry);
21
+ }, { threshold, root, rootMargin });
22
+ observer.observe(node);
23
+ previousObserver.current = observer;
24
+ }
25
+ }, [threshold, root, rootMargin]);
26
+ useEffect(() => {
27
+ if (ref.current) {
28
+ init(ref.current);
29
+ }
30
+ }, [init, ref]);
31
+ // console.log(entry);
32
+ const isIntersecting = entry ? entry.isIntersecting : false;
33
+ return isIntersecting;
34
+ }
35
+
36
+ export function isElement(node?: Node): node is Element {
37
+ return node?.nodeType === Node.ELEMENT_NODE;
38
+ }