@labpane/os 1.0.0 → 1.2.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 +11 -12
- package/dist/index.js +474 -154
- package/dist/index.js.map +4 -4
- package/dist/os/browser-history.d.ts +6 -0
- package/dist/os/context.d.ts +6 -0
- package/dist/os/index.d.ts +5 -1
- package/dist/os/leave-tab.d.ts +4 -0
- package/dist/os/overlay.d.ts +1 -0
- package/dist/os/tab-history.d.ts +17 -0
- package/dist/os/tab-map.d.ts +2 -0
- package/dist/os/tab-state.d.ts +10 -0
- package/dist/os/window.d.ts +15 -0
- package/dist/os/workspace.d.ts +2 -0
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -67,6 +67,10 @@ 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
|
+
## Inside a tab
|
|
71
|
+
|
|
72
|
+
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.
|
|
73
|
+
|
|
70
74
|
## Slots
|
|
71
75
|
|
|
72
76
|
The workspace renders no menus or buttons of its own. You fill these slots with your own components, or with `@labpane/ui`:
|
|
@@ -108,12 +112,7 @@ type Layout = Pane | Split;
|
|
|
108
112
|
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:
|
|
109
113
|
|
|
110
114
|
```tsx
|
|
111
|
-
import {
|
|
112
|
-
WindowControls,
|
|
113
|
-
useFullscreen,
|
|
114
|
-
useWindowFrame,
|
|
115
|
-
type WindowHost,
|
|
116
|
-
} from "@labpane/os";
|
|
115
|
+
import { desktopSlots, useWindowFrame, type WindowHost } from "@labpane/os";
|
|
117
116
|
|
|
118
117
|
const host: WindowHost = {
|
|
119
118
|
platform: "windows", // or "macos" or "linux"
|
|
@@ -123,25 +122,25 @@ const host: WindowHost = {
|
|
|
123
122
|
drag: () => shell.startDrag(), // optional
|
|
124
123
|
resize: (edge) => shell.startResize(edge), // optional, for windows without a native frame
|
|
125
124
|
fullscreen: (on) => shell.setFullscreen(on), // optional
|
|
125
|
+
trafficLights: (center) => shell.setTrafficLights(center), // optional, macOS
|
|
126
126
|
};
|
|
127
127
|
|
|
128
128
|
function App() {
|
|
129
|
-
const [fullscreen] = useFullscreen(host);
|
|
130
129
|
useWindowFrame(host);
|
|
131
130
|
return (
|
|
132
131
|
<Workspace
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
!fullscreen && <div style={{ width: 72 }} />
|
|
136
|
-
}
|
|
137
|
-
trailing={<WindowControls host={host} />}
|
|
132
|
+
titleBar
|
|
133
|
+
{...desktopSlots(host, (align) => <AppMenu align={align} />)}
|
|
138
134
|
// ...
|
|
139
135
|
/>
|
|
140
136
|
);
|
|
141
137
|
}
|
|
142
138
|
```
|
|
143
139
|
|
|
140
|
+
- `desktopSlots(host, menu)` fills the workspace's `leading` and `trailing` slots for the platform: on macOS, room for the traffic lights first and the menu at the end; elsewhere, the menu first and the window buttons at the end. A function `menu` gets the side it lands on, `"start"` or `"end"`, so a dropdown can open inward. Without a host, the menu just leads.
|
|
144
141
|
- `WindowControls` are Windows-style minimise, maximise, and close buttons, flush in the window's top-right corner and reaching down to the top pane. They hide on macOS, which keeps its own traffic lights, and in full screen.
|
|
142
|
+
- `TrafficLights` keeps room for macOS's traffic lights at the start of the toolbar, and hides on other platforms and in full screen. If the host has `trafficLights`, it calls it with the centre of the title bar, in pixels from the top of the window, whenever that moves, so the shell can centre the buttons there.
|
|
143
|
+
- `titleBar` centres the top row's toolbar controls in the title bar, which runs from the top of the window to the top pane, the same as the window buttons. Without it they centre in the toolbar, below any space the page leaves above the workspace.
|
|
145
144
|
- `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.
|
|
146
145
|
- `useFullscreen(host)` returns `[fullscreen, setFullscreen]`. Without a host it uses the browser's Fullscreen API.
|
|
147
146
|
|