@shopify/shop-minis-react 0.0.30 → 0.0.32

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.
Files changed (36) hide show
  1. package/dist/_virtual/index10.js +2 -2
  2. package/dist/_virtual/index2.js +4 -4
  3. package/dist/_virtual/index3.js +4 -4
  4. package/dist/_virtual/index5.js +2 -3
  5. package/dist/_virtual/index5.js.map +1 -1
  6. package/dist/_virtual/index6.js +3 -2
  7. package/dist/_virtual/index6.js.map +1 -1
  8. package/dist/_virtual/index7.js +2 -2
  9. package/dist/_virtual/index8.js +2 -2
  10. package/dist/_virtual/index9.js +2 -2
  11. package/dist/components/commerce/product-card.js +195 -199
  12. package/dist/components/commerce/product-card.js.map +1 -1
  13. package/dist/components/ui/badge.js +21 -19
  14. package/dist/components/ui/badge.js.map +1 -1
  15. package/dist/hooks/user/useGenerateUserToken.js +12 -0
  16. package/dist/hooks/user/useGenerateUserToken.js.map +1 -0
  17. package/dist/index.js +254 -241
  18. package/dist/index.js.map +1 -1
  19. package/dist/mocks.js +16 -8
  20. package/dist/mocks.js.map +1 -1
  21. package/dist/shop-minis-platform/src/types/user.js +6 -0
  22. package/dist/shop-minis-platform/src/types/user.js.map +1 -0
  23. package/dist/shop-minis-react/node_modules/.pnpm/@radix-ui_react-use-is-hydrated@0.1.0_@types_react@19.1.6_react@19.1.0/node_modules/@radix-ui/react-use-is-hydrated/dist/index.js +1 -1
  24. package/dist/shop-minis-react/node_modules/.pnpm/@videojs_xhr@2.7.0/node_modules/@videojs/xhr/lib/index.js +1 -1
  25. package/dist/shop-minis-react/node_modules/.pnpm/@xmldom_xmldom@0.8.10/node_modules/@xmldom/xmldom/lib/index.js +1 -1
  26. package/dist/shop-minis-react/node_modules/.pnpm/color-string@1.9.1/node_modules/color-string/index.js +1 -1
  27. package/dist/shop-minis-react/node_modules/.pnpm/mpd-parser@1.3.1/node_modules/mpd-parser/dist/mpd-parser.es.js +1 -1
  28. package/dist/shop-minis-react/node_modules/.pnpm/use-sync-external-store@1.5.0_react@19.1.0/node_modules/use-sync-external-store/shim/index.js +1 -1
  29. package/dist/shop-minis-react/node_modules/.pnpm/video.js@8.23.3/node_modules/video.js/dist/video.es.js +1 -1
  30. package/dist/utils/colors.js +1 -1
  31. package/package.json +2 -2
  32. package/src/components/commerce/product-card.tsx +211 -182
  33. package/src/components/ui/badge.tsx +7 -9
  34. package/src/hooks/index.ts +1 -0
  35. package/src/hooks/user/useGenerateUserToken.ts +25 -0
  36. package/src/mocks.ts +11 -4
@@ -1,5 +1,5 @@
1
- var r = {};
1
+ var e = { exports: {} };
2
2
  export {
3
- r as __exports
3
+ e as __module
4
4
  };
5
5
  //# sourceMappingURL=index10.js.map
@@ -1,8 +1,8 @@
1
1
  import { getDefaultExportFromCjs as r } from "./_commonjsHelpers.js";
2
- import { __require as o } from "../shop-minis-react/node_modules/.pnpm/color@4.2.3/node_modules/color/index.js";
3
- var t = /* @__PURE__ */ o();
4
- const l = /* @__PURE__ */ r(t);
2
+ import { __require as o } from "../shop-minis-react/node_modules/.pnpm/@videojs_xhr@2.7.0/node_modules/@videojs/xhr/lib/index.js";
3
+ var t = o();
4
+ const a = /* @__PURE__ */ r(t);
5
5
  export {
6
- l as default
6
+ a as default
7
7
  };
8
8
  //# sourceMappingURL=index2.js.map
@@ -1,8 +1,8 @@
1
1
  import { getDefaultExportFromCjs as r } from "./_commonjsHelpers.js";
2
- import { __require as o } from "../shop-minis-react/node_modules/.pnpm/@videojs_xhr@2.7.0/node_modules/@videojs/xhr/lib/index.js";
3
- var t = o();
4
- const a = /* @__PURE__ */ r(t);
2
+ import { __require as o } from "../shop-minis-react/node_modules/.pnpm/color@4.2.3/node_modules/color/index.js";
3
+ var t = /* @__PURE__ */ o();
4
+ const l = /* @__PURE__ */ r(t);
5
5
  export {
6
- a as default
6
+ l as default
7
7
  };
8
8
  //# sourceMappingURL=index3.js.map
@@ -1,6 +1,5 @@
1
- import { __require as r } from "../shop-minis-react/node_modules/.pnpm/use-sync-external-store@1.5.0_react@19.1.0/node_modules/use-sync-external-store/shim/index.js";
2
- var i = r();
1
+ var e = { exports: {} };
3
2
  export {
4
- i as s
3
+ e as __module
5
4
  };
6
5
  //# sourceMappingURL=index5.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index5.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
1
+ {"version":3,"file":"index5.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -1,5 +1,6 @@
1
- var e = { exports: {} };
1
+ import { __require as r } from "../shop-minis-react/node_modules/.pnpm/@xmldom_xmldom@0.8.10/node_modules/@xmldom/xmldom/lib/index.js";
2
+ var i = r();
2
3
  export {
3
- e as __module
4
+ i as l
4
5
  };
5
6
  //# sourceMappingURL=index6.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index6.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
1
+ {"version":3,"file":"index6.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -1,6 +1,6 @@
1
- import { __require as r } from "../shop-minis-react/node_modules/.pnpm/@xmldom_xmldom@0.8.10/node_modules/@xmldom/xmldom/lib/index.js";
1
+ import { __require as r } from "../shop-minis-react/node_modules/.pnpm/use-sync-external-store@1.5.0_react@19.1.0/node_modules/use-sync-external-store/shim/index.js";
2
2
  var i = r();
3
3
  export {
4
- i as l
4
+ i as s
5
5
  };
6
6
  //# sourceMappingURL=index7.js.map
@@ -1,5 +1,5 @@
1
- var o = { exports: {} };
1
+ var r = {};
2
2
  export {
3
- o as __module
3
+ r as __exports
4
4
  };
5
5
  //# sourceMappingURL=index8.js.map
@@ -1,5 +1,5 @@
1
- var e = { exports: {} };
1
+ var o = { exports: {} };
2
2
  export {
3
- e as __module
3
+ o as __module
4
4
  };
5
5
  //# sourceMappingURL=index9.js.map
@@ -1,60 +1,42 @@
1
- import { jsxs as y, jsx as e } from "react/jsx-runtime";
2
- import * as g from "react";
3
- import { useCallback as L } from "react";
4
- import { cva as q } from "../../shop-minis-react/node_modules/.pnpm/class-variance-authority@0.7.1/node_modules/class-variance-authority/dist/index.js";
5
- import { useShopNavigation as E } from "../../hooks/navigation/useShopNavigation.js";
6
- import { useSavedProductsActions as M } from "../../hooks/user/useSavedProductsActions.js";
7
- import { formatMoney as U } from "../../lib/formatMoney.js";
8
- import { cn as c } from "../../lib/utils.js";
9
- import { FavoriteButton as V } from "../atoms/favorite-button.js";
10
- import { ProductVariantPrice as D } from "../atoms/product-variant-price.js";
11
- import { ThumbhashImage as G } from "../atoms/thumbhash-image.js";
12
- import { Touchable as H } from "../atoms/touchable.js";
13
- import { Badge as J } from "../ui/badge.js";
14
- import { Root as K } from "../../shop-minis-react/node_modules/.pnpm/@radix-ui_react-slot@1.2.3_@types_react@19.1.6_react@19.1.0/node_modules/@radix-ui/react-slot/dist/index.js";
15
- const Q = q(
16
- "relative w-full overflow-hidden rounded-xl border border-gray-200",
17
- {
18
- variants: {
19
- variant: {
20
- default: "",
21
- priceOverlay: "",
22
- compact: ""
23
- },
24
- touchable: {
25
- true: "cursor-pointer",
26
- false: ""
27
- }
28
- },
29
- defaultVariants: {
30
- variant: "default",
31
- touchable: !0
32
- }
33
- }
34
- );
35
- function W({
36
- className: o,
37
- variant: t,
38
- touchable: r = !0,
39
- asChild: a = !1,
40
- onPress: i,
41
- ...d
1
+ import { jsx as o, jsxs as v } from "react/jsx-runtime";
2
+ import * as N from "react";
3
+ import { useState as F, useCallback as C, useMemo as A, useContext as k } from "react";
4
+ import { useShopNavigation as T } from "../../hooks/navigation/useShopNavigation.js";
5
+ import { useSavedProductsActions as V } from "../../hooks/user/useSavedProductsActions.js";
6
+ import { formatMoney as j } from "../../lib/formatMoney.js";
7
+ import { cn as s } from "../../lib/utils.js";
8
+ import { FavoriteButton as B } from "../atoms/favorite-button.js";
9
+ import { ProductVariantPrice as E } from "../atoms/product-variant-price.js";
10
+ import { ThumbhashImage as O } from "../atoms/thumbhash-image.js";
11
+ import { Touchable as S } from "../atoms/touchable.js";
12
+ import { Badge as z } from "../ui/badge.js";
13
+ const I = N.createContext(void 0);
14
+ function u() {
15
+ const t = k(I);
16
+ if (!t)
17
+ throw new Error(
18
+ "ProductCard components must be used within a ProductCard provider"
19
+ );
20
+ return t;
21
+ }
22
+ function L({
23
+ className: t,
24
+ ...e
42
25
  }) {
43
- const n = /* @__PURE__ */ e(
44
- a ? K : "div",
26
+ const { touchable: r, onClick: a } = u(), n = /* @__PURE__ */ o(
27
+ "div",
45
28
  {
46
- className: c(
47
- Q({ variant: t, touchable: r }),
48
- "border-0",
49
- o
29
+ className: s(
30
+ "relative w-full overflow-hidden rounded-xl border-0",
31
+ t
50
32
  ),
51
- ...d
33
+ ...e
52
34
  }
53
35
  );
54
- return r && i ? /* @__PURE__ */ e(
55
- H,
36
+ return r && a ? /* @__PURE__ */ o(
37
+ S,
56
38
  {
57
- onClick: i,
39
+ onClick: a,
58
40
  whileTap: { opacity: 0.7 },
59
41
  transition: {
60
42
  opacity: { type: "tween", duration: 0.08, ease: "easeInOut" }
@@ -63,218 +45,232 @@ function W({
63
45
  }
64
46
  ) : n;
65
47
  }
66
- function X({
67
- className: o,
68
- variant: t = "default",
69
- ...r
48
+ function M({
49
+ className: t,
50
+ ...e
70
51
  }) {
71
- return /* @__PURE__ */ e(
52
+ const { variant: r } = u();
53
+ return /* @__PURE__ */ o(
72
54
  "div",
73
55
  {
74
56
  "data-slot": "product-card-image-container",
75
- className: c(
57
+ className: s(
76
58
  // Ensure the product image is stretched to the full size of the container (can't use width/height: 100% because of flex)
77
59
  "flex justify-stretch items-stretch",
78
60
  "relative overflow-hidden rounded-xl border border-gray-200",
79
61
  "w-full aspect-square",
80
- t === "compact" ? "min-h-[104px]" : "min-h-[134px]",
81
- o
62
+ r === "compact" ? "min-h-[104px]" : "min-h-[134px]",
63
+ t
82
64
  ),
83
- ...r
65
+ ...e
84
66
  }
85
67
  );
86
68
  }
87
- function Y({
88
- className: o,
89
- src: t,
90
- alt: r,
91
- aspectRatio: a,
92
- thumbhash: i,
93
- ...d
94
- }) {
95
- const s = L(
96
- (n) => i ? /* @__PURE__ */ e(
97
- G,
69
+ function R({ className: t, ...e }) {
70
+ const { product: r, selectedProductVariant: a } = u(), n = a?.image || r.featuredImage, i = n?.url, d = n?.altText || r.title, c = r.featuredImage?.thumbhash, p = C(
71
+ (l) => c ? /* @__PURE__ */ o(
72
+ O,
98
73
  {
99
74
  "data-slot": "product-card-image",
100
- src: n,
101
- alt: r,
102
- aspectRatio: a,
103
- thumbhash: i,
104
- className: c("w-full h-full object-cover", o),
105
- ...d
75
+ src: l,
76
+ alt: d,
77
+ aspectRatio: 1,
78
+ thumbhash: c,
79
+ className: s("w-full h-full object-cover", t),
80
+ ...e
106
81
  }
107
- ) : /* @__PURE__ */ e(
82
+ ) : /* @__PURE__ */ o(
108
83
  "img",
109
84
  {
110
85
  "data-slot": "product-card-image",
111
- src: n,
112
- alt: r,
113
- className: c("w-full h-full", o),
114
- ...d
86
+ src: l,
87
+ alt: d,
88
+ className: s("w-full h-full", t),
89
+ ...e
115
90
  }
116
91
  ),
117
- [r, a, o, d, i]
92
+ [d, t, e, c]
118
93
  );
119
- return /* @__PURE__ */ e("div", { className: "bg-gray-100 flex items-center justify-center w-full h-full", children: t ? s(t) : /* @__PURE__ */ e("div", { className: "text-gray-400 text-sm w-full text-center", children: "No Image" }) });
94
+ return /* @__PURE__ */ o("div", { className: "bg-gray-100 flex items-center justify-center w-full h-full", children: i ? p(i) : /* @__PURE__ */ o("div", { className: "text-gray-400 text-sm w-full text-center", children: "No Image" }) });
120
95
  }
121
- function k({
122
- className: o,
123
- position: t = "bottom-left",
124
- children: r,
125
- ...a
96
+ function w({
97
+ className: t,
98
+ position: e = "bottom-left",
99
+ variant: r,
100
+ children: a,
101
+ ...n
126
102
  }) {
127
- return /* @__PURE__ */ e(
103
+ const { badgeText: i, badgeVariant: d } = u(), c = a || i;
104
+ return c ? /* @__PURE__ */ o(
128
105
  "div",
129
106
  {
130
- className: c(
107
+ className: s(
131
108
  "absolute z-10",
132
- t === "top-left" ? "top-3 left-3" : "bottom-2 left-2"
109
+ e === "top-left" ? "top-3 left-3" : "bottom-2 left-2"
133
110
  ),
134
- children: /* @__PURE__ */ e(
135
- J,
111
+ children: /* @__PURE__ */ o(
112
+ z,
136
113
  {
137
- className: c("bg-black/50 text-white rounded", o),
138
- ...a,
139
- children: r
114
+ variant: r ?? d ?? "none",
115
+ className: s(
116
+ !d && !r && "bg-black/50 text-white border-transparent",
117
+ "rounded",
118
+ t
119
+ ),
120
+ ...n,
121
+ children: c
140
122
  }
141
123
  )
142
124
  }
143
- );
125
+ ) : null;
144
126
  }
145
- function Z({
146
- className: o,
147
- onPress: t,
148
- filled: r = !1,
149
- ...a
127
+ function q({
128
+ className: t,
129
+ ...e
150
130
  }) {
151
- return /* @__PURE__ */ e("div", { className: c("absolute bottom-3 right-3 z-10", o), ...a, children: /* @__PURE__ */ e(V, { onClick: t, filled: r }) });
131
+ const { isFavorited: r, onFavoriteToggle: a } = u();
132
+ return /* @__PURE__ */ o("div", { className: s("absolute bottom-3 right-3 z-10", t), ...e, children: /* @__PURE__ */ o(B, { onClick: a, filled: r }) });
152
133
  }
153
- function _({
154
- className: o,
155
- variant: t = "default",
156
- ...r
157
- }) {
158
- return t !== "default" ? null : /* @__PURE__ */ e(
134
+ function D({ className: t, ...e }) {
135
+ const { variant: r } = u();
136
+ return r !== "default" ? null : /* @__PURE__ */ o(
159
137
  "div",
160
138
  {
161
139
  "data-slot": "product-card-info",
162
- className: c("px-1 pt-2 pb-0 space-y-1", o),
163
- ...r
140
+ className: s("px-1 pt-2 pb-0 space-y-1", t),
141
+ ...e
164
142
  }
165
143
  );
166
144
  }
167
- function $({
168
- className: o,
169
- children: t,
145
+ function G({
146
+ className: t,
147
+ children: e,
170
148
  ...r
171
149
  }) {
172
- return /* @__PURE__ */ e(
150
+ const { product: a } = u();
151
+ return /* @__PURE__ */ o(
173
152
  "h3",
174
153
  {
175
154
  "data-slot": "product-card-title",
176
- className: c(
155
+ className: s(
177
156
  "text-sm font-medium leading-tight text-gray-900",
178
157
  "truncate overflow-hidden whitespace-nowrap text-ellipsis",
179
- o
158
+ t
180
159
  ),
181
160
  ...r,
182
- children: t
161
+ children: e || a.title
162
+ }
163
+ );
164
+ }
165
+ function H({ className: t }) {
166
+ const { product: e, selectedProductVariant: r } = u(), a = r?.price || e?.price, n = r?.compareAtPrice || e?.compareAtPrice;
167
+ return /* @__PURE__ */ o(
168
+ E,
169
+ {
170
+ amount: a?.amount || "",
171
+ currencyCode: a?.currencyCode || "",
172
+ compareAtPriceAmount: n?.amount,
173
+ compareAtPriceCurrencyCode: n?.currencyCode,
174
+ className: t
183
175
  }
184
176
  );
185
177
  }
186
- function pt({
187
- product: o,
188
- selectedProductVariant: t,
178
+ function J() {
179
+ const { product: t, selectedProductVariant: e, variant: r } = u();
180
+ if (r !== "priceOverlay") return null;
181
+ const a = e?.price || t.price, n = a?.currencyCode, i = a?.amount;
182
+ return !n || !i ? null : /* @__PURE__ */ o(w, { position: "top-left", children: j(i, n) });
183
+ }
184
+ function ot({
185
+ product: t,
186
+ selectedProductVariant: e,
189
187
  variant: r = "default",
190
188
  touchable: a = !0,
191
- badgeText: i,
192
- badgeVariant: d = "secondary",
193
- onFavoriteToggled: s
189
+ badgeText: n,
190
+ badgeVariant: i,
191
+ onProductClick: d,
192
+ onFavoriteToggled: c,
193
+ children: p
194
194
  }) {
195
- const { navigateToProduct: n } = E(), { saveProduct: C, unsaveProduct: b } = M(), {
196
- id: l,
197
- title: x,
198
- featuredImage: I,
199
- price: j,
200
- compareAtPrice: S,
201
- isFavorited: B,
202
- defaultVariantId: m,
203
- shop: f
204
- } = o, P = t?.image || I, w = t?.price || j, N = t?.compareAtPrice || S, [p, A] = g.useState(B), h = w?.currencyCode, v = w?.amount, F = P?.url, T = P?.altText || x, O = N?.amount, R = g.useCallback(() => {
205
- a && n({
206
- productId: l
207
- });
208
- }, [n, l, a]), z = g.useCallback(async () => {
209
- const u = p;
210
- A(!u), s?.(!u);
195
+ const { navigateToProduct: l } = T(), { saveProduct: h, unsaveProduct: g } = V(), [f, P] = F(t.isFavorited), y = C(() => {
196
+ a && (d?.(), l({
197
+ productId: t.id
198
+ }));
199
+ }, [l, t.id, a, d]), x = C(async () => {
200
+ const m = f;
201
+ P(!m), c?.(!m);
211
202
  try {
212
- u ? await b({
213
- productId: l,
214
- shopId: f.id,
215
- productVariantId: t?.id || m
216
- }) : await C({
217
- productId: l,
218
- shopId: f.id,
219
- productVariantId: t?.id || m
203
+ m ? await g({
204
+ productId: t.id,
205
+ shopId: t.shop.id,
206
+ productVariantId: e?.id || t.defaultVariantId
207
+ }) : await h({
208
+ productId: t.id,
209
+ shopId: t.shop.id,
210
+ productVariantId: e?.id || t.defaultVariantId
220
211
  });
221
212
  } catch {
222
- A(u), s?.(u);
213
+ P(m), c?.(m);
223
214
  }
224
215
  }, [
225
- p,
226
- l,
227
- f.id,
228
- t?.id,
229
- m,
230
- C,
231
- b,
232
- s
233
- ]);
234
- return /* @__PURE__ */ y(
235
- W,
236
- {
216
+ f,
217
+ t.id,
218
+ t.shop.id,
219
+ t.defaultVariantId,
220
+ e?.id,
221
+ h,
222
+ g,
223
+ c
224
+ ]), b = A(
225
+ () => ({
226
+ // Core data
227
+ product: t,
228
+ selectedProductVariant: e,
229
+ // UI configuration
237
230
  variant: r,
238
231
  touchable: a,
239
- onPress: R,
240
- children: [
241
- /* @__PURE__ */ y(X, { variant: r, children: [
242
- /* @__PURE__ */ e(
243
- Y,
244
- {
245
- src: F,
246
- alt: T,
247
- aspectRatio: 1,
248
- thumbhash: I?.thumbhash ?? void 0
249
- }
250
- ),
251
- r === "priceOverlay" && h && v && /* @__PURE__ */ e(k, { position: "top-left", children: U(v, h) }),
252
- i && /* @__PURE__ */ e(k, { position: "bottom-left", variant: d, children: i }),
253
- /* @__PURE__ */ e(
254
- Z,
255
- {
256
- filled: p,
257
- onPress: z
258
- }
259
- )
260
- ] }),
261
- /* @__PURE__ */ y(_, { variant: r, children: [
262
- /* @__PURE__ */ e($, { children: x }),
263
- /* @__PURE__ */ e(
264
- D,
265
- {
266
- amount: v,
267
- currencyCode: h,
268
- compareAtPriceAmount: O,
269
- compareAtPriceCurrencyCode: N?.currencyCode
270
- }
271
- )
272
- ] })
273
- ]
274
- }
232
+ badgeText: n,
233
+ badgeVariant: i,
234
+ // State
235
+ isFavorited: f,
236
+ // Actions
237
+ onClick: y,
238
+ onFavoriteToggle: x
239
+ }),
240
+ [
241
+ t,
242
+ e,
243
+ r,
244
+ a,
245
+ n,
246
+ i,
247
+ f,
248
+ y,
249
+ x
250
+ ]
275
251
  );
252
+ return /* @__PURE__ */ o(I.Provider, { value: b, children: p ?? /* @__PURE__ */ v(L, { children: [
253
+ /* @__PURE__ */ v(M, { children: [
254
+ /* @__PURE__ */ o(R, {}),
255
+ r === "priceOverlay" && /* @__PURE__ */ o(J, {}),
256
+ /* @__PURE__ */ o(w, {}),
257
+ /* @__PURE__ */ o(q, {})
258
+ ] }),
259
+ r === "default" && /* @__PURE__ */ v(D, { children: [
260
+ /* @__PURE__ */ o(G, {}),
261
+ /* @__PURE__ */ o(H, {})
262
+ ] })
263
+ ] }) });
276
264
  }
277
265
  export {
278
- pt as ProductCard
266
+ ot as ProductCard,
267
+ w as ProductCardBadge,
268
+ L as ProductCardContainer,
269
+ q as ProductCardFavoriteButton,
270
+ R as ProductCardImage,
271
+ M as ProductCardImageContainer,
272
+ D as ProductCardInfo,
273
+ H as ProductCardPrice,
274
+ G as ProductCardTitle
279
275
  };
280
276
  //# sourceMappingURL=product-card.js.map