@cmssy/react 0.2.0 → 0.2.1

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/client.cjs CHANGED
@@ -1058,6 +1058,9 @@ function fractionDigits(currency) {
1058
1058
  function fromMinorUnits(minor, currency) {
1059
1059
  return minor / 10 ** fractionDigits(currency);
1060
1060
  }
1061
+ function toMinorUnits(amount, currency) {
1062
+ return Math.round(amount * 10 ** fractionDigits(currency));
1063
+ }
1061
1064
  function formatPrice(minor, currency) {
1062
1065
  if (!Number.isFinite(minor)) return "";
1063
1066
  const code = currency ?? "USD";
@@ -1137,7 +1140,7 @@ function ProductComponent({ content }) {
1137
1140
  const imageUrl = c.imageField ? data[c.imageField] : null;
1138
1141
  const hasVariants = product.variants.length > 0;
1139
1142
  const currency = data.currency ?? "USD";
1140
- const priceMinor = hasVariants ? variant?.price : Number(data[c.priceField ?? "price"] ?? 0);
1143
+ const priceMinor = hasVariants ? variant?.price : toMinorUnits(Number(data[c.priceField ?? "price"] ?? 0), currency);
1141
1144
  const showPrice = priceMinor != null && Number.isFinite(priceMinor);
1142
1145
  const allAxesSelected = axes.every((axis) => selections[axis.name]);
1143
1146
  const outOfStock = variant != null && variant.inventory != null && variant.inventory <= 0;
@@ -1415,6 +1418,7 @@ exports.formatPrice = formatPrice;
1415
1418
  exports.fractionDigits = fractionDigits;
1416
1419
  exports.fromMinorUnits = fromMinorUnits;
1417
1420
  exports.productBlock = productBlock;
1421
+ exports.toMinorUnits = toMinorUnits;
1418
1422
  exports.useCart = useCart;
1419
1423
  exports.useCmssyUser = useCmssyUser;
1420
1424
  exports.useEditBridge = useEditBridge;
package/dist/client.d.cts CHANGED
@@ -138,6 +138,7 @@ declare const checkoutBlock: BlockDefinition;
138
138
 
139
139
  declare function fractionDigits(currency: string): number;
140
140
  declare function fromMinorUnits(minor: number, currency: string): number;
141
+ declare function toMinorUnits(amount: number, currency: string): number;
141
142
  declare function formatPrice(minor: number, currency: string | null | undefined): string;
142
143
 
143
- export { type CmssyAddToCartOptions, type CmssyAuthActionResult, CmssyAuthProvider, type CmssyAuthProviderProps, type CmssyAuthState, type CmssyAuthUser, CmssyCart, CmssyCommerceProvider, type CmssyCommerceProviderProps, type CmssyCommerceState, CmssyEditableLayout, type CmssyEditableLayoutProps, CmssyEditablePage, type CmssyEditablePageProps, CmssyLazyEditor, type CmssyLazyEditorProps, CmssyLazyLayout, type CmssyLazyLayoutProps, CmssyOrder, CmssyProduct, type EditBridgeConfig, type EditBridgeState, type PatchMap, cartBlock, checkoutBlock, formatPrice, fractionDigits, fromMinorUnits, productBlock, useCart, useCmssyUser, useEditBridge };
144
+ export { type CmssyAddToCartOptions, type CmssyAuthActionResult, CmssyAuthProvider, type CmssyAuthProviderProps, type CmssyAuthState, type CmssyAuthUser, CmssyCart, CmssyCommerceProvider, type CmssyCommerceProviderProps, type CmssyCommerceState, CmssyEditableLayout, type CmssyEditableLayoutProps, CmssyEditablePage, type CmssyEditablePageProps, CmssyLazyEditor, type CmssyLazyEditorProps, CmssyLazyLayout, type CmssyLazyLayoutProps, CmssyOrder, CmssyProduct, type EditBridgeConfig, type EditBridgeState, type PatchMap, cartBlock, checkoutBlock, formatPrice, fractionDigits, fromMinorUnits, productBlock, toMinorUnits, useCart, useCmssyUser, useEditBridge };
package/dist/client.d.ts CHANGED
@@ -138,6 +138,7 @@ declare const checkoutBlock: BlockDefinition;
138
138
 
139
139
  declare function fractionDigits(currency: string): number;
140
140
  declare function fromMinorUnits(minor: number, currency: string): number;
141
+ declare function toMinorUnits(amount: number, currency: string): number;
141
142
  declare function formatPrice(minor: number, currency: string | null | undefined): string;
142
143
 
143
- export { type CmssyAddToCartOptions, type CmssyAuthActionResult, CmssyAuthProvider, type CmssyAuthProviderProps, type CmssyAuthState, type CmssyAuthUser, CmssyCart, CmssyCommerceProvider, type CmssyCommerceProviderProps, type CmssyCommerceState, CmssyEditableLayout, type CmssyEditableLayoutProps, CmssyEditablePage, type CmssyEditablePageProps, CmssyLazyEditor, type CmssyLazyEditorProps, CmssyLazyLayout, type CmssyLazyLayoutProps, CmssyOrder, CmssyProduct, type EditBridgeConfig, type EditBridgeState, type PatchMap, cartBlock, checkoutBlock, formatPrice, fractionDigits, fromMinorUnits, productBlock, useCart, useCmssyUser, useEditBridge };
144
+ export { type CmssyAddToCartOptions, type CmssyAuthActionResult, CmssyAuthProvider, type CmssyAuthProviderProps, type CmssyAuthState, type CmssyAuthUser, CmssyCart, CmssyCommerceProvider, type CmssyCommerceProviderProps, type CmssyCommerceState, CmssyEditableLayout, type CmssyEditableLayoutProps, CmssyEditablePage, type CmssyEditablePageProps, CmssyLazyEditor, type CmssyLazyEditorProps, CmssyLazyLayout, type CmssyLazyLayoutProps, CmssyOrder, CmssyProduct, type EditBridgeConfig, type EditBridgeState, type PatchMap, cartBlock, checkoutBlock, formatPrice, fractionDigits, fromMinorUnits, productBlock, toMinorUnits, useCart, useCmssyUser, useEditBridge };
package/dist/client.js CHANGED
@@ -1056,6 +1056,9 @@ function fractionDigits(currency) {
1056
1056
  function fromMinorUnits(minor, currency) {
1057
1057
  return minor / 10 ** fractionDigits(currency);
1058
1058
  }
1059
+ function toMinorUnits(amount, currency) {
1060
+ return Math.round(amount * 10 ** fractionDigits(currency));
1061
+ }
1059
1062
  function formatPrice(minor, currency) {
1060
1063
  if (!Number.isFinite(minor)) return "";
1061
1064
  const code = currency ?? "USD";
@@ -1135,7 +1138,7 @@ function ProductComponent({ content }) {
1135
1138
  const imageUrl = c.imageField ? data[c.imageField] : null;
1136
1139
  const hasVariants = product.variants.length > 0;
1137
1140
  const currency = data.currency ?? "USD";
1138
- const priceMinor = hasVariants ? variant?.price : Number(data[c.priceField ?? "price"] ?? 0);
1141
+ const priceMinor = hasVariants ? variant?.price : toMinorUnits(Number(data[c.priceField ?? "price"] ?? 0), currency);
1139
1142
  const showPrice = priceMinor != null && Number.isFinite(priceMinor);
1140
1143
  const allAxesSelected = axes.every((axis) => selections[axis.name]);
1141
1144
  const outOfStock = variant != null && variant.inventory != null && variant.inventory <= 0;
@@ -1401,4 +1404,4 @@ var checkoutBlock = defineBlock({
1401
1404
  component: CheckoutComponent
1402
1405
  });
1403
1406
 
1404
- export { CmssyAuthProvider, CmssyCommerceProvider, CmssyEditableLayout, CmssyEditablePage, CmssyLazyEditor, CmssyLazyLayout, cartBlock, checkoutBlock, formatPrice, fractionDigits, fromMinorUnits, productBlock, useCart, useCmssyUser, useEditBridge };
1407
+ export { CmssyAuthProvider, CmssyCommerceProvider, CmssyEditableLayout, CmssyEditablePage, CmssyLazyEditor, CmssyLazyLayout, cartBlock, checkoutBlock, formatPrice, fractionDigits, fromMinorUnits, productBlock, toMinorUnits, useCart, useCmssyUser, useEditBridge };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/react",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "React blocks, renderers, data client and editor bridge for cmssy headless sites",
5
5
  "keywords": [
6
6
  "cmssy",