@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.
Files changed (70) hide show
  1. package/README.md +5 -5
  2. package/package.json +3 -2
  3. package/schemas/shellui.config.schema.json +10 -2
  4. package/src/app.tsx +8 -4
  5. package/src/components/ContentView.tsx +12 -5
  6. package/src/components/ui/alert-dialog.tsx +1 -1
  7. package/src/components/ui/dialog.tsx +5 -1
  8. package/src/components/ui/dropdown-menu.tsx +39 -4
  9. package/src/components/ui/sheet.tsx +1 -1
  10. package/src/components/ui/sidebar.tsx +60 -20
  11. package/src/components/ui/tabs.tsx +52 -0
  12. package/src/constants/urls.ts +1 -0
  13. package/src/features/auth/AuthProvider.tsx +17 -6
  14. package/src/features/chromeActions/ChromeActionIcons.tsx +261 -0
  15. package/src/features/chromeActions/ChromeActionsDemoView.tsx +149 -0
  16. package/src/features/chromeActions/ChromeActionsHost.tsx +1511 -0
  17. package/src/features/chromeActions/ChromeActionsProvider.tsx +141 -0
  18. package/src/features/chromeActions/chromeActionsStore.spec.ts +61 -0
  19. package/src/features/chromeActions/chromeActionsStore.ts +77 -0
  20. package/src/features/chromeActions/computeActionInsets.spec.ts +360 -0
  21. package/src/features/chromeActions/computeActionInsets.ts +326 -0
  22. package/src/features/chromeActions/index.ts +26 -0
  23. package/src/features/chromeActions/resolveUuidForRemoveIframe.spec.ts +49 -0
  24. package/src/features/config/types.ts +16 -2
  25. package/src/features/layouts/AppLayout.tsx +30 -3
  26. package/src/features/layouts/OverlayShell.tsx +63 -13
  27. package/src/features/layouts/app-bar-inset/AppBarInsetLayout.tsx +22 -0
  28. package/src/features/layouts/appbar/AppBarLayout.tsx +230 -86
  29. package/src/features/layouts/chrome/DesktopChrome.tsx +17 -3
  30. package/src/features/layouts/chrome/InsetMobileRadiusOverlay.tsx +18 -0
  31. package/src/features/layouts/chrome/index.ts +8 -0
  32. package/src/features/layouts/chrome/runtime.ts +73 -0
  33. package/src/features/layouts/chrome/useScrollHideChrome.ts +210 -0
  34. package/src/features/layouts/floating/FloatingBottomDock.tsx +410 -0
  35. package/src/features/layouts/floating/FloatingLayout.tsx +152 -0
  36. package/src/features/layouts/floating/FloatingSidebar.tsx +327 -0
  37. package/src/features/layouts/floating/FloatingStatusScrim.tsx +36 -0
  38. package/src/features/layouts/floating/computeFloatingInsets.spec.ts +83 -0
  39. package/src/features/layouts/floating/computeFloatingInsets.ts +155 -0
  40. package/src/features/layouts/floating/isShellOwnedPath.spec.ts +25 -0
  41. package/src/features/layouts/floating/isShellOwnedPath.ts +17 -0
  42. package/src/features/layouts/floating/layoutChromeStore.spec.ts +138 -0
  43. package/src/features/layouts/floating/layoutChromeStore.ts +209 -0
  44. package/src/features/layouts/floating/scrollChrome.spec.ts +49 -0
  45. package/src/features/layouts/floating/useFloatingChrome.ts +206 -0
  46. package/src/features/layouts/sidebar/SidebarLayout.tsx +119 -37
  47. package/src/features/layouts/sidebar/types.ts +4 -0
  48. package/src/features/layouts/sidebar-inset/SidebarInsetLayout.tsx +15 -0
  49. package/src/features/layouts/windows/WindowsLayout.tsx +240 -110
  50. package/src/features/overlays/ResponsiveModal.tsx +201 -21
  51. package/src/features/overlays/overlaySize.spec.ts +18 -0
  52. package/src/features/overlays/overlaySize.ts +89 -0
  53. package/src/features/settings/SettingsProvider.tsx +36 -9
  54. package/src/features/settings/SettingsView.tsx +6 -6
  55. package/src/features/settings/components/Develop.tsx +33 -13
  56. package/src/features/settings/components/develop/ChromeActionsTestButtons.tsx +63 -0
  57. package/src/features/settings/utils/buildSettingsForPropagation.ts +16 -0
  58. package/src/features/storage/StoragePickerContext.tsx +1 -0
  59. package/src/features/storage/uploads/uploadQueue.spec.ts +56 -1
  60. package/src/features/storage/uploads/uploadQueue.ts +42 -1
  61. package/src/features/theme/applyTheme.ts +23 -5
  62. package/src/hooks/use-mobile.tsx +21 -7
  63. package/src/hooks/use-viewport.ts +40 -0
  64. package/src/i18n/translations/en/settings.json +17 -2
  65. package/src/i18n/translations/fr/settings.json +17 -2
  66. package/src/index.css +473 -12
  67. package/src/index.html +6 -4
  68. package/src/index.ts +8 -0
  69. package/src/routes/components/RouteFallback.tsx +21 -2
  70. package/src/routes/routes.tsx +14 -0
@@ -16,16 +16,18 @@ import { DialogTestButtons } from './develop/DialogTestButtons';
16
16
  import { ModalTestButtons } from './develop/ModalTestButtons';
17
17
  import { DrawerTestButtons } from './develop/DrawerTestButtons';
18
18
  import { StoragePickerTestButtons } from './develop/StoragePickerTestButtons';
19
+ import { ChromeActionsTestButtons } from './develop/ChromeActionsTestButtons';
19
20
  import { captureException } from '../../sentry/initSentry';
20
21
  import { useCookieConsent } from '../../cookieConsent/useCookieConsent';
21
- import type { LayoutType } from '../../config/types';
22
+ import { normalizeLayoutType, type LayoutType } from '../../config/types';
22
23
 
23
24
  export const Develop = () => {
24
25
  const { t } = useTranslation('settings');
25
26
  const { settings, updateSetting } = useSettings();
26
27
  const { config } = useConfig();
27
28
  const currentLanguage = settings.language?.code || 'en';
28
- const effectiveLayout: LayoutType = settings.layout ?? config?.layout ?? 'sidebar';
29
+ const effectiveLayout: LayoutType =
30
+ normalizeLayoutType(settings.layout ?? config?.layout) ?? 'sidebar';
29
31
  const navItems = config?.navigation?.length
30
32
  ? flattenNavigationItems(config?.navigation ?? []).filter(
31
33
  (item, index, self) => index === self.findIndex((i) => i.path === item.path),
@@ -151,17 +153,34 @@ export const Develop = () => {
151
153
  >
152
154
  {t('develop.layout.title')}
153
155
  </h3>
154
- <div className="flex flex-wrap gap-2">
155
- {(['sidebar', 'app-bar', 'windows'] as const).map((layoutMode) => (
156
- <Button
157
- key={layoutMode}
158
- variant={effectiveLayout === layoutMode ? 'default' : 'outline'}
159
- size="sm"
160
- onClick={() => updateSetting('layout', layoutMode as LayoutType)}
161
- >
162
- {t(`develop.layout.${layoutMode}`)}
163
- </Button>
164
- ))}
156
+ <p className="mb-3 text-sm text-muted-foreground">{t('develop.layout.description')}</p>
157
+ <div
158
+ role="group"
159
+ aria-label={t('develop.layout.title')}
160
+ className="inline-flex max-w-full flex-wrap gap-1 rounded-xl border border-border/70 bg-muted/40 p-1"
161
+ >
162
+ {(
163
+ ['sidebar', 'sidebar-inset', 'app-bar', 'app-bar-inset', 'floating', 'windows'] as const
164
+ ).map((layoutMode) => {
165
+ const active = effectiveLayout === layoutMode;
166
+ return (
167
+ <Button
168
+ key={layoutMode}
169
+ type="button"
170
+ variant="ghost"
171
+ size="sm"
172
+ aria-pressed={active}
173
+ className={
174
+ active
175
+ ? 'bg-background text-foreground shadow-sm hover:bg-background'
176
+ : 'text-muted-foreground hover:bg-transparent hover:text-foreground'
177
+ }
178
+ onClick={() => updateSetting('layout', layoutMode as LayoutType)}
179
+ >
180
+ {t(`develop.layout.${layoutMode}`)}
181
+ </Button>
182
+ );
183
+ })}
165
184
  </div>
166
185
  </div>
167
186
 
@@ -213,6 +232,7 @@ export const Develop = () => {
213
232
  <ModalTestButtons />
214
233
  <DrawerTestButtons />
215
234
  <StoragePickerTestButtons />
235
+ <ChromeActionsTestButtons />
216
236
  {errorReportingConfigured && (
217
237
  <div className="flex items-center justify-between">
218
238
  <div className="space-y-0.5">
@@ -0,0 +1,63 @@
1
+ import { useTranslation } from 'react-i18next';
2
+ import { Button } from '../../../../components/ui/button';
3
+ import { shellui } from '@shellui/sdk';
4
+ import urls from '../../../../constants/urls';
5
+
6
+ /**
7
+ * Settings → Develop: open the chrome-actions demo inside a modal/drawer iframe
8
+ * so `shellui.actions.*` runs through the real postMessage path.
9
+ */
10
+ export const ChromeActionsTestButtons = () => {
11
+ const { t } = useTranslation('settings');
12
+
13
+ return (
14
+ <div>
15
+ <h4
16
+ className="text-sm font-medium mb-2"
17
+ style={{ fontFamily: 'var(--heading-font-family, inherit)' }}
18
+ >
19
+ {t('develop.testing.chromeActions.title')}
20
+ </h4>
21
+ <div className="flex flex-wrap gap-2">
22
+ <Button
23
+ type="button"
24
+ variant="outline"
25
+ onClick={() =>
26
+ shellui.openModal({
27
+ url: urls.chromeActionsDemo,
28
+ size: 'lg',
29
+ })
30
+ }
31
+ >
32
+ {t('develop.testing.chromeActions.buttons.openModal')}
33
+ </Button>
34
+ <Button
35
+ type="button"
36
+ variant="outline"
37
+ onClick={() =>
38
+ shellui.openDrawer({
39
+ url: urls.chromeActionsDemo,
40
+ position: 'bottom',
41
+ size: '70vh',
42
+ })
43
+ }
44
+ >
45
+ {t('develop.testing.chromeActions.buttons.openDrawer')}
46
+ </Button>
47
+ <Button
48
+ type="button"
49
+ variant="outline"
50
+ onClick={() => {
51
+ shellui.closeDrawer();
52
+ shellui.closeModal();
53
+ }}
54
+ >
55
+ {t('develop.testing.chromeActions.buttons.close')}
56
+ </Button>
57
+ </div>
58
+ <p className="text-xs text-muted-foreground mt-2">
59
+ {t('develop.testing.chromeActions.description')}
60
+ </p>
61
+ </div>
62
+ );
63
+ };
@@ -4,6 +4,7 @@ import { flattenNavigationItems } from './flattenNavigationItems';
4
4
  import { getAvailableThemesForSettings } from './getAvailableThemesForSettings';
5
5
  import { getResolvedAppearanceForSettings } from './getResolvedAppearanceForSettings';
6
6
  import { resolveLabel } from './resolveLabel';
7
+ import { getPublishedLayoutChrome } from '../../layouts/floating/layoutChromeStore';
7
8
 
8
9
  /**
9
10
  * Build settings for propagation to iframes: inject navigation, full theme object,
@@ -16,6 +17,8 @@ export const buildSettingsForPropagation = (
16
17
  options?: {
17
18
  includeAuthAccessToken?: boolean;
18
19
  accessToken?: string | null;
20
+ /** When false, omit layoutChrome (modal / drawer frames). Default true. */
21
+ includeLayoutChrome?: boolean;
19
22
  },
20
23
  ): Settings => {
21
24
  const appearance = getResolvedAppearanceForSettings(settings, config);
@@ -24,6 +27,19 @@ export const buildSettingsForPropagation = (
24
27
  appearance: appearance ?? settings.appearance,
25
28
  };
26
29
 
30
+ if (options?.includeLayoutChrome !== false) {
31
+ const layoutChrome = getPublishedLayoutChrome();
32
+ if (layoutChrome) {
33
+ result = { ...result, layoutChrome };
34
+ } else if ('layoutChrome' in result) {
35
+ const { layoutChrome: _removed, ...rest } = result;
36
+ result = rest;
37
+ }
38
+ } else if ('layoutChrome' in result) {
39
+ const { layoutChrome: _removed, ...rest } = result;
40
+ result = rest;
41
+ }
42
+
27
43
  // Inject available themes when we have a resolved appearance (themes are already registered above)
28
44
  if (result.appearance && typeof window !== 'undefined') {
29
45
  result = {
@@ -203,6 +203,7 @@ export const StoragePickerProvider = ({ children }: StoragePickerProviderProps)
203
203
  url={pending.url}
204
204
  pathPrefix="storage-picker"
205
205
  ignoreMessages={true}
206
+ layoutChrome={false}
206
207
  navItem={pickerNavItem}
207
208
  />
208
209
  </div>
@@ -1,4 +1,4 @@
1
- import { afterEach, describe, expect, it } from 'vitest';
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
2
  import {
3
3
  addUpload,
4
4
  closeUploadToaster,
@@ -15,11 +15,17 @@ import {
15
15
  setUploadProgress,
16
16
  setUploadToastExpanded,
17
17
  isUploadToastExpanded,
18
+ UPLOAD_TOAST_AUTO_DISMISS_MS,
18
19
  } from './uploadQueue';
19
20
 
20
21
  describe('uploadQueue', () => {
22
+ beforeEach(() => {
23
+ vi.useFakeTimers();
24
+ });
25
+
21
26
  afterEach(() => {
22
27
  resetUploadQueue();
28
+ vi.useRealTimers();
23
29
  });
24
30
 
25
31
  it('tracks progress and overall percent across files', () => {
@@ -115,4 +121,53 @@ describe('uploadQueue', () => {
115
121
  expect(getUploadQueue()).toEqual([]);
116
122
  expect(isUploadToastExpanded()).toBe(false);
117
123
  });
124
+
125
+ it('auto-dismisses the toaster a few seconds after all uploads succeed', () => {
126
+ addUpload({ id: 'a', name: 'a.pdf', path: 'a.pdf', bucket: 'company', size: 10 });
127
+ addUpload({ id: 'b', name: 'b.pdf', path: 'b.pdf', bucket: 'company', size: 10 });
128
+ completeUpload('a');
129
+ expect(getUploadQueue()).toHaveLength(2);
130
+ completeUpload('b');
131
+ expect(getUploadQueue()).toHaveLength(2);
132
+
133
+ vi.advanceTimersByTime(UPLOAD_TOAST_AUTO_DISMISS_MS - 1);
134
+ expect(getUploadQueue()).toHaveLength(2);
135
+
136
+ vi.advanceTimersByTime(1);
137
+ expect(getUploadQueue()).toEqual([]);
138
+ });
139
+
140
+ it('does not auto-dismiss when any upload fails', () => {
141
+ addUpload({ id: 'ok', name: 'ok.pdf', path: 'ok.pdf', bucket: 'company', size: 10 });
142
+ addUpload({ id: 'bad', name: 'bad.pdf', path: 'bad.pdf', bucket: 'company', size: 10 });
143
+ completeUpload('ok');
144
+ failUpload('bad', 'Denied');
145
+
146
+ vi.advanceTimersByTime(UPLOAD_TOAST_AUTO_DISMISS_MS * 2);
147
+ expect(getUploadQueue()).toHaveLength(2);
148
+ expect(getUploadQueue().map((item) => item.status)).toEqual(['success', 'error']);
149
+ });
150
+
151
+ it('cancels a pending auto-dismiss when a new upload starts', () => {
152
+ addUpload({ id: 'ok', name: 'ok.pdf', path: 'ok.pdf', bucket: 'company', size: 10 });
153
+ completeUpload('ok');
154
+
155
+ vi.advanceTimersByTime(UPLOAD_TOAST_AUTO_DISMISS_MS - 100);
156
+ addUpload({ id: 'next', name: 'next.pdf', path: 'next.pdf', bucket: 'company', size: 10 });
157
+
158
+ vi.advanceTimersByTime(UPLOAD_TOAST_AUTO_DISMISS_MS);
159
+ expect(getUploadQueue().map((item) => item.id)).toEqual(['ok', 'next']);
160
+ });
161
+
162
+ it('cancels a pending auto-dismiss when the toaster is closed manually', () => {
163
+ addUpload({ id: 'ok', name: 'ok.pdf', path: 'ok.pdf', bucket: 'company', size: 10 });
164
+ completeUpload('ok');
165
+ closeUploadToaster();
166
+ expect(getUploadQueue()).toEqual([]);
167
+
168
+ addUpload({ id: 'again', name: 'again.pdf', path: 'again.pdf', bucket: 'company', size: 10 });
169
+ vi.advanceTimersByTime(UPLOAD_TOAST_AUTO_DISMISS_MS);
170
+ expect(getUploadQueue()).toHaveLength(1);
171
+ expect(getUploadQueue()[0]?.status).toBe('uploading');
172
+ });
118
173
  });
@@ -2,6 +2,8 @@ import type { UploadItem, UploadItemStatus, UploadQueueSummary } from './types';
2
2
 
3
3
  export const UPLOAD_TOAST_ID = 'shellui-upload-progress';
4
4
  export const UPLOAD_TOAST_DEMO_MESSAGE = 'SHELLUI_UPLOAD_TOAST_DEMO';
5
+ /** Brief pause so the success state is visible before the toaster hides. */
6
+ export const UPLOAD_TOAST_AUTO_DISMISS_MS = 2500;
5
7
 
6
8
  type UploadListener = () => void;
7
9
 
@@ -21,6 +23,33 @@ const demoStartTimeouts: ReturnType<typeof setTimeout>[] = [];
21
23
 
22
24
  let items: UploadItem[] = [];
23
25
  let expanded = false;
26
+ let autoDismissTimeout: ReturnType<typeof setTimeout> | null = null;
27
+
28
+ function clearAutoDismissTimeout(): void {
29
+ if (autoDismissTimeout === null) return;
30
+ clearTimeout(autoDismissTimeout);
31
+ autoDismissTimeout = null;
32
+ }
33
+
34
+ /**
35
+ * Hide the toaster a few seconds after every upload finishes successfully.
36
+ * Errors and in-progress uploads keep the panel open; cancelled-only queues stay too.
37
+ */
38
+ function scheduleAutoDismissIfNeeded(): void {
39
+ clearAutoDismissTimeout();
40
+ const summary = getUploadSummary();
41
+ if (summary.uploading > 0 || summary.error > 0 || summary.success === 0) {
42
+ return;
43
+ }
44
+ autoDismissTimeout = setTimeout(() => {
45
+ autoDismissTimeout = null;
46
+ const current = getUploadSummary();
47
+ if (current.uploading > 0 || current.error > 0 || current.success === 0) {
48
+ return;
49
+ }
50
+ resetUploadQueue();
51
+ }, UPLOAD_TOAST_AUTO_DISMISS_MS);
52
+ }
24
53
 
25
54
  function emit(): void {
26
55
  listeners.forEach((listener) => listener());
@@ -115,6 +144,7 @@ export function getItemPercent(item: UploadItem): number {
115
144
  }
116
145
 
117
146
  export function addUpload(input: AddUploadInput): { id: string; signal: AbortSignal } {
147
+ clearAutoDismissTimeout();
118
148
  const id = input.id ?? createId();
119
149
  const existing = abortControllers.get(id);
120
150
  existing?.abort();
@@ -159,6 +189,7 @@ export function completeUpload(id: string): void {
159
189
  bytesUploaded: item.size || item.bytesUploaded,
160
190
  error: undefined,
161
191
  });
192
+ scheduleAutoDismissIfNeeded();
162
193
  }
163
194
 
164
195
  export function failUpload(id: string, message: string): void {
@@ -167,6 +198,7 @@ export function failUpload(id: string, message: string): void {
167
198
  abortControllers.delete(id);
168
199
  clearDemoTimer(id);
169
200
  patchItem(id, { status: 'error', error: message });
201
+ clearAutoDismissTimeout();
170
202
  }
171
203
 
172
204
  export function markUploadCancelled(id: string): void {
@@ -174,6 +206,7 @@ export function markUploadCancelled(id: string): void {
174
206
  abortControllers.delete(id);
175
207
  clearDemoTimer(id);
176
208
  patchItem(id, { status: 'cancelled' });
209
+ scheduleAutoDismissIfNeeded();
177
210
  }
178
211
 
179
212
  /** Abort an in-progress upload and keep it visible as cancelled. */
@@ -196,11 +229,18 @@ export function removeUpload(id: string): void {
196
229
  const next = items.filter((entry) => entry.id !== id);
197
230
  if (next.length === items.length) return;
198
231
  items = next;
199
- if (items.length === 0) expanded = false;
232
+ if (items.length === 0) {
233
+ expanded = false;
234
+ clearAutoDismissTimeout();
235
+ }
200
236
  emit();
237
+ if (items.length > 0) {
238
+ scheduleAutoDismissIfNeeded();
239
+ }
201
240
  }
202
241
 
203
242
  export function dismissFinishedUploads(): void {
243
+ clearAutoDismissTimeout();
204
244
  const keep = items.filter((item) => item.status === 'uploading');
205
245
  items.forEach((item) => {
206
246
  if (item.status === 'uploading') return;
@@ -228,6 +268,7 @@ export function closeUploadToaster(): void {
228
268
  }
229
269
 
230
270
  export function resetUploadQueue(): void {
271
+ clearAutoDismissTimeout();
231
272
  abortControllers.forEach((controller) => controller.abort());
232
273
  abortControllers.clear();
233
274
  demoTimers.forEach((timer) => clearInterval(timer));
@@ -1,5 +1,7 @@
1
1
  import { toCssVarValue } from './color';
2
2
  import type { ThemeColorsMode, ThemeDefinition } from './types';
3
+ import { isHomeScreenPwa, isTauriRuntime } from '../layouts/chrome/runtime';
4
+
3
5
  const COLOR_VAR_MAP: Array<[keyof ThemeColorsMode, string]> = [
4
6
  ['background', '--background'],
5
7
  ['foreground', '--foreground'],
@@ -35,13 +37,30 @@ const COLOR_VAR_MAP: Array<[keyof ThemeColorsMode, string]> = [
35
37
  ['chart5', '--chart-5'],
36
38
  ];
37
39
 
38
- /** Update <meta name="theme-color"> so PWA / browser chrome matches the active surface. */
40
+ /**
41
+ * Update <meta name="theme-color"> so browser chrome matches the active surface.
42
+ *
43
+ * Skipped for:
44
+ * - Home Screen PWAs (iOS 26/27 Liquid Glass ignores it; on older iOS it can
45
+ * override `black-translucent` and paint an uncoverable slab)
46
+ * - Tauri runtime (native window / status bar owns chrome; meta is meaningless)
47
+ */
39
48
  function syncThemeColorMeta(cssColor: string): void {
40
- if (typeof document === 'undefined' || !cssColor) return;
49
+ if (typeof document === 'undefined') return;
41
50
  const head = document.head || document.getElementsByTagName('head')[0];
42
51
  if (!head) return;
43
52
 
44
- // Prefer a single unconditional theme-color (iOS reads this; media variants are flaky standalone)
53
+ const skip = isTauriRuntime() || isHomeScreenPwa();
54
+ const existing = head.querySelectorAll<HTMLMetaElement>('meta[name="theme-color"]');
55
+
56
+ if (skip) {
57
+ existing.forEach((meta) => meta.remove());
58
+ return;
59
+ }
60
+
61
+ if (!cssColor) return;
62
+
63
+ // Prefer a single unconditional theme-color (media variants are flaky)
45
64
  let meta = head.querySelector<HTMLMetaElement>('meta[name="theme-color"]:not([media])');
46
65
  if (!meta) {
47
66
  meta = document.createElement('meta');
@@ -76,8 +95,7 @@ export function applyTheme(theme: ThemeDefinition, isDark: boolean): void {
76
95
 
77
96
  root.style.setProperty('--radius', colors.radius);
78
97
 
79
- // Keep browser chrome in sync. theme-color coexists with black-translucent — it
80
- // does not paint the iOS status-bar slab, sizing the shell with dvh does.
98
+ // Browser-tab chrome only — see syncThemeColorMeta (skipped for PWA / Tauri).
81
99
  syncThemeColorMeta(toCssVarValue(colors.background) || (isDark ? '#000000' : '#ffffff'));
82
100
 
83
101
  const head = document.head || document.getElementsByTagName('head')[0];
@@ -2,18 +2,32 @@ import * as React from 'react';
2
2
 
3
3
  const MOBILE_BREAKPOINT = 768;
4
4
 
5
+ function readIsMobile(): boolean {
6
+ if (typeof window === 'undefined') return false;
7
+ return window.innerWidth < MOBILE_BREAKPOINT;
8
+ }
9
+
10
+ /**
11
+ * True below the `md` breakpoint (width &lt; 768).
12
+ * Listens to matchMedia **and** resize/orientationchange — iOS often updates
13
+ * `innerWidth` on resize before (or without) a reliable matchMedia `change`.
14
+ */
5
15
  export function useIsMobile() {
6
- const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined);
16
+ const [isMobile, setIsMobile] = React.useState<boolean>(readIsMobile);
7
17
 
8
18
  React.useEffect(() => {
19
+ const sync = () => setIsMobile(readIsMobile());
9
20
  const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
10
- const onChange = () => {
11
- setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
21
+ mql.addEventListener('change', sync);
22
+ window.addEventListener('resize', sync);
23
+ window.addEventListener('orientationchange', sync);
24
+ sync();
25
+ return () => {
26
+ mql.removeEventListener('change', sync);
27
+ window.removeEventListener('resize', sync);
28
+ window.removeEventListener('orientationchange', sync);
12
29
  };
13
- mql.addEventListener('change', onChange);
14
- setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
15
- return () => mql.removeEventListener('change', onChange);
16
30
  }, []);
17
31
 
18
- return !!isMobile;
32
+ return isMobile;
19
33
  }
@@ -0,0 +1,40 @@
1
+ import * as React from 'react';
2
+
3
+ /** Matches Tailwind `md` (tablet and up). */
4
+ export const VIEWPORT_MOBILE_MAX = 767;
5
+ /** Matches Tailwind `lg` (desktop and up). */
6
+ export const VIEWPORT_TABLET_MAX = 1023;
7
+
8
+ export type ShellViewport = 'mobile' | 'tablet' | 'desktop';
9
+
10
+ export function resolveViewport(width: number): ShellViewport {
11
+ if (width <= VIEWPORT_MOBILE_MAX) return 'mobile';
12
+ if (width <= VIEWPORT_TABLET_MAX) return 'tablet';
13
+ return 'desktop';
14
+ }
15
+
16
+ /** Reactive viewport tier: mobile (&lt;768), tablet (768–1023), desktop (≥1024). */
17
+ export function useViewport(): ShellViewport {
18
+ const [viewport, setViewport] = React.useState<ShellViewport>(() =>
19
+ typeof window !== 'undefined' ? resolveViewport(window.innerWidth) : 'desktop',
20
+ );
21
+
22
+ React.useEffect(() => {
23
+ const sync = () => setViewport(resolveViewport(window.innerWidth));
24
+ const mobileMql = window.matchMedia(`(max-width: ${VIEWPORT_MOBILE_MAX}px)`);
25
+ const tabletMql = window.matchMedia(
26
+ `(min-width: ${VIEWPORT_MOBILE_MAX + 1}px) and (max-width: ${VIEWPORT_TABLET_MAX}px)`,
27
+ );
28
+ mobileMql.addEventListener('change', sync);
29
+ tabletMql.addEventListener('change', sync);
30
+ window.addEventListener('resize', sync);
31
+ sync();
32
+ return () => {
33
+ mobileMql.removeEventListener('change', sync);
34
+ tabletMql.removeEventListener('change', sync);
35
+ window.removeEventListener('resize', sync);
36
+ };
37
+ }, []);
38
+
39
+ return viewport;
40
+ }
@@ -271,10 +271,16 @@
271
271
  },
272
272
  "layout": {
273
273
  "title": "Layout",
274
- "description": "Switch between sidebar layout and windows (taskbar) layout. This overrides the app config for this session.",
274
+ "description": "Switch between sidebar, inset, app bar, floating, and windows layouts. This overrides the app config for this session.",
275
275
  "sidebar": "Sidebar",
276
+ "sidebar-inset": "Sidebar inset",
276
277
  "windows": "Windows (experimental)",
277
- "app-bar": "App bar"
278
+ "app-bar": "App bar",
279
+ "app-bar-inset": "App bar inset",
280
+ "floating": "Floating",
281
+ "more": "More",
282
+ "hideSidebar": "Hide sidebar",
283
+ "showSidebar": "Show sidebar"
278
284
  },
279
285
  "logging": {
280
286
  "title": "Logging",
@@ -456,6 +462,15 @@
456
462
  "files": "Select files",
457
463
  "filesAndFolders": "Select files and folders"
458
464
  }
465
+ },
466
+ "chromeActions": {
467
+ "title": "Chrome actions",
468
+ "description": "Opens a shell-owned demo page inside a modal or drawer iframe. That iframe calls shellui.actions.set/clear so chrome and click round-trips use the real postMessage path. Use Set / Update / Clear inside the demo; narrow the viewport for ··· overflow.",
469
+ "buttons": {
470
+ "openModal": "Open demo (modal iframe)",
471
+ "openDrawer": "Open demo (drawer iframe)",
472
+ "close": "Close demo"
473
+ }
459
474
  }
460
475
  }
461
476
  }
@@ -271,10 +271,16 @@
271
271
  },
272
272
  "layout": {
273
273
  "title": "Disposition",
274
- "description": "Basculer entre la disposition avec barre latérale et la disposition fenêtres (barre des tâches). Remplace la config de l'app pour cette session.",
274
+ "description": "Basculer entre barre latérale, encadrés, barre d'app, flottante et fenêtres. Remplace la config de l'app pour cette session.",
275
275
  "sidebar": "Barre latérale",
276
+ "sidebar-inset": "Barre latérale encadrée",
276
277
  "windows": "Fenêtres (expérimental)",
277
- "app-bar": "Barre d'app"
278
+ "app-bar": "Barre d'app",
279
+ "app-bar-inset": "Barre d'app encadrée",
280
+ "floating": "Flottante",
281
+ "more": "Plus",
282
+ "hideSidebar": "Masquer la barre latérale",
283
+ "showSidebar": "Afficher la barre latérale"
278
284
  },
279
285
  "logging": {
280
286
  "title": "Journalisation",
@@ -456,6 +462,15 @@
456
462
  "files": "Sélectionner des fichiers",
457
463
  "filesAndFolders": "Sélectionner fichiers et dossiers"
458
464
  }
465
+ },
466
+ "chromeActions": {
467
+ "title": "Actions chrome",
468
+ "description": "Ouvre une page démo Shellui dans un modal ou un tiroir (iframe). Cette iframe appelle shellui.actions.set/clear pour exercer le chrome et le round-trip postMessage. Utilisez Set / Update / Clear dans la démo ; réduisez la fenêtre pour le menu ···.",
469
+ "buttons": {
470
+ "openModal": "Ouvrir la démo (modal iframe)",
471
+ "openDrawer": "Ouvrir la démo (tiroir iframe)",
472
+ "close": "Fermer la démo"
473
+ }
459
474
  }
460
475
  }
461
476
  }