react-resizable-panels 4.0.0 → 4.0.1
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,2 +1,2 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("react/jsx-runtime"),g=require("react");function x(e,t="Assertion error"){if(!e)throw Error(t)}function ie(e,t){return t.sort(e==="horizontal"?Ie:ke)}function Ie(e,t){const n=e.element.offsetLeft-t.element.offsetLeft;return n!==0?n:e.element.offsetWidth-t.element.offsetWidth}function ke(e,t){const n=e.element.offsetTop-t.element.offsetTop;return n!==0?n:e.element.offsetHeight-t.element.offsetHeight}function ye(e){const{element:t,orientation:n,panels:o,separators:r}=e,i=ie(n,Array.from(t.children).filter(l=>l instanceof HTMLElement).map(l=>({element:l}))).map(({element:l})=>l),u=[];let s,a;for(const l of i){const f=o.find(c=>c.element===l);if(f){if(s){const c=s.element.getBoundingClientRect(),m=l.getBoundingClientRect();u.push({group:e,panels:[s,f],separator:a,rect:n==="horizontal"?new DOMRect(c.right,m.top,m.left-c.right,m.height):new DOMRect(m.left,c.bottom,m.width,m.top-c.bottom)})}s=f,a=void 0}else{const c=r.find(m=>m.element===l);c?a=c:(s=void 0,a=void 0)}}return u}function Oe(e,t){const n=getComputedStyle(e),o=parseFloat(n.fontSize);return t*o}function Te(e,t){const n=getComputedStyle(e.ownerDocument.body),o=parseFloat(n.fontSize);return t*o}function De(e){return e/100*window.innerHeight}function Ae(e){return e/100*window.innerWidth}function $e(e){switch(typeof e){case"number":return[e,"px"];case"string":{const t=parseFloat(e);return e.endsWith("%")?[t,"%"]:e.endsWith("px")?[t,"px"]:e.endsWith("rem")?[t,"rem"]:e.endsWith("em")?[t,"em"]:e.endsWith("vh")?[t,"vh"]:e.endsWith("vw")?[t,"vw"]:[t,"%"]}}}function Z({groupSize:e,panelElement:t,styleProp:n}){let o;const[r,i]=$e(n);switch(i){case"%":{o=r/100*e;break}case"px":{o=r;break}case"rem":{o=Te(t,r);break}case"em":{o=Oe(t,r);break}case"vh":{o=De(r);break}case"vw":{o=Ae(r);break}}return o}function I(e){return parseFloat(e.toFixed(3))}function le({group:e}){const{orientation:t,panels:n}=e;return n.reduce((o,r)=>(o+=t==="horizontal"?r.element.offsetWidth:r.element.offsetHeight,o),0)}function pe(e){const{panels:t}=e,n=le({group:e});return t.map(o=>{const{element:r,panelConstraints:i}=o;let u=0;if(i.collapsedSize){const f=Z({groupSize:n,panelElement:r,styleProp:i.collapsedSize});u=I(f/n*100)}let s;if(i.defaultSize){const f=Z({groupSize:n,panelElement:r,styleProp:i.defaultSize});s=I(f/n*100)}let a=0;if(i.minSize){const f=Z({groupSize:n,panelElement:r,styleProp:i.minSize});a=I(f/n*100)}let l=100;if(i.maxSize){const f=Z({groupSize:n,panelElement:r,styleProp:i.maxSize});l=I(f/n*100)}return{collapsedSize:u,collapsible:i.collapsible===!0,defaultSize:s,minSize:a,maxSize:l,panelId:o.id}})}class Ne{#e={};addListener(t,n){const o=this.#e[t];return o===void 0?this.#e[t]=[n]:o.includes(n)||o.push(n),()=>{this.removeListener(t,n)}}emit(t,n){const o=this.#e[t];if(o!==void 0)if(o.length===1)o[0].call(null,n);else{let r=!1,i=null;const u=Array.from(o);for(let s=0;s<u.length;s++){const a=u[s];try{a.call(null,n)}catch(l){i===null&&(r=!0,i=l)}}if(r)throw i}}removeAllListeners(){this.#e={}}removeListener(t,n){const o=this.#e[t];if(o!==void 0){const r=o.indexOf(n);r>=0&&o.splice(r,1)}}}function P(e,t,n=0){return Math.abs(I(e)-I(t))<=n}let C={cursorFlags:0,interactionState:{state:"inactive"},mountedGroups:new Map};const D=new Ne;function O(){return C}function M(e){const t=typeof e=="function"?e(C):e;if(C===t)return C;const n=C;return C={...C,...t},t.cursorFlags!==void 0&&D.emit("cursorFlagsChange",C.cursorFlags),t.interactionState!==void 0&&D.emit("interactionStateChange",C.interactionState),t.mountedGroups!==void 0&&(C.mountedGroups.forEach((o,r)=>{o.derivedPanelConstraints.forEach(i=>{if(i.collapsible){const{layout:u}=n.mountedGroups.get(r)??{};if(u){const s=P(i.collapsedSize,o.layout[i.panelId]),a=P(i.collapsedSize,u[i.panelId]);s&&!a&&(r.inMemoryLastExpandedPanelSizes[i.panelId]=u[i.panelId])}}})}),D.emit("mountedGroupsChange",C.mountedGroups)),C}function _e(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function F(e,t){return P(e,t)?0:e>t?1:-1}function _({panelConstraints:e,size:t}){const{collapsedSize:n=0,collapsible:o,maxSize:r=100,minSize:i=0}=e;if(F(t,i)<0)if(o){const u=(n+i)/2;F(t,u)<0?t=n:t=i}else t=i;return t=Math.min(r,t),t=I(t),t}function W({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:o,prevLayout:r,trigger:i}){if(P(e,0))return t;const u=Object.values(t),s=Object.values(r),a=[...u],[l,f]=o;x(l!=null,"Invalid first pivot index"),x(f!=null,"Invalid second pivot index");let c=0;if(i==="keyboard"){{const d=e<0?f:l,p=n[d];x(p,`Panel constraints not found for index ${d}`);const{collapsedSize:h=0,collapsible:v,minSize:b=0}=p;if(v){const z=u[d];if(x(z!=null,`Previous layout not found for panel index ${d}`),P(z,h)){const S=b-z;F(S,Math.abs(e))>0&&(e=e<0?0-S:S)}}}{const d=e<0?l:f,p=n[d];x(p,`No panel constraints found for index ${d}`);const{collapsedSize:h=0,collapsible:v,minSize:b=0}=p;if(v){const z=u[d];if(x(z!=null,`Previous layout not found for panel index ${d}`),P(z,b)){const S=z-h;F(S,Math.abs(e))>0&&(e=e<0?0-S:S)}}}}{const d=e<0?1:-1;let p=e<0?f:l,h=0;for(;;){const b=u[p];x(b!=null,`Previous layout not found for panel index ${p}`);const S=_({panelConstraints:n[p],size:100})-b;if(h+=S,p+=d,p<0||p>=n.length)break}const v=Math.min(Math.abs(e),Math.abs(h));e=e<0?0-v:v}{let p=e<0?l:f;for(;p>=0&&p<n.length;){const h=Math.abs(e)-Math.abs(c),v=u[p];x(v!=null,`Previous layout not found for panel index ${p}`);const b=v-h,z=_({panelConstraints:n[p],size:b});if(!P(v,z)&&(c+=v-z,a[p]=z,c.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?p--:p++}}if(_e(s,a))return r;{const d=e<0?f:l,p=u[d];x(p!=null,`Previous layout not found for panel index ${d}`);const h=p+c,v=_({panelConstraints:n[d],size:h});if(a[d]=v,!P(v,h)){let b=h-v,S=e<0?f:l;for(;S>=0&&S<n.length;){const L=a[S];x(L!=null,`Previous layout not found for panel index ${S}`);const R=L+b,E=_({panelConstraints:n[S],size:R});if(P(L,E)||(b-=E-L,a[S]=E),P(b,0))break;e>0?S--:S++}}}const m=Object.values(a).reduce((d,p)=>p+d,0);if(!P(m,100,.1))return r;const y=Object.keys(r);return a.reduce((d,p,h)=>(d[y[h]]=p,d),{})}function ee(e){const t=e.parentElement;x(t,"Parent group element not found");const{mountedGroups:n}=O();for(const[o]of n)if(o.element===t)return o;throw Error("Could not find parent Group for separator element")}function B(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(F(e[n],t[n])!==0)return!1;return!0}function A({layout:e,panelConstraints:t}){const o=[...Object.values(e)],r=o.reduce((s,a)=>s+a,0);if(o.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${o.map(s=>`${s}%`).join(", ")}`);if(!P(r,100)&&o.length>0)for(let s=0;s<t.length;s++){const a=o[s];x(a!=null,`No layout data found for index ${s}`);const l=100/r*a;o[s]=l}let i=0;for(let s=0;s<t.length;s++){const a=o[s];x(a!=null,`No layout data found for index ${s}`);const l=_({panelConstraints:t[s],size:a});a!=l&&(i+=a-l,o[s]=l)}if(!P(i,0))for(let s=0;s<t.length;s++){const a=o[s];x(a!=null,`No layout data found for index ${s}`);const l=a+i,f=_({panelConstraints:t[s],size:l});if(a!==f&&(i-=f-a,o[s]=f,P(i,0)))break}const u=Object.keys(e);return o.reduce((s,a,l)=>(s[u[l]]=a,s),{})}function Se({groupId:e}){const t=()=>{const{mountedGroups:n}=O();for(const[o,r]of n)if(o.id===e)return{group:o,...r};throw Error(`Group ${e} not found`)};return{getLayout(){const{layout:n}=t();return n},setLayout(n){const{derivedPanelConstraints:o,group:r,layout:i,separatorToPanels:u}=t(),s=A({layout:n,panelConstraints:o});return B(i,s)||M(a=>({mountedGroups:new Map(a.mountedGroups).set(r,{derivedPanelConstraints:o,layout:s,separatorToPanels:u})})),s}}}function xe(e){const{mountedGroups:t}=O(),n=t.get(e);return x(n,`Mounted Group ${e.id} not found`),n}function T(e,t){const n=ee(e),o=xe(n),r=n.separators.find(c=>c.element===e);x(r,"Matching separator not found");const i=o.separatorToPanels.get(r);x(i,"Matching panels not found");const u=i.map(c=>n.panels.indexOf(c)),a=Se({groupId:n.id}).getLayout(),l=W({delta:t,initialLayout:a,panelConstraints:o.derivedPanelConstraints,pivotIndices:u,prevLayout:a,trigger:"keyboard"}),f=A({layout:l,panelConstraints:o.derivedPanelConstraints});B(a,f)||M(c=>({mountedGroups:new Map(c.mountedGroups).set(n,{derivedPanelConstraints:o.derivedPanelConstraints,layout:f,separatorToPanels:o.separatorToPanels})}))}function me(e){if(e.defaultPrevented)return;const t=e.currentTarget,n=ee(t);if(!n.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),n.orientation==="vertical"&&T(t,5);break}case"ArrowLeft":{e.preventDefault(),n.orientation==="horizontal"&&T(t,-5);break}case"ArrowRight":{e.preventDefault(),n.orientation==="horizontal"&&T(t,5);break}case"ArrowUp":{e.preventDefault(),n.orientation==="vertical"&&T(t,-5);break}case"End":{e.preventDefault(),T(t,100);break}case"Enter":{e.preventDefault();const o=ee(t),{derivedPanelConstraints:r,layout:i,separatorToPanels:u}=xe(o),s=o.separators.find(c=>c.element===t);x(s,"Matching separator not found");const a=u.get(s);x(a,"Matching panels not found");const l=a[0],f=r.find(c=>c.panelId===l.id);if(x(f,"Panel metadata not found"),f.collapsible){const c=i[l.id],m=f.collapsedSize===c?o.inMemoryLastExpandedPanelSizes[l.id]??f.minSize:f.collapsedSize;T(t,m-c)}break}case"F6":{e.preventDefault();const r=ee(t).separators.map(a=>a.element),i=Array.from(r).findIndex(a=>a===e.currentTarget);x(i!==null,"Index not found");const u=e.shiftKey?i>0?i-1:r.length-1:i+1<r.length?i+1:0;r[u].focus();break}case"Home":{e.preventDefault(),T(t,-100);break}}}const je=e=>e,oe=()=>{},ze=1,be=2,we=4,Pe=8,he={coarse:10,precise:5};function He(e,t){return{x:e.x>=t.left&&e.x<=t.right?0:Math.min(Math.abs(e.x-t.left),Math.abs(e.x-t.right)),y:e.y>=t.top&&e.y<=t.bottom?0:Math.min(Math.abs(e.y-t.top),Math.abs(e.y-t.bottom))}}function Fe(e,t,n){let o,r={x:1/0,y:1/0};for(const i of t){const u=He(n,i.rect);switch(e){case"horizontal":{u.x<=r.x&&(o=i,r=u);break}case"vertical":{u.y<=r.y&&(o=i,r=u);break}}}return o?{distance:r,hitRegion:o}:void 0}let J;function We(){return J===void 0&&(typeof matchMedia=="function"?J=!!matchMedia("(pointer:coarse)").matches:J=!1),J}function Le(e,t){const n=[];return t.forEach((o,r)=>{if(r.disabled)return;const i=We()?he.coarse:he.precise,u=ye(r),s=Fe(r.orientation,u,{x:e.clientX,y:e.clientY});s&&s.distance.x<=i&&s.distance.y<=i&&n.push(s.hitRegion)}),n}function ve(e){if(e.defaultPrevented)return;const{mountedGroups:t}=O(),n=Le(e,t),o=new Set,r=new Set,i=new Set,u=new Map;n.forEach(s=>{o.add(s.group),s.panels.forEach(l=>{r.add(l)}),s.separator&&i.add(s.separator);const a=t.get(s.group);a&&u.set(s.group,a.layout)}),M({interactionState:{hitRegions:n,initialLayoutMap:u,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}}),n.length&&e.preventDefault()}function Be({cursorFlags:e,groups:t,state:n}){let o=0,r=0;switch(n){case"active":case"hover":t.forEach(i=>{if(!i.disableCursor)switch(i.orientation){case"horizontal":{o++;break}case"vertical":{r++;break}}})}if(o===0&&r===0)return null;switch(n){case"active":{const i=(e&ze)!==0,u=(e&be)!==0,s=(e&we)!==0,a=(e&Pe)!==0;if(e){if(i)return s?"se-resize":a?"ne-resize":"e-resize";if(u)return s?"sw-resize":a?"nw-resize":"w-resize";if(s)return"s-resize";if(a)return"n-resize"}break}}return o>0&&r>0?"move":o>0?"ew-resize":"ns-resize"}let se=null,k;function re(){k===void 0&&(k=new CSSStyleSheet,document.adoptedStyleSheets=[k]);const{cursorFlags:e,interactionState:t}=O();switch(t.state){case"active":case"hover":{const n=Be({cursorFlags:e,groups:t.hitRegions.map(o=>o.group),state:t.state});if(se===n)return;se=n,n?k.cssRules.length===0?k.insertRule(`*{cursor: ${n} !important;}`):k.replaceSync(`*{cursor: ${n} !important;}`):k.cssRules.length===1&&k.deleteRule(0);break}case"inactive":{se=null,k.cssRules.length===1&&k.deleteRule(0);break}}}function Q(e){if(e.defaultPrevented)return;const{interactionState:t,mountedGroups:n}=O();switch(t.state){case"active":{if(e.type!=="pointerleave"&&e.buttons===0){M(i=>i.interactionState.state==="inactive"?i:{cursorFlags:0,interactionState:{state:"inactive"}});return}let o=0;const r=new Map(n);t.hitRegions.forEach(i=>{const{disableCursor:u,element:s,orientation:a,panels:l}=i.group;let f=0;t.state==="active"&&(a==="horizontal"?f=(e.clientX-t.pointerDownAtPoint.x)/s.offsetWidth*100:f=(e.clientY-t.pointerDownAtPoint.y)/s.offsetHeight*100);const c=t.initialLayoutMap.get(i.group),{derivedPanelConstraints:m,layout:y,separatorToPanels:d}=n.get(i.group)??{};if(m&&c&&y&&d){const p=W({delta:f,initialLayout:c,panelConstraints:m,pivotIndices:i.panels.map(h=>l.indexOf(h)),prevLayout:y,trigger:"mouse-or-touch"});if(B(p,y)){if(f!==0&&!u)switch(a){case"horizontal":{o|=f<0?ze:be;break}case"vertical":{o|=f<0?we:Pe;break}}}else{r.set(i.group,{derivedPanelConstraints:m,layout:p,separatorToPanels:d});const h=i.group.panels.map(({id:v})=>v).join(",");i.group.inMemoryLayouts[h]=p}}}),M({cursorFlags:o,mountedGroups:r}),re();break}default:{const o=Le(e,n);o.length===0?t.state!=="inactive"&&M({interactionState:{state:"inactive"}}):M({interactionState:{hitRegions:o,state:"hover"}}),re();break}}}function ge(e){if(e.defaultPrevented)return;e.preventDefault();const{interactionState:t}=O();switch(t.state){case"active":M({cursorFlags:0,interactionState:{state:"inactive"}}),re()}}function Ue(e){let t=0,n=0;const o={};for(const i of e)if(i.defaultSize!==void 0){t++;const u=I(i.defaultSize);n+=u,o[i.panelId]=u}else o[i.panelId]=void 0;const r=e.length-t;if(r!==0){const i=I((100-n)/r);for(const u of e)u.defaultSize===void 0&&(o[u.panelId]=i)}return o}function Ke(e,t,n){const o=n[0];if(!o)return;const r=e.panels.find(u=>u.element===t);if(!r||!r.onResize)return;const i=le({group:e});r.onResize({asPercentage:I(o.inlineSize/i*100),inPixels:o.inlineSize},r.id)}function Ve(e){let t=!0;x(e.separators.length===0||e.separators.length<e.panels.length,"Invalid Group configuration; too many Separator components");const n=new Set,o=new Set,r=new ResizeObserver(c=>{for(const m of c){const{borderBoxSize:y,target:d}=m;d===e.element?t&&M(p=>{const h=p.mountedGroups.get(e);if(h){const v=pe(e),b=h.layout,z=A({layout:b,panelConstraints:v});return{mountedGroups:new Map(p.mountedGroups).set(e,{derivedPanelConstraints:v,layout:z,separatorToPanels:h.separatorToPanels})}}return p}):Ke(e,d,y)}});r.observe(e.element),e.panels.forEach(c=>{x(!n.has(c.id),`Panel ids must be unique; id "${c.id}" was used more than once`),n.add(c.id),c.onResize&&r.observe(c.element)});const i=pe(e),u=e.panels.map(({id:c})=>c).join(","),s=e.inMemoryLayouts[u]??e.defaultLayout??Ue(i),a=A({layout:s,panelConstraints:i}),l=ye(e),f=M(c=>({mountedGroups:new Map(c.mountedGroups).set(e,{derivedPanelConstraints:i,layout:a,separatorToPanels:new Map(l.filter(m=>m.separator).map(m=>[m.separator,m.panels]))})}));return e.separators.forEach(c=>{x(!o.has(c.id),`Separator ids must be unique; id "${c.id}" was used more than once`),o.add(c.id),c.element.addEventListener("keydown",me)}),f.mountedGroups.size===1&&(window.addEventListener("pointerdown",ve),window.addEventListener("pointerleave",Q),window.addEventListener("pointermove",Q),window.addEventListener("pointerup",ge)),function(){t=!1;const m=M(y=>{const d=new Map(y.mountedGroups);return d.delete(e),{mountedGroups:d}});e.separators.forEach(y=>{y.element.removeEventListener("keydown",me)}),m.mountedGroups.size===0&&(window.removeEventListener("pointerdown",ve),window.removeEventListener("pointerleave",Q),window.removeEventListener("pointermove",Q),window.removeEventListener("pointerup",ge)),r.disconnect()}}function ue(e){const t=g.useId();return`${e??t}`}const j=typeof window<"u"?g.useLayoutEffect:g.useEffect;function ce(e){const t=g.useRef(e);return j(()=>{t.current=e},[e]),g.useCallback(n=>t.current?.(n),[t])}function fe(...e){return ce(t=>{e.forEach(n=>{if(n)switch(typeof n){case"function":{n(t);break}case"object":{n.current=t;break}}})})}const Re="--react-resizable-panels--panel--pointer-events";function Ee(e,t){const n=e.replace(/[^a-zA-Z0-9\-_]/g,""),o=t.replace(/[^a-zA-Z0-9\-_]/g,"");return`--react-resizable-panels--${n}--${o}`}const Ce=g.createContext(null);function qe(e,t){const n=g.useRef({getLayout:()=>({}),setLayout:je});g.useImperativeHandle(t,()=>n.current,[]),j(()=>{Object.assign(n.current,Se({groupId:e}))})}function Xe({children:e,className:t,defaultLayout:n,disableCursor:o,disabled:r,elementRef:i,groupRef:u,id:s,onLayoutChange:a,orientation:l="horizontal",style:f,...c}){const m=g.useRef({}),y=ce(w=>{B(m.current,w)||(m.current=w,a?.(w))}),d=ue(s),[p,h]=g.useState(!1),[v,b]=g.useState(null),[z,S]=g.useState(n??{}),[L,R]=g.useState([]),[E,U]=g.useState([]),te=g.useRef({}),K=g.useRef({}),V=fe(b,i);qe(d,u);const q=g.useMemo(()=>({id:d,orientation:l,registerPanel:w=>(R(G=>ie(l,[...G,w])),()=>{R(G=>G.filter($=>$!==w))}),registerSeparator:w=>(U(G=>ie(l,[...G,w])),()=>{U(G=>G.filter($=>$!==w))})}),[d,l]);j(()=>{if(v!==null&&L.length>0){const w={defaultLayout:n,disableCursor:!!o,disabled:!!r,element:v,id:d,inMemoryLastExpandedPanelSizes:te.current,inMemoryLayouts:K.current,orientation:l,panels:L,separators:E},G=Ve(w),ne=O().mountedGroups.get(w);ne&&(S(ne.layout),y?.(ne.layout));const Me=D.addListener("interactionStateChange",Y=>{switch(Y.state){case"active":case"hover":{h(Y.hitRegions.some(N=>N.group===w));break}}}),Ge=D.addListener("mountedGroupsChange",Y=>{const N=Y.get(w);N&&N.derivedPanelConstraints.length>0&&(S(N.layout),y?.(N.layout))});return()=>{G(),Me(),Ge()}}},[n,o,r,v,d,y,l,L,E]);const X={[Re]:p?"none":void 0};for(const w in z){const G=Ee(d,w),$=z[w];X[G]=$}return H.jsx(Ce.Provider,{value:q,children:H.jsx("div",{...c,"aria-orientation":l,className:t,"data-group":!0,"data-testid":d,id:d,ref:V,style:{...f,...X,display:"flex",flexDirection:l==="horizontal"?"row":"column",flexWrap:"nowrap"},children:e})})}function ae(e){return`react-resizable-panels:${e}`}function Ye({id:e,layout:t,storage:n}){try{const o=ae(e);n.setItem(o,JSON.stringify(t))}catch(o){console.error(o)}}function Ze({groupId:e,storage:t}){const n=g.useSyncExternalStore(Je,()=>t.getItem(ae(e)),()=>t.getItem(ae(e))),o=g.useMemo(()=>n?JSON.parse(n):null,[n]),r=g.useCallback(i=>Ye({id:e,layout:i,storage:t}),[e,t]);return{defaultLayout:o,onLayoutChange:r}}function Je(){return function(){}}function Qe(){return g.useState(null)}function et(){return g.useRef(null)}function de(){const e=g.useContext(Ce);return x(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function tt({groupId:e,panelId:t}){const n=()=>{const{mountedGroups:s}=O();for(const[a,{derivedPanelConstraints:l,layout:f,separatorToPanels:c}]of s)if(a.id===e)return{derivedPanelConstraints:l,group:a,layout:f,separatorToPanels:c};throw Error(`Group ${e} not found`)},o=()=>{const s=n().derivedPanelConstraints.find(a=>a.panelId===t);if(s!==void 0)return s;throw Error(`Panel constraints not found for Panel ${t}`)},r=()=>{const s=n().group.panels.find(a=>a.id===t);if(s!==void 0)return s;throw Error(`Layout not found for Panel ${t}`)},i=()=>{const s=n().layout[t];if(s!==void 0)return s;throw Error(`Layout not found for Panel ${t}`)},u=s=>{const a=i();if(s===a)return;const{derivedPanelConstraints:l,group:f,layout:c,separatorToPanels:m}=n(),y=f.panels.findIndex(v=>v.id===t),d=y===f.panels.length-1,p=W({delta:d?a-s:s-a,initialLayout:c,panelConstraints:l,pivotIndices:d?[y-1,y]:[y,y+1],prevLayout:c,trigger:"imperative-api"}),h=A({layout:p,panelConstraints:l});B(c,h)||M(v=>({mountedGroups:new Map(v.mountedGroups).set(f,{derivedPanelConstraints:l,layout:h,separatorToPanels:m})}))};return{collapse:()=>{const{collapsible:s,collapsedSize:a}=o(),l=i();s&&l!==a&&u(a)},expand:()=>{const{collapsible:s,collapsedSize:a,minSize:l}=o(),f=i();s&&f===a&&u(l)},getSize:()=>{const{group:s}=n(),a=i(),{element:l}=r(),f=s.orientation==="horizontal"?l.offsetWidth:l.offsetHeight;return{asPercentage:a,inPixels:f}},isCollapsed:()=>{const{collapsible:s,collapsedSize:a}=o(),l=i();return s&&P(a,l)},resize:s=>{if(i()!==s){let l;switch(typeof s){case"number":{const{group:f}=n(),c=le({group:f});l=I(s/c*100);break}case"string":{l=parseFloat(s);break}}u(l)}}}}function nt(e,t){const{id:n}=de(),o=g.useRef({collapse:oe,expand:oe,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:oe});g.useImperativeHandle(t,()=>o.current,[]),j(()=>{Object.assign(o.current,tt({groupId:n,panelId:e}))})}function ot({children:e,className:t,collapsedSize:n=0,collapsible:o=!1,defaultSize:r,elementRef:i,id:u,maxSize:s="100",minSize:a="0",onResize:l,panelRef:f,style:c,...m}){const y=!!u,d=ue(u),[p,h]=g.useState(null),v=fe(h,i),{id:b,registerPanel:z}=de(),S=l!==null,L=ce(E=>{l?.(E,u)});j(()=>{if(p!==null)return z({element:p,id:d,idIsStable:y,onResize:S?L:void 0,panelConstraints:{collapsedSize:n,collapsible:o,defaultSize:r,maxSize:s,minSize:a}})},[n,o,r,p,S,d,y,s,a,L,z]),nt(d,f);const R=Ee(b,d);return H.jsx("div",{...m,"data-panel":!0,"data-testid":d,id:d,ref:v,style:{...st,flexBasis:0,flexGrow:`var(${R}, 1)`,flexShrink:1,overflow:"hidden",pointerEvents:`var(${Re})`},children:H.jsx("div",{className:t,style:{width:"100%",height:"100%",...c},children:e})})}const st={minHeight:"unset",maxHeight:"unset",height:"unset",minWidth:"unset",maxWidth:"unset",width:"unset",flex:"unset",flexBasis:"unset",flexShrink:"unset",flexGrow:"unset",border:"unset",borderWidth:"unset",padding:"unset",margin:"unset"};function it(){return g.useState(null)}function rt(){return g.useRef(null)}function at({layout:e,panelConstraints:t,panelId:n,panelIndex:o}){let r,i;const u=e[n],s=t.find(a=>a.panelId===n);if(s){const a=s.maxSize,l=i=s.collapsible?s.collapsedSize:s.minSize,f=[o,o+1];i=A({layout:W({delta:l-u,initialLayout:e,panelConstraints:t,pivotIndices:f,prevLayout:e,trigger:"keyboard"}),panelConstraints:t})[n],r=A({layout:W({delta:a-u,initialLayout:e,panelConstraints:t,pivotIndices:f,prevLayout:e,trigger:"keyboard"}),panelConstraints:t})[n]}return{valueControls:n,valueMax:r,valueMin:i,valueNow:u}}function lt({children:e,className:t,elementRef:n,id:o,style:r,...i}){const u=ue(o),[s,a]=g.useState({}),[l,f]=g.useState("inactive"),[c,m]=g.useState(null),y=fe(m,n),{id:d,orientation:p,registerSeparator:h}=de(),v=p==="horizontal"?"vertical":"horizontal";return j(()=>{if(c!==null){const b={element:c,id:u},z=h(b),S=D.addListener("interactionStateChange",R=>{f(R.state!=="inactive"&&R.hitRegions.some(E=>E.separator===b)?R.state:"inactive")}),L=D.addListener("mountedGroupsChange",R=>{R.forEach(({derivedPanelConstraints:E,layout:U,separatorToPanels:te},K)=>{if(K.id===d){const V=te.get(b);if(V){const q=V[0],X=K.panels.indexOf(q);a(at({layout:U,panelConstraints:E,panelId:q.id,panelIndex:X}))}}})});return()=>{S(),L(),z()}}},[c,d,u,h]),H.jsx("div",{...i,"aria-controls":s.valueControls,"aria-orientation":v,"aria-valuemax":s.valueMax,"aria-valuemin":s.valueMin,"aria-valuenow":s.valueNow,children:e,className:t,"data-separator":l,"data-testid":u,id:u,ref:y,role:"separator",style:{flexBasis:"auto",...r,flexGrow:0,flexShrink:0},tabIndex:0})}exports.Group=Xe;exports.Panel=ot;exports.Separator=lt;exports.useDefaultLayout=Ze;exports.useGroupCallbackRef=Qe;exports.useGroupRef=et;exports.usePanelCallbackRef=it;exports.usePanelRef=rt;
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("react/jsx-runtime"),g=require("react");function b(e,t="Assertion error"){if(!e)throw Error(t)}function ie(e,t){return t.sort(e==="horizontal"?Oe:Te)}function Oe(e,t){const n=e.element.offsetLeft-t.element.offsetLeft;return n!==0?n:e.element.offsetWidth-t.element.offsetWidth}function Te(e,t){const n=e.element.offsetTop-t.element.offsetTop;return n!==0?n:e.element.offsetHeight-t.element.offsetHeight}function Se(e){const{element:t,orientation:n,panels:o,separators:r}=e,s=ie(n,Array.from(t.children).filter(l=>l instanceof HTMLElement).map(l=>({element:l}))).map(({element:l})=>l),u=[];let i,a;for(const l of s){const f=o.find(c=>c.element===l);if(f){if(i){const c=i.element.getBoundingClientRect(),m=l.getBoundingClientRect();u.push({group:e,panels:[i,f],separator:a,rect:n==="horizontal"?new DOMRect(c.right,m.top,m.left-c.right,m.height):new DOMRect(m.left,c.bottom,m.width,m.top-c.bottom)})}i=f,a=void 0}else{const c=r.find(m=>m.element===l);c?a=c:(i=void 0,a=void 0)}}return u}function De(e,t){const n=getComputedStyle(e),o=parseFloat(n.fontSize);return t*o}function Ae(e,t){const n=getComputedStyle(e.ownerDocument.body),o=parseFloat(n.fontSize);return t*o}function $e(e){return e/100*window.innerHeight}function Ne(e){return e/100*window.innerWidth}function _e(e){switch(typeof e){case"number":return[e,"px"];case"string":{const t=parseFloat(e);return e.endsWith("%")?[t,"%"]:e.endsWith("px")?[t,"px"]:e.endsWith("rem")?[t,"rem"]:e.endsWith("em")?[t,"em"]:e.endsWith("vh")?[t,"vh"]:e.endsWith("vw")?[t,"vw"]:[t,"%"]}}}function Z({groupSize:e,panelElement:t,styleProp:n}){let o;const[r,s]=_e(n);switch(s){case"%":{o=r/100*e;break}case"px":{o=r;break}case"rem":{o=Ae(t,r);break}case"em":{o=De(t,r);break}case"vh":{o=$e(r);break}case"vw":{o=Ne(r);break}}return o}function I(e){return parseFloat(e.toFixed(3))}function re({group:e}){const{orientation:t,panels:n}=e;return n.reduce((o,r)=>(o+=t==="horizontal"?r.element.offsetWidth:r.element.offsetHeight,o),0)}function de(e){const{panels:t}=e,n=re({group:e});return t.map(o=>{const{element:r,panelConstraints:s}=o;let u=0;if(s.collapsedSize){const f=Z({groupSize:n,panelElement:r,styleProp:s.collapsedSize});u=I(f/n*100)}let i;if(s.defaultSize){const f=Z({groupSize:n,panelElement:r,styleProp:s.defaultSize});i=I(f/n*100)}let a=0;if(s.minSize){const f=Z({groupSize:n,panelElement:r,styleProp:s.minSize});a=I(f/n*100)}let l=100;if(s.maxSize){const f=Z({groupSize:n,panelElement:r,styleProp:s.maxSize});l=I(f/n*100)}return{collapsedSize:u,collapsible:s.collapsible===!0,defaultSize:i,minSize:a,maxSize:l,panelId:o.id}})}class je{#e={};addListener(t,n){const o=this.#e[t];return o===void 0?this.#e[t]=[n]:o.includes(n)||o.push(n),()=>{this.removeListener(t,n)}}emit(t,n){const o=this.#e[t];if(o!==void 0)if(o.length===1)o[0].call(null,n);else{let r=!1,s=null;const u=Array.from(o);for(let i=0;i<u.length;i++){const a=u[i];try{a.call(null,n)}catch(l){s===null&&(r=!0,s=l)}}if(r)throw s}}removeAllListeners(){this.#e={}}removeListener(t,n){const o=this.#e[t];if(o!==void 0){const r=o.indexOf(n);r>=0&&o.splice(r,1)}}}function P(e,t,n=0){return Math.abs(I(e)-I(t))<=n}let C={cursorFlags:0,interactionState:{state:"inactive"},mountedGroups:new Map};const D=new je;function O(){return C}function M(e){const t=typeof e=="function"?e(C):e;if(C===t)return C;const n=C;return C={...C,...t},t.cursorFlags!==void 0&&D.emit("cursorFlagsChange",C.cursorFlags),t.interactionState!==void 0&&D.emit("interactionStateChange",C.interactionState),t.mountedGroups!==void 0&&(C.mountedGroups.forEach((o,r)=>{o.derivedPanelConstraints.forEach(s=>{if(s.collapsible){const{layout:u}=n.mountedGroups.get(r)??{};if(u){const i=P(s.collapsedSize,o.layout[s.panelId]),a=P(s.collapsedSize,u[s.panelId]);i&&!a&&(r.inMemoryLastExpandedPanelSizes[s.panelId]=u[s.panelId])}}})}),D.emit("mountedGroupsChange",C.mountedGroups)),C}const He=e=>e,ne=()=>{},xe=1,ze=2,be=4,we=8,pe={coarse:10,precise:5};function Fe({cursorFlags:e,groups:t,state:n}){let o=0,r=0;switch(n){case"active":case"hover":t.forEach(s=>{if(!s.disableCursor)switch(s.orientation){case"horizontal":{o++;break}case"vertical":{r++;break}}})}if(o===0&&r===0)return null;switch(n){case"active":{const s=(e&xe)!==0,u=(e&ze)!==0,i=(e&be)!==0,a=(e&we)!==0;if(e){if(s)return i?"se-resize":a?"ne-resize":"e-resize";if(u)return i?"sw-resize":a?"nw-resize":"w-resize";if(i)return"s-resize";if(a)return"n-resize"}break}}return o>0&&r>0?"move":o>0?"ew-resize":"ns-resize"}let oe=null,k;function ae(){k===void 0&&(k=new CSSStyleSheet,document.adoptedStyleSheets=[k]);const{cursorFlags:e,interactionState:t}=O();switch(t.state){case"active":case"hover":{const n=Fe({cursorFlags:e,groups:t.hitRegions.map(o=>o.group),state:t.state});if(oe===n)return;oe=n,n?k.cssRules.length===0?k.insertRule(`*{cursor: ${n} !important;}`):k.replaceSync(`*{cursor: ${n} !important;}`):k.cssRules.length===1&&k.deleteRule(0);break}case"inactive":{oe=null,k.cssRules.length===1&&k.deleteRule(0);break}}}function We(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function F(e,t){return P(e,t)?0:e>t?1:-1}function _({panelConstraints:e,size:t}){const{collapsedSize:n=0,collapsible:o,maxSize:r=100,minSize:s=0}=e;if(F(t,s)<0)if(o){const u=(n+s)/2;F(t,u)<0?t=n:t=s}else t=s;return t=Math.min(r,t),t=I(t),t}function W({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:o,prevLayout:r,trigger:s}){if(P(e,0))return t;const u=Object.values(t),i=Object.values(r),a=[...u],[l,f]=o;b(l!=null,"Invalid first pivot index"),b(f!=null,"Invalid second pivot index");let c=0;if(s==="keyboard"){{const d=e<0?f:l,p=n[d];b(p,`Panel constraints not found for index ${d}`);const{collapsedSize:v=0,collapsible:h,minSize:y=0}=p;if(h){const z=u[d];if(b(z!=null,`Previous layout not found for panel index ${d}`),P(z,v)){const S=y-z;F(S,Math.abs(e))>0&&(e=e<0?0-S:S)}}}{const d=e<0?l:f,p=n[d];b(p,`No panel constraints found for index ${d}`);const{collapsedSize:v=0,collapsible:h,minSize:y=0}=p;if(h){const z=u[d];if(b(z!=null,`Previous layout not found for panel index ${d}`),P(z,y)){const S=z-v;F(S,Math.abs(e))>0&&(e=e<0?0-S:S)}}}}{const d=e<0?1:-1;let p=e<0?f:l,v=0;for(;;){const y=u[p];b(y!=null,`Previous layout not found for panel index ${p}`);const S=_({panelConstraints:n[p],size:100})-y;if(v+=S,p+=d,p<0||p>=n.length)break}const h=Math.min(Math.abs(e),Math.abs(v));e=e<0?0-h:h}{let p=e<0?l:f;for(;p>=0&&p<n.length;){const v=Math.abs(e)-Math.abs(c),h=u[p];b(h!=null,`Previous layout not found for panel index ${p}`);const y=h-v,z=_({panelConstraints:n[p],size:y});if(!P(h,z)&&(c+=h-z,a[p]=z,c.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?p--:p++}}if(We(i,a))return r;{const d=e<0?f:l,p=u[d];b(p!=null,`Previous layout not found for panel index ${d}`);const v=p+c,h=_({panelConstraints:n[d],size:v});if(a[d]=h,!P(h,v)){let y=v-h,S=e<0?f:l;for(;S>=0&&S<n.length;){const L=a[S];b(L!=null,`Previous layout not found for panel index ${S}`);const R=L+y,E=_({panelConstraints:n[S],size:R});if(P(L,E)||(y-=E-L,a[S]=E),P(y,0))break;e>0?S--:S++}}}const m=Object.values(a).reduce((d,p)=>p+d,0);if(!P(m,100,.1))return r;const x=Object.keys(r);return a.reduce((d,p,v)=>(d[x[v]]=p,d),{})}function B(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(F(e[n],t[n])!==0)return!1;return!0}function Pe({event:e,hitRegions:t,initialLayoutMap:n,mountedGroups:o,pointerDownAtPoint:r}){let s=0;const u=new Map(o);t.forEach(i=>{const{disableCursor:a,element:l,orientation:f,panels:c}=i.group;let m=0;r?f==="horizontal"?m=(e.clientX-r.x)/l.offsetWidth*100:m=(e.clientY-r.y)/l.offsetHeight*100:f==="horizontal"?m=e.clientX<0?-100:100:m=e.clientY<0?-100:100;const x=n.get(i.group),{derivedPanelConstraints:d,layout:p,separatorToPanels:v}=o.get(i.group)??{};if(d&&x&&p&&v){const h=W({delta:m,initialLayout:x,panelConstraints:d,pivotIndices:i.panels.map(y=>c.indexOf(y)),prevLayout:p,trigger:"mouse-or-touch"});if(B(h,p)){if(m!==0&&!a)switch(f){case"horizontal":{s|=m<0?xe:ze;break}case"vertical":{s|=m<0?be:we;break}}}else{u.set(i.group,{derivedPanelConstraints:d,layout:h,separatorToPanels:v});const y=i.group.panels.map(({id:z})=>z).join(",");i.group.inMemoryLayouts[y]=h}}}),M({cursorFlags:s,mountedGroups:u}),ae()}function me(e){if(e.defaultPrevented)return;if(e.relatedTarget!==null)return;const{interactionState:t,mountedGroups:n}=O();switch(t.state){case"active":t.hitRegions.forEach(o=>{e.currentTarget===o.group.element&&Pe({event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n})})}}function Q(e){const t=e.parentElement;b(t,"Parent group element not found");const{mountedGroups:n}=O();for(const[o]of n)if(o.element===t)return o;throw Error("Could not find parent Group for separator element")}function A({layout:e,panelConstraints:t}){const o=[...Object.values(e)],r=o.reduce((i,a)=>i+a,0);if(o.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${o.map(i=>`${i}%`).join(", ")}`);if(!P(r,100)&&o.length>0)for(let i=0;i<t.length;i++){const a=o[i];b(a!=null,`No layout data found for index ${i}`);const l=100/r*a;o[i]=l}let s=0;for(let i=0;i<t.length;i++){const a=o[i];b(a!=null,`No layout data found for index ${i}`);const l=_({panelConstraints:t[i],size:a});a!=l&&(s+=a-l,o[i]=l)}if(!P(s,0))for(let i=0;i<t.length;i++){const a=o[i];b(a!=null,`No layout data found for index ${i}`);const l=a+s,f=_({panelConstraints:t[i],size:l});if(a!==f&&(s-=f-a,o[i]=f,P(s,0)))break}const u=Object.keys(e);return o.reduce((i,a,l)=>(i[u[l]]=a,i),{})}function Le({groupId:e}){const t=()=>{const{mountedGroups:n}=O();for(const[o,r]of n)if(o.id===e)return{group:o,...r};throw Error(`Group ${e} not found`)};return{getLayout(){const{layout:n}=t();return n},setLayout(n){const{derivedPanelConstraints:o,group:r,layout:s,separatorToPanels:u}=t(),i=A({layout:n,panelConstraints:o});return B(s,i)||M(a=>({mountedGroups:new Map(a.mountedGroups).set(r,{derivedPanelConstraints:o,layout:i,separatorToPanels:u})})),i}}}function Re(e){const{mountedGroups:t}=O(),n=t.get(e);return b(n,`Mounted Group ${e.id} not found`),n}function T(e,t){const n=Q(e),o=Re(n),r=n.separators.find(c=>c.element===e);b(r,"Matching separator not found");const s=o.separatorToPanels.get(r);b(s,"Matching panels not found");const u=s.map(c=>n.panels.indexOf(c)),a=Le({groupId:n.id}).getLayout(),l=W({delta:t,initialLayout:a,panelConstraints:o.derivedPanelConstraints,pivotIndices:u,prevLayout:a,trigger:"keyboard"}),f=A({layout:l,panelConstraints:o.derivedPanelConstraints});B(a,f)||M(c=>({mountedGroups:new Map(c.mountedGroups).set(n,{derivedPanelConstraints:o.derivedPanelConstraints,layout:f,separatorToPanels:o.separatorToPanels})}))}function he(e){if(e.defaultPrevented)return;const t=e.currentTarget,n=Q(t);if(!n.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),n.orientation==="vertical"&&T(t,5);break}case"ArrowLeft":{e.preventDefault(),n.orientation==="horizontal"&&T(t,-5);break}case"ArrowRight":{e.preventDefault(),n.orientation==="horizontal"&&T(t,5);break}case"ArrowUp":{e.preventDefault(),n.orientation==="vertical"&&T(t,-5);break}case"End":{e.preventDefault(),T(t,100);break}case"Enter":{e.preventDefault();const o=Q(t),{derivedPanelConstraints:r,layout:s,separatorToPanels:u}=Re(o),i=o.separators.find(c=>c.element===t);b(i,"Matching separator not found");const a=u.get(i);b(a,"Matching panels not found");const l=a[0],f=r.find(c=>c.panelId===l.id);if(b(f,"Panel metadata not found"),f.collapsible){const c=s[l.id],m=f.collapsedSize===c?o.inMemoryLastExpandedPanelSizes[l.id]??f.minSize:f.collapsedSize;T(t,m-c)}break}case"F6":{e.preventDefault();const r=Q(t).separators.map(a=>a.element),s=Array.from(r).findIndex(a=>a===e.currentTarget);b(s!==null,"Index not found");const u=e.shiftKey?s>0?s-1:r.length-1:s+1<r.length?s+1:0;r[u].focus();break}case"Home":{e.preventDefault(),T(t,-100);break}}}function Be(e,t){return{x:e.x>=t.left&&e.x<=t.right?0:Math.min(Math.abs(e.x-t.left),Math.abs(e.x-t.right)),y:e.y>=t.top&&e.y<=t.bottom?0:Math.min(Math.abs(e.y-t.top),Math.abs(e.y-t.bottom))}}function Ue(e,t,n){let o,r={x:1/0,y:1/0};for(const s of t){const u=Be(n,s.rect);switch(e){case"horizontal":{u.x<=r.x&&(o=s,r=u);break}case"vertical":{u.y<=r.y&&(o=s,r=u);break}}}return o?{distance:r,hitRegion:o}:void 0}let J;function Ke(){return J===void 0&&(typeof matchMedia=="function"?J=!!matchMedia("(pointer:coarse)").matches:J=!1),J}function Ee(e,t){const n=[];return t.forEach((o,r)=>{if(r.disabled)return;const s=Ke()?pe.coarse:pe.precise,u=Se(r),i=Ue(r.orientation,u,{x:e.clientX,y:e.clientY});i&&i.distance.x<=s&&i.distance.y<=s&&n.push(i.hitRegion)}),n}function ve(e){if(e.defaultPrevented)return;const{mountedGroups:t}=O(),n=Ee(e,t),o=new Set,r=new Set,s=new Set,u=new Map;n.forEach(i=>{o.add(i.group),i.panels.forEach(l=>{r.add(l)}),i.separator&&s.add(i.separator);const a=t.get(i.group);a&&u.set(i.group,a.layout)}),M({interactionState:{hitRegions:n,initialLayoutMap:u,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}}),n.length&&e.preventDefault()}function ge(e){if(e.defaultPrevented)return;const{interactionState:t,mountedGroups:n}=O();switch(t.state){case"active":{if(e.type!=="pointerleave"&&e.buttons===0){M(o=>o.interactionState.state==="inactive"?o:{cursorFlags:0,interactionState:{state:"inactive"}});return}Pe({event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint});break}default:{const o=Ee(e,n);o.length===0?t.state!=="inactive"&&M({interactionState:{state:"inactive"}}):M({interactionState:{hitRegions:o,state:"hover"}}),ae();break}}}function ye(e){if(e.defaultPrevented)return;e.preventDefault();const{interactionState:t}=O();switch(t.state){case"active":M({cursorFlags:0,interactionState:{state:"inactive"}}),ae()}}function Ve(e){let t=0,n=0;const o={};for(const s of e)if(s.defaultSize!==void 0){t++;const u=I(s.defaultSize);n+=u,o[s.panelId]=u}else o[s.panelId]=void 0;const r=e.length-t;if(r!==0){const s=I((100-n)/r);for(const u of e)u.defaultSize===void 0&&(o[u.panelId]=s)}return o}function qe(e,t,n){const o=n[0];if(!o)return;const r=e.panels.find(u=>u.element===t);if(!r||!r.onResize)return;const s=re({group:e});r.onResize({asPercentage:I(o.inlineSize/s*100),inPixels:o.inlineSize},r.id)}function Xe(e){let t=!0;b(e.separators.length===0||e.separators.length<e.panels.length,"Invalid Group configuration; too many Separator components");const n=new Set,o=new Set,r=new ResizeObserver(c=>{for(const m of c){const{borderBoxSize:x,target:d}=m;d===e.element?t&&M(p=>{const v=p.mountedGroups.get(e);if(v){const h=de(e),y=v.layout,z=A({layout:y,panelConstraints:h});return{mountedGroups:new Map(p.mountedGroups).set(e,{derivedPanelConstraints:h,layout:z,separatorToPanels:v.separatorToPanels})}}return p}):qe(e,d,x)}});r.observe(e.element),e.panels.forEach(c=>{b(!n.has(c.id),`Panel ids must be unique; id "${c.id}" was used more than once`),n.add(c.id),c.onResize&&r.observe(c.element)});const s=de(e),u=e.panels.map(({id:c})=>c).join(","),i=e.inMemoryLayouts[u]??e.defaultLayout??Ve(s),a=A({layout:i,panelConstraints:s}),l=Se(e),f=M(c=>({mountedGroups:new Map(c.mountedGroups).set(e,{derivedPanelConstraints:s,layout:a,separatorToPanels:new Map(l.filter(m=>m.separator).map(m=>[m.separator,m.panels]))})}));return e.element.addEventListener("pointerleave",me),e.separators.forEach(c=>{b(!o.has(c.id),`Separator ids must be unique; id "${c.id}" was used more than once`),o.add(c.id),c.element.addEventListener("keydown",he)}),f.mountedGroups.size===1&&(window.addEventListener("pointerdown",ve),window.addEventListener("pointermove",ge),window.addEventListener("pointerup",ye)),function(){t=!1;const m=M(x=>{const d=new Map(x.mountedGroups);return d.delete(e),{mountedGroups:d}});e.element.removeEventListener("pointerleave",me),e.separators.forEach(x=>{x.element.removeEventListener("keydown",he)}),m.mountedGroups.size===0&&(window.removeEventListener("pointerdown",ve),window.removeEventListener("pointermove",ge),window.removeEventListener("pointerup",ye)),r.disconnect()}}function le(e){const t=g.useId();return`${e??t}`}const j=typeof window<"u"?g.useLayoutEffect:g.useEffect;function ue(e){const t=g.useRef(e);return j(()=>{t.current=e},[e]),g.useCallback(n=>t.current?.(n),[t])}function ce(...e){return ue(t=>{e.forEach(n=>{if(n)switch(typeof n){case"function":{n(t);break}case"object":{n.current=t;break}}})})}const Ce="--react-resizable-panels--panel--pointer-events";function Me(e,t){const n=e.replace(/[^a-zA-Z0-9\-_]/g,""),o=t.replace(/[^a-zA-Z0-9\-_]/g,"");return`--react-resizable-panels--${n}--${o}`}const Ge=g.createContext(null);function Ye(e,t){const n=g.useRef({getLayout:()=>({}),setLayout:He});g.useImperativeHandle(t,()=>n.current,[]),j(()=>{Object.assign(n.current,Le({groupId:e}))})}function Ze({children:e,className:t,defaultLayout:n,disableCursor:o,disabled:r,elementRef:s,groupRef:u,id:i,onLayoutChange:a,orientation:l="horizontal",style:f,...c}){const m=g.useRef({}),x=ue(w=>{B(m.current,w)||(m.current=w,a?.(w))}),d=le(i),[p,v]=g.useState(!1),[h,y]=g.useState(null),[z,S]=g.useState(n??{}),[L,R]=g.useState([]),[E,U]=g.useState([]),ee=g.useRef({}),K=g.useRef({}),V=ce(y,s);Ye(d,u);const q=g.useMemo(()=>({id:d,orientation:l,registerPanel:w=>(R(G=>ie(l,[...G,w])),()=>{R(G=>G.filter($=>$!==w))}),registerSeparator:w=>(U(G=>ie(l,[...G,w])),()=>{U(G=>G.filter($=>$!==w))})}),[d,l]);j(()=>{if(h!==null&&L.length>0){const w={defaultLayout:n,disableCursor:!!o,disabled:!!r,element:h,id:d,inMemoryLastExpandedPanelSizes:ee.current,inMemoryLayouts:K.current,orientation:l,panels:L,separators:E},G=Xe(w),te=O().mountedGroups.get(w);te&&(S(te.layout),x?.(te.layout));const Ie=D.addListener("interactionStateChange",Y=>{switch(Y.state){case"active":case"hover":{v(Y.hitRegions.some(N=>N.group===w));break}}}),ke=D.addListener("mountedGroupsChange",Y=>{const N=Y.get(w);N&&N.derivedPanelConstraints.length>0&&(S(N.layout),x?.(N.layout))});return()=>{G(),Ie(),ke()}}},[n,o,r,h,d,x,l,L,E]);const X={[Ce]:p?"none":void 0};for(const w in z){const G=Me(d,w),$=z[w];X[G]=$}return H.jsx(Ge.Provider,{value:q,children:H.jsx("div",{...c,"aria-orientation":l,className:t,"data-group":!0,"data-testid":d,id:d,ref:V,style:{...f,...X,display:"flex",flexDirection:l==="horizontal"?"row":"column",flexWrap:"nowrap"},children:e})})}function se(e){return`react-resizable-panels:${e}`}function Je({id:e,layout:t,storage:n}){try{const o=se(e);n.setItem(o,JSON.stringify(t))}catch(o){console.error(o)}}function Qe({groupId:e,storage:t}){const n=g.useSyncExternalStore(et,()=>t.getItem(se(e)),()=>t.getItem(se(e))),o=g.useMemo(()=>n?JSON.parse(n):null,[n]),r=g.useCallback(s=>Je({id:e,layout:s,storage:t}),[e,t]);return{defaultLayout:o,onLayoutChange:r}}function et(){return function(){}}function tt(){return g.useState(null)}function nt(){return g.useRef(null)}function fe(){const e=g.useContext(Ge);return b(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function ot({groupId:e,panelId:t}){const n=()=>{const{mountedGroups:i}=O();for(const[a,{derivedPanelConstraints:l,layout:f,separatorToPanels:c}]of i)if(a.id===e)return{derivedPanelConstraints:l,group:a,layout:f,separatorToPanels:c};throw Error(`Group ${e} not found`)},o=()=>{const i=n().derivedPanelConstraints.find(a=>a.panelId===t);if(i!==void 0)return i;throw Error(`Panel constraints not found for Panel ${t}`)},r=()=>{const i=n().group.panels.find(a=>a.id===t);if(i!==void 0)return i;throw Error(`Layout not found for Panel ${t}`)},s=()=>{const i=n().layout[t];if(i!==void 0)return i;throw Error(`Layout not found for Panel ${t}`)},u=i=>{const a=s();if(i===a)return;const{derivedPanelConstraints:l,group:f,layout:c,separatorToPanels:m}=n(),x=f.panels.findIndex(h=>h.id===t),d=x===f.panels.length-1,p=W({delta:d?a-i:i-a,initialLayout:c,panelConstraints:l,pivotIndices:d?[x-1,x]:[x,x+1],prevLayout:c,trigger:"imperative-api"}),v=A({layout:p,panelConstraints:l});B(c,v)||M(h=>({mountedGroups:new Map(h.mountedGroups).set(f,{derivedPanelConstraints:l,layout:v,separatorToPanels:m})}))};return{collapse:()=>{const{collapsible:i,collapsedSize:a}=o(),l=s();i&&l!==a&&u(a)},expand:()=>{const{collapsible:i,collapsedSize:a,minSize:l}=o(),f=s();i&&f===a&&u(l)},getSize:()=>{const{group:i}=n(),a=s(),{element:l}=r(),f=i.orientation==="horizontal"?l.offsetWidth:l.offsetHeight;return{asPercentage:a,inPixels:f}},isCollapsed:()=>{const{collapsible:i,collapsedSize:a}=o(),l=s();return i&&P(a,l)},resize:i=>{if(s()!==i){let l;switch(typeof i){case"number":{const{group:f}=n(),c=re({group:f});l=I(i/c*100);break}case"string":{l=parseFloat(i);break}}u(l)}}}}function it(e,t){const{id:n}=fe(),o=g.useRef({collapse:ne,expand:ne,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:ne});g.useImperativeHandle(t,()=>o.current,[]),j(()=>{Object.assign(o.current,ot({groupId:n,panelId:e}))})}function st({children:e,className:t,collapsedSize:n=0,collapsible:o=!1,defaultSize:r,elementRef:s,id:u,maxSize:i="100",minSize:a="0",onResize:l,panelRef:f,style:c,...m}){const x=!!u,d=le(u),[p,v]=g.useState(null),h=ce(v,s),{id:y,registerPanel:z}=fe(),S=l!==null,L=ue(E=>{l?.(E,u)});j(()=>{if(p!==null)return z({element:p,id:d,idIsStable:x,onResize:S?L:void 0,panelConstraints:{collapsedSize:n,collapsible:o,defaultSize:r,maxSize:i,minSize:a}})},[n,o,r,p,S,d,x,i,a,L,z]),it(d,f);const R=Me(y,d);return H.jsx("div",{...m,"data-panel":!0,"data-testid":d,id:d,ref:h,style:{...rt,flexBasis:0,flexGrow:`var(${R}, 1)`,flexShrink:1,overflow:"hidden",pointerEvents:`var(${Ce})`},children:H.jsx("div",{className:t,style:{width:"100%",height:"100%",...c},children:e})})}const rt={minHeight:"unset",maxHeight:"unset",height:"unset",minWidth:"unset",maxWidth:"unset",width:"unset",flex:"unset",flexBasis:"unset",flexShrink:"unset",flexGrow:"unset",border:"unset",borderWidth:"unset",padding:"unset",margin:"unset"};function at(){return g.useState(null)}function lt(){return g.useRef(null)}function ut({layout:e,panelConstraints:t,panelId:n,panelIndex:o}){let r,s;const u=e[n],i=t.find(a=>a.panelId===n);if(i){const a=i.maxSize,l=s=i.collapsible?i.collapsedSize:i.minSize,f=[o,o+1];s=A({layout:W({delta:l-u,initialLayout:e,panelConstraints:t,pivotIndices:f,prevLayout:e,trigger:"keyboard"}),panelConstraints:t})[n],r=A({layout:W({delta:a-u,initialLayout:e,panelConstraints:t,pivotIndices:f,prevLayout:e,trigger:"keyboard"}),panelConstraints:t})[n]}return{valueControls:n,valueMax:r,valueMin:s,valueNow:u}}function ct({children:e,className:t,elementRef:n,id:o,style:r,...s}){const u=le(o),[i,a]=g.useState({}),[l,f]=g.useState("inactive"),[c,m]=g.useState(null),x=ce(m,n),{id:d,orientation:p,registerSeparator:v}=fe(),h=p==="horizontal"?"vertical":"horizontal";return j(()=>{if(c!==null){const y={element:c,id:u},z=v(y),S=D.addListener("interactionStateChange",R=>{f(R.state!=="inactive"&&R.hitRegions.some(E=>E.separator===y)?R.state:"inactive")}),L=D.addListener("mountedGroupsChange",R=>{R.forEach(({derivedPanelConstraints:E,layout:U,separatorToPanels:ee},K)=>{if(K.id===d){const V=ee.get(y);if(V){const q=V[0],X=K.panels.indexOf(q);a(ut({layout:U,panelConstraints:E,panelId:q.id,panelIndex:X}))}}})});return()=>{S(),L(),z()}}},[c,d,u,v]),H.jsx("div",{...s,"aria-controls":i.valueControls,"aria-orientation":h,"aria-valuemax":i.valueMax,"aria-valuemin":i.valueMin,"aria-valuenow":i.valueNow,children:e,className:t,"data-separator":l,"data-testid":u,id:u,ref:x,role:"separator",style:{flexBasis:"auto",...r,flexGrow:0,flexShrink:0},tabIndex:0})}exports.Group=Ze;exports.Panel=st;exports.Separator=ct;exports.useDefaultLayout=Qe;exports.useGroupCallbackRef=tt;exports.useGroupRef=nt;exports.usePanelCallbackRef=at;exports.usePanelRef=lt;
|
|
2
2
|
//# sourceMappingURL=react-resizable-panels.cjs.map
|