@zag-js/splitter 1.34.1 → 1.35.0
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.mts +9 -254
- package/dist/index.d.ts +9 -254
- package/dist/index.js +37 -1158
- package/dist/index.mjs +11 -1151
- package/dist/splitter.anatomy.d.mts +6 -0
- 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.mts +7 -0
- package/dist/splitter.connect.d.ts +7 -0
- package/dist/splitter.connect.js +298 -0
- package/dist/splitter.connect.mjs +263 -0
- package/dist/splitter.dom.d.mts +19 -0
- package/dist/splitter.dom.d.ts +19 -0
- package/dist/splitter.dom.js +89 -0
- package/dist/splitter.dom.mjs +52 -0
- package/dist/splitter.machine.d.mts +7 -0
- package/dist/splitter.machine.d.ts +7 -0
- package/dist/splitter.machine.js +509 -0
- package/dist/splitter.machine.mjs +482 -0
- package/dist/splitter.props.d.mts +12 -0
- package/dist/splitter.props.d.ts +12 -0
- package/dist/splitter.props.js +63 -0
- package/dist/splitter.props.mjs +33 -0
- package/dist/splitter.types.d.mts +237 -0
- package/dist/splitter.types.d.ts +237 -0
- package/dist/splitter.types.js +18 -0
- package/dist/splitter.types.mjs +0 -0
- package/dist/utils/aria.d.mts +27 -0
- package/dist/utils/aria.d.ts +27 -0
- package/dist/utils/aria.js +79 -0
- package/dist/utils/aria.mjs +53 -0
- package/dist/utils/fuzzy.d.mts +10 -0
- package/dist/utils/fuzzy.d.ts +10 -0
- package/dist/utils/fuzzy.js +60 -0
- package/dist/utils/fuzzy.mjs +32 -0
- package/dist/utils/panel.d.mts +34 -0
- package/dist/utils/panel.d.ts +34 -0
- package/dist/utils/panel.js +147 -0
- package/dist/utils/panel.mjs +114 -0
- package/dist/utils/resize-by-delta.d.mts +20 -0
- package/dist/utils/resize-by-delta.d.ts +20 -0
- package/dist/utils/resize-by-delta.js +165 -0
- package/dist/utils/resize-by-delta.mjs +140 -0
- package/dist/utils/resize-panel.d.mts +16 -0
- package/dist/utils/resize-panel.d.ts +16 -0
- package/dist/utils/resize-panel.js +51 -0
- package/dist/utils/resize-panel.mjs +26 -0
- package/dist/utils/validate-sizes.d.mts +15 -0
- package/dist/utils/validate-sizes.d.ts +15 -0
- package/dist/utils/validate-sizes.js +72 -0
- package/dist/utils/validate-sizes.mjs +47 -0
- package/package.json +17 -7
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as _zag_js_anatomy from '@zag-js/anatomy';
|
|
2
|
+
|
|
3
|
+
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "panel" | "resizeTrigger" | "resizeTriggerIndicator">;
|
|
4
|
+
declare const parts: Record<"root" | "panel" | "resizeTrigger" | "resizeTriggerIndicator", _zag_js_anatomy.AnatomyPart>;
|
|
5
|
+
|
|
6
|
+
export { anatomy, parts };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as _zag_js_anatomy from '@zag-js/anatomy';
|
|
2
|
+
|
|
3
|
+
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "panel" | "resizeTrigger" | "resizeTriggerIndicator">;
|
|
4
|
+
declare const parts: Record<"root" | "panel" | "resizeTrigger" | "resizeTriggerIndicator", _zag_js_anatomy.AnatomyPart>;
|
|
5
|
+
|
|
6
|
+
export { anatomy, parts };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/splitter.anatomy.ts
|
|
21
|
+
var splitter_anatomy_exports = {};
|
|
22
|
+
__export(splitter_anatomy_exports, {
|
|
23
|
+
anatomy: () => anatomy,
|
|
24
|
+
parts: () => parts
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(splitter_anatomy_exports);
|
|
27
|
+
var import_anatomy = require("@zag-js/anatomy");
|
|
28
|
+
var anatomy = (0, import_anatomy.createAnatomy)("splitter").parts("root", "panel", "resizeTrigger", "resizeTriggerIndicator");
|
|
29
|
+
var parts = anatomy.build();
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
anatomy,
|
|
33
|
+
parts
|
|
34
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PropTypes, NormalizeProps } from '@zag-js/types';
|
|
2
|
+
import { SplitterService, SplitterApi } from './splitter.types.mjs';
|
|
3
|
+
import '@zag-js/core';
|
|
4
|
+
|
|
5
|
+
declare function connect<T extends PropTypes>(service: SplitterService, normalize: NormalizeProps<T>): SplitterApi<T>;
|
|
6
|
+
|
|
7
|
+
export { connect };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PropTypes, NormalizeProps } from '@zag-js/types';
|
|
2
|
+
import { SplitterService, SplitterApi } from './splitter.types.js';
|
|
3
|
+
import '@zag-js/core';
|
|
4
|
+
|
|
5
|
+
declare function connect<T extends PropTypes>(service: SplitterService, normalize: NormalizeProps<T>): SplitterApi<T>;
|
|
6
|
+
|
|
7
|
+
export { connect };
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/splitter.connect.ts
|
|
31
|
+
var splitter_connect_exports = {};
|
|
32
|
+
__export(splitter_connect_exports, {
|
|
33
|
+
connect: () => connect
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(splitter_connect_exports);
|
|
36
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
37
|
+
var import_utils = require("@zag-js/utils");
|
|
38
|
+
var import_splitter = require("./splitter.anatomy.cjs");
|
|
39
|
+
var dom = __toESM(require("./splitter.dom.cjs"));
|
|
40
|
+
var import_aria = require("./utils/aria.cjs");
|
|
41
|
+
var import_fuzzy = require("./utils/fuzzy.cjs");
|
|
42
|
+
var import_panel = require("./utils/panel.cjs");
|
|
43
|
+
function connect(service, normalize) {
|
|
44
|
+
const { state, send, prop, computed, context, scope } = service;
|
|
45
|
+
const horizontal = computed("horizontal");
|
|
46
|
+
const dragging = state.matches("dragging");
|
|
47
|
+
const orientation = prop("orientation");
|
|
48
|
+
const getPanelStyle = (id) => {
|
|
49
|
+
const panels = prop("panels");
|
|
50
|
+
const panelIndex = panels.findIndex((panel) => panel.id === id);
|
|
51
|
+
const defaultSize = context.initial("size")[panelIndex];
|
|
52
|
+
const dragState = context.get("dragState");
|
|
53
|
+
return (0, import_panel.getPanelFlexBoxStyle)({
|
|
54
|
+
defaultSize,
|
|
55
|
+
dragState,
|
|
56
|
+
sizes: context.get("size"),
|
|
57
|
+
panels,
|
|
58
|
+
panelIndex
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
const getResizeTriggerState = (props) => {
|
|
62
|
+
const { id, disabled } = props;
|
|
63
|
+
const dragging2 = context.get("dragState")?.resizeTriggerId === id;
|
|
64
|
+
const focused = dragging2 || context.get("keyboardState")?.resizeTriggerId === id;
|
|
65
|
+
return {
|
|
66
|
+
dragging: dragging2,
|
|
67
|
+
focused,
|
|
68
|
+
disabled: !!disabled
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
dragging,
|
|
73
|
+
orientation,
|
|
74
|
+
getPanels() {
|
|
75
|
+
return prop("panels");
|
|
76
|
+
},
|
|
77
|
+
getPanelById(id) {
|
|
78
|
+
return (0, import_panel.getPanelById)(prop("panels"), id);
|
|
79
|
+
},
|
|
80
|
+
getItems() {
|
|
81
|
+
return prop("panels").flatMap((panel, index, arr) => {
|
|
82
|
+
const nextPanel = arr[index + 1];
|
|
83
|
+
if (panel && nextPanel) {
|
|
84
|
+
return [
|
|
85
|
+
{ type: "panel", id: panel.id },
|
|
86
|
+
{ type: "handle", id: `${panel.id}:${nextPanel.id}` }
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
return [{ type: "panel", id: panel.id }];
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
getSizes() {
|
|
93
|
+
return context.get("size");
|
|
94
|
+
},
|
|
95
|
+
setSizes(size) {
|
|
96
|
+
send({ type: "SIZE.SET", size });
|
|
97
|
+
},
|
|
98
|
+
resetSizes() {
|
|
99
|
+
send({ type: "SIZE.SET", size: context.initial("size") });
|
|
100
|
+
},
|
|
101
|
+
collapsePanel(id) {
|
|
102
|
+
send({ type: "PANEL.COLLAPSE", id });
|
|
103
|
+
},
|
|
104
|
+
expandPanel(id, minSize) {
|
|
105
|
+
send({ type: "PANEL.EXPAND", id, minSize });
|
|
106
|
+
},
|
|
107
|
+
resizePanel(id, unsafePanelSize) {
|
|
108
|
+
send({ type: "PANEL.RESIZE", id, size: unsafePanelSize });
|
|
109
|
+
},
|
|
110
|
+
getPanelSize(id) {
|
|
111
|
+
const panels = prop("panels");
|
|
112
|
+
const size = context.get("size");
|
|
113
|
+
const panelData = (0, import_panel.getPanelById)(panels, id);
|
|
114
|
+
const { panelSize } = (0, import_panel.panelDataHelper)(panels, panelData, size);
|
|
115
|
+
(0, import_utils.ensure)(panelSize, () => `Panel size not found for panel "${panelData.id}"`);
|
|
116
|
+
return panelSize;
|
|
117
|
+
},
|
|
118
|
+
isPanelCollapsed(id) {
|
|
119
|
+
const panels = prop("panels");
|
|
120
|
+
const size = context.get("size");
|
|
121
|
+
const panelData = (0, import_panel.getPanelById)(panels, id);
|
|
122
|
+
const { collapsedSize = 0, collapsible, panelSize } = (0, import_panel.panelDataHelper)(panels, panelData, size);
|
|
123
|
+
(0, import_utils.ensure)(panelSize, () => `Panel size not found for panel "${panelData.id}"`);
|
|
124
|
+
return collapsible === true && (0, import_fuzzy.fuzzyNumbersEqual)(panelSize, collapsedSize);
|
|
125
|
+
},
|
|
126
|
+
isPanelExpanded(id) {
|
|
127
|
+
const panels = prop("panels");
|
|
128
|
+
const size = context.get("size");
|
|
129
|
+
const panelData = (0, import_panel.getPanelById)(panels, id);
|
|
130
|
+
const { collapsedSize = 0, collapsible, panelSize } = (0, import_panel.panelDataHelper)(panels, panelData, size);
|
|
131
|
+
(0, import_utils.ensure)(panelSize, () => `Panel size not found for panel "${panelData.id}"`);
|
|
132
|
+
return !collapsible || (0, import_fuzzy.fuzzyCompareNumbers)(panelSize, collapsedSize) > 0;
|
|
133
|
+
},
|
|
134
|
+
getLayout() {
|
|
135
|
+
return (0, import_panel.getPanelLayout)(prop("panels"));
|
|
136
|
+
},
|
|
137
|
+
getRootProps() {
|
|
138
|
+
return normalize.element({
|
|
139
|
+
...import_splitter.parts.root.attrs,
|
|
140
|
+
"data-orientation": orientation,
|
|
141
|
+
"data-dragging": (0, import_dom_query.dataAttr)(dragging),
|
|
142
|
+
id: dom.getRootId(scope),
|
|
143
|
+
dir: prop("dir"),
|
|
144
|
+
style: {
|
|
145
|
+
display: "flex",
|
|
146
|
+
flexDirection: horizontal ? "row" : "column",
|
|
147
|
+
height: "100%",
|
|
148
|
+
width: "100%",
|
|
149
|
+
overflow: "hidden"
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
getPanelProps(props) {
|
|
154
|
+
const { id } = props;
|
|
155
|
+
return normalize.element({
|
|
156
|
+
...import_splitter.parts.panel.attrs,
|
|
157
|
+
"data-orientation": orientation,
|
|
158
|
+
"data-dragging": (0, import_dom_query.dataAttr)(dragging),
|
|
159
|
+
dir: prop("dir"),
|
|
160
|
+
"data-id": id,
|
|
161
|
+
"data-index": (0, import_panel.findPanelIndex)(prop("panels"), id),
|
|
162
|
+
id: dom.getPanelId(scope, id),
|
|
163
|
+
"data-ownedby": dom.getRootId(scope),
|
|
164
|
+
style: getPanelStyle(id)
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
getResizeTriggerState,
|
|
168
|
+
getResizeTriggerIndicator(props) {
|
|
169
|
+
const triggerState = getResizeTriggerState(props);
|
|
170
|
+
return normalize.element({
|
|
171
|
+
...import_splitter.parts.resizeTriggerIndicator.attrs,
|
|
172
|
+
"data-orientation": orientation,
|
|
173
|
+
"data-focus": (0, import_dom_query.dataAttr)(triggerState.focused),
|
|
174
|
+
"data-dragging": (0, import_dom_query.dataAttr)(triggerState.dragging),
|
|
175
|
+
"data-disabled": (0, import_dom_query.dataAttr)(triggerState.disabled),
|
|
176
|
+
"data-ownedby": dom.getRootId(scope)
|
|
177
|
+
});
|
|
178
|
+
},
|
|
179
|
+
getResizeTriggerProps(props) {
|
|
180
|
+
const { id } = props;
|
|
181
|
+
const triggerState = getResizeTriggerState(props);
|
|
182
|
+
const aria = (0, import_aria.getAriaValue)(context.get("size"), prop("panels"), id);
|
|
183
|
+
return normalize.element({
|
|
184
|
+
...import_splitter.parts.resizeTrigger.attrs,
|
|
185
|
+
dir: prop("dir"),
|
|
186
|
+
id: dom.getResizeTriggerId(scope, id),
|
|
187
|
+
role: "separator",
|
|
188
|
+
"data-id": id,
|
|
189
|
+
"data-ownedby": dom.getRootId(scope),
|
|
190
|
+
tabIndex: triggerState.disabled ? void 0 : 0,
|
|
191
|
+
"aria-valuenow": aria.valueNow,
|
|
192
|
+
"aria-valuemin": aria.valueMin,
|
|
193
|
+
"aria-valuemax": aria.valueMax,
|
|
194
|
+
"data-orientation": orientation,
|
|
195
|
+
"aria-orientation": orientation,
|
|
196
|
+
"aria-controls": `${dom.getPanelId(scope, aria.beforeId)} ${dom.getPanelId(scope, aria.afterId)}`,
|
|
197
|
+
"data-focus": (0, import_dom_query.dataAttr)(triggerState.focused),
|
|
198
|
+
"data-dragging": (0, import_dom_query.dataAttr)(triggerState.dragging),
|
|
199
|
+
"data-disabled": (0, import_dom_query.dataAttr)(triggerState.disabled),
|
|
200
|
+
style: {
|
|
201
|
+
touchAction: "none",
|
|
202
|
+
userSelect: "none",
|
|
203
|
+
WebkitUserSelect: "none",
|
|
204
|
+
flex: "0 0 auto",
|
|
205
|
+
pointerEvents: triggerState.disabled ? "none" : triggerState.dragging && !triggerState.focused ? "none" : void 0,
|
|
206
|
+
cursor: triggerState.disabled ? void 0 : horizontal ? "col-resize" : "row-resize",
|
|
207
|
+
[horizontal ? "minHeight" : "minWidth"]: "0"
|
|
208
|
+
},
|
|
209
|
+
onPointerDown(event) {
|
|
210
|
+
if (!(0, import_dom_query.isLeftClick)(event)) return;
|
|
211
|
+
if (triggerState.disabled) {
|
|
212
|
+
event.preventDefault();
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const point = (0, import_dom_query.getEventPoint)(event);
|
|
216
|
+
send({ type: "POINTER_DOWN", id, point });
|
|
217
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
218
|
+
event.preventDefault();
|
|
219
|
+
event.stopPropagation();
|
|
220
|
+
},
|
|
221
|
+
onPointerUp(event) {
|
|
222
|
+
if (triggerState.disabled) return;
|
|
223
|
+
if (event.currentTarget.hasPointerCapture(event.pointerId)) {
|
|
224
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
onPointerOver() {
|
|
228
|
+
if (triggerState.disabled) return;
|
|
229
|
+
send({ type: "POINTER_OVER", id });
|
|
230
|
+
},
|
|
231
|
+
onPointerLeave() {
|
|
232
|
+
if (triggerState.disabled) return;
|
|
233
|
+
send({ type: "POINTER_LEAVE", id });
|
|
234
|
+
},
|
|
235
|
+
onBlur() {
|
|
236
|
+
if (triggerState.disabled) return;
|
|
237
|
+
send({ type: "BLUR" });
|
|
238
|
+
},
|
|
239
|
+
onFocus() {
|
|
240
|
+
if (triggerState.disabled) return;
|
|
241
|
+
send({ type: "FOCUS", id });
|
|
242
|
+
},
|
|
243
|
+
onKeyDown(event) {
|
|
244
|
+
if (event.defaultPrevented) return;
|
|
245
|
+
if (triggerState.disabled) return;
|
|
246
|
+
const keyboardResizeBy = prop("keyboardResizeBy");
|
|
247
|
+
let delta = 0;
|
|
248
|
+
if (event.shiftKey) {
|
|
249
|
+
delta = 10;
|
|
250
|
+
} else if (keyboardResizeBy != null) {
|
|
251
|
+
delta = keyboardResizeBy;
|
|
252
|
+
} else {
|
|
253
|
+
delta = 1;
|
|
254
|
+
}
|
|
255
|
+
const keyMap = {
|
|
256
|
+
Enter() {
|
|
257
|
+
send({ type: "ENTER", id });
|
|
258
|
+
},
|
|
259
|
+
ArrowUp() {
|
|
260
|
+
send({ type: "KEYBOARD_MOVE", id, delta: horizontal ? 0 : -delta });
|
|
261
|
+
},
|
|
262
|
+
ArrowDown() {
|
|
263
|
+
send({ type: "KEYBOARD_MOVE", id, delta: horizontal ? 0 : delta });
|
|
264
|
+
},
|
|
265
|
+
ArrowLeft() {
|
|
266
|
+
send({ type: "KEYBOARD_MOVE", id, delta: horizontal ? -delta : 0 });
|
|
267
|
+
},
|
|
268
|
+
ArrowRight() {
|
|
269
|
+
send({ type: "KEYBOARD_MOVE", id, delta: horizontal ? delta : 0 });
|
|
270
|
+
},
|
|
271
|
+
Home() {
|
|
272
|
+
send({ type: "KEYBOARD_MOVE", id, delta: -100 });
|
|
273
|
+
},
|
|
274
|
+
End() {
|
|
275
|
+
send({ type: "KEYBOARD_MOVE", id, delta: 100 });
|
|
276
|
+
},
|
|
277
|
+
F6() {
|
|
278
|
+
send({ type: "FOCUS.CYCLE", id, shiftKey: event.shiftKey });
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
const key = (0, import_dom_query.getEventKey)(event, {
|
|
282
|
+
dir: prop("dir"),
|
|
283
|
+
orientation
|
|
284
|
+
});
|
|
285
|
+
const exec = keyMap[key];
|
|
286
|
+
if (exec) {
|
|
287
|
+
exec(event);
|
|
288
|
+
event.preventDefault();
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
296
|
+
0 && (module.exports = {
|
|
297
|
+
connect
|
|
298
|
+
});
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
// src/splitter.connect.ts
|
|
2
|
+
import { dataAttr, getEventKey, getEventPoint, isLeftClick } from "@zag-js/dom-query";
|
|
3
|
+
import { ensure } from "@zag-js/utils";
|
|
4
|
+
import { parts } from "./splitter.anatomy.mjs";
|
|
5
|
+
import * as dom from "./splitter.dom.mjs";
|
|
6
|
+
import { getAriaValue } from "./utils/aria.mjs";
|
|
7
|
+
import { fuzzyCompareNumbers, fuzzyNumbersEqual } from "./utils/fuzzy.mjs";
|
|
8
|
+
import { findPanelIndex, getPanelById, getPanelFlexBoxStyle, getPanelLayout, panelDataHelper } from "./utils/panel.mjs";
|
|
9
|
+
function connect(service, normalize) {
|
|
10
|
+
const { state, send, prop, computed, context, scope } = service;
|
|
11
|
+
const horizontal = computed("horizontal");
|
|
12
|
+
const dragging = state.matches("dragging");
|
|
13
|
+
const orientation = prop("orientation");
|
|
14
|
+
const getPanelStyle = (id) => {
|
|
15
|
+
const panels = prop("panels");
|
|
16
|
+
const panelIndex = panels.findIndex((panel) => panel.id === id);
|
|
17
|
+
const defaultSize = context.initial("size")[panelIndex];
|
|
18
|
+
const dragState = context.get("dragState");
|
|
19
|
+
return getPanelFlexBoxStyle({
|
|
20
|
+
defaultSize,
|
|
21
|
+
dragState,
|
|
22
|
+
sizes: context.get("size"),
|
|
23
|
+
panels,
|
|
24
|
+
panelIndex
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
const getResizeTriggerState = (props) => {
|
|
28
|
+
const { id, disabled } = props;
|
|
29
|
+
const dragging2 = context.get("dragState")?.resizeTriggerId === id;
|
|
30
|
+
const focused = dragging2 || context.get("keyboardState")?.resizeTriggerId === id;
|
|
31
|
+
return {
|
|
32
|
+
dragging: dragging2,
|
|
33
|
+
focused,
|
|
34
|
+
disabled: !!disabled
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
dragging,
|
|
39
|
+
orientation,
|
|
40
|
+
getPanels() {
|
|
41
|
+
return prop("panels");
|
|
42
|
+
},
|
|
43
|
+
getPanelById(id) {
|
|
44
|
+
return getPanelById(prop("panels"), id);
|
|
45
|
+
},
|
|
46
|
+
getItems() {
|
|
47
|
+
return prop("panels").flatMap((panel, index, arr) => {
|
|
48
|
+
const nextPanel = arr[index + 1];
|
|
49
|
+
if (panel && nextPanel) {
|
|
50
|
+
return [
|
|
51
|
+
{ type: "panel", id: panel.id },
|
|
52
|
+
{ type: "handle", id: `${panel.id}:${nextPanel.id}` }
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
return [{ type: "panel", id: panel.id }];
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
getSizes() {
|
|
59
|
+
return context.get("size");
|
|
60
|
+
},
|
|
61
|
+
setSizes(size) {
|
|
62
|
+
send({ type: "SIZE.SET", size });
|
|
63
|
+
},
|
|
64
|
+
resetSizes() {
|
|
65
|
+
send({ type: "SIZE.SET", size: context.initial("size") });
|
|
66
|
+
},
|
|
67
|
+
collapsePanel(id) {
|
|
68
|
+
send({ type: "PANEL.COLLAPSE", id });
|
|
69
|
+
},
|
|
70
|
+
expandPanel(id, minSize) {
|
|
71
|
+
send({ type: "PANEL.EXPAND", id, minSize });
|
|
72
|
+
},
|
|
73
|
+
resizePanel(id, unsafePanelSize) {
|
|
74
|
+
send({ type: "PANEL.RESIZE", id, size: unsafePanelSize });
|
|
75
|
+
},
|
|
76
|
+
getPanelSize(id) {
|
|
77
|
+
const panels = prop("panels");
|
|
78
|
+
const size = context.get("size");
|
|
79
|
+
const panelData = getPanelById(panels, id);
|
|
80
|
+
const { panelSize } = panelDataHelper(panels, panelData, size);
|
|
81
|
+
ensure(panelSize, () => `Panel size not found for panel "${panelData.id}"`);
|
|
82
|
+
return panelSize;
|
|
83
|
+
},
|
|
84
|
+
isPanelCollapsed(id) {
|
|
85
|
+
const panels = prop("panels");
|
|
86
|
+
const size = context.get("size");
|
|
87
|
+
const panelData = getPanelById(panels, id);
|
|
88
|
+
const { collapsedSize = 0, collapsible, panelSize } = panelDataHelper(panels, panelData, size);
|
|
89
|
+
ensure(panelSize, () => `Panel size not found for panel "${panelData.id}"`);
|
|
90
|
+
return collapsible === true && fuzzyNumbersEqual(panelSize, collapsedSize);
|
|
91
|
+
},
|
|
92
|
+
isPanelExpanded(id) {
|
|
93
|
+
const panels = prop("panels");
|
|
94
|
+
const size = context.get("size");
|
|
95
|
+
const panelData = getPanelById(panels, id);
|
|
96
|
+
const { collapsedSize = 0, collapsible, panelSize } = panelDataHelper(panels, panelData, size);
|
|
97
|
+
ensure(panelSize, () => `Panel size not found for panel "${panelData.id}"`);
|
|
98
|
+
return !collapsible || fuzzyCompareNumbers(panelSize, collapsedSize) > 0;
|
|
99
|
+
},
|
|
100
|
+
getLayout() {
|
|
101
|
+
return getPanelLayout(prop("panels"));
|
|
102
|
+
},
|
|
103
|
+
getRootProps() {
|
|
104
|
+
return normalize.element({
|
|
105
|
+
...parts.root.attrs,
|
|
106
|
+
"data-orientation": orientation,
|
|
107
|
+
"data-dragging": dataAttr(dragging),
|
|
108
|
+
id: dom.getRootId(scope),
|
|
109
|
+
dir: prop("dir"),
|
|
110
|
+
style: {
|
|
111
|
+
display: "flex",
|
|
112
|
+
flexDirection: horizontal ? "row" : "column",
|
|
113
|
+
height: "100%",
|
|
114
|
+
width: "100%",
|
|
115
|
+
overflow: "hidden"
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
getPanelProps(props) {
|
|
120
|
+
const { id } = props;
|
|
121
|
+
return normalize.element({
|
|
122
|
+
...parts.panel.attrs,
|
|
123
|
+
"data-orientation": orientation,
|
|
124
|
+
"data-dragging": dataAttr(dragging),
|
|
125
|
+
dir: prop("dir"),
|
|
126
|
+
"data-id": id,
|
|
127
|
+
"data-index": findPanelIndex(prop("panels"), id),
|
|
128
|
+
id: dom.getPanelId(scope, id),
|
|
129
|
+
"data-ownedby": dom.getRootId(scope),
|
|
130
|
+
style: getPanelStyle(id)
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
getResizeTriggerState,
|
|
134
|
+
getResizeTriggerIndicator(props) {
|
|
135
|
+
const triggerState = getResizeTriggerState(props);
|
|
136
|
+
return normalize.element({
|
|
137
|
+
...parts.resizeTriggerIndicator.attrs,
|
|
138
|
+
"data-orientation": orientation,
|
|
139
|
+
"data-focus": dataAttr(triggerState.focused),
|
|
140
|
+
"data-dragging": dataAttr(triggerState.dragging),
|
|
141
|
+
"data-disabled": dataAttr(triggerState.disabled),
|
|
142
|
+
"data-ownedby": dom.getRootId(scope)
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
getResizeTriggerProps(props) {
|
|
146
|
+
const { id } = props;
|
|
147
|
+
const triggerState = getResizeTriggerState(props);
|
|
148
|
+
const aria = getAriaValue(context.get("size"), prop("panels"), id);
|
|
149
|
+
return normalize.element({
|
|
150
|
+
...parts.resizeTrigger.attrs,
|
|
151
|
+
dir: prop("dir"),
|
|
152
|
+
id: dom.getResizeTriggerId(scope, id),
|
|
153
|
+
role: "separator",
|
|
154
|
+
"data-id": id,
|
|
155
|
+
"data-ownedby": dom.getRootId(scope),
|
|
156
|
+
tabIndex: triggerState.disabled ? void 0 : 0,
|
|
157
|
+
"aria-valuenow": aria.valueNow,
|
|
158
|
+
"aria-valuemin": aria.valueMin,
|
|
159
|
+
"aria-valuemax": aria.valueMax,
|
|
160
|
+
"data-orientation": orientation,
|
|
161
|
+
"aria-orientation": orientation,
|
|
162
|
+
"aria-controls": `${dom.getPanelId(scope, aria.beforeId)} ${dom.getPanelId(scope, aria.afterId)}`,
|
|
163
|
+
"data-focus": dataAttr(triggerState.focused),
|
|
164
|
+
"data-dragging": dataAttr(triggerState.dragging),
|
|
165
|
+
"data-disabled": dataAttr(triggerState.disabled),
|
|
166
|
+
style: {
|
|
167
|
+
touchAction: "none",
|
|
168
|
+
userSelect: "none",
|
|
169
|
+
WebkitUserSelect: "none",
|
|
170
|
+
flex: "0 0 auto",
|
|
171
|
+
pointerEvents: triggerState.disabled ? "none" : triggerState.dragging && !triggerState.focused ? "none" : void 0,
|
|
172
|
+
cursor: triggerState.disabled ? void 0 : horizontal ? "col-resize" : "row-resize",
|
|
173
|
+
[horizontal ? "minHeight" : "minWidth"]: "0"
|
|
174
|
+
},
|
|
175
|
+
onPointerDown(event) {
|
|
176
|
+
if (!isLeftClick(event)) return;
|
|
177
|
+
if (triggerState.disabled) {
|
|
178
|
+
event.preventDefault();
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const point = getEventPoint(event);
|
|
182
|
+
send({ type: "POINTER_DOWN", id, point });
|
|
183
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
184
|
+
event.preventDefault();
|
|
185
|
+
event.stopPropagation();
|
|
186
|
+
},
|
|
187
|
+
onPointerUp(event) {
|
|
188
|
+
if (triggerState.disabled) return;
|
|
189
|
+
if (event.currentTarget.hasPointerCapture(event.pointerId)) {
|
|
190
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
onPointerOver() {
|
|
194
|
+
if (triggerState.disabled) return;
|
|
195
|
+
send({ type: "POINTER_OVER", id });
|
|
196
|
+
},
|
|
197
|
+
onPointerLeave() {
|
|
198
|
+
if (triggerState.disabled) return;
|
|
199
|
+
send({ type: "POINTER_LEAVE", id });
|
|
200
|
+
},
|
|
201
|
+
onBlur() {
|
|
202
|
+
if (triggerState.disabled) return;
|
|
203
|
+
send({ type: "BLUR" });
|
|
204
|
+
},
|
|
205
|
+
onFocus() {
|
|
206
|
+
if (triggerState.disabled) return;
|
|
207
|
+
send({ type: "FOCUS", id });
|
|
208
|
+
},
|
|
209
|
+
onKeyDown(event) {
|
|
210
|
+
if (event.defaultPrevented) return;
|
|
211
|
+
if (triggerState.disabled) return;
|
|
212
|
+
const keyboardResizeBy = prop("keyboardResizeBy");
|
|
213
|
+
let delta = 0;
|
|
214
|
+
if (event.shiftKey) {
|
|
215
|
+
delta = 10;
|
|
216
|
+
} else if (keyboardResizeBy != null) {
|
|
217
|
+
delta = keyboardResizeBy;
|
|
218
|
+
} else {
|
|
219
|
+
delta = 1;
|
|
220
|
+
}
|
|
221
|
+
const keyMap = {
|
|
222
|
+
Enter() {
|
|
223
|
+
send({ type: "ENTER", id });
|
|
224
|
+
},
|
|
225
|
+
ArrowUp() {
|
|
226
|
+
send({ type: "KEYBOARD_MOVE", id, delta: horizontal ? 0 : -delta });
|
|
227
|
+
},
|
|
228
|
+
ArrowDown() {
|
|
229
|
+
send({ type: "KEYBOARD_MOVE", id, delta: horizontal ? 0 : delta });
|
|
230
|
+
},
|
|
231
|
+
ArrowLeft() {
|
|
232
|
+
send({ type: "KEYBOARD_MOVE", id, delta: horizontal ? -delta : 0 });
|
|
233
|
+
},
|
|
234
|
+
ArrowRight() {
|
|
235
|
+
send({ type: "KEYBOARD_MOVE", id, delta: horizontal ? delta : 0 });
|
|
236
|
+
},
|
|
237
|
+
Home() {
|
|
238
|
+
send({ type: "KEYBOARD_MOVE", id, delta: -100 });
|
|
239
|
+
},
|
|
240
|
+
End() {
|
|
241
|
+
send({ type: "KEYBOARD_MOVE", id, delta: 100 });
|
|
242
|
+
},
|
|
243
|
+
F6() {
|
|
244
|
+
send({ type: "FOCUS.CYCLE", id, shiftKey: event.shiftKey });
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
const key = getEventKey(event, {
|
|
248
|
+
dir: prop("dir"),
|
|
249
|
+
orientation
|
|
250
|
+
});
|
|
251
|
+
const exec = keyMap[key];
|
|
252
|
+
if (exec) {
|
|
253
|
+
exec(event);
|
|
254
|
+
event.preventDefault();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
export {
|
|
262
|
+
connect
|
|
263
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Scope } from '@zag-js/core';
|
|
2
|
+
import { CursorState } from './splitter.types.mjs';
|
|
3
|
+
import '@zag-js/types';
|
|
4
|
+
|
|
5
|
+
declare const getRootId: (ctx: Scope) => any;
|
|
6
|
+
declare const getResizeTriggerId: (ctx: Scope, id: string) => any;
|
|
7
|
+
declare const getLabelId: (ctx: Scope) => any;
|
|
8
|
+
declare const getPanelId: (ctx: Scope, id: string | number) => any;
|
|
9
|
+
declare const getPanelEls: (ctx: Scope) => HTMLElement[];
|
|
10
|
+
declare const getGlobalCursorId: (ctx: Scope) => string;
|
|
11
|
+
declare const getRootEl: (ctx: Scope) => HTMLElement | null;
|
|
12
|
+
declare const getResizeTriggerEl: (ctx: Scope, id: string) => HTMLElement | null;
|
|
13
|
+
declare const getPanelEl: (ctx: Scope, id: string | number) => HTMLElement | null;
|
|
14
|
+
declare const getCursor: (state: CursorState, x: boolean) => (string & {}) | "col-resize" | "e-resize" | "n-resize" | "row-resize" | "s-resize" | "w-resize";
|
|
15
|
+
declare const getResizeTriggerEls: (ctx: Scope) => HTMLElement[];
|
|
16
|
+
declare const setupGlobalCursor: (ctx: Scope, state: CursorState, x: boolean, nonce?: string) => void;
|
|
17
|
+
declare const removeGlobalCursor: (ctx: Scope) => void;
|
|
18
|
+
|
|
19
|
+
export { getCursor, getGlobalCursorId, getLabelId, getPanelEl, getPanelEls, getPanelId, getResizeTriggerEl, getResizeTriggerEls, getResizeTriggerId, getRootEl, getRootId, removeGlobalCursor, setupGlobalCursor };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Scope } from '@zag-js/core';
|
|
2
|
+
import { CursorState } from './splitter.types.js';
|
|
3
|
+
import '@zag-js/types';
|
|
4
|
+
|
|
5
|
+
declare const getRootId: (ctx: Scope) => any;
|
|
6
|
+
declare const getResizeTriggerId: (ctx: Scope, id: string) => any;
|
|
7
|
+
declare const getLabelId: (ctx: Scope) => any;
|
|
8
|
+
declare const getPanelId: (ctx: Scope, id: string | number) => any;
|
|
9
|
+
declare const getPanelEls: (ctx: Scope) => HTMLElement[];
|
|
10
|
+
declare const getGlobalCursorId: (ctx: Scope) => string;
|
|
11
|
+
declare const getRootEl: (ctx: Scope) => HTMLElement | null;
|
|
12
|
+
declare const getResizeTriggerEl: (ctx: Scope, id: string) => HTMLElement | null;
|
|
13
|
+
declare const getPanelEl: (ctx: Scope, id: string | number) => HTMLElement | null;
|
|
14
|
+
declare const getCursor: (state: CursorState, x: boolean) => (string & {}) | "col-resize" | "e-resize" | "n-resize" | "row-resize" | "s-resize" | "w-resize";
|
|
15
|
+
declare const getResizeTriggerEls: (ctx: Scope) => HTMLElement[];
|
|
16
|
+
declare const setupGlobalCursor: (ctx: Scope, state: CursorState, x: boolean, nonce?: string) => void;
|
|
17
|
+
declare const removeGlobalCursor: (ctx: Scope) => void;
|
|
18
|
+
|
|
19
|
+
export { getCursor, getGlobalCursorId, getLabelId, getPanelEl, getPanelEls, getPanelId, getResizeTriggerEl, getResizeTriggerEls, getResizeTriggerId, getRootEl, getRootId, removeGlobalCursor, setupGlobalCursor };
|