* Remove .env.local guard; add portless dep
Remove the check that blocked a local .env.local in apps/editor's dev script and simplify the dev startup to source the root .env. Add portless@^0.4.2 to the project dependencies in package.json. Lockfile updated accordingly.
* Improve tool cursors, previews, and contextual tools
Revamp editor tool visuals and behaviour: replace mesh cursors with a new CursorSphere Group (adds ground marker, vertical indicator and optional tool icon tooltip), unify preview colors to #818cf8, add ground-level previews and ghost lines for ceiling and roof tools, and update slab/zone/wall visuals to match. Add automatic build-mode switching and contextual highlighting for structure tools via a new useContextualTools hook, and relax action-menu visibility checks so tool rows are shown even when not in build mode. Minor typing/import adjustments and small opacity/placement tweaks across multiple tool components.
* Keep tools active and refine action-menu styles
Stop auto-deactivating tools in RoofTool and ZoneTool by removing setTool(null) (and setMode('select') in roof). Add hasActiveTool checks and small layout padding to FurnishTools and StructureTools, and update button classes to improve visual emphasis: smoother transitions, stronger active rings/scale, and dimming/grayscale of non-active tools when another tool is active. These changes improve UX by keeping the selected tool active and giving clearer visual feedback in the action menu.
* Improve selection behavior and refresh UI styling
SelectionManager: add global enter/leave/double-click handlers to support cross-phase hovering and auto-switching into structure/furnish on double-click; normalize click handling (explicitly coalesce shiftKey). Remove per-strategy enter/leave listeners.
UI panels & controls: unify and modernize styles across many panels (ceiling, door, item, reference, roof, slab, wall, window) and action buttons — rounded-md, neutral borders, subtle shadows, translucent headers and consistent hover/focus states. Update view toggles icons and toggle styling.
NumberInput: integrate @number-flow/react NumberFlow for formatted value display, add visual drag progress indicator and refine input/label interactions and styling.
Sidebar: replace rename-popover with inline-rename-input and update tree nodes to use inline editing. Add slider-demo and tweak slider implementation. Update package.json accordingly.
* Use Barlow font across editor UI
Add the Google Barlow font and expose it as a CSS variable, update theme font variables in globals.css, and apply the new font across the editor UI. Imports: add Barlow in app/layout.tsx and include its variable on <html>, set body to use font-sans. Apply font-barlow or font-mono classes to headings, labels, numeric readouts and buttons across multiple panels and primitives to standardize typography. Also update button base variant to include font-barlow. Remove the PhaseSwitcher component and its import/usage from the action menu.
* Replace button wrapper with div in LevelItem
Replace the outer <button> around the LevelItem content with a <div> to avoid nesting interactive button elements (and the resulting invalid HTML/interaction issues). Preserves the original classes and onClick/onDoubleClick handlers so behavior remains the same and allows the PopoverTrigger/button children to function correctly.
* Refine site panel list styles and spacing
Update the SitePanel and TreeNode UI to use compact, border-bottom list rows instead of rounded, card-like items. Simplified active/hover states to use bg-accent variants and reduced shadow/ring styles for a cleaner look. Adjusted paddings (pl/px/py) and container layouts (many sections switched to flex-col) and increased tree node indent/paddingRight for consistent alignment. These changes unify spacing and visual hierarchy across levels, buildings, zones and tree nodes.
* Add auto-scroll to selected items and refine icon styles
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
182 lines
6.4 KiB
TypeScript
182 lines
6.4 KiB
TypeScript
'use client'
|
|
|
|
import { useScene } from '@pascal-app/core'
|
|
import { useCallback, useRef, useState } from 'react'
|
|
import NumberFlow from '@number-flow/react'
|
|
|
|
interface NumberInputProps {
|
|
label: string
|
|
value: number
|
|
onChange: (value: number) => void
|
|
min?: number
|
|
max?: number
|
|
precision?: number
|
|
step?: number
|
|
className?: string
|
|
}
|
|
|
|
export function NumberInput({
|
|
label,
|
|
value,
|
|
onChange,
|
|
min,
|
|
max,
|
|
precision = 2,
|
|
step = 0.1,
|
|
className = '',
|
|
}: NumberInputProps) {
|
|
const [isEditing, setIsEditing] = useState(false)
|
|
const [isDragging, setIsDragging] = useState(false)
|
|
const [inputValue, setInputValue] = useState(value.toFixed(precision))
|
|
const startXRef = useRef(0)
|
|
const startValueRef = useRef(0)
|
|
const labelRef = useRef<HTMLDivElement>(null)
|
|
|
|
const clamp = useCallback(
|
|
(val: number) => {
|
|
if (min !== undefined && val < min) return min
|
|
if (max !== undefined && val > max) return max
|
|
return val
|
|
},
|
|
[min, max],
|
|
)
|
|
|
|
const handleLabelMouseDown = useCallback(
|
|
(e: React.MouseEvent) => {
|
|
if (isEditing) return
|
|
e.preventDefault()
|
|
setIsDragging(true)
|
|
startXRef.current = e.clientX
|
|
startValueRef.current = value
|
|
|
|
// Pause history tracking during drag
|
|
useScene.temporal.getState().pause()
|
|
|
|
let finalValue = value
|
|
|
|
const handleMouseMove = (moveEvent: MouseEvent) => {
|
|
const deltaX = moveEvent.clientX - startXRef.current
|
|
|
|
// Determine step size based on modifier keys
|
|
let dragStep = step // Default from prop
|
|
if (moveEvent.shiftKey) {
|
|
dragStep = step * 10 // Coarse
|
|
} else if (moveEvent.altKey) {
|
|
dragStep = step * 0.1 // Fine
|
|
}
|
|
|
|
const deltaValue = deltaX * dragStep
|
|
const newValue = clamp(startValueRef.current + deltaValue)
|
|
const newFinalValue = Number.parseFloat(newValue.toFixed(precision))
|
|
|
|
// Only call onChange if value actually changed (avoid extra processing on tiny moves)
|
|
if (newFinalValue !== finalValue) {
|
|
finalValue = newFinalValue
|
|
onChange(finalValue)
|
|
}
|
|
}
|
|
|
|
const handleMouseUp = () => {
|
|
setIsDragging(false)
|
|
document.removeEventListener('mousemove', handleMouseMove)
|
|
document.removeEventListener('mouseup', handleMouseUp)
|
|
|
|
// Reset to initial value while still paused (no history entry)
|
|
// Then resume and apply final value (creates single history entry)
|
|
if (finalValue !== startValueRef.current) {
|
|
onChange(startValueRef.current)
|
|
useScene.temporal.getState().resume()
|
|
onChange(finalValue)
|
|
} else {
|
|
useScene.temporal.getState().resume()
|
|
}
|
|
}
|
|
|
|
document.addEventListener('mousemove', handleMouseMove)
|
|
document.addEventListener('mouseup', handleMouseUp)
|
|
},
|
|
[isEditing, value, onChange, clamp, precision],
|
|
)
|
|
|
|
const handleValueClick = useCallback(() => {
|
|
setIsEditing(true)
|
|
setInputValue(value.toFixed(precision))
|
|
}, [value, precision])
|
|
|
|
const handleInputChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
|
setInputValue(e.target.value)
|
|
}, [])
|
|
|
|
const handleInputBlur = useCallback(() => {
|
|
const numValue = Number.parseFloat(inputValue)
|
|
if (!Number.isNaN(numValue)) {
|
|
onChange(clamp(Number.parseFloat(numValue.toFixed(precision))))
|
|
}
|
|
setIsEditing(false)
|
|
}, [inputValue, onChange, clamp, precision])
|
|
|
|
const handleInputKeyDown = useCallback(
|
|
(e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
if (e.key === 'Enter') {
|
|
const numValue = Number.parseFloat(inputValue)
|
|
if (!Number.isNaN(numValue)) {
|
|
onChange(clamp(Number.parseFloat(numValue.toFixed(precision))))
|
|
}
|
|
setIsEditing(false)
|
|
} else if (e.key === 'Escape') {
|
|
setInputValue(value.toFixed(precision))
|
|
setIsEditing(false)
|
|
}
|
|
},
|
|
[inputValue, onChange, value, clamp, precision],
|
|
)
|
|
|
|
return (
|
|
<div className={`${className} relative group/input`}>
|
|
<div
|
|
className={`absolute inset-y-0 left-0 bg-primary/10 dark:bg-primary/20 pointer-events-none transition-all duration-75 ${isDragging ? 'opacity-100' : 'opacity-0'}`}
|
|
style={{
|
|
width: `${Math.min(100, Math.max(0, ((value - (min ?? Math.min(0, value))) / ((max ?? Math.max(10, value)) - (min ?? Math.min(0, value)))) * 100))}%`,
|
|
borderTopRightRadius: value >= (max ?? Math.max(10, value)) ? '0.5rem' : '0',
|
|
borderBottomRightRadius: value >= (max ?? Math.max(10, value)) ? '0.5rem' : '0',
|
|
borderTopLeftRadius: '0.5rem',
|
|
borderBottomLeftRadius: '0.5rem',
|
|
}}
|
|
/>
|
|
<div className={`flex items-center rounded-lg border shadow-[0_1px_2px_0px_rgba(0,0,0,0.05)] overflow-hidden transition-all focus-within:ring-1 focus-within:ring-primary focus-within:border-primary relative z-10 ${isDragging ? 'bg-transparent border-neutral-300 dark:border-border ring-1 ring-neutral-200/60 dark:ring-border/50' : 'bg-white dark:bg-accent/30 border-neutral-200/60 dark:border-border/50 hover:border-neutral-300 dark:hover:border-border/80'}`}>
|
|
<div
|
|
ref={labelRef}
|
|
className={`pl-2 pr-1 py-1.5 text-muted-foreground text-xs select-none font-barlow font-medium truncate z-10 ${
|
|
isDragging ? 'cursor-ew-resize text-foreground' : 'hover:cursor-ew-resize hover:text-foreground'
|
|
} transition-colors`}
|
|
onMouseDown={handleLabelMouseDown}
|
|
>
|
|
{label}
|
|
</div>
|
|
{isEditing ? (
|
|
<input
|
|
autoFocus
|
|
size={1}
|
|
className="flex-1 min-w-0 bg-transparent px-2 py-1.5 text-foreground text-sm font-mono font-medium outline-none text-right placeholder:text-muted-foreground/50 z-10"
|
|
onBlur={handleInputBlur}
|
|
onChange={handleInputChange}
|
|
onKeyDown={handleInputKeyDown}
|
|
type="text"
|
|
value={inputValue}
|
|
/>
|
|
) : (
|
|
<div
|
|
className={`flex-1 px-2 py-1.5 text-sm font-mono font-medium cursor-text hover:bg-black/5 dark:hover:bg-white/5 transition-colors text-right truncate z-10 text-foreground tabular-nums tracking-tight min-w-0`}
|
|
onClick={handleValueClick}
|
|
>
|
|
<NumberFlow
|
|
value={Number(value.toFixed(precision))}
|
|
format={{ minimumFractionDigits: precision, maximumFractionDigits: precision }}
|
|
/>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|