@zag-js/splitter 0.82.2 → 1.0.1

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 CHANGED
@@ -9,56 +9,38 @@ var types = require('@zag-js/types');
9
9
  // src/splitter.anatomy.ts
10
10
  var anatomy = anatomy$1.createAnatomy("splitter").parts("root", "panel", "resizeTrigger");
11
11
  var parts = anatomy.build();
12
- var dom = domQuery.createScope({
13
- getRootId: (ctx) => ctx.ids?.root ?? `splitter:${ctx.id}`,
14
- getResizeTriggerId: (ctx, id) => ctx.ids?.resizeTrigger?.(id) ?? `splitter:${ctx.id}:splitter:${id}`,
15
- getLabelId: (ctx) => ctx.ids?.label ?? `splitter:${ctx.id}:label`,
16
- getPanelId: (ctx, id) => ctx.ids?.panel?.(id) ?? `splitter:${ctx.id}:panel:${id}`,
17
- getGlobalCursorId: (ctx) => `splitter:${ctx.id}:global-cursor`,
18
- getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
19
- getResizeTriggerEl: (ctx, id) => dom.getById(ctx, dom.getResizeTriggerId(ctx, id)),
20
- getPanelEl: (ctx, id) => dom.getById(ctx, dom.getPanelId(ctx, id)),
21
- getCursor(ctx) {
22
- const x = ctx.isHorizontal;
23
- let cursor = x ? "col-resize" : "row-resize";
24
- if (ctx.activeResizeState.isAtMin) cursor = x ? "e-resize" : "s-resize";
25
- if (ctx.activeResizeState.isAtMax) cursor = x ? "w-resize" : "n-resize";
26
- return cursor;
27
- },
28
- getPanelStyle(ctx, id) {
29
- const flexGrow = ctx.panels.find((panel) => panel.id === id)?.size ?? "0";
30
- return {
31
- flexBasis: 0,
32
- flexGrow,
33
- flexShrink: 1,
34
- overflow: "hidden"
35
- };
36
- },
37
- getActiveHandleEl(ctx) {
38
- const activeId = ctx.activeResizeId;
39
- if (activeId == null) return;
40
- return dom.getById(ctx, dom.getResizeTriggerId(ctx, activeId));
41
- },
42
- getResizeTriggerEls(ctx) {
43
- const ownerId = CSS.escape(dom.getRootId(ctx));
44
- return domQuery.queryAll(dom.getRootEl(ctx), `[role=separator][data-ownedby='${ownerId}']`);
45
- },
46
- setupGlobalCursor(ctx) {
47
- const styleEl = dom.getById(ctx, dom.getGlobalCursorId(ctx));
48
- const textContent = `* { cursor: ${dom.getCursor(ctx)} !important; }`;
49
- if (styleEl) {
50
- styleEl.textContent = textContent;
51
- } else {
52
- const style = dom.getDoc(ctx).createElement("style");
53
- style.id = dom.getGlobalCursorId(ctx);
54
- style.textContent = textContent;
55
- dom.getDoc(ctx).head.appendChild(style);
56
- }
57
- },
58
- removeGlobalCursor(ctx) {
59
- dom.getById(ctx, dom.getGlobalCursorId(ctx))?.remove();
12
+ var getRootId = (ctx) => ctx.ids?.root ?? `splitter:${ctx.id}`;
13
+ var getResizeTriggerId = (ctx, id) => ctx.ids?.resizeTrigger?.(id) ?? `splitter:${ctx.id}:splitter:${id}`;
14
+ var getPanelId = (ctx, id) => ctx.ids?.panel?.(id) ?? `splitter:${ctx.id}:panel:${id}`;
15
+ var getGlobalCursorId = (ctx) => `splitter:${ctx.id}:global-cursor`;
16
+ var getRootEl = (ctx) => ctx.getById(getRootId(ctx));
17
+ var getResizeTriggerEl = (ctx, id) => ctx.getById(getResizeTriggerId(ctx, id));
18
+ var getCursor = (state, x) => {
19
+ let cursor = x ? "col-resize" : "row-resize";
20
+ if (state.isAtMin) cursor = x ? "e-resize" : "s-resize";
21
+ if (state.isAtMax) cursor = x ? "w-resize" : "n-resize";
22
+ return cursor;
23
+ };
24
+ var getPanelStyle = (panels, id) => {
25
+ const flexGrow = panels.find((panel) => panel.id === id)?.size ?? "0";
26
+ return { flexBasis: 0, flexGrow, flexShrink: 1, overflow: "hidden" };
27
+ };
28
+ var setupGlobalCursor = (ctx, state, x) => {
29
+ const styleEl = ctx.getById(getGlobalCursorId(ctx));
30
+ const textContent = `* { cursor: ${getCursor(state, x)} !important; }`;
31
+ if (styleEl) {
32
+ styleEl.textContent = textContent;
33
+ } else {
34
+ const style = ctx.getDoc().createElement("style");
35
+ style.id = getGlobalCursorId(ctx);
36
+ style.textContent = textContent;
37
+ ctx.getDoc().head.appendChild(style);
60
38
  }
61
- });
39
+ };
40
+ var removeGlobalCursor = (ctx) => {
41
+ const styleEl = ctx.getById(getGlobalCursorId(ctx));
42
+ styleEl?.remove();
43
+ };
62
44
 
63
45
  // src/splitter.utils.ts
64
46
  function validateSize(key, size) {
@@ -66,11 +48,11 @@ function validateSize(key, size) {
66
48
  throw new Error(`Total ${key} of panels cannot be greater than 100`);
67
49
  }
68
50
  }
69
- function getNormalizedPanels(ctx) {
51
+ function getNormalizedPanels(sizes) {
70
52
  let numOfPanelsWithoutSize = 0;
71
53
  let totalSize = 0;
72
54
  let totalMinSize = 0;
73
- const panels = ctx.size.map((panel) => {
55
+ const panels = sizes.map((panel) => {
74
56
  const minSize = panel.minSize ?? 0;
75
57
  const maxSize = panel.maxSize ?? 100;
76
58
  totalMinSize += minSize;
@@ -108,14 +90,14 @@ function getNormalizedPanels(ctx) {
108
90
  });
109
91
  return result;
110
92
  }
111
- function getHandlePanels(ctx, id = ctx.activeResizeId) {
93
+ function getHandlePanels(panels, id) {
112
94
  const [beforeId, afterId] = id?.split(":") ?? [];
113
95
  if (!beforeId || !afterId) return;
114
- const beforeIndex = ctx.previousPanels.findIndex((panel) => panel.id === beforeId);
115
- const afterIndex = ctx.previousPanels.findIndex((panel) => panel.id === afterId);
96
+ const beforeIndex = panels.findIndex((panel) => panel.id === beforeId);
97
+ const afterIndex = panels.findIndex((panel) => panel.id === afterId);
116
98
  if (beforeIndex === -1 || afterIndex === -1) return;
117
- const before = ctx.previousPanels[beforeIndex];
118
- const after = ctx.previousPanels[afterIndex];
99
+ const before = panels[beforeIndex];
100
+ const after = panels[afterIndex];
119
101
  return {
120
102
  before: {
121
103
  ...before,
@@ -127,20 +109,20 @@ function getHandlePanels(ctx, id = ctx.activeResizeId) {
127
109
  }
128
110
  };
129
111
  }
130
- function getHandleBounds(ctx, id = ctx.activeResizeId) {
131
- const panels = getHandlePanels(ctx, id);
132
- if (!panels) return;
133
- const { before, after } = panels;
112
+ function getHandleBounds(panels, id) {
113
+ const handlePanels = getHandlePanels(panels, id);
114
+ if (!handlePanels) return;
115
+ const { before, after } = handlePanels;
134
116
  return {
135
117
  min: Math.max(before.start + before.minSize, after.end - after.maxSize),
136
118
  max: Math.min(after.end - after.minSize, before.maxSize + before.start)
137
119
  };
138
120
  }
139
- function getPanelBounds(ctx, id) {
140
- const bounds = getHandleBounds(ctx, id);
141
- const panels = getHandlePanels(ctx, id);
142
- if (!bounds || !panels) return;
143
- const { before, after } = panels;
121
+ function getPanelBounds(panels, id) {
122
+ const bounds = getHandleBounds(panels, id);
123
+ const handlePanels = getHandlePanels(panels, id);
124
+ if (!bounds || !handlePanels) return;
125
+ const { before, after } = handlePanels;
144
126
  const beforeMin = Math.abs(before.start - bounds.min);
145
127
  const afterMin = after.size + (before.size - beforeMin);
146
128
  const beforeMax = Math.abs(before.start - bounds.max);
@@ -179,19 +161,21 @@ function clamp(value, min, max) {
179
161
  }
180
162
 
181
163
  // src/splitter.connect.ts
182
- function connect(state, send, normalize) {
183
- const horizontal = state.context.isHorizontal;
164
+ function connect(service, normalize) {
165
+ const { state, send, prop, computed, context, scope } = service;
166
+ const horizontal = computed("isHorizontal");
184
167
  const focused = state.hasTag("focus");
185
168
  const dragging = state.matches("dragging");
186
- const panels = state.context.panels;
169
+ const panels = computed("panels");
170
+ const activeResizeId = context.get("activeResizeId");
187
171
  function getResizeTriggerState(props2) {
188
172
  const { id, disabled } = props2;
189
173
  const ids = id.split(":");
190
- const panelIds = ids.map((id2) => dom.getPanelId(state.context, id2));
191
- const panels2 = getHandleBounds(state.context, id);
174
+ const panelIds = ids.map((id2) => getPanelId(scope, id2));
175
+ const panels2 = getHandleBounds(computed("panels"), id);
192
176
  return {
193
177
  disabled: !!disabled,
194
- focused: state.context.activeResizeId === id && focused,
178
+ focused: activeResizeId === id && focused,
195
179
  panelIds,
196
180
  min: panels2?.min,
197
181
  max: panels2?.max,
@@ -202,7 +186,7 @@ function connect(state, send, normalize) {
202
186
  focused,
203
187
  dragging,
204
188
  getResizeTriggerState,
205
- bounds: getHandleBounds(state.context),
189
+ bounds: getHandleBounds(computed("panels"), activeResizeId),
206
190
  setToMinSize(id) {
207
191
  const panel = panels.find((panel2) => panel2.id === id);
208
192
  send({ type: "SET_PANEL_SIZE", id, size: panel?.minSize, src: "setToMinSize" });
@@ -217,9 +201,9 @@ function connect(state, send, normalize) {
217
201
  getRootProps() {
218
202
  return normalize.element({
219
203
  ...parts.root.attrs,
220
- "data-orientation": state.context.orientation,
221
- id: dom.getRootId(state.context),
222
- dir: state.context.dir,
204
+ "data-orientation": prop("orientation"),
205
+ id: getRootId(scope),
206
+ dir: prop("dir"),
223
207
  style: {
224
208
  display: "flex",
225
209
  flexDirection: horizontal ? "row" : "column",
@@ -233,11 +217,11 @@ function connect(state, send, normalize) {
233
217
  const { id } = props2;
234
218
  return normalize.element({
235
219
  ...parts.panel.attrs,
236
- "data-orientation": state.context.orientation,
237
- dir: state.context.dir,
238
- id: dom.getPanelId(state.context, id),
239
- "data-ownedby": dom.getRootId(state.context),
240
- style: dom.getPanelStyle(state.context, id)
220
+ "data-orientation": prop("orientation"),
221
+ dir: prop("dir"),
222
+ id: getPanelId(scope, id),
223
+ "data-ownedby": getRootId(scope),
224
+ style: getPanelStyle(panels, id)
241
225
  });
242
226
  },
243
227
  getResizeTriggerProps(props2) {
@@ -245,16 +229,16 @@ function connect(state, send, normalize) {
245
229
  const triggerState = getResizeTriggerState(props2);
246
230
  return normalize.element({
247
231
  ...parts.resizeTrigger.attrs,
248
- dir: state.context.dir,
249
- id: dom.getResizeTriggerId(state.context, id),
232
+ dir: prop("dir"),
233
+ id: getResizeTriggerId(scope, id),
250
234
  role: "separator",
251
- "data-ownedby": dom.getRootId(state.context),
235
+ "data-ownedby": getRootId(scope),
252
236
  tabIndex: disabled ? void 0 : 0,
253
237
  "aria-valuenow": triggerState.value,
254
238
  "aria-valuemin": triggerState.min,
255
239
  "aria-valuemax": triggerState.max,
256
- "data-orientation": state.context.orientation,
257
- "aria-orientation": state.context.orientation,
240
+ "data-orientation": prop("orientation"),
241
+ "aria-orientation": prop("orientation"),
258
242
  "aria-controls": triggerState.panelIds.join(" "),
259
243
  "data-focus": domQuery.dataAttr(triggerState.focused),
260
244
  "data-disabled": domQuery.dataAttr(disabled),
@@ -292,7 +276,7 @@ function connect(state, send, normalize) {
292
276
  send({ type: "POINTER_LEAVE", id });
293
277
  },
294
278
  onBlur() {
295
- send("BLUR");
279
+ send({ type: "BLUR" });
296
280
  },
297
281
  onFocus() {
298
282
  send({ type: "FOCUS", id });
@@ -307,7 +291,7 @@ function connect(state, send, normalize) {
307
291
  const moveStep = domQuery.getEventStep(event) * step;
308
292
  const keyMap = {
309
293
  Enter() {
310
- send("ENTER");
294
+ send({ type: "ENTER" });
311
295
  },
312
296
  ArrowUp() {
313
297
  send({ type: "ARROW_UP", step: moveStep });
@@ -322,13 +306,16 @@ function connect(state, send, normalize) {
322
306
  send({ type: "ARROW_RIGHT", step: moveStep });
323
307
  },
324
308
  Home() {
325
- send("HOME");
309
+ send({ type: "HOME" });
326
310
  },
327
311
  End() {
328
- send("END");
312
+ send({ type: "END" });
329
313
  }
330
314
  };
331
- const key = domQuery.getEventKey(event, state.context);
315
+ const key = domQuery.getEventKey(event, {
316
+ dir: prop("dir"),
317
+ orientation: prop("orientation")
318
+ });
332
319
  const exec = keyMap[key];
333
320
  if (exec) {
334
321
  exec(event);
@@ -339,266 +326,333 @@ function connect(state, send, normalize) {
339
326
  }
340
327
  };
341
328
  }
342
- function machine(userContext) {
343
- const ctx = utils.compact(userContext);
344
- return core.createMachine(
345
- {
346
- id: "splitter",
347
- initial: "idle",
348
- context: {
349
- orientation: "horizontal",
350
- activeResizeId: null,
351
- previousPanels: [],
352
- size: [],
353
- initialSize: [],
354
- activeResizeState: {
355
- isAtMin: false,
356
- isAtMax: false
329
+ var machine = core.createMachine({
330
+ props({ props: props2 }) {
331
+ return {
332
+ orientation: "horizontal",
333
+ defaultSize: [],
334
+ ...utils.compact(props2)
335
+ };
336
+ },
337
+ initialState() {
338
+ return "idle";
339
+ },
340
+ context({ prop, bindable, getContext }) {
341
+ return {
342
+ activeResizeId: bindable(() => ({
343
+ defaultValue: null
344
+ })),
345
+ size: bindable(() => ({
346
+ defaultValue: prop("defaultSize"),
347
+ value: prop("size"),
348
+ hash(a) {
349
+ return a.map((panel) => `${panel.id}:${panel.size}`).join(",");
357
350
  },
358
- ...ctx
359
- },
360
- created: ["setPreviousPanels", "setInitialSize"],
361
- watch: {
362
- size: ["setActiveResizeState"]
363
- },
364
- computed: {
365
- isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
366
- panels: (ctx2) => getNormalizedPanels(ctx2)
367
- },
368
- on: {
369
- SET_PANEL_SIZE: {
370
- actions: "setPanelSize"
351
+ onChange(value) {
352
+ const context = getContext();
353
+ prop("onSizeChange")?.({
354
+ size: value,
355
+ activeHandleId: context.get("activeResizeId")
356
+ });
371
357
  }
372
- },
373
- states: {
374
- idle: {
375
- entry: ["clearActiveHandleId"],
376
- on: {
377
- POINTER_OVER: {
378
- target: "hover:temp",
379
- actions: ["setActiveHandleId"]
380
- },
381
- FOCUS: {
382
- target: "focused",
383
- actions: ["setActiveHandleId"]
384
- },
385
- DOUBLE_CLICK: {
386
- actions: ["resetStartPanel", "setPreviousPanels"]
387
- }
388
- }
389
- },
390
- "hover:temp": {
391
- after: {
392
- HOVER_DELAY: "hover"
393
- },
394
- on: {
395
- POINTER_DOWN: {
396
- target: "dragging",
397
- actions: ["setActiveHandleId"]
398
- },
399
- POINTER_LEAVE: "idle"
400
- }
358
+ })),
359
+ activeResizeState: bindable(() => ({
360
+ defaultValue: { isAtMin: false, isAtMax: false }
361
+ }))
362
+ };
363
+ },
364
+ refs({ context }) {
365
+ return {
366
+ previousPanels: getNormalizedPanels(context.get("size"))
367
+ };
368
+ },
369
+ watch({ track, action, context }) {
370
+ track([() => context.hash("size")], () => {
371
+ action(["setActiveResizeState"]);
372
+ });
373
+ },
374
+ computed: {
375
+ isHorizontal: ({ prop }) => prop("orientation") === "horizontal",
376
+ panels: ({ context }) => getNormalizedPanels(context.get("size"))
377
+ },
378
+ on: {
379
+ SET_PANEL_SIZE: {
380
+ actions: ["setPanelSize"]
381
+ }
382
+ },
383
+ states: {
384
+ idle: {
385
+ entry: ["clearActiveHandleId"],
386
+ on: {
387
+ POINTER_OVER: {
388
+ target: "hover:temp",
389
+ actions: ["setActiveHandleId"]
401
390
  },
402
- hover: {
403
- tags: ["focus"],
404
- on: {
405
- POINTER_DOWN: "dragging",
406
- POINTER_LEAVE: "idle"
407
- }
391
+ FOCUS: {
392
+ target: "focused",
393
+ actions: ["setActiveHandleId"]
408
394
  },
409
- focused: {
410
- tags: ["focus"],
411
- on: {
412
- BLUR: "idle",
413
- POINTER_DOWN: {
414
- target: "dragging",
415
- actions: ["setActiveHandleId"]
416
- },
417
- ARROW_LEFT: {
418
- guard: "isHorizontal",
419
- actions: ["shrinkStartPanel", "setPreviousPanels"]
420
- },
421
- ARROW_RIGHT: {
422
- guard: "isHorizontal",
423
- actions: ["expandStartPanel", "setPreviousPanels"]
424
- },
425
- ARROW_UP: {
426
- guard: "isVertical",
427
- actions: ["shrinkStartPanel", "setPreviousPanels"]
428
- },
429
- ARROW_DOWN: {
430
- guard: "isVertical",
431
- actions: ["expandStartPanel", "setPreviousPanels"]
432
- },
433
- ENTER: [
434
- {
435
- guard: "isStartPanelAtMax",
436
- actions: ["setStartPanelToMin", "setPreviousPanels"]
437
- },
438
- { actions: ["setStartPanelToMax", "setPreviousPanels"] }
439
- ],
440
- HOME: {
441
- actions: ["setStartPanelToMin", "setPreviousPanels"]
442
- },
443
- END: {
444
- actions: ["setStartPanelToMax", "setPreviousPanels"]
445
- }
446
- }
447
- },
448
- dragging: {
449
- tags: ["focus"],
450
- entry: "focusResizeHandle",
451
- activities: ["trackPointerMove"],
452
- on: {
453
- POINTER_MOVE: {
454
- actions: ["setPointerValue", "setGlobalCursor", "invokeOnResize"]
455
- },
456
- POINTER_UP: {
457
- target: "focused",
458
- actions: ["setPreviousPanels", "clearGlobalCursor", "blurResizeHandle", "invokeOnResizeEnd"]
459
- }
460
- }
395
+ DOUBLE_CLICK: {
396
+ actions: ["resetStartPanel", "setPreviousPanels"]
461
397
  }
462
398
  }
463
399
  },
464
- {
465
- activities: {
466
- trackPointerMove: (ctx2, _evt, { send }) => {
467
- const doc = dom.getDoc(ctx2);
468
- return domQuery.trackPointerMove(doc, {
469
- onPointerMove(info) {
470
- send({ type: "POINTER_MOVE", point: info.point });
471
- },
472
- onPointerUp() {
473
- send("POINTER_UP");
474
- }
475
- });
476
- }
477
- },
478
- guards: {
479
- isStartPanelAtMin: (ctx2) => ctx2.activeResizeState.isAtMin,
480
- isStartPanelAtMax: (ctx2) => ctx2.activeResizeState.isAtMax,
481
- isHorizontal: (ctx2) => ctx2.isHorizontal,
482
- isVertical: (ctx2) => !ctx2.isHorizontal
483
- },
484
- delays: {
485
- HOVER_DELAY: 250
486
- },
487
- actions: {
488
- setGlobalCursor(ctx2) {
489
- dom.setupGlobalCursor(ctx2);
490
- },
491
- clearGlobalCursor(ctx2) {
492
- dom.removeGlobalCursor(ctx2);
493
- },
494
- invokeOnResize(ctx2) {
495
- ctx2.onSizeChange?.({ size: Array.from(ctx2.size), activeHandleId: ctx2.activeResizeId });
496
- },
497
- invokeOnResizeEnd(ctx2) {
498
- ctx2.onSizeChangeEnd?.({ size: Array.from(ctx2.size), activeHandleId: ctx2.activeResizeId });
499
- },
500
- setActiveHandleId(ctx2, evt) {
501
- ctx2.activeResizeId = evt.id;
502
- },
503
- clearActiveHandleId(ctx2) {
504
- ctx2.activeResizeId = null;
400
+ "hover:temp": {
401
+ effects: ["waitForHoverDelay"],
402
+ on: {
403
+ HOVER_DELAY: {
404
+ target: "hover"
505
405
  },
506
- setInitialSize(ctx2) {
507
- ctx2.initialSize = ctx2.panels.slice().map((panel) => ({
508
- id: panel.id,
509
- size: panel.size
510
- }));
406
+ POINTER_DOWN: {
407
+ target: "dragging",
408
+ actions: ["setActiveHandleId"]
511
409
  },
512
- setPanelSize(ctx2, evt) {
513
- const { id, size } = evt;
514
- ctx2.size = ctx2.size.map((panel) => {
515
- const panelSize = clamp(size, panel.minSize ?? 0, panel.maxSize ?? 100);
516
- return panel.id === id ? { ...panel, size: panelSize } : panel;
517
- });
518
- },
519
- setStartPanelToMin(ctx2) {
520
- const bounds = getPanelBounds(ctx2);
521
- if (!bounds) return;
522
- const { before, after } = bounds;
523
- ctx2.size[before.index].size = before.min;
524
- ctx2.size[after.index].size = after.min;
410
+ POINTER_LEAVE: {
411
+ target: "idle"
412
+ }
413
+ }
414
+ },
415
+ hover: {
416
+ tags: ["focus"],
417
+ on: {
418
+ POINTER_DOWN: {
419
+ target: "dragging"
525
420
  },
526
- setStartPanelToMax(ctx2) {
527
- const bounds = getPanelBounds(ctx2);
528
- if (!bounds) return;
529
- const { before, after } = bounds;
530
- ctx2.size[before.index].size = before.max;
531
- ctx2.size[after.index].size = after.max;
421
+ POINTER_LEAVE: {
422
+ target: "idle"
423
+ }
424
+ }
425
+ },
426
+ focused: {
427
+ tags: ["focus"],
428
+ on: {
429
+ BLUR: {
430
+ target: "idle"
532
431
  },
533
- expandStartPanel(ctx2, evt) {
534
- const bounds = getPanelBounds(ctx2);
535
- if (!bounds) return;
536
- const { before, after } = bounds;
537
- ctx2.size[before.index].size = before.up(evt.step);
538
- ctx2.size[after.index].size = after.down(evt.step);
432
+ POINTER_DOWN: {
433
+ target: "dragging",
434
+ actions: ["setActiveHandleId"]
539
435
  },
540
- shrinkStartPanel(ctx2, evt) {
541
- const bounds = getPanelBounds(ctx2);
542
- if (!bounds) return;
543
- const { before, after } = bounds;
544
- ctx2.size[before.index].size = before.down(evt.step);
545
- ctx2.size[after.index].size = after.up(evt.step);
436
+ ARROW_LEFT: {
437
+ guard: "isHorizontal",
438
+ actions: ["shrinkStartPanel", "setPreviousPanels"]
546
439
  },
547
- resetStartPanel(ctx2, evt) {
548
- const bounds = getPanelBounds(ctx2, evt.id);
549
- if (!bounds) return;
550
- const { before, after } = bounds;
551
- ctx2.size[before.index].size = ctx2.initialSize[before.index].size;
552
- ctx2.size[after.index].size = ctx2.initialSize[after.index].size;
440
+ ARROW_RIGHT: {
441
+ guard: "isHorizontal",
442
+ actions: ["expandStartPanel", "setPreviousPanels"]
553
443
  },
554
- focusResizeHandle(ctx2) {
555
- domQuery.raf(() => {
556
- dom.getActiveHandleEl(ctx2)?.focus({ preventScroll: true });
557
- });
444
+ ARROW_UP: {
445
+ guard: "isVertical",
446
+ actions: ["shrinkStartPanel", "setPreviousPanels"]
558
447
  },
559
- blurResizeHandle(ctx2) {
560
- domQuery.raf(() => {
561
- dom.getActiveHandleEl(ctx2)?.blur();
562
- });
448
+ ARROW_DOWN: {
449
+ guard: "isVertical",
450
+ actions: ["expandStartPanel", "setPreviousPanels"]
563
451
  },
564
- setPreviousPanels(ctx2) {
565
- ctx2.previousPanels = ctx2.panels.slice();
452
+ ENTER: [
453
+ {
454
+ guard: "isStartPanelAtMax",
455
+ actions: ["setStartPanelToMin", "setPreviousPanels"]
456
+ },
457
+ { actions: ["setStartPanelToMax", "setPreviousPanels"] }
458
+ ],
459
+ HOME: {
460
+ actions: ["setStartPanelToMin", "setPreviousPanels"]
566
461
  },
567
- setActiveResizeState(ctx2) {
568
- const panels = getPanelBounds(ctx2);
569
- if (!panels) return;
570
- const { before } = panels;
571
- ctx2.activeResizeState = {
572
- isAtMin: before.isAtMin,
573
- isAtMax: before.isAtMax
574
- };
462
+ END: {
463
+ actions: ["setStartPanelToMax", "setPreviousPanels"]
464
+ }
465
+ }
466
+ },
467
+ dragging: {
468
+ tags: ["focus"],
469
+ entry: ["focusResizeHandle"],
470
+ effects: ["trackPointerMove"],
471
+ on: {
472
+ POINTER_MOVE: {
473
+ actions: ["setPointerValue", "setGlobalCursor", "invokeOnResize"]
575
474
  },
576
- setPointerValue(ctx2, evt) {
577
- const panels = getHandlePanels(ctx2);
578
- const bounds = getHandleBounds(ctx2);
579
- if (!panels || !bounds) return;
580
- const rootEl = dom.getRootEl(ctx2);
581
- if (!rootEl) return;
582
- const relativePoint = domQuery.getRelativePoint(evt.point, rootEl);
583
- const percentValue = relativePoint.getPercentValue({
584
- dir: ctx2.dir,
585
- orientation: ctx2.orientation
586
- });
587
- let pointValue = percentValue * 100;
588
- ctx2.activeResizeState = {
589
- isAtMin: pointValue < bounds.min,
590
- isAtMax: pointValue > bounds.max
591
- };
592
- pointValue = clamp(pointValue, bounds.min, bounds.max);
593
- const { before, after } = panels;
594
- const offset = pointValue - before.end;
595
- ctx2.size[before.index].size = before.size + offset;
596
- ctx2.size[after.index].size = after.size - offset;
475
+ POINTER_UP: {
476
+ target: "focused",
477
+ actions: ["setPreviousPanels", "clearGlobalCursor", "blurResizeHandle", "invokeOnResizeEnd"]
597
478
  }
598
479
  }
599
480
  }
600
- );
601
- }
481
+ },
482
+ implementations: {
483
+ effects: {
484
+ waitForHoverDelay: ({ send }) => {
485
+ const id = setTimeout(() => {
486
+ send({ type: "HOVER_DELAY" });
487
+ }, 250);
488
+ return () => clearTimeout(id);
489
+ },
490
+ trackPointerMove: ({ scope, send }) => {
491
+ const doc = scope.getDoc();
492
+ return domQuery.trackPointerMove(doc, {
493
+ onPointerMove(info) {
494
+ send({ type: "POINTER_MOVE", point: info.point });
495
+ },
496
+ onPointerUp() {
497
+ send({ type: "POINTER_UP" });
498
+ }
499
+ });
500
+ }
501
+ },
502
+ guards: {
503
+ isStartPanelAtMin: ({ context }) => context.get("activeResizeState").isAtMin,
504
+ isStartPanelAtMax: ({ context }) => context.get("activeResizeState").isAtMax,
505
+ isHorizontal: ({ prop }) => prop("orientation") === "horizontal",
506
+ isVertical: ({ prop }) => prop("orientation") !== "horizontal"
507
+ },
508
+ actions: {
509
+ setGlobalCursor({ context, scope, computed }) {
510
+ const activeState = context.get("activeResizeState");
511
+ const isHorizontal = computed("isHorizontal");
512
+ setupGlobalCursor(scope, activeState, isHorizontal);
513
+ },
514
+ clearGlobalCursor({ scope }) {
515
+ removeGlobalCursor(scope);
516
+ },
517
+ invokeOnResize({ context, prop }) {
518
+ prop("onSizeChange")?.({
519
+ size: Array.from(context.get("size")),
520
+ activeHandleId: context.get("activeResizeId")
521
+ });
522
+ },
523
+ invokeOnResizeEnd({ context, prop }) {
524
+ prop("onSizeChangeEnd")?.({
525
+ size: Array.from(context.get("size")),
526
+ activeHandleId: context.get("activeResizeId")
527
+ });
528
+ },
529
+ setActiveHandleId({ context, event }) {
530
+ context.set("activeResizeId", event.id);
531
+ },
532
+ clearActiveHandleId({ context }) {
533
+ context.set("activeResizeId", null);
534
+ },
535
+ setPanelSize({ context, event }) {
536
+ const { id, size } = event;
537
+ context.set(
538
+ "size",
539
+ (prev) => prev.map((panel) => {
540
+ const panelSize = clamp(size, panel.minSize ?? 0, panel.maxSize ?? 100);
541
+ return panel.id === id ? { ...panel, size: panelSize } : panel;
542
+ })
543
+ );
544
+ },
545
+ setStartPanelToMin({ context, computed }) {
546
+ const bounds = getPanelBounds(computed("panels"), context.get("activeResizeId"));
547
+ if (!bounds) return;
548
+ const { before, after } = bounds;
549
+ context.set("size", (prev) => {
550
+ const next = prev.slice();
551
+ next[before.index].size = before.min;
552
+ next[after.index].size = after.min;
553
+ return next;
554
+ });
555
+ },
556
+ setStartPanelToMax({ context, computed }) {
557
+ const bounds = getPanelBounds(computed("panels"), context.get("activeResizeId"));
558
+ if (!bounds) return;
559
+ const { before, after } = bounds;
560
+ context.set("size", (prev) => {
561
+ const next = prev.slice();
562
+ next[before.index].size = before.max;
563
+ next[after.index].size = after.max;
564
+ return next;
565
+ });
566
+ },
567
+ expandStartPanel({ context, event, computed }) {
568
+ const bounds = getPanelBounds(computed("panels"), context.get("activeResizeId"));
569
+ if (!bounds) return;
570
+ const { before, after } = bounds;
571
+ context.set("size", (prev) => {
572
+ const next = prev.slice();
573
+ next[before.index].size = before.up(event.step);
574
+ next[after.index].size = after.down(event.step);
575
+ return next;
576
+ });
577
+ },
578
+ shrinkStartPanel({ context, event, computed }) {
579
+ const bounds = getPanelBounds(computed("panels"), context.get("activeResizeId"));
580
+ if (!bounds) return;
581
+ const { before, after } = bounds;
582
+ context.set("size", (prev) => {
583
+ const next = prev.slice();
584
+ next[before.index].size = before.down(event.step);
585
+ next[after.index].size = after.up(event.step);
586
+ return next;
587
+ });
588
+ },
589
+ resetStartPanel({ context, computed }) {
590
+ const bounds = getPanelBounds(computed("panels"), context.get("activeResizeId"));
591
+ if (!bounds) return;
592
+ const { before, after } = bounds;
593
+ const initialSize = context.initial("size");
594
+ context.set("size", (prev) => {
595
+ const next = prev.slice();
596
+ next[before.index].size = initialSize[before.index].size;
597
+ next[after.index].size = initialSize[after.index].size;
598
+ return next;
599
+ });
600
+ },
601
+ focusResizeHandle({ scope, context }) {
602
+ domQuery.raf(() => {
603
+ const activeId = context.get("activeResizeId");
604
+ if (!activeId) return;
605
+ getResizeTriggerEl(scope, activeId)?.focus({ preventScroll: true });
606
+ });
607
+ },
608
+ blurResizeHandle({ scope, context }) {
609
+ domQuery.raf(() => {
610
+ const activeId = context.get("activeResizeId");
611
+ if (!activeId) return;
612
+ getResizeTriggerEl(scope, activeId)?.blur();
613
+ });
614
+ },
615
+ setPreviousPanels({ refs, computed }) {
616
+ refs.set("previousPanels", computed("panels").slice());
617
+ },
618
+ setActiveResizeState({ context, computed }) {
619
+ const panels = getPanelBounds(computed("panels"), context.get("activeResizeId"));
620
+ if (!panels) return;
621
+ const { before } = panels;
622
+ context.set("activeResizeState", {
623
+ isAtMin: before.isAtMin,
624
+ isAtMax: before.isAtMax
625
+ });
626
+ },
627
+ setPointerValue({ context, event, prop, scope, computed }) {
628
+ const panels = getHandlePanels(computed("panels"), context.get("activeResizeId"));
629
+ const bounds = getHandleBounds(computed("panels"), context.get("activeResizeId"));
630
+ if (!panels || !bounds) return;
631
+ const rootEl = getRootEl(scope);
632
+ if (!rootEl) return;
633
+ const relativePoint = domQuery.getRelativePoint(event.point, rootEl);
634
+ const percentValue = relativePoint.getPercentValue({
635
+ dir: prop("dir"),
636
+ orientation: prop("orientation")
637
+ });
638
+ let pointValue = percentValue * 100;
639
+ context.set("activeResizeState", {
640
+ isAtMin: pointValue < bounds.min,
641
+ isAtMax: pointValue > bounds.max
642
+ });
643
+ pointValue = clamp(pointValue, bounds.min, bounds.max);
644
+ const { before, after } = panels;
645
+ const offset = pointValue - before.end;
646
+ context.set("size", (prev) => {
647
+ const next = prev.slice();
648
+ next[before.index].size = before.size + offset;
649
+ next[after.index].size = after.size - offset;
650
+ return next;
651
+ });
652
+ }
653
+ }
654
+ }
655
+ });
602
656
  var props = types.createProps()([
603
657
  "dir",
604
658
  "getRootNode",
@@ -607,7 +661,8 @@ var props = types.createProps()([
607
661
  "onSizeChange",
608
662
  "onSizeChangeEnd",
609
663
  "orientation",
610
- "size"
664
+ "size",
665
+ "defaultSize"
611
666
  ]);
612
667
  var splitProps = utils.createSplitProps(props);
613
668
  var panelProps = types.createProps()(["id", "snapSize"]);