9.3 KiB
Spatial Context
Locations, Maps and Floor Plans are independently loadable Scene-scoped Context tools. The unified parent retains window identity, two panes, layout, divider, preferences, effective manuscript focus, Hold/Follow and the single native-companion SignalR connection. It supplies generic lifecycle onPosition and onInvalidation hooks, guarded pane closing and an explicit-destination openTool contract. No spatial business logic belongs in the parent.
Read contract
ContextSpatial calls the forward-only migration 339 procedures through Dapper. SpatialContext_Scope authorises an active scene/book/project; the three-scene read uses NarrativeSceneOrder.BookSceneIndex ± 1, within one book. Empty chapters do not introduce synthetic scenes. Scenes.PrimaryLocationID remains the primary assignment. Recorded character/asset/occupancy positions remain separately labelled and never supply a missing primary.
The response includes the three scenes' assigned locations, cycle-safe same-project ancestors, at most forty immediate children of the inspected location, relevant explicit associations, lightweight resource catalogues, relationships and canonical taxonomy presentation. It does not load manuscript paragraphs or the whole location directory. The shared hierarchical picker loads its directory only when invoked.
Direct associations win. Otherwise the nearest active containing location with an authoritative association supplies candidates. Room/block associations take precedence among floor-plan associations at the same depth. Equal candidates prefer coverage of adjacent scenes; an author's still-relevant resource choice is retained. Inherited positions are expressly labelled as containing locations, never exact child positions. No associations are inferred from matching names.
Local selection and refresh
context-spatial.js owns one session per Context root in the current browser window. Its selection message contains location ID, source pane and monotonic revision. It is neither stored nor broadcast. Other visible spatial panes inspect the same location; selecting an ordinary map feature or room never calls manuscript navigation or scene assignment. Future tools such as Assets can call PlotDirectorSpatialContext.subscribe(contextRoot, handler) and retain the returned unsubscribe callback for disposal. inspect(contextRoot, canonicalLocationId, sourceId) publishes inspection only. Version 1 messages carry location, source, revision, Context window ID and project/book scope; consumers must retain these isolation rules and never treat inspection as an assignment command.
State requests are shared by book, scene and inspected location, with a bounded cache; stale response epochs are ignored. Promise identity guards prevent an obsolete response from repopulating the current cache. Hidden tools invalidate cached projections without requesting resources; reactivation then reads fresh data. Paragraph movement does not invoke Scene-scoped lifecycle updates. Visible tools handle relevant invalidations themselves; inactive tools remain stale without loading. Scene/highlight changes retain renderers when resource revisions are unchanged. Persisted location metadata hints refresh canonical floor markup because room labels depend on location names rather than plan timestamps; this refresh restores the selected floor, inspection and viewport. Resource and viewport preferences use author/window/project/tool/resource keys in local storage. Transient placement and inspection selection are never persisted.
Renderers
Maps uses the existing Maps Razor template and maps-workspace.js renderer in an authorised same-origin renderer-only iframe. Its minimal layout has no SignalR or native focus scripts. Editor controls stay hidden; explore mode provides canonical geometry, surrounding features, backgrounds, wheel zoom and pan. The channel/source/origin-checked bridge adds ephemeral combined P/C/N rings and explicit placement coordinates. It cannot save geometry. The main Maps route now validates optional featureId before revealing a feature. Context advanced links target the selected feature or explicit room, and unassociated map features can be inspected without inventing a story-location assignment.
Floor Plans shares _FloorPlanStage, FloorPlanPresentation and floor-plan-renderer.js with the main editor. Original wall segmentation, transitions, hidden-room treatment, geometry and backgrounds remain canonical. Context supplies read-only viewport transforms and ephemeral room badges. Building-level associations do not select an arbitrary room. Editor geometry tools remain in World.
Explicit mutations
Existing LocationWorkspace services handle versioned rename, prose, type and classification edits, protected Undo and child creation. Context scene/marker/plan/room writes use SpatialContext_Mutate: project ownership and edit role, active-location validation, transaction, audit and compare-and-swap are enforced server-side. Scene assignment targets the explicitly labelled current scope scene. Atomic create-and-assign rolls back location creation if assignment fails.
Marker placement inserts an existing location's canonical marker. Duplicate representations are rejected. Repositioning requires explicit confirmation and an unlocked marker; complex geometry stays in Maps. Map revision protects both mutation and Undo. Undo removes only the created marker or restores its original placement.
Room association uses the canonical block's LocationID and a full-row SHA-256 version, read with geometry under repeatable-read isolation. Plan association uses a full-row version. Neither operation changes geometry or location containment. Replacements require confirmation. Persisted changes emit existing lightweight Context invalidations and user-bound, expiring protected Undo receipts. The existing reference invalidation filter also covers successful main Maps/Floor Plans posts. Their shared live-update adapter reuses the established main-window presence connection: clean maps replace their canonical document in place, and clean floor plans reuse the existing workspace replacement/state restoration routine. Active edits are preserved and receive a shared notice; no extra SignalR connection is created. Held windows still receive persisted changes. Scene assignment hints are book-scoped; shared maps, plans, associations and new locations invalidate the project across its books.
Active operations report shared dirty/busy state; tab changes and pane closure are blocked, scene changes defer that pane's refresh, and operation targets remain pinned. Explicit Save/Cancel protects description drafts. Closing the browser warns about active operations.
Boundaries and limitations
Canonical floor-plan blocks require a location ID; there is no separate unassociated-room store. A block can be deliberately reassociated, but Context rejects replacement if recorded floor transitions reference the old or proposed location. Doors/windows use those identities; their reconciliation belongs in the main editor. This preserves transitions rather than creating a competing association model.
Immediate child exploration is bounded to forty entries; open Locations for a larger directory. Advanced boundaries, snapping, smoothing, walls, furniture and architectural construction remain in the main World editors. No routing, geocoding, name inference, AI requests or automatic story-data mutations are introduced.
Physical Windows/Word verification and installed PWA results must be recorded separately from synthetic focus tests in the delivery report.
Main application navigation from Context
Context is a persistent companion workspace. Main application pages must open in its existing main PlotDirector window, leaving every Context pane, draft, selection, viewport and Hold/Follow state intact. Context-local buttons (including Show on map, Show floor plan, scene navigation and inline editing) remain local.
context-main-window.js is the shared delegation point. Its document-level handler
covers same-origin page anchors in the Context document, including dynamically
loaded partials, dialogs and expanded sections. Existing
data-context-workspace-target commands retain their entity/story-point resolver.
Other page links retain their exact path, query and fragment through the optional
ContextWorkspaceTarget.Url contract (tool: page). ContextWorkspaceNavigation
allows only known read-only main-page routes; destination controllers retain normal
authorisation. Add a future page route to that central allowlist rather than adding
feature-specific window discovery, window.open calls or click handlers.
Both forms use the existing workspace.open interaction, Context window registry,
browser/PWA environment identity, native presence connection, main-window activation
and named-window fallback. No extra registry or SignalR connection is introduced.
Rapid requests coalesce to the latest queued destination while a main window opens.
Blocked popups remain intercepted and report through the shared toast; browser/OS
focus policies may require the author to switch windows manually.
Do not change main-page Back buttons to return to Context. Never navigate the
Context document to a main page. Fragment anchors, /Writing/Context routes and
local button interactions are deliberately excluded from this delegation.