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
76 changes: 76 additions & 0 deletions packages/editor/src/lib/floorplan/floorplan-export.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { splitFloorplanOverlay } from '../../components/editor-2d/renderers/floo
import { DEFAULT_FLOORPLAN_ANNOTATION_VISIBILITY } from './annotation-visibility'
import {
collectFloorplanGeometry,
collectFloorplanSchedules,
filterFloorplanExportOverlay,
fitPlanToBox,
isFloorplanExportAnnotationGeometry,
Expand Down Expand Up @@ -424,6 +425,81 @@ describe('isFloorplanNodeInExportScope', () => {
})
})

describe('collectFloorplanSchedules', () => {
test('omits non-structure schedule contributors under structure scope', () => {
const restoreRegistry = nodeRegistry._snapshot()
const structureKind = 'test:structure-schedule'
const siteKind = 'test:site-schedule'
const levelId = 'level_schedules' as AnyNode['id']
const structureNodeId = 'structure_scheduled' as AnyNode['id']
const siteNodeId = 'site_scheduled' as AnyNode['id']

const scheduleFor = (title: string) => ({
id: title.toLowerCase(),
title,
columns: [{ key: 'id', label: 'ID' }],
rows: [{ id: 'row', cells: { id: '1' } }],
})

try {
nodeRegistry._reset()
registerNode({
kind: structureKind,
schemaVersion: 1,
schema: z.object({ type: z.literal(structureKind) }) as never,
category: 'structure',
defaults: () => ({}) as never,
capabilities: {},
extensions: {
'pascal:editor/floorplan': {
schedule: () => scheduleFor('Doors'),
},
},
} as AnyNodeDefinition)
registerNode({
kind: siteKind,
schemaVersion: 1,
schema: z.object({ type: z.literal(siteKind) }) as never,
category: 'site',
defaults: () => ({}) as never,
capabilities: {},
extensions: {
'pascal:editor/floorplan': {
schedule: () => scheduleFor('Rooms'),
},
},
} as AnyNodeDefinition)

const nodes = {
[levelId]: {
id: levelId,
type: 'level',
visible: true,
children: [structureNodeId, siteNodeId],
},
[structureNodeId]: {
id: structureNodeId,
type: structureKind,
visible: true,
},
[siteNodeId]: {
id: siteNodeId,
type: siteKind,
visible: true,
},
} as unknown as Record<string, AnyNode>

const full = collectFloorplanSchedules(nodes, levelId, 'metric', 'full')
expect(full.map((schedule) => schedule.title).sort()).toEqual(['Doors', 'Rooms'])

const structure = collectFloorplanSchedules(nodes, levelId, 'metric', 'structure')
expect(structure.map((schedule) => schedule.title)).toEqual(['Doors'])
} finally {
restoreRegistry()
}
})
})

describe('collectFloorplanGeometry', () => {
test('collects the active Site once below architecture with semantic context and projection', async () => {
const restoreRegistry = nodeRegistry._snapshot()
Expand Down
6 changes: 5 additions & 1 deletion packages/editor/src/lib/floorplan/floorplan-export.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export async function exportFloorplanPdf(scope: FloorplanExportScope): Promise<v
wallDimensionReference,
installedPlugins,
)
const schedules = collectFloorplanSchedules(nodes, level.id, unit)
const schedules = collectFloorplanSchedules(nodes, level.id, unit, scope)
if (geometries.length === 0 && schedules.length === 0) continue
const layout = resolveFloorplanPageLayout(A4_LANDSCAPE_WIDTH_PT, A4_LANDSCAPE_HEIGHT_PT)

Expand Down Expand Up @@ -305,6 +305,7 @@ export function collectFloorplanSchedules(
nodes: Record<string, AnyNode>,
levelId: AnyNodeId,
unit: 'metric' | 'imperial',
scope: FloorplanExportScope = 'full',
): FloorplanSchedule[] {
const siblingsByType = new Map<string, AnyNode[]>()
const visit = (id: AnyNodeId) => {
Expand All @@ -324,6 +325,9 @@ export function collectFloorplanSchedules(
for (const [kind, definition] of nodeRegistry.entries()) {
const scheduleContribution = getFloorplanNodeExtension(definition)?.schedule
if (!scheduleContribution) continue
// Same scope gate as geometry: a structure-only PDF must not list rooms
// or other site-category contributors whose plan geometry was excluded.
if (!isFloorplanNodeInExportScope(definition, scope)) continue
const siblings = siblingsByType.get(kind) ?? []
const schedule = scheduleContribution({ siblings, nodes, levelId, unit })
if (schedule && schedule.rows.length > 0) schedules.push(schedule)
Expand Down