@labpane/os 1.3.0 → 1.4.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
@@ -109,6 +109,41 @@ type Layout = Pane | Split;
109
109
 
110
110
  ## Desktop windows
111
111
 
112
+ ### Installed PWAs
113
+
114
+ Enable the browser's window-controls overlay in your web app manifest:
115
+
116
+ ```json
117
+ {
118
+ "display": "standalone",
119
+ "display_override": ["window-controls-overlay", "standalone"]
120
+ }
121
+ ```
122
+
123
+ Then opt your top-level workspace into the available title-bar area:
124
+
125
+ ```tsx
126
+ import { Workspace } from "@labpane/os";
127
+ import { useWindowControlsOverlay } from "@labpane/os/pwa";
128
+
129
+ function App() {
130
+ const overlay = useWindowControlsOverlay();
131
+ return <Workspace windowControlsOverlay={overlay} {...workspaceProps} />;
132
+ }
133
+ ```
134
+
135
+ The PWA browser integration is a separate entry point. Importing `Workspace` or using `@labpane/ui` alone does not include that module. Pass `false` to the hook to temporarily disable the integration; it then installs no observers or event listeners.
136
+
137
+ Place the workspace at the top of the viewport; remove any separate title-bar spacer. When the installed browser reports a visible overlay, Labpane places the top row of tabs inside its safe rectangle, leaving room for the browser's real window buttons on either side. Panel content keeps the full width. Geometry changes update the layout, and dense tabs get a minimum height sufficient to clear the native title bar. All pane headers share that minimum height while the overlay is active.
138
+
139
+ Set the app's manifest `theme_color` and document `<meta name="theme-color">` to the workspace background color. Update the meta value when the app changes theme so the browser's caption area matches. The generated starter reads `--lab-background` on theme changes; the library leaves document metadata to the application.
140
+
141
+ The blank toolbar area drags the window. Tabs, toolbar actions, and leading/trailing slots remain interactive. Mark a noninteractive leading element with `data-window-drag` if it should also drag; use `data-window-no-drag` for custom interactive content. Don't render `WindowControls` or supply a `WindowHost` for this path: the installed browser owns window actions and caption buttons.
142
+
143
+ Ordinary browser tabs, unsupported browsers, disabled overlays, and fullscreen use the normal layout. The browser controls whether the overlay is enabled; Chromium may require the user to choose **Hide title bar**. A workspace below the title-bar area is left alone. Installability, service workers, and the manifest remain application responsibilities. See the [browser platform documentation](https://learn.microsoft.com/en-us/microsoft-edge/progressive-web-apps/how-to/window-controls-overlay) and [PWA test fixture](../../e2e/consumer/README.md).
144
+
145
+ ### Native shells
146
+
112
147
  To run the workspace in a frameless desktop window (Wails, Tauri, Electron, or your own shell), describe the window as a `WindowHost` and the workspace becomes its title bar:
113
148
 
114
149
  ```tsx
@@ -144,6 +179,8 @@ function App() {
144
179
  - `useWindowFrame` moves the window when an empty part of a toolbar is dragged, maximises it on a double click, resizes it from its edges, and toggles full screen with F11, or Ctrl+Cmd+F on macOS. Add `data-window-drag` to other elements that should move the window.
145
180
  - `useFullscreen(host)` returns `[fullscreen, setFullscreen]`. Without a host it uses the browser's Fullscreen API.
146
181
 
182
+ The host interface has no Wails, Go, Tauri, or Electron dependency. Applications own their shell and adapt its public APIs to these callbacks. If the shell already handles dragging and edge resizing, omit `drag` and `resize` to avoid sending duplicate commands. The [native desktop fixture](../../e2e/wails/README.md) demonstrates this boundary and checks real window actions with Wails. Its shell is test code, not part of this package.
183
+
147
184
  ## Keyboard
148
185
 
149
186
  - Left and Right move between tabs, Home and End jump to the first and last, and Space selects
package/dist/index.js CHANGED
@@ -63,10 +63,15 @@ function densitySize(density) {
63
63
  );
64
64
  }
65
65
  var WorkspaceDensity = createContext(100);
66
+ var MinimumTabHeight = createContext(0);
66
67
  var fitTabWidth = (width, available, count) => Math.min(width, Math.max(128, (available - 16) / Math.max(1, count)));
67
68
  function useTabSize() {
68
69
  const density = useContext(WorkspaceDensity);
69
- return useMemo(() => densitySize(density), [density]);
70
+ const minimumHeight = useContext(MinimumTabHeight);
71
+ return useMemo(() => {
72
+ const size = densitySize(density);
73
+ return { ...size, height: Math.max(size.height, minimumHeight) };
74
+ }, [density, minimumHeight]);
70
75
  }
71
76
  function useWorkspaceIds() {
72
77
  const prefix = useContext(WorkspaceId);
@@ -334,7 +339,8 @@ function WorkspaceSurface({
334
339
  change,
335
340
  header,
336
341
  content,
337
- menu
342
+ menu,
343
+ titlebarArea
338
344
  }) {
339
345
  const ids = useWorkspaceIds();
340
346
  const {
@@ -541,31 +547,42 @@ function WorkspaceSurface({
541
547
  minHeight: required.y
542
548
  },
543
549
  children: [
544
- regions.map(({ pane, box }, index) => /* @__PURE__ */ jsx(
545
- "div",
546
- {
547
- "data-pane-header": pane.id,
548
- "data-top": box.y === 0 || void 0,
549
- className: "lab-pane-header",
550
- style: {
551
- ...position({ ...box, height: tabHeight }),
552
- transitionDuration: transition ? "var(--workspace-duration, 180ms)" : "0ms"
550
+ regions.map(({ pane, box }, index) => {
551
+ const overlay = titlebarArea && box.y < titlebarArea.height;
552
+ const left = overlay ? Math.max(box.x, titlebarArea.left) : box.x;
553
+ const right = overlay ? Math.min(box.x + box.width, titlebarArea.right) : box.x + box.width;
554
+ return /* @__PURE__ */ jsx(
555
+ "div",
556
+ {
557
+ "data-pane-header": pane.id,
558
+ "data-top": box.y === 0 || void 0,
559
+ className: "lab-pane-header",
560
+ "data-titlebar-overlay": overlay ? "" : void 0,
561
+ style: {
562
+ ...position({
563
+ ...box,
564
+ x: left,
565
+ width: Math.max(0, right - left),
566
+ height: tabHeight
567
+ }),
568
+ transitionDuration: transition && !overlay ? "var(--workspace-duration, 180ms)" : "0ms"
569
+ },
570
+ children: /* @__PURE__ */ jsx(
571
+ PaneHeader,
572
+ {
573
+ pane,
574
+ first: index === 0,
575
+ last: pane.id === topRight,
576
+ docking: stableDocking,
577
+ insertion: preview?.pane === pane.id ? preview.index : void 0,
578
+ board,
579
+ render: header
580
+ }
581
+ )
553
582
  },
554
- children: /* @__PURE__ */ jsx(
555
- PaneHeader,
556
- {
557
- pane,
558
- first: index === 0,
559
- last: pane.id === topRight,
560
- docking: stableDocking,
561
- insertion: preview?.pane === pane.id ? preview.index : void 0,
562
- board,
563
- render: header
564
- }
565
- )
566
- },
567
- pane.id
568
- )),
583
+ pane.id
584
+ );
585
+ }),
569
586
  content(regions, transition, lifted),
570
587
  dividers.map(({ split, bounds, ratio, low, high, ...box }) => {
571
588
  const axis = split.axis, horizontal = axis === "x", dimension = horizontal ? "width" : "height";
@@ -1056,6 +1073,7 @@ function WorkspaceTabs({
1056
1073
  if (element) element.inert = true;
1057
1074
  }, []);
1058
1075
  const frameRef = React.useRef(null);
1076
+ const frameLayer = dragBoundary?.closest(".lab-board");
1059
1077
  const maskedSheet = React.useRef(null);
1060
1078
  const maskedOutline = React.useRef(null);
1061
1079
  const restoreFrame = () => {
@@ -1676,18 +1694,21 @@ function WorkspaceTabs({
1676
1694
  "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.",
1677
1695
  menu && " Right-click or press Shift plus F10 for tab actions without dragging."
1678
1696
  ] }),
1679
- active && /* @__PURE__ */ jsx4(
1680
- "svg",
1681
- {
1682
- ref: frameRef,
1683
- "aria-hidden": "true",
1684
- "data-pane-frame": true,
1685
- viewBox: `0 0 ${width} ${height}`,
1686
- strokeWidth: size.borderWidth,
1687
- style: { width, height },
1688
- className: "lab-pane-frame",
1689
- children: /* @__PURE__ */ jsx4("path", { className: "lab-outline" })
1690
- }
1697
+ active && frameLayer && createPortal(
1698
+ /* @__PURE__ */ jsx4(
1699
+ "svg",
1700
+ {
1701
+ ref: frameRef,
1702
+ "aria-hidden": "true",
1703
+ "data-pane-frame": true,
1704
+ viewBox: `0 0 ${width} ${height}`,
1705
+ strokeWidth: size.borderWidth,
1706
+ style: { width, height },
1707
+ className: "lab-pane-frame",
1708
+ children: /* @__PURE__ */ jsx4("path", { className: "lab-outline" })
1709
+ }
1710
+ ),
1711
+ frameLayer
1691
1712
  ),
1692
1713
  dragging && createPortal(
1693
1714
  /* @__PURE__ */ jsxs3(
@@ -2025,6 +2046,7 @@ function WorkspaceContent({
2025
2046
  leading,
2026
2047
  trailing,
2027
2048
  titleBar,
2049
+ windowControlsOverlay,
2028
2050
  toolbar,
2029
2051
  menu,
2030
2052
  confirmClose,
@@ -2040,7 +2062,11 @@ function WorkspaceContent({
2040
2062
  () => new Map(tabs.map((tab) => [tab.key, tab])),
2041
2063
  [tabs]
2042
2064
  );
2043
- const { height, contentHeight, logoSize } = useTabSize();
2065
+ const {
2066
+ height: tabHeight,
2067
+ contentHeight,
2068
+ logoSize
2069
+ } = useMemo3(() => densitySize(density), [density]);
2044
2070
  const corner2 = useRef9(null);
2045
2071
  const [reserve, setReserve] = useState5(0);
2046
2072
  const hasTrailing = !!trailing;
@@ -2051,7 +2077,8 @@ function WorkspaceContent({
2051
2077
  observer2.observe(element);
2052
2078
  return () => observer2.disconnect();
2053
2079
  }, [hasTrailing]);
2054
- const root = useRef9(null);
2080
+ const ownRoot = useRef9(null);
2081
+ const root = windowControlsOverlay?.root ?? ownRoot;
2055
2082
  const [inset, setInset] = useState5(0);
2056
2083
  useLayoutEffect8(() => {
2057
2084
  if (!titleBar) return setInset(0);
@@ -2059,7 +2086,9 @@ function WorkspaceContent({
2059
2086
  measure();
2060
2087
  addEventListener("resize", measure);
2061
2088
  return () => removeEventListener("resize", measure);
2062
- }, [titleBar]);
2089
+ }, [titleBar, root]);
2090
+ const titlebarArea = windowControlsOverlay?.area;
2091
+ const height = Math.max(tabHeight, titlebarArea?.height ?? 0);
2063
2092
  const preferredPane = useRef9(void 0);
2064
2093
  const visibleLayout = reconcileLayout(
2065
2094
  layout,
@@ -2123,7 +2152,7 @@ function WorkspaceContent({
2123
2152
  active: pane.active,
2124
2153
  focus: links.focus
2125
2154
  });
2126
- return /* @__PURE__ */ jsx6(Fragment3, { children: /* @__PURE__ */ jsxs5(
2155
+ return /* @__PURE__ */ jsx6(MinimumTabHeight.Provider, { value: titlebarArea?.height ?? 0, children: /* @__PURE__ */ jsxs5(
2127
2156
  "div",
2128
2157
  {
2129
2158
  ref: root,
@@ -2131,6 +2160,7 @@ function WorkspaceContent({
2131
2160
  "aria-label": "Workspace",
2132
2161
  "data-density": density,
2133
2162
  "data-title-bar": titleBar || void 0,
2163
+ "data-window-controls-overlay": titlebarArea ? "" : void 0,
2134
2164
  style: {
2135
2165
  "--lab-tab-height": `${height}px`,
2136
2166
  "--lab-tab-content-height": `${contentHeight}px`,
@@ -2155,10 +2185,19 @@ function WorkspaceContent({
2155
2185
  selected[(index + (event.shiftKey ? selected.length - 1 : 1)) % selected.length]?.focus();
2156
2186
  },
2157
2187
  children: [
2158
- trailing && /* @__PURE__ */ jsx6("div", { ref: corner2, className: "lab-trailing", style: { height }, children: trailing }),
2188
+ trailing && /* @__PURE__ */ jsx6(
2189
+ "div",
2190
+ {
2191
+ ref: corner2,
2192
+ className: "lab-trailing",
2193
+ style: { height, right: titlebarArea?.insetRight },
2194
+ children: trailing
2195
+ }
2196
+ ),
2159
2197
  /* @__PURE__ */ jsx6(
2160
2198
  WorkspaceSurface,
2161
2199
  {
2200
+ titlebarArea,
2162
2201
  layout: visibleLayout,
2163
2202
  change,
2164
2203
  menu,