@labpane/os 1.5.1 → 1.6.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/README.md CHANGED
@@ -73,6 +73,8 @@ The tab menu's **Close** submenu can close tabs to the left or right, other tabs
73
73
 
74
74
  Background tabs stay mounted, so a tab's content asks where it stands: `useTabActive()` is true for the tab in front of the focused pane and `useTabVisible()` for every tab on screen, including split panes (`useTabVisibleRef()` for listeners, `useShownOnce(visible)` to mount once). Gate polling, intervals, window listeners, and portaled overlays on them; redraw charts and canvases from a `ResizeObserver` on their own element and skip zero width; pause media when its tab is no longer visible. `useLeaveTab()` returns a function that closes the tab and returns to the tab it was opened from. With the `history` prop, each tab keeps its own history behind the browser's Back and Forward, starting at its `href`: `useTabHistory()` gives `{ path, canGoBack, canGoForward, navigate, back, forward }`. `hasOpenOverlay()` is true while a dialog, menu, listbox, or full-screen element is open, and the workspace's shortcuts wait for it.
75
75
 
76
+ For a Back button in an editor or detail view, `useTabBack()` returns `{ canGoBack, back }`. It returns through the current tab's `useTabHistory()` entries first, then through previously selected tabs in the same pane. Back keeps tabs mounted and preserves unsaved drafts. Closed tabs and tabs moved to another pane are skipped. Render the button only when `canGoBack`, or disable it otherwise.
77
+
76
78
  ## Slots
77
79
 
78
80
  The workspace renders no menus or buttons of its own. You fill these slots with your own components, or with `@labpane/ui`:
@@ -187,7 +189,9 @@ The host interface has no Wails, Go, Tauri, or Electron dependency. Applications
187
189
 
188
190
  ## Keyboard
189
191
 
190
- On touch devices, swipe the tab bar to scroll it and tap a tab to select it. An overflowing bar also has a native tab picker at its end. Swiping does not reorder or split tabs. If you supply a `menu`, touch and hold a tab to use its move and split actions. Mouse dragging and keyboard actions remain available.
192
+ On touch devices, swipe the tab bar to scroll it and tap a tab to select it. To reorder or dock a tab, hold it briefly before dragging. Keeping the finger still for a longer hold opens the tab's actions when a `menu` is supplied. An overflowing bar also has a native tab picker at its end. Split dividers have visible grips and 44px touch targets on devices with a coarse pointer; either orientation can be resized without jumping when the drag begins off-center. Mouse dragging and keyboard actions remain available.
193
+
194
+ Swipe non-interactive panel content left or right to select the next or previous tab in that pane. The gesture stops at the first and last tab. Vertical scrolling, pinch gestures, form controls, and horizontally scrollable content retain their native behavior. Use `data-no-swipe` on a custom gesture surface, such as a canvas editor, or set `swipeTabs={false}` on `Workspace` to disable tab swiping altogether.
191
195
 
192
196
  Workspace panels scroll their content independently. Make page headers and action rows wrap, use `min-width: 0` for flex children, and keep wide tables or code blocks in their own scroll containers. A fixed `min-width` on application content can still make a panel scroll sideways even when the document fits the screen.
193
197
 
package/dist/index.js CHANGED
@@ -5,9 +5,9 @@ import {
5
5
  useDeferredValue,
6
6
  useEffect as useEffect5,
7
7
  useId as useId2,
8
- useLayoutEffect as useLayoutEffect8,
8
+ useLayoutEffect as useLayoutEffect9,
9
9
  useMemo as useMemo3,
10
- useRef as useRef9,
10
+ useRef as useRef10,
11
11
  useState as useState5
12
12
  } from "react";
13
13
 
@@ -357,8 +357,10 @@ function WorkspaceSurface({
357
357
  const [resizing, setResizing] = useState(false);
358
358
  const [resizeDraft, setResizeDraft] = useState();
359
359
  const resizeDraftRef = useRef(void 0);
360
+ const resizeStart = useRef(void 0);
360
361
  const displayedLayout = resizeDraft?.base === layout ? resizeDraft.layout : layout;
361
362
  const cancelResize = () => {
363
+ resizeStart.current = void 0;
362
364
  resizePointer.cancel();
363
365
  resizeDraftRef.current = void 0;
364
366
  setResizeDraft(void 0);
@@ -377,11 +379,17 @@ function WorkspaceSurface({
377
379
  previousGeometry.current = geometry;
378
380
  }, [geometry]);
379
381
  useLayoutEffect(() => {
382
+ const element = board.current;
383
+ const measure = (width, height) => setSize(
384
+ (current) => current.width === width && current.height === height ? current : { width, height }
385
+ );
386
+ const bounds = element.getBoundingClientRect();
387
+ measure(bounds.width, bounds.height);
380
388
  const observer2 = new ResizeObserver(([entry]) => {
381
389
  const { width, height } = entry.contentRect;
382
- setSize({ width, height });
390
+ measure(width, height);
383
391
  });
384
- observer2.observe(board.current);
392
+ observer2.observe(element);
385
393
  return () => observer2.disconnect();
386
394
  }, []);
387
395
  const { leaves, dividers } = layoutBoxes(
@@ -437,7 +445,7 @@ function WorkspaceSurface({
437
445
  let index;
438
446
  if (valid && !edge) {
439
447
  const nav = board.current.querySelector(
440
- `[data-pane-header="${CSS.escape(target.pane.id)}"] [role="tablist"]`
448
+ `[data-pane-header="${CSS.escape(target.pane.id)}"] .lab-tablist`
441
449
  );
442
450
  const header2 = nav?.closest("[data-pane-header]");
443
451
  index = target.pane.tabs.length;
@@ -615,39 +623,51 @@ function WorkspaceSurface({
615
623
  "aria-valuemax": Math.round(high * 100),
616
624
  tabIndex: 0,
617
625
  className: "lab-divider",
618
- style: position({
619
- ...box,
620
- [axis]: box[axis] + gutter2[axis] / 2 - 12,
621
- [dimension]: 24
622
- }),
626
+ style: {
627
+ ...position(box),
628
+ [horizontal ? "left" : "top"]: `calc(${box[axis] + gutter2[axis] / 2}px - var(--lab-divider-hit-size) / 2)`,
629
+ [dimension]: "var(--lab-divider-hit-size)"
630
+ },
623
631
  onDoubleClick: () => resize(horizontal ? 0.5 : 2 / 3),
624
632
  onPointerDown: (event) => {
625
- if (event.button !== 0) return;
633
+ if (event.button !== 0 || resizeStart.current) return;
626
634
  event.preventDefault();
635
+ resizeStart.current = {
636
+ pointerId: event.pointerId,
637
+ coordinate: horizontal ? event.clientX : event.clientY,
638
+ ratio
639
+ };
627
640
  event.currentTarget.setPointerCapture(event.pointerId);
628
641
  setResizing(true);
629
642
  },
630
643
  onPointerMove: (event) => {
631
- if (!event.currentTarget.hasPointerCapture(event.pointerId))
644
+ const start = resizeStart.current;
645
+ if (!start || start.pointerId !== event.pointerId || !event.currentTarget.hasPointerCapture(event.pointerId))
632
646
  return;
633
647
  const { clientX, clientY } = event;
634
648
  resizePointer.schedule(() => {
635
- const b = board.current.getBoundingClientRect();
636
- const coordinate = horizontal ? clientX - b.left : clientY - b.top;
649
+ const coordinate = horizontal ? clientX : clientY;
637
650
  resize(
638
- (coordinate - bounds[axis]) / (bounds[dimension] - gutter2[axis]),
651
+ start.ratio + (coordinate - start.coordinate) / (bounds[dimension] - gutter2[axis]),
639
652
  true
640
653
  );
641
654
  });
642
655
  },
643
- onPointerUp: () => {
656
+ onPointerUp: (event) => {
657
+ if (resizeStart.current?.pointerId !== event.pointerId) return;
644
658
  resizePointer.flush();
645
659
  const draft = resizeDraftRef.current;
646
660
  if (draft?.base === layout) change(draft.layout);
647
661
  cancelResize();
648
662
  },
649
- onPointerCancel: cancelResize,
650
- onLostPointerCapture: cancelResize,
663
+ onPointerCancel: (event) => {
664
+ if (resizeStart.current?.pointerId === event.pointerId)
665
+ cancelResize();
666
+ },
667
+ onLostPointerCapture: (event) => {
668
+ if (resizeStart.current?.pointerId === event.pointerId)
669
+ cancelResize();
670
+ },
651
671
  onKeyDown: (event) => {
652
672
  if (hasOpenOverlay()) return;
653
673
  const step = event.shiftKey ? 0.1 : 0.02;
@@ -1068,6 +1088,11 @@ function WorkspaceTabs({
1068
1088
  const helpId = React.useId();
1069
1089
  const menuFocus = React.useRef(void 0);
1070
1090
  const drag = React.useRef(void 0);
1091
+ const touchDrag = React.useRef(void 0);
1092
+ const clearTouchDrag = () => {
1093
+ if (touchDrag.current) clearTimeout(touchDrag.current.timer);
1094
+ touchDrag.current = void 0;
1095
+ };
1071
1096
  const [dragging, setDragging] = React.useState();
1072
1097
  const [pointerFocus, setPointerFocus] = React.useState(false);
1073
1098
  const [announcement, announce] = React.useState("");
@@ -1229,6 +1254,7 @@ function WorkspaceTabs({
1229
1254
  latest.current.refresh();
1230
1255
  });
1231
1256
  const finish = (cancel = false) => {
1257
+ clearTouchDrag();
1232
1258
  if (cancel) pointer.current.cancel();
1233
1259
  else pointer.current.flush();
1234
1260
  const current = drag.current;
@@ -1463,6 +1489,14 @@ function WorkspaceTabs({
1463
1489
  event.preventDefault();
1464
1490
  nav.scrollLeft += event.deltaY * (event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? nav.clientWidth : 1);
1465
1491
  };
1492
+ const touchStart = (event) => {
1493
+ if (drag.current && event.touches.length > 1) latest.current.finish(true);
1494
+ };
1495
+ const touchMove = (event) => {
1496
+ if (event.touches.length !== 1) latest.current.finish(true);
1497
+ else if (touchDrag.current?.ready && event.cancelable)
1498
+ event.preventDefault();
1499
+ };
1466
1500
  const unobserve = geometry.observe(
1467
1501
  [
1468
1502
  nav,
@@ -1475,6 +1509,8 @@ function WorkspaceTabs({
1475
1509
  addEventListener("scroll", scroll, true);
1476
1510
  addEventListener("blur", blur);
1477
1511
  nav.addEventListener("wheel", wheel, { passive: false });
1512
+ nav.addEventListener("touchmove", touchMove, { passive: false });
1513
+ addEventListener("touchstart", touchStart, { passive: true });
1478
1514
  return () => {
1479
1515
  for (const name of ["transitionrun", "transitionend", "transitioncancel"])
1480
1516
  board?.removeEventListener(name, transition);
@@ -1483,12 +1519,15 @@ function WorkspaceTabs({
1483
1519
  removeEventListener("scroll", scroll, true);
1484
1520
  removeEventListener("blur", blur);
1485
1521
  nav.removeEventListener("wheel", wheel);
1522
+ nav.removeEventListener("touchmove", touchMove);
1523
+ removeEventListener("touchstart", touchStart);
1486
1524
  geometry.cancel();
1487
1525
  restoreFrame();
1488
1526
  };
1489
1527
  }, [active, dragBoundary]);
1490
1528
  React.useEffect(
1491
1529
  () => () => {
1530
+ clearTouchDrag();
1492
1531
  pointer.current.cancel();
1493
1532
  settling.current?.cancel();
1494
1533
  for (const animation of animations2.current.values()) animation.cancel();
@@ -1516,16 +1555,24 @@ function WorkspaceTabs({
1516
1555
  );
1517
1556
  return /* @__PURE__ */ jsxs3("div", { ref: stripRef, className: "lab-tabs", children: [
1518
1557
  scrollButton(-1),
1558
+ links.length > 0 && /* @__PURE__ */ jsx4(
1559
+ "div",
1560
+ {
1561
+ role: "tablist",
1562
+ "aria-label": `Workspace tabs: ${labels.get(active)}`,
1563
+ "aria-describedby": helpId,
1564
+ "aria-owns": links.map(([key2]) => ids.tab(key2)).join(" ")
1565
+ }
1566
+ ),
1519
1567
  /* @__PURE__ */ jsxs3(
1520
1568
  "div",
1521
1569
  {
1522
1570
  ref: navRef,
1523
- role: links.length ? "tablist" : void 0,
1524
- "aria-label": links.length ? `Workspace tabs: ${labels.get(active)}` : void 0,
1525
- "aria-describedby": links.length ? helpId : void 0,
1526
1571
  onKeyDownCapture: () => setPointerFocus(false),
1527
1572
  onBlurCapture: () => setPointerFocus(false),
1528
1573
  onPointerDownCapture: () => {
1574
+ docking.cancel();
1575
+ clearTouchDrag();
1529
1576
  pointer.current.cancel();
1530
1577
  setDraftOrder(void 0);
1531
1578
  content.release(false);
@@ -1544,7 +1591,14 @@ function WorkspaceTabs({
1544
1591
  },
1545
1592
  onPointerMove: (event) => {
1546
1593
  const current = drag.current, nav = navRef.current, x = event.clientX;
1547
- if (!(event.buttons & 1) || !current || !nav) return;
1594
+ if (!(event.buttons & 1) || !current || current.pointerId !== event.pointerId || !nav)
1595
+ return;
1596
+ if (hasOpenOverlay()) return finish(true);
1597
+ if (touchDrag.current && !touchDrag.current.ready) {
1598
+ if (Math.hypot(x - current.x, event.clientY - current.y) >= 8)
1599
+ finish(true);
1600
+ return;
1601
+ }
1548
1602
  if (!current.moved && Math.hypot(x - current.x, event.clientY - current.y) < 6)
1549
1603
  return;
1550
1604
  if (!current.moved && active !== current.key) onSelect(current.key);
@@ -1667,13 +1721,23 @@ function WorkspaceTabs({
1667
1721
  onKeyDown: (event) => keyDown(event, key2, index),
1668
1722
  onPointerDown: (event) => {
1669
1723
  if (event.button !== 0 || !event.isPrimary) return;
1670
- if (event.pointerType === "touch") return;
1671
- if (event.pointerType === "mouse") event.preventDefault();
1672
- event.currentTarget.setPointerCapture(event.pointerId);
1673
- event.currentTarget.focus({ preventScroll: true });
1674
- setPointerFocus(true);
1724
+ if (event.pointerType === "touch") {
1725
+ const pending2 = {
1726
+ ready: false,
1727
+ timer: setTimeout(() => {
1728
+ pending2.ready = true;
1729
+ }, 300)
1730
+ };
1731
+ touchDrag.current = pending2;
1732
+ } else {
1733
+ event.preventDefault();
1734
+ event.currentTarget.setPointerCapture(event.pointerId);
1735
+ event.currentTarget.focus({ preventScroll: true });
1736
+ setPointerFocus(true);
1737
+ }
1675
1738
  const box = event.currentTarget.parentElement.getBoundingClientRect();
1676
1739
  drag.current = {
1740
+ pointerId: event.pointerId,
1677
1741
  key: key2,
1678
1742
  offset: event.clientX - box.left,
1679
1743
  offsetY: event.clientY - box.top,
@@ -2071,6 +2135,150 @@ function useBrowserHistory(front) {
2071
2135
  }, [front]);
2072
2136
  }
2073
2137
 
2138
+ // tab-back.ts
2139
+ import { createContext as createContext6, useContext as useContext6, useSyncExternalStore as useSyncExternalStore2 } from "react";
2140
+ function createPaneBack() {
2141
+ let active;
2142
+ let pending2;
2143
+ let previous = [];
2144
+ let available = /* @__PURE__ */ new Set();
2145
+ let select = (_key) => {
2146
+ };
2147
+ const listeners = /* @__PURE__ */ new Set();
2148
+ const back = () => {
2149
+ const key2 = previous.pop();
2150
+ if (!key2) return;
2151
+ pending2 = key2;
2152
+ publish();
2153
+ select(key2);
2154
+ };
2155
+ let snapshot = { canGoBack: false, back };
2156
+ function publish() {
2157
+ const canGoBack = previous.length > 0;
2158
+ if (snapshot.canGoBack === canGoBack) return;
2159
+ snapshot = { canGoBack, back };
2160
+ listeners.forEach((listener) => listener());
2161
+ }
2162
+ return {
2163
+ subscribe(listener) {
2164
+ listeners.add(listener);
2165
+ return () => listeners.delete(listener);
2166
+ },
2167
+ get: () => snapshot,
2168
+ update(key2, keys, onSelect) {
2169
+ available = new Set(keys);
2170
+ select = onSelect;
2171
+ previous = previous.filter((entry) => available.has(entry));
2172
+ if (key2 !== active) {
2173
+ if (pending2 !== key2 && active && available.has(active))
2174
+ previous.push(active);
2175
+ active = key2;
2176
+ pending2 = void 0;
2177
+ }
2178
+ while (previous.at(-1) === active && previous.length) previous.pop();
2179
+ publish();
2180
+ }
2181
+ };
2182
+ }
2183
+ var TabBackContext = createContext6(createPaneBack());
2184
+ function useTabBack() {
2185
+ const history2 = useTabHistory();
2186
+ const store = useContext6(TabBackContext);
2187
+ const pane = useSyncExternalStore2(store.subscribe, store.get, store.get);
2188
+ return history2.canGoBack ? { canGoBack: true, back: history2.back } : pane;
2189
+ }
2190
+
2191
+ // touch-navigation.ts
2192
+ import { useLayoutEffect as useLayoutEffect8, useRef as useRef9 } from "react";
2193
+ var interactive = 'a, button, input, textarea, select, summary, [contenteditable]:not([contenteditable="false"]), [role="button"], [role="link"], [role="checkbox"], [role="radio"], [role="switch"], [role="menuitem"], [role="tab"], [role="separator"], [role="slider"], [role="spinbutton"], [role="listbox"], [role="combobox"], [role="grid"], [role="tree"], [role="application"], canvas, video, audio, [draggable="true"], [data-no-swipe]';
2194
+ function ownsGesture(target, panel) {
2195
+ if (target.closest(interactive)) return true;
2196
+ for (let node = target; node; node = node.parentElement) {
2197
+ const style = getComputedStyle(node);
2198
+ if (style.touchAction === "none") return true;
2199
+ if (node.scrollWidth > node.clientWidth + 1 && /auto|scroll/.test(style.overflowX))
2200
+ return true;
2201
+ if (node === panel) break;
2202
+ }
2203
+ return false;
2204
+ }
2205
+ function useTabSwipe(viewport, enabled, previous, next) {
2206
+ const current = useRef9({ previous, next });
2207
+ const gesture = useRef9(void 0);
2208
+ useLayoutEffect8(() => {
2209
+ current.current = { previous, next };
2210
+ });
2211
+ useLayoutEffect8(() => {
2212
+ const panel = viewport.current;
2213
+ if (!panel || !enabled) return;
2214
+ const cancel = () => {
2215
+ gesture.current = void 0;
2216
+ };
2217
+ const additionalTouch = (event) => {
2218
+ if (event.touches.length > 1) cancel();
2219
+ };
2220
+ const start = (event) => {
2221
+ cancel();
2222
+ if (event.touches.length !== 1 || hasOpenOverlay() || !(event.target instanceof Element) || ownsGesture(event.target, panel) || getSelection()?.type === "Range")
2223
+ return;
2224
+ const touch = event.touches[0];
2225
+ gesture.current = {
2226
+ id: touch.identifier,
2227
+ x: touch.clientX,
2228
+ y: touch.clientY,
2229
+ dx: 0,
2230
+ dy: 0,
2231
+ started: performance.now(),
2232
+ horizontal: false
2233
+ };
2234
+ };
2235
+ const move = (event) => {
2236
+ const moving = gesture.current;
2237
+ if (!moving) return;
2238
+ if (event.touches.length !== 1 || hasOpenOverlay() || performance.now() - moving.started > 1e3)
2239
+ return cancel();
2240
+ const touch = event.touches[0];
2241
+ if (touch.identifier !== moving.id) return cancel();
2242
+ moving.dx = touch.clientX - moving.x;
2243
+ moving.dy = touch.clientY - moving.y;
2244
+ const x = Math.abs(moving.dx), y = Math.abs(moving.dy);
2245
+ if (!moving.horizontal) {
2246
+ if (y > 10 && y >= x) return cancel();
2247
+ if (x < 12 || x < y * 1.4) return;
2248
+ if (!(moving.dx < 0 ? current.current.next : current.current.previous))
2249
+ return cancel();
2250
+ moving.horizontal = true;
2251
+ }
2252
+ if (event.cancelable) event.preventDefault();
2253
+ };
2254
+ const end = (event) => {
2255
+ const finished = gesture.current;
2256
+ cancel();
2257
+ if (!finished || event.touches.length || !finished.horizontal || hasOpenOverlay())
2258
+ return;
2259
+ const threshold = Math.max(48, Math.min(96, panel.clientWidth * 0.15));
2260
+ if (Math.abs(finished.dx) < threshold || Math.abs(finished.dx) < Math.abs(finished.dy) * 1.4)
2261
+ return;
2262
+ (finished.dx < 0 ? current.current.next : current.current.previous)?.();
2263
+ };
2264
+ panel.addEventListener("touchstart", start, { passive: true });
2265
+ panel.addEventListener("touchmove", move, { passive: false });
2266
+ panel.addEventListener("touchend", end);
2267
+ panel.addEventListener("touchcancel", cancel);
2268
+ addEventListener("touchstart", additionalTouch, { passive: true });
2269
+ addEventListener("blur", cancel);
2270
+ return () => {
2271
+ cancel();
2272
+ panel.removeEventListener("touchstart", start);
2273
+ panel.removeEventListener("touchmove", move);
2274
+ panel.removeEventListener("touchend", end);
2275
+ panel.removeEventListener("touchcancel", cancel);
2276
+ removeEventListener("touchstart", additionalTouch);
2277
+ removeEventListener("blur", cancel);
2278
+ };
2279
+ }, [viewport, enabled]);
2280
+ }
2281
+
2074
2282
  // workspace.tsx
2075
2283
  import { Fragment as Fragment3, jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
2076
2284
  function Workspace(props) {
@@ -2095,6 +2303,7 @@ function WorkspaceContent({
2095
2303
  layout,
2096
2304
  onLayoutChange: change,
2097
2305
  history: history2,
2306
+ swipeTabs = true,
2098
2307
  className,
2099
2308
  children,
2100
2309
  empty
@@ -2109,20 +2318,20 @@ function WorkspaceContent({
2109
2318
  contentHeight,
2110
2319
  logoSize
2111
2320
  } = useMemo3(() => densitySize(density), [density]);
2112
- const corner2 = useRef9(null);
2321
+ const corner2 = useRef10(null);
2113
2322
  const [reserve, setReserve] = useState5(0);
2114
2323
  const hasTrailing = !!trailing;
2115
- useLayoutEffect8(() => {
2324
+ useLayoutEffect9(() => {
2116
2325
  const element = corner2.current;
2117
2326
  if (!element) return setReserve(0);
2118
2327
  const observer2 = new ResizeObserver(() => setReserve(element.offsetWidth));
2119
2328
  observer2.observe(element);
2120
2329
  return () => observer2.disconnect();
2121
2330
  }, [hasTrailing]);
2122
- const ownRoot = useRef9(null);
2331
+ const ownRoot = useRef10(null);
2123
2332
  const root = windowControlsOverlay?.root ?? ownRoot;
2124
2333
  const [inset, setInset] = useState5(0);
2125
- useLayoutEffect8(() => {
2334
+ useLayoutEffect9(() => {
2126
2335
  if (!titleBar) return setInset(0);
2127
2336
  const measure = () => setInset(root.current.getBoundingClientRect().top);
2128
2337
  measure();
@@ -2131,23 +2340,40 @@ function WorkspaceContent({
2131
2340
  }, [titleBar, root]);
2132
2341
  const titlebarArea = windowControlsOverlay?.area;
2133
2342
  const height = Math.max(tabHeight, titlebarArea?.height ?? 0);
2134
- const preferredPane = useRef9(void 0);
2343
+ const preferredPane = useRef10(void 0);
2135
2344
  const visibleLayout = reconcileLayout(
2136
2345
  layout,
2137
2346
  tabs.map((t) => t.key),
2138
2347
  active,
2139
2348
  preferredPane.current
2140
2349
  );
2141
- useLayoutEffect8(() => {
2350
+ useLayoutEffect9(() => {
2142
2351
  if (visibleLayout !== layout) change(visibleLayout);
2143
2352
  }, [visibleLayout, layout]);
2144
2353
  const front = active ?? panes(visibleLayout)[0]?.active;
2145
2354
  const openers = useOpeners(tabs, front);
2146
2355
  const historyOf = useTabHistories(tabs);
2356
+ const navigateTab = (key2) => {
2357
+ onSelect(key2);
2358
+ requestAnimationFrame(() => links.get(key2)?.focus({ preventScroll: true }));
2359
+ };
2360
+ const [paneBacks] = useState5(() => /* @__PURE__ */ new Map());
2361
+ const backOf = (pane) => {
2362
+ let store = paneBacks.get(pane.id);
2363
+ if (!store) paneBacks.set(pane.id, store = createPaneBack());
2364
+ return store;
2365
+ };
2366
+ useLayoutEffect9(() => {
2367
+ const currentPanes = panes(visibleLayout);
2368
+ for (const pane of currentPanes)
2369
+ backOf(pane).update(pane.active, pane.tabs, navigateTab);
2370
+ for (const id of paneBacks.keys())
2371
+ if (!currentPanes.some((pane) => pane.id === id)) paneBacks.delete(id);
2372
+ }, [visibleLayout, onSelect]);
2147
2373
  const frontTab = tabsByKey.get(front ?? "");
2148
2374
  useBrowserHistory(history2 && frontTab ? historyOf(frontTab) : void 0);
2149
- const dirty = useRef9(/* @__PURE__ */ new Map());
2150
- const closingTabs = useRef9(false);
2375
+ const dirty = useRef10(/* @__PURE__ */ new Map());
2376
+ const closingTabs = useRef10(false);
2151
2377
  const closeState = {
2152
2378
  tabsByKey,
2153
2379
  visibleLayout,
@@ -2155,8 +2381,8 @@ function WorkspaceContent({
2155
2381
  onClose,
2156
2382
  confirmClose
2157
2383
  };
2158
- const current = useRef9(closeState);
2159
- useLayoutEffect8(() => {
2384
+ const current = useRef10(closeState);
2385
+ useLayoutEffect9(() => {
2160
2386
  current.current = closeState;
2161
2387
  });
2162
2388
  useEffect5(() => {
@@ -2222,8 +2448,8 @@ function WorkspaceContent({
2222
2448
  const opener = openers.get(key2) ?? tabsByKey.get(key2)?.opener;
2223
2449
  requestClose(key2, tabsByKey.has(opener ?? "") ? opener : void 0);
2224
2450
  }
2225
- const services = useRef9(leave);
2226
- useLayoutEffect8(() => {
2451
+ const services = useRef10(leave);
2452
+ useLayoutEffect9(() => {
2227
2453
  services.current = leave;
2228
2454
  });
2229
2455
  const paneOf = (pane) => ({
@@ -2328,6 +2554,7 @@ function WorkspaceContent({
2328
2554
  (r) => r.pane.tabs.includes(tab.key)
2329
2555
  );
2330
2556
  const hidden = tab.key !== region.pane.active && tab.key !== lifted;
2557
+ const index = region.pane.tabs.indexOf(tab.key);
2331
2558
  return /* @__PURE__ */ jsx6(
2332
2559
  TabPanel,
2333
2560
  {
@@ -2336,6 +2563,9 @@ function WorkspaceContent({
2336
2563
  pane: region.pane.id,
2337
2564
  box: region.box,
2338
2565
  transition,
2566
+ swipe: swipeTabs && !hidden && !lifted,
2567
+ previous: index > 0 ? () => navigateTab(region.pane.tabs[index - 1]) : void 0,
2568
+ next: index < region.pane.tabs.length - 1 ? () => navigateTab(region.pane.tabs[index + 1]) : void 0,
2339
2569
  focus: () => {
2340
2570
  preferredPane.current = region.pane.id;
2341
2571
  if (active !== tab.key) onSelect(tab.key);
@@ -2349,6 +2579,7 @@ function WorkspaceContent({
2349
2579
  active: tab.key === front,
2350
2580
  visible: !hidden,
2351
2581
  history: historyOf(tab),
2582
+ back: backOf(region.pane),
2352
2583
  services,
2353
2584
  dirty: dirty.current,
2354
2585
  render: children
@@ -2382,6 +2613,7 @@ var TabBody = memo3(function TabBody2({
2382
2613
  active,
2383
2614
  visible,
2384
2615
  history: history2,
2616
+ back,
2385
2617
  services,
2386
2618
  dirty,
2387
2619
  render
@@ -2406,7 +2638,7 @@ var TabBody = memo3(function TabBody2({
2406
2638
  [inputs]
2407
2639
  );
2408
2640
  const state = useMemo3(() => ({ active, visible }), [active, visible]);
2409
- return /* @__PURE__ */ jsx6(TabStateContext.Provider, { value: state, children: /* @__PURE__ */ jsx6(LeaveTab.Provider, { value: leave, children: /* @__PURE__ */ jsx6(TabHistoryContext.Provider, { value: history2, children: /* @__PURE__ */ jsx6(UnsavedChanges.Provider, { value: report, children: content }) }) }) });
2641
+ return /* @__PURE__ */ jsx6(TabStateContext.Provider, { value: state, children: /* @__PURE__ */ jsx6(LeaveTab.Provider, { value: leave, children: /* @__PURE__ */ jsx6(TabHistoryContext.Provider, { value: history2, children: /* @__PURE__ */ jsx6(TabBackContext.Provider, { value: back, children: /* @__PURE__ */ jsx6(UnsavedChanges.Provider, { value: report, children: content }) }) }) }) });
2410
2642
  });
2411
2643
  function TabPanel({
2412
2644
  tab,
@@ -2415,12 +2647,16 @@ function TabPanel({
2415
2647
  box,
2416
2648
  transition,
2417
2649
  focus,
2650
+ swipe = false,
2651
+ previous,
2652
+ next,
2418
2653
  children
2419
2654
  }) {
2420
2655
  const ids = useWorkspaceIds();
2421
2656
  const { height, borderWidth } = useTabSize();
2422
- const viewport = useRef9(null);
2423
- useLayoutEffect8(() => {
2657
+ const viewport = useRef10(null);
2658
+ useTabSwipe(viewport, swipe, previous, next);
2659
+ useLayoutEffect9(() => {
2424
2660
  viewport.current?.scrollTo(0, 0);
2425
2661
  }, [tab?.scrollKey]);
2426
2662
  return (
@@ -2463,8 +2699,8 @@ function TabPanel({
2463
2699
 
2464
2700
  // workspace-frame.tsx
2465
2701
  import {
2466
- useLayoutEffect as useLayoutEffect9,
2467
- useRef as useRef10,
2702
+ useLayoutEffect as useLayoutEffect10,
2703
+ useRef as useRef11,
2468
2704
  useState as useState6
2469
2705
  } from "react";
2470
2706
  import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
@@ -2473,8 +2709,8 @@ function WorkspaceFrame({
2473
2709
  change,
2474
2710
  children
2475
2711
  }) {
2476
- const viewport = useRef10(null);
2477
- const drag = useRef10(void 0);
2712
+ const viewport = useRef11(null);
2713
+ const drag = useRef11(void 0);
2478
2714
  const [available, setAvailable] = useState6(0);
2479
2715
  const [draft, setDraft] = useState6();
2480
2716
  const compact = Math.min(1600, available);
@@ -2483,7 +2719,7 @@ function WorkspaceFrame({
2483
2719
  drag.current = void 0;
2484
2720
  setDraft(void 0);
2485
2721
  };
2486
- useLayoutEffect9(() => {
2722
+ useLayoutEffect10(() => {
2487
2723
  const observer2 = new ResizeObserver(() => {
2488
2724
  setAvailable(viewport.current.clientWidth);
2489
2725
  cancel();
@@ -2571,8 +2807,8 @@ function WorkspaceFrame({
2571
2807
  // window.tsx
2572
2808
  import {
2573
2809
  useEffect as useEffect6,
2574
- useLayoutEffect as useLayoutEffect10,
2575
- useRef as useRef11,
2810
+ useLayoutEffect as useLayoutEffect11,
2811
+ useRef as useRef12,
2576
2812
  useState as useState7
2577
2813
  } from "react";
2578
2814
  import { Fragment as Fragment4, jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
@@ -2584,8 +2820,8 @@ var setFullscreen = (host, on) => {
2584
2820
  else if (on) void document.documentElement.requestFullscreen?.();
2585
2821
  else if (document.fullscreenElement) void document.exitFullscreen();
2586
2822
  };
2587
- var interactive = "a, button, input, select, textarea, label, summary, [contenteditable], [role=button], [role=tab], [role=separator], [role=menuitem], .lab-tab";
2588
- var draggable = (target) => target instanceof Element && !target.closest(interactive) && (!!target.closest(".lab-toolbar, [data-window-drag]") || target.matches(".lab-workspace") || !!target.querySelector(".lab-workspace"));
2823
+ var interactive2 = "a, button, input, select, textarea, label, summary, [contenteditable], [role=button], [role=tab], [role=separator], [role=menuitem], .lab-tab";
2824
+ var draggable = (target) => target instanceof Element && !target.closest(interactive2) && (!!target.closest(".lab-toolbar, [data-window-drag]") || target.matches(".lab-workspace") || !!target.querySelector(".lab-workspace"));
2589
2825
  function useFullscreen(host) {
2590
2826
  const [full, setFull] = useState7(() => isFullscreen(host));
2591
2827
  useEffect6(() => {
@@ -2673,9 +2909,9 @@ var glyph = (children) => /* @__PURE__ */ jsx8(
2673
2909
  );
2674
2910
  function TrafficLights({ host }) {
2675
2911
  const [full] = useFullscreen(host);
2676
- const spacer = useRef11(null);
2912
+ const spacer = useRef12(null);
2677
2913
  const shown = host.platform === "macos" && !full;
2678
- useLayoutEffect10(() => {
2914
+ useLayoutEffect11(() => {
2679
2915
  const element = spacer.current;
2680
2916
  const toolbar = element?.closest(".lab-toolbar");
2681
2917
  if (!element || !toolbar || !host.trafficLights) return;
@@ -2704,13 +2940,13 @@ function WindowControls({ host }) {
2704
2940
  const [full] = useFullscreen(host);
2705
2941
  const [max, setMax] = useState7(maximized);
2706
2942
  const [top, setTop] = useState7(0);
2707
- const spacer = useRef11(null);
2943
+ const spacer = useRef12(null);
2708
2944
  const hidden = host.platform === "macos" || full;
2709
2945
  const measure = () => {
2710
2946
  setMax(maximized());
2711
2947
  if (spacer.current) setTop(spacer.current.getBoundingClientRect().top);
2712
2948
  };
2713
- useLayoutEffect10(measure);
2949
+ useLayoutEffect11(measure);
2714
2950
  useEffect6(() => {
2715
2951
  window.addEventListener("resize", measure);
2716
2952
  return () => window.removeEventListener("resize", measure);
@@ -2777,6 +3013,7 @@ export {
2777
3013
  useLeaveTab,
2778
3014
  useShownOnce,
2779
3015
  useTabActive,
3016
+ useTabBack,
2780
3017
  useTabHistory,
2781
3018
  useTabVisible,
2782
3019
  useTabVisibleRef,