@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.
Files changed (47) hide show
  1. package/dist/cjs/article/setting/configs/ArticleAuthor/uiV2.js +9 -2
  2. package/dist/cjs/article/setting/configs/ArticleDate/uiV2.js +13 -6
  3. package/dist/cjs/article/setting/configs/ArticleExcerpt/settings.js +1 -1
  4. package/dist/cjs/article/setting/configs/ArticleExcerpt/uiV2.js +11 -1
  5. package/dist/cjs/article/setting/configs/ArticleReadMore/presets.js +9 -9
  6. package/dist/cjs/article/setting/configs/ArticleReadMore/settings.js +4 -4
  7. package/dist/cjs/article/setting/configs/ArticleReadMore/uiV2.js +16 -12
  8. package/dist/cjs/stock-counter/components/StockCounter.js +104 -112
  9. package/dist/cjs/stock-counter/components/StockCounter.liquid.js +116 -141
  10. package/dist/cjs/stock-counter/components/common/getAttrs.js +44 -0
  11. package/dist/cjs/stock-counter/components/common/getClasses.js +68 -0
  12. package/dist/cjs/stock-counter/components/common/getContent.js +71 -0
  13. package/dist/cjs/stock-counter/components/common/getInlineCss.js +39 -0
  14. package/dist/cjs/stock-counter/components/common/getStyles.js +73 -0
  15. package/dist/cjs/stock-counter/components/hook/useStockCounter.js +37 -0
  16. package/dist/cjs/stock-counter/const.js +0 -6
  17. package/dist/cjs/stock-counter/helpers.js +0 -14
  18. package/dist/cjs/stock-counter/index.js +3 -1
  19. package/dist/cjs/stock-counter/setting/StockCounter.js +2 -2
  20. package/dist/cjs/stock-counter/setting/configs/presets.js +3 -0
  21. package/dist/cjs/stock-counter/setting/configs/{settings.js → settingsV2.js} +211 -42
  22. package/dist/cjs/stock-counter/setting/configs/uiV2.js +228 -41
  23. package/dist/esm/article/setting/configs/ArticleAuthor/uiV2.js +9 -2
  24. package/dist/esm/article/setting/configs/ArticleDate/uiV2.js +13 -6
  25. package/dist/esm/article/setting/configs/ArticleExcerpt/settings.js +1 -1
  26. package/dist/esm/article/setting/configs/ArticleExcerpt/uiV2.js +11 -1
  27. package/dist/esm/article/setting/configs/ArticleReadMore/presets.js +9 -9
  28. package/dist/esm/article/setting/configs/ArticleReadMore/settings.js +4 -4
  29. package/dist/esm/article/setting/configs/ArticleReadMore/uiV2.js +16 -12
  30. package/dist/esm/stock-counter/components/StockCounter.js +106 -114
  31. package/dist/esm/stock-counter/components/StockCounter.liquid.js +116 -141
  32. package/dist/esm/stock-counter/components/common/getAttrs.js +39 -0
  33. package/dist/esm/stock-counter/components/common/getClasses.js +60 -0
  34. package/dist/esm/stock-counter/components/common/getContent.js +68 -0
  35. package/dist/esm/stock-counter/components/common/getInlineCss.js +37 -0
  36. package/dist/esm/stock-counter/components/common/getStyles.js +67 -0
  37. package/dist/esm/stock-counter/components/hook/useStockCounter.js +35 -0
  38. package/dist/esm/stock-counter/const.js +1 -4
  39. package/dist/esm/stock-counter/helpers.js +1 -14
  40. package/dist/esm/stock-counter/index.js +3 -1
  41. package/dist/esm/stock-counter/setting/StockCounter.js +2 -2
  42. package/dist/esm/stock-counter/setting/configs/presets.js +3 -0
  43. package/dist/esm/stock-counter/setting/configs/settingsV2.js +438 -0
  44. package/dist/esm/stock-counter/setting/configs/uiV2.js +228 -41
  45. package/dist/types/index.d.ts +13 -5
  46. package/package.json +1 -1
  47. package/dist/esm/stock-counter/setting/configs/settings.js +0 -269
@@ -0,0 +1,68 @@
1
+ import { getStaticLocale } from '../../../helpers.js';
2
+ import { CONTINUE_SELLING_WHEN_OUT_OF_STOCK } from '../../const.js';
3
+ import { transformHighlighTag, transformNumberTag } from '../../helpers.js';
4
+
5
+ const getLiquidTextContent = (setting, styles)=>{
6
+ const { template: templateString, outOfStockMessage, continueSelling, unlimitedQuantityMessage, remaining = 16, source = 'custom' } = setting ?? {};
7
+ const { textColor } = styles ?? {};
8
+ const mainColor = textColor || 'brand';
9
+ return `{% if inventory_management == null or inventory_management != "shopify" and inventory_quantity <= 0 %}
10
+ ${transformHighlighTag(unlimitedQuantityMessage ?? getStaticLocale('StockCounter', 'let_buy_now'), mainColor)}
11
+ {% elsif available == false %}
12
+ ${transformHighlighTag(outOfStockMessage || '', mainColor)}
13
+ {% elsif available and inventory_policy == '${CONTINUE_SELLING_WHEN_OUT_OF_STOCK.toLowerCase()}' and inventory_quantity <= 0 %}
14
+ ${transformHighlighTag(continueSelling || '', mainColor)}
15
+ {% else %}
16
+ ${transformHighlighTag(transformNumberTag(templateString || '', mainColor, source === 'custom' ? remaining : `{{ inventory_quantity }}`), mainColor)}
17
+ {% endif %}`;
18
+ };
19
+ const getLiquidInitData = (setting, styles)=>{
20
+ const { scarcityThreshold = 0, hiddenCounterWhenOutOfStock, displayByDefault } = setting ?? {};
21
+ const { displayProgressBar } = styles ?? {};
22
+ const isScarcityThreshold = !!scarcityThreshold && scarcityThreshold > 0;
23
+ const checkDisplay = ()=>{
24
+ if (displayByDefault) return true;
25
+ return false;
26
+ };
27
+ return `{%- liquid
28
+ assign current_variant = variant
29
+ assign available = current_variant.available | default: false
30
+ assign inventory_management = current_variant.inventory_management | default: null
31
+ assign inventory_policy = current_variant.inventory_policy | default: 'deny'
32
+ assign inventory_quantity = current_variant.inventory_quantity | default: 0
33
+ assign scarcityThreshold = ${isScarcityThreshold}
34
+ assign check_display = ${checkDisplay()}
35
+
36
+ if inventory_management != null and available == false and inventory_quantity <= 0 and inventory_policy != '${CONTINUE_SELLING_WHEN_OUT_OF_STOCK.toLowerCase()}'
37
+ assign is_out_of_stock = true
38
+ endif
39
+
40
+ if check_display == true
41
+ assign should_display = true
42
+ elsif ${isScarcityThreshold} and inventory_quantity >= 0 and inventory_quantity < ${scarcityThreshold}
43
+ assign should_display = true
44
+ else
45
+ assign should_display = false
46
+ endif
47
+
48
+ if ${hiddenCounterWhenOutOfStock === true} and available == false
49
+ assign should_display = false
50
+ endif
51
+
52
+ if ${displayProgressBar === true} and available
53
+ assign show_progress_bar = true
54
+ else
55
+ assign show_progress_bar = false
56
+ endif
57
+ -%}
58
+ {% capture variant_policy_list %}
59
+ {
60
+ {% for variant in product.variants %}
61
+ "{{ variant.id }}":"{{ variant.inventory_policy }}",
62
+ "{{ variant.id }}_management":"{{ variant.inventory_management }}"{% if forloop.last == false %},{% endif %}
63
+ {% endfor %}
64
+ }
65
+ {% endcapture %}`;
66
+ };
67
+
68
+ export { getLiquidInitData, getLiquidTextContent };
@@ -0,0 +1,37 @@
1
+ const getInlineCss = (uniqId, borderRadius)=>{
2
+ const desktopRadius = getBorderRadius(borderRadius?.desktop);
3
+ const tabletRadius = getBorderRadius(borderRadius?.tablet);
4
+ const mobileRadius = getBorderRadius(borderRadius?.mobile);
5
+ if (uniqId) {
6
+ return `
7
+ .${uniqId} {
8
+ .gp-sc-progress-bar{
9
+ ${desktopRadius}
10
+ }
11
+ .gp-sc-progress-bar:before{
12
+ ${desktopRadius}
13
+ }
14
+ @media only screen and (max-width: 1024px) {
15
+ .gp-sc-progress-bar{
16
+ ${tabletRadius}
17
+ }
18
+ .gp-sc-progress-bar:before{
19
+ ${tabletRadius}
20
+ }
21
+ }
22
+ @media only screen and (max-width: 767px) {
23
+ .gp-sc-progress-bar{
24
+ ${mobileRadius}
25
+ }
26
+ .gp-sc-progress-bar:before{
27
+ ${mobileRadius}
28
+ }
29
+ }
30
+ }`;
31
+ }
32
+ };
33
+ const getBorderRadius = (cornerRadius)=>{
34
+ 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'};`;
35
+ };
36
+
37
+ export { getInlineCss };
@@ -0,0 +1,67 @@
1
+ import { makeStyleResponsive, makeStyle, getSingleColorVariable, makeWidth, composeTypographyStyle, getStyleShadow } from '@gem-sdk/core';
2
+
3
+ const getProgressBarStyles = (styles, setting)=>{
4
+ const { progressBarHeight, color } = styles ?? {};
5
+ const { remainingPercentage } = setting ?? {};
6
+ let convertedProgressBarHeight;
7
+ if (progressBarHeight) {
8
+ convertedProgressBarHeight = Object.fromEntries(Object.entries(progressBarHeight).map(([key, value])=>[
9
+ key,
10
+ Number((value + '').replace('px', ''))
11
+ ]));
12
+ }
13
+ return {
14
+ ...makeStyleResponsive('h', convertedProgressBarHeight, 'px'),
15
+ ...makeStyle({
16
+ bg: 'linear-gradient(90deg, #eee 50%, transparent 50%)',
17
+ bgc: getSingleColorVariable(color),
18
+ bgp: `${remainingPercentage}% center`
19
+ })
20
+ };
21
+ };
22
+ const getContainerStyles = (styles)=>{
23
+ const { width, textColor } = styles ?? {};
24
+ return {
25
+ ...makeStyleResponsive('w', makeWidth(width)),
26
+ ...makeStyle({
27
+ c: getSingleColorVariable(textColor)
28
+ })
29
+ };
30
+ };
31
+ const getWrapperStyles = (styles)=>{
32
+ const { alignment } = styles ?? {};
33
+ return {
34
+ ...makeStyleResponsive('ta', alignment)
35
+ };
36
+ };
37
+ const getIconStyles = (styles, setting, isOutOfStock)=>{
38
+ const { iconColor, oosIconColor } = styles ?? {};
39
+ const { iconSize } = setting ?? {};
40
+ return {
41
+ ...makeStyle({
42
+ c: getSingleColorVariable(isOutOfStock ? oosIconColor : iconColor)
43
+ }),
44
+ ...makeStyleResponsive('w', iconSize, 'px')
45
+ };
46
+ };
47
+ const getTextStyles = (styles, isOutOfStock)=>{
48
+ const { typo, oosTextColor } = styles ?? {};
49
+ const displayTypo = {
50
+ ...typo,
51
+ attrs: {
52
+ ...typo?.attrs,
53
+ color: isOutOfStock ? oosTextColor : typo?.attrs?.color
54
+ }
55
+ };
56
+ const appendTypoStyle = composeTypographyStyle(displayTypo, styles?.typography);
57
+ return {
58
+ ...appendTypoStyle,
59
+ ...getStyleShadow({
60
+ value: typo?.custom?.textShadow,
61
+ styleAppliedFor: 'text-shadow',
62
+ isEnableShadow: typo?.custom?.textShadow?.type !== 'none'
63
+ })
64
+ };
65
+ };
66
+
67
+ export { getContainerStyles, getIconStyles, getProgressBarStyles, getTextStyles, getWrapperStyles };
@@ -0,0 +1,35 @@
1
+ import { useCurrentVariant } from '@gem-sdk/core';
2
+ import { useMemo } from 'react';
3
+ import { NO_PRODUCT_LEFT, CONTINUE_SELLING_WHEN_OUT_OF_STOCK } from '../../const.js';
4
+ import { transformHighlighTag, transformNumberTag } from '../../helpers.js';
5
+
6
+ const useStockCounter = (setting, styles)=>{
7
+ const { template, outOfStockMessage, continueSelling, unlimitedQuantityMessage, source = 'custom', remaining = 16 } = setting ?? {};
8
+ const { textColor } = styles ?? {};
9
+ const mainColor = textColor || 'brand';
10
+ const variant = useCurrentVariant();
11
+ const inventoryQuantity = useMemo(()=>{
12
+ return Number(variant ? variant.inventoryQuantity : 0);
13
+ }, [
14
+ variant
15
+ ]);
16
+ const manageInventory = variant ? variant.manageInventory : true;
17
+ const inventoryPolicy = variant ? variant.inventoryPolicy : 'deny';
18
+ const isOutOfStock = manageInventory && inventoryQuantity <= NO_PRODUCT_LEFT && inventoryPolicy !== CONTINUE_SELLING_WHEN_OUT_OF_STOCK;
19
+ const isContinueShopping = inventoryPolicy === CONTINUE_SELLING_WHEN_OUT_OF_STOCK && inventoryQuantity <= NO_PRODUCT_LEFT;
20
+ const isUnlimitedQuantity = !manageInventory && unlimitedQuantityMessage;
21
+ function getMessage() {
22
+ if (isUnlimitedQuantity) return transformHighlighTag(unlimitedQuantityMessage, mainColor);
23
+ if (isOutOfStock) return transformHighlighTag(outOfStockMessage || '', mainColor);
24
+ if (isContinueShopping) return transformHighlighTag(continueSelling || '', mainColor);
25
+ const quantity = source === 'custom' ? remaining : inventoryQuantity;
26
+ return transformHighlighTag(transformNumberTag(template || '', mainColor, quantity), mainColor);
27
+ }
28
+ return {
29
+ getMessage,
30
+ isOutOfStock,
31
+ inventoryQuantity
32
+ };
33
+ };
34
+
35
+ export { useStockCounter };
@@ -6,9 +6,6 @@ const DEFAULT_REMAINING_PERCENT = 20;
6
6
  const MIN_REMAINING_PERCENT = 5;
7
7
  const MAX_REMAINING_PERCENT = 100;
8
8
  const DEFAULT_RANGE_STEP = 1;
9
- const DEFAULT_PROGRESS_BAR_HEIGHT = 10;
10
- const MIN_PROGRESS_BAR_HEIGHT = 5;
11
- const MAX_PROGRESS_BAR_HEIGHT = 20;
12
9
  const CONTINUE_SELLING_WHEN_OUT_OF_STOCK = 'CONTINUE';
13
10
 
14
- export { CONTINUE_SELLING_WHEN_OUT_OF_STOCK, DEFAULT_HIGHLIGHT_TAG, DEFAULT_PROGRESS_BAR_HEIGHT, DEFAULT_QUANTITY_TEMPLATE, DEFAULT_RANGE_STEP, DEFAULT_REMAINING_PERCENT, DEFAULT_SCARCITY_THRESHOLD, MAX_PROGRESS_BAR_HEIGHT, MAX_REMAINING_PERCENT, MIN_PROGRESS_BAR_HEIGHT, MIN_REMAINING_PERCENT, NO_PRODUCT_LEFT };
11
+ export { CONTINUE_SELLING_WHEN_OUT_OF_STOCK, DEFAULT_HIGHLIGHT_TAG, DEFAULT_QUANTITY_TEMPLATE, DEFAULT_RANGE_STEP, DEFAULT_REMAINING_PERCENT, DEFAULT_SCARCITY_THRESHOLD, MAX_REMAINING_PERCENT, MIN_REMAINING_PERCENT, NO_PRODUCT_LEFT };
@@ -33,18 +33,5 @@ const transformNumberTag = (template, stringColor, quantityLeft)=>{
33
33
  }
34
34
  return template.replaceAll(DEFAULT_QUANTITY_TEMPLATE, quantityTag.replace('$quantity$', quantityLeft.toString()));
35
35
  };
36
- const convertSizeToWidth = (typographyVar)=>{
37
- const widthObject = {};
38
- if (typographyVar['--size']) {
39
- widthObject['--w'] = typographyVar['--size'];
40
- }
41
- if (typographyVar['--size-tablet']) {
42
- widthObject['--w-tablet'] = typographyVar['--size-tablet'];
43
- }
44
- if (typographyVar['--size-mobile']) {
45
- widthObject['--w-mobile'] = typographyVar['--size-mobile'];
46
- }
47
- return widthObject;
48
- };
49
36
 
50
- export { convertSizeToWidth, transformHighlighTag, transformNumberTag };
37
+ export { transformHighlighTag, transformNumberTag };
@@ -1,7 +1,9 @@
1
1
  import config from './setting/StockCounter.js';
2
2
  import 'react/jsx-runtime';
3
- import '@gem-sdk/core';
4
3
  import 'react';
4
+ import '@gem-sdk/core';
5
+ import 'next/link';
6
+ import '@gem-sdk/system';
5
7
 
6
8
  const stockCounterSetting = {
7
9
  StockCounter: config
@@ -1,4 +1,4 @@
1
- import { StockCounterSettings } from './configs/settings.js';
1
+ import { StockCounterSettingsV2 } from './configs/settingsV2.js';
2
2
  import { SettingUIV1 } from './configs/uiV1.js';
3
3
  import { SettingUIV2 } from './configs/uiV2.js';
4
4
  import { StockCounterPreset } from './configs/presets.js';
@@ -11,7 +11,7 @@ const config = {
11
11
  <path d="M33.3905 11.2545C33.1953 11.4498 32.8787 11.4498 32.6834 11.2545L29.8643 8.43541C29.6691 8.24014 29.6691 7.92356 29.8643 7.7283L30.9203 6.67231C31.1156 6.47705 31.4322 6.47705 31.6274 6.67231L34.4465 9.49139C34.6418 9.68666 34.6418 10.0032 34.4465 10.1985L33.3905 11.2545ZM15.7838 4.68533C15.7838 4.96148 16.0077 5.18534 16.2838 5.18534H22.84C23.1161 5.18534 23.34 4.96148 23.34 4.68534V3.16663C23.34 2.89048 23.1161 2.66663 22.84 2.66663H16.2838C16.0077 2.66663 15.7838 2.89048 15.7838 3.16663V4.68533ZM28.3774 28.6093L20.8212 21.0532V10.3487C26.4883 10.9784 30.8961 15.7639 30.8961 21.5569C30.8961 24.2016 30.0145 26.7203 28.3774 28.6093ZM8.22769 21.5569C8.22769 15.7639 12.6354 10.9784 18.3025 10.3487V21.7724C18.3025 22.0376 18.4079 22.292 18.5954 22.4795L26.6143 30.4984C24.7252 32.0096 22.2065 33.0171 19.5619 33.0171C13.2651 32.8911 8.22769 27.8537 8.22769 21.5569ZM19.5619 7.70404C11.8798 7.70404 5.70898 13.8749 5.70898 21.5569C5.70898 29.239 11.8798 35.4098 19.5619 35.4098C27.2439 35.4098 33.4148 29.239 33.4148 21.5569C33.4148 13.8749 27.2439 7.70404 19.5619 7.70404Z" fill="currentColor"/>
12
12
  </svg>
13
13
  `,
14
- settings: StockCounterSettings,
14
+ settings: StockCounterSettingsV2,
15
15
  ui: SettingUIV1,
16
16
  uiV2: SettingUIV2,
17
17
  editorConfigs: {
@@ -14,6 +14,9 @@ const StockCounterPreset = [
14
14
  components: [
15
15
  {
16
16
  tag: 'StockCounter',
17
+ settings: {
18
+ layout: 'icon-and-text'
19
+ },
17
20
  styles: {
18
21
  displayProgressBar: false
19
22
  },