@labpane/os 1.4.0 → 1.4.2

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
@@ -67,6 +67,8 @@ Each tab is a `WorkspaceTab`:
67
67
 
68
68
  Tabs whose content has unsaved changes call `useUnsavedChanges(true)`. Closing one asks first: through `confirmClose` if you pass it, and the browser's `confirm` otherwise. The page also warns before unloading.
69
69
 
70
+ The tab menu's **Close** submenu can close tabs to the left or right, other tabs in the same pane, all other tabs, or all tabs and panes. Left and right follow the order within the clicked tab's pane. Each unsaved tab asks separately; keeping one leaves it open while the other selected tabs close. Empty panes disappear.
71
+
70
72
  ## Inside a tab
71
73
 
72
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,6 +77,8 @@ Background tabs stay mounted, so a tab's content asks where it stands: `useTabAc
75
77
 
76
78
  The workspace renders no menus or buttons of its own. You fill these slots with your own components, or with `@labpane/ui`:
77
79
 
80
+ Menu actions are `{ label, onSelect, disabled? }`, `{ label, items }` for submenus, or `null` for separators. `ActionMenu` from `@labpane/ui` renders these directly.
81
+
78
82
  | Prop | |
79
83
  | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ |
80
84
  | `toolbar(pane)` | Content at the end of each pane's toolbar, such as an "open a tab" button |
@@ -183,6 +187,10 @@ The host interface has no Wails, Go, Tauri, or Electron dependency. Applications
183
187
 
184
188
  ## Keyboard
185
189
 
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.
191
+
192
+ 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
+
186
194
  - Left and Right move between tabs, Home and End jump to the first and last, and Space selects
187
195
  - Alt+Left and Alt+Right move the focused tab
188
196
  - Alt+Shift+Left, Right, or Down split the focused tab into a new pane on that side
package/dist/index.js CHANGED
@@ -714,6 +714,7 @@ var icon = (strokeWidth, ...paths) => function Icon(props) {
714
714
  };
715
715
  var ChevronLeftIcon = icon(4 / 3, "M10 4 6 8l4 4");
716
716
  var ChevronRightIcon = icon(4 / 3, "m6 4 4 4-4 4");
717
+ var ChevronDownIcon = icon(4 / 3, "m4 6 4 4 4-4");
717
718
  var XIcon = icon(7 / 6, "m12 4-8 8", "m4 4 8 8");
718
719
 
719
720
  // frame.tsx
@@ -1028,6 +1029,8 @@ function WorkspaceTabs({
1028
1029
  items: sourceItems,
1029
1030
  active,
1030
1031
  onClose,
1032
+ onCloseTabs,
1033
+ allTabs,
1031
1034
  onDuplicate,
1032
1035
  onReorder,
1033
1036
  onSelect,
@@ -1057,7 +1060,8 @@ function WorkspaceTabs({
1057
1060
  width: metrics.width
1058
1061
  }, { width: tabWidth, height, contentHeight } = size, width = tabWidth + 16;
1059
1062
  const links = items.map(({ key: key2, label }) => [key2, label]);
1060
- const tabOrder = JSON.stringify(items.map(({ key: key2 }) => key2));
1063
+ const keys = items.map(({ key: key2 }) => key2);
1064
+ const tabOrder = JSON.stringify(keys);
1061
1065
  const labels = new Map(links);
1062
1066
  const navRef = React.useRef(null);
1063
1067
  const stripRef = React.useRef(null);
@@ -1561,6 +1565,11 @@ function WorkspaceTabs({
1561
1565
  className: "lab-tablist",
1562
1566
  children: [
1563
1567
  links.map(([key2, text], index) => {
1568
+ const close = (label, keys2, next) => ({
1569
+ label,
1570
+ disabled: !keys2.length,
1571
+ onSelect: () => onCloseTabs(keys2, next)
1572
+ });
1564
1573
  const actions = menu ? [
1565
1574
  ...onDuplicate ? [
1566
1575
  {
@@ -1592,7 +1601,25 @@ function WorkspaceTabs({
1592
1601
  disabled: items.length < 2
1593
1602
  })),
1594
1603
  null,
1595
- { label: "Close tab", onSelect: () => onClose(key2) }
1604
+ { label: "Close tab", onSelect: () => onClose(key2) },
1605
+ {
1606
+ label: "Close",
1607
+ items: [
1608
+ close("Tabs to the left", keys.slice(0, index), key2),
1609
+ close("Tabs to the right", keys.slice(index + 1), key2),
1610
+ close(
1611
+ "Others in this pane",
1612
+ keys.filter((tab) => tab !== key2),
1613
+ key2
1614
+ ),
1615
+ close(
1616
+ "All others",
1617
+ allTabs.filter((tab) => tab !== key2),
1618
+ key2
1619
+ ),
1620
+ close("All tabs and panes", [...allTabs])
1621
+ ]
1622
+ }
1596
1623
  ] : [];
1597
1624
  const target = /* @__PURE__ */ jsxs3(
1598
1625
  "div",
@@ -1640,6 +1667,7 @@ function WorkspaceTabs({
1640
1667
  onKeyDown: (event) => keyDown(event, key2, index),
1641
1668
  onPointerDown: (event) => {
1642
1669
  if (event.button !== 0 || !event.isPrimary) return;
1670
+ if (event.pointerType === "touch") return;
1643
1671
  if (event.pointerType === "mouse") event.preventDefault();
1644
1672
  event.currentTarget.setPointerCapture(event.pointerId);
1645
1673
  event.currentTarget.focus({ preventScroll: true });
@@ -1689,6 +1717,20 @@ function WorkspaceTabs({
1689
1717
  }
1690
1718
  ),
1691
1719
  scrollButton(1),
1720
+ metrics.overflow && /* @__PURE__ */ jsxs3("label", { className: "lab-tab-picker", title: "Switch tab", children: [
1721
+ /* @__PURE__ */ jsx4(ChevronDownIcon, { className: "lab-icon" }),
1722
+ /* @__PURE__ */ jsx4(
1723
+ "select",
1724
+ {
1725
+ "aria-label": "Switch tab",
1726
+ value: active,
1727
+ onChange: (event) => {
1728
+ onSelect(event.currentTarget.value);
1729
+ },
1730
+ children: links.map(([key2, label]) => /* @__PURE__ */ jsx4("option", { value: key2, children: label }, key2))
1731
+ }
1732
+ )
1733
+ ] }),
1692
1734
  /* @__PURE__ */ jsx4("span", { className: "lab-sr-only", "aria-live": "polite", children: announcement }),
1693
1735
  /* @__PURE__ */ jsxs3("span", { id: helpId, className: "lab-sr-only", children: [
1694
1736
  "Arrow keys switch tabs. Home and End select the first and last tab. Delete closes a tab. Alt plus Left or Right reorders. Alt plus Shift and Left, Right, or Down splits a pane. F6 moves between panes; Shift plus F6 moves back.",
@@ -2105,6 +2147,18 @@ function WorkspaceContent({
2105
2147
  const frontTab = tabsByKey.get(front ?? "");
2106
2148
  useBrowserHistory(history2 && frontTab ? historyOf(frontTab) : void 0);
2107
2149
  const dirty = useRef9(/* @__PURE__ */ new Map());
2150
+ const closingTabs = useRef9(false);
2151
+ const closeState = {
2152
+ tabsByKey,
2153
+ visibleLayout,
2154
+ front,
2155
+ onClose,
2156
+ confirmClose
2157
+ };
2158
+ const current = useRef9(closeState);
2159
+ useLayoutEffect8(() => {
2160
+ current.current = closeState;
2161
+ });
2108
2162
  useEffect5(() => {
2109
2163
  const warn = (event) => {
2110
2164
  if (dirty.current.size) event.preventDefault();
@@ -2112,31 +2166,57 @@ function WorkspaceContent({
2112
2166
  addEventListener("beforeunload", warn);
2113
2167
  return () => removeEventListener("beforeunload", warn);
2114
2168
  }, []);
2115
- function close(key2, next) {
2116
- const pane = panes(visibleLayout).find((p) => p.tabs.includes(key2));
2117
- if (!pane) return;
2118
- const remaining = pane.tabs.filter((k) => k !== key2);
2119
- const opener = tabsByKey.get(key2)?.opener;
2120
- const neighbor = next ?? remaining.find((key3) => key3 === opener) ?? remaining[Math.min(pane.tabs.indexOf(key2), remaining.length - 1)] ?? tabs.find((t) => t.key !== key2)?.key;
2121
- onClose(key2, neighbor);
2122
- requestAnimationFrame(
2123
- () => (links.get(
2124
- key2 === pane.active ? neighbor ?? "" : pane.active ?? ""
2125
- ) ?? root.current?.querySelector(
2126
- ".lab-toolbar-end button, [data-pane-sheet]"
2127
- ))?.focus({ preventScroll: true })
2128
- );
2129
- }
2130
2169
  function requestClose(key2, next) {
2131
- if (![...dirty.current.values()].includes(key2)) return close(key2, next);
2132
- const tab = tabsByKey.get(key2);
2133
- const element = links.get(key2);
2134
- Promise.resolve(
2135
- confirmClose ? confirmClose(tab) : confirm(`Discard changes in ${tab.label}?`)
2136
- ).then((discard) => {
2137
- if (discard) close(key2, next);
2138
- else requestAnimationFrame(() => element?.focus());
2139
- });
2170
+ void requestCloseTabs([key2], next);
2171
+ }
2172
+ async function requestCloseTabs(keys, next) {
2173
+ if (closingTabs.current) return;
2174
+ closingTabs.current = true;
2175
+ try {
2176
+ const closing = /* @__PURE__ */ new Set();
2177
+ let kept;
2178
+ for (const key2 of new Set(keys)) {
2179
+ const { tabsByKey: tabsByKey3, confirmClose: confirmClose2 } = current.current;
2180
+ const tab = tabsByKey3.get(key2);
2181
+ if (!tab) continue;
2182
+ if ([...dirty.current.values()].includes(key2)) {
2183
+ const discard = await (confirmClose2 ? confirmClose2(tab) : confirm(`Discard changes in ${tab.label}?`));
2184
+ if (!discard) {
2185
+ kept ??= key2;
2186
+ continue;
2187
+ }
2188
+ }
2189
+ closing.add(key2);
2190
+ }
2191
+ const { tabsByKey: tabsByKey2, visibleLayout: visibleLayout2, front: front2, onClose: onClose2 } = current.current;
2192
+ const remaining = [...tabsByKey2.keys()].filter(
2193
+ (key2) => !closing.has(key2)
2194
+ );
2195
+ const survives = (key2) => key2 !== void 0 && remaining.includes(key2);
2196
+ let focus = [kept, next, front2, remaining[0]].find(survives);
2197
+ const leaves = panes(visibleLayout2);
2198
+ for (const key2 of closing) {
2199
+ const pane = leaves.find((pane2) => pane2.tabs.includes(key2));
2200
+ if (!pane) continue;
2201
+ const index = pane.tabs.indexOf(key2);
2202
+ const neighbor = [
2203
+ next,
2204
+ tabsByKey2.get(key2)?.opener,
2205
+ ...pane.tabs.slice(index + 1),
2206
+ ...pane.tabs.slice(0, index).reverse(),
2207
+ remaining[0]
2208
+ ].find(survives);
2209
+ if (key2 === front2 && !kept && !survives(next)) focus = neighbor;
2210
+ onClose2(key2, neighbor);
2211
+ }
2212
+ requestAnimationFrame(
2213
+ () => (links.get(focus ?? "") ?? root.current?.querySelector(
2214
+ ".lab-toolbar-end button, [data-pane-sheet]"
2215
+ ))?.focus({ preventScroll: true })
2216
+ );
2217
+ } finally {
2218
+ closingTabs.current = false;
2219
+ }
2140
2220
  }
2141
2221
  function leave(key2) {
2142
2222
  const opener = openers.get(key2) ?? tabsByKey.get(key2)?.opener;
@@ -2232,6 +2312,8 @@ function WorkspaceContent({
2232
2312
  return copy;
2233
2313
  } : void 0,
2234
2314
  onClose: requestClose,
2315
+ onCloseTabs: requestCloseTabs,
2316
+ allTabs: tabs.map((tab) => tab.key),
2235
2317
  onReorder: (keys) => change(
2236
2318
  updateLayout(visibleLayout, pane.id, (node) => ({
2237
2319
  ...node,