@sledge-app/react-instant-search 2.0.59 → 2.0.61

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.
@@ -590,8 +590,7 @@ const stringToSlug = (text) => {
590
590
  return text;
591
591
  return text.toLowerCase().replace(/[^\w ]+/g, "").replace(/ +/g, "-");
592
592
  };
593
- const shopifyFormatMoney = (cents, format) => {
594
- var _a;
593
+ const shopifyFormatMoney = (cents, format, selectedLocale) => {
595
594
  if (typeof cents == "string") {
596
595
  cents = cents.replace(".", "");
597
596
  }
@@ -612,19 +611,31 @@ const shopifyFormatMoney = (cents, format) => {
612
611
  var parts = number.split("."), dollars = parts[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1" + thousands), cents2 = parts[1] ? decimal + parts[1] : "";
613
612
  return dollars + cents2;
614
613
  }
615
- switch ((_a = formatString.match(placeholderRegex)) == null ? void 0 : _a[1]) {
616
- case "amount":
617
- value = formatWithDelimiters(cents, 2);
618
- break;
619
- case "amount_no_decimals":
620
- value = formatWithDelimiters(cents, 0);
621
- break;
622
- case "amount_with_comma_separator":
623
- value = formatWithDelimiters(cents, 2, ".", ",");
624
- break;
625
- case "amount_no_decimals_with_comma_separator":
626
- value = formatWithDelimiters(cents, 0, ".", ",");
627
- break;
614
+ function useFormatWithDelimiters() {
615
+ var _a;
616
+ switch ((_a = formatString.match(placeholderRegex)) == null ? void 0 : _a[1]) {
617
+ case "amount":
618
+ return formatWithDelimiters(cents, 2);
619
+ case "amount_no_decimals":
620
+ return formatWithDelimiters(cents, 0);
621
+ case "amount_with_comma_separator":
622
+ return formatWithDelimiters(cents, 2, ".", ",");
623
+ case "amount_no_decimals_with_comma_separator":
624
+ return formatWithDelimiters(cents, 0, ".", ",");
625
+ }
626
+ }
627
+ if (selectedLocale) {
628
+ if (cents) {
629
+ try {
630
+ value = new Intl.NumberFormat(selectedLocale).format(cents / 100);
631
+ } catch (error) {
632
+ value = useFormatWithDelimiters();
633
+ }
634
+ } else {
635
+ value = useFormatWithDelimiters();
636
+ }
637
+ } else {
638
+ value = useFormatWithDelimiters();
628
639
  }
629
640
  return formatString.replace(placeholderRegex, value);
630
641
  };
@@ -7060,6 +7071,7 @@ const FacetBlockSelected = React__default.memo(
7060
7071
  handleFilterChange,
7061
7072
  allowedFilterSlider
7062
7073
  } = props;
7074
+ const { isJsVersion, locale } = React__default.useContext(SledgeContext) || {};
7063
7075
  const { money_format: money_format_props } = generalDataSettings || {};
7064
7076
  const { separator: hierarchical_collections_separator } = hierarchicalCollectionsSettings || {};
7065
7077
  const {
@@ -7123,7 +7135,8 @@ const FacetBlockSelected = React__default.memo(
7123
7135
  if (getSettings == null ? void 0 : getSettings.rounded)
7124
7136
  money_format = (_f = money_format == null ? void 0 : money_format.replace) == null ? void 0 : _f.call(money_format, /\{\{\s*amount[^}]*\}\}/g, "{{amount_no_decimals}}");
7125
7137
  const getValueRange = new Set(value).size === 1 ? [value[0]] : value;
7126
- valueText = (_g = getValueRange == null ? void 0 : getValueRange.map((valueItem) => isPriceValue ? shopifyFormatMoney(valueItem * 100, money_format) : isSalePercent ? `${valueItem}%` : valueItem)) == null ? void 0 : _g.join(" - ");
7138
+ const selectedLocale = isJsVersion ? selectedLocaleJs() : locale;
7139
+ valueText = (_g = getValueRange == null ? void 0 : getValueRange.map((valueItem) => isPriceValue ? shopifyFormatMoney(valueItem * 100, money_format, selectedLocale) : isSalePercent ? `${valueItem}%` : valueItem)) == null ? void 0 : _g.join(" - ");
7127
7140
  } else {
7128
7141
  valueText = (_h = String(valueText)) == null ? void 0 : _h.replaceAll(hierarchical_collections_separator, " > ");
7129
7142
  }
@@ -7825,6 +7838,7 @@ const Facet = (props) => {
7825
7838
  keepCounterFacets,
7826
7839
  allowedFilterSlider
7827
7840
  } = props;
7841
+ const { isJsVersion, locale } = React__default.useContext(SledgeContext) || {};
7828
7842
  const [keywordFacet, setKeywordFacet] = React__default.useState("");
7829
7843
  const [showFacet, setShowFacet] = React__default.useState(false);
7830
7844
  const searchFacetRef = React__default.useRef(null);
@@ -8129,9 +8143,10 @@ const Facet = (props) => {
8129
8143
  defaultValueMin = (items == null ? void 0 : items.min) && Number(defaultValueMin) < Number(items == null ? void 0 : items.min) ? items == null ? void 0 : items.min : defaultValueMin;
8130
8144
  defaultValueMax = (items == null ? void 0 : items.max) && Number(defaultValueMax) > Number(items == null ? void 0 : items.max) ? items == null ? void 0 : items.max : defaultValueMax;
8131
8145
  }
8132
- let contentDefaultValueMin = isPriceValue ? shopifyFormatMoney(defaultValueMin * 100, money_format) : isSalePercent ? `${defaultValueMin}%` : defaultValueMin;
8133
- let contentDefaultValueMax = isPriceValue ? shopifyFormatMoney(defaultValueMax * 100, money_format) : isSalePercent ? `${defaultValueMax}%` : defaultValueMax;
8134
- let contentFacetStatsMax = isPriceValue ? shopifyFormatMoney((items == null ? void 0 : items.max) * 100, money_format) : isSalePercent ? `${items == null ? void 0 : items.max}%` : items == null ? void 0 : items.max;
8146
+ const selectedLocale = isJsVersion ? selectedLocaleJs() : locale;
8147
+ let contentDefaultValueMin = isPriceValue ? shopifyFormatMoney(defaultValueMin * 100, money_format, selectedLocale) : isSalePercent ? `${defaultValueMin}%` : defaultValueMin;
8148
+ let contentDefaultValueMax = isPriceValue ? shopifyFormatMoney(defaultValueMax * 100, money_format, selectedLocale) : isSalePercent ? `${defaultValueMax}%` : defaultValueMax;
8149
+ let contentFacetStatsMax = isPriceValue ? shopifyFormatMoney((items == null ? void 0 : items.max) * 100, money_format, selectedLocale) : isSalePercent ? `${items == null ? void 0 : items.max}%` : items == null ? void 0 : items.max;
8135
8150
  let descriptionInputRange = highest_price_info ? String(highest_price_info).replaceAll(OBJECT_DATA_STRING_KEY.PRICE_MAX_MONEY_FORMAT, contentFacetStatsMax) : `The highest price is ${contentFacetStatsMax}`;
8136
8151
  blockComponent = /* @__PURE__ */ jsxRuntimeExports.jsx(
8137
8152
  Slider,