@websolutespa/bom-core 1.7.11 → 1.7.13
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 +406 -14
- package/dist/index.js +317 -255
- package/dist/index.mjs +309 -253
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -37,6 +37,8 @@ __export(src_exports, {
|
|
|
37
37
|
RouteStrategy: () => RouteStrategy,
|
|
38
38
|
asCategoryId: () => asCategoryId,
|
|
39
39
|
asEquatable: () => asEquatable,
|
|
40
|
+
asEquatableNumber: () => asEquatableNumber,
|
|
41
|
+
asEquatableString: () => asEquatableString,
|
|
40
42
|
asServerProps: () => asServerProps,
|
|
41
43
|
asSortedOptions: () => asSortedOptions,
|
|
42
44
|
awaitAll: () => awaitAll,
|
|
@@ -52,6 +54,10 @@ __export(src_exports, {
|
|
|
52
54
|
eachCategorized: () => eachCategorized,
|
|
53
55
|
eachMarketLocale: () => eachMarketLocale,
|
|
54
56
|
enumToList: () => enumToList,
|
|
57
|
+
findCategoryInCategories: () => findCategoryInCategories,
|
|
58
|
+
findChildCategories: () => findChildCategories,
|
|
59
|
+
findRouteOfCategory: () => findRouteOfCategory,
|
|
60
|
+
findRoutesOfCategory: () => findRoutesOfCategory,
|
|
55
61
|
getCategorySegments: () => getCategorySegments,
|
|
56
62
|
getCategorySegmentsByCategory: () => getCategorySegmentsByCategory,
|
|
57
63
|
getClassNames: () => getClassNames,
|
|
@@ -62,6 +68,7 @@ __export(src_exports, {
|
|
|
62
68
|
getIsProduction: () => getIsProduction,
|
|
63
69
|
getOrigin: () => getOrigin,
|
|
64
70
|
getParentCategoriesById: () => getParentCategoriesById,
|
|
71
|
+
getParentCategory: () => getParentCategory,
|
|
65
72
|
getProto: () => getProto,
|
|
66
73
|
getRootCategory: () => getRootCategory,
|
|
67
74
|
getRouteHref: () => getRouteHref,
|
|
@@ -73,7 +80,6 @@ __export(src_exports, {
|
|
|
73
80
|
httpPut: () => httpPut,
|
|
74
81
|
isArray: () => isArray,
|
|
75
82
|
isBrowser: () => isBrowser,
|
|
76
|
-
isCategory: () => isCategory,
|
|
77
83
|
isDevelopment: () => isDevelopment,
|
|
78
84
|
isEntity: () => isEntity,
|
|
79
85
|
isEquatable: () => isEquatable,
|
|
@@ -115,7 +121,6 @@ __export(src_exports, {
|
|
|
115
121
|
qsSerialize: () => qsSerialize,
|
|
116
122
|
qsSerializeRaw: () => qsSerializeRaw,
|
|
117
123
|
resolveMediaType: () => resolveMediaType,
|
|
118
|
-
textToSlug: () => textToSlug,
|
|
119
124
|
toCamelCase: () => toCamelCase,
|
|
120
125
|
toCharCase: () => toCharCase,
|
|
121
126
|
toDisplayName: () => toDisplayName,
|
|
@@ -127,181 +132,85 @@ __export(src_exports, {
|
|
|
127
132
|
toTitleCase: () => toTitleCase,
|
|
128
133
|
toValidCollectionName: () => toValidCollectionName,
|
|
129
134
|
unknownCaseToPascalCase: () => unknownCaseToPascalCase,
|
|
135
|
+
uuidv4: () => uuidv4,
|
|
130
136
|
withSchema: () => withSchema
|
|
131
137
|
});
|
|
132
138
|
module.exports = __toCommonJS(src_exports);
|
|
133
139
|
|
|
134
|
-
// src/
|
|
135
|
-
function
|
|
136
|
-
return
|
|
137
|
-
}
|
|
138
|
-
function asCategoryId(value) {
|
|
139
|
-
return isCategory(value) ? value.id : value;
|
|
140
|
-
}
|
|
141
|
-
var ROOT_CATEGORY = process.env.ROOT_CATEGORY || "";
|
|
142
|
-
function getRootCategory(categories) {
|
|
143
|
-
const rootCategory = ROOT_CATEGORY && categories.find((x) => x.id == ROOT_CATEGORY);
|
|
144
|
-
if (rootCategory) {
|
|
145
|
-
return rootCategory;
|
|
146
|
-
} else {
|
|
147
|
-
return categories.find((x) => x.category == null);
|
|
148
|
-
}
|
|
140
|
+
// src/utils/typeGuards.ts
|
|
141
|
+
function isNumber(item) {
|
|
142
|
+
return typeof item === "number";
|
|
149
143
|
}
|
|
150
|
-
function
|
|
151
|
-
|
|
152
|
-
const routeCategories = [];
|
|
153
|
-
const segments = [];
|
|
154
|
-
let parentId = id || null;
|
|
155
|
-
while (parentId != null) {
|
|
156
|
-
const parentCategory = categories.find((c) => c.id === parentId);
|
|
157
|
-
if (parentCategory) {
|
|
158
|
-
if (parentCategory.slug || parentCategory.id === rootCategory?.id) {
|
|
159
|
-
const segment = { ...parentCategory };
|
|
160
|
-
segments.unshift(segment);
|
|
161
|
-
}
|
|
162
|
-
parentId = parentCategory.category ? asCategoryId(parentCategory.category) : null;
|
|
163
|
-
if (parentId) {
|
|
164
|
-
if (routeCategories.includes(parentId)) {
|
|
165
|
-
console.log("ICategory.getParentCategoriesById", "circular reference found", parentId);
|
|
166
|
-
parentId = null;
|
|
167
|
-
} else {
|
|
168
|
-
routeCategories.push(parentId);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
} else {
|
|
172
|
-
parentId = null;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return segments;
|
|
144
|
+
function isString(item) {
|
|
145
|
+
return typeof item === "string";
|
|
176
146
|
}
|
|
177
|
-
function
|
|
178
|
-
|
|
179
|
-
const segments = getParentCategoriesById(categoryId, categories);
|
|
180
|
-
return segments;
|
|
147
|
+
function isValidString(item) {
|
|
148
|
+
return typeof item === "string" && item.length > 0;
|
|
181
149
|
}
|
|
182
|
-
function
|
|
183
|
-
|
|
184
|
-
const segments = categoryId ? getParentCategoriesById(categoryId, categories) : [];
|
|
185
|
-
segments.push(item);
|
|
186
|
-
return segments;
|
|
150
|
+
function isArray(item) {
|
|
151
|
+
return Array.isArray(item);
|
|
187
152
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
function isClassNameCollection(value) {
|
|
191
|
-
return typeof value === "object" && !Array.isArray(value);
|
|
153
|
+
function isObject(item) {
|
|
154
|
+
return item != null && typeof item === "object" && !isArray(item);
|
|
192
155
|
}
|
|
193
|
-
function
|
|
194
|
-
|
|
195
|
-
const total = keys.length;
|
|
196
|
-
let classNames = "";
|
|
197
|
-
for (let i = 0; i < total; i++) {
|
|
198
|
-
const key = keys[i];
|
|
199
|
-
const value = className[keys[i]];
|
|
200
|
-
if (!value) {
|
|
201
|
-
continue;
|
|
202
|
-
}
|
|
203
|
-
classNames = classNames ? `${classNames} ${String(key)}` : String(key);
|
|
204
|
-
}
|
|
205
|
-
return classNames;
|
|
156
|
+
function isPromise(result) {
|
|
157
|
+
return isObject(result) && typeof result.then === "function";
|
|
206
158
|
}
|
|
207
|
-
function
|
|
208
|
-
|
|
209
|
-
let classNames = "";
|
|
210
|
-
if (total === 0) {
|
|
211
|
-
return classNames;
|
|
212
|
-
}
|
|
213
|
-
for (let i = 0; i < total; i++) {
|
|
214
|
-
const value = props[i];
|
|
215
|
-
if (!value) {
|
|
216
|
-
continue;
|
|
217
|
-
}
|
|
218
|
-
if (isClassNameCollection(value)) {
|
|
219
|
-
classNames += ` ${classNameCollectionToString(value)}`;
|
|
220
|
-
} else {
|
|
221
|
-
classNames += ` ${String(value).trim()}`;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return classNames.trim();
|
|
159
|
+
function isNotNullString(item) {
|
|
160
|
+
return typeof item === "string" && Boolean(item);
|
|
225
161
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
var import_pluralize = __toESM(require("pluralize"));
|
|
229
|
-
function getCollectionDescription(text) {
|
|
230
|
-
text = toValidCollectionName(text);
|
|
231
|
-
const displayName = toDisplayName(text);
|
|
232
|
-
const pluralName = toPluralName(text);
|
|
233
|
-
const pluralDisplayName = toDisplayName(pluralName);
|
|
234
|
-
const singularName = text;
|
|
235
|
-
const title = toTitleCase(text);
|
|
236
|
-
return {
|
|
237
|
-
displayName,
|
|
238
|
-
pluralName,
|
|
239
|
-
pluralDisplayName,
|
|
240
|
-
singularName,
|
|
241
|
-
title
|
|
242
|
-
};
|
|
162
|
+
function isEquatable(item) {
|
|
163
|
+
return typeof item === "number" || isNotNullString(item);
|
|
243
164
|
}
|
|
244
|
-
function
|
|
245
|
-
return
|
|
246
|
-
return index > 0 ? `_${letter.toLowerCase()}` : letter.toLowerCase();
|
|
247
|
-
});
|
|
165
|
+
function isEntity(item) {
|
|
166
|
+
return isObject(item) && isEquatable(item.id);
|
|
248
167
|
}
|
|
249
|
-
function
|
|
250
|
-
return
|
|
168
|
+
function isUnresolvedRelation(item) {
|
|
169
|
+
return isObject(item) && isNotNullString(item.relationTo) && (isEquatable(item.value) || isArray(item.value));
|
|
251
170
|
}
|
|
252
|
-
function
|
|
253
|
-
return
|
|
254
|
-
"category",
|
|
255
|
-
"label",
|
|
256
|
-
"locale",
|
|
257
|
-
"market",
|
|
258
|
-
"menu",
|
|
259
|
-
"redirect",
|
|
260
|
-
"route",
|
|
261
|
-
"template"
|
|
262
|
-
].includes(description.singularName);
|
|
171
|
+
function isRelation(item) {
|
|
172
|
+
return isObject(item) && isNotNullString(item.relationTo) && isEntity(item.value);
|
|
263
173
|
}
|
|
264
|
-
function
|
|
265
|
-
return
|
|
174
|
+
function isUndecoratedMenuItem(item) {
|
|
175
|
+
return isObject(item) && (item.type === "category" && isEquatable(item.category) || item.type === "page" && isEquatable(item.page.value));
|
|
266
176
|
}
|
|
267
|
-
function
|
|
268
|
-
|
|
269
|
-
return plural === text ? `${plural}es` : plural;
|
|
177
|
+
function isUndecoratedNav(item) {
|
|
178
|
+
return isObject(item) && isUndecoratedMenuPage(item.nav);
|
|
270
179
|
}
|
|
271
|
-
function
|
|
272
|
-
return
|
|
180
|
+
function isUndecoratedMenuCategory(item) {
|
|
181
|
+
return isObject(item) && item.type === "category" && isNotNullString(item.category) && item.id === void 0 && item.href === void 0;
|
|
273
182
|
}
|
|
274
|
-
function
|
|
275
|
-
|
|
276
|
-
text = camelToSnakeCase(text);
|
|
277
|
-
text = text.replace(/__/g, "_");
|
|
278
|
-
return text.toLowerCase();
|
|
183
|
+
function isUndecoratedMenuPage(item) {
|
|
184
|
+
return isObject(item) && item.type === "page" && isObject(item.page) && isNotNullString(item.page.relationTo) && isEquatable(item.page.value);
|
|
279
185
|
}
|
|
280
186
|
|
|
281
|
-
// src/
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
if (typeof
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
const log = `[DesignSystem]${tag}: ${message}`;
|
|
289
|
-
if (warningStack[log]) {
|
|
290
|
-
return;
|
|
187
|
+
// src/utils/asEquatable.ts
|
|
188
|
+
function asEquatable(value) {
|
|
189
|
+
const id = isEntity(value) ? value.id : value;
|
|
190
|
+
if (typeof id === "string") {
|
|
191
|
+
if (String(parseInt(id)) === id) {
|
|
192
|
+
return Number(id);
|
|
193
|
+
}
|
|
291
194
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
195
|
+
return id;
|
|
196
|
+
}
|
|
197
|
+
function asEquatableString(value) {
|
|
198
|
+
const id = isEntity(value) ? value.id : value;
|
|
199
|
+
if (typeof id !== "undefined") {
|
|
200
|
+
return String(id);
|
|
295
201
|
}
|
|
296
|
-
|
|
202
|
+
return id;
|
|
297
203
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
204
|
+
function asEquatableNumber(value) {
|
|
205
|
+
const id = isEntity(value) ? value.id : value;
|
|
206
|
+
if (typeof id === "string") {
|
|
207
|
+
if (String(parseInt(id)) === id) {
|
|
208
|
+
return Number(id);
|
|
209
|
+
} else {
|
|
210
|
+
return void 0;
|
|
211
|
+
}
|
|
303
212
|
}
|
|
304
|
-
return
|
|
213
|
+
return id;
|
|
305
214
|
}
|
|
306
215
|
|
|
307
216
|
// src/utils/asSortedOptions.ts
|
|
@@ -364,53 +273,6 @@ function toSnakeCase(unknownCase) {
|
|
|
364
273
|
return snakeCase;
|
|
365
274
|
}
|
|
366
275
|
|
|
367
|
-
// src/utils/typeGuards.ts
|
|
368
|
-
function isNumber(item) {
|
|
369
|
-
return typeof item === "number";
|
|
370
|
-
}
|
|
371
|
-
function isString(item) {
|
|
372
|
-
return typeof item === "string";
|
|
373
|
-
}
|
|
374
|
-
function isValidString(item) {
|
|
375
|
-
return typeof item === "string" && item.length > 0;
|
|
376
|
-
}
|
|
377
|
-
function isArray(item) {
|
|
378
|
-
return Array.isArray(item);
|
|
379
|
-
}
|
|
380
|
-
function isObject(item) {
|
|
381
|
-
return item != null && typeof item === "object" && !isArray(item);
|
|
382
|
-
}
|
|
383
|
-
function isPromise(result) {
|
|
384
|
-
return isObject(result) && typeof result.then === "function";
|
|
385
|
-
}
|
|
386
|
-
function isNotNullString(item) {
|
|
387
|
-
return typeof item === "string" && Boolean(item);
|
|
388
|
-
}
|
|
389
|
-
function isEquatable(item) {
|
|
390
|
-
return typeof item === "number" || isNotNullString(item);
|
|
391
|
-
}
|
|
392
|
-
function isEntity(item) {
|
|
393
|
-
return isObject(item) && isEquatable(item.id);
|
|
394
|
-
}
|
|
395
|
-
function isUnresolvedRelation(item) {
|
|
396
|
-
return isObject(item) && isNotNullString(item.relationTo) && (isEquatable(item.value) || isArray(item.value));
|
|
397
|
-
}
|
|
398
|
-
function isRelation(item) {
|
|
399
|
-
return isObject(item) && isNotNullString(item.relationTo) && isEntity(item.value);
|
|
400
|
-
}
|
|
401
|
-
function isUndecoratedMenuItem(item) {
|
|
402
|
-
return isObject(item) && (item.type === "category" && isEquatable(item.category) || item.type === "page" && isEquatable(item.page.value));
|
|
403
|
-
}
|
|
404
|
-
function isUndecoratedNav(item) {
|
|
405
|
-
return isObject(item) && isUndecoratedMenuPage(item.nav);
|
|
406
|
-
}
|
|
407
|
-
function isUndecoratedMenuCategory(item) {
|
|
408
|
-
return isObject(item) && item.type === "category" && isNotNullString(item.category) && item.id === void 0 && item.href === void 0;
|
|
409
|
-
}
|
|
410
|
-
function isUndecoratedMenuPage(item) {
|
|
411
|
-
return isObject(item) && item.type === "page" && isObject(item.page) && isNotNullString(item.page.relationTo) && isEquatable(item.page.value);
|
|
412
|
-
}
|
|
413
|
-
|
|
414
276
|
// src/utils/cloneItem.ts
|
|
415
277
|
function cloneItem(item) {
|
|
416
278
|
if (isArray(item)) {
|
|
@@ -511,6 +373,14 @@ function enumToList(enumeration, separatorRegex = /_/g) {
|
|
|
511
373
|
}));
|
|
512
374
|
}
|
|
513
375
|
|
|
376
|
+
// src/utils/uuid.ts
|
|
377
|
+
function uuidv4() {
|
|
378
|
+
return "10000000-1000-4000-8000-100000000000".replace(
|
|
379
|
+
/[018]/g,
|
|
380
|
+
(c) => (+c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> +c / 4).toString(16)
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
|
|
514
384
|
// src/utils/index.ts
|
|
515
385
|
function getIsDevelopment() {
|
|
516
386
|
return process && (!process.env.NODE_ENV || process.env.NODE_ENV === "development");
|
|
@@ -564,6 +434,177 @@ function merge(target, source) {
|
|
|
564
434
|
return target;
|
|
565
435
|
}
|
|
566
436
|
|
|
437
|
+
// src/category/category.ts
|
|
438
|
+
var ROOT_CATEGORY = process.env.ROOT_CATEGORY || "";
|
|
439
|
+
function getRootCategory(categories) {
|
|
440
|
+
const rootCategory = ROOT_CATEGORY && categories.find((x) => x.id == ROOT_CATEGORY);
|
|
441
|
+
if (rootCategory) {
|
|
442
|
+
return rootCategory;
|
|
443
|
+
} else {
|
|
444
|
+
return categories.find((x) => x.category == null);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
function getParentCategory(categories, item) {
|
|
448
|
+
const parentCategoryId = asCategoryId(item.category);
|
|
449
|
+
const parentCategory = parentCategoryId ? categories.find((x) => x.id === parentCategoryId) : void 0;
|
|
450
|
+
return parentCategory;
|
|
451
|
+
}
|
|
452
|
+
function getParentCategoriesById(categories, id) {
|
|
453
|
+
const routeCategories = [];
|
|
454
|
+
const segments = [];
|
|
455
|
+
let parentId = id;
|
|
456
|
+
while (parentId != null) {
|
|
457
|
+
const parentCategory = categories.find((c) => c.id === parentId);
|
|
458
|
+
if (parentCategory) {
|
|
459
|
+
const segment = { ...parentCategory };
|
|
460
|
+
segments.unshift(segment);
|
|
461
|
+
routeCategories.push(parentId);
|
|
462
|
+
parentId = asCategoryId(parentCategory.category);
|
|
463
|
+
if (parentId) {
|
|
464
|
+
if (routeCategories.includes(parentId)) {
|
|
465
|
+
console.log("ICategory.getParentCategoriesById", "circular reference found", parentId);
|
|
466
|
+
parentId = void 0;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
} else {
|
|
470
|
+
parentId = void 0;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return segments;
|
|
474
|
+
}
|
|
475
|
+
function getCategorySegments(categories, item) {
|
|
476
|
+
const parentCategoryId = asCategoryId(item.category);
|
|
477
|
+
const segments = getParentCategoriesById(categories, parentCategoryId);
|
|
478
|
+
return segments;
|
|
479
|
+
}
|
|
480
|
+
function getCategorySegmentsByCategory(categories, item) {
|
|
481
|
+
const parentCategoryId = asCategoryId(item.category);
|
|
482
|
+
const segments = parentCategoryId ? getParentCategoriesById(categories, parentCategoryId) : [];
|
|
483
|
+
segments.push(item);
|
|
484
|
+
return segments;
|
|
485
|
+
}
|
|
486
|
+
function asCategoryId(value) {
|
|
487
|
+
return isEntity(value) ? String(value.id) : value ? String(value) : void 0;
|
|
488
|
+
}
|
|
489
|
+
function findCategoryInCategories(categories, item) {
|
|
490
|
+
const categoryId = asCategoryId(item);
|
|
491
|
+
return categoryId ? categories.find((x) => x.id === categoryId) : void 0;
|
|
492
|
+
}
|
|
493
|
+
function findChildCategories(categories, item) {
|
|
494
|
+
const categoryId = asCategoryId(item);
|
|
495
|
+
return categoryId ? categories.filter((x) => asCategoryId(x.category) === categoryId) : [];
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// src/classNames/classNames.ts
|
|
499
|
+
function isClassNameCollection(value) {
|
|
500
|
+
return typeof value === "object" && !Array.isArray(value);
|
|
501
|
+
}
|
|
502
|
+
function classNameCollectionToString(className) {
|
|
503
|
+
const keys = Object.keys(className);
|
|
504
|
+
const total = keys.length;
|
|
505
|
+
let classNames = "";
|
|
506
|
+
for (let i = 0; i < total; i++) {
|
|
507
|
+
const key = keys[i];
|
|
508
|
+
const value = className[keys[i]];
|
|
509
|
+
if (!value) {
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
classNames = classNames ? `${classNames} ${String(key)}` : String(key);
|
|
513
|
+
}
|
|
514
|
+
return classNames;
|
|
515
|
+
}
|
|
516
|
+
function getClassNames(...props) {
|
|
517
|
+
const total = props.length;
|
|
518
|
+
let classNames = "";
|
|
519
|
+
if (total === 0) {
|
|
520
|
+
return classNames;
|
|
521
|
+
}
|
|
522
|
+
for (let i = 0; i < total; i++) {
|
|
523
|
+
const value = props[i];
|
|
524
|
+
if (!value) {
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
if (isClassNameCollection(value)) {
|
|
528
|
+
classNames += ` ${classNameCollectionToString(value)}`;
|
|
529
|
+
} else {
|
|
530
|
+
classNames += ` ${String(value).trim()}`;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return classNames.trim();
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// src/collection/collection.ts
|
|
537
|
+
var import_pluralize = __toESM(require("pluralize"));
|
|
538
|
+
function getCollectionDescription(text) {
|
|
539
|
+
text = toValidCollectionName(text);
|
|
540
|
+
const displayName = toDisplayName(text);
|
|
541
|
+
const pluralName = toPluralName(text);
|
|
542
|
+
const pluralDisplayName = toDisplayName(pluralName);
|
|
543
|
+
const singularName = text;
|
|
544
|
+
const title = toTitleCase(text);
|
|
545
|
+
return {
|
|
546
|
+
displayName,
|
|
547
|
+
pluralName,
|
|
548
|
+
pluralDisplayName,
|
|
549
|
+
singularName,
|
|
550
|
+
title
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
function camelToSnakeCase(text) {
|
|
554
|
+
return text.replace(/[A-Z]/g, (letter, index) => {
|
|
555
|
+
return index > 0 ? `_${letter.toLowerCase()}` : letter.toLowerCase();
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
function isValidCollectionDescription(description) {
|
|
559
|
+
return description.singularName !== description.pluralName;
|
|
560
|
+
}
|
|
561
|
+
function isReservedCollectionDescription(description) {
|
|
562
|
+
return [
|
|
563
|
+
"category",
|
|
564
|
+
"label",
|
|
565
|
+
"locale",
|
|
566
|
+
"market",
|
|
567
|
+
"menu",
|
|
568
|
+
"redirect",
|
|
569
|
+
"route",
|
|
570
|
+
"template"
|
|
571
|
+
].includes(description.singularName);
|
|
572
|
+
}
|
|
573
|
+
function toDisplayName(text) {
|
|
574
|
+
return toTitleCase(text).replace(/\s/g, "");
|
|
575
|
+
}
|
|
576
|
+
function toPluralName(text) {
|
|
577
|
+
const plural = import_pluralize.default.plural(text);
|
|
578
|
+
return plural === text ? `${plural}es` : plural;
|
|
579
|
+
}
|
|
580
|
+
function toTitleCase(text) {
|
|
581
|
+
return text.replace(/^[-_]*(.)/, (_, c) => c.toUpperCase()).replace(/[-_]+(.)/g, (_, c) => " " + c.toUpperCase());
|
|
582
|
+
}
|
|
583
|
+
function toValidCollectionName(text) {
|
|
584
|
+
text = text.trim().replace(/\W/g, "_").replace(/^[_]*(.)/, (_, c) => c);
|
|
585
|
+
text = camelToSnakeCase(text);
|
|
586
|
+
text = text.replace(/__/g, "_");
|
|
587
|
+
return text.toLowerCase();
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
// src/consoleWarn/consoleWarn.ts
|
|
591
|
+
var warningStack = {};
|
|
592
|
+
function consoleWarn(message, component) {
|
|
593
|
+
if (typeof console === "undefined") {
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
const tag = component ? ` [${component}]` : " ";
|
|
597
|
+
const log = `[DesignSystem]${tag}: ${message}`;
|
|
598
|
+
if (warningStack[log]) {
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
warningStack[log] = true;
|
|
602
|
+
if (process.env.NODE_ENV !== "production") {
|
|
603
|
+
return console.error(log);
|
|
604
|
+
}
|
|
605
|
+
console.warn(log);
|
|
606
|
+
}
|
|
607
|
+
|
|
567
608
|
// src/http/http.service.ts
|
|
568
609
|
var defaultOptions = {
|
|
569
610
|
// method: 'POST', // *GET, POST, PUT, DELETE, etc.
|
|
@@ -1212,58 +1253,74 @@ function getOrigin(headers) {
|
|
|
1212
1253
|
}
|
|
1213
1254
|
|
|
1214
1255
|
// src/route/route.ts
|
|
1256
|
+
var RouteStrategy = /* @__PURE__ */ ((RouteStrategy2) => {
|
|
1257
|
+
RouteStrategy2["Auto"] = "auto";
|
|
1258
|
+
RouteStrategy2["Default"] = "default";
|
|
1259
|
+
RouteStrategy2["Manual"] = "manual";
|
|
1260
|
+
return RouteStrategy2;
|
|
1261
|
+
})(RouteStrategy || {});
|
|
1262
|
+
var ROUTE_STRATEGY = process.env.ROUTE_STRATEGY || "auto" /* Auto */;
|
|
1263
|
+
function getPickedProps(item) {
|
|
1264
|
+
const pickedProps = Object.fromEntries(Object.entries(item).filter(([k, v]) => [
|
|
1265
|
+
"category",
|
|
1266
|
+
"isDefault",
|
|
1267
|
+
"media",
|
|
1268
|
+
"order",
|
|
1269
|
+
"template",
|
|
1270
|
+
"updatedAt",
|
|
1271
|
+
"useSplat"
|
|
1272
|
+
].includes(k)));
|
|
1273
|
+
return pickedProps;
|
|
1274
|
+
}
|
|
1215
1275
|
function collectRoutes(store, categories, markets, locales) {
|
|
1216
1276
|
const routes = [];
|
|
1217
1277
|
if (locales.length > 0 && markets.length > 0) {
|
|
1218
1278
|
const rootCategory = getRootCategory(categories);
|
|
1219
1279
|
eachCategorized(store, (item, key) => {
|
|
1220
|
-
const segments = getCategorySegments(
|
|
1221
|
-
const
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1280
|
+
const segments = getCategorySegments(categories, item);
|
|
1281
|
+
const visibleSegments = segments.filter((x) => Boolean(x.isHidden) === false);
|
|
1282
|
+
const visibleCategory = visibleSegments.length > 0 ? visibleSegments[visibleSegments.length - 1] : rootCategory;
|
|
1283
|
+
if (visibleCategory) {
|
|
1284
|
+
const slugs = visibleSegments.map((x) => ({ slug: x.slug }));
|
|
1285
|
+
if (Boolean(item.isDefault) === false) {
|
|
1286
|
+
slugs.push({ slug: item.slug });
|
|
1287
|
+
}
|
|
1288
|
+
if (rootCategory && item.category === rootCategory.id) {
|
|
1289
|
+
const defaultLocale2 = locales.find((x) => x.isDefault) || locales[0];
|
|
1290
|
+
const defaultMarket2 = markets.find((x) => x.isDefault) || markets[0];
|
|
1291
|
+
const defaultMarketLocale = defaultMarket2 && defaultMarket2.defaultLanguage ? defaultMarket2.defaultLanguage : defaultLocale2.id;
|
|
1292
|
+
const title = localize(item.title, defaultMarketLocale);
|
|
1293
|
+
const pickedProps = getPickedProps(item);
|
|
1229
1294
|
const route = {
|
|
1230
|
-
|
|
1231
|
-
id,
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
media: item.media,
|
|
1236
|
-
order: item.order,
|
|
1295
|
+
...pickedProps,
|
|
1296
|
+
resolvedCategory: rootCategory.id,
|
|
1297
|
+
id: "/",
|
|
1298
|
+
market: defaultMarket2.id,
|
|
1299
|
+
locale: defaultMarketLocale,
|
|
1237
1300
|
page: item.id,
|
|
1238
1301
|
schema: key,
|
|
1239
|
-
|
|
1240
|
-
title,
|
|
1241
|
-
updatedAt: item.updatedAt,
|
|
1242
|
-
useSplat: item.useSplat
|
|
1302
|
+
title
|
|
1243
1303
|
};
|
|
1244
1304
|
routes.push(route);
|
|
1245
1305
|
}
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
updatedAt: item.updatedAt
|
|
1265
|
-
};
|
|
1266
|
-
routes.push(route);
|
|
1306
|
+
eachMarketLocale(markets, locales, (market, locale, markets2, locales2) => {
|
|
1307
|
+
if (!item.markets || item.markets.includes(market.id)) {
|
|
1308
|
+
const title = localize(item.title, locale.id);
|
|
1309
|
+
const id = getRouteHref(slugs, market, locale, markets2, locales2);
|
|
1310
|
+
const pickedProps = getPickedProps(item);
|
|
1311
|
+
const route = {
|
|
1312
|
+
...pickedProps,
|
|
1313
|
+
resolvedCategory: visibleCategory.id,
|
|
1314
|
+
id,
|
|
1315
|
+
locale: locale.id,
|
|
1316
|
+
market: market.id,
|
|
1317
|
+
page: item.id,
|
|
1318
|
+
schema: key,
|
|
1319
|
+
title
|
|
1320
|
+
};
|
|
1321
|
+
routes.push(route);
|
|
1322
|
+
}
|
|
1323
|
+
});
|
|
1267
1324
|
}
|
|
1268
1325
|
});
|
|
1269
1326
|
}
|
|
@@ -1288,13 +1345,17 @@ function eachCategorized(store, callback) {
|
|
|
1288
1345
|
}
|
|
1289
1346
|
}
|
|
1290
1347
|
}
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1348
|
+
function findRouteOfCategory(routes, categoryId, market, locale) {
|
|
1349
|
+
const findRoute = market && locale ? (route2) => route2.isDefault && route2.resolvedCategory === categoryId && route2.market === market && route2.locale === locale : (route2) => route2.isDefault && route2.resolvedCategory === categoryId;
|
|
1350
|
+
const route = routes.find(findRoute);
|
|
1351
|
+
return route;
|
|
1352
|
+
}
|
|
1353
|
+
function findRoutesOfCategory(routes, categoryId, isDefault = true) {
|
|
1354
|
+
const filteredRoutes = routes.filter(
|
|
1355
|
+
(route) => route.resolvedCategory === categoryId && Boolean(route.isDefault) === isDefault
|
|
1356
|
+
);
|
|
1357
|
+
return filteredRoutes;
|
|
1358
|
+
}
|
|
1298
1359
|
function getRouteHref(segments, market, locale, markets, locales) {
|
|
1299
1360
|
const href = segments.reduce((p, c, i) => {
|
|
1300
1361
|
let slug = localize(c.slug || "", locale.id);
|
|
@@ -1332,11 +1393,6 @@ function getRouteHref(segments, market, locale, markets, locales) {
|
|
|
1332
1393
|
return `${prefix}${href}`;
|
|
1333
1394
|
}
|
|
1334
1395
|
|
|
1335
|
-
// src/slug/slug.ts
|
|
1336
|
-
function textToSlug(title) {
|
|
1337
|
-
return title.toString().normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/\s+/g, "-").replace(/&/g, "-and-").replace(/[^\w-]+/g, "").replace(/--+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
1396
|
// src/types/media.ts
|
|
1341
1397
|
function resolveMediaType(media) {
|
|
1342
1398
|
if (typeof media.type === "string" && media.type.length > 0) {
|
|
@@ -1413,6 +1469,8 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
|
|
|
1413
1469
|
RouteStrategy,
|
|
1414
1470
|
asCategoryId,
|
|
1415
1471
|
asEquatable,
|
|
1472
|
+
asEquatableNumber,
|
|
1473
|
+
asEquatableString,
|
|
1416
1474
|
asServerProps,
|
|
1417
1475
|
asSortedOptions,
|
|
1418
1476
|
awaitAll,
|
|
@@ -1428,6 +1486,10 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
|
|
|
1428
1486
|
eachCategorized,
|
|
1429
1487
|
eachMarketLocale,
|
|
1430
1488
|
enumToList,
|
|
1489
|
+
findCategoryInCategories,
|
|
1490
|
+
findChildCategories,
|
|
1491
|
+
findRouteOfCategory,
|
|
1492
|
+
findRoutesOfCategory,
|
|
1431
1493
|
getCategorySegments,
|
|
1432
1494
|
getCategorySegmentsByCategory,
|
|
1433
1495
|
getClassNames,
|
|
@@ -1438,6 +1500,7 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
|
|
|
1438
1500
|
getIsProduction,
|
|
1439
1501
|
getOrigin,
|
|
1440
1502
|
getParentCategoriesById,
|
|
1503
|
+
getParentCategory,
|
|
1441
1504
|
getProto,
|
|
1442
1505
|
getRootCategory,
|
|
1443
1506
|
getRouteHref,
|
|
@@ -1449,7 +1512,6 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
|
|
|
1449
1512
|
httpPut,
|
|
1450
1513
|
isArray,
|
|
1451
1514
|
isBrowser,
|
|
1452
|
-
isCategory,
|
|
1453
1515
|
isDevelopment,
|
|
1454
1516
|
isEntity,
|
|
1455
1517
|
isEquatable,
|
|
@@ -1491,7 +1553,6 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
|
|
|
1491
1553
|
qsSerialize,
|
|
1492
1554
|
qsSerializeRaw,
|
|
1493
1555
|
resolveMediaType,
|
|
1494
|
-
textToSlug,
|
|
1495
1556
|
toCamelCase,
|
|
1496
1557
|
toCharCase,
|
|
1497
1558
|
toDisplayName,
|
|
@@ -1503,5 +1564,6 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
|
|
|
1503
1564
|
toTitleCase,
|
|
1504
1565
|
toValidCollectionName,
|
|
1505
1566
|
unknownCaseToPascalCase,
|
|
1567
|
+
uuidv4,
|
|
1506
1568
|
withSchema
|
|
1507
1569
|
});
|