@bridgebrew/rail 0.0.2 → 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 +61 -31
  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;
@@ -456,12 +472,23 @@ function JoinDialog({
456
472
  );
457
473
  }
458
474
 
459
- /** A slug from a title: kebab-case, at most 40 characters (the kernel's rule). */
460
- const slugOf = (title: string) =>
461
- title
475
+ /** The letters NFKD leaves whole (no base letter and mark to split them into), spelled in plain Latin (plugins#217). */
476
+ const LETTERS: Record<string, string> = { ß: 'ss', æ: 'ae', œ: 'oe', ø: 'o', ł: 'l', đ: 'd', ð: 'd', þ: 'th', ı: 'i' };
477
+ /** `text` lowercase in plain Latin letters where it has them: those letters spelled out, then accents dropped
478
+ * (`Straße Łódź` → `strasse lodz`). */
479
+ const foldLetters = (text: string) =>
480
+ text
481
+ // ʼn first: NFKD splits it into an apostrophe and `n`, which would split the word.
482
+ .replace(/ʼn/g, 'n')
483
+ // NFKD before the rest: it reveals letters (`Ǽ` → `Æ` + accent, `𝐒` → `S`) the table and the lowercase then see.
462
484
  .normalize('NFKD')
463
- .replace(/[\u0300-\u036f]/g, '')
464
485
  .toLowerCase()
486
+ .replace(/[ßæœøłđðþı]/g, (letter) => LETTERS[letter] ?? letter)
487
+ .replace(/[\u0300-\u036f]/g, '');
488
+
489
+ /** A slug from a title: kebab-case, at most 40 characters (the kernel's rule). */
490
+ const slugOf = (title: string) =>
491
+ foldLetters(title)
465
492
  .replace(/[^a-z0-9]+/g, '-')
466
493
  .replace(/^-+|-+$/g, '')
467
494
  .slice(0, 40)
@@ -1307,10 +1334,12 @@ function Rail({
1307
1334
  onRestore={(key) => settle(window.bridgeDesktop?.restore(key))}
1308
1335
  />
1309
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. */}
1310
1340
  <div data-slot="rail-bottom" className="flex w-full flex-col items-center gap-2 empty:hidden">
1311
- {renderSlot('rail-bottom', {})}
1341
+ {renderSlot('rail-bottom', { tip: RailTip })}
1312
1342
  </div>
1313
- <Moved node={controls} divider="after" />
1314
1343
  {statusShown(status) && (
1315
1344
  <RailTip label={statusLabel[status]}>
1316
1345
  <a
@@ -1413,6 +1442,7 @@ function Rail({
1413
1442
  }
1414
1443
 
1415
1444
  export function apply(ctx: Context) {
1445
+ holdOverlay = ctx.shell.holdOverlay ?? railHold;
1416
1446
  const list = { kind: 'list', scope: 'root' } as const;
1417
1447
  // The rail's commands in the ⌘K palette (research-034), when the `commands` plugin is there (followed if it comes).
1418
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.2",
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.20261120.1"
39
+ "bridge": ">=0.0.1-nightly.20261124.1"
40
40
  }
41
41
  }