@plainsheet/react 0.2.1 → 0.3.0
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/README.md +1 -1
- package/dist/BottomSheet.d.ts +19 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/useBottomSheet.d.ts +22 -0
- package/dist/index.d.ts +2 -1
- package/dist/plainsheet-react.cjs.js +1 -0
- package/dist/{plainsheet-core.es.js → plainsheet-react.es.js} +505 -478
- package/dist/plainsheet-react.umd.js +1 -0
- package/package.json +7 -7
- package/dist/ReactPlainBottomSheet.d.ts +0 -19
- package/dist/plainsheet-core.cjs.js +0 -1
- package/dist/plainsheet-core.umd.js +0 -1
package/README.md
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { OmitKeyof } from '@plainsheet/utility';
|
|
2
|
+
import { BottomSheetCore, BottomSheetCoreProps } from '@plainsheet/core';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
export { createPlaceholderBottomSheet } from '@plainsheet/core';
|
|
6
|
+
export type { BottomSheetCore } from '@plainsheet/core';
|
|
7
|
+
export type BottomSheetProps = {
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
isOpen: boolean;
|
|
10
|
+
setIsOpen: (isOpen: boolean) => void;
|
|
11
|
+
mountingPoint?: Element | null;
|
|
12
|
+
} & CoreProps;
|
|
13
|
+
type CoreProps = OmitKeyof<BottomSheetCoreProps, "content">;
|
|
14
|
+
export declare const BottomSheet: import('react').ForwardRefExoticComponent<{
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
isOpen: boolean;
|
|
17
|
+
setIsOpen: (isOpen: boolean) => void;
|
|
18
|
+
mountingPoint?: Element | null;
|
|
19
|
+
} & CoreProps & import('react').RefAttributes<BottomSheetCore>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useBottomSheet';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BottomSheetCore } from '@plainsheet/core';
|
|
2
|
+
|
|
3
|
+
interface UseBottomSheetReturn {
|
|
4
|
+
/**
|
|
5
|
+
* Props to be passed to the `BottomSheet`.
|
|
6
|
+
*/
|
|
7
|
+
props: HookProvidedProps;
|
|
8
|
+
/**
|
|
9
|
+
* `BottomSheetCore` instance to control the bottom sheet.
|
|
10
|
+
*/
|
|
11
|
+
instance: BottomSheetCore;
|
|
12
|
+
}
|
|
13
|
+
interface HookProvidedProps {
|
|
14
|
+
/**
|
|
15
|
+
* `ref` of the BottomSheet component. Pass it to the component to use `instance`.
|
|
16
|
+
*/
|
|
17
|
+
ref: React.MutableRefObject<BottomSheetCore>;
|
|
18
|
+
isOpen: boolean;
|
|
19
|
+
setIsOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
20
|
+
}
|
|
21
|
+
export declare function useBottomSheet(): UseBottomSheetReturn;
|
|
22
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './BottomSheet';
|
|
2
|
+
export * from './hooks';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("react"),At=require("react-dom");function Lt(t){return t!=null}(function(){try{if(typeof document<"u"){var t=document.createElement("style");t.appendChild(document.createTextNode('.pbs-root{position:fixed;left:0;bottom:0;display:flex;flex-direction:column;align-items:center;justify-content:flex-start;width:100%;height:fit-content;max-height:100vh;z-index:2}.pbs-dialog-reset{background-color:transparent;color:inherit;border:none;outline:none;padding:0;margin:0}.pbs-backdrop{position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;background-color:transparent;z-index:1;transition:background-color .2s ease-out}.pbs-backdrop.hidden{display:none}.pbs-backdrop.open{background-color:#454545b3}.pbs-container{--pbs-container-background-color: rgb(240, 240, 240);background-color:var(--pbs-container-background-color);position:relative;display:none;flex-direction:column;align-items:center;justify-content:flex-start;width:92%;height:fit-content;max-height:100vh;border-radius:10px 10px 0 0}.pbs-container.open{display:flex}.pbs-container .pbs-gap-filler{position:absolute;bottom:calc(-100vh + .5px);left:0;background-color:var(--pbs-container-background-color);content:"";width:100%;height:100vh}.pbs-handle{position:relative;display:flex;align-items:center;justify-content:center;width:100%;height:30px;cursor:pointer}.pbs-handle.hidden{display:none}.pbs-button-reset{background-color:transparent;-webkit-appearance:none;-moz-appearance:none;appearance:none;outline:none;border:none}button:focus.pbs-button-reset{outline:none}.pbs-handle-bar{background-color:#a8a8a8;position:relative;width:12%;height:7px;border-radius:12px}.pbs-handle-bar.hidden{display:none}.pbs-content-wrapper{position:relative;width:100%;height:fit-content;max-height:100%;overflow-y:scroll}.pbs-content-wrapper::-webkit-scrollbar{display:none}.example{-ms-overflow-style:none;scrollbar-width:none}')),document.head.appendChild(t)}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})();var Ot=Object.defineProperty,Dt=(t,e,n)=>e in t?Ot(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,$=(t,e,n)=>Dt(t,typeof e!="symbol"?e+"":e,n);function T(t){return typeof t=="string"}function Pt(t,e){return t.classList.contains(Q(e))}function q(t,e){t.classList.add(Q(e))}function nt(t,e){t.classList.remove(Q(e))}function j(t,e,n){T(n)&&(T(e)&&nt(t,e),q(t,n))}function Q(t){return T(t)?t.trim().replace(/\./g,""):""}function R(t){return t.map(e=>Q(e)).filter(Boolean).join(" ")}function Bt(t){return t.map(e=>e==null?void 0:e.trim()).filter(Boolean).map(e=>`.${e}`).join(" ")}const lt="open",dt="hidden";function et(t,e){const n=e;if(Array.isArray(t)){t.forEach(o=>{z(o,n),o.setAttribute("aria-modal",n?"true":"false")});return}z(t,n),t.setAttribute("aria-modal",n?"true":"false")}function z(t,e){e?(q(t,lt),nt(t,dt)):(q(t,dt),nt(t,lt))}function St(t){return t instanceof HTMLElement}function A(t){return typeof t=="number"&&!Number.isNaN(t)}function Mt(t){St(t)&&t.focus()}function Yt(t){if(!St(t)||t.offsetParent===null||"disabled"in t&&t.disabled)return!1;const e=t.getAttribute("tabindex"),n=A(e)?parseInt(e,10):-1,o=["INPUT","BUTTON","SELECT","TEXTAREA","A","AREA","IFRAME"].includes(t.tagName),i=t instanceof HTMLAnchorElement&&t.href!==""||t instanceof HTMLAreaElement&&t.href!=="";return o||i||n>-1}var w=(t=>(t.Backdrop="pbs-backdrop",t.Root="pbs-root",t.Container="pbs-container",t.GapFiller="pbs-gap-filler",t.Handle="pbs-handle",t.HandleBar="pbs-handle-bar",t.ContentWrapper="pbs-content-wrapper",t))(w||{}),ot=(t=>(t.Button="pbs-button-reset",t.Dialog="pbs-dialog-reset",t))(ot||{}),X=(t=>(t.Hidden="hidden",t))(X||{});function M(t,e,n){const o=document.createElement(t);return e.split(" ").forEach(i=>{q(o,i)}),T(n)&&o.setAttribute("data-testid",n),o}Bt([w.Root,w.ContentWrapper]);function pt(t,e,n,o){switch(o){case"content-height":return e>=t?yt(t,e,n):0;case"middle":return-(t/2-e);case"top":return-(t-e)+n;default:return 0}}function Ct(t,e){const n=e<t,o=e>t;return{isUp:n,isDown:o,stayedSame:e===t}}function wt(t,e){return e<t?-(t-e):e-t}function V(t,e){return t>e?t-e:e-t}function It(t,e){const n=t<e,o=t>e;return{isUp:n,isDown:o,stayedSame:t===e}}function ht(t,e,n){const o=t==="above";return n.filter(i=>{const r=i*e.viewportHeight;return o?e.visibleHeight<r:e.visibleHeight>r})}function yt(t,e,n){return-(t-e)+n}function mt(t){return Number(t.replace("px",""))}function K(t,...e){return Number(t.toFixed(...e))}function Et(t){const e=/(?<type>\w+)\((?<values>[^)]+)\)/g,n=[];let o;for(;(o=e.exec(t))!==null;){const i=o[1],r=o[2].split(",").map(c=>c.trim());n.push({type:i,values:r})}return n}function Rt(t){const e=t.style.transform,n=Et(e);return{transform:e,transformValues:n}}function Ht(t,e){return t.find(o=>o.type.startsWith(e))||null}const rt="translate";function P(t){const e=t.style.transform,n=Et(e),o=Ht(n,rt);return Tt(o??{type:rt,values:[]})}function J(t,{x:e,y:n}){const{transform:o,transformValues:i}=Rt(t),r=Ht(i,rt);if(r){const c=Tt(r);t.style.transform=`translate(${e??c.x??0}px,${n??c.y??0}px)`;return}if(o){t.style.transform=`${o}, translate(${e??0}px,${n??0}px)`;return}t.style.transform=`translate(${e??0}px,${n??0}px)`}function Tt(t){if(t.type!=="translate")throw new Error(`Could not get coordinates from ${t.type}, since is not translate.`);const e=t.values[0],n=t.values[1];return{x:mt(e)??0,y:mt(n)??0}}function it(t){return t!=null}function ft(t,{min:e,max:n}){return it(n)&&t>=n?n:it(e)&&t<=e?e:t}const Nt=(t,e,n)=>{e instanceof HTMLElement&&!Pt(e,w.Handle)&&n.scrollTop>=1||(t.isDragging=!0)},Ft=(t,e,n,o)=>i=>{o.startY=t.getCoordinates(i).y,o.containerStartTranslate=P(e),n.onDragStart()},Wt=(t,e,n,o,i)=>r=>{Ut(r,t,n,o,i,e,n.marginTop)};function Ut(t,e,n,o,i,r,c){if(!o.isDragging||!A(o.startY))return;const s=e.getCoordinates(t).y,p=wt(o.startY,s),f=window.innerHeight,u=r.clientHeight,b=u-(o.containerStartTranslate.y+p);if(b>=f)return;const E=Ct(o.startY,s);if(E.isUp&&!n.expandable&&b>=u)return;i.start(()=>{J(r,{y:o.containerStartTranslate.y+p})},0);const a=f-c,x=u-o.containerStartTranslate.y;if(E.isUp){const v=a-x,S=a-b,H=ft(1-K(S/v,2),{min:0,max:1});n.onDragMove(E,H)}else if(E.isDown){const v=ft(K(1-b/x,2),{min:0,max:1});n.onDragMove(E,v)}}const jt=(t,e,n,o,i,r,c)=>s=>{if(!o.isDragging||(o.isDragging=!1,!A(o.startY)))return;n.onDragEnd();const p=o.startY,f=t.getCoordinates(s).y,u=P(e).y,b=Ct(p,f),E=window.innerHeight,a=e.clientHeight;if(b.isUp){const x=[...n.snapPoints].sort((H,C)=>H-C),v=a+-u;if(!n.expandable&&v>=a)return;for(const H of x){const C=H*window.innerHeight;if(v<=C){const B=V(v,C);c.translateContainer({startY:u,endY:u-B,animationFrame:i,bottomSheetContainer:e});return}}const S=yt(E,a,n.marginTop);c.translateContainer({startY:u,endY:S,animationFrame:i,bottomSheetContainer:e})}else if(b.isDown){const x=[...n.snapPoints].sort((v,S)=>S-v);for(const v of x){const S=v*window.innerHeight,H=a+-u;if(H>=S){const C=V(H,S);c.translateContainer({startY:u,endY:u+C,animationFrame:i,bottomSheetContainer:e});return}}r()}};var W=(t=>(t[t.All=-1]="All",t[t.None=0]="None",t[t.Capture=1]="Capture",t[t.Target=2]="Target",t[t.Bubble=3]="Bubble",t))(W||{});function gt(t){switch(t){case 0:return 0;case 1:return 1;case 2:return 2;case 3:return 3;default:return-1}}const Gt={eventPhase:W.All};class G{constructor(e){$(this,"currentTarget"),this.currentTarget=e}addEventListeners({onStart:e,onStartOptions:n=Gt,onMove:o,onEnd:i}){this.addTouchEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:i}),this.addMouseEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:i})}addTouchEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:i}){e&&this.currentTarget.addEventListener("touchstart",r=>{if(n.eventPhase===W.All){e(r);return}gt(r.eventPhase)===n.eventPhase&&e(r)},{passive:!0}),o&&this.currentTarget.addEventListener("touchmove",o),i&&this.currentTarget.addEventListener("touchend",i)}addMouseEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:i}){e&&this.currentTarget.addEventListener("mousedown",r=>{if(n.eventPhase===W.All){e(r);return}gt(r.eventPhase)===n.eventPhase&&e(r)},{passive:!0}),o&&this.currentTarget.addEventListener("mousemove",o),i&&this.currentTarget.addEventListener("mouseup",r=>{i(r)})}removeEventListeners({onStart:e,onMove:n,onEnd:o}){e&&this.currentTarget.removeEventListener("touchstart",e),o&&this.currentTarget.removeEventListener("touchend",o),n&&this.currentTarget.removeEventListener("touchmove",n),e&&this.currentTarget.removeEventListener("mousedown",e),n&&this.currentTarget.removeEventListener("mousemove",n),o&&this.currentTarget.removeEventListener("mouseup",o)}getCoordinates(e){if(e.type==="touchstart"||e.type==="mousedown"){if("touches"in e)return{x:e.touches[0].clientX,y:e.touches[0].clientY};if(e instanceof MouseEvent)return{x:e.clientX,y:e.clientY}}if(e.type==="touchend"||e.type==="mouseup"||e.type==="mousemove"||e.type==="touchmove"){if("touches"in e)return{x:e.changedTouches[0].clientX,y:e.changedTouches[0].clientY};if(e instanceof MouseEvent)return{x:e.clientX,y:e.clientY}}return{x:0,y:0}}}function _t(t,e){const n=$t(t);Xt(n),n.bottomSheetContainer.style.width=t.width;const o=document.createElement("div");o.innerHTML=t.content??"";const i=window.innerHeight;n.bottomSheetContainer.style.maxHeight=`${i}px`,n.bottomSheetContentWrapper.appendChild(o);const r=qt({bottomSheetElements:n,bottomSheetProps:t,options:e});return{elements:n,eventHandlers:r}}function $t(t){const e=M("dialog",R([w.Root,ot.Dialog,t.rootClass]),w.Root);e.ariaLabel=t.ariaLabel;const n=M("section",R([w.Container,t.containerClass]),w.Container);t.containerBorderRadius&&(n.style.borderRadius=t.containerBorderRadius);const o=M("div",w.GapFiller,w.GapFiller),i=M("button",R([w.Handle,ot.Button,t.shouldShowHandle?null:X.Hidden,t.handleClass]),w.Handle);i.setAttribute("type","button"),i.ariaLabel="bottom sheet close button";const r=M("span",R([w.HandleBar,t.shouldShowHandle?null:X.Hidden]),w.HandleBar),c=M("article",R([w.ContentWrapper,t.contentWrapperClass]),w.ContentWrapper),s=M("div",R([w.Backdrop,t.backdropClass,X.Hidden]),w.Backdrop);return t.backdropColor&&(s.style.backgroundColor=t.backdropColor),t.backDropTransition&&(s.style.transition=t.backDropTransition),{bottomSheetRoot:e,bottomSheetBackdrop:s,bottomSheetContainer:n,bottomSheetHandle:i,bottomSheetHandleBar:r,bottomSheetContentWrapper:c,bottomSheetContainerGapFiller:o}}function Xt({bottomSheetRoot:t,bottomSheetContainer:e,bottomSheetHandle:n,bottomSheetHandleBar:o,bottomSheetContentWrapper:i,bottomSheetContainerGapFiller:r}){t.appendChild(e),n.appendChild(o),e.appendChild(n),e.appendChild(i),e.appendChild(r)}function qt({bottomSheetElements:t,bottomSheetProps:e,options:n}){const{bottomSheetRoot:o,bottomSheetContainer:i,bottomSheetHandle:r,bottomSheetContainerGapFiller:c,bottomSheetContentWrapper:s}=t,{animationFrame:p}=n,f=new G(r),u=new G(s),b=new G(c),E=e.dragTriggers.reduce((g,L)=>{const O=o.querySelectorAll(L);if(!O.length)return g;const tt=Array.from(O).map(Y=>Y instanceof HTMLElement?new G(Y):null).filter(Y=>!!Y);return[...g,...tt]},[]),a=new G(window),x=Ft(a,i,e,n.draggingState),v=Wt(a,i,e,n.draggingState,p),S=jt(a,i,e,n.draggingState,p,n.onClose,n.bottomSheetState);function H(g){g.target instanceof Element&&!o.contains(g.target)&&n.onClose()}function C(g){Nt(n.draggingState,g.target,t.bottomSheetContentWrapper)}function B(){e.draggable&&(f.addEventListeners({onStart:C}),E.forEach(g=>{g.addEventListeners({onStart:C,onStartOptions:{eventPhase:W.Target}})})),e.draggable&&e.backgroundDraggable&&(u.addEventListeners({onStart:C,onStartOptions:{eventPhase:W.Target}}),b.addEventListeners({onStart:C})),e.draggable&&a.addEventListeners({onStart:x,onMove:v,onEnd:S}),e.draggable&&window.document.addEventListener("keyup",g=>{g.key==="Escape"&&n.onClose()}),e.shouldCloseOnOutsideClick&&window.document.addEventListener("click",H),r.addEventListener("keyup",g=>{if(g.key==="ArrowUp"){n.moveUp();return}if(g.key==="ArrowDown"){n.moveDown();return}if(g.shiftKey&&g.key==="Tab"){const L=_(t.bottomSheetContentWrapper);Mt(L)}})}function _(g){let L=[...Array.from(g.childNodes).reverse()];for(;L.length;){const O=L.shift();if(Yt(O))return O;O&&(L=[...L,...Array.from(O.childNodes).reverse()])}return null}function Z(){f.removeEventListeners({onStart:C}),u.removeEventListeners({onStart:C}),b.removeEventListeners({onStart:C}),E.forEach(g=>{g.removeEventListeners({onStart:C})}),a.removeEventListeners({onStart:x,onMove:v,onEnd:S}),window.removeEventListener("click",H)}return{attachEventListeners:B,clearEventListeners:Z}}class zt{constructor(){$(this,"animationId"),$(this,"isInProgress"),$(this,"startedAt"),this.animationId=null,this.isInProgress=!1,this.startedAt=null}start(e,n,o=!1){this.isInProgress=!0;const i=r=>{this.startedAt||(this.startedAt=r);const c=r-this.startedAt,s=n===0?1:K(c/n,2),p=s>=1&&!o;e(s),p?this.stop():this.animationId=requestAnimationFrame(i)};this.animationId=requestAnimationFrame(i)}stop(){this.isInProgress=!1,this.startedAt=null,A(this.animationId)&&cancelAnimationFrame(this.animationId)}}function Vt(t){const{startY:e,endY:n,bottomSheetContainer:o,animationFrame:i,onEnd:r,animationTimingFunction:c,animationDuration:s}=t,p=wt(e,n);i.stop();let f=!1;i.start(u=>{J(o,{y:e+p*c(u)}),!f&&u>=1&&(r==null||r(),f=!0)},s)}const at=(t,e)=>n=>{Vt({...n,animationTimingFunction:t,animationDuration:e})},F={TOP:"top",MIDDLE:"middle",CONTENT_HEIGHT:"content-height",CLOSED:"closed"};function Kt(t){return!(!A(t)||t>1||t<0)}function Jt(t,e){const n={set(o,i,r,c){return e(i,r),Reflect.set(o,i,r,c)}};return new Proxy(t,n)}function Qt(...t){console.error(t)}const N={EASE:"ease",EASE_IN:"ease-in",EASE_OUT:"ease-out",EASE_IN_OUT:"ease-in-out",SPRING:"spring"};function Zt(t){for(const e of Object.values(N))if(e===t)return!0;return!1}function kt(t){return!!(t instanceof Object&&"p1x"in t&&"p1y"in t&&"p2x"in t&&"p2y"in t&&A(t.p1x)&&A(t.p1y)&&A(t.p2x)&&A(t.p2y))}function U(t,e,n,o){return function(s){return c(i(s))};function i(s){let p=0,f=1,u=s,b;if(s===0||s===1)return s;for(;p<f;){if(b=r(u),Math.abs(b-s)<.001)return u;s>b?p=u:f=u,u=(f+p)/2}return u}function r(s){return 3*t*s*Math.pow(1-s,2)+3*n*Math.pow(s,2)*(1-s)+Math.pow(s,3)}function c(s){return 3*e*s*Math.pow(1-s,2)+3*o*Math.pow(s,2)*(1-s)+Math.pow(s,3)}}const te=U(.25,.1,.25,1),ee=U(.42,0,1,1),xt=U(.42,0,.58,1),bt=U(.4,.1,.6,1),ne=U(.45,1.5,.55,1);function oe(t){switch(t){case N.EASE:return te;case N.EASE_IN:return ee;case N.EASE_OUT:return xt;case N.EASE_IN_OUT:return bt;case N.SPRING:return ne;default:return bt}}function vt(t){return typeof t=="boolean"}const re={ariaLabel:"Bottom sheet",content:"",defaultPosition:F.CONTENT_HEIGHT,marginTop:20,snapPoints:[],width:"92%",dragTriggers:[],beforeOpen:()=>{},afterOpen:()=>{},beforeClose:()=>{},afterClose:()=>{},onDragStart:()=>{},onDragMove:()=>{},onDragEnd:()=>{},expandable:!0,draggable:!0,backgroundDraggable:!0,shouldCloseOnOutsideClick:!0,shouldShowBackdrop:!0,shouldShowHandle:!0,backDropTransition:null,backdropColor:null,containerBorderRadius:null,rootClass:null,containerClass:null,handleClass:null,contentWrapperClass:null,backdropClass:null,draggingAnimationTimings:"ease-in-out",draggingAnimationDuration:180};function ie(t){const e={...re},n=Object.entries(t).reduce((o,i)=>{const[r,c]=i;return it(c)&&(o[r]=c),o},{});return{...e,...n}}function st(t){if(kt(t)){const{p1x:e,p1y:n,p2x:o,p2y:i}=t;return U(e,n,o,i)}return Zt(t)?oe(t):xt}function ae(t,e,n){function o(i,r){switch(i){case"content":T(r)&&(t.bottomSheetContentWrapper.innerHTML=r);break;case"width":T(r)&&(t.bottomSheetContainer.style.width=r);break;case"shouldShowHandle":vt(r)||z(t.bottomSheetHandle,!1);break;case"shouldShowBackdrop":vt(r)||z(t.bottomSheetBackdrop,!1);break;case"containerBorderRadius":T(r)&&(t.bottomSheetContainer.style.borderRadius=r);break;case"backdropColor":T(r)&&(t.bottomSheetBackdrop.style.backgroundColor=r);break;case"backDropTransition":T(r)&&(t.bottomSheetBackdrop.style.transition=r);break;case"rootClass":if(!T(r))return;j(t.bottomSheetRoot,n.rootClass,r);break;case"containerClass":if(!T(r))return;j(t.bottomSheetContainer,n.containerClass,r);break;case"handleClass":if(!T(r))return;j(t.bottomSheetHandle,n.handleClass,r);break;case"contentWrapperClass":if(!T(r))return;j(t.bottomSheetContentWrapper,n.contentWrapperClass,r);break;case"backdropClass":if(!T(r))return;j(t.bottomSheetBackdrop,n.backdropClass,r);break;case"draggingAnimationTimings":if(kt(r)){const c=st(r),s=at(c,n.draggingAnimationDuration);e.translateContainer=s}break;case"draggingAnimationDuration":if(A(r)){const c=st(n.draggingAnimationTimings),s=at(c,r);e.translateContainer=s}break}}return o}function se(t){const e=ie(t),n=st(t.draggingAnimationTimings),o={isMounted:!1,translateContainer:at(n,e.draggingAnimationDuration)},i={startY:null,containerStartTranslate:{x:0,y:0},isDragging:!1,originalDocumentOverflowY:null};function r(){i.originalDocumentOverflowY&&i.originalDocumentOverflowY!=="hidden"&&(document.body.style.overflowY=i.originalDocumentOverflowY)}const c=new zt,s={animationFrame:c,onClose:H,bottomSheetState:o,draggingState:i,snapTo:ut,moveUp:tt,moveDown:Y},{elements:p,eventHandlers:f}=_t(e,s),u=Jt(e,ae(p,o,e)),{bottomSheetBackdrop:b,bottomSheetRoot:E,bottomSheetContainer:a}=p,x=l=>{const d=l??window.document.body;d.appendChild(E),d.appendChild(b);const h=window.innerHeight;J(a,{y:h}),f.attachEventListeners(),o.isMounted=!0},v=()=>{f.clearEventListeners(),Object.values(p).forEach(l=>{l.remove()}),r(),o.isMounted=!1},S=()=>{var l;if(C()||Qt('Bottom Sheet is not mounted yet. call the "mount" method first.'),(l=t.beforeOpen)==null||l.call(t),B())return;u.shouldShowBackdrop&&et(b,!0),et([a],!0),J(a,{y:a.clientHeight});const d=window.innerHeight,h=pt(d,a.clientHeight,u.marginTop,u.defaultPosition),m=P(a).y;o.translateContainer({startY:m,endY:h,animationFrame:c,bottomSheetContainer:a,onEnd:t.afterOpen}),p.bottomSheetHandle.focus();const y=document.body.style.overflowY;i.originalDocumentOverflowY=y||"initial",document.body.style.overflowY="hidden"};function H(){var l;if(_())return;(l=t.beforeClose)==null||l.call(t);const d=P(a).y,h=a.clientHeight;o.translateContainer({startY:d,endY:h,animationFrame:c,bottomSheetContainer:a,onEnd:()=>{var m;(m=t.afterClose)==null||m.call(t),et([b,a],!1)}}),r()}function C(){return o.isMounted}function B(){const l=P(a).y,d=window.innerHeight,h=a.clientHeight>=d?d:a.clientHeight;return l<h}function _(){return!B()}function Z(){const l=P(a).y,d=a.clientHeight,h=window.innerHeight;if(l<=5&&l>=-5)return F.CONTENT_HEIGHT;const m=d-l;if(m===h/2)return F.MIDDLE;const y=h-u.marginTop,D=10;return m<=y+D&&m>=y-D?F.TOP:F.CLOSED}function g(){return a.clientHeight}function L(l){if(!B())return;const d=P(a).y,h=a.clientHeight-d,m=window.innerHeight-l,y=It(h,m),D=V(h,m);o.translateContainer({startY:d,endY:d+(y.isUp?-D:D),animationFrame:c,bottomSheetContainer:a})}function O(l,{viewportHeight:d,visibleHeight:h}){let m=null;for(const y of l){const D=y*d,I=V(h,D);(m===null||I<m)&&(m=I)}return{minOffset:m}}function tt(){const l=[...u.snapPoints].reverse(),d=P(a).y,h=a.clientHeight,m=h-d;if(!u.expandable&&m>=h)return;const y=window.innerHeight,D=ht("above",{visibleHeight:m,viewportHeight:y},l),{minOffset:I}=O(D,{visibleHeight:m,viewportHeight:y});if(I===null&&m<y-u.marginTop){o.translateContainer({startY:d,endY:pt(y,h,u.marginTop,"top"),animationFrame:c,bottomSheetContainer:a});return}A(I)&&o.translateContainer({startY:d,endY:d-I,animationFrame:c,bottomSheetContainer:a})}function Y(){const l=P(a).y,d=a.clientHeight-l;if(d<1)return;const h=window.innerHeight,m=ht("below",{visibleHeight:d,viewportHeight:h},u.snapPoints),{minOffset:y}=O(m,{visibleHeight:d,viewportHeight:h});A(y)&&o.translateContainer({startY:l,endY:l+y,animationFrame:c,bottomSheetContainer:a})}function ut(l){const d=window.innerHeight;if(!Kt(l))return;const h=K(d*l,2);L(h)}return{props:u,elements:p,mount:x,unmount:v,open:S,close:H,getIsMounted:C,getIsOpen:B,getIsClosed:_,getPosition:Z,getHeight:g,moveTo:L,snapTo:ut}}function ct(){return{elements:{bottomSheetRoot:void 0,bottomSheetBackdrop:void 0,bottomSheetContainer:void 0,bottomSheetHandle:void 0,bottomSheetHandleBar:void 0,bottomSheetContentWrapper:void 0,bottomSheetContainerGapFiller:void 0},mount:()=>{},unmount:()=>{},open:()=>{},close:()=>{},getIsMounted:()=>!1,getHeight:()=>0,getIsOpen:()=>!1,getIsClosed:()=>!0,getPosition:()=>F.CLOSED,moveTo:()=>{},snapTo:()=>{},props:{content:""}}}const ce=ct(),ue=k.forwardRef(function(e,n){const{children:o,isOpen:i,setIsOpen:r,afterClose:c,mountingPoint:s,...p}=e,f=k.useRef(ce),[u,b]=k.useState(f.current);k.useImperativeHandle(n,()=>u,[u]);const E=k.useCallback(()=>{r(!1),c==null||c()},[c]);k.useEffect(()=>{i?u.open():u.close()},[i]);const a=k.useRef(null);return k.useEffect(function(){const v=Lt(e.mountingPoint)?e.mountingPoint:window.document.body;if(!v||u.getIsMounted())return;const S=se({content:"",...p,afterClose:E});return S.mount(v),a.current=S.elements.bottomSheetContentWrapper??null,f.current=S,b(S),()=>{u.unmount()}},[e.mountingPoint,p,E]),k.useEffect(function(){Object.assign(f.current.props,{...p}),b(f.current)},[p]),a.current?At.createPortal(e.children,a.current):null}),le=ct();function de(){const t=k.useRef(le),[e,n]=k.useState(!1),[o,i]=k.useState(t.current);return k.useEffect(()=>{i(t.current)},[t.current]),{props:k.useMemo(()=>({ref:t,isOpen:e,setIsOpen:n}),[e]),instance:o}}exports.BottomSheet=ue;exports.createPlaceholderBottomSheet=ct;exports.useBottomSheet=de;
|