@bridgebrew/shell 0.0.4 → 0.0.7
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/browser/browser.tsx +55 -7
- package/browser/errors.tsx +4 -1
- package/browser/mobile.tsx +79 -12
- package/browser/notifications.ts +4 -0
- package/browser/overlay-hold.ts +162 -0
- package/browser/shell-state.ts +2 -0
- package/browser/shell.d.ts +46 -5
- package/package.json +2 -2
package/browser/browser.tsx
CHANGED
|
@@ -142,12 +142,17 @@ import {
|
|
|
142
142
|
import { SidebarToggle, ThemeControls, type ManagerOption } from './theme-controls.tsx';
|
|
143
143
|
import {
|
|
144
144
|
MobileFrame,
|
|
145
|
+
clearMobileHolds,
|
|
146
|
+
isMobile,
|
|
147
|
+
markMore,
|
|
145
148
|
mobileFrame,
|
|
146
149
|
mobileOwner,
|
|
150
|
+
overlayOnPhone,
|
|
147
151
|
setSidebarItems,
|
|
148
152
|
transitions,
|
|
149
153
|
useMobile,
|
|
150
154
|
} from './mobile.tsx';
|
|
155
|
+
import { createOverlayHold, type OverlayHold } from './overlay-hold.ts';
|
|
151
156
|
|
|
152
157
|
export const name = 'shell';
|
|
153
158
|
export const inject = ['slots', 'workspaceEntries', 'hostStatus', 'screenRequests', 'sidebarItems'];
|
|
@@ -1095,6 +1100,35 @@ function Notifications({
|
|
|
1095
1100
|
|
|
1096
1101
|
/** The installed window managers for the theme menu (WM5): every `stage` entry's plugin, the default (the slot's head)
|
|
1097
1102
|
* first; any can be chosen (CAP-6). */
|
|
1103
|
+
/** `overlay`'s entries, each drawn apart: over a joined Bridge's page (`over`), hidden (kept mounted), where they would
|
|
1104
|
+
* cover the rail, but the ones holding the home page in front (`holdOverlay({ id })`), whose window shows there. */
|
|
1105
|
+
export function OverlayEntries({
|
|
1106
|
+
slots,
|
|
1107
|
+
overlays,
|
|
1108
|
+
over,
|
|
1109
|
+
renderSlot,
|
|
1110
|
+
}: {
|
|
1111
|
+
slots: Pick<Context['slots'], 'subscribe' | 'entriesOfSlot'>;
|
|
1112
|
+
overlays: Pick<OverlayHold, 'subscribe' | 'entries'>;
|
|
1113
|
+
over: boolean;
|
|
1114
|
+
renderSlot: (key: 'overlay', props: object, options: { only: string }) => React.ReactNode;
|
|
1115
|
+
}) {
|
|
1116
|
+
const joined = React.useSyncExternalStore(
|
|
1117
|
+
React.useCallback((changed: () => void) => slots.subscribe('overlay', changed), [slots]),
|
|
1118
|
+
() => [...new Set(slots.entriesOfSlot('overlay').map((entry) => entry.options.id ?? ''))].join('\n'),
|
|
1119
|
+
);
|
|
1120
|
+
const held = React.useSyncExternalStore(overlays.subscribe, overlays.entries);
|
|
1121
|
+
return (
|
|
1122
|
+
<div data-slot="shell-overlay" className="contents">
|
|
1123
|
+
{(joined ? joined.split('\n') : []).map((id) => (
|
|
1124
|
+
<div key={id} data-overlay-entry={id} className={over && !held.includes(id) ? 'hidden' : 'contents'}>
|
|
1125
|
+
{renderSlot('overlay', {}, { only: id })}
|
|
1126
|
+
</div>
|
|
1127
|
+
))}
|
|
1128
|
+
</div>
|
|
1129
|
+
);
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1098
1132
|
function useManagers(slots: Context['slots']): ManagerOption[] {
|
|
1099
1133
|
const read = React.useCallback(
|
|
1100
1134
|
() => JSON.stringify(liveStages(slots).map((entry) => entry.registrant ?? null)),
|
|
@@ -1279,7 +1313,9 @@ function Frame({
|
|
|
1279
1313
|
renderSlot,
|
|
1280
1314
|
commands,
|
|
1281
1315
|
themeMenu,
|
|
1316
|
+
overlays,
|
|
1282
1317
|
}: {
|
|
1318
|
+
overlays: OverlayHold;
|
|
1283
1319
|
shell: Shell;
|
|
1284
1320
|
slots: Context['slots'];
|
|
1285
1321
|
hostStatus: Context['hostStatus'];
|
|
@@ -1290,8 +1326,9 @@ function Frame({
|
|
|
1290
1326
|
app: boolean;
|
|
1291
1327
|
errors: ErrorsSignal;
|
|
1292
1328
|
renderSlot: (
|
|
1293
|
-
key: 'rail' | 'sidebar' | 'main' | 'overlay' | 'controls',
|
|
1329
|
+
key: 'rail' | 'sidebar' | 'main' | 'overlay' | 'controls' | 'more',
|
|
1294
1330
|
props: object,
|
|
1331
|
+
options?: { only?: string },
|
|
1295
1332
|
) => React.ReactNode;
|
|
1296
1333
|
commands: CommandsService;
|
|
1297
1334
|
}) {
|
|
@@ -1591,11 +1628,8 @@ function Frame({
|
|
|
1591
1628
|
)}
|
|
1592
1629
|
</div>
|
|
1593
1630
|
</div>
|
|
1594
|
-
{/* Over the whole frame: floating tools (`point`'s selections and windows), each positioned by its plugin
|
|
1595
|
-
|
|
1596
|
-
<div data-slot="shell-overlay" className={over ? 'hidden' : 'contents'}>
|
|
1597
|
-
{renderSlot('overlay', {})}
|
|
1598
|
-
</div>
|
|
1631
|
+
{/* Over the whole frame: floating tools (`point`'s selections and windows), each positioned by its plugin. */}
|
|
1632
|
+
<OverlayEntries slots={slots} overlays={overlays} over={over} renderSlot={renderSlot} />
|
|
1599
1633
|
<ShortcutsHelp shell={shell} help={help} app={app} />
|
|
1600
1634
|
<ErrorsModal
|
|
1601
1635
|
hostStatus={hostStatus}
|
|
@@ -1858,7 +1892,19 @@ export function apply(ctx: Context) {
|
|
|
1858
1892
|
() => setCurrent(slug),
|
|
1859
1893
|
);
|
|
1860
1894
|
};
|
|
1861
|
-
|
|
1895
|
+
// One count for every popup and window over a joined Bridge's page, the phone's opted-in overlays, More's marks
|
|
1896
|
+
// (research-128 §7).
|
|
1897
|
+
const overlays = createOverlayHold();
|
|
1898
|
+
ctx.effect(() => () => {
|
|
1899
|
+
overlays.dispose();
|
|
1900
|
+
clearMobileHolds();
|
|
1901
|
+
});
|
|
1902
|
+
ctx.provide(
|
|
1903
|
+
'shell',
|
|
1904
|
+
Object.defineProperties(Object.assign(shell, { holdOverlay: overlays.hold, overlayOnPhone, markMore }), {
|
|
1905
|
+
mobile: { get: isMobile, enumerable: true },
|
|
1906
|
+
}),
|
|
1907
|
+
);
|
|
1862
1908
|
// What this page has changes (a pack, an icon set, a window manager comes or goes): the looks again, the user's look
|
|
1863
1909
|
// everywhere applying where it now can (research-035).
|
|
1864
1910
|
ctx.effect(() => {
|
|
@@ -2030,6 +2076,7 @@ export function apply(ctx: Context) {
|
|
|
2030
2076
|
sidebar: { ...slot, ...open },
|
|
2031
2077
|
main: slot,
|
|
2032
2078
|
overlay: { kind: 'list', scope: 'root' },
|
|
2079
|
+
more: { kind: 'list', scope: 'root' },
|
|
2033
2080
|
controls: { kind: 'list', scope: 'root', ...open },
|
|
2034
2081
|
},
|
|
2035
2082
|
},
|
|
@@ -2050,6 +2097,7 @@ export function apply(ctx: Context) {
|
|
|
2050
2097
|
renderSlot={renderSlot}
|
|
2051
2098
|
commands={commands}
|
|
2052
2099
|
themeMenu={themeMenu}
|
|
2100
|
+
overlays={overlays}
|
|
2053
2101
|
/>
|
|
2054
2102
|
</PackThemesProvider>
|
|
2055
2103
|
),
|
package/browser/errors.tsx
CHANGED
|
@@ -596,7 +596,10 @@ export function ErrorsModal({
|
|
|
596
596
|
React.useEffect(() => {
|
|
597
597
|
if (!open) return;
|
|
598
598
|
load();
|
|
599
|
-
|
|
599
|
+
// Bridge's update (bridge#677) is no error, and comes at each percent of a download.
|
|
600
|
+
return hostStatus.subscribe((event) => {
|
|
601
|
+
if (String(event.event) !== 'update') load();
|
|
602
|
+
});
|
|
600
603
|
}, [open, hostStatus, load]);
|
|
601
604
|
|
|
602
605
|
// Opening with a key: scroll that item into view and outline it briefly.
|
package/browser/mobile.tsx
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
subscribeClientAppearance,
|
|
26
26
|
} from '@bridge/ui';
|
|
27
27
|
import { modeColour, tileColourOf, tileShapeStyles } from '@bridge/kernel/look';
|
|
28
|
+
import { heldIds } from './overlay-hold.ts';
|
|
28
29
|
import { blocksOn, pathTo, viewOf, type Shell, type View } from './shell-state.ts';
|
|
29
30
|
import './mobile.css';
|
|
30
31
|
|
|
@@ -79,6 +80,9 @@ export function drawerState(
|
|
|
79
80
|
let open = false;
|
|
80
81
|
let marker = 0;
|
|
81
82
|
let after: (() => void) | undefined;
|
|
83
|
+
/** Going back off the drawer's entry (`history.back()` answers later, with `popstate`): a second close or stay
|
|
84
|
+
* meanwhile would go back a second time, past the screen; it is dropped, the first one's action kept. */
|
|
85
|
+
let leaving = false;
|
|
82
86
|
// `stay`: the drawer kept open past its entry gone back off, with no entry of its own (`marker` 0) from there: the
|
|
83
87
|
// shell writes the history of the workspace it opens (its last screen, in place or as a new entry), over which an
|
|
84
88
|
// entry of the drawer's would be lost; Back then goes on under it, and the drawer closes by its own controls.
|
|
@@ -95,6 +99,7 @@ export function drawerState(
|
|
|
95
99
|
(history.state as Record<string, unknown> | null)?.[key] === marker
|
|
96
100
|
)
|
|
97
101
|
return;
|
|
102
|
+
leaving = false;
|
|
98
103
|
if (keep) {
|
|
99
104
|
keep = false;
|
|
100
105
|
const then = after;
|
|
@@ -123,8 +128,10 @@ export function drawerState(
|
|
|
123
128
|
close(then?: () => void): void {
|
|
124
129
|
if (above?.get()) return above.close(() => state.close(then));
|
|
125
130
|
if (!open) return then?.();
|
|
131
|
+
if (leaving) return;
|
|
126
132
|
if ((history.state as Record<string, unknown> | null)?.[key] === marker) {
|
|
127
133
|
after = then;
|
|
134
|
+
leaving = true;
|
|
128
135
|
history.back();
|
|
129
136
|
return;
|
|
130
137
|
}
|
|
@@ -137,8 +144,10 @@ export function drawerState(
|
|
|
137
144
|
if (above?.get()) return above.close(() => state.stay(then));
|
|
138
145
|
if (!open || (history.state as Record<string, unknown> | null)?.[key] !== marker)
|
|
139
146
|
return then();
|
|
147
|
+
if (leaving) return;
|
|
140
148
|
keep = true;
|
|
141
149
|
after = then;
|
|
150
|
+
leaving = true;
|
|
142
151
|
history.back();
|
|
143
152
|
},
|
|
144
153
|
subscribe(listener: () => void) {
|
|
@@ -599,15 +608,7 @@ function BottomBar({ shell, primary }: { shell: Shell; primary: MobileAction | u
|
|
|
599
608
|
</button>
|
|
600
609
|
);
|
|
601
610
|
})}
|
|
602
|
-
<
|
|
603
|
-
type="button"
|
|
604
|
-
aria-label="More"
|
|
605
|
-
onClick={() => drawer.open()}
|
|
606
|
-
className="mobile-press mobile-tab flex h-[52px] min-w-0 flex-1 flex-col items-center justify-center gap-0.5 rounded-full"
|
|
607
|
-
>
|
|
608
|
-
<Icon name="ellipsis" size={22} />
|
|
609
|
-
<span className="text-[10px] font-medium">More</span>
|
|
610
|
-
</button>
|
|
611
|
+
<MoreTab />
|
|
611
612
|
</nav>
|
|
612
613
|
{primary && (
|
|
613
614
|
<GlassButton
|
|
@@ -623,6 +624,47 @@ function BottomBar({ shell, primary }: { shell: Shell; primary: MobileAction | u
|
|
|
623
624
|
);
|
|
624
625
|
}
|
|
625
626
|
|
|
627
|
+
/** The plugins asking for attention on More (`ctx.shell.markMore`): its dot shows while any holds a mark. */
|
|
628
|
+
const moreMarks = heldIds();
|
|
629
|
+
/** Marks More for attention (research-128 §7): the dot on its tab while held; returns the release. */
|
|
630
|
+
export const markMore = (id: string) => moreMarks.hold(id);
|
|
631
|
+
/** The `overlay` entries drawn on a phone too (`ctx.shell.overlayOnPhone`), by their id: none by default. */
|
|
632
|
+
const phoneOverlays = heldIds();
|
|
633
|
+
/** Opts entry `id` of `overlay` in on a phone (research-128 §7): drawn there, outside the shell's frame, while held;
|
|
634
|
+
* returns the release. */
|
|
635
|
+
export const overlayOnPhone = (id: string) => phoneOverlays.hold(id);
|
|
636
|
+
/** The shell is disposed: every mark and phone overlay dropped (a plugin outliving it holds nothing). */
|
|
637
|
+
export const clearMobileHolds = () => {
|
|
638
|
+
moreMarks.clear();
|
|
639
|
+
phoneOverlays.clear();
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
/** "More", with a dot while a plugin marks it for attention (`ctx.shell.markMore`: Bridge's update, research-128). */
|
|
643
|
+
function MoreTab() {
|
|
644
|
+
const marks = React.useSyncExternalStore(moreMarks.subscribe, moreMarks.get);
|
|
645
|
+
const dot = marks.length > 0;
|
|
646
|
+
return (
|
|
647
|
+
<button
|
|
648
|
+
type="button"
|
|
649
|
+
aria-label={dot ? 'More, something needs your attention' : 'More'}
|
|
650
|
+
onClick={() => drawer.open()}
|
|
651
|
+
className="mobile-press mobile-tab flex h-[52px] min-w-0 flex-1 flex-col items-center justify-center gap-0.5 rounded-full"
|
|
652
|
+
>
|
|
653
|
+
<span className="relative flex">
|
|
654
|
+
<Icon name="ellipsis" size={22} />
|
|
655
|
+
{dot && (
|
|
656
|
+
// A plugin's mark: the kit's red, as the rail's update dot (the owner's choice, seen at a glance).
|
|
657
|
+
<span
|
|
658
|
+
data-slot="more-dot"
|
|
659
|
+
className="absolute -top-0.5 -right-1.5 size-2 rounded-full bg-destructive ring-2 ring-background"
|
|
660
|
+
/>
|
|
661
|
+
)}
|
|
662
|
+
</span>
|
|
663
|
+
<span className="text-[10px] font-medium">More</span>
|
|
664
|
+
</button>
|
|
665
|
+
);
|
|
666
|
+
}
|
|
667
|
+
|
|
626
668
|
/** A desktop view's title: its screen's (its items' own names, as `plugin:sessions/en/index`, mean nothing here). */
|
|
627
669
|
const desktopTitle = (shell: Shell, view: View) => {
|
|
628
670
|
const { screen } = view;
|
|
@@ -693,6 +735,7 @@ let sidebarItems: Context['sidebarItems'] = {
|
|
|
693
735
|
export const setSidebarItems = (service: Context['sidebarItems']) => {
|
|
694
736
|
sidebarItems = service;
|
|
695
737
|
};
|
|
738
|
+
|
|
696
739
|
function useSidebarItems() {
|
|
697
740
|
React.useSyncExternalStore(sidebarItems.subscribe, sidebarItems.get);
|
|
698
741
|
React.useSyncExternalStore(sidebarItems.navigation.subscribe, sidebarItems.navigation.get);
|
|
@@ -995,9 +1038,11 @@ export function MobileFrame({
|
|
|
995
1038
|
renderSlot,
|
|
996
1039
|
}: {
|
|
997
1040
|
shell: Shell;
|
|
998
|
-
|
|
1041
|
+
/** The frame's slots: `main`, the drawer's `more` rows, and `overlay` (its entries opted in on a phone only). */
|
|
1042
|
+
renderSlot: (key: 'main' | 'more' | 'overlay', props: object, options?: { only?: string }) => React.ReactNode;
|
|
999
1043
|
}) {
|
|
1000
1044
|
const open = React.useSyncExternalStore(drawer.subscribe, drawer.get);
|
|
1045
|
+
const overlays = React.useSyncExternalStore(phoneOverlays.subscribe, phoneOverlays.get);
|
|
1001
1046
|
const style = React.useSyncExternalStore(menuStyle.subscribe, menuStyle.get);
|
|
1002
1047
|
const { current, workspaces } = React.useSyncExternalStore(shell.subscribe, shell.get);
|
|
1003
1048
|
const mode = React.useSyncExternalStore(
|
|
@@ -1043,6 +1088,7 @@ export function MobileFrame({
|
|
|
1043
1088
|
}
|
|
1044
1089
|
}, [slug, workspaces.length]);
|
|
1045
1090
|
return (
|
|
1091
|
+
<>
|
|
1046
1092
|
<div
|
|
1047
1093
|
data-slot="shell"
|
|
1048
1094
|
data-mobile=""
|
|
@@ -1063,13 +1109,23 @@ export function MobileFrame({
|
|
|
1063
1109
|
: 'mobile-drawer top-0 left-0 h-full max-h-none w-full max-w-none translate-x-0 translate-y-0 rounded-none pt-[env(safe-area-inset-top)] pb-[env(safe-area-inset-bottom)] pr-[env(safe-area-inset-right)] pl-[env(safe-area-inset-left)] transition-transform duration-300 ease-out data-[ending-style]:-translate-x-full data-[starting-style]:-translate-x-full'
|
|
1064
1110
|
}
|
|
1065
1111
|
>
|
|
1066
|
-
<Menu shell={shell} style={style} />
|
|
1112
|
+
<Menu shell={shell} style={style} renderSlot={renderSlot} />
|
|
1067
1113
|
{/* Inside the drawer: dialogs of their own, nested, so a tap in them does not close the drawer. */}
|
|
1068
1114
|
{style === 'tree' && <WorkspaceSheet shell={shell} />}
|
|
1069
1115
|
<PhoneSettings textSize={textSize} mode={mode} style={style} />
|
|
1070
1116
|
</DialogContent>
|
|
1071
1117
|
</Dialog>
|
|
1072
1118
|
</div>
|
|
1119
|
+
{/* The `overlay` entries that opted in on a phone, outside the frame (a window over everything); none by default:
|
|
1120
|
+
the desktop's floating tools (a dock, a palette) stay off a phone. */}
|
|
1121
|
+
{overlays.length > 0 && (
|
|
1122
|
+
<div data-slot="shell-overlay">
|
|
1123
|
+
{overlays.map((id) => (
|
|
1124
|
+
<React.Fragment key={id}>{renderSlot('overlay', {}, { only: id })}</React.Fragment>
|
|
1125
|
+
))}
|
|
1126
|
+
</div>
|
|
1127
|
+
)}
|
|
1128
|
+
</>
|
|
1073
1129
|
);
|
|
1074
1130
|
}
|
|
1075
1131
|
|
|
@@ -1104,7 +1160,15 @@ type Page = { node: string } | { entry: Entry };
|
|
|
1104
1160
|
/** The drawer's content: with `pages`, a page (a node's views, then its child nodes; a view's rows under it), each
|
|
1105
1161
|
* row with rows under it opening its own page in the drawer, Back going up one; with `tree`, the node's views as a
|
|
1106
1162
|
* tree and a row opening the tree's page. The workspaces. It opens on the node shown. */
|
|
1107
|
-
function Menu({
|
|
1163
|
+
function Menu({
|
|
1164
|
+
shell,
|
|
1165
|
+
style,
|
|
1166
|
+
renderSlot,
|
|
1167
|
+
}: {
|
|
1168
|
+
shell: Shell;
|
|
1169
|
+
style: MenuStyle;
|
|
1170
|
+
renderSlot: (key: 'more', props: { style: MenuStyle; close: (then?: () => void) => void }) => React.ReactNode;
|
|
1171
|
+
}) {
|
|
1108
1172
|
const state = React.useSyncExternalStore(shell.subscribe, shell.get);
|
|
1109
1173
|
useSidebarItems();
|
|
1110
1174
|
const { current, nodes } = state;
|
|
@@ -1242,6 +1306,9 @@ function Menu({ shell, style }: { shell: Shell; style: MenuStyle }) {
|
|
|
1242
1306
|
push={(next) => push({ entry: next })}
|
|
1243
1307
|
/>
|
|
1244
1308
|
)}
|
|
1309
|
+
{/* Rows plugins add (`more`, research-128 §7), after More's own: the menu's style, so a row is drawn as its
|
|
1310
|
+
neighbours, and `close`, which closes the drawer and runs `then` after (as a row of the menu does). */}
|
|
1311
|
+
{!back && renderSlot('more', { style, close: (then?: () => void) => drawer.close(then) })}
|
|
1245
1312
|
{style === 'pages' && kids.length > 0 && (
|
|
1246
1313
|
<nav aria-label="Nodes" className="flex flex-col px-2 pb-2">
|
|
1247
1314
|
<h2 className="m-0 px-2 pt-3 pb-1 text-xs font-medium tracking-wide text-secondary uppercase">
|
package/browser/notifications.ts
CHANGED
|
@@ -1061,6 +1061,8 @@ export function notifier(
|
|
|
1061
1061
|
renderCauses();
|
|
1062
1062
|
return;
|
|
1063
1063
|
}
|
|
1064
|
+
// A Bridge-wide event (Bridge's update, bridge#677) is no plugin's: the update screens show it.
|
|
1065
|
+
if (!('slug' in event.data)) return;
|
|
1064
1066
|
const { slug, id } = event.data;
|
|
1065
1067
|
const key = pluginKey(slug, id);
|
|
1066
1068
|
const workspace = titles.get(slug) ?? slug;
|
|
@@ -1138,6 +1140,8 @@ export function notifier(
|
|
|
1138
1140
|
);
|
|
1139
1141
|
};
|
|
1140
1142
|
return (raw: HostStatusEvent) => {
|
|
1143
|
+
// Bridge's update (bridge#677) comes at each percent of a download: nothing here to render again.
|
|
1144
|
+
if (String(raw.event) === 'update') return;
|
|
1141
1145
|
listen(raw);
|
|
1142
1146
|
noteStarted(namedEvent(raw));
|
|
1143
1147
|
renderAttentions();
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// One count for every popup and window of the home page (research-128 §7), whichever plugin opens it: while any is
|
|
2
|
+
// open over a joined Bridge's page, the desktop app keeps the home page in front (`bridgeDesktop.overlay(true)`), and
|
|
3
|
+
// the last one closing gives the window back (`overlay(false)`). Each plugin used to count its own: a tooltip closing
|
|
4
|
+
// while a window of another was open gave the window back too early. `ctx.shell.holdOverlay` is this.
|
|
5
|
+
import type { BridgeDesktop } from './shell.d.ts';
|
|
6
|
+
|
|
7
|
+
type DesktopState = { shown: unknown; overlay?: boolean };
|
|
8
|
+
/** What the hold reads of the desktop app: its overlay, and whether a joined page shows. */
|
|
9
|
+
type Desktop = {
|
|
10
|
+
overlay: BridgeDesktop['overlay'];
|
|
11
|
+
state(): Promise<DesktopState>;
|
|
12
|
+
onState(listener: (state: DesktopState) => void): () => void;
|
|
13
|
+
};
|
|
14
|
+
/** A hold: call it to release (once; later calls do nothing). `ready` resolves once the home page is in front (at once
|
|
15
|
+
* when no joined page shows, and after `waitMs` at most when the app does not answer), so a popup opens over the
|
|
16
|
+
* remote page, not under it. */
|
|
17
|
+
export type OverlayRelease = (() => void) & { readonly ready: Promise<void> };
|
|
18
|
+
export type OverlayHoldOptions = {
|
|
19
|
+
/** A dialog or window (not a tooltip or a menu): it takes the keyboard, the home page is focused. */
|
|
20
|
+
modal?: boolean;
|
|
21
|
+
/** The `overlay` slot entry the popup draws in: over a joined page, that entry alone shows while held. */
|
|
22
|
+
id?: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export function createOverlayHold(
|
|
26
|
+
desktop: () => Desktop | undefined = () => window.bridgeDesktop,
|
|
27
|
+
{ waitMs = 300 }: { waitMs?: number } = {},
|
|
28
|
+
) {
|
|
29
|
+
let count = 0;
|
|
30
|
+
/** A joined Bridge's page shows under the home page (the app's state). */
|
|
31
|
+
let shown = false;
|
|
32
|
+
/** The app was told the home page is in front. */
|
|
33
|
+
let sent = false;
|
|
34
|
+
/** The last overlay request: a hold while it runs waits for it. */
|
|
35
|
+
let request: Promise<void> = Promise.resolve();
|
|
36
|
+
/** The app's state came through `onState`: the first `state()` read, answering later, is stale. */
|
|
37
|
+
let followed = false;
|
|
38
|
+
/** The first `state()` read answered (or failed). */
|
|
39
|
+
let settled = false;
|
|
40
|
+
/** The release that left no hold waits a tick: a hold taken in the same interaction keeps the home page in front. */
|
|
41
|
+
let lowering: ReturnType<typeof setTimeout> | undefined;
|
|
42
|
+
const held = heldIds();
|
|
43
|
+
const app = desktop();
|
|
44
|
+
|
|
45
|
+
const send = (open: boolean, focus = false): Promise<void> => {
|
|
46
|
+
if (!app || (open === sent && !focus)) return request;
|
|
47
|
+
sent = open;
|
|
48
|
+
request = app.overlay(open, ...(focus ? [{ focus: true }] : [])).then(
|
|
49
|
+
() => undefined,
|
|
50
|
+
// Refused (the app is closing, an older app): the popup opens anyway, the next hold asks again.
|
|
51
|
+
() => {
|
|
52
|
+
if (sent === open) sent = !open;
|
|
53
|
+
},
|
|
54
|
+
);
|
|
55
|
+
return request;
|
|
56
|
+
};
|
|
57
|
+
const follow = (state: DesktopState) => {
|
|
58
|
+
shown = state.shown !== null && state.shown !== undefined;
|
|
59
|
+
// The app's overlay, set by someone else: what was sent is no longer true.
|
|
60
|
+
if (typeof state.overlay === 'boolean') sent = state.overlay;
|
|
61
|
+
// A remote page shown while a popup is open: the home page comes in front now; none any more: nothing to cover.
|
|
62
|
+
void send(shown && count > 0);
|
|
63
|
+
};
|
|
64
|
+
const stop = app?.onState((state) => {
|
|
65
|
+
followed = true;
|
|
66
|
+
follow(state);
|
|
67
|
+
});
|
|
68
|
+
/** The app's first state read. */
|
|
69
|
+
const watching: Promise<void> = app
|
|
70
|
+
? app.state().then(
|
|
71
|
+
(state) => {
|
|
72
|
+
settled = true;
|
|
73
|
+
if (!followed) follow(state);
|
|
74
|
+
},
|
|
75
|
+
() => void (settled = true),
|
|
76
|
+
)
|
|
77
|
+
: Promise.resolve();
|
|
78
|
+
const frame = () => new Promise<void>((done) => requestAnimationFrame(() => done()));
|
|
79
|
+
const bounded = (wait: Promise<void>) =>
|
|
80
|
+
new Promise<void>((done) => {
|
|
81
|
+
const timer = setTimeout(done, waitMs);
|
|
82
|
+
void wait.then(() => {
|
|
83
|
+
clearTimeout(timer);
|
|
84
|
+
done();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
watching,
|
|
90
|
+
count: () => count,
|
|
91
|
+
/** The `overlay` entries held now (a stable array between changes). */
|
|
92
|
+
entries: held.get,
|
|
93
|
+
subscribe: held.subscribe,
|
|
94
|
+
hold({ modal = false, id }: OverlayHoldOptions = {}): OverlayRelease {
|
|
95
|
+
count++;
|
|
96
|
+
clearTimeout(lowering);
|
|
97
|
+
const releaseId = id === undefined ? undefined : held.hold(id);
|
|
98
|
+
// The desktop app focuses the home page over its remote view (`focus`, ignored by an older app); the page too.
|
|
99
|
+
if (modal) window.focus();
|
|
100
|
+
const raise = () => (shown ? send(true, modal).then(frame) : Promise.resolve());
|
|
101
|
+
const ready = !app ? Promise.resolve() : bounded(followed || settled ? raise() : watching.then(raise));
|
|
102
|
+
let released = false;
|
|
103
|
+
const release = () => {
|
|
104
|
+
if (released) return;
|
|
105
|
+
released = true;
|
|
106
|
+
count = Math.max(0, count - 1);
|
|
107
|
+
releaseId?.();
|
|
108
|
+
if (count > 0) return;
|
|
109
|
+
clearTimeout(lowering);
|
|
110
|
+
lowering = setTimeout(() => {
|
|
111
|
+
if (count === 0) void send(false);
|
|
112
|
+
}, 0);
|
|
113
|
+
};
|
|
114
|
+
return Object.assign(release, { ready });
|
|
115
|
+
},
|
|
116
|
+
/** The shell is disposed: stop following the app, drop every hold, give the window back. */
|
|
117
|
+
dispose() {
|
|
118
|
+
stop?.();
|
|
119
|
+
clearTimeout(lowering);
|
|
120
|
+
count = 0;
|
|
121
|
+
held.clear();
|
|
122
|
+
void send(false);
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
export type OverlayHold = ReturnType<typeof createOverlayHold>;
|
|
127
|
+
|
|
128
|
+
/** A set of ids held by plugins, each as many times as held (`hold` returns the release), followed by the frame. */
|
|
129
|
+
export function heldIds() {
|
|
130
|
+
const held = new Map<string, number>();
|
|
131
|
+
const listeners = new Set<() => void>();
|
|
132
|
+
let ids: readonly string[] = [];
|
|
133
|
+
const changed = () => {
|
|
134
|
+
ids = [...held.keys()];
|
|
135
|
+
for (const listener of listeners) listener();
|
|
136
|
+
};
|
|
137
|
+
return {
|
|
138
|
+
hold(id: string) {
|
|
139
|
+
held.set(id, (held.get(id) ?? 0) + 1);
|
|
140
|
+
changed();
|
|
141
|
+
let released = false;
|
|
142
|
+
return () => {
|
|
143
|
+
if (released || !held.has(id)) return;
|
|
144
|
+
released = true;
|
|
145
|
+
const left = (held.get(id) ?? 1) - 1;
|
|
146
|
+
if (left > 0) held.set(id, left);
|
|
147
|
+
else held.delete(id);
|
|
148
|
+
changed();
|
|
149
|
+
};
|
|
150
|
+
},
|
|
151
|
+
get: () => ids,
|
|
152
|
+
subscribe(listener: () => void) {
|
|
153
|
+
listeners.add(listener);
|
|
154
|
+
return () => void listeners.delete(listener);
|
|
155
|
+
},
|
|
156
|
+
/** Every hold dropped (the shell is disposed). */
|
|
157
|
+
clear() {
|
|
158
|
+
held.clear();
|
|
159
|
+
changed();
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
package/browser/shell-state.ts
CHANGED
|
@@ -482,6 +482,8 @@ export function followStatus(
|
|
|
482
482
|
let replaying = true;
|
|
483
483
|
const unsubscribe = subscribe((event) => {
|
|
484
484
|
if (event.event === 'nodes') shell.nodesChanged(event.data.workspace, event.data.revision);
|
|
485
|
+
// Bridge's update (bridge#677) changes no workspace, and comes at each percent of a download: nothing to refresh.
|
|
486
|
+
else if (String(event.event) === 'update') return;
|
|
485
487
|
else if (!(replaying && event.event === 'snapshot')) shell.refresh();
|
|
486
488
|
});
|
|
487
489
|
replaying = false;
|
package/browser/shell.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// browser type-check (tsconfig.pages.json); no plugin imports it (AD-8).
|
|
6
6
|
import type {} from 'cordis';
|
|
7
7
|
import type {} from '@bridge/ui-slots';
|
|
8
|
-
import type { ReactNode } from 'react';
|
|
8
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
9
9
|
import type { StatusStreamEvent, WorkspaceLook } from '@bridge/kernel/status';
|
|
10
10
|
|
|
11
11
|
/** `look`: its look as it shows for this user (research-018 slice 8, research-028): the workspace's proposal with the
|
|
@@ -469,8 +469,10 @@ export interface BridgeDesktop {
|
|
|
469
469
|
};
|
|
470
470
|
/** The app's recovery screen (the home Bridge did not start): try it again, in safe mode, or quit. */
|
|
471
471
|
recover(action: 'retry' | 'safe' | 'quit'): Promise<DesktopResult>;
|
|
472
|
-
/** A popup of this page opens (`true`) or closes: over a remote page, the page covers the window meanwhile.
|
|
473
|
-
|
|
472
|
+
/** A popup of this page opens (`true`) or closes: over a remote page, the page covers the window meanwhile.
|
|
473
|
+
* `focus`: a window or dialog, the app also gives the home page the keyboard (bridgebrew/bridge#685; an older app
|
|
474
|
+
* ignores it). */
|
|
475
|
+
overlay(open: boolean, options?: { focus?: boolean }): Promise<unknown>;
|
|
474
476
|
/** Home page (research-034 slice 3): the app took ⌘K in a view; returns the unsubscribe. */
|
|
475
477
|
onPalette(listener: () => void): () => void;
|
|
476
478
|
/** Home page: its palette opened or closed; the home view covers the window meanwhile. */
|
|
@@ -512,6 +514,29 @@ declare module 'cordis' {
|
|
|
512
514
|
* `/_bridge/status`; `key`: the item to scroll to and outline briefly (a cause key, `pluginKey(slug, id)`,
|
|
513
515
|
* or a workspace slug, as a failure toast's `details` gives it), none: the top. */
|
|
514
516
|
showErrors(key?: string): void;
|
|
517
|
+
/** Keeps the home page in front of a joined Bridge's page (the desktop app) while a popup or window of this page
|
|
518
|
+
* is open: one count for every plugin (research-128 §7). Returns the release (call it on close or unmount; once);
|
|
519
|
+
* its `ready` resolves once the home page is in front (at once without a joined page or the app), so the popup
|
|
520
|
+
* opens after it (after a short wait at most when the app does not answer). `modal`: a dialog or window (not a
|
|
521
|
+
* tooltip or a menu): the app gives the home page the keyboard. `id`: the `overlay` entry the popup draws in,
|
|
522
|
+
* which alone shows over the joined page while held (the others stay hidden there). Absent in an older shell:
|
|
523
|
+
* the caller keeps its own `bridgeDesktop.overlay` calls.
|
|
524
|
+
*
|
|
525
|
+
* The shell cannot see who calls it: a plugin ties each hold, mark and phone overlay to its own life (a React
|
|
526
|
+
* effect's cleanup, or `ctx.effect(() => ctx.shell.markMore(id))`); the shell drops them all when it goes. */
|
|
527
|
+
holdOverlay?(options?: {
|
|
528
|
+
modal?: boolean;
|
|
529
|
+
id?: string;
|
|
530
|
+
}): (() => void) & { readonly ready: Promise<void> };
|
|
531
|
+
/** Draws entry `id` of `overlay` on a phone too (none is by default), outside the shell's frame; returns the
|
|
532
|
+
* release. Absent in an older shell. */
|
|
533
|
+
overlayOnPhone?(id: string): () => void;
|
|
534
|
+
/** Marks the phone's More for attention: a dot on its tab while held (any plugin's mark, until the last is
|
|
535
|
+
* released); returns the release. Absent in an older shell. */
|
|
536
|
+
markMore?(id: string): () => void;
|
|
537
|
+
/** The page shows the phone's layout now (a narrow touch screen, or the phone frame); read at render. Absent in an
|
|
538
|
+
* older shell. */
|
|
539
|
+
readonly mobile?: boolean;
|
|
515
540
|
/** Opens the keyboard shortcuts' help (as `?` does): a plugin's button in the `controls` zone asks for it. */
|
|
516
541
|
showShortcuts(): void;
|
|
517
542
|
/** Opens plugin `plugin`'s settings (its id) in workspace `slug` on field `setting`: a fix's Open the setting, the
|
|
@@ -855,14 +880,30 @@ declare module '@bridge/ui-slots' {
|
|
|
855
880
|
/** Declared by `rail` (CAP-4, research-024 C12): a home plugin's icon (an Inbox, an agenda) at the top of
|
|
856
881
|
* the rail, above the workspaces, or at its bottom, above Admin; each entry its own `id`, about 40px square. */
|
|
857
882
|
'rail-top': { kind: 'list'; scope: 'root' };
|
|
858
|
-
|
|
883
|
+
/** Its entries sit at the bottom, after the divider of the controls the shell moves there, above Bridge's status
|
|
884
|
+
* and Admin; `tip`: the rail's tooltip, so an icon there is named as its neighbours (research-128 §7). An older rail
|
|
885
|
+
* passes none: the entry then draws its icon alone. */
|
|
886
|
+
'rail-bottom': {
|
|
887
|
+
kind: 'list';
|
|
888
|
+
scope: 'root';
|
|
889
|
+
owner: { tip?: (props: { label: ReactNode; children: ReactElement }) => ReactNode };
|
|
890
|
+
};
|
|
859
891
|
sidebar: { kind: 'single'; scope: 'root' };
|
|
860
892
|
/** Declared by `windows`' `stage` entry: at the left of its dock, before the desks (a Start button); each entry its
|
|
861
893
|
* own `id`, 28px high. Not drawn while another manager, or none, lays out the windows. */
|
|
862
894
|
'dock-start': { kind: 'list'; scope: 'root' };
|
|
863
895
|
main: { kind: 'single'; scope: 'root' };
|
|
864
|
-
/** Over the whole frame, after it: `_host` plugins add floating layers (each its own `id`), fixed-positioned.
|
|
896
|
+
/** Over the whole frame, after it: `_host` plugins add floating layers (each its own `id`), fixed-positioned. On a
|
|
897
|
+
* phone, only the entries that opted in (`shell.overlayOnPhone(id)`) are drawn, outside the frame. */
|
|
865
898
|
overlay: { kind: 'list'; scope: 'root' };
|
|
899
|
+
/** Declared by `shell` (research-128 §7): rows a plugin adds to the phone's More, after its own, each its own `id`.
|
|
900
|
+
* `style`: the menu's (`tree`: a SidebarTreeItem row, as its views; `pages`: a 48px row with a 20px icon), so a row
|
|
901
|
+
* is drawn as its neighbours; `close(then)`: closes the drawer, then runs `then` (open a page from it). */
|
|
902
|
+
more: {
|
|
903
|
+
kind: 'list';
|
|
904
|
+
scope: 'root';
|
|
905
|
+
owner: { style: 'tree' | 'pages'; close: (then?: () => void) => void };
|
|
906
|
+
};
|
|
866
907
|
/** Declared by `shell`: with its theme controls, wherever they stand (under the sidebar, under the rail while it is
|
|
867
908
|
* hidden, in the narrow column of the desktop app's pages), first; each entry its own `id`, a 28px button (the
|
|
868
909
|
* Start menu's when no dock shows). */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bridgebrew/shell",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "The page around everything: the rail, the sidebar column, the stage beside it and the theme controls.",
|
|
6
6
|
"keywords": [
|
|
@@ -103,6 +103,6 @@
|
|
|
103
103
|
"typecheck": "bridge plugin check ."
|
|
104
104
|
},
|
|
105
105
|
"engines": {
|
|
106
|
-
"bridge": ">=0.0.1-nightly.
|
|
106
|
+
"bridge": ">=0.0.1-nightly.20261124.1"
|
|
107
107
|
}
|
|
108
108
|
}
|