@bothub-chat/ui 2.41.1 → 2.41.2

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
- import{useState as e,useCallback as t,useRef as n,useEffect as o}from"react";const r=({value:r,multiple:l=!1,disabled:i=!1,placement:s="bottom-left",contentHeight:c,onClose:u,onSelectClick:d,onChange:a,onValueChange:w})=>{const[g,m]=e(!1),[p,f]=e(0),[h,v]=e(0),[b,y]=e(0),[E,L]=e(c),[C,k]=e(s),H=t((e=>{if(l&&Array.isArray(e)){const t=w,n=e;null==a||a(e),null==t||t(n.map((e=>"string"==typeof e?e:"string"==typeof e.value?e.value:"")).filter((e=>!!e)))}if(!l&&!Array.isArray(e)){null==a||a(e);const t=w;e?"string"==typeof e?null==t||t(e):"string"==typeof e.value&&(null==t||t(e.value)):null==t||t(null)}}),[l,a,w]);let[R,z]=e(l?[]:null);void 0!==r&&([R,z]=[r,H]);const A=n(!1),X=n(null),Y=n(null);o((()=>{const e=()=>{const e=X.current;if(!e||!E||!c)return;let t=c;const{top:n,bottom:o}=e.getBoundingClientRect();t=C.includes("top")?n-20:window.innerHeight-o-20,L(t<c?t:c)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)}),[X.current,E,C,c,g]),o((()=>{if(!g)return;const e=e=>{if(!A.current||"orientationchange"===e.type){if("mousedown"===e.type){const t=X.current,n=Y.current;if(null===t||null===n)return;if(t.contains(e.target)||n.contains(e.target))return}x()}};return document.addEventListener("mousedown",e),document.addEventListener("scroll",e),window.addEventListener("resize",e),window.addEventListener("orientationchange",e),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("scroll",e),window.removeEventListener("resize",e),window.removeEventListener("orientationchange",e)}}),[g]);const B=t(((e,t)=>{null==d||d();const n=X.current,o=Y.current;if(!n||!o||i)return;e&&t.stopPropagation();const r=window.innerHeight||document.documentElement.clientHeight,{width:l,height:c,top:u,bottom:a,left:w,right:p}=n.getBoundingClientRect(),{width:h}=o.getBoundingClientRect();let b=C;b=u-186<0?"bottom-left"===b?"bottom-left":"bottom-center":a+186>r?"top-right"===s?"top-right":"top-left":s;let E=0,L=0;switch(b){case"bottom-left":E=w+window.scrollX,L=u+window.scrollY+c;break;case"bottom-center":E=Math.floor((w+p)/2+window.scrollX-h/2),L=u+window.scrollY+c;break;case"top-left":E=w+window.scrollX,L=u+window.scrollY;break;case"top-right":E=w+window.scrollX+l,L=u+window.scrollY}f(E),v(L),y(l),k(b),m(!!e||!g)}),[i,g,C,s,d]),x=t((()=>{m(!1),null==u||u()}),[]);return{x:p,y:h,width:b,isOpen:g,triggerRef:X,selectModalRef:Y,placement:C,isKeyboardOpen:A,value:R,disabled:i,multiple:l,contentHeight:E,handleInputClick:B,handleClose:x,setValue:e=>{z(e),H(e)}}};export{r as useSelectField};
1
+ import{useState as e,useCallback as t,useRef as n,useEffect as o}from"react";const r=({value:r,multiple:l=!1,disabled:i=!1,placement:s="bottom-left",contentHeight:c,onClose:u,onSelectClick:d,onChange:a,onValueChange:w})=>{const[g,m]=e(!1),[p,f]=e(0),[h,v]=e(0),[b,y]=e(0),[E,L]=e(c),[C,k]=e(s),H=t((e=>{if(l&&Array.isArray(e)){const t=w,n=e;null==a||a(e),null==t||t(n.map((e=>"string"==typeof e?e:"string"==typeof e.value?e.value:"")).filter((e=>!!e)))}if(!l&&!Array.isArray(e)){null==a||a(e);const t=w;e?"string"==typeof e?null==t||t(e):"string"==typeof e.value&&(null==t||t(e.value)):null==t||t(null)}}),[l,a,w]);let[R,z]=e(l?[]:null);void 0!==r&&([R,z]=[r,H]);const A=n(!1),X=n(null),Y=n(null);o((()=>{const e=()=>{const e=X.current;if(!e||!E||!c)return;let t=c;const{top:n,bottom:o}=e.getBoundingClientRect();t=C.includes("top")?n-20:window.innerHeight-o-20,L(t<c?t:c)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)}),[X.current,E,C,c,g]),o((()=>{if(!g)return;const e=e=>{if(!A.current||"orientationchange"===e.type){if("mousedown"===e.type){const t=X.current,n=Y.current;if(null===t||null===n)return;if(t.contains(e.target)||n.contains(e.target))return}x()}};return document.addEventListener("mousedown",e),document.addEventListener("scroll",e),window.addEventListener("resize",e),window.addEventListener("orientationchange",e),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("scroll",e),window.removeEventListener("resize",e),window.removeEventListener("orientationchange",e)}}),[g]);const B=t(((e,t)=>{null==d||d();const n=X.current,o=Y.current;if(!n||!o||i)return;e&&t.stopPropagation();const r=window.innerHeight||document.documentElement.clientHeight,{width:l,height:c,top:u,bottom:a,left:w,right:p}=n.getBoundingClientRect(),{width:h}=o.getBoundingClientRect();let b=C;b=u-186<0?"bottom-left"===b?"bottom-left":"bottom-center":a+186>r?"top-right"===s?"top-right":"top-left":s;let E=0,L=0;switch(b){case"bottom-left":E=w+window.scrollX,L=u+window.scrollY+c;break;case"bottom-center":E=Math.floor((w+p)/2+window.scrollX-h/2),L=u+window.scrollY+c;break;case"top-left":E=w+window.scrollX,L=u+window.scrollY;break;case"top-right":E=w+window.scrollX+l,L=u+window.scrollY}f(E),v(L),y(l),k(b),m(!!e||!g)}),[i,g,C,s,d]),x=t((()=>{m(!1),null==u||u()}),[]);return{x:p,y:h,width:b,isOpen:g,triggerRef:X,selectModalRef:Y,placement:C,isKeyboardOpen:A,value:R,disabled:i,multiple:l,contentHeight:E,handleInputClick:B,handleClose:x,setValue:e=>{z===H?z(e):(z(e),H(e))}}};export{r as useSelectField};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bothub-chat/ui",
3
- "version": "2.41.1",
3
+ "version": "2.41.2",
4
4
  "description": "Bothub UI Components",
5
5
  "keywords": [
6
6
  "bot",