@pelcro/react-pelcro-js 2.6.0-beta.3 → 2.6.0-beta.4

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/index.cjs.js CHANGED
@@ -6327,13 +6327,34 @@ const getAddressById = id => {
6327
6327
  };
6328
6328
  /**
6329
6329
  * Transforms locale names stored in our backend like
6330
- * "en_US" into the standerd accepted in core i18n methods: "en-US"
6330
+ * "en_US" into the standard accepted in core i18n methods: "en-US"
6331
6331
  * @param {string} localeName
6332
6332
  * @return {string | undefined}
6333
6333
  * @example getCanonicalLocaleFormat("en_US") => "en-US"
6334
6334
  */
6335
6335
 
6336
6336
  const getCanonicalLocaleFormat = localeName => localeName === null || localeName === void 0 ? void 0 : localeName.replace("_", "-");
6337
+ /**
6338
+ * @param {string} localeName
6339
+ * @return {string | undefined}
6340
+ * @example getLanguageWithoutRegion("en-US") => "en"
6341
+ */
6342
+
6343
+ const getLanguageWithoutRegion = localeName => {
6344
+ var _getCanonicalLocaleFo;
6345
+
6346
+ return (_getCanonicalLocaleFo = getCanonicalLocaleFormat(localeName)) === null || _getCanonicalLocaleFo === void 0 ? void 0 : _getCanonicalLocaleFo.split("-")[0];
6347
+ };
6348
+ /**
6349
+ * Gets the current page language or fallbacks to site default
6350
+ * @return {string | undefined}
6351
+ */
6352
+
6353
+ const getPageOrDefaultLanguage = () => {
6354
+ var _window$Pelcro$helper, _window$Pelcro, _window$Pelcro$site, _window$Pelcro$site$r, _window$Pelcro$site$r2;
6355
+
6356
+ return (_window$Pelcro$helper = window.Pelcro.helpers.getHtmlLanguageAttribute()) !== null && _window$Pelcro$helper !== void 0 ? _window$Pelcro$helper : getLanguageWithoutRegion((_window$Pelcro = window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$site = _window$Pelcro.site) === null || _window$Pelcro$site === void 0 ? void 0 : (_window$Pelcro$site$r = _window$Pelcro$site.read) === null || _window$Pelcro$site$r === void 0 ? void 0 : (_window$Pelcro$site$r2 = _window$Pelcro$site$r.call(_window$Pelcro$site)) === null || _window$Pelcro$site$r2 === void 0 ? void 0 : _window$Pelcro$site$r2.default_locale);
6357
+ };
6337
6358
  /**
6338
6359
  * Returns a formatted price string depending on locale
6339
6360
  * @param {number} amount
@@ -6343,7 +6364,7 @@ const getCanonicalLocaleFormat = localeName => localeName === null || localeName
6343
6364
  * @example getFormattedPriceByLocal(10, 'USD', 'en-US') => "$10.00"
6344
6365
  */
6345
6366
 
6346
- const getFormattedPriceByLocal = (amount, currency = "USD", locale = "en-US") => {
6367
+ const getFormattedPriceByLocal = (amount, currency = "USD", locale = "en") => {
6347
6368
  const formatter = new Intl.NumberFormat(getCanonicalLocaleFormat(locale), {
6348
6369
  style: "currency",
6349
6370
  currency
@@ -6368,8 +6389,7 @@ const calcAndFormatItemsTotal = (items, currency) => {
6368
6389
  totalWithoutDividingBy100 += parseFloat(item.price ? (item.price * item.quantity).toFixed(2) : item.amount.toFixed(2));
6369
6390
  }
6370
6391
 
6371
- const locale = window.Pelcro.site.read().default_locale;
6372
- return getFormattedPriceByLocal(totalWithoutDividingBy100, currency, locale);
6392
+ return getFormattedPriceByLocal(totalWithoutDividingBy100, currency, getPageOrDefaultLanguage());
6373
6393
  };
6374
6394
  /**
6375
6395
  * returns true if the URL contains a supported view trigger URL
@@ -6383,12 +6403,15 @@ const isValidViewFromURL = viewID => {
6383
6403
  }
6384
6404
 
6385
6405
  return false;
6406
+ /**
6407
+ *
6408
+ */
6386
6409
 
6387
6410
  function hasValidNewsletterUpdateUrl() {
6388
- var _window$Pelcro, _window$Pelcro$uiSett;
6411
+ var _window$Pelcro2, _window$Pelcro2$uiSet;
6389
6412
 
6390
6413
  if (viewID !== "newsletter-update") return false;
6391
- const newsletters = (_window$Pelcro = window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$uiSett = _window$Pelcro.uiSettings) === null || _window$Pelcro$uiSett === void 0 ? void 0 : _window$Pelcro$uiSett.newsletters;
6414
+ const newsletters = (_window$Pelcro2 = window.Pelcro) === null || _window$Pelcro2 === void 0 ? void 0 : (_window$Pelcro2$uiSet = _window$Pelcro2.uiSettings) === null || _window$Pelcro2$uiSet === void 0 ? void 0 : _window$Pelcro2$uiSet.newsletters;
6392
6415
  const siteHasNewslettersDefined = Array.isArray(newsletters) && newsletters.length > 0;
6393
6416
 
6394
6417
  if (!siteHasNewslettersDefined) {
@@ -6562,9 +6585,8 @@ const getPaymentCardIcon$1 = name => {
6562
6585
  }));
6563
6586
  };
6564
6587
 
6565
- var _window$Pelcro, _window$Pelcro$site, _window$Pelcro$site$r, _window$Pelcro$site$r2;
6566
6588
  const resources = {
6567
- "en-US": {
6589
+ en: {
6568
6590
  common: common_en,
6569
6591
  paymentMethod: paymentMethod_en,
6570
6592
  newsletter: newsletter_en,
@@ -6586,7 +6608,7 @@ const resources = {
6586
6608
  select: select_en,
6587
6609
  notification: notification_en
6588
6610
  },
6589
- "fr-CA": {
6611
+ fr: {
6590
6612
  common: common_fr,
6591
6613
  paymentMethod: paymentMethod_fr,
6592
6614
  newsletter: newsletter_fr,
@@ -6608,13 +6630,14 @@ const resources = {
6608
6630
  select: select_fr,
6609
6631
  notification: notification_fr
6610
6632
  }
6611
- };
6612
- let locale = (_window$Pelcro = window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$site = _window$Pelcro.site) === null || _window$Pelcro$site === void 0 ? void 0 : (_window$Pelcro$site$r = _window$Pelcro$site.read) === null || _window$Pelcro$site$r === void 0 ? void 0 : (_window$Pelcro$site$r2 = _window$Pelcro$site$r.call(_window$Pelcro$site)) === null || _window$Pelcro$site$r2 === void 0 ? void 0 : _window$Pelcro$site$r2.default_locale;
6613
- if (!locale) locale = "en-US";
6633
+ }; // set UI language to the page language or default to the language in site settings
6634
+
6635
+ const locale = getPageOrDefaultLanguage();
6614
6636
  i18next.use(initReactI18next) // passes i18n down to react-i18next,
6615
6637
  .init({
6616
6638
  resources,
6617
- lng: getCanonicalLocaleFormat(locale),
6639
+ lng: locale,
6640
+ fallbackLng: "en",
6618
6641
  // debug: true,
6619
6642
  interpolation: {
6620
6643
  escapeValue: false // react already safes from xss
@@ -6625,6 +6648,16 @@ i18next.use(initReactI18next) // passes i18n down to react-i18next,
6625
6648
 
6626
6649
  }
6627
6650
  });
6651
+ const pageLanguageObserver = new MutationObserver(mutationsList => {
6652
+ mutationsList.forEach(mutationRecord => {
6653
+ if (mutationRecord.attributeName === "lang") {
6654
+ i18next.changeLanguage(window.Pelcro.helpers.getHtmlLanguageAttribute());
6655
+ }
6656
+ });
6657
+ });
6658
+ pageLanguageObserver.observe(document.documentElement, {
6659
+ attributes: true
6660
+ });
6628
6661
 
6629
6662
  function _classPrivateFieldGet(receiver, privateMap) {
6630
6663
  var descriptor = privateMap.get(receiver);
@@ -9920,7 +9953,7 @@ const FacebookLoginButton = ({
9920
9953
  labelClassName = "",
9921
9954
  iconClassName = ""
9922
9955
  }) => {
9923
- var _window$Pelcro$site$r, _window$Pelcro$site$r2;
9956
+ var _window$Pelcro$site$r;
9924
9957
 
9925
9958
  const facebookLoginEnabled = (_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.facebook_app_id;
9926
9959
  const {
@@ -9959,7 +9992,7 @@ const FacebookLoginButton = ({
9959
9992
 
9960
9993
  return facebookLoginEnabled ? /*#__PURE__*/React__default['default'].createElement(FacebookLogin, {
9961
9994
  appId: window.Pelcro.site.read().facebook_app_id,
9962
- language: (_window$Pelcro$site$r2 = window.Pelcro.site.read().default_locale) !== null && _window$Pelcro$site$r2 !== void 0 ? _window$Pelcro$site$r2 : "en_US",
9995
+ language: getPageOrDefaultLanguage(),
9963
9996
  fields: "first_name,last_name,email,picture",
9964
9997
  callback: onSuccess,
9965
9998
  onFailure: onFailure,
@@ -13493,7 +13526,7 @@ const PaymentMethodContainer = props => {
13493
13526
  return /*#__PURE__*/React__default['default'].createElement(es_13, {
13494
13527
  apiKey: window.Pelcro.environment.stripe,
13495
13528
  stripeAccount: window.Pelcro.site.read().account_id,
13496
- locale: getCanonicalLocaleFormat(window.Pelcro.site.read().default_locale)
13529
+ locale: getPageOrDefaultLanguage()
13497
13530
  }, /*#__PURE__*/React__default['default'].createElement(es_11, null, /*#__PURE__*/React__default['default'].createElement(UnwrappedForm, Object.assign({
13498
13531
  store: store$d
13499
13532
  }, props))));
@@ -13605,9 +13638,6 @@ const DiscountedPrice = props => {
13605
13638
  percentOff
13606
13639
  }
13607
13640
  } = React.useContext(store$d);
13608
- const {
13609
- default_locale
13610
- } = Pelcro.site.read();
13611
13641
  const {
13612
13642
  order,
13613
13643
  plan
@@ -13615,7 +13645,7 @@ const DiscountedPrice = props => {
13615
13645
  const ecommOrderCurrency = (_order$currency = order === null || order === void 0 ? void 0 : order.currency) !== null && _order$currency !== void 0 ? _order$currency : order === null || order === void 0 ? void 0 : (_order$ = order[0]) === null || _order$ === void 0 ? void 0 : _order$.currency;
13616
13646
  const planQuantity = (_plan$quantity = plan === null || plan === void 0 ? void 0 : plan.quantity) !== null && _plan$quantity !== void 0 ? _plan$quantity : 1;
13617
13647
  const discountedPriceWithoutTax = updatedPrice - taxAmount;
13618
- const priceFormatted = getFormattedPriceByLocal(order ? updatedPrice : discountedPriceWithoutTax * planQuantity, ecommOrderCurrency !== null && ecommOrderCurrency !== void 0 ? ecommOrderCurrency : plan === null || plan === void 0 ? void 0 : plan.currency, default_locale);
13648
+ const priceFormatted = getFormattedPriceByLocal(order ? updatedPrice : discountedPriceWithoutTax * planQuantity, ecommOrderCurrency !== null && ecommOrderCurrency !== void 0 ? ecommOrderCurrency : plan === null || plan === void 0 ? void 0 : plan.currency, getPageOrDefaultLanguage());
13619
13649
 
13620
13650
  if (percentOff) {
13621
13651
  return /*#__PURE__*/React__default['default'].createElement("div", Object.assign({
@@ -13648,12 +13678,9 @@ const SubmitPaymentMethod = ({
13648
13678
  updatedPrice
13649
13679
  }
13650
13680
  } = React.useContext(store$d);
13651
- const {
13652
- default_locale
13653
- } = Pelcro.site.read();
13654
13681
  const planQuantity = (_plan$quantity = plan === null || plan === void 0 ? void 0 : plan.quantity) !== null && _plan$quantity !== void 0 ? _plan$quantity : 1;
13655
13682
  const price = updatedPrice !== null && updatedPrice !== void 0 ? updatedPrice : plan === null || plan === void 0 ? void 0 : plan.amount;
13656
- const priceFormatted = getFormattedPriceByLocal(price * planQuantity, plan === null || plan === void 0 ? void 0 : plan.currency, default_locale);
13683
+ const priceFormatted = getFormattedPriceByLocal(price * planQuantity, plan === null || plan === void 0 ? void 0 : plan.currency, getPageOrDefaultLanguage());
13657
13684
  return /*#__PURE__*/React__default['default'].createElement(Button, Object.assign({
13658
13685
  role: "submit",
13659
13686
  className: "plc-w-full plc-py-3",
@@ -13898,7 +13925,7 @@ class PaypalClient {
13898
13925
  this.paypalButton = window.paypal.Buttons({
13899
13926
  fundingSource: window.paypal.FUNDING.PAYPAL,
13900
13927
  // button locale
13901
- locale: (_this$config$locale = this.config.locale) !== null && _this$config$locale !== void 0 ? _this$config$locale : this.siteInfo.default_locale,
13928
+ locale: (_this$config$locale = this.config.locale) !== null && _this$config$locale !== void 0 ? _this$config$locale : getPageOrDefaultLanguage(),
13902
13929
  // button style
13903
13930
  style: (_this$config$style = this.config.style) !== null && _this$config$style !== void 0 ? _this$config$style : defaultButtonStyle,
13904
13931
  // create payment handler
@@ -13995,7 +14022,7 @@ class PaypalClient {
13995
14022
  } : undefined,
13996
14023
  shippingAddressEditable: this.config.shippingAddressEditable,
13997
14024
  displayName: (_this$config$displayN = this.config.displayName) !== null && _this$config$displayN !== void 0 ? _this$config$displayN : this.siteInfo.name,
13998
- locale: (_this$config$locale2 = this.config.locale) !== null && _this$config$locale2 !== void 0 ? _this$config$locale2 : this.siteInfo.default_locale
14025
+ locale: (_this$config$locale2 = this.config.locale) !== null && _this$config$locale2 !== void 0 ? _this$config$locale2 : getPageOrDefaultLanguage()
13999
14026
  };
14000
14027
  }
14001
14028
  });
@@ -14004,7 +14031,7 @@ class PaypalClient {
14004
14031
  writable: true,
14005
14032
  value: () => {
14006
14033
  const totalAmount = (this.product.quantity || 1) * this.amount;
14007
- const priceFormatted = getFormattedPriceByLocal(totalAmount, this.product.currency, this.siteInfo.default_locale);
14034
+ const priceFormatted = getFormattedPriceByLocal(totalAmount, this.product.currency, getPageOrDefaultLanguage());
14008
14035
  const autoRenewed = this.product.auto_renew;
14009
14036
  const {
14010
14037
  interval,
@@ -14201,14 +14228,11 @@ const TaxAmount = () => {
14201
14228
  taxAmount
14202
14229
  }
14203
14230
  } = React.useContext(store$d);
14204
- const {
14205
- default_locale
14206
- } = Pelcro.site.read();
14207
14231
  const {
14208
14232
  plan
14209
14233
  } = usePelcro();
14210
14234
  const planQuantity = (_plan$quantity = plan === null || plan === void 0 ? void 0 : plan.quantity) !== null && _plan$quantity !== void 0 ? _plan$quantity : 1;
14211
- const priceFormatted = getFormattedPriceByLocal(taxAmount * planQuantity, plan === null || plan === void 0 ? void 0 : plan.currency, default_locale);
14235
+ const priceFormatted = getFormattedPriceByLocal(taxAmount * planQuantity, plan === null || plan === void 0 ? void 0 : plan.currency, getPageOrDefaultLanguage());
14212
14236
 
14213
14237
  if (taxAmount) {
14214
14238
  return /*#__PURE__*/React__default['default'].createElement("div", {
@@ -15081,10 +15105,7 @@ const SubscriptionCreateView = ({
15081
15105
  interval,
15082
15106
  count: interval_count
15083
15107
  });
15084
- const {
15085
- default_locale
15086
- } = Pelcro.site.read();
15087
- const priceFormatted = getFormattedPriceByLocal((plan === null || plan === void 0 ? void 0 : plan.amount) * ((_plan$quantity = plan === null || plan === void 0 ? void 0 : plan.quantity) !== null && _plan$quantity !== void 0 ? _plan$quantity : 1), plan === null || plan === void 0 ? void 0 : plan.currency, default_locale);
15108
+ const priceFormatted = getFormattedPriceByLocal((plan === null || plan === void 0 ? void 0 : plan.amount) * ((_plan$quantity = plan === null || plan === void 0 ? void 0 : plan.quantity) !== null && _plan$quantity !== void 0 ? _plan$quantity : 1), plan === null || plan === void 0 ? void 0 : plan.currency, getPageOrDefaultLanguage());
15088
15109
  return /*#__PURE__*/React__default['default'].createElement("p", {
15089
15110
  className: "plc-text-gray-600"
15090
15111
  }, /*#__PURE__*/React__default['default'].createElement("span", {
@@ -18261,7 +18282,6 @@ const OrderConfirmModal = props => {
18261
18282
  const userOrders = window.Pelcro.user.read().orders;
18262
18283
  const latestOrder = userOrders === null || userOrders === void 0 ? void 0 : userOrders[userOrders.length - 1];
18263
18284
  const latestOrderDiscount = latestOrder === null || latestOrder === void 0 ? void 0 : (_latestOrder$coupon = latestOrder.coupon) === null || _latestOrder$coupon === void 0 ? void 0 : _latestOrder$coupon.percent_off;
18264
- const locale = window.Pelcro.site.read().default_locale;
18265
18285
  const {
18266
18286
  t
18267
18287
  } = useTranslation("shop");
@@ -18320,7 +18340,7 @@ const OrderConfirmModal = props => {
18320
18340
  className: "plc-mr-1 pelcro-summary-total-text"
18321
18341
  }, t("labels.total")), /*#__PURE__*/React__default['default'].createElement("p", {
18322
18342
  className: "pelcro-summary-total"
18323
- }, latestOrderDiscount && `(-${latestOrderDiscount}%) `, getFormattedPriceByLocal(latestOrder === null || latestOrder === void 0 ? void 0 : latestOrder.amount, latestOrder === null || latestOrder === void 0 ? void 0 : latestOrder.currency, locale)))), /*#__PURE__*/React__default['default'].createElement("div", {
18343
+ }, latestOrderDiscount && `(-${latestOrderDiscount}%) `, getFormattedPriceByLocal(latestOrder === null || latestOrder === void 0 ? void 0 : latestOrder.amount, latestOrder === null || latestOrder === void 0 ? void 0 : latestOrder.currency, getPageOrDefaultLanguage())))), /*#__PURE__*/React__default['default'].createElement("div", {
18324
18344
  className: "plc-flex plc-justify-center plc-mt-6"
18325
18345
  }, /*#__PURE__*/React__default['default'].createElement(Button, {
18326
18346
  id: "pelcro-submit",
@@ -20689,7 +20709,6 @@ const OrderItems = ({
20689
20709
  const {
20690
20710
  t
20691
20711
  } = useTranslation("dashboard");
20692
- const site = window.Pelcro.site.read();
20693
20712
  return !(orders !== null && orders !== void 0 && orders.length) ? /*#__PURE__*/React__default['default'].createElement("tbody", null, /*#__PURE__*/React__default['default'].createElement("tr", null, /*#__PURE__*/React__default['default'].createElement("td", {
20694
20713
  colSpan: "3",
20695
20714
  className: "plc-text-center plc-text-gray-500"
@@ -20705,7 +20724,7 @@ const OrderItems = ({
20705
20724
  className: "plc-py-4 plc-pl-2"
20706
20725
  }, /*#__PURE__*/React__default['default'].createElement("span", {
20707
20726
  className: "plc-text-xl plc-font-semibold "
20708
- }, getFormattedPriceByLocal(order.amount, order.currency, site.default_locale)), /*#__PURE__*/React__default['default'].createElement("br", null), /*#__PURE__*/React__default['default'].createElement("span", {
20727
+ }, getFormattedPriceByLocal(order.amount, order.currency, getPageOrDefaultLanguage())), /*#__PURE__*/React__default['default'].createElement("br", null), /*#__PURE__*/React__default['default'].createElement("span", {
20709
20728
  className: "plc-text-xs plc-text-gray-400 plc-uppercase"
20710
20729
  }, t("labels.orders.itemsAmount", {
20711
20730
  count: getItemsAmount(order.id)
@@ -20734,7 +20753,7 @@ const OrderItems = ({
20734
20753
  className: ""
20735
20754
  }, item.product_sku_name))), /*#__PURE__*/React__default['default'].createElement("td", null, /*#__PURE__*/React__default['default'].createElement("span", {
20736
20755
  className: "plc-font-semibold"
20737
- }, getFormattedPriceByLocal(item.amount, order.currency, site.default_locale))));
20756
+ }, getFormattedPriceByLocal(item.amount, order.currency, getPageOrDefaultLanguage()))));
20738
20757
  }), /*#__PURE__*/React__default['default'].createElement("tr", null, /*#__PURE__*/React__default['default'].createElement("td", {
20739
20758
  colSpan: "3"
20740
20759
  }, /*#__PURE__*/React__default['default'].createElement("hr", {
@@ -21461,7 +21480,7 @@ class Dashboard extends React.Component {
21461
21480
  className: "plc-font-semibold plc-text-gray-500"
21462
21481
  }, sub.plan.nickname), /*#__PURE__*/React__default['default'].createElement("br", null), /*#__PURE__*/React__default['default'].createElement("span", {
21463
21482
  className: "plc-text-xs plc-text-gray-400"
21464
- }, getFormattedPriceByLocal(sub.plan.amount, sub.plan.currency, this.site.default_locale)))), /*#__PURE__*/React__default['default'].createElement("td", null, /*#__PURE__*/React__default['default'].createElement("span", {
21483
+ }, getFormattedPriceByLocal(sub.plan.amount, sub.plan.currency, getPageOrDefaultLanguage())))), /*#__PURE__*/React__default['default'].createElement("td", null, /*#__PURE__*/React__default['default'].createElement("span", {
21465
21484
  className: `plc-inline-flex plc-p-1 plc-text-xs plc-font-semibold ${this.getSubscriptionStatus(sub).bgColor} plc-uppercase ${this.getSubscriptionStatus(sub).textColor} plc-rounded-lg`
21466
21485
  }, this.getSubscriptionStatus(sub).icon, this.getSubscriptionStatus(sub).title), /*#__PURE__*/React__default['default'].createElement("br", null), /*#__PURE__*/React__default['default'].createElement("div", {
21467
21486
  className: "plc-mb-4 plc-text-xs plc-text-gray-500"
@@ -21564,7 +21583,7 @@ class Dashboard extends React.Component {
21564
21583
  className: "plc-font-semibold plc-text-gray-500"
21565
21584
  }, recipient.plan.nickname), /*#__PURE__*/React__default['default'].createElement("br", null), /*#__PURE__*/React__default['default'].createElement("span", {
21566
21585
  className: "plc-text-xs plc-text-gray-400"
21567
- }, getFormattedPriceByLocal(recipient.plan.amount, recipient.plan.currency, this.site.default_locale)))), recipient.status && /*#__PURE__*/React__default['default'].createElement("td", null, /*#__PURE__*/React__default['default'].createElement("span", {
21586
+ }, getFormattedPriceByLocal(recipient.plan.amount, recipient.plan.currency, getPageOrDefaultLanguage())))), recipient.status && /*#__PURE__*/React__default['default'].createElement("td", null, /*#__PURE__*/React__default['default'].createElement("span", {
21568
21587
  className: `plc-inline-flex plc-p-1 plc-text-xs plc-font-semibold ${this.getSubscriptionStatus(recipient).bgColor} plc-uppercase ${this.getSubscriptionStatus(recipient).textColor} plc-rounded-lg`
21569
21588
  }, this.getSubscriptionStatus(recipient).icon, this.getSubscriptionStatus(recipient).title), /*#__PURE__*/React__default['default'].createElement("br", null), /*#__PURE__*/React__default['default'].createElement("div", {
21570
21589
  className: "plc-mb-4 plc-text-xs plc-text-gray-500"
package/dist/index.esm.js CHANGED
@@ -6297,13 +6297,34 @@ const getAddressById = id => {
6297
6297
  };
6298
6298
  /**
6299
6299
  * Transforms locale names stored in our backend like
6300
- * "en_US" into the standerd accepted in core i18n methods: "en-US"
6300
+ * "en_US" into the standard accepted in core i18n methods: "en-US"
6301
6301
  * @param {string} localeName
6302
6302
  * @return {string | undefined}
6303
6303
  * @example getCanonicalLocaleFormat("en_US") => "en-US"
6304
6304
  */
6305
6305
 
6306
6306
  const getCanonicalLocaleFormat = localeName => localeName === null || localeName === void 0 ? void 0 : localeName.replace("_", "-");
6307
+ /**
6308
+ * @param {string} localeName
6309
+ * @return {string | undefined}
6310
+ * @example getLanguageWithoutRegion("en-US") => "en"
6311
+ */
6312
+
6313
+ const getLanguageWithoutRegion = localeName => {
6314
+ var _getCanonicalLocaleFo;
6315
+
6316
+ return (_getCanonicalLocaleFo = getCanonicalLocaleFormat(localeName)) === null || _getCanonicalLocaleFo === void 0 ? void 0 : _getCanonicalLocaleFo.split("-")[0];
6317
+ };
6318
+ /**
6319
+ * Gets the current page language or fallbacks to site default
6320
+ * @return {string | undefined}
6321
+ */
6322
+
6323
+ const getPageOrDefaultLanguage = () => {
6324
+ var _window$Pelcro$helper, _window$Pelcro, _window$Pelcro$site, _window$Pelcro$site$r, _window$Pelcro$site$r2;
6325
+
6326
+ return (_window$Pelcro$helper = window.Pelcro.helpers.getHtmlLanguageAttribute()) !== null && _window$Pelcro$helper !== void 0 ? _window$Pelcro$helper : getLanguageWithoutRegion((_window$Pelcro = window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$site = _window$Pelcro.site) === null || _window$Pelcro$site === void 0 ? void 0 : (_window$Pelcro$site$r = _window$Pelcro$site.read) === null || _window$Pelcro$site$r === void 0 ? void 0 : (_window$Pelcro$site$r2 = _window$Pelcro$site$r.call(_window$Pelcro$site)) === null || _window$Pelcro$site$r2 === void 0 ? void 0 : _window$Pelcro$site$r2.default_locale);
6327
+ };
6307
6328
  /**
6308
6329
  * Returns a formatted price string depending on locale
6309
6330
  * @param {number} amount
@@ -6313,7 +6334,7 @@ const getCanonicalLocaleFormat = localeName => localeName === null || localeName
6313
6334
  * @example getFormattedPriceByLocal(10, 'USD', 'en-US') => "$10.00"
6314
6335
  */
6315
6336
 
6316
- const getFormattedPriceByLocal = (amount, currency = "USD", locale = "en-US") => {
6337
+ const getFormattedPriceByLocal = (amount, currency = "USD", locale = "en") => {
6317
6338
  const formatter = new Intl.NumberFormat(getCanonicalLocaleFormat(locale), {
6318
6339
  style: "currency",
6319
6340
  currency
@@ -6338,8 +6359,7 @@ const calcAndFormatItemsTotal = (items, currency) => {
6338
6359
  totalWithoutDividingBy100 += parseFloat(item.price ? (item.price * item.quantity).toFixed(2) : item.amount.toFixed(2));
6339
6360
  }
6340
6361
 
6341
- const locale = window.Pelcro.site.read().default_locale;
6342
- return getFormattedPriceByLocal(totalWithoutDividingBy100, currency, locale);
6362
+ return getFormattedPriceByLocal(totalWithoutDividingBy100, currency, getPageOrDefaultLanguage());
6343
6363
  };
6344
6364
  /**
6345
6365
  * returns true if the URL contains a supported view trigger URL
@@ -6353,12 +6373,15 @@ const isValidViewFromURL = viewID => {
6353
6373
  }
6354
6374
 
6355
6375
  return false;
6376
+ /**
6377
+ *
6378
+ */
6356
6379
 
6357
6380
  function hasValidNewsletterUpdateUrl() {
6358
- var _window$Pelcro, _window$Pelcro$uiSett;
6381
+ var _window$Pelcro2, _window$Pelcro2$uiSet;
6359
6382
 
6360
6383
  if (viewID !== "newsletter-update") return false;
6361
- const newsletters = (_window$Pelcro = window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$uiSett = _window$Pelcro.uiSettings) === null || _window$Pelcro$uiSett === void 0 ? void 0 : _window$Pelcro$uiSett.newsletters;
6384
+ const newsletters = (_window$Pelcro2 = window.Pelcro) === null || _window$Pelcro2 === void 0 ? void 0 : (_window$Pelcro2$uiSet = _window$Pelcro2.uiSettings) === null || _window$Pelcro2$uiSet === void 0 ? void 0 : _window$Pelcro2$uiSet.newsletters;
6362
6385
  const siteHasNewslettersDefined = Array.isArray(newsletters) && newsletters.length > 0;
6363
6386
 
6364
6387
  if (!siteHasNewslettersDefined) {
@@ -6532,9 +6555,8 @@ const getPaymentCardIcon$1 = name => {
6532
6555
  }));
6533
6556
  };
6534
6557
 
6535
- var _window$Pelcro, _window$Pelcro$site, _window$Pelcro$site$r, _window$Pelcro$site$r2;
6536
6558
  const resources = {
6537
- "en-US": {
6559
+ en: {
6538
6560
  common: common_en,
6539
6561
  paymentMethod: paymentMethod_en,
6540
6562
  newsletter: newsletter_en,
@@ -6556,7 +6578,7 @@ const resources = {
6556
6578
  select: select_en,
6557
6579
  notification: notification_en
6558
6580
  },
6559
- "fr-CA": {
6581
+ fr: {
6560
6582
  common: common_fr,
6561
6583
  paymentMethod: paymentMethod_fr,
6562
6584
  newsletter: newsletter_fr,
@@ -6578,13 +6600,14 @@ const resources = {
6578
6600
  select: select_fr,
6579
6601
  notification: notification_fr
6580
6602
  }
6581
- };
6582
- let locale = (_window$Pelcro = window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$site = _window$Pelcro.site) === null || _window$Pelcro$site === void 0 ? void 0 : (_window$Pelcro$site$r = _window$Pelcro$site.read) === null || _window$Pelcro$site$r === void 0 ? void 0 : (_window$Pelcro$site$r2 = _window$Pelcro$site$r.call(_window$Pelcro$site)) === null || _window$Pelcro$site$r2 === void 0 ? void 0 : _window$Pelcro$site$r2.default_locale;
6583
- if (!locale) locale = "en-US";
6603
+ }; // set UI language to the page language or default to the language in site settings
6604
+
6605
+ const locale = getPageOrDefaultLanguage();
6584
6606
  i18next.use(initReactI18next) // passes i18n down to react-i18next,
6585
6607
  .init({
6586
6608
  resources,
6587
- lng: getCanonicalLocaleFormat(locale),
6609
+ lng: locale,
6610
+ fallbackLng: "en",
6588
6611
  // debug: true,
6589
6612
  interpolation: {
6590
6613
  escapeValue: false // react already safes from xss
@@ -6595,6 +6618,16 @@ i18next.use(initReactI18next) // passes i18n down to react-i18next,
6595
6618
 
6596
6619
  }
6597
6620
  });
6621
+ const pageLanguageObserver = new MutationObserver(mutationsList => {
6622
+ mutationsList.forEach(mutationRecord => {
6623
+ if (mutationRecord.attributeName === "lang") {
6624
+ i18next.changeLanguage(window.Pelcro.helpers.getHtmlLanguageAttribute());
6625
+ }
6626
+ });
6627
+ });
6628
+ pageLanguageObserver.observe(document.documentElement, {
6629
+ attributes: true
6630
+ });
6598
6631
 
6599
6632
  function _classPrivateFieldGet(receiver, privateMap) {
6600
6633
  var descriptor = privateMap.get(receiver);
@@ -9890,7 +9923,7 @@ const FacebookLoginButton = ({
9890
9923
  labelClassName = "",
9891
9924
  iconClassName = ""
9892
9925
  }) => {
9893
- var _window$Pelcro$site$r, _window$Pelcro$site$r2;
9926
+ var _window$Pelcro$site$r;
9894
9927
 
9895
9928
  const facebookLoginEnabled = (_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.facebook_app_id;
9896
9929
  const {
@@ -9929,7 +9962,7 @@ const FacebookLoginButton = ({
9929
9962
 
9930
9963
  return facebookLoginEnabled ? /*#__PURE__*/React__default.createElement(FacebookLogin, {
9931
9964
  appId: window.Pelcro.site.read().facebook_app_id,
9932
- language: (_window$Pelcro$site$r2 = window.Pelcro.site.read().default_locale) !== null && _window$Pelcro$site$r2 !== void 0 ? _window$Pelcro$site$r2 : "en_US",
9965
+ language: getPageOrDefaultLanguage(),
9933
9966
  fields: "first_name,last_name,email,picture",
9934
9967
  callback: onSuccess,
9935
9968
  onFailure: onFailure,
@@ -13463,7 +13496,7 @@ const PaymentMethodContainer = props => {
13463
13496
  return /*#__PURE__*/React__default.createElement(es_13, {
13464
13497
  apiKey: window.Pelcro.environment.stripe,
13465
13498
  stripeAccount: window.Pelcro.site.read().account_id,
13466
- locale: getCanonicalLocaleFormat(window.Pelcro.site.read().default_locale)
13499
+ locale: getPageOrDefaultLanguage()
13467
13500
  }, /*#__PURE__*/React__default.createElement(es_11, null, /*#__PURE__*/React__default.createElement(UnwrappedForm, Object.assign({
13468
13501
  store: store$d
13469
13502
  }, props))));
@@ -13575,9 +13608,6 @@ const DiscountedPrice = props => {
13575
13608
  percentOff
13576
13609
  }
13577
13610
  } = useContext(store$d);
13578
- const {
13579
- default_locale
13580
- } = Pelcro.site.read();
13581
13611
  const {
13582
13612
  order,
13583
13613
  plan
@@ -13585,7 +13615,7 @@ const DiscountedPrice = props => {
13585
13615
  const ecommOrderCurrency = (_order$currency = order === null || order === void 0 ? void 0 : order.currency) !== null && _order$currency !== void 0 ? _order$currency : order === null || order === void 0 ? void 0 : (_order$ = order[0]) === null || _order$ === void 0 ? void 0 : _order$.currency;
13586
13616
  const planQuantity = (_plan$quantity = plan === null || plan === void 0 ? void 0 : plan.quantity) !== null && _plan$quantity !== void 0 ? _plan$quantity : 1;
13587
13617
  const discountedPriceWithoutTax = updatedPrice - taxAmount;
13588
- const priceFormatted = getFormattedPriceByLocal(order ? updatedPrice : discountedPriceWithoutTax * planQuantity, ecommOrderCurrency !== null && ecommOrderCurrency !== void 0 ? ecommOrderCurrency : plan === null || plan === void 0 ? void 0 : plan.currency, default_locale);
13618
+ const priceFormatted = getFormattedPriceByLocal(order ? updatedPrice : discountedPriceWithoutTax * planQuantity, ecommOrderCurrency !== null && ecommOrderCurrency !== void 0 ? ecommOrderCurrency : plan === null || plan === void 0 ? void 0 : plan.currency, getPageOrDefaultLanguage());
13589
13619
 
13590
13620
  if (percentOff) {
13591
13621
  return /*#__PURE__*/React__default.createElement("div", Object.assign({
@@ -13618,12 +13648,9 @@ const SubmitPaymentMethod = ({
13618
13648
  updatedPrice
13619
13649
  }
13620
13650
  } = useContext(store$d);
13621
- const {
13622
- default_locale
13623
- } = Pelcro.site.read();
13624
13651
  const planQuantity = (_plan$quantity = plan === null || plan === void 0 ? void 0 : plan.quantity) !== null && _plan$quantity !== void 0 ? _plan$quantity : 1;
13625
13652
  const price = updatedPrice !== null && updatedPrice !== void 0 ? updatedPrice : plan === null || plan === void 0 ? void 0 : plan.amount;
13626
- const priceFormatted = getFormattedPriceByLocal(price * planQuantity, plan === null || plan === void 0 ? void 0 : plan.currency, default_locale);
13653
+ const priceFormatted = getFormattedPriceByLocal(price * planQuantity, plan === null || plan === void 0 ? void 0 : plan.currency, getPageOrDefaultLanguage());
13627
13654
  return /*#__PURE__*/React__default.createElement(Button, Object.assign({
13628
13655
  role: "submit",
13629
13656
  className: "plc-w-full plc-py-3",
@@ -13868,7 +13895,7 @@ class PaypalClient {
13868
13895
  this.paypalButton = window.paypal.Buttons({
13869
13896
  fundingSource: window.paypal.FUNDING.PAYPAL,
13870
13897
  // button locale
13871
- locale: (_this$config$locale = this.config.locale) !== null && _this$config$locale !== void 0 ? _this$config$locale : this.siteInfo.default_locale,
13898
+ locale: (_this$config$locale = this.config.locale) !== null && _this$config$locale !== void 0 ? _this$config$locale : getPageOrDefaultLanguage(),
13872
13899
  // button style
13873
13900
  style: (_this$config$style = this.config.style) !== null && _this$config$style !== void 0 ? _this$config$style : defaultButtonStyle,
13874
13901
  // create payment handler
@@ -13965,7 +13992,7 @@ class PaypalClient {
13965
13992
  } : undefined,
13966
13993
  shippingAddressEditable: this.config.shippingAddressEditable,
13967
13994
  displayName: (_this$config$displayN = this.config.displayName) !== null && _this$config$displayN !== void 0 ? _this$config$displayN : this.siteInfo.name,
13968
- locale: (_this$config$locale2 = this.config.locale) !== null && _this$config$locale2 !== void 0 ? _this$config$locale2 : this.siteInfo.default_locale
13995
+ locale: (_this$config$locale2 = this.config.locale) !== null && _this$config$locale2 !== void 0 ? _this$config$locale2 : getPageOrDefaultLanguage()
13969
13996
  };
13970
13997
  }
13971
13998
  });
@@ -13974,7 +14001,7 @@ class PaypalClient {
13974
14001
  writable: true,
13975
14002
  value: () => {
13976
14003
  const totalAmount = (this.product.quantity || 1) * this.amount;
13977
- const priceFormatted = getFormattedPriceByLocal(totalAmount, this.product.currency, this.siteInfo.default_locale);
14004
+ const priceFormatted = getFormattedPriceByLocal(totalAmount, this.product.currency, getPageOrDefaultLanguage());
13978
14005
  const autoRenewed = this.product.auto_renew;
13979
14006
  const {
13980
14007
  interval,
@@ -14171,14 +14198,11 @@ const TaxAmount = () => {
14171
14198
  taxAmount
14172
14199
  }
14173
14200
  } = useContext(store$d);
14174
- const {
14175
- default_locale
14176
- } = Pelcro.site.read();
14177
14201
  const {
14178
14202
  plan
14179
14203
  } = usePelcro();
14180
14204
  const planQuantity = (_plan$quantity = plan === null || plan === void 0 ? void 0 : plan.quantity) !== null && _plan$quantity !== void 0 ? _plan$quantity : 1;
14181
- const priceFormatted = getFormattedPriceByLocal(taxAmount * planQuantity, plan === null || plan === void 0 ? void 0 : plan.currency, default_locale);
14205
+ const priceFormatted = getFormattedPriceByLocal(taxAmount * planQuantity, plan === null || plan === void 0 ? void 0 : plan.currency, getPageOrDefaultLanguage());
14182
14206
 
14183
14207
  if (taxAmount) {
14184
14208
  return /*#__PURE__*/React__default.createElement("div", {
@@ -15051,10 +15075,7 @@ const SubscriptionCreateView = ({
15051
15075
  interval,
15052
15076
  count: interval_count
15053
15077
  });
15054
- const {
15055
- default_locale
15056
- } = Pelcro.site.read();
15057
- const priceFormatted = getFormattedPriceByLocal((plan === null || plan === void 0 ? void 0 : plan.amount) * ((_plan$quantity = plan === null || plan === void 0 ? void 0 : plan.quantity) !== null && _plan$quantity !== void 0 ? _plan$quantity : 1), plan === null || plan === void 0 ? void 0 : plan.currency, default_locale);
15078
+ const priceFormatted = getFormattedPriceByLocal((plan === null || plan === void 0 ? void 0 : plan.amount) * ((_plan$quantity = plan === null || plan === void 0 ? void 0 : plan.quantity) !== null && _plan$quantity !== void 0 ? _plan$quantity : 1), plan === null || plan === void 0 ? void 0 : plan.currency, getPageOrDefaultLanguage());
15058
15079
  return /*#__PURE__*/React__default.createElement("p", {
15059
15080
  className: "plc-text-gray-600"
15060
15081
  }, /*#__PURE__*/React__default.createElement("span", {
@@ -18231,7 +18252,6 @@ const OrderConfirmModal = props => {
18231
18252
  const userOrders = window.Pelcro.user.read().orders;
18232
18253
  const latestOrder = userOrders === null || userOrders === void 0 ? void 0 : userOrders[userOrders.length - 1];
18233
18254
  const latestOrderDiscount = latestOrder === null || latestOrder === void 0 ? void 0 : (_latestOrder$coupon = latestOrder.coupon) === null || _latestOrder$coupon === void 0 ? void 0 : _latestOrder$coupon.percent_off;
18234
- const locale = window.Pelcro.site.read().default_locale;
18235
18255
  const {
18236
18256
  t
18237
18257
  } = useTranslation("shop");
@@ -18290,7 +18310,7 @@ const OrderConfirmModal = props => {
18290
18310
  className: "plc-mr-1 pelcro-summary-total-text"
18291
18311
  }, t("labels.total")), /*#__PURE__*/React__default.createElement("p", {
18292
18312
  className: "pelcro-summary-total"
18293
- }, latestOrderDiscount && `(-${latestOrderDiscount}%) `, getFormattedPriceByLocal(latestOrder === null || latestOrder === void 0 ? void 0 : latestOrder.amount, latestOrder === null || latestOrder === void 0 ? void 0 : latestOrder.currency, locale)))), /*#__PURE__*/React__default.createElement("div", {
18313
+ }, latestOrderDiscount && `(-${latestOrderDiscount}%) `, getFormattedPriceByLocal(latestOrder === null || latestOrder === void 0 ? void 0 : latestOrder.amount, latestOrder === null || latestOrder === void 0 ? void 0 : latestOrder.currency, getPageOrDefaultLanguage())))), /*#__PURE__*/React__default.createElement("div", {
18294
18314
  className: "plc-flex plc-justify-center plc-mt-6"
18295
18315
  }, /*#__PURE__*/React__default.createElement(Button, {
18296
18316
  id: "pelcro-submit",
@@ -20659,7 +20679,6 @@ const OrderItems = ({
20659
20679
  const {
20660
20680
  t
20661
20681
  } = useTranslation("dashboard");
20662
- const site = window.Pelcro.site.read();
20663
20682
  return !(orders !== null && orders !== void 0 && orders.length) ? /*#__PURE__*/React__default.createElement("tbody", null, /*#__PURE__*/React__default.createElement("tr", null, /*#__PURE__*/React__default.createElement("td", {
20664
20683
  colSpan: "3",
20665
20684
  className: "plc-text-center plc-text-gray-500"
@@ -20675,7 +20694,7 @@ const OrderItems = ({
20675
20694
  className: "plc-py-4 plc-pl-2"
20676
20695
  }, /*#__PURE__*/React__default.createElement("span", {
20677
20696
  className: "plc-text-xl plc-font-semibold "
20678
- }, getFormattedPriceByLocal(order.amount, order.currency, site.default_locale)), /*#__PURE__*/React__default.createElement("br", null), /*#__PURE__*/React__default.createElement("span", {
20697
+ }, getFormattedPriceByLocal(order.amount, order.currency, getPageOrDefaultLanguage())), /*#__PURE__*/React__default.createElement("br", null), /*#__PURE__*/React__default.createElement("span", {
20679
20698
  className: "plc-text-xs plc-text-gray-400 plc-uppercase"
20680
20699
  }, t("labels.orders.itemsAmount", {
20681
20700
  count: getItemsAmount(order.id)
@@ -20704,7 +20723,7 @@ const OrderItems = ({
20704
20723
  className: ""
20705
20724
  }, item.product_sku_name))), /*#__PURE__*/React__default.createElement("td", null, /*#__PURE__*/React__default.createElement("span", {
20706
20725
  className: "plc-font-semibold"
20707
- }, getFormattedPriceByLocal(item.amount, order.currency, site.default_locale))));
20726
+ }, getFormattedPriceByLocal(item.amount, order.currency, getPageOrDefaultLanguage()))));
20708
20727
  }), /*#__PURE__*/React__default.createElement("tr", null, /*#__PURE__*/React__default.createElement("td", {
20709
20728
  colSpan: "3"
20710
20729
  }, /*#__PURE__*/React__default.createElement("hr", {
@@ -21431,7 +21450,7 @@ class Dashboard extends Component {
21431
21450
  className: "plc-font-semibold plc-text-gray-500"
21432
21451
  }, sub.plan.nickname), /*#__PURE__*/React__default.createElement("br", null), /*#__PURE__*/React__default.createElement("span", {
21433
21452
  className: "plc-text-xs plc-text-gray-400"
21434
- }, getFormattedPriceByLocal(sub.plan.amount, sub.plan.currency, this.site.default_locale)))), /*#__PURE__*/React__default.createElement("td", null, /*#__PURE__*/React__default.createElement("span", {
21453
+ }, getFormattedPriceByLocal(sub.plan.amount, sub.plan.currency, getPageOrDefaultLanguage())))), /*#__PURE__*/React__default.createElement("td", null, /*#__PURE__*/React__default.createElement("span", {
21435
21454
  className: `plc-inline-flex plc-p-1 plc-text-xs plc-font-semibold ${this.getSubscriptionStatus(sub).bgColor} plc-uppercase ${this.getSubscriptionStatus(sub).textColor} plc-rounded-lg`
21436
21455
  }, this.getSubscriptionStatus(sub).icon, this.getSubscriptionStatus(sub).title), /*#__PURE__*/React__default.createElement("br", null), /*#__PURE__*/React__default.createElement("div", {
21437
21456
  className: "plc-mb-4 plc-text-xs plc-text-gray-500"
@@ -21534,7 +21553,7 @@ class Dashboard extends Component {
21534
21553
  className: "plc-font-semibold plc-text-gray-500"
21535
21554
  }, recipient.plan.nickname), /*#__PURE__*/React__default.createElement("br", null), /*#__PURE__*/React__default.createElement("span", {
21536
21555
  className: "plc-text-xs plc-text-gray-400"
21537
- }, getFormattedPriceByLocal(recipient.plan.amount, recipient.plan.currency, this.site.default_locale)))), recipient.status && /*#__PURE__*/React__default.createElement("td", null, /*#__PURE__*/React__default.createElement("span", {
21556
+ }, getFormattedPriceByLocal(recipient.plan.amount, recipient.plan.currency, getPageOrDefaultLanguage())))), recipient.status && /*#__PURE__*/React__default.createElement("td", null, /*#__PURE__*/React__default.createElement("span", {
21538
21557
  className: `plc-inline-flex plc-p-1 plc-text-xs plc-font-semibold ${this.getSubscriptionStatus(recipient).bgColor} plc-uppercase ${this.getSubscriptionStatus(recipient).textColor} plc-rounded-lg`
21539
21558
  }, this.getSubscriptionStatus(recipient).icon, this.getSubscriptionStatus(recipient).title), /*#__PURE__*/React__default.createElement("br", null), /*#__PURE__*/React__default.createElement("div", {
21540
21559
  className: "plc-mb-4 plc-text-xs plc-text-gray-500"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pelcro/react-pelcro-js",
3
3
  "description": "Pelcro's React UI Elements",
4
- "version": "2.6.0-beta.3",
4
+ "version": "2.6.0-beta.4",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "dist/index.cjs.js",