@zag-js/splitter 0.2.6 → 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.
@@ -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
+ };