@zag-js/splitter 0.53.0 → 0.54.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.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +692 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +657 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
- package/src/splitter.connect.ts +15 -13
- package/src/splitter.types.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,693 @@
|
|
|
1
|
-
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var src_exports={};__export(src_exports,{anatomy:()=>anatomy,connect:()=>connect,machine:()=>machine,panelProps:()=>panelProps,props:()=>props,resizeTriggerProps:()=>resizeTriggerProps,splitPanelProps:()=>splitPanelProps,splitProps:()=>splitProps,splitResizeTriggerProps:()=>splitResizeTriggerProps});module.exports=__toCommonJS(src_exports);var import_anatomy=require("@zag-js/anatomy");var anatomy=(0,import_anatomy.createAnatomy)("splitter").parts("root","panel","resizeTrigger");var parts=anatomy.build();var import_dom_event=require("@zag-js/dom-event");var import_dom_query2=require("@zag-js/dom-query");var import_dom_query=require("@zag-js/dom-query");var dom=(0,import_dom_query.createScope)({getRootId:ctx=>ctx.ids?.root??`splitter:${ctx.id}`,getResizeTriggerId:(ctx,id)=>ctx.ids?.resizeTrigger?.(id)??`splitter:${ctx.id}:splitter:${id}`,getLabelId:ctx=>ctx.ids?.label??`splitter:${ctx.id}:label`,getPanelId:(ctx,id)=>ctx.ids?.panel?.(id)??`splitter:${ctx.id}:panel:${id}`,globalCursorId:ctx=>`splitter:${ctx.id}:global-cursor`,getRootEl:ctx=>dom.getById(ctx,dom.getRootId(ctx)),getResizeTriggerEl:(ctx,id)=>dom.getById(ctx,dom.getResizeTriggerId(ctx,id)),getPanelEl:(ctx,id)=>dom.getById(ctx,dom.getPanelId(ctx,id)),getCursor(ctx){const x=ctx.isHorizontal;let cursor=x?"col-resize":"row-resize";if(ctx.activeResizeState.isAtMin)cursor=x?"e-resize":"s-resize";if(ctx.activeResizeState.isAtMax)cursor=x?"w-resize":"n-resize";return cursor},getPanelStyle(ctx,id){const flexGrow=ctx.panels.find(panel=>panel.id===id)?.size??"0";return{flexBasis:0,flexGrow,flexShrink:1,overflow:"hidden"}},getActiveHandleEl(ctx){const activeId=ctx.activeResizeId;if(activeId==null)return;return dom.getById(ctx,dom.getResizeTriggerId(ctx,activeId))},getResizeTriggerEls(ctx){const ownerId=CSS.escape(dom.getRootId(ctx));return(0,import_dom_query.queryAll)(dom.getRootEl(ctx),`[role=separator][data-ownedby='${ownerId}']`)},setupGlobalCursor(ctx){const styleEl=dom.getById(ctx,dom.globalCursorId(ctx));const textContent=`* { cursor: ${dom.getCursor(ctx)} !important; }`;if(styleEl){styleEl.textContent=textContent}else{const style=dom.getDoc(ctx).createElement("style");style.id=dom.globalCursorId(ctx);style.textContent=textContent;dom.getDoc(ctx).head.appendChild(style)}},removeGlobalCursor(ctx){dom.getById(ctx,dom.globalCursorId(ctx))?.remove()}});function validateSize(key,size){if(Math.floor(size)>100){throw new Error(`Total ${key} of panels cannot be greater than 100`)}}function getNormalizedPanels(ctx){let numOfPanelsWithoutSize=0;let totalSize=0;let totalMinSize=0;const panels=ctx.size.map(panel=>{const minSize=panel.minSize??0;const maxSize=panel.maxSize??100;totalMinSize+=minSize;if(panel.size==null){numOfPanelsWithoutSize++}else{totalSize+=panel.size}return{...panel,minSize,maxSize}});validateSize("minSize",totalMinSize);validateSize("size",totalSize);let end=0;let remainingSize=0;const result=panels.map(panel=>{let start=end;if(panel.size!=null){end+=panel.size;remainingSize=panel.size-panel.minSize;return{...panel,start,end,remainingSize}}const size=(100-totalSize)/numOfPanelsWithoutSize;end+=size;remainingSize=size-panel.minSize;return{...panel,size,start,end,remainingSize}});return result}function getHandlePanels(ctx,id=ctx.activeResizeId){const[beforeId,afterId]=id?.split(":")??[];if(!beforeId||!afterId)return;const beforeIndex=ctx.previousPanels.findIndex(panel=>panel.id===beforeId);const afterIndex=ctx.previousPanels.findIndex(panel=>panel.id===afterId);if(beforeIndex===-1||afterIndex===-1)return;const before=ctx.previousPanels[beforeIndex];const after=ctx.previousPanels[afterIndex];return{before:{...before,index:beforeIndex},after:{...after,index:afterIndex}}}function getHandleBounds(ctx,id=ctx.activeResizeId){const panels=getHandlePanels(ctx,id);if(!panels)return;const{before,after}=panels;return{min:Math.max(before.start+before.minSize,after.end-after.maxSize),max:Math.min(after.end-after.minSize,before.maxSize+before.start)}}function getPanelBounds(ctx,id){const bounds=getHandleBounds(ctx,id);const panels=getHandlePanels(ctx,id);if(!bounds||!panels)return;const{before,after}=panels;const beforeMin=Math.abs(before.start-bounds.min);const afterMin=after.size+(before.size-beforeMin);const beforeMax=Math.abs(before.start-bounds.max);const afterMax=after.size-(beforeMax-before.size);return{before:{index:before.index,min:beforeMin,max:beforeMax,isAtMin:beforeMin===before.size,isAtMax:beforeMax===before.size,up(step){return Math.min(before.size+step,beforeMax)},down(step){return Math.max(before.size-step,beforeMin)}},after:{index:after.index,min:afterMin,max:afterMax,isAtMin:afterMin===after.size,isAtMax:afterMax===after.size,up(step){return Math.min(after.size+step,afterMin)},down(step){return Math.max(after.size-step,afterMax)}}}}function clamp(value,min,max){return Math.min(Math.max(value,min),max)}function connect(state,send,normalize){const horizontal=state.context.isHorizontal;const focused=state.hasTag("focus");const dragging=state.matches("dragging");const panels=state.context.panels;function getResizeTriggerState(props2){const{id,disabled}=props2;const ids=id.split(":");const panelIds=ids.map(id2=>dom.getPanelId(state.context,id2));const panels2=getHandleBounds(state.context,id);return{disabled:!!disabled,focused:state.context.activeResizeId===id&&focused,panelIds,min:panels2?.min,max:panels2?.max,value:0}}return{focused,dragging,getResizeTriggerState,bounds:getHandleBounds(state.context),setToMinSize(id){const panel=panels.find(panel2=>panel2.id===id);send({type:"SET_PANEL_SIZE",id,size:panel?.minSize,src:"setToMinSize"})},setToMaxSize(id){const panel=panels.find(panel2=>panel2.id===id);send({type:"SET_PANEL_SIZE",id,size:panel?.maxSize,src:"setToMaxSize"})},setSize(id,size){send({type:"SET_PANEL_SIZE",id,size})},rootProps:normalize.element({...parts.root.attrs,"data-orientation":state.context.orientation,id:dom.getRootId(state.context),dir:state.context.dir,style:{display:"flex",flexDirection:horizontal?"row":"column",height:"100%",width:"100%",overflow:"hidden"}}),getPanelProps(props2){const{id}=props2;return normalize.element({...parts.panel.attrs,"data-orientation":state.context.orientation,dir:state.context.dir,id:dom.getPanelId(state.context,id),"data-ownedby":dom.getRootId(state.context),style:dom.getPanelStyle(state.context,id)})},getResizeTriggerProps(props2){const{id,disabled,step=1}=props2;const triggerState=getResizeTriggerState(props2);return normalize.element({...parts.resizeTrigger.attrs,dir:state.context.dir,id:dom.getResizeTriggerId(state.context,id),role:"separator","data-ownedby":dom.getRootId(state.context),tabIndex:disabled?void 0:0,"aria-valuenow":triggerState.value,"aria-valuemin":triggerState.min,"aria-valuemax":triggerState.max,"data-orientation":state.context.orientation,"aria-orientation":state.context.orientation,"aria-controls":triggerState.panelIds.join(" "),"data-focus":(0,import_dom_query2.dataAttr)(triggerState.focused),"data-disabled":(0,import_dom_query2.dataAttr)(disabled),style:{touchAction:"none",userSelect:"none",flex:"0 0 auto",pointerEvents:dragging&&!triggerState.focused?"none":void 0,cursor:horizontal?"col-resize":"row-resize",[horizontal?"minHeight":"minWidth"]:"0"},onPointerDown(event){if(disabled){event.preventDefault();return}send({type:"POINTER_DOWN",id});event.currentTarget.setPointerCapture(event.pointerId);event.preventDefault();event.stopPropagation()},onPointerUp(event){if(disabled)return;if(event.currentTarget.hasPointerCapture(event.pointerId)){event.currentTarget.releasePointerCapture(event.pointerId)}},onPointerOver(){if(disabled)return;send({type:"POINTER_OVER",id})},onPointerLeave(){if(disabled)return;send({type:"POINTER_LEAVE",id})},onBlur(){send("BLUR")},onFocus(){send({type:"FOCUS",id})},onDoubleClick(){if(disabled)return;send({type:"DOUBLE_CLICK",id})},onKeyDown(event){if(event.defaultPrevented)return;if(disabled)return;const moveStep=(0,import_dom_event.getEventStep)(event)*step;const keyMap={Enter(){send("ENTER")},ArrowUp(){send({type:"ARROW_UP",step:moveStep})},ArrowDown(){send({type:"ARROW_DOWN",step:moveStep})},ArrowLeft(){send({type:"ARROW_LEFT",step:moveStep})},ArrowRight(){send({type:"ARROW_RIGHT",step:moveStep})},Home(){send("HOME")},End(){send("END")}};const key=(0,import_dom_event.getEventKey)(event,state.context);const exec=keyMap[key];if(exec){exec(event);event.preventDefault()}}})}}}var import_core=require("@zag-js/core");var import_dom_event2=require("@zag-js/dom-event");var import_dom_query3=require("@zag-js/dom-query");var import_utils=require("@zag-js/utils");function machine(userContext){const ctx=(0,import_utils.compact)(userContext);return(0,import_core.createMachine)({id:"splitter",initial:"idle",context:{orientation:"horizontal",activeResizeId:null,previousPanels:[],size:[],initialSize:[],activeResizeState:{isAtMin:false,isAtMax:false},...ctx},created:["setPreviousPanels","setInitialSize"],watch:{size:["setActiveResizeState"]},computed:{isHorizontal:ctx2=>ctx2.orientation==="horizontal",panels:ctx2=>getNormalizedPanels(ctx2)},on:{SET_PANEL_SIZE:{actions:"setPanelSize"}},states:{idle:{entry:["clearActiveHandleId"],on:{POINTER_OVER:{target:"hover:temp",actions:["setActiveHandleId"]},FOCUS:{target:"focused",actions:["setActiveHandleId"]},DOUBLE_CLICK:{actions:["resetStartPanel","setPreviousPanels"]}}},"hover:temp":{after:{HOVER_DELAY:"hover"},on:{POINTER_DOWN:{target:"dragging",actions:["setActiveHandleId"]},POINTER_LEAVE:"idle"}},hover:{tags:["focus"],on:{POINTER_DOWN:"dragging",POINTER_LEAVE:"idle"}},focused:{tags:["focus"],on:{BLUR:"idle",POINTER_DOWN:{target:"dragging",actions:["setActiveHandleId"]},ARROW_LEFT:{guard:"isHorizontal",actions:["shrinkStartPanel","setPreviousPanels"]},ARROW_RIGHT:{guard:"isHorizontal",actions:["expandStartPanel","setPreviousPanels"]},ARROW_UP:{guard:"isVertical",actions:["shrinkStartPanel","setPreviousPanels"]},ARROW_DOWN:{guard:"isVertical",actions:["expandStartPanel","setPreviousPanels"]},ENTER:[{guard:"isStartPanelAtMax",actions:["setStartPanelToMin","setPreviousPanels"]},{actions:["setStartPanelToMax","setPreviousPanels"]}],HOME:{actions:["setStartPanelToMin","setPreviousPanels"]},END:{actions:["setStartPanelToMax","setPreviousPanels"]}}},dragging:{tags:["focus"],entry:"focusResizeHandle",activities:["trackPointerMove"],on:{POINTER_MOVE:{actions:["setPointerValue","setGlobalCursor","invokeOnResize"]},POINTER_UP:{target:"focused",actions:["setPreviousPanels","clearGlobalCursor","blurResizeHandle","invokeOnResizeEnd"]}}}}},{activities:{trackPointerMove:(ctx2,_evt,{send})=>{const doc=dom.getDoc(ctx2);return(0,import_dom_event2.trackPointerMove)(doc,{onPointerMove(info){send({type:"POINTER_MOVE",point:info.point})},onPointerUp(){send("POINTER_UP")}})}},guards:{isStartPanelAtMin:ctx2=>ctx2.activeResizeState.isAtMin,isStartPanelAtMax:ctx2=>ctx2.activeResizeState.isAtMax,isHorizontal:ctx2=>ctx2.isHorizontal,isVertical:ctx2=>!ctx2.isHorizontal},delays:{HOVER_DELAY:250},actions:{setGlobalCursor(ctx2){dom.setupGlobalCursor(ctx2)},clearGlobalCursor(ctx2){dom.removeGlobalCursor(ctx2)},invokeOnResize(ctx2){ctx2.onSizeChange?.({size:Array.from(ctx2.size),activeHandleId:ctx2.activeResizeId})},invokeOnResizeEnd(ctx2){ctx2.onSizeChangeEnd?.({size:Array.from(ctx2.size),activeHandleId:ctx2.activeResizeId})},setActiveHandleId(ctx2,evt){ctx2.activeResizeId=evt.id},clearActiveHandleId(ctx2){ctx2.activeResizeId=null},setInitialSize(ctx2){ctx2.initialSize=ctx2.panels.slice().map(panel=>({id:panel.id,size:panel.size}))},setPanelSize(ctx2,evt){const{id,size}=evt;ctx2.size=ctx2.size.map(panel=>{const panelSize=clamp(size,panel.minSize??0,panel.maxSize??100);return panel.id===id?{...panel,size:panelSize}:panel})},setStartPanelToMin(ctx2){const bounds=getPanelBounds(ctx2);if(!bounds)return;const{before,after}=bounds;ctx2.size[before.index].size=before.min;ctx2.size[after.index].size=after.min},setStartPanelToMax(ctx2){const bounds=getPanelBounds(ctx2);if(!bounds)return;const{before,after}=bounds;ctx2.size[before.index].size=before.max;ctx2.size[after.index].size=after.max},expandStartPanel(ctx2,evt){const bounds=getPanelBounds(ctx2);if(!bounds)return;const{before,after}=bounds;ctx2.size[before.index].size=before.up(evt.step);ctx2.size[after.index].size=after.down(evt.step)},shrinkStartPanel(ctx2,evt){const bounds=getPanelBounds(ctx2);if(!bounds)return;const{before,after}=bounds;ctx2.size[before.index].size=before.down(evt.step);ctx2.size[after.index].size=after.up(evt.step)},resetStartPanel(ctx2,evt){const bounds=getPanelBounds(ctx2,evt.id);if(!bounds)return;const{before,after}=bounds;ctx2.size[before.index].size=ctx2.initialSize[before.index].size;ctx2.size[after.index].size=ctx2.initialSize[after.index].size},focusResizeHandle(ctx2){(0,import_dom_query3.raf)(()=>{dom.getActiveHandleEl(ctx2)?.focus({preventScroll:true})})},blurResizeHandle(ctx2){(0,import_dom_query3.raf)(()=>{dom.getActiveHandleEl(ctx2)?.blur()})},setPreviousPanels(ctx2){ctx2.previousPanels=ctx2.panels.slice()},setActiveResizeState(ctx2){const panels=getPanelBounds(ctx2);if(!panels)return;const{before}=panels;ctx2.activeResizeState={isAtMin:before.isAtMin,isAtMax:before.isAtMax}},setPointerValue(ctx2,evt){const panels=getHandlePanels(ctx2);const bounds=getHandleBounds(ctx2);if(!panels||!bounds)return;const rootEl=dom.getRootEl(ctx2);if(!rootEl)return;const relativePoint=(0,import_dom_event2.getRelativePoint)(evt.point,rootEl);const percentValue=relativePoint.getPercentValue({dir:ctx2.dir,orientation:ctx2.orientation});let pointValue=percentValue*100;ctx2.activeResizeState={isAtMin:pointValue<bounds.min,isAtMax:pointValue>bounds.max};pointValue=clamp(pointValue,bounds.min,bounds.max);const{before,after}=panels;const offset=pointValue-before.end;ctx2.size[before.index].size=before.size+offset;ctx2.size[after.index].size=after.size-offset}}})}var import_types=require("@zag-js/types");var import_utils2=require("@zag-js/utils");var props=(0,import_types.createProps)()(["dir","getRootNode","id","ids","onSizeChange","onSizeChangeEnd","orientation","size"]);var splitProps=(0,import_utils2.createSplitProps)(props);var panelProps=(0,import_types.createProps)()(["id","snapSize"]);var splitPanelProps=(0,import_utils2.createSplitProps)(panelProps);var resizeTriggerProps=(0,import_types.createProps)()(["disabled","id","step"]);var splitResizeTriggerProps=(0,import_utils2.createSplitProps)(resizeTriggerProps);0&&(module.exports={anatomy,connect,machine,panelProps,props,resizeTriggerProps,splitPanelProps,splitProps,splitResizeTriggerProps});
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
anatomy: () => anatomy,
|
|
24
|
+
connect: () => connect,
|
|
25
|
+
machine: () => machine,
|
|
26
|
+
panelProps: () => panelProps,
|
|
27
|
+
props: () => props,
|
|
28
|
+
resizeTriggerProps: () => resizeTriggerProps,
|
|
29
|
+
splitPanelProps: () => splitPanelProps,
|
|
30
|
+
splitProps: () => splitProps,
|
|
31
|
+
splitResizeTriggerProps: () => splitResizeTriggerProps
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(src_exports);
|
|
34
|
+
|
|
35
|
+
// src/splitter.anatomy.ts
|
|
36
|
+
var import_anatomy = require("@zag-js/anatomy");
|
|
37
|
+
var anatomy = (0, import_anatomy.createAnatomy)("splitter").parts("root", "panel", "resizeTrigger");
|
|
38
|
+
var parts = anatomy.build();
|
|
39
|
+
|
|
40
|
+
// src/splitter.connect.ts
|
|
41
|
+
var import_dom_event = require("@zag-js/dom-event");
|
|
42
|
+
var import_dom_query2 = require("@zag-js/dom-query");
|
|
43
|
+
|
|
44
|
+
// src/splitter.dom.ts
|
|
45
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
46
|
+
var dom = (0, import_dom_query.createScope)({
|
|
47
|
+
getRootId: (ctx) => ctx.ids?.root ?? `splitter:${ctx.id}`,
|
|
48
|
+
getResizeTriggerId: (ctx, id) => ctx.ids?.resizeTrigger?.(id) ?? `splitter:${ctx.id}:splitter:${id}`,
|
|
49
|
+
getLabelId: (ctx) => ctx.ids?.label ?? `splitter:${ctx.id}:label`,
|
|
50
|
+
getPanelId: (ctx, id) => ctx.ids?.panel?.(id) ?? `splitter:${ctx.id}:panel:${id}`,
|
|
51
|
+
globalCursorId: (ctx) => `splitter:${ctx.id}:global-cursor`,
|
|
52
|
+
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
53
|
+
getResizeTriggerEl: (ctx, id) => dom.getById(ctx, dom.getResizeTriggerId(ctx, id)),
|
|
54
|
+
getPanelEl: (ctx, id) => dom.getById(ctx, dom.getPanelId(ctx, id)),
|
|
55
|
+
getCursor(ctx) {
|
|
56
|
+
const x = ctx.isHorizontal;
|
|
57
|
+
let cursor = x ? "col-resize" : "row-resize";
|
|
58
|
+
if (ctx.activeResizeState.isAtMin)
|
|
59
|
+
cursor = x ? "e-resize" : "s-resize";
|
|
60
|
+
if (ctx.activeResizeState.isAtMax)
|
|
61
|
+
cursor = x ? "w-resize" : "n-resize";
|
|
62
|
+
return cursor;
|
|
63
|
+
},
|
|
64
|
+
getPanelStyle(ctx, id) {
|
|
65
|
+
const flexGrow = ctx.panels.find((panel) => panel.id === id)?.size ?? "0";
|
|
66
|
+
return {
|
|
67
|
+
flexBasis: 0,
|
|
68
|
+
flexGrow,
|
|
69
|
+
flexShrink: 1,
|
|
70
|
+
overflow: "hidden"
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
getActiveHandleEl(ctx) {
|
|
74
|
+
const activeId = ctx.activeResizeId;
|
|
75
|
+
if (activeId == null)
|
|
76
|
+
return;
|
|
77
|
+
return dom.getById(ctx, dom.getResizeTriggerId(ctx, activeId));
|
|
78
|
+
},
|
|
79
|
+
getResizeTriggerEls(ctx) {
|
|
80
|
+
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
81
|
+
return (0, import_dom_query.queryAll)(dom.getRootEl(ctx), `[role=separator][data-ownedby='${ownerId}']`);
|
|
82
|
+
},
|
|
83
|
+
setupGlobalCursor(ctx) {
|
|
84
|
+
const styleEl = dom.getById(ctx, dom.globalCursorId(ctx));
|
|
85
|
+
const textContent = `* { cursor: ${dom.getCursor(ctx)} !important; }`;
|
|
86
|
+
if (styleEl) {
|
|
87
|
+
styleEl.textContent = textContent;
|
|
88
|
+
} else {
|
|
89
|
+
const style = dom.getDoc(ctx).createElement("style");
|
|
90
|
+
style.id = dom.globalCursorId(ctx);
|
|
91
|
+
style.textContent = textContent;
|
|
92
|
+
dom.getDoc(ctx).head.appendChild(style);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
removeGlobalCursor(ctx) {
|
|
96
|
+
dom.getById(ctx, dom.globalCursorId(ctx))?.remove();
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// src/splitter.utils.ts
|
|
101
|
+
function validateSize(key, size) {
|
|
102
|
+
if (Math.floor(size) > 100) {
|
|
103
|
+
throw new Error(`Total ${key} of panels cannot be greater than 100`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function getNormalizedPanels(ctx) {
|
|
107
|
+
let numOfPanelsWithoutSize = 0;
|
|
108
|
+
let totalSize = 0;
|
|
109
|
+
let totalMinSize = 0;
|
|
110
|
+
const panels = ctx.size.map((panel) => {
|
|
111
|
+
const minSize = panel.minSize ?? 0;
|
|
112
|
+
const maxSize = panel.maxSize ?? 100;
|
|
113
|
+
totalMinSize += minSize;
|
|
114
|
+
if (panel.size == null) {
|
|
115
|
+
numOfPanelsWithoutSize++;
|
|
116
|
+
} else {
|
|
117
|
+
totalSize += panel.size;
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
...panel,
|
|
121
|
+
minSize,
|
|
122
|
+
maxSize
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
validateSize("minSize", totalMinSize);
|
|
126
|
+
validateSize("size", totalSize);
|
|
127
|
+
let end = 0;
|
|
128
|
+
let remainingSize = 0;
|
|
129
|
+
const result = panels.map((panel) => {
|
|
130
|
+
let start = end;
|
|
131
|
+
if (panel.size != null) {
|
|
132
|
+
end += panel.size;
|
|
133
|
+
remainingSize = panel.size - panel.minSize;
|
|
134
|
+
return {
|
|
135
|
+
...panel,
|
|
136
|
+
start,
|
|
137
|
+
end,
|
|
138
|
+
remainingSize
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
const size = (100 - totalSize) / numOfPanelsWithoutSize;
|
|
142
|
+
end += size;
|
|
143
|
+
remainingSize = size - panel.minSize;
|
|
144
|
+
return { ...panel, size, start, end, remainingSize };
|
|
145
|
+
});
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
function getHandlePanels(ctx, id = ctx.activeResizeId) {
|
|
149
|
+
const [beforeId, afterId] = id?.split(":") ?? [];
|
|
150
|
+
if (!beforeId || !afterId)
|
|
151
|
+
return;
|
|
152
|
+
const beforeIndex = ctx.previousPanels.findIndex((panel) => panel.id === beforeId);
|
|
153
|
+
const afterIndex = ctx.previousPanels.findIndex((panel) => panel.id === afterId);
|
|
154
|
+
if (beforeIndex === -1 || afterIndex === -1)
|
|
155
|
+
return;
|
|
156
|
+
const before = ctx.previousPanels[beforeIndex];
|
|
157
|
+
const after = ctx.previousPanels[afterIndex];
|
|
158
|
+
return {
|
|
159
|
+
before: {
|
|
160
|
+
...before,
|
|
161
|
+
index: beforeIndex
|
|
162
|
+
},
|
|
163
|
+
after: {
|
|
164
|
+
...after,
|
|
165
|
+
index: afterIndex
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function getHandleBounds(ctx, id = ctx.activeResizeId) {
|
|
170
|
+
const panels = getHandlePanels(ctx, id);
|
|
171
|
+
if (!panels)
|
|
172
|
+
return;
|
|
173
|
+
const { before, after } = panels;
|
|
174
|
+
return {
|
|
175
|
+
min: Math.max(before.start + before.minSize, after.end - after.maxSize),
|
|
176
|
+
max: Math.min(after.end - after.minSize, before.maxSize + before.start)
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function getPanelBounds(ctx, id) {
|
|
180
|
+
const bounds = getHandleBounds(ctx, id);
|
|
181
|
+
const panels = getHandlePanels(ctx, id);
|
|
182
|
+
if (!bounds || !panels)
|
|
183
|
+
return;
|
|
184
|
+
const { before, after } = panels;
|
|
185
|
+
const beforeMin = Math.abs(before.start - bounds.min);
|
|
186
|
+
const afterMin = after.size + (before.size - beforeMin);
|
|
187
|
+
const beforeMax = Math.abs(before.start - bounds.max);
|
|
188
|
+
const afterMax = after.size - (beforeMax - before.size);
|
|
189
|
+
return {
|
|
190
|
+
before: {
|
|
191
|
+
index: before.index,
|
|
192
|
+
min: beforeMin,
|
|
193
|
+
max: beforeMax,
|
|
194
|
+
isAtMin: beforeMin === before.size,
|
|
195
|
+
isAtMax: beforeMax === before.size,
|
|
196
|
+
up(step) {
|
|
197
|
+
return Math.min(before.size + step, beforeMax);
|
|
198
|
+
},
|
|
199
|
+
down(step) {
|
|
200
|
+
return Math.max(before.size - step, beforeMin);
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
after: {
|
|
204
|
+
index: after.index,
|
|
205
|
+
min: afterMin,
|
|
206
|
+
max: afterMax,
|
|
207
|
+
isAtMin: afterMin === after.size,
|
|
208
|
+
isAtMax: afterMax === after.size,
|
|
209
|
+
up(step) {
|
|
210
|
+
return Math.min(after.size + step, afterMin);
|
|
211
|
+
},
|
|
212
|
+
down(step) {
|
|
213
|
+
return Math.max(after.size - step, afterMax);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function clamp(value, min, max) {
|
|
219
|
+
return Math.min(Math.max(value, min), max);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// src/splitter.connect.ts
|
|
223
|
+
function connect(state, send, normalize) {
|
|
224
|
+
const horizontal = state.context.isHorizontal;
|
|
225
|
+
const focused = state.hasTag("focus");
|
|
226
|
+
const dragging = state.matches("dragging");
|
|
227
|
+
const panels = state.context.panels;
|
|
228
|
+
function getResizeTriggerState(props2) {
|
|
229
|
+
const { id, disabled } = props2;
|
|
230
|
+
const ids = id.split(":");
|
|
231
|
+
const panelIds = ids.map((id2) => dom.getPanelId(state.context, id2));
|
|
232
|
+
const panels2 = getHandleBounds(state.context, id);
|
|
233
|
+
return {
|
|
234
|
+
disabled: !!disabled,
|
|
235
|
+
focused: state.context.activeResizeId === id && focused,
|
|
236
|
+
panelIds,
|
|
237
|
+
min: panels2?.min,
|
|
238
|
+
max: panels2?.max,
|
|
239
|
+
value: 0
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
focused,
|
|
244
|
+
dragging,
|
|
245
|
+
getResizeTriggerState,
|
|
246
|
+
bounds: getHandleBounds(state.context),
|
|
247
|
+
setToMinSize(id) {
|
|
248
|
+
const panel = panels.find((panel2) => panel2.id === id);
|
|
249
|
+
send({ type: "SET_PANEL_SIZE", id, size: panel?.minSize, src: "setToMinSize" });
|
|
250
|
+
},
|
|
251
|
+
setToMaxSize(id) {
|
|
252
|
+
const panel = panels.find((panel2) => panel2.id === id);
|
|
253
|
+
send({ type: "SET_PANEL_SIZE", id, size: panel?.maxSize, src: "setToMaxSize" });
|
|
254
|
+
},
|
|
255
|
+
setSize(id, size) {
|
|
256
|
+
send({ type: "SET_PANEL_SIZE", id, size });
|
|
257
|
+
},
|
|
258
|
+
getRootProps() {
|
|
259
|
+
return normalize.element({
|
|
260
|
+
...parts.root.attrs,
|
|
261
|
+
"data-orientation": state.context.orientation,
|
|
262
|
+
id: dom.getRootId(state.context),
|
|
263
|
+
dir: state.context.dir,
|
|
264
|
+
style: {
|
|
265
|
+
display: "flex",
|
|
266
|
+
flexDirection: horizontal ? "row" : "column",
|
|
267
|
+
height: "100%",
|
|
268
|
+
width: "100%",
|
|
269
|
+
overflow: "hidden"
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
},
|
|
273
|
+
getPanelProps(props2) {
|
|
274
|
+
const { id } = props2;
|
|
275
|
+
return normalize.element({
|
|
276
|
+
...parts.panel.attrs,
|
|
277
|
+
"data-orientation": state.context.orientation,
|
|
278
|
+
dir: state.context.dir,
|
|
279
|
+
id: dom.getPanelId(state.context, id),
|
|
280
|
+
"data-ownedby": dom.getRootId(state.context),
|
|
281
|
+
style: dom.getPanelStyle(state.context, id)
|
|
282
|
+
});
|
|
283
|
+
},
|
|
284
|
+
getResizeTriggerProps(props2) {
|
|
285
|
+
const { id, disabled, step = 1 } = props2;
|
|
286
|
+
const triggerState = getResizeTriggerState(props2);
|
|
287
|
+
return normalize.element({
|
|
288
|
+
...parts.resizeTrigger.attrs,
|
|
289
|
+
dir: state.context.dir,
|
|
290
|
+
id: dom.getResizeTriggerId(state.context, id),
|
|
291
|
+
role: "separator",
|
|
292
|
+
"data-ownedby": dom.getRootId(state.context),
|
|
293
|
+
tabIndex: disabled ? void 0 : 0,
|
|
294
|
+
"aria-valuenow": triggerState.value,
|
|
295
|
+
"aria-valuemin": triggerState.min,
|
|
296
|
+
"aria-valuemax": triggerState.max,
|
|
297
|
+
"data-orientation": state.context.orientation,
|
|
298
|
+
"aria-orientation": state.context.orientation,
|
|
299
|
+
"aria-controls": triggerState.panelIds.join(" "),
|
|
300
|
+
"data-focus": (0, import_dom_query2.dataAttr)(triggerState.focused),
|
|
301
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(disabled),
|
|
302
|
+
style: {
|
|
303
|
+
touchAction: "none",
|
|
304
|
+
userSelect: "none",
|
|
305
|
+
flex: "0 0 auto",
|
|
306
|
+
pointerEvents: dragging && !triggerState.focused ? "none" : void 0,
|
|
307
|
+
cursor: horizontal ? "col-resize" : "row-resize",
|
|
308
|
+
[horizontal ? "minHeight" : "minWidth"]: "0"
|
|
309
|
+
},
|
|
310
|
+
onPointerDown(event) {
|
|
311
|
+
if (disabled) {
|
|
312
|
+
event.preventDefault();
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
send({ type: "POINTER_DOWN", id });
|
|
316
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
317
|
+
event.preventDefault();
|
|
318
|
+
event.stopPropagation();
|
|
319
|
+
},
|
|
320
|
+
onPointerUp(event) {
|
|
321
|
+
if (disabled)
|
|
322
|
+
return;
|
|
323
|
+
if (event.currentTarget.hasPointerCapture(event.pointerId)) {
|
|
324
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
onPointerOver() {
|
|
328
|
+
if (disabled)
|
|
329
|
+
return;
|
|
330
|
+
send({ type: "POINTER_OVER", id });
|
|
331
|
+
},
|
|
332
|
+
onPointerLeave() {
|
|
333
|
+
if (disabled)
|
|
334
|
+
return;
|
|
335
|
+
send({ type: "POINTER_LEAVE", id });
|
|
336
|
+
},
|
|
337
|
+
onBlur() {
|
|
338
|
+
send("BLUR");
|
|
339
|
+
},
|
|
340
|
+
onFocus() {
|
|
341
|
+
send({ type: "FOCUS", id });
|
|
342
|
+
},
|
|
343
|
+
onDoubleClick() {
|
|
344
|
+
if (disabled)
|
|
345
|
+
return;
|
|
346
|
+
send({ type: "DOUBLE_CLICK", id });
|
|
347
|
+
},
|
|
348
|
+
onKeyDown(event) {
|
|
349
|
+
if (event.defaultPrevented)
|
|
350
|
+
return;
|
|
351
|
+
if (disabled)
|
|
352
|
+
return;
|
|
353
|
+
const moveStep = (0, import_dom_event.getEventStep)(event) * step;
|
|
354
|
+
const keyMap = {
|
|
355
|
+
Enter() {
|
|
356
|
+
send("ENTER");
|
|
357
|
+
},
|
|
358
|
+
ArrowUp() {
|
|
359
|
+
send({ type: "ARROW_UP", step: moveStep });
|
|
360
|
+
},
|
|
361
|
+
ArrowDown() {
|
|
362
|
+
send({ type: "ARROW_DOWN", step: moveStep });
|
|
363
|
+
},
|
|
364
|
+
ArrowLeft() {
|
|
365
|
+
send({ type: "ARROW_LEFT", step: moveStep });
|
|
366
|
+
},
|
|
367
|
+
ArrowRight() {
|
|
368
|
+
send({ type: "ARROW_RIGHT", step: moveStep });
|
|
369
|
+
},
|
|
370
|
+
Home() {
|
|
371
|
+
send("HOME");
|
|
372
|
+
},
|
|
373
|
+
End() {
|
|
374
|
+
send("END");
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
const key = (0, import_dom_event.getEventKey)(event, state.context);
|
|
378
|
+
const exec = keyMap[key];
|
|
379
|
+
if (exec) {
|
|
380
|
+
exec(event);
|
|
381
|
+
event.preventDefault();
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// src/splitter.machine.ts
|
|
390
|
+
var import_core = require("@zag-js/core");
|
|
391
|
+
var import_dom_event2 = require("@zag-js/dom-event");
|
|
392
|
+
var import_dom_query3 = require("@zag-js/dom-query");
|
|
393
|
+
var import_utils = require("@zag-js/utils");
|
|
394
|
+
function machine(userContext) {
|
|
395
|
+
const ctx = (0, import_utils.compact)(userContext);
|
|
396
|
+
return (0, import_core.createMachine)(
|
|
397
|
+
{
|
|
398
|
+
id: "splitter",
|
|
399
|
+
initial: "idle",
|
|
400
|
+
context: {
|
|
401
|
+
orientation: "horizontal",
|
|
402
|
+
activeResizeId: null,
|
|
403
|
+
previousPanels: [],
|
|
404
|
+
size: [],
|
|
405
|
+
initialSize: [],
|
|
406
|
+
activeResizeState: {
|
|
407
|
+
isAtMin: false,
|
|
408
|
+
isAtMax: false
|
|
409
|
+
},
|
|
410
|
+
...ctx
|
|
411
|
+
},
|
|
412
|
+
created: ["setPreviousPanels", "setInitialSize"],
|
|
413
|
+
watch: {
|
|
414
|
+
size: ["setActiveResizeState"]
|
|
415
|
+
},
|
|
416
|
+
computed: {
|
|
417
|
+
isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
|
|
418
|
+
panels: (ctx2) => getNormalizedPanels(ctx2)
|
|
419
|
+
},
|
|
420
|
+
on: {
|
|
421
|
+
SET_PANEL_SIZE: {
|
|
422
|
+
actions: "setPanelSize"
|
|
423
|
+
}
|
|
424
|
+
},
|
|
425
|
+
states: {
|
|
426
|
+
idle: {
|
|
427
|
+
entry: ["clearActiveHandleId"],
|
|
428
|
+
on: {
|
|
429
|
+
POINTER_OVER: {
|
|
430
|
+
target: "hover:temp",
|
|
431
|
+
actions: ["setActiveHandleId"]
|
|
432
|
+
},
|
|
433
|
+
FOCUS: {
|
|
434
|
+
target: "focused",
|
|
435
|
+
actions: ["setActiveHandleId"]
|
|
436
|
+
},
|
|
437
|
+
DOUBLE_CLICK: {
|
|
438
|
+
actions: ["resetStartPanel", "setPreviousPanels"]
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
},
|
|
442
|
+
"hover:temp": {
|
|
443
|
+
after: {
|
|
444
|
+
HOVER_DELAY: "hover"
|
|
445
|
+
},
|
|
446
|
+
on: {
|
|
447
|
+
POINTER_DOWN: {
|
|
448
|
+
target: "dragging",
|
|
449
|
+
actions: ["setActiveHandleId"]
|
|
450
|
+
},
|
|
451
|
+
POINTER_LEAVE: "idle"
|
|
452
|
+
}
|
|
453
|
+
},
|
|
454
|
+
hover: {
|
|
455
|
+
tags: ["focus"],
|
|
456
|
+
on: {
|
|
457
|
+
POINTER_DOWN: "dragging",
|
|
458
|
+
POINTER_LEAVE: "idle"
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
focused: {
|
|
462
|
+
tags: ["focus"],
|
|
463
|
+
on: {
|
|
464
|
+
BLUR: "idle",
|
|
465
|
+
POINTER_DOWN: {
|
|
466
|
+
target: "dragging",
|
|
467
|
+
actions: ["setActiveHandleId"]
|
|
468
|
+
},
|
|
469
|
+
ARROW_LEFT: {
|
|
470
|
+
guard: "isHorizontal",
|
|
471
|
+
actions: ["shrinkStartPanel", "setPreviousPanels"]
|
|
472
|
+
},
|
|
473
|
+
ARROW_RIGHT: {
|
|
474
|
+
guard: "isHorizontal",
|
|
475
|
+
actions: ["expandStartPanel", "setPreviousPanels"]
|
|
476
|
+
},
|
|
477
|
+
ARROW_UP: {
|
|
478
|
+
guard: "isVertical",
|
|
479
|
+
actions: ["shrinkStartPanel", "setPreviousPanels"]
|
|
480
|
+
},
|
|
481
|
+
ARROW_DOWN: {
|
|
482
|
+
guard: "isVertical",
|
|
483
|
+
actions: ["expandStartPanel", "setPreviousPanels"]
|
|
484
|
+
},
|
|
485
|
+
ENTER: [
|
|
486
|
+
{
|
|
487
|
+
guard: "isStartPanelAtMax",
|
|
488
|
+
actions: ["setStartPanelToMin", "setPreviousPanels"]
|
|
489
|
+
},
|
|
490
|
+
{ actions: ["setStartPanelToMax", "setPreviousPanels"] }
|
|
491
|
+
],
|
|
492
|
+
HOME: {
|
|
493
|
+
actions: ["setStartPanelToMin", "setPreviousPanels"]
|
|
494
|
+
},
|
|
495
|
+
END: {
|
|
496
|
+
actions: ["setStartPanelToMax", "setPreviousPanels"]
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
},
|
|
500
|
+
dragging: {
|
|
501
|
+
tags: ["focus"],
|
|
502
|
+
entry: "focusResizeHandle",
|
|
503
|
+
activities: ["trackPointerMove"],
|
|
504
|
+
on: {
|
|
505
|
+
POINTER_MOVE: {
|
|
506
|
+
actions: ["setPointerValue", "setGlobalCursor", "invokeOnResize"]
|
|
507
|
+
},
|
|
508
|
+
POINTER_UP: {
|
|
509
|
+
target: "focused",
|
|
510
|
+
actions: ["setPreviousPanels", "clearGlobalCursor", "blurResizeHandle", "invokeOnResizeEnd"]
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
activities: {
|
|
518
|
+
trackPointerMove: (ctx2, _evt, { send }) => {
|
|
519
|
+
const doc = dom.getDoc(ctx2);
|
|
520
|
+
return (0, import_dom_event2.trackPointerMove)(doc, {
|
|
521
|
+
onPointerMove(info) {
|
|
522
|
+
send({ type: "POINTER_MOVE", point: info.point });
|
|
523
|
+
},
|
|
524
|
+
onPointerUp() {
|
|
525
|
+
send("POINTER_UP");
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
},
|
|
530
|
+
guards: {
|
|
531
|
+
isStartPanelAtMin: (ctx2) => ctx2.activeResizeState.isAtMin,
|
|
532
|
+
isStartPanelAtMax: (ctx2) => ctx2.activeResizeState.isAtMax,
|
|
533
|
+
isHorizontal: (ctx2) => ctx2.isHorizontal,
|
|
534
|
+
isVertical: (ctx2) => !ctx2.isHorizontal
|
|
535
|
+
},
|
|
536
|
+
delays: {
|
|
537
|
+
HOVER_DELAY: 250
|
|
538
|
+
},
|
|
539
|
+
actions: {
|
|
540
|
+
setGlobalCursor(ctx2) {
|
|
541
|
+
dom.setupGlobalCursor(ctx2);
|
|
542
|
+
},
|
|
543
|
+
clearGlobalCursor(ctx2) {
|
|
544
|
+
dom.removeGlobalCursor(ctx2);
|
|
545
|
+
},
|
|
546
|
+
invokeOnResize(ctx2) {
|
|
547
|
+
ctx2.onSizeChange?.({ size: Array.from(ctx2.size), activeHandleId: ctx2.activeResizeId });
|
|
548
|
+
},
|
|
549
|
+
invokeOnResizeEnd(ctx2) {
|
|
550
|
+
ctx2.onSizeChangeEnd?.({ size: Array.from(ctx2.size), activeHandleId: ctx2.activeResizeId });
|
|
551
|
+
},
|
|
552
|
+
setActiveHandleId(ctx2, evt) {
|
|
553
|
+
ctx2.activeResizeId = evt.id;
|
|
554
|
+
},
|
|
555
|
+
clearActiveHandleId(ctx2) {
|
|
556
|
+
ctx2.activeResizeId = null;
|
|
557
|
+
},
|
|
558
|
+
setInitialSize(ctx2) {
|
|
559
|
+
ctx2.initialSize = ctx2.panels.slice().map((panel) => ({
|
|
560
|
+
id: panel.id,
|
|
561
|
+
size: panel.size
|
|
562
|
+
}));
|
|
563
|
+
},
|
|
564
|
+
setPanelSize(ctx2, evt) {
|
|
565
|
+
const { id, size } = evt;
|
|
566
|
+
ctx2.size = ctx2.size.map((panel) => {
|
|
567
|
+
const panelSize = clamp(size, panel.minSize ?? 0, panel.maxSize ?? 100);
|
|
568
|
+
return panel.id === id ? { ...panel, size: panelSize } : panel;
|
|
569
|
+
});
|
|
570
|
+
},
|
|
571
|
+
setStartPanelToMin(ctx2) {
|
|
572
|
+
const bounds = getPanelBounds(ctx2);
|
|
573
|
+
if (!bounds)
|
|
574
|
+
return;
|
|
575
|
+
const { before, after } = bounds;
|
|
576
|
+
ctx2.size[before.index].size = before.min;
|
|
577
|
+
ctx2.size[after.index].size = after.min;
|
|
578
|
+
},
|
|
579
|
+
setStartPanelToMax(ctx2) {
|
|
580
|
+
const bounds = getPanelBounds(ctx2);
|
|
581
|
+
if (!bounds)
|
|
582
|
+
return;
|
|
583
|
+
const { before, after } = bounds;
|
|
584
|
+
ctx2.size[before.index].size = before.max;
|
|
585
|
+
ctx2.size[after.index].size = after.max;
|
|
586
|
+
},
|
|
587
|
+
expandStartPanel(ctx2, evt) {
|
|
588
|
+
const bounds = getPanelBounds(ctx2);
|
|
589
|
+
if (!bounds)
|
|
590
|
+
return;
|
|
591
|
+
const { before, after } = bounds;
|
|
592
|
+
ctx2.size[before.index].size = before.up(evt.step);
|
|
593
|
+
ctx2.size[after.index].size = after.down(evt.step);
|
|
594
|
+
},
|
|
595
|
+
shrinkStartPanel(ctx2, evt) {
|
|
596
|
+
const bounds = getPanelBounds(ctx2);
|
|
597
|
+
if (!bounds)
|
|
598
|
+
return;
|
|
599
|
+
const { before, after } = bounds;
|
|
600
|
+
ctx2.size[before.index].size = before.down(evt.step);
|
|
601
|
+
ctx2.size[after.index].size = after.up(evt.step);
|
|
602
|
+
},
|
|
603
|
+
resetStartPanel(ctx2, evt) {
|
|
604
|
+
const bounds = getPanelBounds(ctx2, evt.id);
|
|
605
|
+
if (!bounds)
|
|
606
|
+
return;
|
|
607
|
+
const { before, after } = bounds;
|
|
608
|
+
ctx2.size[before.index].size = ctx2.initialSize[before.index].size;
|
|
609
|
+
ctx2.size[after.index].size = ctx2.initialSize[after.index].size;
|
|
610
|
+
},
|
|
611
|
+
focusResizeHandle(ctx2) {
|
|
612
|
+
(0, import_dom_query3.raf)(() => {
|
|
613
|
+
dom.getActiveHandleEl(ctx2)?.focus({ preventScroll: true });
|
|
614
|
+
});
|
|
615
|
+
},
|
|
616
|
+
blurResizeHandle(ctx2) {
|
|
617
|
+
(0, import_dom_query3.raf)(() => {
|
|
618
|
+
dom.getActiveHandleEl(ctx2)?.blur();
|
|
619
|
+
});
|
|
620
|
+
},
|
|
621
|
+
setPreviousPanels(ctx2) {
|
|
622
|
+
ctx2.previousPanels = ctx2.panels.slice();
|
|
623
|
+
},
|
|
624
|
+
setActiveResizeState(ctx2) {
|
|
625
|
+
const panels = getPanelBounds(ctx2);
|
|
626
|
+
if (!panels)
|
|
627
|
+
return;
|
|
628
|
+
const { before } = panels;
|
|
629
|
+
ctx2.activeResizeState = {
|
|
630
|
+
isAtMin: before.isAtMin,
|
|
631
|
+
isAtMax: before.isAtMax
|
|
632
|
+
};
|
|
633
|
+
},
|
|
634
|
+
setPointerValue(ctx2, evt) {
|
|
635
|
+
const panels = getHandlePanels(ctx2);
|
|
636
|
+
const bounds = getHandleBounds(ctx2);
|
|
637
|
+
if (!panels || !bounds)
|
|
638
|
+
return;
|
|
639
|
+
const rootEl = dom.getRootEl(ctx2);
|
|
640
|
+
if (!rootEl)
|
|
641
|
+
return;
|
|
642
|
+
const relativePoint = (0, import_dom_event2.getRelativePoint)(evt.point, rootEl);
|
|
643
|
+
const percentValue = relativePoint.getPercentValue({
|
|
644
|
+
dir: ctx2.dir,
|
|
645
|
+
orientation: ctx2.orientation
|
|
646
|
+
});
|
|
647
|
+
let pointValue = percentValue * 100;
|
|
648
|
+
ctx2.activeResizeState = {
|
|
649
|
+
isAtMin: pointValue < bounds.min,
|
|
650
|
+
isAtMax: pointValue > bounds.max
|
|
651
|
+
};
|
|
652
|
+
pointValue = clamp(pointValue, bounds.min, bounds.max);
|
|
653
|
+
const { before, after } = panels;
|
|
654
|
+
const offset = pointValue - before.end;
|
|
655
|
+
ctx2.size[before.index].size = before.size + offset;
|
|
656
|
+
ctx2.size[after.index].size = after.size - offset;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
// src/splitter.props.ts
|
|
664
|
+
var import_types = require("@zag-js/types");
|
|
665
|
+
var import_utils2 = require("@zag-js/utils");
|
|
666
|
+
var props = (0, import_types.createProps)()([
|
|
667
|
+
"dir",
|
|
668
|
+
"getRootNode",
|
|
669
|
+
"id",
|
|
670
|
+
"ids",
|
|
671
|
+
"onSizeChange",
|
|
672
|
+
"onSizeChangeEnd",
|
|
673
|
+
"orientation",
|
|
674
|
+
"size"
|
|
675
|
+
]);
|
|
676
|
+
var splitProps = (0, import_utils2.createSplitProps)(props);
|
|
677
|
+
var panelProps = (0, import_types.createProps)()(["id", "snapSize"]);
|
|
678
|
+
var splitPanelProps = (0, import_utils2.createSplitProps)(panelProps);
|
|
679
|
+
var resizeTriggerProps = (0, import_types.createProps)()(["disabled", "id", "step"]);
|
|
680
|
+
var splitResizeTriggerProps = (0, import_utils2.createSplitProps)(resizeTriggerProps);
|
|
681
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
682
|
+
0 && (module.exports = {
|
|
683
|
+
anatomy,
|
|
684
|
+
connect,
|
|
685
|
+
machine,
|
|
686
|
+
panelProps,
|
|
687
|
+
props,
|
|
688
|
+
resizeTriggerProps,
|
|
689
|
+
splitPanelProps,
|
|
690
|
+
splitProps,
|
|
691
|
+
splitResizeTriggerProps
|
|
692
|
+
});
|
|
2
693
|
//# sourceMappingURL=index.js.map
|