@shellui/core 0.5.0-beta.3 → 0.5.1
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 +98 -33
- package/src/app.tsx +10 -4
- package/src/components/ContentView.tsx +3 -5
- package/src/components/contentIframeSandbox.spec.ts +25 -0
- package/src/components/contentIframeSandbox.ts +43 -0
- 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 +3 -2
- package/src/components/ui/tabs.tsx +52 -0
- package/src/constants/urls.ts +1 -0
- package/src/features/auth/AuthProvider.tsx +169 -35
- package/src/features/auth/backends/index.ts +2 -0
- package/src/features/auth/backends/shellui.ts +43 -35
- package/src/features/auth/backends/supabase.ts +1 -0
- package/src/features/auth/backends/types.ts +5 -0
- package/src/features/auth/components/LoginView.tsx +5 -1
- package/src/features/auth/components/OAuthCallbackView.tsx +115 -44
- package/src/features/auth/constants/oauth.ts +2 -0
- package/src/features/auth/hooks/useAuth.tsx +4 -0
- package/src/features/auth/utils/authSessionPersistence.spec.ts +93 -0
- package/src/features/auth/utils/authSessionPersistence.ts +138 -0
- package/src/features/auth/utils/authStorageKeys.ts +8 -0
- package/src/features/auth/utils/bffAuthClient.ts +107 -0
- package/src/features/auth/utils/buildOAuthSessionRedirectTo.spec.ts +22 -0
- package/src/features/auth/utils/buildOAuthSessionRedirectTo.ts +17 -0
- package/src/features/auth/utils/buildSessionFromTokenPayload.spec.ts +29 -0
- package/src/features/auth/utils/buildSessionFromTokenPayload.ts +24 -0
- package/src/features/auth/utils/index.ts +18 -3
- package/src/features/auth/utils/isBffAuthEnabled.ts +12 -0
- 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 +49 -2
- package/src/features/layouts/AppLayout.tsx +4 -4
- package/src/features/layouts/OverlayShell.tsx +60 -12
- package/src/features/layouts/app-bar-inset/AppBarInsetLayout.tsx +1 -1
- package/src/features/layouts/appbar/AppBarLayout.tsx +194 -89
- 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 +31 -21
- package/src/features/layouts/floating/FloatingStatusScrim.tsx +36 -0
- package/src/features/layouts/floating/computeFloatingInsets.spec.ts +5 -5
- package/src/features/layouts/floating/computeFloatingInsets.ts +64 -12
- package/src/features/layouts/floating/isShellOwnedPath.spec.ts +2 -0
- package/src/features/layouts/floating/isShellOwnedPath.ts +1 -0
- package/src/features/layouts/floating/layoutChromeStore.spec.ts +138 -0
- package/src/features/layouts/floating/layoutChromeStore.ts +169 -6
- package/src/features/layouts/floating/useFloatingChrome.ts +20 -30
- package/src/features/layouts/sidebar/SidebarLayout.tsx +87 -31
- package/src/features/layouts/sidebar-inset/SidebarInsetLayout.tsx +1 -1
- package/src/features/layouts/windows/WindowsLayout.tsx +240 -110
- package/src/features/messaging/MessagingSecurityBootstrap.tsx +19 -0
- package/src/features/messaging/deriveAllowedMessageOrigins.spec.ts +86 -0
- package/src/features/messaging/deriveAllowedMessageOrigins.ts +74 -0
- package/src/features/modal/ModalContext.spec.ts +13 -2
- package/src/features/modal/validateAndNormalizeUrl.ts +9 -23
- 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/security/trustedFrames.spec.ts +129 -0
- package/src/features/security/trustedFrames.ts +79 -0
- package/src/features/security/urlAllowlist.spec.ts +99 -0
- package/src/features/security/urlAllowlist.ts +122 -0
- package/src/features/settings/SettingsProvider.tsx +38 -54
- package/src/features/settings/components/Develop.tsx +2 -0
- package/src/features/settings/components/develop/ChromeActionsTestButtons.tsx +63 -0
- package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +23 -1
- package/src/features/settings/utils/buildSettingsForPropagation.ts +7 -0
- package/src/features/storage/StorageBridge.spec.ts +82 -0
- package/src/features/storage/StorageBridge.tsx +25 -3
- package/src/features/storage/StoragePickerContext.tsx +3 -4
- package/src/features/storage/uploads/uploadQueue.spec.ts +56 -1
- package/src/features/storage/uploads/uploadQueue.ts +44 -6
- package/src/features/theme/applyTheme.ts +23 -5
- package/src/hooks/use-mobile.tsx +21 -7
- package/src/i18n/translations/en/settings.json +9 -0
- package/src/i18n/translations/fr/settings.json +9 -0
- package/src/index.css +264 -124
- package/src/index.html +6 -4
- package/src/index.ts +8 -0
- package/src/routes/components/NavigationItemRoute.tsx +30 -15
- package/src/routes/components/RouteFallback.tsx +15 -0
- package/src/routes/routes.tsx +14 -0
- package/src/routes/utils/navigationRouteAccess.spec.ts +85 -0
- package/src/routes/utils/navigationRouteAccess.ts +43 -0
- package/src/features/auth/utils/clearStoredAuthSession.spec.ts +0 -23
- package/src/features/auth/utils/clearStoredAuthSession.ts +0 -10
- package/src/features/auth/utils/persistAuthSession.spec.ts +0 -35
- package/src/features/auth/utils/persistAuthSession.ts +0 -12
- package/src/features/auth/utils/readStoredAuthSession.spec.ts +0 -34
- package/src/features/auth/utils/readStoredAuthSession.ts +0 -14
- package/src/features/layouts/floating/FloatingFadeMask.tsx +0 -22
- package/src/features/layouts/floating/FloatingTabBar.tsx +0 -437
- package/src/features/layouts/floating/FloatingTabIndicator.tsx +0 -216
|
@@ -1,437 +0,0 @@
|
|
|
1
|
-
import { Link, useLocation } from 'react-router';
|
|
2
|
-
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
-
import { useTranslation } from 'react-i18next';
|
|
4
|
-
import { shellui } from '@shellui/sdk';
|
|
5
|
-
import type { NavigationItem } from '../../config/types';
|
|
6
|
-
import {
|
|
7
|
-
flattenNavigationItems,
|
|
8
|
-
getActivePathPrefix,
|
|
9
|
-
getNavPathPrefix,
|
|
10
|
-
resolveLocalizedString,
|
|
11
|
-
} from '../utils';
|
|
12
|
-
import { getExternalFaviconUrl } from '../sidebar/sidebarUtils';
|
|
13
|
-
import { NavIcon } from '../sidebar/SidebarIcons';
|
|
14
|
-
import { LoginButton } from '../../auth/components/LoginButton';
|
|
15
|
-
import { cn } from '../../../lib/utils';
|
|
16
|
-
import {
|
|
17
|
-
FLOATING_CHROME_MARGIN,
|
|
18
|
-
FLOATING_MAX_TAB_SLOTS,
|
|
19
|
-
FLOATING_TAB_BAR_HEIGHT,
|
|
20
|
-
} from './computeFloatingInsets';
|
|
21
|
-
import type { ShellViewport } from '../../../hooks/use-viewport';
|
|
22
|
-
import { FloatingTabIndicator } from './FloatingTabIndicator';
|
|
23
|
-
|
|
24
|
-
type TabPlacement = 'bottom' | 'top';
|
|
25
|
-
|
|
26
|
-
const MORE_TAB_KEY = '__more__';
|
|
27
|
-
|
|
28
|
-
function itemIconSrc(item: NavigationItem): string | null {
|
|
29
|
-
if (item.icon) return item.icon;
|
|
30
|
-
if (item.openIn === 'external') return getExternalFaviconUrl(item.url);
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function TabGlyph({ item, label }: { item: NavigationItem; label: string }) {
|
|
35
|
-
const iconSrc = itemIconSrc(item);
|
|
36
|
-
if (iconSrc) {
|
|
37
|
-
return (
|
|
38
|
-
<NavIcon
|
|
39
|
-
src={iconSrc}
|
|
40
|
-
className="size-6"
|
|
41
|
-
/>
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
return (
|
|
45
|
-
<span className="flex size-6 items-center justify-center text-[13px] font-semibold leading-none">
|
|
46
|
-
{label.charAt(0).toUpperCase() || '?'}
|
|
47
|
-
</span>
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function itemKey(item: NavigationItem): string {
|
|
52
|
-
return `${item.path}-${item.url}`;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const tabClassName =
|
|
56
|
-
'shellui-floating-tab relative z-[1] flex h-full min-w-0 flex-1 basis-0 flex-col items-center justify-center gap-0.5 px-1.5 py-1 text-[10px] font-medium transition-colors duration-200';
|
|
57
|
-
|
|
58
|
-
/** Floating glass tab bar — bottom-centered on phone and tablet. */
|
|
59
|
-
export function FloatingTabBar({
|
|
60
|
-
items,
|
|
61
|
-
endItems = [],
|
|
62
|
-
showAuthButton = false,
|
|
63
|
-
placement,
|
|
64
|
-
chromeVisible,
|
|
65
|
-
viewport,
|
|
66
|
-
}: {
|
|
67
|
-
items: NavigationItem[];
|
|
68
|
-
/** `position: 'end'` links (settings, login, …) — shown in the More sheet. */
|
|
69
|
-
endItems?: NavigationItem[];
|
|
70
|
-
/** Account / login control when the login nav item is hidden (logged in). */
|
|
71
|
-
showAuthButton?: boolean;
|
|
72
|
-
placement: TabPlacement;
|
|
73
|
-
chromeVisible: boolean;
|
|
74
|
-
/** Used for bottom safe-area padding (phone vs tablet). */
|
|
75
|
-
viewport: ShellViewport;
|
|
76
|
-
}) {
|
|
77
|
-
const location = useLocation();
|
|
78
|
-
const { i18n, t } = useTranslation('settings');
|
|
79
|
-
const lang = i18n.language || 'en';
|
|
80
|
-
const [moreOpen, setMoreOpen] = useState(false);
|
|
81
|
-
const navRef = useRef<HTMLElement>(null);
|
|
82
|
-
const tabElsRef = useRef(new Map<string, HTMLElement>());
|
|
83
|
-
const [activeEl, setActiveEl] = useState<HTMLElement | null>(null);
|
|
84
|
-
|
|
85
|
-
const flat = useMemo(() => flattenNavigationItems(items), [items]);
|
|
86
|
-
// Cap at 4 slots total: reserve one for More when overflow or end/auth extras exist.
|
|
87
|
-
const showMore = endItems.length > 0 || showAuthButton || flat.length > FLOATING_MAX_TAB_SLOTS;
|
|
88
|
-
const maxPrimary = showMore ? FLOATING_MAX_TAB_SLOTS - 1 : FLOATING_MAX_TAB_SLOTS;
|
|
89
|
-
const primary = useMemo(() => flat.slice(0, maxPrimary), [flat, maxPrimary]);
|
|
90
|
-
// Keep config order. flex-col-reverse places the first DOM node nearest More
|
|
91
|
-
// (bottom → top): overflow links, divider, end links, then account.
|
|
92
|
-
const moreOverflowItems = useMemo(() => flat.slice(maxPrimary), [flat, maxPrimary]);
|
|
93
|
-
const moreEndItems = endItems;
|
|
94
|
-
const moreItems = useMemo(
|
|
95
|
-
() => [...moreOverflowItems, ...moreEndItems],
|
|
96
|
-
[moreOverflowItems, moreEndItems],
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
const activePathPrefix = useMemo(
|
|
100
|
-
() => getActivePathPrefix(location.pathname, [...flat, ...endItems]),
|
|
101
|
-
[location.pathname, flat, endItems],
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
const moreActive = useMemo(
|
|
105
|
-
() =>
|
|
106
|
-
moreItems.some((item) => {
|
|
107
|
-
if (item.openIn === 'modal' || item.openIn === 'drawer' || item.openIn === 'external') {
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
return getNavPathPrefix(item) === activePathPrefix;
|
|
111
|
-
}),
|
|
112
|
-
[moreItems, activePathPrefix],
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
const activeTabKey = useMemo(() => {
|
|
116
|
-
if (moreActive || moreOpen) return MORE_TAB_KEY;
|
|
117
|
-
const active = primary.find((item) => {
|
|
118
|
-
if (item.openIn === 'modal' || item.openIn === 'drawer' || item.openIn === 'external') {
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
return getNavPathPrefix(item) === activePathPrefix;
|
|
122
|
-
});
|
|
123
|
-
return active ? itemKey(active) : null;
|
|
124
|
-
}, [moreActive, moreOpen, primary, activePathPrefix]);
|
|
125
|
-
|
|
126
|
-
const setTabEl = (key: string, node: HTMLElement | null) => {
|
|
127
|
-
if (node) tabElsRef.current.set(key, node);
|
|
128
|
-
else tabElsRef.current.delete(key);
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
useLayoutEffect(() => {
|
|
132
|
-
if (!activeTabKey) {
|
|
133
|
-
setActiveEl(null);
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
setActiveEl(tabElsRef.current.get(activeTabKey) ?? null);
|
|
137
|
-
}, [activeTabKey, primary, showMore]);
|
|
138
|
-
|
|
139
|
-
useEffect(() => {
|
|
140
|
-
setMoreOpen(false);
|
|
141
|
-
}, [location.pathname]);
|
|
142
|
-
|
|
143
|
-
useEffect(() => {
|
|
144
|
-
if (!chromeVisible) setMoreOpen(false);
|
|
145
|
-
}, [chromeVisible]);
|
|
146
|
-
|
|
147
|
-
const renderItem = (navItem: NavigationItem) => {
|
|
148
|
-
const pathPrefix = getNavPathPrefix(navItem);
|
|
149
|
-
const label = resolveLocalizedString(navItem.label, lang);
|
|
150
|
-
const isOverlay = navItem.openIn === 'modal' || navItem.openIn === 'drawer';
|
|
151
|
-
const isExternal = navItem.openIn === 'external';
|
|
152
|
-
const isActive = !isOverlay && !isExternal && pathPrefix === activePathPrefix;
|
|
153
|
-
const key = itemKey(navItem);
|
|
154
|
-
// Match the sliding pill: when More is open, primary tabs lose selected text.
|
|
155
|
-
const isPillSelected = activeTabKey === key;
|
|
156
|
-
|
|
157
|
-
const className = cn(
|
|
158
|
-
tabClassName,
|
|
159
|
-
isPillSelected
|
|
160
|
-
? 'text-sidebar-primary-foreground'
|
|
161
|
-
: 'text-sidebar-foreground/70 hover:text-sidebar-accent-foreground',
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
const body = (
|
|
165
|
-
<>
|
|
166
|
-
<TabGlyph
|
|
167
|
-
item={navItem}
|
|
168
|
-
label={label}
|
|
169
|
-
/>
|
|
170
|
-
<span className="w-full truncate text-center leading-tight">{label}</span>
|
|
171
|
-
</>
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
const bindRef = (node: HTMLElement | null) => setTabEl(key, node);
|
|
175
|
-
|
|
176
|
-
if (navItem.openIn === 'modal') {
|
|
177
|
-
return (
|
|
178
|
-
<button
|
|
179
|
-
key={key}
|
|
180
|
-
ref={bindRef}
|
|
181
|
-
type="button"
|
|
182
|
-
className={className}
|
|
183
|
-
onClick={() => shellui.openModal(navItem.url)}
|
|
184
|
-
>
|
|
185
|
-
{body}
|
|
186
|
-
</button>
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
if (navItem.openIn === 'drawer') {
|
|
190
|
-
return (
|
|
191
|
-
<button
|
|
192
|
-
key={key}
|
|
193
|
-
ref={bindRef}
|
|
194
|
-
type="button"
|
|
195
|
-
className={className}
|
|
196
|
-
onClick={() =>
|
|
197
|
-
shellui.openDrawer({
|
|
198
|
-
url: navItem.url,
|
|
199
|
-
position: navItem.drawerPosition || 'right',
|
|
200
|
-
})
|
|
201
|
-
}
|
|
202
|
-
>
|
|
203
|
-
{body}
|
|
204
|
-
</button>
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
if (isExternal) {
|
|
208
|
-
return (
|
|
209
|
-
<a
|
|
210
|
-
key={key}
|
|
211
|
-
ref={bindRef}
|
|
212
|
-
href={navItem.url}
|
|
213
|
-
target="_blank"
|
|
214
|
-
rel="noopener noreferrer"
|
|
215
|
-
className={className}
|
|
216
|
-
>
|
|
217
|
-
{body}
|
|
218
|
-
</a>
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return (
|
|
223
|
-
<Link
|
|
224
|
-
key={key}
|
|
225
|
-
ref={bindRef}
|
|
226
|
-
to={pathPrefix}
|
|
227
|
-
className={className}
|
|
228
|
-
aria-current={isActive ? 'page' : undefined}
|
|
229
|
-
>
|
|
230
|
-
{body}
|
|
231
|
-
</Link>
|
|
232
|
-
);
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
const renderMoreRow = (item: NavigationItem) => {
|
|
236
|
-
const label = resolveLocalizedString(item.label, lang);
|
|
237
|
-
const pathPrefix = getNavPathPrefix(item);
|
|
238
|
-
const isActive =
|
|
239
|
-
item.openIn !== 'modal' &&
|
|
240
|
-
item.openIn !== 'drawer' &&
|
|
241
|
-
item.openIn !== 'external' &&
|
|
242
|
-
pathPrefix === activePathPrefix;
|
|
243
|
-
const rowClass = cn(
|
|
244
|
-
'shellui-floating-nav-item flex w-full min-w-0 items-center gap-2 px-3 py-2.5 text-left text-sm text-sidebar-foreground',
|
|
245
|
-
'hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',
|
|
246
|
-
isActive && 'bg-sidebar-accent font-medium text-sidebar-accent-foreground',
|
|
247
|
-
);
|
|
248
|
-
const close = () => setMoreOpen(false);
|
|
249
|
-
const labelEl = <span className="min-w-0 flex-1 truncate">{label}</span>;
|
|
250
|
-
const iconEl = (
|
|
251
|
-
<TabGlyph
|
|
252
|
-
item={item}
|
|
253
|
-
label={label}
|
|
254
|
-
/>
|
|
255
|
-
);
|
|
256
|
-
|
|
257
|
-
if (item.openIn === 'modal') {
|
|
258
|
-
return (
|
|
259
|
-
<button
|
|
260
|
-
key={itemKey(item)}
|
|
261
|
-
type="button"
|
|
262
|
-
className={rowClass}
|
|
263
|
-
onClick={() => {
|
|
264
|
-
close();
|
|
265
|
-
shellui.openModal(item.url);
|
|
266
|
-
}}
|
|
267
|
-
>
|
|
268
|
-
{iconEl}
|
|
269
|
-
{labelEl}
|
|
270
|
-
</button>
|
|
271
|
-
);
|
|
272
|
-
}
|
|
273
|
-
if (item.openIn === 'drawer') {
|
|
274
|
-
return (
|
|
275
|
-
<button
|
|
276
|
-
key={itemKey(item)}
|
|
277
|
-
type="button"
|
|
278
|
-
className={rowClass}
|
|
279
|
-
onClick={() => {
|
|
280
|
-
close();
|
|
281
|
-
shellui.openDrawer({
|
|
282
|
-
url: item.url,
|
|
283
|
-
position: item.drawerPosition || 'right',
|
|
284
|
-
});
|
|
285
|
-
}}
|
|
286
|
-
>
|
|
287
|
-
{iconEl}
|
|
288
|
-
{labelEl}
|
|
289
|
-
</button>
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
if (item.openIn === 'external') {
|
|
293
|
-
return (
|
|
294
|
-
<a
|
|
295
|
-
key={itemKey(item)}
|
|
296
|
-
href={item.url}
|
|
297
|
-
target="_blank"
|
|
298
|
-
rel="noopener noreferrer"
|
|
299
|
-
className={rowClass}
|
|
300
|
-
onClick={close}
|
|
301
|
-
>
|
|
302
|
-
{iconEl}
|
|
303
|
-
{labelEl}
|
|
304
|
-
</a>
|
|
305
|
-
);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
return (
|
|
309
|
-
<Link
|
|
310
|
-
key={itemKey(item)}
|
|
311
|
-
to={pathPrefix}
|
|
312
|
-
className={rowClass}
|
|
313
|
-
onClick={() => {
|
|
314
|
-
// Keep moreOpen until the route updates so the tab pill stays on More
|
|
315
|
-
// instead of animating back to the previous primary tab mid-navigation.
|
|
316
|
-
if (pathPrefix === activePathPrefix) close();
|
|
317
|
-
}}
|
|
318
|
-
aria-current={isActive ? 'page' : undefined}
|
|
319
|
-
>
|
|
320
|
-
{iconEl}
|
|
321
|
-
{labelEl}
|
|
322
|
-
</Link>
|
|
323
|
-
);
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
return (
|
|
327
|
-
<>
|
|
328
|
-
{/*
|
|
329
|
-
Full-screen dismiss above iframe content. Document listeners never see
|
|
330
|
-
taps inside cross-origin iframes (common on iPhone), so catch them here.
|
|
331
|
-
*/}
|
|
332
|
-
{moreOpen ? (
|
|
333
|
-
<div
|
|
334
|
-
aria-hidden
|
|
335
|
-
data-shellui-floating-more-dismiss=""
|
|
336
|
-
className="fixed inset-0 z-[44] cursor-pointer touch-manipulation"
|
|
337
|
-
style={{ backgroundColor: 'rgba(0,0,0,0.001)' }}
|
|
338
|
-
onPointerDown={(event) => {
|
|
339
|
-
event.preventDefault();
|
|
340
|
-
setMoreOpen(false);
|
|
341
|
-
}}
|
|
342
|
-
/>
|
|
343
|
-
) : null}
|
|
344
|
-
<div
|
|
345
|
-
data-shellui-floating-tabbar={placement}
|
|
346
|
-
data-chrome-visible={chromeVisible ? 'true' : 'false'}
|
|
347
|
-
className={cn(
|
|
348
|
-
'pointer-events-none absolute z-[45] flex justify-center',
|
|
349
|
-
placement === 'bottom' ? 'inset-x-0 bottom-0' : 'inset-x-0 top-0',
|
|
350
|
-
)}
|
|
351
|
-
style={{
|
|
352
|
-
paddingLeft: `calc(20px + var(--shellui-safe-area-left, 0px))`,
|
|
353
|
-
paddingRight: `calc(20px + var(--shellui-safe-area-right, 0px))`,
|
|
354
|
-
paddingBottom:
|
|
355
|
-
placement === 'bottom'
|
|
356
|
-
? viewport === 'mobile'
|
|
357
|
-
? // Half margin+safe so the bar sits lower on iPhone.
|
|
358
|
-
`calc((${FLOATING_CHROME_MARGIN}px + var(--shellui-safe-area-bottom, 0px)) / 2)`
|
|
359
|
-
: `calc(${FLOATING_CHROME_MARGIN}px + var(--shellui-safe-area-bottom, 0px))`
|
|
360
|
-
: undefined,
|
|
361
|
-
paddingTop:
|
|
362
|
-
placement === 'top'
|
|
363
|
-
? `calc(${FLOATING_CHROME_MARGIN}px + var(--shellui-safe-area-top, 0px))`
|
|
364
|
-
: undefined,
|
|
365
|
-
}}
|
|
366
|
-
>
|
|
367
|
-
<nav
|
|
368
|
-
ref={navRef}
|
|
369
|
-
aria-label={t('develop.layout.floating', { defaultValue: 'Floating' })}
|
|
370
|
-
className={cn(
|
|
371
|
-
'shellui-floating-glass pointer-events-auto relative flex origin-center max-w-lg items-stretch gap-1 px-2 py-1.5',
|
|
372
|
-
placement === 'top' && 'w-auto min-w-[min(100%,28rem)] max-w-2xl scale-105',
|
|
373
|
-
placement === 'bottom' && 'w-full',
|
|
374
|
-
)}
|
|
375
|
-
style={{ height: FLOATING_TAB_BAR_HEIGHT }}
|
|
376
|
-
>
|
|
377
|
-
<FloatingTabIndicator
|
|
378
|
-
navRef={navRef}
|
|
379
|
-
activeEl={activeEl}
|
|
380
|
-
/>
|
|
381
|
-
{primary.map(renderItem)}
|
|
382
|
-
{showMore ? (
|
|
383
|
-
<div
|
|
384
|
-
ref={(node) => setTabEl(MORE_TAB_KEY, node)}
|
|
385
|
-
className="relative z-[1] flex min-w-0 flex-1 basis-0"
|
|
386
|
-
>
|
|
387
|
-
<button
|
|
388
|
-
type="button"
|
|
389
|
-
className={cn(
|
|
390
|
-
tabClassName,
|
|
391
|
-
activeTabKey === MORE_TAB_KEY
|
|
392
|
-
? 'text-sidebar-primary-foreground'
|
|
393
|
-
: 'text-sidebar-foreground/70 hover:text-sidebar-accent-foreground',
|
|
394
|
-
)}
|
|
395
|
-
aria-expanded={moreOpen}
|
|
396
|
-
aria-haspopup="menu"
|
|
397
|
-
onClick={() => setMoreOpen((v) => !v)}
|
|
398
|
-
>
|
|
399
|
-
<span className="flex size-6 shrink-0 items-center justify-center text-xl leading-none">
|
|
400
|
-
…
|
|
401
|
-
</span>
|
|
402
|
-
<span className="w-full truncate text-center leading-tight">
|
|
403
|
-
{t('develop.layout.more', { defaultValue: 'More' })}
|
|
404
|
-
</span>
|
|
405
|
-
</button>
|
|
406
|
-
{moreOpen ? (
|
|
407
|
-
<div
|
|
408
|
-
role="menu"
|
|
409
|
-
className={cn(
|
|
410
|
-
'shellui-floating-glass shellui-floating-glass-menu absolute right-0 z-50 flex max-h-[min(70vh,24rem)] w-max min-w-[11rem] max-w-[min(18rem,calc(100vw-1.5rem))] flex-col-reverse gap-0.5 overflow-y-auto overscroll-contain p-2 shadow-lg',
|
|
411
|
-
placement === 'bottom'
|
|
412
|
-
? 'bottom-[calc(100%+0.5rem)]'
|
|
413
|
-
: 'top-[calc(100%+0.5rem)]',
|
|
414
|
-
)}
|
|
415
|
-
>
|
|
416
|
-
{moreOverflowItems.map(renderMoreRow)}
|
|
417
|
-
{moreOverflowItems.length > 0 && (moreEndItems.length > 0 || showAuthButton) ? (
|
|
418
|
-
<div
|
|
419
|
-
role="separator"
|
|
420
|
-
className="my-1 border-t border-sidebar-border"
|
|
421
|
-
/>
|
|
422
|
-
) : null}
|
|
423
|
-
{moreEndItems.map(renderMoreRow)}
|
|
424
|
-
{showAuthButton ? (
|
|
425
|
-
<div className="px-1 pt-1">
|
|
426
|
-
<LoginButton variant="sidebar" />
|
|
427
|
-
</div>
|
|
428
|
-
) : null}
|
|
429
|
-
</div>
|
|
430
|
-
) : null}
|
|
431
|
-
</div>
|
|
432
|
-
) : null}
|
|
433
|
-
</nav>
|
|
434
|
-
</div>
|
|
435
|
-
</>
|
|
436
|
-
);
|
|
437
|
-
}
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import { useLayoutEffect, useRef } from 'react';
|
|
2
|
-
|
|
3
|
-
type IndicatorBox = { left: number; width: number; top: number; height: number };
|
|
4
|
-
|
|
5
|
-
/** Baseline travel speed for a typical adjacent hop (px / ms). */
|
|
6
|
-
const INDICATOR_SPEED_PX_PER_MS = 0.85;
|
|
7
|
-
/**
|
|
8
|
-
* Distance → time exponent. 1 = fully linear; lower = long hops stay relatively faster.
|
|
9
|
-
* e.g. 0.75 → 4× distance ≈ 2.8× duration instead of 4×.
|
|
10
|
-
*/
|
|
11
|
-
const INDICATOR_DISTANCE_EXPONENT = 0.75;
|
|
12
|
-
/** Reference distance (px) where travel time matches pure linear speed. */
|
|
13
|
-
const INDICATOR_DISTANCE_REF_PX = 90;
|
|
14
|
-
/** Fixed settle after arrival — not mixed into travel. */
|
|
15
|
-
const INDICATOR_SETTLE_MS = 80;
|
|
16
|
-
/** Short press-scale on the whole floating nav — runs with the pill travel. */
|
|
17
|
-
const NAV_CLICK_SCALE = 0.96;
|
|
18
|
-
const NAV_CLICK_SCALE_MS = 200;
|
|
19
|
-
|
|
20
|
-
function prefersReducedMotion(): boolean {
|
|
21
|
-
if (typeof window === 'undefined' || !window.matchMedia) return false;
|
|
22
|
-
return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** Brief scale pulse on the glass bar so a tab change feels like a tap. */
|
|
26
|
-
function playNavClickScale(nav: HTMLElement): Animation {
|
|
27
|
-
return nav.animate(
|
|
28
|
-
[
|
|
29
|
-
{ transform: 'scale(1)' },
|
|
30
|
-
{ transform: `scale(${NAV_CLICK_SCALE})`, offset: 0.35 },
|
|
31
|
-
{ transform: 'scale(1)' },
|
|
32
|
-
],
|
|
33
|
-
{
|
|
34
|
-
duration: NAV_CLICK_SCALE_MS,
|
|
35
|
-
easing: 'cubic-bezier(0.25, 0.1, 0.25, 1)',
|
|
36
|
-
},
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function readBox(nav: HTMLElement, tab: HTMLElement): IndicatorBox {
|
|
41
|
-
const navRect = nav.getBoundingClientRect();
|
|
42
|
-
const tabRect = tab.getBoundingClientRect();
|
|
43
|
-
return {
|
|
44
|
-
left: tabRect.left - navRect.left,
|
|
45
|
-
width: tabRect.width,
|
|
46
|
-
top: tabRect.top - navRect.top,
|
|
47
|
-
height: tabRect.height,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function applyBox(pill: HTMLElement, box: IndicatorBox) {
|
|
52
|
-
pill.style.transform = `translate3d(${box.left}px, ${box.top}px, 0)`;
|
|
53
|
-
pill.style.width = `${box.width}px`;
|
|
54
|
-
pill.style.height = `${box.height}px`;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function centerX(box: IndicatorBox): number {
|
|
58
|
-
return box.left + box.width / 2;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/** Sub-linear travel time: longer hops take longer, but less than 1:1 with distance. */
|
|
62
|
-
function travelMsForDistance(dist: number): number {
|
|
63
|
-
if (dist < 0.5) return 0;
|
|
64
|
-
const linearRefMs = INDICATOR_DISTANCE_REF_PX / INDICATOR_SPEED_PX_PER_MS;
|
|
65
|
-
return linearRefMs * Math.pow(dist / INDICATOR_DISTANCE_REF_PX, INDICATOR_DISTANCE_EXPONENT);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Travel time grows with distance (sub-linear); settle is appended after.
|
|
70
|
-
* Keyframe offsets scale so morph timing tracks that travel window.
|
|
71
|
-
*/
|
|
72
|
-
function timingForDistance(dist: number): { duration: number; tMid: number; tArrive: number } {
|
|
73
|
-
const travelMs = travelMsForDistance(dist);
|
|
74
|
-
const duration = Math.round(travelMs + INDICATOR_SETTLE_MS);
|
|
75
|
-
const tArrive = travelMs <= 0 ? 0.55 : travelMs / duration;
|
|
76
|
-
return { duration, tMid: tArrive * 0.5, tArrive };
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Shared selection pill that slides between tabs.
|
|
81
|
-
* Mid-travel it widens and squashes (shape morph) while the center still
|
|
82
|
-
* covers the full gap; then a short settle. The whole floating nav gets a
|
|
83
|
-
* short press-scale in parallel so the change reads as a tap.
|
|
84
|
-
*/
|
|
85
|
-
export function FloatingTabIndicator({
|
|
86
|
-
navRef,
|
|
87
|
-
activeEl,
|
|
88
|
-
}: {
|
|
89
|
-
navRef: React.RefObject<HTMLElement | null>;
|
|
90
|
-
activeEl: HTMLElement | null;
|
|
91
|
-
}) {
|
|
92
|
-
const pillRef = useRef<HTMLDivElement>(null);
|
|
93
|
-
const fromRef = useRef<IndicatorBox | null>(null);
|
|
94
|
-
const animRef = useRef<Animation | null>(null);
|
|
95
|
-
const clickAnimRef = useRef<Animation | null>(null);
|
|
96
|
-
|
|
97
|
-
useLayoutEffect(() => {
|
|
98
|
-
const nav = navRef.current;
|
|
99
|
-
const pill = pillRef.current;
|
|
100
|
-
if (!nav || !pill) return;
|
|
101
|
-
|
|
102
|
-
if (!activeEl) {
|
|
103
|
-
pill.style.opacity = '0';
|
|
104
|
-
fromRef.current = null;
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const to = readBox(nav, activeEl);
|
|
109
|
-
const from = fromRef.current;
|
|
110
|
-
pill.style.opacity = '1';
|
|
111
|
-
|
|
112
|
-
if (!from || prefersReducedMotion()) {
|
|
113
|
-
animRef.current?.cancel();
|
|
114
|
-
clickAnimRef.current?.cancel();
|
|
115
|
-
applyBox(pill, to);
|
|
116
|
-
fromRef.current = to;
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const fromCx = centerX(from);
|
|
121
|
-
const toCx = centerX(to);
|
|
122
|
-
const dx = toCx - fromCx;
|
|
123
|
-
const dist = Math.abs(dx);
|
|
124
|
-
if (dist < 0.5 && Math.abs(to.width - from.width) < 0.5) {
|
|
125
|
-
applyBox(pill, to);
|
|
126
|
-
fromRef.current = to;
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// Stretch toward the span while the center still travels halfway — full slide, visible morph.
|
|
131
|
-
const spanLeft = Math.min(from.left, to.left);
|
|
132
|
-
const spanRight = Math.max(from.left + from.width, to.left + to.width);
|
|
133
|
-
const spanWidth = spanRight - spanLeft;
|
|
134
|
-
const baseMidWidth = (from.width + to.width) / 2;
|
|
135
|
-
const midWidth = baseMidWidth + (spanWidth - baseMidWidth) * 0.35;
|
|
136
|
-
const midCx = fromCx + dx * 0.5;
|
|
137
|
-
const midLeft = midCx - midWidth / 2;
|
|
138
|
-
const overshoot = Math.min(4, dist * 0.03) * Math.sign(dx || 1);
|
|
139
|
-
const { duration, tMid, tArrive } = timingForDistance(dist);
|
|
140
|
-
|
|
141
|
-
animRef.current?.cancel();
|
|
142
|
-
clickAnimRef.current?.cancel();
|
|
143
|
-
clickAnimRef.current = playNavClickScale(nav);
|
|
144
|
-
|
|
145
|
-
const animation = pill.animate(
|
|
146
|
-
[
|
|
147
|
-
{
|
|
148
|
-
transform: `translate3d(${from.left}px, ${from.top}px, 0) scaleY(1)`,
|
|
149
|
-
width: `${from.width}px`,
|
|
150
|
-
height: `${from.height}px`,
|
|
151
|
-
offset: 0,
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
transform: `translate3d(${midLeft}px, ${to.top + to.height * 0.05}px, 0) scaleY(0.84)`,
|
|
155
|
-
width: `${midWidth}px`,
|
|
156
|
-
height: `${to.height}px`,
|
|
157
|
-
offset: tMid,
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
transform: `translate3d(${to.left + overshoot}px, ${to.top}px, 0) scaleY(1.05)`,
|
|
161
|
-
width: `${to.width}px`,
|
|
162
|
-
height: `${to.height}px`,
|
|
163
|
-
offset: Math.min(tArrive, 0.98),
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
transform: `translate3d(${to.left}px, ${to.top}px, 0) scaleY(1)`,
|
|
167
|
-
width: `${to.width}px`,
|
|
168
|
-
height: `${to.height}px`,
|
|
169
|
-
offset: 1,
|
|
170
|
-
},
|
|
171
|
-
],
|
|
172
|
-
{
|
|
173
|
-
duration,
|
|
174
|
-
// Linear timing so distance maps 1:1 to travel time (bounce lives in keyframes).
|
|
175
|
-
easing: 'linear',
|
|
176
|
-
fill: 'forwards',
|
|
177
|
-
},
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
animRef.current = animation;
|
|
181
|
-
animation.finished
|
|
182
|
-
.then(() => {
|
|
183
|
-
if (animRef.current !== animation) return;
|
|
184
|
-
applyBox(pill, to);
|
|
185
|
-
animation.cancel();
|
|
186
|
-
})
|
|
187
|
-
.catch(() => {
|
|
188
|
-
/* cancelled */
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
fromRef.current = to;
|
|
192
|
-
}, [navRef, activeEl]);
|
|
193
|
-
|
|
194
|
-
useLayoutEffect(() => {
|
|
195
|
-
const nav = navRef.current;
|
|
196
|
-
if (!nav) return;
|
|
197
|
-
const ro = new ResizeObserver(() => {
|
|
198
|
-
const pill = pillRef.current;
|
|
199
|
-
if (!pill || !activeEl || animRef.current?.playState === 'running') return;
|
|
200
|
-
const box = readBox(nav, activeEl);
|
|
201
|
-
applyBox(pill, box);
|
|
202
|
-
fromRef.current = box;
|
|
203
|
-
});
|
|
204
|
-
ro.observe(nav);
|
|
205
|
-
return () => ro.disconnect();
|
|
206
|
-
}, [navRef, activeEl]);
|
|
207
|
-
|
|
208
|
-
return (
|
|
209
|
-
<div
|
|
210
|
-
ref={pillRef}
|
|
211
|
-
aria-hidden
|
|
212
|
-
className="shellui-floating-tab-indicator pointer-events-none absolute top-0 left-0 z-0 will-change-transform"
|
|
213
|
-
style={{ opacity: 0, width: 0, height: 0 }}
|
|
214
|
-
/>
|
|
215
|
-
);
|
|
216
|
-
}
|