@zag-js/splitter 0.2.4 → 0.2.6
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-7IDNY7GP.mjs +217 -0
- package/dist/chunk-A3GF7W2N.mjs +97 -0
- package/dist/chunk-DX6NGFGC.mjs +16 -0
- package/dist/chunk-F2ZDEPE3.mjs +510 -0
- package/dist/index.d.ts +7 -966
- package/dist/index.js +37 -16
- package/dist/index.mjs +10 -794
- package/dist/splitter.anatomy.d.ts +6 -0
- package/dist/splitter.anatomy.js +41 -0
- package/dist/splitter.anatomy.mjs +8 -0
- package/dist/splitter.connect.d.ts +23 -0
- package/dist/splitter.connect.js +342 -0
- package/dist/splitter.connect.mjs +8 -0
- package/dist/splitter.dom.d.ts +37 -0
- package/dist/splitter.dom.js +123 -0
- package/dist/splitter.dom.mjs +6 -0
- package/dist/splitter.machine.d.ts +7 -0
- package/dist/splitter.machine.js +624 -0
- package/dist/splitter.machine.mjs +7 -0
- package/dist/splitter.types.d.ts +96 -0
- package/dist/splitter.types.js +18 -0
- package/dist/splitter.types.mjs +0 -0
- package/package.json +22 -12
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parts
|
|
3
|
+
} from "./chunk-DX6NGFGC.mjs";
|
|
4
|
+
import {
|
|
5
|
+
dom
|
|
6
|
+
} from "./chunk-A3GF7W2N.mjs";
|
|
7
|
+
|
|
8
|
+
// ../../utilities/dom/src/attrs.ts
|
|
9
|
+
var dataAttr = (guard) => {
|
|
10
|
+
return guard ? "" : void 0;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// ../../utilities/dom/src/keyboard-event.ts
|
|
14
|
+
var rtlKeyMap = {
|
|
15
|
+
ArrowLeft: "ArrowRight",
|
|
16
|
+
ArrowRight: "ArrowLeft"
|
|
17
|
+
};
|
|
18
|
+
var sameKeyMap = {
|
|
19
|
+
Up: "ArrowUp",
|
|
20
|
+
Down: "ArrowDown",
|
|
21
|
+
Esc: "Escape",
|
|
22
|
+
" ": "Space",
|
|
23
|
+
",": "Comma",
|
|
24
|
+
Left: "ArrowLeft",
|
|
25
|
+
Right: "ArrowRight"
|
|
26
|
+
};
|
|
27
|
+
function getEventKey(event, options = {}) {
|
|
28
|
+
var _a;
|
|
29
|
+
const { dir = "ltr", orientation = "horizontal" } = options;
|
|
30
|
+
let { key } = event;
|
|
31
|
+
key = (_a = sameKeyMap[key]) != null ? _a : key;
|
|
32
|
+
const isRtl = dir === "rtl" && orientation === "horizontal";
|
|
33
|
+
if (isRtl && key in rtlKeyMap) {
|
|
34
|
+
key = rtlKeyMap[key];
|
|
35
|
+
}
|
|
36
|
+
return key;
|
|
37
|
+
}
|
|
38
|
+
var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
|
|
39
|
+
var ARROW_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
|
|
40
|
+
function getEventStep(event) {
|
|
41
|
+
if (event.ctrlKey || event.metaKey) {
|
|
42
|
+
return 0.1;
|
|
43
|
+
} else {
|
|
44
|
+
const isPageKey = PAGE_KEYS.has(event.key);
|
|
45
|
+
const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.has(event.key);
|
|
46
|
+
return isSkipKey ? 10 : 1;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/splitter.connect.ts
|
|
51
|
+
function connect(state, send, normalize) {
|
|
52
|
+
const isHorizontal = state.context.isHorizontal;
|
|
53
|
+
const isDisabled = state.context.disabled;
|
|
54
|
+
const isFocused = state.hasTag("focus");
|
|
55
|
+
const isDragging = state.matches("dragging");
|
|
56
|
+
const isAtMin = state.context.isAtMin;
|
|
57
|
+
const isAtMax = state.context.isAtMax;
|
|
58
|
+
const min = state.context.min;
|
|
59
|
+
const max = state.context.max;
|
|
60
|
+
const value = state.context.value;
|
|
61
|
+
return {
|
|
62
|
+
isCollapsed: isAtMin,
|
|
63
|
+
isExpanded: isAtMax,
|
|
64
|
+
isFocused,
|
|
65
|
+
isDragging,
|
|
66
|
+
value,
|
|
67
|
+
collapse() {
|
|
68
|
+
send("COLLAPSE");
|
|
69
|
+
},
|
|
70
|
+
expand() {
|
|
71
|
+
send("EXPAND");
|
|
72
|
+
},
|
|
73
|
+
toggle() {
|
|
74
|
+
send("TOGGLE");
|
|
75
|
+
},
|
|
76
|
+
setSize(size) {
|
|
77
|
+
send({ type: "SET_SIZE", size });
|
|
78
|
+
},
|
|
79
|
+
rootProps: normalize.element({
|
|
80
|
+
...parts.root.attrs,
|
|
81
|
+
"data-orientation": state.context.orientation,
|
|
82
|
+
"data-disabled": dataAttr(isDisabled),
|
|
83
|
+
id: dom.getRootId(state.context),
|
|
84
|
+
style: {
|
|
85
|
+
display: "flex",
|
|
86
|
+
flex: "1 1 0%",
|
|
87
|
+
flexDirection: isHorizontal ? "row" : "column"
|
|
88
|
+
}
|
|
89
|
+
}),
|
|
90
|
+
secondaryPaneProps: normalize.element({
|
|
91
|
+
...parts.secondaryPane.attrs,
|
|
92
|
+
"data-disabled": dataAttr(isDisabled),
|
|
93
|
+
id: dom.getSecondaryPaneId(state.context),
|
|
94
|
+
style: {
|
|
95
|
+
height: isHorizontal ? "100%" : "auto",
|
|
96
|
+
width: isHorizontal ? "auto" : "100%",
|
|
97
|
+
flex: "1 1 auto",
|
|
98
|
+
position: "relative"
|
|
99
|
+
}
|
|
100
|
+
}),
|
|
101
|
+
primaryPaneProps: normalize.element({
|
|
102
|
+
...parts.primaryPane.attrs,
|
|
103
|
+
id: dom.getPrimaryPaneId(state.context),
|
|
104
|
+
"data-disabled": dataAttr(isDisabled),
|
|
105
|
+
"data-state": isAtMax ? "at-max" : isAtMin ? "at-min" : "between",
|
|
106
|
+
style: {
|
|
107
|
+
visibility: "visible",
|
|
108
|
+
flex: `0 0 ${value}px`,
|
|
109
|
+
position: "relative",
|
|
110
|
+
userSelect: isDragging ? "none" : "auto",
|
|
111
|
+
...isHorizontal ? { minWidth: `${min}px`, maxWidth: `${max}px` } : { minHeight: `${min}px`, maxHeight: `${max}px` }
|
|
112
|
+
}
|
|
113
|
+
}),
|
|
114
|
+
toggleButtonProps: normalize.element({
|
|
115
|
+
...parts.toggleButton.attrs,
|
|
116
|
+
id: dom.getToggleButtonId(state.context),
|
|
117
|
+
"aria-label": state.context.isAtMin ? "Expand Primary Pane" : "Collapse Primary Pane",
|
|
118
|
+
onClick() {
|
|
119
|
+
send("TOGGLE");
|
|
120
|
+
}
|
|
121
|
+
}),
|
|
122
|
+
labelProps: normalize.element({
|
|
123
|
+
...parts.label.attrs,
|
|
124
|
+
id: dom.getLabelId(state.context)
|
|
125
|
+
}),
|
|
126
|
+
splitterProps: normalize.element({
|
|
127
|
+
...parts.splitter.attrs,
|
|
128
|
+
id: dom.getSplitterId(state.context),
|
|
129
|
+
role: "separator",
|
|
130
|
+
tabIndex: isDisabled ? void 0 : 0,
|
|
131
|
+
"aria-valuenow": value,
|
|
132
|
+
"aria-valuemin": min,
|
|
133
|
+
"aria-valuemax": max,
|
|
134
|
+
"aria-orientation": state.context.orientation,
|
|
135
|
+
"aria-labelledby": dom.getLabelId(state.context),
|
|
136
|
+
"aria-controls": dom.getPrimaryPaneId(state.context),
|
|
137
|
+
"data-orientation": state.context.orientation,
|
|
138
|
+
"data-focus": dataAttr(isFocused),
|
|
139
|
+
"data-disabled": dataAttr(isDisabled),
|
|
140
|
+
style: {
|
|
141
|
+
touchAction: "none",
|
|
142
|
+
userSelect: "none",
|
|
143
|
+
WebkitUserSelect: "none",
|
|
144
|
+
msUserSelect: "none",
|
|
145
|
+
flex: "0 0 auto",
|
|
146
|
+
cursor: dom.getCursor(state.context),
|
|
147
|
+
minHeight: isHorizontal ? "0px" : void 0,
|
|
148
|
+
minWidth: isHorizontal ? void 0 : "0px"
|
|
149
|
+
},
|
|
150
|
+
onPointerDown(event) {
|
|
151
|
+
if (isDisabled) {
|
|
152
|
+
event.preventDefault();
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
send("POINTER_DOWN");
|
|
156
|
+
event.preventDefault();
|
|
157
|
+
event.stopPropagation();
|
|
158
|
+
},
|
|
159
|
+
onPointerOver() {
|
|
160
|
+
if (isDisabled)
|
|
161
|
+
return;
|
|
162
|
+
send("POINTER_OVER");
|
|
163
|
+
},
|
|
164
|
+
onPointerLeave() {
|
|
165
|
+
if (isDisabled)
|
|
166
|
+
return;
|
|
167
|
+
send("POINTER_LEAVE");
|
|
168
|
+
},
|
|
169
|
+
onBlur() {
|
|
170
|
+
send("BLUR");
|
|
171
|
+
},
|
|
172
|
+
onFocus() {
|
|
173
|
+
send("FOCUS");
|
|
174
|
+
},
|
|
175
|
+
onDoubleClick() {
|
|
176
|
+
if (isDisabled)
|
|
177
|
+
return;
|
|
178
|
+
send("DOUBLE_CLICK");
|
|
179
|
+
},
|
|
180
|
+
onKeyDown(event) {
|
|
181
|
+
if (isDisabled)
|
|
182
|
+
return;
|
|
183
|
+
const step = getEventStep(event) * state.context.step;
|
|
184
|
+
const keyMap = {
|
|
185
|
+
ArrowUp() {
|
|
186
|
+
send({ type: "ARROW_UP", step });
|
|
187
|
+
},
|
|
188
|
+
ArrowDown() {
|
|
189
|
+
send({ type: "ARROW_DOWN", step });
|
|
190
|
+
},
|
|
191
|
+
ArrowLeft() {
|
|
192
|
+
send({ type: "ARROW_LEFT", step });
|
|
193
|
+
},
|
|
194
|
+
ArrowRight() {
|
|
195
|
+
send({ type: "ARROW_RIGHT", step });
|
|
196
|
+
},
|
|
197
|
+
Home() {
|
|
198
|
+
send("HOME");
|
|
199
|
+
},
|
|
200
|
+
End() {
|
|
201
|
+
send("END");
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
const key = getEventKey(event, state.context);
|
|
205
|
+
const exec = keyMap[key];
|
|
206
|
+
if (exec) {
|
|
207
|
+
exec(event);
|
|
208
|
+
event.preventDefault();
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
})
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export {
|
|
216
|
+
connect
|
|
217
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
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
|
+
createEmitter: (ctx, target) => {
|
|
30
|
+
const win = dom2.getWin(ctx);
|
|
31
|
+
return function emit(evt, detail, options) {
|
|
32
|
+
const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
|
|
33
|
+
const eventName = `zag:${evt}`;
|
|
34
|
+
const init = { bubbles, cancelable, composed, detail };
|
|
35
|
+
const event = new win.CustomEvent(eventName, init);
|
|
36
|
+
target.dispatchEvent(event);
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
createListener: (target) => {
|
|
40
|
+
return function listen(evt, handler) {
|
|
41
|
+
const eventName = `zag:${evt}`;
|
|
42
|
+
const listener = (e) => handler(e);
|
|
43
|
+
target.addEventListener(eventName, listener);
|
|
44
|
+
return () => target.removeEventListener(eventName, listener);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
...dom2,
|
|
50
|
+
...helpers
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/splitter.dom.ts
|
|
55
|
+
var dom = defineDomHelpers({
|
|
56
|
+
getRootId: (ctx) => {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `splitter:${ctx.id}`;
|
|
59
|
+
},
|
|
60
|
+
getSplitterId: (ctx) => {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.splitter) != null ? _b : `splitter:${ctx.id}:splitter`;
|
|
63
|
+
},
|
|
64
|
+
getToggleButtonId: (ctx) => {
|
|
65
|
+
var _a, _b;
|
|
66
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.toggleBtn) != null ? _b : `splitter:${ctx.id}:toggle-btn`;
|
|
67
|
+
},
|
|
68
|
+
getLabelId: (ctx) => {
|
|
69
|
+
var _a, _b;
|
|
70
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `splitter:${ctx.id}:label`;
|
|
71
|
+
},
|
|
72
|
+
getPrimaryPaneId: (ctx) => {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.primaryPane) != null ? _b : `splitter:${ctx.id}:primary`;
|
|
75
|
+
},
|
|
76
|
+
getSecondaryPaneId: (ctx) => {
|
|
77
|
+
var _a, _b;
|
|
78
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.secondaryPane) != null ? _b : `splitter:${ctx.id}:secondary`;
|
|
79
|
+
},
|
|
80
|
+
getSplitterEl: (ctx) => dom.getById(ctx, dom.getSplitterId(ctx)),
|
|
81
|
+
getPrimaryPaneEl: (ctx) => dom.getById(ctx, dom.getPrimaryPaneId(ctx)),
|
|
82
|
+
getCursor(ctx) {
|
|
83
|
+
if (ctx.disabled || ctx.fixed)
|
|
84
|
+
return "default";
|
|
85
|
+
const x = ctx.isHorizontal;
|
|
86
|
+
let cursor = x ? "col-resize" : "row-resize";
|
|
87
|
+
if (ctx.isAtMin)
|
|
88
|
+
cursor = x ? "e-resize" : "s-resize";
|
|
89
|
+
if (ctx.isAtMax)
|
|
90
|
+
cursor = x ? "w-resize" : "n-resize";
|
|
91
|
+
return cursor;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
export {
|
|
96
|
+
dom
|
|
97
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/splitter.anatomy.ts
|
|
2
|
+
import { createAnatomy } from "@zag-js/anatomy";
|
|
3
|
+
var anatomy = createAnatomy("splitter").parts(
|
|
4
|
+
"root",
|
|
5
|
+
"secondaryPane",
|
|
6
|
+
"primaryPane",
|
|
7
|
+
"toggleButton",
|
|
8
|
+
"label",
|
|
9
|
+
"splitter"
|
|
10
|
+
);
|
|
11
|
+
var parts = anatomy.build();
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
anatomy,
|
|
15
|
+
parts
|
|
16
|
+
};
|