@tapcart/mobile-components 0.12.6 → 0.12.7
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/dist/components/hooks/use-product-options.d.ts +4 -0
- package/dist/components/hooks/use-product-options.d.ts.map +1 -1
- package/dist/components/hooks/use-product-options.js +18 -0
- package/dist/components/hooks/use-recommendations.d.ts.map +1 -1
- package/dist/components/hooks/use-recommendations.js +29 -13
- package/dist/styles.css +39 -0
- package/package.json +1 -1
|
@@ -4,6 +4,10 @@ export declare function useProductOptions(variants: ProductVariant[] | undefined
|
|
|
4
4
|
selectedOptions: SelectedOptions;
|
|
5
5
|
handleSelect: (optionName: string, optionValue: string) => void;
|
|
6
6
|
selectedVariant: ProductVariant | undefined;
|
|
7
|
+
productOptions: {
|
|
8
|
+
name: string;
|
|
9
|
+
values: string[];
|
|
10
|
+
}[];
|
|
7
11
|
};
|
|
8
12
|
export {};
|
|
9
13
|
//# sourceMappingURL=use-product-options.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-product-options.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-product-options.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD,KAAK,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAE7C,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,cAAc,EAAE,GAAG,SAAS,GAAG,IAAI,EAC7C,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI;;+BA+DC,MAAM,eAAe,MAAM,KAAG,IAAI
|
|
1
|
+
{"version":3,"file":"use-product-options.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-product-options.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD,KAAK,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAE7C,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,cAAc,EAAE,GAAG,SAAS,GAAG,IAAI,EAC7C,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI;;+BA+DC,MAAM,eAAe,MAAM,KAAG,IAAI;;;;;;EA4CrE"}
|
|
@@ -54,9 +54,27 @@ export function useProductOptions(variants, selectedVariantId) {
|
|
|
54
54
|
setSelectedOptions(initializeSelectedOptions(selectedVariantId));
|
|
55
55
|
}, [safeVariants, initializeSelectedOptions, selectedVariantId]);
|
|
56
56
|
const selectedVariant = useMemo(() => safeVariants.find((v) => { var _a; return (_a = v.selectedOptions) === null || _a === void 0 ? void 0 : _a.every((o) => selectedOptions[o.name] === o.value); }), [safeVariants, selectedOptions]);
|
|
57
|
+
const productOptions = useMemo(() => {
|
|
58
|
+
var _a;
|
|
59
|
+
const optionsMap = new Map();
|
|
60
|
+
for (const variant of safeVariants) {
|
|
61
|
+
for (const { name, value } of (variant === null || variant === void 0 ? void 0 : variant.selectedOptions) || []) {
|
|
62
|
+
if (!optionsMap.has(name)) {
|
|
63
|
+
optionsMap.set(name, new Set());
|
|
64
|
+
}
|
|
65
|
+
(_a = optionsMap.get(name)) === null || _a === void 0 ? void 0 : _a.add(value);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Convert Map to plain array
|
|
69
|
+
return Array.from(optionsMap.entries()).map(([name, values]) => ({
|
|
70
|
+
name,
|
|
71
|
+
values: Array.from(values),
|
|
72
|
+
}));
|
|
73
|
+
}, [safeVariants]);
|
|
57
74
|
return {
|
|
58
75
|
selectedOptions,
|
|
59
76
|
handleSelect,
|
|
60
77
|
selectedVariant,
|
|
78
|
+
productOptions,
|
|
61
79
|
};
|
|
62
80
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-recommendations.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-recommendations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,g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QAAA,MAAM,kBAAkB,yEASrB,sBAAsB,KAAG,uBAmH3B,CAAA;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAA"}
|
|
@@ -22,6 +22,7 @@ const getCollections = (collections) => {
|
|
|
22
22
|
: [];
|
|
23
23
|
};
|
|
24
24
|
const recommendationsLocalStorage = new RecommendationsLocalStorage();
|
|
25
|
+
const MIN_QUERY_LENGTH = 3;
|
|
25
26
|
const useRecommendations = ({
|
|
26
27
|
// Search client props
|
|
27
28
|
searchClient, query = "", customSearchConfig,
|
|
@@ -33,6 +34,8 @@ queryVariables, apiURL, }) => {
|
|
|
33
34
|
const recommendation = usingSearchClient
|
|
34
35
|
? query
|
|
35
36
|
: (searchParams === null || searchParams === void 0 ? void 0 : searchParams.get("recommendation")) || "";
|
|
37
|
+
// Check if resolved recommendation meets minimum length requirement
|
|
38
|
+
const shouldFetch = recommendation.length >= MIN_QUERY_LENGTH;
|
|
36
39
|
const [cachedRecommendation, setCachedRecommendations] = React.useState(recommendationsLocalStorage.getCacheItem({
|
|
37
40
|
id: `${recommendation}-${queryVariables === null || queryVariables === void 0 ? void 0 : queryVariables.language}`,
|
|
38
41
|
}));
|
|
@@ -59,19 +62,21 @@ queryVariables, apiURL, }) => {
|
|
|
59
62
|
}
|
|
60
63
|
return data;
|
|
61
64
|
}));
|
|
62
|
-
// Determine which approach to use
|
|
63
|
-
const swrKey =
|
|
64
|
-
?
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
65
|
+
// Determine which approach to use (null key prevents fetch)
|
|
66
|
+
const swrKey = shouldFetch
|
|
67
|
+
? usingSearchClient
|
|
68
|
+
? {
|
|
69
|
+
type: "searchClient",
|
|
70
|
+
query: recommendation,
|
|
71
|
+
language: queryVariables === null || queryVariables === void 0 ? void 0 : queryVariables.language,
|
|
72
|
+
customSearchConfig,
|
|
73
|
+
}
|
|
74
|
+
: {
|
|
75
|
+
appId: queryVariables.appId,
|
|
76
|
+
query: recommendation,
|
|
77
|
+
language: queryVariables.language,
|
|
78
|
+
}
|
|
79
|
+
: null;
|
|
75
80
|
const fetcher = usingSearchClient ? searchClientFetcher : apiFetcher;
|
|
76
81
|
const { data, error, isLoading } = useSWR(swrKey, usingSearchClient ? fetcher : (body) => apiFetcher(body), {
|
|
77
82
|
revalidateOnFocus: false,
|
|
@@ -89,6 +94,17 @@ queryVariables, apiURL, }) => {
|
|
|
89
94
|
facets: (data === null || data === void 0 ? void 0 : data.facets) || [],
|
|
90
95
|
});
|
|
91
96
|
}, [data, recommendation, queryVariables === null || queryVariables === void 0 ? void 0 : queryVariables.language]);
|
|
97
|
+
// Return empty results when recommendation is below minimum length
|
|
98
|
+
if (!shouldFetch) {
|
|
99
|
+
return {
|
|
100
|
+
products: [],
|
|
101
|
+
collections: [],
|
|
102
|
+
searches: [],
|
|
103
|
+
facets: [],
|
|
104
|
+
isLoading: false,
|
|
105
|
+
error: null,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
92
108
|
return {
|
|
93
109
|
products: cachedRecommendation === null || cachedRecommendation === void 0 ? void 0 : cachedRecommendation.products,
|
|
94
110
|
collections: cachedRecommendation === null || cachedRecommendation === void 0 ? void 0 : cachedRecommendation.collections,
|
package/dist/styles.css
CHANGED
|
@@ -648,6 +648,13 @@ video {
|
|
|
648
648
|
color: hsl(var(--foreground));
|
|
649
649
|
font-feature-settings: "rlig" 1, "calt" 1;
|
|
650
650
|
}
|
|
651
|
+
.\!container {
|
|
652
|
+
width: 100% !important;
|
|
653
|
+
margin-right: auto !important;
|
|
654
|
+
margin-left: auto !important;
|
|
655
|
+
padding-right: 2rem !important;
|
|
656
|
+
padding-left: 2rem !important;
|
|
657
|
+
}
|
|
651
658
|
.container {
|
|
652
659
|
width: 100%;
|
|
653
660
|
margin-right: auto;
|
|
@@ -657,6 +664,10 @@ video {
|
|
|
657
664
|
}
|
|
658
665
|
@media (min-width: 1400px) {
|
|
659
666
|
|
|
667
|
+
.\!container {
|
|
668
|
+
max-width: 1400px !important;
|
|
669
|
+
}
|
|
670
|
+
|
|
660
671
|
.container {
|
|
661
672
|
max-width: 1400px;
|
|
662
673
|
}
|
|
@@ -1791,6 +1802,14 @@ video {
|
|
|
1791
1802
|
.bg-foreground {
|
|
1792
1803
|
background-color: hsl(var(--foreground));
|
|
1793
1804
|
}
|
|
1805
|
+
.bg-gray-100 {
|
|
1806
|
+
--tw-bg-opacity: 1;
|
|
1807
|
+
background-color: rgb(243 244 246 / var(--tw-bg-opacity, 1));
|
|
1808
|
+
}
|
|
1809
|
+
.bg-gray-200 {
|
|
1810
|
+
--tw-bg-opacity: 1;
|
|
1811
|
+
background-color: rgb(229 231 235 / var(--tw-bg-opacity, 1));
|
|
1812
|
+
}
|
|
1794
1813
|
.bg-gray-300 {
|
|
1795
1814
|
--tw-bg-opacity: 1;
|
|
1796
1815
|
background-color: rgb(209 213 219 / var(--tw-bg-opacity, 1));
|
|
@@ -1798,6 +1817,10 @@ video {
|
|
|
1798
1817
|
.bg-productBadging-fill {
|
|
1799
1818
|
background-color: var(--productBadging-fill);
|
|
1800
1819
|
}
|
|
1820
|
+
.bg-red-100 {
|
|
1821
|
+
--tw-bg-opacity: 1;
|
|
1822
|
+
background-color: rgb(254 226 226 / var(--tw-bg-opacity, 1));
|
|
1823
|
+
}
|
|
1801
1824
|
.bg-stateColors-disabled {
|
|
1802
1825
|
background-color: var(--stateColors-disabled);
|
|
1803
1826
|
}
|
|
@@ -2214,6 +2237,10 @@ video {
|
|
|
2214
2237
|
.text-productBadging-text {
|
|
2215
2238
|
color: var(--productBadging-text);
|
|
2216
2239
|
}
|
|
2240
|
+
.text-red-500 {
|
|
2241
|
+
--tw-text-opacity: 1;
|
|
2242
|
+
color: rgb(239 68 68 / var(--tw-text-opacity, 1));
|
|
2243
|
+
}
|
|
2217
2244
|
.text-red-600 {
|
|
2218
2245
|
--tw-text-opacity: 1;
|
|
2219
2246
|
color: rgb(220 38 38 / var(--tw-text-opacity, 1));
|
|
@@ -2266,6 +2293,10 @@ video {
|
|
|
2266
2293
|
.text-textColors-strikethroughPriceText {
|
|
2267
2294
|
color: var(--textColors-strikethroughPriceText);
|
|
2268
2295
|
}
|
|
2296
|
+
.text-white {
|
|
2297
|
+
--tw-text-opacity: 1;
|
|
2298
|
+
color: rgb(255 255 255 / var(--tw-text-opacity, 1));
|
|
2299
|
+
}
|
|
2269
2300
|
.underline {
|
|
2270
2301
|
text-decoration-line: underline;
|
|
2271
2302
|
}
|
|
@@ -2379,6 +2410,10 @@ video {
|
|
|
2379
2410
|
--tw-blur: blur(8px);
|
|
2380
2411
|
filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
|
|
2381
2412
|
}
|
|
2413
|
+
.drop-shadow {
|
|
2414
|
+
--tw-drop-shadow: drop-shadow(0 1px 2px rgb(0 0 0 / 0.1)) drop-shadow(0 1px 1px rgb(0 0 0 / 0.06));
|
|
2415
|
+
filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
|
|
2416
|
+
}
|
|
2382
2417
|
.drop-shadow-\[0_3px_1px_0_rgba\(0\2c 0\2c 0\2c 1\)\] {
|
|
2383
2418
|
--tw-drop-shadow: drop-shadow(0 3px 1px 0 rgba(0,0,0,1));
|
|
2384
2419
|
filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
|
|
@@ -2490,6 +2525,10 @@ video {
|
|
|
2490
2525
|
.paused {
|
|
2491
2526
|
animation-play-state: paused;
|
|
2492
2527
|
}
|
|
2528
|
+
.\!container {
|
|
2529
|
+
padding-right: 16px !important;
|
|
2530
|
+
padding-left: 16px !important;
|
|
2531
|
+
}
|
|
2493
2532
|
.container {
|
|
2494
2533
|
padding-right: 16px;
|
|
2495
2534
|
padding-left: 16px;
|