@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,141 @@
|
|
|
1
|
+
import { useEffect, useSyncExternalStore, type ReactNode } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
clampChromeActions,
|
|
4
|
+
getLogger,
|
|
5
|
+
shellui,
|
|
6
|
+
type ChromeActionsPayload,
|
|
7
|
+
type ShellUIMessage,
|
|
8
|
+
} from '@shellui/sdk';
|
|
9
|
+
import { republishLayoutChromeWithActions } from '../layouts/floating/layoutChromeStore';
|
|
10
|
+
import {
|
|
11
|
+
clearChromeActionsForFrame,
|
|
12
|
+
getAllChromeActions,
|
|
13
|
+
setChromeActionsForFrame,
|
|
14
|
+
subscribeChromeActions,
|
|
15
|
+
SHELL_DEVELOP_CHROME_ACTIONS_FRAME,
|
|
16
|
+
} from './chromeActionsStore';
|
|
17
|
+
|
|
18
|
+
const logger = getLogger('shellcore');
|
|
19
|
+
|
|
20
|
+
function resolveFrameUuid(data: ShellUIMessage, event: MessageEvent): string | null {
|
|
21
|
+
const fromUuid = data.from?.[0];
|
|
22
|
+
if (fromUuid) return fromUuid;
|
|
23
|
+
const source = event.source;
|
|
24
|
+
// Use `typeof window` (lowercase) for SSR — `Window` is a TS type / ambient interface.
|
|
25
|
+
if (source && typeof window !== 'undefined' && source instanceof Window) {
|
|
26
|
+
const bySource = shellui.getUuidByIframe(source);
|
|
27
|
+
if (bySource) return bySource;
|
|
28
|
+
}
|
|
29
|
+
// Same-window posts (Settings → Develop) — no iframe uuid.
|
|
30
|
+
if (source === window || source === null) {
|
|
31
|
+
return SHELL_DEVELOP_CHROME_ACTIONS_FRAME;
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Resolve the frame UUID for a `removeIframe` argument before the registry drops it.
|
|
38
|
+
* When the iframe is already detached, `contentWindow` is null — fall back to matching
|
|
39
|
+
* the element in `frameRegistry`.
|
|
40
|
+
*/
|
|
41
|
+
export function resolveUuidFromRemoveTarget(
|
|
42
|
+
identifier: string | { contentWindow: Window | null },
|
|
43
|
+
lookup: {
|
|
44
|
+
getUuidByWindow: (win: Window) => string | undefined;
|
|
45
|
+
findUuidByElement: (el: unknown) => string | undefined;
|
|
46
|
+
},
|
|
47
|
+
): string | undefined {
|
|
48
|
+
if (typeof identifier === 'string') return identifier;
|
|
49
|
+
const win = identifier.contentWindow;
|
|
50
|
+
if (win) {
|
|
51
|
+
const byWindow = lookup.getUuidByWindow(win);
|
|
52
|
+
if (byWindow) return byWindow;
|
|
53
|
+
}
|
|
54
|
+
return lookup.findUuidByElement(identifier);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function resolveUuidForRemoveIframe(
|
|
58
|
+
identifier: string | HTMLIFrameElement,
|
|
59
|
+
): string | undefined {
|
|
60
|
+
return resolveUuidFromRemoveTarget(identifier, {
|
|
61
|
+
getUuidByWindow: (win) => shellui.getUuidByIframe(win),
|
|
62
|
+
findUuidByElement: (el) => {
|
|
63
|
+
for (const [uuid, iframe] of shellui.frameRegistry.getAllIframes()) {
|
|
64
|
+
if (iframe === el) return uuid;
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Listens for SHELLUI_ACTIONS_SET / CLEAR and keeps the per-frame store in sync.
|
|
73
|
+
* Also clears actions when a content iframe is removed (shell navigation).
|
|
74
|
+
*/
|
|
75
|
+
export function ChromeActionsProvider({ children }: { children: ReactNode }) {
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
const onSet = (data: ShellUIMessage, event: MessageEvent) => {
|
|
78
|
+
const frameUuid = resolveFrameUuid(data, event);
|
|
79
|
+
if (!frameUuid) {
|
|
80
|
+
logger.warn('SHELLUI_ACTIONS_SET without frame uuid — ignored');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const raw = (data.payload ?? {}) as ChromeActionsPayload;
|
|
84
|
+
const { payload, warnings } = clampChromeActions({
|
|
85
|
+
back: raw.back,
|
|
86
|
+
title: raw.title,
|
|
87
|
+
trailing: raw.trailing,
|
|
88
|
+
primary: raw.primary,
|
|
89
|
+
});
|
|
90
|
+
for (const warning of warnings) {
|
|
91
|
+
logger.warn(warning);
|
|
92
|
+
}
|
|
93
|
+
setChromeActionsForFrame(frameUuid, payload);
|
|
94
|
+
republishLayoutChromeWithActions();
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const onClear = (data: ShellUIMessage, event: MessageEvent) => {
|
|
98
|
+
const frameUuid = resolveFrameUuid(data, event);
|
|
99
|
+
if (!frameUuid) return;
|
|
100
|
+
clearChromeActionsForFrame(frameUuid);
|
|
101
|
+
republishLayoutChromeWithActions();
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const stopSet = shellui.addMessageListener('SHELLUI_ACTIONS_SET', onSet);
|
|
105
|
+
const stopClear = shellui.addMessageListener('SHELLUI_ACTIONS_CLEAR', onClear);
|
|
106
|
+
return () => {
|
|
107
|
+
stopSet();
|
|
108
|
+
stopClear();
|
|
109
|
+
};
|
|
110
|
+
}, []);
|
|
111
|
+
|
|
112
|
+
// Wrap removeIframe so shell nav / remount clears that view's actions + padding.
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
const original = shellui.removeIframe.bind(shellui);
|
|
115
|
+
shellui.removeIframe = ((identifier: string | HTMLIFrameElement) => {
|
|
116
|
+
// Resolve UUID before the registry forgets the iframe (contentWindow may already be null).
|
|
117
|
+
const uuid = resolveUuidForRemoveIframe(identifier);
|
|
118
|
+
const result = original(identifier);
|
|
119
|
+
if (uuid) {
|
|
120
|
+
clearChromeActionsForFrame(uuid);
|
|
121
|
+
republishLayoutChromeWithActions();
|
|
122
|
+
}
|
|
123
|
+
return result;
|
|
124
|
+
}) as typeof shellui.removeIframe;
|
|
125
|
+
return () => {
|
|
126
|
+
shellui.removeIframe = original;
|
|
127
|
+
};
|
|
128
|
+
}, []);
|
|
129
|
+
|
|
130
|
+
return <>{children}</>;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function useChromeActionsSnapshot() {
|
|
134
|
+
return useSyncExternalStore(subscribeChromeActions, getAllChromeActions, getAllChromeActions);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function useChromeActionsForFrame(frameUuid: string | null | undefined) {
|
|
138
|
+
const all = useChromeActionsSnapshot();
|
|
139
|
+
if (!frameUuid) return null;
|
|
140
|
+
return all.find((entry) => entry.frameUuid === frameUuid) ?? null;
|
|
141
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, expect, it, vi, beforeEach } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
clearAllChromeActions,
|
|
4
|
+
clearChromeActionsForFrame,
|
|
5
|
+
getAllChromeActions,
|
|
6
|
+
getChromeActionsForFrame,
|
|
7
|
+
setChromeActionsForFrame,
|
|
8
|
+
subscribeChromeActions,
|
|
9
|
+
} from './chromeActionsStore';
|
|
10
|
+
|
|
11
|
+
describe('chrome actions clear-on-shell-nav (store)', () => {
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
clearAllChromeActions();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('keeps getAllChromeActions referentially stable between emits', () => {
|
|
17
|
+
const emptyA = getAllChromeActions();
|
|
18
|
+
const emptyB = getAllChromeActions();
|
|
19
|
+
expect(emptyA).toBe(emptyB);
|
|
20
|
+
|
|
21
|
+
setChromeActionsForFrame('frame-a', { title: 'A' });
|
|
22
|
+
const withA = getAllChromeActions();
|
|
23
|
+
expect(withA).not.toBe(emptyA);
|
|
24
|
+
expect(getAllChromeActions()).toBe(withA);
|
|
25
|
+
expect(withA).toHaveLength(1);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('notifies subscribers when a frame is cleared (iframe remove / shell nav)', () => {
|
|
29
|
+
const listener = vi.fn();
|
|
30
|
+
const stop = subscribeChromeActions(listener);
|
|
31
|
+
setChromeActionsForFrame('frame-a', {
|
|
32
|
+
title: 'A',
|
|
33
|
+
primary: { id: 'p', icon: 'plus' },
|
|
34
|
+
});
|
|
35
|
+
setChromeActionsForFrame('frame-b', { title: 'B' });
|
|
36
|
+
expect(listener).toHaveBeenCalled();
|
|
37
|
+
listener.mockClear();
|
|
38
|
+
|
|
39
|
+
// Simulate ContentView unmount → removeIframe → clearChromeActionsForFrame
|
|
40
|
+
expect(clearChromeActionsForFrame('frame-a')).toBe(true);
|
|
41
|
+
expect(getChromeActionsForFrame('frame-a')).toBeNull();
|
|
42
|
+
expect(getChromeActionsForFrame('frame-b')?.title).toBe('B');
|
|
43
|
+
expect(listener).toHaveBeenCalledTimes(1);
|
|
44
|
+
stop();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('keeps independent action sets per contentView', () => {
|
|
48
|
+
setChromeActionsForFrame('a', {
|
|
49
|
+
title: 'One',
|
|
50
|
+
trailing: [{ id: 't1', label: 'Edit' }],
|
|
51
|
+
});
|
|
52
|
+
setChromeActionsForFrame('b', {
|
|
53
|
+
title: 'Two',
|
|
54
|
+
primary: { id: 'fab', icon: 'plus' },
|
|
55
|
+
});
|
|
56
|
+
expect(getChromeActionsForFrame('a')?.trailing?.[0]?.id).toBe('t1');
|
|
57
|
+
expect(getChromeActionsForFrame('a')?.primary).toBeUndefined();
|
|
58
|
+
expect(getChromeActionsForFrame('b')?.primary?.id).toBe('fab');
|
|
59
|
+
expect(getChromeActionsForFrame('b')?.trailing).toBeUndefined();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { ChromeActionsPayload } from '@shellui/sdk';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Synthetic frame id for `shellui.actions.*` calls from the shell window itself
|
|
5
|
+
* (Settings → Develop test buttons). Not a real iframe.
|
|
6
|
+
*/
|
|
7
|
+
export const SHELL_DEVELOP_CHROME_ACTIONS_FRAME = '__shell_develop__';
|
|
8
|
+
|
|
9
|
+
export type FrameChromeActions = ChromeActionsPayload & {
|
|
10
|
+
/** Frame UUID that owns this set (from message `from[0]`). */
|
|
11
|
+
frameUuid: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type Listener = () => void;
|
|
15
|
+
|
|
16
|
+
const actionsByFrame = new Map<string, FrameChromeActions>();
|
|
17
|
+
const listeners = new Set<Listener>();
|
|
18
|
+
/** Stable snapshot for useSyncExternalStore — must keep referential identity until emit. */
|
|
19
|
+
let cachedSnapshot: FrameChromeActions[] = [];
|
|
20
|
+
|
|
21
|
+
function rebuildSnapshot(): void {
|
|
22
|
+
cachedSnapshot = Array.from(actionsByFrame.values());
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function emit(): void {
|
|
26
|
+
rebuildSnapshot();
|
|
27
|
+
for (const listener of listeners) {
|
|
28
|
+
try {
|
|
29
|
+
listener();
|
|
30
|
+
} catch {
|
|
31
|
+
// Ignore subscriber errors.
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function getChromeActionsForFrame(frameUuid: string): FrameChromeActions | null {
|
|
37
|
+
return actionsByFrame.get(frameUuid) ?? null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function getAllChromeActions(): FrameChromeActions[] {
|
|
41
|
+
return cachedSnapshot;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function setChromeActionsForFrame(frameUuid: string, payload: ChromeActionsPayload): void {
|
|
45
|
+
if (!frameUuid) return;
|
|
46
|
+
const hasAny =
|
|
47
|
+
Boolean(payload.back) ||
|
|
48
|
+
Boolean(payload.title) ||
|
|
49
|
+
Boolean(payload.trailing?.length) ||
|
|
50
|
+
Boolean(payload.primary);
|
|
51
|
+
if (!hasAny) {
|
|
52
|
+
if (actionsByFrame.delete(frameUuid)) emit();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
actionsByFrame.set(frameUuid, { frameUuid, ...payload });
|
|
56
|
+
emit();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function clearChromeActionsForFrame(frameUuid: string): boolean {
|
|
60
|
+
if (!frameUuid) return false;
|
|
61
|
+
const removed = actionsByFrame.delete(frameUuid);
|
|
62
|
+
if (removed) emit();
|
|
63
|
+
return removed;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function clearAllChromeActions(): void {
|
|
67
|
+
if (actionsByFrame.size === 0) return;
|
|
68
|
+
actionsByFrame.clear();
|
|
69
|
+
emit();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function subscribeChromeActions(listener: Listener): () => void {
|
|
73
|
+
listeners.add(listener);
|
|
74
|
+
return () => {
|
|
75
|
+
listeners.delete(listener);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
actionChromeFlags,
|
|
4
|
+
CHROME_ACTIONS_CONTENT_CLEARANCE,
|
|
5
|
+
CHROME_ACTIONS_FAB_EDGE_MARGIN,
|
|
6
|
+
CHROME_ACTIONS_FAB_SIZE,
|
|
7
|
+
CHROME_ACTIONS_FAB_SIZE_DESKTOP,
|
|
8
|
+
CHROME_ACTIONS_FAB_SIZE_SHELL,
|
|
9
|
+
CHROME_ACTIONS_TOP_BAR_HEIGHT,
|
|
10
|
+
CHROME_ACTIONS_TOP_BAR_HEIGHT_NARROW,
|
|
11
|
+
CHROME_ACTIONS_TOP_MARGIN,
|
|
12
|
+
CHROME_ACTIONS_TOP_MARGIN_DESKTOP,
|
|
13
|
+
CHROME_ACTIONS_TOP_MARGIN_MINIMAL,
|
|
14
|
+
chromeActionsFabBottomOffsetCss,
|
|
15
|
+
chromeActionsFabRightOffsetCss,
|
|
16
|
+
chromeActionsShouldHonorSafeAreaTop,
|
|
17
|
+
chromeActionsTopBarHeight,
|
|
18
|
+
chromeActionsTopMargin,
|
|
19
|
+
chromeActionsTopOffsetCss,
|
|
20
|
+
computeActionInsets,
|
|
21
|
+
mergeInsets,
|
|
22
|
+
} from './computeActionInsets';
|
|
23
|
+
import {
|
|
24
|
+
FLOATING_CHROME_MARGIN,
|
|
25
|
+
FLOATING_CONTENT_CLEARANCE,
|
|
26
|
+
} from '../layouts/floating/computeFloatingInsets';
|
|
27
|
+
import {
|
|
28
|
+
clearAllChromeActions,
|
|
29
|
+
clearChromeActionsForFrame,
|
|
30
|
+
getAllChromeActions,
|
|
31
|
+
getChromeActionsForFrame,
|
|
32
|
+
setChromeActionsForFrame,
|
|
33
|
+
} from './chromeActionsStore';
|
|
34
|
+
|
|
35
|
+
describe('chromeActionsStore', () => {
|
|
36
|
+
it('stores and clears per frame', () => {
|
|
37
|
+
clearAllChromeActions();
|
|
38
|
+
setChromeActionsForFrame('a', { title: 'A', primary: { id: 'p', icon: 'plus' } });
|
|
39
|
+
setChromeActionsForFrame('b', { title: 'B' });
|
|
40
|
+
expect(getChromeActionsForFrame('a')?.title).toBe('A');
|
|
41
|
+
expect(getAllChromeActions()).toHaveLength(2);
|
|
42
|
+
expect(clearChromeActionsForFrame('a')).toBe(true);
|
|
43
|
+
expect(getChromeActionsForFrame('a')).toBeNull();
|
|
44
|
+
expect(getAllChromeActions()).toHaveLength(1);
|
|
45
|
+
clearAllChromeActions();
|
|
46
|
+
expect(getAllChromeActions()).toHaveLength(0);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('drops empty payloads', () => {
|
|
50
|
+
clearAllChromeActions();
|
|
51
|
+
setChromeActionsForFrame('a', { title: 'A' });
|
|
52
|
+
setChromeActionsForFrame('a', {});
|
|
53
|
+
expect(getChromeActionsForFrame('a')).toBeNull();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('chromeActionsTopMargin', () => {
|
|
58
|
+
it('uses the chrome margin for floating phone and tablet', () => {
|
|
59
|
+
expect(
|
|
60
|
+
chromeActionsTopMargin({
|
|
61
|
+
layout: 'floating',
|
|
62
|
+
viewport: 'tablet',
|
|
63
|
+
}),
|
|
64
|
+
).toBe(CHROME_ACTIONS_TOP_MARGIN);
|
|
65
|
+
expect(
|
|
66
|
+
chromeActionsTopMargin({
|
|
67
|
+
layout: 'floating',
|
|
68
|
+
viewport: 'mobile',
|
|
69
|
+
}),
|
|
70
|
+
).toBe(CHROME_ACTIONS_TOP_MARGIN);
|
|
71
|
+
expect(CHROME_ACTIONS_TOP_MARGIN).toBe(FLOATING_CHROME_MARGIN);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('drops floating desktop one margin lower', () => {
|
|
75
|
+
expect(
|
|
76
|
+
chromeActionsTopMargin({
|
|
77
|
+
layout: 'floating',
|
|
78
|
+
viewport: 'desktop',
|
|
79
|
+
sidebarExpanded: true,
|
|
80
|
+
}),
|
|
81
|
+
).toBe(CHROME_ACTIONS_TOP_MARGIN_DESKTOP);
|
|
82
|
+
expect(CHROME_ACTIONS_TOP_MARGIN_DESKTOP).toBe(CHROME_ACTIONS_TOP_MARGIN + 12);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('uses a minimal top margin for other layouts', () => {
|
|
86
|
+
expect(chromeActionsTopMargin({ layout: 'actions', viewport: 'desktop' })).toBe(
|
|
87
|
+
CHROME_ACTIONS_TOP_MARGIN_MINIMAL,
|
|
88
|
+
);
|
|
89
|
+
expect(chromeActionsTopMargin({ layout: 'sidebar', viewport: 'mobile' })).toBe(
|
|
90
|
+
CHROME_ACTIONS_TOP_MARGIN_MINIMAL,
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe('chromeActionsTopOffsetCss', () => {
|
|
96
|
+
it('skips safe-area on sidebar and app-bar (shell header band instead)', () => {
|
|
97
|
+
expect(chromeActionsTopOffsetCss({ layout: 'sidebar', viewport: 'mobile' })).toBe(
|
|
98
|
+
`calc(var(--shellui-shell-header-height, 0px) + ${CHROME_ACTIONS_TOP_MARGIN_MINIMAL}px)`,
|
|
99
|
+
);
|
|
100
|
+
expect(chromeActionsTopOffsetCss({ layout: 'app-bar', viewport: 'mobile' })).toBe(
|
|
101
|
+
`calc(var(--shellui-shell-header-height, 0px) + ${CHROME_ACTIONS_TOP_MARGIN_MINIMAL}px)`,
|
|
102
|
+
);
|
|
103
|
+
// Mobile inset still overlays the header — clear the same band as flush.
|
|
104
|
+
expect(chromeActionsTopOffsetCss({ layout: 'sidebar-inset', viewport: 'mobile' })).toBe(
|
|
105
|
+
`calc(var(--shellui-shell-header-height, 0px) + ${CHROME_ACTIONS_TOP_MARGIN_MINIMAL}px)`,
|
|
106
|
+
);
|
|
107
|
+
expect(chromeActionsTopOffsetCss({ layout: 'app-bar-inset', viewport: 'mobile' })).toBe(
|
|
108
|
+
`calc(var(--shellui-shell-header-height, 0px) + ${CHROME_ACTIONS_TOP_MARGIN_MINIMAL}px)`,
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('honors safe-area on floating and fullscreen', () => {
|
|
113
|
+
// Floating stacks margin + safe-area (same as FloatingSidebar edge pad).
|
|
114
|
+
expect(chromeActionsTopOffsetCss({ layout: 'floating', viewport: 'mobile' })).toBe(
|
|
115
|
+
`calc(${CHROME_ACTIONS_TOP_MARGIN}px + var(--shellui-safe-area-top, 0px))`,
|
|
116
|
+
);
|
|
117
|
+
expect(chromeActionsTopOffsetCss({ layout: 'floating', viewport: 'desktop' })).toBe(
|
|
118
|
+
`calc(${CHROME_ACTIONS_TOP_MARGIN_DESKTOP}px + var(--shellui-safe-area-top, 0px))`,
|
|
119
|
+
);
|
|
120
|
+
expect(chromeActionsTopOffsetCss({ layout: 'fullscreen', viewport: 'mobile' })).toBe(
|
|
121
|
+
`max(${CHROME_ACTIONS_TOP_MARGIN_MINIMAL}px, var(--shellui-safe-area-top, 0px))`,
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('sits below the shell header band on mobile shell chrome; desktop inset uses margin only', () => {
|
|
126
|
+
expect(chromeActionsTopOffsetCss({ layout: 'sidebar', viewport: 'mobile' })).toBe(
|
|
127
|
+
`calc(var(--shellui-shell-header-height, 0px) + ${CHROME_ACTIONS_TOP_MARGIN_MINIMAL}px)`,
|
|
128
|
+
);
|
|
129
|
+
expect(chromeActionsTopOffsetCss({ layout: 'app-bar-inset', viewport: 'mobile' })).toBe(
|
|
130
|
+
`calc(var(--shellui-shell-header-height, 0px) + ${CHROME_ACTIONS_TOP_MARGIN_MINIMAL}px)`,
|
|
131
|
+
);
|
|
132
|
+
expect(chromeActionsTopOffsetCss({ layout: 'sidebar-inset', viewport: 'desktop' })).toBe(
|
|
133
|
+
`${CHROME_ACTIONS_TOP_MARGIN_MINIMAL}px`,
|
|
134
|
+
);
|
|
135
|
+
expect(chromeActionsTopOffsetCss({ layout: 'app-bar-inset', viewport: 'desktop' })).toBe(
|
|
136
|
+
`${CHROME_ACTIONS_TOP_MARGIN_MINIMAL}px`,
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('allows forcing safe-area for overlay surfaces on header layouts', () => {
|
|
141
|
+
expect(
|
|
142
|
+
chromeActionsTopOffsetCss(
|
|
143
|
+
{ layout: 'sidebar', viewport: 'mobile' },
|
|
144
|
+
{ honorSafeAreaTop: true },
|
|
145
|
+
),
|
|
146
|
+
).toBe(`max(${CHROME_ACTIONS_TOP_MARGIN_MINIMAL}px, var(--shellui-safe-area-top, 0px))`);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe('chromeActionsShouldHonorSafeAreaTop', () => {
|
|
151
|
+
it('matches layout chrome ownership of the status band', () => {
|
|
152
|
+
expect(chromeActionsShouldHonorSafeAreaTop('floating')).toBe(true);
|
|
153
|
+
expect(chromeActionsShouldHonorSafeAreaTop('fullscreen')).toBe(true);
|
|
154
|
+
expect(chromeActionsShouldHonorSafeAreaTop('sidebar')).toBe(false);
|
|
155
|
+
expect(chromeActionsShouldHonorSafeAreaTop('app-bar')).toBe(false);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
describe('chromeActionsTopBarHeight', () => {
|
|
160
|
+
it('uses a taller row on phone and tablet', () => {
|
|
161
|
+
expect(chromeActionsTopBarHeight('desktop')).toBe(CHROME_ACTIONS_TOP_BAR_HEIGHT);
|
|
162
|
+
expect(chromeActionsTopBarHeight('mobile')).toBe(CHROME_ACTIONS_TOP_BAR_HEIGHT_NARROW);
|
|
163
|
+
expect(chromeActionsTopBarHeight('tablet')).toBe(CHROME_ACTIONS_TOP_BAR_HEIGHT_NARROW);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
describe('computeActionInsets', () => {
|
|
168
|
+
it('detects top and primary flags', () => {
|
|
169
|
+
expect(actionChromeFlags(null)).toEqual({ hasTop: false, hasPrimary: false });
|
|
170
|
+
expect(actionChromeFlags({ frameUuid: 'x', title: 'T' })).toEqual({
|
|
171
|
+
hasTop: true,
|
|
172
|
+
hasPrimary: false,
|
|
173
|
+
});
|
|
174
|
+
expect(actionChromeFlags({ frameUuid: 'x', primary: { id: 'p' } })).toEqual({
|
|
175
|
+
hasTop: false,
|
|
176
|
+
hasPrimary: true,
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('adds top inset unless title-bar mode', () => {
|
|
181
|
+
const withTop = computeActionInsets({ hasTop: true, hasPrimary: false });
|
|
182
|
+
expect(withTop.top).toBeGreaterThanOrEqual(CHROME_ACTIONS_TOP_BAR_HEIGHT);
|
|
183
|
+
expect(
|
|
184
|
+
computeActionInsets({ hasTop: true, hasPrimary: false }, { topInTitleBar: true }).top,
|
|
185
|
+
).toBe(0);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('uses a taller top bar on mobile than desktop for non-floating layouts', () => {
|
|
189
|
+
const desktop = computeActionInsets(
|
|
190
|
+
{ hasTop: true, hasPrimary: false },
|
|
191
|
+
{ viewport: 'desktop', layout: 'actions' },
|
|
192
|
+
);
|
|
193
|
+
const mobile = computeActionInsets(
|
|
194
|
+
{ hasTop: true, hasPrimary: false },
|
|
195
|
+
{ viewport: 'mobile', layout: 'actions' },
|
|
196
|
+
);
|
|
197
|
+
expect(desktop.top).toBe(
|
|
198
|
+
CHROME_ACTIONS_TOP_MARGIN_MINIMAL +
|
|
199
|
+
CHROME_ACTIONS_TOP_BAR_HEIGHT +
|
|
200
|
+
CHROME_ACTIONS_CONTENT_CLEARANCE,
|
|
201
|
+
);
|
|
202
|
+
expect(mobile.top).toBe(
|
|
203
|
+
CHROME_ACTIONS_TOP_MARGIN_MINIMAL +
|
|
204
|
+
CHROME_ACTIONS_TOP_BAR_HEIGHT_NARROW +
|
|
205
|
+
CHROME_ACTIONS_CONTENT_CLEARANCE,
|
|
206
|
+
);
|
|
207
|
+
expect(mobile.top).toBeGreaterThan(desktop.top);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('keeps floating desktop top inset one margin below the brand row', () => {
|
|
211
|
+
const top = computeActionInsets(
|
|
212
|
+
{ hasTop: true, hasPrimary: false },
|
|
213
|
+
{ viewport: 'desktop', layout: 'floating', sidebarExpanded: true },
|
|
214
|
+
).top;
|
|
215
|
+
expect(top).toBe(
|
|
216
|
+
CHROME_ACTIONS_TOP_MARGIN_DESKTOP +
|
|
217
|
+
CHROME_ACTIONS_TOP_BAR_HEIGHT +
|
|
218
|
+
CHROME_ACTIONS_CONTENT_CLEARANCE,
|
|
219
|
+
);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('stacks chrome margin above safe-area on floating (matches sidebar pad)', () => {
|
|
223
|
+
const safeTop = 47;
|
|
224
|
+
const extra = computeActionInsets(
|
|
225
|
+
{ hasTop: true, hasPrimary: false },
|
|
226
|
+
{
|
|
227
|
+
viewport: 'mobile',
|
|
228
|
+
layout: 'floating',
|
|
229
|
+
existingTopInset: safeTop,
|
|
230
|
+
},
|
|
231
|
+
).top;
|
|
232
|
+
// visualTop = 12 + 47; needed = 59+40+8 = 107; extra = 107-47 = 60
|
|
233
|
+
expect(extra).toBe(
|
|
234
|
+
CHROME_ACTIONS_TOP_MARGIN +
|
|
235
|
+
CHROME_ACTIONS_TOP_BAR_HEIGHT_NARROW +
|
|
236
|
+
CHROME_ACTIONS_CONTENT_CLEARANCE,
|
|
237
|
+
);
|
|
238
|
+
expect(safeTop + extra).toBe(
|
|
239
|
+
safeTop +
|
|
240
|
+
CHROME_ACTIONS_TOP_MARGIN +
|
|
241
|
+
CHROME_ACTIONS_TOP_BAR_HEIGHT_NARROW +
|
|
242
|
+
CHROME_ACTIONS_CONTENT_CLEARANCE,
|
|
243
|
+
);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('stacks FAB above existing bottom inset', () => {
|
|
247
|
+
const alone = computeActionInsets({ hasTop: false, hasPrimary: true });
|
|
248
|
+
const stacked = computeActionInsets(
|
|
249
|
+
{ hasTop: false, hasPrimary: true },
|
|
250
|
+
{ existingBottomInset: 100 },
|
|
251
|
+
);
|
|
252
|
+
expect(stacked.bottom).toBe(CHROME_ACTIONS_FAB_SIZE + 12);
|
|
253
|
+
expect(alone.bottom).toBeGreaterThan(stacked.bottom);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it('uses a larger FAB + edge margin on tablet and desktop', () => {
|
|
257
|
+
const desktop = computeActionInsets(
|
|
258
|
+
{ hasTop: false, hasPrimary: true },
|
|
259
|
+
{ viewport: 'desktop' },
|
|
260
|
+
);
|
|
261
|
+
const mobile = computeActionInsets({ hasTop: false, hasPrimary: true }, { viewport: 'mobile' });
|
|
262
|
+
expect(desktop.bottom).toBe(
|
|
263
|
+
CHROME_ACTIONS_FAB_EDGE_MARGIN + CHROME_ACTIONS_FAB_SIZE_DESKTOP + FLOATING_CONTENT_CLEARANCE,
|
|
264
|
+
);
|
|
265
|
+
expect(mobile.bottom).toBe(
|
|
266
|
+
FLOATING_CHROME_MARGIN + CHROME_ACTIONS_FAB_SIZE + FLOATING_CONTENT_CLEARANCE,
|
|
267
|
+
);
|
|
268
|
+
expect(desktop.bottom).toBeGreaterThan(mobile.bottom);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it('uses a larger shell FAB on sidebar / app-bar layouts', () => {
|
|
272
|
+
const sidebar = computeActionInsets(
|
|
273
|
+
{ hasTop: false, hasPrimary: true },
|
|
274
|
+
{ viewport: 'mobile', layout: 'sidebar' },
|
|
275
|
+
);
|
|
276
|
+
const appBar = computeActionInsets(
|
|
277
|
+
{ hasTop: false, hasPrimary: true },
|
|
278
|
+
{ viewport: 'mobile', layout: 'app-bar-inset' },
|
|
279
|
+
);
|
|
280
|
+
expect(sidebar.bottom).toBe(
|
|
281
|
+
FLOATING_CHROME_MARGIN + CHROME_ACTIONS_FAB_SIZE_SHELL + FLOATING_CONTENT_CLEARANCE,
|
|
282
|
+
);
|
|
283
|
+
expect(appBar.bottom).toBe(sidebar.bottom);
|
|
284
|
+
expect(sidebar.bottom).toBeGreaterThan(
|
|
285
|
+
FLOATING_CHROME_MARGIN + CHROME_ACTIONS_FAB_SIZE + FLOATING_CONTENT_CLEARANCE,
|
|
286
|
+
);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it('skips top inset when actions live in the title bar', () => {
|
|
290
|
+
expect(
|
|
291
|
+
computeActionInsets(
|
|
292
|
+
{ hasTop: true, hasPrimary: false },
|
|
293
|
+
{
|
|
294
|
+
viewport: 'mobile',
|
|
295
|
+
layout: 'sidebar',
|
|
296
|
+
existingTopInset: 90,
|
|
297
|
+
topInTitleBar: true,
|
|
298
|
+
},
|
|
299
|
+
).top,
|
|
300
|
+
).toBe(0);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it('adds safe-area-bottom for corner FABs when no existing bottom chrome', () => {
|
|
304
|
+
expect(
|
|
305
|
+
computeActionInsets(
|
|
306
|
+
{ hasTop: false, hasPrimary: true },
|
|
307
|
+
{ viewport: 'mobile', layout: 'actions', safeAreaBottom: 34 },
|
|
308
|
+
).bottom,
|
|
309
|
+
).toBe(FLOATING_CHROME_MARGIN + CHROME_ACTIONS_FAB_SIZE + FLOATING_CONTENT_CLEARANCE + 34);
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it('does not add safe-area-bottom when stacking above an existing bottom inset', () => {
|
|
313
|
+
expect(
|
|
314
|
+
computeActionInsets(
|
|
315
|
+
{ hasTop: false, hasPrimary: true },
|
|
316
|
+
{ viewport: 'mobile', existingBottomInset: 88, safeAreaBottom: 34 },
|
|
317
|
+
).bottom,
|
|
318
|
+
).toBe(CHROME_ACTIONS_FAB_SIZE + 12);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('stacks action-row inset on top of a mobile shell header band', () => {
|
|
322
|
+
const headerBand = 91;
|
|
323
|
+
expect(
|
|
324
|
+
computeActionInsets(
|
|
325
|
+
{ hasTop: true, hasPrimary: false },
|
|
326
|
+
{ viewport: 'mobile', layout: 'sidebar', existingTopInset: headerBand },
|
|
327
|
+
).top,
|
|
328
|
+
).toBe(CHROME_ACTIONS_TOP_BAR_HEIGHT_NARROW + CHROME_ACTIONS_CONTENT_CLEARANCE);
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
it('builds FAB edge offsets that honor safe-area CSS vars', () => {
|
|
332
|
+
expect(chromeActionsFabBottomOffsetCss(12)).toBe(
|
|
333
|
+
'calc(12px + var(--shellui-safe-area-bottom, 0px))',
|
|
334
|
+
);
|
|
335
|
+
expect(chromeActionsFabRightOffsetCss(12, { useLayoutInsets: true })).toBe(
|
|
336
|
+
'calc(12px + max(var(--shellui-inset-right, 0px), var(--shellui-safe-area-right, 0px)))',
|
|
337
|
+
);
|
|
338
|
+
expect(chromeActionsFabRightOffsetCss(12)).toBe(
|
|
339
|
+
'calc(12px + var(--shellui-safe-area-right, 0px))',
|
|
340
|
+
);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it('skips FAB bottom inset when primary is in the floating dock', () => {
|
|
344
|
+
expect(
|
|
345
|
+
computeActionInsets(
|
|
346
|
+
{ hasTop: false, hasPrimary: true },
|
|
347
|
+
{ existingBottomInset: 88, primaryInDock: true },
|
|
348
|
+
).bottom,
|
|
349
|
+
).toBe(0);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it('merges insets additively', () => {
|
|
353
|
+
expect(
|
|
354
|
+
mergeInsets(
|
|
355
|
+
{ top: 1, right: 2, bottom: 3, left: 4 },
|
|
356
|
+
{ top: 10, right: 20, bottom: 30, left: 40 },
|
|
357
|
+
),
|
|
358
|
+
).toEqual({ top: 11, right: 22, bottom: 33, left: 44 });
|
|
359
|
+
});
|
|
360
|
+
});
|