@shopify/shop-minis-react 0.0.25 → 0.0.27

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 (58) hide show
  1. package/dist/_virtual/index10.js +2 -2
  2. package/dist/_virtual/index4.js +2 -3
  3. package/dist/_virtual/index4.js.map +1 -1
  4. package/dist/_virtual/index7.js +3 -2
  5. package/dist/_virtual/index7.js.map +1 -1
  6. package/dist/_virtual/index9.js +2 -2
  7. package/dist/components/atoms/product-variant-price.js +61 -0
  8. package/dist/components/atoms/product-variant-price.js.map +1 -0
  9. package/dist/components/commerce/product-card.js +120 -153
  10. package/dist/components/commerce/product-card.js.map +1 -1
  11. package/dist/components/commerce/product-link-skeleton.js +30 -0
  12. package/dist/components/commerce/product-link-skeleton.js.map +1 -0
  13. package/dist/components/commerce/product-link.js +73 -77
  14. package/dist/components/commerce/product-link.js.map +1 -1
  15. package/dist/components/commerce/search.js +144 -0
  16. package/dist/components/commerce/search.js.map +1 -0
  17. package/dist/components/content/content-monitor.js +17 -0
  18. package/dist/components/content/content-monitor.js.map +1 -0
  19. package/dist/components/content/content-wrapper.js +17 -0
  20. package/dist/components/content/content-wrapper.js.map +1 -0
  21. package/dist/components/ui/input.js +3 -3
  22. package/dist/components/ui/input.js.map +1 -1
  23. package/dist/hooks/content/useContent.js +24 -0
  24. package/dist/hooks/content/useContent.js.map +1 -0
  25. package/dist/hooks/content/useCreateImageContent.js +21 -18
  26. package/dist/hooks/content/useCreateImageContent.js.map +1 -1
  27. package/dist/hooks/product/useProductSearch.js +24 -23
  28. package/dist/hooks/product/useProductSearch.js.map +1 -1
  29. package/dist/index.js +230 -221
  30. package/dist/index.js.map +1 -1
  31. package/dist/mocks.js +21 -6
  32. package/dist/mocks.js.map +1 -1
  33. package/dist/shop-minis-platform/src/types/content.js +5 -0
  34. package/dist/shop-minis-platform/src/types/content.js.map +1 -0
  35. 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
  36. package/dist/shop-minis-react/node_modules/.pnpm/@xmldom_xmldom@0.8.10/node_modules/@xmldom/xmldom/lib/index.js +1 -1
  37. package/dist/shop-minis-react/node_modules/.pnpm/lucide-react@0.513.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/search.js +16 -0
  38. package/dist/shop-minis-react/node_modules/.pnpm/lucide-react@0.513.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/search.js.map +1 -0
  39. package/dist/shop-minis-react/node_modules/.pnpm/querystringify@2.2.0/node_modules/querystringify/index.js +1 -1
  40. 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
  41. package/dist/shop-minis-react.css +1 -1
  42. package/package.json +5 -4
  43. package/src/components/atoms/product-variant-price.tsx +74 -0
  44. package/src/components/commerce/product-card.tsx +7 -56
  45. package/src/components/commerce/product-link-skeleton.tsx +30 -0
  46. package/src/components/commerce/product-link.tsx +8 -7
  47. package/src/components/commerce/search.tsx +264 -0
  48. package/src/components/content/content-monitor.tsx +23 -0
  49. package/src/components/content/content-wrapper.tsx +56 -0
  50. package/src/components/index.ts +3 -0
  51. package/src/components/ui/input.tsx +1 -1
  52. package/src/hooks/content/useContent.ts +50 -0
  53. package/src/hooks/content/useCreateImageContent.ts +20 -5
  54. package/src/hooks/product/useProductSearch.ts +10 -1
  55. package/src/mocks.ts +15 -0
  56. package/src/stories/ProductVariantPrice.stories.tsx +73 -0
  57. package/src/stories/Toaster.stories.tsx +2 -2
  58. package/src/styles/utilities.css +9 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-wrapper.js","sources":["../../../src/components/content/content-wrapper.tsx"],"sourcesContent":["import {useContent} from '../../hooks/content/useContent'\nimport {Content} from '../../types'\n\nimport {ContentMonitor} from './content-monitor'\n\ninterface BaseContentWrapperProps {\n children: ({\n content,\n loading,\n }: {\n content?: Content\n loading: boolean\n }) => JSX.Element | null\n}\n\ninterface PublicIdContentWrapperProps extends BaseContentWrapperProps {\n publicId: string\n externalId?: never\n}\n\ninterface ExternalIdContentWrapperProps extends BaseContentWrapperProps {\n externalId: string\n publicId?: never\n}\n\ntype ContentWrapperProps =\n | PublicIdContentWrapperProps\n | ExternalIdContentWrapperProps\n\n// It's too messy in the docs to show the complete types here so we show a simplified version\nexport interface ContentWrapperPropsForDocs extends BaseContentWrapperProps {\n publicId?: string\n externalId?: string\n}\n\nexport function ContentWrapper({\n publicId,\n externalId,\n children,\n}: ContentWrapperProps) {\n const {content, loading} = useContent({\n identifiers: [{publicId, externalId}],\n })\n\n const contentItem = content?.[0]\n\n if (loading || !contentItem) {\n return children({loading})\n }\n\n return (\n <ContentMonitor publicId={contentItem.publicId}>\n {children({content: contentItem, loading})}\n </ContentMonitor>\n )\n}\n"],"names":["ContentWrapper","publicId","externalId","children","content","loading","useContent","contentItem","jsx","ContentMonitor"],"mappings":";;;AAmCO,SAASA,EAAe;AAAA,EAC7B,UAAAC;AAAA,EACA,YAAAC;AAAA,EACA,UAAAC;AACF,GAAwB;AACtB,QAAM,EAAC,SAAAC,GAAS,SAAAC,EAAO,IAAIC,EAAW;AAAA,IACpC,aAAa,CAAC,EAAC,UAAAL,GAAU,YAAAC,EAAW,CAAA;AAAA,EAAA,CACrC,GAEKK,IAAcH,IAAU,CAAC;AAE3B,SAAAC,KAAW,CAACE,IACPJ,EAAS,EAAC,SAAAE,GAAQ,IAIzB,gBAAAG,EAACC,GAAe,EAAA,UAAUF,EAAY,UACnC,UAASJ,EAAA,EAAC,SAASI,GAAa,SAAAF,EAAO,CAAC,EAC3C,CAAA;AAEJ;"}
@@ -1,6 +1,6 @@
1
1
  import { jsx as t } from "react/jsx-runtime";
2
2
  import { cn as n } from "../../lib/utils.js";
3
- function a({ className: e, type: i, ...r }) {
3
+ function l({ className: e, type: i, ...r }) {
4
4
  return /* @__PURE__ */ t(
5
5
  "input",
6
6
  {
@@ -8,7 +8,7 @@ function a({ className: e, type: i, ...r }) {
8
8
  "data-slot": "input",
9
9
  className: n(
10
10
  "file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input flex h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
11
- "focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
11
+ "focus:outline-none focus:ring-0 focus-visible:ring-0 focus-visible:outline-none",
12
12
  "aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
13
13
  e
14
14
  ),
@@ -17,6 +17,6 @@ function a({ className: e, type: i, ...r }) {
17
17
  );
18
18
  }
19
19
  export {
20
- a as Input
20
+ l as Input
21
21
  };
22
22
  //# sourceMappingURL=input.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"input.js","sources":["../../../src/components/ui/input.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport {cn} from '../../lib/utils'\n\nfunction Input({className, type, ...props}: React.ComponentProps<'input'>) {\n return (\n <input\n type={type}\n data-slot=\"input\"\n className={cn(\n 'file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input flex h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm',\n 'focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]',\n 'aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive',\n className\n )}\n {...props}\n />\n )\n}\n\nexport {Input}\n"],"names":["Input","className","type","props","jsx","cn"],"mappings":";;AAIA,SAASA,EAAM,EAAC,WAAAC,GAAW,MAAAC,GAAM,GAAGC,KAAuC;AAEvE,SAAA,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,MAAAF;AAAA,MACA,aAAU;AAAA,MACV,WAAWG;AAAA,QACT;AAAA,QACA;AAAA,QACA;AAAA,QACAJ;AAAA,MACF;AAAA,MACC,GAAGE;AAAA,IAAA;AAAA,EACN;AAEJ;"}
1
+ {"version":3,"file":"input.js","sources":["../../../src/components/ui/input.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport {cn} from '../../lib/utils'\n\nfunction Input({className, type, ...props}: React.ComponentProps<'input'>) {\n return (\n <input\n type={type}\n data-slot=\"input\"\n className={cn(\n 'file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input flex h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm',\n 'focus:outline-none focus:ring-0 focus-visible:ring-0 focus-visible:outline-none',\n 'aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive',\n className\n )}\n {...props}\n />\n )\n}\n\nexport {Input}\n"],"names":["Input","className","type","props","jsx","cn"],"mappings":";;AAIA,SAASA,EAAM,EAAC,WAAAC,GAAW,MAAAC,GAAM,GAAGC,KAAuC;AAEvE,SAAA,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,MAAAF;AAAA,MACA,aAAU;AAAA,MACV,WAAWG;AAAA,QACT;AAAA,QACA;AAAA,QACA;AAAA,QACAJ;AAAA,MACF;AAAA,MACC,GAAGE;AAAA,IAAA;AAAA,EACN;AAEJ;"}
@@ -0,0 +1,24 @@
1
+ import { useMemo as m } from "react";
2
+ import { useShopActions as u } from "../../internal/useShopActions.js";
3
+ import { useShopActionsDataFetching as a } from "../../internal/useShopActionsDataFetching.js";
4
+ const l = (o) => {
5
+ const { getContent: e } = u(), { identifiers: n, skip: s = !1, ...r } = o, { data: t, ...i } = a(
6
+ e,
7
+ {
8
+ identifiers: n,
9
+ ...r
10
+ },
11
+ {
12
+ skip: s,
13
+ hook: "useContent"
14
+ }
15
+ ), c = m(() => t ?? null, [t]);
16
+ return {
17
+ ...i,
18
+ content: c
19
+ };
20
+ };
21
+ export {
22
+ l as useContent
23
+ };
24
+ //# sourceMappingURL=useContent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useContent.js","sources":["../../../src/hooks/content/useContent.ts"],"sourcesContent":["import {useMemo} from 'react'\n\nimport {useShopActions} from '../../internal/useShopActions'\nimport {useShopActionsDataFetching} from '../../internal/useShopActionsDataFetching'\nimport {\n Content,\n ContentIdentifierInput,\n DataHookOptionsBase,\n DataHookReturnsBase,\n} from '../../types'\n\nexport interface UseContentParams extends DataHookOptionsBase {\n /**\n * The identifiers of the content to fetch.\n */\n identifiers: ContentIdentifierInput | ContentIdentifierInput[]\n}\n\ninterface UseContentReturns extends DataHookReturnsBase {\n /**\n * The content returned from the query.\n */\n content: Content[] | null\n}\n\nexport const useContent = (params: UseContentParams): UseContentReturns => {\n const {getContent} = useShopActions()\n const {identifiers, skip = false, ...restParams} = params\n\n const {data, ...rest} = useShopActionsDataFetching(\n getContent,\n {\n identifiers,\n ...restParams,\n },\n {\n skip,\n hook: 'useContent',\n }\n )\n\n const content = useMemo(() => {\n return data ?? null\n }, [data])\n\n return {\n ...rest,\n content,\n }\n}\n"],"names":["useContent","params","getContent","useShopActions","identifiers","skip","restParams","data","rest","useShopActionsDataFetching","content","useMemo"],"mappings":";;;AAyBa,MAAAA,IAAa,CAACC,MAAgD;AACnE,QAAA,EAAC,YAAAC,EAAU,IAAIC,EAAe,GAC9B,EAAC,aAAAC,GAAa,MAAAC,IAAO,IAAO,GAAGC,EAAc,IAAAL,GAE7C,EAAC,MAAAM,GAAM,GAAGC,EAAA,IAAQC;AAAA,IACtBP;AAAA,IACA;AAAA,MACE,aAAAE;AAAA,MACA,GAAGE;AAAA,IACL;AAAA,IACA;AAAA,MACE,MAAAD;AAAA,MACA,MAAM;AAAA,IAAA;AAAA,EAEV,GAEMK,IAAUC,EAAQ,MACfJ,KAAQ,MACd,CAACA,CAAI,CAAC;AAEF,SAAA;AAAA,IACL,GAAGC;AAAA,IACH,SAAAE;AAAA,EACF;AACF;"}
@@ -1,37 +1,40 @@
1
- import { useCallback as s } from "react";
2
- import { useHandleAction as p } from "../../internal/useHandleAction.js";
3
- import { useShopActions as c } from "../../internal/useShopActions.js";
4
- import { useImageUpload as u } from "../storage/useImageUpload.js";
5
- import { fileToDataUri as g } from "../../utils/imageToDataUri.js";
6
- const C = () => {
7
- const { createContent: t } = c(), { uploadImage: o } = u(), a = s(
8
- async (i) => {
9
- const { image: e, contentTitle: n, visibility: m } = i;
1
+ import { useState as u, useCallback as g } from "react";
2
+ import { useHandleAction as f } from "../../internal/useHandleAction.js";
3
+ import { useShopActions as d } from "../../internal/useShopActions.js";
4
+ import { useImageUpload as w } from "../storage/useImageUpload.js";
5
+ import { fileToDataUri as I } from "../../utils/imageToDataUri.js";
6
+ const E = () => {
7
+ const { createContent: t } = d(), { uploadImage: a } = w(), [i, o] = u(!1), n = g(
8
+ async (m) => {
9
+ o(!0);
10
+ const { image: e, contentTitle: s, visibility: l } = m;
10
11
  if (!e.type)
11
12
  throw new Error("Unable to determine file type");
12
13
  if (!e.type.startsWith("image/"))
13
14
  throw new Error("Invalid file type: must be an image");
14
- const [l] = await o([
15
+ const [c] = await a([
15
16
  {
16
17
  mimeType: e.type,
17
- uri: await g(e)
18
+ uri: await I(e)
18
19
  }
19
- ]), r = l.imageUrl;
20
+ ]), r = c.imageUrl;
20
21
  if (!r)
21
22
  throw new Error("Image upload failed");
22
- return t({
23
- title: n,
23
+ const p = await t({
24
+ title: s,
24
25
  imageUrl: r,
25
- visibility: m
26
+ visibility: l
26
27
  });
28
+ return o(!1), p;
27
29
  },
28
- [t, o]
30
+ [t, a]
29
31
  );
30
32
  return {
31
- createImageContent: p(a)
33
+ createImageContent: f(n),
34
+ loading: i
32
35
  };
33
36
  };
34
37
  export {
35
- C as useCreateImageContent
38
+ E as useCreateImageContent
36
39
  };
37
40
  //# sourceMappingURL=useCreateImageContent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useCreateImageContent.js","sources":["../../../src/hooks/content/useCreateImageContent.ts"],"sourcesContent":["import {useCallback} from 'react'\n\nimport {ContentVisibility} from '@shopify/shop-minis-platform'\nimport {CreateContentResponse} from '@shopify/shop-minis-platform/actions'\n\nimport {useHandleAction} from '../../internal/useHandleAction'\nimport {useShopActions} from '../../internal/useShopActions'\nimport {fileToDataUri} from '../../utils'\nimport {useImageUpload} from '../storage/useImageUpload'\n\ninterface CreateImageContentParams {\n image: File\n contentTitle: string\n visibility?: ContentVisibility[] | null\n}\n\ninterface UseCreateImageContentReturns {\n /**\n * Upload an image and create content.\n */\n createImageContent: (\n params: CreateImageContentParams\n ) => Promise<CreateContentResponse>\n}\n\nexport const useCreateImageContent = (): UseCreateImageContentReturns => {\n const {createContent} = useShopActions()\n const {uploadImage} = useImageUpload()\n\n const createImageContent = useCallback(\n async (params: CreateImageContentParams) => {\n const {image, contentTitle, visibility} = params\n\n if (!image.type) {\n throw new Error('Unable to determine file type')\n }\n if (!image.type.startsWith('image/')) {\n throw new Error('Invalid file type: must be an image')\n }\n\n const [uploadImageResult] = await uploadImage([\n {\n mimeType: image.type,\n uri: await fileToDataUri(image),\n },\n ])\n const uploadImageUrl = uploadImageResult.imageUrl\n\n if (!uploadImageUrl) {\n throw new Error('Image upload failed')\n }\n\n return createContent({\n title: contentTitle,\n imageUrl: uploadImageUrl,\n visibility,\n })\n },\n [createContent, uploadImage]\n )\n\n return {\n createImageContent: useHandleAction(createImageContent),\n }\n}\n"],"names":["useCreateImageContent","createContent","useShopActions","uploadImage","useImageUpload","createImageContent","useCallback","params","image","contentTitle","visibility","uploadImageResult","fileToDataUri","uploadImageUrl","useHandleAction"],"mappings":";;;;;AAyBO,MAAMA,IAAwB,MAAoC;AACjE,QAAA,EAAC,eAAAC,EAAa,IAAIC,EAAe,GACjC,EAAC,aAAAC,EAAW,IAAIC,EAAe,GAE/BC,IAAqBC;AAAA,IACzB,OAAOC,MAAqC;AAC1C,YAAM,EAAC,OAAAC,GAAO,cAAAC,GAAc,YAAAC,EAAc,IAAAH;AAEtC,UAAA,CAACC,EAAM;AACH,cAAA,IAAI,MAAM,+BAA+B;AAEjD,UAAI,CAACA,EAAM,KAAK,WAAW,QAAQ;AAC3B,cAAA,IAAI,MAAM,qCAAqC;AAGvD,YAAM,CAACG,CAAiB,IAAI,MAAMR,EAAY;AAAA,QAC5C;AAAA,UACE,UAAUK,EAAM;AAAA,UAChB,KAAK,MAAMI,EAAcJ,CAAK;AAAA,QAAA;AAAA,MAChC,CACD,GACKK,IAAiBF,EAAkB;AAEzC,UAAI,CAACE;AACG,cAAA,IAAI,MAAM,qBAAqB;AAGvC,aAAOZ,EAAc;AAAA,QACnB,OAAOQ;AAAA,QACP,UAAUI;AAAA,QACV,YAAAH;AAAA,MAAA,CACD;AAAA,IACH;AAAA,IACA,CAACT,GAAeE,CAAW;AAAA,EAC7B;AAEO,SAAA;AAAA,IACL,oBAAoBW,EAAgBT,CAAkB;AAAA,EACxD;AACF;"}
1
+ {"version":3,"file":"useCreateImageContent.js","sources":["../../../src/hooks/content/useCreateImageContent.ts"],"sourcesContent":["import {useCallback, useState} from 'react'\n\nimport {\n ContentVisibility,\n Content,\n ContentCreateUserErrors,\n} from '@shopify/shop-minis-platform'\n\nimport {useHandleAction} from '../../internal/useHandleAction'\nimport {useShopActions} from '../../internal/useShopActions'\nimport {fileToDataUri} from '../../utils'\nimport {useImageUpload} from '../storage/useImageUpload'\n\ninterface CreateImageContentParams {\n image: File\n contentTitle: string\n visibility?: ContentVisibility[] | null\n}\n\ninterface UseCreateImageContentReturns {\n /**\n * Upload an image and create content.\n */\n createImageContent: (\n params: CreateImageContentParams\n ) => Promise<{data: Content; userErrors?: ContentCreateUserErrors[]}>\n /**\n * Whether the content is being created.\n */\n loading: boolean\n}\n\nexport const useCreateImageContent = (): UseCreateImageContentReturns => {\n const {createContent} = useShopActions()\n const {uploadImage} = useImageUpload()\n const [loading, setLoading] = useState(false)\n\n const createImageContent = useCallback(\n async (params: CreateImageContentParams) => {\n setLoading(true)\n\n const {image, contentTitle, visibility} = params\n\n if (!image.type) {\n throw new Error('Unable to determine file type')\n }\n if (!image.type.startsWith('image/')) {\n throw new Error('Invalid file type: must be an image')\n }\n\n const [uploadImageResult] = await uploadImage([\n {\n mimeType: image.type,\n uri: await fileToDataUri(image),\n },\n ])\n const uploadImageUrl = uploadImageResult.imageUrl\n\n if (!uploadImageUrl) {\n throw new Error('Image upload failed')\n }\n\n const createContentResult = await createContent({\n title: contentTitle,\n imageUrl: uploadImageUrl,\n visibility,\n })\n\n setLoading(false)\n\n return createContentResult\n },\n [createContent, uploadImage]\n )\n\n return {\n createImageContent: useHandleAction(createImageContent),\n loading,\n }\n}\n"],"names":["useCreateImageContent","createContent","useShopActions","uploadImage","useImageUpload","loading","setLoading","useState","createImageContent","useCallback","params","image","contentTitle","visibility","uploadImageResult","fileToDataUri","uploadImageUrl","createContentResult","useHandleAction"],"mappings":";;;;;AAgCO,MAAMA,IAAwB,MAAoC;AACjE,QAAA,EAAC,eAAAC,EAAa,IAAIC,EAAe,GACjC,EAAC,aAAAC,EAAW,IAAIC,EAAe,GAC/B,CAACC,GAASC,CAAU,IAAIC,EAAS,EAAK,GAEtCC,IAAqBC;AAAA,IACzB,OAAOC,MAAqC;AAC1C,MAAAJ,EAAW,EAAI;AAEf,YAAM,EAAC,OAAAK,GAAO,cAAAC,GAAc,YAAAC,EAAc,IAAAH;AAEtC,UAAA,CAACC,EAAM;AACH,cAAA,IAAI,MAAM,+BAA+B;AAEjD,UAAI,CAACA,EAAM,KAAK,WAAW,QAAQ;AAC3B,cAAA,IAAI,MAAM,qCAAqC;AAGvD,YAAM,CAACG,CAAiB,IAAI,MAAMX,EAAY;AAAA,QAC5C;AAAA,UACE,UAAUQ,EAAM;AAAA,UAChB,KAAK,MAAMI,EAAcJ,CAAK;AAAA,QAAA;AAAA,MAChC,CACD,GACKK,IAAiBF,EAAkB;AAEzC,UAAI,CAACE;AACG,cAAA,IAAI,MAAM,qBAAqB;AAGjC,YAAAC,IAAsB,MAAMhB,EAAc;AAAA,QAC9C,OAAOW;AAAA,QACP,UAAUI;AAAA,QACV,YAAAH;AAAA,MAAA,CACD;AAED,aAAAP,EAAW,EAAK,GAETW;AAAA,IACT;AAAA,IACA,CAAChB,GAAeE,CAAW;AAAA,EAC7B;AAEO,SAAA;AAAA,IACL,oBAAoBe,EAAgBV,CAAkB;AAAA,IACtD,SAAAH;AAAA,EACF;AACF;"}
@@ -1,41 +1,42 @@
1
- import { useState as S, useCallback as h, useEffect as y, useMemo as b } from "react";
2
- import P from "../../_virtual/debounce.js";
3
- import { useShopActions as g } from "../../internal/useShopActions.js";
1
+ import { useState as h, useCallback as S, useEffect as y, useMemo as b } from "react";
2
+ import g from "../../_virtual/debounce.js";
3
+ import { useShopActions as P } from "../../internal/useShopActions.js";
4
4
  import { useShopActionsPaginatedDataFetching as k } from "../../internal/useShopActionsPaginatedDataFetching.js";
5
- const v = (r) => {
6
- const { getProductSearch: s } = g(), {
5
+ const v = (s) => {
6
+ const { getProductSearch: u } = P(), {
7
7
  query: e,
8
8
  filters: c,
9
- sortBy: u,
10
- includeSensitive: n = !1,
11
- skip: a = !1,
9
+ sortBy: n,
10
+ includeSensitive: a = !1,
11
+ skip: i = !1,
12
12
  ...d
13
- } = r ?? {}, [i, m] = S(e), t = h(
14
- P((p) => {
15
- m(p);
13
+ } = s ?? {}, [t, l] = h(e), r = S(
14
+ g((p) => {
15
+ l(p);
16
16
  }, 300),
17
17
  []
18
18
  );
19
- y(() => (t(e), () => {
20
- t.cancel();
21
- }), [e, t]);
22
- const { data: o, ...f } = k(
23
- s,
19
+ y(() => (r(e), () => {
20
+ r.cancel();
21
+ }), [e, r]);
22
+ const { data: o, ...m } = k(
23
+ u,
24
24
  {
25
- query: i,
25
+ query: t,
26
26
  filters: c,
27
- sortBy: u,
28
- includeSensitive: n,
27
+ sortBy: n,
28
+ includeSensitive: a,
29
29
  ...d
30
30
  },
31
31
  {
32
- skip: a,
32
+ skip: i,
33
33
  hook: "useProductSearch"
34
34
  }
35
- ), l = b(() => o ?? null, [o]);
35
+ ), f = b(() => t.trim().length === 0 ? null : o ?? null, [o, t]);
36
36
  return {
37
- ...f,
38
- products: l
37
+ ...m,
38
+ products: f,
39
+ isTyping: t !== e
39
40
  };
40
41
  };
41
42
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"useProductSearch.js","sources":["../../../src/hooks/product/useProductSearch.ts"],"sourcesContent":["import {useCallback, useEffect, useMemo, useState} from 'react'\n\nimport debounce from 'lodash/debounce'\n\nimport {useShopActions} from '../../internal/useShopActions'\nimport {useShopActionsPaginatedDataFetching} from '../../internal/useShopActionsPaginatedDataFetching'\nimport {\n PaginatedDataHookOptionsBase,\n PaginatedDataHookReturnsBase,\n Product,\n ProductFilters,\n ProductSearchSortBy,\n} from '../../types'\n\nexport interface UseProductSearchParams extends PaginatedDataHookOptionsBase {\n /**\n * The search query.\n */\n query: string\n /**\n * The filters to apply to the search.\n */\n filters?: ProductFilters\n /**\n * The sort order of the results.\n */\n sortBy?: ProductSearchSortBy\n /**\n * Whether to include sensitive products.\n */\n includeSensitive?: boolean\n}\n\ninterface UseProductSearchReturns extends PaginatedDataHookReturnsBase {\n /**\n * The products returned from the query.\n */\n products: Product[] | null\n}\n\nexport const useProductSearch = (\n params: UseProductSearchParams\n): UseProductSearchReturns => {\n const {getProductSearch} = useShopActions()\n const {\n query,\n filters,\n sortBy,\n includeSensitive = false,\n skip = false,\n ...restParams\n } = params ?? {}\n\n const [debouncedQuery, setDebouncedQuery] = useState<string>(query)\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const debouncedSetQuery = useCallback(\n debounce((newQuery: string) => {\n setDebouncedQuery(newQuery)\n }, 300),\n []\n )\n\n useEffect(() => {\n debouncedSetQuery(query)\n\n return () => {\n debouncedSetQuery.cancel()\n }\n }, [query, debouncedSetQuery])\n\n const {data, ...rest} = useShopActionsPaginatedDataFetching(\n getProductSearch,\n {\n query: debouncedQuery,\n filters,\n sortBy,\n includeSensitive,\n ...restParams,\n },\n {\n skip,\n hook: 'useProductSearch',\n }\n )\n\n const products = useMemo(() => {\n return data ?? null\n }, [data])\n\n return {\n ...rest,\n products,\n }\n}\n"],"names":["useProductSearch","params","getProductSearch","useShopActions","query","filters","sortBy","includeSensitive","skip","restParams","debouncedQuery","setDebouncedQuery","useState","debouncedSetQuery","useCallback","debounce","newQuery","useEffect","data","rest","useShopActionsPaginatedDataFetching","products","useMemo"],"mappings":";;;;AAwCa,MAAAA,IAAmB,CAC9BC,MAC4B;AACtB,QAAA,EAAC,kBAAAC,EAAgB,IAAIC,EAAe,GACpC;AAAA,IACJ,OAAAC;AAAA,IACA,SAAAC;AAAA,IACA,QAAAC;AAAA,IACA,kBAAAC,IAAmB;AAAA,IACnB,MAAAC,IAAO;AAAA,IACP,GAAGC;AAAA,EACL,IAAIR,KAAU,CAAC,GAET,CAACS,GAAgBC,CAAiB,IAAIC,EAAiBR,CAAK,GAG5DS,IAAoBC;AAAA,IACxBC,EAAS,CAACC,MAAqB;AAC7B,MAAAL,EAAkBK,CAAQ;AAAA,OACzB,GAAG;AAAA,IACN,CAAA;AAAA,EACF;AAEA,EAAAC,EAAU,OACRJ,EAAkBT,CAAK,GAEhB,MAAM;AACX,IAAAS,EAAkB,OAAO;AAAA,EAC3B,IACC,CAACT,GAAOS,CAAiB,CAAC;AAE7B,QAAM,EAAC,MAAAK,GAAM,GAAGC,EAAA,IAAQC;AAAA,IACtBlB;AAAA,IACA;AAAA,MACE,OAAOQ;AAAA,MACP,SAAAL;AAAA,MACA,QAAAC;AAAA,MACA,kBAAAC;AAAA,MACA,GAAGE;AAAA,IACL;AAAA,IACA;AAAA,MACE,MAAAD;AAAA,MACA,MAAM;AAAA,IAAA;AAAA,EAEV,GAEMa,IAAWC,EAAQ,MAChBJ,KAAQ,MACd,CAACA,CAAI,CAAC;AAEF,SAAA;AAAA,IACL,GAAGC;AAAA,IACH,UAAAE;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"useProductSearch.js","sources":["../../../src/hooks/product/useProductSearch.ts"],"sourcesContent":["import {useCallback, useEffect, useMemo, useState} from 'react'\n\nimport debounce from 'lodash/debounce'\n\nimport {useShopActions} from '../../internal/useShopActions'\nimport {useShopActionsPaginatedDataFetching} from '../../internal/useShopActionsPaginatedDataFetching'\nimport {\n PaginatedDataHookOptionsBase,\n PaginatedDataHookReturnsBase,\n Product,\n ProductFilters,\n ProductSearchSortBy,\n} from '../../types'\n\nexport interface UseProductSearchParams extends PaginatedDataHookOptionsBase {\n /**\n * The search query.\n */\n query: string\n /**\n * The filters to apply to the search.\n */\n filters?: ProductFilters\n /**\n * The sort order of the results.\n */\n sortBy?: ProductSearchSortBy\n /**\n * Whether to include sensitive products.\n */\n includeSensitive?: boolean\n}\n\ninterface UseProductSearchReturns extends PaginatedDataHookReturnsBase {\n /**\n * The products returned from the query.\n */\n products: Product[] | null\n /**\n * Whether the user is typing.\n */\n isTyping: boolean\n}\n\nexport const useProductSearch = (\n params: UseProductSearchParams\n): UseProductSearchReturns => {\n const {getProductSearch} = useShopActions()\n const {\n query,\n filters,\n sortBy,\n includeSensitive = false,\n skip = false,\n ...restParams\n } = params ?? {}\n\n const [debouncedQuery, setDebouncedQuery] = useState<string>(query)\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const debouncedSetQuery = useCallback(\n debounce((newQuery: string) => {\n setDebouncedQuery(newQuery)\n }, 300),\n []\n )\n\n useEffect(() => {\n debouncedSetQuery(query)\n\n return () => {\n debouncedSetQuery.cancel()\n }\n }, [query, debouncedSetQuery])\n\n const {data, ...rest} = useShopActionsPaginatedDataFetching(\n getProductSearch,\n {\n query: debouncedQuery,\n filters,\n sortBy,\n includeSensitive,\n ...restParams,\n },\n {\n skip,\n hook: 'useProductSearch',\n }\n )\n\n const products = useMemo(() => {\n if (debouncedQuery.trim().length === 0) {\n return null\n }\n\n return data ?? null\n }, [data, debouncedQuery])\n\n return {\n ...rest,\n products,\n isTyping: debouncedQuery !== query,\n }\n}\n"],"names":["useProductSearch","params","getProductSearch","useShopActions","query","filters","sortBy","includeSensitive","skip","restParams","debouncedQuery","setDebouncedQuery","useState","debouncedSetQuery","useCallback","debounce","newQuery","useEffect","data","rest","useShopActionsPaginatedDataFetching","products","useMemo"],"mappings":";;;;AA4Ca,MAAAA,IAAmB,CAC9BC,MAC4B;AACtB,QAAA,EAAC,kBAAAC,EAAgB,IAAIC,EAAe,GACpC;AAAA,IACJ,OAAAC;AAAA,IACA,SAAAC;AAAA,IACA,QAAAC;AAAA,IACA,kBAAAC,IAAmB;AAAA,IACnB,MAAAC,IAAO;AAAA,IACP,GAAGC;AAAA,EACL,IAAIR,KAAU,CAAC,GAET,CAACS,GAAgBC,CAAiB,IAAIC,EAAiBR,CAAK,GAG5DS,IAAoBC;AAAA,IACxBC,EAAS,CAACC,MAAqB;AAC7B,MAAAL,EAAkBK,CAAQ;AAAA,OACzB,GAAG;AAAA,IACN,CAAA;AAAA,EACF;AAEA,EAAAC,EAAU,OACRJ,EAAkBT,CAAK,GAEhB,MAAM;AACX,IAAAS,EAAkB,OAAO;AAAA,EAC3B,IACC,CAACT,GAAOS,CAAiB,CAAC;AAE7B,QAAM,EAAC,MAAAK,GAAM,GAAGC,EAAA,IAAQC;AAAA,IACtBlB;AAAA,IACA;AAAA,MACE,OAAOQ;AAAA,MACP,SAAAL;AAAA,MACA,QAAAC;AAAA,MACA,kBAAAC;AAAA,MACA,GAAGE;AAAA,IACL;AAAA,IACA;AAAA,MACE,MAAAD;AAAA,MACA,MAAM;AAAA,IAAA;AAAA,EAEV,GAEMa,IAAWC,EAAQ,MACnBZ,EAAe,OAAO,WAAW,IAC5B,OAGFQ,KAAQ,MACd,CAACA,GAAMR,CAAc,CAAC;AAElB,SAAA;AAAA,IACL,GAAGS;AAAA,IACH,UAAAE;AAAA,IACA,UAAUX,MAAmBN;AAAA,EAC/B;AACF;"}