@zag-js/splitter 0.2.6 → 0.2.8

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.
@@ -0,0 +1,209 @@
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
+ const api = {
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(props) {
98
+ const { id, disabled } = props;
99
+ const ids = id.split(":");
100
+ const panelIds = ids.map((id2) => dom.getPanelId(state.context, id2));
101
+ const panels = getHandleBounds(state.context, id);
102
+ return {
103
+ isDisabled: !!disabled,
104
+ isFocused: state.context.activeResizeId === id && isFocused,
105
+ panelIds,
106
+ min: panels == null ? void 0 : panels.min,
107
+ max: panels == null ? void 0 : panels.max,
108
+ value: 0
109
+ };
110
+ },
111
+ getResizeTriggerProps(props) {
112
+ const { id, disabled, step = 1 } = props;
113
+ const triggerState = api.getResizeTriggerState(props);
114
+ return normalize.element({
115
+ ...parts.resizeTrigger.attrs,
116
+ dir: state.context.dir,
117
+ id: dom.getResizeTriggerId(state.context, id),
118
+ role: "separator",
119
+ "data-ownedby": dom.getRootId(state.context),
120
+ tabIndex: disabled ? void 0 : 0,
121
+ "aria-valuenow": triggerState.value,
122
+ "aria-valuemin": triggerState.min,
123
+ "aria-valuemax": triggerState.max,
124
+ "data-orientation": state.context.orientation,
125
+ "aria-orientation": state.context.orientation,
126
+ "aria-controls": triggerState.panelIds.join(" "),
127
+ "data-focus": dataAttr(triggerState.isFocused),
128
+ "data-disabled": dataAttr(disabled),
129
+ style: {
130
+ touchAction: "none",
131
+ userSelect: "none",
132
+ flex: "0 0 auto",
133
+ pointerEvents: isDragging && !triggerState.isFocused ? "none" : void 0,
134
+ cursor: isHorizontal ? "col-resize" : "row-resize",
135
+ [isHorizontal ? "minHeight" : "minWidth"]: "0"
136
+ },
137
+ onPointerDown(event) {
138
+ if (disabled) {
139
+ event.preventDefault();
140
+ return;
141
+ }
142
+ send({ type: "POINTER_DOWN", id });
143
+ event.preventDefault();
144
+ event.stopPropagation();
145
+ },
146
+ onPointerOver() {
147
+ if (disabled)
148
+ return;
149
+ send({ type: "POINTER_OVER", id });
150
+ },
151
+ onPointerLeave() {
152
+ if (disabled)
153
+ return;
154
+ send({ type: "POINTER_LEAVE", id });
155
+ },
156
+ onBlur() {
157
+ send("BLUR");
158
+ },
159
+ onFocus() {
160
+ send({ type: "FOCUS", id });
161
+ },
162
+ onDoubleClick() {
163
+ if (disabled)
164
+ return;
165
+ send({ type: "DOUBLE_CLICK", id });
166
+ },
167
+ onKeyDown(event) {
168
+ if (disabled)
169
+ return;
170
+ const moveStep = getEventStep(event) * step;
171
+ const keyMap = {
172
+ Enter() {
173
+ send("ENTER");
174
+ },
175
+ ArrowUp() {
176
+ send({ type: "ARROW_UP", step: moveStep });
177
+ },
178
+ ArrowDown() {
179
+ send({ type: "ARROW_DOWN", step: moveStep });
180
+ },
181
+ ArrowLeft() {
182
+ send({ type: "ARROW_LEFT", step: moveStep });
183
+ },
184
+ ArrowRight() {
185
+ send({ type: "ARROW_RIGHT", step: moveStep });
186
+ },
187
+ Home() {
188
+ send("HOME");
189
+ },
190
+ End() {
191
+ send("END");
192
+ }
193
+ };
194
+ const key = getEventKey(event, state.context);
195
+ const exec = keyMap[key];
196
+ if (exec) {
197
+ exec(event);
198
+ event.preventDefault();
199
+ }
200
+ }
201
+ });
202
+ }
203
+ };
204
+ return api;
205
+ }
206
+
207
+ export {
208
+ connect
209
+ };