react-zeugma 2.2.2 → 2.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/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -1
- package/dist/index.d.ts +22 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ interface SplitNode {
|
|
|
11
11
|
interface PaneNode {
|
|
12
12
|
type: 'pane';
|
|
13
13
|
paneId: string;
|
|
14
|
+
locked?: boolean;
|
|
14
15
|
metadata?: Record<string, unknown>;
|
|
15
16
|
}
|
|
16
17
|
type TreeNode = SplitNode | PaneNode;
|
|
@@ -18,6 +19,8 @@ type TreeNode = SplitNode | PaneNode;
|
|
|
18
19
|
interface ZeugmaClassNames {
|
|
19
20
|
/** CSS class applied to the outer container div of each `<Pane>`. */
|
|
20
21
|
pane?: string;
|
|
22
|
+
/** CSS class applied to the pane container when locked. */
|
|
23
|
+
paneLocked?: string;
|
|
21
24
|
/** CSS class applied to drop zone indicators when hovering over layout edges to split a pane. */
|
|
22
25
|
dropPreview?: string;
|
|
23
26
|
/** CSS class applied to the drop zone indicator when hovering over the center of a pane to swap. */
|
|
@@ -28,6 +31,10 @@ interface ZeugmaClassNames {
|
|
|
28
31
|
resizer?: string;
|
|
29
32
|
/** CSS class applied to the background dismiss zone indicator during a drag-out dismiss gesture. */
|
|
30
33
|
dismissPreview?: string;
|
|
34
|
+
/** CSS class applied to root container when dashboard is globally locked. */
|
|
35
|
+
dashboardLocked?: string;
|
|
36
|
+
/** CSS class applied to drop zone indicator when hovering over a locked pane. */
|
|
37
|
+
lockedPreview?: string;
|
|
31
38
|
}
|
|
32
39
|
interface ZeugmaProps {
|
|
33
40
|
/** The layout tree model (TreeNode) defining pane organization and split percentages. Set to null for empty layout. */
|
|
@@ -74,6 +81,8 @@ interface ZeugmaProps {
|
|
|
74
81
|
dismissThreshold?: number;
|
|
75
82
|
/** Callback triggered when the drag-out/dismiss intent changes (active pane ID or null when drag returns inside bounds). */
|
|
76
83
|
onDismissIntentChange?: (paneId: string | null) => void;
|
|
84
|
+
/** Whether the layout is locked. When locked, resizing, dragging, and dropping are disabled. */
|
|
85
|
+
locked?: boolean;
|
|
77
86
|
/** Child nodes nested inside the Zeugma context, usually containing a <PaneTree> or similar layout viewer. */
|
|
78
87
|
children: ReactNode;
|
|
79
88
|
}
|
|
@@ -114,6 +123,8 @@ interface ZeugmaStateValue {
|
|
|
114
123
|
minSplitPercentage?: number;
|
|
115
124
|
/** Maximum split percentage allowed when resizing. */
|
|
116
125
|
maxSplitPercentage?: number;
|
|
126
|
+
/** Whether the layout is globally locked. */
|
|
127
|
+
locked: boolean;
|
|
117
128
|
}
|
|
118
129
|
/**
|
|
119
130
|
* Actions context — holds stable dispatch functions with permanent identity.
|
|
@@ -132,6 +143,8 @@ interface ZeugmaActionsValue {
|
|
|
132
143
|
updateSplitPercentage: (currentNode: SplitNode, percentage: number) => void;
|
|
133
144
|
/** Stable callback to update metadata for a specific pane. */
|
|
134
145
|
updatePaneMetadata: (paneId: string, updater: (current: Record<string, unknown> | undefined) => Record<string, unknown> | undefined) => void;
|
|
146
|
+
/** Stable callback to update the locked status of a specific pane in the layout tree. */
|
|
147
|
+
updatePaneLock: (paneId: string, locked: boolean) => void;
|
|
135
148
|
}
|
|
136
149
|
|
|
137
150
|
declare const useZeugmaState: () => ZeugmaStateValue;
|
|
@@ -206,6 +219,8 @@ interface PaneRenderProps {
|
|
|
206
219
|
metadata: Record<string, unknown> | undefined;
|
|
207
220
|
/** Updates the metadata of this pane using an updater function. */
|
|
208
221
|
updateMetadata: (updater: (current: Record<string, unknown> | undefined) => Record<string, unknown> | undefined) => void;
|
|
222
|
+
/** True if this specific pane or the dashboard globally is locked. */
|
|
223
|
+
locked: boolean;
|
|
209
224
|
}
|
|
210
225
|
|
|
211
226
|
interface PaneProps {
|
|
@@ -215,6 +230,8 @@ interface PaneProps {
|
|
|
215
230
|
children: (props: PaneRenderProps) => React.ReactNode;
|
|
216
231
|
/** Optional inline CSS styles applied to the pane outer container. */
|
|
217
232
|
style?: React.CSSProperties;
|
|
233
|
+
/** Optional override to lock this specific pane. */
|
|
234
|
+
locked?: boolean;
|
|
218
235
|
}
|
|
219
236
|
declare const Pane: React.FC<PaneProps>;
|
|
220
237
|
|
|
@@ -260,6 +277,10 @@ declare function findPane(tree: TreeNode | null, paneId: string): PaneNode | nul
|
|
|
260
277
|
* Update metadata on a specific pane node using an updater function.
|
|
261
278
|
*/
|
|
262
279
|
declare function updatePaneMetadata(tree: TreeNode | null, paneId: string, updater: (current: Record<string, unknown> | undefined) => Record<string, unknown> | undefined): TreeNode | null;
|
|
280
|
+
/**
|
|
281
|
+
* Update the locked status on a specific pane node in the layout tree.
|
|
282
|
+
*/
|
|
283
|
+
declare function updatePaneLock(tree: TreeNode | null, paneId: string, locked: boolean): TreeNode | null;
|
|
263
284
|
|
|
264
285
|
/**
|
|
265
286
|
* Shared drag-session lifecycle utility.
|
|
@@ -286,4 +307,4 @@ interface DragSessionConfig {
|
|
|
286
307
|
}
|
|
287
308
|
declare function createDragSession({ cursor, resizerEl, onMove, onEnd }: DragSessionConfig): void;
|
|
288
309
|
|
|
289
|
-
export { DEFAULT_DRAG_ACTIVATION_DISTANCE, DEFAULT_RESIZER_SIZE, DEFAULT_SNAP_THRESHOLD, DragHandle, type DragHandleProps, type DragSessionConfig, Pane, type PaneNode, type PaneProps, type PaneRenderProps, PaneTree, ResizableContainer, type ResizableContainerProps, type SplitDirection, type SplitNode, type TreeNode, Zeugma, type ZeugmaActionsValue, type ZeugmaClassNames, type ZeugmaProps, type ZeugmaStateValue, addPane, createDragSession, findPane, removePane, splitPane, swapPanes, updatePaneMetadata, updateSplitPercentage, useResizer, useZeugmaActions, useZeugmaState };
|
|
310
|
+
export { DEFAULT_DRAG_ACTIVATION_DISTANCE, DEFAULT_RESIZER_SIZE, DEFAULT_SNAP_THRESHOLD, DragHandle, type DragHandleProps, type DragSessionConfig, Pane, type PaneNode, type PaneProps, type PaneRenderProps, PaneTree, ResizableContainer, type ResizableContainerProps, type SplitDirection, type SplitNode, type TreeNode, Zeugma, type ZeugmaActionsValue, type ZeugmaClassNames, type ZeugmaProps, type ZeugmaStateValue, addPane, createDragSession, findPane, removePane, splitPane, swapPanes, updatePaneLock, updatePaneMetadata, updateSplitPercentage, useResizer, useZeugmaActions, useZeugmaState };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {createContext,useContext,useState,useRef,useCallback,useMemo,useEffect}from'react';import {useSensors,useSensor,DndContext,pointerWithin,useDraggable,PointerSensor,TouchSensor,useDroppable}from'@dnd-kit/core';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var
|
|
1
|
+
import {createContext,useContext,useState,useRef,useCallback,useMemo,useEffect}from'react';import {useSensors,useSensor,DndContext,pointerWithin,useDraggable,PointerSensor,TouchSensor,useDroppable}from'@dnd-kit/core';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var ve=createContext(void 0),be=createContext(void 0);var G=()=>{let e=useContext(ve);if(!e)throw new Error("useZeugmaState must be used within a Zeugma provider");return e},Te=()=>{let e=useContext(be);if(!e)throw new Error("useZeugmaActions must be used within a Zeugma provider");return e};function Ue(e){let t=useRef(null);return useEffect(()=>{if(!e){t.current=null;return}let o=n=>{t.current={x:n.clientX,y:n.clientY};},r=n=>{let i=n.touches[0]||n.changedTouches[0];i&&(t.current={x:i.clientX,y:i.clientY});};return window.addEventListener("pointermove",o,{passive:true}),window.addEventListener("touchmove",r,{passive:true}),()=>{window.removeEventListener("pointermove",o),window.removeEventListener("touchmove",r);}},[e]),t}function We(e){useEffect(()=>(e?document.body.style.setProperty("cursor","not-allowed","important"):document.body.style.removeProperty("cursor"),()=>{document.body.style.removeProperty("cursor");}),[e]);}function ae(e,t){if(e===null)return null;if(e.type==="pane")return e.paneId===t?null:e;let o=ae(e.first,t),r=ae(e.second,t);return o===null?r:r===null?o:{...e,first:o,second:r}}function ue(e,t,o,r,n){if(e===null)return typeof n=="string"?{type:"pane",paneId:n}:n;if(e.type==="pane"){if(e.paneId===t){let i=typeof n=="string"?{type:"pane",paneId:n}:n,s=r==="left"||r==="top";return {type:"split",direction:o,first:s?i:e,second:s?e:i,splitPercentage:50}}return e}return {...e,first:ue(e.first,t,o,r,n)||e.first,second:ue(e.second,t,o,r,n)||e.second}}function ze(e,t,o){if(e===null)return null;let r=B(e,t),n=B(e,o);if(!r||!n)return e;function i(s){return s.type==="pane"?s.paneId===t?{...n}:s.paneId===o?{...r}:s:{...s,first:i(s.first),second:i(s.second)}}return i(e)}function Be(e,t){if(e===null)return {type:"pane",paneId:t};function o(r,n){return r.type==="pane"?{type:"split",direction:n==="row"?"column":"row",splitPercentage:50,first:r,second:{type:"pane",paneId:t}}:{...r,second:o(r.second,r.direction)}}return o(e,null)}function te(e,t,o){return e===null?null:e===t?{...e,splitPercentage:o}:e.type==="split"?{...e,first:te(e.first,t,o)||e.first,second:te(e.second,t,o)||e.second}:e}function B(e,t){return e===null?null:e.type==="pane"?e.paneId===t?e:null:B(e.first,t)??B(e.second,t)}function he(e,t,o){if(e===null)return null;if(e.type==="pane"){if(e.paneId===t){let r=o(e.metadata);if(r===void 0){let{metadata:n,...i}=e;return i}return {...e,metadata:r}}return e}return {...e,first:he(e.first,t,o)??e.first,second:he(e.second,t,o)??e.second}}function Pe(e,t,o){if(e===null)return null;if(e.type==="pane"){if(e.paneId===t){if(o===false){let{locked:r,...n}=e;return n}return {...e,locked:o}}return e}return {...e,first:Pe(e.first,t,o)??e.first,second:Pe(e.second,t,o)??e.second}}var st=8,at=8,Xt=4;var Xe=({activeId:e,render:t,className:o})=>{let r=useRef(null);return useEffect(()=>{let n=i=>{r.current&&(r.current.style.transform=`translate(${i.clientX+12}px, ${i.clientY+12}px)`);};return document.addEventListener("pointermove",n),()=>document.removeEventListener("pointermove",n)},[]),jsx("div",{ref:r,className:o,style:{position:"fixed",top:0,left:0,zIndex:9999,pointerEvents:"none"},children:t(e)})};var xe=class extends PointerSensor{static activators=[{eventName:"onPointerDown",handler:({nativeEvent:t})=>!t.target?.closest(".drag-cancel")}]},ye=class extends TouchSensor{static activators=[{eventName:"onTouchStart",handler:({nativeEvent:t})=>!t.target?.closest(".drag-cancel")}]};function Ke(e){if(e instanceof MouseEvent||e instanceof PointerEvent)return {x:e.clientX,y:e.clientY};if(typeof TouchEvent<"u"&&e instanceof TouchEvent){let t=e.touches[0]||e.changedTouches[0];if(t)return {x:t.clientX,y:t.clientY}}return null}var vt=({layout:e,onChange:t,renderPane:o,renderDragOverlay:r,classNames:n={},fullscreenPaneId:i=null,onFullscreenChange:s,onRemove:c,dragActivationDistance:x=8,snapThreshold:y=8,onDragStart:z,onDragEnd:a,onResizeStart:R,onResize:m,onResizeEnd:d,minSplitPercentage:E=5,maxSplitPercentage:L=95,enableDragToDismiss:S=false,dismissThreshold:f=60,onDismissIntentChange:v,locked:w=false,children:D})=>{let[u,b]=useState(e),[X,N]=useState(e);e!==X&&(N(e),b(e));let[k,Z]=useState(null),[I,C]=useState(null),Y=useRef(null),g=useRef(null),A=Ue(k),W=useCallback(l=>{Y.current=l;},[]),[O,M]=useState(false);We(O);let H=useCallback(l=>o(l),[o]),oe=useMemo(()=>n,[n.pane,n.paneLocked,n.dropPreview,n.swapPreview,n.dragOverlay,n.resizer,n.dismissPreview,n.dashboardLocked,n.lockedPreview]),Le=useSensors(useSensor(xe,{activationConstraint:{distance:x}}),useSensor(ye,{activationConstraint:{delay:250,tolerance:5}})),me=l=>{let p=l.active.id.toString();Z(p);let T=l.activatorEvent;A.current=Ke(T),S&&Y.current?g.current=Y.current.getBoundingClientRect():g.current=null,z&&z(p);},re=l=>{let{over:p}=l,P=(p?.id.toString()||"").startsWith("drop-locked-");if(M(P),!S)return;let K=l.active.id.toString(),h=g.current;if(!h){I!==null&&(C(null),v?.(null));return}let J=l.activatorEvent,U=null,F=null;if(A.current)U=A.current.x,F=A.current.y;else {let $=Ke(J);$&&(U=$.x+l.delta.x,F=$.y+l.delta.y);}let Q=0;if(U!==null&&F!==null){let $=0,V=0;U<h.left?$=h.left-U:U>h.right&&($=U-h.right),F<h.top?V=h.top-F:F>h.bottom&&(V=F-h.bottom),Q=Math.sqrt($*$+V*V);}else {let $=l.active.rect.current.translated;if($){let V=$.left+$.width/2,j=$.top+$.height/2,q=0,ee=0;V<h.left?q=h.left-V:V>h.right&&(q=V-h.right),j<h.top?ee=h.top-j:j>h.bottom&&(ee=j-h.bottom),Q=Math.sqrt(q*q+ee*ee);}}Q>f?I!==K&&(C(K),v?.(K)):I!==null&&(C(null),v?.(null));},ge=l=>{Z(null),M(false);let{active:p,over:T}=l,P=p.id.toString(),K=S&&I===P;if(C(null),v?.(null),g.current=null,K){c?c(P):le(P),a&&a(P,null,null);return}if(!T){a&&a(P,null,null);return}let h=T.id.toString();if(h.startsWith("drop-locked-")){a&&a(P,null,null);return}let J=h.match(/^drop-center-(.+)$/);if(J){let[,q]=J;if(P!==q){let ee=ze(u,P,q);b(ee),t(ee);}a&&a(P,q,{type:"swap",position:"center"});return}let U=h.match(/^drop-(left|right|top|bottom)-(.+)$/);if(!U){a&&a(P,null,null);return}let[,F,Q]=U;if(P===Q){a&&a(P,null,null);return}let Ne=F==="left"||F==="right"?"row":"column",$=B(u,P)??{type:"pane",paneId:P},V=ae(u,P),j=ue(V,Q,Ne,F,$);b(j),t(j),a&&a(P,Q,{type:"split",direction:Ne,position:F});},ie=useCallback((l,p=false)=>{b(l),p||t(l);},[t]),le=useCallback(l=>{let p=ae(u,l);b(p),t(p);},[u,t]),ce=useCallback(l=>{let p=Be(u,l);b(p),t(p);},[u,t]),se=useCallback((l,p)=>{let T=ze(u,l,p);b(T),t(T);},[u,t]),Ae=useCallback((l,p,T,P)=>{let K=B(u,P)??{type:"pane",paneId:P},h=ae(u,P),J=ue(h,l,p,T,K);b(J),t(J);},[u,t]),ke=useCallback((l,p)=>{let T=te(u,l,p);b(T),t(T);},[u,t]),He=useCallback((l,p)=>{let T=he(u,l,p);b(T),t(T);},[u,t]),Fe=useCallback((l,p)=>{let T=Pe(u,l,p);b(T),t(T);},[u,t]),Oe=useCallback((l,p)=>{d&&d(l,p);},[d]),ot=useMemo(()=>({layout:u,onLayoutChange:ie,renderPane:H,activeId:k,dismissIntentId:I,setContainerRef:W,fullscreenPaneId:i,classNames:oe,onRemove:c,onFullscreenChange:s,snapThreshold:y,onResizeStart:R,onResize:m,onResizeEnd:Oe,minSplitPercentage:E,maxSplitPercentage:L,locked:w}),[u,k,I,W,i,oe,c,s,y,R,m,E,L,ie,H,Oe,w]),rt=useMemo(()=>({removePane:le,addPane:ce,swapPanes:se,splitPane:Ae,updateSplitPercentage:ke,updatePaneMetadata:He,updatePaneLock:Fe}),[le,ce,se,Ae,ke,He,Fe]);return jsx(be.Provider,{value:rt,children:jsxs(ve.Provider,{value:ot,children:[jsx(DndContext,{id:"zeugma-dnd-context",sensors:Le,collisionDetection:pointerWithin,onDragStart:me,onDragMove:re,onDragEnd:ge,children:D}),k&&r&&jsx(Xe,{activeId:k,render:r,className:`${n.dragOverlay||""} ${k===I?n.dismissPreview||"zeugma-dismiss-preview":""}`.trim()})]})})};function Se({cursor:e,resizerEl:t,onMove:o,onEnd:r}){document.body.classList.add("zeugma-resizing");let n=document.createElement("style");n.id="zeugma-global-cursor-style",n.textContent=`
|
|
2
2
|
* {
|
|
3
3
|
cursor: ${e} !important;
|
|
4
4
|
user-select: none !important;
|
|
5
5
|
}
|
|
6
|
-
`,document.head.appendChild(n),t.setAttribute("data-resizing","true");let i=c=>{o(c);},a=()=>{document.body.classList.remove("zeugma-resizing"),t.removeAttribute("data-resizing");let c=document.getElementById("zeugma-global-cursor-style");c&&c.remove(),document.removeEventListener("pointermove",i),document.removeEventListener("pointerup",a),r();};document.addEventListener("pointermove",i),document.addEventListener("pointerup",a);}function De({containerRef:e,isRow:t,direction:o,splitPercentage:r,resizerSize:n,snapThreshold:i,layout:a,currentNode:c,onLayoutChange:b,onResizeStart:P,onResizeEnd:T,parentLeft:s,parentTop:h,parentWidth:y,parentHeight:v}){let{onResizeStart:R,onResize:d,onResizeEnd:m,minSplitPercentage:I=5,maxSplitPercentage:L=95}=W();return useCallback(E=>{E.preventDefault();let p=e.current;if(!p)return;P&&P(),R&&R(c);let f=p.getBoundingClientRect(),K=E.clientX,oe=E.clientY,w=r,X=E.currentTarget,D=f.left+f.width*(s/100),Z=f.top+f.height*(h/100),V=f.width*(y/100),H=f.height*(v/100),C=Array.from(document.querySelectorAll('div[role="separator"][data-direction]')).filter(z=>z!==X&&z.getAttribute("data-direction")===o).map(z=>{let A=z.getBoundingClientRect();return t?A.left+A.width/2:A.top+A.height/2}),F=w;be({cursor:t?"col-resize":"row-resize",resizerEl:X,onMove:z=>{let A=t?(z.clientX-K)/V*100:(z.clientY-oe)/H*100,U=w+A,Se=t?D+(V-n)*(U/100)+n/2:Z+(H-n)*(U/100)+n/2,ce=1/0,B=null;for(let re of C){let j=Math.abs(Se-re);j<i&&j<ce&&(ce=j,B=re);}let J=U;B!==null&&(J=t?(B-n/2-D)/(V-n)*100:(B-n/2-Z)/(H-n)*100);let Q=Math.max(I,Math.min(L,J));F=Q;let ue=G(a,c,Q);b(ue,true),d&&d(c,Q);},onEnd:()=>{let z=G(a,c,F);b(z),T&&T(),m&&m(c,F);}});},[e,t,o,r,n,i,a,c,b,P,T,R,d,m,I,L,s,h,y,v])}function se(e,t=0,o=0,r=100,n=100,i="root"){if(e.type==="pane")return {panes:[{paneId:e.paneId,left:t,top:o,width:r,height:n,node:e}],splitters:[]};let{direction:a,splitPercentage:c,first:b,second:P}=e,s={id:`splitter-${i}-${a}`,currentNode:e,direction:a,left:a==="row"?t+r*(c/100):t,top:a==="column"?o+n*(c/100):o,width:a==="row"?0:r,height:a==="column"?0:n,parentLeft:t,parentTop:o,parentWidth:r,parentHeight:n},h={panes:[],splitters:[]},y={panes:[],splitters:[]};if(a==="row"){let v=r*(c/100);h=se(b,t,o,v,n,`${i}-L`),y=se(P,t+v,o,r-v,n,`${i}-R`);}else {let v=n*(c/100);h=se(b,t,o,r,v,`${i}-T`),y=se(P,t,o+v,r,n-v,`${i}-B`);}return {panes:[...h.panes,...y.panes],splitters:[s,...h.splitters,...y.splitters]}}var vt=({splitter:e,resizerSize:t,snapThreshold:o,containerRef:r})=>{let{layout:n,onLayoutChange:i,classNames:a}=W(),[c,b]=useState(false),{currentNode:P,direction:T,left:s,top:h,width:y,height:v,parentLeft:R,parentTop:d,parentWidth:m,parentHeight:I}=e,L=T==="row",E=De({containerRef:r,isRow:L,direction:T,splitPercentage:P.splitPercentage,resizerSize:t,snapThreshold:o,layout:n,currentNode:P,onLayoutChange:i,onResizeStart:()=>b(true),onResizeEnd:()=>b(false),parentLeft:R,parentTop:d,parentWidth:m,parentHeight:I}),p=L?{position:"absolute",left:`calc(${s}% - ${t/2}px)`,top:`${h}%`,width:`${t}px`,height:`${v}%`,cursor:"col-resize",zIndex:10,userSelect:"none",touchAction:"none",boxSizing:"border-box"}:{position:"absolute",left:`${s}%`,top:`calc(${h}% - ${t/2}px)`,width:`${y}%`,height:`${t}px`,cursor:"row-resize",zIndex:10,userSelect:"none",touchAction:"none",boxSizing:"border-box"};return jsx("div",{className:`zeugma-resizer ${a.resizer||""}`.trim(),"data-direction":T,"data-resizing":c||void 0,style:p,onPointerDown:E,role:"separator","aria-valuenow":P.splitPercentage,"aria-valuemin":5,"aria-valuemax":95})},bt=({tree:e,resizerSize:t=4,snapThreshold:o})=>{let{layout:r,renderPane:n,activeId:i,dismissIntentId:a,setContainerRef:c,fullscreenPaneId:b,snapThreshold:P}=W(),T=o!==void 0?o:P??8,s=e!==void 0?e:r,h=useRef(null),{panes:y,splitters:v}=useMemo(()=>s?se(s):{panes:[],splitters:[]},[s]);if(!s)return null;let R=()=>jsxs(Fragment,{children:[y.map(d=>{let m=b===d.paneId;return jsx("div",{style:{position:"absolute",left:m?"0%":`${d.left}%`,top:m?"0%":`${d.top}%`,width:m?"100%":`${d.width}%`,height:m?"100%":`${d.height}%`,overflow:"hidden",zIndex:m?20:1,display:b&&!m?"none":"block",padding:m?"0px":`${t/2}px`,boxSizing:"border-box"},children:n(d.paneId)},d.paneId)}),!b&&v.map(d=>jsx(vt,{splitter:d,resizerSize:t,snapThreshold:T,containerRef:h},d.id))]});return e===void 0?jsx("div",{ref:I=>{c(I),h.current=I;},className:`zeugma-dashboard-root ${i!==null&&i===a?"zeugma-dashboard-dismiss-active":""}`.trim(),style:{position:"relative",width:"100%",height:"100%",overflow:"hidden"},children:R()}):jsx("div",{ref:h,style:{position:"relative",width:"100%",height:"100%",overflow:"hidden"},children:R()})};var Xe="zeugma-height:",yt="default-pane";function Rt(e){try{let t=localStorage.getItem(Xe+e);if(t!==null){let o=Number(t);if(Number.isFinite(o)&&o>0)return o}}catch{}return null}function We(e,t){try{localStorage.setItem(Xe+e,String(Math.round(t)));}catch{}}var Be=({children:e,active:t=true,height:o,onHeightChange:r,minHeight:n=100,maxHeight:i=1/0,persist:a,localStorageKey:c,resizerHeight:b=6,className:P,resizerClassName:T})=>{let s=a?c||yt:null,h=()=>{let E=(s?Rt(s):null)??o??400;return he(E,n,i)},[y,v]=useState(h),R=useRef(null),d=s?y:o??y,m=useRef(o);useEffect(()=>{if(o!==void 0&&o!==m.current){let E=he(o,n,i);v(E),s&&We(s,E);}m.current=o;},[o,n,i,s]);let I=useCallback(()=>i,[i]),L=useCallback(E=>{E.preventDefault();let p=E.clientY,f=d,K=I(),oe=E.currentTarget,w=qe(R.current),X=w?w.scrollTop:0,D=p,Z=null,V=(x,C)=>{let F=C-X,A=x-p+F,U=he(f+A,n,K);return R.current&&(R.current.style.height=`${U}px`),U},H=()=>{if(!w)return;let x=w===document.documentElement||w===document.body?{top:0,bottom:window.innerHeight}:w.getBoundingClientRect(),C=40,F=10,z=0;D>x.bottom-C?z=Math.min(1,(D-(x.bottom-C))/C)*F:D<x.top+C&&(z=-Math.min(1,(x.top+C-D)/C)*F),z!==0&&(w.scrollTop+=z,V(D,w.scrollTop)),Z=requestAnimationFrame(H);};Z=requestAnimationFrame(H),be({cursor:"row-resize",resizerEl:oe,onMove:x=>{D=x.clientY,w&&V(D,w.scrollTop);},onEnd:()=>{Z!==null&&cancelAnimationFrame(Z);let x=f;R.current&&(x=R.current.getBoundingClientRect().height),x=he(x,n,K),v(x),r&&r(x),s&&We(s,x);}});},[d,n,I,r,s]);return t?jsxs("div",{ref:R,className:`zeugma-resizable-container ${P||""}`.trim(),style:{height:`${d}px`,position:"relative",overflow:"hidden",boxSizing:"border-box"},children:[jsx("div",{style:{height:`calc(100% - ${b}px)`,overflow:"hidden"},children:e}),jsx("div",{className:`zeugma-resizable-handle ${T||""}`.trim(),style:{height:`${b}px`,cursor:"row-resize",position:"relative",zIndex:10,userSelect:"none",touchAction:"none",boxSizing:"border-box",flexShrink:0},onPointerDown:L,role:"separator","aria-orientation":"horizontal","aria-valuenow":Math.round(d),"aria-valuemin":n,"aria-valuemax":i===1/0?void 0:i})]}):jsx("div",{className:`zeugma-resizable-container disabled ${P||""}`.trim(),style:{height:"100%",position:"relative",overflow:"hidden",boxSizing:"border-box"},children:jsx("div",{style:{height:"100%",overflow:"hidden"},children:e})})};function he(e,t,o){return Math.max(t,Math.min(o,e))}function qe(e){if(typeof window>"u"||!e)return null;let t=e.parentElement;if(!t)return document.documentElement;let r=window.getComputedStyle(t).overflowY;return r==="auto"||r==="scroll"?t:qe(t)}var xe=createContext(null);var Dt={top:{position:"absolute",top:0,left:"25%",width:"50%",height:"25%",zIndex:20,pointerEvents:"auto"},bottom:{position:"absolute",bottom:0,left:"25%",width:"50%",height:"25%",zIndex:20,pointerEvents:"auto"},left:{position:"absolute",top:"25%",left:0,width:"25%",height:"50%",zIndex:20,pointerEvents:"auto"},right:{position:"absolute",top:"25%",right:0,width:"25%",height:"50%",zIndex:20,pointerEvents:"auto"},center:{position:"absolute",top:"25%",left:"25%",width:"50%",height:"50%",zIndex:20,pointerEvents:"auto"}},zt={top:{position:"absolute",top:0,left:0,right:0,height:"50%",zIndex:21,pointerEvents:"none",boxSizing:"border-box"},bottom:{position:"absolute",bottom:0,left:0,right:0,height:"50%",zIndex:21,pointerEvents:"none",boxSizing:"border-box"},left:{position:"absolute",top:0,bottom:0,left:0,width:"50%",zIndex:21,pointerEvents:"none",boxSizing:"border-box"},right:{position:"absolute",top:0,bottom:0,right:0,width:"50%",zIndex:21,pointerEvents:"none",boxSizing:"border-box"},center:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:21,pointerEvents:"none",boxSizing:"border-box"}},Ge=({id:e,position:t,activeClassName:o})=>{let{setNodeRef:r,isOver:n}=useDroppable({id:e});return jsxs(Fragment,{children:[jsx("div",{ref:r,style:Dt[t]}),n&&jsx("div",{className:o,style:zt[t]})]})},Lt=({id:e,children:t,style:o})=>{let{layout:r,activeId:n,classNames:i,fullscreenPaneId:a,onRemove:c,onFullscreenChange:b}=W(),{removePane:P,updatePaneMetadata:T}=we(),s=n!==null&&n!==e,{attributes:h,listeners:y,setNodeRef:v,isDragging:R}=useDraggable({id:e}),d=n===e||R,m=a===e,L=useMemo(()=>O(r,e),[r,e])?.metadata,E=useMemo(()=>({isDragging:d,isFullscreen:m,toggleFullscreen:()=>b?.(m?null:e),remove:()=>{m&&b?.(null),c?c(e):P(e);},metadata:L,updateMetadata:f=>{T(e,f);}}),[d,m,b,e,c,P,L,T]),p=useMemo(()=>({...y,...h}),[y,h]);return jsx(xe.Provider,{value:p,children:jsxs("div",{ref:v,className:i.pane,style:{position:"relative",width:"100%",height:"100%",...o},children:[t(E),s&&jsxs("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:15,pointerEvents:"none"},children:[["top","bottom","left","right"].map(f=>jsx(Ge,{id:`drop-${f}-${e}`,position:f,activeClassName:i.dropPreview},f)),jsx(Ge,{id:`drop-center-${e}`,position:"center",activeClassName:i.swapPreview})]})]})})};var Mt=({children:e,className:t,style:o})=>{let r=useContext(xe);if(!r)throw new Error("<DragHandle> must be used inside a <Pane>");return jsx("div",{className:t,style:{cursor:"grab",userSelect:"none",touchAction:"none",...o},...r,children:e})};export{tt as DEFAULT_DRAG_ACTIVATION_DISTANCE,Yt as DEFAULT_RESIZER_SIZE,et as DEFAULT_SNAP_THRESHOLD,Mt as DragHandle,Lt as Pane,bt as PaneTree,Be as ResizableContainer,ut as Zeugma,Fe as addPane,be as createDragSession,O as findPane,ne as removePane,ie as splitPane,Ee as swapPanes,me as updatePaneMetadata,G as updateSplitPercentage,De as useResizer,we as useZeugmaActions,W as useZeugmaState};//# sourceMappingURL=index.js.map
|
|
6
|
+
`,document.head.appendChild(n),t.setAttribute("data-resizing","true");let i=c=>{o(c);},s=()=>{document.body.classList.remove("zeugma-resizing"),t.removeAttribute("data-resizing");let c=document.getElementById("zeugma-global-cursor-style");c&&c.remove(),document.removeEventListener("pointermove",i),document.removeEventListener("pointerup",s),r();};document.addEventListener("pointermove",i),document.addEventListener("pointerup",s);}function Ce({containerRef:e,isRow:t,direction:o,splitPercentage:r,resizerSize:n,snapThreshold:i,layout:s,currentNode:c,onLayoutChange:x,onResizeStart:y,onResizeEnd:z,parentLeft:a,parentTop:R,parentWidth:m,parentHeight:d}){let{onResizeStart:E,onResize:L,onResizeEnd:S,minSplitPercentage:f=5,maxSplitPercentage:v=95,locked:w=false}=G();return useCallback(D=>{if(w)return;D.preventDefault();let u=e.current;if(!u)return;y&&y(),E&&E(c);let b=u.getBoundingClientRect(),X=D.clientX,N=D.clientY,k=r,Z=D.currentTarget,I=b.left+b.width*(a/100),C=b.top+b.height*(R/100),Y=b.width*(m/100),g=b.height*(d/100),W=Array.from(document.querySelectorAll('div[role="separator"][data-direction]')).filter(M=>M!==Z&&M.getAttribute("data-direction")===o).map(M=>{let H=M.getBoundingClientRect();return t?H.left+H.width/2:H.top+H.height/2}),O=k;Se({cursor:t?"col-resize":"row-resize",resizerEl:Z,onMove:M=>{let H=t?(M.clientX-X)/Y*100:(M.clientY-N)/g*100,oe=k+H,Le=t?I+(Y-n)*(oe/100)+n/2:C+(g-n)*(oe/100)+n/2,me=1/0,re=null;for(let ce of W){let se=Math.abs(Le-ce);se<i&&se<me&&(me=se,re=ce);}let ge=oe;re!==null&&(ge=t?(re-n/2-I)/(Y-n)*100:(re-n/2-C)/(g-n)*100);let ie=Math.max(f,Math.min(v,ge));O=ie;let le=te(s,c,ie);x(le,true),L&&L(c,ie);},onEnd:()=>{let M=te(s,c,O);x(M),z&&z(),S&&S(c,O);}});},[e,t,o,r,n,i,s,c,x,y,z,E,L,S,f,v,a,R,m,d])}function pe(e,t=0,o=0,r=100,n=100,i="root"){if(e.type==="pane")return {panes:[{paneId:e.paneId,left:t,top:o,width:r,height:n,node:e}],splitters:[]};let{direction:s,splitPercentage:c,first:x,second:y}=e,a={id:`splitter-${i}-${s}`,currentNode:e,direction:s,left:s==="row"?t+r*(c/100):t,top:s==="column"?o+n*(c/100):o,width:s==="row"?0:r,height:s==="column"?0:n,parentLeft:t,parentTop:o,parentWidth:r,parentHeight:n},R={panes:[],splitters:[]},m={panes:[],splitters:[]};if(s==="row"){let d=r*(c/100);R=pe(x,t,o,d,n,`${i}-L`),m=pe(y,t+d,o,r-d,n,`${i}-R`);}else {let d=n*(c/100);R=pe(x,t,o,r,d,`${i}-T`),m=pe(y,t,o+d,r,n-d,`${i}-B`);}return {panes:[...R.panes,...m.panes],splitters:[a,...R.splitters,...m.splitters]}}var St=({splitter:e,resizerSize:t,snapThreshold:o,containerRef:r})=>{let{layout:n,onLayoutChange:i,classNames:s,locked:c}=G(),[x,y]=useState(false),{currentNode:z,direction:a,left:R,top:m,width:d,height:E,parentLeft:L,parentTop:S,parentWidth:f,parentHeight:v}=e,w=a==="row",D=Ce({containerRef:r,isRow:w,direction:a,splitPercentage:z.splitPercentage,resizerSize:t,snapThreshold:o,layout:n,currentNode:z,onLayoutChange:i,onResizeStart:()=>y(true),onResizeEnd:()=>y(false),parentLeft:L,parentTop:S,parentWidth:f,parentHeight:v}),u=w?{position:"absolute",left:`calc(${R}% - ${t/2}px)`,top:`${m}%`,width:`${t}px`,height:`${E}%`,cursor:c?"default":"col-resize",pointerEvents:c?"none":"auto",zIndex:10,userSelect:"none",touchAction:"none",boxSizing:"border-box"}:{position:"absolute",left:`${R}%`,top:`calc(${m}% - ${t/2}px)`,width:`${d}%`,height:`${t}px`,cursor:c?"default":"row-resize",pointerEvents:c?"none":"auto",zIndex:10,userSelect:"none",touchAction:"none",boxSizing:"border-box"};return jsx("div",{className:`zeugma-resizer ${s.resizer||""}`.trim(),"data-direction":a,"data-resizing":x||void 0,style:u,onPointerDown:D,role:"separator","aria-valuenow":z.splitPercentage,"aria-valuemin":5,"aria-valuemax":95})},wt=({tree:e,resizerSize:t=4,snapThreshold:o})=>{let{layout:r,renderPane:n,activeId:i,dismissIntentId:s,setContainerRef:c,fullscreenPaneId:x,snapThreshold:y,locked:z,classNames:a}=G(),R=o!==void 0?o:y??8,m=e!==void 0?e:r,d=useRef(null),{panes:E,splitters:L}=useMemo(()=>m?pe(m):{panes:[],splitters:[]},[m]);if(!m)return null;let S=()=>jsxs(Fragment,{children:[E.map(f=>{let v=x===f.paneId;return jsx("div",{style:{position:"absolute",left:v?"0%":`${f.left}%`,top:v?"0%":`${f.top}%`,width:v?"100%":`${f.width}%`,height:v?"100%":`${f.height}%`,overflow:"hidden",zIndex:v?20:1,display:x&&!v?"none":"block",padding:v?"0px":`${t/2}px`,boxSizing:"border-box"},children:n(f.paneId)},f.paneId)}),!x&&L.map(f=>jsx(St,{splitter:f,resizerSize:t,snapThreshold:R,containerRef:d},f.id))]});if(e===void 0){let f=i!==null&&i===s,v=D=>{c(D),d.current=D;},w=`zeugma-dashboard-root ${f?"zeugma-dashboard-dismiss-active":""} ${z?a.dashboardLocked||"zeugma-dashboard-locked":""}`.trim();return jsx("div",{ref:v,className:w,style:{position:"relative",width:"100%",height:"100%",overflow:"hidden"},children:S()})}return jsx("div",{ref:d,style:{position:"relative",width:"100%",height:"100%",overflow:"hidden"},children:S()})};var et="zeugma-height:",Tt="default-pane";function zt(e){try{let t=localStorage.getItem(et+e);if(t!==null){let o=Number(t);if(Number.isFinite(o)&&o>0)return o}}catch{}return null}function je(e,t){try{localStorage.setItem(et+e,String(Math.round(t)));}catch{}}var tt=({children:e,active:t=true,height:o,onHeightChange:r,minHeight:n=100,maxHeight:i=1/0,persist:s,localStorageKey:c,resizerHeight:x=6,className:y,resizerClassName:z})=>{let a=s?c||Tt:null,R=()=>{let w=(a?zt(a):null)??o??400;return we(w,n,i)},[m,d]=useState(R),E=useRef(null),L=a?m:o??m,S=useRef(o);useEffect(()=>{if(o!==void 0&&o!==S.current){let w=we(o,n,i);d(w),a&&je(a,w);}S.current=o;},[o,n,i,a]);let f=useCallback(()=>i,[i]),v=useCallback(w=>{w.preventDefault();let D=w.clientY,u=L,b=f(),X=w.currentTarget,N=nt(E.current),k=N?N.scrollTop:0,Z=D,I=null,C=(g,A)=>{let W=A-k,M=g-D+W,H=we(u+M,n,b);return E.current&&(E.current.style.height=`${H}px`),H},Y=()=>{if(!N)return;let g=N===document.documentElement||N===document.body?{top:0,bottom:window.innerHeight}:N.getBoundingClientRect(),A=40,W=10,O=0;Z>g.bottom-A?O=Math.min(1,(Z-(g.bottom-A))/A)*W:Z<g.top+A&&(O=-Math.min(1,(g.top+A-Z)/A)*W),O!==0&&(N.scrollTop+=O,C(Z,N.scrollTop)),I=requestAnimationFrame(Y);};I=requestAnimationFrame(Y),Se({cursor:"row-resize",resizerEl:X,onMove:g=>{Z=g.clientY,N&&C(Z,N.scrollTop);},onEnd:()=>{I!==null&&cancelAnimationFrame(I);let g=u;E.current&&(g=E.current.getBoundingClientRect().height),g=we(g,n,b),d(g),r&&r(g),a&&je(a,g);}});},[L,n,f,r,a]);return t?jsxs("div",{ref:E,className:`zeugma-resizable-container ${y||""}`.trim(),style:{height:`${L}px`,position:"relative",overflow:"hidden",boxSizing:"border-box"},children:[jsx("div",{style:{height:`calc(100% - ${x}px)`,overflow:"hidden"},children:e}),jsx("div",{className:`zeugma-resizable-handle ${z||""}`.trim(),style:{height:`${x}px`,cursor:"row-resize",position:"relative",zIndex:10,userSelect:"none",touchAction:"none",boxSizing:"border-box",flexShrink:0},onPointerDown:v,role:"separator","aria-orientation":"horizontal","aria-valuenow":Math.round(L),"aria-valuemin":n,"aria-valuemax":i===1/0?void 0:i})]}):jsx("div",{className:`zeugma-resizable-container disabled ${y||""}`.trim(),style:{height:"100%",position:"relative",overflow:"hidden",boxSizing:"border-box"},children:jsx("div",{style:{height:"100%",overflow:"hidden"},children:e})})};function we(e,t,o){return Math.max(t,Math.min(o,e))}function nt(e){if(typeof window>"u"||!e)return null;let t=e.parentElement;if(!t)return document.documentElement;let r=window.getComputedStyle(t).overflowY;return r==="auto"||r==="scroll"?t:nt(t)}var Ee=createContext(null);var $t={top:{position:"absolute",top:0,left:"25%",width:"50%",height:"25%",zIndex:20,pointerEvents:"auto"},bottom:{position:"absolute",bottom:0,left:"25%",width:"50%",height:"25%",zIndex:20,pointerEvents:"auto"},left:{position:"absolute",top:"25%",left:0,width:"25%",height:"50%",zIndex:20,pointerEvents:"auto"},right:{position:"absolute",top:"25%",right:0,width:"25%",height:"50%",zIndex:20,pointerEvents:"auto"},center:{position:"absolute",top:"25%",left:"25%",width:"50%",height:"50%",zIndex:20,pointerEvents:"auto"},full:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:20,pointerEvents:"auto",cursor:"not-allowed"}},Zt={top:{position:"absolute",top:0,left:0,right:0,height:"50%",zIndex:21,pointerEvents:"none",boxSizing:"border-box"},bottom:{position:"absolute",bottom:0,left:0,right:0,height:"50%",zIndex:21,pointerEvents:"none",boxSizing:"border-box"},left:{position:"absolute",top:0,bottom:0,left:0,width:"50%",zIndex:21,pointerEvents:"none",boxSizing:"border-box"},right:{position:"absolute",top:0,bottom:0,right:0,width:"50%",zIndex:21,pointerEvents:"none",boxSizing:"border-box"},center:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:21,pointerEvents:"none",boxSizing:"border-box"},full:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:21,pointerEvents:"none",boxSizing:"border-box"}},$e=({id:e,position:t,activeClassName:o})=>{let{setNodeRef:r,isOver:n}=useDroppable({id:e});return jsxs(Fragment,{children:[jsx("div",{ref:r,style:$t[t]}),n&&jsx("div",{className:o,style:Zt[t]})]})},At=({id:e,children:t,style:o,locked:r=false})=>{let{layout:n,activeId:i,classNames:s,fullscreenPaneId:c,onRemove:x,onFullscreenChange:y,locked:z}=G(),{removePane:a,updatePaneMetadata:R}=Te(),m=useMemo(()=>B(n,e),[n,e]),d=m?.metadata,E=m?.locked??false,L=r||E,S=z||L,f=z||L,v=i!==null&&i!==e&&!f,{attributes:w,listeners:D,setNodeRef:u,isDragging:b}=useDraggable({id:e,disabled:S}),X=i===e||b,N=c===e,k=useMemo(()=>({isDragging:X,isFullscreen:N,toggleFullscreen:()=>y?.(N?null:e),remove:()=>{N&&y?.(null),x?x(e):a(e);},metadata:d,updateMetadata:C=>{R(e,C);},locked:S}),[X,N,y,e,x,a,d,R,S]),Z=useMemo(()=>S?{disabled:true}:{...D,...w},[D,w,S]),I=`${s.pane||""} ${L?s.paneLocked||"zeugma-pane-locked":""}`.trim();return jsx(Ee.Provider,{value:Z,children:jsxs("div",{ref:u,className:I,style:{position:"relative",width:"100%",height:"100%",...o},children:[t(k),v&&jsxs("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:15,pointerEvents:"none"},children:[["top","bottom","left","right"].map(C=>jsx($e,{id:`drop-${C}-${e}`,position:C,activeClassName:s.dropPreview},C)),jsx($e,{id:`drop-center-${e}`,position:"center",activeClassName:s.swapPreview})]}),i!==null&&i!==e&&f&&jsx("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:15,pointerEvents:"none"},children:jsx($e,{id:`drop-locked-${e}`,position:"full",activeClassName:s.lockedPreview||"zeugma-locked-preview"})})]})})};var Ft=({children:e,className:t,style:o})=>{let r=useContext(Ee);if(!r)throw new Error("<DragHandle> must be used inside a <Pane>");let{disabled:n,...i}=r;return jsx("div",{className:t,style:{cursor:n?"default":"grab",userSelect:n?"auto":"none",touchAction:n?"auto":"none",...o},...n?{}:i,children:e})};export{at as DEFAULT_DRAG_ACTIVATION_DISTANCE,Xt as DEFAULT_RESIZER_SIZE,st as DEFAULT_SNAP_THRESHOLD,Ft as DragHandle,At as Pane,wt as PaneTree,tt as ResizableContainer,vt as Zeugma,Be as addPane,Se as createDragSession,B as findPane,ae as removePane,ue as splitPane,ze as swapPanes,Pe as updatePaneLock,he as updatePaneMetadata,te as updateSplitPercentage,Ce as useResizer,Te as useZeugmaActions,G as useZeugmaState};//# sourceMappingURL=index.js.map
|
|
7
7
|
//# sourceMappingURL=index.js.map
|