@bikdotai/bik-component-library 0.0.548-beta.2 → 0.0.548-beta.3

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.
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ export interface InfiniteScrollProps {
3
+ children: React.ReactNode;
4
+ fetchMore: () => Promise<boolean>;
5
+ loadingComponent?: React.ReactNode;
6
+ containerRef: React.RefObject<HTMLDivElement>;
7
+ hasData: boolean;
8
+ }
9
+ export declare const InfiniteScroll: React.FC<InfiniteScrollProps>;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),r=require("react"),t=require("../product-picker-v2/ProductPickerShimmer.js");exports.InfiniteScroll=n=>{let{children:i,fetchMore:c,loadingComponent:o=e.jsx(t.ProductPickerShimmer,{limit:1}),containerRef:u,hasData:s}=n;const l=r.useRef(!1),[d,a]=r.useState(!1),f=r.useRef(null);return r.useEffect((()=>{if(!u.current||!f.current)return;const e=u.current,r=f.current,t=()=>{if(d)return;const t=e.getBoundingClientRect(),n=r.getBoundingClientRect();n.top<=t.bottom&&n.bottom>=t.top&&(a(!0),c().then((e=>{e&&(l.current=!0),a(!1)})))};return e.addEventListener("scroll",t),()=>{e.removeEventListener("scroll",t)}}),[c,d,u]),e.jsxs("div",{children:[i,!!s&&!l.current&&e.jsx("div",Object.assign({ref:f,style:{minHeight:"10px"}},{children:o}))]})};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("../../assets/icons/arrow_left.svg.js"),r=require("../../assets/icons/box.svg.js"),c=require("../../assets/icons/search.svg.js"),o=require("lodash"),s=require("react"),n=require("../../constants/Theme.js"),i=require("../checkBox/CheckBox.js"),l=require("../icon-button/IconButton.js"),u=require("../input/Input.js"),d=require("../spinner/Spinner.js"),a=require("../TypographyStyle.js"),h=require("./emptyState.js"),p=require("./product.js"),j=require("./ProductPickerShimmer.js"),g=require("./reducers.js"),v=require("./style.js"),f=require("./type.js"),y=require("./utility.js");const b=t=>{let{children:r,fetchMore:c,loadingComponent:o=e.jsx(j.ProductPickerShimmer,{limit:1}),containerRef:n}=t;const i=s.useRef(!1),[l,u]=s.useState(!1),d=s.useRef(null);return s.useEffect((()=>{if(!n.current||!d.current)return;const e=n.current,t=d.current,r=()=>{if(l)return;const r=e.getBoundingClientRect(),o=t.getBoundingClientRect();o.top<=r.bottom&&o.bottom>=r.top&&(u(!0),c().then((e=>{Object.keys(e).length||(i.current=!0),u(!1)})))};return e.addEventListener("scroll",r),()=>{e.removeEventListener("scroll",r)}}),[c,l,n]),e.jsxs("div",{children:[r,!i.current&&e.jsx("div",Object.assign({ref:d,style:{minHeight:"10px"}},{children:o}))]})};exports.ProductsScreen=C=>{var P,O;const{data:k,collectionsDispatch:x,selectedData:m,selectedCollectionsDispatch:S,productFetcher:I,storeId:E,setScreen:R,setSaveDisabled:q,hideInCollectionSearch:A,customCollectionRestriction:T,hideProductCheckbox:D,outOfStockAction:V=f.OUT_OF_STOCK_ACTION.BLUR,hideVariantCheckbox:L=!1,selectProductsFromCustomCollection:B=!1,pickerType:F,hideProductVariants:w,fbStatusFetcher:_,onProductDetailClick:M,showProductDetailInfoIcon:H,scrollContainerRef:U}=C,J=s.useContext(g.CollectionIdContext),K=s.useRef(0),N=s.useRef(!1),[W,z]=s.useState(""),[G,Q]=s.useState(!1),[X,Y]=s.useState(k),Z=s.useRef(!1);s.useEffect((()=>{const e=setTimeout((()=>{W.length?(Q(!0),C.searchInCollectionFetcher(E,J,W).then((e=>{const t=o.cloneDeep(k);t.products=e,Y(t);const r=y.getVariantIdsToFetchAtProductLevel(null!=e?e:{});ee(r,null!=e?e:{},!0),q(!1),Q(!1)}))):Y(k)}),800);return()=>clearTimeout(e)}),[W]),s.useEffect((()=>{var e,t,r,c;Z.current=!1,K.current=Math.floor((null===(t=Object.keys(null!==(e=k.products)&&void 0!==e?e:{}))||void 0===t?void 0:t.length)/10);const o=y.getVariantIdsToFetchAtProductLevel(null!==(r=k.products)&&void 0!==r?r:{});ee(o,null!==(c=k.products)&&void 0!==c?c:{})}),[J]);const $=!!T&&k.isSmartCollection;s.useEffect((()=>{(null==k?void 0:k.products)||te(10)}),[]);const ee=(e,t,r)=>{_||(r?y.markVariantsAsApprovedProductsLevel(t,x,J,X,Y):y.markVariantsAsApprovedProductsLevel(t,x,J)),e.length>0&&_&&_(E,e).then((e=>{const c=Object.assign({},t);Object.keys(t).forEach((r=>{var o,s;Object.keys(null!==(s=null===(o=null==t?void 0:t[r])||void 0===o?void 0:o.variants)&&void 0!==s?s:{}).forEach((o=>{var s,n;const i=null===(s=null==t?void 0:t[r].variants)||void 0===s?void 0:s[o];i&&"REJECTED"===e[o]?i.fbStatus="REJECTED":i&&"APPROVED"===e[o]&&(i.fbStatus="APPROVED");const l=null===(n=null==c?void 0:c[r])||void 0===n?void 0:n.variants;l&&l[o]&&(l[o]=i)}))})),r?(Y((e=>{const t=Object.assign({},e);return t.products=c,t})),x({type:"productsPaged",data:{collectionId:J,products:c}})):x({type:"productsPaged",data:{collectionId:J,products:c}})})).catch((e=>{r?y.markVariantsAsApprovedProductsLevel(t,x,J,X,Y):y.markVariantsAsApprovedProductsLevel(t,x,J)}))},te=e=>{q(!0),Q(!0),I(J,E,e,0).then((t=>{if(Object.keys(t).length||(Z.current=!0),Object.keys(t).length){Y(Object.assign(Object.assign({},X),{products:t}));const e=y.getVariantIdsToFetchAtProductLevel(t);ee(e,t),K.current=1}e||S({type:"selected",data:{id:J,val:Object.assign(Object.assign({},k),{products:t})}}),q(!1),Q(!1)})).catch()},re=(e,t)=>{const r=y.liftTheStateUp(t,k);S({type:e,data:Object.assign(Object.assign({},r),{isRestricted:T})})},ce=!!(null==m?void 0:m[J])&&!!Object.keys(null!==(O=null===(P=null==m?void 0:m[J])||void 0===P?void 0:P.products)&&void 0!==O?O:{}).length;return s.useRef(null),e.jsxs("div",{children:[e.jsxs(v.ProductScreenHeader,{children:[e.jsx(l.IconButton,{Icon:t.default,height:16,onClick:()=>{R("collections")}}),e.jsx(a.BodyCaption,Object.assign({style:{color:n.COLORS.content.secondary}},{children:k.name}))]}),!A&&e.jsx("div",Object.assign({style:{padding:16,height:"76px",borderBottom:"1px solid #E0E0E0"}},{children:e.jsx(u.Input,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>G&&W.length?e.jsx(d.Spinner,{size:"small",color:n.COLORS.content.primary}):e.jsx(c.default,{})},id:"listInput",height:"24px",type:"text",value:W,onChangeText:e=>{e.length&&e.trim().length?z(e):z("")},placeholder:"Search products in this collection..."})})),Object.keys((null==X?void 0:X.products)||[]).length>0&&!$&&!W.length&&!D&&"-1"!==J&&e.jsxs(v.ProductScreenCollectionCardStyle,{children:[e.jsx(i.CheckBox,{isChecked:ce,isPartiallyChecked:y.isCollectionPartiallyChecked(J,X,m,w),onValueChange:function(e){e?te():S({type:"unselected",data:{id:J}})}}),e.jsx("div",Object.assign({style:{width:40,height:40}},{children:e.jsx(r.default,{})})),e.jsx(a.TitleRegular,{children:"All Products"})]}),e.jsx(b,Object.assign({fetchMore:()=>(N.current=!0,I(J,E,10,K.current).then((e=>{if(Object.keys(e).length||(Z.current=!0),Object.keys(e).length){const t=X;t.products=Object.assign(Object.assign({},X.products),e),Y(Object.assign({},t));const r=y.getVariantIdsToFetchAtProductLevel(e);ee(r,e)}return N.current=!1,K.current+=1,e}))),loadingComponent:e.jsx(j.ProductPickerShimmer,{limit:1}),containerRef:U},{children:Object.keys((null==X?void 0:X.products)||[]).length?Object.keys(X.products||[]).map((t=>e.jsx(p.ProductGroup,{outOfStockAction:V,collectionId:J,isProductPartiallyChecked:y.isProductPartiallyChecked(J,t,m,X,w),productId:t,data:X.products[t],selectedData:m,selectedCollectionsDispatch:S,viewOnly:!B&&!!$,upliftAdditions:re,hideProductCheckbox:D,hideVariantCheckbox:L,hideProductVariants:w,pickerType:F,onProductDetailClick:M,showProductDetailInfoIcon:H},t))):G?e.jsx(j.ProductPickerShimmer,{limit:10}):e.jsx(h.EmptyState,{title:"No products to show",subtitle:W.length?"We couldn't find the product you were looking for":"We couldn’t find any product in this collection."})}))]})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("../../assets/icons/arrow_left.svg.js"),o=require("../../assets/icons/box.svg.js"),c=require("../../assets/icons/search.svg.js"),s=require("lodash"),r=require("react"),n=require("../../constants/Theme.js"),i=require("../checkBox/CheckBox.js"),l=require("../icon-button/IconButton.js"),d=require("../InfiniteScroll/InfiniteScroll.js"),u=require("../input/Input.js"),a=require("../spinner/Spinner.js"),h=require("../TypographyStyle.js"),p=require("./emptyState.js"),j=require("./product.js"),v=require("./ProductPickerShimmer.js"),g=require("./reducers.js"),y=require("./style.js"),O=require("./type.js"),P=require("./utility.js");exports.ProductsScreen=b=>{var C,k;const{data:f,collectionsDispatch:x,selectedData:S,selectedCollectionsDispatch:m,productFetcher:I,storeId:q,setScreen:A,setSaveDisabled:E,hideInCollectionSearch:T,customCollectionRestriction:D,hideProductCheckbox:R,outOfStockAction:V=O.OUT_OF_STOCK_ACTION.BLUR,hideVariantCheckbox:L=!1,selectProductsFromCustomCollection:F=!1,pickerType:w,hideProductVariants:B,fbStatusFetcher:_,onProductDetailClick:M,showProductDetailInfoIcon:U,scrollContainerRef:H}=b,J=r.useContext(g.CollectionIdContext),K=r.useRef(0),N=r.useRef(!1),[W,z]=r.useState(""),[G,Q]=r.useState(!1),[X,Y]=r.useState(f),Z=r.useRef(!1);r.useEffect((()=>{const e=setTimeout((()=>{W.length?(Q(!0),b.searchInCollectionFetcher(q,J,W).then((e=>{const t=s.cloneDeep(f);t.products=e,Y(t);const o=P.getVariantIdsToFetchAtProductLevel(null!=e?e:{});ee(o,null!=e?e:{},!0),E(!1),Q(!1)}))):Y(f)}),800);return()=>clearTimeout(e)}),[W]);r.useEffect((()=>{var e,t,o,c;Z.current=!1,K.current=Math.floor((null===(t=Object.keys(null!==(e=f.products)&&void 0!==e?e:{}))||void 0===t?void 0:t.length)/10);const s=P.getVariantIdsToFetchAtProductLevel(null!==(o=f.products)&&void 0!==o?o:{});ee(s,null!==(c=f.products)&&void 0!==c?c:{})}),[J]);const $=!!D&&f.isSmartCollection;r.useEffect((()=>{(null==f?void 0:f.products)||te(10)}),[]);const ee=(e,t,o)=>{_||(o?P.markVariantsAsApprovedProductsLevel(t,x,J,X,Y):P.markVariantsAsApprovedProductsLevel(t,x,J)),e.length>0&&_&&_(q,e).then((e=>{const c=Object.assign({},t);Object.keys(t).forEach((o=>{var s,r;Object.keys(null!==(r=null===(s=null==t?void 0:t[o])||void 0===s?void 0:s.variants)&&void 0!==r?r:{}).forEach((s=>{var r,n;const i=null===(r=null==t?void 0:t[o].variants)||void 0===r?void 0:r[s];i&&"REJECTED"===e[s]?i.fbStatus="REJECTED":i&&"APPROVED"===e[s]&&(i.fbStatus="APPROVED");const l=null===(n=null==c?void 0:c[o])||void 0===n?void 0:n.variants;l&&l[s]&&(l[s]=i)}))})),o?(Y((e=>{const t=Object.assign({},e);return t.products=c,t})),x({type:"productsPaged",data:{collectionId:J,products:c}})):x({type:"productsPaged",data:{collectionId:J,products:c}})})).catch((e=>{o?P.markVariantsAsApprovedProductsLevel(t,x,J,X,Y):P.markVariantsAsApprovedProductsLevel(t,x,J)}))},te=e=>{E(!0),Q(!0),I(J,q,e,0).then((t=>{if(Object.keys(t).length||(Z.current=!0),Object.keys(t).length){Y(Object.assign(Object.assign({},X),{products:t}));const e=P.getVariantIdsToFetchAtProductLevel(t);ee(e,t),K.current=1}e||m({type:"selected",data:{id:J,val:Object.assign(Object.assign({},f),{products:t})}}),E(!1),Q(!1)})).catch()},oe=(e,t)=>{const o=P.liftTheStateUp(t,f);m({type:e,data:Object.assign(Object.assign({},o),{isRestricted:D})})},ce=!!(null==S?void 0:S[J])&&!!Object.keys(null!==(k=null===(C=null==S?void 0:S[J])||void 0===C?void 0:C.products)&&void 0!==k?k:{}).length;return e.jsxs("div",{children:[e.jsxs(y.ProductScreenHeader,{children:[e.jsx(l.IconButton,{Icon:t.default,height:16,onClick:()=>{A("collections")}}),e.jsx(h.BodyCaption,Object.assign({style:{color:n.COLORS.content.secondary}},{children:f.name}))]}),!T&&e.jsx("div",Object.assign({style:{padding:16,height:"76px",borderBottom:"1px solid #E0E0E0"}},{children:e.jsx(u.Input,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>G&&W.length?e.jsx(a.Spinner,{size:"small",color:n.COLORS.content.primary}):e.jsx(c.default,{})},id:"listInput",height:"24px",type:"text",value:W,onChangeText:e=>{e.length&&e.trim().length?z(e):z("")},placeholder:"Search products in this collection..."})})),Object.keys((null==X?void 0:X.products)||[]).length>0&&!$&&!W.length&&!R&&"-1"!==J&&e.jsxs(y.ProductScreenCollectionCardStyle,{children:[e.jsx(i.CheckBox,{isChecked:ce,isPartiallyChecked:P.isCollectionPartiallyChecked(J,X,S,B),onValueChange:function(e){e?te():m({type:"unselected",data:{id:J}})}}),e.jsx("div",Object.assign({style:{width:40,height:40}},{children:e.jsx(o.default,{})})),e.jsx(h.TitleRegular,{children:"All Products"})]}),e.jsx(d.InfiniteScroll,Object.assign({hasData:!!Object.keys((null==X?void 0:X.products)||[]).length,fetchMore:()=>(N.current=!0,I(J,q,10,K.current).then((e=>{let t=!1;if(Object.keys(e).length||(t=!0),Object.keys(e).length){const t=X;t.products=Object.assign(Object.assign({},X.products),e),Y(Object.assign({},t));const o=P.getVariantIdsToFetchAtProductLevel(e);ee(o,e)}return E(!1),N.current=!1,K.current+=1,t}))),loadingComponent:e.jsx(v.ProductPickerShimmer,{limit:1}),containerRef:H},{children:Object.keys((null==X?void 0:X.products)||[]).length?Object.keys(X.products||[]).map((t=>e.jsx(j.ProductGroup,{outOfStockAction:V,collectionId:J,isProductPartiallyChecked:P.isProductPartiallyChecked(J,t,S,X,B),productId:t,data:X.products[t],selectedData:S,selectedCollectionsDispatch:m,viewOnly:!F&&!!$,upliftAdditions:oe,hideProductCheckbox:R,hideVariantCheckbox:L,hideProductVariants:B,pickerType:w,onProductDetailClick:M,showProductDetailInfoIcon:U},t))):G?e.jsx(v.ProductPickerShimmer,{limit:10}):e.jsx(p.EmptyState,{title:"No products to show",subtitle:W.length?"We couldn't find the product you were looking for":"We couldn’t find any product in this collection."})}))]})};
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ export interface InfiniteScrollProps {
3
+ children: React.ReactNode;
4
+ fetchMore: () => Promise<boolean>;
5
+ loadingComponent?: React.ReactNode;
6
+ containerRef: React.RefObject<HTMLDivElement>;
7
+ hasData: boolean;
8
+ }
9
+ export declare const InfiniteScroll: React.FC<InfiniteScrollProps>;
@@ -0,0 +1 @@
1
+ import{jsx as t,jsxs as r}from"react/jsx-runtime";import{useRef as e,useState as n,useEffect as o}from"react";import{ProductPickerShimmer as i}from"../product-picker-v2/ProductPickerShimmer.js";const c=c=>{let{children:u,fetchMore:l,loadingComponent:m=t(i,{limit:1}),containerRef:s,hasData:d}=c;const p=e(!1),[a,f]=n(!1),h=e(null);return o((()=>{if(!s.current||!h.current)return;const t=s.current,r=h.current,e=()=>{if(a)return;const e=t.getBoundingClientRect(),n=r.getBoundingClientRect();n.top<=e.bottom&&n.bottom>=e.top&&(f(!0),l().then((t=>{t&&(p.current=!0),f(!1)})))};return t.addEventListener("scroll",e),()=>{t.removeEventListener("scroll",e)}}),[l,a,s]),r("div",{children:[u,!!d&&!p.current&&t("div",Object.assign({ref:h,style:{minHeight:"10px"}},{children:m}))]})};export{c as InfiniteScroll};
@@ -1 +1 @@
1
- import{jsxs as t,jsx as e}from"react/jsx-runtime";import o from"../../assets/icons/arrow_left.svg.js";import n from"../../assets/icons/box.svg.js";import c from"../../assets/icons/search.svg.js";import{cloneDeep as r}from"lodash";import{useContext as i,useRef as s,useState as l,useEffect as d}from"react";import{COLORS as a}from"../../constants/Theme.js";import{CheckBox as u}from"../checkBox/CheckBox.js";import{IconButton as h}from"../icon-button/IconButton.js";import{Input as p}from"../input/Input.js";import{Spinner as m}from"../spinner/Spinner.js";import{BodyCaption as g,TitleRegular as f}from"../TypographyStyle.js";import{EmptyState as j}from"./emptyState.js";import{ProductGroup as v}from"./product.js";import{ProductPickerShimmer as b}from"./ProductPickerShimmer.js";import{CollectionIdContext as y}from"./reducers.js";import{ProductScreenHeader as O,ProductScreenCollectionCardStyle as k}from"./style.js";import{OUT_OF_STOCK_ACTION as C}from"./type.js";import{getVariantIdsToFetchAtProductLevel as P,markVariantsAsApprovedProductsLevel as E,isCollectionPartiallyChecked as I,isProductPartiallyChecked as x,liftTheStateUp as D}from"./utility.js";const S=S=>{var T,w;const{data:B,collectionsDispatch:V,selectedData:A,selectedCollectionsDispatch:F,productFetcher:L,storeId:M,setScreen:H,setSaveDisabled:J,hideInCollectionSearch:W,customCollectionRestriction:z,hideProductCheckbox:K,outOfStockAction:N=C.BLUR,hideVariantCheckbox:U=!1,selectProductsFromCustomCollection:_=!1,pickerType:q,hideProductVariants:G,fbStatusFetcher:Q,onProductDetailClick:X,showProductDetailInfoIcon:Y,scrollContainerRef:Z}=S,$=i(y),tt=s(0),et=s(!1),[ot,nt]=l(""),[ct,rt]=l(!1),[it,st]=l(B),lt=s(!1);d((()=>{const t=setTimeout((()=>{ot.length?(rt(!0),S.searchInCollectionFetcher(M,$,ot).then((t=>{const e=r(B);e.products=t,st(e);const o=P(null!=t?t:{});at(o,null!=t?t:{},!0),J(!1),rt(!1)}))):st(B)}),800);return()=>clearTimeout(t)}),[ot]),d((()=>{var t,e,o,n;lt.current=!1,tt.current=Math.floor((null===(e=Object.keys(null!==(t=B.products)&&void 0!==t?t:{}))||void 0===e?void 0:e.length)/10);const c=P(null!==(o=B.products)&&void 0!==o?o:{});at(c,null!==(n=B.products)&&void 0!==n?n:{})}),[$]);const dt=!!z&&B.isSmartCollection;d((()=>{(null==B?void 0:B.products)||ut(10)}),[]);const at=(t,e,o)=>{Q||(o?E(e,V,$,it,st):E(e,V,$)),t.length>0&&Q&&Q(M,t).then((t=>{const n=Object.assign({},e);Object.keys(e).forEach((o=>{var c,r;Object.keys(null!==(r=null===(c=null==e?void 0:e[o])||void 0===c?void 0:c.variants)&&void 0!==r?r:{}).forEach((c=>{var r,i;const s=null===(r=null==e?void 0:e[o].variants)||void 0===r?void 0:r[c];s&&"REJECTED"===t[c]?s.fbStatus="REJECTED":s&&"APPROVED"===t[c]&&(s.fbStatus="APPROVED");const l=null===(i=null==n?void 0:n[o])||void 0===i?void 0:i.variants;l&&l[c]&&(l[c]=s)}))})),o?(st((t=>{const e=Object.assign({},t);return e.products=n,e})),V({type:"productsPaged",data:{collectionId:$,products:n}})):V({type:"productsPaged",data:{collectionId:$,products:n}})})).catch((t=>{o?E(e,V,$,it,st):E(e,V,$)}))},ut=t=>{J(!0),rt(!0),L($,M,t,0).then((e=>{if(Object.keys(e).length||(lt.current=!0),Object.keys(e).length){st(Object.assign(Object.assign({},it),{products:e}));const t=P(e);at(t,e),tt.current=1}t||F({type:"selected",data:{id:$,val:Object.assign(Object.assign({},B),{products:e})}}),J(!1),rt(!1)})).catch()},ht=(t,e)=>{const o=D(e,B);F({type:t,data:Object.assign(Object.assign({},o),{isRestricted:z})})},pt=!!(null==A?void 0:A[$])&&!!Object.keys(null!==(w=null===(T=null==A?void 0:A[$])||void 0===T?void 0:T.products)&&void 0!==w?w:{}).length;return s(null),t("div",{children:[t(O,{children:[e(h,{Icon:o,height:16,onClick:()=>{H("collections")}}),e(g,Object.assign({style:{color:a.content.secondary}},{children:B.name}))]}),!W&&e("div",Object.assign({style:{padding:16,height:"76px",borderBottom:"1px solid #E0E0E0"}},{children:e(p,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>ct&&ot.length?e(m,{size:"small",color:a.content.primary}):e(c,{})},id:"listInput",height:"24px",type:"text",value:ot,onChangeText:t=>{t.length&&t.trim().length?nt(t):nt("")},placeholder:"Search products in this collection..."})})),Object.keys((null==it?void 0:it.products)||[]).length>0&&!dt&&!ot.length&&!K&&"-1"!==$&&t(k,{children:[e(u,{isChecked:pt,isPartiallyChecked:I($,it,A,G),onValueChange:function(t){t?ut():F({type:"unselected",data:{id:$}})}}),e("div",Object.assign({style:{width:40,height:40}},{children:e(n,{})})),e(f,{children:"All Products"})]}),e(R,Object.assign({fetchMore:()=>(et.current=!0,L($,M,10,tt.current).then((t=>{if(Object.keys(t).length||(lt.current=!0),Object.keys(t).length){const e=it;e.products=Object.assign(Object.assign({},it.products),t),st(Object.assign({},e));const o=P(t);at(o,t)}return et.current=!1,tt.current+=1,t}))),loadingComponent:e(b,{limit:1}),containerRef:Z},{children:Object.keys((null==it?void 0:it.products)||[]).length?Object.keys(it.products||[]).map((t=>e(v,{outOfStockAction:N,collectionId:$,isProductPartiallyChecked:x($,t,A,it,G),productId:t,data:it.products[t],selectedData:A,selectedCollectionsDispatch:F,viewOnly:!_&&!!dt,upliftAdditions:ht,hideProductCheckbox:K,hideVariantCheckbox:U,hideProductVariants:G,pickerType:q,onProductDetailClick:X,showProductDetailInfoIcon:Y},t))):ct?e(b,{limit:10}):e(j,{title:"No products to show",subtitle:ot.length?"We couldn't find the product you were looking for":"We couldn’t find any product in this collection."})}))]})},R=o=>{let{children:n,fetchMore:c,loadingComponent:r=e(b,{limit:1}),containerRef:i}=o;const a=s(!1),[u,h]=l(!1),p=s(null);return d((()=>{if(!i.current||!p.current)return;const t=i.current,e=p.current,o=()=>{if(u)return;const o=t.getBoundingClientRect(),n=e.getBoundingClientRect();n.top<=o.bottom&&n.bottom>=o.top&&(h(!0),c().then((t=>{Object.keys(t).length||(a.current=!0),h(!1)})))};return t.addEventListener("scroll",o),()=>{t.removeEventListener("scroll",o)}}),[c,u,i]),t("div",{children:[n,!a.current&&e("div",Object.assign({ref:p,style:{minHeight:"10px"}},{children:r}))]})};export{S as ProductsScreen};
1
+ import{jsxs as t,jsx as e}from"react/jsx-runtime";import o from"../../assets/icons/arrow_left.svg.js";import c from"../../assets/icons/box.svg.js";import n from"../../assets/icons/search.svg.js";import{cloneDeep as i}from"lodash";import{useContext as r,useRef as s,useState as l,useEffect as d}from"react";import{COLORS as a}from"../../constants/Theme.js";import{CheckBox as u}from"../checkBox/CheckBox.js";import{IconButton as h}from"../icon-button/IconButton.js";import{InfiniteScroll as p}from"../InfiniteScroll/InfiniteScroll.js";import{Input as m}from"../input/Input.js";import{Spinner as g}from"../spinner/Spinner.js";import{BodyCaption as j,TitleRegular as f}from"../TypographyStyle.js";import{EmptyState as v}from"./emptyState.js";import{ProductGroup as b}from"./product.js";import{ProductPickerShimmer as y}from"./ProductPickerShimmer.js";import{CollectionIdContext as O}from"./reducers.js";import{ProductScreenHeader as k,ProductScreenCollectionCardStyle as C}from"./style.js";import{OUT_OF_STOCK_ACTION as P}from"./type.js";import{getVariantIdsToFetchAtProductLevel as I,markVariantsAsApprovedProductsLevel as D,isCollectionPartiallyChecked as S,isProductPartiallyChecked as x,liftTheStateUp as E}from"./utility.js";const R=R=>{var T,w;const{data:V,collectionsDispatch:A,selectedData:B,selectedCollectionsDispatch:F,productFetcher:J,storeId:M,setScreen:W,setSaveDisabled:z,hideInCollectionSearch:H,customCollectionRestriction:K,hideProductCheckbox:L,outOfStockAction:N=P.BLUR,hideVariantCheckbox:U=!1,selectProductsFromCustomCollection:_=!1,pickerType:q,hideProductVariants:G,fbStatusFetcher:Q,onProductDetailClick:X,showProductDetailInfoIcon:Y,scrollContainerRef:Z}=R,$=r(O),tt=s(0),et=s(!1),[ot,ct]=l(""),[nt,it]=l(!1),[rt,st]=l(V),lt=s(!1);d((()=>{const t=setTimeout((()=>{ot.length?(it(!0),R.searchInCollectionFetcher(M,$,ot).then((t=>{const e=i(V);e.products=t,st(e);const o=I(null!=t?t:{});at(o,null!=t?t:{},!0),z(!1),it(!1)}))):st(V)}),800);return()=>clearTimeout(t)}),[ot]);d((()=>{var t,e,o,c;lt.current=!1,tt.current=Math.floor((null===(e=Object.keys(null!==(t=V.products)&&void 0!==t?t:{}))||void 0===e?void 0:e.length)/10);const n=I(null!==(o=V.products)&&void 0!==o?o:{});at(n,null!==(c=V.products)&&void 0!==c?c:{})}),[$]);const dt=!!K&&V.isSmartCollection;d((()=>{(null==V?void 0:V.products)||ut(10)}),[]);const at=(t,e,o)=>{Q||(o?D(e,A,$,rt,st):D(e,A,$)),t.length>0&&Q&&Q(M,t).then((t=>{const c=Object.assign({},e);Object.keys(e).forEach((o=>{var n,i;Object.keys(null!==(i=null===(n=null==e?void 0:e[o])||void 0===n?void 0:n.variants)&&void 0!==i?i:{}).forEach((n=>{var i,r;const s=null===(i=null==e?void 0:e[o].variants)||void 0===i?void 0:i[n];s&&"REJECTED"===t[n]?s.fbStatus="REJECTED":s&&"APPROVED"===t[n]&&(s.fbStatus="APPROVED");const l=null===(r=null==c?void 0:c[o])||void 0===r?void 0:r.variants;l&&l[n]&&(l[n]=s)}))})),o?(st((t=>{const e=Object.assign({},t);return e.products=c,e})),A({type:"productsPaged",data:{collectionId:$,products:c}})):A({type:"productsPaged",data:{collectionId:$,products:c}})})).catch((t=>{o?D(e,A,$,rt,st):D(e,A,$)}))},ut=t=>{z(!0),it(!0),J($,M,t,0).then((e=>{if(Object.keys(e).length||(lt.current=!0),Object.keys(e).length){st(Object.assign(Object.assign({},rt),{products:e}));const t=I(e);at(t,e),tt.current=1}t||F({type:"selected",data:{id:$,val:Object.assign(Object.assign({},V),{products:e})}}),z(!1),it(!1)})).catch()},ht=(t,e)=>{const o=E(e,V);F({type:t,data:Object.assign(Object.assign({},o),{isRestricted:K})})},pt=!!(null==B?void 0:B[$])&&!!Object.keys(null!==(w=null===(T=null==B?void 0:B[$])||void 0===T?void 0:T.products)&&void 0!==w?w:{}).length;return t("div",{children:[t(k,{children:[e(h,{Icon:o,height:16,onClick:()=>{W("collections")}}),e(j,Object.assign({style:{color:a.content.secondary}},{children:V.name}))]}),!H&&e("div",Object.assign({style:{padding:16,height:"76px",borderBottom:"1px solid #E0E0E0"}},{children:e(m,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>nt&&ot.length?e(g,{size:"small",color:a.content.primary}):e(n,{})},id:"listInput",height:"24px",type:"text",value:ot,onChangeText:t=>{t.length&&t.trim().length?ct(t):ct("")},placeholder:"Search products in this collection..."})})),Object.keys((null==rt?void 0:rt.products)||[]).length>0&&!dt&&!ot.length&&!L&&"-1"!==$&&t(C,{children:[e(u,{isChecked:pt,isPartiallyChecked:S($,rt,B,G),onValueChange:function(t){t?ut():F({type:"unselected",data:{id:$}})}}),e("div",Object.assign({style:{width:40,height:40}},{children:e(c,{})})),e(f,{children:"All Products"})]}),e(p,Object.assign({hasData:!!Object.keys((null==rt?void 0:rt.products)||[]).length,fetchMore:()=>(et.current=!0,J($,M,10,tt.current).then((t=>{let e=!1;if(Object.keys(t).length||(e=!0),Object.keys(t).length){const e=rt;e.products=Object.assign(Object.assign({},rt.products),t),st(Object.assign({},e));const o=I(t);at(o,t)}return z(!1),et.current=!1,tt.current+=1,e}))),loadingComponent:e(y,{limit:1}),containerRef:Z},{children:Object.keys((null==rt?void 0:rt.products)||[]).length?Object.keys(rt.products||[]).map((t=>e(b,{outOfStockAction:N,collectionId:$,isProductPartiallyChecked:x($,t,B,rt,G),productId:t,data:rt.products[t],selectedData:B,selectedCollectionsDispatch:F,viewOnly:!_&&!!dt,upliftAdditions:ht,hideProductCheckbox:L,hideVariantCheckbox:U,hideProductVariants:G,pickerType:q,onProductDetailClick:X,showProductDetailInfoIcon:Y},t))):nt?e(y,{limit:10}):e(v,{title:"No products to show",subtitle:ot.length?"We couldn't find the product you were looking for":"We couldn’t find any product in this collection."})}))]})};export{R as ProductsScreen};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikdotai/bik-component-library",
3
- "version": "0.0.548-beta.2",
3
+ "version": "0.0.548-beta.3",
4
4
  "description": "Bik Component Library",
5
5
  "repository": {
6
6
  "type": "git",