@websolutespa/bom-mixer-hooks 1.9.1 → 1.9.3
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 +16 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +75 -34
- package/dist/index.mjs +48 -8
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/useMetaData/useMetaData.tsx +13 -2
- package/src/useScrollDirection/useScrollDirection.ts +37 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @websolutespa/bom-mixer-hooks
|
|
2
2
|
|
|
3
|
+
## 1.9.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0c7f05f: Modified: useMetaData canonical
|
|
8
|
+
- Updated dependencies [0c7f05f]
|
|
9
|
+
- Updated dependencies [0c7f05f]
|
|
10
|
+
- @websolutespa/bom-mixer-models@1.10.1
|
|
11
|
+
- @websolutespa/bom-core@1.8.23
|
|
12
|
+
|
|
13
|
+
## 1.9.2
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 4c2d7a6: Added: useScrollDirection
|
|
18
|
+
|
|
3
19
|
## 1.9.1
|
|
4
20
|
|
|
5
21
|
### Patch 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,
|
|
@@ -1535,9 +1536,13 @@ function MetaDataProvider({ children, metaData }) {
|
|
|
1535
1536
|
const description = (0, import_html_to_text.convert)(((_b = page.meta) == null ? void 0 : _b.description) || page.abstract || "");
|
|
1536
1537
|
const media = ((_c = page.meta) == null ? void 0 : _c.image) || page.media;
|
|
1537
1538
|
const image = media ? (0, import_bom_mixer_models.resolveHref)(media.src || media.url) : brand.logo;
|
|
1538
|
-
|
|
1539
|
+
let canonical = (0, import_bom_mixer_models.resolveHref)(page.href);
|
|
1539
1540
|
const queryIndex = router.asPath.indexOf("?");
|
|
1540
|
-
const
|
|
1541
|
+
const query = queryIndex !== -1 ? router.asPath.substring(queryIndex) : "";
|
|
1542
|
+
if (query.match(/^\?pagination\[page\]=(\d+)$/) && query !== "?pagination[page]=1") {
|
|
1543
|
+
canonical = `${canonical}${query}`;
|
|
1544
|
+
}
|
|
1545
|
+
const url = `${canonical}${query}`;
|
|
1541
1546
|
const alternates = (0, import_react26.useMemo)(() => {
|
|
1542
1547
|
const alternates2 = [];
|
|
1543
1548
|
page.alternates.forEach((alternate) => {
|
|
@@ -1614,6 +1619,12 @@ function MetaDataProvider({ children, metaData }) {
|
|
|
1614
1619
|
},
|
|
1615
1620
|
url: brand.url
|
|
1616
1621
|
/*
|
|
1622
|
+
description,
|
|
1623
|
+
founder,
|
|
1624
|
+
foundingDate,
|
|
1625
|
+
numberOfEmployees,
|
|
1626
|
+
*/
|
|
1627
|
+
/*
|
|
1617
1628
|
foundingDate: '2020-01-01',
|
|
1618
1629
|
numberOfEmployees: {
|
|
1619
1630
|
'@type': 'QuantitativeValue',
|
|
@@ -2116,13 +2127,42 @@ function useScroll() {
|
|
|
2116
2127
|
return scroll;
|
|
2117
2128
|
}
|
|
2118
2129
|
|
|
2119
|
-
// src/
|
|
2130
|
+
// src/useScrollDirection/useScrollDirection.ts
|
|
2120
2131
|
var import_react36 = require("react");
|
|
2132
|
+
var lastScrollTop = 0;
|
|
2121
2133
|
var DEFAULT_CALLBACK = (top, left) => {
|
|
2134
|
+
const scrollTop = window.scrollY || document.documentElement.scrollTop;
|
|
2135
|
+
let direction = 0;
|
|
2136
|
+
if (scrollTop > lastScrollTop) {
|
|
2137
|
+
direction = 1;
|
|
2138
|
+
} else if (scrollTop < lastScrollTop) {
|
|
2139
|
+
direction = -1;
|
|
2140
|
+
}
|
|
2141
|
+
lastScrollTop = scrollTop <= 0 ? 0 : scrollTop;
|
|
2142
|
+
return direction;
|
|
2143
|
+
};
|
|
2144
|
+
function useScrollDirection(callback = DEFAULT_CALLBACK) {
|
|
2145
|
+
const [direction, setDirection] = (0, import_react36.useState)(0);
|
|
2146
|
+
const onScrolled = () => {
|
|
2147
|
+
const direction_ = callback(window.scrollY, window.scrollX);
|
|
2148
|
+
if (direction !== direction_) {
|
|
2149
|
+
setDirection(direction_);
|
|
2150
|
+
}
|
|
2151
|
+
};
|
|
2152
|
+
useEventListener("scroll", onScrolled);
|
|
2153
|
+
useIsomorphicLayoutEffect(() => {
|
|
2154
|
+
onScrolled();
|
|
2155
|
+
}, []);
|
|
2156
|
+
return direction;
|
|
2157
|
+
}
|
|
2158
|
+
|
|
2159
|
+
// src/useScrolled/useScrolled.ts
|
|
2160
|
+
var import_react37 = require("react");
|
|
2161
|
+
var DEFAULT_CALLBACK2 = (top, left) => {
|
|
2122
2162
|
return top > 0;
|
|
2123
2163
|
};
|
|
2124
|
-
function useScrolled(callback =
|
|
2125
|
-
const [scrolled, setScrolled] = (0,
|
|
2164
|
+
function useScrolled(callback = DEFAULT_CALLBACK2) {
|
|
2165
|
+
const [scrolled, setScrolled] = (0, import_react37.useState)(false);
|
|
2126
2166
|
const onScrolled = () => {
|
|
2127
2167
|
const scrolled_ = callback(window.scrollY, window.scrollX);
|
|
2128
2168
|
if (scrolled !== scrolled_) {
|
|
@@ -2174,7 +2214,7 @@ function scrollToY(y = 0) {
|
|
|
2174
2214
|
|
|
2175
2215
|
// src/useSearchParams/useSearchParams.ts
|
|
2176
2216
|
var import_router3 = require("next/router");
|
|
2177
|
-
var
|
|
2217
|
+
var import_react38 = require("react");
|
|
2178
2218
|
function deserialize_(url) {
|
|
2179
2219
|
const components = url.split("?");
|
|
2180
2220
|
const search = components[1] || "";
|
|
@@ -2228,16 +2268,16 @@ function replaceSearchParamsSilently(router, params) {
|
|
|
2228
2268
|
function useSearchParams() {
|
|
2229
2269
|
const router = (0, import_router3.useRouter)();
|
|
2230
2270
|
const params = getSearchParams2(router.asPath);
|
|
2231
|
-
const pushParams = (0,
|
|
2271
|
+
const pushParams = (0, import_react38.useCallback)((params2) => {
|
|
2232
2272
|
pushSearchParams(router, params2);
|
|
2233
2273
|
}, [router]);
|
|
2234
|
-
const pushParamsSilently = (0,
|
|
2274
|
+
const pushParamsSilently = (0, import_react38.useCallback)((params2) => {
|
|
2235
2275
|
pushSearchParamsSilently(router, params2);
|
|
2236
2276
|
}, [router]);
|
|
2237
|
-
const replaceParams = (0,
|
|
2277
|
+
const replaceParams = (0, import_react38.useCallback)((params2) => {
|
|
2238
2278
|
replaceSearchParams(router, params2);
|
|
2239
2279
|
}, [router]);
|
|
2240
|
-
const replaceParamsSilently = (0,
|
|
2280
|
+
const replaceParamsSilently = (0, import_react38.useCallback)((params2) => {
|
|
2241
2281
|
replaceSearchParamsSilently(router, params2);
|
|
2242
2282
|
}, [router]);
|
|
2243
2283
|
return { params, pushParams, pushParamsSilently, replaceParams, replaceParamsSilently };
|
|
@@ -2245,16 +2285,16 @@ function useSearchParams() {
|
|
|
2245
2285
|
function useSearchParamsValue(key) {
|
|
2246
2286
|
const router = (0, import_router3.useRouter)();
|
|
2247
2287
|
const params = getSearchParams2(router.asPath, key);
|
|
2248
|
-
const pushParams = (0,
|
|
2288
|
+
const pushParams = (0, import_react38.useCallback)((params2) => {
|
|
2249
2289
|
pushSearchParams(router, params2);
|
|
2250
2290
|
}, [router]);
|
|
2251
|
-
const pushParamsSilently = (0,
|
|
2291
|
+
const pushParamsSilently = (0, import_react38.useCallback)((params2) => {
|
|
2252
2292
|
pushSearchParamsSilently(router, params2);
|
|
2253
2293
|
}, [router]);
|
|
2254
|
-
const replaceParams = (0,
|
|
2294
|
+
const replaceParams = (0, import_react38.useCallback)((params2) => {
|
|
2255
2295
|
replaceSearchParams(router, params2);
|
|
2256
2296
|
}, [router]);
|
|
2257
|
-
const replaceParamsSilently = (0,
|
|
2297
|
+
const replaceParamsSilently = (0, import_react38.useCallback)((params2) => {
|
|
2258
2298
|
replaceSearchParamsSilently(router, params2);
|
|
2259
2299
|
}, [router]);
|
|
2260
2300
|
return { params, pushParams, pushParamsSilently, replaceParams, replaceParamsSilently };
|
|
@@ -2263,7 +2303,7 @@ function useSearchParamsValue(key) {
|
|
|
2263
2303
|
// src/useSearchParamsEncoded/useSearchParamsEncoded.ts
|
|
2264
2304
|
var import_bom_core11 = require("@websolutespa/bom-core");
|
|
2265
2305
|
var import_router4 = require("next/router");
|
|
2266
|
-
var
|
|
2306
|
+
var import_react39 = require("react");
|
|
2267
2307
|
var USE_ENCRYPTION = true;
|
|
2268
2308
|
function stringToURLSearchParams(url) {
|
|
2269
2309
|
return new URLSearchParams(url);
|
|
@@ -2355,16 +2395,16 @@ function replaceSearchParamsEncodedSilently(router, value, key) {
|
|
|
2355
2395
|
function useSearchParamsEncoded(key) {
|
|
2356
2396
|
const router = (0, import_router4.useRouter)();
|
|
2357
2397
|
const params = getSearchParamsEncoded(router.asPath, key);
|
|
2358
|
-
const pushParams = (0,
|
|
2398
|
+
const pushParams = (0, import_react39.useCallback)((params2) => {
|
|
2359
2399
|
pushSearchParamsEncoded(router, params2, key);
|
|
2360
2400
|
}, [key, router]);
|
|
2361
|
-
const pushParamsSilently = (0,
|
|
2401
|
+
const pushParamsSilently = (0, import_react39.useCallback)((params2) => {
|
|
2362
2402
|
pushSearchParamsEncodedSilently(router, params2, key);
|
|
2363
2403
|
}, [key, router]);
|
|
2364
|
-
const replaceParams = (0,
|
|
2404
|
+
const replaceParams = (0, import_react39.useCallback)((params2) => {
|
|
2365
2405
|
replaceSearchParamsEncoded(router, params2, key);
|
|
2366
2406
|
}, [key, router]);
|
|
2367
|
-
const replaceParamsSilently = (0,
|
|
2407
|
+
const replaceParamsSilently = (0, import_react39.useCallback)((params2) => {
|
|
2368
2408
|
replaceSearchParamsEncodedSilently(router, params2, key);
|
|
2369
2409
|
}, [key, router]);
|
|
2370
2410
|
return { params, pushParams, pushParamsSilently, replaceParams, replaceParamsSilently };
|
|
@@ -2373,7 +2413,7 @@ function useSearchParamsEncoded(key) {
|
|
|
2373
2413
|
// src/useSearchParamsQs/useSearchParamsQs.ts
|
|
2374
2414
|
var import_bom_core12 = require("@websolutespa/bom-core");
|
|
2375
2415
|
var import_router5 = require("next/router");
|
|
2376
|
-
var
|
|
2416
|
+
var import_react40 = require("react");
|
|
2377
2417
|
function deserialize(encoded, key) {
|
|
2378
2418
|
let decoded = {};
|
|
2379
2419
|
if (encoded) {
|
|
@@ -2435,28 +2475,28 @@ function replaceSearchParamsQsSilently(router, value, key) {
|
|
|
2435
2475
|
function useSearchParamsQs(key) {
|
|
2436
2476
|
const router = (0, import_router5.useRouter)();
|
|
2437
2477
|
const params = getSearchParamsQs(router.asPath, key);
|
|
2438
|
-
const pushParams = (0,
|
|
2478
|
+
const pushParams = (0, import_react40.useCallback)((params2) => {
|
|
2439
2479
|
pushSearchParamsQs(router, params2, key);
|
|
2440
2480
|
}, [key, router]);
|
|
2441
|
-
const pushParamsSilently = (0,
|
|
2481
|
+
const pushParamsSilently = (0, import_react40.useCallback)((params2) => {
|
|
2442
2482
|
pushSearchParamsQsSilently(router, params2, key);
|
|
2443
2483
|
}, [key, router]);
|
|
2444
|
-
const replaceParams = (0,
|
|
2484
|
+
const replaceParams = (0, import_react40.useCallback)((params2) => {
|
|
2445
2485
|
replaceSearchParamsQs(router, params2, key);
|
|
2446
2486
|
}, [key, router]);
|
|
2447
|
-
const replaceParamsSilently = (0,
|
|
2487
|
+
const replaceParamsSilently = (0, import_react40.useCallback)((params2) => {
|
|
2448
2488
|
replaceSearchParamsQsSilently(router, params2, key);
|
|
2449
2489
|
}, [key, router]);
|
|
2450
2490
|
return { params, pushParamsSilently, pushParams, replaceParamsSilently, replaceParams };
|
|
2451
2491
|
}
|
|
2452
2492
|
|
|
2453
2493
|
// src/useSorting/useSorting.ts
|
|
2454
|
-
var
|
|
2494
|
+
var import_react41 = require("react");
|
|
2455
2495
|
function useSorting(items_, callback_, sort_) {
|
|
2456
|
-
const [sort, setSort] = (0,
|
|
2457
|
-
const [items, setItems] = (0,
|
|
2458
|
-
const isInitialMount = (0,
|
|
2459
|
-
(0,
|
|
2496
|
+
const [sort, setSort] = (0, import_react41.useState)(sort_);
|
|
2497
|
+
const [items, setItems] = (0, import_react41.useState)(callback_(items_.slice(), sort));
|
|
2498
|
+
const isInitialMount = (0, import_react41.useRef)(true);
|
|
2499
|
+
(0, import_react41.useEffect)(() => {
|
|
2460
2500
|
if (isInitialMount.current) {
|
|
2461
2501
|
isInitialMount.current = false;
|
|
2462
2502
|
} else {
|
|
@@ -2472,11 +2512,11 @@ function useSorting(items_, callback_, sort_) {
|
|
|
2472
2512
|
}
|
|
2473
2513
|
|
|
2474
2514
|
// src/useSyncedRef/useSyncedRef.ts
|
|
2475
|
-
var
|
|
2515
|
+
var import_react42 = require("react");
|
|
2476
2516
|
function useSyncedRef(value) {
|
|
2477
|
-
const ref = (0,
|
|
2517
|
+
const ref = (0, import_react42.useRef)(value);
|
|
2478
2518
|
ref.current = value;
|
|
2479
|
-
return (0,
|
|
2519
|
+
return (0, import_react42.useMemo)(() => Object.freeze({
|
|
2480
2520
|
get current() {
|
|
2481
2521
|
return ref.current;
|
|
2482
2522
|
}
|
|
@@ -2489,10 +2529,10 @@ function useUnit(unit = "kilometer", locale) {
|
|
|
2489
2529
|
}
|
|
2490
2530
|
|
|
2491
2531
|
// src/useUnmountEffect/useUnmountEffect.ts
|
|
2492
|
-
var
|
|
2532
|
+
var import_react43 = require("react");
|
|
2493
2533
|
function useUnmountEffect(effect) {
|
|
2494
2534
|
const effectRef = useSyncedRef(effect);
|
|
2495
|
-
(0,
|
|
2535
|
+
(0, import_react43.useEffect)(() => () => {
|
|
2496
2536
|
effectRef.current();
|
|
2497
2537
|
}, []);
|
|
2498
2538
|
}
|
|
@@ -2618,6 +2658,7 @@ function useUnmountEffect(effect) {
|
|
|
2618
2658
|
useResize,
|
|
2619
2659
|
useSSR,
|
|
2620
2660
|
useScroll,
|
|
2661
|
+
useScrollDirection,
|
|
2621
2662
|
useScrollTo,
|
|
2622
2663
|
useScrolled,
|
|
2623
2664
|
useSearchParams,
|
package/dist/index.mjs
CHANGED
|
@@ -1381,9 +1381,13 @@ function MetaDataProvider({ children, metaData }) {
|
|
|
1381
1381
|
const description = htmlToText(((_b = page.meta) == null ? void 0 : _b.description) || page.abstract || "");
|
|
1382
1382
|
const media = ((_c = page.meta) == null ? void 0 : _c.image) || page.media;
|
|
1383
1383
|
const image = media ? resolveHref(media.src || media.url) : brand.logo;
|
|
1384
|
-
|
|
1384
|
+
let canonical = resolveHref(page.href);
|
|
1385
1385
|
const queryIndex = router.asPath.indexOf("?");
|
|
1386
|
-
const
|
|
1386
|
+
const query = queryIndex !== -1 ? router.asPath.substring(queryIndex) : "";
|
|
1387
|
+
if (query.match(/^\?pagination\[page\]=(\d+)$/) && query !== "?pagination[page]=1") {
|
|
1388
|
+
canonical = `${canonical}${query}`;
|
|
1389
|
+
}
|
|
1390
|
+
const url = `${canonical}${query}`;
|
|
1387
1391
|
const alternates = useMemo5(() => {
|
|
1388
1392
|
const alternates2 = [];
|
|
1389
1393
|
page.alternates.forEach((alternate) => {
|
|
@@ -1460,6 +1464,12 @@ function MetaDataProvider({ children, metaData }) {
|
|
|
1460
1464
|
},
|
|
1461
1465
|
url: brand.url
|
|
1462
1466
|
/*
|
|
1467
|
+
description,
|
|
1468
|
+
founder,
|
|
1469
|
+
foundingDate,
|
|
1470
|
+
numberOfEmployees,
|
|
1471
|
+
*/
|
|
1472
|
+
/*
|
|
1463
1473
|
foundingDate: '2020-01-01',
|
|
1464
1474
|
numberOfEmployees: {
|
|
1465
1475
|
'@type': 'QuantitativeValue',
|
|
@@ -1962,13 +1972,42 @@ function useScroll() {
|
|
|
1962
1972
|
return scroll;
|
|
1963
1973
|
}
|
|
1964
1974
|
|
|
1965
|
-
// src/
|
|
1975
|
+
// src/useScrollDirection/useScrollDirection.ts
|
|
1966
1976
|
import { useState as useState22 } from "react";
|
|
1977
|
+
var lastScrollTop = 0;
|
|
1967
1978
|
var DEFAULT_CALLBACK = (top, left) => {
|
|
1979
|
+
const scrollTop = window.scrollY || document.documentElement.scrollTop;
|
|
1980
|
+
let direction = 0;
|
|
1981
|
+
if (scrollTop > lastScrollTop) {
|
|
1982
|
+
direction = 1;
|
|
1983
|
+
} else if (scrollTop < lastScrollTop) {
|
|
1984
|
+
direction = -1;
|
|
1985
|
+
}
|
|
1986
|
+
lastScrollTop = scrollTop <= 0 ? 0 : scrollTop;
|
|
1987
|
+
return direction;
|
|
1988
|
+
};
|
|
1989
|
+
function useScrollDirection(callback = DEFAULT_CALLBACK) {
|
|
1990
|
+
const [direction, setDirection] = useState22(0);
|
|
1991
|
+
const onScrolled = () => {
|
|
1992
|
+
const direction_ = callback(window.scrollY, window.scrollX);
|
|
1993
|
+
if (direction !== direction_) {
|
|
1994
|
+
setDirection(direction_);
|
|
1995
|
+
}
|
|
1996
|
+
};
|
|
1997
|
+
useEventListener("scroll", onScrolled);
|
|
1998
|
+
useIsomorphicLayoutEffect(() => {
|
|
1999
|
+
onScrolled();
|
|
2000
|
+
}, []);
|
|
2001
|
+
return direction;
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
// src/useScrolled/useScrolled.ts
|
|
2005
|
+
import { useState as useState23 } from "react";
|
|
2006
|
+
var DEFAULT_CALLBACK2 = (top, left) => {
|
|
1968
2007
|
return top > 0;
|
|
1969
2008
|
};
|
|
1970
|
-
function useScrolled(callback =
|
|
1971
|
-
const [scrolled, setScrolled] =
|
|
2009
|
+
function useScrolled(callback = DEFAULT_CALLBACK2) {
|
|
2010
|
+
const [scrolled, setScrolled] = useState23(false);
|
|
1972
2011
|
const onScrolled = () => {
|
|
1973
2012
|
const scrolled_ = callback(window.scrollY, window.scrollX);
|
|
1974
2013
|
if (scrolled !== scrolled_) {
|
|
@@ -2297,10 +2336,10 @@ function useSearchParamsQs(key) {
|
|
|
2297
2336
|
}
|
|
2298
2337
|
|
|
2299
2338
|
// src/useSorting/useSorting.ts
|
|
2300
|
-
import { useEffect as useEffect26, useRef as useRef10, useState as
|
|
2339
|
+
import { useEffect as useEffect26, useRef as useRef10, useState as useState24 } from "react";
|
|
2301
2340
|
function useSorting(items_, callback_, sort_) {
|
|
2302
|
-
const [sort, setSort] =
|
|
2303
|
-
const [items, setItems] =
|
|
2341
|
+
const [sort, setSort] = useState24(sort_);
|
|
2342
|
+
const [items, setItems] = useState24(callback_(items_.slice(), sort));
|
|
2304
2343
|
const isInitialMount = useRef10(true);
|
|
2305
2344
|
useEffect26(() => {
|
|
2306
2345
|
if (isInitialMount.current) {
|
|
@@ -2463,6 +2502,7 @@ export {
|
|
|
2463
2502
|
useResize,
|
|
2464
2503
|
useSSR,
|
|
2465
2504
|
useScroll,
|
|
2505
|
+
useScrollDirection,
|
|
2466
2506
|
useScrollTo,
|
|
2467
2507
|
useScrolled,
|
|
2468
2508
|
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';
|
|
@@ -48,9 +48,14 @@ function MetaDataProvider({ children, metaData }: {
|
|
|
48
48
|
const description = htmlToText(page.meta?.description || page.abstract || '');
|
|
49
49
|
const media = ((page.meta as { image: IMedia } | undefined)?.image || page.media);
|
|
50
50
|
const image = media ? resolveHref(media.src || media.url) : brand.logo;
|
|
51
|
-
|
|
51
|
+
let canonical = resolveHref(page.href);
|
|
52
52
|
const queryIndex = router.asPath.indexOf('?');
|
|
53
|
-
const
|
|
53
|
+
const query = queryIndex !== -1 ? router.asPath.substring(queryIndex) : '';
|
|
54
|
+
if (query.match(/^\?pagination\[page\]=(\d+)$/) && query !== '?pagination[page]=1') {
|
|
55
|
+
canonical = `${canonical}${query}`;
|
|
56
|
+
// title = `${title} - ${query.replace('?pagination[page]=','')}`;
|
|
57
|
+
}
|
|
58
|
+
const url = `${canonical}${query}`;
|
|
54
59
|
const alternates = useMemo(() => {
|
|
55
60
|
const alternates: IAlternate[] = [];
|
|
56
61
|
page.alternates.forEach((alternate: IRoute) => {
|
|
@@ -127,6 +132,12 @@ function MetaDataProvider({ children, metaData }: {
|
|
|
127
132
|
},
|
|
128
133
|
url: brand.url,
|
|
129
134
|
/*
|
|
135
|
+
description,
|
|
136
|
+
founder,
|
|
137
|
+
foundingDate,
|
|
138
|
+
numberOfEmployees,
|
|
139
|
+
*/
|
|
140
|
+
/*
|
|
130
141
|
foundingDate: '2020-01-01',
|
|
131
142
|
numberOfEmployees: {
|
|
132
143
|
'@type': 'QuantitativeValue',
|
|
@@ -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
|
+
}
|