@tapcart/mobile-components 0.7.7 → 0.7.8
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-nosto-recommendation.d.ts +8 -0
- package/dist/components/hooks/use-nosto-recommendation.d.ts.map +1 -0
- package/dist/components/hooks/use-nosto-recommendation.js +105 -0
- package/dist/components/hooks/use-products.d.ts.map +1 -1
- package/dist/components/hooks/use-products.js +2 -1
- package/dist/components/ui/ProductCard/utils.d.ts +94 -0
- package/dist/components/ui/ProductCard/utils.d.ts.map +1 -0
- package/dist/components/ui/ProductCard/utils.js +148 -0
- package/dist/components/ui/carousel.d.ts.map +1 -1
- package/dist/components/ui/carousel.js +1 -0
- package/dist/components/ui/drawer.d.ts +3 -5
- package/dist/components/ui/drawer.d.ts.map +1 -1
- package/dist/components/ui/drawer.js +8 -7
- package/dist/components/ui/favorite.js +1 -1
- package/dist/components/ui/image.js +2 -2
- package/dist/components/ui/tap.d.ts +12 -0
- package/dist/components/ui/tap.d.ts.map +1 -0
- package/dist/components/ui/tap.js +128 -0
- package/dist/components/ui/video-enhanced.d.ts +18 -0
- package/dist/components/ui/video-enhanced.d.ts.map +1 -0
- package/dist/components/ui/video-enhanced.js +197 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/lib/price.d.ts +29 -0
- package/dist/lib/price.d.ts.map +1 -0
- package/dist/lib/price.js +66 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +31 -5
- package/dist/styles.css +49 -11
- package/package.json +2 -2
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Integrations } from "app-studio-types";
|
|
2
|
+
export declare function useNostoRecommendations(integrations: Integrations, baseURL: string, slotId?: null): {
|
|
3
|
+
recommendations: import("app-studio-types").Product[];
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
error: any;
|
|
6
|
+
isEmpty: boolean;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=use-nosto-recommendation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-nosto-recommendation.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-nosto-recommendation.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AA+E/C,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,MAAM,EACf,MAAM,OAAO;;;;;EA4Cd"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
import { useState, useEffect } from "react";
|
|
12
|
+
import { useProducts } from "./use-products";
|
|
13
|
+
const getRecommendations = (integrations, slotId = null) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
if (!Array.isArray(integrations))
|
|
15
|
+
return [];
|
|
16
|
+
const nosto = integrations.find((integration) => integration.name === "nosto");
|
|
17
|
+
const url = "https://api.nosto.com/v1/graphql";
|
|
18
|
+
const headers = new Headers({
|
|
19
|
+
"Content-Type": "application/json",
|
|
20
|
+
Authorization: "Basic " + btoa(":" + (nosto === null || nosto === void 0 ? void 0 : nosto.key)),
|
|
21
|
+
});
|
|
22
|
+
// Fetch sessionId
|
|
23
|
+
const sessionBody = JSON.stringify({
|
|
24
|
+
query: `mutation { newSession }`,
|
|
25
|
+
});
|
|
26
|
+
const sessionResponse = yield fetch(url, {
|
|
27
|
+
method: "POST",
|
|
28
|
+
headers: headers,
|
|
29
|
+
body: sessionBody,
|
|
30
|
+
});
|
|
31
|
+
const sessionData = yield sessionResponse.json();
|
|
32
|
+
const sessionId = sessionData.data.newSession;
|
|
33
|
+
// Main recommendation query
|
|
34
|
+
const body = JSON.stringify({
|
|
35
|
+
query: `
|
|
36
|
+
mutation {
|
|
37
|
+
updateSession(
|
|
38
|
+
by: BY_CID
|
|
39
|
+
id: "${sessionId}"
|
|
40
|
+
params: {
|
|
41
|
+
event: { type: VIEWED_PAGE, target: "home" }
|
|
42
|
+
}
|
|
43
|
+
) {
|
|
44
|
+
pages {
|
|
45
|
+
forFrontPage(
|
|
46
|
+
params: {
|
|
47
|
+
isPreview: false
|
|
48
|
+
imageVersion: VERSION_8_400_400
|
|
49
|
+
${slotId ? `slotIds: ["${slotId}"]` : ""}
|
|
50
|
+
}
|
|
51
|
+
) {
|
|
52
|
+
primary {
|
|
53
|
+
productId
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
`,
|
|
60
|
+
});
|
|
61
|
+
const response = yield fetch(url, {
|
|
62
|
+
method: "POST",
|
|
63
|
+
headers: headers,
|
|
64
|
+
mode: "cors",
|
|
65
|
+
body,
|
|
66
|
+
});
|
|
67
|
+
const json = yield response.json();
|
|
68
|
+
return json;
|
|
69
|
+
});
|
|
70
|
+
export function useNostoRecommendations(integrations, baseURL, slotId = null) {
|
|
71
|
+
var _a, _b, _c, _d;
|
|
72
|
+
const [nostoData, setNostoData] = useState(null);
|
|
73
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
74
|
+
const [error, setError] = useState(null);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
function fetchNostoData() {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
try {
|
|
79
|
+
const result = yield getRecommendations(integrations, slotId);
|
|
80
|
+
setNostoData(result);
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
console.error("Error fetching recommendations:", err);
|
|
84
|
+
setError(err);
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
setIsLoading(false);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
fetchNostoData();
|
|
92
|
+
}, [integrations, slotId]);
|
|
93
|
+
const productIds = ((_d = (_c = (_b = (_a = nostoData === null || nostoData === void 0 ? void 0 : nostoData.data) === null || _a === void 0 ? void 0 : _a.updateSession) === null || _b === void 0 ? void 0 : _b.pages) === null || _c === void 0 ? void 0 : _c.forFrontPage) === null || _d === void 0 ? void 0 : _d.flatMap((page) => page.primary).filter((item) => item && item.productId).map((item) => item.productId)) || [];
|
|
94
|
+
const { products, error: productsError, isLoading: productsLoading, } = useProducts({
|
|
95
|
+
productIds,
|
|
96
|
+
baseURL,
|
|
97
|
+
productHandles: [],
|
|
98
|
+
});
|
|
99
|
+
return {
|
|
100
|
+
recommendations: products,
|
|
101
|
+
isLoading: isLoading || productsLoading,
|
|
102
|
+
error: error || productsError,
|
|
103
|
+
isEmpty: products.length === 0,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-products.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-products.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"use-products.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-products.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAG1C,KAAK,GAAG,GAAG,MAAM,CAAA;AACjB,KAAK,cAAc,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAA;AACxD,KAAK,gBAAgB,GAAG;IACtB,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,cAAc,EAAE,MAAM,EAAE,CAAA;IACxB,OAAO,EAAE,GAAG,CAAA;IACZ,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACpC,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;IAC1E,UAAU,CAAC,EAAE,cAAc,EAAE,CAAA;CAC9B,CAAA;AACD,KAAK,iBAAiB,GAAG;IACvB,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,KAAK,EAAE,GAAG,CAAA;IACV,SAAS,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI,GAAG,iBAAiB,CAyD7E"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import useSWR from "swr";
|
|
3
|
+
import { getProductGidsFromIds } from "../../lib/utils";
|
|
3
4
|
export function useProducts(props) {
|
|
4
5
|
let url = null;
|
|
5
6
|
let body = null;
|
|
@@ -7,7 +8,7 @@ export function useProducts(props) {
|
|
|
7
8
|
const { baseURL, productIds, productHandles, metafields, collection, queryVariables, } = props;
|
|
8
9
|
let queryParams = new URLSearchParams();
|
|
9
10
|
if ((productIds === null || productIds === void 0 ? void 0 : productIds.length) > 0) {
|
|
10
|
-
queryParams.set("ids", productIds.join(","));
|
|
11
|
+
queryParams.set("ids", getProductGidsFromIds(productIds).join(","));
|
|
11
12
|
}
|
|
12
13
|
if ((productHandles === null || productHandles === void 0 ? void 0 : productHandles.length) > 0) {
|
|
13
14
|
queryParams.set("handles", productHandles.join(","));
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
interface ProductCardBadgeConfig {
|
|
2
|
+
variants: {
|
|
3
|
+
horizontalPosition: {
|
|
4
|
+
start: string;
|
|
5
|
+
end: string;
|
|
6
|
+
center: string;
|
|
7
|
+
};
|
|
8
|
+
verticalPosition: {
|
|
9
|
+
top: string;
|
|
10
|
+
bottom: string;
|
|
11
|
+
below: string;
|
|
12
|
+
};
|
|
13
|
+
imageSwipeEnabled: {
|
|
14
|
+
true: string;
|
|
15
|
+
false: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
compoundVariants: Array<{
|
|
19
|
+
verticalPosition: "bottom";
|
|
20
|
+
imageSwipeEnabled: true;
|
|
21
|
+
class: string;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
export declare function getProductCardBadgeVariantsFn(config?: Partial<ProductCardBadgeConfig>): (props?: ({
|
|
25
|
+
horizontalPosition?: "center" | "end" | "start" | null | undefined;
|
|
26
|
+
verticalPosition?: "top" | "bottom" | "below" | null | undefined;
|
|
27
|
+
imageSwipeEnabled?: boolean | null | undefined;
|
|
28
|
+
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
29
|
+
interface ProductCardFavoriteConfig {
|
|
30
|
+
variants: {
|
|
31
|
+
iconPosition: {
|
|
32
|
+
"top-left": string;
|
|
33
|
+
"top-right": string;
|
|
34
|
+
"bottom-left": string;
|
|
35
|
+
"bottom-right": string;
|
|
36
|
+
"below-image-on-right": string;
|
|
37
|
+
};
|
|
38
|
+
badgeHorizontalPosition: {
|
|
39
|
+
start: string;
|
|
40
|
+
end: string;
|
|
41
|
+
center: string;
|
|
42
|
+
};
|
|
43
|
+
badgeVerticalPosition: {
|
|
44
|
+
top: string;
|
|
45
|
+
bottom: string;
|
|
46
|
+
below: string;
|
|
47
|
+
};
|
|
48
|
+
isSoldOut: {
|
|
49
|
+
true: string;
|
|
50
|
+
false: string;
|
|
51
|
+
};
|
|
52
|
+
showSoldOutBadge: {
|
|
53
|
+
true: string;
|
|
54
|
+
false: string;
|
|
55
|
+
};
|
|
56
|
+
imageSwipeEnabled: {
|
|
57
|
+
true: string;
|
|
58
|
+
false: string;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
compoundVariants: Array<{
|
|
62
|
+
[key: string]: any;
|
|
63
|
+
class: string;
|
|
64
|
+
}>;
|
|
65
|
+
defaultVariants: {
|
|
66
|
+
iconPosition: "below-image-on-right";
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export declare function getProductCardFavoriteVariantsFn(config?: Partial<ProductCardFavoriteConfig>): (props?: ({
|
|
70
|
+
iconPosition?: "below-image-on-right" | "top-right" | "top-left" | "bottom-left" | "bottom-right" | null | undefined;
|
|
71
|
+
badgeHorizontalPosition?: "center" | "end" | "start" | null | undefined;
|
|
72
|
+
badgeVerticalPosition?: "top" | "bottom" | "below" | null | undefined;
|
|
73
|
+
isSoldOut?: boolean | null | undefined;
|
|
74
|
+
showSoldOutBadge?: boolean | null | undefined;
|
|
75
|
+
imageSwipeEnabled?: boolean | null | undefined;
|
|
76
|
+
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
77
|
+
type PageState = {
|
|
78
|
+
pageViewType: "collection" | "search";
|
|
79
|
+
};
|
|
80
|
+
export declare function getProductCardTranslationsFn(pageState: PageState, translations: Record<string, string>): {
|
|
81
|
+
gridTranslations: {
|
|
82
|
+
title: string;
|
|
83
|
+
description: string;
|
|
84
|
+
buttonLabel: string;
|
|
85
|
+
};
|
|
86
|
+
productCardTranslations: {
|
|
87
|
+
quickAdd: string;
|
|
88
|
+
soldOut: string;
|
|
89
|
+
addToBag: string;
|
|
90
|
+
viewItem: string;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
export {};
|
|
94
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../components/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;YACZ,KAAK,EAAE,MAAM,CAAA;SACd,CAAA;QACD,iBAAiB,EAAE;YACjB,IAAI,EAAE,MAAM,CAAA;YACZ,KAAK,EAAE,MAAM,CAAA;SACd,CAAA;KACF,CAAA;IACD,gBAAgB,EAAE,KAAK,CAAC;QACtB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;QAClB,KAAK,EAAE,MAAM,CAAA;KACd,CAAC,CAAA;IACF,eAAe,EAAE;QACf,YAAY,EAAE,sBAAsB,CAAA;KACrC,CAAA;CACF;AAED,wBAAgB,gCAAgC,CAC9C,MAAM,GAAE,OAAO,CAAC,yBAAyB,CAAM;;;;;;;oFAuGhD;AAED,KAAK,SAAS,GAAG;IAAE,YAAY,EAAE,YAAY,GAAG,QAAQ,CAAA;CAAE,CAAA;AAE1D,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;;;;;;;;;;;;EAuBrC"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { cva } from "../../../lib/utils";
|
|
2
|
+
export function getProductCardBadgeVariantsFn(config = {}) {
|
|
3
|
+
const defaultConfig = {
|
|
4
|
+
variants: {
|
|
5
|
+
horizontalPosition: {
|
|
6
|
+
start: "left-0",
|
|
7
|
+
end: "right-0",
|
|
8
|
+
center: "",
|
|
9
|
+
},
|
|
10
|
+
verticalPosition: {
|
|
11
|
+
top: "top-0 mt-2",
|
|
12
|
+
bottom: "bottom-0 mb-2",
|
|
13
|
+
below: "",
|
|
14
|
+
},
|
|
15
|
+
imageSwipeEnabled: {
|
|
16
|
+
true: "",
|
|
17
|
+
false: "",
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
compoundVariants: [
|
|
21
|
+
{
|
|
22
|
+
verticalPosition: "bottom",
|
|
23
|
+
imageSwipeEnabled: true,
|
|
24
|
+
class: "bottom-[18px]",
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
};
|
|
28
|
+
return cva("absolute truncate pointer-events-none", Object.assign(Object.assign({}, defaultConfig), config));
|
|
29
|
+
}
|
|
30
|
+
export function getProductCardFavoriteVariantsFn(config = {}) {
|
|
31
|
+
const defaultConfig = {
|
|
32
|
+
variants: {
|
|
33
|
+
iconPosition: {
|
|
34
|
+
"top-left": "top-0 left-2 mt-2",
|
|
35
|
+
"top-right": "top-0 right-2 mt-2",
|
|
36
|
+
"bottom-left": "bottom-0 left-2 mb-2",
|
|
37
|
+
"bottom-right": "bottom-0 right-2 mb-2",
|
|
38
|
+
"below-image-on-right": "",
|
|
39
|
+
},
|
|
40
|
+
badgeHorizontalPosition: {
|
|
41
|
+
start: "",
|
|
42
|
+
end: "",
|
|
43
|
+
center: "",
|
|
44
|
+
},
|
|
45
|
+
badgeVerticalPosition: {
|
|
46
|
+
top: "",
|
|
47
|
+
bottom: "",
|
|
48
|
+
below: "",
|
|
49
|
+
},
|
|
50
|
+
isSoldOut: {
|
|
51
|
+
true: "",
|
|
52
|
+
false: "",
|
|
53
|
+
},
|
|
54
|
+
showSoldOutBadge: {
|
|
55
|
+
true: "",
|
|
56
|
+
false: "",
|
|
57
|
+
},
|
|
58
|
+
imageSwipeEnabled: {
|
|
59
|
+
true: "",
|
|
60
|
+
false: "",
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
compoundVariants: [
|
|
64
|
+
{
|
|
65
|
+
iconPosition: "top-left",
|
|
66
|
+
badgeHorizontalPosition: ["start", "center"],
|
|
67
|
+
badgeVerticalPosition: "top",
|
|
68
|
+
showSoldOutBadge: false,
|
|
69
|
+
class: "top-10",
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
iconPosition: "top-right",
|
|
73
|
+
badgeHorizontalPosition: ["end", "center"],
|
|
74
|
+
badgeVerticalPosition: "top",
|
|
75
|
+
class: "top-10",
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
iconPosition: "bottom-left",
|
|
79
|
+
badgeHorizontalPosition: ["start", "center"],
|
|
80
|
+
badgeVerticalPosition: "bottom",
|
|
81
|
+
class: "bottom-10",
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
iconPosition: "bottom-right",
|
|
85
|
+
badgeHorizontalPosition: ["end", "center"],
|
|
86
|
+
badgeVerticalPosition: "bottom",
|
|
87
|
+
class: "bottom-10",
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
iconPosition: "bottom-left",
|
|
91
|
+
showSoldOutBadge: true,
|
|
92
|
+
class: "bottom-10",
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
iconPosition: ["bottom-left", "bottom-right"],
|
|
96
|
+
imageSwipeEnabled: true,
|
|
97
|
+
class: "bottom-[18px]",
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
iconPosition: "bottom-left",
|
|
101
|
+
badgeHorizontalPosition: ["start", "center"],
|
|
102
|
+
badgeVerticalPosition: "bottom",
|
|
103
|
+
isSoldOut: false,
|
|
104
|
+
showSoldOutBadge: false,
|
|
105
|
+
imageSwipeEnabled: true,
|
|
106
|
+
class: "bottom-[58px]",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
iconPosition: "bottom-right",
|
|
110
|
+
badgeHorizontalPosition: ["end", "center"],
|
|
111
|
+
badgeVerticalPosition: "bottom",
|
|
112
|
+
showSoldOutBadge: false,
|
|
113
|
+
imageSwipeEnabled: true,
|
|
114
|
+
class: "bottom-[58px]",
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
iconPosition: "bottom-left",
|
|
118
|
+
showSoldOutBadge: true,
|
|
119
|
+
imageSwipeEnabled: true,
|
|
120
|
+
class: "bottom-[58px]",
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
defaultVariants: {
|
|
124
|
+
iconPosition: "below-image-on-right",
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
return cva("absolute ", Object.assign(Object.assign({}, defaultConfig), config));
|
|
128
|
+
}
|
|
129
|
+
export function getProductCardTranslationsFn(pageState, translations) {
|
|
130
|
+
const gridTranslations = pageState.pageViewType === "collection"
|
|
131
|
+
? {
|
|
132
|
+
title: translations["collection-empty-title"],
|
|
133
|
+
description: translations["collection-empty-message"],
|
|
134
|
+
buttonLabel: translations["collection-empty-button"],
|
|
135
|
+
}
|
|
136
|
+
: {
|
|
137
|
+
title: translations["product-search-empty-title"],
|
|
138
|
+
description: translations["product-search-empty-message"],
|
|
139
|
+
buttonLabel: translations["product-search-empty-button"],
|
|
140
|
+
};
|
|
141
|
+
const productCardTranslations = {
|
|
142
|
+
quickAdd: translations["collection-product-quick-add"],
|
|
143
|
+
soldOut: translations["collection-product-sold-out"],
|
|
144
|
+
addToBag: translations["quick-add-add"],
|
|
145
|
+
viewItem: translations["quick-add-view"],
|
|
146
|
+
};
|
|
147
|
+
return { gridTranslations, productCardTranslations };
|
|
148
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"carousel.d.ts","sourceRoot":"","sources":["../../../components/ui/carousel.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,gBAAgB,EAAE,EACvB,KAAK,oBAAoB,EAC1B,MAAM,sBAAsB,CAAA;AAS7B,KAAK,WAAW,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAA;AAC1C,KAAK,qBAAqB,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAA;AAChE,KAAK,eAAe,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAA;AAC/C,KAAK,cAAc,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAA;AAE9C,KAAK,aAAa,GAAG;IACnB,IAAI,CAAC,EAAE,eAAe,CAAA;IACtB,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,WAAW,CAAC,EAAE,YAAY,GAAG,UAAU,CAAA;IACvC,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,CAAC,GAA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MAAM,CAAA;CAClB,CAAA;AAED,QAAA,MAAM,YAAY,iIAuDjB,CAAA;AA8DD,OAAO,EACL,KAAK,WAAW,EAChB,QAAQ,EACR,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,YAAY,GACb,CAAA"}
|
|
@@ -90,6 +90,7 @@ const Carousel = React.forwardRef((_a, ref) => {
|
|
|
90
90
|
.on("reInit", setTweenFactor)
|
|
91
91
|
.on("reInit", tweenScale)
|
|
92
92
|
.on("scroll", tweenScale)
|
|
93
|
+
// @ts-ignore
|
|
93
94
|
.on("slideFocus", tweenScale);
|
|
94
95
|
}, [api, tweenScale]);
|
|
95
96
|
return (_jsx(CarouselContext.Provider, Object.assign({ value: {
|
|
@@ -13,10 +13,10 @@ declare const DrawerTrigger: React.FC<DrawerTriggerProps>;
|
|
|
13
13
|
declare const DrawerPortal: React.FC<DrawerPortalProps>;
|
|
14
14
|
declare const DrawerClose: React.FC<DrawerCloseProps>;
|
|
15
15
|
type DrawerProps = React.ComponentProps<typeof DrawerPrimitive.Root> & {
|
|
16
|
-
containerRef?: HTMLElement
|
|
16
|
+
containerRef?: HTMLElement;
|
|
17
17
|
};
|
|
18
18
|
declare const Drawer: {
|
|
19
|
-
({ shouldScaleBackground,
|
|
19
|
+
({ shouldScaleBackground, ...props }: DrawerProps): import("react/jsx-runtime").JSX.Element;
|
|
20
20
|
displayName: string;
|
|
21
21
|
};
|
|
22
22
|
declare const DrawerOverlay: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
@@ -39,8 +39,6 @@ type DrawerHeaderProps = {
|
|
|
39
39
|
onCloseClick?: (event: React.MouseEvent) => void;
|
|
40
40
|
};
|
|
41
41
|
declare const DrawerHeader: ({ title, iconLeftName, iconRightName, onCloseClick, }: DrawerHeaderProps) => import("react/jsx-runtime").JSX.Element;
|
|
42
|
-
declare const DrawerContent: ({ children }:
|
|
43
|
-
children: React.ReactNode;
|
|
44
|
-
}) => import("react/jsx-runtime").JSX.Element;
|
|
42
|
+
declare const DrawerContent: ({ children, className, ...props }: React.HTMLAttributes<HTMLDivElement>) => import("react/jsx-runtime").JSX.Element;
|
|
45
43
|
export { Drawer, DrawerPortal, DrawerOverlay, DrawerTrigger, DrawerClose, DrawerContentBase, DrawerContent, DrawerFooter, DrawerDescription, DrawerHeader, };
|
|
46
44
|
//# sourceMappingURL=drawer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drawer.d.ts","sourceRoot":"","sources":["../../../components/ui/drawer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,MAAM,IAAI,eAAe,EAAE,MAAM,MAAM,CAAA;AAIhD,KAAK,kBAAkB,GAAG,KAAK,CAAC,wBAAwB,CAAC,QAAQ,CAAC,GAAG;IACnE,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,KAAK,iBAAiB,GAAG;IACvB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B,CAAA;AAED,KAAK,gBAAgB,GAAG,KAAK,CAAC,wBAAwB,CAAC,QAAQ,CAAC,GAAG;IACjE,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,QAAA,MAAM,aAAa,8BAA0D,CAAA;AAG7E,QAAA,MAAM,YAAY,6BAAwD,CAAA;AAG1E,QAAA,MAAM,WAAW,4BAAsD,CAAA;AAGvE,KAAK,WAAW,GAAG,KAAK,CAAC,cAAc,CAAC,OAAO,eAAe,CAAC,IAAI,CAAC,GAAG;IACrE,YAAY,CAAC,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"drawer.d.ts","sourceRoot":"","sources":["../../../components/ui/drawer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,MAAM,IAAI,eAAe,EAAE,MAAM,M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b,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,YAAY,GACb,CAAA"}
|
|
@@ -22,8 +22,8 @@ DrawerPortal.displayName = "DrawerPortal";
|
|
|
22
22
|
const DrawerClose = DrawerPrimitive.Close;
|
|
23
23
|
DrawerClose.displayName = "DrawerClose";
|
|
24
24
|
const Drawer = (_a) => {
|
|
25
|
-
var { shouldScaleBackground
|
|
26
|
-
return (_jsx(DrawerPrimitive.Root, Object.assign({ shouldScaleBackground:
|
|
25
|
+
var { shouldScaleBackground } = _a, props = __rest(_a, ["shouldScaleBackground"]);
|
|
26
|
+
return (_jsx(DrawerPrimitive.Root, Object.assign({ shouldScaleBackground: true }, props, { noBodyStyles: true, disablePreventScroll: true })));
|
|
27
27
|
};
|
|
28
28
|
Drawer.displayName = "Drawer";
|
|
29
29
|
const DrawerOverlay = React.forwardRef((_a, ref) => {
|
|
@@ -33,7 +33,7 @@ const DrawerOverlay = React.forwardRef((_a, ref) => {
|
|
|
33
33
|
});
|
|
34
34
|
DrawerOverlay.displayName = "DrawerOverlay";
|
|
35
35
|
const DrawerContentBase = React.forwardRef((_a, ref) => {
|
|
36
|
-
var { className, children, hideBackdrop = false, backdropHexColor, isSheet = false } = _a, props = __rest(_a, ["className", "children", "hideBackdrop", "backdropHexColor", "isSheet"]);
|
|
36
|
+
var { className, children, hideBackdrop = false, backdropHexColor, isSheet = false, onAnimationEnd } = _a, props = __rest(_a, ["className", "children", "hideBackdrop", "backdropHexColor", "isSheet", "onAnimationEnd"]);
|
|
37
37
|
const styles = isSheet
|
|
38
38
|
? { height: "calc(100vh - 112px)" }
|
|
39
39
|
: { maxHeight: "calc(100vh - 112px)" };
|
|
@@ -47,9 +47,9 @@ const DrawerHeaderBase = (_a) => {
|
|
|
47
47
|
DrawerHeaderBase.displayName = "DrawerHeaderBase";
|
|
48
48
|
const DrawerTitle = React.forwardRef((_a, ref) => {
|
|
49
49
|
var { className } = _a, props = __rest(_a, ["className"]);
|
|
50
|
-
return (_jsx(
|
|
50
|
+
return (_jsx(DrawerPrimitive.Title, Object.assign({ ref: ref, className: cn("text-textColors-primaryColor text-center text-[18px] font-medium leading-[24px] truncate my-0 mx-4", className) }, props)));
|
|
51
51
|
});
|
|
52
|
-
DrawerTitle.displayName =
|
|
52
|
+
DrawerTitle.displayName = DrawerPrimitive.Title.displayName;
|
|
53
53
|
const DrawerFooter = (_a) => {
|
|
54
54
|
var { className } = _a, props = __rest(_a, ["className"]);
|
|
55
55
|
return (_jsx("div", Object.assign({ className: cn("mt-auto flex flex-row gap-2 pb-8 pt-4 pl-4 pr-4 border-t border-coreColors-dividingLines", className) }, props)));
|
|
@@ -63,7 +63,8 @@ DrawerDescription.displayName = "DrawerDescription";
|
|
|
63
63
|
const DrawerHeader = ({ title, iconLeftName, iconRightName, onCloseClick, }) => {
|
|
64
64
|
return (_jsxs(DrawerHeaderBase, Object.assign({ className: "p-4 text-center flex justify-between" }, { children: [iconLeftName ? (_jsx(DrawerClose, Object.assign({ className: "h-6 w-6 p-0", onClick: onCloseClick }, { children: _jsx(Icon, { name: iconLeftName, color: "coreColors-secondaryIcon", className: "h-6 w-6 p-0", size: "md" }) }))) : (_jsx("div", { className: "w-6" })), _jsx(DrawerTitle, { children: title }), iconRightName ? (_jsx(DrawerClose, Object.assign({ className: "h-6 w-6 p-0", onClick: onCloseClick }, { children: _jsx(Icon, { name: iconRightName, color: "coreColors-secondaryIcon", className: "h-6 w-6 p-0", size: "md" }) }))) : (_jsx("div", { className: "w-6" }))] })));
|
|
65
65
|
};
|
|
66
|
-
const DrawerContent = (
|
|
67
|
-
|
|
66
|
+
const DrawerContent = (_a) => {
|
|
67
|
+
var { children, className } = _a, props = __rest(_a, ["children", "className"]);
|
|
68
|
+
return _jsx("div", Object.assign({ className: cn("h-full overflow-scroll", className) }, props, { children: children }));
|
|
68
69
|
};
|
|
69
70
|
export { Drawer, DrawerPortal, DrawerOverlay, DrawerTrigger, DrawerClose, DrawerContentBase, DrawerContent, DrawerFooter, DrawerDescription, DrawerHeader, };
|
|
@@ -14,7 +14,7 @@ import * as React from "react";
|
|
|
14
14
|
import { cva } from "class-variance-authority";
|
|
15
15
|
import { cn, getBorderSidesStyle, getPaddingStyle, } from "../../lib/utils";
|
|
16
16
|
import { Icon } from "./icon";
|
|
17
|
-
import { useTap } from "
|
|
17
|
+
import { useTap } from "./tap";
|
|
18
18
|
import { useMergeRefs } from "../hooks/use-merge-refs";
|
|
19
19
|
const favoriteVariants = cva("flex p-2 gap-2 rounded-[4px]", {
|
|
20
20
|
variants: {
|
|
@@ -168,7 +168,7 @@ export const Image = React.forwardRef((_a, ref) => {
|
|
|
168
168
|
}
|
|
169
169
|
}, [ref]);
|
|
170
170
|
const imgClassName = `opacity-0 transition-opacity duration-500 ease-in-out ${isLoaded ? "opacity-100" : ""}`;
|
|
171
|
-
const wrapperStyle = Object.assign({ aspectRatio: (_b = normalizedProps.aspectRatio) === null || _b === void 0 ? void 0 : _b.replace(":", "/") }, imageWrapperStyles);
|
|
171
|
+
const wrapperStyle = Object.assign({ aspectRatio: (_b = normalizedProps === null || normalizedProps === void 0 ? void 0 : normalizedProps.aspectRatio) === null || _b === void 0 ? void 0 : _b.replace(":", "/") }, imageWrapperStyles);
|
|
172
172
|
const srcSet = generateSrcSet(normalizedProps.src, generateSizes(imageWidths, normalizedProps.aspectRatio, crop), loader, normalizedProps.objectFit === "contain");
|
|
173
173
|
return (_jsxs(_Fragment, { children: [loading === "eager" && (_jsx(ImagePreload, { imgAttributes: {
|
|
174
174
|
srcSet,
|
|
@@ -183,7 +183,7 @@ export const Image = React.forwardRef((_a, ref) => {
|
|
|
183
183
|
// and `sizes` are defined.
|
|
184
184
|
// This bug cannot be reproduced in Chrome or Firefox.
|
|
185
185
|
src: normalizedProps.src, ref: setRefs, style: Object.assign({ objectFit: normalizedProps.objectFit, maxHeight: "100%", height: "100%", width: "100%", borderRadius: `${imageRadius}px` }, passthroughProps.style) }))) : (_jsx("div", { className: "w-full h-full bg-stateColors-skeleton", style: Object.assign({ aspectRatio: aspectRatio && aspectRatio !== "auto"
|
|
186
|
-
? (_c = normalizedProps.aspectRatio) === null || _c === void 0 ? void 0 : _c.replace(":", "/")
|
|
186
|
+
? (_c = normalizedProps === null || normalizedProps === void 0 ? void 0 : normalizedProps.aspectRatio) === null || _c === void 0 ? void 0 : _c.replace(":", "/")
|
|
187
187
|
: "2/3" }, imageWrapperStyles) })) }))] }));
|
|
188
188
|
});
|
|
189
189
|
/**
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
|
+
declare const useTap: (tapThreshold?: number) => {
|
|
3
|
+
onTap: (handler: (event: any) => void) => (event: any) => void;
|
|
4
|
+
isPressed: boolean;
|
|
5
|
+
ref: React.MutableRefObject<null>;
|
|
6
|
+
};
|
|
7
|
+
interface TapProps {
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
declare const Tap: React.FC<TapProps>;
|
|
11
|
+
export { Tap, useTap };
|
|
12
|
+
//# sourceMappingURL=tap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tap.d.ts","sourceRoot":"","sources":["../../../components/ui/tap.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAMZ,SAAS,EACV,MAAM,OAAO,CAAA;AAuFd,QAAA,MAAM,MAAM;6BAuBkC,GAAG,KAAK,IAAI,aACvC,GAAG;;;CAerB,CAAA;AAED,UAAU,QAAQ;IAChB,QAAQ,EAAE,SAAS,CAAA;CACpB;AAED,QAAA,MAAM,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC,QAAQ,CAuC3B,CAAA;AAED,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,CAAA"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import React, { useState, useEffect, useCallback, useRef, } from "react";
|
|
4
|
+
// Shared manager for all instances of the hook
|
|
5
|
+
const tapManager = (() => {
|
|
6
|
+
const elements = new Map();
|
|
7
|
+
let isListening = false;
|
|
8
|
+
const startListening = () => {
|
|
9
|
+
if (isListening)
|
|
10
|
+
return;
|
|
11
|
+
const handleTouchStart = (e) => {
|
|
12
|
+
const touch = e.touches[0];
|
|
13
|
+
elements.forEach((data, el) => {
|
|
14
|
+
if (el.contains(touch.target)) {
|
|
15
|
+
data.touchStarted = true;
|
|
16
|
+
data.touchMoved = false;
|
|
17
|
+
data.startPosition = { x: touch.clientX, y: touch.clientY };
|
|
18
|
+
// Don't set isPressed here, wait to determine if it's a tap or drag
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
const handleTouchMove = (e) => {
|
|
23
|
+
const touch = e.touches[0];
|
|
24
|
+
elements.forEach((data, el) => {
|
|
25
|
+
if (data.touchStarted) {
|
|
26
|
+
const deltaX = Math.abs(touch.clientX - data.startPosition.x);
|
|
27
|
+
const deltaY = Math.abs(touch.clientY - data.startPosition.y);
|
|
28
|
+
if (deltaX > data.tapThreshold || deltaY > data.tapThreshold) {
|
|
29
|
+
data.touchMoved = true;
|
|
30
|
+
data.setIsPressed(false);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
const handleTouchEnd = () => {
|
|
36
|
+
elements.forEach((data) => {
|
|
37
|
+
if (data.touchStarted) {
|
|
38
|
+
data.touchStarted = false;
|
|
39
|
+
if (!data.touchMoved) {
|
|
40
|
+
// It's a tap, set isPressed briefly
|
|
41
|
+
data.setIsPressed(true);
|
|
42
|
+
setTimeout(() => data.setIsPressed(false), 100);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
document.addEventListener("touchstart", (e) => handleTouchStart(e), { passive: true });
|
|
48
|
+
document.addEventListener("touchmove", (e) => handleTouchMove(e), { passive: true });
|
|
49
|
+
document.addEventListener("touchend", () => handleTouchEnd(), {
|
|
50
|
+
passive: true,
|
|
51
|
+
});
|
|
52
|
+
isListening = true;
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
register: (el, data) => {
|
|
56
|
+
elements.set(el, data);
|
|
57
|
+
startListening();
|
|
58
|
+
},
|
|
59
|
+
unregister: (el) => {
|
|
60
|
+
elements.delete(el);
|
|
61
|
+
},
|
|
62
|
+
elements,
|
|
63
|
+
};
|
|
64
|
+
})();
|
|
65
|
+
const useTap = (tapThreshold = 10) => {
|
|
66
|
+
const [isPressed, setIsPressed] = useState(false);
|
|
67
|
+
const elementRef = useRef(null);
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
const element = elementRef.current;
|
|
70
|
+
if (!element)
|
|
71
|
+
return;
|
|
72
|
+
const data = {
|
|
73
|
+
touchStarted: false,
|
|
74
|
+
touchMoved: false,
|
|
75
|
+
startPosition: { x: 0, y: 0 },
|
|
76
|
+
setIsPressed,
|
|
77
|
+
tapThreshold,
|
|
78
|
+
};
|
|
79
|
+
tapManager.register(element, data);
|
|
80
|
+
return () => {
|
|
81
|
+
tapManager.unregister(element);
|
|
82
|
+
};
|
|
83
|
+
}, [tapThreshold]);
|
|
84
|
+
const onTap = useCallback((handler) => {
|
|
85
|
+
return (event) => {
|
|
86
|
+
const data = tapManager.elements.get(elementRef.current);
|
|
87
|
+
if (!data)
|
|
88
|
+
return;
|
|
89
|
+
if (event.type === "touchend" && !data.touchMoved) {
|
|
90
|
+
handler(event);
|
|
91
|
+
}
|
|
92
|
+
else if (event.type === "click" && !data.touchStarted) {
|
|
93
|
+
handler(event);
|
|
94
|
+
setIsPressed(true);
|
|
95
|
+
setTimeout(() => setIsPressed(false), 100);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}, []);
|
|
99
|
+
return { onTap, isPressed, ref: elementRef };
|
|
100
|
+
};
|
|
101
|
+
const Tap = ({ children }) => {
|
|
102
|
+
const { onTap, isPressed, ref } = useTap();
|
|
103
|
+
const child = React.Children.only(children);
|
|
104
|
+
const cloneElement = (element, props) => {
|
|
105
|
+
return React.cloneElement(element, Object.assign(Object.assign({}, props), { onClick: undefined, onTouchEnd: (event) => {
|
|
106
|
+
onTap(() => {
|
|
107
|
+
if (element.props.onTouchEnd) {
|
|
108
|
+
element.props.onTouchEnd(event);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (element.props.onClick) {
|
|
112
|
+
element.props.onClick(event);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
})(event);
|
|
116
|
+
}, style: Object.assign(Object.assign({}, element.props.style), { cursor: "pointer", opacity: isPressed ? 0.7 : 1 }) }));
|
|
117
|
+
};
|
|
118
|
+
const cloneChildren = (children) => {
|
|
119
|
+
return React.Children.map(children, (child) => {
|
|
120
|
+
if (React.isValidElement(child)) {
|
|
121
|
+
return cloneElement(child, { ref });
|
|
122
|
+
}
|
|
123
|
+
return child;
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
return _jsx(_Fragment, { children: cloneChildren(child) });
|
|
127
|
+
};
|
|
128
|
+
export { Tap, useTap };
|