@websolutespa/bom-mixer-models 1.3.0 → 1.5.0
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 +12 -0
- package/dist/index.d.ts +15 -2
- package/dist/index.js +75 -28
- package/dist/index.mjs +67 -25
- package/package.json +1 -1
- package/src/layout/layout.service.ts +7 -7
- package/src/lazy/lazy.ts +50 -0
- package/src/page/page.service.ts +10 -1
- package/src/route/route.service.ts +31 -20
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ILayout, IPage, IRouteParams, ISchema, IEquatable, IMedia, QueryParams, ICategory, ICategorized, IOption, INamedEntity, ILabel, ILocale, IMarket, IMenu, ValueOf, IPageResult, IRoute, IRouteLink, IQuerable, IRedirect, IEntity } from '@websolutespa/bom-core';
|
|
1
|
+
import { ILayout, IPage, IRouteParams, ISchema, IEquatable, IMedia, QueryParams, ICategory, ICategorized, IOption, INamedEntity, ILabel, PageProps, ILocale, IMarket, IMenu, ValueOf, IPageResult, IRoute, IRouteLink, IQuerable, IRedirect, IEntity } from '@websolutespa/bom-core';
|
|
2
2
|
import { AppProps } from 'next/app';
|
|
3
3
|
import { FC, ReactNode, ComponentType } from 'react';
|
|
4
|
+
import { DynamicOptions, Loader } from 'next/dynamic';
|
|
4
5
|
import { HtmlProps } from 'next/dist/shared/lib/html-context';
|
|
5
6
|
import { RenderPageResult } from 'next/dist/shared/lib/utils';
|
|
6
7
|
import { NextRequest, NextFetchEvent, NextResponse } from 'next/server';
|
|
@@ -194,6 +195,15 @@ type ILazyComponentProps = {
|
|
|
194
195
|
index: number;
|
|
195
196
|
};
|
|
196
197
|
type ILazyModules = Record<string, ComponentType<ILazyProps<any>>>;
|
|
198
|
+
type ILazyComponentFunc<P = {}> = DynamicOptions<P> | Loader<P>;
|
|
199
|
+
type ILazyFuncProps<T> = PageProps & {
|
|
200
|
+
component: T & ILazyComponent;
|
|
201
|
+
};
|
|
202
|
+
type ILazyStaticPropsFunc<T = any> = (props: ILazyFuncProps<T>) => Promise<T & ILazyComponent>;
|
|
203
|
+
type ILazyStaticProps = Record<string, ILazyStaticPropsFunc>;
|
|
204
|
+
declare const LAZY_PROPS: ILazyStaticProps;
|
|
205
|
+
declare function withLazyProps<T>(key: string, getComponentProps: ILazyStaticPropsFunc<T>): void;
|
|
206
|
+
declare function getDecoratedComponents(props: PageProps): Promise<void>;
|
|
197
207
|
|
|
198
208
|
type ILink = {
|
|
199
209
|
href: string;
|
|
@@ -264,6 +274,8 @@ declare function getErrorPageLayout(): Promise<{
|
|
|
264
274
|
layout: ILayout;
|
|
265
275
|
page: IPage;
|
|
266
276
|
}>;
|
|
277
|
+
type PartialPageProps<T extends ICategorized, B> = Omit<PageProps<T>, 'page'> & Partial<Pick<PageProps<T>, 'page'>> & B;
|
|
278
|
+
declare function getPageProps<T extends ICategorized, B = any>(props: PartialPageProps<T, B>): Promise<PageProps<T> & B>;
|
|
267
279
|
|
|
268
280
|
declare function getProvinces(locale?: string): Promise<INamedEntity[]>;
|
|
269
281
|
declare function getProvince(id: IEquatable, params?: QueryParams): Promise<INamedEntity | undefined>;
|
|
@@ -291,6 +303,7 @@ declare function getRoutesForTemplates(templates: string[], market?: string, loc
|
|
|
291
303
|
declare function getStaticPathsForSchema(schema: string): Promise<StaticPath[]>;
|
|
292
304
|
declare function getBreadcrumbFromSegments(segments: ICategory[], market?: string, locale?: string): Promise<IRouteLink[]>;
|
|
293
305
|
declare function getRouteLinkTree(market?: string, locale?: string): Promise<IRouteLink | undefined>;
|
|
306
|
+
declare function newRouteLink(category: ICategory, route?: IRoute, locale?: string): IRouteLink;
|
|
294
307
|
declare function categoryToRouteLink(routes: IRoute[], categories: ICategory[], category: ICategory, locale?: string): IRouteLink;
|
|
295
308
|
declare function resolveRoute(route: IRoute & {
|
|
296
309
|
splat?: string;
|
|
@@ -324,4 +337,4 @@ type IModelStore = {
|
|
|
324
337
|
[key: string]: IQuerable<IEntity>;
|
|
325
338
|
};
|
|
326
339
|
|
|
327
|
-
export { IAddress, IAddressOptions, IAppProps, IApplication, IApplicationProps, ICartAddItem, ICartItem, ICheckout, ICheckoutDelivery, ICheckoutDiscount, ICheckoutInfo, ICheckoutItem, ICheckoutPartial, ICheckoutPayment, ICheckoutPaymentRedirect, ICheckoutStore, ICompanyAddress, IFeatureType, IKeyedList, ILazyComponent, ILazyComponentProps, ILazyModules, ILazyProps, ILazyableProps, ILazyedProps, ILink, IList, IModelStore, IOrder, IOrderDetail, IOrderStatus, IOrderStatusValue, ISiteMap, IUser, IUserAddress, IUserChangePassword, IUserForgot, IUserLogin, IUserRegister, StaticPath, categoryToRouteLink, findManyPages, findOnePage, getBreadcrumbFromSegments, getCategories, getCategory, getCountries, getCountry, getDeliveries, getErrorPageLayout, getFeatureType, getFeatureTypes, getInfo, getItems, getLabel, getLabels, getLayout, getListByKeys, getLists, getLocale, getLocaleFromProps, getLocales, getMarket, getMarkets, getMenu, getMenus, getOrder, getOrders, getPage, getPageCategory, getPageRoutes, getPayment, getPayments, getProvince, getProvinces, getRegion, getRegions, getRoute, getRouteLinkTree, getRoutes, getRoutesForSchemas, getRoutesForTemplates, getSegments, getSiteMapIndex, getSiteMapIndexProps, getSiteMapXML, getSiteMapXMLProps, getSiteMapXSL, getSiteMapXSLProps, getStaticPathsForSchema, getStores, resolveLabel, resolveRoute, routeInterceptor, routeRevalidateHandler, setDiscountCode, updateCheckout };
|
|
340
|
+
export { IAddress, IAddressOptions, IAppProps, IApplication, IApplicationProps, ICartAddItem, ICartItem, ICheckout, ICheckoutDelivery, ICheckoutDiscount, ICheckoutInfo, ICheckoutItem, ICheckoutPartial, ICheckoutPayment, ICheckoutPaymentRedirect, ICheckoutStore, ICompanyAddress, IFeatureType, IKeyedList, ILazyComponent, ILazyComponentFunc, ILazyComponentProps, ILazyFuncProps, ILazyModules, ILazyProps, ILazyStaticProps, ILazyStaticPropsFunc, ILazyableProps, ILazyedProps, ILink, IList, IModelStore, IOrder, IOrderDetail, IOrderStatus, IOrderStatusValue, ISiteMap, IUser, IUserAddress, IUserChangePassword, IUserForgot, IUserLogin, IUserRegister, LAZY_PROPS, PartialPageProps, StaticPath, categoryToRouteLink, findManyPages, findOnePage, getBreadcrumbFromSegments, getCategories, getCategory, getCountries, getCountry, getDecoratedComponents, getDeliveries, getErrorPageLayout, getFeatureType, getFeatureTypes, getInfo, getItems, getLabel, getLabels, getLayout, getListByKeys, getLists, getLocale, getLocaleFromProps, getLocales, getMarket, getMarkets, getMenu, getMenus, getOrder, getOrders, getPage, getPageCategory, getPageProps, getPageRoutes, getPayment, getPayments, getProvince, getProvinces, getRegion, getRegions, getRoute, getRouteLinkTree, getRoutes, getRoutesForSchemas, getRoutesForTemplates, getSegments, getSiteMapIndex, getSiteMapIndexProps, getSiteMapXML, getSiteMapXMLProps, getSiteMapXSL, getSiteMapXSLProps, getStaticPathsForSchema, getStores, newRouteLink, resolveLabel, resolveRoute, routeInterceptor, routeRevalidateHandler, setDiscountCode, updateCheckout, withLazyProps };
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
IOrderStatus: () => IOrderStatus,
|
|
24
|
+
LAZY_PROPS: () => LAZY_PROPS,
|
|
24
25
|
categoryToRouteLink: () => categoryToRouteLink,
|
|
25
26
|
findManyPages: () => findManyPages,
|
|
26
27
|
findOnePage: () => findOnePage,
|
|
@@ -29,6 +30,7 @@ __export(src_exports, {
|
|
|
29
30
|
getCategory: () => getCategory,
|
|
30
31
|
getCountries: () => getCountries,
|
|
31
32
|
getCountry: () => getCountry,
|
|
33
|
+
getDecoratedComponents: () => getDecoratedComponents,
|
|
32
34
|
getDeliveries: () => getDeliveries,
|
|
33
35
|
getErrorPageLayout: () => getErrorPageLayout,
|
|
34
36
|
getFeatureType: () => getFeatureType,
|
|
@@ -51,6 +53,7 @@ __export(src_exports, {
|
|
|
51
53
|
getOrders: () => getOrders,
|
|
52
54
|
getPage: () => getPage,
|
|
53
55
|
getPageCategory: () => getPageCategory,
|
|
56
|
+
getPageProps: () => getPageProps,
|
|
54
57
|
getPageRoutes: () => getPageRoutes,
|
|
55
58
|
getPayment: () => getPayment,
|
|
56
59
|
getPayments: () => getPayments,
|
|
@@ -72,12 +75,14 @@ __export(src_exports, {
|
|
|
72
75
|
getSiteMapXSLProps: () => getSiteMapXSLProps,
|
|
73
76
|
getStaticPathsForSchema: () => getStaticPathsForSchema,
|
|
74
77
|
getStores: () => getStores,
|
|
78
|
+
newRouteLink: () => newRouteLink,
|
|
75
79
|
resolveLabel: () => resolveLabel,
|
|
76
80
|
resolveRoute: () => resolveRoute,
|
|
77
81
|
routeInterceptor: () => routeInterceptor,
|
|
78
82
|
routeRevalidateHandler: () => routeRevalidateHandler,
|
|
79
83
|
setDiscountCode: () => setDiscountCode,
|
|
80
|
-
updateCheckout: () => updateCheckout
|
|
84
|
+
updateCheckout: () => updateCheckout,
|
|
85
|
+
withLazyProps: () => withLazyProps
|
|
81
86
|
});
|
|
82
87
|
module.exports = __toCommonJS(src_exports);
|
|
83
88
|
|
|
@@ -225,18 +230,15 @@ async function getBreadcrumbFromSegments(segments, market = "ww", locale = "en")
|
|
|
225
230
|
const route = routes.find(
|
|
226
231
|
(r) => r.category === segment.id
|
|
227
232
|
);
|
|
228
|
-
const href = route ? route.id.toString() : "/#";
|
|
229
|
-
return { segment, href };
|
|
230
|
-
}).map((x) => {
|
|
231
|
-
const segment = x.segment;
|
|
232
|
-
const href = x.href;
|
|
233
|
-
const title = (0, import_bom_core2.localize)(segment.title || "untitled", locale);
|
|
234
233
|
return {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
href,
|
|
238
|
-
items: []
|
|
234
|
+
segment,
|
|
235
|
+
route
|
|
239
236
|
};
|
|
237
|
+
}).map((x) => {
|
|
238
|
+
const category = x.segment;
|
|
239
|
+
const route = x.route;
|
|
240
|
+
const routeLink = newRouteLink(category, route, locale);
|
|
241
|
+
return routeLink;
|
|
240
242
|
});
|
|
241
243
|
return tree;
|
|
242
244
|
}
|
|
@@ -262,24 +264,35 @@ async function getRouteLinkTree(market = "ww", locale = "en") {
|
|
|
262
264
|
}
|
|
263
265
|
return void 0;
|
|
264
266
|
}
|
|
267
|
+
function newRouteLink(category, route, locale = "en") {
|
|
268
|
+
const href = route && route.id ? route.id.toString() : "/";
|
|
269
|
+
const id = route?.page || category.id;
|
|
270
|
+
const media = category.media || route?.media;
|
|
271
|
+
const schema = route?.schema || category?.schema || "unknown";
|
|
272
|
+
const title = (0, import_bom_core2.localize)(category.title || route?.title || "untitled", locale);
|
|
273
|
+
const routeLink = {
|
|
274
|
+
category: category.id,
|
|
275
|
+
href,
|
|
276
|
+
id,
|
|
277
|
+
items: [],
|
|
278
|
+
media,
|
|
279
|
+
schema,
|
|
280
|
+
title
|
|
281
|
+
};
|
|
282
|
+
return routeLink;
|
|
283
|
+
}
|
|
265
284
|
function categoryToRouteLink(routes, categories, category, locale = "en") {
|
|
266
285
|
const route = routes.find(
|
|
267
286
|
(r) => r.category === category.id
|
|
268
287
|
);
|
|
269
|
-
const href = route && route.id ? route.id.toString() : "/";
|
|
270
|
-
const title = (0, import_bom_core2.localize)(category.title || "untitled", locale);
|
|
271
288
|
const rootCategory = (0, import_bom_core2.getRootCategory)(categories);
|
|
272
289
|
const childCategories = categories.filter((x) => {
|
|
273
290
|
const parentId = x.category && typeof x.category === "object" ? x.category["id"] : x.category;
|
|
274
291
|
return rootCategory && category.id === rootCategory.id ? x.id !== rootCategory.id && (parentId === category.id || !parentId) : parentId === category.id;
|
|
275
292
|
});
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
href,
|
|
280
|
-
media: category.media,
|
|
281
|
-
items: childCategories.map((x) => categoryToRouteLink(routes, categories, x, locale))
|
|
282
|
-
};
|
|
293
|
+
const routeLink = newRouteLink(category, route, locale);
|
|
294
|
+
routeLink.items = childCategories.map((x) => categoryToRouteLink(routes, categories, x, locale));
|
|
295
|
+
return routeLink;
|
|
283
296
|
}
|
|
284
297
|
function resolveRoute(route) {
|
|
285
298
|
const routepath = route.template ? route.template : route.schema;
|
|
@@ -677,13 +690,13 @@ async function getLayout(market, locale) {
|
|
|
677
690
|
const tree = await getRouteLinkTree(market, locale);
|
|
678
691
|
const firstLevelRoutes = tree?.items || [];
|
|
679
692
|
const flatTopLevelRoutes = tree ? [tree, ...firstLevelRoutes] : [];
|
|
680
|
-
const topLevelRoutes = flatTopLevelRoutes.reduce((object,
|
|
681
|
-
object[
|
|
693
|
+
const topLevelRoutes = flatTopLevelRoutes.reduce((object, routeLink) => {
|
|
694
|
+
object[routeLink.schema] = routeLink;
|
|
682
695
|
return object;
|
|
683
696
|
}, {});
|
|
684
|
-
const topLevelHrefs = flatTopLevelRoutes.reduce((object,
|
|
685
|
-
if (
|
|
686
|
-
object[
|
|
697
|
+
const topLevelHrefs = flatTopLevelRoutes.reduce((object, routeLink) => {
|
|
698
|
+
if (routeLink.href) {
|
|
699
|
+
object[routeLink.schema] = routeLink.href;
|
|
687
700
|
}
|
|
688
701
|
return object;
|
|
689
702
|
}, {});
|
|
@@ -705,6 +718,28 @@ async function getLayout(market, locale) {
|
|
|
705
718
|
};
|
|
706
719
|
}
|
|
707
720
|
|
|
721
|
+
// src/lazy/lazy.ts
|
|
722
|
+
var LAZY_PROPS = {};
|
|
723
|
+
function withLazyProps(key, getComponentProps) {
|
|
724
|
+
LAZY_PROPS[key] = getComponentProps;
|
|
725
|
+
}
|
|
726
|
+
async function getDecoratedComponents(props) {
|
|
727
|
+
const page = props.page;
|
|
728
|
+
if (page.components) {
|
|
729
|
+
const decoratedComponents = [];
|
|
730
|
+
for (const component of page.components) {
|
|
731
|
+
const getComponentProps = LAZY_PROPS[component.schema];
|
|
732
|
+
if (typeof getComponentProps === "function") {
|
|
733
|
+
const decoratedComponent = await getComponentProps({ ...props, component });
|
|
734
|
+
decoratedComponents.push(decoratedComponent);
|
|
735
|
+
} else {
|
|
736
|
+
decoratedComponents.push(component);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
page.components = decoratedComponents;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
|
|
708
743
|
// src/list/list.service.ts
|
|
709
744
|
var import_bom_mixer_store11 = require("@websolutespa/bom-mixer-store");
|
|
710
745
|
async function getLists(locale) {
|
|
@@ -1045,6 +1080,7 @@ async function getOrder(id, market, locale) {
|
|
|
1045
1080
|
}
|
|
1046
1081
|
|
|
1047
1082
|
// src/page/page.service.ts
|
|
1083
|
+
var import_bom_core3 = require("@websolutespa/bom-core");
|
|
1048
1084
|
var import_bom_mixer_store12 = require("@websolutespa/bom-mixer-store");
|
|
1049
1085
|
async function findOnePage(schema, id, params) {
|
|
1050
1086
|
const store = await (0, import_bom_mixer_store12.getStore)();
|
|
@@ -1179,6 +1215,12 @@ async function getErrorPageLayout() {
|
|
|
1179
1215
|
};
|
|
1180
1216
|
return { layout, page };
|
|
1181
1217
|
}
|
|
1218
|
+
async function getPageProps(props) {
|
|
1219
|
+
if (props.page) {
|
|
1220
|
+
await getDecoratedComponents(props);
|
|
1221
|
+
}
|
|
1222
|
+
return (0, import_bom_core3.asServerProps)(props);
|
|
1223
|
+
}
|
|
1182
1224
|
|
|
1183
1225
|
// src/route/route-revalidate.handler.ts
|
|
1184
1226
|
var import_bom_mixer_store13 = require("@websolutespa/bom-mixer-store");
|
|
@@ -1243,7 +1285,7 @@ async function routeInterceptor(request, next) {
|
|
|
1243
1285
|
}
|
|
1244
1286
|
|
|
1245
1287
|
// src/sitemap/sitemap.service.ts
|
|
1246
|
-
var
|
|
1288
|
+
var import_bom_core4 = require("@websolutespa/bom-core");
|
|
1247
1289
|
async function getSiteMapIndex(origin) {
|
|
1248
1290
|
let markets = await getMarkets();
|
|
1249
1291
|
let locales = await getLocales();
|
|
@@ -1254,7 +1296,7 @@ async function getSiteMapIndex(origin) {
|
|
|
1254
1296
|
const getTime = (date) => {
|
|
1255
1297
|
return typeof date !== "undefined" ? (typeof date === "string" ? new Date(date) : date).getTime() : 0;
|
|
1256
1298
|
};
|
|
1257
|
-
(0,
|
|
1299
|
+
(0, import_bom_core4.eachMarketLocale)(markets, locales, (market, locale, markets2, locales2) => {
|
|
1258
1300
|
const sitemapRoutes = routes.filter((x) => x.market === market.id && x.locale === locale.id);
|
|
1259
1301
|
sitemapRoutes.sort((a, b) => getTime(a.updatedAt) - getTime(b.updatedAt));
|
|
1260
1302
|
sitemaps.push({
|
|
@@ -1546,6 +1588,7 @@ var getSiteMapXSLProps = async (context) => {
|
|
|
1546
1588
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1547
1589
|
0 && (module.exports = {
|
|
1548
1590
|
IOrderStatus,
|
|
1591
|
+
LAZY_PROPS,
|
|
1549
1592
|
categoryToRouteLink,
|
|
1550
1593
|
findManyPages,
|
|
1551
1594
|
findOnePage,
|
|
@@ -1554,6 +1597,7 @@ var getSiteMapXSLProps = async (context) => {
|
|
|
1554
1597
|
getCategory,
|
|
1555
1598
|
getCountries,
|
|
1556
1599
|
getCountry,
|
|
1600
|
+
getDecoratedComponents,
|
|
1557
1601
|
getDeliveries,
|
|
1558
1602
|
getErrorPageLayout,
|
|
1559
1603
|
getFeatureType,
|
|
@@ -1576,6 +1620,7 @@ var getSiteMapXSLProps = async (context) => {
|
|
|
1576
1620
|
getOrders,
|
|
1577
1621
|
getPage,
|
|
1578
1622
|
getPageCategory,
|
|
1623
|
+
getPageProps,
|
|
1579
1624
|
getPageRoutes,
|
|
1580
1625
|
getPayment,
|
|
1581
1626
|
getPayments,
|
|
@@ -1597,10 +1642,12 @@ var getSiteMapXSLProps = async (context) => {
|
|
|
1597
1642
|
getSiteMapXSLProps,
|
|
1598
1643
|
getStaticPathsForSchema,
|
|
1599
1644
|
getStores,
|
|
1645
|
+
newRouteLink,
|
|
1600
1646
|
resolveLabel,
|
|
1601
1647
|
resolveRoute,
|
|
1602
1648
|
routeInterceptor,
|
|
1603
1649
|
routeRevalidateHandler,
|
|
1604
1650
|
setDiscountCode,
|
|
1605
|
-
updateCheckout
|
|
1651
|
+
updateCheckout,
|
|
1652
|
+
withLazyProps
|
|
1606
1653
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -142,18 +142,15 @@ async function getBreadcrumbFromSegments(segments, market = "ww", locale = "en")
|
|
|
142
142
|
const route = routes.find(
|
|
143
143
|
(r) => r.category === segment.id
|
|
144
144
|
);
|
|
145
|
-
const href = route ? route.id.toString() : "/#";
|
|
146
|
-
return { segment, href };
|
|
147
|
-
}).map((x) => {
|
|
148
|
-
const segment = x.segment;
|
|
149
|
-
const href = x.href;
|
|
150
|
-
const title = localize(segment.title || "untitled", locale);
|
|
151
145
|
return {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
href,
|
|
155
|
-
items: []
|
|
146
|
+
segment,
|
|
147
|
+
route
|
|
156
148
|
};
|
|
149
|
+
}).map((x) => {
|
|
150
|
+
const category = x.segment;
|
|
151
|
+
const route = x.route;
|
|
152
|
+
const routeLink = newRouteLink(category, route, locale);
|
|
153
|
+
return routeLink;
|
|
157
154
|
});
|
|
158
155
|
return tree;
|
|
159
156
|
}
|
|
@@ -179,24 +176,35 @@ async function getRouteLinkTree(market = "ww", locale = "en") {
|
|
|
179
176
|
}
|
|
180
177
|
return void 0;
|
|
181
178
|
}
|
|
179
|
+
function newRouteLink(category, route, locale = "en") {
|
|
180
|
+
const href = route && route.id ? route.id.toString() : "/";
|
|
181
|
+
const id = route?.page || category.id;
|
|
182
|
+
const media = category.media || route?.media;
|
|
183
|
+
const schema = route?.schema || category?.schema || "unknown";
|
|
184
|
+
const title = localize(category.title || route?.title || "untitled", locale);
|
|
185
|
+
const routeLink = {
|
|
186
|
+
category: category.id,
|
|
187
|
+
href,
|
|
188
|
+
id,
|
|
189
|
+
items: [],
|
|
190
|
+
media,
|
|
191
|
+
schema,
|
|
192
|
+
title
|
|
193
|
+
};
|
|
194
|
+
return routeLink;
|
|
195
|
+
}
|
|
182
196
|
function categoryToRouteLink(routes, categories, category, locale = "en") {
|
|
183
197
|
const route = routes.find(
|
|
184
198
|
(r) => r.category === category.id
|
|
185
199
|
);
|
|
186
|
-
const href = route && route.id ? route.id.toString() : "/";
|
|
187
|
-
const title = localize(category.title || "untitled", locale);
|
|
188
200
|
const rootCategory = getRootCategory(categories);
|
|
189
201
|
const childCategories = categories.filter((x) => {
|
|
190
202
|
const parentId = x.category && typeof x.category === "object" ? x.category["id"] : x.category;
|
|
191
203
|
return rootCategory && category.id === rootCategory.id ? x.id !== rootCategory.id && (parentId === category.id || !parentId) : parentId === category.id;
|
|
192
204
|
});
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
href,
|
|
197
|
-
media: category.media,
|
|
198
|
-
items: childCategories.map((x) => categoryToRouteLink(routes, categories, x, locale))
|
|
199
|
-
};
|
|
205
|
+
const routeLink = newRouteLink(category, route, locale);
|
|
206
|
+
routeLink.items = childCategories.map((x) => categoryToRouteLink(routes, categories, x, locale));
|
|
207
|
+
return routeLink;
|
|
200
208
|
}
|
|
201
209
|
function resolveRoute(route) {
|
|
202
210
|
const routepath = route.template ? route.template : route.schema;
|
|
@@ -594,13 +602,13 @@ async function getLayout(market, locale) {
|
|
|
594
602
|
const tree = await getRouteLinkTree(market, locale);
|
|
595
603
|
const firstLevelRoutes = tree?.items || [];
|
|
596
604
|
const flatTopLevelRoutes = tree ? [tree, ...firstLevelRoutes] : [];
|
|
597
|
-
const topLevelRoutes = flatTopLevelRoutes.reduce((object,
|
|
598
|
-
object[
|
|
605
|
+
const topLevelRoutes = flatTopLevelRoutes.reduce((object, routeLink) => {
|
|
606
|
+
object[routeLink.schema] = routeLink;
|
|
599
607
|
return object;
|
|
600
608
|
}, {});
|
|
601
|
-
const topLevelHrefs = flatTopLevelRoutes.reduce((object,
|
|
602
|
-
if (
|
|
603
|
-
object[
|
|
609
|
+
const topLevelHrefs = flatTopLevelRoutes.reduce((object, routeLink) => {
|
|
610
|
+
if (routeLink.href) {
|
|
611
|
+
object[routeLink.schema] = routeLink.href;
|
|
604
612
|
}
|
|
605
613
|
return object;
|
|
606
614
|
}, {});
|
|
@@ -622,6 +630,28 @@ async function getLayout(market, locale) {
|
|
|
622
630
|
};
|
|
623
631
|
}
|
|
624
632
|
|
|
633
|
+
// src/lazy/lazy.ts
|
|
634
|
+
var LAZY_PROPS = {};
|
|
635
|
+
function withLazyProps(key, getComponentProps) {
|
|
636
|
+
LAZY_PROPS[key] = getComponentProps;
|
|
637
|
+
}
|
|
638
|
+
async function getDecoratedComponents(props) {
|
|
639
|
+
const page = props.page;
|
|
640
|
+
if (page.components) {
|
|
641
|
+
const decoratedComponents = [];
|
|
642
|
+
for (const component of page.components) {
|
|
643
|
+
const getComponentProps = LAZY_PROPS[component.schema];
|
|
644
|
+
if (typeof getComponentProps === "function") {
|
|
645
|
+
const decoratedComponent = await getComponentProps({ ...props, component });
|
|
646
|
+
decoratedComponents.push(decoratedComponent);
|
|
647
|
+
} else {
|
|
648
|
+
decoratedComponents.push(component);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
page.components = decoratedComponents;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
|
|
625
655
|
// src/list/list.service.ts
|
|
626
656
|
import { getStore as getStore11 } from "@websolutespa/bom-mixer-store";
|
|
627
657
|
async function getLists(locale) {
|
|
@@ -962,6 +992,7 @@ async function getOrder(id, market, locale) {
|
|
|
962
992
|
}
|
|
963
993
|
|
|
964
994
|
// src/page/page.service.ts
|
|
995
|
+
import { asServerProps } from "@websolutespa/bom-core";
|
|
965
996
|
import { getStore as getStore12 } from "@websolutespa/bom-mixer-store";
|
|
966
997
|
async function findOnePage(schema, id, params) {
|
|
967
998
|
const store = await getStore12();
|
|
@@ -1096,6 +1127,12 @@ async function getErrorPageLayout() {
|
|
|
1096
1127
|
};
|
|
1097
1128
|
return { layout, page };
|
|
1098
1129
|
}
|
|
1130
|
+
async function getPageProps(props) {
|
|
1131
|
+
if (props.page) {
|
|
1132
|
+
await getDecoratedComponents(props);
|
|
1133
|
+
}
|
|
1134
|
+
return asServerProps(props);
|
|
1135
|
+
}
|
|
1099
1136
|
|
|
1100
1137
|
// src/route/route-revalidate.handler.ts
|
|
1101
1138
|
import { apiHandler } from "@websolutespa/bom-mixer-store";
|
|
@@ -1462,6 +1499,7 @@ var getSiteMapXSLProps = async (context) => {
|
|
|
1462
1499
|
};
|
|
1463
1500
|
export {
|
|
1464
1501
|
IOrderStatus,
|
|
1502
|
+
LAZY_PROPS,
|
|
1465
1503
|
categoryToRouteLink,
|
|
1466
1504
|
findManyPages,
|
|
1467
1505
|
findOnePage,
|
|
@@ -1470,6 +1508,7 @@ export {
|
|
|
1470
1508
|
getCategory,
|
|
1471
1509
|
getCountries,
|
|
1472
1510
|
getCountry,
|
|
1511
|
+
getDecoratedComponents,
|
|
1473
1512
|
getDeliveries,
|
|
1474
1513
|
getErrorPageLayout,
|
|
1475
1514
|
getFeatureType,
|
|
@@ -1492,6 +1531,7 @@ export {
|
|
|
1492
1531
|
getOrders,
|
|
1493
1532
|
getPage,
|
|
1494
1533
|
getPageCategory,
|
|
1534
|
+
getPageProps,
|
|
1495
1535
|
getPageRoutes,
|
|
1496
1536
|
getPayment,
|
|
1497
1537
|
getPayments,
|
|
@@ -1513,10 +1553,12 @@ export {
|
|
|
1513
1553
|
getSiteMapXSLProps,
|
|
1514
1554
|
getStaticPathsForSchema,
|
|
1515
1555
|
getStores,
|
|
1556
|
+
newRouteLink,
|
|
1516
1557
|
resolveLabel,
|
|
1517
1558
|
resolveRoute,
|
|
1518
1559
|
routeInterceptor,
|
|
1519
1560
|
routeRevalidateHandler,
|
|
1520
1561
|
setDiscountCode,
|
|
1521
|
-
updateCheckout
|
|
1562
|
+
updateCheckout,
|
|
1563
|
+
withLazyProps
|
|
1522
1564
|
};
|
package/package.json
CHANGED
|
@@ -18,17 +18,17 @@ export async function getLayout(market: string, locale: string): Promise<ILayout
|
|
|
18
18
|
// console.log('firstLevelRoutes', firstLevelRoutes);
|
|
19
19
|
const flatTopLevelRoutes = tree ? [tree, ...firstLevelRoutes] : [];
|
|
20
20
|
// console.log('flatTopLevelRoutes', flatTopLevelRoutes);
|
|
21
|
-
const topLevelRoutes = flatTopLevelRoutes.reduce((object,
|
|
22
|
-
object[
|
|
21
|
+
const topLevelRoutes = flatTopLevelRoutes.reduce((object, routeLink: IRouteLink) => {
|
|
22
|
+
object[routeLink.schema] = routeLink;
|
|
23
23
|
return object;
|
|
24
|
-
}, {} as
|
|
24
|
+
}, {} as Record<string, IRouteLink>);
|
|
25
25
|
// console.log('topLevelRoutes', topLevelRoutes);
|
|
26
|
-
const topLevelHrefs = flatTopLevelRoutes.reduce((object,
|
|
27
|
-
if (
|
|
28
|
-
object[
|
|
26
|
+
const topLevelHrefs = flatTopLevelRoutes.reduce((object, routeLink: IRouteLink) => {
|
|
27
|
+
if (routeLink.href) {
|
|
28
|
+
object[routeLink.schema] = routeLink.href;
|
|
29
29
|
}
|
|
30
30
|
return object;
|
|
31
|
-
}, {} as
|
|
31
|
+
}, {} as Record<string, string>);
|
|
32
32
|
// console.log('topLevelHrefs', topLevelHrefs);
|
|
33
33
|
const menu: Record<string, IMenu> = {};
|
|
34
34
|
// console.log('menu', menu);
|
package/src/lazy/lazy.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { PageProps } from '@websolutespa/bom-core';
|
|
2
|
+
import { DynamicOptions, Loader } from 'next/dynamic';
|
|
1
3
|
import { ComponentType, ReactNode } from 'react';
|
|
2
4
|
|
|
3
5
|
export type ILazyComponent = {
|
|
@@ -25,3 +27,51 @@ export type ILazyComponentProps = {
|
|
|
25
27
|
};
|
|
26
28
|
|
|
27
29
|
export type ILazyModules = Record<string, ComponentType<ILazyProps<any>>>;
|
|
30
|
+
|
|
31
|
+
export type ILazyComponentFunc<P = {}> = DynamicOptions<P> | Loader<P>;
|
|
32
|
+
|
|
33
|
+
export type ILazyFuncProps<T> = PageProps & { component: T & ILazyComponent };
|
|
34
|
+
|
|
35
|
+
export type ILazyStaticPropsFunc<T = any> = (props: ILazyFuncProps<T>) => Promise<T & ILazyComponent>;
|
|
36
|
+
|
|
37
|
+
export type ILazyStaticProps = Record<string, ILazyStaticPropsFunc>;
|
|
38
|
+
|
|
39
|
+
export const LAZY_PROPS: ILazyStaticProps = {};
|
|
40
|
+
|
|
41
|
+
export function withLazyProps<T>(key: string, getComponentProps: ILazyStaticPropsFunc<T>) {
|
|
42
|
+
LAZY_PROPS[key] = getComponentProps;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function getDecoratedComponents(props: PageProps) {
|
|
46
|
+
const page = props.page;
|
|
47
|
+
if (page.components) {
|
|
48
|
+
const decoratedComponents: ILazyComponent[] = [];
|
|
49
|
+
for (const component of page.components) {
|
|
50
|
+
const getComponentProps = LAZY_PROPS[component.schema];
|
|
51
|
+
if (typeof getComponentProps === 'function') {
|
|
52
|
+
const decoratedComponent = await getComponentProps({ ...(props as PageProps), component });
|
|
53
|
+
decoratedComponents.push(decoratedComponent);
|
|
54
|
+
} else {
|
|
55
|
+
decoratedComponents.push(component);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
page.components = decoratedComponents;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/*
|
|
63
|
+
export const LAZY_MODULES: ILazyModules = {};
|
|
64
|
+
|
|
65
|
+
export function withLazyModule<T>(key: string, callback: ILazyComponentFunc<ILazyProps<T>>) {
|
|
66
|
+
const module = dynamic<ILazyProps<T>>(callback);
|
|
67
|
+
LAZY_MODULES[key] = module;
|
|
68
|
+
return module;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function withLazyModules(modules: Record<string, ILazyComponentFunc<ILazyProps<any>>>) {
|
|
72
|
+
Object.entries(modules).forEach(([key, callback]) => {
|
|
73
|
+
withLazyModule(key, callback);
|
|
74
|
+
});
|
|
75
|
+
return LAZY_MODULES;
|
|
76
|
+
}
|
|
77
|
+
*/
|
package/src/page/page.service.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { ICategorized, ICategory, IEquatable, ILayout, IPage, IPageResult, IRoute, IRouteLink, QueryParams, SchemaType } from '@websolutespa/bom-core';
|
|
1
|
+
import { ICategorized, ICategory, IEquatable, ILayout, IPage, IPageResult, IRoute, IRouteLink, PageProps, QueryParams, SchemaType, asServerProps } from '@websolutespa/bom-core';
|
|
2
2
|
import { getStore } from '@websolutespa/bom-mixer-store';
|
|
3
3
|
import { getSegments } from '../category/category.service';
|
|
4
4
|
import { resolveLabel } from '../label/label.service';
|
|
5
5
|
import { getLayout } from '../layout/layout.service';
|
|
6
|
+
import { getDecoratedComponents } from '../lazy/lazy';
|
|
6
7
|
import { getBreadcrumbFromSegments } from '../route/route.service';
|
|
7
8
|
import { IModelStore } from '../store/store';
|
|
8
9
|
|
|
@@ -147,3 +148,11 @@ export async function getErrorPageLayout(): Promise<{ layout: ILayout, page: IPa
|
|
|
147
148
|
return { layout, page };
|
|
148
149
|
}
|
|
149
150
|
|
|
151
|
+
export type PartialPageProps<T extends ICategorized, B> = Omit<PageProps<T>, 'page'> & Partial<Pick<PageProps<T>, 'page'>> & B;
|
|
152
|
+
|
|
153
|
+
export async function getPageProps<T extends ICategorized, B = any>(props: PartialPageProps<T, B>) {
|
|
154
|
+
if (props.page) {
|
|
155
|
+
await getDecoratedComponents(props as PageProps<T> & B);
|
|
156
|
+
}
|
|
157
|
+
return asServerProps(props) as PageProps<T> & B;
|
|
158
|
+
}
|
|
@@ -94,18 +94,15 @@ export async function getBreadcrumbFromSegments(segments: ICategory[], market: s
|
|
|
94
94
|
const route = routes.find(r =>
|
|
95
95
|
r.category === segment.id
|
|
96
96
|
);
|
|
97
|
-
const href = route ? route.id.toString() : '/#';
|
|
98
|
-
return { segment, href };
|
|
99
|
-
}).map(x => {
|
|
100
|
-
const segment: ICategory = x.segment;
|
|
101
|
-
const href: string = x.href;
|
|
102
|
-
const title = localize(segment.title || 'untitled', locale);
|
|
103
97
|
return {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
href,
|
|
107
|
-
items: [],
|
|
98
|
+
segment,
|
|
99
|
+
route,
|
|
108
100
|
};
|
|
101
|
+
}).map(x => {
|
|
102
|
+
const category = x.segment;
|
|
103
|
+
const route = x.route;
|
|
104
|
+
const routeLink = newRouteLink(category, route, locale);
|
|
105
|
+
return routeLink;
|
|
109
106
|
});
|
|
110
107
|
return tree;
|
|
111
108
|
}
|
|
@@ -136,13 +133,28 @@ export async function getRouteLinkTree(market: string = 'ww', locale: string = '
|
|
|
136
133
|
return undefined;
|
|
137
134
|
}
|
|
138
135
|
|
|
136
|
+
export function newRouteLink(category: ICategory, route?: IRoute, locale: string = 'en'): IRouteLink {
|
|
137
|
+
const href = (route && route.id) ? route.id.toString() : '/';
|
|
138
|
+
const id = route?.page || category.id;
|
|
139
|
+
const media = category.media || route?.media;
|
|
140
|
+
const schema = route?.schema || category?.schema || 'unknown';
|
|
141
|
+
const title = localize(category.title || route?.title || 'untitled', locale);
|
|
142
|
+
const routeLink = {
|
|
143
|
+
category: category.id,
|
|
144
|
+
href,
|
|
145
|
+
id,
|
|
146
|
+
items: [],
|
|
147
|
+
media,
|
|
148
|
+
schema,
|
|
149
|
+
title,
|
|
150
|
+
};
|
|
151
|
+
return routeLink;
|
|
152
|
+
}
|
|
153
|
+
|
|
139
154
|
export function categoryToRouteLink(routes: IRoute[], categories: ICategory[], category: ICategory, locale: string = 'en'): IRouteLink {
|
|
140
155
|
const route = routes.find(r =>
|
|
141
156
|
r.category === category.id
|
|
142
157
|
);
|
|
143
|
-
const href = (route && route.id) ? route.id.toString() : '/';
|
|
144
|
-
// console.log('categoryToRouteLink', href, category.id, route);
|
|
145
|
-
const title = localize(category.title || 'untitled', locale);
|
|
146
158
|
const rootCategory = getRootCategory(categories);
|
|
147
159
|
const childCategories = categories.filter(x => {
|
|
148
160
|
const parentId = x.category && typeof x.category === 'object' ? x.category['id'] : x.category;
|
|
@@ -151,13 +163,12 @@ export function categoryToRouteLink(routes: IRoute[], categories: ICategory[], c
|
|
|
151
163
|
parentId === category.id;
|
|
152
164
|
});
|
|
153
165
|
// console.log('childCategories', category.id, childCategories);
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
};
|
|
166
|
+
const routeLink = newRouteLink(category, route, locale);
|
|
167
|
+
// const title = localize(category.title || 'untitled', locale);
|
|
168
|
+
// const href = (route && route.id) ? route.id.toString() : '/';
|
|
169
|
+
// console.log('categoryToRouteLink', href, category.id, route);
|
|
170
|
+
routeLink.items = childCategories.map(x => categoryToRouteLink(routes, categories, x, locale));
|
|
171
|
+
return routeLink;
|
|
161
172
|
}
|
|
162
173
|
|
|
163
174
|
export function resolveRoute(route: IRoute & { splat?: string }) {
|