@zag-js/splitter 0.2.5 → 0.2.7
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/chunk-HPRMFGOY.mjs +9 -0
- package/dist/chunk-IOEWCDUH.mjs +556 -0
- package/dist/chunk-SQ3UMXCZ.mjs +131 -0
- package/dist/chunk-T56NFB6E.mjs +102 -0
- package/dist/chunk-X2M4RMIJ.mjs +206 -0
- package/dist/index.d.ts +7 -966
- package/dist/index.js +502 -336
- package/dist/index.mjs +11 -794
- package/dist/splitter.anatomy.d.ts +6 -0
- package/dist/splitter.anatomy.js +34 -0
- package/dist/splitter.anatomy.mjs +8 -0
- package/dist/splitter.connect.d.ts +28 -0
- package/dist/splitter.connect.js +360 -0
- package/dist/splitter.connect.mjs +9 -0
- package/dist/splitter.dom.d.ts +39 -0
- package/dist/splitter.dom.js +128 -0
- package/dist/splitter.dom.mjs +6 -0
- package/dist/splitter.machine.d.ts +7 -0
- package/dist/splitter.machine.js +792 -0
- package/dist/splitter.machine.mjs +8 -0
- package/dist/splitter.types.d.ts +68 -0
- package/dist/splitter.types.js +18 -0
- package/dist/splitter.types.mjs +0 -0
- package/dist/splitter.utils.d.ts +54 -0
- package/dist/splitter.utils.js +159 -0
- package/dist/splitter.utils.mjs +14 -0
- package/package.json +22 -12
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// ../../utilities/dom/src/query.ts
|
|
2
|
+
function isDocument(el) {
|
|
3
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
4
|
+
}
|
|
5
|
+
function isWindow(value) {
|
|
6
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
7
|
+
}
|
|
8
|
+
function getDocument(el) {
|
|
9
|
+
var _a;
|
|
10
|
+
if (isWindow(el))
|
|
11
|
+
return el.document;
|
|
12
|
+
if (isDocument(el))
|
|
13
|
+
return el;
|
|
14
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
15
|
+
}
|
|
16
|
+
function defineDomHelpers(helpers) {
|
|
17
|
+
const dom2 = {
|
|
18
|
+
getRootNode: (ctx) => {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
21
|
+
},
|
|
22
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
23
|
+
getWin: (ctx) => {
|
|
24
|
+
var _a;
|
|
25
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
26
|
+
},
|
|
27
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
28
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
...dom2,
|
|
32
|
+
...helpers
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// ../../utilities/dom/src/nodelist.ts
|
|
37
|
+
function queryAll(root, selector) {
|
|
38
|
+
var _a;
|
|
39
|
+
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// src/splitter.dom.ts
|
|
43
|
+
var dom = defineDomHelpers({
|
|
44
|
+
getRootId: (ctx) => `splitter:${ctx.id}`,
|
|
45
|
+
getResizeTriggerId: (ctx, id) => `splitter:${ctx.id}:splitter:${id}`,
|
|
46
|
+
getToggleTriggerId: (ctx) => `splitter:${ctx.id}:toggle-btn`,
|
|
47
|
+
getLabelId: (ctx) => `splitter:${ctx.id}:label`,
|
|
48
|
+
getPanelId: (ctx, id) => `splitter:${ctx.id}:panel:${id}`,
|
|
49
|
+
globalCursorId: (ctx) => `splitter:${ctx.id}:global-cursor`,
|
|
50
|
+
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
51
|
+
getResizeTriggerEl: (ctx, id) => dom.getById(ctx, dom.getResizeTriggerId(ctx, id)),
|
|
52
|
+
getPanelEl: (ctx, id) => dom.getById(ctx, dom.getPanelId(ctx, id)),
|
|
53
|
+
getCursor(ctx) {
|
|
54
|
+
const x = ctx.isHorizontal;
|
|
55
|
+
let cursor = x ? "col-resize" : "row-resize";
|
|
56
|
+
if (ctx.activeResizeState.isAtMin)
|
|
57
|
+
cursor = x ? "e-resize" : "s-resize";
|
|
58
|
+
if (ctx.activeResizeState.isAtMax)
|
|
59
|
+
cursor = x ? "w-resize" : "n-resize";
|
|
60
|
+
return cursor;
|
|
61
|
+
},
|
|
62
|
+
getPanelStyle(ctx, id) {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
const flexGrow = (_b = (_a = ctx.panels.find((panel) => panel.id === id)) == null ? void 0 : _a.size) != null ? _b : "0";
|
|
65
|
+
return {
|
|
66
|
+
flexBasis: 0,
|
|
67
|
+
flexGrow,
|
|
68
|
+
flexShrink: 1,
|
|
69
|
+
overflow: "hidden"
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
getActiveHandleEl(ctx) {
|
|
73
|
+
const activeId = ctx.activeResizeId;
|
|
74
|
+
if (activeId == null)
|
|
75
|
+
return;
|
|
76
|
+
return dom.getById(ctx, dom.getResizeTriggerId(ctx, activeId));
|
|
77
|
+
},
|
|
78
|
+
getResizeTriggerEls(ctx) {
|
|
79
|
+
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
80
|
+
return queryAll(dom.getRootEl(ctx), `[role=separator][data-ownedby='${ownerId}']`);
|
|
81
|
+
},
|
|
82
|
+
setupGlobalCursor(ctx) {
|
|
83
|
+
const styleEl = dom.getById(ctx, dom.globalCursorId(ctx));
|
|
84
|
+
const textContent = `* { cursor: ${dom.getCursor(ctx)} !important; }`;
|
|
85
|
+
if (styleEl) {
|
|
86
|
+
styleEl.textContent = textContent;
|
|
87
|
+
} else {
|
|
88
|
+
const style = dom.getDoc(ctx).createElement("style");
|
|
89
|
+
style.id = dom.globalCursorId(ctx);
|
|
90
|
+
style.textContent = textContent;
|
|
91
|
+
dom.getDoc(ctx).head.appendChild(style);
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
removeGlobalCursor(ctx) {
|
|
95
|
+
var _a;
|
|
96
|
+
(_a = dom.getById(ctx, dom.globalCursorId(ctx))) == null ? void 0 : _a.remove();
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
export {
|
|
101
|
+
dom
|
|
102
|
+
};
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parts
|
|
3
|
+
} from "./chunk-HPRMFGOY.mjs";
|
|
4
|
+
import {
|
|
5
|
+
dom
|
|
6
|
+
} from "./chunk-T56NFB6E.mjs";
|
|
7
|
+
import {
|
|
8
|
+
getHandleBounds
|
|
9
|
+
} from "./chunk-SQ3UMXCZ.mjs";
|
|
10
|
+
|
|
11
|
+
// ../../utilities/dom/src/attrs.ts
|
|
12
|
+
var dataAttr = (guard) => {
|
|
13
|
+
return guard ? "" : void 0;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// ../../utilities/dom/src/keyboard-event.ts
|
|
17
|
+
var rtlKeyMap = {
|
|
18
|
+
ArrowLeft: "ArrowRight",
|
|
19
|
+
ArrowRight: "ArrowLeft"
|
|
20
|
+
};
|
|
21
|
+
var sameKeyMap = {
|
|
22
|
+
Up: "ArrowUp",
|
|
23
|
+
Down: "ArrowDown",
|
|
24
|
+
Esc: "Escape",
|
|
25
|
+
" ": "Space",
|
|
26
|
+
",": "Comma",
|
|
27
|
+
Left: "ArrowLeft",
|
|
28
|
+
Right: "ArrowRight"
|
|
29
|
+
};
|
|
30
|
+
function getEventKey(event, options = {}) {
|
|
31
|
+
var _a;
|
|
32
|
+
const { dir = "ltr", orientation = "horizontal" } = options;
|
|
33
|
+
let { key } = event;
|
|
34
|
+
key = (_a = sameKeyMap[key]) != null ? _a : key;
|
|
35
|
+
const isRtl = dir === "rtl" && orientation === "horizontal";
|
|
36
|
+
if (isRtl && key in rtlKeyMap) {
|
|
37
|
+
key = rtlKeyMap[key];
|
|
38
|
+
}
|
|
39
|
+
return key;
|
|
40
|
+
}
|
|
41
|
+
var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
|
|
42
|
+
var ARROW_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
|
|
43
|
+
function getEventStep(event) {
|
|
44
|
+
if (event.ctrlKey || event.metaKey) {
|
|
45
|
+
return 0.1;
|
|
46
|
+
} else {
|
|
47
|
+
const isPageKey = PAGE_KEYS.has(event.key);
|
|
48
|
+
const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.has(event.key);
|
|
49
|
+
return isSkipKey ? 10 : 1;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/splitter.connect.ts
|
|
54
|
+
function connect(state, send, normalize) {
|
|
55
|
+
const isHorizontal = state.context.isHorizontal;
|
|
56
|
+
const isFocused = state.hasTag("focus");
|
|
57
|
+
const isDragging = state.matches("dragging");
|
|
58
|
+
return {
|
|
59
|
+
isFocused,
|
|
60
|
+
isDragging,
|
|
61
|
+
bounds: getHandleBounds(state.context),
|
|
62
|
+
collapse(id) {
|
|
63
|
+
send({ type: "COLLAPSE", id });
|
|
64
|
+
},
|
|
65
|
+
expand(id) {
|
|
66
|
+
send({ type: "EXPAND", id });
|
|
67
|
+
},
|
|
68
|
+
toggle(id) {
|
|
69
|
+
send({ type: "TOGGLE", id });
|
|
70
|
+
},
|
|
71
|
+
setSize(id, size) {
|
|
72
|
+
send({ type: "SET_SIZE", id, size });
|
|
73
|
+
},
|
|
74
|
+
rootProps: normalize.element({
|
|
75
|
+
...parts.root.attrs,
|
|
76
|
+
"data-orientation": state.context.orientation,
|
|
77
|
+
id: dom.getRootId(state.context),
|
|
78
|
+
dir: state.context.dir,
|
|
79
|
+
style: {
|
|
80
|
+
display: "flex",
|
|
81
|
+
flexDirection: isHorizontal ? "row" : "column",
|
|
82
|
+
height: "100%",
|
|
83
|
+
width: "100%",
|
|
84
|
+
overflow: "hidden"
|
|
85
|
+
}
|
|
86
|
+
}),
|
|
87
|
+
getPanelProps(props) {
|
|
88
|
+
const { id } = props;
|
|
89
|
+
return normalize.element({
|
|
90
|
+
...parts.panel.attrs,
|
|
91
|
+
dir: state.context.dir,
|
|
92
|
+
id: dom.getPanelId(state.context, id),
|
|
93
|
+
"data-ownedby": dom.getRootId(state.context),
|
|
94
|
+
style: dom.getPanelStyle(state.context, id)
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
getResizeTriggerState(id) {
|
|
98
|
+
const ids = id.split(":");
|
|
99
|
+
const panelIds = ids.map((id2) => dom.getPanelId(state.context, id2));
|
|
100
|
+
const panels = getHandleBounds(state.context, id);
|
|
101
|
+
return {
|
|
102
|
+
isFocused: state.context.activeResizeId === id && isFocused,
|
|
103
|
+
panelIds,
|
|
104
|
+
min: panels == null ? void 0 : panels.min,
|
|
105
|
+
max: panels == null ? void 0 : panels.max,
|
|
106
|
+
value: 0
|
|
107
|
+
};
|
|
108
|
+
},
|
|
109
|
+
getResizeTriggerProps(props) {
|
|
110
|
+
const { id, disabled, step = 1 } = props;
|
|
111
|
+
const triggerState = this.getResizeTriggerState(id);
|
|
112
|
+
return normalize.element({
|
|
113
|
+
...parts.resizeTrigger.attrs,
|
|
114
|
+
dir: state.context.dir,
|
|
115
|
+
id: dom.getResizeTriggerId(state.context, id),
|
|
116
|
+
role: "separator",
|
|
117
|
+
"data-ownedby": dom.getRootId(state.context),
|
|
118
|
+
tabIndex: disabled ? void 0 : 0,
|
|
119
|
+
"aria-valuenow": triggerState.value,
|
|
120
|
+
"aria-valuemin": triggerState.min,
|
|
121
|
+
"aria-valuemax": triggerState.max,
|
|
122
|
+
"data-orientation": state.context.orientation,
|
|
123
|
+
"aria-orientation": state.context.orientation,
|
|
124
|
+
"aria-controls": triggerState.panelIds.join(" "),
|
|
125
|
+
"data-focus": dataAttr(triggerState.isFocused),
|
|
126
|
+
"data-disabled": dataAttr(disabled),
|
|
127
|
+
style: {
|
|
128
|
+
touchAction: "none",
|
|
129
|
+
userSelect: "none",
|
|
130
|
+
flex: "0 0 auto",
|
|
131
|
+
pointerEvents: isDragging && !triggerState.isFocused ? "none" : void 0,
|
|
132
|
+
cursor: isHorizontal ? "col-resize" : "row-resize",
|
|
133
|
+
[isHorizontal ? "minHeight" : "minWidth"]: "0"
|
|
134
|
+
},
|
|
135
|
+
onPointerDown(event) {
|
|
136
|
+
if (disabled) {
|
|
137
|
+
event.preventDefault();
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
send({ type: "POINTER_DOWN", id });
|
|
141
|
+
event.preventDefault();
|
|
142
|
+
event.stopPropagation();
|
|
143
|
+
},
|
|
144
|
+
onPointerOver() {
|
|
145
|
+
if (disabled)
|
|
146
|
+
return;
|
|
147
|
+
send({ type: "POINTER_OVER", id });
|
|
148
|
+
},
|
|
149
|
+
onPointerLeave() {
|
|
150
|
+
if (disabled)
|
|
151
|
+
return;
|
|
152
|
+
send({ type: "POINTER_LEAVE", id });
|
|
153
|
+
},
|
|
154
|
+
onBlur() {
|
|
155
|
+
send("BLUR");
|
|
156
|
+
},
|
|
157
|
+
onFocus() {
|
|
158
|
+
send({ type: "FOCUS", id });
|
|
159
|
+
},
|
|
160
|
+
onDoubleClick() {
|
|
161
|
+
if (disabled)
|
|
162
|
+
return;
|
|
163
|
+
send({ type: "DOUBLE_CLICK", id });
|
|
164
|
+
},
|
|
165
|
+
onKeyDown(event) {
|
|
166
|
+
if (disabled)
|
|
167
|
+
return;
|
|
168
|
+
const moveStep = getEventStep(event) * step;
|
|
169
|
+
const keyMap = {
|
|
170
|
+
Enter() {
|
|
171
|
+
send("ENTER");
|
|
172
|
+
},
|
|
173
|
+
ArrowUp() {
|
|
174
|
+
send({ type: "ARROW_UP", step: moveStep });
|
|
175
|
+
},
|
|
176
|
+
ArrowDown() {
|
|
177
|
+
send({ type: "ARROW_DOWN", step: moveStep });
|
|
178
|
+
},
|
|
179
|
+
ArrowLeft() {
|
|
180
|
+
send({ type: "ARROW_LEFT", step: moveStep });
|
|
181
|
+
},
|
|
182
|
+
ArrowRight() {
|
|
183
|
+
send({ type: "ARROW_RIGHT", step: moveStep });
|
|
184
|
+
},
|
|
185
|
+
Home() {
|
|
186
|
+
send("HOME");
|
|
187
|
+
},
|
|
188
|
+
End() {
|
|
189
|
+
send("END");
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
const key = getEventKey(event, state.context);
|
|
193
|
+
const exec = keyMap[key];
|
|
194
|
+
if (exec) {
|
|
195
|
+
exec(event);
|
|
196
|
+
event.preventDefault();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export {
|
|
205
|
+
connect
|
|
206
|
+
};
|