Skip to content

Assembly Explosion Stage and Move Elements - #936

Draft
seveibar wants to merge 1 commit into
mainfrom
assembly-explosion-stage-and-move
Draft

seveibar wants to merge 1 commit into
mainfrom
assembly-explosion-stage-and-move

Conversation

@seveibar

@seveibar seveibar commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Adds props for <assembly.explosion.stage> and <assembly.explosion.move> so TSX authors can describe staged disassembly, including moving a subassembly intact before exploding its children at the displaced pose.

Stages accept name, optional nextStageRef / prevStageRef, and preserved children. Moves accept targetRef and signed, unit-aware offX / offY / offZ, normalized to finite millimeters. targetRef avoids React's reserved ref prop. Validators and input types are exported individually and through assemblyProps.explosion.

The proposal documents document-order fallback, cross-assembly ordering references, accumulated motion, and automatic swept-path collision checks. This PR supplies props and validation; namespaced JSX components, stage scheduling, and collision checking require corresponding core support. No explosion container or run, detach, translate, or collision-check elements are introduced.

Validation:

  • bun test: 674 passed, 0 failed.
  • tsc --noEmit: passed.
  • biome format .: passed.
  • All four required documentation generation scripts completed; generated props overview included.

Approval tracking: this PR remains draft and awaiting API approval. Related speculative drafts are core#4631 for constrained explosion views and PoppyGL renders, and poppygl#49 for guide lines. All three require approval before merge; core uses pinned previews until the upstream packages are approved and released.

Comment on lines +1 to +149
import { expect, test } from "bun:test"
import {
type AssemblyExplosionMoveProps,
type AssemblyExplosionMovePropsInput,
type AssemblyExplosionStageProps,
type AssemblyExplosionStagePropsInput,
assemblyExplosionMoveProps,
assemblyExplosionProps,
assemblyExplosionStageProps,
assemblyProps,
assemblySubassemblyProps,
} from "lib"
import { createElement, type ReactNode } from "react"

test("exports stage and move through the nested explosion namespace", () => {
expect(assemblyProps.explosion).toBe(assemblyExplosionProps)
expect(assemblyProps.explosion.stage).toBe(assemblyExplosionStageProps)
expect(assemblyProps.explosion.move).toBe(assemblyExplosionMoveProps)
expect(Object.keys(assemblyProps.explosion).sort()).toEqual(["move", "stage"])
})

test("trims stage identities and ordering hints without adding defaults", () => {
const input: AssemblyExplosionStageProps = {
name: " remove-cover ",
prevStageRef: " remove-screws ",
nextStageRef: " cover.remove-window ",
}
const props: AssemblyExplosionStagePropsInput = input
expect(assemblyExplosionStageProps.parse(props)).toEqual({
name: "remove-cover",
prevStageRef: "remove-screws",
nextStageRef: "cover.remove-window",
})
expect(assemblyExplosionStageProps.parse({ name: "lift" })).toEqual({
name: "lift",
})
})

test("rejects missing, blank, or invalid stage identities and hints", () => {
for (const input of [
{},
{ name: "" },
{ name: " " },
{ name: 1 },
{ name: "lift", nextStageRef: " " },
{ name: "lift", prevStageRef: "" },
{ name: "lift", nextStageRef: null },
{ name: "lift", prevStageRef: 1 },
]) {
expect(assemblyExplosionStageProps.safeParse(input).success).toBe(false)
}
})

test("converts signed offsets to finite millimeters and leaves absent axes omitted", () => {
const input: AssemblyExplosionMoveProps = {
targetRef: " cover ",
offX: "-2cm",
offY: 0,
offZ: "1in",
}
const props: AssemblyExplosionMovePropsInput = input
expect(assemblyExplosionMoveProps.parse(props)).toEqual({
targetRef: "cover",
offX: -20,
offY: 0,
offZ: 25.4,
})
for (const axis of ["offX", "offY", "offZ"] as const) {
expect(
assemblyExplosionMoveProps.parse({ targetRef: "cover", [axis]: 0 }),
).toEqual({ targetRef: "cover", [axis]: 0 })
expect(
assemblyExplosionMoveProps.parse({
targetRef: "cover.window",
[axis]: "-5mm",
}),
).toEqual({ targetRef: "cover.window", [axis]: -5 })
}
})

test("rejects invalid move targets, missing offsets, and nonfinite distances", () => {
for (const input of [
{},
{ offZ: 10 },
{ targetRef: "", offZ: 10 },
{ targetRef: " ", offZ: 10 },
{ targetRef: 1, offZ: 10 },
{ targetRef: "cover" },
]) {
expect(assemblyExplosionMoveProps.safeParse(input).success).toBe(false)
}
for (const axis of ["offX", "offY", "offZ"] as const) {
for (const value of [
"nonsense",
Number.NaN,
Number.POSITIVE_INFINITY,
Number.NEGATIVE_INFINITY,
null,
]) {
expect(
assemblyExplosionMoveProps.safeParse({
targetRef: "cover",
[axis]: value,
}).success,
).toBe(false)
}
}
})

test("TSX preserves move targets and ordered children inside subassemblies", () => {
// Props supplies validators; core supplies the namespaced JSX components.
const assembly = {
explosion: {
stage: (props: AssemblyExplosionStagePropsInput) =>
createElement("assembly.explosion.stage", props),
move: (props: AssemblyExplosionMovePropsInput) =>
createElement("assembly.explosion.move", props),
},
}
const firstMove = <assembly.explosion.move targetRef="cover" offZ="12mm" />
const secondMove = <assembly.explosion.move targetRef="cover" offX="60mm" />
expect(assemblyExplosionMoveProps.parse(firstMove.props)).toEqual({
targetRef: "cover",
offZ: 12,
})
const stage = (
<assembly.explosion.stage
name="remove-cover"
nextStageRef="cover.remove-window"
>
{firstMove}
{secondMove}
</assembly.explosion.stage>
)
const parsed = assemblyExplosionStageProps.parse(stage.props)
expect(parsed.children).toBe(stage.props.children)
expect(parsed.children).toEqual([firstMove, secondMove])
expect(
assemblySubassemblyProps.parse({ name: "module", children: stage })
.children,
).toBe(stage)
const emptyChildren: ReactNode = null
expect(
assemblyExplosionStageProps.parse({
name: "pause",
children: emptyChildren,
}).children,
).toBeNull()
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file contains 6 test(...) calls, but the style guide rule states that a *.test.ts (or *.test.tsx) file may have AT MOST one test(...). After that, the tests should be split into multiple numbered files, e.g., assembly-explosion1.test.tsx, assembly-explosion2.test.tsx, assembly-explosion3.test.tsx, etc. Please split this file into 6 separate numbered test files, each containing exactly one test(...) call.

Spotted by Graphite (based on custom rule: Custom rule)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant