@ubnt/store.core 9.12.0-alpha.0 → 9.12.0-alpha.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 +4 -0
- package/lib/_virtual/_virtual_multi-entry.js +15 -2
- package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
- package/lib/_virtual/_virtual_multi-entry.mjs +2 -0
- package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
- package/lib/assets/attention.svg +5 -5
- package/lib/assets/attention2.svg +5 -5
- package/lib/assets/check2.svg +3 -3
- package/lib/assets/check3.svg +3 -3
- package/lib/assets/close2.svg +3 -2
- package/lib/assets/close3.svg +2 -3
- package/lib/assets/ucgMax.jpg +0 -0
- package/lib/assets/ucgMax2.jpg +0 -0
- package/lib/assets/ucgUltra.jpg +0 -0
- package/lib/assets/ucgUltra2.jpg +0 -0
- package/lib/assets/udmPro.jpg +0 -0
- package/lib/assets/udmPro2.jpg +0 -0
- package/lib/assets/udmProMax.jpg +0 -0
- package/lib/assets/udmProMax2.jpg +0 -0
- package/lib/assets/udmProSpecial.jpg +0 -0
- package/lib/assets/udmProSpecial2.jpg +0 -0
- package/lib/components/Explore/ExploreData.js +2 -2
- package/lib/components/Explore/ExploreData.js.map +1 -1
- package/lib/components/Explore/ExploreData.mjs +2 -2
- package/lib/components/Explore/ExploreData.mjs.map +1 -1
- package/lib/components/Explore/assets/{uispConsole.jpg.js → UISPConsole.jpg.js} +2 -2
- package/lib/components/Explore/assets/UISPConsole.jpg.js.map +1 -0
- package/lib/components/Explore/assets/UISPConsole.jpg.mjs +3 -0
- package/lib/components/Explore/assets/UISPConsole.jpg.mjs.map +1 -0
- package/lib/components/FeaturesSection_deprecated/FeaturesSection.js +1 -1
- package/lib/components/FeaturesSection_deprecated/FeaturesSection.mjs +1 -1
- package/lib/components/FeaturesSection_deprecated/assets/close.svg.js +1 -1
- package/lib/components/FeaturesSection_deprecated/assets/close.svg.mjs +2 -2
- package/lib/components/ModelCompareV3/ModelComparePropertyValueGridItem.js +1 -1
- package/lib/components/ModelCompareV3/ModelComparePropertyValueGridItem.mjs +1 -1
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgMax.jpg.js +5 -5
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgMax.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.js +5 -5
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.js +5 -5
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProMax.jpg.js +5 -5
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProMax.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.js +5 -5
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/ucgMax.jpg.js +1 -1
- package/lib/components/ModelCompareV3/assets/Consoles/ucgMax.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.js +1 -1
- package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.js +1 -1
- package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/udmProMax.jpg.js +1 -1
- package/lib/components/ModelCompareV3/assets/Consoles/udmProMax.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.js +1 -1
- package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/check.svg.js +1 -1
- package/lib/components/ModelCompareV3/assets/check.svg.mjs +2 -2
- package/lib/components/ModelCompareV3/data/CloudGateways.js +15 -15
- package/lib/components/ModelCompareV3/data/CloudGateways.mjs +10 -10
- package/lib/components/ModelCompareV3/data/products/ucgMax.js +1 -1
- package/lib/components/ModelCompareV3/data/products/ucgMax.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/ucgUltra.js +1 -1
- package/lib/components/ModelCompareV3/data/products/ucgUltra.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/udmPro.js +1 -1
- package/lib/components/ModelCompareV3/data/products/udmPro.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/udmProMax.js +1 -1
- package/lib/components/ModelCompareV3/data/products/udmProMax.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/udmProSpecial.js +1 -1
- package/lib/components/ModelCompareV3/data/products/udmProSpecial.mjs +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.js +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.mjs +2 -2
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.js +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.mjs +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.js +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.mjs +2 -2
- package/lib/components/VariantSelector/CheckBox/CheckBox.js +1 -1
- package/lib/components/VariantSelector/CheckBox/CheckBox.mjs +1 -1
- package/lib/components/VariantSelector/CheckBox/assets/check.svg.js +1 -1
- package/lib/components/VariantSelector/CheckBox/assets/check.svg.mjs +2 -2
- package/lib/components/VideoPlayerNew/VideoPlayer.js +1 -1
- package/lib/components/VideoPlayerNew/VideoPlayer.mjs +1 -1
- package/lib/components/VideoPlayerNew/assets/close.svg.js +1 -1
- package/lib/components/VideoPlayerNew/assets/close.svg.mjs +2 -2
- package/lib/constants/icons/options/colors/black.svg.js +5 -5
- package/lib/constants/icons/options/colors/index.js +3 -3
- package/lib/constants/icons/options/styles/black.svg.js +5 -5
- package/lib/constants/icons/options/styles/index.js +3 -3
- package/lib/constants/optionIcons.js +6 -6
- package/lib/constants/optionIcons.mjs +4 -4
- package/lib/helpers/index.d.ts +1 -0
- package/lib/helpers/index.js +11 -0
- package/lib/helpers/index.js.map +1 -1
- package/lib/helpers/index.mjs +1 -0
- package/lib/helpers/index.mjs.map +1 -1
- package/lib/helpers/product.d.ts +87 -0
- package/lib/helpers/product.js +346 -0
- package/lib/helpers/product.js.map +1 -0
- package/lib/helpers/product.mjs +335 -0
- package/lib/helpers/product.mjs.map +1 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +2 -0
- package/lib/types/index.js.map +1 -1
- package/lib/types/index.mjs +1 -0
- package/lib/types/index.mjs.map +1 -1
- package/lib/types/product.d.ts +87 -0
- package/lib/types/product.js +14 -0
- package/lib/types/product.js.map +1 -0
- package/lib/types/product.mjs +13 -0
- package/lib/types/product.mjs.map +1 -0
- package/lib/utils/array.d.ts +4 -0
- package/lib/utils/array.js +10 -0
- package/lib/utils/array.js.map +1 -1
- package/lib/utils/array.mjs +10 -1
- package/lib/utils/array.mjs.map +1 -1
- package/lib/utils/productSort.d.ts +41 -0
- package/lib/utils/productSort.js +66 -0
- package/lib/utils/productSort.js.map +1 -0
- package/lib/utils/productSort.mjs +59 -0
- package/lib/utils/productSort.mjs.map +1 -0
- package/package.json +1 -1
- package/lib/components/Explore/assets/uispConsole.jpg.js.map +0 -1
- package/lib/components/Explore/assets/uispConsole.jpg.mjs +0 -3
- package/lib/components/Explore/assets/uispConsole.jpg.mjs.map +0 -1
- /package/lib/assets/{uispConsole.jpg → UISPConsole.jpg} +0 -0
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { cloneDeep } from 'lodash-es';
|
|
2
|
+
import '../constants/proStoreCategories/index.mjs';
|
|
3
|
+
import '../types/index.mjs';
|
|
4
|
+
import { areEqualArrays } from '../utils/array.mjs';
|
|
5
|
+
import { sortProducts } from '../utils/productSort.mjs';
|
|
6
|
+
import { getSubCategoryIdByCollectionSlug } from './proStoreCategories.mjs';
|
|
7
|
+
import { UniFiCategoryId } from '../constants/proStoreCategories/mapping/unifi.mjs';
|
|
8
|
+
import { UISPCategoryId } from '../constants/proStoreCategories/mapping/uisp.mjs';
|
|
9
|
+
import { DisplayProductStatus } from '../types/product.mjs';
|
|
10
|
+
"use strict";
|
|
11
|
+
const isNonNullish = entry => entry !== null && entry !== void 0;
|
|
12
|
+
const EXCLUDE_PRODUCT_FROM_STORE_GRID_TAG_PREFIX = "exclude-from-store-grid:";
|
|
13
|
+
const removeExcludedProducts = (products, storeId) => {
|
|
14
|
+
const excludeTag = `${EXCLUDE_PRODUCT_FROM_STORE_GRID_TAG_PREFIX}${storeId}`.toLowerCase();
|
|
15
|
+
return products.filter(product => {
|
|
16
|
+
return !product.tags.some(tag => tag.name.toLowerCase() === excludeTag);
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
const isAccessoryCategoryItem = categoryItem => {
|
|
20
|
+
return !!categoryItem && [UniFiCategoryId.Accessories, UISPCategoryId.AccessoryTech].includes(
|
|
21
|
+
// TODO: Check why this TS error appears
|
|
22
|
+
// @ts-expect-error: Unreachable code error
|
|
23
|
+
categoryItem.id);
|
|
24
|
+
};
|
|
25
|
+
var HDDProductSlugs = /* @__PURE__ */(HDDProductSlugs2 => {
|
|
26
|
+
HDDProductSlugs2["HDD_1TB"] = "uacc-hdd-s-1tb";
|
|
27
|
+
HDDProductSlugs2["HDD_8TB_Enterprise"] = "uacc-hdd-e-8tb";
|
|
28
|
+
HDDProductSlugs2["HDD_16TB_Enterprise"] = "uacc-hdd-e-16tb";
|
|
29
|
+
return HDDProductSlugs2;
|
|
30
|
+
})(HDDProductSlugs || {});
|
|
31
|
+
const isAllowedAccessoryCategoryProduct = ({
|
|
32
|
+
slug
|
|
33
|
+
}) => {
|
|
34
|
+
const allowedAccessoryProductSlugs = ["u-lte", "u-lte-backup-pro", "uacc-hdd-s-1tb" /* HDD_1TB */, "uacc-hdd-e-8tb" /* HDD_8TB_Enterprise */, "uacc-hdd-e-16tb" /* HDD_16TB_Enterprise */];
|
|
35
|
+
return allowedAccessoryProductSlugs.includes(slug);
|
|
36
|
+
};
|
|
37
|
+
const isAccessoryCategorySubItem = (categorySubItem, allCategoryItems) => {
|
|
38
|
+
const categoryItem = allCategoryItems.find(item => item.items?.some(subItem => subItem.id === categorySubItem.id));
|
|
39
|
+
return isAccessoryCategoryItem(categoryItem);
|
|
40
|
+
};
|
|
41
|
+
const createSectionHierarchy = (sections, level = 1) => {
|
|
42
|
+
const currentLevelSections = sections.filter(section => section.productTags.length === level);
|
|
43
|
+
if (!currentLevelSections.length) {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
return currentLevelSections.map(section => ({
|
|
47
|
+
...section,
|
|
48
|
+
items: createSectionHierarchy(sections.filter(nextSection => section.productTags.every(tag => nextSection.productTags.includes(tag))), level + 1)
|
|
49
|
+
}));
|
|
50
|
+
};
|
|
51
|
+
var MagicCollectionTags = /* @__PURE__ */(MagicCollectionTags2 => {
|
|
52
|
+
MagicCollectionTags2["LayoutAccessories"] = "layout-accessories";
|
|
53
|
+
MagicCollectionTags2["ProStore"] = "pro-store";
|
|
54
|
+
MagicCollectionTags2["DisableLengthOptions"] = "disable-length-options";
|
|
55
|
+
MagicCollectionTags2["DisableSpeedOptions"] = "disable-speed-options";
|
|
56
|
+
return MagicCollectionTags2;
|
|
57
|
+
})(MagicCollectionTags || {});
|
|
58
|
+
var ProductOptions = /* @__PURE__ */(ProductOptions2 => {
|
|
59
|
+
ProductOptions2["Length"] = "length";
|
|
60
|
+
ProductOptions2["Speed"] = "speed";
|
|
61
|
+
ProductOptions2["Color"] = "color";
|
|
62
|
+
return ProductOptions2;
|
|
63
|
+
})(ProductOptions || {});
|
|
64
|
+
const formatOptionValueTitleToTag = optionValueTitle => optionValueTitle.toLowerCase().replace(/[,\s]/g, "").replace(".", "-");
|
|
65
|
+
const divideProductByOption = (product, optionTitle) => {
|
|
66
|
+
const option = product.options.find(option2 => option2.slug === optionTitle);
|
|
67
|
+
if (!option) {
|
|
68
|
+
return [product];
|
|
69
|
+
}
|
|
70
|
+
return option.values.map(value => {
|
|
71
|
+
return {
|
|
72
|
+
...product,
|
|
73
|
+
options: product.options.filter(option2 => option2.slug !== optionTitle),
|
|
74
|
+
tags: [...product.tags, {
|
|
75
|
+
id: value.id,
|
|
76
|
+
name: formatOptionValueTitleToTag(value.slug)
|
|
77
|
+
}],
|
|
78
|
+
variants: product.variants.filter(variant => variant.optionValueIds?.includes(value.id))
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
const COLLECTION_SECTION_OTHER_ID = "other";
|
|
83
|
+
const UNIT_FACTORS = {
|
|
84
|
+
m: 1,
|
|
85
|
+
km: 1e3
|
|
86
|
+
};
|
|
87
|
+
const DISTANCE_REGEX = /^\s*(\d+)\s*(m|km)\s*$/;
|
|
88
|
+
const mapProductsToSections = (products, section) => {
|
|
89
|
+
const productsInThisSection = products.filter(product => {
|
|
90
|
+
return section.productTags.every(sectionTag => {
|
|
91
|
+
return product.tags.find(tag => tag.name === sectionTag);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
if (productsInThisSection.length === 0) {
|
|
95
|
+
return void 0;
|
|
96
|
+
}
|
|
97
|
+
const items = section?.items?.map(item => mapProductsToSections(productsInThisSection, item)).filter(isNonNullish) ?? [];
|
|
98
|
+
const otherProducts = productsInThisSection.filter(product => {
|
|
99
|
+
return !items.some(item => item.products.find(p => p.id === product.id));
|
|
100
|
+
});
|
|
101
|
+
if (otherProducts.length && items.length) {
|
|
102
|
+
items.push({
|
|
103
|
+
id: `${section.id}-${COLLECTION_SECTION_OTHER_ID}`,
|
|
104
|
+
// TODO: Add translation
|
|
105
|
+
title: "Other",
|
|
106
|
+
productTags: section.productTags,
|
|
107
|
+
items: [],
|
|
108
|
+
products: otherProducts
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
...section,
|
|
113
|
+
items,
|
|
114
|
+
products: productsInThisSection
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
const compareDistanceTitles = (a, b) => {
|
|
118
|
+
const aMatch = a.title.match(DISTANCE_REGEX);
|
|
119
|
+
const bMatch = b.title.match(DISTANCE_REGEX);
|
|
120
|
+
if (!aMatch?.[1] || !aMatch[2] || !bMatch?.[1] || !bMatch[2]) {
|
|
121
|
+
return 0;
|
|
122
|
+
}
|
|
123
|
+
const aValue = parseInt(aMatch[1]) * (UNIT_FACTORS[aMatch[2]] || 0);
|
|
124
|
+
const bValue = parseInt(bMatch[1]) * (UNIT_FACTORS[bMatch[2]] || 0);
|
|
125
|
+
return aValue - bValue;
|
|
126
|
+
};
|
|
127
|
+
const processSectionProductsWithDistanceInOptions = sections => {
|
|
128
|
+
return sections.map(section => ({
|
|
129
|
+
...section,
|
|
130
|
+
items: section.items.map(sec => {
|
|
131
|
+
const section2 = cloneDeep(sec);
|
|
132
|
+
const sectionWithDistanceTag = section2.items.find(section3 => section3.productTags.includes("distance"));
|
|
133
|
+
const sectionsMainProductTag = sectionWithDistanceTag?.productTags.filter(tag => tag !== "distance");
|
|
134
|
+
if (!sectionWithDistanceTag || !sectionsMainProductTag) {
|
|
135
|
+
return section2;
|
|
136
|
+
}
|
|
137
|
+
sectionWithDistanceTag.products.forEach(product => {
|
|
138
|
+
const optionValues = product?.options[0]?.values;
|
|
139
|
+
if (!optionValues?.length) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const formattedOptionValues = optionValues.map(value => ({
|
|
143
|
+
...value,
|
|
144
|
+
titleInTagFormat: formatOptionValueTitleToTag(value.title)
|
|
145
|
+
}));
|
|
146
|
+
formattedOptionValues.forEach(currentValue => {
|
|
147
|
+
const newSecondLevelSectionsTags = [...sectionsMainProductTag, currentValue.titleInTagFormat];
|
|
148
|
+
const alreadyExistingSecondLevelSection = section2.items.findIndex(section3 => areEqualArrays(section3.productTags, newSecondLevelSectionsTags));
|
|
149
|
+
const variantToAdd = product.variants.find(variant => variant.optionValueIds?.includes(currentValue.id));
|
|
150
|
+
if (!variantToAdd) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const productToAdd = {
|
|
154
|
+
...product,
|
|
155
|
+
options: product.options.filter(option => option.values.some(value => value.id === currentValue.id)).map(option => ({
|
|
156
|
+
...option,
|
|
157
|
+
values: option.values.filter(value => value.id === currentValue.id)
|
|
158
|
+
})),
|
|
159
|
+
variants: [variantToAdd]
|
|
160
|
+
};
|
|
161
|
+
if (alreadyExistingSecondLevelSection >= 0) {
|
|
162
|
+
section2.items[alreadyExistingSecondLevelSection]?.products.push(productToAdd);
|
|
163
|
+
} else {
|
|
164
|
+
const sectionToAdd = {
|
|
165
|
+
id: currentValue.id,
|
|
166
|
+
// TODO: Maybe so>me different ID would be better
|
|
167
|
+
items: [],
|
|
168
|
+
// FIXME: This is problem!
|
|
169
|
+
products: [productToAdd],
|
|
170
|
+
productTags: newSecondLevelSectionsTags,
|
|
171
|
+
title: currentValue.title
|
|
172
|
+
};
|
|
173
|
+
section2.items.push(sectionToAdd);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
return {
|
|
178
|
+
...section2,
|
|
179
|
+
items: section2.items.sort(compareDistanceTitles).filter(section3 => !section3.productTags.includes("distance"))
|
|
180
|
+
};
|
|
181
|
+
})
|
|
182
|
+
}));
|
|
183
|
+
};
|
|
184
|
+
const processSectionsWithOutOfStockProducts = section => {
|
|
185
|
+
const isDisabled = section.products.every(product => product.variants.every(variant => variant.status !== DisplayProductStatus.Available));
|
|
186
|
+
return {
|
|
187
|
+
...section,
|
|
188
|
+
isDisabled,
|
|
189
|
+
items: section.items.map(processSectionsWithOutOfStockProducts)
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
const getProductGroups = (products, sectionHierarchy, tags) => {
|
|
193
|
+
if (!products?.length || !sectionHierarchy) return void 0;
|
|
194
|
+
const processedProducts = products.flatMap(product => {
|
|
195
|
+
const disableLengthOptions = tags?.find(tag => tag.name === "disable-length-options" /* DisableLengthOptions */);
|
|
196
|
+
const lengthOptions = !disableLengthOptions && product?.options?.find(option => option.slug === "length" /* Length */);
|
|
197
|
+
if (lengthOptions && product.options !== void 0) {
|
|
198
|
+
return divideProductByOption(product, "length" /* Length */);
|
|
199
|
+
}
|
|
200
|
+
const disableSpeedOptions = tags?.find(tag => tag.name === "disable-speed-options" /* DisableSpeedOptions */);
|
|
201
|
+
const speedOptions = !disableSpeedOptions && product?.options?.find(option => {
|
|
202
|
+
return option.slug === "speed" /* Speed */;
|
|
203
|
+
});
|
|
204
|
+
if (speedOptions) {
|
|
205
|
+
return divideProductByOption(product, "speed" /* Speed */);
|
|
206
|
+
}
|
|
207
|
+
return [product];
|
|
208
|
+
});
|
|
209
|
+
const mappedProductGroups = sectionHierarchy.map(section => {
|
|
210
|
+
return mapProductsToSections(processedProducts, section);
|
|
211
|
+
}).filter(section => !!section);
|
|
212
|
+
const otherProducts = products.filter(product => {
|
|
213
|
+
return !mappedProductGroups.some(section => {
|
|
214
|
+
return section.products.find(p => p.id === product.id);
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
if (otherProducts.length) {
|
|
218
|
+
otherProducts.forEach(product => {
|
|
219
|
+
mappedProductGroups.push({
|
|
220
|
+
id: product.id,
|
|
221
|
+
products: [product],
|
|
222
|
+
title: "",
|
|
223
|
+
items: [],
|
|
224
|
+
productTags: []
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
const processedProductGroups = processSectionProductsWithDistanceInOptions(mappedProductGroups).map(processSectionsWithOutOfStockProducts);
|
|
229
|
+
return processedProductGroups.sort((a, b) => {
|
|
230
|
+
const aFirstProductId = a?.products?.[0]?.id;
|
|
231
|
+
const bFirstProductId = b?.products?.[0]?.id;
|
|
232
|
+
const aFirstProduct = products.findIndex(product => product.id === aFirstProductId);
|
|
233
|
+
const bFirstProduct = products.findIndex(product => product.id === bFirstProductId);
|
|
234
|
+
return aFirstProduct - bFirstProduct;
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
const getProStoreCategory = ({
|
|
238
|
+
queryCategory,
|
|
239
|
+
product,
|
|
240
|
+
ignoreQuery
|
|
241
|
+
}) => {
|
|
242
|
+
return (
|
|
243
|
+
/**
|
|
244
|
+
* If category specified via the url search/query parameter then use it
|
|
245
|
+
*/
|
|
246
|
+
!ignoreQuery && queryCategory ||
|
|
247
|
+
/**
|
|
248
|
+
* Attempt to find category by it's default collection or fallback to the virtual default collection
|
|
249
|
+
*/
|
|
250
|
+
getSubCategoryIdByCollectionSlug(product.collectionSlug) || getSubCategoryIdByCollectionSlug(product.organizationalCollectionSlug) ||
|
|
251
|
+
/**
|
|
252
|
+
* If all else fails fallback detecting to category from pro store collection, unlikely but wouldn't hurt to do so
|
|
253
|
+
*/
|
|
254
|
+
getSubCategoryIdByCollectionSlug(product.proCollectionSlug)
|
|
255
|
+
);
|
|
256
|
+
};
|
|
257
|
+
const getStoreProducts = ({
|
|
258
|
+
storeId,
|
|
259
|
+
queryCategory,
|
|
260
|
+
currentProduct,
|
|
261
|
+
collections,
|
|
262
|
+
allCategoryItems
|
|
263
|
+
}) => {
|
|
264
|
+
const returnObj = {
|
|
265
|
+
category: void 0,
|
|
266
|
+
products: []
|
|
267
|
+
};
|
|
268
|
+
const category = getProStoreCategory({
|
|
269
|
+
queryCategory,
|
|
270
|
+
product: currentProduct
|
|
271
|
+
});
|
|
272
|
+
const categoryItem = allCategoryItems.find(item => item.items?.some(subItem => subItem.id === category));
|
|
273
|
+
const categorySubItem = categoryItem?.items?.find(subItem => subItem.id === category);
|
|
274
|
+
const categoryId = categorySubItem?.id ?? category;
|
|
275
|
+
if (categoryId) {
|
|
276
|
+
returnObj.category = {
|
|
277
|
+
id: categoryId,
|
|
278
|
+
label: categoryItem?.label ?? null
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
const filteredCollections = collections.map(collection => ({
|
|
282
|
+
...collection,
|
|
283
|
+
products: removeExcludedProducts(collection.products, storeId)
|
|
284
|
+
}));
|
|
285
|
+
if (categoryItem?.hideSubItems) {
|
|
286
|
+
const products = filteredCollections.flatMap(collection => collection.products);
|
|
287
|
+
if (isAccessoryCategoryItem(categoryItem)) {
|
|
288
|
+
returnObj.products = isAllowedAccessoryCategoryProduct(currentProduct) ? products.filter(isAllowedAccessoryCategoryProduct) : [];
|
|
289
|
+
} else {
|
|
290
|
+
returnObj.products = products;
|
|
291
|
+
}
|
|
292
|
+
} else {
|
|
293
|
+
const collection = filteredCollections.find(collection2 => collection2.products.some(el => el.id === currentProduct.id));
|
|
294
|
+
if (!collection) {
|
|
295
|
+
throw new Error("Collection not found");
|
|
296
|
+
}
|
|
297
|
+
const subItems = (categoryItem?.items?.slice(1) ?? allCategoryItems.flatMap(el => el.items?.slice(1))).filter(Boolean);
|
|
298
|
+
const subItem = subItems.find(item => item.collectionSlugs.includes(collection.slug));
|
|
299
|
+
if (subItem && returnObj.category) {
|
|
300
|
+
returnObj.category = {
|
|
301
|
+
id: subItem.id,
|
|
302
|
+
label: subItem.label
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
const subItemCollections = filteredCollections.filter(el => subItem?.collectionSlugs.includes(el.slug));
|
|
306
|
+
const products = subItemCollections.flatMap(el => el.products);
|
|
307
|
+
if (subItem) {
|
|
308
|
+
if (isAccessoryCategorySubItem(subItem, allCategoryItems)) {
|
|
309
|
+
returnObj.products = isAllowedAccessoryCategoryProduct(currentProduct) ? products.filter(isAllowedAccessoryCategoryProduct) : [];
|
|
310
|
+
} else {
|
|
311
|
+
returnObj.products = products;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
const sections = subItemCollections.flatMap(el => el.sections);
|
|
315
|
+
const sectionHierarchy = createSectionHierarchy(sections);
|
|
316
|
+
const productGroups = getProductGroups(products, sectionHierarchy);
|
|
317
|
+
if (productGroups) {
|
|
318
|
+
return {
|
|
319
|
+
category: returnObj.category,
|
|
320
|
+
productGroups: productGroups.sort((a, b) => {
|
|
321
|
+
if (a.products[0] && b.products[0]) {
|
|
322
|
+
return sortProducts(null, storeId)(a.products[0], b.products[0]);
|
|
323
|
+
}
|
|
324
|
+
return 0;
|
|
325
|
+
})
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
...returnObj,
|
|
331
|
+
products: returnObj.products.sort(sortProducts(null, storeId))
|
|
332
|
+
};
|
|
333
|
+
};
|
|
334
|
+
export { COLLECTION_SECTION_OTHER_ID, HDDProductSlugs, MagicCollectionTags, ProductOptions, createSectionHierarchy, getProStoreCategory, getProductGroups, getStoreProducts, isNonNullish, removeExcludedProducts };
|
|
335
|
+
//# sourceMappingURL=product.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product.mjs","sources":["../../src/helpers/product.ts"],"sourcesContent":["import { cloneDeep } from \"lodash-es\";\n\nimport type {\n ParsedCategoryItem,\n ParsedCategorySubItem,\n} from \"../constants/proStoreCategories\";\nimport {\n UISPCategoryId,\n UniFiCategoryId,\n} from \"../constants/proStoreCategories\";\nimport type {\n CollectionSection,\n MappedProductSection,\n Nullish,\n ProductTagFragment,\n Section,\n StorefrontOption,\n StorefrontProduct,\n StoreId,\n} from \"../types\";\nimport { DisplayProductStatus } from \"../types\";\nimport { areEqualArrays } from \"../utils/array\";\nimport { sortProducts } from \"../utils/productSort\";\nimport { getSubCategoryIdByCollectionSlug } from \"./proStoreCategories\";\n\nexport const isNonNullish = <T>(entry: T | null | undefined): entry is T =>\n entry !== null && entry !== undefined;\n\n/**\n * Prefix for tags that is added to product to exclude it from store grid\n * and breadcrumbs but still show it in other places (e.g. search and new user store)\n *\n * The full tag would include the store ID for specifying which from which\n * store to exclude the product.\n *\n * @example `\"exclude-from-store-grid:us`\n */\nconst EXCLUDE_PRODUCT_FROM_STORE_GRID_TAG_PREFIX =\n \"exclude-from-store-grid:\" as const;\n\n/**\n * Removes products that have tag starting with `EXCLUDE_PRODUCT_FROM_STORE_GRID_TAG_PREFIX`\n * and ends with `storeId`, e.g. `\"exclude-from-store-grid:us`\n *\n * @warning Use this function only on grid and breadcrumbs products\n */\nexport const removeExcludedProducts = <\n T extends { tags: ProductTagFragment[] },\n>(\n products: T[],\n storeId: StoreId,\n): T[] => {\n const excludeTag =\n `${EXCLUDE_PRODUCT_FROM_STORE_GRID_TAG_PREFIX}${storeId}`.toLowerCase();\n\n return products.filter((product) => {\n return !product.tags.some((tag) => tag.name.toLowerCase() === excludeTag);\n });\n};\n\nconst isAccessoryCategoryItem = (\n categoryItem: Nullish<ParsedCategoryItem>,\n): boolean => {\n return (\n !!categoryItem &&\n [UniFiCategoryId.Accessories, UISPCategoryId.AccessoryTech].includes(\n // TODO: Check why this TS error appears\n // @ts-expect-error: Unreachable code error\n categoryItem.id,\n )\n );\n};\n\nexport enum HDDProductSlugs {\n HDD_1TB = \"uacc-hdd-s-1tb\",\n // Currently disabled and replaced dirty with HDD_8TB_Enterprise\n // HDD_8TB = \"uacc-hdd-s-8tb\",\n HDD_8TB_Enterprise = \"uacc-hdd-e-8tb\",\n HDD_16TB_Enterprise = \"uacc-hdd-e-16tb\",\n}\n\nconst isAllowedAccessoryCategoryProduct = ({\n slug,\n}: {\n slug: string;\n}): boolean => {\n const allowedAccessoryProductSlugs = [\n \"u-lte\",\n \"u-lte-backup-pro\",\n HDDProductSlugs.HDD_1TB,\n HDDProductSlugs.HDD_8TB_Enterprise,\n HDDProductSlugs.HDD_16TB_Enterprise,\n ];\n\n return allowedAccessoryProductSlugs.includes(slug);\n};\n\nconst isAccessoryCategorySubItem = (\n categorySubItem: ParsedCategorySubItem,\n allCategoryItems: ParsedCategoryItem[],\n): boolean => {\n const categoryItem = allCategoryItems.find((item) =>\n item.items?.some((subItem) => subItem.id === categorySubItem.id),\n );\n\n return isAccessoryCategoryItem(categoryItem);\n};\n\n/**\n * Recursively create section hierarchy\n */\nexport const createSectionHierarchy = (\n sections: CollectionSection[],\n level = 1,\n): Section[] => {\n const currentLevelSections = sections.filter(\n (section) => section.productTags.length === level,\n );\n\n if (!currentLevelSections.length) {\n return [];\n }\n\n return currentLevelSections.map((section) => ({\n ...section,\n items: createSectionHierarchy(\n sections.filter((nextSection) =>\n section.productTags.every((tag) =>\n nextSection.productTags.includes(tag),\n ),\n ),\n level + 1,\n ),\n }));\n};\n\nexport enum MagicCollectionTags {\n /**\n * Used to determine if collection should be shown in an accessory\n * layout style where sections are placed inside variant cards\n */\n LayoutAccessories = \"layout-accessories\",\n /**\n * Used to determine if collection is pro-store specific and should\n * be redirected to pro-store's appropriate category\n */\n ProStore = \"pro-store\",\n /**\n * Used to disable length options (disable product splitting by \"length\")\n */\n DisableLengthOptions = \"disable-length-options\",\n /**\n * Used to disable speed options (disable product splitting by \"speed\")\n */\n DisableSpeedOptions = \"disable-speed-options\",\n}\n\nexport enum ProductOptions {\n // Used for finding option category using option slug\n Length = \"length\",\n Speed = \"speed\",\n Color = \"color\",\n}\n\n/**\n * Format option value title to tag.\n * This removes spaces, dots, commas, and make all lower case.\n * TODO: We could use the tag formatter from admin panel here.\n */\nconst formatOptionValueTitleToTag = (optionValueTitle: string) =>\n optionValueTitle.toLowerCase().replace(/[,\\s]/g, \"\").replace(\".\", \"-\");\n\n/**\n * Divides a product in multiple products by an option\n */\nconst divideProductByOption = <\n T extends StorefrontProduct & {\n options: StorefrontOption[];\n },\n>(\n product: T,\n optionTitle: ProductOptions,\n) => {\n const option = product.options.find((option) => option.slug === optionTitle);\n\n if (!option) {\n return [product];\n }\n\n return option.values.map((value) => {\n return {\n ...product,\n options: product.options.filter((option) => option.slug !== optionTitle),\n tags: [\n ...product.tags,\n {\n id: value.id,\n name: formatOptionValueTitleToTag(value.slug),\n },\n ],\n variants: product.variants.filter((variant) =>\n variant.optionValueIds?.includes(value.id),\n ),\n };\n });\n};\n\nexport const COLLECTION_SECTION_OTHER_ID = \"other\";\n\n// A mapping of unit suffixes to conversion factors in meters\nconst UNIT_FACTORS: Record<string, number> = {\n m: 1,\n km: 1000,\n};\n\n// A regular expression to extract the numerical value and unit suffix, with optional whitespace\nconst DISTANCE_REGEX = /^\\s*(\\d+)\\s*(m|km)\\s*$/;\n\n/**\n * Recursively map products to sections based on tags\n *\n * TODO: Add tests\n */\nconst mapProductsToSections = <T extends StorefrontProduct>(\n products: T[],\n section: Section,\n): MappedProductSection<T> | undefined => {\n // Filter products which have all tags from this section\n const productsInThisSection = products.filter((product) => {\n return section.productTags.every((sectionTag) => {\n return product.tags.find((tag) => tag.name === sectionTag);\n });\n });\n\n // If there are no products in this section, we don't want to show it\n if (productsInThisSection.length === 0) {\n return undefined;\n }\n\n // Recursively map products to sub-sections\n const items =\n section?.items\n ?.map((item) => mapProductsToSections(productsInThisSection, item))\n .filter(isNonNullish) ?? [];\n\n // Filter products which are not in any sub-section\n const otherProducts = productsInThisSection.filter((product) => {\n return !items.some((item) =>\n item.products.find((p) => p.id === product.id),\n );\n });\n\n // If there are products which are not in any sub-section, we want to create \"Other\" section\n if (otherProducts.length && items.length) {\n items.push({\n id: `${section.id}-${COLLECTION_SECTION_OTHER_ID}`,\n // TODO: Add translation\n title: \"Other\",\n productTags: section.productTags,\n items: [],\n products: otherProducts,\n });\n }\n\n return {\n ...section,\n items,\n products: productsInThisSection,\n };\n};\n\n// A predicate function that compares two section titles\nconst compareDistanceTitles = <T>(\n a: MappedProductSection<T>,\n b: MappedProductSection<T>,\n) => {\n const aMatch = a.title.match(DISTANCE_REGEX) as [string, string, string];\n const bMatch = b.title.match(DISTANCE_REGEX) as [string, string, string];\n\n if (!aMatch?.[1] || !aMatch[2] || !bMatch?.[1] || !bMatch[2]) {\n return 0;\n }\n\n const aValue = parseInt(aMatch[1]!) * (UNIT_FACTORS[aMatch[2]] || 0);\n const bValue = parseInt(bMatch[1]!) * (UNIT_FACTORS[bMatch[2]] || 0);\n\n return aValue - bValue;\n};\n\n/**\n * Process sections with products which have \"distance\" tag or/and has\n * \"distance\" option in options list. If there are such products, we want to\n * to add to the appropriate distance section or create a new one.\n */\nconst processSectionProductsWithDistanceInOptions = <\n T extends StorefrontProduct & {\n options: StorefrontOption[];\n },\n>(\n sections: MappedProductSection<T>[],\n) => {\n return sections.map((section) => ({\n ...section,\n items: section.items.map((sec) => {\n // Make a deep copy of the object, otherwise you will modify the original value\n const section = cloneDeep(sec);\n\n // TODO: Move the magic tag to a constants file, here and in other places as well\n const sectionWithDistanceTag = section.items.find((section) =>\n section.productTags.includes(\"distance\"),\n );\n\n // Here we take the first element because this is 2nd level section and it should have only 2 elements in the list\n const sectionsMainProductTag = sectionWithDistanceTag?.productTags.filter(\n (tag) => tag !== \"distance\",\n );\n\n // If there is no section with \"distance\" tag, then we can skip this\n if (!sectionWithDistanceTag || !sectionsMainProductTag) {\n return section;\n }\n\n sectionWithDistanceTag.products.forEach((product) => {\n /**\n * FIXME: Flat mapping is unsafe here. This part was written with a guarantee that these\n * products only have one option type by which they differ\n */\n const optionValues = product?.options[0]?.values;\n\n // FIXME: We need to add error handling here for cases where product has distance tag but does not have variants\n if (!optionValues?.length) {\n return;\n }\n\n /**\n * Format the option titles so that we can match them with the tags used.\n * This removes spaces, dots, commas, and make all lower case.\n * TODO: We could use the tag formatter from admin panel here.\n */\n const formattedOptionValues = optionValues.map((value) => ({\n ...value,\n titleInTagFormat: formatOptionValueTitleToTag(value.title),\n }));\n\n formattedOptionValues.forEach((currentValue) => {\n const newSecondLevelSectionsTags = [\n ...sectionsMainProductTag,\n currentValue.titleInTagFormat,\n ];\n\n const alreadyExistingSecondLevelSection = section.items.findIndex(\n (section) =>\n areEqualArrays(section.productTags, newSecondLevelSectionsTags),\n );\n\n const variantToAdd = product.variants.find((variant) =>\n variant.optionValueIds?.includes(currentValue.id),\n );\n\n // TODO: Add error handling\n if (!variantToAdd) {\n return;\n }\n\n const productToAdd: T = {\n ...product,\n options: product.options\n .filter((option) =>\n option.values.some((value) => value.id === currentValue.id),\n )\n .map((option) => ({\n ...option,\n values: option.values.filter(\n (value) => value.id === currentValue.id,\n ),\n })),\n variants: [variantToAdd],\n };\n\n if (alreadyExistingSecondLevelSection >= 0) {\n section.items[alreadyExistingSecondLevelSection]?.products.push(\n productToAdd,\n );\n } else {\n const sectionToAdd: MappedProductSection<T> = {\n id: currentValue.id, // TODO: Maybe so>me different ID would be better\n items: [], // FIXME: This is problem!\n products: [productToAdd],\n productTags: newSecondLevelSectionsTags,\n title: currentValue.title,\n };\n\n section.items.push(sectionToAdd);\n }\n });\n });\n\n return {\n ...section,\n items: section.items\n .sort(compareDistanceTitles)\n .filter((section) => !section.productTags.includes(\"distance\")),\n };\n }),\n }));\n};\n\n/**\n * Goes through all sections and sets isDisabled flag to true if all products\n * in the section are not available\n */\nconst processSectionsWithOutOfStockProducts = <\n T extends { variants: { status: Nullish<DisplayProductStatus> }[] },\n>(\n section: MappedProductSection<T>,\n): MappedProductSection<T> => {\n const isDisabled = section.products.every((product) =>\n product.variants.every(\n (variant) => variant.status !== DisplayProductStatus.Available,\n ),\n );\n\n return {\n ...section,\n isDisabled,\n items: section.items.map(processSectionsWithOutOfStockProducts),\n };\n};\n\n/**\n * Create product groups\n */\nexport const getProductGroups = <\n T extends StorefrontProduct & {\n options: StorefrontOption[];\n },\n>(\n products?: T[],\n sectionHierarchy?: Nullish<Section[]>,\n tags?: Array<{\n id: string;\n name: string;\n }>,\n) => {\n if (!products?.length || !sectionHierarchy) return undefined;\n\n const processedProducts = products.flatMap((product) => {\n const disableLengthOptions = tags?.find(\n (tag) => tag.name === MagicCollectionTags.DisableLengthOptions,\n );\n const lengthOptions =\n !disableLengthOptions &&\n product?.options?.find((option) => option.slug === ProductOptions.Length);\n\n if (lengthOptions && product.options !== undefined) {\n return divideProductByOption(product, ProductOptions.Length);\n }\n\n const disableSpeedOptions = tags?.find(\n (tag) => tag.name === MagicCollectionTags.DisableSpeedOptions,\n );\n const speedOptions =\n !disableSpeedOptions &&\n product?.options?.find((option) => {\n return option.slug === ProductOptions.Speed;\n });\n\n if (speedOptions) {\n return divideProductByOption(product, ProductOptions.Speed);\n }\n\n return [product];\n });\n\n const mappedProductGroups = sectionHierarchy\n .map((section) => {\n return mapProductsToSections(processedProducts, section);\n })\n .filter((section): section is MappedProductSection<T> => !!section);\n\n const otherProducts = products.filter((product) => {\n return !mappedProductGroups.some((section) => {\n return section.products.find((p) => p.id === product.id);\n });\n });\n\n // If there are products which are not in any section, we want to create \"Other\" section\n if (otherProducts.length) {\n otherProducts.forEach((product) => {\n mappedProductGroups.push({\n id: product.id,\n products: [product],\n title: \"\",\n items: [],\n productTags: [],\n });\n });\n }\n\n const processedProductGroups = processSectionProductsWithDistanceInOptions(\n mappedProductGroups,\n ).map(processSectionsWithOutOfStockProducts);\n\n /**\n * Sort product groups by the order of the first product in each group\n * based on the order of the products that is in collection settings\n */\n return processedProductGroups.sort((a, b) => {\n const aFirstProductId = a?.products?.[0]?.id;\n const bFirstProductId = b?.products?.[0]?.id;\n\n const aFirstProduct = products.findIndex(\n (product) => product.id === aFirstProductId,\n );\n\n const bFirstProduct = products.findIndex(\n (product) => product.id === bFirstProductId,\n );\n\n return aFirstProduct - bFirstProduct;\n });\n};\n\nexport const getProStoreCategory = ({\n queryCategory,\n product,\n ignoreQuery,\n}: {\n queryCategory?: string;\n product: Pick<\n StorefrontProduct,\n \"collectionSlug\" | \"organizationalCollectionSlug\" | \"proCollectionSlug\"\n >;\n ignoreQuery?: boolean;\n}): string | null => {\n return (\n /**\n * If category specified via the url search/query parameter then use it\n */\n (!ignoreQuery && queryCategory) ||\n /**\n * Attempt to find category by it's default collection or fallback to the virtual default collection\n */\n getSubCategoryIdByCollectionSlug(product.collectionSlug) ||\n getSubCategoryIdByCollectionSlug(product.organizationalCollectionSlug) ||\n /**\n * If all else fails fallback detecting to category from pro store collection, unlikely but wouldn't hurt to do so\n */\n getSubCategoryIdByCollectionSlug(product.proCollectionSlug)\n );\n};\n\ntype StoreProductsData =\n | ({\n category: { id: string; label: string | null } | undefined;\n } & {\n products: StorefrontProduct[];\n })\n | {\n productGroups: MappedProductSection<StorefrontProduct>[];\n };\n\nexport const getStoreProducts = ({\n storeId,\n queryCategory,\n currentProduct,\n collections,\n allCategoryItems,\n}: {\n storeId: StoreId;\n queryCategory: string | undefined;\n currentProduct: Pick<\n StorefrontProduct,\n | \"id\"\n | \"slug\"\n | \"collectionSlug\"\n | \"organizationalCollectionSlug\"\n | \"proCollectionSlug\"\n >;\n collections: Array<{\n slug: string;\n sections: Array<{\n id: string;\n title: string;\n productTags: Array<string>;\n }>;\n products: Array<\n Pick<\n StorefrontProduct,\n | \"id\"\n | \"slug\"\n | \"tags\"\n | \"variants\"\n | \"options\"\n | \"title\"\n | \"status\"\n | \"minDisplayPrice\"\n >\n >;\n }>;\n allCategoryItems: ParsedCategoryItem[];\n}): StoreProductsData => {\n const returnObj: StoreProductsData = {\n category: undefined,\n products: [],\n };\n\n const category = getProStoreCategory({\n queryCategory,\n product: currentProduct,\n });\n\n // Find the category item and sub-item\n const categoryItem = allCategoryItems.find((item) =>\n item.items?.some((subItem) => subItem.id === category),\n );\n const categorySubItem = categoryItem?.items?.find(\n (subItem) => subItem.id === category,\n );\n\n // Set the base category\n const categoryId = categorySubItem?.id ?? category;\n if (categoryId) {\n returnObj.category = {\n id: categoryId,\n label: categoryItem?.label ?? null,\n };\n }\n\n // Removes products that need to be excluded from product grid from the collections\n const filteredCollections = collections.map((collection) => ({\n ...collection,\n products: removeExcludedProducts(collection.products, storeId),\n }));\n\n if (categoryItem?.hideSubItems) {\n const products = filteredCollections.flatMap(\n (collection) => collection.products,\n );\n\n if (isAccessoryCategoryItem(categoryItem)) {\n // Show allowed products\n returnObj.products = isAllowedAccessoryCategoryProduct(currentProduct)\n ? products.filter(isAllowedAccessoryCategoryProduct)\n : [];\n } else {\n // Show all products of collections\n returnObj.products = products;\n }\n } else {\n // Find the collection in which the product is in\n const collection = filteredCollections.find((collection) =>\n collection.products.some((el) => el.id === currentProduct.id),\n );\n\n if (!collection) {\n throw new Error(\"Collection not found\");\n }\n\n const subItems = (\n categoryItem?.items?.slice(1) ??\n allCategoryItems.flatMap((el) => el.items?.slice(1))\n ).filter(Boolean);\n\n // Find sub-category item that has this collection\n const subItem = subItems.find((item) =>\n item.collectionSlugs.includes(collection.slug),\n );\n\n // Update category\n if (subItem && returnObj.category) {\n returnObj.category = {\n id: subItem.id,\n label: subItem.label,\n };\n }\n\n // Find all collections data that are included in subItem\n const subItemCollections = filteredCollections.filter((el) =>\n subItem?.collectionSlugs.includes(el.slug),\n );\n\n const products = subItemCollections.flatMap((el) => el.products);\n\n if (subItem) {\n if (isAccessoryCategorySubItem(subItem, allCategoryItems)) {\n // Show allowed products\n returnObj.products = isAllowedAccessoryCategoryProduct(currentProduct)\n ? products.filter(isAllowedAccessoryCategoryProduct)\n : [];\n } else {\n // Show all products of found collection\n returnObj.products = products;\n }\n }\n\n // #############################################################################\n // Product groups\n // #############################################################################\n const sections = subItemCollections.flatMap((el) => el.sections);\n\n const sectionHierarchy = createSectionHierarchy(sections);\n\n const productGroups = getProductGroups(products, sectionHierarchy);\n\n if (productGroups) {\n return {\n category: returnObj.category,\n productGroups: productGroups.sort((a, b) => {\n if (a.products[0] && b.products[0]) {\n return sortProducts(null, storeId)(a.products[0], b.products[0]);\n }\n\n return 0;\n }),\n };\n }\n }\n\n return {\n ...returnObj,\n products: returnObj.products.sort(sortProducts(null, storeId)),\n };\n};\n"],"names":["isNonNullish","entry","EXCLUDE_PRODUCT_FROM_STORE_GRID_TAG_PREFIX","removeExcludedProducts","products","storeId","excludeTag","toLowerCase","filter","product","tags","some","tag","name","isAccessoryCategoryItem","categoryItem","UniFiCategoryId","Accessories","UISPCategoryId","AccessoryTech","includes","id","HDDProductSlugs","isAllowedAccessoryCategoryProduct","slug","allowedAccessoryProductSlugs","isAccessoryCategorySubItem","categorySubItem","allCategoryItems","find","item","items","subItem","createSectionHierarchy","sections","level","currentLevelSections","section","productTags","length","map","nextSection","every","MagicCollectionTags","ProductOptions","formatOptionValueTitleToTag","optionValueTitle","replace","divideProductByOption","optionTitle","option","options","values","value","variants","variant","optionValueIds","COLLECTION_SECTION_OTHER_ID","UNIT_FACTORS","m","km","DISTANCE_REGEX","mapProductsToSections","productsInThisSection","sectionTag","otherProducts","p","push","title","compareDistanceTitles","a","b","aMatch","match","bMatch","aValue","parseInt","bValue","processSectionProductsWithDistanceInOptions","sec","cloneDeep","sectionWithDistanceTag","sectionsMainProductTag","forEach","optionValues","formattedOptionValues","titleInTagFormat","currentValue","newSecondLevelSectionsTags","alreadyExistingSecondLevelSection","findIndex","areEqualArrays","variantToAdd","productToAdd","sectionToAdd","sort","processSectionsWithOutOfStockProducts","isDisabled","status","DisplayProductStatus","Available","getProductGroups","sectionHierarchy","processedProducts","flatMap","disableLengthOptions","lengthOptions","disableSpeedOptions","speedOptions","mappedProductGroups","processedProductGroups","aFirstProductId","bFirstProductId","aFirstProduct","bFirstProduct","getProStoreCategory","queryCategory","ignoreQuery","getSubCategoryIdByCollectionSlug","collectionSlug","organizationalCollectionSlug","proCollectionSlug","getStoreProducts","currentProduct","collections","returnObj","category","categoryId","label","filteredCollections","collection","hideSubItems","el","Error","subItems","slice","Boolean","collectionSlugs","subItemCollections","productGroups","sortProducts"],"mappings":";;;;;;;;;;AAyBO,MAAMA,YAAe,GAAIC,KAC9B,IAAAA,KAAA,KAAU,QAAQA,KAAU,KAAA,KAAA,CAAA;AAW9B,MAAMC,0CACJ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CAAAzH,QAAA,GAAWmB,kCAAkCoG,cAAc,CAAA,GACjEvH,SAASI,MAAO,CAAAe,iCAAiC,IACjD,EAAC;MAAA,CACA,MAAA;QAELsG,SAAA,CAAUzH,QAAW,GAAAA,QAAA;MACvB;IACF;IAKA,MAAM8B,WAAWwG,kBAAmB,CAAAlC,OAAA,CAAS4B,EAAA,IAAOA,GAAGlG,QAAQ,CAAA;IAEzD,MAAAoE,gBAAA,GAAmBrE,uBAAuBC,QAAQ,CAAA;IAElD,MAAAyG,aAAA,GAAgBtC,gBAAiB,CAAAjG,QAAA,EAAUkG,gBAAgB,CAAA;IAEjE,IAAIqC,aAAe,EAAA;MACV,OAAA;QACLb,UAAUD,SAAU,CAAAC,QAAA;QACpBa,aAAe,EAAAA,aAAA,CAAc5C,IAAK,CAAA,CAACzB,GAAGC,CAAM,KAAA;UAC1C,IAAID,EAAElE,QAAS,CAAA,CAAC,KAAKmE,CAAE,CAAAnE,QAAA,CAAS,CAAC,CAAG,EAAA;YAC3B,OAAAwI,YAAA,CAAa,IAAM,EAAAvI,OAAO,CAAE,CAAAiE,CAAA,CAAElE,QAAS,CAAA,CAAC,CAAG,EAAAmE,CAAA,CAAEnE,QAAS,CAAA,CAAC,CAAC,CAAA;UACjE;UAEO,OAAA,CAAA;QAAA,CACR;MAAA,CACH;IACF;EACF;EAEO,OAAA;IACL,GAAGyH,SAAA;IACHzH,UAAUyH,SAAU,CAAAzH,QAAA,CAAS2F,KAAK6C,YAAa,CAAA,IAAA,EAAMvI,OAAO,CAAC;EAAA,CAC/D;AACF,CAAA;"}
|
package/lib/types/index.d.ts
CHANGED
package/lib/types/index.js
CHANGED
|
@@ -5,6 +5,7 @@ var constants = require('./constants.js');
|
|
|
5
5
|
var generated = require('./generated.js');
|
|
6
6
|
require('./object.js');
|
|
7
7
|
require('./utils.js');
|
|
8
|
+
var product = require('./product.js');
|
|
8
9
|
"use strict";
|
|
9
10
|
exports.AddressUsageType = constants.AddressUsageType;
|
|
10
11
|
exports.Language = constants.Language;
|
|
@@ -18,4 +19,5 @@ exports.Unit = generated.Unit;
|
|
|
18
19
|
exports.UnitSystem = generated.UnitSystem;
|
|
19
20
|
exports.UserAssignedCountryCode = generated.UserAssignedCountryCode;
|
|
20
21
|
exports.ValidateTaxStatus = generated.ValidateTaxStatus;
|
|
22
|
+
exports.DisplayProductStatus = product.DisplayProductStatus;
|
|
21
23
|
//# sourceMappingURL=index.js.map
|
package/lib/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;"}
|
package/lib/types/index.mjs
CHANGED
|
@@ -3,5 +3,6 @@ export { AddressUsageType, Language } from './constants.mjs';
|
|
|
3
3
|
export { AddressType, CountryCode, Currency, GlobalStoreId, ProductLine, StoreId, Unit, UnitSystem, UserAssignedCountryCode, ValidateTaxStatus } from './generated.mjs';
|
|
4
4
|
import './object.mjs';
|
|
5
5
|
import './utils.mjs';
|
|
6
|
+
export { DisplayProductStatus } from './product.mjs';
|
|
6
7
|
"use strict";
|
|
7
8
|
//# sourceMappingURL=index.mjs.map
|
package/lib/types/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { Currency } from "../types";
|
|
2
|
+
export declare enum DisplayProductStatus {
|
|
3
|
+
Available = "Available",
|
|
4
|
+
Backorder = "Backorder",
|
|
5
|
+
ComingSoon = "ComingSoon",
|
|
6
|
+
RegionNotAvailable = "RegionNotAvailable",
|
|
7
|
+
SoldOut = "SoldOut",
|
|
8
|
+
Unavailable = "Unavailable"
|
|
9
|
+
}
|
|
10
|
+
export type CollectionSection = {
|
|
11
|
+
id: string;
|
|
12
|
+
productTags: Array<string>;
|
|
13
|
+
title: string;
|
|
14
|
+
};
|
|
15
|
+
export interface Section extends CollectionSection {
|
|
16
|
+
items: Section[];
|
|
17
|
+
}
|
|
18
|
+
export type ProductTagFragment = {
|
|
19
|
+
__typename?: "ProductTag";
|
|
20
|
+
name: string;
|
|
21
|
+
};
|
|
22
|
+
export interface MappedProductSection<T> extends Section {
|
|
23
|
+
items: MappedProductSection<T>[];
|
|
24
|
+
products: T[];
|
|
25
|
+
/**
|
|
26
|
+
* States which is conditionally calculated based on the need.
|
|
27
|
+
* E.g. if it is an optical collection where collection sections
|
|
28
|
+
* are rendered inside the VariantSelector items, we need to
|
|
29
|
+
* know which section does not contain products that are in stock.
|
|
30
|
+
* If all products in the section are out of stock, we need to
|
|
31
|
+
* apply grayed out style to the section button.
|
|
32
|
+
*/
|
|
33
|
+
isDisabled?: boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface StorefrontProduct {
|
|
36
|
+
id: string;
|
|
37
|
+
slug: string;
|
|
38
|
+
title: string;
|
|
39
|
+
shortTitle?: string | null;
|
|
40
|
+
collectionSlug?: string | null;
|
|
41
|
+
organizationalCollectionSlug?: string | null;
|
|
42
|
+
proCollectionSlug?: string | null;
|
|
43
|
+
status: DisplayProductStatus;
|
|
44
|
+
options: Array<{
|
|
45
|
+
__typename?: "StorefrontOption";
|
|
46
|
+
id: string;
|
|
47
|
+
title: string;
|
|
48
|
+
slug: string;
|
|
49
|
+
values: Array<{
|
|
50
|
+
__typename?: "StorefrontOptionValue";
|
|
51
|
+
id: string;
|
|
52
|
+
title: string;
|
|
53
|
+
slug: string;
|
|
54
|
+
}>;
|
|
55
|
+
}>;
|
|
56
|
+
tags: Array<{
|
|
57
|
+
__typename?: "ProductTag";
|
|
58
|
+
name: string;
|
|
59
|
+
}>;
|
|
60
|
+
minDisplayPrice: {
|
|
61
|
+
__typename?: "Money";
|
|
62
|
+
amount: number;
|
|
63
|
+
currency: Currency;
|
|
64
|
+
};
|
|
65
|
+
variants: Array<{
|
|
66
|
+
__typename?: "StorefrontProductVariant";
|
|
67
|
+
id: string;
|
|
68
|
+
status: DisplayProductStatus;
|
|
69
|
+
availableInOtherStores: Array<{
|
|
70
|
+
__typename: "StorefrontProductVariantAlternativeStore";
|
|
71
|
+
}>;
|
|
72
|
+
optionValueIds?: Array<string> | null;
|
|
73
|
+
}>;
|
|
74
|
+
}
|
|
75
|
+
export type StorefrontOptionValue = {
|
|
76
|
+
__typename?: "StorefrontOptionValue";
|
|
77
|
+
id: string;
|
|
78
|
+
slug: string;
|
|
79
|
+
title: string;
|
|
80
|
+
};
|
|
81
|
+
export type StorefrontOption = {
|
|
82
|
+
__typename?: "StorefrontOption";
|
|
83
|
+
id: string;
|
|
84
|
+
slug: string;
|
|
85
|
+
title: string;
|
|
86
|
+
values: Array<StorefrontOptionValue>;
|
|
87
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var DisplayProductStatus = /* @__PURE__ */(DisplayProductStatus2 => {
|
|
5
|
+
DisplayProductStatus2["Available"] = "Available";
|
|
6
|
+
DisplayProductStatus2["Backorder"] = "Backorder";
|
|
7
|
+
DisplayProductStatus2["ComingSoon"] = "ComingSoon";
|
|
8
|
+
DisplayProductStatus2["RegionNotAvailable"] = "RegionNotAvailable";
|
|
9
|
+
DisplayProductStatus2["SoldOut"] = "SoldOut";
|
|
10
|
+
DisplayProductStatus2["Unavailable"] = "Unavailable";
|
|
11
|
+
return DisplayProductStatus2;
|
|
12
|
+
})(DisplayProductStatus || {});
|
|
13
|
+
exports.DisplayProductStatus = DisplayProductStatus;
|
|
14
|
+
//# sourceMappingURL=product.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product.js","sources":["../../src/types/product.ts"],"sourcesContent":["import type { Currency } from \"../types\";\n\n\nexport enum DisplayProductStatus {\n Available = \"Available\",\n Backorder = \"Backorder\",\n ComingSoon = \"ComingSoon\",\n RegionNotAvailable = \"RegionNotAvailable\",\n SoldOut = \"SoldOut\",\n Unavailable = \"Unavailable\",\n}\n\nexport type CollectionSection = {\n id: string;\n productTags: Array<string>;\n title: string;\n};\n\nexport interface Section extends CollectionSection {\n items: Section[];\n}\n\nexport type ProductTagFragment = { __typename?: \"ProductTag\"; name: string };\n\nexport interface MappedProductSection<T> extends Section {\n items: MappedProductSection<T>[];\n products: T[];\n /**\n * States which is conditionally calculated based on the need.\n * E.g. if it is an optical collection where collection sections\n * are rendered inside the VariantSelector items, we need to\n * know which section does not contain products that are in stock.\n * If all products in the section are out of stock, we need to\n * apply grayed out style to the section button.\n */\n isDisabled?: boolean;\n}\n\nexport interface StorefrontProduct {\n id: string;\n slug: string;\n title: string;\n shortTitle?: string | null;\n collectionSlug?: string | null;\n organizationalCollectionSlug?: string | null;\n proCollectionSlug?: string | null;\n status: DisplayProductStatus;\n options: Array<{\n __typename?: \"StorefrontOption\";\n id: string;\n title: string;\n slug: string;\n values: Array<{\n __typename?: \"StorefrontOptionValue\";\n id: string;\n title: string;\n slug: string;\n }>;\n }>;\n tags: Array<{ __typename?: \"ProductTag\"; name: string }>;\n minDisplayPrice: { __typename?: \"Money\"; amount: number; currency: Currency };\n variants: Array<{\n __typename?: \"StorefrontProductVariant\";\n id: string;\n status: DisplayProductStatus;\n availableInOtherStores: Array<{\n __typename: \"StorefrontProductVariantAlternativeStore\";\n }>;\n optionValueIds?: Array<string> | null;\n }>;\n}\n\nexport type StorefrontOptionValue = {\n __typename?: \"StorefrontOptionValue\";\n id: string;\n slug: string;\n title: string;\n};\n\nexport type StorefrontOption = {\n __typename?: \"StorefrontOption\";\n id: string;\n slug: string;\n title: string;\n values: Array<StorefrontOptionValue>;\n};\n"],"names":["DisplayProductStatus"],"mappings":";;;AAGY,IAAAA,oBAAA,GAAA,gBAAAA,qBAAL,IAAA;EACLA,sBAAA,WAAY,CAAA,GAAA,WAAA;EACZA,sBAAA,WAAY,CAAA,GAAA,WAAA;EACZA,sBAAA,YAAa,CAAA,GAAA,YAAA;EACbA,sBAAA,oBAAqB,CAAA,GAAA,oBAAA;EACrBA,sBAAA,SAAU,CAAA,GAAA,SAAA;EACVA,sBAAA,aAAc,CAAA,GAAA,aAAA;EANJA,OAAAA,qBAAAA;AAAA,CAAA,EAAAA,oBAAA,IAAA,CAAA,CAAA,CAAA;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var DisplayProductStatus = /* @__PURE__ */(DisplayProductStatus2 => {
|
|
4
|
+
DisplayProductStatus2["Available"] = "Available";
|
|
5
|
+
DisplayProductStatus2["Backorder"] = "Backorder";
|
|
6
|
+
DisplayProductStatus2["ComingSoon"] = "ComingSoon";
|
|
7
|
+
DisplayProductStatus2["RegionNotAvailable"] = "RegionNotAvailable";
|
|
8
|
+
DisplayProductStatus2["SoldOut"] = "SoldOut";
|
|
9
|
+
DisplayProductStatus2["Unavailable"] = "Unavailable";
|
|
10
|
+
return DisplayProductStatus2;
|
|
11
|
+
})(DisplayProductStatus || {});
|
|
12
|
+
export { DisplayProductStatus };
|
|
13
|
+
//# sourceMappingURL=product.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product.mjs","sources":["../../src/types/product.ts"],"sourcesContent":["import type { Currency } from \"../types\";\n\n\nexport enum DisplayProductStatus {\n Available = \"Available\",\n Backorder = \"Backorder\",\n ComingSoon = \"ComingSoon\",\n RegionNotAvailable = \"RegionNotAvailable\",\n SoldOut = \"SoldOut\",\n Unavailable = \"Unavailable\",\n}\n\nexport type CollectionSection = {\n id: string;\n productTags: Array<string>;\n title: string;\n};\n\nexport interface Section extends CollectionSection {\n items: Section[];\n}\n\nexport type ProductTagFragment = { __typename?: \"ProductTag\"; name: string };\n\nexport interface MappedProductSection<T> extends Section {\n items: MappedProductSection<T>[];\n products: T[];\n /**\n * States which is conditionally calculated based on the need.\n * E.g. if it is an optical collection where collection sections\n * are rendered inside the VariantSelector items, we need to\n * know which section does not contain products that are in stock.\n * If all products in the section are out of stock, we need to\n * apply grayed out style to the section button.\n */\n isDisabled?: boolean;\n}\n\nexport interface StorefrontProduct {\n id: string;\n slug: string;\n title: string;\n shortTitle?: string | null;\n collectionSlug?: string | null;\n organizationalCollectionSlug?: string | null;\n proCollectionSlug?: string | null;\n status: DisplayProductStatus;\n options: Array<{\n __typename?: \"StorefrontOption\";\n id: string;\n title: string;\n slug: string;\n values: Array<{\n __typename?: \"StorefrontOptionValue\";\n id: string;\n title: string;\n slug: string;\n }>;\n }>;\n tags: Array<{ __typename?: \"ProductTag\"; name: string }>;\n minDisplayPrice: { __typename?: \"Money\"; amount: number; currency: Currency };\n variants: Array<{\n __typename?: \"StorefrontProductVariant\";\n id: string;\n status: DisplayProductStatus;\n availableInOtherStores: Array<{\n __typename: \"StorefrontProductVariantAlternativeStore\";\n }>;\n optionValueIds?: Array<string> | null;\n }>;\n}\n\nexport type StorefrontOptionValue = {\n __typename?: \"StorefrontOptionValue\";\n id: string;\n slug: string;\n title: string;\n};\n\nexport type StorefrontOption = {\n __typename?: \"StorefrontOption\";\n id: string;\n slug: string;\n title: string;\n values: Array<StorefrontOptionValue>;\n};\n"],"names":["DisplayProductStatus"],"mappings":";;AAGY,IAAAA,oBAAA,GAAA,gBAAAA,qBAAL,IAAA;EACLA,sBAAA,WAAY,CAAA,GAAA,WAAA;EACZA,sBAAA,WAAY,CAAA,GAAA,WAAA;EACZA,sBAAA,YAAa,CAAA,GAAA,YAAA;EACbA,sBAAA,oBAAqB,CAAA,GAAA,oBAAA;EACrBA,sBAAA,SAAU,CAAA,GAAA,SAAA;EACVA,sBAAA,aAAc,CAAA,GAAA,aAAA;EANJA,OAAAA,qBAAAA;AAAA,CAAA,EAAAA,oBAAA,IAAA,CAAA,CAAA,CAAA;"}
|
package/lib/utils/array.d.ts
CHANGED
|
@@ -28,3 +28,7 @@ export declare const arraySafeIndexFind: <T>(array: T[], index: number) => T | u
|
|
|
28
28
|
* Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts
|
|
29
29
|
*/
|
|
30
30
|
export declare const normalizeSortResult: (sortResult: number) => number;
|
|
31
|
+
/**
|
|
32
|
+
* Combine multiple sort functions into one
|
|
33
|
+
*/
|
|
34
|
+
export declare const combineSorts: <T>(sorts: ((a: T, b: T) => number)[]) => ((a: T, b: T) => number);
|
package/lib/utils/array.js
CHANGED
|
@@ -24,9 +24,19 @@ const arraySafeIndexFind = (array, index) => {
|
|
|
24
24
|
return array[safeIndex];
|
|
25
25
|
};
|
|
26
26
|
const normalizeSortResult = sortResult => number.clamp(sortResult, -1, 1);
|
|
27
|
+
const combineSorts = sorts => (a, b) => {
|
|
28
|
+
for (const sort of sorts) {
|
|
29
|
+
const result = sort(a, b);
|
|
30
|
+
if (result !== 0) {
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return 0;
|
|
35
|
+
};
|
|
27
36
|
exports.areEqualArrays = areEqualArrays;
|
|
28
37
|
exports.arraySafeIndex = arraySafeIndex;
|
|
29
38
|
exports.arraySafeIndexFind = arraySafeIndexFind;
|
|
39
|
+
exports.combineSorts = combineSorts;
|
|
30
40
|
exports.dedupe = dedupe;
|
|
31
41
|
exports.ensureArray = ensureArray;
|
|
32
42
|
exports.normalizeSortResult = normalizeSortResult;
|
package/lib/utils/array.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.js","sources":["../../src/utils/array.ts"],"sourcesContent":["import { clamp } from \"./number\";\n\n/**\n * Make sure the element is an array\n * If it's not, make it an array of one element\n */\nexport function ensureArray<T>(value: T | T[]): T[] {\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Utility to quickly remove duplicates from an array.\n *\n * Similar to lodash's `uniq`, but doesn't require lodash as dependency.\n */\nexport const dedupe = <T>(arr: T[]) => [...new Set(arr)];\n\n/**\n * Utility function check if given arrays contain same elements (regardless the order)\n *\n * @example\n * areArraysEqual([1, 2, 3], [3, 2, 1]) // true\n * areArraysEqual([1, 2, 3], [3, 2, 1, 4]) // false\n */\nexport const areEqualArrays = (a: string[], b: string[]): boolean => {\n if (a.length !== b.length) {\n return false;\n }\n if (!a.every((el) => b.includes(el))) {\n return false;\n }\n return !b.every((el) => a.includes(el)) ? false : true;\n};\n\n/**\n * Function to get array index by positive and negative wrap-around offsets\n *\n * @see https://dirask.com/posts/JavaScript-positive-and-negative-around-index-wrapping-overlapping-to-address-items-in-array-pVyrnD\n */\nexport const arraySafeIndex = <T>(array: T[], index: number): number => {\n const indexSize = array.length;\n\n return ((index % indexSize) + indexSize) % indexSize;\n};\n\nexport const arraySafeIndexFind = <T>(\n array: T[],\n index: number,\n): T | undefined => {\n const safeIndex = arraySafeIndex(array, index);\n\n return array[safeIndex];\n};\n\n/**\n * Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts\n */\nexport const normalizeSortResult = (sortResult: number): number =>\n clamp(sortResult, -1, 1);\n"],"names":["ensureArray","value","Array","isArray","dedupe","arr","Set","areEqualArrays","a","b","length","every","el","includes","arraySafeIndex","array","index","indexSize","arraySafeIndexFind","safeIndex","normalizeSortResult","sortResult","clamp"],"mappings":";;;;AAMO,SAASA,YAAeC,KAAqB,EAAA;EAClD,OAAOC,MAAMC,OAAQ,CAAAF,KAAK,CAAI,GAAAA,KAAA,GAAQ,CAACA,KAAK,CAAA;AAC9C;AAOa,MAAAG,MAAA,GAAaC,GAAa,IAAA,CAAC,GAAG,IAAIC,GAAA,CAAID,GAAG,CAAC,CAAA;AAS1C,MAAAE,cAAA,GAAiBA,CAACC,CAAA,EAAaC,CAAyB,KAAA;EAC/D,IAAAD,CAAA,CAAEE,MAAW,KAAAD,CAAA,CAAEC,MAAQ,EAAA;IAClB,OAAA,KAAA;EACT;EACI,IAAA,CAACF,EAAEG,KAAM,CAACC,MAAOH,CAAE,CAAAI,QAAA,CAASD,EAAE,CAAC,CAAG,EAAA;IAC7B,OAAA,KAAA;EACT;EACO,OAAA,CAACH,CAAE,CAAAE,KAAA,CAAOC,EAAA,IAAOJ,EAAEK,QAAS,CAAAD,EAAE,CAAC,CAAA,GAAI,KAAQ,GAAA,IAAA;AACpD,CAAA;AAOa,MAAAE,cAAA,GAAiBA,CAAIC,KAAA,EAAYC,KAA0B,KAAA;EACtE,MAAMC,YAAYF,KAAM,CAAAL,MAAA;EAEf,OAAA,CAAAM,KAAA,GAAQC,YAAaA,SAAa,IAAAA,SAAA;AAC7C,CAAA;AAEa,MAAAC,kBAAA,GAAqBA,CAChCH,KAAA,EACAC,KACkB,KAAA;EACZ,MAAAG,SAAA,GAAYL,cAAe,CAAAC,KAAA,EAAOC,KAAK,CAAA;EAE7C,OAAOD,MAAMI,SAAS,CAAA;AACxB,CAAA;AAKO,MAAMC,sBAAuBC,UAAA,IAClCC,MAAAA,CAAAA,KAAM,CAAAD,UAAA,EAAY,IAAI,CAAC,CAAA
|
|
1
|
+
{"version":3,"file":"array.js","sources":["../../src/utils/array.ts"],"sourcesContent":["import { clamp } from \"./number\";\n\n/**\n * Make sure the element is an array\n * If it's not, make it an array of one element\n */\nexport function ensureArray<T>(value: T | T[]): T[] {\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Utility to quickly remove duplicates from an array.\n *\n * Similar to lodash's `uniq`, but doesn't require lodash as dependency.\n */\nexport const dedupe = <T>(arr: T[]) => [...new Set(arr)];\n\n/**\n * Utility function check if given arrays contain same elements (regardless the order)\n *\n * @example\n * areArraysEqual([1, 2, 3], [3, 2, 1]) // true\n * areArraysEqual([1, 2, 3], [3, 2, 1, 4]) // false\n */\nexport const areEqualArrays = (a: string[], b: string[]): boolean => {\n if (a.length !== b.length) {\n return false;\n }\n if (!a.every((el) => b.includes(el))) {\n return false;\n }\n return !b.every((el) => a.includes(el)) ? false : true;\n};\n\n/**\n * Function to get array index by positive and negative wrap-around offsets\n *\n * @see https://dirask.com/posts/JavaScript-positive-and-negative-around-index-wrapping-overlapping-to-address-items-in-array-pVyrnD\n */\nexport const arraySafeIndex = <T>(array: T[], index: number): number => {\n const indexSize = array.length;\n\n return ((index % indexSize) + indexSize) % indexSize;\n};\n\nexport const arraySafeIndexFind = <T>(\n array: T[],\n index: number,\n): T | undefined => {\n const safeIndex = arraySafeIndex(array, index);\n\n return array[safeIndex];\n};\n\n/**\n * Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts\n */\nexport const normalizeSortResult = (sortResult: number): number =>\n clamp(sortResult, -1, 1);\n\n/**\n * Combine multiple sort functions into one\n */\nexport const combineSorts =\n <T>(sorts: ((a: T, b: T) => number)[]): ((a: T, b: T) => number) =>\n (a, b) => {\n for (const sort of sorts) {\n const result = sort(a, b);\n\n if (result !== 0) {\n return result;\n }\n }\n\n return 0;\n };\n"],"names":["ensureArray","value","Array","isArray","dedupe","arr","Set","areEqualArrays","a","b","length","every","el","includes","arraySafeIndex","array","index","indexSize","arraySafeIndexFind","safeIndex","normalizeSortResult","sortResult","clamp","combineSorts","sorts","sort","result"],"mappings":";;;;AAMO,SAASA,YAAeC,KAAqB,EAAA;EAClD,OAAOC,MAAMC,OAAQ,CAAAF,KAAK,CAAI,GAAAA,KAAA,GAAQ,CAACA,KAAK,CAAA;AAC9C;AAOa,MAAAG,MAAA,GAAaC,GAAa,IAAA,CAAC,GAAG,IAAIC,GAAA,CAAID,GAAG,CAAC,CAAA;AAS1C,MAAAE,cAAA,GAAiBA,CAACC,CAAA,EAAaC,CAAyB,KAAA;EAC/D,IAAAD,CAAA,CAAEE,MAAW,KAAAD,CAAA,CAAEC,MAAQ,EAAA;IAClB,OAAA,KAAA;EACT;EACI,IAAA,CAACF,EAAEG,KAAM,CAACC,MAAOH,CAAE,CAAAI,QAAA,CAASD,EAAE,CAAC,CAAG,EAAA;IAC7B,OAAA,KAAA;EACT;EACO,OAAA,CAACH,CAAE,CAAAE,KAAA,CAAOC,EAAA,I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