@zag-js/splitter 0.10.1 → 0.10.3
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.ts +4 -7
- package/dist/index.js +8 -684
- package/dist/index.mjs +3 -16
- package/dist/splitter.anatomy.d.ts +3 -6
- package/dist/splitter.anatomy.js +10 -33
- package/dist/splitter.anatomy.mjs +6 -8
- package/dist/splitter.connect.d.ts +3 -7
- package/dist/splitter.connect.js +28 -144
- package/dist/splitter.connect.mjs +181 -9
- package/dist/splitter.dom.d.ts +25 -29
- package/dist/splitter.dom.js +9 -31
- package/dist/splitter.dom.mjs +58 -6
- package/dist/splitter.machine.d.ts +3 -7
- package/dist/splitter.machine.js +34 -250
- package/dist/splitter.machine.mjs +281 -8
- package/dist/splitter.types.d.ts +12 -14
- package/dist/splitter.utils.d.ts +6 -11
- package/dist/splitter.utils.js +10 -37
- package/dist/splitter.utils.mjs +122 -14
- package/package.json +9 -14
- package/src/splitter.connect.ts +3 -3
- package/src/splitter.machine.ts +1 -16
- package/src/splitter.utils.ts +1 -1
- package/dist/chunk-3GDOPT5W.mjs +0 -60
- package/dist/chunk-53T2VZ2R.mjs +0 -190
- package/dist/chunk-HPRMFGOY.mjs +0 -9
- package/dist/chunk-MV44GBQY.mjs +0 -129
- package/dist/chunk-X2E2LAC5.mjs +0 -307
- package/dist/splitter.types.js +0 -18
- package/dist/splitter.types.mjs +0 -0
package/dist/chunk-3GDOPT5W.mjs
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
// src/splitter.dom.ts
|
|
2
|
-
import { createScope, queryAll } from "@zag-js/dom-query";
|
|
3
|
-
var dom = createScope({
|
|
4
|
-
getRootId: (ctx) => ctx.ids?.root ?? `splitter:${ctx.id}`,
|
|
5
|
-
getResizeTriggerId: (ctx, id) => ctx.ids?.resizeTrigger?.(id) ?? `splitter:${ctx.id}:splitter:${id}`,
|
|
6
|
-
getToggleTriggerId: (ctx) => ctx.ids?.toggleTrigger?.(ctx.id) ?? `splitter:${ctx.id}:toggle-btn`,
|
|
7
|
-
getLabelId: (ctx) => ctx.ids?.label ?? `splitter:${ctx.id}:label`,
|
|
8
|
-
getPanelId: (ctx, id) => ctx.ids?.panel?.(id) ?? `splitter:${ctx.id}:panel:${id}`,
|
|
9
|
-
globalCursorId: (ctx) => `splitter:${ctx.id}:global-cursor`,
|
|
10
|
-
getRootEl: (ctx) => dom.queryById(ctx, dom.getRootId(ctx)),
|
|
11
|
-
getResizeTriggerEl: (ctx, id) => dom.getById(ctx, dom.getResizeTriggerId(ctx, id)),
|
|
12
|
-
getPanelEl: (ctx, id) => dom.getById(ctx, dom.getPanelId(ctx, id)),
|
|
13
|
-
getCursor(ctx) {
|
|
14
|
-
const x = ctx.isHorizontal;
|
|
15
|
-
let cursor = x ? "col-resize" : "row-resize";
|
|
16
|
-
if (ctx.activeResizeState.isAtMin)
|
|
17
|
-
cursor = x ? "e-resize" : "s-resize";
|
|
18
|
-
if (ctx.activeResizeState.isAtMax)
|
|
19
|
-
cursor = x ? "w-resize" : "n-resize";
|
|
20
|
-
return cursor;
|
|
21
|
-
},
|
|
22
|
-
getPanelStyle(ctx, id) {
|
|
23
|
-
const flexGrow = ctx.panels.find((panel) => panel.id === id)?.size ?? "0";
|
|
24
|
-
return {
|
|
25
|
-
flexBasis: 0,
|
|
26
|
-
flexGrow,
|
|
27
|
-
flexShrink: 1,
|
|
28
|
-
overflow: "hidden"
|
|
29
|
-
};
|
|
30
|
-
},
|
|
31
|
-
getActiveHandleEl(ctx) {
|
|
32
|
-
const activeId = ctx.activeResizeId;
|
|
33
|
-
if (activeId == null)
|
|
34
|
-
return;
|
|
35
|
-
return dom.getById(ctx, dom.getResizeTriggerId(ctx, activeId));
|
|
36
|
-
},
|
|
37
|
-
getResizeTriggerEls(ctx) {
|
|
38
|
-
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
39
|
-
return queryAll(dom.getRootEl(ctx), `[role=separator][data-ownedby='${ownerId}']`);
|
|
40
|
-
},
|
|
41
|
-
setupGlobalCursor(ctx) {
|
|
42
|
-
const styleEl = dom.getById(ctx, dom.globalCursorId(ctx));
|
|
43
|
-
const textContent = `* { cursor: ${dom.getCursor(ctx)} !important; }`;
|
|
44
|
-
if (styleEl) {
|
|
45
|
-
styleEl.textContent = textContent;
|
|
46
|
-
} else {
|
|
47
|
-
const style = dom.getDoc(ctx).createElement("style");
|
|
48
|
-
style.id = dom.globalCursorId(ctx);
|
|
49
|
-
style.textContent = textContent;
|
|
50
|
-
dom.getDoc(ctx).head.appendChild(style);
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
removeGlobalCursor(ctx) {
|
|
54
|
-
dom.getById(ctx, dom.globalCursorId(ctx))?.remove();
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
export {
|
|
59
|
-
dom
|
|
60
|
-
};
|
package/dist/chunk-53T2VZ2R.mjs
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
parts
|
|
3
|
-
} from "./chunk-HPRMFGOY.mjs";
|
|
4
|
-
import {
|
|
5
|
-
dom
|
|
6
|
-
} from "./chunk-3GDOPT5W.mjs";
|
|
7
|
-
import {
|
|
8
|
-
getHandleBounds
|
|
9
|
-
} from "./chunk-MV44GBQY.mjs";
|
|
10
|
-
|
|
11
|
-
// src/splitter.connect.ts
|
|
12
|
-
import { getEventKey, getEventStep } from "@zag-js/dom-event";
|
|
13
|
-
import { dataAttr } from "@zag-js/dom-query";
|
|
14
|
-
function connect(state, send, normalize) {
|
|
15
|
-
const isHorizontal = state.context.isHorizontal;
|
|
16
|
-
const isFocused = state.hasTag("focus");
|
|
17
|
-
const isDragging = state.matches("dragging");
|
|
18
|
-
const panels = state.context.panels;
|
|
19
|
-
const api = {
|
|
20
|
-
/**
|
|
21
|
-
* Whether the splitter is focused.
|
|
22
|
-
*/
|
|
23
|
-
isFocused,
|
|
24
|
-
/**
|
|
25
|
-
* Whether the splitter is being dragged.
|
|
26
|
-
*/
|
|
27
|
-
isDragging,
|
|
28
|
-
/**
|
|
29
|
-
* The bounds of the currently dragged splitter handle.
|
|
30
|
-
*/
|
|
31
|
-
bounds: getHandleBounds(state.context),
|
|
32
|
-
/**
|
|
33
|
-
* Function to set a panel to its minimum size.
|
|
34
|
-
*/
|
|
35
|
-
setToMinSize(id) {
|
|
36
|
-
const panel = panels.find((panel2) => panel2.id === id);
|
|
37
|
-
send({ type: "SET_SIZE", id, size: panel?.minSize, src: "collapse" });
|
|
38
|
-
},
|
|
39
|
-
/**
|
|
40
|
-
* Function to set a panel to its maximum size.
|
|
41
|
-
*/
|
|
42
|
-
setToMaxSize(id) {
|
|
43
|
-
const panel = panels.find((panel2) => panel2.id === id);
|
|
44
|
-
send({ type: "SET_SIZE", id, size: panel?.maxSize, src: "expand" });
|
|
45
|
-
},
|
|
46
|
-
/**
|
|
47
|
-
* Function to set the size of a panel.
|
|
48
|
-
*/
|
|
49
|
-
setSize(id, size) {
|
|
50
|
-
send({ type: "SET_SIZE", id, size });
|
|
51
|
-
},
|
|
52
|
-
/**
|
|
53
|
-
* Returns the state details for a resize trigger.
|
|
54
|
-
*/
|
|
55
|
-
getResizeTriggerState(props) {
|
|
56
|
-
const { id, disabled } = props;
|
|
57
|
-
const ids = id.split(":");
|
|
58
|
-
const panelIds = ids.map((id2) => dom.getPanelId(state.context, id2));
|
|
59
|
-
const panels2 = getHandleBounds(state.context, id);
|
|
60
|
-
return {
|
|
61
|
-
isDisabled: !!disabled,
|
|
62
|
-
isFocused: state.context.activeResizeId === id && isFocused,
|
|
63
|
-
panelIds,
|
|
64
|
-
min: panels2?.min,
|
|
65
|
-
max: panels2?.max,
|
|
66
|
-
value: 0
|
|
67
|
-
};
|
|
68
|
-
},
|
|
69
|
-
rootProps: normalize.element({
|
|
70
|
-
...parts.root.attrs,
|
|
71
|
-
"data-orientation": state.context.orientation,
|
|
72
|
-
id: dom.getRootId(state.context),
|
|
73
|
-
dir: state.context.dir,
|
|
74
|
-
style: {
|
|
75
|
-
display: "flex",
|
|
76
|
-
flexDirection: isHorizontal ? "row" : "column",
|
|
77
|
-
height: "100%",
|
|
78
|
-
width: "100%",
|
|
79
|
-
overflow: "hidden"
|
|
80
|
-
}
|
|
81
|
-
}),
|
|
82
|
-
getPanelProps(props) {
|
|
83
|
-
const { id } = props;
|
|
84
|
-
return normalize.element({
|
|
85
|
-
...parts.panel.attrs,
|
|
86
|
-
dir: state.context.dir,
|
|
87
|
-
id: dom.getPanelId(state.context, id),
|
|
88
|
-
"data-ownedby": dom.getRootId(state.context),
|
|
89
|
-
style: dom.getPanelStyle(state.context, id)
|
|
90
|
-
});
|
|
91
|
-
},
|
|
92
|
-
getResizeTriggerProps(props) {
|
|
93
|
-
const { id, disabled, step = 1 } = props;
|
|
94
|
-
const triggerState = api.getResizeTriggerState(props);
|
|
95
|
-
return normalize.element({
|
|
96
|
-
...parts.resizeTrigger.attrs,
|
|
97
|
-
dir: state.context.dir,
|
|
98
|
-
id: dom.getResizeTriggerId(state.context, id),
|
|
99
|
-
role: "separator",
|
|
100
|
-
"data-ownedby": dom.getRootId(state.context),
|
|
101
|
-
tabIndex: disabled ? void 0 : 0,
|
|
102
|
-
"aria-valuenow": triggerState.value,
|
|
103
|
-
"aria-valuemin": triggerState.min,
|
|
104
|
-
"aria-valuemax": triggerState.max,
|
|
105
|
-
"data-orientation": state.context.orientation,
|
|
106
|
-
"aria-orientation": state.context.orientation,
|
|
107
|
-
"aria-controls": triggerState.panelIds.join(" "),
|
|
108
|
-
"data-focus": dataAttr(triggerState.isFocused),
|
|
109
|
-
"data-disabled": dataAttr(disabled),
|
|
110
|
-
style: {
|
|
111
|
-
touchAction: "none",
|
|
112
|
-
userSelect: "none",
|
|
113
|
-
flex: "0 0 auto",
|
|
114
|
-
pointerEvents: isDragging && !triggerState.isFocused ? "none" : void 0,
|
|
115
|
-
cursor: isHorizontal ? "col-resize" : "row-resize",
|
|
116
|
-
[isHorizontal ? "minHeight" : "minWidth"]: "0"
|
|
117
|
-
},
|
|
118
|
-
onPointerDown(event) {
|
|
119
|
-
if (disabled) {
|
|
120
|
-
event.preventDefault();
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
send({ type: "POINTER_DOWN", id });
|
|
124
|
-
event.preventDefault();
|
|
125
|
-
event.stopPropagation();
|
|
126
|
-
},
|
|
127
|
-
onPointerOver() {
|
|
128
|
-
if (disabled)
|
|
129
|
-
return;
|
|
130
|
-
send({ type: "POINTER_OVER", id });
|
|
131
|
-
},
|
|
132
|
-
onPointerLeave() {
|
|
133
|
-
if (disabled)
|
|
134
|
-
return;
|
|
135
|
-
send({ type: "POINTER_LEAVE", id });
|
|
136
|
-
},
|
|
137
|
-
onBlur() {
|
|
138
|
-
send("BLUR");
|
|
139
|
-
},
|
|
140
|
-
onFocus() {
|
|
141
|
-
send({ type: "FOCUS", id });
|
|
142
|
-
},
|
|
143
|
-
onDoubleClick() {
|
|
144
|
-
if (disabled)
|
|
145
|
-
return;
|
|
146
|
-
send({ type: "DOUBLE_CLICK", id });
|
|
147
|
-
},
|
|
148
|
-
onKeyDown(event) {
|
|
149
|
-
if (disabled)
|
|
150
|
-
return;
|
|
151
|
-
const moveStep = getEventStep(event) * step;
|
|
152
|
-
const keyMap = {
|
|
153
|
-
Enter() {
|
|
154
|
-
send("ENTER");
|
|
155
|
-
},
|
|
156
|
-
ArrowUp() {
|
|
157
|
-
send({ type: "ARROW_UP", step: moveStep });
|
|
158
|
-
},
|
|
159
|
-
ArrowDown() {
|
|
160
|
-
send({ type: "ARROW_DOWN", step: moveStep });
|
|
161
|
-
},
|
|
162
|
-
ArrowLeft() {
|
|
163
|
-
send({ type: "ARROW_LEFT", step: moveStep });
|
|
164
|
-
},
|
|
165
|
-
ArrowRight() {
|
|
166
|
-
send({ type: "ARROW_RIGHT", step: moveStep });
|
|
167
|
-
},
|
|
168
|
-
Home() {
|
|
169
|
-
send("HOME");
|
|
170
|
-
},
|
|
171
|
-
End() {
|
|
172
|
-
send("END");
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
const key = getEventKey(event, state.context);
|
|
176
|
-
const exec = keyMap[key];
|
|
177
|
-
if (exec) {
|
|
178
|
-
exec(event);
|
|
179
|
-
event.preventDefault();
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
return api;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export {
|
|
189
|
-
connect
|
|
190
|
-
};
|
package/dist/chunk-HPRMFGOY.mjs
DELETED
package/dist/chunk-MV44GBQY.mjs
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
// src/splitter.utils.ts
|
|
2
|
-
function validateSize(key, size) {
|
|
3
|
-
if (Math.floor(size) > 100) {
|
|
4
|
-
throw new Error(`Total ${key} of panels cannot be greater than 100`);
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
function getNormalizedPanels(ctx) {
|
|
8
|
-
let numOfPanelsWithoutSize = 0;
|
|
9
|
-
let totalSize = 0;
|
|
10
|
-
let totalMinSize = 0;
|
|
11
|
-
const panels = ctx.size.map((panel) => {
|
|
12
|
-
const minSize = panel.minSize ?? 10;
|
|
13
|
-
const maxSize = panel.maxSize ?? 100;
|
|
14
|
-
totalMinSize += minSize;
|
|
15
|
-
if (panel.size == null) {
|
|
16
|
-
numOfPanelsWithoutSize++;
|
|
17
|
-
} else {
|
|
18
|
-
totalSize += panel.size;
|
|
19
|
-
}
|
|
20
|
-
return {
|
|
21
|
-
...panel,
|
|
22
|
-
minSize,
|
|
23
|
-
maxSize
|
|
24
|
-
};
|
|
25
|
-
});
|
|
26
|
-
validateSize("minSize", totalMinSize);
|
|
27
|
-
validateSize("size", totalSize);
|
|
28
|
-
let end = 0;
|
|
29
|
-
let remainingSize = 0;
|
|
30
|
-
const result = panels.map((panel) => {
|
|
31
|
-
let start = end;
|
|
32
|
-
if (panel.size != null) {
|
|
33
|
-
end += panel.size;
|
|
34
|
-
remainingSize = panel.size - panel.minSize;
|
|
35
|
-
return {
|
|
36
|
-
...panel,
|
|
37
|
-
start,
|
|
38
|
-
end,
|
|
39
|
-
remainingSize
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
const size = (100 - totalSize) / numOfPanelsWithoutSize;
|
|
43
|
-
end += size;
|
|
44
|
-
remainingSize = size - panel.minSize;
|
|
45
|
-
return { ...panel, size, start, end, remainingSize };
|
|
46
|
-
});
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
49
|
-
function getHandlePanels(ctx, id = ctx.activeResizeId) {
|
|
50
|
-
const [beforeId, afterId] = id?.split(":") ?? [];
|
|
51
|
-
if (!beforeId || !afterId)
|
|
52
|
-
return;
|
|
53
|
-
const beforeIndex = ctx.previousPanels.findIndex((panel) => panel.id === beforeId);
|
|
54
|
-
const afterIndex = ctx.previousPanels.findIndex((panel) => panel.id === afterId);
|
|
55
|
-
if (beforeIndex === -1 || afterIndex === -1)
|
|
56
|
-
return;
|
|
57
|
-
const before = ctx.previousPanels[beforeIndex];
|
|
58
|
-
const after = ctx.previousPanels[afterIndex];
|
|
59
|
-
return {
|
|
60
|
-
before: {
|
|
61
|
-
...before,
|
|
62
|
-
index: beforeIndex
|
|
63
|
-
},
|
|
64
|
-
after: {
|
|
65
|
-
...after,
|
|
66
|
-
index: afterIndex
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
function getHandleBounds(ctx, id = ctx.activeResizeId) {
|
|
71
|
-
const panels = getHandlePanels(ctx, id);
|
|
72
|
-
if (!panels)
|
|
73
|
-
return;
|
|
74
|
-
const { before, after } = panels;
|
|
75
|
-
return {
|
|
76
|
-
min: Math.max(before.start + before.minSize, after.end - after.maxSize),
|
|
77
|
-
max: Math.min(after.end - after.minSize, before.maxSize + before.start)
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
function getPanelBounds(ctx, id) {
|
|
81
|
-
const bounds = getHandleBounds(ctx, id);
|
|
82
|
-
const panels = getHandlePanels(ctx, id);
|
|
83
|
-
if (!bounds || !panels)
|
|
84
|
-
return;
|
|
85
|
-
const { before, after } = panels;
|
|
86
|
-
const beforeMin = Math.abs(before.start - bounds.min);
|
|
87
|
-
const afterMin = after.size + (before.size - beforeMin);
|
|
88
|
-
const beforeMax = Math.abs(before.start - bounds.max);
|
|
89
|
-
const afterMax = after.size - (beforeMax - before.size);
|
|
90
|
-
return {
|
|
91
|
-
before: {
|
|
92
|
-
index: before.index,
|
|
93
|
-
min: beforeMin,
|
|
94
|
-
max: beforeMax,
|
|
95
|
-
isAtMin: beforeMin === before.size,
|
|
96
|
-
isAtMax: beforeMax === before.size,
|
|
97
|
-
up(step) {
|
|
98
|
-
return Math.min(before.size + step, beforeMax);
|
|
99
|
-
},
|
|
100
|
-
down(step) {
|
|
101
|
-
return Math.max(before.size - step, beforeMin);
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
after: {
|
|
105
|
-
index: after.index,
|
|
106
|
-
min: afterMin,
|
|
107
|
-
max: afterMax,
|
|
108
|
-
isAtMin: afterMin === after.size,
|
|
109
|
-
isAtMax: afterMax === after.size,
|
|
110
|
-
up(step) {
|
|
111
|
-
return Math.min(after.size + step, afterMin);
|
|
112
|
-
},
|
|
113
|
-
down(step) {
|
|
114
|
-
return Math.max(after.size - step, afterMax);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
function clamp(value, min, max) {
|
|
120
|
-
return Math.min(Math.max(value, min), max);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export {
|
|
124
|
-
getNormalizedPanels,
|
|
125
|
-
getHandlePanels,
|
|
126
|
-
getHandleBounds,
|
|
127
|
-
getPanelBounds,
|
|
128
|
-
clamp
|
|
129
|
-
};
|
package/dist/chunk-X2E2LAC5.mjs
DELETED
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
dom
|
|
3
|
-
} from "./chunk-3GDOPT5W.mjs";
|
|
4
|
-
import {
|
|
5
|
-
clamp,
|
|
6
|
-
getHandleBounds,
|
|
7
|
-
getHandlePanels,
|
|
8
|
-
getNormalizedPanels,
|
|
9
|
-
getPanelBounds
|
|
10
|
-
} from "./chunk-MV44GBQY.mjs";
|
|
11
|
-
|
|
12
|
-
// src/splitter.machine.ts
|
|
13
|
-
import { createMachine } from "@zag-js/core";
|
|
14
|
-
import { getRelativePoint, trackPointerMove } from "@zag-js/dom-event";
|
|
15
|
-
import { raf } from "@zag-js/dom-query";
|
|
16
|
-
import { compact } from "@zag-js/utils";
|
|
17
|
-
function machine(userContext) {
|
|
18
|
-
const ctx = compact(userContext);
|
|
19
|
-
return createMachine(
|
|
20
|
-
{
|
|
21
|
-
id: "splitter",
|
|
22
|
-
initial: "idle",
|
|
23
|
-
context: {
|
|
24
|
-
orientation: "horizontal",
|
|
25
|
-
activeResizeId: null,
|
|
26
|
-
previousPanels: [],
|
|
27
|
-
size: [],
|
|
28
|
-
initialSize: [],
|
|
29
|
-
activeResizeState: {
|
|
30
|
-
isAtMin: false,
|
|
31
|
-
isAtMax: false
|
|
32
|
-
},
|
|
33
|
-
...ctx
|
|
34
|
-
},
|
|
35
|
-
created: ["setPreviousPanels", "setInitialSize"],
|
|
36
|
-
watch: {
|
|
37
|
-
size: ["setActiveResizeState"]
|
|
38
|
-
},
|
|
39
|
-
computed: {
|
|
40
|
-
isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
|
|
41
|
-
panels: (ctx2) => getNormalizedPanels(ctx2)
|
|
42
|
-
},
|
|
43
|
-
on: {
|
|
44
|
-
COLLAPSE: {
|
|
45
|
-
actions: "setStartPanelToMin"
|
|
46
|
-
},
|
|
47
|
-
EXPAND: {
|
|
48
|
-
actions: "setStartPanelToMax"
|
|
49
|
-
},
|
|
50
|
-
TOGGLE: [
|
|
51
|
-
{
|
|
52
|
-
guard: "isStartPanelAtMin",
|
|
53
|
-
actions: "setStartPanelToMax"
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
actions: "setStartPanelToMin"
|
|
57
|
-
}
|
|
58
|
-
],
|
|
59
|
-
SET_SIZE: {
|
|
60
|
-
actions: "setPanelSize"
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
states: {
|
|
64
|
-
idle: {
|
|
65
|
-
entry: ["clearActiveHandleId"],
|
|
66
|
-
on: {
|
|
67
|
-
POINTER_OVER: {
|
|
68
|
-
target: "hover:temp",
|
|
69
|
-
actions: ["setActiveHandleId"]
|
|
70
|
-
},
|
|
71
|
-
FOCUS: {
|
|
72
|
-
target: "focused",
|
|
73
|
-
actions: ["setActiveHandleId"]
|
|
74
|
-
},
|
|
75
|
-
DOUBLE_CLICK: {
|
|
76
|
-
actions: ["resetStartPanel", "setPreviousPanels"]
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
"hover:temp": {
|
|
81
|
-
after: {
|
|
82
|
-
HOVER_DELAY: "hover"
|
|
83
|
-
},
|
|
84
|
-
on: {
|
|
85
|
-
POINTER_DOWN: {
|
|
86
|
-
target: "dragging",
|
|
87
|
-
actions: ["setActiveHandleId", "invokeOnResizeStart"]
|
|
88
|
-
},
|
|
89
|
-
POINTER_LEAVE: "idle"
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
hover: {
|
|
93
|
-
tags: ["focus"],
|
|
94
|
-
on: {
|
|
95
|
-
POINTER_DOWN: {
|
|
96
|
-
target: "dragging",
|
|
97
|
-
actions: ["invokeOnResizeStart"]
|
|
98
|
-
},
|
|
99
|
-
POINTER_LEAVE: "idle"
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
focused: {
|
|
103
|
-
tags: ["focus"],
|
|
104
|
-
on: {
|
|
105
|
-
BLUR: "idle",
|
|
106
|
-
POINTER_DOWN: {
|
|
107
|
-
target: "dragging",
|
|
108
|
-
actions: ["setActiveHandleId", "invokeOnResizeStart"]
|
|
109
|
-
},
|
|
110
|
-
ARROW_LEFT: {
|
|
111
|
-
guard: "isHorizontal",
|
|
112
|
-
actions: ["shrinkStartPanel", "setPreviousPanels"]
|
|
113
|
-
},
|
|
114
|
-
ARROW_RIGHT: {
|
|
115
|
-
guard: "isHorizontal",
|
|
116
|
-
actions: ["expandStartPanel", "setPreviousPanels"]
|
|
117
|
-
},
|
|
118
|
-
ARROW_UP: {
|
|
119
|
-
guard: "isVertical",
|
|
120
|
-
actions: ["shrinkStartPanel", "setPreviousPanels"]
|
|
121
|
-
},
|
|
122
|
-
ARROW_DOWN: {
|
|
123
|
-
guard: "isVertical",
|
|
124
|
-
actions: ["expandStartPanel", "setPreviousPanels"]
|
|
125
|
-
},
|
|
126
|
-
ENTER: [
|
|
127
|
-
{
|
|
128
|
-
guard: "isStartPanelAtMax",
|
|
129
|
-
actions: ["setStartPanelToMin", "setPreviousPanels"]
|
|
130
|
-
},
|
|
131
|
-
{ actions: ["setStartPanelToMax", "setPreviousPanels"] }
|
|
132
|
-
],
|
|
133
|
-
HOME: {
|
|
134
|
-
actions: ["setStartPanelToMin", "setPreviousPanels"]
|
|
135
|
-
},
|
|
136
|
-
END: {
|
|
137
|
-
actions: ["setStartPanelToMax", "setPreviousPanels"]
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
dragging: {
|
|
142
|
-
tags: ["focus"],
|
|
143
|
-
entry: "focusResizeHandle",
|
|
144
|
-
activities: ["trackPointerMove"],
|
|
145
|
-
on: {
|
|
146
|
-
POINTER_MOVE: {
|
|
147
|
-
actions: ["setPointerValue", "setGlobalCursor"]
|
|
148
|
-
},
|
|
149
|
-
POINTER_UP: {
|
|
150
|
-
target: "focused",
|
|
151
|
-
actions: ["invokeOnResizeEnd", "setPreviousPanels", "clearGlobalCursor", "blurResizeHandle"]
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
activities: {
|
|
159
|
-
trackPointerMove: (ctx2, _evt, { send }) => {
|
|
160
|
-
const doc = dom.getDoc(ctx2);
|
|
161
|
-
return trackPointerMove(doc, {
|
|
162
|
-
onPointerMove(info) {
|
|
163
|
-
send({ type: "POINTER_MOVE", point: info.point });
|
|
164
|
-
},
|
|
165
|
-
onPointerUp() {
|
|
166
|
-
send("POINTER_UP");
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
guards: {
|
|
172
|
-
isStartPanelAtMin: (ctx2) => ctx2.activeResizeState.isAtMin,
|
|
173
|
-
isStartPanelAtMax: (ctx2) => ctx2.activeResizeState.isAtMax,
|
|
174
|
-
isHorizontal: (ctx2) => ctx2.isHorizontal,
|
|
175
|
-
isVertical: (ctx2) => !ctx2.isHorizontal
|
|
176
|
-
},
|
|
177
|
-
delays: {
|
|
178
|
-
HOVER_DELAY: 250
|
|
179
|
-
},
|
|
180
|
-
actions: {
|
|
181
|
-
setGlobalCursor(ctx2) {
|
|
182
|
-
dom.setupGlobalCursor(ctx2);
|
|
183
|
-
},
|
|
184
|
-
clearGlobalCursor(ctx2) {
|
|
185
|
-
dom.removeGlobalCursor(ctx2);
|
|
186
|
-
},
|
|
187
|
-
invokeOnResize(ctx2) {
|
|
188
|
-
ctx2.onResize?.({ size: ctx2.size, activeHandleId: ctx2.activeResizeId });
|
|
189
|
-
},
|
|
190
|
-
invokeOnResizeStart(ctx2) {
|
|
191
|
-
ctx2.onResizeStart?.({ size: ctx2.size, activeHandleId: ctx2.activeResizeId });
|
|
192
|
-
},
|
|
193
|
-
invokeOnResizeEnd(ctx2) {
|
|
194
|
-
ctx2.onResizeEnd?.({ size: ctx2.size, activeHandleId: ctx2.activeResizeId });
|
|
195
|
-
},
|
|
196
|
-
setActiveHandleId(ctx2, evt) {
|
|
197
|
-
ctx2.activeResizeId = evt.id;
|
|
198
|
-
},
|
|
199
|
-
clearActiveHandleId(ctx2) {
|
|
200
|
-
ctx2.activeResizeId = null;
|
|
201
|
-
},
|
|
202
|
-
setInitialSize(ctx2) {
|
|
203
|
-
ctx2.initialSize = ctx2.panels.slice().map((panel) => ({
|
|
204
|
-
id: panel.id,
|
|
205
|
-
size: panel.size
|
|
206
|
-
}));
|
|
207
|
-
},
|
|
208
|
-
setPanelSize(ctx2, evt) {
|
|
209
|
-
const { id, size } = evt;
|
|
210
|
-
ctx2.size = ctx2.size.map((panel) => {
|
|
211
|
-
const panelSize = clamp(size, panel.minSize ?? 0, panel.maxSize ?? 100);
|
|
212
|
-
return panel.id === id ? { ...panel, size: panelSize } : panel;
|
|
213
|
-
});
|
|
214
|
-
},
|
|
215
|
-
setStartPanelToMin(ctx2) {
|
|
216
|
-
const bounds = getPanelBounds(ctx2);
|
|
217
|
-
if (!bounds)
|
|
218
|
-
return;
|
|
219
|
-
const { before, after } = bounds;
|
|
220
|
-
ctx2.size[before.index].size = before.min;
|
|
221
|
-
ctx2.size[after.index].size = after.min;
|
|
222
|
-
},
|
|
223
|
-
setStartPanelToMax(ctx2) {
|
|
224
|
-
const bounds = getPanelBounds(ctx2);
|
|
225
|
-
if (!bounds)
|
|
226
|
-
return;
|
|
227
|
-
const { before, after } = bounds;
|
|
228
|
-
ctx2.size[before.index].size = before.max;
|
|
229
|
-
ctx2.size[after.index].size = after.max;
|
|
230
|
-
},
|
|
231
|
-
expandStartPanel(ctx2, evt) {
|
|
232
|
-
const bounds = getPanelBounds(ctx2);
|
|
233
|
-
if (!bounds)
|
|
234
|
-
return;
|
|
235
|
-
const { before, after } = bounds;
|
|
236
|
-
ctx2.size[before.index].size = before.up(evt.step);
|
|
237
|
-
ctx2.size[after.index].size = after.down(evt.step);
|
|
238
|
-
},
|
|
239
|
-
shrinkStartPanel(ctx2, evt) {
|
|
240
|
-
const bounds = getPanelBounds(ctx2);
|
|
241
|
-
if (!bounds)
|
|
242
|
-
return;
|
|
243
|
-
const { before, after } = bounds;
|
|
244
|
-
ctx2.size[before.index].size = before.down(evt.step);
|
|
245
|
-
ctx2.size[after.index].size = after.up(evt.step);
|
|
246
|
-
},
|
|
247
|
-
resetStartPanel(ctx2, evt) {
|
|
248
|
-
const bounds = getPanelBounds(ctx2, evt.id);
|
|
249
|
-
if (!bounds)
|
|
250
|
-
return;
|
|
251
|
-
const { before, after } = bounds;
|
|
252
|
-
ctx2.size[before.index].size = ctx2.initialSize[before.index].size;
|
|
253
|
-
ctx2.size[after.index].size = ctx2.initialSize[after.index].size;
|
|
254
|
-
},
|
|
255
|
-
focusResizeHandle(ctx2) {
|
|
256
|
-
raf(() => {
|
|
257
|
-
dom.getActiveHandleEl(ctx2)?.focus({ preventScroll: true });
|
|
258
|
-
});
|
|
259
|
-
},
|
|
260
|
-
blurResizeHandle(ctx2) {
|
|
261
|
-
raf(() => {
|
|
262
|
-
dom.getActiveHandleEl(ctx2)?.blur();
|
|
263
|
-
});
|
|
264
|
-
},
|
|
265
|
-
setPreviousPanels(ctx2) {
|
|
266
|
-
ctx2.previousPanels = ctx2.panels.slice();
|
|
267
|
-
},
|
|
268
|
-
setActiveResizeState(ctx2) {
|
|
269
|
-
const panels = getPanelBounds(ctx2);
|
|
270
|
-
if (!panels)
|
|
271
|
-
return;
|
|
272
|
-
const { before } = panels;
|
|
273
|
-
ctx2.activeResizeState = {
|
|
274
|
-
isAtMin: before.isAtMin,
|
|
275
|
-
isAtMax: before.isAtMax
|
|
276
|
-
};
|
|
277
|
-
},
|
|
278
|
-
setPointerValue(ctx2, evt) {
|
|
279
|
-
const panels = getHandlePanels(ctx2);
|
|
280
|
-
const bounds = getHandleBounds(ctx2);
|
|
281
|
-
if (!panels || !bounds)
|
|
282
|
-
return;
|
|
283
|
-
const rootEl = dom.getRootEl(ctx2);
|
|
284
|
-
const relativePoint = getRelativePoint(evt.point, rootEl);
|
|
285
|
-
const percentValue = relativePoint.getPercentValue({
|
|
286
|
-
dir: ctx2.dir,
|
|
287
|
-
orientation: ctx2.orientation
|
|
288
|
-
});
|
|
289
|
-
let pointValue = percentValue * 100;
|
|
290
|
-
ctx2.activeResizeState = {
|
|
291
|
-
isAtMin: pointValue < bounds.min,
|
|
292
|
-
isAtMax: pointValue > bounds.max
|
|
293
|
-
};
|
|
294
|
-
pointValue = clamp(pointValue, bounds.min, bounds.max);
|
|
295
|
-
const { before, after } = panels;
|
|
296
|
-
const offset = pointValue - before.end;
|
|
297
|
-
ctx2.size[before.index].size = before.size + offset;
|
|
298
|
-
ctx2.size[after.index].size = after.size - offset;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
export {
|
|
306
|
-
machine
|
|
307
|
-
};
|