@gem-sdk/core 1.14.0-next.91 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/AddOn.js +18 -1
- package/dist/cjs/components/ComponentWrapper.js +28 -1
- package/dist/cjs/components/ComponentWrapperPreview.js +72 -1
- package/dist/cjs/components/Empty.js +7 -1
- package/dist/cjs/components/Render.js +65 -1
- package/dist/cjs/components/Render.liquid.js +158 -3
- package/dist/cjs/components/RenderBlock.js +54 -1
- package/dist/cjs/components/RenderPreview.js +66 -1
- package/dist/cjs/components/RenderSection.js +23 -1
- package/dist/cjs/components/constant.js +39 -1
- package/dist/cjs/contexts/AddonContext.js +36 -1
- package/dist/cjs/contexts/BuilderComponent.js +34 -1
- package/dist/cjs/contexts/BuilderContext.js +35 -1
- package/dist/cjs/contexts/BuilderPreviewContext.js +370 -1
- package/dist/cjs/contexts/CartLineContext.js +29 -1
- package/dist/cjs/contexts/CollectionContext.js +38 -1
- package/dist/cjs/contexts/ModalContext.js +47 -1
- package/dist/cjs/contexts/ProductContext.js +149 -1
- package/dist/cjs/contexts/ProductListContext.js +32 -1
- package/dist/cjs/contexts/SectionContext.js +53 -1
- package/dist/cjs/contexts/ShopContext.js +70 -1
- package/dist/cjs/graphql/fragments/analytic.generated.js +6 -2
- package/dist/cjs/graphql/fragments/collection-detail.generated.js +6 -2
- package/dist/cjs/graphql/fragments/collection-product.generated.js +6 -2
- package/dist/cjs/graphql/fragments/collection.generated.js +6 -2
- package/dist/cjs/graphql/fragments/custom-code.generated.js +6 -2
- package/dist/cjs/graphql/fragments/data-seo.generated.js +6 -2
- package/dist/cjs/graphql/fragments/media.generated.js +6 -3
- package/dist/cjs/graphql/fragments/product-little.generated.js +6 -2
- package/dist/cjs/graphql/fragments/product-option-value.generated.js +6 -2
- package/dist/cjs/graphql/fragments/product-option.generated.js +6 -2
- package/dist/cjs/graphql/fragments/product.generated.js +6 -2
- package/dist/cjs/graphql/fragments/published-custom-section.generated.js +6 -2
- package/dist/cjs/graphql/fragments/published-page-section.generated.js +6 -2
- package/dist/cjs/graphql/fragments/published-theme-page.generated.js +6 -2
- package/dist/cjs/graphql/fragments/published-theme-style.generated.js +6 -2
- package/dist/cjs/graphql/fragments/selected-option.generated.js +6 -2
- package/dist/cjs/graphql/fragments/variant.generated.js +6 -2
- package/dist/cjs/graphql/mutations/page-view-up.generated.js +7 -3
- package/dist/cjs/graphql/queries/collection-detail-filter.generated.js +16 -2
- package/dist/cjs/graphql/queries/collection.generated.js +14 -2
- package/dist/cjs/graphql/queries/collections.generated.js +9 -2
- package/dist/cjs/graphql/queries/preview-page.generated.js +14 -2
- package/dist/cjs/graphql/queries/product-little-detail.generated.js +11 -2
- package/dist/cjs/graphql/queries/product-medias.generated.js +8 -2
- package/dist/cjs/graphql/queries/product-variants.generated.js +10 -2
- package/dist/cjs/graphql/queries/products.generated.js +17 -3
- package/dist/cjs/graphql/queries/published-theme-pages.generated.js +14 -2
- package/dist/cjs/graphql/queries/store-property.generated.js +6 -2
- package/dist/cjs/helpers/GlobalEvent.js +19 -1
- package/dist/cjs/helpers/background.js +109 -1
- package/dist/cjs/helpers/borders.js +183 -4
- package/dist/cjs/helpers/clone-deep.js +5 -1
- package/dist/cjs/helpers/cls.js +16 -1
- package/dist/cjs/helpers/colors.js +183 -1
- package/dist/cjs/helpers/compose-advance-style.js +188 -1
- package/dist/cjs/helpers/constant.js +23 -1
- package/dist/cjs/helpers/convert.js +7 -1
- package/dist/cjs/helpers/css-variable.js +7 -1
- package/dist/cjs/helpers/email.js +11 -1
- package/dist/cjs/helpers/flatten-connection.js +9 -1
- package/dist/cjs/helpers/get-resonsive-value.js +31 -1
- package/dist/cjs/helpers/get-shortname.js +92 -1
- package/dist/cjs/helpers/is-browser.js +9 -1
- package/dist/cjs/helpers/is-defined.js +7 -1
- package/dist/cjs/helpers/is-empty-children.js +12 -1
- package/dist/cjs/helpers/is-safari.js +9 -1
- package/dist/cjs/helpers/layout.js +59 -1
- package/dist/cjs/helpers/load-script.js +31 -1
- package/dist/cjs/helpers/make-style.js +128 -1
- package/dist/cjs/helpers/normalize-builder-data.js +23 -1
- package/dist/cjs/helpers/prefetch-queries.js +78 -1
- package/dist/cjs/helpers/product.js +45 -1
- package/dist/cjs/helpers/queries/get-collection.js +220 -1
- package/dist/cjs/helpers/queries/get-collections.js +21 -1
- package/dist/cjs/helpers/queries/get-product-by-slug.js +125 -1
- package/dist/cjs/helpers/queries/get-product.js +154 -1
- package/dist/cjs/helpers/queries/get-products.js +161 -1
- package/dist/cjs/helpers/query.js +29 -1
- package/dist/cjs/helpers/radius.js +131 -6
- package/dist/cjs/helpers/render.js +71 -1
- package/dist/cjs/helpers/shadow.js +56 -1
- package/dist/cjs/helpers/size.js +35 -4
- package/dist/cjs/helpers/spacing.js +43 -1
- package/dist/cjs/helpers/tracking/fpixel.js +28 -1
- package/dist/cjs/helpers/tracking/gtag.js +93 -1
- package/dist/cjs/helpers/tracking/tiktokpixel.js +17 -1
- package/dist/cjs/helpers/typography.js +105 -17
- package/dist/cjs/helpers/variant.js +8 -1
- package/dist/cjs/hooks/cart/use-add-to-cart.js +20 -1
- package/dist/cjs/hooks/cart/use-cart-data.js +28 -1
- package/dist/cjs/hooks/cart/use-cart-discount-codes-update.js +20 -1
- package/dist/cjs/hooks/cart/use-cart-note-update.js +20 -1
- package/dist/cjs/hooks/cart/use-create-cart.js +22 -1
- package/dist/cjs/hooks/cart/use-remove-cart-item.js +20 -1
- package/dist/cjs/hooks/cart/use-update-cart-item.js +20 -1
- package/dist/cjs/hooks/shop/use-collection-query.js +22 -1
- package/dist/cjs/hooks/shop/use-collections-query.js +17 -1
- package/dist/cjs/hooks/shop/use-product-query.js +22 -1
- package/dist/cjs/hooks/shop/use-products-query.js +22 -1
- package/dist/cjs/hooks/shop.js +126 -1
- package/dist/cjs/hooks/use-current-device.js +21 -1
- package/dist/cjs/hooks/use-lazy-video.js +15 -1
- package/dist/cjs/hooks/useCartId.js +44 -1
- package/dist/cjs/hooks/useCartLine.js +11 -1
- package/dist/cjs/hooks/useCartUI.js +48 -1
- package/dist/cjs/hooks/useCollection.js +9 -1
- package/dist/cjs/hooks/useFetchHandle.js +13 -1
- package/dist/cjs/hooks/useFormatMoney.js +58 -1
- package/dist/cjs/hooks/useIsomorphicLayoutEffect.js +10 -1
- package/dist/cjs/hooks/useLoadScript.js +32 -1
- package/dist/cjs/hooks/useMoney.js +84 -1
- package/dist/cjs/hooks/usePrevious.js +19 -1
- package/dist/cjs/hooks/useProduct.js +124 -1
- package/dist/cjs/hooks/useProductList.js +21 -1
- package/dist/cjs/hooks/useSuspenseFetch.js +27 -1
- package/dist/cjs/hooks/useSwatchesOptions.js +41 -1
- package/dist/cjs/index.js +291 -1
- package/dist/cjs/types/global-style.js +14 -1
- package/dist/cjs/types/shop.js +2 -1
- package/dist/esm/components/AddOn.js +14 -1
- package/dist/esm/components/ComponentWrapper.js +24 -1
- package/dist/esm/components/ComponentWrapperPreview.js +68 -1
- package/dist/esm/components/Empty.js +3 -1
- package/dist/esm/components/Render.js +61 -1
- package/dist/esm/components/Render.liquid.js +153 -3
- package/dist/esm/components/RenderBlock.js +50 -1
- package/dist/esm/components/RenderPreview.js +62 -1
- package/dist/esm/components/RenderSection.js +19 -1
- package/dist/esm/components/constant.js +37 -1
- package/dist/esm/contexts/AddonContext.js +32 -1
- package/dist/esm/contexts/BuilderComponent.js +31 -1
- package/dist/esm/contexts/BuilderContext.js +32 -1
- package/dist/esm/contexts/BuilderPreviewContext.js +367 -1
- package/dist/esm/contexts/CartLineContext.js +26 -1
- package/dist/esm/contexts/CollectionContext.js +35 -1
- package/dist/esm/contexts/ModalContext.js +44 -1
- package/dist/esm/contexts/ProductContext.js +146 -1
- package/dist/esm/contexts/ProductListContext.js +28 -1
- package/dist/esm/contexts/SectionContext.js +49 -1
- package/dist/esm/contexts/ShopContext.js +67 -1
- package/dist/esm/graphql/fragments/analytic.generated.js +4 -2
- package/dist/esm/graphql/fragments/collection-detail.generated.js +4 -2
- package/dist/esm/graphql/fragments/collection-product.generated.js +4 -2
- package/dist/esm/graphql/fragments/collection.generated.js +4 -2
- package/dist/esm/graphql/fragments/custom-code.generated.js +4 -2
- package/dist/esm/graphql/fragments/data-seo.generated.js +4 -2
- package/dist/esm/graphql/fragments/media.generated.js +4 -3
- package/dist/esm/graphql/fragments/product-little.generated.js +4 -2
- package/dist/esm/graphql/fragments/product-option-value.generated.js +4 -2
- package/dist/esm/graphql/fragments/product-option.generated.js +4 -2
- package/dist/esm/graphql/fragments/product.generated.js +4 -2
- package/dist/esm/graphql/fragments/published-custom-section.generated.js +4 -2
- package/dist/esm/graphql/fragments/published-page-section.generated.js +4 -2
- package/dist/esm/graphql/fragments/published-theme-page.generated.js +4 -2
- package/dist/esm/graphql/fragments/published-theme-style.generated.js +4 -2
- package/dist/esm/graphql/fragments/selected-option.generated.js +4 -2
- package/dist/esm/graphql/fragments/variant.generated.js +4 -2
- package/dist/esm/graphql/mutations/page-view-up.generated.js +5 -3
- package/dist/esm/graphql/queries/collection-detail-filter.generated.js +22 -10
- package/dist/esm/graphql/queries/collection.generated.js +18 -8
- package/dist/esm/graphql/queries/collections.generated.js +8 -3
- package/dist/esm/graphql/queries/preview-page.generated.js +18 -8
- package/dist/esm/graphql/queries/product-little-detail.generated.js +12 -5
- package/dist/esm/graphql/queries/product-medias.generated.js +6 -2
- package/dist/esm/graphql/queries/product-variants.generated.js +10 -4
- package/dist/esm/graphql/queries/products.generated.js +20 -9
- package/dist/esm/graphql/queries/published-theme-pages.generated.js +18 -8
- package/dist/esm/graphql/queries/store-property.generated.js +4 -2
- package/dist/esm/helpers/GlobalEvent.js +15 -1
- package/dist/esm/helpers/background.js +106 -1
- package/dist/esm/helpers/borders.js +175 -4
- package/dist/esm/helpers/clone-deep.js +3 -1
- package/dist/esm/helpers/cls.js +14 -1
- package/dist/esm/helpers/colors.js +168 -1
- package/dist/esm/helpers/compose-advance-style.js +185 -1
- package/dist/esm/helpers/constant.js +19 -1
- package/dist/esm/helpers/convert.js +4 -1
- package/dist/esm/helpers/css-variable.js +5 -1
- package/dist/esm/helpers/email.js +6 -1
- package/dist/esm/helpers/flatten-connection.js +7 -1
- package/dist/esm/helpers/get-resonsive-value.js +27 -1
- package/dist/esm/helpers/get-shortname.js +90 -1
- package/dist/esm/helpers/is-browser.js +5 -1
- package/dist/esm/helpers/is-defined.js +5 -1
- package/dist/esm/helpers/is-empty-children.js +7 -1
- package/dist/esm/helpers/is-safari.js +5 -1
- package/dist/esm/helpers/layout.js +54 -1
- package/dist/esm/helpers/load-script.js +29 -1
- package/dist/esm/helpers/make-style.js +117 -1
- package/dist/esm/helpers/normalize-builder-data.js +21 -1
- package/dist/esm/helpers/prefetch-queries.js +76 -1
- package/dist/esm/helpers/product.js +41 -1
- package/dist/esm/helpers/queries/get-collection.js +217 -1
- package/dist/esm/helpers/queries/get-collections.js +19 -1
- package/dist/esm/helpers/queries/get-product-by-slug.js +123 -1
- package/dist/esm/helpers/queries/get-product.js +150 -1
- package/dist/esm/helpers/queries/get-products.js +159 -1
- package/dist/esm/helpers/query.js +25 -1
- package/dist/esm/helpers/radius.js +124 -6
- package/dist/esm/helpers/render.js +64 -1
- package/dist/esm/helpers/shadow.js +51 -1
- package/dist/esm/helpers/size.js +31 -4
- package/dist/esm/helpers/spacing.js +40 -1
- package/dist/esm/helpers/tracking/fpixel.js +24 -1
- package/dist/esm/helpers/tracking/gtag.js +87 -1
- package/dist/esm/helpers/tracking/tiktokpixel.js +15 -1
- package/dist/esm/helpers/typography.js +96 -17
- package/dist/esm/helpers/variant.js +6 -1
- package/dist/esm/hooks/cart/use-add-to-cart.js +18 -1
- package/dist/esm/hooks/cart/use-cart-data.js +26 -1
- package/dist/esm/hooks/cart/use-cart-discount-codes-update.js +18 -1
- package/dist/esm/hooks/cart/use-cart-note-update.js +18 -1
- package/dist/esm/hooks/cart/use-create-cart.js +20 -1
- package/dist/esm/hooks/cart/use-remove-cart-item.js +18 -1
- package/dist/esm/hooks/cart/use-update-cart-item.js +18 -1
- package/dist/esm/hooks/shop/use-collection-query.js +20 -1
- package/dist/esm/hooks/shop/use-collections-query.js +15 -1
- package/dist/esm/hooks/shop/use-product-query.js +20 -1
- package/dist/esm/hooks/shop/use-products-query.js +20 -1
- package/dist/esm/hooks/shop.js +111 -1
- package/dist/esm/hooks/use-current-device.js +19 -1
- package/dist/esm/hooks/use-lazy-video.js +13 -1
- package/dist/esm/hooks/useCartId.js +40 -1
- package/dist/esm/hooks/useCartLine.js +7 -1
- package/dist/esm/hooks/useCartUI.js +44 -1
- package/dist/esm/hooks/useCollection.js +7 -1
- package/dist/esm/hooks/useFetchHandle.js +11 -1
- package/dist/esm/hooks/useFormatMoney.js +56 -1
- package/dist/esm/hooks/useIsomorphicLayoutEffect.js +6 -1
- package/dist/esm/hooks/useLoadScript.js +28 -1
- package/dist/esm/hooks/useMoney.js +80 -1
- package/dist/esm/hooks/usePrevious.js +17 -1
- package/dist/esm/hooks/useProduct.js +111 -1
- package/dist/esm/hooks/useProductList.js +16 -1
- package/dist/esm/hooks/useSuspenseFetch.js +23 -1
- package/dist/esm/hooks/useSwatchesOptions.js +37 -1
- package/dist/esm/index.js +92 -1
- package/dist/esm/types/global-style.js +11 -1
- package/dist/types/index.d.ts +27 -28
- package/package.json +2 -2
|
@@ -1,17 +1,96 @@
|
|
|
1
|
-
import{getSingleColorVariable
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
${
|
|
12
|
-
${
|
|
13
|
-
${
|
|
14
|
-
${
|
|
15
|
-
${
|
|
16
|
-
${
|
|
17
|
-
|
|
1
|
+
import { getSingleColorVariable } from './colors.js';
|
|
2
|
+
import { removeNullUndefined, makeStyle, makeStyleResponsive } from './make-style.js';
|
|
3
|
+
|
|
4
|
+
const genTypoClass = (name)=>{
|
|
5
|
+
return `g-${name}`;
|
|
6
|
+
};
|
|
7
|
+
const composeTypographyCss = (typography)=>{
|
|
8
|
+
const typographyCustom = typography?.custom;
|
|
9
|
+
const { fontFamily, fontSize, fontStyle, fontWeight, lineHeight, letterSpacing } = typographyCustom?.desktop ?? {};
|
|
10
|
+
return `
|
|
11
|
+
${fontFamily ? `font-family: var(--g-font-${fontFamily}, ${fontFamily});` : ''}
|
|
12
|
+
${fontSize ? `font-size: ${fontSize};` : ''}
|
|
13
|
+
${fontStyle ? `font-style: ${fontStyle};` : ''}
|
|
14
|
+
${fontWeight ? `font-weight: ${fontWeight};` : ''}
|
|
15
|
+
${letterSpacing ? `letter-spacing: ${letterSpacing};` : ''}
|
|
16
|
+
${lineHeight ? `line-height: ${lineHeight};` : ''}
|
|
17
|
+
`;
|
|
18
|
+
};
|
|
19
|
+
const composeTypographyV2Css = (typography)=>{
|
|
20
|
+
const typographyCustom = typography?.custom;
|
|
21
|
+
const { fontFamily, fontSize, fontWeight, lineHeight, letterSpacing } = typographyCustom ?? {};
|
|
22
|
+
const typographyAttrs = typography?.attrs;
|
|
23
|
+
const { bold, italic, underline, transform } = typographyAttrs ?? {};
|
|
24
|
+
return `
|
|
25
|
+
${fontFamily ? `font-family: var(--g-font-${fontFamily}, ${fontFamily});` : ''}
|
|
26
|
+
${fontSize?.desktop ? `font-size: ${fontSize?.desktop};` : ''}
|
|
27
|
+
${bold ? `font-weight: bold;` : fontWeight ? `font-weight: ${fontWeight};` : ''}
|
|
28
|
+
${letterSpacing ? `letter-spacing: ${letterSpacing};` : ''}
|
|
29
|
+
${lineHeight ? `line-height: ${lineHeight};` : ''}
|
|
30
|
+
${italic ? `font-style: italic;` : ''}
|
|
31
|
+
${underline ? `text-decoration-line: underline;` : ''}
|
|
32
|
+
${transform ? `text-transform: ${transform};` : ''}
|
|
33
|
+
`;
|
|
34
|
+
};
|
|
35
|
+
function getCustomCSSByDevice(typography, device) {
|
|
36
|
+
if (!typography || !device) return {};
|
|
37
|
+
const suffix = device === 'desktop' || !device ? '' : `-${device}`;
|
|
38
|
+
const { fontFamily } = typography?.[device] ?? {};
|
|
39
|
+
return {
|
|
40
|
+
[`--size${suffix}`]: typography?.[device]?.fontSize,
|
|
41
|
+
[`--lh${suffix}`]: typography?.[device]?.lineHeight,
|
|
42
|
+
[`--fs${suffix}`]: typography?.[device]?.fontStyle,
|
|
43
|
+
[`--ff${suffix}`]: fontFamily ? `var(--g-font-${fontFamily}, ${fontFamily})` : undefined,
|
|
44
|
+
[`--weight${suffix}`]: typography?.[device]?.fontWeight,
|
|
45
|
+
[`--ls${suffix}`]: typography?.[device]?.letterSpacing
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const composeTypography = (typography)=>{
|
|
49
|
+
if (!typography) return {};
|
|
50
|
+
return removeNullUndefined({
|
|
51
|
+
...getCustomCSSByDevice(typography, 'desktop'),
|
|
52
|
+
...getCustomCSSByDevice(typography, 'tablet'),
|
|
53
|
+
...getCustomCSSByDevice(typography, 'mobile')
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
const composeTypographyV2 = (value, attrs)=>{
|
|
57
|
+
if (!value) return {};
|
|
58
|
+
return removeNullUndefined({
|
|
59
|
+
...makeStyle({
|
|
60
|
+
fs: !attrs?.italic ? value?.fontStyle : undefined,
|
|
61
|
+
ff: value?.fontFamily ? `var(--g-font-${value.fontFamily.replace(/ /g, '-')}, ${value.fontFamily})` : undefined,
|
|
62
|
+
weight: !attrs?.bold ? value?.fontWeight : undefined,
|
|
63
|
+
ls: value?.letterSpacing,
|
|
64
|
+
lh: value?.lineHeight
|
|
65
|
+
}),
|
|
66
|
+
...makeStyleResponsive('size', value?.fontSize)
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
const composeTypographyAttr = (attrs)=>{
|
|
70
|
+
if (!attrs) return {};
|
|
71
|
+
return removeNullUndefined({
|
|
72
|
+
...makeStyle({
|
|
73
|
+
fs: attrs?.italic ? 'italic' : undefined,
|
|
74
|
+
weight: attrs?.bold ? 'bold' : undefined,
|
|
75
|
+
c: getSingleColorVariable(attrs?.color),
|
|
76
|
+
tt: attrs?.transform,
|
|
77
|
+
tdl: attrs?.underline ? 'underline' : undefined
|
|
78
|
+
})
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
const composeTypographyClassName = (typo, typography)=>{
|
|
82
|
+
return typo ? typo?.type && !typo.custom ? genTypoClass(typo.type) : '' : typography?.type && genTypoClass(typography?.type);
|
|
83
|
+
};
|
|
84
|
+
const composeTypographyStyle = (typo, typography, disableAttr)=>{
|
|
85
|
+
if (typo) {
|
|
86
|
+
return {
|
|
87
|
+
...composeTypographyV2(typo.custom, typo.attrs),
|
|
88
|
+
...!disableAttr && composeTypographyAttr(typo.attrs)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
...!typography?.type ? composeTypography(typography?.custom) : {}
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export { composeTypography, composeTypographyAttr, composeTypographyClassName, composeTypographyCss, composeTypographyStyle, composeTypographyV2, composeTypographyV2Css, genTypoClass };
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
function checkInStock(
|
|
1
|
+
function checkInStock(variant) {
|
|
2
|
+
if (!variant) return false;
|
|
3
|
+
return variant?.inventoryQuantity && variant.inventoryQuantity > 0 || !variant?.manageInventory || variant.inventoryPolicy === 'CONTINUE';
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export { checkInStock };
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
import{addToCartOperation
|
|
1
|
+
import { addToCartOperation } from '@gem-sdk/adapter-shopify';
|
|
2
|
+
import { useSWRConfig } from 'swr';
|
|
3
|
+
import useSWRMutation from 'swr/mutation';
|
|
4
|
+
import { useStoreFront } from '../shop.js';
|
|
5
|
+
|
|
6
|
+
const useAddToCart = (options)=>{
|
|
7
|
+
const shop = useStoreFront();
|
|
8
|
+
const { mutate } = useSWRConfig();
|
|
9
|
+
return useSWRMutation('add-to-cart', (_, { arg })=>addToCartOperation(shop)(arg), {
|
|
10
|
+
...options,
|
|
11
|
+
onSuccess: (result, key, config)=>{
|
|
12
|
+
mutate('cart', result, false);
|
|
13
|
+
options?.onSuccess?.(result, key, config);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { useAddToCart };
|
|
@@ -1 +1,26 @@
|
|
|
1
|
-
import{getCartOperation
|
|
1
|
+
import { getCartOperation } from '@gem-sdk/adapter-shopify';
|
|
2
|
+
import useSWR from 'swr';
|
|
3
|
+
import { useStoreFront } from '../shop.js';
|
|
4
|
+
import useCartId from '../useCartId.js';
|
|
5
|
+
|
|
6
|
+
const useCartData = (options)=>{
|
|
7
|
+
const { cartId, clearCartId } = useCartId();
|
|
8
|
+
const shop = useStoreFront();
|
|
9
|
+
return useSWR(cartId ? 'cart' : null, ()=>getCartOperation(shop)({
|
|
10
|
+
cartId: cartId
|
|
11
|
+
}), {
|
|
12
|
+
revalidateOnMount: true,
|
|
13
|
+
revalidateOnFocus: true,
|
|
14
|
+
keepPreviousData: false,
|
|
15
|
+
dedupingInterval: 2000,
|
|
16
|
+
...options,
|
|
17
|
+
onSuccess (data, key, config) {
|
|
18
|
+
if (!data) {
|
|
19
|
+
clearCartId();
|
|
20
|
+
}
|
|
21
|
+
options?.onSuccess?.(data, key, config);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { useCartData };
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
import{cartDiscountCodesUpdateOperation
|
|
1
|
+
import { cartDiscountCodesUpdateOperation } from '@gem-sdk/adapter-shopify';
|
|
2
|
+
import { useSWRConfig } from 'swr';
|
|
3
|
+
import useSWRMutation from 'swr/mutation';
|
|
4
|
+
import { useStoreFront } from '../shop.js';
|
|
5
|
+
|
|
6
|
+
const useCartDiscountCodesUpdate = (options)=>{
|
|
7
|
+
const shop = useStoreFront();
|
|
8
|
+
const { mutate } = useSWRConfig();
|
|
9
|
+
return useSWRMutation('cart-discount-codes-update', (_, { arg })=>cartDiscountCodesUpdateOperation(shop)(arg), {
|
|
10
|
+
...options,
|
|
11
|
+
onSuccess: (result, key, config)=>{
|
|
12
|
+
mutate('cart', result, false);
|
|
13
|
+
options?.onSuccess?.(result, key, config);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { useCartDiscountCodesUpdate };
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
import{cartNoteUpdateOperation
|
|
1
|
+
import { cartNoteUpdateOperation } from '@gem-sdk/adapter-shopify';
|
|
2
|
+
import { useSWRConfig } from 'swr';
|
|
3
|
+
import useSWRMutation from 'swr/mutation';
|
|
4
|
+
import { useStoreFront } from '../shop.js';
|
|
5
|
+
|
|
6
|
+
const useCartNoteUpdate = (options)=>{
|
|
7
|
+
const shop = useStoreFront();
|
|
8
|
+
const { mutate } = useSWRConfig();
|
|
9
|
+
return useSWRMutation('cart-note-update', (_, { arg })=>cartNoteUpdateOperation(shop)(arg), {
|
|
10
|
+
...options,
|
|
11
|
+
onSuccess: (result, key, config)=>{
|
|
12
|
+
mutate('cart', result, false);
|
|
13
|
+
options?.onSuccess?.(result, key, config);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { useCartNoteUpdate };
|
|
@@ -1 +1,20 @@
|
|
|
1
|
-
import{createCartOperation
|
|
1
|
+
import { createCartOperation } from '@gem-sdk/adapter-shopify';
|
|
2
|
+
import { useSWRConfig } from 'swr';
|
|
3
|
+
import useSWRMutation from 'swr/mutation';
|
|
4
|
+
import { useStoreFront } from '../shop.js';
|
|
5
|
+
|
|
6
|
+
const useCreateCart = (options)=>{
|
|
7
|
+
const shop = useStoreFront();
|
|
8
|
+
const { mutate } = useSWRConfig();
|
|
9
|
+
return useSWRMutation('create-cart', (_, { arg })=>{
|
|
10
|
+
return createCartOperation(shop)(arg);
|
|
11
|
+
}, {
|
|
12
|
+
...options,
|
|
13
|
+
onSuccess: (result, key, config)=>{
|
|
14
|
+
mutate('cart', result, false);
|
|
15
|
+
options?.onSuccess?.(result, key, config);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { useCreateCart };
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
import{removeCartItemOperation
|
|
1
|
+
import { removeCartItemOperation } from '@gem-sdk/adapter-shopify';
|
|
2
|
+
import { useSWRConfig } from 'swr';
|
|
3
|
+
import useSWRMutation from 'swr/mutation';
|
|
4
|
+
import { useStoreFront } from '../shop.js';
|
|
5
|
+
|
|
6
|
+
const useRemoveCartItem = (options)=>{
|
|
7
|
+
const shop = useStoreFront();
|
|
8
|
+
const { mutate } = useSWRConfig();
|
|
9
|
+
return useSWRMutation('remove-cart-item', (_, { arg })=>removeCartItemOperation(shop)(arg), {
|
|
10
|
+
...options,
|
|
11
|
+
onSuccess: (result, key, config)=>{
|
|
12
|
+
mutate('cart', result, false);
|
|
13
|
+
options?.onSuccess?.(result, key, config);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { useRemoveCartItem };
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
import{updateCartLineOperation
|
|
1
|
+
import { updateCartLineOperation } from '@gem-sdk/adapter-shopify';
|
|
2
|
+
import { useSWRConfig } from 'swr';
|
|
3
|
+
import useSWRMutation from 'swr/mutation';
|
|
4
|
+
import { useStoreFront } from '../shop.js';
|
|
5
|
+
|
|
6
|
+
const useUpdateCartItem = (options)=>{
|
|
7
|
+
const shop = useStoreFront();
|
|
8
|
+
const { mutate } = useSWRConfig();
|
|
9
|
+
return useSWRMutation('update-cart-item', (_, { arg })=>updateCartLineOperation(shop)(arg), {
|
|
10
|
+
...options,
|
|
11
|
+
onSuccess: (result, key, config)=>{
|
|
12
|
+
mutate('cart', result, false);
|
|
13
|
+
options?.onSuccess?.(result, key, config);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { useUpdateCartItem };
|
|
@@ -1 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import useSWR from 'swr';
|
|
2
|
+
import { getCollection } from '../../helpers/queries/get-collection.js';
|
|
3
|
+
import { useIsSampleProduct, useIsStorefrontProduct } from '../shop.js';
|
|
4
|
+
import { useFetchHandle } from '../useFetchHandle.js';
|
|
5
|
+
import { generateCollectionQueryKey } from '../../helpers/query.js';
|
|
6
|
+
|
|
7
|
+
const useCollectionQuery = (args, options)=>{
|
|
8
|
+
const fetcher = useFetchHandle();
|
|
9
|
+
const isSample = useIsSampleProduct();
|
|
10
|
+
const isStorefront = useIsStorefrontProduct();
|
|
11
|
+
return useSWR(args ? generateCollectionQueryKey({
|
|
12
|
+
...args,
|
|
13
|
+
isSample,
|
|
14
|
+
isStorefront
|
|
15
|
+
}) : null, ([, arg])=>{
|
|
16
|
+
return getCollection(fetcher, arg);
|
|
17
|
+
}, options);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { useCollectionQuery };
|
|
@@ -1 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import useSWR from 'swr';
|
|
2
|
+
import { getCollections } from '../../helpers/queries/get-collections.js';
|
|
3
|
+
import { useFetchHandle } from '../useFetchHandle.js';
|
|
4
|
+
|
|
5
|
+
const useCollectionsQuery = (variable, options)=>{
|
|
6
|
+
const fetcher = useFetchHandle();
|
|
7
|
+
return useSWR(variable ? [
|
|
8
|
+
'query/collections',
|
|
9
|
+
variable
|
|
10
|
+
] : null, async ([, arg])=>{
|
|
11
|
+
return getCollections(fetcher, arg);
|
|
12
|
+
}, options);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { useCollectionsQuery };
|
|
@@ -1 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import useSWR from 'swr';
|
|
2
|
+
import { getProduct } from '../../helpers/queries/get-product.js';
|
|
3
|
+
import { useIsSampleProduct, useIsStorefrontProduct } from '../shop.js';
|
|
4
|
+
import { useFetchHandle } from '../useFetchHandle.js';
|
|
5
|
+
import { generateProductQueryKey } from '../../helpers/query.js';
|
|
6
|
+
|
|
7
|
+
const useProductQuery = (productId, options)=>{
|
|
8
|
+
const fetcher = useFetchHandle();
|
|
9
|
+
const isSample = useIsSampleProduct();
|
|
10
|
+
const isStorefront = useIsStorefrontProduct();
|
|
11
|
+
return useSWR(productId ? generateProductQueryKey({
|
|
12
|
+
id: productId,
|
|
13
|
+
isSample,
|
|
14
|
+
isStorefront
|
|
15
|
+
}) : null, async ([, arg])=>{
|
|
16
|
+
return getProduct(fetcher, arg);
|
|
17
|
+
}, options);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { useProductQuery };
|
|
@@ -1 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import useSWR from 'swr';
|
|
2
|
+
import { getProducts } from '../../helpers/queries/get-products.js';
|
|
3
|
+
import { generateProductsQueryKey } from '../../helpers/query.js';
|
|
4
|
+
import { useIsSampleProduct, useIsStorefrontProduct } from '../shop.js';
|
|
5
|
+
import { useFetchHandle } from '../useFetchHandle.js';
|
|
6
|
+
|
|
7
|
+
const useProductsQuery = (ids, options)=>{
|
|
8
|
+
const fetcher = useFetchHandle();
|
|
9
|
+
const isSample = useIsSampleProduct();
|
|
10
|
+
const isStorefront = useIsStorefrontProduct();
|
|
11
|
+
return useSWR(ids ? generateProductsQueryKey({
|
|
12
|
+
ids,
|
|
13
|
+
isSample,
|
|
14
|
+
isStorefront
|
|
15
|
+
}) : null, async ([, arg])=>{
|
|
16
|
+
return getProducts(fetcher, arg);
|
|
17
|
+
}, options);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { useProductsQuery };
|
package/dist/esm/hooks/shop.js
CHANGED
|
@@ -1 +1,111 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useSWRConfig } from 'swr';
|
|
3
|
+
import { useShopStore } from '../contexts/ShopContext.js';
|
|
4
|
+
|
|
5
|
+
const useLocale = ()=>{
|
|
6
|
+
const locale = useShopStore((state)=>state.locale);
|
|
7
|
+
const changeLocale = useShopStore((state)=>state.changeLocale);
|
|
8
|
+
return useMemo(()=>({
|
|
9
|
+
locale,
|
|
10
|
+
changeLocale
|
|
11
|
+
}), [
|
|
12
|
+
locale,
|
|
13
|
+
changeLocale
|
|
14
|
+
]);
|
|
15
|
+
};
|
|
16
|
+
const useCurrency = ()=>{
|
|
17
|
+
const currency = useShopStore((state)=>state.currency);
|
|
18
|
+
const changeCurrency = useShopStore((state)=>state.changeCurrency);
|
|
19
|
+
return useMemo(()=>({
|
|
20
|
+
currency,
|
|
21
|
+
changeCurrency
|
|
22
|
+
}), [
|
|
23
|
+
currency,
|
|
24
|
+
changeCurrency
|
|
25
|
+
]);
|
|
26
|
+
};
|
|
27
|
+
const useMoneyFormat = ()=>{
|
|
28
|
+
const moneyFormat = useShopStore((state)=>state.moneyFormat);
|
|
29
|
+
const moneyWithCurrencyFormat = useShopStore((state)=>state.moneyWithCurrencyFormat);
|
|
30
|
+
return useMemo(()=>({
|
|
31
|
+
moneyFormat,
|
|
32
|
+
moneyWithCurrencyFormat
|
|
33
|
+
}), [
|
|
34
|
+
moneyFormat,
|
|
35
|
+
moneyWithCurrencyFormat
|
|
36
|
+
]);
|
|
37
|
+
};
|
|
38
|
+
const useSwatches = ()=>{
|
|
39
|
+
const swatches = useShopStore((state)=>state.swatches);
|
|
40
|
+
const changeSwatches = useShopStore((state)=>state.changeSwatches);
|
|
41
|
+
return useMemo(()=>({
|
|
42
|
+
swatches,
|
|
43
|
+
changeSwatches
|
|
44
|
+
}), [
|
|
45
|
+
swatches,
|
|
46
|
+
changeSwatches
|
|
47
|
+
]);
|
|
48
|
+
};
|
|
49
|
+
const usePageType = ()=>{
|
|
50
|
+
const pageType = useShopStore((state)=>state.pageType);
|
|
51
|
+
return useMemo(()=>pageType || 'STATIC', [
|
|
52
|
+
pageType
|
|
53
|
+
]);
|
|
54
|
+
};
|
|
55
|
+
const useStoreFront = ()=>{
|
|
56
|
+
const provider = useShopStore((state)=>state.provider);
|
|
57
|
+
const storefrontToken = useShopStore((state)=>state.storefrontToken);
|
|
58
|
+
const storefrontUrl = useShopStore((state)=>state.storefrontUrl);
|
|
59
|
+
return {
|
|
60
|
+
provider,
|
|
61
|
+
storefrontToken,
|
|
62
|
+
storefrontUrl
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
const usePluginEnable = ()=>{
|
|
66
|
+
return useShopStore((state)=>state.plugins);
|
|
67
|
+
};
|
|
68
|
+
const useEditorMode = ()=>{
|
|
69
|
+
return useShopStore((state)=>state.mode);
|
|
70
|
+
};
|
|
71
|
+
const useMobileOnly = ()=>{
|
|
72
|
+
return useShopStore((state)=>state.mobileOnly);
|
|
73
|
+
};
|
|
74
|
+
const useMatchMutate = ()=>{
|
|
75
|
+
const { cache, mutate } = useSWRConfig();
|
|
76
|
+
return (matcher, opts)=>{
|
|
77
|
+
if (!(cache instanceof Map)) {
|
|
78
|
+
throw new Error('matchMutate requires the cache provider to be a Map instance');
|
|
79
|
+
}
|
|
80
|
+
const keys = [];
|
|
81
|
+
cache.forEach((_, key)=>{
|
|
82
|
+
if (matcher.test(key)) {
|
|
83
|
+
keys.push(key);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
const mutations = keys.map((key)=>{
|
|
87
|
+
const cacheData = cache.get(key);
|
|
88
|
+
return mutate(key, cacheData?.data, opts);
|
|
89
|
+
});
|
|
90
|
+
return Promise.all(mutations);
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
function useConnectedShopify() {
|
|
94
|
+
const { storefrontToken } = useStoreFront();
|
|
95
|
+
return !!storefrontToken;
|
|
96
|
+
}
|
|
97
|
+
function useIsSampleProduct() {
|
|
98
|
+
const { storefrontToken } = useStoreFront();
|
|
99
|
+
const isStorefront = useShopStore((state)=>state.isStorefront);
|
|
100
|
+
return isStorefront && !storefrontToken;
|
|
101
|
+
}
|
|
102
|
+
function useIsStorefrontProduct() {
|
|
103
|
+
return useShopStore((state)=>state.isStorefront);
|
|
104
|
+
}
|
|
105
|
+
function useCheckoutUrl(url) {
|
|
106
|
+
const { storefrontToken } = useStoreFront();
|
|
107
|
+
if (!url) return undefined;
|
|
108
|
+
return storefrontToken ? `${url}?access_token=${storefrontToken}` : url;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export { useCheckoutUrl, useConnectedShopify, useCurrency, useEditorMode, useIsSampleProduct, useIsStorefrontProduct, useLocale, useMatchMutate, useMobileOnly, useMoneyFormat, usePageType, usePluginEnable, useStoreFront, useSwatches };
|
|
@@ -1 +1,19 @@
|
|
|
1
|
-
import{useSyncExternalStore
|
|
1
|
+
import { useSyncExternalStore } from 'react';
|
|
2
|
+
|
|
3
|
+
function subscribe(callback) {
|
|
4
|
+
window.addEventListener('resize', callback);
|
|
5
|
+
return ()=>window.removeEventListener('resize', callback);
|
|
6
|
+
}
|
|
7
|
+
const useCurrentDevice = ()=>{
|
|
8
|
+
return useSyncExternalStore(subscribe, ()=>{
|
|
9
|
+
if (window.innerWidth < 768) {
|
|
10
|
+
return 'mobile';
|
|
11
|
+
} else if (window.innerWidth >= 768 && window.innerWidth < 1024) {
|
|
12
|
+
return 'tablet';
|
|
13
|
+
} else {
|
|
14
|
+
return 'desktop';
|
|
15
|
+
}
|
|
16
|
+
}, ()=>'desktop');
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { useCurrentDevice };
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
import{useEffect
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import LazyLoad from 'vanilla-lazyload';
|
|
3
|
+
|
|
4
|
+
const useLazyVideo = ()=>{
|
|
5
|
+
useEffect(()=>{
|
|
6
|
+
const lazyLoadInstance = new LazyLoad({
|
|
7
|
+
use_native: true
|
|
8
|
+
});
|
|
9
|
+
lazyLoadInstance.update();
|
|
10
|
+
}, []);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { useLazyVideo };
|
|
@@ -1 +1,40 @@
|
|
|
1
|
-
import{useSyncExternalStore
|
|
1
|
+
import { useSyncExternalStore, useCallback, useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
const cartKey = 'cart-id';
|
|
4
|
+
const getCartId = ()=>{
|
|
5
|
+
return window.localStorage.getItem(cartKey);
|
|
6
|
+
};
|
|
7
|
+
const writeCartId = (value)=>{
|
|
8
|
+
if (value) {
|
|
9
|
+
window.localStorage.setItem(cartKey, value);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const removeCartId = ()=>{
|
|
13
|
+
window.localStorage.removeItem(cartKey);
|
|
14
|
+
};
|
|
15
|
+
const subscribeStorage = (callback)=>{
|
|
16
|
+
window.addEventListener('storage', callback);
|
|
17
|
+
return ()=>{
|
|
18
|
+
window.removeEventListener('storage', callback);
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
const useCartId = ()=>{
|
|
22
|
+
const cartId = useSyncExternalStore(subscribeStorage, getCartId, ()=>undefined);
|
|
23
|
+
const updateCartId = useCallback((val)=>{
|
|
24
|
+
writeCartId(val);
|
|
25
|
+
}, []);
|
|
26
|
+
const clearCartId = useCallback(()=>{
|
|
27
|
+
removeCartId();
|
|
28
|
+
}, []);
|
|
29
|
+
return useMemo(()=>({
|
|
30
|
+
cartId,
|
|
31
|
+
updateCartId,
|
|
32
|
+
clearCartId
|
|
33
|
+
}), [
|
|
34
|
+
cartId,
|
|
35
|
+
clearCartId,
|
|
36
|
+
updateCartId
|
|
37
|
+
]);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { useCartId as default };
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
import{useCartLineStore
|
|
1
|
+
import { useCartLineStore } from '../contexts/CartLineContext.js';
|
|
2
|
+
|
|
3
|
+
const useCartLine = ()=>{
|
|
4
|
+
return useCartLineStore((s)=>s.line);
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export { useCartLine as default };
|
|
@@ -1 +1,44 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { create } from 'zustand';
|
|
3
|
+
import { usePluginEnable } from './shop.js';
|
|
4
|
+
|
|
5
|
+
const useStore = create((set)=>({
|
|
6
|
+
isCartOpen: false,
|
|
7
|
+
setOpen: (isCartOpen)=>{
|
|
8
|
+
const scrollBarGap = window.innerWidth - document.documentElement.clientWidth;
|
|
9
|
+
const computedBodyPaddingRight = parseInt(window.getComputedStyle(document.body).getPropertyValue('padding-right'), 10);
|
|
10
|
+
if (isCartOpen) {
|
|
11
|
+
document.body.style.overflow = `hidden`;
|
|
12
|
+
document.body.style.paddingRight = `${computedBodyPaddingRight + scrollBarGap}px`;
|
|
13
|
+
} else {
|
|
14
|
+
document.body.style.overflow = '';
|
|
15
|
+
document.body.style.paddingRight = '';
|
|
16
|
+
}
|
|
17
|
+
set({
|
|
18
|
+
isCartOpen
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}));
|
|
22
|
+
function useCartUI() {
|
|
23
|
+
const plugins = usePluginEnable();
|
|
24
|
+
const isCartOpen = useStore((s)=>s.isCartOpen);
|
|
25
|
+
const setOpen = useStore((s)=>s.setOpen);
|
|
26
|
+
const openCart = useCallback(()=>{
|
|
27
|
+
if (plugins?.includes('cart-drawer')) {
|
|
28
|
+
setOpen(true);
|
|
29
|
+
}
|
|
30
|
+
}, [
|
|
31
|
+
plugins,
|
|
32
|
+
setOpen
|
|
33
|
+
]);
|
|
34
|
+
const closeCart = useCallback(()=>setOpen(false), [
|
|
35
|
+
setOpen
|
|
36
|
+
]);
|
|
37
|
+
return {
|
|
38
|
+
isCartOpen,
|
|
39
|
+
openCart,
|
|
40
|
+
closeCart
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { useCartUI as default };
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
import{useCollectionStore
|
|
1
|
+
import { useCollectionStore } from '../contexts/CollectionContext.js';
|
|
2
|
+
|
|
3
|
+
const useCollection = ()=>{
|
|
4
|
+
return useCollectionStore((s)=>s.collection);
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export { useCollection };
|
|
@@ -1 +1,11 @@
|
|
|
1
|
-
import{useSWRConfig
|
|
1
|
+
import { useSWRConfig } from 'swr';
|
|
2
|
+
|
|
3
|
+
const useFetchHandle = ()=>{
|
|
4
|
+
const { fetcher } = useSWRConfig();
|
|
5
|
+
if (!fetcher) {
|
|
6
|
+
throw new Error('Application must be init within a fetcher');
|
|
7
|
+
}
|
|
8
|
+
return fetcher;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { useFetchHandle };
|