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
698 changes: 356 additions & 342 deletions apps/editor/components/build-tab.tsx

Large diffs are not rendered by default.

133 changes: 133 additions & 0 deletions apps/editor/components/kitchen-browser.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
'use client'

import {
type AnyNodeId,
type CabinetNode,
emitter,
resolveLevelId,
useScene,
} from '@pascal-app/core'
import { useCommandPalette, useCommandRegistry, useEditor } from '@pascal-app/editor'
import {
beginKitchenPlacement,
findKitchenItems,
KITCHEN_ITEMS,
KitchenCollection,
kitchenPresetForModule,
} from '@pascal-app/nodes'
import { useViewer } from '@pascal-app/viewer'
import { useEffect } from 'react'
import { useShallow } from 'zustand/react/shallow'

const NO_ITEMS: never[] = []

function focusKitchenItem(id: AnyNodeId) {
const nodes = useScene.getState().nodes
const node = nodes[id]
if (!node) return
const levelId = resolveLevelId(node, nodes)
const level = levelId ? nodes[levelId as AnyNodeId] : undefined
const building = level?.parentId ? nodes[level.parentId as AnyNodeId] : undefined
useEditor.getState().setMode('select')
useViewer.getState().setSelection({
selectedIds: [id],
...(level?.type === 'level' ? { levelId: level.id } : {}),
...(building?.type === 'building' ? { buildingId: building.id } : {}),
})
emitter.emit('camera-controls:focus', { nodeId: id })
emitter.emit('selection:find-node', node)
}

export function KitchenBrowser({ query = '' }: { query?: string }) {
const defaults = useEditor((state) => state.toolDefaults.cabinet)
const mode = useEditor((state) => state.mode)
// Read the scene only while a query asks for placed items.
const matches = useScene(
useShallow((state) => (query.trim() ? findKitchenItems(state.nodes, query) : NO_ITEMS)),
)
const active = KITCHEN_ITEMS.find((item) => item.id === defaults?.kitchenPreset)
return (
<div className="space-y-4">
<div>
<h3 className="text-sm font-medium">Add to kitchen</h3>
<p className="mt-1 text-xs text-muted-foreground">
Choose an item, then click to place it. Appliances include their cabinetry.
</p>
</div>
<KitchenCollection
query={query}
activeId={mode === 'build' ? active?.id : null}
onSelect={beginKitchenPlacement}
/>
{query.trim() && (
<div className="space-y-2 border-t border-border pt-3">
<h3 className="text-xs font-medium">Find in this project · {matches.length}</h3>
{matches.map((node) => (
<button
key={node.id}
type="button"
onClick={() => focusKitchenItem(node.id)}
className="block w-full rounded-lg border border-border/60 px-3 py-2 text-left text-xs hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring"
>
{node.name || 'Kitchen cabinet'}
<span className="block text-[10px] text-muted-foreground">
Select and show in scene
</span>
</button>
))}
{!matches.length && (
<p className="text-xs text-muted-foreground">No matching kitchen items placed yet.</p>
)}
</div>
)}
</div>
)
}

export function KitchenCommands() {
const register = useCommandRegistry((state) => state.register)
// Always mounted: the placed items are read only while the palette is open to list them.
const paletteOpen = useCommandPalette((state) => state.open)
const modules = useScene(
useShallow((state) => (paletteOpen ? findKitchenItems(state.nodes, '') : NO_ITEMS)),
)
useEffect(
() =>
register(
KITCHEN_ITEMS.map((item) => ({
id: `kitchen.add.${item.id}`,
label: `Add ${item.label}`,
group: 'Kitchen · Add',
keywords: item.keywords.split(' '),
execute: () => beginKitchenPlacement(item.id),
})),
),
[register],
)
useEffect(
() =>
register(
modules.map((node) => {
const nodes = useScene.getState().nodes
const parent = node.parentId ? nodes[node.parentId as AnyNodeId] : undefined
const preset =
node.type === 'cabinet-module'
? kitchenPresetForModule(
node,
parent?.type === 'cabinet' ? (parent as CabinetNode) : undefined,
)
: 'base-door'
const item = KITCHEN_ITEMS.find((entry) => entry.id === preset)!
return {
id: `kitchen.find.${node.id}`,
label: `Find ${node.name || item.label}`,
group: 'Kitchen · In this project',
keywords: item.keywords.split(' '),
execute: () => focusKitchenItem(node.id),
}
}),
),
[register, modules],
)
return null
}
2 changes: 2 additions & 0 deletions apps/editor/components/scene-loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { type PersistedSceneGraph, sceneGraphSignature } from '@/lib/scene-signa
import { useThumbnailAutosave } from '@/lib/use-thumbnail-autosave'
import { BuildTab } from './build-tab'
import { EditorNavbar } from './editor-navbar'
import { KitchenCommands } from './kitchen-browser'
import { PaintPanel } from './paint-panel'
import { EditorViewerToolbarLeft, EditorViewerToolbarRight } from './viewer-toolbar'
import { useWebXRFeature, useWebXRInstalled, WebXRFeatureRuntime } from './webxr-feature-gate'
Expand Down Expand Up @@ -368,6 +369,7 @@ function SceneEditor({ initialScene, meta: initialMeta }: SceneLoaderProps) {
<p className="font-medium text-destructive text-xs">{saveError}</p>
</div>
)}
<KitchenCommands />
<Editor
disablePostFx={lightPreview}
immersive={vr?.session ? vr.immersive : undefined}
Expand Down
Binary file added apps/editor/public/icons/kitchen/base-door.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/editor/public/icons/kitchen/cooktop-gas.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/editor/public/icons/kitchen/dishwasher.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/editor/public/icons/kitchen/drawer-base.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/editor/public/icons/kitchen/oven-tower.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/editor/public/icons/kitchen/sink-base.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/editor/public/icons/kitchen/tall-pantry.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/core/src/schema/nodes/cabinet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const CabinetModuleNode = BaseNode.extend({
// Discriminator for specialty units (corner L-shape, sink base, appliance
// gap, open shelving). 'standard' modules use the compartment stack as-is;
// new kinds extend this enum instead of overloading the stack.
moduleKind: z.enum(['standard', 'corner-filler']).default('standard'),
moduleKind: z.enum(['standard', 'corner-filler', 'wall-filler']).default('standard'),
// Shared-boundary opening for inside-corner pockets: drops the side panel on
// that side and lets interior shelves / decks run through to the neighbour.
openSide: z.enum(['left', 'right']).optional(),
Expand Down
11 changes: 8 additions & 3 deletions packages/editor/src/components/ui/build-panel/build-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,12 @@ type BuildToolTileProps = Omit<ComponentPropsWithoutRef<'button'>, 'children' |
iconSrc: string
label: string
size?: 'lg' | 'sm'
tone?: 'primary' | 'neutral'
}

/**
* One tool tile: the isometric icon over its name. Inactive icons stay grey and
* take their colour on hover; the armed tool keeps it, on the primary tint.
* take their colour on hover. Neutral tiles keep that behavior when armed.
*/
export function BuildToolTile({
active,
Expand All @@ -141,6 +142,7 @@ export function BuildToolTile({
iconSrc,
label,
size = 'sm',
tone = 'primary',
...buttonProps
}: BuildToolTileProps) {
return (
Expand All @@ -152,7 +154,9 @@ export function BuildToolTile({
// tiles stretch together, so a row keeps one height.
size === 'lg' ? 'h-[104px] gap-1.5 px-1.5 pt-2 pb-2.5' : 'min-h-[74px] gap-1 px-1 pt-1.5 pb-2',
active
? 'bg-primary/10 ring-1 ring-primary/50'
? tone === 'neutral'
? 'bg-black/8 ring-1 ring-foreground/30 dark:bg-muted'
: 'bg-primary/10 ring-1 ring-primary/50'
: 'bg-black/4 hover:bg-black/8 dark:bg-muted/40 dark:hover:bg-muted',
className,
)}
Expand All @@ -164,7 +168,8 @@ export function BuildToolTile({
className={cn(
'min-h-0 object-contain transition duration-200 group-hover:scale-110',
size === 'lg' ? 'size-14' : 'size-9',
!active && 'opacity-70 grayscale group-hover:opacity-100 group-hover:grayscale-0',
(!active || tone === 'neutral') &&
'opacity-70 grayscale group-hover:opacity-100 group-hover:grayscale-0',
)}
draggable={false}
src={iconSrc}
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/components/ui/controls/action-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export function ActionButton({ icon, label, className, ...props }: ActionButtonP
// The fill runs through custom properties so a caller's `bg-*` or
// `hover:bg-*` replaces it in both themes; tailwind-merge would keep a
// `dark:bg-*` fill alive under the caller's class.
'flex h-9 flex-1 items-center justify-center gap-1.5 rounded-lg border border-border/50 bg-(--action-fill) px-3 font-medium text-foreground text-xs transition-colors [--action-fill-hover:rgb(0_0_0/0.08)] [--action-fill:rgb(0_0_0/0.04)] hover:bg-(--action-fill-hover) active:bg-(--action-fill-hover) dark:[--action-fill-hover:#3e3e3e] dark:[--action-fill:#2C2C2E]',
'flex min-h-9 min-w-0 flex-1 shrink-0 items-center justify-center gap-1.5 rounded-lg border border-border/50 bg-(--action-fill) px-3 py-2 font-medium text-foreground text-xs leading-4 transition-colors [&>svg]:shrink-0 [--action-fill-hover:rgb(0_0_0/0.08)] [--action-fill:rgb(0_0_0/0.04)] hover:bg-(--action-fill-hover) active:bg-(--action-fill-hover) dark:[--action-fill-hover:#3e3e3e] dark:[--action-fill:#2C2C2E]',
className,
)}
>
{icon}
<span>{label}</span>
<span className="min-w-0 whitespace-normal text-center">{label}</span>
</button>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function SegmentedControl<T extends string>({
return (
<div
className={cn(
'flex h-9 w-full items-center rounded-lg border border-border/50 bg-black/4 dark:bg-[#2C2C2E] p-[3px]',
'flex min-h-9 w-full items-stretch rounded-lg border border-border/50 bg-black/4 dark:bg-[#2C2C2E] p-[3px]',
disabled && 'opacity-60',
className,
)}
Expand All @@ -34,7 +34,7 @@ export function SegmentedControl<T extends string>({
<button
aria-pressed={isSelected}
className={cn(
'relative flex h-full flex-1 items-center justify-center rounded-md font-medium text-xs transition-all duration-200',
'relative flex min-h-7 min-w-0 flex-1 items-center justify-center rounded-md px-1.5 py-1 font-medium text-xs leading-4 transition-colors duration-200',
isSelected
? 'bg-white dark:bg-[#3e3e3e] text-foreground shadow-sm ring-1 ring-border/50'
: 'text-muted-foreground hover:bg-black/4 dark:hover:bg-white/5 hover:text-foreground',
Expand All @@ -47,7 +47,9 @@ export function SegmentedControl<T extends string>({
onClick={() => onChange(option.value)}
type="button"
>
<span className="relative z-10 flex items-center gap-1.5">{option.label}</span>
<span className="relative z-10 flex min-w-0 items-center justify-center gap-1.5 whitespace-normal text-center [&>svg]:shrink-0">
{option.label}
</span>
</button>
)
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export function HelperManager() {
// A tool whose kind gives placement notices: its transient draft is the node in hand.
const toolNotices = !!(tool && nodeRegistry.get(tool)?.placementNotice)
const toolDraftId = useScene((s) => (toolNotices ? transientDraftId(s.nodes) : null))
const placementNotice = usePlacementNotice(movingNode?.id ?? toolDraftId)
const placementNotice = usePlacementNotice(movingNode?.id ?? toolDraftId, toolNotices)
const reshapingNode = useReshapingNode()
const activeHandleDrag = useActiveHandleDrag()
const mezzanineHandle = useScene((s) => mezzanineGesture(activeHandleDrag, s.nodes))
Expand Down
25 changes: 24 additions & 1 deletion packages/editor/src/hooks/use-placement-notice.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { describe, expect, test } from 'bun:test'
import { type AnyNode, registerNode } from '@pascal-app/core'
import { placementNoticeOf, transientDraftId } from './use-placement-notice'
import {
placementNoticeOf,
previewPlacementNoticeOf,
transientDraftId,
} from './use-placement-notice'

// The editor asks a node's definition for its placement notice; it names no kind.
function registerKind(placementNotice?: unknown): string {
Expand Down Expand Up @@ -46,3 +50,22 @@ describe('the placement notice of the node in hand', () => {
expect(transientDraftId({ kept: nodes.kept })).toBeNull()
})
})

test('ephemeral preview notices see their context without inserting a draft into the scene', () => {
const kind = registerKind((node: AnyNode, ctx: { nodes: Record<string, AnyNode> }) => ({
line: `${node.id}:${ctx.nodes.child?.name}`,
}))
const nodes = {}
const draft = nodeOf('preview', kind)
expect(
previewPlacementNoticeOf(nodes, {
node: draft,
parentNode: null,
contextNodes: [{ ...nodeOf('child', kind), name: 'draft child' }],
}),
).toEqual({ line: 'preview:draft child' })
expect(nodes).toEqual({})
expect(
previewPlacementNoticeOf(nodes, { node: null, parentNode: null, contextNodes: [] }),
).toBeNull()
})
43 changes: 37 additions & 6 deletions packages/editor/src/hooks/use-placement-notice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
useScene,
} from '@pascal-app/core'
import { useMemo } from 'react'
import { useShallow } from 'zustand/react/shallow'
import usePlacementPreview from '../store/use-placement-preview'

/** The notice `nodeId`'s kind gives for where it stands (`placementNotice`), if it declares one. */
export function placementNoticeOf(
Expand All @@ -21,18 +23,47 @@ export function placementNoticeOf(
return notice(node as never, live ? { nodes, live } : { nodes })
}

export function previewPlacementNoticeOf(
nodes: Readonly<Record<string, AnyNode>>,
draft: Pick<
ReturnType<typeof usePlacementPreview.getState>,
'node' | 'parentNode' | 'contextNodes'
>,
): PlacementNotice | null {
if (!draft.node) return null
const context = {
...nodes,
...Object.fromEntries(draft.contextNodes.map((node) => [node.id, node])),
...(draft.parentNode ? { [draft.parentNode.id]: draft.parentNode } : {}),
[draft.node.id]: draft.node,
}
return placementNoticeOf(context, draft.node.id)
}

/**
* What the node in hand, or the selected node, says about where it stands, read at its live pose
* while it is placed or moved. Subscribes to the scene only while a node is given, so an
* always-mounted caller doesn't re-render on every write.
*/
export function usePlacementNotice(nodeId: string | null | undefined): PlacementNotice | null {
const nodes = useScene((state) => (nodeId ? state.nodes : null))
const live = useLiveTransforms((state) => (nodeId ? state.get(nodeId) : undefined))
return useMemo(
() => (nodeId && nodes ? placementNoticeOf(nodes, nodeId, live) : null),
[nodes, live, nodeId],
export function usePlacementNotice(
nodeId: string | null | undefined,
preview = false,
): PlacementNotice | null {
const draft = usePlacementPreview(
useShallow((state) =>
preview
? { node: state.node, parentNode: state.parentNode, contextNodes: state.contextNodes }
: null,
),
)
const nodes = useScene((state) => (nodeId || draft?.node ? state.nodes : null))
const live = useLiveTransforms((state) => (nodeId ? state.get(nodeId) : undefined))
return useMemo(() => {
if (!nodes) return null
if (nodeId) return placementNoticeOf(nodes, nodeId, live)
if (!draft?.node) return null
return previewPlacementNoticeOf(nodes, draft)
}, [nodes, live, nodeId, draft])
}

/** The node a construction tool is placing: its transient draft. */
Expand Down
Loading
Loading