@bridgebrew/rail 0.0.3 → 0.0.4

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.
Files changed (2) hide show
  1. package/browser/browser.tsx +46 -27
  2. package/package.json +2 -2
@@ -113,48 +113,64 @@ function useDesktopState() {
113
113
  return state;
114
114
  }
115
115
 
116
- /** A remote page shows under this one (the desktop app's state): only then do the rail's popups need the window. */
116
+ /** The shell's one hold of the home page over a joined Bridge's page (`ctx.shell.holdOverlay`, research-128 §7), set
117
+ * by `apply`: every popup and window of every plugin counts in it, so one closing never gives the window back while
118
+ * another is open. An older shell has none: the rail's own count (`railHold`). */
119
+ let holdOverlay: NonNullable<Context['shell']['holdOverlay']> | undefined;
120
+ /** A remote page shows under this one (the desktop app's state): only then does `railHold` need the window. */
117
121
  let remoteShown = false;
118
- /** The rail's popups open over a remote page: the app is told the absolute state on each change (the home view covers
119
- * the window while any is open, the rail's rectangle again as soon as none is). */
120
- let raised = 0;
121
- let rising: Promise<unknown> = Promise.resolve();
122
- const raise = (desktop: NonNullable<Window['bridgeDesktop']>) => {
123
- raised++;
124
- rising = desktop.overlay(raised > 0);
125
- // The popup paints one frame after the view grew.
126
- return rising.then(() => new Promise((done) => requestAnimationFrame(done)));
127
- };
128
- const lower = (desktop: NonNullable<Window['bridgeDesktop']>) => {
129
- raised = Math.max(0, raised - 1);
130
- void desktop.overlay(raised > 0);
131
- };
122
+ /** The rail's own count, with a shell from before research-128 §7: the home view covers the window while any of the
123
+ * rail's popups is open over a remote page. */
124
+ const railHold = (() => {
125
+ let count = 0;
126
+ return (): ReturnType<NonNullable<typeof holdOverlay>> => {
127
+ const desktop = window.bridgeDesktop;
128
+ if (!desktop || !remoteShown) return Object.assign(() => {}, { ready: Promise.resolve() });
129
+ count++;
130
+ // The popup paints one frame after the view grew; a refused request opens it anyway.
131
+ const ready = desktop
132
+ .overlay(true)
133
+ .then(
134
+ () => new Promise<void>((done) => requestAnimationFrame(() => done())),
135
+ () => {},
136
+ );
137
+ let released = false;
138
+ const release = () => {
139
+ if (released) return;
140
+ released = true;
141
+ count = Math.max(0, count - 1);
142
+ if (count === 0) void desktop.overlay(false).catch(() => {});
143
+ };
144
+ return Object.assign(release, { ready });
145
+ };
146
+ })();
132
147
 
133
- /** A popup's open state, gated over a remote page in the desktop app: it opens once the app made room for it. */
148
+ /** A popup's open state, held in the shell's count while open: over a remote page in the desktop app, it opens once
149
+ * the app made room for it. `initial`: a dialog, open from the start, a modal hold (the home page focused). */
134
150
  function useLayer(initial = false) {
135
151
  const [open, setOpen] = React.useState(false);
136
152
  const wanted = React.useRef(false);
137
- const held = React.useRef(false);
153
+ const release = React.useRef<(() => void) | undefined>(undefined);
138
154
  const change = React.useCallback((next: boolean) => {
139
155
  wanted.current = next;
140
- const desktop = window.bridgeDesktop;
141
156
  if (!next) {
142
157
  setOpen(false);
143
- if (held.current && desktop) lower(desktop);
144
- held.current = false;
158
+ release.current?.();
159
+ release.current = undefined;
145
160
  return;
146
161
  }
147
- if (held.current || !desktop || !remoteShown) return setOpen(true);
148
- held.current = true;
149
- void raise(desktop).then(() => {
162
+ if (release.current || !holdOverlay) return setOpen(true);
163
+ const held = holdOverlay(initial ? { modal: true } : {});
164
+ release.current = held;
165
+ void held.ready.then(() => {
150
166
  if (wanted.current) setOpen(true);
151
167
  });
152
168
  }, []);
153
169
  React.useEffect(() => {
154
170
  if (initial) change(true);
155
171
  return () => {
156
- if (held.current && window.bridgeDesktop) lower(window.bridgeDesktop);
157
- held.current = false;
172
+ release.current?.();
173
+ release.current = undefined;
158
174
  };
159
175
  }, []);
160
176
  return [open, change] as const;
@@ -1318,10 +1334,12 @@ function Rail({
1318
1334
  onRestore={(key) => settle(window.bridgeDesktop?.restore(key))}
1319
1335
  />
1320
1336
  <span className="flex-1" />
1337
+ <Moved node={controls} divider="after" />
1338
+ {/* Plugins' icons at the bottom (research-128 §7): after the divider of the sidebar's moved controls, with
1339
+ Bridge's own controls, named by the rail's tooltip as their neighbours. */}
1321
1340
  <div data-slot="rail-bottom" className="flex w-full flex-col items-center gap-2 empty:hidden">
1322
- {renderSlot('rail-bottom', {})}
1341
+ {renderSlot('rail-bottom', { tip: RailTip })}
1323
1342
  </div>
1324
- <Moved node={controls} divider="after" />
1325
1343
  {statusShown(status) && (
1326
1344
  <RailTip label={statusLabel[status]}>
1327
1345
  <a
@@ -1424,6 +1442,7 @@ function Rail({
1424
1442
  }
1425
1443
 
1426
1444
  export function apply(ctx: Context) {
1445
+ holdOverlay = ctx.shell.holdOverlay ?? railHold;
1427
1446
  const list = { kind: 'list', scope: 'root' } as const;
1428
1447
  // The rail's commands in the ⌘K palette (research-034), when the `commands` plugin is there (followed if it comes).
1429
1448
  const ask = (dialog: 'create' | 'join') => () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bridgebrew/rail",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "license": "MIT",
5
5
  "description": "The column of workspace tiles, with the Bridge button and its status dot.",
6
6
  "keywords": [
@@ -36,6 +36,6 @@
36
36
  "typecheck": "bridge plugin check ."
37
37
  },
38
38
  "engines": {
39
- "bridge": ">=0.0.1-nightly.20261123.1"
39
+ "bridge": ">=0.0.1-nightly.20261124.1"
40
40
  }
41
41
  }