@commercelayer/react-components 4.15.7 → 4.15.8-beta.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.
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CheckoutLink=CheckoutLink;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),getApplicationLink_1=require("../../utils/getApplicationLink"),getDomain_1=require("../../utils/getDomain"),organization_1=require("../../utils/organization");function CheckoutLink(props){var _a;const{label,hostedCheckout=!0,children,onClick}=props,p=tslib_1.__rest(props,["label","hostedCheckout","children","onClick"]),{order}=(0,react_1.useContext)(OrderContext_1.default),{accessToken,endpoint}=(0,react_1.useContext)(CommerceLayerContext_1.default);if(accessToken==null||endpoint==null)throw new Error("Cannot use `CheckoutLink` outside of `CommerceLayer`");const{domain,slug}=(0,getDomain_1.getDomain)(endpoint),href=hostedCheckout&&order?.id?(0,getApplicationLink_1.getApplicationLink)({slug,orderId:order?.id,accessToken,applicationType:"checkout",domain}):(_a=order?.checkout_url)!==null&&_a!==void 0?_a:"",parentProps=Object.assign({checkoutUrl:order?.checkout_url,hostedCheckout,label,href},p);function handleClick(e){e.preventDefault(),e.stopPropagation();const currentHref=e.currentTarget.href;accessToken&&endpoint&&order?.id?(0,organization_1.getOrganizationConfig)({accessToken,endpoint,params:{accessToken,orderId:order?.id}}).then(config=>{var _a2;!((_a2=config?.links)===null||_a2===void 0)&&_a2.checkout?location.href=config.links.checkout:location.href=currentHref}):location.href=currentHref}return children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children})):(0,jsx_runtime_1.jsx)("a",Object.assign({href,onClick:handleClick},p,{children:label}))}exports.default=CheckoutLink;
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CheckoutLink=CheckoutLink;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),getApplicationLink_1=require("../../utils/getApplicationLink"),getDomain_1=require("../../utils/getDomain"),organization_1=require("../../utils/organization");function CheckoutLink(props){var _a;const{label,hostedCheckout=!0,children,onClick}=props,p=tslib_1.__rest(props,["label","hostedCheckout","children","onClick"]),{order}=(0,react_1.useContext)(OrderContext_1.default),{accessToken,endpoint}=(0,react_1.useContext)(CommerceLayerContext_1.default);if(accessToken==null||endpoint==null)throw new Error("Cannot use `CheckoutLink` outside of `CommerceLayer`");const{domain,slug}=(0,getDomain_1.getDomain)(endpoint),href=hostedCheckout&&order?.id?(0,getApplicationLink_1.getApplicationLink)({slug,orderId:order?.id,accessToken,applicationType:"checkout",domain}):(_a=order?.checkout_url)!==null&&_a!==void 0?_a:"",parentProps=Object.assign({checkoutUrl:order?.checkout_url,hostedCheckout,label,href},p);function handleClick(e){e.preventDefault(),e.stopPropagation();const currentHref=e.currentTarget.href;accessToken&&endpoint&&order?.id?(0,organization_1.getOrganizationConfig)({accessToken,endpoint,params:{accessToken,orderId:order?.id}}).then(config=>{var _a2;!((_a2=config?.links)===null||_a2===void 0)&&_a2.checkout?window.open(config.links.checkout,"_top"):window.open(currentHref,"_top")}):window.open(currentHref,"_top")}return children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children})):(0,jsx_runtime_1.jsx)("a",Object.assign({href,onClick:handleClick},p,{children:label}))}exports.default=CheckoutLink;
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=tslib_1.__importDefault(require("react")),Parent_1=tslib_1.__importDefault(require("./Parent")),lodash_1=require("lodash"),BaseSelect=(props,ref)=>{const{options=[],children,placeholder={label:"Select an option",value:""},value=""}=props,p=tslib_1.__rest(props,["options","children","placeholder","value"]);(0,lodash_1.findIndex)(options,placeholder)===-1?options.unshift(placeholder):options[0]=placeholder;const Options=options.map((o,k)=>{const{label}=o,option=tslib_1.__rest(o,["label"]);return(0,jsx_runtime_1.jsx)("option",Object.assign({},option,{children:label}),k)}),parentProps=Object.assign({options,ref},p);return children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children})):(0,jsx_runtime_1.jsx)("select",Object.assign({ref,defaultValue:value},p,{children:Options}))};exports.default=react_1.default.forwardRef(BaseSelect);
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=tslib_1.__importDefault(require("react")),Parent_1=tslib_1.__importDefault(require("./Parent")),BaseSelect=(props,ref)=>{const{options=[],children,placeholder={label:"Select an option",value:""},value=""}=props,p=tslib_1.__rest(props,["options","children","placeholder","value"]);placeholder!=null&&(options.some(option=>option.value===placeholder.value)||options.unshift(placeholder));const Options=options.map((o,k)=>{const{label}=o,option=tslib_1.__rest(o,["label"]);return(0,jsx_runtime_1.jsx)("option",Object.assign({},option,{children:label}),k)}),parentProps=Object.assign({options,ref},p);return children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children})):(0,jsx_runtime_1.jsx)("select",Object.assign({ref,defaultValue:value},p,{children:Options}))};exports.default=react_1.default.forwardRef(BaseSelect);
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import OrderContext from"../../context/OrderContext";import Parent from"../utils/Parent";import CommerceLayerContext from"../../context/CommerceLayerContext";import{getApplicationLink}from"../../utils/getApplicationLink";import{getDomain}from"../../utils/getDomain";import{getOrganizationConfig}from"../../utils/organization";export function CheckoutLink(props){const{label,hostedCheckout=!0,children,onClick,...p}=props,{order}=useContext(OrderContext),{accessToken,endpoint}=useContext(CommerceLayerContext);if(accessToken==null||endpoint==null)throw new Error("Cannot use `CheckoutLink` outside of `CommerceLayer`");const{domain,slug}=getDomain(endpoint),href=hostedCheckout&&order?.id?getApplicationLink({slug,orderId:order?.id,accessToken,applicationType:"checkout",domain}):order?.checkout_url??"",parentProps={checkoutUrl:order?.checkout_url,hostedCheckout,label,href,...p};function handleClick(e){e.preventDefault(),e.stopPropagation();const currentHref=e.currentTarget.href;accessToken&&endpoint&&order?.id?getOrganizationConfig({accessToken,endpoint,params:{accessToken,orderId:order?.id}}).then(config=>{config?.links?.checkout?location.href=config.links.checkout:location.href=currentHref}):location.href=currentHref}return children?_jsx(Parent,{...parentProps,children}):_jsx("a",{href,onClick:handleClick,...p,children:label})}export default CheckoutLink;
2
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import OrderContext from"../../context/OrderContext";import Parent from"../utils/Parent";import CommerceLayerContext from"../../context/CommerceLayerContext";import{getApplicationLink}from"../../utils/getApplicationLink";import{getDomain}from"../../utils/getDomain";import{getOrganizationConfig}from"../../utils/organization";export function CheckoutLink(props){const{label,hostedCheckout=!0,children,onClick,...p}=props,{order}=useContext(OrderContext),{accessToken,endpoint}=useContext(CommerceLayerContext);if(accessToken==null||endpoint==null)throw new Error("Cannot use `CheckoutLink` outside of `CommerceLayer`");const{domain,slug}=getDomain(endpoint),href=hostedCheckout&&order?.id?getApplicationLink({slug,orderId:order?.id,accessToken,applicationType:"checkout",domain}):order?.checkout_url??"",parentProps={checkoutUrl:order?.checkout_url,hostedCheckout,label,href,...p};function handleClick(e){e.preventDefault(),e.stopPropagation();const currentHref=e.currentTarget.href;accessToken&&endpoint&&order?.id?getOrganizationConfig({accessToken,endpoint,params:{accessToken,orderId:order?.id}}).then(config=>{config?.links?.checkout?window.open(config.links.checkout,"_top"):window.open(currentHref,"_top")}):window.open(currentHref,"_top")}return children?_jsx(Parent,{...parentProps,children}):_jsx("a",{href,onClick:handleClick,...p,children:label})}export default CheckoutLink;
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import{jsx as _jsx}from"react/jsx-runtime";import React from"react";import Parent from"./Parent";import{findIndex}from"lodash";const BaseSelect=(props,ref)=>{const{options=[],children,placeholder={label:"Select an option",value:""},value="",...p}=props;findIndex(options,placeholder)===-1?options.unshift(placeholder):options[0]=placeholder;const Options=options.map((o,k)=>{const{label,...option}=o;return _jsx("option",{...option,children:label},k)}),parentProps={options,ref,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx("select",{ref,defaultValue:value,...p,children:Options})};export default React.forwardRef(BaseSelect);
2
+ import{jsx as _jsx}from"react/jsx-runtime";import React from"react";import Parent from"./Parent";const BaseSelect=(props,ref)=>{const{options=[],children,placeholder={label:"Select an option",value:""},value="",...p}=props;placeholder!=null&&(options.some(option=>option.value===placeholder.value)||options.unshift(placeholder));const Options=options.map((o,k)=>{const{label,...option}=o;return _jsx("option",{...option,children:label},k)}),parentProps={options,ref,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx("select",{ref,defaultValue:value,...p,children:Options})};export default React.forwardRef(BaseSelect);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercelayer/react-components",
3
- "version": "4.15.7",
3
+ "version": "4.15.8-beta.1",
4
4
  "description": "The Official Commerce Layer React Components",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/esm/index.js",