@shopify/shop-minis-react 0.0.19 → 0.0.21

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 (60) hide show
  1. package/dist/components/MinisContainer.js +13 -11
  2. package/dist/components/MinisContainer.js.map +1 -1
  3. package/dist/components/atoms/list.js +52 -0
  4. package/dist/components/atoms/list.js.map +1 -0
  5. package/dist/components/atoms/pagination.js +10 -0
  6. package/dist/components/atoms/pagination.js.map +1 -0
  7. package/dist/components/atoms/tracking-pixel.js +32 -0
  8. package/dist/components/atoms/tracking-pixel.js.map +1 -0
  9. package/dist/hooks/storage/useImageUpload.js.map +1 -1
  10. package/dist/hooks/util/useErrorScreen.js.map +1 -1
  11. package/dist/hooks/util/useErrorToast.js.map +1 -1
  12. package/dist/index.js +194 -189
  13. package/dist/index.js.map +1 -1
  14. package/dist/internal/useShopActions.js.map +1 -1
  15. package/dist/internal/useShopActionsDataFetching.js +26 -26
  16. package/dist/internal/useShopActionsDataFetching.js.map +1 -1
  17. package/dist/internal/useShopActionsPaginatedDataFetching.js.map +1 -1
  18. package/dist/mocks.js +267 -0
  19. package/dist/mocks.js.map +1 -0
  20. package/dist/shop-minis-react/node_modules/.pnpm/@babel_runtime@7.27.6/node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js +8 -0
  21. package/dist/shop-minis-react/node_modules/.pnpm/@babel_runtime@7.27.6/node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js.map +1 -0
  22. package/dist/shop-minis-react/node_modules/.pnpm/@babel_runtime@7.27.6/node_modules/@babel/runtime/helpers/esm/extends.js +13 -0
  23. package/dist/shop-minis-react/node_modules/.pnpm/@babel_runtime@7.27.6/node_modules/@babel/runtime/helpers/esm/extends.js.map +1 -0
  24. package/dist/shop-minis-react/node_modules/.pnpm/@babel_runtime@7.27.6/node_modules/@babel/runtime/helpers/esm/inheritsLoose.js +8 -0
  25. package/dist/shop-minis-react/node_modules/.pnpm/@babel_runtime@7.27.6/node_modules/@babel/runtime/helpers/esm/inheritsLoose.js.map +1 -0
  26. package/dist/shop-minis-react/node_modules/.pnpm/@babel_runtime@7.27.6/node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js +9 -0
  27. package/dist/shop-minis-react/node_modules/.pnpm/@babel_runtime@7.27.6/node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js.map +1 -0
  28. package/dist/shop-minis-react/node_modules/.pnpm/memoize-one@5.2.1/node_modules/memoize-one/dist/memoize-one.esm.js +28 -0
  29. package/dist/shop-minis-react/node_modules/.pnpm/memoize-one@5.2.1/node_modules/memoize-one/dist/memoize-one.esm.js.map +1 -0
  30. package/dist/shop-minis-react/node_modules/.pnpm/react-intersection-observer@9.16.0_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-intersection-observer/dist/index.js +135 -0
  31. package/dist/shop-minis-react/node_modules/.pnpm/react-intersection-observer@9.16.0_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-intersection-observer/dist/index.js.map +1 -0
  32. package/dist/shop-minis-react/node_modules/.pnpm/react-window@1.8.11_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-window/dist/index.esm.js +375 -0
  33. package/dist/shop-minis-react/node_modules/.pnpm/react-window@1.8.11_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-window/dist/index.esm.js.map +1 -0
  34. package/dist/shop-minis-react.css +1 -0
  35. package/package.json +9 -4
  36. package/src/components/MinisContainer.tsx +4 -1
  37. package/src/components/atoms/list.tsx +101 -0
  38. package/src/components/atoms/pagination.tsx +19 -0
  39. package/src/components/atoms/tracking-pixel.tsx +40 -0
  40. package/src/components/index.ts +2 -0
  41. package/src/hooks/navigation/useCloseMini.example.tsx +1 -1
  42. package/src/hooks/navigation/useShopNavigation.example.tsx +12 -9
  43. package/src/hooks/product/useProductListActions.example.tsx +19 -16
  44. package/src/hooks/shop/useShopCartActions.example.tsx +2 -2
  45. package/src/hooks/storage/useImageUpload.example.tsx +1 -1
  46. package/src/hooks/storage/useImageUpload.ts +3 -2
  47. package/src/hooks/user/useFollowedShopsActions.example.tsx +6 -8
  48. package/src/hooks/user/useSavedProductsActions.example.tsx +8 -6
  49. package/src/hooks/util/useErrorScreen.example.tsx +1 -2
  50. package/src/hooks/util/useErrorScreen.ts +2 -1
  51. package/src/hooks/util/useErrorToast.example.tsx +1 -1
  52. package/src/hooks/util/useErrorToast.ts +2 -1
  53. package/src/hooks/util/useImagePicker.example.tsx +4 -12
  54. package/src/index.css +1 -0
  55. package/src/internal/useShopActions.ts +1 -1
  56. package/src/internal/useShopActionsDataFetching.ts +6 -7
  57. package/src/internal/useShopActionsPaginatedDataFetching.ts +3 -6
  58. package/src/mocks.ts +20 -8
  59. package/src/stories/List.stories.tsx +68 -0
  60. package/src/styles/utilities.css +22 -0
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { DATA_NAVIGATION_TYPE_ATTRIBUTE as o, NAVIGATION_TYPES as t } from "./types/index.js";
2
- import { MinisContainer as l } from "./components/MinisContainer.js";
2
+ import { MinisContainer as i } from "./components/MinisContainer.js";
3
3
  import { ProductCard as p } from "./components/commerce/product-card.js";
4
4
  import { ProductLink as m } from "./components/commerce/product-link.js";
5
5
  import { MerchantCard as u, MerchantCardPrimitive as x } from "./components/commerce/merchant-card.js";
6
6
  import { ProductCardSkeleton as c } from "./components/commerce/product-card-skeleton.js";
7
- import { MerchantCardSkeleton as S } from "./components/commerce/merchant-card-skeleton.js";
7
+ import { MerchantCardSkeleton as g } from "./components/commerce/merchant-card-skeleton.js";
8
8
  import { TransitionContainer as D } from "./components/navigation/transition-container.js";
9
9
  import { TransitionLink as C } from "./components/navigation/transition-link.js";
10
10
  import { Button as T } from "./components/atoms/button.js";
@@ -12,207 +12,212 @@ import { FavoriteButton as I } from "./components/atoms/favorite-button.js";
12
12
  import { IconButton as v } from "./components/atoms/icon-button.js";
13
13
  import { ThumbhashImage as k } from "./components/atoms/thumbhash-image.js";
14
14
  import { Touchable as F } from "./components/atoms/touchable.js";
15
- import { AlertDialogAtom as M } from "./components/atoms/alert-dialog.js";
16
- import { Accordion as B, AccordionContent as L, AccordionItem as y, AccordionTrigger as G } from "./components/ui/accordion.js";
17
- import { Alert as O, AlertDescription as U, AlertTitle as V } from "./components/ui/alert.js";
18
- import { AlertDialog as z, AlertDialogAction as Y, AlertDialogCancel as W, AlertDialogContent as j, AlertDialogDescription as q, AlertDialogFooter as J, AlertDialogHeader as K, AlertDialogOverlay as Q, AlertDialogPortal as X, AlertDialogTitle as Z, AlertDialogTrigger as $ } from "./components/ui/alert-dialog.js";
19
- import { Avatar as er, AvatarFallback as or, AvatarImage as tr } from "./components/ui/avatar.js";
20
- import { Card as lr, CardAction as ir, CardContent as pr, CardDescription as sr, CardFooter as mr, CardHeader as nr, CardTitle as ur } from "./components/ui/card.js";
21
- import { Carousel as fr, CarouselContent as cr, CarouselItem as dr, CarouselNext as Sr, CarouselPrevious as gr } from "./components/ui/carousel.js";
22
- import { Checkbox as Ar } from "./components/ui/checkbox.js";
23
- import { Dialog as Pr, DialogClose as Tr, DialogContent as hr, DialogDescription as Ir, DialogFooter as wr, DialogHeader as vr, DialogOverlay as br, DialogPortal as kr, DialogTitle as Er, DialogTrigger as Fr } from "./components/ui/dialog.js";
24
- import { Drawer as Mr, DrawerClose as Nr, DrawerContent as Br, DrawerDescription as Lr, DrawerFooter as yr, DrawerHeader as Gr, DrawerOverlay as Hr, DrawerPortal as Or, DrawerTitle as Ur, DrawerTrigger as Vr } from "./components/ui/drawer.js";
25
- import { Input as zr } from "./components/ui/input.js";
26
- import { Label as Wr } from "./components/ui/label.js";
27
- import { Progress as qr } from "./components/ui/progress.js";
28
- import { RadioGroup as Kr, RadioGroupItem as Qr } from "./components/ui/radio-group.js";
29
- import { ResizableHandle as Zr, ResizablePanel as $r, ResizablePanelGroup as re } from "./components/ui/resizable.js";
30
- import { ScrollArea as oe, ScrollBar as te } from "./components/ui/scroll-area.js";
31
- import { Select as le, SelectContent as ie, SelectGroup as pe, SelectItem as se, SelectLabel as me, SelectScrollDownButton as ne, SelectScrollUpButton as ue, SelectSeparator as xe, SelectTrigger as fe, SelectValue as ce } from "./components/ui/select.js";
32
- import { Separator as Se } from "./components/ui/separator.js";
33
- import { Sheet as De, SheetClose as Ae, SheetContent as Ce, SheetDescription as Pe, SheetFooter as Te, SheetHeader as he, SheetTitle as Ie, SheetTrigger as we } from "./components/ui/sheet.js";
34
- import { Toaster as be } from "./components/ui/sonner.js";
35
- import { Skeleton as Ee } from "./components/ui/skeleton.js";
36
- import { useRecentProducts as Re } from "./hooks/user/useRecentProducts.js";
37
- import { useRecentShops as Ne } from "./hooks/user/useRecentShops.js";
38
- import { useSavedProducts as Le } from "./hooks/user/useSavedProducts.js";
39
- import { useSavedProductsActions as Ge } from "./hooks/user/useSavedProductsActions.js";
40
- import { useFollowedShops as Oe } from "./hooks/user/useFollowedShops.js";
41
- import { useFollowedShopsActions as Ve } from "./hooks/user/useFollowedShopsActions.js";
42
- import { useCurrentUser as ze } from "./hooks/user/useCurrentUser.js";
43
- import { useOrders as We } from "./hooks/user/useOrders.js";
44
- import { useBuyerAttributes as qe } from "./hooks/user/useBuyerAttributes.js";
45
- import { useProductListActions as Ke } from "./hooks/product/useProductListActions.js";
46
- import { useProductLists as Xe } from "./hooks/product/useProductLists.js";
47
- import { useProductList as $e } from "./hooks/product/useProductList.js";
48
- import { useProduct as eo } from "./hooks/product/useProduct.js";
49
- import { useProducts as to } from "./hooks/product/useProducts.js";
50
- import { useProductVariants as lo } from "./hooks/product/useProductVariants.js";
51
- import { useProductMedia as po } from "./hooks/product/useProductMedia.js";
52
- import { useProductSearch as mo } from "./hooks/product/useProductSearch.js";
53
- import { useRecommendedProducts as uo } from "./hooks/product/useRecommendedProducts.js";
54
- import { usePopularProducts as fo } from "./hooks/product/usePopularProducts.js";
55
- import { useCuratedProducts as So } from "./hooks/product/useCuratedProducts.js";
56
- import { useAsyncStorage as Do } from "./hooks/storage/useAsyncStorage.js";
57
- import { useSecureStorage as Co } from "./hooks/storage/useSecureStorage.js";
58
- import { useImageUpload as To } from "./hooks/storage/useImageUpload.js";
59
- import { useShopNavigation as Io } from "./hooks/navigation/useShopNavigation.js";
60
- import { useCloseMini as vo } from "./hooks/navigation/useCloseMini.js";
61
- import { useDeeplink as ko } from "./hooks/navigation/useDeeplink.js";
62
- import { useNavigateWithTransition as Fo } from "./hooks/navigation/useNavigateWithTransition.js";
63
- import { useShop as Mo } from "./hooks/shop/useShop.js";
64
- import { useShopCartActions as Bo } from "./hooks/shop/useShopCartActions.js";
65
- import { useRecommendedShops as yo } from "./hooks/shop/useRecommendedShops.js";
66
- import { useErrorToast as Ho } from "./hooks/util/useErrorToast.js";
67
- import { useErrorScreen as Uo } from "./hooks/util/useErrorScreen.js";
68
- import { useShare as _o } from "./hooks/util/useShare.js";
69
- import { useImagePicker as Yo } from "./hooks/util/useImagePicker.js";
70
- import { MiniEntityNotFoundError as jo, MiniError as qo, MiniNetworkError as Jo, formatError as Ko } from "./utils/errors.js";
71
- import { parseUrl as Xo } from "./utils/parseUrl.js";
72
- import { Consent as $o, ConsentStatus as rt } from "./shop-minis-platform/src/types/permissions.js";
15
+ import { AlertDialogAtom as B } from "./components/atoms/alert-dialog.js";
16
+ import { List as N } from "./components/atoms/list.js";
17
+ import { Accordion as y, AccordionContent as G, AccordionItem as H, AccordionTrigger as O } from "./components/ui/accordion.js";
18
+ import { Alert as V, AlertDescription as _, AlertTitle as z } from "./components/ui/alert.js";
19
+ import { AlertDialog as W, AlertDialogAction as j, AlertDialogCancel as q, AlertDialogContent as J, AlertDialogDescription as K, AlertDialogFooter as Q, AlertDialogHeader as X, AlertDialogOverlay as Z, AlertDialogPortal as $, AlertDialogTitle as rr, AlertDialogTrigger as er } from "./components/ui/alert-dialog.js";
20
+ import { Avatar as tr, AvatarFallback as ar, AvatarImage as ir } from "./components/ui/avatar.js";
21
+ import { Badge as pr, badgeVariants as sr } from "./components/ui/badge.js";
22
+ import { Card as nr, CardAction as ur, CardContent as xr, CardDescription as fr, CardFooter as cr, CardHeader as dr, CardTitle as gr } from "./components/ui/card.js";
23
+ import { Carousel as Dr, CarouselContent as Ar, CarouselItem as Cr, CarouselNext as Pr, CarouselPrevious as Tr } from "./components/ui/carousel.js";
24
+ import { Checkbox as Ir } from "./components/ui/checkbox.js";
25
+ import { Dialog as vr, DialogClose as br, DialogContent as kr, DialogDescription as Er, DialogFooter as Fr, DialogHeader as Rr, DialogOverlay as Br, DialogPortal as Mr, DialogTitle as Nr, DialogTrigger as Lr } from "./components/ui/dialog.js";
26
+ import { Drawer as Gr, DrawerClose as Hr, DrawerContent as Or, DrawerDescription as Ur, DrawerFooter as Vr, DrawerHeader as _r, DrawerOverlay as zr, DrawerPortal as Yr, DrawerTitle as Wr, DrawerTrigger as jr } from "./components/ui/drawer.js";
27
+ import { Input as Jr } from "./components/ui/input.js";
28
+ import { Label as Qr } from "./components/ui/label.js";
29
+ import { Progress as Zr } from "./components/ui/progress.js";
30
+ import { RadioGroup as re, RadioGroupItem as ee } from "./components/ui/radio-group.js";
31
+ import { ResizableHandle as te, ResizablePanel as ae, ResizablePanelGroup as ie } from "./components/ui/resizable.js";
32
+ import { ScrollArea as pe, ScrollBar as se } from "./components/ui/scroll-area.js";
33
+ import { Select as ne, SelectContent as ue, SelectGroup as xe, SelectItem as fe, SelectLabel as ce, SelectScrollDownButton as de, SelectScrollUpButton as ge, SelectSeparator as Se, SelectTrigger as De, SelectValue as Ae } from "./components/ui/select.js";
34
+ import { Separator as Pe } from "./components/ui/separator.js";
35
+ import { Sheet as he, SheetClose as Ie, SheetContent as we, SheetDescription as ve, SheetFooter as be, SheetHeader as ke, SheetTitle as Ee, SheetTrigger as Fe } from "./components/ui/sheet.js";
36
+ import { Toaster as Be } from "./components/ui/sonner.js";
37
+ import { Skeleton as Ne } from "./components/ui/skeleton.js";
38
+ import { useRecentProducts as ye } from "./hooks/user/useRecentProducts.js";
39
+ import { useRecentShops as He } from "./hooks/user/useRecentShops.js";
40
+ import { useSavedProducts as Ue } from "./hooks/user/useSavedProducts.js";
41
+ import { useSavedProductsActions as _e } from "./hooks/user/useSavedProductsActions.js";
42
+ import { useFollowedShops as Ye } from "./hooks/user/useFollowedShops.js";
43
+ import { useFollowedShopsActions as je } from "./hooks/user/useFollowedShopsActions.js";
44
+ import { useCurrentUser as Je } from "./hooks/user/useCurrentUser.js";
45
+ import { useOrders as Qe } from "./hooks/user/useOrders.js";
46
+ import { useBuyerAttributes as Ze } from "./hooks/user/useBuyerAttributes.js";
47
+ import { useProductListActions as ro } from "./hooks/product/useProductListActions.js";
48
+ import { useProductLists as oo } from "./hooks/product/useProductLists.js";
49
+ import { useProductList as ao } from "./hooks/product/useProductList.js";
50
+ import { useProduct as lo } from "./hooks/product/useProduct.js";
51
+ import { useProducts as so } from "./hooks/product/useProducts.js";
52
+ import { useProductVariants as no } from "./hooks/product/useProductVariants.js";
53
+ import { useProductMedia as xo } from "./hooks/product/useProductMedia.js";
54
+ import { useProductSearch as co } from "./hooks/product/useProductSearch.js";
55
+ import { useRecommendedProducts as So } from "./hooks/product/useRecommendedProducts.js";
56
+ import { usePopularProducts as Ao } from "./hooks/product/usePopularProducts.js";
57
+ import { useCuratedProducts as Po } from "./hooks/product/useCuratedProducts.js";
58
+ import { useAsyncStorage as ho } from "./hooks/storage/useAsyncStorage.js";
59
+ import { useSecureStorage as wo } from "./hooks/storage/useSecureStorage.js";
60
+ import { useImageUpload as bo } from "./hooks/storage/useImageUpload.js";
61
+ import { useShopNavigation as Eo } from "./hooks/navigation/useShopNavigation.js";
62
+ import { useCloseMini as Ro } from "./hooks/navigation/useCloseMini.js";
63
+ import { useDeeplink as Mo } from "./hooks/navigation/useDeeplink.js";
64
+ import { useNavigateWithTransition as Lo } from "./hooks/navigation/useNavigateWithTransition.js";
65
+ import { useShop as Go } from "./hooks/shop/useShop.js";
66
+ import { useShopCartActions as Oo } from "./hooks/shop/useShopCartActions.js";
67
+ import { useRecommendedShops as Vo } from "./hooks/shop/useRecommendedShops.js";
68
+ import { useErrorToast as zo } from "./hooks/util/useErrorToast.js";
69
+ import { useErrorScreen as Wo } from "./hooks/util/useErrorScreen.js";
70
+ import { useShare as qo } from "./hooks/util/useShare.js";
71
+ import { useImagePicker as Ko } from "./hooks/util/useImagePicker.js";
72
+ import { MiniEntityNotFoundError as Xo, MiniError as Zo, MiniNetworkError as $o, formatError as rt } from "./utils/errors.js";
73
+ import { parseUrl as ot } from "./utils/parseUrl.js";
74
+ import { Consent as at, ConsentStatus as it } from "./shop-minis-platform/src/types/permissions.js";
73
75
  export {
74
- B as Accordion,
75
- L as AccordionContent,
76
- y as AccordionItem,
77
- G as AccordionTrigger,
78
- O as Alert,
79
- U as AlertDescription,
80
- z as AlertDialog,
81
- Y as AlertDialogAction,
82
- M as AlertDialogAtom,
83
- W as AlertDialogCancel,
84
- j as AlertDialogContent,
85
- q as AlertDialogDescription,
86
- J as AlertDialogFooter,
87
- K as AlertDialogHeader,
88
- Q as AlertDialogOverlay,
89
- X as AlertDialogPortal,
90
- Z as AlertDialogTitle,
91
- $ as AlertDialogTrigger,
92
- V as AlertTitle,
93
- er as Avatar,
94
- or as AvatarFallback,
95
- tr as AvatarImage,
76
+ y as Accordion,
77
+ G as AccordionContent,
78
+ H as AccordionItem,
79
+ O as AccordionTrigger,
80
+ V as Alert,
81
+ _ as AlertDescription,
82
+ W as AlertDialog,
83
+ j as AlertDialogAction,
84
+ B as AlertDialogAtom,
85
+ q as AlertDialogCancel,
86
+ J as AlertDialogContent,
87
+ K as AlertDialogDescription,
88
+ Q as AlertDialogFooter,
89
+ X as AlertDialogHeader,
90
+ Z as AlertDialogOverlay,
91
+ $ as AlertDialogPortal,
92
+ rr as AlertDialogTitle,
93
+ er as AlertDialogTrigger,
94
+ z as AlertTitle,
95
+ tr as Avatar,
96
+ ar as AvatarFallback,
97
+ ir as AvatarImage,
98
+ pr as Badge,
96
99
  T as Button,
97
- lr as Card,
98
- ir as CardAction,
99
- pr as CardContent,
100
- sr as CardDescription,
101
- mr as CardFooter,
102
- nr as CardHeader,
103
- ur as CardTitle,
104
- fr as Carousel,
105
- cr as CarouselContent,
106
- dr as CarouselItem,
107
- Sr as CarouselNext,
108
- gr as CarouselPrevious,
109
- Ar as Checkbox,
110
- $o as Consent,
111
- rt as ConsentStatus,
100
+ nr as Card,
101
+ ur as CardAction,
102
+ xr as CardContent,
103
+ fr as CardDescription,
104
+ cr as CardFooter,
105
+ dr as CardHeader,
106
+ gr as CardTitle,
107
+ Dr as Carousel,
108
+ Ar as CarouselContent,
109
+ Cr as CarouselItem,
110
+ Pr as CarouselNext,
111
+ Tr as CarouselPrevious,
112
+ Ir as Checkbox,
113
+ at as Consent,
114
+ it as ConsentStatus,
112
115
  o as DATA_NAVIGATION_TYPE_ATTRIBUTE,
113
- Pr as Dialog,
114
- Tr as DialogClose,
115
- hr as DialogContent,
116
- Ir as DialogDescription,
117
- wr as DialogFooter,
118
- vr as DialogHeader,
119
- br as DialogOverlay,
120
- kr as DialogPortal,
121
- Er as DialogTitle,
122
- Fr as DialogTrigger,
123
- Mr as Drawer,
124
- Nr as DrawerClose,
125
- Br as DrawerContent,
126
- Lr as DrawerDescription,
127
- yr as DrawerFooter,
128
- Gr as DrawerHeader,
129
- Hr as DrawerOverlay,
130
- Or as DrawerPortal,
131
- Ur as DrawerTitle,
132
- Vr as DrawerTrigger,
116
+ vr as Dialog,
117
+ br as DialogClose,
118
+ kr as DialogContent,
119
+ Er as DialogDescription,
120
+ Fr as DialogFooter,
121
+ Rr as DialogHeader,
122
+ Br as DialogOverlay,
123
+ Mr as DialogPortal,
124
+ Nr as DialogTitle,
125
+ Lr as DialogTrigger,
126
+ Gr as Drawer,
127
+ Hr as DrawerClose,
128
+ Or as DrawerContent,
129
+ Ur as DrawerDescription,
130
+ Vr as DrawerFooter,
131
+ _r as DrawerHeader,
132
+ zr as DrawerOverlay,
133
+ Yr as DrawerPortal,
134
+ Wr as DrawerTitle,
135
+ jr as DrawerTrigger,
133
136
  I as FavoriteButton,
134
137
  v as IconButton,
135
- zr as Input,
136
- Wr as Label,
138
+ Jr as Input,
139
+ Qr as Label,
140
+ N as List,
137
141
  u as MerchantCard,
138
142
  x as MerchantCardPrimitive,
139
- S as MerchantCardSkeleton,
140
- jo as MiniEntityNotFoundError,
141
- qo as MiniError,
142
- Jo as MiniNetworkError,
143
- l as MinisContainer,
143
+ g as MerchantCardSkeleton,
144
+ Xo as MiniEntityNotFoundError,
145
+ Zo as MiniError,
146
+ $o as MiniNetworkError,
147
+ i as MinisContainer,
144
148
  t as NAVIGATION_TYPES,
145
149
  p as ProductCard,
146
150
  c as ProductCardSkeleton,
147
151
  m as ProductLink,
148
- qr as Progress,
149
- Kr as RadioGroup,
150
- Qr as RadioGroupItem,
151
- Zr as ResizableHandle,
152
- $r as ResizablePanel,
153
- re as ResizablePanelGroup,
154
- oe as ScrollArea,
155
- te as ScrollBar,
156
- le as Select,
157
- ie as SelectContent,
158
- pe as SelectGroup,
159
- se as SelectItem,
160
- me as SelectLabel,
161
- ne as SelectScrollDownButton,
162
- ue as SelectScrollUpButton,
163
- xe as SelectSeparator,
164
- fe as SelectTrigger,
165
- ce as SelectValue,
166
- Se as Separator,
167
- De as Sheet,
168
- Ae as SheetClose,
169
- Ce as SheetContent,
170
- Pe as SheetDescription,
171
- Te as SheetFooter,
172
- he as SheetHeader,
173
- Ie as SheetTitle,
174
- we as SheetTrigger,
175
- Ee as Skeleton,
152
+ Zr as Progress,
153
+ re as RadioGroup,
154
+ ee as RadioGroupItem,
155
+ te as ResizableHandle,
156
+ ae as ResizablePanel,
157
+ ie as ResizablePanelGroup,
158
+ pe as ScrollArea,
159
+ se as ScrollBar,
160
+ ne as Select,
161
+ ue as SelectContent,
162
+ xe as SelectGroup,
163
+ fe as SelectItem,
164
+ ce as SelectLabel,
165
+ de as SelectScrollDownButton,
166
+ ge as SelectScrollUpButton,
167
+ Se as SelectSeparator,
168
+ De as SelectTrigger,
169
+ Ae as SelectValue,
170
+ Pe as Separator,
171
+ he as Sheet,
172
+ Ie as SheetClose,
173
+ we as SheetContent,
174
+ ve as SheetDescription,
175
+ be as SheetFooter,
176
+ ke as SheetHeader,
177
+ Ee as SheetTitle,
178
+ Fe as SheetTrigger,
179
+ Ne as Skeleton,
176
180
  k as ThumbhashImage,
177
- be as Toaster,
181
+ Be as Toaster,
178
182
  F as Touchable,
179
183
  D as TransitionContainer,
180
184
  C as TransitionLink,
181
- Ko as formatError,
182
- Xo as parseUrl,
183
- Do as useAsyncStorage,
184
- qe as useBuyerAttributes,
185
- vo as useCloseMini,
186
- So as useCuratedProducts,
187
- ze as useCurrentUser,
188
- ko as useDeeplink,
189
- Uo as useErrorScreen,
190
- Ho as useErrorToast,
191
- Oe as useFollowedShops,
192
- Ve as useFollowedShopsActions,
193
- Yo as useImagePicker,
194
- To as useImageUpload,
195
- Fo as useNavigateWithTransition,
196
- We as useOrders,
197
- fo as usePopularProducts,
198
- eo as useProduct,
199
- $e as useProductList,
200
- Ke as useProductListActions,
201
- Xe as useProductLists,
202
- po as useProductMedia,
203
- mo as useProductSearch,
204
- lo as useProductVariants,
205
- to as useProducts,
206
- Re as useRecentProducts,
207
- Ne as useRecentShops,
208
- uo as useRecommendedProducts,
209
- yo as useRecommendedShops,
210
- Le as useSavedProducts,
211
- Ge as useSavedProductsActions,
212
- Co as useSecureStorage,
213
- _o as useShare,
214
- Mo as useShop,
215
- Bo as useShopCartActions,
216
- Io as useShopNavigation
185
+ sr as badgeVariants,
186
+ rt as formatError,
187
+ ot as parseUrl,
188
+ ho as useAsyncStorage,
189
+ Ze as useBuyerAttributes,
190
+ Ro as useCloseMini,
191
+ Po as useCuratedProducts,
192
+ Je as useCurrentUser,
193
+ Mo as useDeeplink,
194
+ Wo as useErrorScreen,
195
+ zo as useErrorToast,
196
+ Ye as useFollowedShops,
197
+ je as useFollowedShopsActions,
198
+ Ko as useImagePicker,
199
+ bo as useImageUpload,
200
+ Lo as useNavigateWithTransition,
201
+ Qe as useOrders,
202
+ Ao as usePopularProducts,
203
+ lo as useProduct,
204
+ ao as useProductList,
205
+ ro as useProductListActions,
206
+ oo as useProductLists,
207
+ xo as useProductMedia,
208
+ co as useProductSearch,
209
+ no as useProductVariants,
210
+ so as useProducts,
211
+ ye as useRecentProducts,
212
+ He as useRecentShops,
213
+ So as useRecommendedProducts,
214
+ Vo as useRecommendedShops,
215
+ Ue as useSavedProducts,
216
+ _e as useSavedProductsActions,
217
+ wo as useSecureStorage,
218
+ qo as useShare,
219
+ Go as useShop,
220
+ Oo as useShopCartActions,
221
+ Eo as useShopNavigation
217
222
  };
218
223
  //# sourceMappingURL=index.js.map
package/dist/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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useShopActions.js","sources":["../../src/internal/useShopActions.ts"],"sourcesContent":["import {ShopActions} from '../types'\n\nexport function useShopActions(): ShopActions {\n return window.minisSDK\n}\n"],"names":["useShopActions"],"mappings":"AAEO,SAASA,IAA8B;AAC5C,SAAO,OAAO;AAChB;"}
1
+ {"version":3,"file":"useShopActions.js","sources":["../../src/internal/useShopActions.ts"],"sourcesContent":["import {ShopActions} from '@shopify/shop-minis-platform/actions'\n\nexport function useShopActions(): ShopActions {\n return window.minisSDK\n}\n"],"names":["useShopActions"],"mappings":"AAEO,SAASA,IAA8B;AAC5C,SAAO,OAAO;AAChB;"}
@@ -1,38 +1,38 @@
1
1
  import { useState as b, useCallback as u, useMemo as v, useEffect as M } from "react";
2
2
  import { MiniError as P, formatError as V } from "../utils/errors.js";
3
- const A = (d, c, f) => {
4
- const [o, n] = b({
3
+ const A = (c, d, f) => {
4
+ const [n, l] = b({
5
5
  data: null,
6
6
  loading: !0,
7
7
  error: null
8
8
  }), h = f?.skip === !0, { validator: g, hook: t } = f, w = u(
9
- (l) => {
9
+ (s) => {
10
10
  try {
11
- return g?.(l), null;
12
- } catch (s) {
13
- return s ?? new P({
11
+ return g?.(s), null;
12
+ } catch (e) {
13
+ return e instanceof Error ? e : new P({
14
14
  hook: t,
15
15
  message: "Validation failed"
16
16
  });
17
17
  }
18
18
  },
19
19
  [g, t]
20
- ), y = v(() => c, [JSON.stringify(c)]), a = u(
21
- async (l, {
22
- setLoading: s = !0,
20
+ ), y = v(() => d, [JSON.stringify(d)]), a = u(
21
+ async (s, {
22
+ setLoading: e = !0,
23
23
  setError: p = !0,
24
- resetOnError: m = !0,
24
+ resetOnError: E = !0,
25
25
  throwOnError: O = !0
26
26
  } = {}) => {
27
- let E = null, i = null;
28
- n((r) => ({
27
+ let m = null, i = null;
28
+ l((r) => ({
29
29
  ...r,
30
- loading: s ? !0 : r.loading
30
+ loading: e ? !0 : r.loading
31
31
  }));
32
32
  try {
33
- const r = await d({ ...y, ...l });
33
+ const r = await c({ ...y, ...s });
34
34
  if (r.ok)
35
- i = w(r.data.data), n((S) => ({
35
+ i = w(r.data.data), l((S) => ({
36
36
  ...S,
37
37
  data: r.data.data,
38
38
  loading: !1,
@@ -41,17 +41,17 @@ const A = (d, c, f) => {
41
41
  else
42
42
  throw r.error;
43
43
  } catch (r) {
44
- E = V({ hook: t }, r);
44
+ m = V({ hook: t }, r);
45
45
  }
46
- const e = i || E;
47
- if (e && (p || m) && n((r) => ({
48
- data: m ? null : r.data,
46
+ const o = i || m;
47
+ if (o && (p || E) && l((r) => ({
48
+ data: E ? null : r.data,
49
49
  loading: !1,
50
- error: e
51
- })), e && O)
52
- throw e;
50
+ error: o
51
+ })), o && O)
52
+ throw o;
53
53
  },
54
- [d, y, t, w]
54
+ [c, y, t, w]
55
55
  ), k = u(async () => {
56
56
  await a({ fetchPolicy: "network-only" }, {
57
57
  setLoading: !1,
@@ -67,9 +67,9 @@ const A = (d, c, f) => {
67
67
  }
68
68
  );
69
69
  }, [a, h]), {
70
- data: o.data,
71
- loading: o.loading,
72
- error: o.error,
70
+ data: n.data,
71
+ loading: n.loading,
72
+ error: n.error,
73
73
  refetch: k
74
74
  };
75
75
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useShopActionsDataFetching.js","sources":["../../src/internal/useShopActionsDataFetching.ts"],"sourcesContent":["import {useCallback, useEffect, useMemo, useState} from 'react'\n\nimport {ShopActionResult} from '@shopify/shop-minis-platform/actions'\n\nimport {DataHookFetchPolicy, DataHookReturnsBase} from '../types'\nimport {formatError, MiniError} from '../utils/errors'\n\nexport interface ShopActionsDataFetchingResult<R> extends DataHookReturnsBase {\n data: R | null\n}\n\nexport const useShopActionsDataFetching = <\n S = unknown,\n P extends {fetchPolicy?: DataHookFetchPolicy} = {\n fetchPolicy?: DataHookFetchPolicy\n },\n>(\n action: (params: P) => Promise<ShopActionResult<{data: S}>>,\n params: P,\n options: {\n skip?: boolean\n hook?: string\n validator?: (data: S) => void\n }\n): ShopActionsDataFetchingResult<S> => {\n const [state, setState] = useState<{\n data: S | null\n loading: boolean\n error: Error | null\n }>({\n data: null,\n loading: true,\n error: null,\n })\n\n const skip = options?.skip === true\n const {validator, hook} = options\n const runValidator = useCallback(\n (dataToValidate: S) => {\n try {\n validator?.(dataToValidate)\n return null\n } catch (err) {\n return (\n err ??\n new MiniError({\n hook,\n message: 'Validation failed',\n })\n )\n }\n },\n [validator, hook]\n )\n\n // Params object is recreated on every render, so we need to memoize it.\n // We don't know what's inside the params object, but we can stringify it.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const stableParams = useMemo(() => params, [JSON.stringify(params)])\n\n // There's a lot of complexity here because each type of fetch has different side effects if we are trying to\n // stay close to how Apollo client works. eg:\n // - Initial fetch: set loading, set error, set data, reset on error (don't throw)\n // - change params fetch: set loading, set error, set data, reset on error (don't throw)\n // - refetch fetch: don't set loading, set error, update data, leave data as is was on error (also throw)\n // - fetchMore fetch: don't set loading, don't set error, update data, leave data as is was on error (also throw)\n const fetch = useCallback(\n async (\n extraParams?: Partial<P>,\n {\n setLoading = true,\n setError = true,\n resetOnError = true,\n throwOnError = true,\n }: {\n setLoading?: boolean\n setError?: boolean\n resetOnError?: boolean\n throwOnError?: boolean\n } = {}\n ) => {\n let queryError: Error | null = null\n let validationError: Error | null = null\n\n setState(curState => ({\n ...curState,\n loading: setLoading ? true : curState.loading,\n }))\n\n try {\n const result = await action({...stableParams, ...extraParams})\n\n if (result.ok) {\n validationError = runValidator(result.data.data)\n\n setState(curState => ({\n ...curState,\n data: result.data.data,\n loading: false,\n error: validationError ?? null,\n }))\n } else {\n throw result.error\n }\n } catch (err) {\n queryError = formatError({hook}, err)\n }\n\n const error = validationError || queryError\n\n if (error && (setError || resetOnError)) {\n setState(curState => ({\n data: resetOnError ? null : curState.data,\n loading: false,\n error,\n }))\n }\n\n if (error && throwOnError) {\n throw error\n }\n },\n [action, stableParams, hook, runValidator]\n )\n\n const refetch = useCallback(async () => {\n await fetch({fetchPolicy: 'network-only'} as Partial<P>, {\n setLoading: false,\n resetOnError: false,\n throwOnError: true,\n })\n }, [fetch])\n\n useEffect(() => {\n if (skip) return\n\n fetch(\n {},\n {\n throwOnError: false,\n }\n )\n }, [fetch, skip])\n\n return {\n data: state.data,\n loading: state.loading,\n error: state.error,\n refetch,\n }\n}\n"],"names":["useShopActionsDataFetching","action","params","options","state","setState","useState","skip","validator","hook","runValidator","useCallback","dataToValidate","err","MiniError","stableParams","useMemo","fetch","extraParams","setLoading","setError","resetOnError","throwOnError","queryError","validationError","curState","result","formatError","error","refetch","useEffect"],"mappings":";;AAWO,MAAMA,IAA6B,CAMxCC,GACAC,GACAC,MAKqC;AACrC,QAAM,CAACC,GAAOC,CAAQ,IAAIC,EAIvB;AAAA,IACD,MAAM;AAAA,IACN,S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A,QACpB,MAAMJ,IAAe,OAAOI,EAAS;AAAA,QACrC,SAAS;AAAA,QACT,OAAAG;AAAA,MAAA,EACA,GAGAA,KAASN;AACL,cAAAM;AAAA,IAEV;AAAA,IACA,CAAC3B,GAAQc,GAAcN,GAAMC,CAAY;AAAA,EAC3C,GAEMmB,IAAUlB,EAAY,YAAY;AACtC,UAAMM,EAAM,EAAC,aAAa,kBAA+B;AAAA,MACvD,YAAY;AAAA,MACZ,cAAc;AAAA,MACd,cAAc;AAAA,IAAA,CACf;AAAA,EAAA,GACA,CAACA,CAAK,CAAC;AAEV,SAAAa,EAAU,MAAM;AACd,IAAIvB,KAEJU;AAAA,MACE,CAAC;AAAA,MACD;AAAA,QACE,cAAc;AAAA,MAAA;AAAA,IAElB;AAAA,EAAA,GACC,CAACA,GAAOV,CAAI,CAAC,GAET;AAAA,IACL,MAAMH,EAAM;AAAA,IACZ,SAASA,EAAM;AAAA,IACf,OAAOA,EAAM;AAAA,IACb,SAAAyB;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"useShopActionsDataFetching.js","sources":["../../src/internal/useShopActionsDataFetching.ts"],"sourcesContent":["import {useCallback, useEffect, useMemo, useState} from 'react'\n\nimport {ShopActionResult} from '@shopify/shop-minis-platform/actions'\n\nimport {DataHookFetchPolicy, DataHookReturnsBase} from '../types'\nimport {formatError, MiniError} from '../utils/errors'\n\nexport interface ShopActionsDataFetchingResult<R> extends DataHookReturnsBase {\n data: R | null\n}\n\nexport const useShopActionsDataFetching = <\n S = unknown,\n P extends {fetchPolicy?: DataHookFetchPolicy} = {\n fetchPolicy?: DataHookFetchPolicy\n },\n>(\n action: (params: P) => Promise<ShopActionResult<{data: S}>>,\n params: P,\n options: {\n skip?: boolean\n hook?: string\n validator?: (data: S) => void\n }\n): ShopActionsDataFetchingResult<S> => {\n const [state, setState] = useState<{\n data: S | null\n loading: boolean\n error: Error | null\n }>({\n data: null,\n loading: true,\n error: null,\n })\n\n const skip = options?.skip === true\n const {validator, hook} = options\n const runValidator = useCallback(\n (dataToValidate: S) => {\n try {\n validator?.(dataToValidate)\n return null\n } catch (err) {\n if (err instanceof Error) return err\n\n return new MiniError({\n hook,\n message: 'Validation failed',\n })\n }\n },\n [validator, hook]\n )\n\n // Params object is recreated on every render, so we need to memoize it.\n // We don't know what's inside the params object, but we can stringify it.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const stableParams = useMemo(() => params, [JSON.stringify(params)])\n\n // There's a lot of complexity here because each type of fetch has different side effects if we are trying to\n // stay close to how Apollo client works. eg:\n // - Initial fetch: set loading, set error, set data, reset on error (don't throw)\n // - change params fetch: set loading, set error, set data, reset on error (don't throw)\n // - refetch fetch: don't set loading, set error, update data, leave data as is was on error (also throw)\n // - fetchMore fetch: don't set loading, don't set error, update data, leave data as is was on error (also throw)\n const fetch = useCallback(\n async (\n extraParams?: Partial<P>,\n {\n setLoading = true,\n setError = true,\n resetOnError = true,\n throwOnError = true,\n }: {\n setLoading?: boolean\n setError?: boolean\n resetOnError?: boolean\n throwOnError?: boolean\n } = {}\n ) => {\n let queryError: Error | null = null\n let validationError: Error | null = null\n\n setState(curState => ({\n ...curState,\n loading: setLoading ? true : curState.loading,\n }))\n\n try {\n const result = await action({...stableParams, ...extraParams})\n\n if (result.ok) {\n validationError = runValidator(result.data.data)\n\n setState(curState => ({\n ...curState,\n data: result.data.data,\n loading: false,\n error: validationError ?? null,\n }))\n } else {\n throw result.error\n }\n } catch (err) {\n queryError = formatError({hook}, err)\n }\n\n const error = validationError || queryError\n\n if (error && (setError || resetOnError)) {\n setState(curState => ({\n data: resetOnError ? null : curState.data,\n loading: false,\n error,\n }))\n }\n\n if (error && throwOnError) {\n throw error\n }\n },\n [action, stableParams, hook, runValidator]\n )\n\n const refetch = useCallback(async () => {\n await fetch({fetchPolicy: 'network-only'} as Partial<P>, {\n setLoading: false,\n resetOnError: false,\n throwOnError: true,\n })\n }, [fetch])\n\n useEffect(() => {\n if (skip) return\n\n fetch(\n {},\n {\n throwOnError: false,\n }\n )\n }, [fetch, skip])\n\n return {\n data: state.data,\n loading: state.loading,\n error: state.error,\n refetch,\n }\n}\n"],"names":["useShopActionsDataFetching","action","params","options","state","setState","useState","skip","validator","hook","runValidator","useCallback","dataToValidate","err","MiniError","stableParams","useMemo","fetch","extraParams","setLoading","setError","resetOnError","throwOnError","queryError","validationError","curState","result","formatError","error","refetch","useEffect"],"mappings":";;AAWO,MAAMA,IAA6B,CAMxCC,GACAC,GACAC,MAKqC;AACrC,QAAM,CAACC,GAAOC,CAAQ,IAAIC,EAIvB;AAAA,IACD,MAAM;AAAA,IACN,SAAS;AAAA,IACT,OAAO;AAAA,EAAA,CACR,GAEKC,IAAOJ,GAAS,SAAS,IACzB,EAAC,WAAAK,GAAW,MAAAC,EAAA,IAAQN,GACpBO,IAAeC;AAAA,IACnB,CAACC,MAAsB;AACjB,UAAA;AACF,eAAAJ,IAAYI,CAAc,GACnB;AAAA,eACAC,GAAK;AACR,eAAAA,aAAe,QAAcA,IAE1B,IAAIC,EAAU;AAAA,UACnB,MAAAL;AAAA,UACA,SAAS;AAAA,QAAA,CACV;AAAA,MAAA;AAAA,IAEL;AAAA,IACA,CAACD,GAAWC,CAAI;AAAA,EAClB,GAKMM,IAAeC,EAAQ,MAAMd,GAAQ,CAAC,KAAK,UAAUA,CAAM,CAAC,CAAC,GAQ7De,IAAQN;AAAA,IACZ,OACEO,GACA;AAAA,MACE,YAAAC,IAAa;AAAA,MACb,UAAAC,IAAW;AAAA,MACX,cAAAC,IAAe;AAAA,MACf,cAAAC,IAAe;AAAA,IACjB,IAKI,OACD;AACH,UAAIC,IAA2B,MAC3BC,IAAgC;AAEpC,MAAAnB,EAAS,CAAaoB,OAAA;AAAA,QACpB,GAAGA;AAAA,QACH,SAASN,IAAa,KAAOM,EAAS;AAAA,MAAA,EACtC;AAEE,UAAA;AACI,cAAAC,IAAS,MAAMzB,EAAO,EAAC,GAAGc,GAAc,GAAGG,GAAY;AAE7D,YAAIQ,EAAO;AACS,UAAAF,IAAAd,EAAagB,EAAO,KAAK,IAAI,GAE/CrB,EAAS,CAAaoB,OAAA;AAAA,YACpB,GAAGA;AAAA,YACH,MAAMC,EAAO,KAAK;AAAA,YAClB,SAAS;AAAA,YACT,OAAOF,KAAmB;AAAA,UAAA,EAC1B;AAAA;AAEF,gBAAME,EAAO;AAAA,eAERb,GAAK;AACZ,QAAAU,IAAaI,EAAY,EAAC,MAAAlB,EAAI,GAAGI,CAAG;AAAA,MAAA;AAGtC,YAAMe,IAAQJ,KAAmBD;AAUjC,UARIK,MAAUR,KAAYC,MACxBhB,EAAS,CAAaoB,OAAA;AAAA,QACpB,MAAMJ,IAAe,OAAOI,EAAS;AAAA,QACrC,SAAS;AAAA,QACT,OAAAG;AAAA,MAAA,EACA,GAGAA,KAASN;AACL,cAAAM;AAAA,IAEV;AAAA,IACA,CAAC3B,GAAQc,GAAcN,GAAMC,CAAY;AAAA,EAC3C,GAEMmB,IAAUlB,EAAY,YAAY;AACtC,UAAMM,EAAM,EAAC,aAAa,kBAA+B;AAAA,MACvD,YAAY;AAAA,MACZ,cAAc;AAAA,MACd,cAAc;AAAA,IAAA,CACf;AAAA,EAAA,GACA,CAACA,CAAK,CAAC;AAEV,SAAAa,EAAU,MAAM;AACd,IAAIvB,KAEJU;AAAA,MACE,CAAC;AAAA,MACD;AAAA,QACE,cAAc;AAAA,MAAA;AAAA,IAElB;AAAA,EAAA,GACC,CAACA,GAAOV,CAAI,CAAC,GAET;AAAA,IACL,MAAMH,EAAM;AAAA,IACZ,SAASA,EAAM;AAAA,IACf,OAAOA,EAAM;AAAA,IACb,SAAAyB;AAAA,EACF;AACF;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useShopActionsPaginatedDataFetching.js","sources":["../../src/internal/useShopActionsPaginatedDataFetching.ts"],"sourcesContent":["import {useCallback, useEffect, useMemo, useState} from 'react'\n\nimport {\n DataHookFetchPolicy,\n PaginatedDataHookReturnsBase,\n PaginationInfo,\n ShopAction,\n} from '../types'\nimport {formatError, MiniError} from '../utils/errors'\n\nexport interface ShopActionsDataFetchingResult<S>\n extends PaginatedDataHookReturnsBase {\n data: S | null\n}\n\nexport const useShopActionsPaginatedDataFetching = <\n S = unknown,\n P extends {after?: string; fetchPolicy?: DataHookFetchPolicy} = {\n after?: undefined\n fetchPolicy?: DataHookFetchPolicy\n },\n>(\n action: ShopAction<P, {data: S; pageInfo: PaginationInfo}>,\n params: P,\n options: {\n skip?: boolean\n hook?: string\n validator?: (data: S) => void\n }\n): ShopActionsDataFetchingResult<S> => {\n const [state, setState] = useState<{\n data: S | null\n pageInfo: PaginationInfo\n loading: boolean\n error: Error | null\n }>({\n data: null,\n pageInfo: {hasNextPage: false, endCursor: null},\n loading: false,\n error: null,\n })\n\n const skip = options?.skip === true\n const {validator, hook} = options\n const runValidator = useCallback(\n (dataToValidate: S): Error | null => {\n try {\n validator?.(dataToValidate)\n return null\n } catch (err) {\n if (err instanceof Error) return err\n\n return new MiniError({\n hook,\n message: 'Validation failed',\n })\n }\n },\n [validator, hook]\n )\n\n // Params object is recreated on every render, so we need to memoize it.\n // We don't know what's inside the params object, but we can stringify it.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const stableParams = useMemo(() => params, [JSON.stringify(params)])\n\n // There's a lot of complexity here because each type of fetch has different side effects if we are trying to\n // stay close to how Apollo client works. eg:\n // - Initial fetch: set loading, set error, set data, reset on error (don't throw)\n // - change params fetch: set loading, set error, set data, reset on error (don't throw)\n // - refetch fetch: don't set loading, set error, update data, leave data as is was on error (also throw)\n // - fetchMore fetch: don't set loading, don't set error, update data, leave data as is was on error (also throw)\n const fetch = useCallback(\n async (\n extraParams?: Partial<P>,\n {\n setLoading = true,\n setError = true,\n resetOnError = true,\n throwOnError = true,\n appendData = false,\n }: {\n setLoading?: boolean\n setError?: boolean\n resetOnError?: boolean\n throwOnError?: boolean\n appendData?: boolean\n } = {}\n ) => {\n let queryError: Error | null = null\n let validationError: Error | null = null\n\n setState(curState => ({\n ...curState,\n loading: setLoading ? true : curState.loading,\n }))\n\n try {\n const result = await action({...stableParams, ...extraParams})\n\n if (result.ok) {\n validationError = runValidator(result.data.data)\n\n setState(curState => {\n let newData = result.data.data\n\n if (\n appendData &&\n curState.data &&\n Array.isArray(curState.data) &&\n Array.isArray(result.data.data)\n ) {\n newData = [...curState.data, ...result.data.data] as S\n }\n\n return {\n ...curState,\n data: newData,\n pageInfo: result.data.pageInfo,\n loading: false,\n error: validationError ?? null,\n }\n })\n } else {\n throw result.error\n }\n } catch (err) {\n console.log('caught 1', err)\n queryError = formatError({hook}, err)\n }\n\n const error = validationError || queryError\n\n if (error && (setError || resetOnError)) {\n setState(curState => ({\n data: resetOnError ? null : curState.data,\n pageInfo: resetOnError\n ? {hasNextPage: false, endCursor: null}\n : curState.pageInfo,\n loading: false,\n error,\n }))\n }\n\n if (error && throwOnError) {\n throw error\n }\n },\n [action, stableParams, hook, runValidator]\n )\n\n const refetch = useCallback(async () => {\n await fetch({fetchPolicy: 'network-only'} as Partial<P>, {\n setLoading: false,\n resetOnError: false,\n throwOnError: true,\n })\n }, [fetch])\n\n const fetchMore = useCallback(async () => {\n if (!state.pageInfo.hasNextPage || !state.pageInfo.endCursor) return\n\n await fetch({after: state.pageInfo.endCursor} as Partial<P>, {\n setLoading: false,\n setError: false,\n resetOnError: false,\n throwOnError: true,\n appendData: true,\n })\n }, [state.pageInfo.hasNextPage, state.pageInfo.endCursor, fetch])\n\n useEffect(() => {\n if (skip) return\n\n fetch(\n {},\n {\n throwOnError: false,\n }\n )\n }, [fetch, skip])\n\n return {\n data: state.data,\n loading: state.loading,\n error: state.error,\n hasNextPage: state.pageInfo.hasNextPage,\n refetch,\n fetchMore,\n }\n}\n"],"names":["useShopActionsPaginatedDataFetching","action","params","options","state","setState","useState","skip","validator","hook","runValidator","useCallback","dataToValidate","err","MiniError","stableParams","useMemo","fetch","extraParams","setLoading","setError","resetOnError","throwOnError","appendData","queryError","validationError","curState","result","newData","formatError","error","refetch","fetchMore","useEffect"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MAAM;AACd,IAAI1B,KAEJU;AAAA,MACE,CAAC;AAAA,MACD;AAAA,QACE,cAAc;AAAA,MAAA;AAAA,IAElB;AAAA,EAAA,GACC,CAACA,GAAOV,CAAI,CAAC,GAET;AAAA,IACL,MAAMH,EAAM;AAAA,IACZ,SAASA,EAAM;AAAA,IACf,OAAOA,EAAM;AAAA,IACb,aAAaA,EAAM,SAAS;AAAA,IAC5B,SAAA2B;AAAA,IACA,WAAAC;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"useShopActionsPaginatedDataFetching.js","sources":["../../src/internal/useShopActionsPaginatedDataFetching.ts"],"sourcesContent":["import {useCallback, useEffect, useMemo, useState} from 'react'\n\nimport {ShopAction, PaginationInfo} from '@shopify/shop-minis-platform/actions'\n\nimport {DataHookFetchPolicy, PaginatedDataHookReturnsBase} from '../types'\nimport {formatError, MiniError} from '../utils/errors'\n\nexport interface ShopActionsDataFetchingResult<S>\n extends PaginatedDataHookReturnsBase {\n data: S | null\n}\n\nexport const useShopActionsPaginatedDataFetching = <\n S = unknown,\n P extends {after?: string; fetchPolicy?: DataHookFetchPolicy} = {\n after?: undefined\n fetchPolicy?: DataHookFetchPolicy\n },\n>(\n action: ShopAction<P, {data: S; pageInfo: PaginationInfo}>,\n params: P,\n options: {\n skip?: boolean\n hook?: string\n validator?: (data: S) => void\n }\n): ShopActionsDataFetchingResult<S> => {\n const [state, setState] = useState<{\n data: S | null\n pageInfo: PaginationInfo\n loading: boolean\n error: Error | null\n }>({\n data: null,\n pageInfo: {hasNextPage: false, endCursor: null},\n loading: false,\n error: null,\n })\n\n const skip = options?.skip === true\n const {validator, hook} = options\n const runValidator = useCallback(\n (dataToValidate: S): Error | null => {\n try {\n validator?.(dataToValidate)\n return null\n } catch (err) {\n if (err instanceof Error) return err\n\n return new MiniError({\n hook,\n message: 'Validation failed',\n })\n }\n },\n [validator, hook]\n )\n\n // Params object is recreated on every render, so we need to memoize it.\n // We don't know what's inside the params object, but we can stringify it.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const stableParams = useMemo(() => params, [JSON.stringify(params)])\n\n // There's a lot of complexity here because each type of fetch has different side effects if we are trying to\n // stay close to how Apollo client works. eg:\n // - Initial fetch: set loading, set error, set data, reset on error (don't throw)\n // - change params fetch: set loading, set error, set data, reset on error (don't throw)\n // - refetch fetch: don't set loading, set error, update data, leave data as is was on error (also throw)\n // - fetchMore fetch: don't set loading, don't set error, update data, leave data as is was on error (also throw)\n const fetch = useCallback(\n async (\n extraParams?: Partial<P>,\n {\n setLoading = true,\n setError = true,\n resetOnError = true,\n throwOnError = true,\n appendData = false,\n }: {\n setLoading?: boolean\n setError?: boolean\n resetOnError?: boolean\n throwOnError?: boolean\n appendData?: boolean\n } = {}\n ) => {\n let queryError: Error | null = null\n let validationError: Error | null = null\n\n setState(curState => ({\n ...curState,\n loading: setLoading ? true : curState.loading,\n }))\n\n try {\n const result = await action({...stableParams, ...extraParams})\n\n if (result.ok) {\n validationError = runValidator(result.data.data)\n\n setState(curState => {\n let newData = result.data.data\n\n if (\n appendData &&\n curState.data &&\n Array.isArray(curState.data) &&\n Array.isArray(result.data.data)\n ) {\n newData = [...curState.data, ...result.data.data] as S\n }\n\n return {\n ...curState,\n data: newData,\n pageInfo: result.data.pageInfo,\n loading: false,\n error: validationError ?? null,\n }\n })\n } else {\n throw result.error\n }\n } catch (err) {\n console.log('caught 1', err)\n queryError = formatError({hook}, err)\n }\n\n const error = validationError || queryError\n\n if (error && (setError || resetOnError)) {\n setState(curState => ({\n data: resetOnError ? null : curState.data,\n pageInfo: resetOnError\n ? {hasNextPage: false, endCursor: null}\n : curState.pageInfo,\n loading: false,\n error,\n }))\n }\n\n if (error && throwOnError) {\n throw error\n }\n },\n [action, stableParams, hook, runValidator]\n )\n\n const refetch = useCallback(async () => {\n await fetch({fetchPolicy: 'network-only'} as Partial<P>, {\n setLoading: false,\n resetOnError: false,\n throwOnError: true,\n })\n }, [fetch])\n\n const fetchMore = useCallback(async () => {\n if (!state.pageInfo.hasNextPage || !state.pageInfo.endCursor) return\n\n await fetch({after: state.pageInfo.endCursor} as Partial<P>, {\n setLoading: false,\n setError: false,\n resetOnError: false,\n throwOnError: true,\n appendData: true,\n })\n }, [state.pageInfo.hasNextPage, state.pageInfo.endCursor, fetch])\n\n useEffect(() => {\n if (skip) return\n\n fetch(\n {},\n {\n throwOnError: false,\n }\n )\n }, [fetch, skip])\n\n return {\n data: state.data,\n loading: state.loading,\n error: state.error,\n hasNextPage: state.pageInfo.hasNextPage,\n refetch,\n fetchMore,\n }\n}\n"],"names":["useShopActionsPaginatedDataFetching","action","params","options","state","setState","useState","skip","validator","hook","runValidator","useCallback","dataToValidate","err","MiniError","stableParams","useMemo","fetch","extraParams","setLoading","setError","resetOnError","throwOnError","appendData","queryError","validationError","curState","result","newData","formatError","error","refetch","fetchMore","useEffect"],"mappings":";;AAYO,MAAMA,IAAsC,CAOjDC,GACAC,GACAC,MAKqC;AACrC,QAAM,CAACC,GAAOC,CAAQ,IAAIC,EAKvB;AAAA,IACD,MAAM;AAAA,IACN,UAAU,EAAC,aAAa,IAAO,WAAW,KAAI;AAAA,IAC9C,SAAS;AAAA,IACT,OAAO;AAAA,EAAA,CACR,GAEKC,IAAOJ,GAAS,SAAS,IACzB,EAAC,WAAAK,GAAW,MAAAC,EAAA,IAAQN,GACpBO,IAAeC;AAAA,IACnB,CAACC,MAAoC;AAC/B,UAAA;AACF,eAAAJ,IAAYI,CAAc,GACnB;AAAA,eACAC,GAAK;AACR,eAAAA,aAAe,QAAcA,IAE1B,IAAIC,EAAU;AAAA,UACnB,MAAAL;AAAA,UACA,SAAS;AAAA,QAAA,CACV;AAAA,MAAA;AAAA,IAEL;AAAA,IACA,CAACD,GAAWC,CAAI;AAAA,EAClB,GAKMM,IAAeC,EAAQ,MAAMd,GAAQ,CAAC,KAAK,UAAUA,CAAM,CAAC,CAAC,GAQ7De,IAAQN;AAAA,IACZ,OACEO,GACA;AAAA,MACE,YAAAC,IAAa;AAAA,MACb,U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