@websolutespa/bom-core 3.0.1 → 3.0.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 +13 -0
- package/dist/index.d.ts +16 -8
- package/dist/index.js +51 -9
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @websolutespa/bom-core
|
|
2
2
|
|
|
3
|
+
## 3.0.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Modified: IRoutes schema
|
|
8
|
+
- Fixing: qsDeserialize
|
|
9
|
+
|
|
10
|
+
## 3.0.2
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Modified: menu decorator MenuCategoryStrategy
|
|
15
|
+
|
|
3
16
|
## 3.0.1
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -383,19 +383,25 @@ type IMarket = IEntity & {
|
|
|
383
383
|
type IRoute = {
|
|
384
384
|
category: IEquatable;
|
|
385
385
|
id: string;
|
|
386
|
-
isDefault?: boolean;
|
|
387
|
-
isRoot?: boolean;
|
|
388
386
|
locale: string;
|
|
389
387
|
market: string;
|
|
390
|
-
media?: IMedia;
|
|
391
|
-
noindex?: boolean;
|
|
392
|
-
order?: number;
|
|
393
388
|
page: IEquatable;
|
|
394
389
|
resolvedCategory: IEquatable;
|
|
395
390
|
schema: string;
|
|
396
|
-
template?: string;
|
|
397
391
|
title: string;
|
|
398
|
-
|
|
392
|
+
_status?: 'published' | 'draft';
|
|
393
|
+
isDefault?: boolean;
|
|
394
|
+
isRoot?: boolean;
|
|
395
|
+
media?: {
|
|
396
|
+
url: string;
|
|
397
|
+
src?: string;
|
|
398
|
+
type: string;
|
|
399
|
+
updatedAt?: Date | string;
|
|
400
|
+
};
|
|
401
|
+
noindex?: boolean;
|
|
402
|
+
order?: number;
|
|
403
|
+
template?: string;
|
|
404
|
+
updatedAt?: Date | string;
|
|
399
405
|
useSplat?: boolean;
|
|
400
406
|
};
|
|
401
407
|
type IRouteCanonical = IRoute & {
|
|
@@ -484,7 +490,9 @@ type IPageUnresolvedRelation = {
|
|
|
484
490
|
|
|
485
491
|
declare enum MenuCategoryStrategy {
|
|
486
492
|
Default = "default",// show hidden categories recursively,
|
|
487
|
-
ExcludeHidden = "exclude-hidden"
|
|
493
|
+
ExcludeHidden = "exclude-hidden",
|
|
494
|
+
ExcludeRoute = "exclude-route",
|
|
495
|
+
ExcludeHiddenAndRoute = "exclude-hidden-and-route"
|
|
488
496
|
}
|
|
489
497
|
type IMenuBase = {
|
|
490
498
|
abstract?: ILocalizable;
|
package/dist/index.js
CHANGED
|
@@ -417,6 +417,8 @@ function isMedia(item) {
|
|
|
417
417
|
var MenuCategoryStrategy = /* @__PURE__ */ ((MenuCategoryStrategy2) => {
|
|
418
418
|
MenuCategoryStrategy2["Default"] = "default";
|
|
419
419
|
MenuCategoryStrategy2["ExcludeHidden"] = "exclude-hidden";
|
|
420
|
+
MenuCategoryStrategy2["ExcludeRoute"] = "exclude-route";
|
|
421
|
+
MenuCategoryStrategy2["ExcludeHiddenAndRoute"] = "exclude-hidden-and-route";
|
|
420
422
|
return MenuCategoryStrategy2;
|
|
421
423
|
})(MenuCategoryStrategy || {});
|
|
422
424
|
function isMenuHref(item) {
|
|
@@ -1439,7 +1441,7 @@ function qsDeserializeKey(value) {
|
|
|
1439
1441
|
return value;
|
|
1440
1442
|
}
|
|
1441
1443
|
function qsDeserializeKeys(key) {
|
|
1442
|
-
const keys = key.replace(/[\]]/g, "").split("[").map((x) => qsDeserializeKey(x));
|
|
1444
|
+
const keys = key.replace(/[\]]/g, "").split("[").map((x) => qsDeserializeKey(x)).filter((x) => Boolean(x));
|
|
1443
1445
|
return keys;
|
|
1444
1446
|
}
|
|
1445
1447
|
function getNextKeyItem(key) {
|
|
@@ -1538,8 +1540,37 @@ function collectRoutes(store, categories, markets, locales, medias) {
|
|
|
1538
1540
|
const routes = [];
|
|
1539
1541
|
if (locales.length > 0 && markets.length > 0) {
|
|
1540
1542
|
const rootCategory = getRootCategory(categories);
|
|
1543
|
+
const activeLocales = locales.filter((locale) => locale.isActive !== false);
|
|
1544
|
+
const activeMarkets = markets.filter((market) => market.isActive !== false);
|
|
1545
|
+
const categoryById = new Map(categories.filter((category) => typeof category.id === "string").map((category) => [category.id, category]));
|
|
1546
|
+
const localeById = new Map(activeLocales.filter((locale) => typeof locale.id === "string").map((locale) => [locale.id, locale]));
|
|
1547
|
+
const mediaById = new Map((medias || []).filter((media) => typeof media.id === "string").map((media) => [media.id, media]));
|
|
1548
|
+
const marketLocales = activeMarkets.flatMap((market) => {
|
|
1549
|
+
const localesForMarket = market.languages && market.languages.length > 0 ? market.languages.map((language) => localeById.get(String(asEntityId(language)))).filter((locale) => locale !== void 0) : activeLocales;
|
|
1550
|
+
return localesForMarket.map((locale) => ({ market, locale }));
|
|
1551
|
+
});
|
|
1552
|
+
const getSegments = (item) => {
|
|
1553
|
+
const routeCategories = [];
|
|
1554
|
+
const segments = [];
|
|
1555
|
+
let parentId = asCategoryId(item.category);
|
|
1556
|
+
while (parentId != null) {
|
|
1557
|
+
const parentCategory = categoryById.get(parentId);
|
|
1558
|
+
if (parentCategory) {
|
|
1559
|
+
segments.unshift({ ...parentCategory });
|
|
1560
|
+
routeCategories.push(parentId);
|
|
1561
|
+
parentId = asCategoryId(parentCategory.category);
|
|
1562
|
+
if (parentId && routeCategories.includes(parentId)) {
|
|
1563
|
+
console.log("ICategory.getParentCategoriesById", "circular reference found", parentId);
|
|
1564
|
+
parentId = void 0;
|
|
1565
|
+
}
|
|
1566
|
+
} else {
|
|
1567
|
+
parentId = void 0;
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
return segments;
|
|
1571
|
+
};
|
|
1541
1572
|
eachCategorized(store, (item, key) => {
|
|
1542
|
-
const segments =
|
|
1573
|
+
const segments = getSegments(item);
|
|
1543
1574
|
const visibleSegments = segments.filter((x) => x.id !== rootCategory?.id && Boolean(x.isHidden) === false);
|
|
1544
1575
|
const visibleCategory = visibleSegments.length > 0 ? visibleSegments[visibleSegments.length - 1] : rootCategory;
|
|
1545
1576
|
if (visibleCategory) {
|
|
@@ -1548,10 +1579,10 @@ function collectRoutes(store, categories, markets, locales, medias) {
|
|
|
1548
1579
|
slugs.push({ slug: item.slug });
|
|
1549
1580
|
}
|
|
1550
1581
|
const isRootCategory = rootCategory && item.category === rootCategory.id && item.isDefault;
|
|
1551
|
-
|
|
1582
|
+
marketLocales.forEach(({ market, locale }) => {
|
|
1552
1583
|
if (hasMarket(item, market)) {
|
|
1553
1584
|
const title = localize(item.title, locale.id);
|
|
1554
|
-
const id = getRouteHref(slugs, market, locale,
|
|
1585
|
+
const id = getRouteHref(slugs, market, locale, activeMarkets, activeLocales);
|
|
1555
1586
|
const {
|
|
1556
1587
|
_status,
|
|
1557
1588
|
category,
|
|
@@ -1565,11 +1596,10 @@ function collectRoutes(store, categories, markets, locales, medias) {
|
|
|
1565
1596
|
const route = {
|
|
1566
1597
|
_status,
|
|
1567
1598
|
category,
|
|
1568
|
-
// id: isDefaultRootCategory ? '/' : id,
|
|
1569
1599
|
id,
|
|
1570
1600
|
locale: locale.id,
|
|
1571
1601
|
market: market.id,
|
|
1572
|
-
media,
|
|
1602
|
+
media: routeMedia(media),
|
|
1573
1603
|
page: item.id,
|
|
1574
1604
|
resolvedCategory: visibleCategory.id,
|
|
1575
1605
|
schema: key,
|
|
@@ -1594,10 +1624,10 @@ function collectRoutes(store, categories, markets, locales, medias) {
|
|
|
1594
1624
|
route.useSplat = true;
|
|
1595
1625
|
}
|
|
1596
1626
|
const mediaId = typeof item.media === "string" ? item.media : void 0;
|
|
1597
|
-
if (
|
|
1598
|
-
const media2 =
|
|
1627
|
+
if (mediaId) {
|
|
1628
|
+
const media2 = mediaById.get(mediaId);
|
|
1599
1629
|
if (media2) {
|
|
1600
|
-
route.media = media2;
|
|
1630
|
+
route.media = routeMedia(media2);
|
|
1601
1631
|
}
|
|
1602
1632
|
}
|
|
1603
1633
|
routes.push(route);
|
|
@@ -1608,6 +1638,18 @@ function collectRoutes(store, categories, markets, locales, medias) {
|
|
|
1608
1638
|
}
|
|
1609
1639
|
return routes;
|
|
1610
1640
|
}
|
|
1641
|
+
function routeMedia(media) {
|
|
1642
|
+
const url = media?.url || media?.src;
|
|
1643
|
+
return media && url ? {
|
|
1644
|
+
// createdAt: media.createdAt,
|
|
1645
|
+
updatedAt: media.updatedAt,
|
|
1646
|
+
// filename: media.filename,
|
|
1647
|
+
// mimeType: media.mimeType,
|
|
1648
|
+
// id: media.id,
|
|
1649
|
+
url,
|
|
1650
|
+
type: media.type
|
|
1651
|
+
} : void 0;
|
|
1652
|
+
}
|
|
1611
1653
|
function eachMarketLocale(markets, locales, callback) {
|
|
1612
1654
|
locales = locales.filter((x) => x.isActive !== false);
|
|
1613
1655
|
markets = markets.filter((x) => x.isActive !== false);
|