@shellui/core 0.5.0-beta.2 → 0.5.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 +5 -5
- package/package.json +3 -2
- package/schemas/shellui.config.schema.json +10 -2
- package/src/app.tsx +8 -4
- package/src/components/ContentView.tsx +12 -5
- package/src/components/ui/alert-dialog.tsx +1 -1
- package/src/components/ui/dialog.tsx +5 -1
- package/src/components/ui/dropdown-menu.tsx +39 -4
- package/src/components/ui/sheet.tsx +1 -1
- package/src/components/ui/sidebar.tsx +60 -20
- package/src/components/ui/tabs.tsx +52 -0
- package/src/constants/urls.ts +1 -0
- package/src/features/auth/AuthProvider.tsx +17 -6
- package/src/features/chromeActions/ChromeActionIcons.tsx +261 -0
- package/src/features/chromeActions/ChromeActionsDemoView.tsx +149 -0
- package/src/features/chromeActions/ChromeActionsHost.tsx +1511 -0
- package/src/features/chromeActions/ChromeActionsProvider.tsx +141 -0
- package/src/features/chromeActions/chromeActionsStore.spec.ts +61 -0
- package/src/features/chromeActions/chromeActionsStore.ts +77 -0
- package/src/features/chromeActions/computeActionInsets.spec.ts +360 -0
- package/src/features/chromeActions/computeActionInsets.ts +326 -0
- package/src/features/chromeActions/index.ts +26 -0
- package/src/features/chromeActions/resolveUuidForRemoveIframe.spec.ts +49 -0
- package/src/features/config/types.ts +16 -2
- package/src/features/layouts/AppLayout.tsx +30 -3
- package/src/features/layouts/OverlayShell.tsx +63 -13
- package/src/features/layouts/app-bar-inset/AppBarInsetLayout.tsx +22 -0
- package/src/features/layouts/appbar/AppBarLayout.tsx +230 -86
- package/src/features/layouts/chrome/DesktopChrome.tsx +17 -3
- package/src/features/layouts/chrome/InsetMobileRadiusOverlay.tsx +18 -0
- package/src/features/layouts/chrome/index.ts +8 -0
- package/src/features/layouts/chrome/runtime.ts +73 -0
- package/src/features/layouts/chrome/useScrollHideChrome.ts +210 -0
- package/src/features/layouts/floating/FloatingBottomDock.tsx +410 -0
- package/src/features/layouts/floating/FloatingLayout.tsx +152 -0
- package/src/features/layouts/floating/FloatingSidebar.tsx +327 -0
- package/src/features/layouts/floating/FloatingStatusScrim.tsx +36 -0
- package/src/features/layouts/floating/computeFloatingInsets.spec.ts +83 -0
- package/src/features/layouts/floating/computeFloatingInsets.ts +155 -0
- package/src/features/layouts/floating/isShellOwnedPath.spec.ts +25 -0
- package/src/features/layouts/floating/isShellOwnedPath.ts +17 -0
- package/src/features/layouts/floating/layoutChromeStore.spec.ts +138 -0
- package/src/features/layouts/floating/layoutChromeStore.ts +209 -0
- package/src/features/layouts/floating/scrollChrome.spec.ts +49 -0
- package/src/features/layouts/floating/useFloatingChrome.ts +206 -0
- package/src/features/layouts/sidebar/SidebarLayout.tsx +119 -37
- package/src/features/layouts/sidebar/types.ts +4 -0
- package/src/features/layouts/sidebar-inset/SidebarInsetLayout.tsx +15 -0
- package/src/features/layouts/windows/WindowsLayout.tsx +240 -110
- package/src/features/overlays/ResponsiveModal.tsx +201 -21
- package/src/features/overlays/overlaySize.spec.ts +18 -0
- package/src/features/overlays/overlaySize.ts +89 -0
- package/src/features/settings/SettingsProvider.tsx +36 -9
- package/src/features/settings/SettingsView.tsx +6 -6
- package/src/features/settings/components/Develop.tsx +33 -13
- package/src/features/settings/components/develop/ChromeActionsTestButtons.tsx +63 -0
- package/src/features/settings/utils/buildSettingsForPropagation.ts +16 -0
- package/src/features/storage/StoragePickerContext.tsx +1 -0
- package/src/features/storage/uploads/uploadQueue.spec.ts +56 -1
- package/src/features/storage/uploads/uploadQueue.ts +42 -1
- package/src/features/theme/applyTheme.ts +23 -5
- package/src/hooks/use-mobile.tsx +21 -7
- package/src/hooks/use-viewport.ts +40 -0
- package/src/i18n/translations/en/settings.json +17 -2
- package/src/i18n/translations/fr/settings.json +17 -2
- package/src/index.css +473 -12
- package/src/index.html +6 -4
- package/src/index.ts +8 -0
- package/src/routes/components/RouteFallback.tsx +21 -2
- package/src/routes/routes.tsx +14 -0
|
@@ -0,0 +1,1511 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useCallback,
|
|
3
|
+
useEffect,
|
|
4
|
+
useMemo,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
useSyncExternalStore,
|
|
8
|
+
type CSSProperties,
|
|
9
|
+
type ReactNode,
|
|
10
|
+
} from 'react';
|
|
11
|
+
import { createPortal } from 'react-dom';
|
|
12
|
+
import {
|
|
13
|
+
CHROME_ACTIONS_VISIBLE_TRAILING,
|
|
14
|
+
CHROME_ACTION_VARIANT_DEFAULT,
|
|
15
|
+
shellui,
|
|
16
|
+
type ChromeActionPayloadItem,
|
|
17
|
+
type ChromeActionVariant,
|
|
18
|
+
type ChromeActionsPayload,
|
|
19
|
+
type LayoutChrome,
|
|
20
|
+
} from '@shellui/sdk';
|
|
21
|
+
import { Button } from '../../components/ui/button';
|
|
22
|
+
import {
|
|
23
|
+
DropdownMenu,
|
|
24
|
+
DropdownMenuContent,
|
|
25
|
+
DropdownMenuItem,
|
|
26
|
+
DropdownMenuTrigger,
|
|
27
|
+
} from '../../components/ui/dropdown-menu';
|
|
28
|
+
import {
|
|
29
|
+
Tooltip,
|
|
30
|
+
TooltipContent,
|
|
31
|
+
TooltipProvider,
|
|
32
|
+
TooltipTrigger,
|
|
33
|
+
} from '../../components/ui/tooltip';
|
|
34
|
+
import { cn } from '../../lib/utils';
|
|
35
|
+
import { useViewport } from '../../hooks/use-viewport';
|
|
36
|
+
import { useSettings } from '../settings/hooks/useSettings';
|
|
37
|
+
import {
|
|
38
|
+
FLOATING_CHROME_MARGIN,
|
|
39
|
+
floatingTabBarBottomPadCss,
|
|
40
|
+
floatingTabBarHeight,
|
|
41
|
+
} from '../layouts/floating/computeFloatingInsets';
|
|
42
|
+
import {
|
|
43
|
+
getPublishedLayoutChrome,
|
|
44
|
+
subscribeLayoutChrome,
|
|
45
|
+
} from '../layouts/floating/layoutChromeStore';
|
|
46
|
+
import { useChromeActionsSnapshot } from './ChromeActionsProvider';
|
|
47
|
+
import { SHELL_DEVELOP_CHROME_ACTIONS_FRAME, type FrameChromeActions } from './chromeActionsStore';
|
|
48
|
+
import {
|
|
49
|
+
CHROME_ACTIONS_FAB_SIZE,
|
|
50
|
+
CHROME_ACTIONS_TOP_SCRIM_FADE,
|
|
51
|
+
actionChromeFlags,
|
|
52
|
+
chromeActionsFabBottomOffsetCss,
|
|
53
|
+
chromeActionsFabEdgeMargin,
|
|
54
|
+
chromeActionsFabRightOffsetCss,
|
|
55
|
+
chromeActionsFabSize,
|
|
56
|
+
chromeActionsTopBarHeight,
|
|
57
|
+
chromeActionsTopMargin,
|
|
58
|
+
chromeActionsTopOffsetCss,
|
|
59
|
+
isShellChromeLayout,
|
|
60
|
+
} from './computeActionInsets';
|
|
61
|
+
import {
|
|
62
|
+
ChevronLeftIcon,
|
|
63
|
+
ChromeActionGlyph,
|
|
64
|
+
MoreHorizontalIcon,
|
|
65
|
+
PlusIcon,
|
|
66
|
+
} from './ChromeActionIcons';
|
|
67
|
+
|
|
68
|
+
type FrameSurface = 'main' | 'overlay' | 'develop' | 'window';
|
|
69
|
+
|
|
70
|
+
/** Fade duration for chrome actions appear / clear (keep in sync with transition classes). */
|
|
71
|
+
const CHROME_ACTIONS_FADE_MS = 200;
|
|
72
|
+
/** Title swap: soft overlapping crossfade (opacity only). */
|
|
73
|
+
const CHROME_ACTIONS_TITLE_MS = 520;
|
|
74
|
+
/** Trailing row crossfade (old overlay → remove → new). */
|
|
75
|
+
const CHROME_ACTIONS_TRAILING_MS = 220;
|
|
76
|
+
/**
|
|
77
|
+
* Back button slot open/close — width + glyph motion so the title translates
|
|
78
|
+
* with the same curve (keep in sync with BackLeadingSlot / title shift).
|
|
79
|
+
*/
|
|
80
|
+
const CHROME_ACTIONS_BACK_SLOT_MS = 340;
|
|
81
|
+
/** Easing shared by back slot + title shift (snappy settle, soft land). */
|
|
82
|
+
const CHROME_ACTIONS_BACK_SLOT_EASE = 'cubic-bezier(0.22, 1, 0.36, 1)';
|
|
83
|
+
/** Overlay back control: size-8 + mr-2 (desktop). */
|
|
84
|
+
const CHROME_ACTIONS_BACK_SLOT_OPEN = 40;
|
|
85
|
+
/** Overlay back control: size-10 + mr-2 (phone/tablet). */
|
|
86
|
+
const CHROME_ACTIONS_BACK_SLOT_OPEN_NARROW = 48;
|
|
87
|
+
/** Title-bar back control: size-7 + mr-1. */
|
|
88
|
+
const CHROME_ACTIONS_BACK_SLOT_OPEN_TITLEBAR = 32;
|
|
89
|
+
/** Collapsed leading spacer when no back control. */
|
|
90
|
+
const CHROME_ACTIONS_BACK_SLOT_CLOSED = 8;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Floating / sidebar / app-bar phone hide-on-scroll: mirror nav chromeVisible
|
|
94
|
+
* for main-frame action buttons. Desktop and overlays stay visible.
|
|
95
|
+
*/
|
|
96
|
+
function scrollHideApplies(chrome: LayoutChrome | null, surface: FrameSurface): boolean {
|
|
97
|
+
if (surface !== 'main') return false;
|
|
98
|
+
if (!chrome) return false;
|
|
99
|
+
if (chrome.viewport !== 'mobile' && chrome.viewport !== 'tablet') return false;
|
|
100
|
+
switch (chrome.layout) {
|
|
101
|
+
case 'floating':
|
|
102
|
+
case 'sidebar':
|
|
103
|
+
case 'sidebar-inset':
|
|
104
|
+
case 'app-bar':
|
|
105
|
+
case 'app-bar-inset':
|
|
106
|
+
return true;
|
|
107
|
+
default:
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function usePublishedLayoutChrome(): LayoutChrome | null {
|
|
113
|
+
return useSyncExternalStore(subscribeLayoutChrome, getPublishedLayoutChrome, () => null);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
type PresenceItem = {
|
|
117
|
+
actions: FrameChromeActions;
|
|
118
|
+
/** False while entering (pre-paint) or exiting (fade-out). */
|
|
119
|
+
visible: boolean;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
type TrailingItem = ChromeActionPayloadItem;
|
|
123
|
+
|
|
124
|
+
function resolveActionVariant(
|
|
125
|
+
itemVariant: ChromeActionVariant | undefined,
|
|
126
|
+
setVariant: ChromeActionVariant | undefined,
|
|
127
|
+
): ChromeActionVariant {
|
|
128
|
+
return itemVariant ?? setVariant ?? CHROME_ACTION_VARIANT_DEFAULT;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Shared sizing for back / trailing chrome action controls (flat — no elevation). */
|
|
132
|
+
const chromeActionControlClass = 'shadow-none h-8 rounded-md text-xs';
|
|
133
|
+
const chromeActionControlClassNarrow = 'shadow-none h-10 rounded-md text-sm';
|
|
134
|
+
const chromeActionIconControlClass = 'shadow-none size-8 rounded-md text-xs';
|
|
135
|
+
const chromeActionIconControlClassNarrow = 'shadow-none size-10 rounded-md text-sm';
|
|
136
|
+
/** Windows title-bar: flush ghost controls that match maximize/close. */
|
|
137
|
+
const chromeActionTitlebarClass =
|
|
138
|
+
'shadow-none border-0 bg-transparent text-muted-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground';
|
|
139
|
+
const chromeActionTitlebarDestructiveClass =
|
|
140
|
+
'shadow-none border-0 bg-transparent text-destructive hover:bg-destructive/20 hover:text-destructive';
|
|
141
|
+
|
|
142
|
+
function resolveTitlebarButtonClass(variant: ChromeActionVariant): string {
|
|
143
|
+
return variant === 'destructive'
|
|
144
|
+
? chromeActionTitlebarDestructiveClass
|
|
145
|
+
: chromeActionTitlebarClass;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Icon-only chrome controls — show the action label on hover. */
|
|
149
|
+
function ChromeActionTooltip({
|
|
150
|
+
label,
|
|
151
|
+
side = 'bottom',
|
|
152
|
+
children,
|
|
153
|
+
}: {
|
|
154
|
+
label?: string | null;
|
|
155
|
+
side?: 'top' | 'bottom' | 'left' | 'right';
|
|
156
|
+
children: ReactNode;
|
|
157
|
+
}) {
|
|
158
|
+
const text = label?.trim();
|
|
159
|
+
if (!text) return <>{children}</>;
|
|
160
|
+
return (
|
|
161
|
+
<Tooltip delayDuration={250}>
|
|
162
|
+
<TooltipTrigger asChild>{children}</TooltipTrigger>
|
|
163
|
+
<TooltipContent
|
|
164
|
+
side={side}
|
|
165
|
+
align="center"
|
|
166
|
+
>
|
|
167
|
+
{text}
|
|
168
|
+
</TooltipContent>
|
|
169
|
+
</Tooltip>
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
type TrailingSnapshot = {
|
|
174
|
+
/** Membership key (visible ids + more). Same key → in-place refresh, no crossfade. */
|
|
175
|
+
key: string;
|
|
176
|
+
visible: TrailingItem[];
|
|
177
|
+
moreItems: TrailingItem[] | null;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const chromeActionsFadeClass =
|
|
181
|
+
'transition-opacity duration-200 ease-out motion-reduce:transition-none';
|
|
182
|
+
|
|
183
|
+
function idsKey(ids: string[]): string {
|
|
184
|
+
return ids.join('\0');
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function buildTrailingSnapshot(trailing: TrailingItem[], narrow: boolean): TrailingSnapshot {
|
|
188
|
+
const maxVisible = narrow ? 0 : CHROME_ACTIONS_VISIBLE_TRAILING;
|
|
189
|
+
const visible = trailing.slice(0, maxVisible);
|
|
190
|
+
const overflow = trailing.slice(maxVisible);
|
|
191
|
+
const showMore = overflow.length > 0 || (narrow && trailing.length > 0);
|
|
192
|
+
const moreItems = showMore ? (narrow ? trailing : overflow) : null;
|
|
193
|
+
return {
|
|
194
|
+
key: idsKey([...visible.map((i) => i.id), moreItems ? '__more__' : '']),
|
|
195
|
+
visible,
|
|
196
|
+
moreItems,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Keeps cleared frames mounted through the fade-out, and starts new frames
|
|
202
|
+
* at opacity 0 so the first paint can transition in.
|
|
203
|
+
*/
|
|
204
|
+
function useChromeActionsPresence(live: FrameChromeActions[]): PresenceItem[] {
|
|
205
|
+
const key = idsKey(live.map((a) => a.frameUuid));
|
|
206
|
+
const liveRef = useRef(live);
|
|
207
|
+
liveRef.current = live;
|
|
208
|
+
|
|
209
|
+
const [items, setItems] = useState<PresenceItem[]>(() =>
|
|
210
|
+
live.map((actions) => ({ actions, visible: true })),
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
useEffect(() => {
|
|
214
|
+
const liveNow = liveRef.current;
|
|
215
|
+
setItems((prev) => {
|
|
216
|
+
const prevById = new Map(prev.map((p) => [p.actions.frameUuid, p]));
|
|
217
|
+
const next: PresenceItem[] = [];
|
|
218
|
+
|
|
219
|
+
for (const actions of liveNow) {
|
|
220
|
+
const existing = prevById.get(actions.frameUuid);
|
|
221
|
+
if (existing) {
|
|
222
|
+
next.push({ actions, visible: true });
|
|
223
|
+
prevById.delete(actions.frameUuid);
|
|
224
|
+
} else {
|
|
225
|
+
next.push({ actions, visible: false });
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
for (const leftover of prevById.values()) {
|
|
229
|
+
next.push({ actions: leftover.actions, visible: false });
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (
|
|
233
|
+
prev.length === next.length &&
|
|
234
|
+
prev.every(
|
|
235
|
+
(p, i) =>
|
|
236
|
+
p.actions.frameUuid === next[i].actions.frameUuid && p.visible === next[i].visible,
|
|
237
|
+
)
|
|
238
|
+
) {
|
|
239
|
+
let changed = false;
|
|
240
|
+
const refreshed = prev.map((p, i) => {
|
|
241
|
+
if (p.actions === next[i].actions) return p;
|
|
242
|
+
changed = true;
|
|
243
|
+
return { ...p, actions: next[i].actions };
|
|
244
|
+
});
|
|
245
|
+
return changed ? refreshed : prev;
|
|
246
|
+
}
|
|
247
|
+
return next;
|
|
248
|
+
});
|
|
249
|
+
}, [key]);
|
|
250
|
+
|
|
251
|
+
useEffect(() => {
|
|
252
|
+
const entering = items.some(
|
|
253
|
+
(i) => !i.visible && liveRef.current.some((l) => l.frameUuid === i.actions.frameUuid),
|
|
254
|
+
);
|
|
255
|
+
if (!entering) return;
|
|
256
|
+
const id = requestAnimationFrame(() => {
|
|
257
|
+
setItems((prev) => {
|
|
258
|
+
let changed = false;
|
|
259
|
+
const next = prev.map((i) => {
|
|
260
|
+
if (!i.visible && liveRef.current.some((l) => l.frameUuid === i.actions.frameUuid)) {
|
|
261
|
+
changed = true;
|
|
262
|
+
return { ...i, visible: true };
|
|
263
|
+
}
|
|
264
|
+
return i;
|
|
265
|
+
});
|
|
266
|
+
return changed ? next : prev;
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
return () => cancelAnimationFrame(id);
|
|
270
|
+
}, [items]);
|
|
271
|
+
|
|
272
|
+
useEffect(() => {
|
|
273
|
+
const exitingIds = items
|
|
274
|
+
.filter(
|
|
275
|
+
(i) => !i.visible && !liveRef.current.some((l) => l.frameUuid === i.actions.frameUuid),
|
|
276
|
+
)
|
|
277
|
+
.map((i) => i.actions.frameUuid);
|
|
278
|
+
if (exitingIds.length === 0) return;
|
|
279
|
+
const exiting = new Set(exitingIds);
|
|
280
|
+
const t = window.setTimeout(() => {
|
|
281
|
+
setItems((prev) => {
|
|
282
|
+
const next = prev.filter(
|
|
283
|
+
(i) =>
|
|
284
|
+
!exiting.has(i.actions.frameUuid) ||
|
|
285
|
+
liveRef.current.some((l) => l.frameUuid === i.actions.frameUuid),
|
|
286
|
+
);
|
|
287
|
+
return next.length === prev.length ? prev : next;
|
|
288
|
+
});
|
|
289
|
+
}, CHROME_ACTIONS_FADE_MS);
|
|
290
|
+
return () => window.clearTimeout(t);
|
|
291
|
+
}, [items]);
|
|
292
|
+
|
|
293
|
+
return items.map((entry) => {
|
|
294
|
+
const fresh = live.find((l) => l.frameUuid === entry.actions.frameUuid);
|
|
295
|
+
return fresh && fresh !== entry.actions ? { ...entry, actions: fresh } : entry;
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** Single optional control (FAB) with enter + exit fade. */
|
|
300
|
+
function useOptionalPresence<T extends { id: string }>(
|
|
301
|
+
live: T | null | undefined,
|
|
302
|
+
): { item: T | null; visible: boolean } {
|
|
303
|
+
const liveId = live?.id ?? null;
|
|
304
|
+
const liveRef = useRef(live);
|
|
305
|
+
liveRef.current = live;
|
|
306
|
+
|
|
307
|
+
const [held, setHeld] = useState<T | null>(live ?? null);
|
|
308
|
+
const [visible, setVisible] = useState(Boolean(live));
|
|
309
|
+
|
|
310
|
+
useEffect(() => {
|
|
311
|
+
if (liveId) {
|
|
312
|
+
const current = liveRef.current;
|
|
313
|
+
if (current) setHeld(current);
|
|
314
|
+
const id = requestAnimationFrame(() => setVisible(true));
|
|
315
|
+
return () => cancelAnimationFrame(id);
|
|
316
|
+
}
|
|
317
|
+
setVisible(false);
|
|
318
|
+
const t = window.setTimeout(() => {
|
|
319
|
+
if (!liveRef.current) setHeld(null);
|
|
320
|
+
}, CHROME_ACTIONS_FADE_MS);
|
|
321
|
+
return () => window.clearTimeout(t);
|
|
322
|
+
}, [liveId]);
|
|
323
|
+
|
|
324
|
+
// Prefer live payload while present; keep `held` only for the exit fade.
|
|
325
|
+
return { item: live ?? held, visible };
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function FadePresence({
|
|
329
|
+
visible,
|
|
330
|
+
scrollHidden = false,
|
|
331
|
+
className,
|
|
332
|
+
style,
|
|
333
|
+
children,
|
|
334
|
+
}: {
|
|
335
|
+
visible: boolean;
|
|
336
|
+
/** Floating hide-on-scroll: slide away while presence stays mounted. */
|
|
337
|
+
scrollHidden?: boolean;
|
|
338
|
+
className?: string;
|
|
339
|
+
style?: CSSProperties;
|
|
340
|
+
children: ReactNode;
|
|
341
|
+
}) {
|
|
342
|
+
return (
|
|
343
|
+
<div
|
|
344
|
+
data-visible={visible ? 'true' : 'false'}
|
|
345
|
+
data-scroll-hidden={scrollHidden ? 'true' : 'false'}
|
|
346
|
+
data-shellui-chrome-actions-fab-slot=""
|
|
347
|
+
className={cn(
|
|
348
|
+
// Opacity / translate transitions owned by index.css (match tab-bar hide).
|
|
349
|
+
visible ? null : 'pointer-events-none',
|
|
350
|
+
className,
|
|
351
|
+
)}
|
|
352
|
+
style={style}
|
|
353
|
+
>
|
|
354
|
+
{children}
|
|
355
|
+
</div>
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Soft title crossfade: old and new overlap and ease opacity only (no slide /
|
|
361
|
+
* stagger). Layers stay absolute so trailing actions never reflow.
|
|
362
|
+
* Horizontal motion comes from `BackLeadingSlot` width — the title rides flex layout.
|
|
363
|
+
*/
|
|
364
|
+
function ChromeActionTitle({ title }: { title?: string }) {
|
|
365
|
+
const titleRef = useRef(title ?? '');
|
|
366
|
+
const keyRef = useRef(0);
|
|
367
|
+
const [outgoing, setOutgoing] = useState<{ text: string; leaving: boolean } | null>(null);
|
|
368
|
+
const [current, setCurrent] = useState<{ text: string; key: number; shown: boolean }>({
|
|
369
|
+
text: title ?? '',
|
|
370
|
+
key: 0,
|
|
371
|
+
shown: true,
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
useEffect(() => {
|
|
375
|
+
const prev = titleRef.current;
|
|
376
|
+
const next = title ?? '';
|
|
377
|
+
if (prev === next) return;
|
|
378
|
+
titleRef.current = next;
|
|
379
|
+
|
|
380
|
+
if (!prev) {
|
|
381
|
+
keyRef.current += 1;
|
|
382
|
+
setOutgoing(null);
|
|
383
|
+
setCurrent({ text: next, key: keyRef.current, shown: true });
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
keyRef.current += 1;
|
|
388
|
+
const nextKey = keyRef.current;
|
|
389
|
+
|
|
390
|
+
setOutgoing({ text: prev, leaving: false });
|
|
391
|
+
setCurrent({ text: next, key: nextKey, shown: false });
|
|
392
|
+
|
|
393
|
+
// Paint both layers at rest, then crossfade on the next frame.
|
|
394
|
+
const swapRaf = requestAnimationFrame(() => {
|
|
395
|
+
setOutgoing((o) => (o ? { ...o, leaving: true } : null));
|
|
396
|
+
setCurrent((c) => (c.key === nextKey ? { ...c, shown: true } : c));
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
const clearOut = window.setTimeout(() => setOutgoing(null), CHROME_ACTIONS_TITLE_MS);
|
|
400
|
+
|
|
401
|
+
return () => {
|
|
402
|
+
cancelAnimationFrame(swapRaf);
|
|
403
|
+
window.clearTimeout(clearOut);
|
|
404
|
+
};
|
|
405
|
+
}, [title]);
|
|
406
|
+
|
|
407
|
+
if (!current.text && !outgoing) {
|
|
408
|
+
return <span className="min-w-0 flex-1" />;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
const fadeStyle = (): CSSProperties => ({
|
|
412
|
+
transitionProperty: 'opacity',
|
|
413
|
+
transitionDuration: `${CHROME_ACTIONS_TITLE_MS}ms`,
|
|
414
|
+
transitionTimingFunction: 'ease-in-out',
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
const layerClass =
|
|
418
|
+
'absolute inset-0 truncate text-sm font-semibold leading-5 text-foreground motion-reduce:transition-none';
|
|
419
|
+
|
|
420
|
+
return (
|
|
421
|
+
<span
|
|
422
|
+
className="relative isolate min-w-0 flex-1 overflow-hidden px-1"
|
|
423
|
+
style={{ height: '1.25rem', fontFamily: 'var(--heading-font-family, inherit)' }}
|
|
424
|
+
>
|
|
425
|
+
{outgoing ? (
|
|
426
|
+
<span
|
|
427
|
+
aria-hidden
|
|
428
|
+
className={cn(
|
|
429
|
+
layerClass,
|
|
430
|
+
'pointer-events-none z-[1]',
|
|
431
|
+
outgoing.leaving ? 'opacity-0' : 'opacity-100',
|
|
432
|
+
)}
|
|
433
|
+
style={fadeStyle()}
|
|
434
|
+
>
|
|
435
|
+
{outgoing.text}
|
|
436
|
+
</span>
|
|
437
|
+
) : null}
|
|
438
|
+
{current.text ? (
|
|
439
|
+
<span
|
|
440
|
+
key={current.key}
|
|
441
|
+
className={cn(layerClass, 'z-[2]', current.shown ? 'opacity-100' : 'opacity-0')}
|
|
442
|
+
style={fadeStyle()}
|
|
443
|
+
>
|
|
444
|
+
{current.text}
|
|
445
|
+
</span>
|
|
446
|
+
) : null}
|
|
447
|
+
</span>
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Leading back control: expands/collapses width so the title translates with it,
|
|
453
|
+
* while the button fades + eases in from the left.
|
|
454
|
+
*/
|
|
455
|
+
function BackLeadingSlot({
|
|
456
|
+
back,
|
|
457
|
+
titlebar,
|
|
458
|
+
setVariant,
|
|
459
|
+
frameUuid,
|
|
460
|
+
interactive,
|
|
461
|
+
narrow = false,
|
|
462
|
+
}: {
|
|
463
|
+
back?: ChromeActionPayloadItem | null;
|
|
464
|
+
titlebar: boolean;
|
|
465
|
+
setVariant?: ChromeActionVariant;
|
|
466
|
+
frameUuid: string;
|
|
467
|
+
interactive: boolean;
|
|
468
|
+
/** Phone/tablet: larger hit targets. */
|
|
469
|
+
narrow?: boolean;
|
|
470
|
+
}) {
|
|
471
|
+
const backId = back?.id ?? null;
|
|
472
|
+
const [displayed, setDisplayed] = useState<ChromeActionPayloadItem | null>(back ?? null);
|
|
473
|
+
const [open, setOpen] = useState(Boolean(back));
|
|
474
|
+
|
|
475
|
+
useEffect(() => {
|
|
476
|
+
if (back) {
|
|
477
|
+
setDisplayed(back);
|
|
478
|
+
const id = requestAnimationFrame(() => setOpen(true));
|
|
479
|
+
return () => cancelAnimationFrame(id);
|
|
480
|
+
}
|
|
481
|
+
setOpen(false);
|
|
482
|
+
const t = window.setTimeout(() => setDisplayed(null), CHROME_ACTIONS_BACK_SLOT_MS);
|
|
483
|
+
return () => window.clearTimeout(t);
|
|
484
|
+
}, [backId]);
|
|
485
|
+
|
|
486
|
+
// Refresh label/icon/disabled while the same back id stays mounted.
|
|
487
|
+
useEffect(() => {
|
|
488
|
+
if (back && open) setDisplayed(back);
|
|
489
|
+
}, [back, open]);
|
|
490
|
+
|
|
491
|
+
const openWidth = titlebar
|
|
492
|
+
? CHROME_ACTIONS_BACK_SLOT_OPEN_TITLEBAR
|
|
493
|
+
: narrow
|
|
494
|
+
? CHROME_ACTIONS_BACK_SLOT_OPEN_NARROW
|
|
495
|
+
: CHROME_ACTIONS_BACK_SLOT_OPEN;
|
|
496
|
+
const width = open ? openWidth : CHROME_ACTIONS_BACK_SLOT_CLOSED;
|
|
497
|
+
const item = displayed;
|
|
498
|
+
const iconClass = narrow ? chromeActionIconControlClassNarrow : chromeActionIconControlClass;
|
|
499
|
+
|
|
500
|
+
return (
|
|
501
|
+
<div
|
|
502
|
+
data-shellui-chrome-actions-back-slot=""
|
|
503
|
+
data-open={open ? 'true' : 'false'}
|
|
504
|
+
className="relative shrink-0 overflow-hidden motion-reduce:transition-none"
|
|
505
|
+
style={{
|
|
506
|
+
width,
|
|
507
|
+
transitionProperty: 'width',
|
|
508
|
+
transitionDuration: `${CHROME_ACTIONS_BACK_SLOT_MS}ms`,
|
|
509
|
+
transitionTimingFunction: CHROME_ACTIONS_BACK_SLOT_EASE,
|
|
510
|
+
}}
|
|
511
|
+
>
|
|
512
|
+
{item ? (
|
|
513
|
+
<div
|
|
514
|
+
className={cn(
|
|
515
|
+
'origin-left motion-reduce:transition-none',
|
|
516
|
+
open ? 'translate-x-0 scale-100 opacity-100' : '-translate-x-2 scale-[0.92] opacity-0',
|
|
517
|
+
)}
|
|
518
|
+
style={{
|
|
519
|
+
transitionProperty: 'opacity, transform',
|
|
520
|
+
transitionDuration: `${CHROME_ACTIONS_BACK_SLOT_MS}ms`,
|
|
521
|
+
transitionTimingFunction: CHROME_ACTIONS_BACK_SLOT_EASE,
|
|
522
|
+
}}
|
|
523
|
+
>
|
|
524
|
+
<ChromeActionTooltip label={item.label || 'Back'}>
|
|
525
|
+
<Button
|
|
526
|
+
type="button"
|
|
527
|
+
variant={titlebar ? 'ghost' : resolveActionVariant(item.variant, setVariant)}
|
|
528
|
+
size="icon"
|
|
529
|
+
disabled={Boolean(item.disabled)}
|
|
530
|
+
className={cn(
|
|
531
|
+
'shrink-0',
|
|
532
|
+
titlebar
|
|
533
|
+
? cn(
|
|
534
|
+
'mr-1 size-7',
|
|
535
|
+
resolveTitlebarButtonClass(resolveActionVariant(item.variant, setVariant)),
|
|
536
|
+
)
|
|
537
|
+
: cn('mr-2', iconClass),
|
|
538
|
+
)}
|
|
539
|
+
aria-label={item.label || 'Back'}
|
|
540
|
+
aria-hidden={!open}
|
|
541
|
+
tabIndex={interactive && open ? undefined : -1}
|
|
542
|
+
onClick={(e) => {
|
|
543
|
+
e.stopPropagation();
|
|
544
|
+
if (!open || item.disabled) return;
|
|
545
|
+
fireAction(frameUuid, item.id);
|
|
546
|
+
}}
|
|
547
|
+
>
|
|
548
|
+
{item.icon && item.icon !== 'back' ? (
|
|
549
|
+
<ChromeActionGlyph
|
|
550
|
+
icon={item.icon}
|
|
551
|
+
label={item.label}
|
|
552
|
+
animate={item.animate}
|
|
553
|
+
/>
|
|
554
|
+
) : (
|
|
555
|
+
<ChevronLeftIcon
|
|
556
|
+
className={item.animate === 'icon-rotate' ? 'animate-spin' : undefined}
|
|
557
|
+
{...(item.animate === 'icon-rotate'
|
|
558
|
+
? { 'data-shellui-chrome-action-animate': 'icon-rotate' }
|
|
559
|
+
: {})}
|
|
560
|
+
/>
|
|
561
|
+
)}
|
|
562
|
+
</Button>
|
|
563
|
+
</ChromeActionTooltip>
|
|
564
|
+
</div>
|
|
565
|
+
) : (
|
|
566
|
+
<span
|
|
567
|
+
aria-hidden
|
|
568
|
+
className="block size-2"
|
|
569
|
+
/>
|
|
570
|
+
)}
|
|
571
|
+
</div>
|
|
572
|
+
);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/** Horizontal pad inside the action row (layout insets applied on the outer shell). */
|
|
576
|
+
function actionRowInlinePad(useLayoutInsets: boolean): CSSProperties {
|
|
577
|
+
if (useLayoutInsets) {
|
|
578
|
+
// Leading chip clearance is folded into the overlay `left` so it shares the
|
|
579
|
+
// same CSS-var transition as `--shellui-inset-left` (no competing padding jump).
|
|
580
|
+
return {
|
|
581
|
+
paddingLeft: FLOATING_CHROME_MARGIN,
|
|
582
|
+
paddingRight: FLOATING_CHROME_MARGIN,
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
return {
|
|
586
|
+
paddingLeft: `calc(${FLOATING_CHROME_MARGIN}px + var(--shellui-safe-area-left, 0px))`,
|
|
587
|
+
paddingRight: `calc(${FLOATING_CHROME_MARGIN}px + var(--shellui-safe-area-right, 0px))`,
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
function fireAction(frameUuid: string, id: string): void {
|
|
592
|
+
// Develop buttons run in the shell window — trigger callbacks locally.
|
|
593
|
+
if (frameUuid === SHELL_DEVELOP_CHROME_ACTIONS_FRAME) {
|
|
594
|
+
shellui.callbackRegistry.triggerAction(id);
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
shellui.sendMessage({
|
|
598
|
+
type: 'SHELLUI_ACTION',
|
|
599
|
+
payload: { id },
|
|
600
|
+
to: [frameUuid],
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
function resolveFrameSurface(frameUuid: string): {
|
|
605
|
+
rect: DOMRect | null;
|
|
606
|
+
surface: FrameSurface;
|
|
607
|
+
/** Overlay frames portal into the ContentView root (inside modal/drawer). */
|
|
608
|
+
portalParent: HTMLElement | null;
|
|
609
|
+
/** Match inset / rounded content frames so fixed chrome is clipped to their corners. */
|
|
610
|
+
borderRadius: string;
|
|
611
|
+
} {
|
|
612
|
+
if (frameUuid === SHELL_DEVELOP_CHROME_ACTIONS_FRAME) {
|
|
613
|
+
return {
|
|
614
|
+
rect: new DOMRect(0, 0, window.innerWidth, window.innerHeight),
|
|
615
|
+
surface: 'develop',
|
|
616
|
+
portalParent: null,
|
|
617
|
+
borderRadius: '',
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
for (const [uuid, iframe] of shellui.frameRegistry.getAllIframes()) {
|
|
621
|
+
if (uuid === frameUuid && iframe.isConnected) {
|
|
622
|
+
const isOverlay = iframe.getAttribute('data-shellui-frame') === 'overlay';
|
|
623
|
+
// Portal into the window content root so FAB tracks drag/resize with the card.
|
|
624
|
+
const inWindows = Boolean(iframe.closest('[data-shellui-windows-layout]'));
|
|
625
|
+
const surface: FrameSurface = isOverlay ? 'overlay' : inWindows ? 'window' : 'main';
|
|
626
|
+
return {
|
|
627
|
+
rect: iframe.getBoundingClientRect(),
|
|
628
|
+
surface,
|
|
629
|
+
portalParent: isOverlay || inWindows ? iframe.parentElement : null,
|
|
630
|
+
borderRadius: surface === 'main' ? resolveFrameClipRadius(iframe) : '',
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
return { rect: null, surface: 'main', portalParent: null, borderRadius: '' };
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Walk up from the content iframe to the nearest ancestor that both rounds and
|
|
639
|
+
* clips (sidebar-inset / app-bar-inset cards). Fixed action chrome sits above
|
|
640
|
+
* the iframe in the shell window, so it must reuse that radius to avoid square
|
|
641
|
+
* corners poking past the rounded frame.
|
|
642
|
+
*/
|
|
643
|
+
function resolveFrameClipRadius(iframe: HTMLElement): string {
|
|
644
|
+
let el: HTMLElement | null = iframe.parentElement;
|
|
645
|
+
while (el && el !== document.documentElement) {
|
|
646
|
+
const cs = getComputedStyle(el);
|
|
647
|
+
const radii = [
|
|
648
|
+
parseFloat(cs.borderTopLeftRadius),
|
|
649
|
+
parseFloat(cs.borderTopRightRadius),
|
|
650
|
+
parseFloat(cs.borderBottomRightRadius),
|
|
651
|
+
parseFloat(cs.borderBottomLeftRadius),
|
|
652
|
+
];
|
|
653
|
+
const hasRadius = radii.some((n) => Number.isFinite(n) && n > 0);
|
|
654
|
+
const clips =
|
|
655
|
+
cs.overflow === 'hidden' ||
|
|
656
|
+
cs.overflow === 'auto' ||
|
|
657
|
+
cs.overflow === 'clip' ||
|
|
658
|
+
cs.overflowX === 'hidden' ||
|
|
659
|
+
cs.overflowY === 'hidden';
|
|
660
|
+
if (hasRadius && clips) {
|
|
661
|
+
return cs.borderRadius;
|
|
662
|
+
}
|
|
663
|
+
el = el.parentElement;
|
|
664
|
+
}
|
|
665
|
+
return '';
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
function ActionButton({
|
|
669
|
+
item,
|
|
670
|
+
frameUuid,
|
|
671
|
+
compact,
|
|
672
|
+
setVariant,
|
|
673
|
+
className,
|
|
674
|
+
disabled,
|
|
675
|
+
titlebar = false,
|
|
676
|
+
narrow = false,
|
|
677
|
+
}: {
|
|
678
|
+
item: TrailingItem;
|
|
679
|
+
frameUuid: string;
|
|
680
|
+
compact?: boolean;
|
|
681
|
+
setVariant?: ChromeActionVariant;
|
|
682
|
+
className?: string;
|
|
683
|
+
disabled?: boolean;
|
|
684
|
+
/** Windows title-bar: ghost, no fill/border. */
|
|
685
|
+
titlebar?: boolean;
|
|
686
|
+
/** Phone/tablet: larger hit targets. */
|
|
687
|
+
narrow?: boolean;
|
|
688
|
+
}) {
|
|
689
|
+
const iconOnly = Boolean(item.icon) && (!item.label || compact);
|
|
690
|
+
const resolved = resolveActionVariant(item.variant, setVariant);
|
|
691
|
+
const variant = titlebar ? 'ghost' : resolved;
|
|
692
|
+
const isDisabled = Boolean(disabled || item.disabled);
|
|
693
|
+
const tip = item.label || item.icon || item.id;
|
|
694
|
+
const controlClass = narrow ? chromeActionControlClassNarrow : chromeActionControlClass;
|
|
695
|
+
const iconClass = narrow ? chromeActionIconControlClassNarrow : chromeActionIconControlClass;
|
|
696
|
+
const button = (
|
|
697
|
+
<Button
|
|
698
|
+
type="button"
|
|
699
|
+
variant={variant}
|
|
700
|
+
size={iconOnly ? 'icon' : 'sm'}
|
|
701
|
+
disabled={isDisabled}
|
|
702
|
+
data-shellui-chrome-actions-hit=""
|
|
703
|
+
className={cn(
|
|
704
|
+
titlebar
|
|
705
|
+
? cn('h-7 rounded-md text-xs', resolveTitlebarButtonClass(resolved))
|
|
706
|
+
: controlClass,
|
|
707
|
+
iconOnly ? (titlebar ? 'size-7 px-0' : cn(iconClass, 'px-0')) : 'px-3',
|
|
708
|
+
compact && iconOnly && !titlebar && !narrow && 'size-7',
|
|
709
|
+
className,
|
|
710
|
+
)}
|
|
711
|
+
onClick={(e) => {
|
|
712
|
+
e.stopPropagation();
|
|
713
|
+
if (isDisabled) return;
|
|
714
|
+
fireAction(frameUuid, item.id);
|
|
715
|
+
}}
|
|
716
|
+
aria-label={tip}
|
|
717
|
+
>
|
|
718
|
+
{item.icon ? (
|
|
719
|
+
<ChromeActionGlyph
|
|
720
|
+
icon={item.icon}
|
|
721
|
+
label={item.label}
|
|
722
|
+
animate={item.animate}
|
|
723
|
+
/>
|
|
724
|
+
) : null}
|
|
725
|
+
{item.label && !iconOnly ? <span className="max-w-[7rem] truncate">{item.label}</span> : null}
|
|
726
|
+
{item.label && compact && !item.icon ? (
|
|
727
|
+
<span className="max-w-[5rem] truncate">{item.label}</span>
|
|
728
|
+
) : null}
|
|
729
|
+
</Button>
|
|
730
|
+
);
|
|
731
|
+
|
|
732
|
+
// Only tip when the label isn’t already visible on the control.
|
|
733
|
+
if (!iconOnly) return button;
|
|
734
|
+
return <ChromeActionTooltip label={tip}>{button}</ChromeActionTooltip>;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
function TrailingActionsRow({
|
|
738
|
+
snapshot,
|
|
739
|
+
frameUuid,
|
|
740
|
+
compact,
|
|
741
|
+
setVariant,
|
|
742
|
+
iconClassName,
|
|
743
|
+
disabled,
|
|
744
|
+
titlebar = false,
|
|
745
|
+
narrowControls = false,
|
|
746
|
+
}: {
|
|
747
|
+
snapshot: TrailingSnapshot;
|
|
748
|
+
frameUuid: string;
|
|
749
|
+
compact: boolean;
|
|
750
|
+
setVariant?: ChromeActionVariant;
|
|
751
|
+
iconClassName: string;
|
|
752
|
+
disabled: boolean;
|
|
753
|
+
titlebar?: boolean;
|
|
754
|
+
narrowControls?: boolean;
|
|
755
|
+
}) {
|
|
756
|
+
return (
|
|
757
|
+
<div className="flex items-center gap-2">
|
|
758
|
+
{snapshot.visible.map((item) => (
|
|
759
|
+
<ActionButton
|
|
760
|
+
key={item.id}
|
|
761
|
+
item={item}
|
|
762
|
+
frameUuid={frameUuid}
|
|
763
|
+
compact={compact}
|
|
764
|
+
setVariant={setVariant}
|
|
765
|
+
disabled={disabled}
|
|
766
|
+
titlebar={titlebar}
|
|
767
|
+
narrow={narrowControls}
|
|
768
|
+
/>
|
|
769
|
+
))}
|
|
770
|
+
{snapshot.moreItems ? (
|
|
771
|
+
<DropdownMenu>
|
|
772
|
+
<DropdownMenuTrigger asChild>
|
|
773
|
+
<Button
|
|
774
|
+
type="button"
|
|
775
|
+
variant={titlebar ? 'ghost' : resolveActionVariant(undefined, setVariant)}
|
|
776
|
+
size="icon"
|
|
777
|
+
disabled={disabled}
|
|
778
|
+
className={iconClassName}
|
|
779
|
+
aria-label="More actions"
|
|
780
|
+
onClick={(e) => e.stopPropagation()}
|
|
781
|
+
>
|
|
782
|
+
<MoreHorizontalIcon />
|
|
783
|
+
</Button>
|
|
784
|
+
</DropdownMenuTrigger>
|
|
785
|
+
<DropdownMenuContent
|
|
786
|
+
align="end"
|
|
787
|
+
onClick={(e) => e.stopPropagation()}
|
|
788
|
+
>
|
|
789
|
+
{snapshot.moreItems.map((item) => (
|
|
790
|
+
<DropdownMenuItem
|
|
791
|
+
key={item.id}
|
|
792
|
+
disabled={disabled || Boolean(item.disabled)}
|
|
793
|
+
onSelect={() => {
|
|
794
|
+
if (disabled || item.disabled) return;
|
|
795
|
+
fireAction(frameUuid, item.id);
|
|
796
|
+
}}
|
|
797
|
+
>
|
|
798
|
+
<ChromeActionGlyph
|
|
799
|
+
icon={item.icon}
|
|
800
|
+
label={item.label}
|
|
801
|
+
animate={item.animate}
|
|
802
|
+
/>
|
|
803
|
+
<span className="truncate">{item.label || item.id}</span>
|
|
804
|
+
</DropdownMenuItem>
|
|
805
|
+
))}
|
|
806
|
+
</DropdownMenuContent>
|
|
807
|
+
</DropdownMenu>
|
|
808
|
+
) : null}
|
|
809
|
+
</div>
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
/**
|
|
814
|
+
* Crossfades the whole trailing cluster when membership changes:
|
|
815
|
+
* new layout takes the layout slot, old overlays on top and fades out, then old is removed.
|
|
816
|
+
* Buttons stay disabled for the duration so clicks can't land mid-transition.
|
|
817
|
+
*/
|
|
818
|
+
function TrailingActionsCrossfade({
|
|
819
|
+
trailing,
|
|
820
|
+
narrow,
|
|
821
|
+
frameUuid,
|
|
822
|
+
compact,
|
|
823
|
+
isOverlay,
|
|
824
|
+
setVariant,
|
|
825
|
+
}: {
|
|
826
|
+
trailing: TrailingItem[];
|
|
827
|
+
narrow: boolean;
|
|
828
|
+
frameUuid: string;
|
|
829
|
+
compact: boolean;
|
|
830
|
+
isOverlay: boolean;
|
|
831
|
+
setVariant?: ChromeActionVariant;
|
|
832
|
+
}) {
|
|
833
|
+
const live = buildTrailingSnapshot(trailing, narrow);
|
|
834
|
+
const liveKey = live.key;
|
|
835
|
+
const contentSig = trailing
|
|
836
|
+
.map(
|
|
837
|
+
(t) =>
|
|
838
|
+
`${t.id}:${t.label ?? ''}:${t.icon ?? ''}:${t.variant ?? ''}:${t.disabled ? 1 : 0}:${t.animate ?? ''}`,
|
|
839
|
+
)
|
|
840
|
+
.join('|');
|
|
841
|
+
|
|
842
|
+
const [current, setCurrent] = useState(live);
|
|
843
|
+
const [outgoing, setOutgoing] = useState<{
|
|
844
|
+
snapshot: TrailingSnapshot;
|
|
845
|
+
leaving: boolean;
|
|
846
|
+
} | null>(null);
|
|
847
|
+
const [incomingShown, setIncomingShown] = useState(true);
|
|
848
|
+
const currentRef = useRef(current);
|
|
849
|
+
currentRef.current = current;
|
|
850
|
+
const trailingRef = useRef(trailing);
|
|
851
|
+
trailingRef.current = trailing;
|
|
852
|
+
const narrowRef = useRef(narrow);
|
|
853
|
+
narrowRef.current = narrow;
|
|
854
|
+
|
|
855
|
+
// Same membership: refresh labels/icons in place (no crossfade).
|
|
856
|
+
useEffect(() => {
|
|
857
|
+
const next = buildTrailingSnapshot(trailingRef.current, narrowRef.current);
|
|
858
|
+
if (next.key === currentRef.current.key) {
|
|
859
|
+
setCurrent(next);
|
|
860
|
+
}
|
|
861
|
+
}, [contentSig, narrow]);
|
|
862
|
+
|
|
863
|
+
// Membership changed: overlay old row, swap layout to new, fade old out.
|
|
864
|
+
useEffect(() => {
|
|
865
|
+
const next = buildTrailingSnapshot(trailingRef.current, narrowRef.current);
|
|
866
|
+
if (next.key === currentRef.current.key) return;
|
|
867
|
+
|
|
868
|
+
const previous = currentRef.current;
|
|
869
|
+
setOutgoing({ snapshot: previous, leaving: false });
|
|
870
|
+
setCurrent(next);
|
|
871
|
+
setIncomingShown(false);
|
|
872
|
+
|
|
873
|
+
const leaveRaf = requestAnimationFrame(() => {
|
|
874
|
+
setOutgoing((o) => (o ? { ...o, leaving: true } : null));
|
|
875
|
+
});
|
|
876
|
+
const showIn = window.setTimeout(() => setIncomingShown(true), 40);
|
|
877
|
+
const clearOut = window.setTimeout(() => {
|
|
878
|
+
setOutgoing(null);
|
|
879
|
+
setIncomingShown(true);
|
|
880
|
+
}, CHROME_ACTIONS_TRAILING_MS);
|
|
881
|
+
|
|
882
|
+
return () => {
|
|
883
|
+
cancelAnimationFrame(leaveRaf);
|
|
884
|
+
window.clearTimeout(showIn);
|
|
885
|
+
window.clearTimeout(clearOut);
|
|
886
|
+
};
|
|
887
|
+
}, [liveKey, narrow]);
|
|
888
|
+
|
|
889
|
+
const busy = outgoing !== null || !incomingShown;
|
|
890
|
+
const titlebar = !isOverlay;
|
|
891
|
+
const iconClassName = cn(
|
|
892
|
+
titlebar
|
|
893
|
+
? cn('size-7 rounded-md text-xs', chromeActionTitlebarClass)
|
|
894
|
+
: narrow
|
|
895
|
+
? chromeActionIconControlClassNarrow
|
|
896
|
+
: chromeActionIconControlClass,
|
|
897
|
+
);
|
|
898
|
+
const empty = current.visible.length === 0 && !current.moreItems && !outgoing;
|
|
899
|
+
if (empty) return null;
|
|
900
|
+
|
|
901
|
+
return (
|
|
902
|
+
<div className="relative isolate flex shrink-0 items-center">
|
|
903
|
+
<div
|
|
904
|
+
className={cn(
|
|
905
|
+
chromeActionsFadeClass,
|
|
906
|
+
incomingShown ? 'opacity-100' : 'opacity-0',
|
|
907
|
+
busy && 'pointer-events-none',
|
|
908
|
+
)}
|
|
909
|
+
style={{ transitionDuration: `${CHROME_ACTIONS_TRAILING_MS}ms` }}
|
|
910
|
+
>
|
|
911
|
+
<TrailingActionsRow
|
|
912
|
+
snapshot={current}
|
|
913
|
+
frameUuid={frameUuid}
|
|
914
|
+
compact={compact}
|
|
915
|
+
setVariant={setVariant}
|
|
916
|
+
iconClassName={iconClassName}
|
|
917
|
+
disabled={busy}
|
|
918
|
+
titlebar={titlebar}
|
|
919
|
+
narrowControls={!titlebar && narrow}
|
|
920
|
+
/>
|
|
921
|
+
</div>
|
|
922
|
+
{outgoing ? (
|
|
923
|
+
<div
|
|
924
|
+
aria-hidden
|
|
925
|
+
className={cn(
|
|
926
|
+
'pointer-events-none absolute inset-y-0 right-0 z-[1] flex items-center',
|
|
927
|
+
chromeActionsFadeClass,
|
|
928
|
+
outgoing.leaving ? 'opacity-0' : 'opacity-100',
|
|
929
|
+
)}
|
|
930
|
+
style={{ transitionDuration: `${CHROME_ACTIONS_TRAILING_MS}ms` }}
|
|
931
|
+
>
|
|
932
|
+
<TrailingActionsRow
|
|
933
|
+
snapshot={outgoing.snapshot}
|
|
934
|
+
frameUuid={frameUuid}
|
|
935
|
+
compact={compact}
|
|
936
|
+
setVariant={setVariant}
|
|
937
|
+
iconClassName={iconClassName}
|
|
938
|
+
disabled
|
|
939
|
+
titlebar={titlebar}
|
|
940
|
+
narrowControls={!titlebar && narrow}
|
|
941
|
+
/>
|
|
942
|
+
</div>
|
|
943
|
+
) : null}
|
|
944
|
+
</div>
|
|
945
|
+
);
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
function TopActionBar({
|
|
949
|
+
actions,
|
|
950
|
+
placement,
|
|
951
|
+
visible = true,
|
|
952
|
+
/** When true, honor host `--shellui-inset-left/right` (main floating content). */
|
|
953
|
+
useLayoutInsets = false,
|
|
954
|
+
/** Floating hide-on-scroll — slide/fade with the tab bar (main frame only). */
|
|
955
|
+
scrollHidden = false,
|
|
956
|
+
/**
|
|
957
|
+
* When set, overrides layout-based safe-area decision (e.g. modal overlays still
|
|
958
|
+
* need the notch clearance even on sidebar/app-bar shells).
|
|
959
|
+
*/
|
|
960
|
+
honorSafeAreaTop,
|
|
961
|
+
}: {
|
|
962
|
+
actions: FrameChromeActions;
|
|
963
|
+
placement: 'overlay' | 'titlebar';
|
|
964
|
+
visible?: boolean;
|
|
965
|
+
useLayoutInsets?: boolean;
|
|
966
|
+
scrollHidden?: boolean;
|
|
967
|
+
honorSafeAreaTop?: boolean;
|
|
968
|
+
}) {
|
|
969
|
+
const viewport = useViewport();
|
|
970
|
+
const { settings } = useSettings();
|
|
971
|
+
const layoutChrome = usePublishedLayoutChrome();
|
|
972
|
+
const narrow = viewport === 'mobile' || viewport === 'tablet';
|
|
973
|
+
const trailing = actions.trailing ?? [];
|
|
974
|
+
|
|
975
|
+
// Prefer published floating chrome; otherwise use the active shell layout.
|
|
976
|
+
const layout =
|
|
977
|
+
layoutChrome?.layout === 'floating' ? 'floating' : (settings.layout ?? layoutChrome?.layout);
|
|
978
|
+
const sidebarExpanded =
|
|
979
|
+
layout === 'floating' && viewport === 'desktop'
|
|
980
|
+
? (layoutChrome?.chromeVisible ?? true)
|
|
981
|
+
: undefined;
|
|
982
|
+
const topContext = { viewport, layout, sidebarExpanded };
|
|
983
|
+
const topOffset = chromeActionsTopOffsetCss(topContext, { honorSafeAreaTop });
|
|
984
|
+
const barHeight = chromeActionsTopBarHeight(viewport);
|
|
985
|
+
const topMargin = chromeActionsTopMargin(topContext);
|
|
986
|
+
// Shell headers (flush + mobile inset) own the tray / radius band. Scrim fills
|
|
987
|
+
// from the header bottom through the action row so no gap shows through.
|
|
988
|
+
// Always fade from content background (bright) — never the darker inset tray.
|
|
989
|
+
const scrimClearsShellHeader = isShellChromeLayout(layout) && honorSafeAreaTop !== true;
|
|
990
|
+
const clipToInsetCard =
|
|
991
|
+
(layout === 'sidebar-inset' || layout === 'app-bar-inset') &&
|
|
992
|
+
viewport === 'mobile' &&
|
|
993
|
+
honorSafeAreaTop !== true;
|
|
994
|
+
const shellScrollSync =
|
|
995
|
+
isShellChromeLayout(layout) &&
|
|
996
|
+
honorSafeAreaTop !== true &&
|
|
997
|
+
(viewport === 'mobile' || viewport === 'tablet');
|
|
998
|
+
// When clipped to the inset card, offsets are relative to the card top (header already cleared).
|
|
999
|
+
const rowTop = clipToInsetCard ? `${topMargin}px` : topOffset;
|
|
1000
|
+
const scrimTop = clipToInsetCard
|
|
1001
|
+
? 0
|
|
1002
|
+
: scrimClearsShellHeader
|
|
1003
|
+
? 'var(--shellui-shell-header-height, 0px)'
|
|
1004
|
+
: 0;
|
|
1005
|
+
const scrimHeight = clipToInsetCard
|
|
1006
|
+
? `calc(${topMargin}px + ${barHeight}px + ${CHROME_ACTIONS_TOP_SCRIM_FADE}px)`
|
|
1007
|
+
: scrimClearsShellHeader
|
|
1008
|
+
? `calc(${topMargin}px + ${barHeight}px + ${CHROME_ACTIONS_TOP_SCRIM_FADE}px)`
|
|
1009
|
+
: `calc(${topOffset} + ${barHeight}px + ${CHROME_ACTIONS_TOP_SCRIM_FADE}px)`;
|
|
1010
|
+
|
|
1011
|
+
const flags = actionChromeFlags(actions);
|
|
1012
|
+
if (!flags.hasTop) return null;
|
|
1013
|
+
|
|
1014
|
+
const back = actions.back;
|
|
1015
|
+
const isOverlay = placement === 'overlay';
|
|
1016
|
+
const titlebar = placement === 'titlebar';
|
|
1017
|
+
const inlinePad = isOverlay ? actionRowInlinePad(useLayoutInsets) : undefined;
|
|
1018
|
+
const setVariant = actions.variant;
|
|
1019
|
+
const interactive = visible && !scrollHidden;
|
|
1020
|
+
|
|
1021
|
+
return (
|
|
1022
|
+
<TooltipProvider delayDuration={250}>
|
|
1023
|
+
<div
|
|
1024
|
+
data-shellui-chrome-actions-top={placement}
|
|
1025
|
+
data-visible={visible ? 'true' : 'false'}
|
|
1026
|
+
data-scroll-hidden={scrollHidden ? 'true' : 'false'}
|
|
1027
|
+
data-shell-scroll-sync={shellScrollSync ? '' : undefined}
|
|
1028
|
+
className={cn(
|
|
1029
|
+
'pointer-events-none',
|
|
1030
|
+
// Overlay: opacity/translate owned by index.css (scroll hide + presence).
|
|
1031
|
+
!isOverlay && chromeActionsFadeClass,
|
|
1032
|
+
!isOverlay && (visible ? 'opacity-100' : 'opacity-0'),
|
|
1033
|
+
isOverlay && 'absolute inset-x-0 z-[46]',
|
|
1034
|
+
isOverlay && !clipToInsetCard && 'top-0',
|
|
1035
|
+
titlebar && 'relative min-w-0 flex-1',
|
|
1036
|
+
)}
|
|
1037
|
+
style={
|
|
1038
|
+
isOverlay && useLayoutInsets
|
|
1039
|
+
? {
|
|
1040
|
+
// One animated edge (inset + collapsed-chip clearance) so actions
|
|
1041
|
+
// track the floating sidebar / layout resize instead of fighting it.
|
|
1042
|
+
left: `calc(var(--shellui-inset-left, 0px) + var(--shellui-chrome-actions-leading-extra, 0px))`,
|
|
1043
|
+
right: 'var(--shellui-inset-right, 0px)',
|
|
1044
|
+
// Match InsetMobileRadiusOverlay cutout so the bright scrim doesn’t
|
|
1045
|
+
// square off the top card corners.
|
|
1046
|
+
...(clipToInsetCard
|
|
1047
|
+
? {
|
|
1048
|
+
top: 'var(--shellui-shell-header-height, 0px)',
|
|
1049
|
+
bottom: 0,
|
|
1050
|
+
borderRadius: '1rem 1rem 0 0',
|
|
1051
|
+
overflow: 'hidden',
|
|
1052
|
+
}
|
|
1053
|
+
: undefined),
|
|
1054
|
+
}
|
|
1055
|
+
: undefined
|
|
1056
|
+
}
|
|
1057
|
+
>
|
|
1058
|
+
{isOverlay ? (
|
|
1059
|
+
<div
|
|
1060
|
+
aria-hidden
|
|
1061
|
+
className="pointer-events-none absolute inset-x-0 bg-gradient-to-b from-background from-70% to-transparent"
|
|
1062
|
+
style={{
|
|
1063
|
+
top: scrimTop,
|
|
1064
|
+
height: scrimHeight,
|
|
1065
|
+
}}
|
|
1066
|
+
/>
|
|
1067
|
+
) : null}
|
|
1068
|
+
|
|
1069
|
+
<div
|
|
1070
|
+
data-shellui-chrome-actions-hit=""
|
|
1071
|
+
className={cn(
|
|
1072
|
+
'pointer-events-auto relative flex items-center gap-2',
|
|
1073
|
+
titlebar && 'min-w-0 flex-1 gap-1',
|
|
1074
|
+
!interactive && 'pointer-events-none',
|
|
1075
|
+
)}
|
|
1076
|
+
style={
|
|
1077
|
+
isOverlay
|
|
1078
|
+
? {
|
|
1079
|
+
top: rowTop,
|
|
1080
|
+
height: barHeight,
|
|
1081
|
+
...inlinePad,
|
|
1082
|
+
}
|
|
1083
|
+
: undefined
|
|
1084
|
+
}
|
|
1085
|
+
>
|
|
1086
|
+
<BackLeadingSlot
|
|
1087
|
+
back={back}
|
|
1088
|
+
titlebar={titlebar}
|
|
1089
|
+
setVariant={setVariant}
|
|
1090
|
+
frameUuid={actions.frameUuid}
|
|
1091
|
+
interactive={interactive}
|
|
1092
|
+
narrow={!titlebar && narrow}
|
|
1093
|
+
/>
|
|
1094
|
+
|
|
1095
|
+
<ChromeActionTitle title={actions.title} />
|
|
1096
|
+
|
|
1097
|
+
<TrailingActionsCrossfade
|
|
1098
|
+
trailing={trailing}
|
|
1099
|
+
narrow={narrow}
|
|
1100
|
+
frameUuid={actions.frameUuid}
|
|
1101
|
+
compact={titlebar}
|
|
1102
|
+
isOverlay={isOverlay}
|
|
1103
|
+
setVariant={setVariant}
|
|
1104
|
+
/>
|
|
1105
|
+
</div>
|
|
1106
|
+
</div>
|
|
1107
|
+
</TooltipProvider>
|
|
1108
|
+
);
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
function PrimaryFab({
|
|
1112
|
+
actions,
|
|
1113
|
+
bottomOffset,
|
|
1114
|
+
visible = true,
|
|
1115
|
+
useLayoutInsets = false,
|
|
1116
|
+
scrollHidden = false,
|
|
1117
|
+
sizePx = CHROME_ACTIONS_FAB_SIZE,
|
|
1118
|
+
edgeMargin = FLOATING_CHROME_MARGIN,
|
|
1119
|
+
/** Phone/tablet dock: binary pill. Desktop: theme `--radius` (0 → square). */
|
|
1120
|
+
shape = 'theme',
|
|
1121
|
+
}: {
|
|
1122
|
+
actions: FrameChromeActions;
|
|
1123
|
+
/** Pixel number or CSS length (e.g. calc with safe-area). */
|
|
1124
|
+
bottomOffset: number | string;
|
|
1125
|
+
visible?: boolean;
|
|
1126
|
+
useLayoutInsets?: boolean;
|
|
1127
|
+
scrollHidden?: boolean;
|
|
1128
|
+
/** FAB diameter in px. */
|
|
1129
|
+
sizePx?: number;
|
|
1130
|
+
/** Outer inset from the frame / screen edge. */
|
|
1131
|
+
edgeMargin?: number;
|
|
1132
|
+
shape?: 'pill' | 'theme';
|
|
1133
|
+
}) {
|
|
1134
|
+
const primary = actions.primary ?? null;
|
|
1135
|
+
const { item, visible: itemVisible } = useOptionalPresence(primary);
|
|
1136
|
+
if (!item) return null;
|
|
1137
|
+
|
|
1138
|
+
const right = chromeActionsFabRightOffsetCss(edgeMargin, { useLayoutInsets });
|
|
1139
|
+
|
|
1140
|
+
const ariaLabel = item.label || item.icon || 'Primary action';
|
|
1141
|
+
const shown = visible && itemVisible && !scrollHidden;
|
|
1142
|
+
|
|
1143
|
+
return (
|
|
1144
|
+
<FadePresence
|
|
1145
|
+
visible={visible && itemVisible}
|
|
1146
|
+
scrollHidden={scrollHidden}
|
|
1147
|
+
className="pointer-events-auto absolute z-[46]"
|
|
1148
|
+
style={{
|
|
1149
|
+
right,
|
|
1150
|
+
bottom: typeof bottomOffset === 'number' ? `${bottomOffset}px` : bottomOffset,
|
|
1151
|
+
}}
|
|
1152
|
+
>
|
|
1153
|
+
<Button
|
|
1154
|
+
type="button"
|
|
1155
|
+
variant="default"
|
|
1156
|
+
size="icon"
|
|
1157
|
+
disabled={Boolean(item.disabled)}
|
|
1158
|
+
data-shellui-chrome-actions-fab=""
|
|
1159
|
+
data-shellui-chrome-actions-hit=""
|
|
1160
|
+
data-shellui-floating-fab={shape === 'pill' ? 'true' : undefined}
|
|
1161
|
+
className={cn('shadow-sm', shape === 'theme' && 'rounded-md')}
|
|
1162
|
+
style={{ width: sizePx, height: sizePx }}
|
|
1163
|
+
aria-label={ariaLabel}
|
|
1164
|
+
tabIndex={shown ? undefined : -1}
|
|
1165
|
+
onClick={(e) => {
|
|
1166
|
+
e.stopPropagation();
|
|
1167
|
+
if (item.disabled) return;
|
|
1168
|
+
fireAction(actions.frameUuid, item.id);
|
|
1169
|
+
}}
|
|
1170
|
+
>
|
|
1171
|
+
{item.icon ? (
|
|
1172
|
+
<ChromeActionGlyph
|
|
1173
|
+
icon={item.icon}
|
|
1174
|
+
label={item.label}
|
|
1175
|
+
animate={item.animate}
|
|
1176
|
+
/>
|
|
1177
|
+
) : item.label ? (
|
|
1178
|
+
<span className="px-1 text-sm font-semibold">{item.label}</span>
|
|
1179
|
+
) : (
|
|
1180
|
+
<PlusIcon
|
|
1181
|
+
className={item.animate === 'icon-rotate' ? 'animate-spin' : undefined}
|
|
1182
|
+
{...(item.animate === 'icon-rotate'
|
|
1183
|
+
? { 'data-shellui-chrome-action-animate': 'icon-rotate' }
|
|
1184
|
+
: {})}
|
|
1185
|
+
/>
|
|
1186
|
+
)}
|
|
1187
|
+
</Button>
|
|
1188
|
+
</FadePresence>
|
|
1189
|
+
);
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
function FrameActionsOverlay({
|
|
1193
|
+
actions,
|
|
1194
|
+
showTop,
|
|
1195
|
+
fabBottomOffset,
|
|
1196
|
+
visible,
|
|
1197
|
+
scrollHidden = false,
|
|
1198
|
+
fabSizePx = CHROME_ACTIONS_FAB_SIZE,
|
|
1199
|
+
fabEdgeMargin = FLOATING_CHROME_MARGIN,
|
|
1200
|
+
fabShape = 'theme',
|
|
1201
|
+
}: {
|
|
1202
|
+
actions: FrameChromeActions;
|
|
1203
|
+
showTop: boolean;
|
|
1204
|
+
fabBottomOffset: number | string;
|
|
1205
|
+
visible: boolean;
|
|
1206
|
+
/** Floating phone/tablet: hide with nav on scroll. */
|
|
1207
|
+
scrollHidden?: boolean;
|
|
1208
|
+
/** Main-frame FAB diameter. */
|
|
1209
|
+
fabSizePx?: number;
|
|
1210
|
+
/** Main-frame FAB edge inset. */
|
|
1211
|
+
fabEdgeMargin?: number;
|
|
1212
|
+
/** Main-frame FAB corner treatment. */
|
|
1213
|
+
fabShape?: 'pill' | 'theme';
|
|
1214
|
+
}) {
|
|
1215
|
+
const [{ rect, surface, portalParent, borderRadius }, setFrame] = useState(() =>
|
|
1216
|
+
resolveFrameSurface(actions.frameUuid),
|
|
1217
|
+
);
|
|
1218
|
+
|
|
1219
|
+
const refresh = useCallback(() => {
|
|
1220
|
+
setFrame(resolveFrameSurface(actions.frameUuid));
|
|
1221
|
+
}, [actions.frameUuid]);
|
|
1222
|
+
|
|
1223
|
+
// Keep the fixed overlay locked to the iframe while layout animates (sidebar
|
|
1224
|
+
// collapse, inset transitions). Polling every 500ms lagged behind CSS motion.
|
|
1225
|
+
useEffect(() => {
|
|
1226
|
+
refresh();
|
|
1227
|
+
|
|
1228
|
+
let raf = 0;
|
|
1229
|
+
let trackingUntil = 0;
|
|
1230
|
+
|
|
1231
|
+
const read = () => {
|
|
1232
|
+
setFrame((prev) => {
|
|
1233
|
+
const next = resolveFrameSurface(actions.frameUuid);
|
|
1234
|
+
const a = prev.rect;
|
|
1235
|
+
const b = next.rect;
|
|
1236
|
+
if (
|
|
1237
|
+
a &&
|
|
1238
|
+
b &&
|
|
1239
|
+
a.top === b.top &&
|
|
1240
|
+
a.left === b.left &&
|
|
1241
|
+
a.width === b.width &&
|
|
1242
|
+
a.height === b.height &&
|
|
1243
|
+
prev.surface === next.surface &&
|
|
1244
|
+
prev.portalParent === next.portalParent &&
|
|
1245
|
+
prev.borderRadius === next.borderRadius
|
|
1246
|
+
) {
|
|
1247
|
+
return prev;
|
|
1248
|
+
}
|
|
1249
|
+
return next;
|
|
1250
|
+
});
|
|
1251
|
+
};
|
|
1252
|
+
|
|
1253
|
+
const tick = () => {
|
|
1254
|
+
raf = 0;
|
|
1255
|
+
read();
|
|
1256
|
+
if (performance.now() < trackingUntil) {
|
|
1257
|
+
raf = requestAnimationFrame(tick);
|
|
1258
|
+
}
|
|
1259
|
+
};
|
|
1260
|
+
|
|
1261
|
+
const trackFor = (ms: number) => {
|
|
1262
|
+
trackingUntil = Math.max(trackingUntil, performance.now() + ms);
|
|
1263
|
+
if (!raf) raf = requestAnimationFrame(tick);
|
|
1264
|
+
};
|
|
1265
|
+
|
|
1266
|
+
const onResize = () => trackFor(240);
|
|
1267
|
+
window.addEventListener('resize', onResize);
|
|
1268
|
+
|
|
1269
|
+
const iframe = (() => {
|
|
1270
|
+
for (const [uuid, el] of shellui.frameRegistry.getAllIframes()) {
|
|
1271
|
+
if (uuid === actions.frameUuid && el.isConnected) return el;
|
|
1272
|
+
}
|
|
1273
|
+
return null;
|
|
1274
|
+
})();
|
|
1275
|
+
|
|
1276
|
+
const ro =
|
|
1277
|
+
typeof ResizeObserver !== 'undefined' ? new ResizeObserver(() => trackFor(240)) : null;
|
|
1278
|
+
if (iframe) {
|
|
1279
|
+
ro?.observe(iframe);
|
|
1280
|
+
if (iframe.parentElement) ro?.observe(iframe.parentElement);
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
// Floating sidebar / inset CSS vars transition — follow for the full duration.
|
|
1284
|
+
const onTransition = (event: TransitionEvent) => {
|
|
1285
|
+
const prop = event.propertyName;
|
|
1286
|
+
if (
|
|
1287
|
+
prop === 'transform' ||
|
|
1288
|
+
prop === 'width' ||
|
|
1289
|
+
prop === 'left' ||
|
|
1290
|
+
prop === 'padding-left' ||
|
|
1291
|
+
prop.startsWith('--shellui-inset') ||
|
|
1292
|
+
prop === '--shellui-chrome-actions-leading-extra'
|
|
1293
|
+
) {
|
|
1294
|
+
trackFor(240);
|
|
1295
|
+
}
|
|
1296
|
+
};
|
|
1297
|
+
document.addEventListener('transitionrun', onTransition, true);
|
|
1298
|
+
document.addEventListener('transitionstart', onTransition, true);
|
|
1299
|
+
|
|
1300
|
+
// Catch the sidebar toggle even before transition events fire.
|
|
1301
|
+
trackFor(240);
|
|
1302
|
+
|
|
1303
|
+
return () => {
|
|
1304
|
+
window.removeEventListener('resize', onResize);
|
|
1305
|
+
document.removeEventListener('transitionrun', onTransition, true);
|
|
1306
|
+
document.removeEventListener('transitionstart', onTransition, true);
|
|
1307
|
+
ro?.disconnect();
|
|
1308
|
+
if (raf) cancelAnimationFrame(raf);
|
|
1309
|
+
};
|
|
1310
|
+
}, [actions.frameUuid, refresh]);
|
|
1311
|
+
|
|
1312
|
+
const isOverlaySurface = surface === 'overlay';
|
|
1313
|
+
const isWindowSurface = surface === 'window';
|
|
1314
|
+
const useLayoutInsets = surface === 'main' || surface === 'develop';
|
|
1315
|
+
// Corner FAB inside portaled surfaces (modal/drawer/window content).
|
|
1316
|
+
const overlayFabOffset = isWindowSurface
|
|
1317
|
+
? FLOATING_CHROME_MARGIN
|
|
1318
|
+
: isOverlaySurface
|
|
1319
|
+
? chromeActionsFabBottomOffsetCss(FLOATING_CHROME_MARGIN)
|
|
1320
|
+
: fabBottomOffset;
|
|
1321
|
+
const fabSize = isOverlaySurface || isWindowSurface ? CHROME_ACTIONS_FAB_SIZE : fabSizePx;
|
|
1322
|
+
const fabEdge = isOverlaySurface || isWindowSurface ? FLOATING_CHROME_MARGIN : fabEdgeMargin;
|
|
1323
|
+
const shape = isOverlaySurface || isWindowSurface ? 'theme' : fabShape;
|
|
1324
|
+
// Overlays / windows / develop never follow floating tab-bar hide-on-scroll.
|
|
1325
|
+
const hideWithNav = scrollHidden && surface === 'main';
|
|
1326
|
+
|
|
1327
|
+
const chrome = (
|
|
1328
|
+
<>
|
|
1329
|
+
{showTop ? (
|
|
1330
|
+
<TopActionBar
|
|
1331
|
+
actions={actions}
|
|
1332
|
+
placement="overlay"
|
|
1333
|
+
visible={visible}
|
|
1334
|
+
scrollHidden={hideWithNav}
|
|
1335
|
+
useLayoutInsets={useLayoutInsets}
|
|
1336
|
+
// Modal/drawer overlays are full-bleed under the notch even on
|
|
1337
|
+
// sidebar/app-bar shells — keep safe-area for those surfaces only.
|
|
1338
|
+
honorSafeAreaTop={isOverlaySurface ? true : undefined}
|
|
1339
|
+
/>
|
|
1340
|
+
) : null}
|
|
1341
|
+
<PrimaryFab
|
|
1342
|
+
actions={actions}
|
|
1343
|
+
bottomOffset={overlayFabOffset}
|
|
1344
|
+
visible={visible}
|
|
1345
|
+
scrollHidden={hideWithNav}
|
|
1346
|
+
useLayoutInsets={useLayoutInsets}
|
|
1347
|
+
sizePx={fabSize}
|
|
1348
|
+
edgeMargin={fabEdge}
|
|
1349
|
+
shape={shape}
|
|
1350
|
+
/>
|
|
1351
|
+
</>
|
|
1352
|
+
);
|
|
1353
|
+
|
|
1354
|
+
// Overlay / window iframes: portal into ContentView root so chrome stays inside
|
|
1355
|
+
// the host surface (modal stacking, window drag/resize).
|
|
1356
|
+
if (portalParent) {
|
|
1357
|
+
return createPortal(
|
|
1358
|
+
<div
|
|
1359
|
+
data-shellui-chrome-actions=""
|
|
1360
|
+
data-shellui-chrome-actions-frame={actions.frameUuid}
|
|
1361
|
+
data-shellui-chrome-actions-surface={surface}
|
|
1362
|
+
className="pointer-events-none absolute inset-0 z-10"
|
|
1363
|
+
>
|
|
1364
|
+
{chrome}
|
|
1365
|
+
</div>,
|
|
1366
|
+
portalParent,
|
|
1367
|
+
);
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
if (!rect || rect.width < 8 || rect.height < 8) return null;
|
|
1371
|
+
|
|
1372
|
+
return (
|
|
1373
|
+
<div
|
|
1374
|
+
data-shellui-chrome-actions=""
|
|
1375
|
+
data-shellui-chrome-actions-frame={actions.frameUuid}
|
|
1376
|
+
data-shellui-chrome-actions-surface={surface}
|
|
1377
|
+
className="pointer-events-none fixed z-[46]"
|
|
1378
|
+
style={{
|
|
1379
|
+
top: rect.top,
|
|
1380
|
+
left: rect.left,
|
|
1381
|
+
width: rect.width,
|
|
1382
|
+
height: rect.height,
|
|
1383
|
+
// Mirror inset card clipping — fixed chrome is outside the iframe's
|
|
1384
|
+
// overflow:hidden, so without this the corners stay square.
|
|
1385
|
+
...(borderRadius ? { borderRadius, overflow: 'hidden' as const } : {}),
|
|
1386
|
+
}}
|
|
1387
|
+
>
|
|
1388
|
+
{chrome}
|
|
1389
|
+
</div>
|
|
1390
|
+
);
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
/**
|
|
1394
|
+
* Host chrome for SDK floating actions — top bar + bottom FAB, positioned
|
|
1395
|
+
* over each content iframe that has declared actions.
|
|
1396
|
+
*/
|
|
1397
|
+
export function ChromeActionsHost() {
|
|
1398
|
+
const live = useChromeActionsSnapshot();
|
|
1399
|
+
const presence = useChromeActionsPresence(live);
|
|
1400
|
+
const { settings } = useSettings();
|
|
1401
|
+
const viewport = useViewport();
|
|
1402
|
+
const windowsLayout = settings.layout === 'windows';
|
|
1403
|
+
const layoutChrome = usePublishedLayoutChrome();
|
|
1404
|
+
// Mobile sidebar header hosts top actions (same idea as windows title bars).
|
|
1405
|
+
const topInTitleBar =
|
|
1406
|
+
windowsLayout ||
|
|
1407
|
+
((settings.layout === 'sidebar' || settings.layout === 'sidebar-inset') &&
|
|
1408
|
+
viewport === 'mobile');
|
|
1409
|
+
|
|
1410
|
+
const floatingDock =
|
|
1411
|
+
settings.layout === 'floating' && (viewport === 'mobile' || viewport === 'tablet');
|
|
1412
|
+
// Floating dock: FAB diameter matches the bottom nav bar height (phone 56 / tablet 64).
|
|
1413
|
+
// Sidebar / app-bar: larger shell FAB so it doesn’t feel tiny against flush chrome.
|
|
1414
|
+
const fabSizePx = floatingDock
|
|
1415
|
+
? floatingTabBarHeight(viewport)
|
|
1416
|
+
: chromeActionsFabSize(viewport, { layout: settings.layout });
|
|
1417
|
+
const fabEdgeMargin = chromeActionsFabEdgeMargin(viewport);
|
|
1418
|
+
// Pill only beside the phone/tablet dock; desktop uses theme radius (square when 0).
|
|
1419
|
+
const fabShape = floatingDock ? 'pill' : 'theme';
|
|
1420
|
+
|
|
1421
|
+
const fabBottomOffset = useMemo(() => {
|
|
1422
|
+
if (floatingDock) {
|
|
1423
|
+
// Match FloatingBottomDock paddingBottom (includes safe-area CSS var).
|
|
1424
|
+
return floatingTabBarBottomPadCss(viewport);
|
|
1425
|
+
}
|
|
1426
|
+
// Sidebar / app-bar / fullscreen / floating desktop: clear home indicator.
|
|
1427
|
+
return chromeActionsFabBottomOffsetCss(fabEdgeMargin);
|
|
1428
|
+
}, [floatingDock, viewport, fabEdgeMargin]);
|
|
1429
|
+
|
|
1430
|
+
// Same hide-on-scroll signal as FloatingBottomDock (phone/tablet floating only).
|
|
1431
|
+
const scrollHidden = Boolean(
|
|
1432
|
+
layoutChrome && scrollHideApplies(layoutChrome, 'main') && layoutChrome.chromeVisible === false,
|
|
1433
|
+
);
|
|
1434
|
+
|
|
1435
|
+
if (presence.length === 0) return null;
|
|
1436
|
+
|
|
1437
|
+
return (
|
|
1438
|
+
<>
|
|
1439
|
+
{presence.map(({ actions, visible }) => (
|
|
1440
|
+
<FrameActionsOverlay
|
|
1441
|
+
key={actions.frameUuid}
|
|
1442
|
+
actions={actions}
|
|
1443
|
+
visible={visible}
|
|
1444
|
+
scrollHidden={scrollHidden}
|
|
1445
|
+
fabSizePx={fabSizePx}
|
|
1446
|
+
fabEdgeMargin={fabEdgeMargin}
|
|
1447
|
+
fabShape={fabShape}
|
|
1448
|
+
showTop={!topInTitleBar || actions.frameUuid === SHELL_DEVELOP_CHROME_ACTIONS_FRAME}
|
|
1449
|
+
// Windows: FAB lives inside the window card — no device safe-area.
|
|
1450
|
+
fabBottomOffset={windowsLayout ? FLOATING_CHROME_MARGIN : fabBottomOffset}
|
|
1451
|
+
/>
|
|
1452
|
+
))}
|
|
1453
|
+
</>
|
|
1454
|
+
);
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
/** Compact top actions for a windows-layout title bar. */
|
|
1458
|
+
export function WindowTitleBarActions({
|
|
1459
|
+
frameUuid,
|
|
1460
|
+
fallbackTitle,
|
|
1461
|
+
}: {
|
|
1462
|
+
frameUuid: string | null;
|
|
1463
|
+
fallbackTitle?: string;
|
|
1464
|
+
}) {
|
|
1465
|
+
const all = useChromeActionsSnapshot();
|
|
1466
|
+
const actions = useMemo(
|
|
1467
|
+
() => (frameUuid ? (all.find((a) => a.frameUuid === frameUuid) ?? null) : null),
|
|
1468
|
+
[all, frameUuid],
|
|
1469
|
+
);
|
|
1470
|
+
const [displayed, setDisplayed] = useState<FrameChromeActions | null>(actions);
|
|
1471
|
+
const [barVisible, setBarVisible] = useState(
|
|
1472
|
+
Boolean(actions && actionChromeFlags(actions).hasTop),
|
|
1473
|
+
);
|
|
1474
|
+
|
|
1475
|
+
useEffect(() => {
|
|
1476
|
+
if (actions && actionChromeFlags(actions).hasTop) {
|
|
1477
|
+
setDisplayed(actions.title ? actions : { ...actions, title: fallbackTitle });
|
|
1478
|
+
const id = requestAnimationFrame(() => setBarVisible(true));
|
|
1479
|
+
return () => cancelAnimationFrame(id);
|
|
1480
|
+
}
|
|
1481
|
+
setBarVisible(false);
|
|
1482
|
+
const t = window.setTimeout(() => setDisplayed(null), CHROME_ACTIONS_FADE_MS);
|
|
1483
|
+
return () => window.clearTimeout(t);
|
|
1484
|
+
}, [actions, fallbackTitle]);
|
|
1485
|
+
|
|
1486
|
+
if (displayed && actionChromeFlags(displayed).hasTop) {
|
|
1487
|
+
return (
|
|
1488
|
+
<TopActionBar
|
|
1489
|
+
actions={displayed}
|
|
1490
|
+
placement="titlebar"
|
|
1491
|
+
visible={barVisible}
|
|
1492
|
+
/>
|
|
1493
|
+
);
|
|
1494
|
+
}
|
|
1495
|
+
if (fallbackTitle) {
|
|
1496
|
+
return (
|
|
1497
|
+
<span
|
|
1498
|
+
className={cn(
|
|
1499
|
+
'min-w-0 flex-1 truncate text-sm font-medium',
|
|
1500
|
+
chromeActionsFadeClass,
|
|
1501
|
+
'opacity-100',
|
|
1502
|
+
)}
|
|
1503
|
+
>
|
|
1504
|
+
{fallbackTitle}
|
|
1505
|
+
</span>
|
|
1506
|
+
);
|
|
1507
|
+
}
|
|
1508
|
+
return <span className="min-w-0 flex-1" />;
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
export type { ChromeActionsPayload };
|