Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 59 additions & 10 deletions packages/editor/src/components/editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ import { ViewerOverlay } from '../../components/viewer-overlay'
import { ViewerZoneSystem } from '../../components/viewer-zone-system'
import { type SaveStatus, useAutoSave } from '../../hooks/use-auto-save'
import { useKeyboard } from '../../hooks/use-keyboard'
import { useIsMobile } from '../../hooks/use-mobile'
import { useSaveShortcut } from '../../hooks/use-save-shortcut'
import { useCeilingEditSessionOwner } from '../../lib/ceiling-edit-session'
import { showsWholeBuilding, useEditorLevelDisplay } from '../../lib/editor-level-display'
import { isSceneView } from '../../lib/editor-views'
import { useGestureLifecycleOwner } from '../../lib/gesture-lifecycle'
import { shouldShowEditingControls } from '../../lib/interaction/overlay-policy'
import {
createLocalProjectPresentationPersistence,
type LocalProjectPresentationPersistence,
Expand All @@ -58,6 +60,7 @@ import {
} from '../../lib/scene'
import { disposeSFXBus, initSFXBus } from '../../lib/sfx-bus'
import { useUnitFocusRules } from '../../lib/units'
import { cn } from '../../lib/utils'
import { useViewerFloorDisplay } from '../../lib/viewer-selection'
import { type CameraHintAction, useCameraHintFocus } from '../../store/use-camera-hint-focus'
import useEditor from '../../store/use-editor'
Expand All @@ -74,6 +77,7 @@ import { ZoneSystem } from '../systems/zone/zone-system'
import { BoxSelectTool } from '../tools/select/box-select-tool'
import { ToolManager } from '../tools/tool-manager'
import { ActionMenu } from '../ui/action-menu'
import { type ActionMenuPlacement, TOP_MENU_CLEARANCE } from '../ui/action-menu/placement'
import { CommandPalette, type CommandPaletteEmptyAction } from '../ui/command-palette'
import { EditorCommands } from '../ui/command-palette/editor-commands'
import { FloatingLevelSelector } from '../ui/floating-level-selector'
Expand Down Expand Up @@ -196,6 +200,8 @@ function initializeEditorRuntime(): () => void {
export interface EditorProps {
// Layout version — 'v1' (default) or 'v2' (navbar + two-column)
layoutVersion?: 'v1' | 'v2'
// Viewport edge the tool menu docks to (desktop only; mobile stays at the bottom)
actionMenuPlacement?: ActionMenuPlacement

// UI slots (v1)
appMenuButton?: ReactNode
Expand Down Expand Up @@ -580,7 +586,13 @@ function CameraControlHintItem({ hint }: { hint: CameraControlHint }) {
)
}

function ViewerCanvasControlsHint({ onDismiss }: { onDismiss: () => void }) {
function ViewerCanvasControlsHint({
belowTopMenu = false,
onDismiss,
}: {
belowTopMenu?: boolean
onDismiss: () => void
}) {
const all = CAMERA_CONTROL_HINTS
// A host teaching one gesture at a time narrows this to the one it is asking
// for, and to nothing once it is done. Null — the default — is all of them.
Expand All @@ -592,7 +604,13 @@ function ViewerCanvasControlsHint({ onDismiss }: { onDismiss: () => void }) {
}

return (
<div className="pointer-events-none absolute top-14 left-1/2 z-40 max-w-[calc(100%-2rem)] -translate-x-1/2">
<div
className={cn(
'pointer-events-none absolute left-1/2 z-40 max-w-[calc(100%-2rem)] -translate-x-1/2',
!belowTopMenu && 'top-14',
)}
style={belowTopMenu ? { top: TOP_MENU_CLEARANCE } : undefined}
>
<section
aria-label="Camera controls hint"
className="pointer-events-auto flex items-start gap-3 rounded-2xl border border-border/35 bg-background/90 px-3.5 py-2.5 shadow-elevation-4 backdrop-blur-xl"
Expand Down Expand Up @@ -1090,6 +1108,7 @@ const ViewerCanvas = memo(function ViewerCanvas({
floorplanSceneSlot,
disablePostFx = false,
immersive,
hintBelowTopMenu = false,
}: {
isVersionPreviewMode: boolean
isLoading: boolean
Expand All @@ -1105,6 +1124,7 @@ const ViewerCanvas = memo(function ViewerCanvas({
floorplanSceneSlot?: ReactNode
disablePostFx?: boolean
immersive?: ViewerImmersiveSession
hintBelowTopMenu?: boolean
}) {
const layout = useActiveViewLayout()
const views = useEditorViews()
Expand Down Expand Up @@ -1238,7 +1258,10 @@ const ViewerCanvas = memo(function ViewerCanvas({
/>
{!isVersionPreviewMode && <PointAskLayer />}
{!showLoader && isCameraControlsHintVisible && !isFirstPersonMode ? (
<ViewerCanvasControlsHint onDismiss={dismissCameraControlsHint} />
<ViewerCanvasControlsHint
belowTopMenu={hintBelowTopMenu}
onDismiss={dismissCameraControlsHint}
/>
) : null}
<SelectionPersistenceManager enabled={hasLoadedInitialScene && !showLoader} />
<Viewer
Expand Down Expand Up @@ -1364,6 +1387,7 @@ function PreviewStage({
function EditorContent({
guardAgainstSceneWipe,
layoutVersion = 'v1',
actionMenuPlacement,
appMenuButton,
sidebarTop,
navbarSlot,
Expand Down Expand Up @@ -1398,6 +1422,9 @@ function EditorContent({
extraSidebarPanels,
commandPaletteEmptyAction,
}: EditorProps) {
const isMobile = useIsMobile()
// A top-docked menu sits at the top of the scene panes on desktop (layout v2).
const dockMenuOnTop = actionMenuPlacement === 'top' && !isMobile
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
const isFirstPersonMode = useEditor((s) => s.isFirstPersonMode)
const isStudioMode = useEditor((s) => s.workspaceMode === 'studio')
const presentationProjectId = projectId ?? null
Expand Down Expand Up @@ -1452,6 +1479,12 @@ function EditorContent({
const [previewStageMode, setPreviewStageMode] = useState<ViewerStageMode>('3d')
const isPreviewMode = useEditor((s) => s.isPreviewMode)
const isCaptureMode = useEditor((s) => s.isCaptureMode)
const readOnly = useScene((s) => s.readOnly)
// Chrome only steps down for the top menu while the menu is actually there.
const topMenuShown =
dockMenuOnTop &&
!(isVersionPreviewMode || isCaptureMode || isStudioMode) &&
shouldShowEditingControls(readOnly)

const sidebarWidth = useSidebarStore((s) => s.width)
const isSidebarCollapsed = useSidebarStore((s) => s.isCollapsed)
Expand Down Expand Up @@ -1664,6 +1697,7 @@ function EditorContent({
const viewerCanvas = (
<ViewerCanvas
disablePostFx={disablePostFx}
hintBelowTopMenu={topMenuShown}
hasLoadedInitialScene={hasLoadedInitialScene}
isFirstPersonMode={isFirstPersonMode}
isLoading={isLoading}
Expand Down Expand Up @@ -1762,15 +1796,26 @@ function EditorContent({
<>
<SceneRegion>
{!(isCaptureMode || stageOverlay) && <FloatingLevelSelector />}
{!(isVersionPreviewMode || isCaptureMode || isStudioMode) && (
<div className="pointer-events-auto">
<ActionMenu />
</div>
)}
{!(isVersionPreviewMode || isCaptureMode || isStudioMode) &&
(dockMenuOnTop ? (
// Own row under the toolbar, below the level selector's opening list (z-20).
// No transform: the menu's fixed pill must anchor to the scene region.
<div className="pointer-events-none absolute inset-x-0 top-14 z-10 flex justify-center">
<div className="pointer-events-auto">
<ActionMenu inline placement="top" />
</div>
</div>
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
) : (
<div className="pointer-events-auto">
<ActionMenu placement={actionMenuPlacement} />
</div>
))}
{sceneOverlay}
</SceneRegion>
{/* The inspector and the shortcuts card share one right column. */}
<RightStack
belowTopMenu={topMenuShown}
reserveBottomMenu={!dockMenuOnTop}
helper={isCaptureMode ? null : <HelperManager />}
inspector={
isVersionPreviewMode || isCaptureMode || isStudioMode ? null : (
Expand Down Expand Up @@ -1858,9 +1903,13 @@ function EditorContent({
{/* Fixed UI overlays scoped to the viewer area */}
<ViewerOverlays left={overlayLeft}>
<div className="pointer-events-auto">
<ActionMenu />
<ActionMenu placement={actionMenuPlacement} />
</div>
<RightStack helper={<HelperManager />} inspector={<PanelManager />} />
<RightStack
helper={<HelperManager />}
inspector={<PanelManager />}
reserveBottomMenu={actionMenuPlacement !== 'top' || isMobile}
/>
<RiserDiagramPanel />
{isFirstPersonMode && (
<FirstPersonOverlay onExit={() => useEditor.getState().setFirstPersonMode(false)} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from './../../../components/ui/primitives/tooltip'
import { triggerSFX } from './../../../lib/sfx-bus'
import { cn } from './../../../lib/utils'
import { useActionMenuPopupSide } from './placement'

interface ActionButtonProps extends React.ComponentProps<typeof Button> {
label: string
Expand Down Expand Up @@ -35,6 +36,7 @@ export const ActionButton = React.forwardRef<HTMLButtonElement, ActionButtonProp
},
ref,
) => {
const popupSide = useActionMenuPopupSide()
return (
<Tooltip>
<TooltipTrigger asChild>
Expand Down Expand Up @@ -71,7 +73,7 @@ export const ActionButton = React.forwardRef<HTMLButtonElement, ActionButtonProp
)}
</Button>
</TooltipTrigger>
<TooltipContent className={tooltipClassName} side={tooltipSide}>
<TooltipContent className={tooltipClassName} side={tooltipSide ?? popupSide}>
{tooltipContent || (
<p>
{label} {shortcut && `(${shortcut})`}
Expand Down
89 changes: 55 additions & 34 deletions packages/editor/src/components/ui/action-menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,24 @@ import useEditor from './../../../store/use-editor'
import { CameraActions } from './camera-actions'
import { ControlModes } from './control-modes'
import { FollowPascalPill } from './follow-pascal-pill'
import { type ActionMenuPlacement, ActionMenuPlacementProvider } from './placement'
import { SecondaryToggles } from './view-toggles'

// Mobile bottom offset matches the viewer's overlap behind the sheet's
// rounded corners (SHEET_OVERLAP_PX in editor-layout-mobile) so the menu sits
// just above that strip instead of inside it.
const MOBILE_BOTTOM_OFFSET = 24

export function ActionMenu({ className }: { className?: string }) {
export function ActionMenu({
className,
inline = false,
placement = 'bottom',
}: {
className?: string
// Rendered in the flow of a layout slot instead of floating over the viewer.
inline?: boolean
placement?: ActionMenuPlacement
}) {
const isMobile = useIsMobile()
const readOnly = useScene((s) => s.readOnly)
const hasSelectionOnMobile = useViewer((s) => isMobile && s.selection.selectedIds.length > 0)
Expand Down Expand Up @@ -48,42 +58,53 @@ export function ActionMenu({ className }: { className?: string }) {
? { duration: 0 }
: { type: 'spring' as const, bounce: 0.2, duration: 0.4 }

// Mobile keeps the bottom rail: the sheet owns the rest of the screen.
const effectivePlacement = isMobile ? 'bottom' : placement

return (
<TooltipProvider>
<FollowPascalPill />
<motion.div
className={cn(
'left-1/2 z-50 -translate-x-1/2',
isMobile ? 'absolute origin-bottom scale-90' : 'fixed bottom-6',
'rounded-2xl border border-border bg-background/90 shadow-2xl backdrop-blur-md',
'transition-colors duration-200 ease-out',
className,
)}
layout
style={isMobile ? { bottom: MOBILE_BOTTOM_OFFSET } : undefined}
transition={transition}
>
{isMobile ? (
<div className="flex flex-col items-stretch gap-0.5 px-2 py-1.5">
{/* Row 1: control modes only */}
<div className="flex items-center justify-center gap-1">
<ControlModes />
<ActionMenuPlacementProvider value={effectivePlacement}>
<TooltipProvider>
<FollowPascalPill />
<motion.div
className={cn(
'z-50',
isMobile
? 'absolute left-1/2 origin-bottom -translate-x-1/2 scale-90'
: inline
? 'relative'
: effectivePlacement === 'top'
? 'fixed top-3 left-1/2 -translate-x-1/2'
: 'fixed bottom-6 left-1/2 -translate-x-1/2',
'rounded-2xl border border-border bg-background/90 shadow-2xl backdrop-blur-md',
'transition-colors duration-200 ease-out',
className,
)}
layout
style={isMobile ? { bottom: MOBILE_BOTTOM_OFFSET } : undefined}
transition={transition}
>
{isMobile ? (
<div className="flex flex-col items-stretch gap-0.5 px-2 py-1.5">
{/* Row 1: control modes only */}
<div className="flex items-center justify-center gap-1">
<ControlModes />
</div>
{/* Row 2: secondary toggles (orbit + top view hidden) */}
<div className="flex items-center justify-center gap-1 border-border/50 border-t pt-1">
<SecondaryToggles />
</div>
</div>
{/* Row 2: secondary toggles (orbit + top view hidden) */}
<div className="flex items-center justify-center gap-1 border-border/50 border-t pt-1">
) : (
<div className="flex items-center justify-center gap-1 px-2 py-1.5">
<ControlModes />
<div className="mx-1 h-5 w-px bg-border" />
<SecondaryToggles />
<div className="mx-1 h-5 w-px bg-border" />
<CameraActions />
</div>
</div>
) : (
<div className="flex items-center justify-center gap-1 px-2 py-1.5">
<ControlModes />
<div className="mx-1 h-5 w-px bg-border" />
<SecondaryToggles />
<div className="mx-1 h-5 w-px bg-border" />
<CameraActions />
</div>
)}
</motion.div>
</TooltipProvider>
)}
</motion.div>
</TooltipProvider>
</ActionMenuPlacementProvider>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { VIEW_2D } from '../../../store/view-layout'
import useFloorplanMode from '../../../store/use-floorplan-mode'
import { Popover, PopoverContent, PopoverTrigger } from '../primitives/popover'
import { ActionButton } from './action-button'
import { useActionMenuPopupSide } from './placement'

const measurementOptions = [
{ kind: 'distance', label: 'Distance', icon: Ruler },
Expand Down Expand Up @@ -62,6 +63,7 @@ const constructionDimensionOptions = [
}[]

export function MeasurementControl() {
const popupSide = useActionMenuPopupSide()
const [isOpen, setIsOpen] = useState(false)
const mode = useEditor((state) => state.mode)
const tool = useEditor((state) => state.tool)
Expand Down Expand Up @@ -182,7 +184,7 @@ export function MeasurementControl() {
<PopoverContent
align="center"
className="max-h-[70vh] w-64 overflow-y-auto rounded-lg border-border/45 bg-background/96 p-2 shadow-elevation-3 backdrop-blur-xl"
side="top"
side={popupSide}
sideOffset={14}
>
<div aria-label="Measurement type" className="space-y-1" role="menu">
Expand Down
20 changes: 20 additions & 0 deletions packages/editor/src/components/ui/action-menu/placement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createContext, useContext } from 'react'

/** Viewport edge the action menu docks to. */
export type ActionMenuPlacement = 'bottom' | 'top'

/** Where chrome under a top-docked menu starts: below the host toolbar row and the menu itself. */
export const TOP_MENU_CLEARANCE = '7.25rem'

const ActionMenuPlacementContext = createContext<ActionMenuPlacement>('bottom')

export const ActionMenuPlacementProvider = ActionMenuPlacementContext.Provider

export function useActionMenuPlacement(): ActionMenuPlacement {
return useContext(ActionMenuPlacementContext)
}

/** Side tooltips and popovers open toward, away from the docked edge. */
export function useActionMenuPopupSide(): 'top' | 'bottom' {
return useActionMenuPlacement() === 'top' ? 'bottom' : 'top'
}
Loading
Loading