@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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useCallback,
|
|
3
3
|
useEffect,
|
|
4
|
+
useLayoutEffect,
|
|
4
5
|
useRef,
|
|
5
6
|
useState,
|
|
6
7
|
type CSSProperties,
|
|
@@ -9,16 +10,20 @@ import {
|
|
|
9
10
|
} from 'react';
|
|
10
11
|
import { Dialog, DialogContent, DialogDescription, DialogTitle } from '../../components/ui/dialog';
|
|
11
12
|
import { cn } from '../../lib/utils';
|
|
13
|
+
import { sheetExpandedHeightPx } from './overlaySize';
|
|
12
14
|
|
|
13
15
|
export type ResponsiveModalPresentation = 'dialog' | 'sheet';
|
|
14
16
|
|
|
15
17
|
const SWIPE_DISMISS_PX = 80;
|
|
16
18
|
const SWIPE_DISMISS_RATIO = 0.2;
|
|
19
|
+
/** Drag distance (px) to commit expand / collapse on release. */
|
|
20
|
+
const SHEET_SNAP_COMMIT_PX = 56;
|
|
17
21
|
const MIN_WIDTH = 320;
|
|
18
22
|
const MIN_HEIGHT = 240;
|
|
19
23
|
const VIEWPORT_MARGIN = 8;
|
|
20
24
|
|
|
21
25
|
type ResizeEdge = 'n' | 's' | 'e' | 'w' | 'ne' | 'nw' | 'se' | 'sw';
|
|
26
|
+
type SheetSnap = 'normal' | 'expanded';
|
|
22
27
|
|
|
23
28
|
type ModalGeometry = {
|
|
24
29
|
x: number;
|
|
@@ -133,6 +138,16 @@ export function ResponsiveModal({
|
|
|
133
138
|
const dragCurrentY = useRef(0);
|
|
134
139
|
const [sheetDragOffset, setSheetDragOffset] = useState(0);
|
|
135
140
|
const [isSheetDragging, setIsSheetDragging] = useState(false);
|
|
141
|
+
/** True only during the opening slide so resize morph doesn’t re-trigger enter. */
|
|
142
|
+
const [enterMotion, setEnterMotion] = useState(false);
|
|
143
|
+
/** Swipe dismiss already translated off-screen — skip the CSS close slide. */
|
|
144
|
+
const [dismissMode, setDismissMode] = useState<'none' | 'swipe'>('none');
|
|
145
|
+
/** Bottom sheet height snap: normal (configured) ↔ near-full. */
|
|
146
|
+
const [sheetSnap, setSheetSnap] = useState<SheetSnap>('normal');
|
|
147
|
+
/** Live height while dragging between snaps (px). */
|
|
148
|
+
const [sheetDragHeight, setSheetDragHeight] = useState<number | null>(null);
|
|
149
|
+
const normalHeightRef = useRef<number | null>(null);
|
|
150
|
+
const sheetSnapRef = useRef<SheetSnap>('normal');
|
|
136
151
|
|
|
137
152
|
const [geometry, setGeometry] = useState<ModalGeometry | null>(null);
|
|
138
153
|
const geometryRef = useRef<ModalGeometry | null>(null);
|
|
@@ -310,12 +325,60 @@ export function ResponsiveModal({
|
|
|
310
325
|
dragCurrentY.current = 0;
|
|
311
326
|
setSheetDragOffset(0);
|
|
312
327
|
setIsSheetDragging(false);
|
|
328
|
+
setDismissMode('none');
|
|
329
|
+
setSheetSnap('normal');
|
|
330
|
+
sheetSnapRef.current = 'normal';
|
|
331
|
+
setSheetDragHeight(null);
|
|
332
|
+
normalHeightRef.current = null;
|
|
333
|
+
if (isSheet) {
|
|
334
|
+
setEnterMotion(true);
|
|
335
|
+
const t = window.setTimeout(() => setEnterMotion(false), 450);
|
|
336
|
+
return () => window.clearTimeout(t);
|
|
337
|
+
}
|
|
338
|
+
setEnterMotion(false);
|
|
339
|
+
return;
|
|
313
340
|
}
|
|
314
|
-
|
|
341
|
+
setEnterMotion(false);
|
|
342
|
+
}, [open, isSheet]);
|
|
343
|
+
|
|
344
|
+
useEffect(() => {
|
|
345
|
+
sheetSnapRef.current = sheetSnap;
|
|
346
|
+
}, [sheetSnap]);
|
|
347
|
+
|
|
348
|
+
const expandedSheetHeight = useCallback(() => {
|
|
349
|
+
return sheetExpandedHeightPx();
|
|
350
|
+
}, []);
|
|
351
|
+
|
|
352
|
+
// Remember the configured (normal) height whenever we're settled at that snap
|
|
353
|
+
useLayoutEffect(() => {
|
|
354
|
+
if (
|
|
355
|
+
!open ||
|
|
356
|
+
!isSheet ||
|
|
357
|
+
sheetSnap !== 'normal' ||
|
|
358
|
+
isSheetDragging ||
|
|
359
|
+
sheetDragHeight !== null
|
|
360
|
+
) {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
const h = contentRef.current?.offsetHeight;
|
|
364
|
+
if (h && h > 0) {
|
|
365
|
+
normalHeightRef.current = h;
|
|
366
|
+
}
|
|
367
|
+
}, [open, isSheet, sheetSnap, isSheetDragging, sheetDragHeight, style, className, children]);
|
|
368
|
+
|
|
369
|
+
const canExpandSheet = useCallback(() => {
|
|
370
|
+
const normal = normalHeightRef.current ?? contentRef.current?.offsetHeight ?? 0;
|
|
371
|
+
const expanded = expandedSheetHeight();
|
|
372
|
+
return normal > 0 && expanded - normal >= SHEET_SNAP_COMMIT_PX;
|
|
373
|
+
}, [expandedSheetHeight]);
|
|
315
374
|
|
|
316
375
|
const handleSheetPointerDown = useCallback(
|
|
317
376
|
(e: ReactPointerEvent<HTMLDivElement>) => {
|
|
318
377
|
if (!isSheet || !dismissible) return;
|
|
378
|
+
// Capture normal height before expand so collapse can restore it
|
|
379
|
+
if (sheetSnapRef.current === 'normal' && contentRef.current) {
|
|
380
|
+
normalHeightRef.current = contentRef.current.offsetHeight;
|
|
381
|
+
}
|
|
319
382
|
dragStartY.current = e.clientY;
|
|
320
383
|
dragCurrentY.current = 0;
|
|
321
384
|
setIsSheetDragging(true);
|
|
@@ -324,12 +387,45 @@ export function ResponsiveModal({
|
|
|
324
387
|
[isSheet, dismissible],
|
|
325
388
|
);
|
|
326
389
|
|
|
327
|
-
const handleSheetPointerMove = useCallback(
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
390
|
+
const handleSheetPointerMove = useCallback(
|
|
391
|
+
(e: ReactPointerEvent<HTMLDivElement>) => {
|
|
392
|
+
if (dragStartY.current === null) return;
|
|
393
|
+
const rawDelta = e.clientY - dragStartY.current; // +down / −up
|
|
394
|
+
dragCurrentY.current = rawDelta;
|
|
395
|
+
const normal = normalHeightRef.current ?? contentRef.current?.offsetHeight ?? 0;
|
|
396
|
+
const expanded = expandedSheetHeight();
|
|
397
|
+
const expandable = canExpandSheet();
|
|
398
|
+
|
|
399
|
+
if (sheetSnapRef.current === 'normal') {
|
|
400
|
+
if (rawDelta >= 0 || !expandable) {
|
|
401
|
+
// Drag down → dismiss preview (no upward expand)
|
|
402
|
+
setSheetDragOffset(Math.max(0, rawDelta));
|
|
403
|
+
setSheetDragHeight(null);
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
// Drag up → grow toward expanded
|
|
407
|
+
setSheetDragOffset(0);
|
|
408
|
+
setSheetDragHeight(Math.min(expanded, normal - rawDelta));
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// Expanded: drag down shrinks; further down peeks dismiss translate
|
|
413
|
+
if (rawDelta <= 0) {
|
|
414
|
+
setSheetDragOffset(0);
|
|
415
|
+
setSheetDragHeight(expanded);
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
const shrinkRange = expanded - normal;
|
|
419
|
+
if (rawDelta < shrinkRange) {
|
|
420
|
+
setSheetDragOffset(0);
|
|
421
|
+
setSheetDragHeight(expanded - rawDelta);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
setSheetDragHeight(normal);
|
|
425
|
+
setSheetDragOffset(rawDelta - shrinkRange);
|
|
426
|
+
},
|
|
427
|
+
[canExpandSheet, expandedSheetHeight],
|
|
428
|
+
);
|
|
333
429
|
|
|
334
430
|
const handleSheetPointerUp = useCallback(
|
|
335
431
|
(e: ReactPointerEvent<HTMLDivElement>) => {
|
|
@@ -339,32 +435,87 @@ export function ResponsiveModal({
|
|
|
339
435
|
} catch {
|
|
340
436
|
// ignore
|
|
341
437
|
}
|
|
342
|
-
const
|
|
438
|
+
const rawDelta = dragCurrentY.current;
|
|
343
439
|
const height = contentRef.current?.offsetHeight ?? window.innerHeight;
|
|
344
|
-
const
|
|
440
|
+
const normal = normalHeightRef.current ?? height;
|
|
441
|
+
const expanded = expandedSheetHeight();
|
|
442
|
+
const expandable = canExpandSheet();
|
|
345
443
|
|
|
346
444
|
dragStartY.current = null;
|
|
347
445
|
dragCurrentY.current = 0;
|
|
348
446
|
setIsSheetDragging(false);
|
|
349
447
|
|
|
350
|
-
if (
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
448
|
+
if (sheetSnapRef.current === 'normal') {
|
|
449
|
+
if (rawDelta > 0) {
|
|
450
|
+
const shouldDismiss =
|
|
451
|
+
dismissible &&
|
|
452
|
+
(rawDelta >= SWIPE_DISMISS_PX || rawDelta >= height * SWIPE_DISMISS_RATIO);
|
|
453
|
+
if (shouldDismiss) {
|
|
454
|
+
setDismissMode('swipe');
|
|
455
|
+
setSheetDragOffset(Math.max(rawDelta, height));
|
|
456
|
+
setSheetDragHeight(null);
|
|
457
|
+
onOpenChange(false);
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
setSheetDragOffset(0);
|
|
461
|
+
setSheetDragHeight(null);
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// Dragged up — commit expand if far enough / past midpoint
|
|
466
|
+
if (
|
|
467
|
+
expandable &&
|
|
468
|
+
(normal - rawDelta >= (normal + expanded) / 2 || -rawDelta >= SHEET_SNAP_COMMIT_PX)
|
|
469
|
+
) {
|
|
470
|
+
setSheetSnap('expanded');
|
|
471
|
+
sheetSnapRef.current = 'expanded';
|
|
472
|
+
setSheetDragHeight(null);
|
|
473
|
+
setSheetDragOffset(0);
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
setSheetDragHeight(null);
|
|
477
|
+
setSheetDragOffset(0);
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// From expanded
|
|
482
|
+
const shrinkRange = Math.max(1, expanded - normal);
|
|
483
|
+
if (rawDelta > shrinkRange) {
|
|
484
|
+
const dismissDelta = rawDelta - shrinkRange;
|
|
485
|
+
const shouldDismiss =
|
|
486
|
+
dismissible &&
|
|
487
|
+
(dismissDelta >= SWIPE_DISMISS_PX || dismissDelta >= normal * SWIPE_DISMISS_RATIO);
|
|
488
|
+
if (shouldDismiss) {
|
|
489
|
+
setDismissMode('swipe');
|
|
490
|
+
setSheetDragOffset(Math.max(dismissDelta, height));
|
|
491
|
+
setSheetDragHeight(null);
|
|
492
|
+
onOpenChange(false);
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
// Not far enough past normal — collapse to normal
|
|
496
|
+
setSheetSnap('normal');
|
|
497
|
+
sheetSnapRef.current = 'normal';
|
|
498
|
+
setSheetDragHeight(null);
|
|
499
|
+
setSheetDragOffset(0);
|
|
354
500
|
return;
|
|
355
501
|
}
|
|
356
502
|
|
|
357
|
-
|
|
503
|
+
if (rawDelta >= SHEET_SNAP_COMMIT_PX || expanded - rawDelta <= (normal + expanded) / 2) {
|
|
504
|
+
setSheetSnap('normal');
|
|
505
|
+
sheetSnapRef.current = 'normal';
|
|
506
|
+
}
|
|
507
|
+
setSheetDragHeight(null);
|
|
358
508
|
setSheetDragOffset(0);
|
|
359
509
|
},
|
|
360
|
-
[dismissible, onOpenChange],
|
|
510
|
+
[canExpandSheet, dismissible, expandedSheetHeight, onOpenChange],
|
|
361
511
|
);
|
|
362
512
|
|
|
363
513
|
const canMove = movable && !isSheet;
|
|
364
514
|
const canResize = resizable && !isSheet;
|
|
365
515
|
const hasCustomGeometry = !isSheet && geometry !== null;
|
|
366
516
|
|
|
367
|
-
const sheetExitTransition =
|
|
517
|
+
const sheetExitTransition =
|
|
518
|
+
'transform 0.32s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.32s ease-out, height 0.32s cubic-bezier(0.32, 0.72, 0, 1), max-height 0.32s cubic-bezier(0.32, 0.72, 0, 1)';
|
|
368
519
|
|
|
369
520
|
const geometryStyle: CSSProperties | undefined = hasCustomGeometry
|
|
370
521
|
? {
|
|
@@ -380,6 +531,26 @@ export function ResponsiveModal({
|
|
|
380
531
|
}
|
|
381
532
|
: undefined;
|
|
382
533
|
|
|
534
|
+
const sheetHeightStyle: CSSProperties | undefined = (() => {
|
|
535
|
+
if (!isSheet) return undefined;
|
|
536
|
+
if (sheetDragHeight !== null) {
|
|
537
|
+
return {
|
|
538
|
+
height: sheetDragHeight,
|
|
539
|
+
maxHeight: sheetDragHeight,
|
|
540
|
+
minHeight: sheetDragHeight,
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
if (sheetSnap === 'expanded') {
|
|
544
|
+
const h = expandedSheetHeight();
|
|
545
|
+
return {
|
|
546
|
+
height: h,
|
|
547
|
+
maxHeight: h,
|
|
548
|
+
minHeight: h,
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
return undefined;
|
|
552
|
+
})();
|
|
553
|
+
|
|
383
554
|
return (
|
|
384
555
|
<Dialog
|
|
385
556
|
open={open}
|
|
@@ -392,6 +563,9 @@ export function ResponsiveModal({
|
|
|
392
563
|
data-presentation={presentation}
|
|
393
564
|
data-geometry={hasCustomGeometry ? 'custom' : 'auto'}
|
|
394
565
|
data-window-interacting={isWindowInteracting ? 'true' : undefined}
|
|
566
|
+
data-enter-motion={enterMotion ? '' : undefined}
|
|
567
|
+
data-dismiss={dismissMode === 'swipe' ? 'swipe' : undefined}
|
|
568
|
+
data-sheet-snap={isSheet ? sheetSnap : undefined}
|
|
395
569
|
showCloseButton={showCloseButton}
|
|
396
570
|
className={cn(
|
|
397
571
|
'gap-0 p-0 overflow-hidden flex flex-col',
|
|
@@ -403,11 +577,16 @@ export function ResponsiveModal({
|
|
|
403
577
|
style={{
|
|
404
578
|
...style,
|
|
405
579
|
...geometryStyle,
|
|
580
|
+
...sheetHeightStyle,
|
|
406
581
|
...(isSheet
|
|
407
|
-
?
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
582
|
+
? enterMotion
|
|
583
|
+
? {
|
|
584
|
+
// Opening slide owns `transform` — don’t pin translateY(0) inline.
|
|
585
|
+
}
|
|
586
|
+
: {
|
|
587
|
+
transform: `translateY(${sheetDragOffset}px)`,
|
|
588
|
+
transition: isSheetDragging ? 'none' : sheetExitTransition,
|
|
589
|
+
}
|
|
411
590
|
: {}),
|
|
412
591
|
...((isSheetDragging || isWindowInteracting) && { transition: 'none' }),
|
|
413
592
|
}}
|
|
@@ -473,11 +652,12 @@ export function ResponsiveModal({
|
|
|
473
652
|
onPointerMove={handleSheetPointerMove}
|
|
474
653
|
onPointerUp={handleSheetPointerUp}
|
|
475
654
|
onPointerCancel={() => {
|
|
476
|
-
// Cancel mid-drag — ease back to
|
|
655
|
+
// Cancel mid-drag — ease back to the current snap
|
|
477
656
|
dragStartY.current = null;
|
|
478
657
|
dragCurrentY.current = 0;
|
|
479
658
|
setIsSheetDragging(false);
|
|
480
659
|
setSheetDragOffset(0);
|
|
660
|
+
setSheetDragHeight(null);
|
|
481
661
|
}}
|
|
482
662
|
/>
|
|
483
663
|
</div>
|
|
@@ -3,11 +3,14 @@ import {
|
|
|
3
3
|
DYNAMIC_DRAWER_PENDING_PX,
|
|
4
4
|
DYNAMIC_OVERLAY_PENDING_PX,
|
|
5
5
|
isOverlaySizePreset,
|
|
6
|
+
resolveBottomSheetSnapPoints,
|
|
6
7
|
resolveDialogSize,
|
|
7
8
|
resolveDismissOptions,
|
|
8
9
|
resolveDrawerSize,
|
|
9
10
|
resolveDrawerSizeForViewport,
|
|
10
11
|
resolveEffectiveDrawerPosition,
|
|
12
|
+
sheetExpandedSnapFraction,
|
|
13
|
+
SHEET_EXPANDED_TOP_GAP_PX,
|
|
11
14
|
toCssLength,
|
|
12
15
|
} from './overlaySize';
|
|
13
16
|
|
|
@@ -94,4 +97,19 @@ describe('overlaySize', () => {
|
|
|
94
97
|
showDragHandle: false,
|
|
95
98
|
});
|
|
96
99
|
});
|
|
100
|
+
|
|
101
|
+
it('resolves bottom sheet snap points for expand / collapse', () => {
|
|
102
|
+
// viewport 1000, no safe-area → expanded = 1000 - 60
|
|
103
|
+
const expanded = sheetExpandedSnapFraction(1000, 0);
|
|
104
|
+
expect(expanded).toBe(Number(((1000 - SHEET_EXPANDED_TOP_GAP_PX) / 1000).toFixed(4)));
|
|
105
|
+
expect(resolveBottomSheetSnapPoints({ size: 'md' }, null, 1000, 0)).toEqual([0.55, expanded]);
|
|
106
|
+
expect(resolveBottomSheetSnapPoints(null, null, 1000, 0)).toEqual([0.8, expanded]);
|
|
107
|
+
expect(resolveBottomSheetSnapPoints({ size: '400px' }, null, 1000, 0)).toEqual([0.4, expanded]);
|
|
108
|
+
expect(resolveBottomSheetSnapPoints({ size: 'full' }, null, 1000, 0)).toBeNull();
|
|
109
|
+
expect(resolveBottomSheetSnapPoints({ size: 'sm' }, 700, 1000, 0)).toEqual([0.7, expanded]);
|
|
110
|
+
// With notch inset, expanded shrinks further
|
|
111
|
+
expect(sheetExpandedSnapFraction(1000, 47)).toBe(
|
|
112
|
+
Number(((1000 - 47 - SHEET_EXPANDED_TOP_GAP_PX) / 1000).toFixed(4)),
|
|
113
|
+
);
|
|
114
|
+
});
|
|
97
115
|
});
|
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
OverlaySizeValue,
|
|
6
6
|
DrawerPosition,
|
|
7
7
|
} from '@shellui/sdk';
|
|
8
|
+
import { readSafeAreaInsetTop } from '../layouts/chrome/viewport';
|
|
8
9
|
|
|
9
10
|
/** CSS max-height for overlays — matches --shellui-overlay-max-height in index.css. */
|
|
10
11
|
const OVERLAY_MAX_HEIGHT_CSS = 'var(--shellui-overlay-max-height)';
|
|
@@ -281,3 +282,91 @@ export function resolveDismissOptions(
|
|
|
281
282
|
showDragHandle,
|
|
282
283
|
};
|
|
283
284
|
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Expanded bottom-sheet height leaves a tappable overlay band above the sheet:
|
|
288
|
+
* top safe-area inset + {@link SHEET_EXPANDED_TOP_GAP_PX}.
|
|
289
|
+
*/
|
|
290
|
+
export const SHEET_EXPANDED_TOP_GAP_PX = 60;
|
|
291
|
+
|
|
292
|
+
/** CSS height for the expanded bottom-sheet chrome. */
|
|
293
|
+
export const SHEET_EXPANDED_HEIGHT_CSS = `calc(var(--shellui-app-height) - var(--shellui-safe-area-top) - ${SHEET_EXPANDED_TOP_GAP_PX}px)`;
|
|
294
|
+
|
|
295
|
+
/** Pixel height for the expanded snap (matches {@link SHEET_EXPANDED_HEIGHT_CSS}). */
|
|
296
|
+
export function sheetExpandedHeightPx(
|
|
297
|
+
viewportHeightPx?: number,
|
|
298
|
+
safeAreaTopPx?: number,
|
|
299
|
+
topGapPx = SHEET_EXPANDED_TOP_GAP_PX,
|
|
300
|
+
): number {
|
|
301
|
+
const viewport = viewportHeightPx ?? (typeof window !== 'undefined' ? window.innerHeight : 0);
|
|
302
|
+
let safeTop = safeAreaTopPx;
|
|
303
|
+
if (safeTop === undefined) {
|
|
304
|
+
safeTop = typeof document !== 'undefined' ? readSafeAreaInsetTop() : 0;
|
|
305
|
+
}
|
|
306
|
+
return Math.max(0, Math.round(viewport - safeTop - topGapPx));
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** Vaul snap fraction for the expanded height (`height / viewport`). */
|
|
310
|
+
export function sheetExpandedSnapFraction(
|
|
311
|
+
viewportHeightPx?: number,
|
|
312
|
+
safeAreaTopPx?: number,
|
|
313
|
+
): number {
|
|
314
|
+
const viewport = viewportHeightPx ?? (typeof window !== 'undefined' ? window.innerHeight : 0);
|
|
315
|
+
if (!(viewport > 0)) return 0.9;
|
|
316
|
+
return Number((sheetExpandedHeightPx(viewport, safeAreaTopPx) / viewport).toFixed(4));
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/** Vertical drawer presets → window-height fraction (Vaul snapPoints). */
|
|
320
|
+
const VERTICAL_SNAP_BY_PRESET: Record<OverlaySizePreset, number> = {
|
|
321
|
+
sm: 0.4,
|
|
322
|
+
md: 0.55,
|
|
323
|
+
lg: 0.75,
|
|
324
|
+
xl: 0.9,
|
|
325
|
+
full: 1,
|
|
326
|
+
content: 0.5,
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Resolve `[normal, expanded]` Vaul snap points for a bottom sheet.
|
|
331
|
+
* Returns null when the sheet is already near the expanded height (nothing useful to expand to).
|
|
332
|
+
*/
|
|
333
|
+
export function resolveBottomSheetSnapPoints(
|
|
334
|
+
options?: OverlayOpenOptions | null,
|
|
335
|
+
reportedHeightPx?: number | null,
|
|
336
|
+
viewportHeightPx?: number,
|
|
337
|
+
safeAreaTopPx?: number,
|
|
338
|
+
): number[] | null {
|
|
339
|
+
const viewport = viewportHeightPx ?? (typeof window !== 'undefined' ? window.innerHeight : 0);
|
|
340
|
+
if (!(viewport > 0)) return null;
|
|
341
|
+
|
|
342
|
+
const expanded = sheetExpandedSnapFraction(viewport, safeAreaTopPx);
|
|
343
|
+
|
|
344
|
+
let normal: number;
|
|
345
|
+
if (reportedHeightPx !== null && Number.isFinite(reportedHeightPx) && reportedHeightPx > 0) {
|
|
346
|
+
normal = reportedHeightPx / viewport;
|
|
347
|
+
} else {
|
|
348
|
+
const dynamic = isDynamicSizing(options);
|
|
349
|
+
const size = (dynamic ? 'content' : options?.size) as OverlaySizeValue | undefined;
|
|
350
|
+
if (!size) {
|
|
351
|
+
normal = 0.8;
|
|
352
|
+
} else if (isOverlaySizePreset(size)) {
|
|
353
|
+
if (size === 'full') return null;
|
|
354
|
+
normal = VERTICAL_SNAP_BY_PRESET[size];
|
|
355
|
+
} else if (typeof size === 'number' && Number.isFinite(size)) {
|
|
356
|
+
normal = size / viewport;
|
|
357
|
+
} else {
|
|
358
|
+
const raw = String(size).trim();
|
|
359
|
+
const vh = raw.match(/^([\d.]+)vh$/i);
|
|
360
|
+
const px = raw.match(/^([\d.]+)px$/i);
|
|
361
|
+
if (vh) normal = parseFloat(vh[1]) / 100;
|
|
362
|
+
else if (px) normal = parseFloat(px[1]) / viewport;
|
|
363
|
+
else normal = 0.8;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// Already near expanded — expand would be a no-op
|
|
368
|
+
if (normal >= expanded - 0.04) return null;
|
|
369
|
+
// Keep a meaningful gap between snaps
|
|
370
|
+
normal = Math.min(Math.max(normal, 0.2), expanded - 0.05);
|
|
371
|
+
return [Number(normal.toFixed(4)), expanded];
|
|
372
|
+
}
|
|
@@ -12,6 +12,7 @@ import type { NavigationItem } from '../config/types';
|
|
|
12
12
|
import { useAuth } from '../auth/hooks/useAuth';
|
|
13
13
|
import { isAdminFrame } from '../admin/utils';
|
|
14
14
|
import { isFrameForAppUrl } from '../layouts/utils';
|
|
15
|
+
import { isMainLayoutFrame } from '../layouts/floating/layoutChromeStore';
|
|
15
16
|
import { defaultTheme } from '../theme/themes';
|
|
16
17
|
import {
|
|
17
18
|
buildSettingsForPropagation,
|
|
@@ -220,6 +221,7 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
220
221
|
const settingsToPropagate = buildSettingsForPropagation(baseSettings, config, lang, {
|
|
221
222
|
includeAuthAccessToken,
|
|
222
223
|
accessToken,
|
|
224
|
+
includeLayoutChrome: isMainLayoutFrame(iframe),
|
|
223
225
|
});
|
|
224
226
|
shellui.sendMessage({
|
|
225
227
|
type: 'SHELLUI_SETTINGS',
|
|
@@ -235,9 +237,13 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
235
237
|
(iframeUuid: string, frameSrc: string, baseSettings: Settings) => {
|
|
236
238
|
const lang = baseSettings.language?.code || 'en';
|
|
237
239
|
const includeAuthAccessToken = isTrustedFrameForAuthToken(frameSrc);
|
|
240
|
+
const iframe = shellui.frameRegistry
|
|
241
|
+
.getAllIframes()
|
|
242
|
+
.find(([uuid]) => uuid === iframeUuid)?.[1];
|
|
238
243
|
const settingsToPropagate = buildSettingsForPropagation(baseSettings, config, lang, {
|
|
239
244
|
includeAuthAccessToken,
|
|
240
245
|
accessToken: accessTokenRef.current,
|
|
246
|
+
includeLayoutChrome: isMainLayoutFrame(iframe),
|
|
241
247
|
});
|
|
242
248
|
shellui.sendMessage({
|
|
243
249
|
type: 'SHELLUI_SETTINGS',
|
|
@@ -309,17 +315,27 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
309
315
|
const mergedSettings = mergePreferencesIntoSettings(currentSettings, tokenPreferences);
|
|
310
316
|
const signature = JSON.stringify(getPreferenceSnapshot(mergedSettings));
|
|
311
317
|
const prevSignature = JSON.stringify(getPreferenceSnapshot(currentSettings));
|
|
312
|
-
lastSyncedPreferencesRef.current = signature;
|
|
313
318
|
if (signature === prevSignature) {
|
|
319
|
+
lastSyncedPreferencesRef.current = signature;
|
|
314
320
|
logger.info('JWT app preferences match current settings; skipping state update', {
|
|
315
321
|
preferences: getPreferenceSnapshot(mergedSettings),
|
|
316
322
|
});
|
|
317
323
|
return;
|
|
318
324
|
}
|
|
325
|
+
// Current UI already matches what we last synced — JWT is lagging a newer
|
|
326
|
+
// local change (or a superseded sync). Don’t regress appearance.
|
|
327
|
+
if (prevSignature === lastSyncedPreferencesRef.current) {
|
|
328
|
+
logger.info('Ignoring stale JWT preferences that lag last-synced settings', {
|
|
329
|
+
jwt: getPreferenceSnapshot(mergedSettings),
|
|
330
|
+
current: getPreferenceSnapshot(currentSettings),
|
|
331
|
+
});
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
lastSyncedPreferencesRef.current = signature;
|
|
319
335
|
settingsRef.current = mergedSettings;
|
|
320
336
|
setSettings(mergedSettings);
|
|
321
337
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(mergedSettings));
|
|
322
|
-
|
|
338
|
+
schedulePropagateSettingsToIframes(mergedSettings);
|
|
323
339
|
logger.info('Loaded app preferences from JWT metadata', {
|
|
324
340
|
preferences: getPreferenceSnapshot(mergedSettings),
|
|
325
341
|
});
|
|
@@ -431,7 +447,8 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
431
447
|
try {
|
|
432
448
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(nextSettings));
|
|
433
449
|
logger.info('Root Parent received settings update', { message });
|
|
434
|
-
|
|
450
|
+
// Coalesce with rapid theme spam (same debounce as updateSettings).
|
|
451
|
+
schedulePropagateSettingsToIframes(nextSettings);
|
|
435
452
|
} catch (error) {
|
|
436
453
|
logger.error('Failed to update settings from message:', { error });
|
|
437
454
|
}
|
|
@@ -459,6 +476,7 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
459
476
|
const settingsToPropagate = buildSettingsForPropagation(currentSettings, config, lang, {
|
|
460
477
|
includeAuthAccessToken,
|
|
461
478
|
accessToken: accessTokenRef.current,
|
|
479
|
+
includeLayoutChrome: isMainLayoutFrame(frame),
|
|
462
480
|
});
|
|
463
481
|
|
|
464
482
|
// Route through the full parent -> child -> ... -> requester path so deep descendants
|
|
@@ -521,7 +539,13 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
521
539
|
cleanupSettingsRequested();
|
|
522
540
|
cleanupInitialized();
|
|
523
541
|
};
|
|
524
|
-
}, [
|
|
542
|
+
}, [
|
|
543
|
+
config,
|
|
544
|
+
isTrustedFrameForAuthToken,
|
|
545
|
+
propagateSettingsToIframes,
|
|
546
|
+
pushSettingsToFrame,
|
|
547
|
+
schedulePropagateSettingsToIframes,
|
|
548
|
+
]);
|
|
525
549
|
|
|
526
550
|
// Apply config activeTheme / defaultTheme on first visit (no localStorage preference yet)
|
|
527
551
|
useEffect(() => {
|
|
@@ -598,7 +622,9 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
598
622
|
// ACTIONS
|
|
599
623
|
const updateSettings = useCallback(
|
|
600
624
|
(updates: Partial<Settings>) => {
|
|
601
|
-
|
|
625
|
+
// Always merge from the latest ref so rapid theme toggles don’t clobber each other.
|
|
626
|
+
const base = settingsRef.current ?? defaultSettings;
|
|
627
|
+
const nextSettings = { ...base, ...updates };
|
|
602
628
|
|
|
603
629
|
// Update localStorage and propagate to children if we're in the root window
|
|
604
630
|
if (typeof window !== 'undefined' && window.parent === window) {
|
|
@@ -624,20 +650,21 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
624
650
|
payload: { settings: stripSensitiveUserFields(nextSettings) },
|
|
625
651
|
});
|
|
626
652
|
},
|
|
627
|
-
[
|
|
653
|
+
[schedulePropagateSettingsToIframes],
|
|
628
654
|
);
|
|
629
655
|
|
|
630
656
|
const updateSetting = useCallback(
|
|
631
657
|
<K extends keyof Settings>(key: K, updates: Partial<Settings[K]>) => {
|
|
632
|
-
// Deep merge: preserve existing nested properties
|
|
633
|
-
const
|
|
658
|
+
// Deep merge from latest ref: preserve existing nested properties
|
|
659
|
+
const base = settingsRef.current ?? defaultSettings;
|
|
660
|
+
const currentValue = base[key];
|
|
634
661
|
const mergedValue =
|
|
635
662
|
typeof currentValue === 'object' && currentValue !== null && !Array.isArray(currentValue)
|
|
636
663
|
? { ...currentValue, ...updates }
|
|
637
664
|
: updates;
|
|
638
665
|
updateSettings({ [key]: mergedValue } as Partial<Settings>);
|
|
639
666
|
},
|
|
640
|
-
[
|
|
667
|
+
[updateSettings],
|
|
641
668
|
);
|
|
642
669
|
|
|
643
670
|
const resetAllData = useCallback(() => {
|
|
@@ -230,7 +230,7 @@ export const SettingsView = () => {
|
|
|
230
230
|
}, [navigate]);
|
|
231
231
|
|
|
232
232
|
return (
|
|
233
|
-
<div className="flex h-full w-full overflow-hidden items-start">
|
|
233
|
+
<div className="flex h-full w-full overflow-hidden items-start md:pt-[var(--shellui-inset-top,0px)] md:pr-[var(--shellui-inset-right,0px)] md:pb-[var(--shellui-inset-bottom,0px)] md:pl-[var(--shellui-inset-left,0px)]">
|
|
234
234
|
{/* Desktop settings nav — local provider so this works outside the shell sidebar layout */}
|
|
235
235
|
<SidebarProvider className="hidden h-full min-h-0 w-auto shrink-0 md:flex">
|
|
236
236
|
<Sidebar
|
|
@@ -276,10 +276,10 @@ export const SettingsView = () => {
|
|
|
276
276
|
{isSettingsRoot ? (
|
|
277
277
|
// Show list of settings pages
|
|
278
278
|
<div className="flex flex-1 flex-col overflow-y-auto bg-background">
|
|
279
|
-
<header className="flex h-16 shrink-0 items-center justify-center px-4
|
|
279
|
+
<header className="flex min-h-16 shrink-0 items-center justify-center border-b px-4 pt-[var(--shellui-inset-top,0px)]">
|
|
280
280
|
<h1 className="text-lg font-semibold">{t('title')}</h1>
|
|
281
281
|
</header>
|
|
282
|
-
<div className="flex flex-1 flex-col gap-6 p-4 pb-[max(1.5rem,calc(1rem+env(safe-area-inset-bottom,0px)))] pl-[max(1rem,env(safe-area-inset-left,0px))] pr-[max(1rem,env(safe-area-inset-right,0px))]">
|
|
282
|
+
<div className="flex flex-1 flex-col gap-6 p-4 pb-[max(1.5rem,calc(1rem+max(var(--shellui-inset-bottom,0px),env(safe-area-inset-bottom,0px))))] pl-[max(1rem,max(var(--shellui-inset-left,0px),env(safe-area-inset-left,0px)))] pr-[max(1rem,max(var(--shellui-inset-right,0px),env(safe-area-inset-right,0px)))]">
|
|
283
283
|
{groupedRoutes.map((group) => (
|
|
284
284
|
<div
|
|
285
285
|
key={group.title}
|
|
@@ -333,7 +333,7 @@ export const SettingsView = () => {
|
|
|
333
333
|
) : (
|
|
334
334
|
// Show selected settings page with back button
|
|
335
335
|
<div className="flex h-full flex-1 flex-col overflow-hidden">
|
|
336
|
-
<header className="flex h-16 shrink-0 items-center gap-2 px-4
|
|
336
|
+
<header className="flex min-h-16 shrink-0 items-center gap-2 border-b px-4 pt-[var(--shellui-inset-top,0px)]">
|
|
337
337
|
<Button
|
|
338
338
|
variant="ghost"
|
|
339
339
|
size="icon"
|
|
@@ -349,7 +349,7 @@ export const SettingsView = () => {
|
|
|
349
349
|
'flex flex-1 flex-col overflow-hidden',
|
|
350
350
|
selectedItem?.path?.startsWith('app-')
|
|
351
351
|
? 'min-h-0'
|
|
352
|
-
: 'gap-4 overflow-y-auto p-4 pt-4 pb-[max(1.5rem,calc(1rem+env(safe-area-inset-bottom,0px)))] pl-[max(1rem,env(safe-area-inset-left,0px))] pr-[max(1rem,env(safe-area-inset-right,0px))]',
|
|
352
|
+
: 'gap-4 overflow-y-auto p-4 pt-4 pb-[max(1.5rem,calc(1rem+max(var(--shellui-inset-bottom,0px),env(safe-area-inset-bottom,0px))))] pl-[max(1rem,max(var(--shellui-inset-left,0px),env(safe-area-inset-left,0px)))] pr-[max(1rem,max(var(--shellui-inset-right,0px),env(safe-area-inset-right,0px)))]',
|
|
353
353
|
)}
|
|
354
354
|
>
|
|
355
355
|
<Routes>
|
|
@@ -380,7 +380,7 @@ export const SettingsView = () => {
|
|
|
380
380
|
{/* Desktop Main Content */}
|
|
381
381
|
<main className="hidden md:flex h-full flex-1 flex-col overflow-hidden">
|
|
382
382
|
{selectedItem && (
|
|
383
|
-
<header className="flex h-16 shrink-0 items-center gap-2 transition-[width,height] ease-linear">
|
|
383
|
+
<header className="flex min-h-16 shrink-0 items-center gap-2 pt-[var(--shellui-inset-top,0px)] transition-[width,height] ease-linear">
|
|
384
384
|
<div className="flex items-center gap-2 px-4">
|
|
385
385
|
<Breadcrumb>
|
|
386
386
|
<BreadcrumbList>
|