@websolutespa/bom-mixer-hooks 1.9.0 → 1.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +95 -48
- package/dist/index.mjs +53 -7
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/useMetaData/useMetaData.tsx +17 -3
- package/src/useScrollDirection/useScrollDirection.ts +37 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @websolutespa/bom-mixer-hooks
|
|
2
2
|
|
|
3
|
+
## 1.9.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4c2d7a6: Added: useScrollDirection
|
|
8
|
+
|
|
9
|
+
## 1.9.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Modified: MetaData Meta added xDefault
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
- @websolutespa/bom-mixer-models@1.9.5
|
|
16
|
+
|
|
3
17
|
## 1.9.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -938,6 +938,8 @@ type Scroll = {
|
|
|
938
938
|
};
|
|
939
939
|
declare function useScroll(): Scroll;
|
|
940
940
|
|
|
941
|
+
declare function useScrollDirection(callback?: (top: number, left: number) => number): number;
|
|
942
|
+
|
|
941
943
|
declare function useScrolled(callback?: (top: number, left: number) => boolean): boolean;
|
|
942
944
|
|
|
943
945
|
declare function useScrollTo(offset?: number): (event: React.MouseEvent<HTMLElement>) => void;
|
|
@@ -1055,4 +1057,4 @@ type WindowSize = {
|
|
|
1055
1057
|
};
|
|
1056
1058
|
declare function useWindowSize(): WindowSize;
|
|
1057
1059
|
|
|
1058
|
-
export { BodyScrollOptions, ClickOutGetContainer, ColorScheme, CurrentStateType, ElementStackItem, ExtraProvider, Filter, FilterMode, FilterParams, FilterValues, GeoLocationSensorState, IExtra, IFilter, IFilterOption, IGeolocationPositionError, ILabelContext, ILayoutContext, ILazyModulesContext, IMetaDataContext, IPageContext, IPageRoute, IPageRouteOptions, IPaginationInfo, IPaginationItem, IPaginationLegacyInfo, IPaginationOptions, IParams, IParamsEncoded, IParamsQs, IUseSearchParamsEncodedResult, IUseSearchParamsQsResult, IUseSearchParamsResult, IUseSearchParamsValueResult, KeyCode, KeyMod, KeyboardOptions, KeyboardResult, LabelProvider, LabelService, LayoutProvider, LazyModulesProvider, MetaDataProvider, PageProvider, SSRState, SizeResult, SizeType, Sorting, UIReducer, UIValue, UseFiltersResultType, UseKeyboard, UseKeyboardHandler, createElementWithId, createGenericContext, detectIsBrowser, filtersToParams, getCurrentPosition, getFilteredItems, getFilters, getMoreItems, getOwnerPaddingRight, getOwnerScrollbarWidth, getPagedItems, getPagedItemsLegacy, getPaginationInfo, getPaginationLegacyInfo, getPreferredColorScheme, getPreferredReducedMotion, getRealSize, getSearchParams, getSearchParamsEncoded, getSearchParamsQs, getUID, hasGeolocation, isElement, isPaginationInfo, isPaginationLegacyInfo, 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, useAutosizeTextArea, useBodyScroll, useBreakpoint, useClickAnyWhere, useClickOut, useCollectionApi, useCollectionApiDelete, useCollectionApiGet, useCollectionApiPatch, useCollectionApiPost, useCollectionApiPut, useColorScheme, useCurrency, useCurrentState, useDateTimeFormat, useDebounce, useDebounceCallback, useDebugChangedProps, useDomObserver, useDrawer, useElementSize, useEventListener, useExtra, useFilters, useFocusTrap, useGeolocation, useIdle, useInfiniteLoader, useIntersectionObserver, useIsomorphicLayoutEffect, useKeyboard, useLabel, useLayout, useLazyModules, useMetaData, useModal, useMounted, useNumber, usePage, usePageLoading, usePagination, usePaginationLegacy, usePortal, usePrevious, useRealSize, useReducedMotion, useReducedMotionLocal, useResize, useSSR, useScroll, useScrollTo, useScrolled, useSearchParams, useSearchParamsEncoded, useSearchParamsQs, useSearchParamsValue, useSorting, useSyncedRef, useUI, useUnit, useUnmountEffect, useWindowSize };
|
|
1060
|
+
export { BodyScrollOptions, ClickOutGetContainer, ColorScheme, CurrentStateType, ElementStackItem, ExtraProvider, Filter, FilterMode, FilterParams, FilterValues, GeoLocationSensorState, IExtra, IFilter, IFilterOption, IGeolocationPositionError, ILabelContext, ILayoutContext, ILazyModulesContext, IMetaDataContext, IPageContext, IPageRoute, IPageRouteOptions, IPaginationInfo, IPaginationItem, IPaginationLegacyInfo, IPaginationOptions, IParams, IParamsEncoded, IParamsQs, IUseSearchParamsEncodedResult, IUseSearchParamsQsResult, IUseSearchParamsResult, IUseSearchParamsValueResult, KeyCode, KeyMod, KeyboardOptions, KeyboardResult, LabelProvider, LabelService, LayoutProvider, LazyModulesProvider, MetaDataProvider, PageProvider, SSRState, SizeResult, SizeType, Sorting, UIReducer, UIValue, UseFiltersResultType, UseKeyboard, UseKeyboardHandler, createElementWithId, createGenericContext, detectIsBrowser, filtersToParams, getCurrentPosition, getFilteredItems, getFilters, getMoreItems, getOwnerPaddingRight, getOwnerScrollbarWidth, getPagedItems, getPagedItemsLegacy, getPaginationInfo, getPaginationLegacyInfo, getPreferredColorScheme, getPreferredReducedMotion, getRealSize, getSearchParams, getSearchParamsEncoded, getSearchParamsQs, getUID, hasGeolocation, isElement, isPaginationInfo, isPaginationLegacyInfo, 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, useAutosizeTextArea, useBodyScroll, useBreakpoint, useClickAnyWhere, useClickOut, useCollectionApi, useCollectionApiDelete, useCollectionApiGet, useCollectionApiPatch, useCollectionApiPost, useCollectionApiPut, useColorScheme, useCurrency, useCurrentState, useDateTimeFormat, useDebounce, useDebounceCallback, useDebugChangedProps, useDomObserver, useDrawer, useElementSize, useEventListener, useExtra, useFilters, useFocusTrap, useGeolocation, useIdle, useInfiniteLoader, useIntersectionObserver, useIsomorphicLayoutEffect, useKeyboard, useLabel, useLayout, useLazyModules, useMetaData, useModal, useMounted, useNumber, usePage, usePageLoading, usePagination, usePaginationLegacy, usePortal, usePrevious, useRealSize, useReducedMotion, useReducedMotionLocal, useResize, useSSR, useScroll, useScrollDirection, useScrollTo, useScrolled, useSearchParams, useSearchParamsEncoded, useSearchParamsQs, useSearchParamsValue, useSorting, useSyncedRef, useUI, useUnit, useUnmountEffect, useWindowSize };
|
package/dist/index.js
CHANGED
|
@@ -189,6 +189,7 @@ __export(src_exports, {
|
|
|
189
189
|
useResize: () => useResize,
|
|
190
190
|
useSSR: () => useSSR,
|
|
191
191
|
useScroll: () => useScroll,
|
|
192
|
+
useScrollDirection: () => useScrollDirection,
|
|
192
193
|
useScrollTo: () => useScrollTo,
|
|
193
194
|
useScrolled: () => useScrolled,
|
|
194
195
|
useSearchParams: () => useSearchParams,
|
|
@@ -1512,6 +1513,7 @@ function LazyModulesProvider({ children, modules }) {
|
|
|
1512
1513
|
}
|
|
1513
1514
|
|
|
1514
1515
|
// src/useMetaData/useMetaData.tsx
|
|
1516
|
+
var import_bom_core6 = require("@websolutespa/bom-core");
|
|
1515
1517
|
var import_bom_mixer_models = require("@websolutespa/bom-mixer-models");
|
|
1516
1518
|
var import_html_to_text = require("html-to-text");
|
|
1517
1519
|
var import_router = require("next/router");
|
|
@@ -1562,6 +1564,20 @@ function MetaDataProvider({ children, metaData }) {
|
|
|
1562
1564
|
});
|
|
1563
1565
|
return alternates2;
|
|
1564
1566
|
}, [layout, page]);
|
|
1567
|
+
const xDefault = (0, import_react26.useMemo)(() => {
|
|
1568
|
+
var _a2, _b2;
|
|
1569
|
+
const xDefaultMarket = ((_a2 = layout.markets.find((x) => x.isDefault)) == null ? void 0 : _a2.id) || import_bom_core6.defaultMarket;
|
|
1570
|
+
const xDefaultLocale = ((_b2 = layout.locales.find((x) => x.isDefault)) == null ? void 0 : _b2.id) || import_bom_core6.defaultLocale;
|
|
1571
|
+
const alternate = page.alternates.find((x) => x.market === xDefaultMarket && x.locale === xDefaultLocale);
|
|
1572
|
+
if (alternate) {
|
|
1573
|
+
return {
|
|
1574
|
+
id: `${alternate.market}-${alternate.locale}`,
|
|
1575
|
+
href: (0, import_bom_mixer_models.resolveHref)(alternate.id),
|
|
1576
|
+
hrefLang: alternate.locale
|
|
1577
|
+
};
|
|
1578
|
+
}
|
|
1579
|
+
return void 0;
|
|
1580
|
+
}, [layout, page]);
|
|
1565
1581
|
const meta = {
|
|
1566
1582
|
title,
|
|
1567
1583
|
description,
|
|
@@ -1571,7 +1587,8 @@ function MetaDataProvider({ children, metaData }) {
|
|
|
1571
1587
|
slug: page.href,
|
|
1572
1588
|
url,
|
|
1573
1589
|
canonical,
|
|
1574
|
-
alternates
|
|
1590
|
+
alternates,
|
|
1591
|
+
xDefault
|
|
1575
1592
|
};
|
|
1576
1593
|
const contactPoint = {
|
|
1577
1594
|
"@type": "ContactPoint",
|
|
@@ -1752,9 +1769,9 @@ function usePageLoading(options = { loading: false }) {
|
|
|
1752
1769
|
}
|
|
1753
1770
|
|
|
1754
1771
|
// src/usePagination/pagination.service.ts
|
|
1755
|
-
var
|
|
1772
|
+
var import_bom_core7 = require("@websolutespa/bom-core");
|
|
1756
1773
|
function isPaginationInfo(item) {
|
|
1757
|
-
return (0,
|
|
1774
|
+
return (0, import_bom_core7.isObject)(item) && (typeof item.page === "number" && typeof item.pages === "number" && typeof item.perPage === "number" && typeof item.total === "number" && (0, import_bom_core7.isArray)(item.items));
|
|
1758
1775
|
}
|
|
1759
1776
|
function getPagedItems(items, page, perPage) {
|
|
1760
1777
|
const from = (page - 1) * perPage;
|
|
@@ -1865,9 +1882,9 @@ function usePagination(items, options) {
|
|
|
1865
1882
|
}
|
|
1866
1883
|
|
|
1867
1884
|
// src/usePaginationLegacy/pagination-legacy.service.ts
|
|
1868
|
-
var
|
|
1885
|
+
var import_bom_core8 = require("@websolutespa/bom-core");
|
|
1869
1886
|
function isPaginationLegacyInfo(item) {
|
|
1870
|
-
return (0,
|
|
1887
|
+
return (0, import_bom_core8.isObject)(item) && (typeof item.page === "number" && typeof item.pages === "number" && typeof item.total === "number" && (0, import_bom_core8.isArray)(item.items));
|
|
1871
1888
|
}
|
|
1872
1889
|
function getPagedItemsLegacy(items, page, perPage) {
|
|
1873
1890
|
const from = (page - 1) * perPage;
|
|
@@ -1985,15 +2002,15 @@ function getComputedValue(style, parentNum) {
|
|
|
1985
2002
|
}
|
|
1986
2003
|
|
|
1987
2004
|
// src/useReducedMotion/useReducedMotion.ts
|
|
1988
|
-
var
|
|
2005
|
+
var import_bom_core9 = require("@websolutespa/bom-core");
|
|
1989
2006
|
var import_zustand3 = require("zustand");
|
|
1990
2007
|
var import_middleware2 = require("zustand/middleware");
|
|
1991
2008
|
var QUERY2 = "(prefers-reduced-motion: no-preference)";
|
|
1992
2009
|
function getPreferredReducedMotion() {
|
|
1993
|
-
return
|
|
2010
|
+
return import_bom_core9.isBrowser && !window.matchMedia(QUERY2).matches;
|
|
1994
2011
|
}
|
|
1995
2012
|
var updateClassList2 = (reducedMotion) => {
|
|
1996
|
-
if (
|
|
2013
|
+
if (import_bom_core9.isBrowser) {
|
|
1997
2014
|
document.documentElement.classList.toggle("--reduced-motion", reducedMotion);
|
|
1998
2015
|
document.documentElement.classList.toggle("--motion", !reducedMotion);
|
|
1999
2016
|
}
|
|
@@ -2100,13 +2117,42 @@ function useScroll() {
|
|
|
2100
2117
|
return scroll;
|
|
2101
2118
|
}
|
|
2102
2119
|
|
|
2103
|
-
// src/
|
|
2120
|
+
// src/useScrollDirection/useScrollDirection.ts
|
|
2104
2121
|
var import_react36 = require("react");
|
|
2122
|
+
var lastScrollTop = 0;
|
|
2105
2123
|
var DEFAULT_CALLBACK = (top, left) => {
|
|
2124
|
+
const scrollTop = window.scrollY || document.documentElement.scrollTop;
|
|
2125
|
+
let direction = 0;
|
|
2126
|
+
if (scrollTop > lastScrollTop) {
|
|
2127
|
+
direction = 1;
|
|
2128
|
+
} else if (scrollTop < lastScrollTop) {
|
|
2129
|
+
direction = -1;
|
|
2130
|
+
}
|
|
2131
|
+
lastScrollTop = scrollTop <= 0 ? 0 : scrollTop;
|
|
2132
|
+
return direction;
|
|
2133
|
+
};
|
|
2134
|
+
function useScrollDirection(callback = DEFAULT_CALLBACK) {
|
|
2135
|
+
const [direction, setDirection] = (0, import_react36.useState)(0);
|
|
2136
|
+
const onScrolled = () => {
|
|
2137
|
+
const direction_ = callback(window.scrollY, window.scrollX);
|
|
2138
|
+
if (direction !== direction_) {
|
|
2139
|
+
setDirection(direction_);
|
|
2140
|
+
}
|
|
2141
|
+
};
|
|
2142
|
+
useEventListener("scroll", onScrolled);
|
|
2143
|
+
useIsomorphicLayoutEffect(() => {
|
|
2144
|
+
onScrolled();
|
|
2145
|
+
}, []);
|
|
2146
|
+
return direction;
|
|
2147
|
+
}
|
|
2148
|
+
|
|
2149
|
+
// src/useScrolled/useScrolled.ts
|
|
2150
|
+
var import_react37 = require("react");
|
|
2151
|
+
var DEFAULT_CALLBACK2 = (top, left) => {
|
|
2106
2152
|
return top > 0;
|
|
2107
2153
|
};
|
|
2108
|
-
function useScrolled(callback =
|
|
2109
|
-
const [scrolled, setScrolled] = (0,
|
|
2154
|
+
function useScrolled(callback = DEFAULT_CALLBACK2) {
|
|
2155
|
+
const [scrolled, setScrolled] = (0, import_react37.useState)(false);
|
|
2110
2156
|
const onScrolled = () => {
|
|
2111
2157
|
const scrolled_ = callback(window.scrollY, window.scrollX);
|
|
2112
2158
|
if (scrolled !== scrolled_) {
|
|
@@ -2121,7 +2167,7 @@ function useScrolled(callback = DEFAULT_CALLBACK) {
|
|
|
2121
2167
|
}
|
|
2122
2168
|
|
|
2123
2169
|
// src/useScrollTo/useScrollTo.ts
|
|
2124
|
-
var
|
|
2170
|
+
var import_bom_core10 = require("@websolutespa/bom-core");
|
|
2125
2171
|
var import_framer_motion = require("framer-motion");
|
|
2126
2172
|
function useScrollTo(offset = 0) {
|
|
2127
2173
|
const scrollToHash = (event) => {
|
|
@@ -2134,7 +2180,7 @@ function useScrollTo(offset = 0) {
|
|
|
2134
2180
|
return scrollToHash;
|
|
2135
2181
|
}
|
|
2136
2182
|
function scrollToSelector(selector, offset = 0) {
|
|
2137
|
-
if (selector &&
|
|
2183
|
+
if (selector && import_bom_core10.isBrowser) {
|
|
2138
2184
|
const element = document.querySelector(selector);
|
|
2139
2185
|
if (element) {
|
|
2140
2186
|
const rect = element.getBoundingClientRect();
|
|
@@ -2158,7 +2204,7 @@ function scrollToY(y = 0) {
|
|
|
2158
2204
|
|
|
2159
2205
|
// src/useSearchParams/useSearchParams.ts
|
|
2160
2206
|
var import_router3 = require("next/router");
|
|
2161
|
-
var
|
|
2207
|
+
var import_react38 = require("react");
|
|
2162
2208
|
function deserialize_(url) {
|
|
2163
2209
|
const components = url.split("?");
|
|
2164
2210
|
const search = components[1] || "";
|
|
@@ -2212,16 +2258,16 @@ function replaceSearchParamsSilently(router, params) {
|
|
|
2212
2258
|
function useSearchParams() {
|
|
2213
2259
|
const router = (0, import_router3.useRouter)();
|
|
2214
2260
|
const params = getSearchParams2(router.asPath);
|
|
2215
|
-
const pushParams = (0,
|
|
2261
|
+
const pushParams = (0, import_react38.useCallback)((params2) => {
|
|
2216
2262
|
pushSearchParams(router, params2);
|
|
2217
2263
|
}, [router]);
|
|
2218
|
-
const pushParamsSilently = (0,
|
|
2264
|
+
const pushParamsSilently = (0, import_react38.useCallback)((params2) => {
|
|
2219
2265
|
pushSearchParamsSilently(router, params2);
|
|
2220
2266
|
}, [router]);
|
|
2221
|
-
const replaceParams = (0,
|
|
2267
|
+
const replaceParams = (0, import_react38.useCallback)((params2) => {
|
|
2222
2268
|
replaceSearchParams(router, params2);
|
|
2223
2269
|
}, [router]);
|
|
2224
|
-
const replaceParamsSilently = (0,
|
|
2270
|
+
const replaceParamsSilently = (0, import_react38.useCallback)((params2) => {
|
|
2225
2271
|
replaceSearchParamsSilently(router, params2);
|
|
2226
2272
|
}, [router]);
|
|
2227
2273
|
return { params, pushParams, pushParamsSilently, replaceParams, replaceParamsSilently };
|
|
@@ -2229,25 +2275,25 @@ function useSearchParams() {
|
|
|
2229
2275
|
function useSearchParamsValue(key) {
|
|
2230
2276
|
const router = (0, import_router3.useRouter)();
|
|
2231
2277
|
const params = getSearchParams2(router.asPath, key);
|
|
2232
|
-
const pushParams = (0,
|
|
2278
|
+
const pushParams = (0, import_react38.useCallback)((params2) => {
|
|
2233
2279
|
pushSearchParams(router, params2);
|
|
2234
2280
|
}, [router]);
|
|
2235
|
-
const pushParamsSilently = (0,
|
|
2281
|
+
const pushParamsSilently = (0, import_react38.useCallback)((params2) => {
|
|
2236
2282
|
pushSearchParamsSilently(router, params2);
|
|
2237
2283
|
}, [router]);
|
|
2238
|
-
const replaceParams = (0,
|
|
2284
|
+
const replaceParams = (0, import_react38.useCallback)((params2) => {
|
|
2239
2285
|
replaceSearchParams(router, params2);
|
|
2240
2286
|
}, [router]);
|
|
2241
|
-
const replaceParamsSilently = (0,
|
|
2287
|
+
const replaceParamsSilently = (0, import_react38.useCallback)((params2) => {
|
|
2242
2288
|
replaceSearchParamsSilently(router, params2);
|
|
2243
2289
|
}, [router]);
|
|
2244
2290
|
return { params, pushParams, pushParamsSilently, replaceParams, replaceParamsSilently };
|
|
2245
2291
|
}
|
|
2246
2292
|
|
|
2247
2293
|
// src/useSearchParamsEncoded/useSearchParamsEncoded.ts
|
|
2248
|
-
var
|
|
2294
|
+
var import_bom_core11 = require("@websolutespa/bom-core");
|
|
2249
2295
|
var import_router4 = require("next/router");
|
|
2250
|
-
var
|
|
2296
|
+
var import_react39 = require("react");
|
|
2251
2297
|
var USE_ENCRYPTION = true;
|
|
2252
2298
|
function stringToURLSearchParams(url) {
|
|
2253
2299
|
return new URLSearchParams(url);
|
|
@@ -2277,7 +2323,7 @@ function serialize_2(url, value, key) {
|
|
|
2277
2323
|
function decode(encoded, key) {
|
|
2278
2324
|
let decoded = null;
|
|
2279
2325
|
if (encoded) {
|
|
2280
|
-
const json = USE_ENCRYPTION ? (0,
|
|
2326
|
+
const json = USE_ENCRYPTION ? (0, import_bom_core11.base64ToString)(encoded) : encoded;
|
|
2281
2327
|
decoded = JSON.parse(json);
|
|
2282
2328
|
}
|
|
2283
2329
|
if (key && decoded) {
|
|
@@ -2294,7 +2340,7 @@ function encode(params, value, key) {
|
|
|
2294
2340
|
params = Object.assign(params, value);
|
|
2295
2341
|
}
|
|
2296
2342
|
const json = JSON.stringify(params);
|
|
2297
|
-
encoded = USE_ENCRYPTION ? (0,
|
|
2343
|
+
encoded = USE_ENCRYPTION ? (0, import_bom_core11.stringToBase64)(json) : json;
|
|
2298
2344
|
return encoded;
|
|
2299
2345
|
}
|
|
2300
2346
|
function searchParamsToObject_2(params) {
|
|
@@ -2339,29 +2385,29 @@ function replaceSearchParamsEncodedSilently(router, value, key) {
|
|
|
2339
2385
|
function useSearchParamsEncoded(key) {
|
|
2340
2386
|
const router = (0, import_router4.useRouter)();
|
|
2341
2387
|
const params = getSearchParamsEncoded(router.asPath, key);
|
|
2342
|
-
const pushParams = (0,
|
|
2388
|
+
const pushParams = (0, import_react39.useCallback)((params2) => {
|
|
2343
2389
|
pushSearchParamsEncoded(router, params2, key);
|
|
2344
2390
|
}, [key, router]);
|
|
2345
|
-
const pushParamsSilently = (0,
|
|
2391
|
+
const pushParamsSilently = (0, import_react39.useCallback)((params2) => {
|
|
2346
2392
|
pushSearchParamsEncodedSilently(router, params2, key);
|
|
2347
2393
|
}, [key, router]);
|
|
2348
|
-
const replaceParams = (0,
|
|
2394
|
+
const replaceParams = (0, import_react39.useCallback)((params2) => {
|
|
2349
2395
|
replaceSearchParamsEncoded(router, params2, key);
|
|
2350
2396
|
}, [key, router]);
|
|
2351
|
-
const replaceParamsSilently = (0,
|
|
2397
|
+
const replaceParamsSilently = (0, import_react39.useCallback)((params2) => {
|
|
2352
2398
|
replaceSearchParamsEncodedSilently(router, params2, key);
|
|
2353
2399
|
}, [key, router]);
|
|
2354
2400
|
return { params, pushParams, pushParamsSilently, replaceParams, replaceParamsSilently };
|
|
2355
2401
|
}
|
|
2356
2402
|
|
|
2357
2403
|
// src/useSearchParamsQs/useSearchParamsQs.ts
|
|
2358
|
-
var
|
|
2404
|
+
var import_bom_core12 = require("@websolutespa/bom-core");
|
|
2359
2405
|
var import_router5 = require("next/router");
|
|
2360
|
-
var
|
|
2406
|
+
var import_react40 = require("react");
|
|
2361
2407
|
function deserialize(encoded, key) {
|
|
2362
2408
|
let decoded = {};
|
|
2363
2409
|
if (encoded) {
|
|
2364
|
-
decoded = (0,
|
|
2410
|
+
decoded = (0, import_bom_core12.qsDeserializeRaw)(encoded);
|
|
2365
2411
|
}
|
|
2366
2412
|
if (key && decoded) {
|
|
2367
2413
|
decoded = decoded[key];
|
|
@@ -2376,7 +2422,7 @@ function encode2(params, value, key) {
|
|
|
2376
2422
|
} else {
|
|
2377
2423
|
params = __spreadValues({}, params);
|
|
2378
2424
|
}
|
|
2379
|
-
const search = (0,
|
|
2425
|
+
const search = (0, import_bom_core12.qsSerializeRaw)(params);
|
|
2380
2426
|
return { search, params };
|
|
2381
2427
|
}
|
|
2382
2428
|
function serialize(search, value, key) {
|
|
@@ -2419,28 +2465,28 @@ function replaceSearchParamsQsSilently(router, value, key) {
|
|
|
2419
2465
|
function useSearchParamsQs(key) {
|
|
2420
2466
|
const router = (0, import_router5.useRouter)();
|
|
2421
2467
|
const params = getSearchParamsQs(router.asPath, key);
|
|
2422
|
-
const pushParams = (0,
|
|
2468
|
+
const pushParams = (0, import_react40.useCallback)((params2) => {
|
|
2423
2469
|
pushSearchParamsQs(router, params2, key);
|
|
2424
2470
|
}, [key, router]);
|
|
2425
|
-
const pushParamsSilently = (0,
|
|
2471
|
+
const pushParamsSilently = (0, import_react40.useCallback)((params2) => {
|
|
2426
2472
|
pushSearchParamsQsSilently(router, params2, key);
|
|
2427
2473
|
}, [key, router]);
|
|
2428
|
-
const replaceParams = (0,
|
|
2474
|
+
const replaceParams = (0, import_react40.useCallback)((params2) => {
|
|
2429
2475
|
replaceSearchParamsQs(router, params2, key);
|
|
2430
2476
|
}, [key, router]);
|
|
2431
|
-
const replaceParamsSilently = (0,
|
|
2477
|
+
const replaceParamsSilently = (0, import_react40.useCallback)((params2) => {
|
|
2432
2478
|
replaceSearchParamsQsSilently(router, params2, key);
|
|
2433
2479
|
}, [key, router]);
|
|
2434
2480
|
return { params, pushParamsSilently, pushParams, replaceParamsSilently, replaceParams };
|
|
2435
2481
|
}
|
|
2436
2482
|
|
|
2437
2483
|
// src/useSorting/useSorting.ts
|
|
2438
|
-
var
|
|
2484
|
+
var import_react41 = require("react");
|
|
2439
2485
|
function useSorting(items_, callback_, sort_) {
|
|
2440
|
-
const [sort, setSort] = (0,
|
|
2441
|
-
const [items, setItems] = (0,
|
|
2442
|
-
const isInitialMount = (0,
|
|
2443
|
-
(0,
|
|
2486
|
+
const [sort, setSort] = (0, import_react41.useState)(sort_);
|
|
2487
|
+
const [items, setItems] = (0, import_react41.useState)(callback_(items_.slice(), sort));
|
|
2488
|
+
const isInitialMount = (0, import_react41.useRef)(true);
|
|
2489
|
+
(0, import_react41.useEffect)(() => {
|
|
2444
2490
|
if (isInitialMount.current) {
|
|
2445
2491
|
isInitialMount.current = false;
|
|
2446
2492
|
} else {
|
|
@@ -2456,11 +2502,11 @@ function useSorting(items_, callback_, sort_) {
|
|
|
2456
2502
|
}
|
|
2457
2503
|
|
|
2458
2504
|
// src/useSyncedRef/useSyncedRef.ts
|
|
2459
|
-
var
|
|
2505
|
+
var import_react42 = require("react");
|
|
2460
2506
|
function useSyncedRef(value) {
|
|
2461
|
-
const ref = (0,
|
|
2507
|
+
const ref = (0, import_react42.useRef)(value);
|
|
2462
2508
|
ref.current = value;
|
|
2463
|
-
return (0,
|
|
2509
|
+
return (0, import_react42.useMemo)(() => Object.freeze({
|
|
2464
2510
|
get current() {
|
|
2465
2511
|
return ref.current;
|
|
2466
2512
|
}
|
|
@@ -2473,10 +2519,10 @@ function useUnit(unit = "kilometer", locale) {
|
|
|
2473
2519
|
}
|
|
2474
2520
|
|
|
2475
2521
|
// src/useUnmountEffect/useUnmountEffect.ts
|
|
2476
|
-
var
|
|
2522
|
+
var import_react43 = require("react");
|
|
2477
2523
|
function useUnmountEffect(effect) {
|
|
2478
2524
|
const effectRef = useSyncedRef(effect);
|
|
2479
|
-
(0,
|
|
2525
|
+
(0, import_react43.useEffect)(() => () => {
|
|
2480
2526
|
effectRef.current();
|
|
2481
2527
|
}, []);
|
|
2482
2528
|
}
|
|
@@ -2602,6 +2648,7 @@ function useUnmountEffect(effect) {
|
|
|
2602
2648
|
useResize,
|
|
2603
2649
|
useSSR,
|
|
2604
2650
|
useScroll,
|
|
2651
|
+
useScrollDirection,
|
|
2605
2652
|
useScrollTo,
|
|
2606
2653
|
useScrolled,
|
|
2607
2654
|
useSearchParams,
|
package/dist/index.mjs
CHANGED
|
@@ -1358,6 +1358,7 @@ function LazyModulesProvider({ children, modules }) {
|
|
|
1358
1358
|
}
|
|
1359
1359
|
|
|
1360
1360
|
// src/useMetaData/useMetaData.tsx
|
|
1361
|
+
import { defaultLocale, defaultMarket } from "@websolutespa/bom-core";
|
|
1361
1362
|
import { getPublicUrl, resolveHref } from "@websolutespa/bom-mixer-models";
|
|
1362
1363
|
import { convert as htmlToText } from "html-to-text";
|
|
1363
1364
|
import { useRouter } from "next/router";
|
|
@@ -1408,6 +1409,20 @@ function MetaDataProvider({ children, metaData }) {
|
|
|
1408
1409
|
});
|
|
1409
1410
|
return alternates2;
|
|
1410
1411
|
}, [layout, page]);
|
|
1412
|
+
const xDefault = useMemo5(() => {
|
|
1413
|
+
var _a2, _b2;
|
|
1414
|
+
const xDefaultMarket = ((_a2 = layout.markets.find((x) => x.isDefault)) == null ? void 0 : _a2.id) || defaultMarket;
|
|
1415
|
+
const xDefaultLocale = ((_b2 = layout.locales.find((x) => x.isDefault)) == null ? void 0 : _b2.id) || defaultLocale;
|
|
1416
|
+
const alternate = page.alternates.find((x) => x.market === xDefaultMarket && x.locale === xDefaultLocale);
|
|
1417
|
+
if (alternate) {
|
|
1418
|
+
return {
|
|
1419
|
+
id: `${alternate.market}-${alternate.locale}`,
|
|
1420
|
+
href: resolveHref(alternate.id),
|
|
1421
|
+
hrefLang: alternate.locale
|
|
1422
|
+
};
|
|
1423
|
+
}
|
|
1424
|
+
return void 0;
|
|
1425
|
+
}, [layout, page]);
|
|
1411
1426
|
const meta = {
|
|
1412
1427
|
title,
|
|
1413
1428
|
description,
|
|
@@ -1417,7 +1432,8 @@ function MetaDataProvider({ children, metaData }) {
|
|
|
1417
1432
|
slug: page.href,
|
|
1418
1433
|
url,
|
|
1419
1434
|
canonical,
|
|
1420
|
-
alternates
|
|
1435
|
+
alternates,
|
|
1436
|
+
xDefault
|
|
1421
1437
|
};
|
|
1422
1438
|
const contactPoint = {
|
|
1423
1439
|
"@type": "ContactPoint",
|
|
@@ -1946,13 +1962,42 @@ function useScroll() {
|
|
|
1946
1962
|
return scroll;
|
|
1947
1963
|
}
|
|
1948
1964
|
|
|
1949
|
-
// src/
|
|
1965
|
+
// src/useScrollDirection/useScrollDirection.ts
|
|
1950
1966
|
import { useState as useState22 } from "react";
|
|
1967
|
+
var lastScrollTop = 0;
|
|
1951
1968
|
var DEFAULT_CALLBACK = (top, left) => {
|
|
1969
|
+
const scrollTop = window.scrollY || document.documentElement.scrollTop;
|
|
1970
|
+
let direction = 0;
|
|
1971
|
+
if (scrollTop > lastScrollTop) {
|
|
1972
|
+
direction = 1;
|
|
1973
|
+
} else if (scrollTop < lastScrollTop) {
|
|
1974
|
+
direction = -1;
|
|
1975
|
+
}
|
|
1976
|
+
lastScrollTop = scrollTop <= 0 ? 0 : scrollTop;
|
|
1977
|
+
return direction;
|
|
1978
|
+
};
|
|
1979
|
+
function useScrollDirection(callback = DEFAULT_CALLBACK) {
|
|
1980
|
+
const [direction, setDirection] = useState22(0);
|
|
1981
|
+
const onScrolled = () => {
|
|
1982
|
+
const direction_ = callback(window.scrollY, window.scrollX);
|
|
1983
|
+
if (direction !== direction_) {
|
|
1984
|
+
setDirection(direction_);
|
|
1985
|
+
}
|
|
1986
|
+
};
|
|
1987
|
+
useEventListener("scroll", onScrolled);
|
|
1988
|
+
useIsomorphicLayoutEffect(() => {
|
|
1989
|
+
onScrolled();
|
|
1990
|
+
}, []);
|
|
1991
|
+
return direction;
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1994
|
+
// src/useScrolled/useScrolled.ts
|
|
1995
|
+
import { useState as useState23 } from "react";
|
|
1996
|
+
var DEFAULT_CALLBACK2 = (top, left) => {
|
|
1952
1997
|
return top > 0;
|
|
1953
1998
|
};
|
|
1954
|
-
function useScrolled(callback =
|
|
1955
|
-
const [scrolled, setScrolled] =
|
|
1999
|
+
function useScrolled(callback = DEFAULT_CALLBACK2) {
|
|
2000
|
+
const [scrolled, setScrolled] = useState23(false);
|
|
1956
2001
|
const onScrolled = () => {
|
|
1957
2002
|
const scrolled_ = callback(window.scrollY, window.scrollX);
|
|
1958
2003
|
if (scrolled !== scrolled_) {
|
|
@@ -2281,10 +2326,10 @@ function useSearchParamsQs(key) {
|
|
|
2281
2326
|
}
|
|
2282
2327
|
|
|
2283
2328
|
// src/useSorting/useSorting.ts
|
|
2284
|
-
import { useEffect as useEffect26, useRef as useRef10, useState as
|
|
2329
|
+
import { useEffect as useEffect26, useRef as useRef10, useState as useState24 } from "react";
|
|
2285
2330
|
function useSorting(items_, callback_, sort_) {
|
|
2286
|
-
const [sort, setSort] =
|
|
2287
|
-
const [items, setItems] =
|
|
2331
|
+
const [sort, setSort] = useState24(sort_);
|
|
2332
|
+
const [items, setItems] = useState24(callback_(items_.slice(), sort));
|
|
2288
2333
|
const isInitialMount = useRef10(true);
|
|
2289
2334
|
useEffect26(() => {
|
|
2290
2335
|
if (isInitialMount.current) {
|
|
@@ -2447,6 +2492,7 @@ export {
|
|
|
2447
2492
|
useResize,
|
|
2448
2493
|
useSSR,
|
|
2449
2494
|
useScroll,
|
|
2495
|
+
useScrollDirection,
|
|
2450
2496
|
useScrollTo,
|
|
2451
2497
|
useScrolled,
|
|
2452
2498
|
useSearchParams,
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -50,6 +50,7 @@ export * from './useReducedMotion/useReducedMotion';
|
|
|
50
50
|
export * from './useReducedMotion/useReducedMotionLocal';
|
|
51
51
|
export * from './useResize/useResize';
|
|
52
52
|
export * from './useScroll/useScroll';
|
|
53
|
+
export * from './useScrollDirection/useScrollDirection';
|
|
53
54
|
export * from './useScrolled/useScrolled';
|
|
54
55
|
export * from './useScrollTo/useScrollTo';
|
|
55
56
|
export * from './useSearchParams/useSearchParams';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IMedia, IRoute } from '@websolutespa/bom-core';
|
|
1
|
+
import { defaultLocale, defaultMarket, IMedia, IRoute } from '@websolutespa/bom-core';
|
|
2
2
|
import { createGenericContext, useLayout, usePage } from '@websolutespa/bom-mixer-hooks';
|
|
3
|
-
import { getPublicUrl, IBrand, IMeta, IMetaData, OpenGraphType, resolveHref, StructuredDataType, TwitterCardType } from '@websolutespa/bom-mixer-models';
|
|
3
|
+
import { getPublicUrl, IAlternate, IBrand, IMeta, IMetaData, OpenGraphType, resolveHref, StructuredDataType, TwitterCardType } from '@websolutespa/bom-mixer-models';
|
|
4
4
|
import { convert as htmlToText } from 'html-to-text';
|
|
5
5
|
import { useRouter } from 'next/router';
|
|
6
6
|
import React, { useMemo } from 'react';
|
|
@@ -52,7 +52,7 @@ function MetaDataProvider({ children, metaData }: {
|
|
|
52
52
|
const queryIndex = router.asPath.indexOf('?');
|
|
53
53
|
const url = `${canonical}${queryIndex !== -1 ? router.asPath.substring(queryIndex) : ''}`;
|
|
54
54
|
const alternates = useMemo(() => {
|
|
55
|
-
const alternates:
|
|
55
|
+
const alternates: IAlternate[] = [];
|
|
56
56
|
page.alternates.forEach((alternate: IRoute) => {
|
|
57
57
|
const market = layout.markets.find(x => x.id === alternate.market);
|
|
58
58
|
if (market) {
|
|
@@ -77,6 +77,19 @@ function MetaDataProvider({ children, metaData }: {
|
|
|
77
77
|
});
|
|
78
78
|
return alternates;
|
|
79
79
|
}, [layout, page]);
|
|
80
|
+
const xDefault = useMemo(() => {
|
|
81
|
+
const xDefaultMarket = layout.markets.find(x => x.isDefault)?.id || defaultMarket;
|
|
82
|
+
const xDefaultLocale = layout.locales.find(x => x.isDefault)?.id || defaultLocale;
|
|
83
|
+
const alternate = page.alternates.find(x => x.market === xDefaultMarket && x.locale === xDefaultLocale);
|
|
84
|
+
if (alternate) {
|
|
85
|
+
return {
|
|
86
|
+
id: `${alternate.market}-${alternate.locale}`,
|
|
87
|
+
href: resolveHref(alternate.id),
|
|
88
|
+
hrefLang: alternate.locale,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return undefined;
|
|
92
|
+
}, [layout, page]);
|
|
80
93
|
const meta: IMeta = {
|
|
81
94
|
title: title,
|
|
82
95
|
description: description,
|
|
@@ -87,6 +100,7 @@ function MetaDataProvider({ children, metaData }: {
|
|
|
87
100
|
url,
|
|
88
101
|
canonical,
|
|
89
102
|
alternates,
|
|
103
|
+
xDefault,
|
|
90
104
|
};
|
|
91
105
|
const contactPoint: ContactPoint = {
|
|
92
106
|
'@type': 'ContactPoint',
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useEventListener, useIsomorphicLayoutEffect } from '@websolutespa/bom-mixer-hooks';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
|
|
4
|
+
let lastScrollTop: number = 0;
|
|
5
|
+
|
|
6
|
+
const DEFAULT_CALLBACK = (top: number, left: number) => {
|
|
7
|
+
const scrollTop = window.scrollY || document.documentElement.scrollTop;
|
|
8
|
+
let direction = 0;
|
|
9
|
+
if (scrollTop > lastScrollTop) {
|
|
10
|
+
direction = 1;
|
|
11
|
+
} else if (scrollTop < lastScrollTop) {
|
|
12
|
+
direction = -1;
|
|
13
|
+
}
|
|
14
|
+
lastScrollTop = scrollTop <= 0 ? 0 : scrollTop;
|
|
15
|
+
return direction;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function useScrollDirection(callback: (top: number, left: number) => number = DEFAULT_CALLBACK): number {
|
|
19
|
+
const [direction, setDirection] = useState<number>(0);
|
|
20
|
+
|
|
21
|
+
const onScrolled = () => {
|
|
22
|
+
const direction_ = callback(window.scrollY, window.scrollX);
|
|
23
|
+
if (direction !== direction_) {
|
|
24
|
+
setDirection(direction_);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
useEventListener('scroll', onScrolled);
|
|
29
|
+
|
|
30
|
+
// Set size at the first client-side load
|
|
31
|
+
useIsomorphicLayoutEffect(() => {
|
|
32
|
+
onScrolled();
|
|
33
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
34
|
+
}, []);
|
|
35
|
+
|
|
36
|
+
return direction;
|
|
37
|
+
}
|