@zag-js/splitter 0.1.12 → 0.1.14
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.js +8 -38
- package/package.json +8 -8
- package/dist/index.mjs +0 -750
package/dist/index.js
CHANGED
|
@@ -1,31 +1,4 @@
|
|
|
1
|
-
|
|
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/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
connect: () => connect,
|
|
24
|
-
machine: () => machine
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(src_exports);
|
|
27
|
-
|
|
28
|
-
// ../../utilities/dom/dist/index.mjs
|
|
1
|
+
// ../../utilities/dom/dist/index.js
|
|
29
2
|
var dataAttr = (guard) => {
|
|
30
3
|
return guard ? "" : void 0;
|
|
31
4
|
};
|
|
@@ -116,9 +89,7 @@ function getPointRelativeToNode(point, element) {
|
|
|
116
89
|
}
|
|
117
90
|
var rtlKeyMap = {
|
|
118
91
|
ArrowLeft: "ArrowRight",
|
|
119
|
-
ArrowRight: "ArrowLeft"
|
|
120
|
-
Home: "End",
|
|
121
|
-
End: "Home"
|
|
92
|
+
ArrowRight: "ArrowLeft"
|
|
122
93
|
};
|
|
123
94
|
var sameKeyMap = {
|
|
124
95
|
Up: "ArrowUp",
|
|
@@ -508,9 +479,9 @@ function connect(state2, send, normalize) {
|
|
|
508
479
|
}
|
|
509
480
|
|
|
510
481
|
// src/splitter.machine.ts
|
|
511
|
-
|
|
482
|
+
import { createMachine, guards } from "@zag-js/core";
|
|
512
483
|
|
|
513
|
-
// ../../utilities/number/dist/index.
|
|
484
|
+
// ../../utilities/number/dist/index.js
|
|
514
485
|
function round(v, t) {
|
|
515
486
|
let num = valueOf(v);
|
|
516
487
|
const p = 10 ** (t ?? 10);
|
|
@@ -558,9 +529,9 @@ function decimalOperation(a, op, b) {
|
|
|
558
529
|
var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
|
|
559
530
|
|
|
560
531
|
// src/splitter.machine.ts
|
|
561
|
-
var { not } =
|
|
532
|
+
var { not } = guards;
|
|
562
533
|
function machine(ctx) {
|
|
563
|
-
return
|
|
534
|
+
return createMachine(
|
|
564
535
|
{
|
|
565
536
|
id: "splitter",
|
|
566
537
|
initial: "unknown",
|
|
@@ -771,8 +742,7 @@ function machine(ctx) {
|
|
|
771
742
|
}
|
|
772
743
|
);
|
|
773
744
|
}
|
|
774
|
-
|
|
775
|
-
0 && (module.exports = {
|
|
745
|
+
export {
|
|
776
746
|
connect,
|
|
777
747
|
machine
|
|
778
|
-
}
|
|
748
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
+
"type": "module",
|
|
2
3
|
"name": "@zag-js/splitter",
|
|
3
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.14",
|
|
4
5
|
"description": "Core logic for the splitter widget implemented as a state machine",
|
|
5
6
|
"keywords": [
|
|
6
7
|
"js",
|
|
@@ -17,7 +18,6 @@
|
|
|
17
18
|
"license": "MIT",
|
|
18
19
|
"main": "dist/index.js",
|
|
19
20
|
"types": "dist/index.d.ts",
|
|
20
|
-
"module": "dist/index.mjs",
|
|
21
21
|
"repository": "https://github.com/chakra-ui/zag/tree/main/packages/splitter",
|
|
22
22
|
"sideEffects": false,
|
|
23
23
|
"files": [
|
|
@@ -30,17 +30,17 @@
|
|
|
30
30
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@zag-js/core": "0.1.
|
|
34
|
-
"@zag-js/types": "0.2.
|
|
33
|
+
"@zag-js/core": "0.1.11",
|
|
34
|
+
"@zag-js/types": "0.2.6"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@zag-js/dom-utils": "0.1.
|
|
38
|
-
"@zag-js/number-utils": "0.1.
|
|
37
|
+
"@zag-js/dom-utils": "0.1.12",
|
|
38
|
+
"@zag-js/number-utils": "0.1.5"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
|
-
"build-fast": "tsup src/index.ts --format=esm
|
|
41
|
+
"build-fast": "tsup src/index.ts --format=esm",
|
|
42
42
|
"start": "pnpm build --watch",
|
|
43
|
-
"build": "tsup src/index.ts --format=esm
|
|
43
|
+
"build": "tsup src/index.ts --format=esm --dts",
|
|
44
44
|
"test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
|
|
45
45
|
"lint": "eslint src --ext .ts,.tsx",
|
|
46
46
|
"test-ci": "pnpm test --ci --runInBand",
|
package/dist/index.mjs
DELETED
|
@@ -1,750 +0,0 @@
|
|
|
1
|
-
// ../../utilities/dom/dist/index.mjs
|
|
2
|
-
var dataAttr = (guard) => {
|
|
3
|
-
return guard ? "" : void 0;
|
|
4
|
-
};
|
|
5
|
-
var runIfFn = (v, ...a) => {
|
|
6
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
7
|
-
return res ?? void 0;
|
|
8
|
-
};
|
|
9
|
-
var callAll = (...fns) => (...a) => {
|
|
10
|
-
fns.forEach(function(fn) {
|
|
11
|
-
fn == null ? void 0 : fn(...a);
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
var isArray = (v) => Array.isArray(v);
|
|
15
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
16
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
-
var isDom = () => typeof window !== "undefined";
|
|
18
|
-
function getPlatform() {
|
|
19
|
-
const agent = navigator.userAgentData;
|
|
20
|
-
return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
|
|
21
|
-
}
|
|
22
|
-
var pt = (v) => isDom() && v.test(getPlatform());
|
|
23
|
-
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
24
|
-
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
25
|
-
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
26
|
-
var isIos = () => isApple() && !isMac();
|
|
27
|
-
function isDocument(el) {
|
|
28
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
29
|
-
}
|
|
30
|
-
function isWindow(value) {
|
|
31
|
-
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
32
|
-
}
|
|
33
|
-
function getDocument(el) {
|
|
34
|
-
if (isWindow(el))
|
|
35
|
-
return el.document;
|
|
36
|
-
if (isDocument(el))
|
|
37
|
-
return el;
|
|
38
|
-
return (el == null ? void 0 : el.ownerDocument) ?? document;
|
|
39
|
-
}
|
|
40
|
-
function defineDomHelpers(helpers) {
|
|
41
|
-
const dom2 = {
|
|
42
|
-
getRootNode: (ctx) => {
|
|
43
|
-
var _a;
|
|
44
|
-
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
|
|
45
|
-
},
|
|
46
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
47
|
-
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
48
|
-
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
49
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
50
|
-
};
|
|
51
|
-
return {
|
|
52
|
-
...dom2,
|
|
53
|
-
...helpers
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
57
|
-
var supportsTouchEvent = () => isDom() && window.ontouchstart === null;
|
|
58
|
-
var supportsMouseEvent = () => isDom() && window.onmousedown === null;
|
|
59
|
-
var isMouseEvent = (v) => isObject(v) && hasProp(v, "button");
|
|
60
|
-
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
61
|
-
var isLeftClick = (v) => v.button === 0;
|
|
62
|
-
function getElementOffset(element) {
|
|
63
|
-
let left = 0;
|
|
64
|
-
let top = 0;
|
|
65
|
-
let el = element;
|
|
66
|
-
if (el.parentNode) {
|
|
67
|
-
do {
|
|
68
|
-
left += el.offsetLeft;
|
|
69
|
-
top += el.offsetTop;
|
|
70
|
-
} while ((el = el.offsetParent) && el.nodeType < 9);
|
|
71
|
-
el = element;
|
|
72
|
-
do {
|
|
73
|
-
left -= el.scrollLeft;
|
|
74
|
-
top -= el.scrollTop;
|
|
75
|
-
} while ((el = el.parentNode) && !/body/i.test(el.nodeName));
|
|
76
|
-
}
|
|
77
|
-
return {
|
|
78
|
-
top,
|
|
79
|
-
right: innerWidth - left - element.offsetWidth,
|
|
80
|
-
bottom: innerHeight - top - element.offsetHeight,
|
|
81
|
-
left
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
function getPointRelativeToNode(point, element) {
|
|
85
|
-
const offset = getElementOffset(element);
|
|
86
|
-
const x = point.x - offset.left;
|
|
87
|
-
const y = point.y - offset.top;
|
|
88
|
-
return { x, y };
|
|
89
|
-
}
|
|
90
|
-
var rtlKeyMap = {
|
|
91
|
-
ArrowLeft: "ArrowRight",
|
|
92
|
-
ArrowRight: "ArrowLeft",
|
|
93
|
-
Home: "End",
|
|
94
|
-
End: "Home"
|
|
95
|
-
};
|
|
96
|
-
var sameKeyMap = {
|
|
97
|
-
Up: "ArrowUp",
|
|
98
|
-
Down: "ArrowDown",
|
|
99
|
-
Esc: "Escape",
|
|
100
|
-
" ": "Space",
|
|
101
|
-
",": "Comma",
|
|
102
|
-
Left: "ArrowLeft",
|
|
103
|
-
Right: "ArrowRight"
|
|
104
|
-
};
|
|
105
|
-
function getEventKey(event, options = {}) {
|
|
106
|
-
const { dir = "ltr", orientation = "horizontal" } = options;
|
|
107
|
-
let { key } = event;
|
|
108
|
-
key = sameKeyMap[key] ?? key;
|
|
109
|
-
const isRtl = dir === "rtl" && orientation === "horizontal";
|
|
110
|
-
if (isRtl && key in rtlKeyMap) {
|
|
111
|
-
key = rtlKeyMap[key];
|
|
112
|
-
}
|
|
113
|
-
return key;
|
|
114
|
-
}
|
|
115
|
-
var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
|
|
116
|
-
var ARROW_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
|
|
117
|
-
function getEventStep(event) {
|
|
118
|
-
if (event.ctrlKey || event.metaKey) {
|
|
119
|
-
return 0.1;
|
|
120
|
-
} else {
|
|
121
|
-
const isPageKey = PAGE_KEYS.has(event.key);
|
|
122
|
-
const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.has(event.key);
|
|
123
|
-
return isSkipKey ? 10 : 1;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
var isRef = (v) => hasProp(v, "current");
|
|
127
|
-
var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
|
|
128
|
-
function extractInfo(event, type = "page") {
|
|
129
|
-
const point = isTouchEvent(event) ? event.touches[0] || event.changedTouches[0] || fallback2 : event;
|
|
130
|
-
return {
|
|
131
|
-
point: {
|
|
132
|
-
x: point[`${type}X`],
|
|
133
|
-
y: point[`${type}Y`]
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
function addDomEvent(target, eventName, handler, options) {
|
|
138
|
-
const node = isRef(target) ? target.current : runIfFn(target);
|
|
139
|
-
node == null ? void 0 : node.addEventListener(eventName, handler, options);
|
|
140
|
-
return () => {
|
|
141
|
-
node == null ? void 0 : node.removeEventListener(eventName, handler, options);
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
function addPointerEvent(target, event, listener, options) {
|
|
145
|
-
const type = getEventName(event) ?? event;
|
|
146
|
-
return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options);
|
|
147
|
-
}
|
|
148
|
-
function wrapHandler(fn, filter = false) {
|
|
149
|
-
const listener = (event) => {
|
|
150
|
-
fn(event, extractInfo(event));
|
|
151
|
-
};
|
|
152
|
-
return filter ? filterPrimaryPointer(listener) : listener;
|
|
153
|
-
}
|
|
154
|
-
function filterPrimaryPointer(fn) {
|
|
155
|
-
return (event) => {
|
|
156
|
-
const win = event.view ?? window;
|
|
157
|
-
const isMouseEvent2 = event instanceof win.MouseEvent;
|
|
158
|
-
const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0;
|
|
159
|
-
if (isPrimary)
|
|
160
|
-
fn(event);
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
var mouseEventNames = {
|
|
164
|
-
pointerdown: "mousedown",
|
|
165
|
-
pointermove: "mousemove",
|
|
166
|
-
pointerup: "mouseup",
|
|
167
|
-
pointercancel: "mousecancel",
|
|
168
|
-
pointerover: "mouseover",
|
|
169
|
-
pointerout: "mouseout",
|
|
170
|
-
pointerenter: "mouseenter",
|
|
171
|
-
pointerleave: "mouseleave"
|
|
172
|
-
};
|
|
173
|
-
var touchEventNames = {
|
|
174
|
-
pointerdown: "touchstart",
|
|
175
|
-
pointermove: "touchmove",
|
|
176
|
-
pointerup: "touchend",
|
|
177
|
-
pointercancel: "touchcancel"
|
|
178
|
-
};
|
|
179
|
-
function getEventName(evt) {
|
|
180
|
-
if (supportsPointerEvent())
|
|
181
|
-
return evt;
|
|
182
|
-
if (supportsTouchEvent())
|
|
183
|
-
return touchEventNames[evt];
|
|
184
|
-
if (supportsMouseEvent())
|
|
185
|
-
return mouseEventNames[evt];
|
|
186
|
-
return evt;
|
|
187
|
-
}
|
|
188
|
-
function nextTick(fn) {
|
|
189
|
-
const set = /* @__PURE__ */ new Set();
|
|
190
|
-
function raf2(fn2) {
|
|
191
|
-
const id = globalThis.requestAnimationFrame(fn2);
|
|
192
|
-
set.add(() => globalThis.cancelAnimationFrame(id));
|
|
193
|
-
}
|
|
194
|
-
raf2(() => raf2(fn));
|
|
195
|
-
return function cleanup() {
|
|
196
|
-
set.forEach(function(fn2) {
|
|
197
|
-
fn2();
|
|
198
|
-
});
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
function raf(fn) {
|
|
202
|
-
const id = globalThis.requestAnimationFrame(fn);
|
|
203
|
-
return function cleanup() {
|
|
204
|
-
globalThis.cancelAnimationFrame(id);
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
var state = "default";
|
|
208
|
-
var savedUserSelect = "";
|
|
209
|
-
var modifiedElementMap = /* @__PURE__ */ new WeakMap();
|
|
210
|
-
function disableTextSelection({ target, doc } = {}) {
|
|
211
|
-
const _document = doc ?? document;
|
|
212
|
-
if (isIos()) {
|
|
213
|
-
if (state === "default") {
|
|
214
|
-
savedUserSelect = _document.documentElement.style.webkitUserSelect;
|
|
215
|
-
_document.documentElement.style.webkitUserSelect = "none";
|
|
216
|
-
}
|
|
217
|
-
state = "disabled";
|
|
218
|
-
} else if (target) {
|
|
219
|
-
modifiedElementMap.set(target, target.style.userSelect);
|
|
220
|
-
target.style.userSelect = "none";
|
|
221
|
-
}
|
|
222
|
-
return () => restoreTextSelection({ target, doc: _document });
|
|
223
|
-
}
|
|
224
|
-
function restoreTextSelection({ target, doc } = {}) {
|
|
225
|
-
const _document = doc ?? document;
|
|
226
|
-
if (isIos()) {
|
|
227
|
-
if (state !== "disabled")
|
|
228
|
-
return;
|
|
229
|
-
state = "restoring";
|
|
230
|
-
setTimeout(() => {
|
|
231
|
-
nextTick(() => {
|
|
232
|
-
if (state === "restoring") {
|
|
233
|
-
if (_document.documentElement.style.webkitUserSelect === "none") {
|
|
234
|
-
_document.documentElement.style.webkitUserSelect = savedUserSelect || "";
|
|
235
|
-
}
|
|
236
|
-
savedUserSelect = "";
|
|
237
|
-
state = "default";
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
}, 300);
|
|
241
|
-
} else {
|
|
242
|
-
if (target && modifiedElementMap.has(target)) {
|
|
243
|
-
let targetOldUserSelect = modifiedElementMap.get(target);
|
|
244
|
-
if (target.style.userSelect === "none") {
|
|
245
|
-
target.style.userSelect = targetOldUserSelect ?? "";
|
|
246
|
-
}
|
|
247
|
-
if (target.getAttribute("style") === "") {
|
|
248
|
-
target.removeAttribute("style");
|
|
249
|
-
}
|
|
250
|
-
modifiedElementMap.delete(target);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
var THRESHOLD = 5;
|
|
255
|
-
function trackPointerMove(doc, opts) {
|
|
256
|
-
const { onPointerMove, onPointerUp } = opts;
|
|
257
|
-
const handlePointerMove = (event, info) => {
|
|
258
|
-
const { point: p } = info;
|
|
259
|
-
const distance = Math.sqrt(p.x ** 2 + p.y ** 2);
|
|
260
|
-
if (distance < THRESHOLD)
|
|
261
|
-
return;
|
|
262
|
-
if (isMouseEvent(event) && isLeftClick(event)) {
|
|
263
|
-
onPointerUp();
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
onPointerMove(info, event);
|
|
267
|
-
};
|
|
268
|
-
return callAll(
|
|
269
|
-
addPointerEvent(doc, "pointermove", handlePointerMove, false),
|
|
270
|
-
addPointerEvent(doc, "pointerup", onPointerUp, false),
|
|
271
|
-
addPointerEvent(doc, "pointercancel", onPointerUp, false),
|
|
272
|
-
addPointerEvent(doc, "contextmenu", onPointerUp, false),
|
|
273
|
-
disableTextSelection({ doc })
|
|
274
|
-
);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
// src/splitter.dom.ts
|
|
278
|
-
var dom = defineDomHelpers({
|
|
279
|
-
getRootId: (ctx) => {
|
|
280
|
-
var _a;
|
|
281
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.root) ?? `splitter:${ctx.id}`;
|
|
282
|
-
},
|
|
283
|
-
getSplitterId: (ctx) => {
|
|
284
|
-
var _a;
|
|
285
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.splitter) ?? `splitter:${ctx.id}:splitter`;
|
|
286
|
-
},
|
|
287
|
-
getToggleButtonId: (ctx) => {
|
|
288
|
-
var _a;
|
|
289
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.toggleBtn) ?? `splitter:${ctx.id}:toggle-btn`;
|
|
290
|
-
},
|
|
291
|
-
getLabelId: (ctx) => {
|
|
292
|
-
var _a;
|
|
293
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.label) ?? `splitter:${ctx.id}:label`;
|
|
294
|
-
},
|
|
295
|
-
getPrimaryPaneId: (ctx) => {
|
|
296
|
-
var _a;
|
|
297
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.primaryPane) ?? `splitter:${ctx.id}:primary`;
|
|
298
|
-
},
|
|
299
|
-
getSecondaryPaneId: (ctx) => {
|
|
300
|
-
var _a;
|
|
301
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.secondaryPane) ?? `splitter:${ctx.id}:secondary`;
|
|
302
|
-
},
|
|
303
|
-
getSplitterEl: (ctx) => dom.getById(ctx, dom.getSplitterId(ctx)),
|
|
304
|
-
getPrimaryPaneEl: (ctx) => dom.getById(ctx, dom.getPrimaryPaneId(ctx)),
|
|
305
|
-
getCursor(ctx) {
|
|
306
|
-
if (ctx.disabled || ctx.fixed)
|
|
307
|
-
return "default";
|
|
308
|
-
const x = ctx.isHorizontal;
|
|
309
|
-
let cursor = x ? "col-resize" : "row-resize";
|
|
310
|
-
if (ctx.isAtMin)
|
|
311
|
-
cursor = x ? "e-resize" : "s-resize";
|
|
312
|
-
if (ctx.isAtMax)
|
|
313
|
-
cursor = x ? "w-resize" : "n-resize";
|
|
314
|
-
return cursor;
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
// src/splitter.connect.ts
|
|
319
|
-
function connect(state2, send, normalize) {
|
|
320
|
-
const isHorizontal = state2.context.isHorizontal;
|
|
321
|
-
const isDisabled = state2.context.disabled;
|
|
322
|
-
const isFocused = state2.hasTag("focus");
|
|
323
|
-
const isDragging = state2.matches("dragging");
|
|
324
|
-
const isAtMin = state2.context.isAtMin;
|
|
325
|
-
const isAtMax = state2.context.isAtMax;
|
|
326
|
-
const min = state2.context.min;
|
|
327
|
-
const max = state2.context.max;
|
|
328
|
-
const value = state2.context.value;
|
|
329
|
-
return {
|
|
330
|
-
isCollapsed: isAtMin,
|
|
331
|
-
isExpanded: isAtMax,
|
|
332
|
-
isFocused,
|
|
333
|
-
isDragging,
|
|
334
|
-
value,
|
|
335
|
-
collapse() {
|
|
336
|
-
send("COLLAPSE");
|
|
337
|
-
},
|
|
338
|
-
expand() {
|
|
339
|
-
send("EXPAND");
|
|
340
|
-
},
|
|
341
|
-
toggle() {
|
|
342
|
-
send("TOGGLE");
|
|
343
|
-
},
|
|
344
|
-
setSize(size) {
|
|
345
|
-
send({ type: "SET_SIZE", size });
|
|
346
|
-
},
|
|
347
|
-
rootProps: normalize.element({
|
|
348
|
-
"data-part": "root",
|
|
349
|
-
"data-orientation": state2.context.orientation,
|
|
350
|
-
"data-disabled": dataAttr(isDisabled),
|
|
351
|
-
id: dom.getRootId(state2.context),
|
|
352
|
-
style: {
|
|
353
|
-
display: "flex",
|
|
354
|
-
flex: "1 1 0%",
|
|
355
|
-
flexDirection: isHorizontal ? "row" : "column"
|
|
356
|
-
}
|
|
357
|
-
}),
|
|
358
|
-
secondaryPaneProps: normalize.element({
|
|
359
|
-
"data-part": "secondary-pane",
|
|
360
|
-
"data-disabled": dataAttr(isDisabled),
|
|
361
|
-
id: dom.getSecondaryPaneId(state2.context),
|
|
362
|
-
style: {
|
|
363
|
-
height: isHorizontal ? "100%" : "auto",
|
|
364
|
-
width: isHorizontal ? "auto" : "100%",
|
|
365
|
-
flex: "1 1 auto",
|
|
366
|
-
position: "relative"
|
|
367
|
-
}
|
|
368
|
-
}),
|
|
369
|
-
primaryPaneProps: normalize.element({
|
|
370
|
-
"data-part": "primary-pane",
|
|
371
|
-
id: dom.getPrimaryPaneId(state2.context),
|
|
372
|
-
"data-disabled": dataAttr(isDisabled),
|
|
373
|
-
"data-state": isAtMax ? "at-max" : isAtMin ? "at-min" : "between",
|
|
374
|
-
style: {
|
|
375
|
-
visibility: "visible",
|
|
376
|
-
flex: `0 0 ${value}px`,
|
|
377
|
-
position: "relative",
|
|
378
|
-
userSelect: isDragging ? "none" : "auto",
|
|
379
|
-
...isHorizontal ? { minWidth: `${min}px`, maxWidth: `${max}px` } : { minHeight: `${min}px`, maxHeight: `${max}px` }
|
|
380
|
-
}
|
|
381
|
-
}),
|
|
382
|
-
toggleButtonProps: normalize.element({
|
|
383
|
-
"data-part": "toggle-button",
|
|
384
|
-
id: dom.getToggleButtonId(state2.context),
|
|
385
|
-
"aria-label": state2.context.isAtMin ? "Expand Primary Pane" : "Collapse Primary Pane",
|
|
386
|
-
onClick() {
|
|
387
|
-
send("TOGGLE");
|
|
388
|
-
}
|
|
389
|
-
}),
|
|
390
|
-
labelProps: normalize.element({
|
|
391
|
-
"data-part": "label",
|
|
392
|
-
id: dom.getLabelId(state2.context)
|
|
393
|
-
}),
|
|
394
|
-
splitterProps: normalize.element({
|
|
395
|
-
"data-part": "splitter",
|
|
396
|
-
id: dom.getSplitterId(state2.context),
|
|
397
|
-
role: "separator",
|
|
398
|
-
tabIndex: isDisabled ? void 0 : 0,
|
|
399
|
-
"aria-valuenow": value,
|
|
400
|
-
"aria-valuemin": min,
|
|
401
|
-
"aria-valuemax": max,
|
|
402
|
-
"aria-orientation": state2.context.orientation,
|
|
403
|
-
"aria-labelledby": dom.getLabelId(state2.context),
|
|
404
|
-
"aria-controls": dom.getPrimaryPaneId(state2.context),
|
|
405
|
-
"data-orientation": state2.context.orientation,
|
|
406
|
-
"data-focus": dataAttr(isFocused),
|
|
407
|
-
"data-disabled": dataAttr(isDisabled),
|
|
408
|
-
style: {
|
|
409
|
-
touchAction: "none",
|
|
410
|
-
userSelect: "none",
|
|
411
|
-
WebkitUserSelect: "none",
|
|
412
|
-
msUserSelect: "none",
|
|
413
|
-
flex: "0 0 auto",
|
|
414
|
-
cursor: dom.getCursor(state2.context),
|
|
415
|
-
minHeight: isHorizontal ? "0px" : void 0,
|
|
416
|
-
minWidth: isHorizontal ? void 0 : "0px"
|
|
417
|
-
},
|
|
418
|
-
onPointerDown(event) {
|
|
419
|
-
if (isDisabled) {
|
|
420
|
-
event.preventDefault();
|
|
421
|
-
return;
|
|
422
|
-
}
|
|
423
|
-
send("POINTER_DOWN");
|
|
424
|
-
event.preventDefault();
|
|
425
|
-
event.stopPropagation();
|
|
426
|
-
},
|
|
427
|
-
onPointerOver() {
|
|
428
|
-
if (isDisabled)
|
|
429
|
-
return;
|
|
430
|
-
send("POINTER_OVER");
|
|
431
|
-
},
|
|
432
|
-
onPointerLeave() {
|
|
433
|
-
if (isDisabled)
|
|
434
|
-
return;
|
|
435
|
-
send("POINTER_LEAVE");
|
|
436
|
-
},
|
|
437
|
-
onBlur() {
|
|
438
|
-
send("BLUR");
|
|
439
|
-
},
|
|
440
|
-
onFocus() {
|
|
441
|
-
send("FOCUS");
|
|
442
|
-
},
|
|
443
|
-
onDoubleClick() {
|
|
444
|
-
if (isDisabled)
|
|
445
|
-
return;
|
|
446
|
-
send("DOUBLE_CLICK");
|
|
447
|
-
},
|
|
448
|
-
onKeyDown(event) {
|
|
449
|
-
if (isDisabled)
|
|
450
|
-
return;
|
|
451
|
-
const step = getEventStep(event) * state2.context.step;
|
|
452
|
-
const keyMap = {
|
|
453
|
-
ArrowUp() {
|
|
454
|
-
send({ type: "ARROW_UP", step });
|
|
455
|
-
},
|
|
456
|
-
ArrowDown() {
|
|
457
|
-
send({ type: "ARROW_DOWN", step });
|
|
458
|
-
},
|
|
459
|
-
ArrowLeft() {
|
|
460
|
-
send({ type: "ARROW_LEFT", step });
|
|
461
|
-
},
|
|
462
|
-
ArrowRight() {
|
|
463
|
-
send({ type: "ARROW_RIGHT", step });
|
|
464
|
-
},
|
|
465
|
-
Home() {
|
|
466
|
-
send("HOME");
|
|
467
|
-
},
|
|
468
|
-
End() {
|
|
469
|
-
send("END");
|
|
470
|
-
}
|
|
471
|
-
};
|
|
472
|
-
const key = getEventKey(event, state2.context);
|
|
473
|
-
const exec = keyMap[key];
|
|
474
|
-
if (exec) {
|
|
475
|
-
exec(event);
|
|
476
|
-
event.preventDefault();
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
})
|
|
480
|
-
};
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
// src/splitter.machine.ts
|
|
484
|
-
import { createMachine, guards } from "@zag-js/core";
|
|
485
|
-
|
|
486
|
-
// ../../utilities/number/dist/index.mjs
|
|
487
|
-
function round(v, t) {
|
|
488
|
-
let num = valueOf(v);
|
|
489
|
-
const p = 10 ** (t ?? 10);
|
|
490
|
-
num = Math.round(num * p) / p;
|
|
491
|
-
return t ? num.toFixed(t) : v.toString();
|
|
492
|
-
}
|
|
493
|
-
function clamp(v, o) {
|
|
494
|
-
return Math.min(Math.max(valueOf(v), o.min), o.max);
|
|
495
|
-
}
|
|
496
|
-
function countDecimals(value) {
|
|
497
|
-
if (!Number.isFinite(value))
|
|
498
|
-
return 0;
|
|
499
|
-
let e = 1, p = 0;
|
|
500
|
-
while (Math.round(value * e) / e !== value) {
|
|
501
|
-
e *= 10;
|
|
502
|
-
p += 1;
|
|
503
|
-
}
|
|
504
|
-
return p;
|
|
505
|
-
}
|
|
506
|
-
var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
|
|
507
|
-
var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
|
|
508
|
-
function snapToStep(value, step) {
|
|
509
|
-
const num = valueOf(value);
|
|
510
|
-
const p = countDecimals(step);
|
|
511
|
-
const v = Math.round(num / step) * step;
|
|
512
|
-
return round(v, p);
|
|
513
|
-
}
|
|
514
|
-
function valueOf(v) {
|
|
515
|
-
if (typeof v === "number")
|
|
516
|
-
return v;
|
|
517
|
-
const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
|
|
518
|
-
return !Number.isNaN(num) ? num : 0;
|
|
519
|
-
}
|
|
520
|
-
function decimalOperation(a, op, b) {
|
|
521
|
-
let result = op === "+" ? a + b : a - b;
|
|
522
|
-
if (a % 1 !== 0 || b % 1 !== 0) {
|
|
523
|
-
const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
|
|
524
|
-
a = Math.round(a * multiplier);
|
|
525
|
-
b = Math.round(b * multiplier);
|
|
526
|
-
result = op === "+" ? a + b : a - b;
|
|
527
|
-
result /= multiplier;
|
|
528
|
-
}
|
|
529
|
-
return result;
|
|
530
|
-
}
|
|
531
|
-
var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
|
|
532
|
-
|
|
533
|
-
// src/splitter.machine.ts
|
|
534
|
-
var { not } = guards;
|
|
535
|
-
function machine(ctx) {
|
|
536
|
-
return createMachine(
|
|
537
|
-
{
|
|
538
|
-
id: "splitter",
|
|
539
|
-
initial: "unknown",
|
|
540
|
-
context: {
|
|
541
|
-
orientation: "horizontal",
|
|
542
|
-
min: 224,
|
|
543
|
-
max: 340,
|
|
544
|
-
step: 1,
|
|
545
|
-
value: 256,
|
|
546
|
-
snapOffset: 0,
|
|
547
|
-
...ctx
|
|
548
|
-
},
|
|
549
|
-
computed: {
|
|
550
|
-
isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
|
|
551
|
-
isAtMin: (ctx2) => ctx2.value === ctx2.min,
|
|
552
|
-
isAtMax: (ctx2) => ctx2.value === ctx2.max
|
|
553
|
-
},
|
|
554
|
-
on: {
|
|
555
|
-
COLLAPSE: {
|
|
556
|
-
actions: "setToMin"
|
|
557
|
-
},
|
|
558
|
-
EXPAND: {
|
|
559
|
-
actions: "setToMax"
|
|
560
|
-
},
|
|
561
|
-
TOGGLE: [
|
|
562
|
-
{
|
|
563
|
-
guard: "isCollapsed",
|
|
564
|
-
actions: "setToMax"
|
|
565
|
-
},
|
|
566
|
-
{
|
|
567
|
-
actions: "setToMin"
|
|
568
|
-
}
|
|
569
|
-
]
|
|
570
|
-
},
|
|
571
|
-
states: {
|
|
572
|
-
unknown: {
|
|
573
|
-
on: {
|
|
574
|
-
SETUP: "idle"
|
|
575
|
-
}
|
|
576
|
-
},
|
|
577
|
-
idle: {
|
|
578
|
-
on: {
|
|
579
|
-
POINTER_OVER: {
|
|
580
|
-
guard: not("isFixed"),
|
|
581
|
-
target: "hover:temp"
|
|
582
|
-
},
|
|
583
|
-
POINTER_LEAVE: "idle",
|
|
584
|
-
FOCUS: "focused"
|
|
585
|
-
}
|
|
586
|
-
},
|
|
587
|
-
"hover:temp": {
|
|
588
|
-
after: {
|
|
589
|
-
HOVER_DELAY: "hover"
|
|
590
|
-
},
|
|
591
|
-
on: {
|
|
592
|
-
POINTER_DOWN: {
|
|
593
|
-
target: "dragging",
|
|
594
|
-
actions: ["invokeOnChangeStart"]
|
|
595
|
-
},
|
|
596
|
-
POINTER_LEAVE: "idle"
|
|
597
|
-
}
|
|
598
|
-
},
|
|
599
|
-
hover: {
|
|
600
|
-
tags: ["focus"],
|
|
601
|
-
on: {
|
|
602
|
-
POINTER_DOWN: {
|
|
603
|
-
target: "dragging",
|
|
604
|
-
actions: ["invokeOnChangeStart"]
|
|
605
|
-
},
|
|
606
|
-
POINTER_LEAVE: "idle"
|
|
607
|
-
}
|
|
608
|
-
},
|
|
609
|
-
focused: {
|
|
610
|
-
tags: ["focus"],
|
|
611
|
-
on: {
|
|
612
|
-
BLUR: "idle",
|
|
613
|
-
POINTER_DOWN: {
|
|
614
|
-
target: "dragging",
|
|
615
|
-
actions: ["invokeOnChangeStart"]
|
|
616
|
-
},
|
|
617
|
-
ARROW_LEFT: {
|
|
618
|
-
guard: "isHorizontal",
|
|
619
|
-
actions: "decrement"
|
|
620
|
-
},
|
|
621
|
-
ARROW_RIGHT: {
|
|
622
|
-
guard: "isHorizontal",
|
|
623
|
-
actions: "increment"
|
|
624
|
-
},
|
|
625
|
-
ARROW_UP: {
|
|
626
|
-
guard: "isVertical",
|
|
627
|
-
actions: "increment"
|
|
628
|
-
},
|
|
629
|
-
ARROW_DOWN: {
|
|
630
|
-
guard: "isVertical",
|
|
631
|
-
actions: "decrement"
|
|
632
|
-
},
|
|
633
|
-
ENTER: [
|
|
634
|
-
{
|
|
635
|
-
guard: "isCollapsed",
|
|
636
|
-
actions: "setToMin"
|
|
637
|
-
},
|
|
638
|
-
{ actions: "setToMin" }
|
|
639
|
-
],
|
|
640
|
-
HOME: {
|
|
641
|
-
actions: "setToMin"
|
|
642
|
-
},
|
|
643
|
-
END: {
|
|
644
|
-
actions: "setToMax"
|
|
645
|
-
},
|
|
646
|
-
DOUBLE_CLICK: [
|
|
647
|
-
{
|
|
648
|
-
guard: "isCollapsed",
|
|
649
|
-
actions: "setToMax"
|
|
650
|
-
},
|
|
651
|
-
{ actions: "setToMin" }
|
|
652
|
-
]
|
|
653
|
-
}
|
|
654
|
-
},
|
|
655
|
-
dragging: {
|
|
656
|
-
tags: ["focus"],
|
|
657
|
-
entry: "focusSplitter",
|
|
658
|
-
activities: "trackPointerMove",
|
|
659
|
-
on: {
|
|
660
|
-
POINTER_UP: {
|
|
661
|
-
target: "focused",
|
|
662
|
-
actions: ["invokeOnChangeEnd"]
|
|
663
|
-
},
|
|
664
|
-
POINTER_MOVE: {
|
|
665
|
-
actions: "setPointerValue"
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
},
|
|
671
|
-
{
|
|
672
|
-
activities: {
|
|
673
|
-
trackPointerMove: (ctx2, _evt, { send }) => {
|
|
674
|
-
const doc = dom.getDoc(ctx2);
|
|
675
|
-
return trackPointerMove(doc, {
|
|
676
|
-
onPointerMove(info) {
|
|
677
|
-
send({ type: "POINTER_MOVE", point: info.point });
|
|
678
|
-
doc.documentElement.style.cursor = dom.getCursor(ctx2);
|
|
679
|
-
},
|
|
680
|
-
onPointerUp() {
|
|
681
|
-
send("POINTER_UP");
|
|
682
|
-
doc.documentElement.style.cursor = "";
|
|
683
|
-
}
|
|
684
|
-
});
|
|
685
|
-
}
|
|
686
|
-
},
|
|
687
|
-
guards: {
|
|
688
|
-
isCollapsed: (ctx2) => ctx2.isAtMin,
|
|
689
|
-
isHorizontal: (ctx2) => ctx2.isHorizontal,
|
|
690
|
-
isVertical: (ctx2) => !ctx2.isHorizontal,
|
|
691
|
-
isFixed: (ctx2) => !!ctx2.fixed
|
|
692
|
-
},
|
|
693
|
-
delays: {
|
|
694
|
-
HOVER_DELAY: 250
|
|
695
|
-
},
|
|
696
|
-
actions: {
|
|
697
|
-
invokeOnChange(ctx2, evt) {
|
|
698
|
-
var _a;
|
|
699
|
-
if (evt.type !== "SETUP") {
|
|
700
|
-
(_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
|
|
701
|
-
}
|
|
702
|
-
},
|
|
703
|
-
invokeOnChangeStart(ctx2) {
|
|
704
|
-
var _a;
|
|
705
|
-
(_a = ctx2.onChangeStart) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
|
|
706
|
-
},
|
|
707
|
-
invokeOnChangeEnd(ctx2) {
|
|
708
|
-
var _a;
|
|
709
|
-
(_a = ctx2.onChangeEnd) == null ? void 0 : _a.call(ctx2, { value: ctx2.value });
|
|
710
|
-
},
|
|
711
|
-
setToMin(ctx2) {
|
|
712
|
-
ctx2.value = ctx2.min;
|
|
713
|
-
},
|
|
714
|
-
setToMax(ctx2) {
|
|
715
|
-
ctx2.value = ctx2.max;
|
|
716
|
-
},
|
|
717
|
-
increment(ctx2, evt) {
|
|
718
|
-
ctx2.value = clamp(increment(ctx2.value, evt.step), ctx2);
|
|
719
|
-
},
|
|
720
|
-
decrement(ctx2, evt) {
|
|
721
|
-
ctx2.value = clamp(decrement(ctx2.value, evt.step), ctx2);
|
|
722
|
-
},
|
|
723
|
-
focusSplitter(ctx2) {
|
|
724
|
-
raf(() => {
|
|
725
|
-
var _a;
|
|
726
|
-
return (_a = dom.getSplitterEl(ctx2)) == null ? void 0 : _a.focus();
|
|
727
|
-
});
|
|
728
|
-
},
|
|
729
|
-
setPointerValue(ctx2, evt) {
|
|
730
|
-
const el = dom.getPrimaryPaneEl(ctx2);
|
|
731
|
-
if (!el)
|
|
732
|
-
return;
|
|
733
|
-
const relativePoint = getPointRelativeToNode(evt.point, el);
|
|
734
|
-
let currentPoint = ctx2.isHorizontal ? relativePoint.x : relativePoint.y;
|
|
735
|
-
let value = parseFloat(snapToStep(clamp(currentPoint, ctx2), ctx2.step));
|
|
736
|
-
if (Math.abs(value - ctx2.min) <= ctx2.snapOffset) {
|
|
737
|
-
value = ctx2.min;
|
|
738
|
-
} else if (Math.abs(value - ctx2.max) <= ctx2.snapOffset) {
|
|
739
|
-
value = ctx2.max;
|
|
740
|
-
}
|
|
741
|
-
ctx2.value = value;
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
);
|
|
746
|
-
}
|
|
747
|
-
export {
|
|
748
|
-
connect,
|
|
749
|
-
machine
|
|
750
|
-
};
|