@gem-sdk/core 1.14.0-next.96 → 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 +26 -28
- package/package.json +2 -2
|
@@ -1 +1,56 @@
|
|
|
1
|
-
import{useMoneyFormat
|
|
1
|
+
import { useMoneyFormat } from './shop.js';
|
|
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 +1,6 @@
|
|
|
1
|
-
import{useLayoutEffect
|
|
1
|
+
import { useLayoutEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
// const isBrowser = typeof window !== 'undefined';
|
|
4
|
+
const useIsomorphicLayoutEffect = useLayoutEffect;
|
|
5
|
+
|
|
6
|
+
export { useIsomorphicLayoutEffect as default };
|
|
@@ -1 +1,28 @@
|
|
|
1
|
-
import{useState
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { loadScript } from '../helpers/load-script.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The `useLoadScript` hook loads an external script tag on the client-side.
|
|
6
|
+
*/ function useLoadScript(url, options) {
|
|
7
|
+
const [status, setStatus] = useState('loading');
|
|
8
|
+
const stringifiedOptions = JSON.stringify(options);
|
|
9
|
+
useEffect(()=>{
|
|
10
|
+
async function loadScriptWrapper() {
|
|
11
|
+
try {
|
|
12
|
+
setStatus('loading');
|
|
13
|
+
await loadScript(url, options);
|
|
14
|
+
setStatus('done');
|
|
15
|
+
} catch (error) {
|
|
16
|
+
setStatus('error');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
loadScriptWrapper();
|
|
20
|
+
}, [
|
|
21
|
+
url,
|
|
22
|
+
stringifiedOptions,
|
|
23
|
+
options
|
|
24
|
+
]);
|
|
25
|
+
return status;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { useLoadScript as default };
|
|
@@ -1 +1,80 @@
|
|
|
1
|
-
import{useMemo
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useLocale, useCurrency } from './shop.js';
|
|
3
|
+
|
|
4
|
+
const useMoney = (amount)=>{
|
|
5
|
+
const { locale } = useLocale();
|
|
6
|
+
const { currency } = useCurrency();
|
|
7
|
+
const options = useMemo(()=>({
|
|
8
|
+
style: 'currency',
|
|
9
|
+
currency: currency
|
|
10
|
+
}), [
|
|
11
|
+
currency
|
|
12
|
+
]);
|
|
13
|
+
const defaultFormatter = useLazyFormatter(locale, options);
|
|
14
|
+
const nameFormatter = useLazyFormatter(locale, {
|
|
15
|
+
...options,
|
|
16
|
+
currencyDisplay: 'name'
|
|
17
|
+
});
|
|
18
|
+
const narrowSymbolFormatter = useLazyFormatter(locale, {
|
|
19
|
+
...options,
|
|
20
|
+
currencyDisplay: 'narrowSymbol'
|
|
21
|
+
});
|
|
22
|
+
const withoutTrailingZerosFormatter = useLazyFormatter(locale, {
|
|
23
|
+
...options,
|
|
24
|
+
minimumFractionDigits: 0,
|
|
25
|
+
maximumFractionDigits: 0
|
|
26
|
+
});
|
|
27
|
+
const withoutCurrencyFormatter = useLazyFormatter(locale);
|
|
28
|
+
const withoutTrailingZerosOrCurrencyFormatter = useLazyFormatter(locale, {
|
|
29
|
+
minimumFractionDigits: 0,
|
|
30
|
+
maximumFractionDigits: 0
|
|
31
|
+
});
|
|
32
|
+
const isPartCurrency = (part)=>part.type === 'currency';
|
|
33
|
+
// By wrapping these properties in functions, we only
|
|
34
|
+
// create formatters if they are going to be used.
|
|
35
|
+
const lazyFormatters = useMemo(()=>({
|
|
36
|
+
currencyCode: ()=>currency,
|
|
37
|
+
localizedString: ()=>defaultFormatter().format(amount),
|
|
38
|
+
parts: ()=>defaultFormatter().formatToParts(amount),
|
|
39
|
+
withoutTrailingZeros: ()=>amount % 1 === 0 ? withoutTrailingZerosFormatter().format(amount) : defaultFormatter().format(amount),
|
|
40
|
+
withoutTrailingZerosAndCurrency: ()=>amount % 1 === 0 ? withoutTrailingZerosOrCurrencyFormatter().format(amount) : withoutCurrencyFormatter().format(amount),
|
|
41
|
+
currencyName: ()=>nameFormatter().formatToParts(amount).find(isPartCurrency)?.value ?? currency,
|
|
42
|
+
currencySymbol: ()=>defaultFormatter().formatToParts(amount).find(isPartCurrency)?.value ?? currency,
|
|
43
|
+
currencyNarrowSymbol: ()=>narrowSymbolFormatter().formatToParts(amount).find(isPartCurrency)?.value ?? '',
|
|
44
|
+
amount: ()=>defaultFormatter().formatToParts(amount).filter((part)=>[
|
|
45
|
+
'decimal',
|
|
46
|
+
'fraction',
|
|
47
|
+
'group',
|
|
48
|
+
'integer',
|
|
49
|
+
'literal'
|
|
50
|
+
].includes(part.type)).map((part)=>part.value).join('')
|
|
51
|
+
}), [
|
|
52
|
+
currency,
|
|
53
|
+
amount,
|
|
54
|
+
nameFormatter,
|
|
55
|
+
defaultFormatter,
|
|
56
|
+
narrowSymbolFormatter,
|
|
57
|
+
withoutCurrencyFormatter,
|
|
58
|
+
withoutTrailingZerosFormatter,
|
|
59
|
+
withoutTrailingZerosOrCurrencyFormatter
|
|
60
|
+
]);
|
|
61
|
+
// Call functions automatically when the properties are accessed
|
|
62
|
+
// to keep these functions as an implementation detail.
|
|
63
|
+
return useMemo(()=>new Proxy(lazyFormatters, {
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
65
|
+
get: (target, key)=>Reflect.get(target, key)?.call(null)
|
|
66
|
+
}), [
|
|
67
|
+
lazyFormatters
|
|
68
|
+
]);
|
|
69
|
+
};
|
|
70
|
+
function useLazyFormatter(locale, options) {
|
|
71
|
+
return useMemo(()=>{
|
|
72
|
+
let memoized;
|
|
73
|
+
return ()=>memoized ??= new Intl.NumberFormat(locale, options);
|
|
74
|
+
}, [
|
|
75
|
+
locale,
|
|
76
|
+
options
|
|
77
|
+
]);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export { useMoney as default };
|
|
@@ -1 +1,17 @@
|
|
|
1
|
-
import{useRef
|
|
1
|
+
import { useRef, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
const usePrevious = (value)=>{
|
|
4
|
+
// The ref object is a generic container whose current property is mutable ...
|
|
5
|
+
// ... and can hold any value, similar to an instance property on a class
|
|
6
|
+
const ref = useRef();
|
|
7
|
+
// Store current value in ref
|
|
8
|
+
useEffect(()=>{
|
|
9
|
+
ref.current = value;
|
|
10
|
+
}, [
|
|
11
|
+
value
|
|
12
|
+
]); // Only re-run if value changes
|
|
13
|
+
// Return previous value (happens before update in useEffect above)
|
|
14
|
+
return ref.current;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { usePrevious };
|
|
@@ -1 +1,111 @@
|
|
|
1
|
-
import{useCallback
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
|
+
import { useProductStore } from '../contexts/ProductContext.js';
|
|
3
|
+
import { flattenConnection } from '../helpers/flatten-connection.js';
|
|
4
|
+
import 'swr';
|
|
5
|
+
import { getSelectedVariant } from '../helpers/product.js';
|
|
6
|
+
import '../helpers/convert.js';
|
|
7
|
+
import { checkInStock } from '../helpers/variant.js';
|
|
8
|
+
|
|
9
|
+
const useUniqProductID = ()=>{
|
|
10
|
+
return useProductStore((s)=>s.uiqueId);
|
|
11
|
+
};
|
|
12
|
+
const useProduct = ()=>{
|
|
13
|
+
return useProductStore((s)=>s.product);
|
|
14
|
+
};
|
|
15
|
+
const useFeaturedImageGlobal = ()=>{
|
|
16
|
+
return useProductStore((s)=>s.featuredImageGlobal);
|
|
17
|
+
};
|
|
18
|
+
const useProductProperties = ()=>{
|
|
19
|
+
return useProductStore((s)=>s.properties);
|
|
20
|
+
};
|
|
21
|
+
const useQuantity = ()=>{
|
|
22
|
+
const quantity = useProductStore((s)=>s.quantity);
|
|
23
|
+
const decrement = useProductStore((s)=>s.decrementQuantity);
|
|
24
|
+
const increment = useProductStore((s)=>s.incrementQuantity);
|
|
25
|
+
const updateQuantity = useProductStore((s)=>s.setQuantity);
|
|
26
|
+
const reset = useCallback(()=>{
|
|
27
|
+
updateQuantity(1);
|
|
28
|
+
}, [
|
|
29
|
+
updateQuantity
|
|
30
|
+
]);
|
|
31
|
+
return useMemo(()=>({
|
|
32
|
+
quantity,
|
|
33
|
+
increment,
|
|
34
|
+
decrement,
|
|
35
|
+
reset,
|
|
36
|
+
setQuantity: updateQuantity
|
|
37
|
+
}), [
|
|
38
|
+
decrement,
|
|
39
|
+
increment,
|
|
40
|
+
quantity,
|
|
41
|
+
reset,
|
|
42
|
+
updateQuantity
|
|
43
|
+
]);
|
|
44
|
+
};
|
|
45
|
+
const useSelectedOption = ()=>{
|
|
46
|
+
const setSelectedOption = useProductStore((s)=>s.setSelectedOption);
|
|
47
|
+
const selectedOptions = useProductStore((s)=>s.selectedOptions);
|
|
48
|
+
const forceSelectedOption = useProductStore((s)=>s.forceSelectedOption);
|
|
49
|
+
const updateOption = useCallback((optionId, optionValue)=>{
|
|
50
|
+
setSelectedOption(optionId, optionValue);
|
|
51
|
+
}, [
|
|
52
|
+
setSelectedOption
|
|
53
|
+
]);
|
|
54
|
+
return useMemo(()=>({
|
|
55
|
+
selectedOptions,
|
|
56
|
+
setSelectedOption: updateOption,
|
|
57
|
+
forceSelectedOption
|
|
58
|
+
}), [
|
|
59
|
+
selectedOptions,
|
|
60
|
+
updateOption,
|
|
61
|
+
forceSelectedOption
|
|
62
|
+
]);
|
|
63
|
+
};
|
|
64
|
+
const useVariants = ()=>{
|
|
65
|
+
const variants = useProductStore((s)=>s.product?.variants);
|
|
66
|
+
return flattenConnection(variants);
|
|
67
|
+
};
|
|
68
|
+
const useVariant = (id)=>{
|
|
69
|
+
const variants = useVariants();
|
|
70
|
+
return useMemo(()=>variants?.find((v)=>v?.id === id), [
|
|
71
|
+
id,
|
|
72
|
+
variants
|
|
73
|
+
]);
|
|
74
|
+
};
|
|
75
|
+
const useCurrentVariant = ()=>{
|
|
76
|
+
const { selectedOptions } = useSelectedOption();
|
|
77
|
+
const variants = useVariants();
|
|
78
|
+
return useMemo(()=>getSelectedVariant(variants, selectedOptions), [
|
|
79
|
+
selectedOptions,
|
|
80
|
+
variants
|
|
81
|
+
]);
|
|
82
|
+
};
|
|
83
|
+
const useCurrentVariantInStock = ()=>{
|
|
84
|
+
const currentVariant = useCurrentVariant();
|
|
85
|
+
const isInStock = checkInStock(currentVariant);
|
|
86
|
+
return isInStock;
|
|
87
|
+
};
|
|
88
|
+
const useVariantOutStock = (optionId, optionValue)=>{
|
|
89
|
+
const { selectedOptions } = useSelectedOption();
|
|
90
|
+
const variants = useVariants();
|
|
91
|
+
const matchedVariant = getSelectedVariant(variants, {
|
|
92
|
+
...selectedOptions,
|
|
93
|
+
[optionId]: optionValue
|
|
94
|
+
});
|
|
95
|
+
const isInStock = checkInStock(matchedVariant);
|
|
96
|
+
return !isInStock;
|
|
97
|
+
};
|
|
98
|
+
const useCheckAvailableVariantInStock = (optionId, optionValue)=>{
|
|
99
|
+
const variants = useVariants();
|
|
100
|
+
return variants ? variants.some((item)=>{
|
|
101
|
+
if (item) {
|
|
102
|
+
const { selectedOptions } = item;
|
|
103
|
+
const opt = selectedOptions?.some((option)=>option?.name === optionId && option.value === optionValue);
|
|
104
|
+
const isInStock = checkInStock(item);
|
|
105
|
+
return opt && isInStock;
|
|
106
|
+
}
|
|
107
|
+
return false;
|
|
108
|
+
}) : false;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export { useCheckAvailableVariantInStock, useCurrentVariant, useCurrentVariantInStock, useFeaturedImageGlobal, useProduct, useProductProperties, useQuantity, useSelectedOption, useUniqProductID, useVariant, useVariantOutStock, useVariants };
|
|
@@ -1 +1,16 @@
|
|
|
1
|
-
import{useProductListStore
|
|
1
|
+
import { useProductListStore } from '../contexts/ProductListContext.js';
|
|
2
|
+
|
|
3
|
+
const useProductList = ()=>{
|
|
4
|
+
return useProductListStore((s)=>s.collection);
|
|
5
|
+
};
|
|
6
|
+
const useProductListProducts = ()=>{
|
|
7
|
+
return useProductListStore((s)=>s.products);
|
|
8
|
+
};
|
|
9
|
+
const useProductListSettings = ()=>{
|
|
10
|
+
return useProductListStore((s)=>s.settings);
|
|
11
|
+
};
|
|
12
|
+
const useProductListStyles = ()=>{
|
|
13
|
+
return useProductListStore((s)=>s.styles);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { useProductList, useProductListProducts, useProductListSettings, useProductListStyles };
|
|
@@ -1 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
const cache = new Map();
|
|
2
|
+
const useSuspenseFetch = (key, promise)=>{
|
|
3
|
+
const value = cache.get(key) || {
|
|
4
|
+
status: 'new',
|
|
5
|
+
data: null
|
|
6
|
+
};
|
|
7
|
+
if (value.status === 'resolved') {
|
|
8
|
+
return {
|
|
9
|
+
data: value.data
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
promise().then((data)=>{
|
|
13
|
+
value.status = 'resolved';
|
|
14
|
+
value.data = data;
|
|
15
|
+
cache.set(key, value);
|
|
16
|
+
}).catch(()=>{
|
|
17
|
+
value.status = 'error';
|
|
18
|
+
value.data = null;
|
|
19
|
+
});
|
|
20
|
+
throw promise();
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { useSuspenseFetch as default };
|
|
@@ -1 +1,37 @@
|
|
|
1
|
-
import{useSwatches
|
|
1
|
+
import { useSwatches } from './shop.js';
|
|
2
|
+
|
|
3
|
+
const initialSwatchOptionValue = {
|
|
4
|
+
label: '',
|
|
5
|
+
colors: [],
|
|
6
|
+
imageUrl: ''
|
|
7
|
+
};
|
|
8
|
+
const initialGlobalSwatchesData = {
|
|
9
|
+
optionTitle: '',
|
|
10
|
+
optionType: '',
|
|
11
|
+
optionValues: []
|
|
12
|
+
};
|
|
13
|
+
const useSwatchesOptions = (options)=>{
|
|
14
|
+
const { swatches } = useSwatches();
|
|
15
|
+
if (!options) return [];
|
|
16
|
+
return options?.map((option)=>{
|
|
17
|
+
const swatchOption = swatches?.find((sw)=>sw?.optionTitle === option?.name) || {
|
|
18
|
+
...initialGlobalSwatchesData
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
...option,
|
|
22
|
+
optionType: swatchOption ? swatchOption.optionType : '',
|
|
23
|
+
values: option.values?.map((val)=>{
|
|
24
|
+
const swatchValue = swatchOption && swatchOption?.optionValues?.find((swatOp)=>swatOp?.label === val?.label) || {
|
|
25
|
+
...initialSwatchOptionValue
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
...val,
|
|
29
|
+
colors: swatchValue?.colors || [],
|
|
30
|
+
imageUrl: swatchValue?.imageUrl || ''
|
|
31
|
+
};
|
|
32
|
+
})
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { useSwatchesOptions as default };
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1,92 @@
|
|
|
1
|
-
export{default as AddOn
|
|
1
|
+
export { default as AddOn } from './components/AddOn.js';
|
|
2
|
+
export { default as Render } from './components/Render.js';
|
|
3
|
+
export { default as RenderPreview } from './components/RenderPreview.js';
|
|
4
|
+
export { RenderChildren, default as RenderLiquid } from './components/Render.liquid.js';
|
|
5
|
+
export { AddonProvider, useAddon, useAddons } from './contexts/AddonContext.js';
|
|
6
|
+
export { BuilderComponentProvider, useBuilderComponent } from './contexts/BuilderComponent.js';
|
|
7
|
+
export { BuilderProvider, useBuilderStore } from './contexts/BuilderContext.js';
|
|
8
|
+
export { BuilderPreviewProvider, useBuilderPreviewStore } from './contexts/BuilderPreviewContext.js';
|
|
9
|
+
export { CartLineProvider, useCartLineStore } from './contexts/CartLineContext.js';
|
|
10
|
+
export { ProductListProvider, useProductListStore } from './contexts/ProductListContext.js';
|
|
11
|
+
export { ProductProvider, useProductStore } from './contexts/ProductContext.js';
|
|
12
|
+
export { SectionProvider, useSection, useSectionStore } from './contexts/SectionContext.js';
|
|
13
|
+
export { ShopProvider, useShopStore } from './contexts/ShopContext.js';
|
|
14
|
+
export { CollectionProvider, useCollectionStore } from './contexts/CollectionContext.js';
|
|
15
|
+
export { ModalProvider, useModalStore } from './contexts/ModalContext.js';
|
|
16
|
+
export { PageViewUpDocument } from './graphql/mutations/page-view-up.generated.js';
|
|
17
|
+
export { CollectionDetailFilterDocument } from './graphql/queries/collection-detail-filter.generated.js';
|
|
18
|
+
export { CollectionDocument } from './graphql/queries/collection.generated.js';
|
|
19
|
+
export { CollectionsDocument } from './graphql/queries/collections.generated.js';
|
|
20
|
+
export { PublishedThemePagesDocument } from './graphql/queries/published-theme-pages.generated.js';
|
|
21
|
+
export { ProductsDocument } from './graphql/queries/products.generated.js';
|
|
22
|
+
export { StorePropertyDocument } from './graphql/queries/store-property.generated.js';
|
|
23
|
+
export { PreviewPageDocument } from './graphql/queries/preview-page.generated.js';
|
|
24
|
+
export { composeBorderCss, getBorderStyle, handleConvertBorderColor, handleConvertBorderStyle, handleConvertBorderWidth, handleConvertClassColor, handleConvertClassColorDynamicBtn } from './helpers/borders.js';
|
|
25
|
+
export { cls } from './helpers/cls.js';
|
|
26
|
+
export { flattenConnection } from './helpers/flatten-connection.js';
|
|
27
|
+
export { getResponsiveStateValue, getResponsiveValue, getResponsiveValueByScreen } from './helpers/get-resonsive-value.js';
|
|
28
|
+
export { getShortName } from './helpers/get-shortname.js';
|
|
29
|
+
export { default as globalEvent } from './helpers/GlobalEvent.js';
|
|
30
|
+
export { default as isBrowser } from './helpers/is-browser.js';
|
|
31
|
+
export { default as isSafari } from './helpers/is-safari.js';
|
|
32
|
+
export { isEmptyChildren } from './helpers/is-empty-children.js';
|
|
33
|
+
export { makeAspectRatio, makeHeight, makeLineClamp, makeStyle, makeStyleResponsive, makeStyleResponsiveState, makeStyleState, makeWidth, removeNullUndefined } from './helpers/make-style.js';
|
|
34
|
+
export { normalizeBuilderData } from './helpers/normalize-builder-data.js';
|
|
35
|
+
export { prefetchQueries } from './helpers/prefetch-queries.js';
|
|
36
|
+
export { composeSpacing, getSpacingVariable } from './helpers/spacing.js';
|
|
37
|
+
export { loadScript } from './helpers/load-script.js';
|
|
38
|
+
export { validateEmail } from './helpers/email.js';
|
|
39
|
+
export { genVariable } from './helpers/css-variable.js';
|
|
40
|
+
export { composeGridLayout, convertOldLayout, gridToArrayRegex, optionLayoutStyle } from './helpers/layout.js';
|
|
41
|
+
export { isDefined } from './helpers/is-defined.js';
|
|
42
|
+
export { composeTextColorCss, getGlobalColorCSSProp, getGlobalColorClass, getGlobalColorResponsiveClass, getGlobalColorResponsiveStyle, getGlobalColorStateClass, getGlobalColorStateClassDynamicBtn, getGlobalColorStateResponsiveClass, getGlobalColorStateResponsiveClassDynamicBtn, getGlobalColorStateResponsiveStyle, getGlobalColorStateStyle, getGlobalColorStyle, getSingleColorVariable, isColor } from './helpers/colors.js';
|
|
43
|
+
export { composeTypography, composeTypographyAttr, composeTypographyClassName, composeTypographyCss, composeTypographyStyle, composeTypographyV2, composeTypographyV2Css, genTypoClass } from './helpers/typography.js';
|
|
44
|
+
export { composeCornerCss, composeRadius, getCornerCSSFromGlobal, getCustomRadius, getRadiusCSSFromGlobal, getRadiusStyleActiveState } from './helpers/radius.js';
|
|
45
|
+
export { checkAvailableVariantInStock, getSelectedVariant, parseSelectedOption } from './helpers/product.js';
|
|
46
|
+
import * as fpixel from './helpers/tracking/fpixel.js';
|
|
47
|
+
export { fpixel };
|
|
48
|
+
import * as gtag from './helpers/tracking/gtag.js';
|
|
49
|
+
export { gtag };
|
|
50
|
+
import * as tiktokpixel from './helpers/tracking/tiktokpixel.js';
|
|
51
|
+
export { tiktokpixel };
|
|
52
|
+
export { RenderIf, composeMemo, dataStringify, props, styles, template } from './helpers/render.js';
|
|
53
|
+
export { baseAssetURL, isLocalEnv } from './helpers/convert.js';
|
|
54
|
+
export { composeSize, composeSizeCss, genSizeClass } from './helpers/size.js';
|
|
55
|
+
export { composeShadowCss, getStyleShadow, getStyleShadowState, parseValueWithUnit } from './helpers/shadow.js';
|
|
56
|
+
export { composeBackgroundCss, getStyleBackgroundByDevice } from './helpers/background.js';
|
|
57
|
+
export { generateCollectionQueryKey, generateProductQueryKey, generateProductsQueryKey } from './helpers/query.js';
|
|
58
|
+
export { composeAdvanceStyle, splitStyle } from './helpers/compose-advance-style.js';
|
|
59
|
+
export { useAddToCart } from './hooks/cart/use-add-to-cart.js';
|
|
60
|
+
export { useCartData } from './hooks/cart/use-cart-data.js';
|
|
61
|
+
export { useCartDiscountCodesUpdate } from './hooks/cart/use-cart-discount-codes-update.js';
|
|
62
|
+
export { useCartNoteUpdate } from './hooks/cart/use-cart-note-update.js';
|
|
63
|
+
export { useCreateCart } from './hooks/cart/use-create-cart.js';
|
|
64
|
+
export { useRemoveCartItem } from './hooks/cart/use-remove-cart-item.js';
|
|
65
|
+
export { useUpdateCartItem } from './hooks/cart/use-update-cart-item.js';
|
|
66
|
+
export { useCheckoutUrl, useConnectedShopify, useCurrency, useEditorMode, useIsSampleProduct, useIsStorefrontProduct, useLocale, useMatchMutate, useMobileOnly, useMoneyFormat, usePageType, usePluginEnable, useStoreFront, useSwatches } from './hooks/shop.js';
|
|
67
|
+
export { useCollectionQuery } from './hooks/shop/use-collection-query.js';
|
|
68
|
+
export { useCollectionsQuery } from './hooks/shop/use-collections-query.js';
|
|
69
|
+
export { useProductQuery } from './hooks/shop/use-product-query.js';
|
|
70
|
+
export { useProductsQuery } from './hooks/shop/use-products-query.js';
|
|
71
|
+
export { useCurrentDevice } from './hooks/use-current-device.js';
|
|
72
|
+
export { useFormatMoney } from './hooks/useFormatMoney.js';
|
|
73
|
+
export { useLazyVideo } from './hooks/use-lazy-video.js';
|
|
74
|
+
export { default as useCartId } from './hooks/useCartId.js';
|
|
75
|
+
export { default as useCartLine } from './hooks/useCartLine.js';
|
|
76
|
+
export { default as useCartUI } from './hooks/useCartUI.js';
|
|
77
|
+
export { useCollection } from './hooks/useCollection.js';
|
|
78
|
+
export { useId } from 'react';
|
|
79
|
+
export { default as useIsomorphicLayoutEffect } from './hooks/useIsomorphicLayoutEffect.js';
|
|
80
|
+
export { default as useLoadScript } from './hooks/useLoadScript.js';
|
|
81
|
+
export { default as useMoney } from './hooks/useMoney.js';
|
|
82
|
+
export { usePrevious } from './hooks/usePrevious.js';
|
|
83
|
+
export { useCheckAvailableVariantInStock, useCurrentVariant, useCurrentVariantInStock, useFeaturedImageGlobal, useProduct, useProductProperties, useQuantity, useSelectedOption, useUniqProductID, useVariant, useVariantOutStock, useVariants } from './hooks/useProduct.js';
|
|
84
|
+
export { useProductList, useProductListProducts, useProductListSettings, useProductListStyles } from './hooks/useProductList.js';
|
|
85
|
+
export { default as useSuspenseFetch } from './hooks/useSuspenseFetch.js';
|
|
86
|
+
export { default as useSwatchesOptions } from './hooks/useSwatchesOptions.js';
|
|
87
|
+
import * as shop from './types/shop.js';
|
|
88
|
+
export { shop as ShopType };
|
|
89
|
+
export { OptionNormalStyle, OptionSpecialStyle } from './types/global-style.js';
|
|
90
|
+
export { calculateFirstProduct, getCollection } from './helpers/queries/get-collection.js';
|
|
91
|
+
export { fetchMedias, fetchVariants, getProduct } from './helpers/queries/get-product.js';
|
|
92
|
+
export { getProductBySlug } from './helpers/queries/get-product-by-slug.js';
|
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
const OptionNormalStyle = [
|
|
2
|
+
'radio_buttons',
|
|
3
|
+
'dropdown'
|
|
4
|
+
];
|
|
5
|
+
const OptionSpecialStyle = [
|
|
6
|
+
'color',
|
|
7
|
+
'image',
|
|
8
|
+
'rectangle_list'
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
export { OptionNormalStyle, OptionSpecialStyle };
|