Skip to content

Worksheet

The Worksheet modality arranges components on a grid and compiles them into a linear sequence of worksheet elements. It implements all three core traits — Reducer, Component, and Modality — on a single struct.

Associated TypeConcrete Type
SyncedWorksheetSynced
EphemeralWorksheetEphemeral
PositionGridPosition
ChildComponentdyn WorksheetComponent
Component::MetadataWorksheetMetadata
Component::OutputVec<WorksheetElement>
SnapshotWorksheetSnapshot

Session type: Session<Worksheet, SessionIntent<WorksheetIntent>>

pub struct Worksheet {
state: State<WorksheetSynced, WorksheetEphemeral>,
}

GridPosition describes where a component sits on the worksheet grid:

pub struct GridPosition {
pub row: u32,
pub col: u32,
// grid span, etc.
}

Implements Clone, PartialEq, Hash, Describe. Describe output: "row 2, col 3".

pub struct WorksheetSynced {
pub placements: Vec<ComponentPlacement<GridPosition>>,
// resource metadata (HasResourceMeta)
}

Each placement has a component_key (e.g. "question", "section_heading") and optional component_id for customized instances.

The compiled output is a sequence of WorksheetElement values (renamed from WorksheetNode):

pub enum WorksheetElement {
Question(QuestionElement),
SectionHeading(SectionHeadingElement),
// ... additional variants
}

The worksheet keeps its own compile context for grid layout math. WorksheetMetadata captures the grid parameters used as the modality-level Component::Metadata:

pub struct WorksheetMetadata {
pub cell_width: f64,
pub cell_height: f64,
pub margin: f64,
// grid dimensions, node bounds, etc.
}

WorksheetMetadata: Hash enables the incremental compilation cache on Session. When the grid parameters change, the entire worksheet recompiles; when only a single placement changes, only that component recompiles.

The layout() default iterates placements, resolves bindings, and delegates to compile_child. assemble() collects the per-component WorksheetElement outputs into Vec<WorksheetElement>.

fn compile_child(
&self,
placement: &ComponentPlacement<GridPosition>,
_meta: &(),
values: &HashMap<String, PropertyValue>,
) -> Result<WorksheetElement, CompileError> {
let component = resolve_component(&placement.component_key);
component.compile(&(), values)
}
  • Intents — all WorksheetIntent variants
  • Components — the WorksheetComponent subtrait and built-ins
  • Reducer — state management via the Genvoy pattern
  • Command — the universal envelope wrapping WorksheetIntent
  • FRB Patterns — how worksheet types cross the Dart/Rust boundary