@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.
Files changed (108) hide show
  1. package/README.md +5 -5
  2. package/package.json +3 -2
  3. package/schemas/shellui.config.schema.json +98 -33
  4. package/src/app.tsx +10 -4
  5. package/src/components/ContentView.tsx +3 -5
  6. package/src/components/contentIframeSandbox.spec.ts +25 -0
  7. package/src/components/contentIframeSandbox.ts +43 -0
  8. package/src/components/ui/dialog.tsx +5 -1
  9. package/src/components/ui/dropdown-menu.tsx +39 -4
  10. package/src/components/ui/sheet.tsx +1 -1
  11. package/src/components/ui/sidebar.tsx +3 -2
  12. package/src/components/ui/tabs.tsx +52 -0
  13. package/src/constants/urls.ts +1 -0
  14. package/src/features/auth/AuthProvider.tsx +169 -35
  15. package/src/features/auth/backends/index.ts +2 -0
  16. package/src/features/auth/backends/shellui.ts +43 -35
  17. package/src/features/auth/backends/supabase.ts +1 -0
  18. package/src/features/auth/backends/types.ts +5 -0
  19. package/src/features/auth/components/LoginView.tsx +5 -1
  20. package/src/features/auth/components/OAuthCallbackView.tsx +115 -44
  21. package/src/features/auth/constants/oauth.ts +2 -0
  22. package/src/features/auth/hooks/useAuth.tsx +4 -0
  23. package/src/features/auth/utils/authSessionPersistence.spec.ts +93 -0
  24. package/src/features/auth/utils/authSessionPersistence.ts +138 -0
  25. package/src/features/auth/utils/authStorageKeys.ts +8 -0
  26. package/src/features/auth/utils/bffAuthClient.ts +107 -0
  27. package/src/features/auth/utils/buildOAuthSessionRedirectTo.spec.ts +22 -0
  28. package/src/features/auth/utils/buildOAuthSessionRedirectTo.ts +17 -0
  29. package/src/features/auth/utils/buildSessionFromTokenPayload.spec.ts +29 -0
  30. package/src/features/auth/utils/buildSessionFromTokenPayload.ts +24 -0
  31. package/src/features/auth/utils/index.ts +18 -3
  32. package/src/features/auth/utils/isBffAuthEnabled.ts +12 -0
  33. package/src/features/chromeActions/ChromeActionIcons.tsx +261 -0
  34. package/src/features/chromeActions/ChromeActionsDemoView.tsx +149 -0
  35. package/src/features/chromeActions/ChromeActionsHost.tsx +1511 -0
  36. package/src/features/chromeActions/ChromeActionsProvider.tsx +141 -0
  37. package/src/features/chromeActions/chromeActionsStore.spec.ts +61 -0
  38. package/src/features/chromeActions/chromeActionsStore.ts +77 -0
  39. package/src/features/chromeActions/computeActionInsets.spec.ts +360 -0
  40. package/src/features/chromeActions/computeActionInsets.ts +326 -0
  41. package/src/features/chromeActions/index.ts +26 -0
  42. package/src/features/chromeActions/resolveUuidForRemoveIframe.spec.ts +49 -0
  43. package/src/features/config/types.ts +49 -2
  44. package/src/features/layouts/AppLayout.tsx +4 -4
  45. package/src/features/layouts/OverlayShell.tsx +60 -12
  46. package/src/features/layouts/app-bar-inset/AppBarInsetLayout.tsx +1 -1
  47. package/src/features/layouts/appbar/AppBarLayout.tsx +194 -89
  48. package/src/features/layouts/chrome/DesktopChrome.tsx +17 -3
  49. package/src/features/layouts/chrome/InsetMobileRadiusOverlay.tsx +18 -0
  50. package/src/features/layouts/chrome/index.ts +8 -0
  51. package/src/features/layouts/chrome/runtime.ts +73 -0
  52. package/src/features/layouts/chrome/useScrollHideChrome.ts +210 -0
  53. package/src/features/layouts/floating/FloatingBottomDock.tsx +410 -0
  54. package/src/features/layouts/floating/FloatingLayout.tsx +31 -21
  55. package/src/features/layouts/floating/FloatingStatusScrim.tsx +36 -0
  56. package/src/features/layouts/floating/computeFloatingInsets.spec.ts +5 -5
  57. package/src/features/layouts/floating/computeFloatingInsets.ts +64 -12
  58. package/src/features/layouts/floating/isShellOwnedPath.spec.ts +2 -0
  59. package/src/features/layouts/floating/isShellOwnedPath.ts +1 -0
  60. package/src/features/layouts/floating/layoutChromeStore.spec.ts +138 -0
  61. package/src/features/layouts/floating/layoutChromeStore.ts +169 -6
  62. package/src/features/layouts/floating/useFloatingChrome.ts +20 -30
  63. package/src/features/layouts/sidebar/SidebarLayout.tsx +87 -31
  64. package/src/features/layouts/sidebar-inset/SidebarInsetLayout.tsx +1 -1
  65. package/src/features/layouts/windows/WindowsLayout.tsx +240 -110
  66. package/src/features/messaging/MessagingSecurityBootstrap.tsx +19 -0
  67. package/src/features/messaging/deriveAllowedMessageOrigins.spec.ts +86 -0
  68. package/src/features/messaging/deriveAllowedMessageOrigins.ts +74 -0
  69. package/src/features/modal/ModalContext.spec.ts +13 -2
  70. package/src/features/modal/validateAndNormalizeUrl.ts +9 -23
  71. package/src/features/overlays/ResponsiveModal.tsx +201 -21
  72. package/src/features/overlays/overlaySize.spec.ts +18 -0
  73. package/src/features/overlays/overlaySize.ts +89 -0
  74. package/src/features/security/trustedFrames.spec.ts +129 -0
  75. package/src/features/security/trustedFrames.ts +79 -0
  76. package/src/features/security/urlAllowlist.spec.ts +99 -0
  77. package/src/features/security/urlAllowlist.ts +122 -0
  78. package/src/features/settings/SettingsProvider.tsx +38 -54
  79. package/src/features/settings/components/Develop.tsx +2 -0
  80. package/src/features/settings/components/develop/ChromeActionsTestButtons.tsx +63 -0
  81. package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +23 -1
  82. package/src/features/settings/utils/buildSettingsForPropagation.ts +7 -0
  83. package/src/features/storage/StorageBridge.spec.ts +82 -0
  84. package/src/features/storage/StorageBridge.tsx +25 -3
  85. package/src/features/storage/StoragePickerContext.tsx +3 -4
  86. package/src/features/storage/uploads/uploadQueue.spec.ts +56 -1
  87. package/src/features/storage/uploads/uploadQueue.ts +44 -6
  88. package/src/features/theme/applyTheme.ts +23 -5
  89. package/src/hooks/use-mobile.tsx +21 -7
  90. package/src/i18n/translations/en/settings.json +9 -0
  91. package/src/i18n/translations/fr/settings.json +9 -0
  92. package/src/index.css +264 -124
  93. package/src/index.html +6 -4
  94. package/src/index.ts +8 -0
  95. package/src/routes/components/NavigationItemRoute.tsx +30 -15
  96. package/src/routes/components/RouteFallback.tsx +15 -0
  97. package/src/routes/routes.tsx +14 -0
  98. package/src/routes/utils/navigationRouteAccess.spec.ts +85 -0
  99. package/src/routes/utils/navigationRouteAccess.ts +43 -0
  100. package/src/features/auth/utils/clearStoredAuthSession.spec.ts +0 -23
  101. package/src/features/auth/utils/clearStoredAuthSession.ts +0 -10
  102. package/src/features/auth/utils/persistAuthSession.spec.ts +0 -35
  103. package/src/features/auth/utils/persistAuthSession.ts +0 -12
  104. package/src/features/auth/utils/readStoredAuthSession.spec.ts +0 -34
  105. package/src/features/auth/utils/readStoredAuthSession.ts +0 -14
  106. package/src/features/layouts/floating/FloatingFadeMask.tsx +0 -22
  107. package/src/features/layouts/floating/FloatingTabBar.tsx +0 -437
  108. package/src/features/layouts/floating/FloatingTabIndicator.tsx +0 -216
@@ -5,31 +5,46 @@ import { Navigate, useLocation } from 'react-router';
5
5
  import urls from '../../constants/urls';
6
6
  import { buildAuthUrlWithNext } from '../../features/auth/utils';
7
7
  import { useAuth } from '../../features/auth/hooks/useAuth';
8
+ import { AdminForbiddenAccess } from '../../features/admin/components/AdminForbiddenAccess';
9
+ import { getNavigationRouteAccess } from '../utils/navigationRouteAccess';
8
10
  import { RouteFallback } from './RouteFallback';
9
11
 
10
12
  export const NavigationItemRoute = () => {
11
13
  const location = useLocation();
12
- const { isAuthenticated, isLoading } = useAuth();
14
+ const { isAuthenticated, isLoading, user } = useAuth();
13
15
  const { url, currentItem } = useNavigationItems();
14
16
 
15
17
  if (!currentItem) {
16
18
  return <NotFoundView />;
17
19
  }
18
20
 
19
- if (currentItem.requiresAuth) {
20
- if (isLoading) {
21
- return <RouteFallback />;
22
- }
23
- if (!isAuthenticated) {
24
- const next = `${location.pathname}${location.search}`;
25
- const loginUrl = buildAuthUrlWithNext(urls.login, next);
26
- return (
27
- <Navigate
28
- to={loginUrl}
29
- replace
30
- />
31
- );
32
- }
21
+ const next = `${location.pathname}${location.search}`;
22
+ const access = getNavigationRouteAccess(
23
+ currentItem,
24
+ {
25
+ isLoading,
26
+ isAuthenticated,
27
+ isStaff: Boolean(user?.isStaff),
28
+ },
29
+ next,
30
+ );
31
+
32
+ if (access.kind === 'loading') {
33
+ return <RouteFallback />;
34
+ }
35
+
36
+ if (access.kind === 'login') {
37
+ const loginUrl = buildAuthUrlWithNext(urls.login, access.next);
38
+ return (
39
+ <Navigate
40
+ to={loginUrl}
41
+ replace
42
+ />
43
+ );
44
+ }
45
+
46
+ if (access.kind === 'forbidden') {
47
+ return <AdminForbiddenAccess />;
33
48
  }
34
49
 
35
50
  return (
@@ -1,6 +1,21 @@
1
1
  import { LoadingOverlay } from '../../components/LoadingOverlay';
2
+ import { isShellUiRootWindow } from '../../features/layouts/chrome/SafeAreaTopbar';
2
3
 
4
+ /**
5
+ * Suspense fallback for lazy routes.
6
+ * Nested shell-in-iframe: parent ContentView already shows the loading bar until
7
+ * SHELLUI_INITIALIZED — another bar here reads as a double load / redirect.
8
+ */
3
9
  export function RouteFallback() {
10
+ if (!isShellUiRootWindow()) {
11
+ return (
12
+ <div
13
+ className="h-full min-h-full bg-background"
14
+ aria-hidden
15
+ />
16
+ );
17
+ }
18
+
4
19
  return (
5
20
  <div
6
21
  className="relative h-full min-h-full bg-background"
@@ -22,6 +22,11 @@ const OverlayDynamicDemoView = lazy(() =>
22
22
  default: m.OverlayDynamicDemoView,
23
23
  })),
24
24
  );
25
+ const ChromeActionsDemoView = lazy(() =>
26
+ import('../features/chromeActions/ChromeActionsDemoView').then((m) => ({
27
+ default: m.ChromeActionsDemoView,
28
+ })),
29
+ );
25
30
  const LoginView = lazy(() =>
26
31
  import('../features/auth/components/LoginView').then((m) => ({ default: m.LoginView })),
27
32
  );
@@ -82,6 +87,15 @@ export const createRoutes = (config: ShellUIConfig): RouteObject[] => {
82
87
  </Suspense>
83
88
  ),
84
89
  },
90
+ {
91
+ // Chrome actions demo (develop → iframe set/clear)
92
+ path: urls.chromeActionsDemo.replace(/^\//, ''),
93
+ element: (
94
+ <Suspense fallback={<RouteFallback />}>
95
+ <ChromeActionsDemoView />
96
+ </Suspense>
97
+ ),
98
+ },
85
99
  {
86
100
  // Login route
87
101
  path: urls.login.replace(/^\//, ''),
@@ -0,0 +1,85 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import type { NavigationItem } from '../../features/config/types';
3
+ import { getNavigationRouteAccess } from './navigationRouteAccess';
4
+
5
+ const staffRoute: NavigationItem = {
6
+ label: 'Staff tools',
7
+ path: 'staff',
8
+ url: 'https://app.example.com/staff',
9
+ requiresStaff: true,
10
+ };
11
+
12
+ const authRoute: NavigationItem = {
13
+ label: 'Billing',
14
+ path: 'billing',
15
+ url: 'https://app.example.com/billing',
16
+ requiresAuth: true,
17
+ };
18
+
19
+ const publicRoute: NavigationItem = {
20
+ label: 'Home',
21
+ path: 'home',
22
+ url: 'https://app.example.com/',
23
+ };
24
+
25
+ describe('getNavigationRouteAccess', () => {
26
+ it('allows public routes', () => {
27
+ expect(
28
+ getNavigationRouteAccess(
29
+ publicRoute,
30
+ { isLoading: false, isAuthenticated: false, isStaff: false },
31
+ '/home',
32
+ ),
33
+ ).toEqual({ kind: 'allow' });
34
+ });
35
+
36
+ it('redirects unauthenticated users on requiresAuth routes', () => {
37
+ expect(
38
+ getNavigationRouteAccess(
39
+ authRoute,
40
+ { isLoading: false, isAuthenticated: false, isStaff: false },
41
+ '/billing?tab=1',
42
+ ),
43
+ ).toEqual({ kind: 'login', next: '/billing?tab=1' });
44
+ });
45
+
46
+ it('denies non-staff users on requiresStaff routes', () => {
47
+ expect(
48
+ getNavigationRouteAccess(
49
+ staffRoute,
50
+ { isLoading: false, isAuthenticated: true, isStaff: false },
51
+ '/staff',
52
+ ),
53
+ ).toEqual({ kind: 'forbidden' });
54
+ });
55
+
56
+ it('denies signed-out users on requiresStaff routes', () => {
57
+ expect(
58
+ getNavigationRouteAccess(
59
+ staffRoute,
60
+ { isLoading: false, isAuthenticated: false, isStaff: false },
61
+ '/staff',
62
+ ),
63
+ ).toEqual({ kind: 'forbidden' });
64
+ });
65
+
66
+ it('allows staff users on requiresStaff routes', () => {
67
+ expect(
68
+ getNavigationRouteAccess(
69
+ staffRoute,
70
+ { isLoading: false, isAuthenticated: true, isStaff: true },
71
+ '/staff',
72
+ ),
73
+ ).toEqual({ kind: 'allow' });
74
+ });
75
+
76
+ it('waits while auth is loading', () => {
77
+ expect(
78
+ getNavigationRouteAccess(
79
+ authRoute,
80
+ { isLoading: true, isAuthenticated: false, isStaff: false },
81
+ '/billing',
82
+ ),
83
+ ).toEqual({ kind: 'loading' });
84
+ });
85
+ });
@@ -0,0 +1,43 @@
1
+ import type { NavigationItem } from '../../features/config/types';
2
+
3
+ export type NavigationRouteAccess =
4
+ | { kind: 'allow' }
5
+ | { kind: 'loading' }
6
+ | { kind: 'login'; next: string }
7
+ | { kind: 'forbidden' };
8
+
9
+ export type NavigationRouteAccessState = {
10
+ isLoading: boolean;
11
+ isAuthenticated: boolean;
12
+ isStaff: boolean;
13
+ };
14
+
15
+ /**
16
+ * Client-side route access for navigation items. APIs remain the source of truth for
17
+ * authorization; this is UX defense-in-depth for `requiresAuth` and `requiresStaff`.
18
+ */
19
+ export const getNavigationRouteAccess = (
20
+ item: NavigationItem,
21
+ state: NavigationRouteAccessState,
22
+ nextPath: string,
23
+ ): NavigationRouteAccess => {
24
+ if (item.requiresAuth) {
25
+ if (state.isLoading) {
26
+ return { kind: 'loading' };
27
+ }
28
+ if (!state.isAuthenticated) {
29
+ return { kind: 'login', next: nextPath };
30
+ }
31
+ }
32
+
33
+ if (item.requiresStaff) {
34
+ if (state.isLoading) {
35
+ return { kind: 'loading' };
36
+ }
37
+ if (!state.isAuthenticated || !state.isStaff) {
38
+ return { kind: 'forbidden' };
39
+ }
40
+ }
41
+
42
+ return { kind: 'allow' };
43
+ };
@@ -1,23 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from 'vitest';
2
- import { clearStoredAuthSession } from './clearStoredAuthSession';
3
-
4
- describe('clearStoredAuthSession', () => {
5
- beforeEach(() => {
6
- Object.defineProperty(globalThis, 'localStorage', {
7
- configurable: true,
8
- value: {
9
- getItem: vi.fn(),
10
- setItem: vi.fn(),
11
- removeItem: vi.fn(),
12
- clear: vi.fn(),
13
- key: vi.fn(() => null),
14
- length: 0,
15
- } as unknown as Storage,
16
- });
17
- });
18
-
19
- it('removes auth session from storage', () => {
20
- clearStoredAuthSession();
21
- expect(localStorage.removeItem).toHaveBeenCalledWith('shellui.auth.session');
22
- });
23
- });
@@ -1,10 +0,0 @@
1
- const AUTH_SESSION_STORAGE_KEY = 'shellui.auth.session';
2
-
3
- // Removes the persisted auth session from local storage.
4
- export const clearStoredAuthSession = () => {
5
- try {
6
- localStorage.removeItem(AUTH_SESSION_STORAGE_KEY);
7
- } catch {
8
- // Ignore storage errors.
9
- }
10
- };
@@ -1,35 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from 'vitest';
2
- import { persistAuthSession } from './persistAuthSession';
3
- import type { AuthSession } from '../types';
4
-
5
- const createStorageMock = () => {
6
- const data = new Map<string, string>();
7
- return {
8
- getItem: vi.fn((key: string) => data.get(key) ?? null),
9
- setItem: vi.fn((key: string, value: string) => data.set(key, value)),
10
- removeItem: vi.fn((key: string) => data.delete(key)),
11
- clear: vi.fn(() => data.clear()),
12
- key: vi.fn(() => null),
13
- get length() {
14
- return data.size;
15
- },
16
- } as unknown as Storage;
17
- };
18
-
19
- describe('persistAuthSession', () => {
20
- beforeEach(() => {
21
- Object.defineProperty(globalThis, 'localStorage', {
22
- configurable: true,
23
- value: createStorageMock(),
24
- });
25
- });
26
-
27
- it('stores session under auth storage key', () => {
28
- const session = { userId: '1' } as AuthSession;
29
- persistAuthSession(session);
30
- expect(localStorage.setItem).toHaveBeenCalledWith(
31
- 'shellui.auth.session',
32
- JSON.stringify(session),
33
- );
34
- });
35
- });
@@ -1,12 +0,0 @@
1
- import type { AuthSession } from '../types';
2
-
3
- const AUTH_SESSION_STORAGE_KEY = 'shellui.auth.session';
4
-
5
- // Persists the current auth session to local storage for browser reload recovery.
6
- export const persistAuthSession = (session: AuthSession) => {
7
- try {
8
- localStorage.setItem(AUTH_SESSION_STORAGE_KEY, JSON.stringify(session));
9
- } catch {
10
- // Ignore storage errors (e.g. private mode); user can still continue in-memory.
11
- }
12
- };
@@ -1,34 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from 'vitest';
2
- import { readStoredAuthSession } from './readStoredAuthSession';
3
-
4
- const createStorageMock = (value: string | null) =>
5
- ({
6
- getItem: vi.fn(() => value),
7
- setItem: vi.fn(),
8
- removeItem: vi.fn(),
9
- clear: vi.fn(),
10
- key: vi.fn(() => null),
11
- length: 0,
12
- }) as unknown as Storage;
13
-
14
- describe('readStoredAuthSession', () => {
15
- beforeEach(() => {
16
- Object.defineProperty(globalThis, 'localStorage', {
17
- configurable: true,
18
- value: createStorageMock(null),
19
- });
20
- });
21
-
22
- it('returns null when there is no stored session', () => {
23
- expect(readStoredAuthSession()).toBeNull();
24
- });
25
-
26
- it('parses and returns stored session data', () => {
27
- const stored = JSON.stringify({ userId: 'u1', expiresAt: 123 });
28
- Object.defineProperty(globalThis, 'localStorage', {
29
- configurable: true,
30
- value: createStorageMock(stored),
31
- });
32
- expect(readStoredAuthSession()).toEqual({ userId: 'u1', expiresAt: 123 });
33
- });
34
- });
@@ -1,14 +0,0 @@
1
- import type { AuthSession } from '../types';
2
-
3
- const AUTH_SESSION_STORAGE_KEY = 'shellui.auth.session';
4
-
5
- // Reads a previously persisted auth session from local storage.
6
- export const readStoredAuthSession = (): AuthSession | null => {
7
- try {
8
- const raw = localStorage.getItem(AUTH_SESSION_STORAGE_KEY);
9
- if (!raw) return null;
10
- return JSON.parse(raw) as AuthSession;
11
- } catch {
12
- return null;
13
- }
14
- };
@@ -1,22 +0,0 @@
1
- /** Soft edge fades — mask-tapered blur so scrolling content softens toward chrome. */
2
- export function FloatingFadeMask({
3
- placement,
4
- visible,
5
- }: {
6
- placement: 'top' | 'bottom';
7
- /** False at the matching scroll edge (top/bottom) or when content does not overflow. */
8
- visible: boolean;
9
- }) {
10
- return (
11
- <div
12
- aria-hidden
13
- data-shellui-floating-fade={placement}
14
- data-visible={visible ? 'true' : 'false'}
15
- className={
16
- placement === 'top'
17
- ? 'shellui-floating-fade shellui-floating-fade-top'
18
- : 'shellui-floating-fade shellui-floating-fade-bottom'
19
- }
20
- />
21
- );
22
- }