@plainsheet/react 0.2.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/LICENSE +22 -0
- package/README.md +70 -0
- package/dist/ReactPlainBottomSheet.d.ts +19 -0
- package/dist/index.d.ts +1 -0
- package/dist/plainsheet-core.cjs.js +1 -0
- package/dist/plainsheet-core.es.js +1217 -0
- package/dist/plainsheet-core.umd.js +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(O,k){typeof exports=="object"&&typeof module<"u"?k(exports,require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","react-dom"],k):(O=typeof globalThis<"u"?globalThis:O||self,k(O.ReactPlainBottomSheet={},O.React,O.ReactDOM))})(this,function(O,k,xt){"use strict";function At(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,Pt=(t,e,n)=>e in t?Ot(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,$=(t,e,n)=>(Pt(t,typeof e!="symbol"?e+"":e,n),n);function E(t){return typeof t=="string"}function Dt(t,e){return t.classList.contains(X(e))}function q(t,e){t.classList.add(X(e))}function J(t,e){t.classList.remove(X(e))}function G(t,e,n){E(n)&&(E(e)&&J(t,e),q(t,n))}function X(t){return E(t)?t.trim().replace(/\./g,""):""}function I(t){return t.map(e=>X(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",ut="hidden";function tt(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),J(t,ut)):(q(t,ut),J(t,lt))}function dt(t){return t instanceof HTMLElement}function x(t){return typeof t=="number"&&!Number.isNaN(t)}function Mt(t){dt(t)&&t.focus()}function Yt(t){if(!dt(t)||t.offsetParent===null||"disabled"in t&&t.disabled)return!1;const e=t.getAttribute("tabindex"),n=x(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||{}),et=(t=>(t.Button="pbs-button-reset",t.Dialog="pbs-dialog-reset",t))(et||{}),V=(t=>(t.Hidden="hidden",t))(V||{});function M(t,e,n){const o=document.createElement(t);return e.split(" ").forEach(i=>{q(o,i)}),E(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?gt(t,e,n):0;case"middle":return-(t/2-e);case"top":return-(t-e)+n;default:return 0}}function ht(t,e){const n=e<t,o=e>t;return{isUp:n,isDown:o,stayedSame:e===t}}function mt(t,e){return e<t?-(t-e):e-t}function K(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 ft(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 gt(t,e,n){return-(t-e)+n}function bt(t){return Number(t.replace("px",""))}function Q(t,...e){return Number(t.toFixed(...e))}function vt(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=vt(e);return{transform:e,transformValues:n}}function St(t,e){return t.find(o=>o.type.startsWith(e))||null}const nt="translate";function P(t){const e=t.style.transform,n=vt(e),o=St(n,nt);return Ct(o??{type:nt,values:[]})}function Z(t,{x:e,y:n}){const{transform:o,transformValues:i}=Rt(t),r=St(i,nt);if(r){const c=Ct(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 Ct(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:bt(e)??0,y:bt(n)??0}}function ot(t){return t!=null}function yt(t,{min:e,max:n}){return ot(n)&&t>=n?n:ot(e)&&t<=e?e:t}const Nt=(t,e,n)=>{e instanceof HTMLElement&&!Dt(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),o.originalDocumentOverflowY=document.body.style.overflowY,document.body.style.overflowY="hidden",n.onDragStart()},Wt=(t,e,n,o,i)=>r=>{jt(r,t,n,o,i,e,n.marginTop)};function jt(t,e,n,o,i,r,c){if(!o.isDragging||!x(o.startY))return;const a=e.getCoordinates(t).y,m=mt(o.startY,a),u=window.innerHeight,l=r.clientHeight,b=l-(o.containerStartTranslate.y+m);if(b>=u)return;const s=ht(o.startY,a);if(s.isUp&&!n.expandable&&b>=l)return;i.start(()=>{Z(r,{y:o.containerStartTranslate.y+m})},0);const v=u-c,L=l-o.containerStartTranslate.y;if(s.isUp){const S=v-L,C=v-b,T=yt(1-Q(C/S,2),{min:0,max:1});n.onDragMove(s,T)}else if(s.isDown){const S=yt(Q(1-b/L,2),{min:0,max:1});n.onDragMove(s,S)}}const Ut=(t,e,n,o,i,r,c)=>a=>{if(!o.isDragging||(o.isDragging=!1,document.body.style.overflowY=o.originalDocumentOverflowY,!x(o.startY)))return;n.onDragEnd();const m=o.startY,u=t.getCoordinates(a).y,l=P(e).y,b=ht(m,u),s=window.innerHeight,v=e.clientHeight;if(b.isUp){const L=[...n.snapPoints].sort((T,y)=>T-y),S=v+-l;if(!n.expandable&&S>=v)return;for(const T of L){const y=T*window.innerHeight;if(S<=y){const j=K(S,y);c.translateContainer({startY:l,endY:l-j,animationFrame:i,bottomSheetContainer:e});return}}const C=gt(s,v,n.marginTop);c.translateContainer({startY:l,endY:C,animationFrame:i,bottomSheetContainer:e})}else if(b.isDown){const L=[...n.snapPoints].sort((S,C)=>C-S);for(const S of L){const C=S*window.innerHeight,T=v+-l;if(T>=C){const y=K(T,C);c.translateContainer({startY:l,endY:l+y,animationFrame:i,bottomSheetContainer:e});return}}r()}};var R=(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))(R||{});function wt(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:R.All};class _{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===R.All){e(r);return}wt(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===R.All){e(r);return}wt(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);qt(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=Xt({bottomSheetElements:n,bottomSheetProps:t,options:e});return{elements:n,eventHandlers:r}}function $t(t){const e=M("dialog",I([w.Root,et.Dialog,t.rootClass]),w.Root);e.ariaLabel=t.ariaLabel;const n=M("section",I([w.Container,t.containerClass]),w.Container);t.containerBorderRadius&&(n.style.borderRadius=t.containerBorderRadius);const o=M("div",w.GapFiller,w.GapFiller),i=M("button",I([w.Handle,et.Button,t.shouldShowHandle?null:V.Hidden,t.handleClass]),w.Handle);i.setAttribute("type","button"),i.ariaLabel="bottom sheet close button";const r=M("span",I([w.HandleBar,t.shouldShowHandle?null:V.Hidden]),w.HandleBar),c=M("article",I([w.ContentWrapper,t.contentWrapperClass]),w.ContentWrapper),a=M("div",I([w.Backdrop,t.backdropClass,V.Hidden]),w.Backdrop);return t.backdropColor&&(a.style.backgroundColor=t.backdropColor),t.backDropTransition&&(a.style.transition=t.backDropTransition),{bottomSheetRoot:e,bottomSheetBackdrop:a,bottomSheetContainer:n,bottomSheetHandle:i,bottomSheetHandleBar:r,bottomSheetContentWrapper:c,bottomSheetContainerGapFiller:o}}function qt({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 Xt({bottomSheetElements:t,bottomSheetProps:e,options:n}){const{bottomSheetRoot:o,bottomSheetContainer:i,bottomSheetHandle:r,bottomSheetContainerGapFiller:c,bottomSheetContentWrapper:a}=t,{animationFrame:m}=n,u=new _(r),l=new _(a),b=new _(c),s=e.dragTriggers.reduce((f,A)=>{const D=o.querySelectorAll(A);if(!D.length)return f;const ct=Array.from(D).map(Y=>Y instanceof HTMLElement?new _(Y):null).filter(Y=>!!Y);return[...f,...ct]},[]),v=new _(window),L=Ft(v,i,e,n.draggingState),S=Wt(v,i,e,n.draggingState,m),C=Ut(v,i,e,n.draggingState,m,n.onClose,n.bottomSheetState);function T(f){f.target instanceof Element&&!o.contains(f.target)&&n.onClose()}function y(f){Nt(n.draggingState,f.target,t.bottomSheetContentWrapper)}function j(){e.draggable&&(u.addEventListeners({onStart:y}),s.forEach(f=>{f.addEventListeners({onStart:y,onStartOptions:{eventPhase:R.Target}})})),e.draggable&&e.backgroundDraggable&&(l.addEventListeners({onStart:y,onStartOptions:{eventPhase:R.Target}}),b.addEventListeners({onStart:y})),e.draggable&&v.addEventListeners({onStart:L,onMove:S,onEnd:C}),e.draggable&&window.document.addEventListener("keyup",f=>{f.key==="Escape"&&n.onClose()}),e.shouldCloseOnOutsideClick&&window.document.addEventListener("click",T),r.addEventListener("keyup",f=>{if(f.key==="ArrowUp"){n.moveUp();return}if(f.key==="ArrowDown"){n.moveDown();return}if(f.shiftKey&&f.key==="Tab"){const A=at(t.bottomSheetContentWrapper);Mt(A)}})}function at(f){let A=[...Array.from(f.childNodes).reverse()];for(;A.length;){const D=A.shift();if(Yt(D))return D;D&&(A=[...A,...Array.from(D.childNodes).reverse()])}return null}function st(){u.removeEventListeners({onStart:y}),l.removeEventListeners({onStart:y}),b.removeEventListeners({onStart:y}),s.forEach(f=>{f.removeEventListeners({onStart:y})}),v.removeEventListeners({onStart:L,onMove:S,onEnd:C}),window.removeEventListener("click",T)}return{attachEventListeners:j,clearEventListeners:st}}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,a=n===0?1:Q(c/n,2),m=a>=1&&!o;e(a),m?this.stop():this.animationId=requestAnimationFrame(i)};this.animationId=requestAnimationFrame(i)}stop(){this.isInProgress=!1,this.startedAt=null,x(this.animationId)&&cancelAnimationFrame(this.animationId)}}function Vt(t){const{startY:e,endY:n,bottomSheetContainer:o,animationFrame:i,onEnd:r,animationTimingFunction:c,animationDuration:a}=t,m=mt(e,n);i.stop();let u=!1;i.start(l=>{Z(o,{y:e+m*c(l)}),!u&&l>=1&&(r==null||r(),u=!0)},a)}const rt=(t,e)=>n=>{Vt({...n,animationTimingFunction:t,animationDuration:e})},N={TOP:"top",MIDDLE:"middle",CONTENT_HEIGHT:"content-height",CLOSED:"closed"};function Kt(t){return!(!x(t)||t>1||t<0)}function Qt(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 Zt(...t){console.error(t)}const F={EASE:"ease",EASE_IN:"ease-in",EASE_OUT:"ease-out",EASE_IN_OUT:"ease-in-out",SPRING:"spring"};function Jt(t){for(const e of Object.values(F))if(e===t)return!0;return!1}function Et(t){return!!(t instanceof Object&&"p1x"in t&&"p1y"in t&&"p2x"in t&&"p2y"in t&&x(t.p1x)&&x(t.p1y)&&x(t.p2x)&&x(t.p2y))}function W(t,e,n,o){return function(a){return c(i(a))};function i(a){let m=0,u=1,l=a,b;if(a===0||a===1)return a;for(;m<u;){if(b=r(l),Math.abs(b-a)<.001)return l;a>b?m=l:u=l,l=(u+m)/2}return l}function r(a){return 3*t*a*Math.pow(1-a,2)+3*n*Math.pow(a,2)*(1-a)+Math.pow(a,3)}function c(a){return 3*e*a*Math.pow(1-a,2)+3*o*Math.pow(a,2)*(1-a)+Math.pow(a,3)}}const te=W(.25,.1,.25,1),ee=W(.42,0,1,1),Tt=W(.42,0,.58,1),Ht=W(.4,.1,.6,1),ne=W(.45,1.5,.55,1);function oe(t){switch(t){case F.EASE:return te;case F.EASE_IN:return ee;case F.EASE_OUT:return Tt;case F.EASE_IN_OUT:return Ht;case F.SPRING:return ne;default:return Ht}}function kt(t){return typeof t=="boolean"}const re={ariaLabel:"Bottom sheet",content:"",defaultPosition:N.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 ot(c)&&(o[r]=c),o},{});return{...e,...n}}function it(t){if(Et(t)){const{p1x:e,p1y:n,p2x:o,p2y:i}=t;return W(e,n,o,i)}return Jt(t)?oe(t):Tt}function ae(t,e,n){function o(i,r){switch(i){case"content":E(r)&&(t.bottomSheetContentWrapper.innerHTML=r);break;case"width":E(r)&&(t.bottomSheetContainer.style.width=r);break;case"shouldShowHandle":kt(r)||z(t.bottomSheetHandle,!1);break;case"shouldShowBackdrop":kt(r)||z(t.bottomSheetBackdrop,!1);break;case"containerBorderRadius":E(r)&&(t.bottomSheetContainer.style.borderRadius=r);break;case"backdropColor":E(r)&&(t.bottomSheetBackdrop.style.backgroundColor=r);break;case"backDropTransition":E(r)&&(t.bottomSheetBackdrop.style.transition=r);break;case"rootClass":if(!E(r))return;G(t.bottomSheetRoot,n.rootClass,r);break;case"containerClass":if(!E(r))return;G(t.bottomSheetContainer,n.containerClass,r);break;case"handleClass":if(!E(r))return;G(t.bottomSheetHandle,n.handleClass,r);break;case"contentWrapperClass":if(!E(r))return;G(t.bottomSheetContentWrapper,n.contentWrapperClass,r);break;case"backdropClass":if(!E(r))return;G(t.bottomSheetBackdrop,n.backdropClass,r);break;case"draggingAnimationTimings":if(Et(r)){const c=it(r),a=rt(c,n.draggingAnimationDuration);e.translateContainer=a}break;case"draggingAnimationDuration":if(x(r)){const c=it(n.draggingAnimationTimings),a=rt(c,r);e.translateContainer=a}break}}return o}function se(t){const e=ie(t),n=it(t.draggingAnimationTimings),o={isMounted:!1,translateContainer:rt(n,e.draggingAnimationDuration)},i={startY:null,containerStartTranslate:{x:0,y:0},isDragging:!1,originalDocumentOverflowY:document.body.style.overflowY},r=new zt,c={animationFrame:r,onClose:C,bottomSheetState:o,draggingState:i,snapTo:Y,moveUp:D,moveDown:ct},{elements:a,eventHandlers:m}=_t(e,c),u=Qt(e,ae(a,o,e)),{bottomSheetBackdrop:l,bottomSheetRoot:b,bottomSheetContainer:s}=a,v=d=>{const p=d??window.document.body;p.appendChild(b),p.appendChild(l);const h=window.innerHeight;Z(s,{y:h}),m.attachEventListeners(),o.isMounted=!0},L=()=>{m.clearEventListeners(),Object.values(a).forEach(d=>{d.remove()}),o.isMounted=!1},S=()=>{var d;if(T()||Zt('Bottom Sheet is not mounted yet. call the "mount" method first.'),(d=t.beforeOpen)==null||d.call(t),y())return;u.shouldShowBackdrop&&tt(l,!0),tt([s],!0),Z(s,{y:s.clientHeight});const p=window.innerHeight,h=pt(p,s.clientHeight,u.marginTop,u.defaultPosition),g=P(s).y;o.translateContainer({startY:g,endY:h,animationFrame:r,bottomSheetContainer:s,onEnd:t.afterOpen}),a.bottomSheetHandle.focus()};function C(){var d;if(j())return;(d=t.beforeClose)==null||d.call(t);const p=P(s).y,h=s.clientHeight;o.translateContainer({startY:p,endY:h,animationFrame:r,bottomSheetContainer:s,onEnd:()=>{var g;(g=t.afterClose)==null||g.call(t),tt([l,s],!1)}})}function T(){return o.isMounted}function y(){const d=P(s).y,p=window.innerHeight,h=s.clientHeight>=p?p:s.clientHeight;return d<h}function j(){return!y()}function at(){const d=P(s).y,p=s.clientHeight,h=window.innerHeight;if(d<=5&&d>=-5)return N.CONTENT_HEIGHT;const g=p-d;if(g===h/2)return N.MIDDLE;const H=h-u.marginTop,B=10;return g<=H+B&&g>=H-B?N.TOP:N.CLOSED}function st(){return s.clientHeight}function f(d){const p=P(s).y,h=s.clientHeight-p,g=window.innerHeight-d,H=It(h,g),B=K(h,g);o.translateContainer({startY:p,endY:p+(H.isUp?-B:B),animationFrame:r,bottomSheetContainer:s})}function A(d,{viewportHeight:p,visibleHeight:h}){let g=null;for(const H of d){const B=H*p,U=K(h,B);(g===null||U<g)&&(g=U)}return{minOffset:g}}function D(){const d=[...u.snapPoints].reverse(),p=P(s).y,h=s.clientHeight,g=h-p;if(!u.expandable&&g>=h)return;const H=window.innerHeight,B=ft("above",{visibleHeight:g,viewportHeight:H},d),{minOffset:U}=A(B,{visibleHeight:g,viewportHeight:H});if(U===null&&g<H-u.marginTop){o.translateContainer({startY:p,endY:pt(H,h,u.marginTop,"top"),animationFrame:r,bottomSheetContainer:s});return}x(U)&&o.translateContainer({startY:p,endY:p-U,animationFrame:r,bottomSheetContainer:s})}function ct(){const d=P(s).y,p=s.clientHeight-d;if(p<1)return;const h=window.innerHeight,g=ft("below",{visibleHeight:p,viewportHeight:h},u.snapPoints),{minOffset:H}=A(g,{visibleHeight:p,viewportHeight:h});x(H)&&o.translateContainer({startY:d,endY:d+H,animationFrame:r,bottomSheetContainer:s})}function Y(d){const p=window.innerHeight;if(!Kt(d))return;const h=Q(p*d,2);f(h)}return{props:u,elements:a,mount:v,unmount:L,open:S,close:C,getIsMounted:T,getIsOpen:y,getIsClosed:j,getPosition:at,getHeight:st,moveTo:f,snapTo:Y}}function Lt(){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:()=>N.CLOSED,moveTo:()=>{},snapTo:()=>{},props:{content:""}}}const ce=Lt(),le=k.forwardRef(function(e,n){const{children:o,isOpen:i,setIsOpen:r,afterClose:c,mountingPoint:a,...m}=e,u=k.useRef(ce),[l,b]=k.useState(u.current);k.useImperativeHandle(n,()=>l,[l]);const s=k.useCallback(()=>{r(!1),c==null||c()},[c]);k.useEffect(()=>{i?l.open():l.close()},[i]);const v=k.useRef(null);return k.useEffect(function(){const S=At(e.mountingPoint)?e.mountingPoint:window.document.body;if(!S||l.getIsMounted())return;const C=se({content:"",...m,afterClose:s});return C.mount(S),v.current=C.elements.bottomSheetContentWrapper??null,u.current=C,b(C),()=>{l.unmount()}},[e.mountingPoint,m,s]),k.useEffect(function(){Object.assign(u.current.props,{...m}),b(u.current)},[m]),v.current?xt.createPortal(e.children,v.current):null});O.ReactPlainBottomSheet=le,O.createPlaceholderBottomSheet=Lt,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@plainsheet/react",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"ui",
|
|
9
|
+
"react",
|
|
10
|
+
"javascript",
|
|
11
|
+
"typescript",
|
|
12
|
+
"component",
|
|
13
|
+
"bottom-sheet"
|
|
14
|
+
],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "dist/plainsheet-core.cjs.js",
|
|
17
|
+
"module": "dist/plainsheet-core.es.js",
|
|
18
|
+
"types": "dist/index.d.ts",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"import": "./dist/plainsheet-core.es.js",
|
|
25
|
+
"require": "./dist/plainsheet-core.cjs.js",
|
|
26
|
+
"types": "./dist/index.d.ts"
|
|
27
|
+
},
|
|
28
|
+
"./package.json": "./package.json"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@plainsheet/core": "0.5.0",
|
|
35
|
+
"pbs-utility": "0.0.2"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@eslint/js": "^9.8.0",
|
|
39
|
+
"@types/react": "^18.3.3",
|
|
40
|
+
"@types/react-dom": "^18.3.0",
|
|
41
|
+
"@vitejs/plugin-react-swc": "^3.5.0",
|
|
42
|
+
"@vitest/ui": "^1.6.0",
|
|
43
|
+
"eslint": "^9.8.0",
|
|
44
|
+
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
|
|
45
|
+
"eslint-plugin-react-refresh": "^0.4.9",
|
|
46
|
+
"globals": "^15.9.0",
|
|
47
|
+
"jsdom": "^24.0.0",
|
|
48
|
+
"typescript": "^5.5.3",
|
|
49
|
+
"typescript-eslint": "^8.0.0",
|
|
50
|
+
"vite": "^5.4.0",
|
|
51
|
+
"vitest": "^1.6.0",
|
|
52
|
+
"vite-plugin-dts": "^3.8.1"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"react": "^18",
|
|
56
|
+
"react-dom": "^18"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"dev": "vite build --watch --mode development",
|
|
60
|
+
"build": "tsc --noEmit && vite build",
|
|
61
|
+
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
62
|
+
"lint": "eslint . --max-warnings 0",
|
|
63
|
+
"test": "vitest run",
|
|
64
|
+
"test:watch": "vitest --ui"
|
|
65
|
+
}
|
|
66
|
+
}
|