@gem-sdk/components 2.0.0-dev.274 → 2.0.0-dev.275

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist/cjs/banner/components/HeroBannerItem.liquid.js +1 -1
  2. package/dist/cjs/builder.js +13 -13
  3. package/dist/cjs/cart/components/ShopPayButton/ShopPayButton.js +70 -0
  4. package/dist/cjs/cart/components/ShopPayButton/ShopPayButton.liquid.js +71 -0
  5. package/dist/cjs/cart/components/ShopPayButton/common/classes.js +18 -0
  6. package/dist/cjs/cart/components/ShopPayButton/common/helpers.js +31 -0
  7. package/dist/cjs/cart/components/ShopPayButton/common/styles.js +12 -0
  8. package/dist/cjs/cart/components/ShopPayButton/hooks/useShopPayButton.js +70 -0
  9. package/dist/cjs/cart/next.js +1 -1
  10. package/dist/cjs/estimate-delivery/components/EstimateDate.liquid.js +1 -1
  11. package/dist/cjs/header/components/kind/basic/index.js +1 -1
  12. package/dist/cjs/header/components/kind/modern/index.js +1 -1
  13. package/dist/cjs/index.js +39 -39
  14. package/dist/cjs/index.liquid.js +9 -9
  15. package/dist/cjs/product/components/DynamicCheckout/DynamicCheckout.js +28 -0
  16. package/dist/cjs/product/components/DynamicCheckout/DynamicCheckout.liquid.js +23 -0
  17. package/dist/cjs/product/components/DynamicCheckout/common/classes.js +32 -0
  18. package/dist/cjs/product/components/DynamicCheckout/common/styles.js +181 -0
  19. package/dist/cjs/product/components/DynamicCheckout/components/Button.liquid.js +58 -0
  20. package/dist/cjs/product/components/FileUpload/components/common/index.js +1 -1
  21. package/dist/cjs/product/components/ProductDescription/common/const.js +9 -0
  22. package/dist/cjs/product/components/ProductDescription/common/getClasses.js +30 -0
  23. package/dist/cjs/product/components/ProductDescription/common/getStyle.js +81 -0
  24. package/dist/cjs/product/components/ProductDescription/hooks/useGpDescription.js +90 -0
  25. package/dist/cjs/product/components/ProductDescription/index.js +115 -0
  26. package/dist/cjs/product/components/ProductDescription/index.liquid.js +86 -0
  27. package/dist/cjs/product/next.js +1 -1
  28. package/dist/cjs/setting.js +1 -1
  29. package/dist/esm/banner/components/HeroBannerItem.liquid.js +1 -1
  30. package/dist/esm/builder.js +3 -3
  31. package/dist/esm/cart/components/ShopPayButton/ShopPayButton.js +66 -0
  32. package/dist/esm/cart/components/ShopPayButton/ShopPayButton.liquid.js +67 -0
  33. package/dist/esm/cart/components/ShopPayButton/common/classes.js +15 -0
  34. package/dist/esm/cart/components/ShopPayButton/common/helpers.js +27 -0
  35. package/dist/esm/cart/components/ShopPayButton/common/styles.js +10 -0
  36. package/dist/esm/cart/components/ShopPayButton/hooks/useShopPayButton.js +68 -0
  37. package/dist/esm/cart/next.js +1 -1
  38. package/dist/esm/estimate-delivery/components/EstimateDate.liquid.js +1 -1
  39. package/dist/esm/header/components/kind/basic/index.js +1 -1
  40. package/dist/esm/header/components/kind/modern/index.js +1 -1
  41. package/dist/esm/index.js +3 -3
  42. package/dist/esm/index.liquid.js +3 -3
  43. package/dist/esm/product/components/DynamicCheckout/DynamicCheckout.js +24 -0
  44. package/dist/esm/product/components/DynamicCheckout/DynamicCheckout.liquid.js +19 -0
  45. package/dist/esm/product/components/DynamicCheckout/common/classes.js +30 -0
  46. package/dist/esm/product/components/DynamicCheckout/common/styles.js +179 -0
  47. package/dist/esm/product/components/DynamicCheckout/components/Button.liquid.js +54 -0
  48. package/dist/esm/product/components/FileUpload/components/common/index.js +1 -1
  49. package/dist/esm/product/components/ProductDescription/common/const.js +6 -0
  50. package/dist/esm/product/components/ProductDescription/common/getClasses.js +27 -0
  51. package/dist/esm/product/components/ProductDescription/common/getStyle.js +77 -0
  52. package/dist/esm/product/components/ProductDescription/hooks/useGpDescription.js +88 -0
  53. package/dist/esm/product/components/ProductDescription/index.js +111 -0
  54. package/dist/esm/product/components/ProductDescription/index.liquid.js +82 -0
  55. package/dist/esm/product/next.js +1 -1
  56. package/dist/esm/setting.js +1 -1
  57. package/dist/types/index.d.ts +29 -97
  58. package/package.json +1 -1
  59. package/dist/cjs/cart/components/ShopPayButton/ShopPayButtonCommon.js +0 -20
  60. package/dist/cjs/cart/components/ShopPayButton/index.js +0 -113
  61. package/dist/cjs/cart/components/ShopPayButton/index.liquid.js +0 -51
  62. package/dist/cjs/product/components/DynamicCheckout.liquid.js +0 -250
  63. package/dist/cjs/product/components/ProductDescription/const.js +0 -5
  64. package/dist/cjs/product/components/ProductDescription.js +0 -172
  65. package/dist/cjs/product/components/ProductDescription.liquid.js +0 -120
  66. package/dist/esm/cart/components/ShopPayButton/ShopPayButtonCommon.js +0 -17
  67. package/dist/esm/cart/components/ShopPayButton/index.js +0 -109
  68. package/dist/esm/cart/components/ShopPayButton/index.liquid.js +0 -47
  69. package/dist/esm/product/components/DynamicCheckout.liquid.js +0 -246
  70. package/dist/esm/product/components/ProductDescription/const.js +0 -3
  71. package/dist/esm/product/components/ProductDescription.js +0 -168
  72. package/dist/esm/product/components/ProductDescription.liquid.js +0 -116
  73. /package/dist/cjs/product/components/ProductDescription/{common.js → common/getMaxHeight.js} +0 -0
  74. /package/dist/esm/product/components/ProductDescription/{common.js → common/getMaxHeight.js} +0 -0
@@ -0,0 +1,115 @@
1
+ 'use client';
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var jsxRuntime = require('react/jsx-runtime');
7
+ var core = require('@gem-sdk/core');
8
+ var NoDataState = require('../../../common/components/NoDataState.js');
9
+ var _const = require('./common/const.js');
10
+ var system = require('@gem-sdk/system');
11
+ var getClasses = require('./common/getClasses.js');
12
+ var getStyle = require('./common/getStyle.js');
13
+ var useGpDescription = require('./hooks/useGpDescription.js');
14
+
15
+ const ProductDescription = (props)=>{
16
+ const { setting, advanced, builderProps } = props;
17
+ const { htmlTag } = setting ?? {};
18
+ const Tag = htmlTag === 'html' ? 'div' : 'p';
19
+ const product = core.useProduct();
20
+ const currentDevice = core.useCurrentDevice();
21
+ const hasLineClamp = core.getResponsiveValueByScreen(setting?.hasLineClamp, currentDevice);
22
+ const { ref, open, isShowViewMore, handleToggleShowMore, mode, redirectProductShopifyLink } = useGpDescription.useGpDescription(setting);
23
+ const gpDescriptionClasses = system.createClass({
24
+ 'gp-product-description': true,
25
+ [advanced?.cssClass]: true
26
+ });
27
+ const textClasses = system.createClass(getClasses.getClasses({
28
+ setting
29
+ }));
30
+ const buttonClasses = system.createClass(getClasses.getButtonClasses({
31
+ setting
32
+ }));
33
+ const showMoreTextClasses = system.createClass({
34
+ 'gp-show-more-text': true
35
+ });
36
+ const showMoreIconClasses = system.createClass({
37
+ 'gp-show-more-icon gp-ml-1': true,
38
+ ...open ? {
39
+ 'gp-rotate-180': true
40
+ } : {}
41
+ });
42
+ const textStyle = system.createStyle({
43
+ ...getStyle.getTextStyle({
44
+ setting
45
+ }),
46
+ ...!open ? core.makeStyleResponsive('line-clamp', core.makeLineClamp(setting?.lineClamp, setting?.hasLineClamp)) : {}
47
+ });
48
+ const buttonStyle = system.createStyle(getStyle.getButtonStyle({
49
+ setting
50
+ }));
51
+ const attr = system.createAttr({
52
+ 'data-id': `${builderProps?.uid}`
53
+ });
54
+ const textAttr = system.createAttr({
55
+ 'data-gp-text': ''
56
+ });
57
+ const { gpDescriptionCss, textDescriptionCss } = getStyle.getStaticCss();
58
+ const noDescriptionHtml = !product?.descriptionHtml;
59
+ if (noDescriptionHtml && mode === 'edit') {
60
+ return /*#__PURE__*/ jsxRuntime.jsx(NoDataState.default, {
61
+ elementType: "secondary",
62
+ description: "Highlight key benefits with product description.",
63
+ descriptionActions: [
64
+ {
65
+ text: 'Add description',
66
+ callback: redirectProductShopifyLink
67
+ },
68
+ {
69
+ text: 'sync data',
70
+ callback: 'syncProduct'
71
+ }
72
+ ]
73
+ });
74
+ }
75
+ return system.If(noDescriptionHtml, '', /*#__PURE__*/ jsxRuntime.jsxs("div", {
76
+ ...attr,
77
+ className: gpDescriptionClasses,
78
+ children: [
79
+ /*#__PURE__*/ jsxRuntime.jsx("style", {
80
+ children: textDescriptionCss
81
+ }),
82
+ system.If(!core.isSafari(), /*#__PURE__*/ jsxRuntime.jsx("style", {
83
+ children: gpDescriptionCss
84
+ }), ' '),
85
+ /*#__PURE__*/ jsxRuntime.jsx(Tag, {
86
+ ref: ref,
87
+ ...textAttr,
88
+ className: textClasses,
89
+ style: textStyle,
90
+ dangerouslySetInnerHTML: {
91
+ __html: product?.descriptionHtml || ''
92
+ }
93
+ }),
94
+ system.If(hasLineClamp && isShowViewMore, /*#__PURE__*/ jsxRuntime.jsxs("button", {
95
+ className: buttonClasses,
96
+ style: buttonStyle,
97
+ onClick: handleToggleShowMore,
98
+ children: [
99
+ /*#__PURE__*/ jsxRuntime.jsx("span", {
100
+ className: showMoreTextClasses,
101
+ children: system.If(open, setting?.viewLessText || '', setting?.viewMoreText)
102
+ }),
103
+ system.If(setting?.enableViewMoreIcon, /*#__PURE__*/ jsxRuntime.jsx("span", {
104
+ className: showMoreIconClasses,
105
+ dangerouslySetInnerHTML: {
106
+ __html: _const.ICON_SVG
107
+ }
108
+ }))
109
+ ]
110
+ }), ' ')
111
+ ]
112
+ }));
113
+ };
114
+
115
+ exports.default = ProductDescription;
@@ -0,0 +1,86 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@gem-sdk/core');
6
+ var helpers = require('../../../helpers.js');
7
+ var system = require('@gem-sdk/system');
8
+ var getClasses = require('./common/getClasses.js');
9
+ var getStyle = require('./common/getStyle.js');
10
+ var _const = require('./common/const.js');
11
+
12
+ const ProductDescription = (props)=>{
13
+ const { setting, advanced, builderProps } = props;
14
+ const { htmlTag } = setting ?? {};
15
+ const Tag = htmlTag === 'html' ? 'div' : 'p';
16
+ const gpDescriptionClasses = system.createClass({
17
+ 'gp-product-description': true,
18
+ [advanced?.cssClass]: true
19
+ });
20
+ const textClasses = system.createClass(getClasses.getClasses({
21
+ setting
22
+ }));
23
+ const buttonClasses = system.createClass(getClasses.getButtonClasses({
24
+ setting
25
+ }));
26
+ const showMoreTextClasses = system.createClass({
27
+ 'gp-show-more-text': true
28
+ });
29
+ const showMoreIconClasses = system.createClass({
30
+ 'gp-show-more-icon gp-ml-1': true
31
+ });
32
+ const textStyle = system.createStyle({
33
+ ...getStyle.getTextStyle({
34
+ setting,
35
+ renderMaxHeight: true
36
+ }),
37
+ ...core.makeStyleResponsive('line-clamp', core.makeLineClamp(setting?.lineClamp, setting?.hasLineClamp))
38
+ });
39
+ const buttonStyle = system.createStyle(getStyle.getButtonStyle({
40
+ setting
41
+ }));
42
+ const attr = system.createAttr({
43
+ 'data-id': `${builderProps?.uid}`
44
+ });
45
+ const textAttr = system.createAttr({
46
+ 'data-gp-text': ''
47
+ });
48
+ const { gpDescriptionCss, textDescriptionCss } = getStyle.getStaticCss();
49
+ const noDescriptionHtml = 'product.description == blank';
50
+ const renderScript = ()=>{
51
+ const jsURL = core.isLocalEnv ? `{{ 'gp-product-description-v2.js' | asset_url }}` : `${core.baseAssetURL}/assets-v2/gp-product-description-v2.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}`;
52
+ return `<script ${helpers.getSettingPreloadData('class="gps-link" delay', 'src')}="${jsURL}" defer="defer"></script>`;
53
+ };
54
+ const stateData = system.createStateOrContext({
55
+ setting: {
56
+ lineClamp: setting?.lineClamp,
57
+ hasLineClamp: setting?.hasLineClamp,
58
+ viewMoreText: setting?.viewMoreText,
59
+ viewLessText: setting?.viewLessText,
60
+ enableViewMoreIcon: setting?.enableViewMoreIcon
61
+ },
62
+ textStyle
63
+ });
64
+ return system.LiquidIf(noDescriptionHtml, '', system.Liquid(core.template`
65
+ <gp-product-description-v2
66
+ ${attr}
67
+ class="${gpDescriptionClasses}"
68
+ gp-data='${core.dataStringify(stateData).replaceAll("'", '&#039;')}'>
69
+ <style>${textDescriptionCss}</style>
70
+ ${system.If(!core.isSafari(), `<style>${gpDescriptionCss}</style>`, ' ')}
71
+ ${system.LiquidUnless('product', `<p>Product not found</p>`, core.template`<${Tag} ${textAttr} class="${textClasses}" style="${textStyle}">
72
+ {{product.description}}
73
+ </${Tag}>
74
+ ${system.LiquidUnless(noDescriptionHtml, core.template`<button type="button" class="${buttonClasses}" style="${buttonStyle}">
75
+ <span class="${showMoreTextClasses}">
76
+ ${system.If(false, setting?.viewLessText || '', setting?.viewMoreText)}
77
+ </span>
78
+ ${system.If(setting?.enableViewMoreIcon, core.template`<span class="${showMoreIconClasses}">${_const.ICON_SVG}</span>`, ' ')}
79
+ </button>`)}`)}
80
+ </gp-product-description-v2>
81
+
82
+ ${renderScript()}
83
+ `));
84
+ };
85
+
86
+ exports.default = ProductDescription;
@@ -17,7 +17,7 @@ const ProductTitle = dynamic(()=>Promise.resolve().then(function () { return req
17
17
  const ProductQuantity = dynamic(()=>Promise.resolve().then(function () { return require('./components/ProductQuantity.js'); }), {
18
18
  loading: Loading.default
19
19
  });
20
- const ProductDescription = dynamic(()=>Promise.resolve().then(function () { return require('./components/ProductDescription.js'); }), {
20
+ const ProductDescription = dynamic(()=>Promise.resolve().then(function () { return require('./components/ProductDescription/index.js'); }), {
21
21
  loading: Loading.default
22
22
  });
23
23
  const ProductPrice = dynamic(()=>Promise.resolve().then(function () { return require('./components/ProductPrice.js'); }), {
@@ -23,7 +23,7 @@ require('next/image');
23
23
  require('react-youtube');
24
24
  var index$c = require('./image/setting/index.js');
25
25
  require('./image/components/AdaptiveImage.js');
26
- require('./cart/components/ShopPayButton/index.js');
26
+ require('./cart/components/ShopPayButton/ShopPayButton.js');
27
27
  var index$6 = require('./collection/setting/index.js');
28
28
  var index$7 = require('./countdown-timer/setting/index.js');
29
29
  var index$9 = require('./heading/setting/index.js');
@@ -19,7 +19,7 @@ import { DEVICES, getImageSrc } from '../../image/helpers/getSrcSet.js';
19
19
  import { getYoutubeVideoId, youtubeVideoRegex } from '../../video/helpers/common.js';
20
20
  import 'react-youtube';
21
21
  import '../../image/components/AdaptiveImage.js';
22
- import '../../cart/components/ShopPayButton/index.js';
22
+ import '../../cart/components/ShopPayButton/ShopPayButton.js';
23
23
  import '../../countdown-timer/setting/configs/settings.js';
24
24
  import '../../header/components/Header.js';
25
25
  import '../../header/components/kind/basic/index.js';
@@ -136,7 +136,7 @@ import CartDiscount from './cart/components/CartDiscount.js';
136
136
  import CartOrderNote from './cart/components/CartOrderNote.js';
137
137
  import CartLineAttribute from './cart/components/CartLineAttribute.js';
138
138
  import CouponList from './cart/components/CouponList.js';
139
- import ShopPayButton from './cart/components/ShopPayButton/index.js';
139
+ import ShopPayButton from './cart/components/ShopPayButton/ShopPayButton.js';
140
140
  import CheckoutNow from './cart/components/CheckoutNow.js';
141
141
  import CollectionTitle from './collection/components/CollectionTitle.js';
142
142
  import CollectionBanner from './collection/components/CollectionBanner.js';
@@ -180,7 +180,7 @@ import PostPurchaseProductVariants from './post-purchase/product/components/prod
180
180
  import Product from './product/components/Product.js';
181
181
  import ProductTitle from './product/components/ProductTitle/index.js';
182
182
  import ProductQuantity from './product/components/ProductQuantity.js';
183
- import ProductDescription from './product/components/ProductDescription.js';
183
+ import ProductDescription from './product/components/ProductDescription/index.js';
184
184
  import ProductPrice from './product/components/ProductPrice.js';
185
185
  import ProductButton from './product/components/ProductButton.js';
186
186
  import ProductVariants from './product/components/ProductVariants/index.js';
@@ -190,7 +190,7 @@ import ProductProperties from './product/components/ProductProperties.js';
190
190
  import QuickView from './product/components/ProductQuickView/index.js';
191
191
  import ProductTag from './product/components/ProductTag.js';
192
192
  import ProductList from './product/components/ProductList.js';
193
- import DynamicCheckout from './product/components/DynamicCheckout.js';
193
+ import DynamicCheckout from './product/components/DynamicCheckout/DynamicCheckout.js';
194
194
  import ProductBundleDiscount from './product/components/ProductBundleDiscount.js';
195
195
  import ProductBundleDiscountItem from './product/components/ProductBundleDiscountItem.js';
196
196
  import ProductVendor from './product/components/Vendor.js';
@@ -0,0 +1,66 @@
1
+ 'use client';
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import { createStyle, createClass, createAttr } from '@gem-sdk/system';
4
+ import dynamic from 'next/dynamic';
5
+ import { getButtonClasses, getButtonWrapperClasses } from './common/classes.js';
6
+ import { getSPButton } from './common/helpers.js';
7
+ import { getButtonWrapperStyles } from './common/styles.js';
8
+ import { useShopPayButton } from './hooks/useShopPayButton.js';
9
+
10
+ const DynamicCheckoutBlack = dynamic(()=>import('./icons/DynamicCheckoutBlack.js'));
11
+ const DynamicCheckoutPurple = dynamic(()=>import('./icons/DynamicCheckoutPurple.js'));
12
+ const DynamicCheckoutWhite = dynamic(()=>import('./icons/DynamicCheckoutWhite.js'));
13
+ const ExpressCheckoutBlack = dynamic(()=>import('./icons/ExpressCheckoutBlack.js'));
14
+ const ExpressCheckoutPurple = dynamic(()=>import('./icons/ExpressCheckoutPurple.js'));
15
+ const ExpressCheckoutWhite = dynamic(()=>import('./icons/ExpressCheckoutWhite.js'));
16
+ /**
17
+ * The `ShopPayButton` component renders a button that redirects to the Shop Pay checkout.
18
+ */ const ShopPayButton = ({ style, styles, setting, className, builderAttrs })=>{
19
+ const { variants, storeUrl, handleOnPay } = useShopPayButton(setting);
20
+ if (!storeUrl) {
21
+ return /*#__PURE__*/ jsx("div", {
22
+ ...builderAttrs,
23
+ children: "URL Not Found"
24
+ });
25
+ }
26
+ const SPButton = getSPButton({
27
+ styles,
28
+ buttons: {
29
+ DynamicCheckoutBlack,
30
+ DynamicCheckoutPurple,
31
+ DynamicCheckoutWhite,
32
+ ExpressCheckoutBlack,
33
+ ExpressCheckoutPurple,
34
+ ExpressCheckoutWhite
35
+ }
36
+ });
37
+ const buttonWrapperStyles = createStyle({
38
+ ...getButtonWrapperStyles(style, styles)
39
+ });
40
+ const buttonClasses = createClass({
41
+ ...getButtonClasses()
42
+ });
43
+ const buttonWrapperClasses = createClass({
44
+ ...getButtonWrapperClasses(className)
45
+ });
46
+ const buttonAttributes = createAttr({
47
+ disabled: !variants?.length,
48
+ 'aria-label': 'Buy with Shop Pay'
49
+ });
50
+ return /*#__PURE__*/ jsx("div", {
51
+ ...builderAttrs,
52
+ style: buttonWrapperStyles,
53
+ className: buttonWrapperClasses,
54
+ children: /*#__PURE__*/ jsx("button", {
55
+ ...buttonAttributes,
56
+ className: buttonClasses,
57
+ onClick: ()=>handleOnPay({
58
+ inputWidth: 600,
59
+ inputHeight: 600
60
+ }),
61
+ children: /*#__PURE__*/ jsx(SPButton, {})
62
+ })
63
+ });
64
+ };
65
+
66
+ export { ShopPayButton as default };
@@ -0,0 +1,67 @@
1
+ import { template, isLocalEnv, baseAssetURL } from '@gem-sdk/core';
2
+ import { createStyle, createClass, createAttr, createStateOrContext, If } from '@gem-sdk/system';
3
+ import { getSettingPreloadData } from '../../../helpers.js';
4
+ import { getButtonClasses, getButtonWrapperClasses } from './common/classes.js';
5
+ import { getSPButton } from './common/helpers.js';
6
+ import { getButtonWrapperStyles } from './common/styles.js';
7
+ import DynamicCheckoutBlack from './icons/DynamicCheckoutBlack.liquid.js';
8
+ import DynamicCheckoutPurple from './icons/DynamicCheckoutPurple.liquid.js';
9
+ import DynamicCheckoutWhite from './icons/DynamicCheckoutWhite.liquid.js';
10
+ import ExpressCheckoutBlack from './icons/ExpressCheckoutBlack.liquid.js';
11
+ import ExpressCheckoutPurple from './icons/ExpressCheckoutPurple.liquid.js';
12
+ import ExpressCheckoutWhite from './icons/ExpressCheckoutWhite.liquid.js';
13
+
14
+ /**
15
+ * The `ShopPayButton` component renders a button that redirects to the Shop Pay checkout.
16
+ */ const ShopPayButton = ({ style, styles, setting, className, builderAttrs })=>{
17
+ const SPButton = getSPButton({
18
+ styles,
19
+ buttons: {
20
+ DynamicCheckoutBlack: DynamicCheckoutBlack({}),
21
+ DynamicCheckoutPurple: DynamicCheckoutPurple({}),
22
+ DynamicCheckoutWhite: DynamicCheckoutWhite({}),
23
+ ExpressCheckoutBlack: ExpressCheckoutBlack({}),
24
+ ExpressCheckoutPurple: ExpressCheckoutPurple({}),
25
+ ExpressCheckoutWhite: ExpressCheckoutWhite({})
26
+ }
27
+ });
28
+ const buttonWrapperStyles = createStyle({
29
+ ...getButtonWrapperStyles(style, styles)
30
+ });
31
+ const buttonClasses = createClass({
32
+ ...getButtonClasses()
33
+ });
34
+ const buttonWrapperClasses = createClass({
35
+ ...getButtonWrapperClasses(className)
36
+ });
37
+ const buttonAttributes = createAttr({
38
+ disabled: false,
39
+ 'aria-label': 'Buy with Shop Pay'
40
+ });
41
+ const buttonState = createStateOrContext({
42
+ setting: JSON.stringify(setting),
43
+ shop_url: '{{shop.url}}'
44
+ });
45
+ return template`
46
+ <gp-shop-pay-button
47
+ ${{
48
+ ...builderAttrs
49
+ }}
50
+ style="${buttonWrapperStyles}"
51
+ class="${buttonWrapperClasses}"
52
+ gp-data='${buttonState}'
53
+ >
54
+ <button
55
+ ${{
56
+ ...buttonAttributes
57
+ }}
58
+ class="${buttonClasses}"
59
+ >
60
+ ${SPButton}
61
+ </button>
62
+ </gp-shop-pay-button>
63
+ ${If(isLocalEnv, `<script ${getSettingPreloadData('class="gps-link" delay', 'src')}="{{ 'gp-shop-pay-button.js' | asset_url }}" defer="defer"></script>`, `<script ${getSettingPreloadData('class="gps-link" delay', 'src')}="${baseAssetURL}/assets-v2/gp-shop-pay-button.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}" defer="defer"></script>`)}
64
+ `;
65
+ };
66
+
67
+ export { ShopPayButton as default };
@@ -0,0 +1,15 @@
1
+ const getButtonWrapperClasses = (className)=>{
2
+ return {
3
+ ...className && {
4
+ [className]: true
5
+ },
6
+ 'gp-flex': true
7
+ };
8
+ };
9
+ const getButtonClasses = ()=>{
10
+ return {
11
+ 'disabled:gp-cursor-not-allowed disabled:gp-opacity-50 gp-shop-button': true
12
+ };
13
+ };
14
+
15
+ export { getButtonClasses, getButtonWrapperClasses };
@@ -0,0 +1,27 @@
1
+ const getSPButton = ({ styles, buttons })=>{
2
+ const { DynamicCheckoutBlack, DynamicCheckoutWhite, DynamicCheckoutPurple, ExpressCheckoutBlack, ExpressCheckoutWhite, ExpressCheckoutPurple } = buttons;
3
+ if (styles?.type === 'dynamic') {
4
+ if (styles.color === 'black') return DynamicCheckoutBlack;
5
+ if (styles.color === 'purple') return DynamicCheckoutPurple;
6
+ return DynamicCheckoutWhite;
7
+ } else {
8
+ if (styles?.color === 'black') return ExpressCheckoutBlack;
9
+ if (styles?.color === 'purple') return ExpressCheckoutPurple;
10
+ return ExpressCheckoutWhite;
11
+ }
12
+ };
13
+ const getIdFromGid = (id)=>{
14
+ if (!id) return;
15
+ return id.split('/').at(-1);
16
+ };
17
+ const getStoreUrl = (url)=>{
18
+ if (!url) return;
19
+ try {
20
+ const data = new URL(url);
21
+ return data.origin;
22
+ } catch {
23
+ return;
24
+ }
25
+ };
26
+
27
+ export { getIdFromGid, getSPButton, getStoreUrl };
@@ -0,0 +1,10 @@
1
+ import { makeStyleResponsive } from '@gem-sdk/core';
2
+
3
+ const getButtonWrapperStyles = (style, styles)=>{
4
+ return {
5
+ ...style,
6
+ ...makeStyleResponsive('jc', styles?.align)
7
+ };
8
+ };
9
+
10
+ export { getButtonWrapperStyles };
@@ -0,0 +1,68 @@
1
+ import { useEditorMode, useQuantity, useCartData, useCurrentVariant, useShopStore, useCurrentVariantInStock } from '@gem-sdk/core';
2
+ import { useMemo } from 'react';
3
+ import { getStoreUrl, getIdFromGid } from '../common/helpers.js';
4
+
5
+ const useShopPayButton = (setting)=>{
6
+ const mode = useEditorMode();
7
+ const { quantity } = useQuantity();
8
+ const { data: cartData } = useCartData();
9
+ const currentVariant = useCurrentVariant();
10
+ const storefrontUrl = useShopStore((s)=>s.storefrontUrl);
11
+ const isCurrentVariantInStock = useCurrentVariantInStock();
12
+ const storeUrl = getStoreUrl(storefrontUrl);
13
+ const idsInCart = useMemo(()=>{
14
+ const items = cartData?.lineItems.map((v)=>({
15
+ id: v.variantId,
16
+ quantity: v.quantity
17
+ }))?.reduce((prev, curr)=>{
18
+ const bareId = getIdFromGid(curr?.id);
19
+ if (bareId) {
20
+ prev.push(`${bareId}:${curr?.quantity ?? 1}`);
21
+ }
22
+ return prev;
23
+ }, []);
24
+ return items;
25
+ }, [
26
+ cartData?.lineItems
27
+ ]);
28
+ const variants = useMemo(()=>{
29
+ if (setting?.kind === 'cart-buy') {
30
+ return idsInCart;
31
+ }
32
+ if (currentVariant?.baseID && isCurrentVariantInStock && quantity) {
33
+ return [
34
+ `${getIdFromGid(currentVariant.baseID)}:${quantity}`
35
+ ];
36
+ }
37
+ return undefined;
38
+ }, [
39
+ setting?.kind,
40
+ currentVariant?.baseID,
41
+ isCurrentVariantInStock,
42
+ quantity,
43
+ idsInCart
44
+ ]);
45
+ const payUrl = `${storeUrl}/cart/${variants?.join(',')}?payment=shop_pay`;
46
+ const handleOnPay = ({ inputWidth = 600, inputHeight = 600 })=>{
47
+ if (mode === 'edit') return;
48
+ if (setting?.openMode === 'popup') {
49
+ const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : window.screenX;
50
+ const dualScreenTop = window.screenTop !== undefined ? window.screenTop : window.screenY;
51
+ const width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
52
+ const height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
53
+ const systemZoom = width / window.screen.availWidth;
54
+ const left = (width - inputWidth) / 2 / systemZoom + dualScreenLeft;
55
+ const top = (height - inputHeight) / 2 / systemZoom + dualScreenTop;
56
+ window.open(payUrl, 'shop_pay', `scrollbars=yes, width=${inputWidth / systemZoom}, height=${inputHeight / systemZoom}, top=${top}, left=${left}`);
57
+ } else {
58
+ !!payUrl && window.open(payUrl);
59
+ }
60
+ };
61
+ return {
62
+ storeUrl,
63
+ variants,
64
+ handleOnPay
65
+ };
66
+ };
67
+
68
+ export { useShopPayButton };
@@ -47,7 +47,7 @@ const CouponList = dynamic(()=>import('./components/CouponList.js'), {
47
47
  const CheckoutNow = dynamic(()=>import('./components/CheckoutNow.js'), {
48
48
  loading: Loading
49
49
  });
50
- const ShopPayButton = dynamic(()=>import('./components/ShopPayButton/index.js'), {
50
+ const ShopPayButton = dynamic(()=>import('./components/ShopPayButton/ShopPayButton.js'), {
51
51
  ssr: false,
52
52
  loading: Loading
53
53
  });
@@ -16,7 +16,7 @@ import '@gem-sdk/keen-slider/react';
16
16
  import 'next/image';
17
17
  import 'react-youtube';
18
18
  import '../../image/components/AdaptiveImage.js';
19
- import '../../cart/components/ShopPayButton/index.js';
19
+ import '../../cart/components/ShopPayButton/ShopPayButton.js';
20
20
  import '../../countdown-timer/setting/configs/settings.js';
21
21
  import '../../header/components/Header.js';
22
22
  import '../../header/components/kind/basic/index.js';
@@ -9,7 +9,7 @@ import 'next/head';
9
9
  import 'next/image';
10
10
  import 'react-youtube';
11
11
  import Image from '../../../../image/components/Image.js';
12
- import '../../../../cart/components/ShopPayButton/index.js';
12
+ import '../../../../cart/components/ShopPayButton/ShopPayButton.js';
13
13
  import CheckoutNow from '../../../../cart/components/CheckoutNow.js';
14
14
 
15
15
  const MobileMenu = dynamic(()=>import('./MobileMenu.js'));
@@ -9,7 +9,7 @@ import 'next/image';
9
9
  import 'react-youtube';
10
10
  import 'next/link';
11
11
  import '../../../../image/components/AdaptiveImage.js';
12
- import '../../../../cart/components/ShopPayButton/index.js';
12
+ import '../../../../cart/components/ShopPayButton/ShopPayButton.js';
13
13
 
14
14
  const ModernHeader = (props)=>{
15
15
  return /*#__PURE__*/ jsxs("div", {
package/dist/esm/index.js CHANGED
@@ -25,7 +25,7 @@ export { default as CartDiscount } from './cart/components/CartDiscount.js';
25
25
  export { default as CartOrderNote } from './cart/components/CartOrderNote.js';
26
26
  export { default as CartLineAttribute } from './cart/components/CartLineAttribute.js';
27
27
  export { default as CouponList } from './cart/components/CouponList.js';
28
- export { default as ShopPayButton } from './cart/components/ShopPayButton/index.js';
28
+ export { default as ShopPayButton } from './cart/components/ShopPayButton/ShopPayButton.js';
29
29
  export { default as CheckoutNow } from './cart/components/CheckoutNow.js';
30
30
  export { default as collectionSetting } from './collection/setting/index.js';
31
31
  export { default as CollectionTitle } from './collection/components/CollectionTitle.js';
@@ -68,7 +68,7 @@ export { default as productSetting } from './product/setting/index.js';
68
68
  export { default as Product } from './product/components/Product.js';
69
69
  export { default as ProductTitle } from './product/components/ProductTitle/index.js';
70
70
  export { default as ProductQuantity } from './product/components/ProductQuantity.js';
71
- export { default as ProductDescription } from './product/components/ProductDescription.js';
71
+ export { default as ProductDescription } from './product/components/ProductDescription/index.js';
72
72
  export { default as ProductPrice } from './product/components/ProductPrice.js';
73
73
  export { default as ProductButton } from './product/components/ProductButton.js';
74
74
  export { default as ProductVariants } from './product/components/ProductVariants/index.js';
@@ -78,7 +78,7 @@ export { default as ProductPropertyInput } from './product/components/ProductPro
78
78
  export { default as ProductQuickView } from './product/components/ProductQuickView/index.js';
79
79
  export { default as ProductTag } from './product/components/ProductTag.js';
80
80
  export { default as ProductList } from './product/components/ProductList.js';
81
- export { default as DynamicCheckout } from './product/components/DynamicCheckout.js';
81
+ export { default as DynamicCheckout } from './product/components/DynamicCheckout/DynamicCheckout.js';
82
82
  export { default as ProductBundleDiscount } from './product/components/ProductBundleDiscount.js';
83
83
  export { default as ProductBundleDiscountItem } from './product/components/ProductBundleDiscountItem.js';
84
84
  export { default as ProductVendor } from './product/components/Vendor.js';
@@ -12,7 +12,7 @@ export { default as Product } from './product/components/Product.liquid.js';
12
12
  export { default as ProductTitle } from './product/components/ProductTitle/index.liquid.js';
13
13
  export { ProductPrice } from './product/components/ProductPrice.liquid.js';
14
14
  export { default as ProductButton } from './product/components/ProductButton.liquid.js';
15
- export { default as ProductDescription } from './product/components/ProductDescription.liquid.js';
15
+ export { default as ProductDescription } from './product/components/ProductDescription/index.liquid.js';
16
16
  export { default as ProductImages } from './product/components/ProductImages.liquid.js';
17
17
  export { default as ProductImagesV2 } from './product/components/ProductImagesV2/liquid/ProductImages.liquid.js';
18
18
  export { default as ProductQuantity } from './product/components/ProductQuantity.liquid.js';
@@ -20,7 +20,7 @@ export { default as ProductVariants } from './product/components/ProductVariants
20
20
  export { default as ProductTag } from './product/components/ProductTag.liquid.js';
21
21
  export { default as ProductProperties } from './product/components/ProductProperties.liquid.js';
22
22
  export { default as ProductList } from './product/components/ProductList.liquid.js';
23
- export { default as DynamicCheckout } from './product/components/DynamicCheckout.liquid.js';
23
+ export { default as DynamicCheckout } from './product/components/DynamicCheckout/DynamicCheckout.liquid.js';
24
24
  export { default as ProductVendor } from './product/components/Vendor.liquid.js';
25
25
  export { default as ProductBundleDiscount } from './product/components/ProductBundleDiscount.liquid.js';
26
26
  export { default as ProductBundleDiscountItem } from './product/components/ProductBundleDiscountItem.liquid.js';
@@ -47,7 +47,7 @@ export { default as TabItem } from './tab/components/TabItem.liquid.js';
47
47
  export { default as HeroBanner } from './banner/components/HeroBanner.liquid.js';
48
48
  export { default as CSSCode } from './code/components/CSSCode.liquid.js';
49
49
  export { default as StockCounter } from './stock-counter/components/StockCounter.liquid.js';
50
- export { default as ShopPayButton } from './cart/components/ShopPayButton/index.liquid.js';
50
+ export { default as ShopPayButton } from './cart/components/ShopPayButton/ShopPayButton.liquid.js';
51
51
  export { default as Newsletter } from './form/components/newsletter/Newsletter.liquid.js';
52
52
  export { default as ContactForm } from './form/components/contact/Contact.liquid.js';
53
53
  export { default as FormEmail } from './form/components/form-email/FormEmail.liquid.js';
@@ -0,0 +1,24 @@
1
+ 'use client';
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import Button from '../../../button/components/v2/ButtonV2.js';
4
+ import '@gem-sdk/core';
5
+ import 'next/link';
6
+ import 'react';
7
+
8
+ const DynamicCheckout = ({ builderProps, builderAttrs, style, styles, advanced, setting })=>{
9
+ const { ...buttonStyles } = styles ?? {};
10
+ const label = setting?.label || 'Buy it now';
11
+ return /*#__PURE__*/ jsx(Button, {
12
+ builderProps: builderProps,
13
+ builderAttrs: builderAttrs,
14
+ advanced: advanced,
15
+ setting: {
16
+ label: label,
17
+ htmlType: 'button'
18
+ },
19
+ style: style,
20
+ styles: buttonStyles
21
+ });
22
+ };
23
+
24
+ export { DynamicCheckout as default };