@bikdotai/bik-component-library 0.0.442 → 0.0.443
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 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react/jsx-runtime"),r=require("../../assets/icons/search.svg.js"),o=require("react"),c=require("../../constants/Theme.js"),s=require("../button/Button.js"),n=require("../input/Input.js"),i=require("../modals/styledModal.js"),l=require("../spinner/Spinner.js"),a=require("../tag/Tag.js"),d=require("./collectionScreen.js"),u=require("./productScreen.js"),h=require("./rearrangeScreen.js"),p=require("./reducers.js"),S=require("./searchScreen.js"),C=require("./selectedScreen.js"),x=require("./style.js"),g=require("./type.js");exports.ScreenName=void 0,(e=exports.ScreenName||(exports.ScreenName={})).Collections="collections",e.RearrangeProducts="rearrange",e.SelectedProducts="view",e.SearchProducts="searchProducts",e.Products="products";exports.ProductPickerModal=e=>{const{storeId:j,selectedItems:m,onClose:y,visible:b,zIndex:v,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react/jsx-runtime"),r=require("../../assets/icons/search.svg.js"),o=require("react"),c=require("../../constants/Theme.js"),s=require("../button/Button.js"),n=require("../input/Input.js"),i=require("../modals/styledModal.js"),l=require("../spinner/Spinner.js"),a=require("../tag/Tag.js"),d=require("./collectionScreen.js"),u=require("./productScreen.js"),h=require("./rearrangeScreen.js"),p=require("./reducers.js"),S=require("./searchScreen.js"),C=require("./selectedScreen.js"),x=require("./style.js"),g=require("./type.js");exports.ScreenName=void 0,(e=exports.ScreenName||(exports.ScreenName={})).Collections="collections",e.RearrangeProducts="rearrange",e.SelectedProducts="view",e.SearchProducts="searchProducts",e.Products="products";exports.ProductPickerModal=e=>{const{storeId:j,selectedItems:m,onClose:y,visible:b,zIndex:v,minlimit:P,limit:f,hideCollectionCheckbox:k,hideProductCheckbox:O,outOfStockAction:R=g.OUT_OF_STOCK_ACTION.BLUR,hideVariantCheckbox:T,selectProductsFromCustomCollection:F,hideSelectionCount:I,title:q,width:E,renderWithoutModal:D,onClickSave:N,pickerType:w,hideProductVariants:M=!1,startupScreen:A=exports.ScreenName.Collections,rearrangeEnabled:B}=e,[V,L]=o.useReducer(p.collectionsReducer,{}),[$,_]=o.useState([exports.ScreenName.Collections,exports.ScreenName.RearrangeProducts].includes(A)?A:exports.ScreenName.Collections),[z,G]=o.useState("grid"),[H,W]=o.useState(""),[K,U]=o.useState(0),[Y,J]=o.useState(!1),[Q,X]=o.useState(0),[Z,ee]=o.useState(""),[te,re]=o.useState(!1),[oe,ce]=o.useState(!1),[se,ne]=o.useState(),[ie,le]=o.useReducer(p.selectedColectionsReducer,Object.keys(m).length>0?m:{}),ae=o.useRef(null);o.useEffect((()=>{J(!0),ce(!0),e.collectionFetcher(K,j).then((e=>{L({type:"fetched",data:(null==e?void 0:e.collections)||{}}),J(!1),U((e=>e+1)),ce(!1)})).catch()}),[]),o.useEffect((()=>{let e=0;Object.keys(ie||[]).forEach((t=>{var r;Object.keys((null===(r=ie[t])||void 0===r?void 0:r.products)||[]).forEach((r=>{var o,c;Object.keys((null===(c=null===(o=ie[t].products)||void 0===o?void 0:o[r])||void 0===c?void 0:c.variants)||[]).forEach((()=>{e+=1}))}))})),X(e)})),o.useEffect((()=>{var t;H&&!(null===(t=null==V?void 0:V[H])||void 0===t?void 0:t.products)&&(J(!0),e.productFetcher(H,j).then((e=>{Object.keys(e).length&&L({type:"productsFetched",data:{collectionId:H,products:e}}),J(!1)})).catch())}),[H]),o.useEffect((()=>{const t=setTimeout((()=>{"rearrange"!==$&&(Z.length?(re(!0),e.searchFetcher(j,Z).then((e=>{ne(Object.assign({},e)),_("searchProducts"),J(!1),re(!1)}))):_("collections"))}),800);return()=>clearTimeout(t)}),[Z]),o.useEffect((()=>{N&&(e.onAdd(ie,Q),de())}),[N]);const de=()=>{le({type:"reset",data:{}})},ue=t.jsxs(x.ContainerStyle,{children:[e.postHeader&&t.jsx("div",Object.assign({style:{padding:"0 24px"}},{children:e.postHeader})),!e.hideGlobalSearch&&t.jsx(t.Fragment,{children:("collections"===$||"searchProducts"===$)&&t.jsx("div",Object.assign({style:{padding:D?"8px 16px":"12px 24px",borderBottom:"1px solid #E0E0E0"}},{children:t.jsx(n.Input,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>te?t.jsx(l.Spinner,{size:"small",color:c.COLORS.content.primary}):t.jsx(r.default,{})},id:"listInput",height:"24px",type:"text",value:Z,onChangeText:e=>{e.length&&e.trim().length?ee(e):ee("")}})}))}),t.jsxs(x.ScrollContainerStyle,Object.assign({ref:ae},{children:["collections"===$&&t.jsx(d.CollectionsScreen,{customCollectionRestriction:e.customCollectionRestriction,dataLoading:oe,collections:V,selectedCollectionsDispatch:le,setCollectionId:W,setScreen:_,selectedCollections:ie,collectionFetcher:e.collectionFetcher,storeId:j,collectionsDispatch:L,setSaveDisabled:J,pagingControls:{curPage:K,setCurPage:U},hideCollectionCheckbox:k,renderWithoutModal:D,pickerType:w}),"products"===$&&H&&t.jsx(p.CollectionIdContext.Provider,Object.assign({value:H},{children:t.jsx(u.ProductsScreen,{hideInCollectionSearch:e.hideInCollectionSearch,customCollectionRestriction:e.customCollectionRestriction,productFetcher:e.productFetcher,setScreen:_,storeId:j,data:V[H],collectionsDispatch:L,selectedCollectionsDispatch:le,selectedData:ie,setSaveDisabled:J,searchInCollectionFetcher:e.searchInCollectionFetcher,hideProductCheckbox:O,outOfStockAction:R,hideVariantCheckbox:T,selectProductsFromCustomCollection:F,renderWithoutModal:D,pickerType:w,hideProductVariants:M})})),"view"===$&&t.jsx(C.SelectedScreen,{selectedCollections:ie||{},selectedCollectionsDispatch:le,setScreen:_,collections:V}),"rearrange"===$&&t.jsx(h.RearrangeScreen,{selectedCollections:ie||{},selectedCollectionsDispatch:le,setScreen:_,outOfStockAction:R,rearrangeViewType:"grid"===z?"list":"grid",scrollContainerRef:ae}),"searchProducts"===$&&t.jsx(S.SearchScreen,{customCollectionRestriction:e.customCollectionRestriction,selectedCollections:ie||{},searchedCollections:se||{},selectedCollectionsDispatch:le,setScreen:_,collections:V,onBackPress:()=>{ee(""),ne({})},pickerType:w,hideProductCheckbox:O,hideProductVariants:M,hideVariantCheckbox:T})]}))]});return t.jsx(t.Fragment,{children:D?ue:t.jsx(i.StyledModal,Object.assign({zIndex:v,open:b,onClose:()=>{null==y||y(),de()},headingTitle:q||("collections"===$||"products"===$?"Select Products":"view"===$?"Selected Products":"searchProducts"===$?"Searched Products":"rearrange"===$?"Rearrange Products":void 0),footerShadow:!0,centralContainerStyles:{width:E||"480px"},headerRightCustomElement:"rearrange"===$?(console.log("ignore:",G),t.jsx(t.Fragment,{})):t.jsx(t.Fragment,{}),primaryButton:{buttonText:Y?"Loading...":$===exports.ScreenName.RearrangeProducts?"Done":"Add",disabled:Y||Q<1||P&&Q<P||f&&Q>f||!1,onClick:()=>{e.onAdd(ie,Q),de()}},footerLeftCustomElement:I?t.jsx(t.Fragment,{}):f&&Q>f?t.jsx(a.Tag,{tagText:`You can only select ${f} products`,type:"negative"}):Q>0?t.jsx(s.Button,{onClick:()=>{_(B?exports.ScreenName.RearrangeProducts:exports.ScreenName.SelectedProducts)},buttonText:`${Q} products selected ${P?`(Minimum limit ${P})`:""}`,buttonType:["rearrange","view"].includes($)?"tertiaryGray":"tertiary",disabled:["rearrange","view"].includes($)}):t.jsx(s.Button,{disabled:!0,buttonText:`${Q} products selected`,buttonType:"tertiaryGray"})},{children:ue}))})};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as e,jsx as t,Fragment as o}from"react/jsx-runtime";import c from"../../assets/icons/search.svg.js";import{useReducer as r,useState as i,useRef as
|
|
1
|
+
import{jsxs as e,jsx as t,Fragment as o}from"react/jsx-runtime";import c from"../../assets/icons/search.svg.js";import{useReducer as r,useState as i,useRef as n,useEffect as s}from"react";import{COLORS as l}from"../../constants/Theme.js";import{Button as d}from"../button/Button.js";import{Input as a}from"../input/Input.js";import{StyledModal as h}from"../modals/styledModal.js";import{Spinner as u}from"../spinner/Spinner.js";import{Tag as p}from"../tag/Tag.js";import{CollectionsScreen as m}from"./collectionScreen.js";import{ProductsScreen as C}from"./productScreen.js";import{RearrangeScreen as g}from"./rearrangeScreen.js";import{collectionsReducer as b,selectedColectionsReducer as v,CollectionIdContext as y}from"./reducers.js";import{SearchScreen as f}from"./searchScreen.js";import{SelectedScreen as S}from"./selectedScreen.js";import{ContainerStyle as P,ScrollContainerStyle as j}from"./style.js";import{OUT_OF_STOCK_ACTION as x}from"./type.js";var k;!function(e){e.Collections="collections",e.RearrangeProducts="rearrange",e.SelectedProducts="view",e.SearchProducts="searchProducts",e.Products="products"}(k||(k={}));const T=T=>{const{storeId:I,selectedItems:O,onClose:R,visible:D,zIndex:F,minlimit:w,limit:E,hideCollectionCheckbox:V,hideProductCheckbox:A,outOfStockAction:B=x.BLUR,hideVariantCheckbox:M,selectProductsFromCustomCollection:$,hideSelectionCount:L,title:z,width:G,renderWithoutModal:H,onClickSave:W,pickerType:K,hideProductVariants:U=!1,startupScreen:Y=k.Collections,rearrangeEnabled:q}=T,[J,N]=r(b,{}),[Q,X]=i([k.Collections,k.RearrangeProducts].includes(Y)?Y:k.Collections),[Z,_]=i("grid"),[ee,te]=i(""),[oe,ce]=i(0),[re,ie]=i(!1),[ne,se]=i(0),[le,de]=i(""),[ae,he]=i(!1),[ue,pe]=i(!1),[me,Ce]=i(),[ge,be]=r(v,Object.keys(O).length>0?O:{}),ve=n(null);s((()=>{ie(!0),pe(!0),T.collectionFetcher(oe,I).then((e=>{N({type:"fetched",data:(null==e?void 0:e.collections)||{}}),ie(!1),ce((e=>e+1)),pe(!1)})).catch()}),[]),s((()=>{let e=0;Object.keys(ge||[]).forEach((t=>{var o;Object.keys((null===(o=ge[t])||void 0===o?void 0:o.products)||[]).forEach((o=>{var c,r;Object.keys((null===(r=null===(c=ge[t].products)||void 0===c?void 0:c[o])||void 0===r?void 0:r.variants)||[]).forEach((()=>{e+=1}))}))})),se(e)})),s((()=>{var e;ee&&!(null===(e=null==J?void 0:J[ee])||void 0===e?void 0:e.products)&&(ie(!0),T.productFetcher(ee,I).then((e=>{Object.keys(e).length&&N({type:"productsFetched",data:{collectionId:ee,products:e}}),ie(!1)})).catch())}),[ee]),s((()=>{const e=setTimeout((()=>{"rearrange"!==Q&&(le.length?(he(!0),T.searchFetcher(I,le).then((e=>{Ce(Object.assign({},e)),X("searchProducts"),ie(!1),he(!1)}))):X("collections"))}),800);return()=>clearTimeout(e)}),[le]),s((()=>{W&&(T.onAdd(ge,ne),ye())}),[W]);const ye=()=>{be({type:"reset",data:{}})},fe=e(P,{children:[T.postHeader&&t("div",Object.assign({style:{padding:"0 24px"}},{children:T.postHeader})),!T.hideGlobalSearch&&t(o,{children:("collections"===Q||"searchProducts"===Q)&&t("div",Object.assign({style:{padding:H?"8px 16px":"12px 24px",borderBottom:"1px solid #E0E0E0"}},{children:t(a,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>ae?t(u,{size:"small",color:l.content.primary}):t(c,{})},id:"listInput",height:"24px",type:"text",value:le,onChangeText:e=>{e.length&&e.trim().length?de(e):de("")}})}))}),e(j,Object.assign({ref:ve},{children:["collections"===Q&&t(m,{customCollectionRestriction:T.customCollectionRestriction,dataLoading:ue,collections:J,selectedCollectionsDispatch:be,setCollectionId:te,setScreen:X,selectedCollections:ge,collectionFetcher:T.collectionFetcher,storeId:I,collectionsDispatch:N,setSaveDisabled:ie,pagingControls:{curPage:oe,setCurPage:ce},hideCollectionCheckbox:V,renderWithoutModal:H,pickerType:K}),"products"===Q&&ee&&t(y.Provider,Object.assign({value:ee},{children:t(C,{hideInCollectionSearch:T.hideInCollectionSearch,customCollectionRestriction:T.customCollectionRestriction,productFetcher:T.productFetcher,setScreen:X,storeId:I,data:J[ee],collectionsDispatch:N,selectedCollectionsDispatch:be,selectedData:ge,setSaveDisabled:ie,searchInCollectionFetcher:T.searchInCollectionFetcher,hideProductCheckbox:A,outOfStockAction:B,hideVariantCheckbox:M,selectProductsFromCustomCollection:$,renderWithoutModal:H,pickerType:K,hideProductVariants:U})})),"view"===Q&&t(S,{selectedCollections:ge||{},selectedCollectionsDispatch:be,setScreen:X,collections:J}),"rearrange"===Q&&t(g,{selectedCollections:ge||{},selectedCollectionsDispatch:be,setScreen:X,outOfStockAction:B,rearrangeViewType:"grid"===Z?"list":"grid",scrollContainerRef:ve}),"searchProducts"===Q&&t(f,{customCollectionRestriction:T.customCollectionRestriction,selectedCollections:ge||{},searchedCollections:me||{},selectedCollectionsDispatch:be,setScreen:X,collections:J,onBackPress:()=>{de(""),Ce({})},pickerType:K,hideProductCheckbox:A,hideProductVariants:U,hideVariantCheckbox:M})]}))]});return t(o,{children:H?fe:t(h,Object.assign({zIndex:F,open:D,onClose:()=>{null==R||R(),ye()},headingTitle:z||("collections"===Q||"products"===Q?"Select Products":"view"===Q?"Selected Products":"searchProducts"===Q?"Searched Products":"rearrange"===Q?"Rearrange Products":void 0),footerShadow:!0,centralContainerStyles:{width:G||"480px"},headerRightCustomElement:"rearrange"===Q?(console.log("ignore:",_),t(o,{})):t(o,{}),primaryButton:{buttonText:re?"Loading...":Q===k.RearrangeProducts?"Done":"Add",disabled:re||ne<1||w&&ne<w||E&&ne>E||!1,onClick:()=>{T.onAdd(ge,ne),ye()}},footerLeftCustomElement:L?t(o,{}):E&&ne>E?t(p,{tagText:`You can only select ${E} products`,type:"negative"}):t(d,ne>0?{onClick:()=>{X(q?k.RearrangeProducts:k.SelectedProducts)},buttonText:`${ne} products selected ${w?`(Minimum limit ${w})`:""}`,buttonType:["rearrange","view"].includes(Q)?"tertiaryGray":"tertiary",disabled:["rearrange","view"].includes(Q)}:{disabled:!0,buttonText:`${ne} products selected`,buttonType:"tertiaryGray"})},{children:fe}))})};export{T as ProductPickerModal,k as ScreenName};
|