@gem-sdk/components 2.0.0-dev.351 → 2.0.0-dev.352
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/article/setting/configs/ArticleAuthor/uiV2.js +9 -2
- package/dist/cjs/article/setting/configs/ArticleDate/uiV2.js +13 -6
- package/dist/cjs/article/setting/configs/ArticleExcerpt/settings.js +1 -1
- package/dist/cjs/article/setting/configs/ArticleExcerpt/uiV2.js +11 -1
- package/dist/cjs/article/setting/configs/ArticleReadMore/presets.js +9 -9
- package/dist/cjs/article/setting/configs/ArticleReadMore/settings.js +4 -4
- package/dist/cjs/article/setting/configs/ArticleReadMore/uiV2.js +16 -12
- package/dist/cjs/stock-counter/components/StockCounter.js +104 -112
- package/dist/cjs/stock-counter/components/StockCounter.liquid.js +116 -141
- package/dist/cjs/stock-counter/components/common/getAttrs.js +44 -0
- package/dist/cjs/stock-counter/components/common/getClasses.js +68 -0
- package/dist/cjs/stock-counter/components/common/getContent.js +71 -0
- package/dist/cjs/stock-counter/components/common/getInlineCss.js +39 -0
- package/dist/cjs/stock-counter/components/common/getStyles.js +73 -0
- package/dist/cjs/stock-counter/components/hook/useStockCounter.js +37 -0
- package/dist/cjs/stock-counter/const.js +0 -6
- package/dist/cjs/stock-counter/helpers.js +0 -14
- package/dist/cjs/stock-counter/index.js +3 -1
- package/dist/cjs/stock-counter/setting/StockCounter.js +2 -2
- package/dist/cjs/stock-counter/setting/configs/presets.js +3 -0
- package/dist/cjs/stock-counter/setting/configs/{settings.js → settingsV2.js} +211 -42
- package/dist/cjs/stock-counter/setting/configs/uiV2.js +228 -41
- package/dist/esm/article/setting/configs/ArticleAuthor/uiV2.js +9 -2
- package/dist/esm/article/setting/configs/ArticleDate/uiV2.js +13 -6
- package/dist/esm/article/setting/configs/ArticleExcerpt/settings.js +1 -1
- package/dist/esm/article/setting/configs/ArticleExcerpt/uiV2.js +11 -1
- package/dist/esm/article/setting/configs/ArticleReadMore/presets.js +9 -9
- package/dist/esm/article/setting/configs/ArticleReadMore/settings.js +4 -4
- package/dist/esm/article/setting/configs/ArticleReadMore/uiV2.js +16 -12
- package/dist/esm/stock-counter/components/StockCounter.js +106 -114
- package/dist/esm/stock-counter/components/StockCounter.liquid.js +116 -141
- package/dist/esm/stock-counter/components/common/getAttrs.js +39 -0
- package/dist/esm/stock-counter/components/common/getClasses.js +60 -0
- package/dist/esm/stock-counter/components/common/getContent.js +68 -0
- package/dist/esm/stock-counter/components/common/getInlineCss.js +37 -0
- package/dist/esm/stock-counter/components/common/getStyles.js +67 -0
- package/dist/esm/stock-counter/components/hook/useStockCounter.js +35 -0
- package/dist/esm/stock-counter/const.js +1 -4
- package/dist/esm/stock-counter/helpers.js +1 -14
- package/dist/esm/stock-counter/index.js +3 -1
- package/dist/esm/stock-counter/setting/StockCounter.js +2 -2
- package/dist/esm/stock-counter/setting/configs/presets.js +3 -0
- package/dist/esm/stock-counter/setting/configs/settingsV2.js +438 -0
- package/dist/esm/stock-counter/setting/configs/uiV2.js +228 -41
- package/dist/types/index.d.ts +13 -5
- package/package.json +1 -1
- package/dist/esm/stock-counter/setting/configs/settings.js +0 -269
|
@@ -3,163 +3,138 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var core = require('@gem-sdk/core');
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
6
|
+
var helpers = require('../../helpers.js');
|
|
7
|
+
var getInlineCss = require('./common/getInlineCss.js');
|
|
8
|
+
var getClasses = require('./common/getClasses.js');
|
|
9
|
+
var getStyles = require('./common/getStyles.js');
|
|
10
|
+
var getContent = require('./common/getContent.js');
|
|
11
|
+
var getAttrs = require('./common/getAttrs.js');
|
|
12
|
+
var system = require('@gem-sdk/system');
|
|
9
13
|
|
|
10
14
|
const StockCounter = ({ setting, styles, style, advanced, builderProps })=>{
|
|
11
|
-
const {
|
|
12
|
-
const {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const { borderRadius } = styles ?? {};
|
|
16
|
+
const { showIcon, icon, oosIcon, layout = 'full' } = setting ?? {};
|
|
17
|
+
const inlineCss = getInlineCss.getInlineCss(builderProps?.uid, borderRadius);
|
|
18
|
+
const showText = layout !== 'progress-bar';
|
|
19
|
+
const liquidTagAttrs = system.createAttr({
|
|
20
|
+
...getAttrs.getLiquidTagAttrs(builderProps, setting, styles)
|
|
21
|
+
});
|
|
22
|
+
const progressBarClasses = system.createClass({
|
|
23
|
+
...core.composeClasses('gp-stock-counter-progress gp-mt-2 data-[visible=true]:gp-block data-[visible=false]:gp-hidden'),
|
|
24
|
+
...getClasses.getProgressBarClasses(styles)
|
|
25
|
+
});
|
|
26
|
+
const progressBarStyles = system.createStyle({
|
|
27
|
+
...getStyles.getProgressBarStyles(styles, setting)
|
|
28
|
+
});
|
|
29
|
+
const containerStyles = system.createStyle({
|
|
30
|
+
...getStyles.getContainerStyles(styles)
|
|
31
|
+
});
|
|
32
|
+
const containerClasses = system.createClass({
|
|
33
|
+
...getClasses.getContainerClasses(setting)
|
|
34
|
+
});
|
|
35
|
+
const liquidTagClasses = system.createClass({
|
|
36
|
+
...getClasses.getLiquidTagClasses(advanced)
|
|
37
|
+
});
|
|
38
|
+
const liquidTagStyles = system.createStyle({
|
|
39
|
+
...style,
|
|
40
|
+
...getStyles.getWrapperStyles(styles)
|
|
41
|
+
});
|
|
42
|
+
const liquidInitData = getContent.getLiquidInitData(setting, styles);
|
|
43
|
+
const liquidTextContent = getContent.getLiquidTextContent(setting, styles);
|
|
44
|
+
const wrapperIconClasses = system.createClass({
|
|
45
|
+
...getClasses.getWrapperIconClasses(setting)
|
|
46
|
+
});
|
|
47
|
+
const iconClasses = system.createClass({
|
|
48
|
+
...core.composeClasses('gp-stock-counter-icon'),
|
|
49
|
+
...getClasses.getIconClasses()
|
|
50
|
+
});
|
|
51
|
+
const iconStyles = (isOutOfStock)=>{
|
|
52
|
+
return system.createStyle({
|
|
53
|
+
...getStyles.getIconStyles(styles, setting, isOutOfStock)
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
const progressBarAttrs = system.createAttr({
|
|
57
|
+
...getAttrs.getLiquidProgressBarAttrs()
|
|
58
|
+
});
|
|
59
|
+
const textClasses = (isOutOfStock)=>{
|
|
60
|
+
return system.createClass({
|
|
61
|
+
...getClasses.getTextClasses(styles, isOutOfStock),
|
|
62
|
+
...core.composeClasses('gp-stock-counter-mark')
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
const textStyles = (isOutOfStock)=>{
|
|
66
|
+
return system.createStyle({
|
|
67
|
+
...getStyles.getTextStyles(styles, isOutOfStock)
|
|
68
|
+
});
|
|
17
69
|
};
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return typo && typo.custom ? helpers.convertSizeToWidth(core.composeTypographyV2(typo.custom)) : {};
|
|
22
|
-
}
|
|
23
|
-
return typography && typography.custom ? helpers.convertSizeToWidth(core.composeTypography(typography.custom)) : {};
|
|
24
|
-
}, [
|
|
25
|
-
typo,
|
|
26
|
-
typography
|
|
27
|
-
]);
|
|
28
|
-
const typoWidth = core.composeMemo(()=>{
|
|
29
|
-
if (typo) {
|
|
30
|
-
return typo && !typo.custom ? core.genVariable(core.getShortName(`typography-${typo.type}-fontSize`)) : undefined;
|
|
31
|
-
}
|
|
32
|
-
return typography && !typography.custom ? core.genVariable(core.getShortName(`typography-${typography.type}-fontSize`)) : undefined;
|
|
33
|
-
}, [
|
|
34
|
-
typo,
|
|
35
|
-
typography
|
|
36
|
-
]);
|
|
37
|
-
const appendTypoClass = core.composeTypographyClassName(styles?.typo, styles?.typography);
|
|
38
|
-
const appendTypoStyle = core.composeTypographyStyle(styles?.typo, styles?.typography);
|
|
70
|
+
const textAttrs = system.createAttr({
|
|
71
|
+
...getAttrs.getLiquidTextAttrs()
|
|
72
|
+
});
|
|
39
73
|
return core.template /* liquid */ `
|
|
40
|
-
{
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
assign scarcityThreshold = ${isScarcityThreshold}
|
|
47
|
-
assign check_display = ${checkDisplay()}
|
|
48
|
-
|
|
49
|
-
if check_display == true
|
|
50
|
-
assign should_display = true
|
|
51
|
-
elsif ${isScarcityThreshold} and inventory_quantity >= 0 and inventory_quantity < ${scarcityThreshold}
|
|
52
|
-
assign should_display = true
|
|
53
|
-
else
|
|
54
|
-
assign should_display = false
|
|
55
|
-
endif
|
|
56
|
-
|
|
57
|
-
if ${hiddenCounterWhenOutOfStock === true} and available == false
|
|
58
|
-
assign should_display = false
|
|
59
|
-
endif
|
|
60
|
-
|
|
61
|
-
if ${displayProgressBar === true} and available
|
|
62
|
-
assign show_progress_bar = true
|
|
63
|
-
else
|
|
64
|
-
assign show_progress_bar = false
|
|
65
|
-
endif
|
|
66
|
-
-%}
|
|
67
|
-
{% capture variant_policy_list %}
|
|
68
|
-
{
|
|
69
|
-
{% for variant in product.variants %}
|
|
70
|
-
"{{ variant.id }}":"{{ variant.inventory_policy }}",
|
|
71
|
-
"{{ variant.id }}_management":"{{ variant.inventory_management }}"{% if forloop.last == false %},{% endif %}
|
|
72
|
-
{% endfor %}
|
|
73
|
-
}
|
|
74
|
-
{% endcapture %}
|
|
75
|
-
<gp-product-stock-counter
|
|
76
|
-
data-id="${builderProps?.uid}"
|
|
77
|
-
data-visible="{{ should_display }}"
|
|
78
|
-
data-policy='{{ variant_policy_list }}'
|
|
79
|
-
gp-setting='${JSON.stringify({
|
|
80
|
-
displayByDefault,
|
|
81
|
-
displayProgressBar,
|
|
82
|
-
scarcityThreshold,
|
|
83
|
-
template: templateString,
|
|
84
|
-
outOfStockMessage,
|
|
85
|
-
continueSelling,
|
|
86
|
-
unlimitedQuantityMessage,
|
|
87
|
-
color: mainColor,
|
|
88
|
-
hiddenCounterWhenOutOfStock
|
|
89
|
-
}).replaceAll("'", ''')}'
|
|
90
|
-
class="gp-product-stock-counter data-[visible=true]:gp-block data-[visible=false]:gp-hidden ${advanced?.cssClass}"
|
|
91
|
-
style="${{
|
|
92
|
-
...style,
|
|
93
|
-
...core.makeStyleResponsive('ta', alignment)
|
|
94
|
-
}}">
|
|
74
|
+
${liquidInitData}
|
|
75
|
+
<gp-product-stock-counter ${{
|
|
76
|
+
...liquidTagAttrs
|
|
77
|
+
}} class="${liquidTagClasses}"
|
|
78
|
+
style="${liquidTagStyles}">
|
|
79
|
+
<style>${inlineCss}</style>
|
|
95
80
|
<div
|
|
96
|
-
class="
|
|
97
|
-
style="${
|
|
98
|
-
...core.makeStyleResponsive('w', core.makeWidth(width)),
|
|
99
|
-
...core.makeStyle({
|
|
100
|
-
c: core.getSingleColorVariable(textColor)
|
|
101
|
-
})
|
|
102
|
-
}}"
|
|
81
|
+
class="${containerClasses}"
|
|
82
|
+
style="${containerStyles}"
|
|
103
83
|
>
|
|
104
|
-
<div class="
|
|
84
|
+
<div class="${wrapperIconClasses}">
|
|
105
85
|
${core.RenderIf(showIcon, core.template /* liquid */ `
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
86
|
+
{% if is_out_of_stock %}
|
|
87
|
+
<div
|
|
88
|
+
class="${iconClasses}"
|
|
89
|
+
style="${iconStyles(true)}"
|
|
90
|
+
>
|
|
91
|
+
${oosIcon}
|
|
92
|
+
</div>
|
|
93
|
+
{% else %}
|
|
94
|
+
<div
|
|
95
|
+
class="${iconClasses}"
|
|
96
|
+
style="${iconStyles(false)}"
|
|
97
|
+
>
|
|
98
|
+
${icon}
|
|
99
|
+
</div>
|
|
100
|
+
{% endif %}
|
|
117
101
|
`)}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
...
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
>
|
|
130
|
-
{% if inventory_management == null or inventory_management != "shopify" and inventory_quantity <= 0 %}
|
|
131
|
-
${helpers.transformHighlighTag(unlimitedQuantityMessage ?? helpers$1.getStaticLocale('StockCounter', 'let_buy_now'), mainColor)}
|
|
132
|
-
{% elsif available == false %}
|
|
133
|
-
${helpers.transformHighlighTag(outOfStockMessage ?? '', mainColor)}
|
|
134
|
-
{% elsif available and inventory_policy == '${_const.CONTINUE_SELLING_WHEN_OUT_OF_STOCK.toLowerCase()}' and inventory_quantity <= 0 %}
|
|
135
|
-
${helpers.transformHighlighTag(continueSelling ?? '', mainColor)}
|
|
102
|
+
${core.RenderIf(showText, core.template`
|
|
103
|
+
{% if is_out_of_stock %}
|
|
104
|
+
<p
|
|
105
|
+
${{
|
|
106
|
+
...textAttrs
|
|
107
|
+
}}
|
|
108
|
+
class="${textClasses(true)}"
|
|
109
|
+
style="${textStyles(true)}"
|
|
110
|
+
>
|
|
111
|
+
${liquidTextContent}
|
|
112
|
+
</p>
|
|
136
113
|
{% else %}
|
|
137
|
-
|
|
114
|
+
<p
|
|
115
|
+
${{
|
|
116
|
+
...textAttrs
|
|
117
|
+
}}
|
|
118
|
+
class="${textClasses(false)}"
|
|
119
|
+
style="${textStyles(false)}"
|
|
120
|
+
>
|
|
121
|
+
${liquidTextContent}
|
|
122
|
+
</p>
|
|
138
123
|
{% endif %}
|
|
139
|
-
|
|
124
|
+
`)}
|
|
125
|
+
|
|
140
126
|
</div>
|
|
141
127
|
|
|
142
128
|
<div
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
bg: 'linear-gradient(90deg, #eee 50%, transparent 50%)',
|
|
149
|
-
bgc: core.getSingleColorVariable(color),
|
|
150
|
-
bgp: `${remainingPercentage}% center`
|
|
151
|
-
})
|
|
152
|
-
}}"
|
|
153
|
-
class="${core.cls('gp-stock-counter-progress gp-relative gp-mt-2 gp-w-full -gp-scale-100 data-[visible=true]:gp-block data-[visible=false]:gp-hidden !gp-bg-[length:200%]', {
|
|
154
|
-
'gp-rounded-md ': roundedBorder,
|
|
155
|
-
"before:gp-absolute before:gp-left-0 before:gp-h-full before:gp-w-full before:gp-animate-shift before:gp-content-['']": effect,
|
|
156
|
-
'before:gp-bg-stock-counter-animate before:gp-bg-[length:60px_100%] before:gp-shadow-stock-counter': effect,
|
|
157
|
-
'before:gp-rounded-md': effect && roundedBorder
|
|
158
|
-
})}"
|
|
129
|
+
${{
|
|
130
|
+
...progressBarAttrs
|
|
131
|
+
}}
|
|
132
|
+
style="${progressBarStyles}"
|
|
133
|
+
class="${progressBarClasses}"
|
|
159
134
|
></div>
|
|
160
135
|
</div>
|
|
161
136
|
</gp-product-stock-counter>
|
|
162
|
-
${core.RenderIf(core.isLocalEnv, `<script ${helpers
|
|
137
|
+
${core.RenderIf(core.isLocalEnv, `<script ${helpers.getSettingPreloadData('class="gps-link" delay', 'src')}="{{ 'gp-product-stock-counter.js' | asset_url }}" defer="defer"></script>`, `<script ${helpers.getSettingPreloadData('class="gps-link" delay', 'src')}="${core.baseAssetURL}/assets-v2/gp-product-stock-counter.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}" defer="defer"></script>`)}
|
|
163
138
|
`;
|
|
164
139
|
};
|
|
165
140
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const getLiquidTagAttrs = (builderProps, setting, styles)=>{
|
|
4
|
+
const { displayByDefault, scarcityThreshold = 0, template: templateString, outOfStockMessage, continueSelling, unlimitedQuantityMessage, hiddenCounterWhenOutOfStock } = setting ?? {};
|
|
5
|
+
const { displayProgressBar, textColor } = styles ?? {};
|
|
6
|
+
const mainColor = textColor || 'brand';
|
|
7
|
+
return {
|
|
8
|
+
'data-id': builderProps?.uid ?? '',
|
|
9
|
+
'data-visible': '{{ should_display }}',
|
|
10
|
+
'data-policy': '{{ variant_policy_list | escape }}',
|
|
11
|
+
'gp-setting': JSON.stringify({
|
|
12
|
+
displayByDefault,
|
|
13
|
+
displayProgressBar,
|
|
14
|
+
scarcityThreshold,
|
|
15
|
+
template: templateString,
|
|
16
|
+
outOfStockMessage,
|
|
17
|
+
continueSelling,
|
|
18
|
+
unlimitedQuantityMessage,
|
|
19
|
+
color: mainColor,
|
|
20
|
+
hiddenCounterWhenOutOfStock
|
|
21
|
+
}).replaceAll(`"`, '"')
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
const getLiquidProgressBarAttrs = ()=>{
|
|
25
|
+
return {
|
|
26
|
+
'data-slot-type': 'progress-bar',
|
|
27
|
+
'data-visible': '{{ show_progress_bar }}'
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
const getLiquidTextAttrs = ()=>{
|
|
31
|
+
return {
|
|
32
|
+
'data-slot-type': 'message'
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
const getWrapperAttrs = (builderProps)=>{
|
|
36
|
+
return {
|
|
37
|
+
'data-id': builderProps?.uid ?? ''
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
exports.getLiquidProgressBarAttrs = getLiquidProgressBarAttrs;
|
|
42
|
+
exports.getLiquidTagAttrs = getLiquidTagAttrs;
|
|
43
|
+
exports.getLiquidTextAttrs = getLiquidTextAttrs;
|
|
44
|
+
exports.getWrapperAttrs = getWrapperAttrs;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@gem-sdk/core');
|
|
4
|
+
|
|
5
|
+
const getProgressBarClasses = (styles)=>{
|
|
6
|
+
const { effect } = styles ?? {};
|
|
7
|
+
const effectClasses = effect ? core.composeClasses("before:gp-absolute before:gp-left-0 before:gp-h-full before:gp-w-full before:gp-animate-shift before:gp-content-[''] before:gp-bg-stock-counter-animate before:gp-bg-[length:60px_100%] before:gp-shadow-stock-counter") : {};
|
|
8
|
+
return {
|
|
9
|
+
...core.composeClasses('gp-sc-progress-bar gp-relative gp-w-full -gp-scale-100 !gp-bg-[length:200%]'),
|
|
10
|
+
...effectClasses
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
const getContainerClasses = (setting)=>{
|
|
14
|
+
const { progressBarPosition = 'bottom' } = setting ?? {};
|
|
15
|
+
const isProgressBarBottom = progressBarPosition === 'bottom';
|
|
16
|
+
return {
|
|
17
|
+
...core.composeClasses('gp-inline-block gp-flex gp-flex-col gp-gap-y-1.5'),
|
|
18
|
+
'gp-flex-col': isProgressBarBottom,
|
|
19
|
+
'gp-flex-col-reverse': !isProgressBarBottom
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
const getLiquidTagClasses = (advanced)=>{
|
|
23
|
+
return {
|
|
24
|
+
...core.composeClasses('gp-product-stock-counter data-[visible=true]:gp-block data-[visible=false]:gp-hidden'),
|
|
25
|
+
...core.composeClasses(advanced?.cssClass)
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
const getWrapperIconClasses = (setting)=>{
|
|
29
|
+
const { iconPosition = 'left' } = setting ?? {};
|
|
30
|
+
return {
|
|
31
|
+
...core.composeClasses('gp-flex gp-items-baseline gp-gap-x-1'),
|
|
32
|
+
'gp-flex-row': iconPosition === 'left',
|
|
33
|
+
'gp-flex-row-reverse gp-justify-end': iconPosition === 'right'
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
const getIconClasses = ()=>{
|
|
37
|
+
return {
|
|
38
|
+
...core.composeClasses('gp-shrink-0 gp-bg-[length:60px_100%]')
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
const getTextClasses = (styles, isOutOfStock)=>{
|
|
42
|
+
const { typo, oosTextColor } = styles ?? {};
|
|
43
|
+
const displayTypo = {
|
|
44
|
+
...typo,
|
|
45
|
+
attrs: {
|
|
46
|
+
...typo?.attrs,
|
|
47
|
+
color: isOutOfStock ? oosTextColor : typo?.attrs?.color
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const appendTypoClass = core.composeTypographyClassName(displayTypo, styles?.typography);
|
|
51
|
+
return {
|
|
52
|
+
...core.composeClasses(appendTypoClass)
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
const getWrapperClasses = (setting, isOutOfStock)=>{
|
|
56
|
+
const { hiddenCounterWhenOutOfStock } = setting ?? {};
|
|
57
|
+
return {
|
|
58
|
+
'gp-opacity-50': isOutOfStock && hiddenCounterWhenOutOfStock
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
exports.getContainerClasses = getContainerClasses;
|
|
63
|
+
exports.getIconClasses = getIconClasses;
|
|
64
|
+
exports.getLiquidTagClasses = getLiquidTagClasses;
|
|
65
|
+
exports.getProgressBarClasses = getProgressBarClasses;
|
|
66
|
+
exports.getTextClasses = getTextClasses;
|
|
67
|
+
exports.getWrapperClasses = getWrapperClasses;
|
|
68
|
+
exports.getWrapperIconClasses = getWrapperIconClasses;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var helpers$1 = require('../../../helpers.js');
|
|
4
|
+
var _const = require('../../const.js');
|
|
5
|
+
var helpers = require('../../helpers.js');
|
|
6
|
+
|
|
7
|
+
const getLiquidTextContent = (setting, styles)=>{
|
|
8
|
+
const { template: templateString, outOfStockMessage, continueSelling, unlimitedQuantityMessage, remaining = 16, source = 'custom' } = setting ?? {};
|
|
9
|
+
const { textColor } = styles ?? {};
|
|
10
|
+
const mainColor = textColor || 'brand';
|
|
11
|
+
return `{% if inventory_management == null or inventory_management != "shopify" and inventory_quantity <= 0 %}
|
|
12
|
+
${helpers.transformHighlighTag(unlimitedQuantityMessage ?? helpers$1.getStaticLocale('StockCounter', 'let_buy_now'), mainColor)}
|
|
13
|
+
{% elsif available == false %}
|
|
14
|
+
${helpers.transformHighlighTag(outOfStockMessage || '', mainColor)}
|
|
15
|
+
{% elsif available and inventory_policy == '${_const.CONTINUE_SELLING_WHEN_OUT_OF_STOCK.toLowerCase()}' and inventory_quantity <= 0 %}
|
|
16
|
+
${helpers.transformHighlighTag(continueSelling || '', mainColor)}
|
|
17
|
+
{% else %}
|
|
18
|
+
${helpers.transformHighlighTag(helpers.transformNumberTag(templateString || '', mainColor, source === 'custom' ? remaining : `{{ inventory_quantity }}`), mainColor)}
|
|
19
|
+
{% endif %}`;
|
|
20
|
+
};
|
|
21
|
+
const getLiquidInitData = (setting, styles)=>{
|
|
22
|
+
const { scarcityThreshold = 0, hiddenCounterWhenOutOfStock, displayByDefault } = setting ?? {};
|
|
23
|
+
const { displayProgressBar } = styles ?? {};
|
|
24
|
+
const isScarcityThreshold = !!scarcityThreshold && scarcityThreshold > 0;
|
|
25
|
+
const checkDisplay = ()=>{
|
|
26
|
+
if (displayByDefault) return true;
|
|
27
|
+
return false;
|
|
28
|
+
};
|
|
29
|
+
return `{%- liquid
|
|
30
|
+
assign current_variant = variant
|
|
31
|
+
assign available = current_variant.available | default: false
|
|
32
|
+
assign inventory_management = current_variant.inventory_management | default: null
|
|
33
|
+
assign inventory_policy = current_variant.inventory_policy | default: 'deny'
|
|
34
|
+
assign inventory_quantity = current_variant.inventory_quantity | default: 0
|
|
35
|
+
assign scarcityThreshold = ${isScarcityThreshold}
|
|
36
|
+
assign check_display = ${checkDisplay()}
|
|
37
|
+
|
|
38
|
+
if inventory_management != null and available == false and inventory_quantity <= 0 and inventory_policy != '${_const.CONTINUE_SELLING_WHEN_OUT_OF_STOCK.toLowerCase()}'
|
|
39
|
+
assign is_out_of_stock = true
|
|
40
|
+
endif
|
|
41
|
+
|
|
42
|
+
if check_display == true
|
|
43
|
+
assign should_display = true
|
|
44
|
+
elsif ${isScarcityThreshold} and inventory_quantity >= 0 and inventory_quantity < ${scarcityThreshold}
|
|
45
|
+
assign should_display = true
|
|
46
|
+
else
|
|
47
|
+
assign should_display = false
|
|
48
|
+
endif
|
|
49
|
+
|
|
50
|
+
if ${hiddenCounterWhenOutOfStock === true} and available == false
|
|
51
|
+
assign should_display = false
|
|
52
|
+
endif
|
|
53
|
+
|
|
54
|
+
if ${displayProgressBar === true} and available
|
|
55
|
+
assign show_progress_bar = true
|
|
56
|
+
else
|
|
57
|
+
assign show_progress_bar = false
|
|
58
|
+
endif
|
|
59
|
+
-%}
|
|
60
|
+
{% capture variant_policy_list %}
|
|
61
|
+
{
|
|
62
|
+
{% for variant in product.variants %}
|
|
63
|
+
"{{ variant.id }}":"{{ variant.inventory_policy }}",
|
|
64
|
+
"{{ variant.id }}_management":"{{ variant.inventory_management }}"{% if forloop.last == false %},{% endif %}
|
|
65
|
+
{% endfor %}
|
|
66
|
+
}
|
|
67
|
+
{% endcapture %}`;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
exports.getLiquidInitData = getLiquidInitData;
|
|
71
|
+
exports.getLiquidTextContent = getLiquidTextContent;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const getInlineCss = (uniqId, borderRadius)=>{
|
|
4
|
+
const desktopRadius = getBorderRadius(borderRadius?.desktop);
|
|
5
|
+
const tabletRadius = getBorderRadius(borderRadius?.tablet);
|
|
6
|
+
const mobileRadius = getBorderRadius(borderRadius?.mobile);
|
|
7
|
+
if (uniqId) {
|
|
8
|
+
return `
|
|
9
|
+
.${uniqId} {
|
|
10
|
+
.gp-sc-progress-bar{
|
|
11
|
+
${desktopRadius}
|
|
12
|
+
}
|
|
13
|
+
.gp-sc-progress-bar:before{
|
|
14
|
+
${desktopRadius}
|
|
15
|
+
}
|
|
16
|
+
@media only screen and (max-width: 1024px) {
|
|
17
|
+
.gp-sc-progress-bar{
|
|
18
|
+
${tabletRadius}
|
|
19
|
+
}
|
|
20
|
+
.gp-sc-progress-bar:before{
|
|
21
|
+
${tabletRadius}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
@media only screen and (max-width: 767px) {
|
|
25
|
+
.gp-sc-progress-bar{
|
|
26
|
+
${mobileRadius}
|
|
27
|
+
}
|
|
28
|
+
.gp-sc-progress-bar:before{
|
|
29
|
+
${mobileRadius}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}`;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const getBorderRadius = (cornerRadius)=>{
|
|
36
|
+
return `border-top-left-radius: ${cornerRadius?.btlr ?? '0px'};border-top-right-radius: ${cornerRadius?.btrr ?? '0px'};border-bottom-left-radius: ${cornerRadius?.bblr ?? '0px'};border-bottom-right-radius: ${cornerRadius?.bbrr ?? '0px'};`;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
exports.getInlineCss = getInlineCss;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@gem-sdk/core');
|
|
4
|
+
|
|
5
|
+
const getProgressBarStyles = (styles, setting)=>{
|
|
6
|
+
const { progressBarHeight, color } = styles ?? {};
|
|
7
|
+
const { remainingPercentage } = setting ?? {};
|
|
8
|
+
let convertedProgressBarHeight;
|
|
9
|
+
if (progressBarHeight) {
|
|
10
|
+
convertedProgressBarHeight = Object.fromEntries(Object.entries(progressBarHeight).map(([key, value])=>[
|
|
11
|
+
key,
|
|
12
|
+
Number((value + '').replace('px', ''))
|
|
13
|
+
]));
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
...core.makeStyleResponsive('h', convertedProgressBarHeight, 'px'),
|
|
17
|
+
...core.makeStyle({
|
|
18
|
+
bg: 'linear-gradient(90deg, #eee 50%, transparent 50%)',
|
|
19
|
+
bgc: core.getSingleColorVariable(color),
|
|
20
|
+
bgp: `${remainingPercentage}% center`
|
|
21
|
+
})
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
const getContainerStyles = (styles)=>{
|
|
25
|
+
const { width, textColor } = styles ?? {};
|
|
26
|
+
return {
|
|
27
|
+
...core.makeStyleResponsive('w', core.makeWidth(width)),
|
|
28
|
+
...core.makeStyle({
|
|
29
|
+
c: core.getSingleColorVariable(textColor)
|
|
30
|
+
})
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
const getWrapperStyles = (styles)=>{
|
|
34
|
+
const { alignment } = styles ?? {};
|
|
35
|
+
return {
|
|
36
|
+
...core.makeStyleResponsive('ta', alignment)
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
const getIconStyles = (styles, setting, isOutOfStock)=>{
|
|
40
|
+
const { iconColor, oosIconColor } = styles ?? {};
|
|
41
|
+
const { iconSize } = setting ?? {};
|
|
42
|
+
return {
|
|
43
|
+
...core.makeStyle({
|
|
44
|
+
c: core.getSingleColorVariable(isOutOfStock ? oosIconColor : iconColor)
|
|
45
|
+
}),
|
|
46
|
+
...core.makeStyleResponsive('w', iconSize, 'px')
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
const getTextStyles = (styles, isOutOfStock)=>{
|
|
50
|
+
const { typo, oosTextColor } = styles ?? {};
|
|
51
|
+
const displayTypo = {
|
|
52
|
+
...typo,
|
|
53
|
+
attrs: {
|
|
54
|
+
...typo?.attrs,
|
|
55
|
+
color: isOutOfStock ? oosTextColor : typo?.attrs?.color
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const appendTypoStyle = core.composeTypographyStyle(displayTypo, styles?.typography);
|
|
59
|
+
return {
|
|
60
|
+
...appendTypoStyle,
|
|
61
|
+
...core.getStyleShadow({
|
|
62
|
+
value: typo?.custom?.textShadow,
|
|
63
|
+
styleAppliedFor: 'text-shadow',
|
|
64
|
+
isEnableShadow: typo?.custom?.textShadow?.type !== 'none'
|
|
65
|
+
})
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
exports.getContainerStyles = getContainerStyles;
|
|
70
|
+
exports.getIconStyles = getIconStyles;
|
|
71
|
+
exports.getProgressBarStyles = getProgressBarStyles;
|
|
72
|
+
exports.getTextStyles = getTextStyles;
|
|
73
|
+
exports.getWrapperStyles = getWrapperStyles;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@gem-sdk/core');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var _const = require('../../const.js');
|
|
6
|
+
var helpers = require('../../helpers.js');
|
|
7
|
+
|
|
8
|
+
const useStockCounter = (setting, styles)=>{
|
|
9
|
+
const { template, outOfStockMessage, continueSelling, unlimitedQuantityMessage, source = 'custom', remaining = 16 } = setting ?? {};
|
|
10
|
+
const { textColor } = styles ?? {};
|
|
11
|
+
const mainColor = textColor || 'brand';
|
|
12
|
+
const variant = core.useCurrentVariant();
|
|
13
|
+
const inventoryQuantity = React.useMemo(()=>{
|
|
14
|
+
return Number(variant ? variant.inventoryQuantity : 0);
|
|
15
|
+
}, [
|
|
16
|
+
variant
|
|
17
|
+
]);
|
|
18
|
+
const manageInventory = variant ? variant.manageInventory : true;
|
|
19
|
+
const inventoryPolicy = variant ? variant.inventoryPolicy : 'deny';
|
|
20
|
+
const isOutOfStock = manageInventory && inventoryQuantity <= _const.NO_PRODUCT_LEFT && inventoryPolicy !== _const.CONTINUE_SELLING_WHEN_OUT_OF_STOCK;
|
|
21
|
+
const isContinueShopping = inventoryPolicy === _const.CONTINUE_SELLING_WHEN_OUT_OF_STOCK && inventoryQuantity <= _const.NO_PRODUCT_LEFT;
|
|
22
|
+
const isUnlimitedQuantity = !manageInventory && unlimitedQuantityMessage;
|
|
23
|
+
function getMessage() {
|
|
24
|
+
if (isUnlimitedQuantity) return helpers.transformHighlighTag(unlimitedQuantityMessage, mainColor);
|
|
25
|
+
if (isOutOfStock) return helpers.transformHighlighTag(outOfStockMessage || '', mainColor);
|
|
26
|
+
if (isContinueShopping) return helpers.transformHighlighTag(continueSelling || '', mainColor);
|
|
27
|
+
const quantity = source === 'custom' ? remaining : inventoryQuantity;
|
|
28
|
+
return helpers.transformHighlighTag(helpers.transformNumberTag(template || '', mainColor, quantity), mainColor);
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
getMessage,
|
|
32
|
+
isOutOfStock,
|
|
33
|
+
inventoryQuantity
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
exports.useStockCounter = useStockCounter;
|
|
@@ -8,20 +8,14 @@ const DEFAULT_REMAINING_PERCENT = 20;
|
|
|
8
8
|
const MIN_REMAINING_PERCENT = 5;
|
|
9
9
|
const MAX_REMAINING_PERCENT = 100;
|
|
10
10
|
const DEFAULT_RANGE_STEP = 1;
|
|
11
|
-
const DEFAULT_PROGRESS_BAR_HEIGHT = 10;
|
|
12
|
-
const MIN_PROGRESS_BAR_HEIGHT = 5;
|
|
13
|
-
const MAX_PROGRESS_BAR_HEIGHT = 20;
|
|
14
11
|
const CONTINUE_SELLING_WHEN_OUT_OF_STOCK = 'CONTINUE';
|
|
15
12
|
|
|
16
13
|
exports.CONTINUE_SELLING_WHEN_OUT_OF_STOCK = CONTINUE_SELLING_WHEN_OUT_OF_STOCK;
|
|
17
14
|
exports.DEFAULT_HIGHLIGHT_TAG = DEFAULT_HIGHLIGHT_TAG;
|
|
18
|
-
exports.DEFAULT_PROGRESS_BAR_HEIGHT = DEFAULT_PROGRESS_BAR_HEIGHT;
|
|
19
15
|
exports.DEFAULT_QUANTITY_TEMPLATE = DEFAULT_QUANTITY_TEMPLATE;
|
|
20
16
|
exports.DEFAULT_RANGE_STEP = DEFAULT_RANGE_STEP;
|
|
21
17
|
exports.DEFAULT_REMAINING_PERCENT = DEFAULT_REMAINING_PERCENT;
|
|
22
18
|
exports.DEFAULT_SCARCITY_THRESHOLD = DEFAULT_SCARCITY_THRESHOLD;
|
|
23
|
-
exports.MAX_PROGRESS_BAR_HEIGHT = MAX_PROGRESS_BAR_HEIGHT;
|
|
24
19
|
exports.MAX_REMAINING_PERCENT = MAX_REMAINING_PERCENT;
|
|
25
|
-
exports.MIN_PROGRESS_BAR_HEIGHT = MIN_PROGRESS_BAR_HEIGHT;
|
|
26
20
|
exports.MIN_REMAINING_PERCENT = MIN_REMAINING_PERCENT;
|
|
27
21
|
exports.NO_PRODUCT_LEFT = NO_PRODUCT_LEFT;
|
|
@@ -35,20 +35,6 @@ const transformNumberTag = (template, stringColor, quantityLeft)=>{
|
|
|
35
35
|
}
|
|
36
36
|
return template.replaceAll(_const.DEFAULT_QUANTITY_TEMPLATE, quantityTag.replace('$quantity$', quantityLeft.toString()));
|
|
37
37
|
};
|
|
38
|
-
const convertSizeToWidth = (typographyVar)=>{
|
|
39
|
-
const widthObject = {};
|
|
40
|
-
if (typographyVar['--size']) {
|
|
41
|
-
widthObject['--w'] = typographyVar['--size'];
|
|
42
|
-
}
|
|
43
|
-
if (typographyVar['--size-tablet']) {
|
|
44
|
-
widthObject['--w-tablet'] = typographyVar['--size-tablet'];
|
|
45
|
-
}
|
|
46
|
-
if (typographyVar['--size-mobile']) {
|
|
47
|
-
widthObject['--w-mobile'] = typographyVar['--size-mobile'];
|
|
48
|
-
}
|
|
49
|
-
return widthObject;
|
|
50
|
-
};
|
|
51
38
|
|
|
52
|
-
exports.convertSizeToWidth = convertSizeToWidth;
|
|
53
39
|
exports.transformHighlighTag = transformHighlighTag;
|
|
54
40
|
exports.transformNumberTag = transformNumberTag;
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
var StockCounter$1 = require('./setting/StockCounter.js');
|
|
4
4
|
require('react/jsx-runtime');
|
|
5
|
-
require('@gem-sdk/core');
|
|
6
5
|
require('react');
|
|
6
|
+
require('@gem-sdk/core');
|
|
7
|
+
require('next/link');
|
|
8
|
+
require('@gem-sdk/system');
|
|
7
9
|
|
|
8
10
|
const stockCounterSetting = {
|
|
9
11
|
StockCounter: StockCounter$1.default
|