@gem-sdk/core 1.38.0 → 2.0.0-dev.832
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 +1 -18
- package/dist/cjs/components/ComponentToolbarPreview.js +1 -465
- package/dist/cjs/components/ComponentWrapper.js +1 -46
- package/dist/cjs/components/ComponentWrapperPreview.js +1 -136
- package/dist/cjs/components/Empty.js +1 -7
- package/dist/cjs/components/Render.js +1 -65
- package/dist/cjs/components/Render.liquid.js +14 -288
- package/dist/cjs/components/RenderBlock.js +1 -54
- package/dist/cjs/components/RenderCustomCode.js +3 -56
- package/dist/cjs/components/RenderPreview.js +1 -66
- package/dist/cjs/components/RenderSection.js +1 -23
- package/dist/cjs/components/ai-generator/AIContentGenerator.js +1 -0
- package/dist/cjs/components/ai-generator/AIGenContentLoading.js +1 -0
- package/dist/cjs/components/ai-generator/components/PickProduct.js +1 -0
- package/dist/cjs/components/ai-generator/components/ToneAndVoice.js +1 -0
- package/dist/cjs/components/ai-generator/hooks/useGettingGenerateRequest.js +1 -0
- package/dist/cjs/components/ai-generator/hooks/useListenEventGenerate.js +1 -0
- package/dist/cjs/components/ai-generator/icons/AIIcon.js +1 -0
- package/dist/cjs/components/ai-generator/icons/CloseIcon.js +1 -0
- package/dist/cjs/components/ai-generator/icons/DropdownIcon.js +1 -0
- package/dist/cjs/components/ai-generator/icons/ShowMoreIcon.js +1 -0
- package/dist/cjs/components/animation/AnimationWrapper.js +1 -0
- package/dist/cjs/components/constant.js +1 -54
- package/dist/cjs/components/resize/Resize.js +1 -16
- package/dist/cjs/components/resize/Spacing.js +1 -248
- package/dist/cjs/components/src/product/helpers/variant-presets.js +1 -56
- package/dist/cjs/components/theme-section/CreateThemeSection.js +1 -117
- package/dist/cjs/components/theme-section/ThemeSectionStatus.js +1 -36
- package/dist/cjs/components/theme-section/ThemeSectionTooltip.js +1 -102
- package/dist/cjs/components/toolbar/Tooltip.js +1 -22
- package/dist/cjs/contexts/AddonContext.js +1 -36
- package/dist/cjs/contexts/BuilderComponent.js +1 -34
- package/dist/cjs/contexts/BuilderContext.js +1 -35
- package/dist/cjs/contexts/BuilderPreviewContext.js +1 -479
- package/dist/cjs/contexts/CartLineContext.js +1 -29
- package/dist/cjs/contexts/CollectionContext.js +1 -38
- package/dist/cjs/contexts/ModalContext.js +1 -47
- package/dist/cjs/contexts/PageContext.js +1 -44
- package/dist/cjs/contexts/ProductContext.js +1 -156
- package/dist/cjs/contexts/ProductListContext.js +1 -32
- package/dist/cjs/contexts/SectionContext.js +1 -53
- package/dist/cjs/contexts/ShopContext.js +1 -80
- package/dist/cjs/graphql/fragments/analytic.generated.js +2 -6
- package/dist/cjs/graphql/fragments/collection-detail.generated.js +2 -6
- package/dist/cjs/graphql/fragments/collection-product.generated.js +2 -6
- package/dist/cjs/graphql/fragments/collection.generated.js +2 -6
- package/dist/cjs/graphql/fragments/custom-code.generated.js +2 -6
- package/dist/cjs/graphql/fragments/custom-font.generated.js +2 -6
- package/dist/cjs/graphql/fragments/data-seo.generated.js +2 -6
- package/dist/cjs/graphql/fragments/media.generated.js +2 -6
- package/dist/cjs/graphql/fragments/product-little.generated.js +11 -6
- package/dist/cjs/graphql/fragments/product-option-value.generated.js +2 -6
- package/dist/cjs/graphql/fragments/product-option.generated.js +2 -6
- package/dist/cjs/graphql/fragments/product.generated.js +11 -6
- package/dist/cjs/graphql/fragments/published-custom-section.generated.js +2 -6
- package/dist/cjs/graphql/fragments/published-page-section.generated.js +2 -6
- package/dist/cjs/graphql/fragments/published-theme-page.generated.js +3 -9
- package/dist/cjs/graphql/fragments/published-theme-style.generated.js +2 -6
- package/dist/cjs/graphql/fragments/selected-option.generated.js +2 -6
- package/dist/cjs/graphql/fragments/variant.generated.js +2 -6
- package/dist/cjs/graphql/mutations/page-view-up.generated.js +3 -7
- package/dist/cjs/graphql/queries/collection-detail-filter.generated.js +2 -16
- package/dist/cjs/graphql/queries/collection.generated.js +2 -14
- package/dist/cjs/graphql/queries/collections.generated.js +2 -9
- package/dist/cjs/graphql/queries/preview-page.generated.js +2 -14
- package/dist/cjs/graphql/queries/product-little-detail.generated.js +2 -11
- package/dist/cjs/graphql/queries/product-medias.generated.js +2 -8
- package/dist/cjs/graphql/queries/product-value-label.generated.js +2 -6
- package/dist/cjs/graphql/queries/product-variants.generated.js +2 -10
- package/dist/cjs/graphql/queries/products.generated.js +12 -17
- package/dist/cjs/graphql/queries/published-theme-pages.generated.js +2 -15
- package/dist/cjs/graphql/queries/store-property.generated.js +2 -6
- package/dist/cjs/graphql-app-api/queries/LibraryTemplate.generated.js +13 -0
- package/dist/cjs/graphql-app-api/queries/SaleFunnelDiscounts.generated.js +34 -0
- package/dist/cjs/graphql-app-api/queries/ThemePage.generated.js +22 -0
- package/dist/cjs/helpers/GlobalEvent.js +1 -19
- package/dist/cjs/helpers/animations.js +1 -213
- package/dist/cjs/helpers/background.js +1 -230
- package/dist/cjs/helpers/borders.js +4 -183
- package/dist/cjs/helpers/carousel.js +1 -58
- package/dist/cjs/helpers/clone-deep.js +1 -5
- package/dist/cjs/helpers/cls.js +1 -16
- package/dist/cjs/helpers/colors.js +1 -184
- package/dist/cjs/helpers/compose-advance-style.js +1 -268
- package/dist/cjs/helpers/constant.js +1 -23
- package/dist/cjs/helpers/convert.js +1 -7
- package/dist/cjs/helpers/covert-entities-html.js +1 -19
- package/dist/cjs/helpers/css-variable.js +1 -7
- package/dist/cjs/helpers/email.js +1 -11
- package/dist/cjs/helpers/filter-toolbar-preview.js +1 -14
- package/dist/cjs/helpers/flatten-connection.js +1 -9
- package/dist/cjs/helpers/get-resonsive-value.js +1 -36
- package/dist/cjs/helpers/get-shortname.js +1 -92
- package/dist/cjs/helpers/icon-list.js +1 -61
- package/dist/cjs/helpers/is-browser.js +1 -9
- package/dist/cjs/helpers/is-defined.js +1 -7
- package/dist/cjs/helpers/is-empty-children.js +1 -15
- package/dist/cjs/helpers/is-safari.js +1 -9
- package/dist/cjs/helpers/layout.js +1 -59
- package/dist/cjs/helpers/load-script.js +1 -31
- package/dist/cjs/helpers/make-style.js +1 -163
- package/dist/cjs/helpers/normalize-builder-data.js +1 -23
- package/dist/cjs/helpers/prefetch-queries.js +1 -78
- package/dist/cjs/helpers/product.js +1 -48
- package/dist/cjs/helpers/queries/get-collection.js +1 -226
- package/dist/cjs/helpers/queries/get-collections.js +1 -21
- package/dist/cjs/helpers/queries/get-product-by-slug.js +1 -125
- package/dist/cjs/helpers/queries/get-product.js +1 -154
- package/dist/cjs/helpers/queries/get-products.js +1 -163
- package/dist/cjs/helpers/query.js +1 -29
- package/dist/cjs/helpers/radius.js +6 -140
- package/dist/cjs/helpers/render.js +1 -76
- package/dist/cjs/helpers/shadow.js +1 -57
- package/dist/cjs/helpers/size.js +4 -183
- package/dist/cjs/helpers/spacing.js +1 -43
- package/dist/cjs/helpers/tracking/fpixel.js +1 -28
- package/dist/cjs/helpers/tracking/gtag.js +1 -93
- package/dist/cjs/helpers/tracking/tiktokpixel.js +1 -17
- package/dist/cjs/helpers/typography.js +17 -126
- package/dist/cjs/helpers/variant.js +1 -11
- package/dist/cjs/hooks/animation/animations.js +1 -0
- package/dist/cjs/hooks/animation/useAnimationActions.js +1 -39
- package/dist/cjs/hooks/animation/useAnimationConfig.js +1 -29
- package/dist/cjs/hooks/animation/useAnimationPreview.js +1 -31
- package/dist/cjs/hooks/animation/useAnimationTarget.js +1 -120
- package/dist/cjs/hooks/animation/useApplyAnimation.js +1 -87
- package/dist/cjs/hooks/animation/useLivePageAnimation.js +1 -0
- package/dist/cjs/hooks/cart/use-add-to-cart.js +1 -20
- package/dist/cjs/hooks/cart/use-cart-data.js +1 -28
- package/dist/cjs/hooks/cart/use-cart-discount-codes-update.js +1 -20
- package/dist/cjs/hooks/cart/use-cart-note-update.js +1 -20
- package/dist/cjs/hooks/cart/use-create-cart.js +1 -22
- package/dist/cjs/hooks/cart/use-remove-cart-item.js +1 -20
- package/dist/cjs/hooks/cart/use-update-cart-item.js +1 -20
- package/dist/cjs/hooks/shop/use-collection-query.js +1 -22
- package/dist/cjs/hooks/shop/use-collections-query.js +1 -17
- package/dist/cjs/hooks/shop/use-product-query.js +1 -22
- package/dist/cjs/hooks/shop/use-products-query.js +1 -23
- package/dist/cjs/hooks/shop.js +1 -126
- package/dist/cjs/hooks/use-current-device.js +1 -21
- package/dist/cjs/hooks/use-lazy-video.js +1 -15
- package/dist/cjs/hooks/useAnimations.js +1 -26
- package/dist/cjs/hooks/useCartId.js +1 -44
- package/dist/cjs/hooks/useCartLine.js +1 -11
- package/dist/cjs/hooks/useCartUI.js +1 -48
- package/dist/cjs/hooks/useCollection.js +1 -9
- package/dist/cjs/hooks/useFetchHandle.js +1 -13
- package/dist/cjs/hooks/useFormatMoney.js +1 -58
- package/dist/cjs/hooks/useInitialSwatchesOptions.js +1 -113
- package/dist/cjs/hooks/useIsomorphicLayoutEffect.js +1 -10
- package/dist/cjs/hooks/useLoadScript.js +1 -32
- package/dist/cjs/hooks/useMoney.js +1 -84
- package/dist/cjs/hooks/usePrevious.js +1 -19
- package/dist/cjs/hooks/useProduct.js +1 -206
- package/dist/cjs/hooks/useProductList.js +1 -21
- package/dist/cjs/hooks/useSuspenseFetch.js +1 -27
- package/dist/cjs/hooks/useSwatchesOptions.js +1 -41
- package/dist/cjs/hooks/useToolbarPostPurchase.js +1 -0
- package/dist/cjs/index.js +1 -361
- package/dist/cjs/types/animations.js +1 -47
- package/dist/cjs/types/appAPI.js +1 -0
- package/dist/cjs/types/global-style.js +1 -15
- package/dist/cjs/types/shop.js +1 -2
- package/dist/cjs/web-components/src/helpers/styles/constant.js +1 -9
- package/dist/esm/components/AddOn.js +1 -14
- package/dist/esm/components/ComponentToolbarPreview.js +1 -463
- package/dist/esm/components/ComponentWrapper.js +1 -42
- package/dist/esm/components/ComponentWrapperPreview.js +1 -132
- package/dist/esm/components/Empty.js +1 -3
- package/dist/esm/components/Render.js +1 -61
- package/dist/esm/components/Render.liquid.js +14 -282
- package/dist/esm/components/RenderBlock.js +1 -50
- package/dist/esm/components/RenderCustomCode.js +3 -52
- package/dist/esm/components/RenderPreview.js +1 -62
- package/dist/esm/components/RenderSection.js +1 -19
- package/dist/esm/components/ai-generator/AIContentGenerator.js +1 -0
- package/dist/esm/components/ai-generator/AIGenContentLoading.js +1 -0
- package/dist/esm/components/ai-generator/components/PickProduct.js +1 -0
- package/dist/esm/components/ai-generator/components/ToneAndVoice.js +1 -0
- package/dist/esm/components/ai-generator/hooks/useGettingGenerateRequest.js +1 -0
- package/dist/esm/components/ai-generator/hooks/useListenEventGenerate.js +1 -0
- package/dist/esm/components/ai-generator/icons/AIIcon.js +1 -0
- package/dist/esm/components/ai-generator/icons/CloseIcon.js +1 -0
- package/dist/esm/components/ai-generator/icons/DropdownIcon.js +1 -0
- package/dist/esm/components/ai-generator/icons/ShowMoreIcon.js +1 -0
- package/dist/esm/components/animation/AnimationWrapper.js +1 -0
- package/dist/esm/components/constant.js +1 -50
- package/dist/esm/components/resize/Resize.js +1 -12
- package/dist/esm/components/resize/Spacing.js +1 -244
- package/dist/esm/components/src/product/helpers/variant-presets.js +1 -54
- package/dist/esm/components/theme-section/CreateThemeSection.js +1 -115
- package/dist/esm/components/theme-section/ThemeSectionStatus.js +1 -34
- package/dist/esm/components/theme-section/ThemeSectionTooltip.js +1 -100
- package/dist/esm/components/toolbar/Tooltip.js +1 -18
- package/dist/esm/contexts/AddonContext.js +1 -32
- package/dist/esm/contexts/BuilderComponent.js +1 -31
- package/dist/esm/contexts/BuilderContext.js +1 -32
- package/dist/esm/contexts/BuilderPreviewContext.js +1 -476
- package/dist/esm/contexts/CartLineContext.js +1 -26
- package/dist/esm/contexts/CollectionContext.js +1 -35
- package/dist/esm/contexts/ModalContext.js +1 -44
- package/dist/esm/contexts/PageContext.js +1 -41
- package/dist/esm/contexts/ProductContext.js +1 -153
- package/dist/esm/contexts/ProductListContext.js +1 -28
- package/dist/esm/contexts/SectionContext.js +1 -49
- package/dist/esm/contexts/ShopContext.js +1 -77
- package/dist/esm/graphql/fragments/analytic.generated.js +2 -4
- package/dist/esm/graphql/fragments/collection-detail.generated.js +2 -4
- package/dist/esm/graphql/fragments/collection-product.generated.js +2 -4
- package/dist/esm/graphql/fragments/collection.generated.js +2 -4
- package/dist/esm/graphql/fragments/custom-code.generated.js +2 -4
- package/dist/esm/graphql/fragments/custom-font.generated.js +2 -4
- package/dist/esm/graphql/fragments/data-seo.generated.js +2 -4
- package/dist/esm/graphql/fragments/media.generated.js +2 -4
- package/dist/esm/graphql/fragments/product-little.generated.js +11 -4
- package/dist/esm/graphql/fragments/product-option-value.generated.js +2 -4
- package/dist/esm/graphql/fragments/product-option.generated.js +2 -4
- package/dist/esm/graphql/fragments/product.generated.js +11 -4
- package/dist/esm/graphql/fragments/published-custom-section.generated.js +2 -4
- package/dist/esm/graphql/fragments/published-page-section.generated.js +2 -4
- package/dist/esm/graphql/fragments/published-theme-page.generated.js +3 -6
- package/dist/esm/graphql/fragments/published-theme-style.generated.js +2 -4
- package/dist/esm/graphql/fragments/selected-option.generated.js +2 -4
- package/dist/esm/graphql/fragments/variant.generated.js +2 -4
- package/dist/esm/graphql/mutations/page-view-up.generated.js +3 -5
- package/dist/esm/graphql/queries/collection-detail-filter.generated.js +10 -22
- package/dist/esm/graphql/queries/collection.generated.js +8 -18
- package/dist/esm/graphql/queries/collections.generated.js +3 -8
- package/dist/esm/graphql/queries/preview-page.generated.js +8 -18
- package/dist/esm/graphql/queries/product-little-detail.generated.js +5 -12
- package/dist/esm/graphql/queries/product-medias.generated.js +2 -6
- package/dist/esm/graphql/queries/product-value-label.generated.js +2 -4
- package/dist/esm/graphql/queries/product-variants.generated.js +4 -10
- package/dist/esm/graphql/queries/products.generated.js +18 -20
- package/dist/esm/graphql/queries/published-theme-pages.generated.js +9 -20
- package/dist/esm/graphql/queries/store-property.generated.js +2 -4
- package/dist/esm/graphql-app-api/queries/LibraryTemplate.generated.js +13 -0
- package/dist/esm/graphql-app-api/queries/SaleFunnelDiscounts.generated.js +34 -0
- package/dist/esm/graphql-app-api/queries/ThemePage.generated.js +22 -0
- package/dist/esm/helpers/GlobalEvent.js +1 -15
- package/dist/esm/helpers/animations.js +1 -211
- package/dist/esm/helpers/background.js +1 -222
- package/dist/esm/helpers/borders.js +4 -175
- package/dist/esm/helpers/carousel.js +1 -54
- package/dist/esm/helpers/clone-deep.js +1 -3
- package/dist/esm/helpers/cls.js +1 -14
- package/dist/esm/helpers/colors.js +1 -169
- package/dist/esm/helpers/compose-advance-style.js +1 -261
- package/dist/esm/helpers/constant.js +1 -19
- package/dist/esm/helpers/convert.js +1 -4
- package/dist/esm/helpers/covert-entities-html.js +1 -17
- package/dist/esm/helpers/css-variable.js +1 -5
- package/dist/esm/helpers/email.js +1 -6
- package/dist/esm/helpers/filter-toolbar-preview.js +1 -9
- package/dist/esm/helpers/flatten-connection.js +1 -7
- package/dist/esm/helpers/get-resonsive-value.js +1 -31
- package/dist/esm/helpers/get-shortname.js +1 -90
- package/dist/esm/helpers/icon-list.js +1 -58
- package/dist/esm/helpers/is-browser.js +1 -5
- package/dist/esm/helpers/is-defined.js +1 -5
- package/dist/esm/helpers/is-empty-children.js +1 -10
- package/dist/esm/helpers/is-safari.js +1 -5
- package/dist/esm/helpers/layout.js +1 -54
- package/dist/esm/helpers/load-script.js +1 -29
- package/dist/esm/helpers/make-style.js +1 -149
- package/dist/esm/helpers/normalize-builder-data.js +1 -21
- package/dist/esm/helpers/prefetch-queries.js +1 -76
- package/dist/esm/helpers/product.js +1 -44
- package/dist/esm/helpers/queries/get-collection.js +1 -223
- package/dist/esm/helpers/queries/get-collections.js +1 -19
- package/dist/esm/helpers/queries/get-product-by-slug.js +1 -123
- package/dist/esm/helpers/queries/get-product.js +1 -150
- package/dist/esm/helpers/queries/get-products.js +1 -161
- package/dist/esm/helpers/query.js +1 -25
- package/dist/esm/helpers/radius.js +6 -132
- package/dist/esm/helpers/render.js +1 -68
- package/dist/esm/helpers/shadow.js +1 -52
- package/dist/esm/helpers/size.js +4 -171
- package/dist/esm/helpers/spacing.js +1 -40
- package/dist/esm/helpers/tracking/fpixel.js +1 -24
- package/dist/esm/helpers/tracking/gtag.js +1 -87
- package/dist/esm/helpers/tracking/tiktokpixel.js +1 -15
- package/dist/esm/helpers/typography.js +17 -116
- package/dist/esm/helpers/variant.js +1 -9
- package/dist/esm/hooks/animation/animations.js +1 -0
- package/dist/esm/hooks/animation/useAnimationActions.js +1 -37
- package/dist/esm/hooks/animation/useAnimationConfig.js +1 -27
- package/dist/esm/hooks/animation/useAnimationPreview.js +1 -29
- package/dist/esm/hooks/animation/useAnimationTarget.js +1 -118
- package/dist/esm/hooks/animation/useApplyAnimation.js +1 -83
- package/dist/esm/hooks/animation/useLivePageAnimation.js +1 -0
- package/dist/esm/hooks/cart/use-add-to-cart.js +1 -18
- package/dist/esm/hooks/cart/use-cart-data.js +1 -26
- package/dist/esm/hooks/cart/use-cart-discount-codes-update.js +1 -18
- package/dist/esm/hooks/cart/use-cart-note-update.js +1 -18
- package/dist/esm/hooks/cart/use-create-cart.js +1 -20
- package/dist/esm/hooks/cart/use-remove-cart-item.js +1 -18
- package/dist/esm/hooks/cart/use-update-cart-item.js +1 -18
- package/dist/esm/hooks/shop/use-collection-query.js +1 -20
- package/dist/esm/hooks/shop/use-collections-query.js +1 -15
- package/dist/esm/hooks/shop/use-product-query.js +1 -20
- package/dist/esm/hooks/shop/use-products-query.js +1 -21
- package/dist/esm/hooks/shop.js +1 -111
- package/dist/esm/hooks/use-current-device.js +1 -19
- package/dist/esm/hooks/use-lazy-video.js +1 -13
- package/dist/esm/hooks/useAnimations.js +1 -24
- package/dist/esm/hooks/useCartId.js +1 -40
- package/dist/esm/hooks/useCartLine.js +1 -7
- package/dist/esm/hooks/useCartUI.js +1 -44
- package/dist/esm/hooks/useCollection.js +1 -7
- package/dist/esm/hooks/useFetchHandle.js +1 -11
- package/dist/esm/hooks/useFormatMoney.js +1 -56
- package/dist/esm/hooks/useInitialSwatchesOptions.js +1 -109
- package/dist/esm/hooks/useIsomorphicLayoutEffect.js +1 -6
- package/dist/esm/hooks/useLoadScript.js +1 -28
- package/dist/esm/hooks/useMoney.js +1 -80
- package/dist/esm/hooks/usePrevious.js +1 -17
- package/dist/esm/hooks/useProduct.js +1 -192
- package/dist/esm/hooks/useProductList.js +1 -16
- package/dist/esm/hooks/useSuspenseFetch.js +1 -23
- package/dist/esm/hooks/useSwatchesOptions.js +1 -37
- package/dist/esm/hooks/useToolbarPostPurchase.js +1 -0
- package/dist/esm/index.js +1 -100
- package/dist/esm/types/animations.js +1 -47
- package/dist/esm/types/appAPI.js +1 -0
- package/dist/esm/types/global-style.js +1 -12
- package/dist/esm/web-components/src/helpers/styles/constant.js +1 -7
- package/dist/types/index.d.ts +24803 -6239
- package/package.json +8 -3
|
@@ -1,18 +1 @@
|
|
|
1
|
-
import
|
|
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
|
+
import{addToCartOperation as r}from"@gem-sdk/adapter-shopify";import{useSWRConfig as o}from"swr";import t from"swr/mutation";import{useStoreFront as s}from"../shop.js";let useAddToCart=e=>{let m=s(),{mutate:a}=o();return t("add-to-cart",(o,{arg:t})=>r(m)(t),{...e,onSuccess:(r,o,t)=>{a("cart",r,!1),e?.onSuccess?.(r,o,t)}})};export{useAddToCart};
|
|
@@ -1,26 +1 @@
|
|
|
1
|
-
import
|
|
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
|
+
import{getCartOperation as r}from"@gem-sdk/adapter-shopify";import e from"swr";import{useStoreFront as t}from"../shop.js";import a from"../useCartId.js";let useCartData=o=>{let{cartId:s,clearCartId:u}=a(),p=t();return e(s?"cart":null,()=>r(p)({cartId:s}),{revalidateOnMount:!0,revalidateOnFocus:!0,keepPreviousData:!1,dedupingInterval:2e3,...o,onSuccess(r,e,t){r||u(),o?.onSuccess?.(r,e,t)}})};export{useCartData};
|
|
@@ -1,18 +1 @@
|
|
|
1
|
-
import
|
|
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
|
+
import{cartDiscountCodesUpdateOperation as t}from"@gem-sdk/adapter-shopify";import{useSWRConfig as o}from"swr";import r from"swr/mutation";import{useStoreFront as s}from"../shop.js";let useCartDiscountCodesUpdate=e=>{let p=s(),{mutate:a}=o();return r("cart-discount-codes-update",(o,{arg:r})=>t(p)(r),{...e,onSuccess:(t,o,r)=>{a("cart",t,!1),e?.onSuccess?.(t,o,r)}})};export{useCartDiscountCodesUpdate};
|
|
@@ -1,18 +1 @@
|
|
|
1
|
-
import
|
|
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
|
+
import{cartNoteUpdateOperation as t}from"@gem-sdk/adapter-shopify";import{useSWRConfig as r}from"swr";import o from"swr/mutation";import{useStoreFront as e}from"../shop.js";let useCartNoteUpdate=s=>{let p=e(),{mutate:a}=r();return o("cart-note-update",(r,{arg:o})=>t(p)(o),{...s,onSuccess:(t,r,o)=>{a("cart",t,!1),s?.onSuccess?.(t,r,o)}})};export{useCartNoteUpdate};
|
|
@@ -1,20 +1 @@
|
|
|
1
|
-
import
|
|
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
|
+
import{createCartOperation as r}from"@gem-sdk/adapter-shopify";import{useSWRConfig as t}from"swr";import e from"swr/mutation";import{useStoreFront as o}from"../shop.js";let useCreateCart=s=>{let a=o(),{mutate:m}=t();return e("create-cart",(t,{arg:e})=>r(a)(e),{...s,onSuccess:(r,t,e)=>{m("cart",r,!1),s?.onSuccess?.(r,t,e)}})};export{useCreateCart};
|
|
@@ -1,18 +1 @@
|
|
|
1
|
-
import
|
|
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
|
+
import{removeCartItemOperation as e}from"@gem-sdk/adapter-shopify";import{useSWRConfig as r}from"swr";import t from"swr/mutation";import{useStoreFront as o}from"../shop.js";let useRemoveCartItem=m=>{let s=o(),{mutate:p}=r();return t("remove-cart-item",(r,{arg:t})=>e(s)(t),{...m,onSuccess:(e,r,t)=>{p("cart",e,!1),m?.onSuccess?.(e,r,t)}})};export{useRemoveCartItem};
|
|
@@ -1,18 +1 @@
|
|
|
1
|
-
import
|
|
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
|
+
import{updateCartLineOperation as t}from"@gem-sdk/adapter-shopify";import{useSWRConfig as r}from"swr";import e from"swr/mutation";import{useStoreFront as o}from"../shop.js";let useUpdateCartItem=m=>{let s=o(),{mutate:p}=r();return e("update-cart-item",(r,{arg:e})=>t(s)(e),{...m,onSuccess:(t,r,e)=>{p("cart",t,!1),m?.onSuccess?.(t,r,e)}})};export{useUpdateCartItem};
|
|
@@ -1,20 +1 @@
|
|
|
1
|
-
import
|
|
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
|
+
import e from"swr";import{getCollection as r}from"../../helpers/queries/get-collection.js";import{useIsSampleProduct as o,useIsStorefrontProduct as t}from"../shop.js";import{useFetchHandle as l}from"../useFetchHandle.js";import{generateCollectionQueryKey as s}from"../../helpers/query.js";let useCollectionQuery=(m,i)=>{let p=l(),u=o(),n=t();return e(m?s({...m,isSample:u,isStorefront:n}):null,([,e])=>r(p,e),i)};export{useCollectionQuery};
|
|
@@ -1,15 +1 @@
|
|
|
1
|
-
import
|
|
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
|
+
import e from"swr";import{getCollections as o}from"../../helpers/queries/get-collections.js";import{useFetchHandle as r}from"../useFetchHandle.js";let useCollectionsQuery=(l,s)=>{let t=r();return e(l?["query/collections",l]:null,async([,e])=>o(t,e),s)};export{useCollectionsQuery};
|
|
@@ -1,20 +1 @@
|
|
|
1
|
-
import
|
|
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
|
+
import r from"swr";import{getProduct as e}from"../../helpers/queries/get-product.js";import{useIsSampleProduct as o,useIsStorefrontProduct as t}from"../shop.js";import{useFetchHandle as s}from"../useFetchHandle.js";import{generateProductQueryKey as u}from"../../helpers/query.js";let useProductQuery=(m,p)=>{let i=s(),l=o(),c=t();return r(m?u({id:m,isSample:l,isStorefront:c}):null,async([,r])=>e(i,r),p)};export{useProductQuery};
|
|
@@ -1,21 +1 @@
|
|
|
1
|
-
import
|
|
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, defaultSelectedProductCount)=>{
|
|
8
|
-
const fetcher = useFetchHandle();
|
|
9
|
-
const isSample = useIsSampleProduct();
|
|
10
|
-
const isStorefront = useIsStorefrontProduct();
|
|
11
|
-
return useSWR(ids ? generateProductsQueryKey({
|
|
12
|
-
ids,
|
|
13
|
-
isSample,
|
|
14
|
-
isStorefront,
|
|
15
|
-
defaultSelectedProductCount
|
|
16
|
-
}) : null, async ([, arg])=>{
|
|
17
|
-
return getProducts(fetcher, arg);
|
|
18
|
-
}, options);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export { useProductsQuery };
|
|
1
|
+
import e from"swr";import{getProducts as r,getProductQueryAll as t}from"../../helpers/queries/get-products.js";import{generateProductsQueryKey as u}from"../../helpers/query.js";import{useIsSampleProduct as s,useIsStorefrontProduct as l}from"../shop.js";import{useFetchHandle as o}from"../useFetchHandle.js";let useProductsQuery=(t,c,d)=>{let p=o(),m=s(),a=l();return e(t?u({ids:t,isSample:m,isStorefront:a,defaultSelectedProductCount:d?.defaultSelectedProductCount,allStatus:d?.allStatus}):null,async([,e])=>r(p,e),c)},useProductsQueryAll=(r,u)=>{let s=o();return e(r?["query/products",r]:null,async([,e])=>t(s,e),u)};export{useProductsQuery,useProductsQueryAll};
|
package/dist/esm/hooks/shop.js
CHANGED
|
@@ -1,111 +1 @@
|
|
|
1
|
-
import {
|
|
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
|
+
import{useMemo as e}from"react";import{useSWRConfig as t}from"swr";import{useShopStore as r}from"../contexts/ShopContext.js";let useLocale=()=>{let t=r(e=>e.locale),o=r(e=>e.changeLocale);return e(()=>({locale:t,changeLocale:o}),[t,o])},useCurrency=()=>{let t=r(e=>e.currency),o=r(e=>e.changeCurrency);return e(()=>({currency:t,changeCurrency:o}),[t,o])},useMoneyFormat=()=>{let t=r(e=>e.moneyFormat),o=r(e=>e.moneyWithCurrencyFormat);return e(()=>({moneyFormat:t,moneyWithCurrencyFormat:o}),[t,o])},useSwatches=()=>{let t=r(e=>e.swatches),o=r(e=>e.changeSwatches);return e(()=>({swatches:t,changeSwatches:o}),[t,o])},usePageType=()=>{let t=r(e=>e.pageType);return e(()=>t||"STATIC",[t])},useStoreFront=()=>{let e=r(e=>e.provider),t=r(e=>e.storefrontToken),o=r(e=>e.storefrontUrl);return{provider:e,storefrontToken:t,storefrontUrl:o}},usePluginEnable=()=>r(e=>e.plugins),useEditorMode=()=>r(e=>e.mode),useMobileOnly=()=>r(e=>e.mobileOnly),useMatchMutate=()=>{let{cache:e,mutate:r}=t();return(t,o)=>{if(!(e instanceof Map))throw Error("matchMutate requires the cache provider to be a Map instance");let u=[];e.forEach((e,r)=>{t.test(r)&&u.push(r)});let n=u.map(t=>{let u=e.get(t);return r(t,u?.data,o)});return Promise.all(n)}};function useConnectedShopify(){let{storefrontToken:e}=useStoreFront();return!!e}function useIsSampleProduct(){let{storefrontToken:e}=useStoreFront(),t=r(e=>e.isStorefront);return t&&!e}function useIsStorefrontProduct(){return r(e=>e.isStorefront)}function useCheckoutUrl(e){let{storefrontToken:t}=useStoreFront();if(e)return t?`${e}?access_token=${t}`:e}export{useCheckoutUrl,useConnectedShopify,useCurrency,useEditorMode,useIsSampleProduct,useIsStorefrontProduct,useLocale,useMatchMutate,useMobileOnly,useMoneyFormat,usePageType,usePluginEnable,useStoreFront,useSwatches};
|
|
@@ -1,19 +1 @@
|
|
|
1
|
-
import
|
|
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
|
+
import{useSyncExternalStore as e}from"react";function subscribe(e){return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)}let useCurrentDevice=()=>e(subscribe,()=>window.innerWidth<768?"mobile":window.innerWidth>=768&&window.innerWidth<1024?"tablet":"desktop",()=>"desktop");export{useCurrentDevice};
|
|
@@ -1,13 +1 @@
|
|
|
1
|
-
import
|
|
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
|
+
import{useEffect as e}from"react";import a from"vanilla-lazyload";let useLazyVideo=()=>{e(()=>{let e=new a({use_native:!0});e.update()},[])};export{useLazyVideo};
|
|
@@ -1,24 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import 'react';
|
|
3
|
-
import 'react/jsx-runtime';
|
|
4
|
-
import 'zustand';
|
|
5
|
-
import 'swr';
|
|
6
|
-
import '@gem-sdk/adapter-shopify';
|
|
7
|
-
import 'swr/mutation';
|
|
8
|
-
import 'vanilla-lazyload';
|
|
9
|
-
import './useCartUI.js';
|
|
10
|
-
import 'react-transition-group';
|
|
11
|
-
import '@gem-sdk/core';
|
|
12
|
-
import '../helpers/convert.js';
|
|
13
|
-
|
|
14
|
-
const useAnimations = ()=>{
|
|
15
|
-
const { zoom, shake, fade, slide } = animations();
|
|
16
|
-
return {
|
|
17
|
-
zoom,
|
|
18
|
-
shake,
|
|
19
|
-
fade,
|
|
20
|
-
slide
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export { useAnimations };
|
|
1
|
+
import{animations as t}from"../helpers/animations.js";import"react";import"react/jsx-runtime";import"zustand";import"swr";import"@gem-sdk/adapter-shopify";import"swr/mutation";import"vanilla-lazyload";import"./useCartUI.js";import"react-transition-group";import"@gem-sdk/core";import"classnames";import"../helpers/convert.js";let useAnimations=()=>{let{zoom:r,shake:i,fade:o,slide:m}=t();return{zoom:r,shake:i,fade:o,slide:m}};export{useAnimations};
|
|
@@ -1,40 +1 @@
|
|
|
1
|
-
import
|
|
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
|
+
import{useSyncExternalStore as e,useCallback as t,useMemo as r}from"react";let cartKey="cart-id",getCartId=()=>window.localStorage.getItem(cartKey),writeCartId=e=>{e&&window.localStorage.setItem(cartKey,e)},removeCartId=()=>{window.localStorage.removeItem(cartKey)},subscribeStorage=e=>(window.addEventListener("storage",e),()=>{window.removeEventListener("storage",e)}),useCartId=()=>{let a=e(subscribeStorage,getCartId,()=>void 0),o=t(e=>{writeCartId(e)},[]),d=t(()=>{removeCartId()},[]);return r(()=>({cartId:a,updateCartId:o,clearCartId:d}),[a,d,o])};export{useCartId as default};
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const useCartLine = ()=>{
|
|
4
|
-
return useCartLineStore((s)=>s.line);
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export { useCartLine as default };
|
|
1
|
+
import{useCartLineStore as e}from"../contexts/CartLineContext.js";let useCartLine=()=>e(e=>e.line);export{useCartLine as default};
|
|
@@ -1,44 +1 @@
|
|
|
1
|
-
import {
|
|
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
|
+
import{useCallback as e}from"react";import{create as t}from"zustand";import{usePluginEnable as o}from"./shop.js";let useStore=t(e=>({isCartOpen:!1,setOpen:t=>{let o=window.innerWidth-document.documentElement.clientWidth,d=parseInt(window.getComputedStyle(document.body).getPropertyValue("padding-right"),10);t?(document.body.style.overflow="hidden",document.body.style.paddingRight=`${d+o}px`):(document.body.style.overflow="",document.body.style.paddingRight=""),e({isCartOpen:t})}}));function useCartUI(){let t=o(),d=useStore(e=>e.isCartOpen),n=useStore(e=>e.setOpen),r=e(()=>{t?.includes("cart-drawer")&&n(!0)},[t,n]),i=e(()=>n(!1),[n]);return{isCartOpen:d,openCart:r,closeCart:i}}export{useCartUI as default};
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const useCollection = ()=>{
|
|
4
|
-
return useCollectionStore((s)=>s.collection);
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export { useCollection };
|
|
1
|
+
import{useCollectionStore as o}from"../contexts/CollectionContext.js";let useCollection=()=>o(o=>o.collection);export{useCollection};
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
import
|
|
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 };
|
|
1
|
+
import{useSWRConfig as e}from"swr";let useFetchHandle=()=>{let{fetcher:t}=e();if(!t)throw Error("Application must be init within a fetcher");return t};export{useFetchHandle};
|
|
@@ -1,56 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const useFormatMoney = (amount, withCurrency)=>{
|
|
4
|
-
const { moneyFormat, moneyWithCurrencyFormat } = useMoneyFormat();
|
|
5
|
-
const formatMoney = function(cents, format) {
|
|
6
|
-
let value = '';
|
|
7
|
-
const placeholderRegex = /\{\{\s*(\w+)\s*\}\}/;
|
|
8
|
-
const formatString = format || '${{amount}}';
|
|
9
|
-
/**
|
|
10
|
-
* check default
|
|
11
|
-
* @param opt opt
|
|
12
|
-
* @param def def
|
|
13
|
-
* @returns any
|
|
14
|
-
*/ function defaultOption(opt, def) {
|
|
15
|
-
return typeof opt == 'undefined' ? def : opt;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* formatWithDelimiters
|
|
19
|
-
* @param number number
|
|
20
|
-
* @param precision precision
|
|
21
|
-
* @param thousands thousands
|
|
22
|
-
* @param decimal decimal
|
|
23
|
-
* @returns any
|
|
24
|
-
*/ // eslint-disable-next-line max-params
|
|
25
|
-
function formatWithDelimiters(number, precision, thousands, decimal) {
|
|
26
|
-
precision = defaultOption(precision, 2);
|
|
27
|
-
thousands = defaultOption(thousands, ',');
|
|
28
|
-
decimal = defaultOption(decimal, '.');
|
|
29
|
-
if (isNaN(number) || number == null) {
|
|
30
|
-
return 0;
|
|
31
|
-
}
|
|
32
|
-
// shopify làm tròn bằng cách cắt đi các số ở đằng sau chứ không sử dụng toFixed để làm tròn như toán học
|
|
33
|
-
number = parseFloat(`${number}`).toFixed(Number(precision) + 1).slice(0, -1);
|
|
34
|
-
const parts = number.split('.'), dollars = parts[0]?.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1' + thousands), cents = parts[1] ? decimal + parts[1] : '';
|
|
35
|
-
return dollars + cents;
|
|
36
|
-
}
|
|
37
|
-
switch(formatString.match(placeholderRegex)[1]){
|
|
38
|
-
case 'amount':
|
|
39
|
-
value = formatWithDelimiters(cents, 2);
|
|
40
|
-
break;
|
|
41
|
-
case 'amount_no_decimals':
|
|
42
|
-
value = formatWithDelimiters(cents, 0);
|
|
43
|
-
break;
|
|
44
|
-
case 'amount_with_comma_separator':
|
|
45
|
-
value = formatWithDelimiters(cents, 2, '.', ',');
|
|
46
|
-
break;
|
|
47
|
-
case 'amount_no_decimals_with_comma_separator':
|
|
48
|
-
value = formatWithDelimiters(cents, 0, '.', ',');
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
return formatString.replace(placeholderRegex, value);
|
|
52
|
-
};
|
|
53
|
-
return withCurrency ? formatMoney(`${amount}`, moneyWithCurrencyFormat || moneyFormat) : formatMoney(`${amount}`, moneyFormat);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export { useFormatMoney };
|
|
1
|
+
import{useMoneyFormat as e}from"./shop.js";let shopifyPriceRounding=(e,o)=>parseFloat(`${e}`).toFixed(Number(o)+1).slice(0,-1),useFormatMoney=(o,r)=>{let{moneyFormat:t,moneyWithCurrencyFormat:a}=e(),n=function(e,o){let r="",t=/\{\{\s*(\w+)\s*\}\}/,a=o||"${{amount}}";function n(e,o){return void 0===e?o:e}function i(e,o,r,t){if(o=n(o,2),r=n(r,","),t=n(t,"."),isNaN(e)||null==e)return 0;e=shopifyPriceRounding(e,Number(o));let a=e.split("."),i=a[0]?.replace(/(\d)(?=(\d\d\d)+(?!\d))/g,"$1"+r),s=a[1]?t+a[1]:"";return i+s}switch(a.match(t)[1]){case"amount":r=i(e,2);break;case"amount_no_decimals":r=i(e,0);break;case"amount_with_comma_separator":r=i(e,2,".",",");break;case"amount_no_decimals_with_comma_separator":r=i(e,0,".",",")}return a.replace(t,r)};return n(`${o}`,r&&a||t)};export{shopifyPriceRounding,useFormatMoney};
|