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
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import { type AnyNodeDefinition, emitter, nodeRegistry, registerNode } from '@pa
import { createElement } from 'react'
import { renderToStaticMarkup } from 'react-dom/server'
import { z } from 'zod'
import { AXIS_MOVE_DRAG_LABEL, PATH_POINT_DRAG_LABEL } from '../../../lib/contextual-help'
import {
FLOORPLAN_NODE_EXTENSION_KEY,
floorplanGeometryMetadata,
} from '../../../lib/floorplan/floorplan-extension'
import type { SessionWrites } from '../../../lib/session-writes'
import { snapContextOf } from '../../../lib/snapping-mode'
import {
buildFloorplanEntryGeometry,
cancelFloorplanAffordanceDrag,
Expand Down Expand Up @@ -276,6 +278,26 @@ describe('floorplan affordance ownership', () => {
driver: 'floorplan',
})
})

// With no scope, Select mode reads every snap mode as off, so these drags
// never snapped to the grid on the plan.
test('gives the MEP run point and segment drags a handle-drag scope in the run snap context', () => {
const point = floorplanAffordanceReshapeScope('move-path-point', 'duct_1', { pointIndex: 0 })
const segment = floorplanAffordanceReshapeScope('move-segment', 'duct_1', { segmentIndex: 0 })
expect(point).toEqual({ kind: 'handle-drag', nodeId: 'duct_1', handle: PATH_POINT_DRAG_LABEL })
expect(segment).toEqual({ kind: 'handle-drag', nodeId: 'duct_1', handle: AXIS_MOVE_DRAG_LABEL })
for (const scope of [point, segment]) {
expect(
snapContextOf({
scope: scope!,
mode: 'select',
tool: null,
profileOf: () => undefined,
profileOfNode: () => 'structural',
}),
).toBe('polygon')
}
})
})

function cabinetRun(id: string, children: string[] = [], parentId: string | null = 'level_test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ import {
useRoomRecords,
} from '../../../hooks/use-selected-room'
import { useCeilingEditSession } from '../../../lib/ceiling-edit-session'
import { ROTATE_HANDLE_DRAG_LABEL } from '../../../lib/contextual-help'
import {
AXIS_MOVE_DRAG_LABEL,
PATH_POINT_DRAG_LABEL,
ROTATE_HANDLE_DRAG_LABEL,
} from '../../../lib/contextual-help'
import {
canDirectRotateNode,
resolveDirectManipulationNode,
Expand Down Expand Up @@ -321,7 +325,7 @@ export function subscribeFloorplanAffordanceToolCancel(
// edits that set a direction/shape map to a scope; resize / rotate / body-move
// affordances return `null` (no polygon/wall snapping chip). Keyed off the
// affordance name the kinds register (`move-vertex` / `move-edge` / `add-vertex`
// / `curve` / `move-endpoint`).
// / `curve` / `move-endpoint` / `move-path-point` / `move-segment`).
export function floorplanAffordanceReshapeScope(
affordance: string,
nodeId: string,
Expand Down Expand Up @@ -362,6 +366,14 @@ export function floorplanAffordanceReshapeScope(
if (affordance.includes('rotate')) {
return { kind: 'handle-drag', nodeId, handle: ROTATE_HANDLE_DRAG_LABEL }
}
// MEP run point and run segment drags: the same handle-drag scopes as their
// 3D arrows, so they snap in the kind's own context (polygon for runs).
if (affordance === 'move-path-point') {
return { kind: 'handle-drag', nodeId, handle: PATH_POINT_DRAG_LABEL }
}
if (affordance === 'move-segment') {
return { kind: 'handle-drag', nodeId, handle: AXIS_MOVE_DRAG_LABEL }
}
return null
}

Expand Down
53 changes: 53 additions & 0 deletions packages/editor/src/components/ui/helpers/helper-manager.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { describe, expect, test } from 'bun:test'
import { renderToStaticMarkup } from 'react-dom/server'
import {
AXIS_MOVE_DRAG_LABEL,
PATH_POINT_DRAG_LABEL,
ROTATE_HANDLE_DRAG_LABEL,
} from '../../../lib/contextual-help'
import { SELECT_HUD_TITLE, toolHudTitle } from '../../../lib/hud-title'
import { snapContextOf } from '../../../lib/snapping-mode'
import { cornerHintRows } from '../../../store/use-corner-snap-hint'
import { TooltipProvider } from '../primitives/tooltip'
import { ContextualHelperPanel } from './contextual-helper-panel'
import {
mepHandleGesture,
mepHandleGestureHints,
mezzanineHints,
openingHints,
ROOM_DIVIDE_HINTS,
Expand Down Expand Up @@ -128,6 +135,52 @@ describe('HUD header', () => {
})
})

describe('MEP handle HUD', () => {
const english = (hints: ReturnType<typeof mepHandleGestureHints>) =>
hints.map((hint) => (typeof hint.label === 'string' ? hint.label : hint.label.message))
const drag = (label: string) => ({ nodeId: 'pipe_a', label })

test('names a run point drag and an axis slide, and leaves rotate and resize to their own HUDs', () => {
expect(mepHandleGesture(drag(PATH_POINT_DRAG_LABEL))).toBe('edit-path')
expect(mepHandleGesture(drag(AXIS_MOVE_DRAG_LABEL))).toBe('move')
expect(mepHandleGesture(drag(ROTATE_HANDLE_DRAG_LABEL))).toBeNull()
expect(mepHandleGesture(drag('resize-diameter'))).toBeNull()
expect(mepHandleGesture(null)).toBeNull()
})

test('keeps "Alt: Detach the joint" on screen for the whole run point drag', () => {
const idle = mepHandleGestureHints('edit-path', false)
expect(english(idle)).toEqual(['Detach the joint', 'Cancel'])
expect(idle.map((hint) => hint.keys)).toEqual([['Alt'], ['Esc']])
expect(idle[0]?.active).toBe(false)
expect(mepHandleGestureHints('edit-path', true)[0]?.active).toBe(true)
expect(english(mepHandleGestureHints('move', false))).toEqual(['Cancel'])

const html = renderToStaticMarkup(
<TooltipProvider>
<ContextualHelperPanel hints={idle} snapContext="polygon" />
</TooltipProvider>,
)
for (const label of ['Detach the joint', 'Cancel', 'Snapping: Grid']) expect(html).toContain(label)
})

test('a handle drag snaps in its kind context, and a rotate arc in angles', () => {
const contextOf = (handle: string, profile: 'item' | 'structural') =>
snapContextOf({
scope: { kind: 'handle-drag', nodeId: 'pipe_a', handle },
mode: 'select',
tool: null,
profileOf: () => undefined,
profileOfNode: () => profile,
})
expect(contextOf(PATH_POINT_DRAG_LABEL, 'structural')).toBe('polygon')
expect(contextOf(AXIS_MOVE_DRAG_LABEL, 'structural')).toBe('polygon')
expect(contextOf(AXIS_MOVE_DRAG_LABEL, 'item')).toBe('item')
expect(contextOf('resize-diameter', 'item')).toBe('item')
expect(contextOf(ROTATE_HANDLE_DRAG_LABEL, 'item')).toBe('rotation')
})
})

describe('Cut opening HUD', () => {
test('names the drag gesture "Draw the opening", not the mezzanine', () => {
// The drag row folds under "More shortcuts", so read the rows the HUD is given.
Expand Down
54 changes: 54 additions & 0 deletions packages/editor/src/components/ui/helpers/helper-manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import { useEffect, useMemo, useState, useSyncExternalStore } from 'react'
import { useShallow } from 'zustand/react/shallow'
import { useIsMobile } from '../../../hooks/use-mobile'
import {
AXIS_MOVE_DRAG_LABEL,
type ContextualShortcutHint,
GROUP_MOVE_DRAG_LABEL,
GROUP_ROTATE_DRAG_LABEL,
PATH_POINT_DRAG_LABEL,
ROTATE_HANDLE_DRAG_LABEL,
resolveRotateHandleHelpHints,
resolveSelectModeHelpHints,
Expand Down Expand Up @@ -294,6 +296,40 @@ export const MEZZANINE_GESTURE_HINTS: Record<MezzanineGesture, ContextualShortcu
],
}

export type MepHandleGesture = 'edit-path' | 'move'

/**
* A drag on an MEP handle — a run point, where Alt detaches the joint, or a
* fitting, run or run segment slid along an axis — or null. Its HUD names the
* kind and the gesture, not "Resize".
*/
export function mepHandleGesture(
drag: { nodeId: string; label: string } | null,
): MepHandleGesture | null {
if (drag?.label === PATH_POINT_DRAG_LABEL) return 'edit-path'
if (drag?.label === AXIS_MOVE_DRAG_LABEL) return 'move'
return null
}

export function mepHandleGestureHints(
gesture: MepHandleGesture,
altPressed: boolean,
): ContextualShortcutHint[] {
const cancel: ContextualShortcutHint = {
keys: ['Esc'],
label: /* i18n */ { id: 'editor.helpers.helperManager.cancel', message: 'Cancel' },
}
if (gesture === 'move') return [cancel]
return [
{
keys: ['Alt'],
label: /* i18n */ { id: 'editor.helpers.helperManager.detachTheJoint', message: 'Detach the joint' },
active: altPressed,
},
cancel,
]
}

/**
* Whether the armed tool's own hints (`toolHints`) win over the node in hand: a registry tool that
* holds its draft in a placing scope (the roof's footprint, a fitting, a block) says what its clicks
Expand Down Expand Up @@ -340,6 +376,10 @@ export function HelperManager() {
const reshapingNode = useReshapingNode()
const activeHandleDrag = useActiveHandleDrag()
const mezzanineHandle = useScene((s) => mezzanineGesture(activeHandleDrag, s.nodes))
const mepHandle = mepHandleGesture(activeHandleDrag)
const mepHandleKind = useScene((s) =>
mepHandle && activeHandleDrag ? s.nodes[activeHandleDrag.nodeId as AnyNodeId]?.type : undefined,
)
const selectedIds = useViewer((s) => s.selection.selectedIds)
const isMobile = useIsMobile()
const modifiers = useActiveModifierKeys()
Expand Down Expand Up @@ -518,6 +558,20 @@ export function HelperManager() {
)
}

if (mepHandle) {
return (
<ContextualHelperPanel
hints={mepHandleGestureHints(mepHandle, modifiers.alt)}
snapContext={snapContext}
title={
mepHandleKind
? nodeKindHudTitle(mepHandleKind, mepHandle === 'move' ? 'move' : 'edit')
: null
}
/>
)
}

// A single-node resize arrow is still an active snapping interaction. Roof
// width/depth handles opt into grid snapping, so keep the mode and grid-step
// controls visible for the whole drag instead of falling through to idle
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/i18n/locales/en-XA/messages.ts

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions packages/editor/src/i18n/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -1865,6 +1865,10 @@ msgstr "Cancel picking"
msgid "editor.helpers.helperManager.cancelStroke"
msgstr "Cancel stroke"

#: packages/editor/src/components/ui/helpers/helper-manager.tsx
msgid "editor.helpers.helperManager.detachTheJoint"
msgstr "Detach the joint"

#: packages/editor/src/components/ui/helpers/helper-manager.tsx
msgid "editor.helpers.helperManager.done"
msgstr "Done"
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/i18n/locales/en/messages.ts

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions packages/editor/src/i18n/locales/es/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -4595,6 +4595,16 @@ msgstr "Cancelar selección"
msgid "editor.helpers.helperManager.cancelStroke"
msgstr "Cancelar trazo"

# Source-Hash: 7aaeeaeb3e2f247a
# Review: required
# AI-Provider: claude-code
# AI-Model: claude-opus-5-5
# English: "Detach the joint"
#: packages/editor/src/components/ui/helpers/helper-manager.tsx
#, fuzzy
msgid "editor.helpers.helperManager.detachTheJoint"
msgstr "Separar la unión"

# Source-Hash: 16552c2580bbe8b8
# Review: required
# AI-Provider: claude-code
Expand Down
10 changes: 10 additions & 0 deletions packages/editor/src/i18n/locales/fr/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -4595,6 +4595,16 @@ msgstr "Annuler la sélection"
msgid "editor.helpers.helperManager.cancelStroke"
msgstr "Annuler le tracé"

# Source-Hash: 7aaeeaeb3e2f247a
# Review: required
# AI-Provider: claude-code
# AI-Model: claude-opus-5-5
# English: "Detach the joint"
#: packages/editor/src/components/ui/helpers/helper-manager.tsx
#, fuzzy
msgid "editor.helpers.helperManager.detachTheJoint"
msgstr "Détacher la jonction"

# Source-Hash: 16552c2580bbe8b8
# Review: required
# AI-Provider: claude-code
Expand Down
10 changes: 10 additions & 0 deletions packages/editor/src/i18n/locales/ja/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -4595,6 +4595,16 @@ msgstr "選択をキャンセル"
msgid "editor.helpers.helperManager.cancelStroke"
msgstr "ストロークをキャンセル"

# Source-Hash: 7aaeeaeb3e2f247a
# Review: required
# AI-Provider: claude-code
# AI-Model: claude-opus-5-5
# English: "Detach the joint"
#: packages/editor/src/components/ui/helpers/helper-manager.tsx
#, fuzzy
msgid "editor.helpers.helperManager.detachTheJoint"
msgstr "接合を外す"

# Source-Hash: 16552c2580bbe8b8
# Review: required
# AI-Provider: claude-code
Expand Down
10 changes: 10 additions & 0 deletions packages/editor/src/i18n/locales/zh-CN/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -4595,6 +4595,16 @@ msgstr "取消拾取"
msgid "editor.helpers.helperManager.cancelStroke"
msgstr "取消笔画"

# Source-Hash: 7aaeeaeb3e2f247a
# Review: required
# AI-Provider: claude-code
# AI-Model: claude-opus-5-5
# English: "Detach the joint"
#: packages/editor/src/components/ui/helpers/helper-manager.tsx
#, fuzzy
msgid "editor.helpers.helperManager.detachTheJoint"
msgstr "断开连接"

# Source-Hash: 16552c2580bbe8b8
# Review: required
# AI-Provider: claude-code
Expand Down
7 changes: 6 additions & 1 deletion packages/editor/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,12 @@ export {
resolveCeilingPlanPointSnap,
} from './lib/ceiling-plan-snap'
export { EDITOR_LAYER } from './lib/constants'
export type { ContextualShortcutHint } from './lib/contextual-help'
export {
AXIS_MOVE_DRAG_LABEL,
type ContextualShortcutHint,
PATH_POINT_DRAG_LABEL,
ROTATE_HANDLE_DRAG_LABEL,
} from './lib/contextual-help'
export {
CONTEXTUAL_HELP_NODE_EXTENSION_KEY,
type ContextualHelpNodeExtension,
Expand Down
6 changes: 6 additions & 0 deletions packages/editor/src/lib/contextual-help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export const RESIZE_HANDLE_DRAG_LABEL = 'resize-handle'
export const GROUP_MOVE_DRAG_LABEL = 'group-move-handle'
export const GROUP_ROTATE_DRAG_LABEL = 'group-rotate-handle'

// `activeHandleDrag.label`s for the MEP handles, in 3D and on the plan: one
// point of a run, where Alt detaches the joint, and a fitting, a run or one
// run segment slid along an axis. Their snap context is the kind's own.
export const PATH_POINT_DRAG_LABEL = 'path-point'
export const AXIS_MOVE_DRAG_LABEL = 'axis-move'

export function resolveRotateHandleHelpHints(altPressed: boolean): ContextualShortcutHint[] {
return [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/nodes/src/agent-tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const pipeConnectTool = {
export const builtinAgentTools = {
pluginId: 'pascal:core',
apiVersion: 1,
version: '1.1.1',
version: '1.1.2',
tools: [
finishKitchenRunTool,
checkKitchenClearanceTool,
Expand Down
Loading
Loading