@websolutespa/bom-mixer-hooks 1.9.0 → 1.9.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 +8 -0
- package/dist/index.js +32 -16
- package/dist/index.mjs +17 -1
- package/package.json +1 -1
- package/src/useMetaData/useMetaData.tsx +17 -3
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1512,6 +1512,7 @@ function LazyModulesProvider({ children, modules }) {
|
|
|
1512
1512
|
}
|
|
1513
1513
|
|
|
1514
1514
|
// src/useMetaData/useMetaData.tsx
|
|
1515
|
+
var import_bom_core6 = require("@websolutespa/bom-core");
|
|
1515
1516
|
var import_bom_mixer_models = require("@websolutespa/bom-mixer-models");
|
|
1516
1517
|
var import_html_to_text = require("html-to-text");
|
|
1517
1518
|
var import_router = require("next/router");
|
|
@@ -1562,6 +1563,20 @@ function MetaDataProvider({ children, metaData }) {
|
|
|
1562
1563
|
});
|
|
1563
1564
|
return alternates2;
|
|
1564
1565
|
}, [layout, page]);
|
|
1566
|
+
const xDefault = (0, import_react26.useMemo)(() => {
|
|
1567
|
+
var _a2, _b2;
|
|
1568
|
+
const xDefaultMarket = ((_a2 = layout.markets.find((x) => x.isDefault)) == null ? void 0 : _a2.id) || import_bom_core6.defaultMarket;
|
|
1569
|
+
const xDefaultLocale = ((_b2 = layout.locales.find((x) => x.isDefault)) == null ? void 0 : _b2.id) || import_bom_core6.defaultLocale;
|
|
1570
|
+
const alternate = page.alternates.find((x) => x.market === xDefaultMarket && x.locale === xDefaultLocale);
|
|
1571
|
+
if (alternate) {
|
|
1572
|
+
return {
|
|
1573
|
+
id: `${alternate.market}-${alternate.locale}`,
|
|
1574
|
+
href: (0, import_bom_mixer_models.resolveHref)(alternate.id),
|
|
1575
|
+
hrefLang: alternate.locale
|
|
1576
|
+
};
|
|
1577
|
+
}
|
|
1578
|
+
return void 0;
|
|
1579
|
+
}, [layout, page]);
|
|
1565
1580
|
const meta = {
|
|
1566
1581
|
title,
|
|
1567
1582
|
description,
|
|
@@ -1571,7 +1586,8 @@ function MetaDataProvider({ children, metaData }) {
|
|
|
1571
1586
|
slug: page.href,
|
|
1572
1587
|
url,
|
|
1573
1588
|
canonical,
|
|
1574
|
-
alternates
|
|
1589
|
+
alternates,
|
|
1590
|
+
xDefault
|
|
1575
1591
|
};
|
|
1576
1592
|
const contactPoint = {
|
|
1577
1593
|
"@type": "ContactPoint",
|
|
@@ -1752,9 +1768,9 @@ function usePageLoading(options = { loading: false }) {
|
|
|
1752
1768
|
}
|
|
1753
1769
|
|
|
1754
1770
|
// src/usePagination/pagination.service.ts
|
|
1755
|
-
var
|
|
1771
|
+
var import_bom_core7 = require("@websolutespa/bom-core");
|
|
1756
1772
|
function isPaginationInfo(item) {
|
|
1757
|
-
return (0,
|
|
1773
|
+
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
1774
|
}
|
|
1759
1775
|
function getPagedItems(items, page, perPage) {
|
|
1760
1776
|
const from = (page - 1) * perPage;
|
|
@@ -1865,9 +1881,9 @@ function usePagination(items, options) {
|
|
|
1865
1881
|
}
|
|
1866
1882
|
|
|
1867
1883
|
// src/usePaginationLegacy/pagination-legacy.service.ts
|
|
1868
|
-
var
|
|
1884
|
+
var import_bom_core8 = require("@websolutespa/bom-core");
|
|
1869
1885
|
function isPaginationLegacyInfo(item) {
|
|
1870
|
-
return (0,
|
|
1886
|
+
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
1887
|
}
|
|
1872
1888
|
function getPagedItemsLegacy(items, page, perPage) {
|
|
1873
1889
|
const from = (page - 1) * perPage;
|
|
@@ -1985,15 +2001,15 @@ function getComputedValue(style, parentNum) {
|
|
|
1985
2001
|
}
|
|
1986
2002
|
|
|
1987
2003
|
// src/useReducedMotion/useReducedMotion.ts
|
|
1988
|
-
var
|
|
2004
|
+
var import_bom_core9 = require("@websolutespa/bom-core");
|
|
1989
2005
|
var import_zustand3 = require("zustand");
|
|
1990
2006
|
var import_middleware2 = require("zustand/middleware");
|
|
1991
2007
|
var QUERY2 = "(prefers-reduced-motion: no-preference)";
|
|
1992
2008
|
function getPreferredReducedMotion() {
|
|
1993
|
-
return
|
|
2009
|
+
return import_bom_core9.isBrowser && !window.matchMedia(QUERY2).matches;
|
|
1994
2010
|
}
|
|
1995
2011
|
var updateClassList2 = (reducedMotion) => {
|
|
1996
|
-
if (
|
|
2012
|
+
if (import_bom_core9.isBrowser) {
|
|
1997
2013
|
document.documentElement.classList.toggle("--reduced-motion", reducedMotion);
|
|
1998
2014
|
document.documentElement.classList.toggle("--motion", !reducedMotion);
|
|
1999
2015
|
}
|
|
@@ -2121,7 +2137,7 @@ function useScrolled(callback = DEFAULT_CALLBACK) {
|
|
|
2121
2137
|
}
|
|
2122
2138
|
|
|
2123
2139
|
// src/useScrollTo/useScrollTo.ts
|
|
2124
|
-
var
|
|
2140
|
+
var import_bom_core10 = require("@websolutespa/bom-core");
|
|
2125
2141
|
var import_framer_motion = require("framer-motion");
|
|
2126
2142
|
function useScrollTo(offset = 0) {
|
|
2127
2143
|
const scrollToHash = (event) => {
|
|
@@ -2134,7 +2150,7 @@ function useScrollTo(offset = 0) {
|
|
|
2134
2150
|
return scrollToHash;
|
|
2135
2151
|
}
|
|
2136
2152
|
function scrollToSelector(selector, offset = 0) {
|
|
2137
|
-
if (selector &&
|
|
2153
|
+
if (selector && import_bom_core10.isBrowser) {
|
|
2138
2154
|
const element = document.querySelector(selector);
|
|
2139
2155
|
if (element) {
|
|
2140
2156
|
const rect = element.getBoundingClientRect();
|
|
@@ -2245,7 +2261,7 @@ function useSearchParamsValue(key) {
|
|
|
2245
2261
|
}
|
|
2246
2262
|
|
|
2247
2263
|
// src/useSearchParamsEncoded/useSearchParamsEncoded.ts
|
|
2248
|
-
var
|
|
2264
|
+
var import_bom_core11 = require("@websolutespa/bom-core");
|
|
2249
2265
|
var import_router4 = require("next/router");
|
|
2250
2266
|
var import_react38 = require("react");
|
|
2251
2267
|
var USE_ENCRYPTION = true;
|
|
@@ -2277,7 +2293,7 @@ function serialize_2(url, value, key) {
|
|
|
2277
2293
|
function decode(encoded, key) {
|
|
2278
2294
|
let decoded = null;
|
|
2279
2295
|
if (encoded) {
|
|
2280
|
-
const json = USE_ENCRYPTION ? (0,
|
|
2296
|
+
const json = USE_ENCRYPTION ? (0, import_bom_core11.base64ToString)(encoded) : encoded;
|
|
2281
2297
|
decoded = JSON.parse(json);
|
|
2282
2298
|
}
|
|
2283
2299
|
if (key && decoded) {
|
|
@@ -2294,7 +2310,7 @@ function encode(params, value, key) {
|
|
|
2294
2310
|
params = Object.assign(params, value);
|
|
2295
2311
|
}
|
|
2296
2312
|
const json = JSON.stringify(params);
|
|
2297
|
-
encoded = USE_ENCRYPTION ? (0,
|
|
2313
|
+
encoded = USE_ENCRYPTION ? (0, import_bom_core11.stringToBase64)(json) : json;
|
|
2298
2314
|
return encoded;
|
|
2299
2315
|
}
|
|
2300
2316
|
function searchParamsToObject_2(params) {
|
|
@@ -2355,13 +2371,13 @@ function useSearchParamsEncoded(key) {
|
|
|
2355
2371
|
}
|
|
2356
2372
|
|
|
2357
2373
|
// src/useSearchParamsQs/useSearchParamsQs.ts
|
|
2358
|
-
var
|
|
2374
|
+
var import_bom_core12 = require("@websolutespa/bom-core");
|
|
2359
2375
|
var import_router5 = require("next/router");
|
|
2360
2376
|
var import_react39 = require("react");
|
|
2361
2377
|
function deserialize(encoded, key) {
|
|
2362
2378
|
let decoded = {};
|
|
2363
2379
|
if (encoded) {
|
|
2364
|
-
decoded = (0,
|
|
2380
|
+
decoded = (0, import_bom_core12.qsDeserializeRaw)(encoded);
|
|
2365
2381
|
}
|
|
2366
2382
|
if (key && decoded) {
|
|
2367
2383
|
decoded = decoded[key];
|
|
@@ -2376,7 +2392,7 @@ function encode2(params, value, key) {
|
|
|
2376
2392
|
} else {
|
|
2377
2393
|
params = __spreadValues({}, params);
|
|
2378
2394
|
}
|
|
2379
|
-
const search = (0,
|
|
2395
|
+
const search = (0, import_bom_core12.qsSerializeRaw)(params);
|
|
2380
2396
|
return { search, params };
|
|
2381
2397
|
}
|
|
2382
2398
|
function serialize(search, value, key) {
|
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",
|
package/package.json
CHANGED
|
@@ -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',
|