@shopify/shop-minis-react 0.0.0-snapshot.20251216112959 → 0.0.0-snapshot.20251217193626

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 (80) hide show
  1. package/dist/_virtual/index4.js +2 -2
  2. package/dist/_virtual/index5.js +3 -2
  3. package/dist/_virtual/index5.js.map +1 -1
  4. package/dist/_virtual/index6.js +2 -3
  5. package/dist/_virtual/index6.js.map +1 -1
  6. package/dist/components/atoms/alert-dialog.js.map +1 -1
  7. package/dist/components/atoms/button.js.map +1 -1
  8. package/dist/components/atoms/icon-button.js.map +1 -1
  9. package/dist/components/atoms/image.js +65 -51
  10. package/dist/components/atoms/image.js.map +1 -1
  11. package/dist/components/atoms/list.js.map +1 -1
  12. package/dist/components/atoms/product-variant-price.js +1 -1
  13. package/dist/components/atoms/product-variant-price.js.map +1 -1
  14. package/dist/components/atoms/text-input.js.map +1 -1
  15. package/dist/components/atoms/touchable.js.map +1 -1
  16. package/dist/components/atoms/video-player.js +1 -1
  17. package/dist/components/atoms/video-player.js.map +1 -1
  18. package/dist/components/commerce/add-to-cart.js.map +1 -1
  19. package/dist/components/commerce/buy-now.js.map +1 -1
  20. package/dist/components/commerce/favorite-button.js +1 -4
  21. package/dist/components/commerce/favorite-button.js.map +1 -1
  22. package/dist/components/commerce/merchant-card.js.map +1 -1
  23. package/dist/components/commerce/product-card.js +1 -1
  24. package/dist/components/commerce/product-card.js.map +1 -1
  25. package/dist/components/commerce/product-link.js +1 -1
  26. package/dist/components/commerce/product-link.js.map +1 -1
  27. package/dist/components/commerce/quantity-selector.js.map +1 -1
  28. package/dist/components/content/image-content-wrapper.js.map +1 -1
  29. package/dist/components/navigation/minis-router.js.map +1 -1
  30. package/dist/components/navigation/transition-link.js.map +1 -1
  31. package/dist/components/ui/alert.js.map +1 -1
  32. package/dist/components/ui/badge.js.map +1 -1
  33. package/dist/components/ui/input.js.map +1 -1
  34. package/dist/hooks/storage/useImageUpload.js +32 -24
  35. package/dist/hooks/storage/useImageUpload.js.map +1 -1
  36. package/dist/index.js +92 -88
  37. package/dist/index.js.map +1 -1
  38. package/dist/mocks.js +70 -50
  39. package/dist/mocks.js.map +1 -1
  40. package/dist/shop-minis-react/node_modules/.pnpm/@videojs_xhr@2.7.0/node_modules/@videojs/xhr/lib/index.js +1 -1
  41. package/dist/shop-minis-react/node_modules/.pnpm/mpd-parser@1.3.1/node_modules/mpd-parser/dist/mpd-parser.es.js +1 -1
  42. package/dist/shop-minis-react/node_modules/.pnpm/querystringify@2.2.0/node_modules/querystringify/index.js +1 -1
  43. package/dist/utils/formatMoney.js.map +1 -0
  44. package/dist/utils/image.js +44 -24
  45. package/dist/utils/image.js.map +1 -1
  46. package/eslint/rules/validate-manifest.cjs +91 -41
  47. package/package.json +2 -2
  48. package/src/components/atoms/alert-dialog.tsx +3 -3
  49. package/src/components/atoms/button.tsx +22 -0
  50. package/src/components/atoms/icon-button.tsx +16 -8
  51. package/src/components/atoms/image.test.tsx +27 -13
  52. package/src/components/atoms/image.tsx +41 -8
  53. package/src/components/atoms/list.tsx +25 -2
  54. package/src/components/atoms/product-variant-price.test.tsx +1 -1
  55. package/src/components/atoms/product-variant-price.tsx +1 -1
  56. package/src/components/atoms/text-input.tsx +3 -1
  57. package/src/components/atoms/touchable.tsx +15 -4
  58. package/src/components/atoms/video-player.tsx +16 -6
  59. package/src/components/commerce/add-to-cart.tsx +7 -11
  60. package/src/components/commerce/buy-now.tsx +7 -10
  61. package/src/components/commerce/favorite-button.tsx +6 -5
  62. package/src/components/commerce/merchant-card.tsx +4 -0
  63. package/src/components/commerce/product-card.test.tsx +1 -1
  64. package/src/components/commerce/product-card.tsx +1 -1
  65. package/src/components/commerce/product-link.test.tsx +1 -1
  66. package/src/components/commerce/product-link.tsx +16 -1
  67. package/src/components/commerce/quantity-selector.tsx +6 -1
  68. package/src/components/content/image-content-wrapper.tsx +16 -1
  69. package/src/components/navigation/minis-router.tsx +2 -2
  70. package/src/components/navigation/transition-link.tsx +11 -1
  71. package/src/components/ui/alert.tsx +7 -0
  72. package/src/components/ui/badge.tsx +9 -0
  73. package/src/components/ui/input.tsx +15 -0
  74. package/src/hooks/storage/useImageUpload.ts +13 -0
  75. package/src/mocks.ts +48 -19
  76. package/src/utils/image.ts +38 -0
  77. package/src/utils/index.ts +1 -0
  78. package/dist/lib/formatMoney.js.map +0 -1
  79. /package/dist/{lib → utils}/formatMoney.js +0 -0
  80. /package/src/{lib → utils}/formatMoney.ts +0 -0
package/src/mocks.ts CHANGED
@@ -6,28 +6,50 @@ import {
6
6
  } from '@shopify/shop-minis-platform'
7
7
  import {ShopActions} from '@shopify/shop-minis-platform/actions'
8
8
 
9
+ const SAMPLE_IMAGE_NAMES = [
10
+ 'garnished.jpeg',
11
+ 'bath.jpeg',
12
+ 'teapot.jpg',
13
+ 'shoes.jpeg',
14
+ ]
15
+
16
+ // Simple hash function to get a deterministic index from a string
17
+ const hashString = (str: string): number => {
18
+ let hash = 0
19
+ for (let i = 0; i < str.length; i++) {
20
+ hash = (hash << 5) - hash + str.charCodeAt(i)
21
+ hash |= 0
22
+ }
23
+ return Math.abs(hash)
24
+ }
25
+
9
26
  // Helper functions for common data structures
10
27
  export const createProduct = (
11
28
  id: string,
12
29
  title: string,
13
30
  price = '99.99',
14
31
  compareAtPrice?: string
15
- ): Product => ({
16
- id,
17
- title,
18
- price: {amount: price, currencyCode: 'USD'},
19
- ...(compareAtPrice && {
20
- compareAtPrice: {amount: compareAtPrice, currencyCode: 'USD'},
21
- }),
22
- reviewAnalytics: {averageRating: 4.5, reviewCount: 10},
23
- shop: createShop('shop1', 'Mock Shop'),
24
- defaultVariantId: `variant-${id}`,
25
- isFavorited: false,
26
- featuredImage: {
27
- url: `https://cdn.shopify.com/static/sample-images/teapot.jpg`,
28
- altText: title,
29
- },
30
- })
32
+ ): Product => {
33
+ const imageIndex = hashString(id) % SAMPLE_IMAGE_NAMES.length
34
+ const imageName = SAMPLE_IMAGE_NAMES[imageIndex]
35
+
36
+ return {
37
+ id,
38
+ title,
39
+ price: {amount: price, currencyCode: 'USD'},
40
+ ...(compareAtPrice && {
41
+ compareAtPrice: {amount: compareAtPrice, currencyCode: 'USD'},
42
+ }),
43
+ reviewAnalytics: {averageRating: 4.5, reviewCount: 10},
44
+ shop: createShop('shop1', 'Mock Shop'),
45
+ defaultVariantId: `variant-${id}`,
46
+ isFavorited: false,
47
+ featuredImage: {
48
+ url: `https://cdn.shopify.com/static/sample-images/${imageName}`,
49
+ altText: title,
50
+ },
51
+ }
52
+ }
31
53
 
32
54
  export const createShop = (
33
55
  id: string,
@@ -202,7 +224,11 @@ function makeMockMethod<K extends keyof ShopActions>(
202
224
  ): ShopActions[K] {
203
225
  return ((params: Parameters<ShopActions[K]>[0]) => {
204
226
  logMockAction(String(key), params)
205
- return Promise.resolve({ok: true as const, data: result})
227
+ return Promise.resolve({
228
+ ok: true as const,
229
+ data: result,
230
+ mocked: true,
231
+ })
206
232
  }) as ShopActions[K]
207
233
  }
208
234
 
@@ -249,6 +275,7 @@ export function makeMockActions(): ShopActions {
249
275
  navigateToOrder: undefined,
250
276
  navigateToCheckout: undefined,
251
277
  createImageUploadLink: {
278
+ // This action is mocked in the actual hook. See `useImageUpload` for more details.
252
279
  targets: [
253
280
  {
254
281
  url: 'https://example.com/upload',
@@ -262,7 +289,9 @@ export function makeMockActions(): ShopActions {
262
289
  {
263
290
  id: 'file-123',
264
291
  fileStatus: 'READY',
265
- image: {url: 'https://example.com/image.jpg'},
292
+ image: {
293
+ url: 'https://example.com/image.jpg',
294
+ },
266
295
  },
267
296
  ],
268
297
  },
@@ -556,7 +585,7 @@ export const injectMocks = ({force}: {force?: boolean} = {}) => {
556
585
  window.minisSDK = makeMockActions()
557
586
  window.minisParams = {
558
587
  handle: 'mock-handle',
559
- initialUrl: '/mock-initial-url',
588
+ initialUrl: '/',
560
589
  platform: 'web',
561
590
  }
562
591
  }
@@ -18,6 +18,44 @@ export function getThumbhashDataURL(thumbhash?: string): string | undefined {
18
18
  }
19
19
  }
20
20
 
21
+ /**
22
+ * Converts a data URL to a Blob
23
+ * @param dataURL The data URL to convert
24
+ * @returns A Blob object
25
+ */
26
+ export function dataURLToBlob(dataURL: string): Blob {
27
+ const [header, base64Data] = dataURL.split(',')
28
+ const mimeMatch = header.match(/:(.*?);/)
29
+ const mime = mimeMatch ? mimeMatch[1] : 'image/png'
30
+ const binary = atob(base64Data)
31
+ const array = new Uint8Array(binary.length)
32
+ for (let i = 0; i < binary.length; i++) {
33
+ array[i] = binary.charCodeAt(i)
34
+ }
35
+ return new Blob([array], {type: mime})
36
+ }
37
+
38
+ /**
39
+ * Converts a thumbhash string to a blob URL for use as an image placeholder
40
+ * This is useful when CSP restrictions prevent data URLs
41
+ * @param thumbhash Base64 encoded thumbhash string
42
+ * @returns Blob URL that can be used as image source or undefined if conversion fails
43
+ */
44
+ export function getThumbhashBlobURL(thumbhash?: string): string | undefined {
45
+ if (!thumbhash) return
46
+
47
+ try {
48
+ const dataURL = getThumbhashDataURL(thumbhash)
49
+ if (!dataURL) return
50
+
51
+ const blob = dataURLToBlob(dataURL)
52
+ return URL.createObjectURL(blob)
53
+ } catch (error) {
54
+ console.warn('Failed to create thumbhash blob URL', error)
55
+ return undefined
56
+ }
57
+ }
58
+
21
59
  /** Converts a file to a data URI
22
60
  * @param file The file to convert
23
61
  * @returns A promise that resolves to the data URI string
@@ -2,3 +2,4 @@ export * from './errors'
2
2
  export * from './merchant-card'
3
3
  export * from './parseUrl'
4
4
  export * from './image'
5
+ export * from './formatMoney'
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatMoney.js","sources":["../../src/lib/formatMoney.ts"],"sourcesContent":["/**\n * Formats money amount with appropriate currency symbol\n * Uses browser's Intl.NumberFormat for consistent currency formatting\n */\nexport function formatMoney(amount: string, currencyCode: string): string {\n try {\n // Use en-US specifically for USD to get $ instead of US$\n // For other currencies, use browser locale but fallback to en-US\n const locale =\n currencyCode === 'USD' ? 'en-US' : navigator.language || 'en-US'\n\n return new Intl.NumberFormat(locale, {\n style: 'currency',\n currency: currencyCode,\n }).format(Number(amount))\n } catch (error) {\n // Fallback if currency code is invalid or not supported\n console.warn(`Invalid currency code: ${currencyCode}`, error)\n return `${currencyCode} ${amount}`\n }\n}\n"],"names":["formatMoney","amount","currencyCode","locale","error"],"mappings":"AAIgB,SAAAA,EAAYC,GAAgBC,GAA8B;AACpE,MAAA;AAGF,UAAMC,IACJD,MAAiB,QAAQ,UAAU,UAAU,YAAY;AAEpD,WAAA,IAAI,KAAK,aAAaC,GAAQ;AAAA,MACnC,OAAO;AAAA,MACP,UAAUD;AAAA,IACX,CAAA,EAAE,OAAO,OAAOD,CAAM,CAAC;AAAA,WACjBG,GAAO;AAEd,mBAAQ,KAAK,0BAA0BF,CAAY,IAAIE,CAAK,GACrD,GAAGF,CAAY,IAAID,CAAM;AAAA,EAAA;AAEpC;"}
File without changes
File without changes