@websolutespa/bom-core 1.7.16 → 1.8.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 +12 -0
- package/dist/index.d.ts +58 -9
- package/dist/index.js +61 -2
- package/dist/index.mjs +58 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @websolutespa/bom-core
|
|
2
2
|
|
|
3
|
+
## 1.8.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Modified: Market & Language
|
|
8
|
+
|
|
9
|
+
## 1.8.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- f8a1d97: Modified: extracted all website sample components & features
|
|
14
|
+
|
|
3
15
|
## 1.7.16
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -130,6 +130,7 @@ type IAnchor = {
|
|
|
130
130
|
|
|
131
131
|
type IComponent = {
|
|
132
132
|
schema: string;
|
|
133
|
+
anchor?: IAnchor;
|
|
133
134
|
[key: string]: unknown;
|
|
134
135
|
};
|
|
135
136
|
|
|
@@ -154,12 +155,11 @@ type IFeature = Record<string, any> & {
|
|
|
154
155
|
id: IEquatable;
|
|
155
156
|
title: string;
|
|
156
157
|
};
|
|
157
|
-
type IFeatureType = {
|
|
158
|
+
type IFeatureType = IEntity & {
|
|
158
159
|
id: string;
|
|
159
|
-
schema?: string;
|
|
160
160
|
title: string;
|
|
161
161
|
mode: string;
|
|
162
|
-
features
|
|
162
|
+
features: IFeature[];
|
|
163
163
|
};
|
|
164
164
|
|
|
165
165
|
type IMediaType = 'image' | 'video' | 'json' | 'pdf' | string;
|
|
@@ -306,9 +306,9 @@ type ILocale = IEntity & {
|
|
|
306
306
|
type IMarket = IEntity & {
|
|
307
307
|
id: string;
|
|
308
308
|
title?: string;
|
|
309
|
-
countries?: string[];
|
|
310
|
-
languages?: string[];
|
|
311
|
-
defaultLanguage?: string;
|
|
309
|
+
countries?: string[] | IEntity[];
|
|
310
|
+
languages?: string[] | IEntity[];
|
|
311
|
+
defaultLanguage?: string | IEntity;
|
|
312
312
|
isActive?: boolean;
|
|
313
313
|
isDefault?: boolean;
|
|
314
314
|
isHidden?: boolean;
|
|
@@ -348,10 +348,30 @@ type IRouteParams = Record<string, any> & {
|
|
|
348
348
|
market: string;
|
|
349
349
|
};
|
|
350
350
|
|
|
351
|
+
/**
|
|
352
|
+
* Represents a listing item returned from the findMany method of a page collection.
|
|
353
|
+
* @template T - The type of the categorized item.
|
|
354
|
+
*/
|
|
355
|
+
type IPageItem<T extends ICategorized = ICategorized> = ILocalized<T> & {
|
|
356
|
+
schema: string;
|
|
357
|
+
category: ILocalized<ICategory> & {
|
|
358
|
+
href: string;
|
|
359
|
+
};
|
|
360
|
+
href: string;
|
|
361
|
+
locale: string;
|
|
362
|
+
market: string;
|
|
363
|
+
};
|
|
364
|
+
/**
|
|
365
|
+
* Represents a detail item returned from the findOne method of a page collection.
|
|
366
|
+
* @template T - The type of the categorized item.
|
|
367
|
+
*/
|
|
351
368
|
type IPage<T extends ICategorized = ICategorized> = ILocalized<T> & {
|
|
369
|
+
schema: string;
|
|
352
370
|
alternates: IRoute[];
|
|
353
371
|
breadcrumb: IRouteLink[];
|
|
354
|
-
category: ILocalized<ICategory
|
|
372
|
+
category: ILocalized<ICategory> & {
|
|
373
|
+
href: string;
|
|
374
|
+
};
|
|
355
375
|
href: string;
|
|
356
376
|
locale: string;
|
|
357
377
|
market: string;
|
|
@@ -359,6 +379,10 @@ type IPage<T extends ICategorized = ICategorized> = ILocalized<T> & {
|
|
|
359
379
|
slug: string;
|
|
360
380
|
title: string;
|
|
361
381
|
};
|
|
382
|
+
/**
|
|
383
|
+
* Represents the props for a page component.
|
|
384
|
+
* @template T - The type of the categorized item.
|
|
385
|
+
*/
|
|
362
386
|
type PageProps<T extends ICategorized = ICategorized> = {
|
|
363
387
|
layout: ILayout;
|
|
364
388
|
page: IPage<T>;
|
|
@@ -367,13 +391,24 @@ type PageProps<T extends ICategorized = ICategorized> = {
|
|
|
367
391
|
locale?: string;
|
|
368
392
|
defaultLocale?: string;
|
|
369
393
|
};
|
|
394
|
+
/**
|
|
395
|
+
* Represents the result of a page relation.
|
|
396
|
+
* @template T - The type of the categorized item.
|
|
397
|
+
*/
|
|
370
398
|
type IPageRelationResult<T extends ICategorized = ICategorized> = {
|
|
371
399
|
href: string;
|
|
372
400
|
} & T;
|
|
401
|
+
/**
|
|
402
|
+
* Represents a page relation.
|
|
403
|
+
* @template T - The type of the categorized item.
|
|
404
|
+
*/
|
|
373
405
|
type IPageRelation<T extends ICategorized = ICategorized> = {
|
|
374
406
|
relationTo: string;
|
|
375
|
-
value: IPageRelationResult<T
|
|
407
|
+
value: IPageRelationResult<T> | IPageRelationResult<T>[];
|
|
376
408
|
};
|
|
409
|
+
/**
|
|
410
|
+
* Represents an unresolved page relation.
|
|
411
|
+
*/
|
|
377
412
|
type IPageUnresolvedRelation = {
|
|
378
413
|
relationTo: string;
|
|
379
414
|
value: IEquatable | IEquatable[];
|
|
@@ -737,6 +772,17 @@ declare function toValidCollectionName(text: string): string;
|
|
|
737
772
|
|
|
738
773
|
declare function consoleWarn(message: string, component?: string): void;
|
|
739
774
|
|
|
775
|
+
/**
|
|
776
|
+
* Retrieves the ID of a category or an object that implements IEquatable.
|
|
777
|
+
* @param value - The category or object to retrieve the ID from.
|
|
778
|
+
* @returns The ID of the category or object as a string.
|
|
779
|
+
*/
|
|
780
|
+
declare function asEntityId(value: undefined): undefined;
|
|
781
|
+
declare function asEntityId(value: string): string;
|
|
782
|
+
declare function asEntityId(value: number): number;
|
|
783
|
+
declare function asEntityId(value: IEntity | IEquatable): string | number;
|
|
784
|
+
declare function asEntityId(value: IEntity | IEquatable | undefined): string | number | undefined;
|
|
785
|
+
|
|
740
786
|
/**
|
|
741
787
|
* Performs an HTTP fetch request.
|
|
742
788
|
* @param url - The URL to fetch.
|
|
@@ -1017,6 +1063,8 @@ declare function getRouteHref(segments: {
|
|
|
1017
1063
|
slug: ILocalizable;
|
|
1018
1064
|
}[], market: IMarket, locale: ILocale, markets: IMarket[], locales: ILocale[]): string;
|
|
1019
1065
|
|
|
1066
|
+
declare function arrayShuffle<T extends IEntity>(items: T[]): T[];
|
|
1067
|
+
|
|
1020
1068
|
/**
|
|
1021
1069
|
* Converts a value to an `IEquatable` or `undefined`.
|
|
1022
1070
|
* If the value is an `IEntity`, it extracts the `id` property.
|
|
@@ -1078,6 +1126,7 @@ declare function toSnakeCase(unknownCase: string): string;
|
|
|
1078
1126
|
declare function cloneItem<T = unknown>(item: T): T;
|
|
1079
1127
|
|
|
1080
1128
|
declare function collectFeatureTypes<T extends IEntity = IEntity>(items: T[], ...keys: string[]): Promise<IFeatureType[]>;
|
|
1129
|
+
declare function collectFeatureTypes__<T extends IEntity = IEntity>(items: T[], ...keys: string[]): Promise<IFeatureType[]>;
|
|
1081
1130
|
|
|
1082
1131
|
/**
|
|
1083
1132
|
* Collects options from an array of items based on specified keys.
|
|
@@ -1229,4 +1278,4 @@ declare function asServerProps(props: any): any;
|
|
|
1229
1278
|
declare function awaitAll(array: any, callback: (item: any, index: number) => Promise<any>): Promise<any[]>;
|
|
1230
1279
|
declare function merge(target: any, source: any): any;
|
|
1231
1280
|
|
|
1232
|
-
export { DeepPartial, Dynamic, FetchError, FetchRequestOptions, FetchService, FindParams, FindWhereParams, IAction, IActionEmailData, IAnchor, ICategorized, ICategory, ICategoryItem, IClassName, IClassNameCollection, IClassNameValue, ICollectionDescription, IComponent, IConfig, IConsentPreference, IContextBaseParams, IContextParams, IDecoratedNav, IEmailConfig, IEndUser, IEntity, IEquatable, IFeature, IFeatureType, ILabel, ILayout, ILegalNotice, ILetter, ILocale, ILocaleId, ILocalizable, ILocalized, ILocalizedString, IMarket, IMedia, IMediaImage, IMediaInfo, IMediaJson, IMediaPdf, IMediaType, IMediaVideo, IMemoryStore, IMenu, IMenuBase, IMenuCategory, IMenuCustom, IMenuGroup, IMenuHref, IMenuItem, IMenuLink, IMenuPage, IMenuRoute, INamedEntity, IOption, IOverride, IOverrideReturnValue, IOverrideValue, IPackages, IPage, IPageRelation, IPageRelationResult, IPageUnresolvedRelation, IPagedResult, IPaginationResult, IPartial, IPreference, IPrettify, IQuerable, IRedirect, IRoute, IRouteCanonical, IRouteLink, IRouteParams, ISchema, ISerializedCollection, ISerializedStore, IServerSideContext, IServerSideSplatContext, IStaticContext, IStore, ITemplate, ITitledEntity, IUndecoratedMenu, IUndecoratedMenuBase, IUndecoratedMenuCategory, IUndecoratedMenuCustom, IUndecoratedMenuGroup, IUndecoratedMenuItem, IUndecoratedMenuLink, IUndecoratedMenuPage, IUndecoratedNav, Json, JsonService, LiteralUnion, Logger, LoggerLevel, MenuCategoryStrategy, NextApiRequestCookies, Operator, PageProps, Pagination, PreviewData, Primitive, QueryParams, RedirectReason, RequireAtLeastOne, RouteStrategy, SchemaType, ServerSidePropsContext, StaticPropsContext, User, UserRole, UserWithRoles, ValueOf, Where, WhereAndOr, WhereBase, WhereField, asCategoryId, asEquatable, asEquatableNumber, asEquatableString, asServerProps, asSortedOptions, awaitAll, camelToSnakeCase, cloneItem, collectFeatureTypes, collectOptions, collectRoutes, consoleWarn, deepMerge, defaultLocale, defaultMarket, eachCategorized, eachMarketLocale, enumToList, findCategoryInCategories, findChildCategories, findRouteOfCategory, findRoutesOfCategory, getCategorySegments, getCategorySegmentsByCategory, getClassNames, getCollectionDescription, getEnv, getHost, getIsDevelopment, getIsProduction, getOrigin, getParentCategoriesById, getParentCategory, getProto, getRootCategory, getRouteHref, httpDelete, httpFetch, httpGet, httpPatch, httpPost, httpPut, isArray, isBrowser, isDevelopment, isEntity, isEquatable, isHeaders, isIncomingHttpHeaders, isLocalizedString, isMediaImage, isMediaJson, isMediaPdf, isMediaVideo, isMenuHref, isNotNullString, isNumber, isObject, isProduction, isPromise, isRelation, isReservedCollectionDescription, isStage, isString, isUndecoratedMenuCategory, isUndecoratedMenuItem, isUndecoratedMenuPage, isUndecoratedNav, isUnresolvedRelation, isValidCollectionDescription, isValidString, localize, localizeItem, localizeValue, localizedToString, merge, pascalCaseToCamelCase, pascalCaseToCharCase, pascalCaseToKebabCase, pascalCaseToSnakeCase, qsDeserialize, qsDeserializeRaw, qsSerialize, qsSerializeRaw, resolveMediaType, toCamelCase, toCharCase, toDisplayName, toFindParams, toKebabCase, toPascalCase, toPluralName, toSnakeCase, toTitleCase, toValidCollectionName, unknownCaseToPascalCase, uuidv4, withSchema };
|
|
1281
|
+
export { DeepPartial, Dynamic, FetchError, FetchRequestOptions, FetchService, FindParams, FindWhereParams, IAction, IActionEmailData, IAnchor, ICategorized, ICategory, ICategoryItem, IClassName, IClassNameCollection, IClassNameValue, ICollectionDescription, IComponent, IConfig, IConsentPreference, IContextBaseParams, IContextParams, IDecoratedNav, IEmailConfig, IEndUser, IEntity, IEquatable, IFeature, IFeatureType, ILabel, ILayout, ILegalNotice, ILetter, ILocale, ILocaleId, ILocalizable, ILocalized, ILocalizedString, IMarket, IMedia, IMediaImage, IMediaInfo, IMediaJson, IMediaPdf, IMediaType, IMediaVideo, IMemoryStore, IMenu, IMenuBase, IMenuCategory, IMenuCustom, IMenuGroup, IMenuHref, IMenuItem, IMenuLink, IMenuPage, IMenuRoute, INamedEntity, IOption, IOverride, IOverrideReturnValue, IOverrideValue, IPackages, IPage, IPageItem, IPageRelation, IPageRelationResult, IPageUnresolvedRelation, IPagedResult, IPaginationResult, IPartial, IPreference, IPrettify, IQuerable, IRedirect, IRoute, IRouteCanonical, IRouteLink, IRouteParams, ISchema, ISerializedCollection, ISerializedStore, IServerSideContext, IServerSideSplatContext, IStaticContext, IStore, ITemplate, ITitledEntity, IUndecoratedMenu, IUndecoratedMenuBase, IUndecoratedMenuCategory, IUndecoratedMenuCustom, IUndecoratedMenuGroup, IUndecoratedMenuItem, IUndecoratedMenuLink, IUndecoratedMenuPage, IUndecoratedNav, Json, JsonService, LiteralUnion, Logger, LoggerLevel, MenuCategoryStrategy, NextApiRequestCookies, Operator, PageProps, Pagination, PreviewData, Primitive, QueryParams, RedirectReason, RequireAtLeastOne, RouteStrategy, SchemaType, ServerSidePropsContext, StaticPropsContext, User, UserRole, UserWithRoles, ValueOf, Where, WhereAndOr, WhereBase, WhereField, arrayShuffle, asCategoryId, asEntityId, asEquatable, asEquatableNumber, asEquatableString, asServerProps, asSortedOptions, awaitAll, camelToSnakeCase, cloneItem, collectFeatureTypes, collectFeatureTypes__, collectOptions, collectRoutes, consoleWarn, deepMerge, defaultLocale, defaultMarket, eachCategorized, eachMarketLocale, enumToList, findCategoryInCategories, findChildCategories, findRouteOfCategory, findRoutesOfCategory, getCategorySegments, getCategorySegmentsByCategory, getClassNames, getCollectionDescription, getEnv, getHost, getIsDevelopment, getIsProduction, getOrigin, getParentCategoriesById, getParentCategory, getProto, getRootCategory, getRouteHref, httpDelete, httpFetch, httpGet, httpPatch, httpPost, httpPut, isArray, isBrowser, isDevelopment, isEntity, isEquatable, isHeaders, isIncomingHttpHeaders, isLocalizedString, isMediaImage, isMediaJson, isMediaPdf, isMediaVideo, isMenuHref, isNotNullString, isNumber, isObject, isProduction, isPromise, isRelation, isReservedCollectionDescription, isStage, isString, isUndecoratedMenuCategory, isUndecoratedMenuItem, isUndecoratedMenuPage, isUndecoratedNav, isUnresolvedRelation, isValidCollectionDescription, isValidString, localize, localizeItem, localizeValue, localizedToString, merge, pascalCaseToCamelCase, pascalCaseToCharCase, pascalCaseToKebabCase, pascalCaseToSnakeCase, qsDeserialize, qsDeserializeRaw, qsSerialize, qsSerializeRaw, resolveMediaType, toCamelCase, toCharCase, toDisplayName, toFindParams, toKebabCase, toPascalCase, toPluralName, toSnakeCase, toTitleCase, toValidCollectionName, unknownCaseToPascalCase, uuidv4, withSchema };
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,9 @@ __export(src_exports, {
|
|
|
36
36
|
MenuCategoryStrategy: () => MenuCategoryStrategy,
|
|
37
37
|
RedirectReason: () => RedirectReason,
|
|
38
38
|
RouteStrategy: () => RouteStrategy,
|
|
39
|
+
arrayShuffle: () => arrayShuffle,
|
|
39
40
|
asCategoryId: () => asCategoryId,
|
|
41
|
+
asEntityId: () => asEntityId,
|
|
40
42
|
asEquatable: () => asEquatable,
|
|
41
43
|
asEquatableNumber: () => asEquatableNumber,
|
|
42
44
|
asEquatableString: () => asEquatableString,
|
|
@@ -46,6 +48,7 @@ __export(src_exports, {
|
|
|
46
48
|
camelToSnakeCase: () => camelToSnakeCase,
|
|
47
49
|
cloneItem: () => cloneItem,
|
|
48
50
|
collectFeatureTypes: () => collectFeatureTypes,
|
|
51
|
+
collectFeatureTypes__: () => collectFeatureTypes__,
|
|
49
52
|
collectOptions: () => collectOptions,
|
|
50
53
|
collectRoutes: () => collectRoutes,
|
|
51
54
|
consoleWarn: () => consoleWarn,
|
|
@@ -138,6 +141,11 @@ __export(src_exports, {
|
|
|
138
141
|
});
|
|
139
142
|
module.exports = __toCommonJS(src_exports);
|
|
140
143
|
|
|
144
|
+
// src/utils/arrayShuffle.ts
|
|
145
|
+
function arrayShuffle(items) {
|
|
146
|
+
return items.map((item) => ({ item, order: Math.random() })).sort((a, b) => a.order - b.order).map(({ item }) => item);
|
|
147
|
+
}
|
|
148
|
+
|
|
141
149
|
// src/utils/typeGuards.ts
|
|
142
150
|
function isNumber(item) {
|
|
143
151
|
return typeof item === "number";
|
|
@@ -290,6 +298,49 @@ function cloneItem(item) {
|
|
|
290
298
|
|
|
291
299
|
// src/utils/collectFeatureTypes.ts
|
|
292
300
|
async function collectFeatureTypes(items, ...keys) {
|
|
301
|
+
const featureTypes = [];
|
|
302
|
+
if (keys.length > 0) {
|
|
303
|
+
items.forEach((item) => {
|
|
304
|
+
keys.forEach((key) => {
|
|
305
|
+
const value = item[key] || [];
|
|
306
|
+
const values = Array.isArray(value) ? value : [value];
|
|
307
|
+
values.forEach((value2) => {
|
|
308
|
+
let featureType = featureTypes.find((x) => x.id === key);
|
|
309
|
+
if (!featureType) {
|
|
310
|
+
featureType = {
|
|
311
|
+
id: key,
|
|
312
|
+
schema: "featureType",
|
|
313
|
+
title: key,
|
|
314
|
+
mode: "or",
|
|
315
|
+
features: []
|
|
316
|
+
};
|
|
317
|
+
featureTypes.push(featureType);
|
|
318
|
+
}
|
|
319
|
+
const features = featureType.features;
|
|
320
|
+
const option = isObject(value2) ? {
|
|
321
|
+
...value2,
|
|
322
|
+
title: value2.title || value2.name || value2.label || "Untitled"
|
|
323
|
+
} : {
|
|
324
|
+
id: value2,
|
|
325
|
+
title: String(value2)
|
|
326
|
+
};
|
|
327
|
+
if (features && !features.find((x) => x.id === option.id)) {
|
|
328
|
+
features.push(option);
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
featureTypes.forEach((featureType) => {
|
|
335
|
+
featureType.features.sort((a, b) => {
|
|
336
|
+
const textA = a.title.toUpperCase();
|
|
337
|
+
const textB = b.title.toUpperCase();
|
|
338
|
+
return textA < textB ? -1 : textA > textB ? 1 : 0;
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
return featureTypes;
|
|
342
|
+
}
|
|
343
|
+
async function collectFeatureTypes__(items, ...keys) {
|
|
293
344
|
const featureTypes = [];
|
|
294
345
|
if (keys.length > 0) {
|
|
295
346
|
items.forEach((item) => {
|
|
@@ -606,6 +657,11 @@ function consoleWarn(message, component) {
|
|
|
606
657
|
console.warn(log);
|
|
607
658
|
}
|
|
608
659
|
|
|
660
|
+
// src/entity/entity.ts
|
|
661
|
+
function asEntityId(value) {
|
|
662
|
+
return isEntity(value) ? value.id : value;
|
|
663
|
+
}
|
|
664
|
+
|
|
609
665
|
// src/http/http.service.ts
|
|
610
666
|
var defaultOptions = {
|
|
611
667
|
// method: 'POST', // *GET, POST, PUT, DELETE, etc.
|
|
@@ -1289,7 +1345,7 @@ function collectRoutes(store, categories, markets, locales) {
|
|
|
1289
1345
|
if (rootCategory && item.category === rootCategory.id) {
|
|
1290
1346
|
const defaultLocale2 = locales.find((x) => x.isDefault) || locales[0];
|
|
1291
1347
|
const defaultMarket2 = markets.find((x) => x.isDefault) || markets[0];
|
|
1292
|
-
const defaultMarketLocale = defaultMarket2 && defaultMarket2.defaultLanguage ? defaultMarket2.defaultLanguage : defaultLocale2.id;
|
|
1348
|
+
const defaultMarketLocale = defaultMarket2 && defaultMarket2.defaultLanguage ? asEntityId(defaultMarket2.defaultLanguage) : defaultLocale2.id;
|
|
1293
1349
|
const title = localize(item.title, defaultMarketLocale);
|
|
1294
1350
|
const pickedProps = getPickedProps(item);
|
|
1295
1351
|
const route = {
|
|
@@ -1331,7 +1387,7 @@ function eachMarketLocale(markets, locales, callback) {
|
|
|
1331
1387
|
locales = locales.filter((x) => x.isActive !== false);
|
|
1332
1388
|
markets = markets.filter((x) => x.isActive !== false);
|
|
1333
1389
|
markets.forEach((market) => {
|
|
1334
|
-
const marketLocales = market.languages && market.languages.length > 0 ? market.languages.map((
|
|
1390
|
+
const marketLocales = market.languages && market.languages.length > 0 ? market.languages.map((idOrEntity) => locales.find((x) => x.id === asEntityId(idOrEntity))).filter((x) => x !== void 0) : locales;
|
|
1335
1391
|
marketLocales.forEach((locale) => {
|
|
1336
1392
|
callback(market, locale, markets, locales);
|
|
1337
1393
|
});
|
|
@@ -1474,7 +1530,9 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
|
|
|
1474
1530
|
MenuCategoryStrategy,
|
|
1475
1531
|
RedirectReason,
|
|
1476
1532
|
RouteStrategy,
|
|
1533
|
+
arrayShuffle,
|
|
1477
1534
|
asCategoryId,
|
|
1535
|
+
asEntityId,
|
|
1478
1536
|
asEquatable,
|
|
1479
1537
|
asEquatableNumber,
|
|
1480
1538
|
asEquatableString,
|
|
@@ -1484,6 +1542,7 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
|
|
|
1484
1542
|
camelToSnakeCase,
|
|
1485
1543
|
cloneItem,
|
|
1486
1544
|
collectFeatureTypes,
|
|
1545
|
+
collectFeatureTypes__,
|
|
1487
1546
|
collectOptions,
|
|
1488
1547
|
collectRoutes,
|
|
1489
1548
|
consoleWarn,
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
// src/utils/arrayShuffle.ts
|
|
2
|
+
function arrayShuffle(items) {
|
|
3
|
+
return items.map((item) => ({ item, order: Math.random() })).sort((a, b) => a.order - b.order).map(({ item }) => item);
|
|
4
|
+
}
|
|
5
|
+
|
|
1
6
|
// src/utils/typeGuards.ts
|
|
2
7
|
function isNumber(item) {
|
|
3
8
|
return typeof item === "number";
|
|
@@ -150,6 +155,49 @@ function cloneItem(item) {
|
|
|
150
155
|
|
|
151
156
|
// src/utils/collectFeatureTypes.ts
|
|
152
157
|
async function collectFeatureTypes(items, ...keys) {
|
|
158
|
+
const featureTypes = [];
|
|
159
|
+
if (keys.length > 0) {
|
|
160
|
+
items.forEach((item) => {
|
|
161
|
+
keys.forEach((key) => {
|
|
162
|
+
const value = item[key] || [];
|
|
163
|
+
const values = Array.isArray(value) ? value : [value];
|
|
164
|
+
values.forEach((value2) => {
|
|
165
|
+
let featureType = featureTypes.find((x) => x.id === key);
|
|
166
|
+
if (!featureType) {
|
|
167
|
+
featureType = {
|
|
168
|
+
id: key,
|
|
169
|
+
schema: "featureType",
|
|
170
|
+
title: key,
|
|
171
|
+
mode: "or",
|
|
172
|
+
features: []
|
|
173
|
+
};
|
|
174
|
+
featureTypes.push(featureType);
|
|
175
|
+
}
|
|
176
|
+
const features = featureType.features;
|
|
177
|
+
const option = isObject(value2) ? {
|
|
178
|
+
...value2,
|
|
179
|
+
title: value2.title || value2.name || value2.label || "Untitled"
|
|
180
|
+
} : {
|
|
181
|
+
id: value2,
|
|
182
|
+
title: String(value2)
|
|
183
|
+
};
|
|
184
|
+
if (features && !features.find((x) => x.id === option.id)) {
|
|
185
|
+
features.push(option);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
featureTypes.forEach((featureType) => {
|
|
192
|
+
featureType.features.sort((a, b) => {
|
|
193
|
+
const textA = a.title.toUpperCase();
|
|
194
|
+
const textB = b.title.toUpperCase();
|
|
195
|
+
return textA < textB ? -1 : textA > textB ? 1 : 0;
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
return featureTypes;
|
|
199
|
+
}
|
|
200
|
+
async function collectFeatureTypes__(items, ...keys) {
|
|
153
201
|
const featureTypes = [];
|
|
154
202
|
if (keys.length > 0) {
|
|
155
203
|
items.forEach((item) => {
|
|
@@ -466,6 +514,11 @@ function consoleWarn(message, component) {
|
|
|
466
514
|
console.warn(log);
|
|
467
515
|
}
|
|
468
516
|
|
|
517
|
+
// src/entity/entity.ts
|
|
518
|
+
function asEntityId(value) {
|
|
519
|
+
return isEntity(value) ? value.id : value;
|
|
520
|
+
}
|
|
521
|
+
|
|
469
522
|
// src/http/http.service.ts
|
|
470
523
|
var defaultOptions = {
|
|
471
524
|
// method: 'POST', // *GET, POST, PUT, DELETE, etc.
|
|
@@ -1149,7 +1202,7 @@ function collectRoutes(store, categories, markets, locales) {
|
|
|
1149
1202
|
if (rootCategory && item.category === rootCategory.id) {
|
|
1150
1203
|
const defaultLocale2 = locales.find((x) => x.isDefault) || locales[0];
|
|
1151
1204
|
const defaultMarket2 = markets.find((x) => x.isDefault) || markets[0];
|
|
1152
|
-
const defaultMarketLocale = defaultMarket2 && defaultMarket2.defaultLanguage ? defaultMarket2.defaultLanguage : defaultLocale2.id;
|
|
1205
|
+
const defaultMarketLocale = defaultMarket2 && defaultMarket2.defaultLanguage ? asEntityId(defaultMarket2.defaultLanguage) : defaultLocale2.id;
|
|
1153
1206
|
const title = localize(item.title, defaultMarketLocale);
|
|
1154
1207
|
const pickedProps = getPickedProps(item);
|
|
1155
1208
|
const route = {
|
|
@@ -1191,7 +1244,7 @@ function eachMarketLocale(markets, locales, callback) {
|
|
|
1191
1244
|
locales = locales.filter((x) => x.isActive !== false);
|
|
1192
1245
|
markets = markets.filter((x) => x.isActive !== false);
|
|
1193
1246
|
markets.forEach((market) => {
|
|
1194
|
-
const marketLocales = market.languages && market.languages.length > 0 ? market.languages.map((
|
|
1247
|
+
const marketLocales = market.languages && market.languages.length > 0 ? market.languages.map((idOrEntity) => locales.find((x) => x.id === asEntityId(idOrEntity))).filter((x) => x !== void 0) : locales;
|
|
1195
1248
|
marketLocales.forEach((locale) => {
|
|
1196
1249
|
callback(market, locale, markets, locales);
|
|
1197
1250
|
});
|
|
@@ -1333,7 +1386,9 @@ export {
|
|
|
1333
1386
|
MenuCategoryStrategy,
|
|
1334
1387
|
RedirectReason,
|
|
1335
1388
|
RouteStrategy,
|
|
1389
|
+
arrayShuffle,
|
|
1336
1390
|
asCategoryId,
|
|
1391
|
+
asEntityId,
|
|
1337
1392
|
asEquatable,
|
|
1338
1393
|
asEquatableNumber,
|
|
1339
1394
|
asEquatableString,
|
|
@@ -1343,6 +1398,7 @@ export {
|
|
|
1343
1398
|
camelToSnakeCase,
|
|
1344
1399
|
cloneItem,
|
|
1345
1400
|
collectFeatureTypes,
|
|
1401
|
+
collectFeatureTypes__,
|
|
1346
1402
|
collectOptions,
|
|
1347
1403
|
collectRoutes,
|
|
1348
1404
|
consoleWarn,
|