pub struct Model<B> {
pub rows: Vec<Row>,
pub selected: usize,
pub mode: Mode,
pub status: String,
pub dirty: bool,
/* private fields */
}Fields§
§rows: Vec<Row>§selected: usize§mode: Mode§status: String§dirty: boolImplementations§
Source§impl<B: Backend> Model<B>
impl<B: Backend> Model<B>
Build a model that hides the given top-level mapping keys from the row
projection while keeping them in the document (see
tree::build_rows). For an embedder whose
format reserves some top-level keys (prov/diaryx-managed frontmatter).
Sourcepub fn with_managed(
backend: B,
hidden: Vec<String>,
derived: Vec<String>,
) -> Result<Self>
pub fn with_managed( backend: B, hidden: Vec<String>, derived: Vec<String>, ) -> Result<Self>
Build a model over backend distinguishing the two kinds of managed key:
hidden ones produce no row (edited through another affordance), while
derived ones keep their row but decline every edit (the workspace
maintains them — see derived).
A key in both is hidden: no row means nothing to mark read-only.
Sourcepub fn with_collapsed(
backend: B,
hidden: Vec<String>,
derived: Vec<String>,
collapsed: Vec<Vec<Seg>>,
) -> Result<Self>
pub fn with_collapsed( backend: B, hidden: Vec<String>, derived: Vec<String>, collapsed: Vec<Vec<Seg>>, ) -> Result<Self>
Build a model whose containers at collapsed arrive shut, before the
first row list is ever built.
A document can have one field nobody reads as a list: an index document’s
contents is one row per child — ninety-five of them in a year index,
ahead of the four fields anyone types by hand. Such a section wants to open
as a summary, not a wall you scroll past. Toggling it afterwards through
activate would work, but that is the interactive
door: it moves the selection and rebuilds the row list once per container.
Seeding the set here costs neither — the paths are in place before
reload, so the opening frame is already correct.
A path that names a scalar (or nothing at all) is inert rather than an error, so a caller can name the keys it wants collapsed without first checking which of them turned out to be containers.
Sourcepub fn set_schema(&mut self, schema: Schema)
pub fn set_schema(&mut self, schema: Schema)
Inject a schema out-of-band — the embedder precedent, mirroring
with_hidden. For a host whose backend does not
supply one but that knows the governing schema (a diaryx host feeding a
fig-backed frontmatter block plus its resolved workspace config).
Sourcepub fn rule_at(&self, path: &[Seg]) -> Option<&FieldRule>
pub fn rule_at(&self, path: &[Seg]) -> Option<&FieldRule>
The schema rule governing the node at path, if any — for a frontend
deciding a widget (a picker for an enum field) or presentation.
Sourcepub fn root_kind(&self) -> &'static str
pub fn root_kind(&self) -> &'static str
The kind of the document root, for a frontend deciding how to add a
top-level entry: "map", "seq", or "scalar".
How many of the hidden top-level keys are actually present in the document — for a “N managed fields” affordance.
Sourcepub fn is_derived(&self, path: &[Seg]) -> bool
pub fn is_derived(&self, path: &[Seg]) -> bool
Whether the node at path sits under a workspace-maintained (derived)
top-level key — for a frontend rendering it read-only rather than as an
editable control. Edits to it are declined at the commit funnel regardless.
Sourcepub fn addable_fields(&self) -> Vec<&FieldRule> ⓘ
pub fn addable_fields(&self) -> Vec<&FieldRule> ⓘ
The schema-declared top-level fields the document does not yet carry — what an “add field” affordance offers, so a declared field is reachable before it exists.
Rows are projected from the document
(build_rows), so a field the schema declares
but the document omits has no row and is otherwise unreachable: the user
would have to know the key and type it exactly. This closes that gap —
it is the schema’s half of the row list, and the reason a declared type
is worth writing down for a field that is empty.
Only a rule addressing exactly one top-level key names an addable field: an each-item or subtree rule governs within a field rather than naming one. Hidden (managed) keys are never offered — the embedder reserves those. Order follows the schema’s own rule order, so a caller can present them as declared.
Sourcepub fn source_snapshot(&self) -> String
pub fn source_snapshot(&self) -> String
The canonical serialized document — what the embedder writes on save.
Sourcepub fn backend(&self) -> &B
pub fn backend(&self) -> &B
The backend, for backend-specific reads (e.g. a prov backend’s body).
Sourcepub fn backend_mut(&mut self) -> &mut B
pub fn backend_mut(&mut self) -> &mut B
The backend, for backend-specific operations that do not change the metadata tree flower renders (e.g. replacing a prov document’s prose body). An op that does change the metadata leaves the view stale — go through the model’s own edit methods for those.
pub fn set_status(&mut self, s: impl Into<String>)
Sourcepub fn mark_saved(&mut self)
pub fn mark_saved(&mut self)
Clear the dirty flag after the embedder has persisted the source.
pub fn move_down(&mut self)
pub fn move_up(&mut self)
Sourcepub fn expand_or_enter(&mut self)
pub fn expand_or_enter(&mut self)
l: expand a collapsed container, else step into its first child.
Sourcepub fn collapse_or_leave(&mut self)
pub fn collapse_or_leave(&mut self)
h: collapse an expanded container, else step out to the parent row.
Sourcepub fn is_collapsed(&self, path: &[Seg]) -> bool
pub fn is_collapsed(&self, path: &[Seg]) -> bool
Whether the container at path is collapsed. Answers for a node with no
row too (one nested inside another collapsed container), which
Row::expanded cannot.
Sourcepub fn set_collapsed(&mut self, path: &[Seg], collapsed: bool)
pub fn set_collapsed(&mut self, path: &[Seg], collapsed: bool)
Collapse or expand the container at path, leaving the selection where the
user put it — the by-path, non-interactive counterpart to
activate.
activate folds the selected row, so driving it from a path means moving
the selection first and putting it back after. This doesn’t: it re-anchors
onto whatever was selected before, and only falls back to path itself when
the selection was a descendant that the fold just took off screen.
A path naming a scalar (or nothing) is inert — see
with_collapsed.
pub fn begin_edit(&mut self)
pub fn edit_push(&mut self, c: char)
pub fn edit_backspace(&mut self)
pub fn edit_cancel(&mut self)
pub fn edit_commit(&mut self)
Sourcepub fn set_value_at(&mut self, path: &[Seg], value: Value)
pub fn set_value_at(&mut self, path: &[Seg], value: Value)
Programmatically replace the value at path (any depth), refreshing the
view. The non-interactive counterpart to edit_commit
— for an embedder or FFI that edits by path rather than through the
selection.
Sourcepub fn set_scalar_text(&mut self, path: &[Seg], text: &str)
pub fn set_scalar_text(&mut self, path: &[Seg], text: &str)
Set the scalar at path from an edit-buffer text, coercing by the
schema’s expected type when known (a str field keeps "123" a string)
and otherwise guessing by literal shape — the by-path, schema-aware analog
of edit_commit. Validation (closed-vocabulary
rejection) still happens at the commit funnel.
Sourcepub fn rename_key(&mut self, path: &[Seg], new_key: &str)
pub fn rename_key(&mut self, path: &[Seg], new_key: &str)
Rename the mapping entry at path to new_key, keeping its value and
re-anchoring the selection onto the renamed entry. A no-op (with a status
hint) when path doesn’t end in a key — a sequence item has no key. The
backend rejects a name that collides with an existing sibling key.
Sourcepub fn insert_key(&mut self, map_path: &[Seg], key: &str, value: Value)
pub fn insert_key(&mut self, map_path: &[Seg], key: &str, value: Value)
Insert key = value into the mapping at map_path, selecting the new
entry. A frontend offers this on a map container; the backend rejects a
duplicate key or a non-mapping target, leaving the document untouched.
Sourcepub fn insert_key_text(&mut self, map_path: &[Seg], key: &str, text: &str)
pub fn insert_key_text(&mut self, map_path: &[Seg], key: &str, text: &str)
Insert key = text into the mapping at map_path, coercing text by the
type the schema declares for the new entry and otherwise guessing by literal
shape — the insert-shaped analog of
set_scalar_text.
Prefer this to insert_key whenever the value comes
from a user’s text: a caller that shape-guesses on its own writes 2026 as
an integer into a field the schema declares str, and gets no say from the
schema it is otherwise honoring everywhere else.
Sourcepub fn append_item(&mut self, seq_path: &[Seg], value: Value)
pub fn append_item(&mut self, seq_path: &[Seg], value: Value)
Append value to the sequence at seq_path, selecting the new item.
Sourcepub fn append_item_text(&mut self, seq_path: &[Seg], text: &str)
pub fn append_item_text(&mut self, seq_path: &[Seg], text: &str)
Append text to the sequence at seq_path, coercing it by the type the
schema declares for the sequence’s items and otherwise guessing by literal
shape — the append-shaped analog of
set_scalar_text.
The item’s type comes from the rule matching the item path (an each-item or
subtree rule), not from the rule on the list itself: tags is a seq, its
items are str.
Sourcepub fn move_selected_up(&mut self)
pub fn move_selected_up(&mut self)
Move the selected row one place earlier among its siblings — a sequence item via fig’s array-move, a mapping entry via a one-swap reorder.
Sourcepub fn move_selected_down(&mut self)
pub fn move_selected_down(&mut self)
Move the selected row one place later among its siblings.
Sourcepub fn value_at(&self, path: &[Seg]) -> Option<&Value>
pub fn value_at(&self, path: &[Seg]) -> Option<&Value>
The value the document currently holds at path (the whole tree for the
empty path), or None when the path doesn’t resolve — for a frontend
reading a row’s value without reaching for the backend.
Sourcepub fn seq_len(&self, path: &[Seg]) -> usize
pub fn seq_len(&self, path: &[Seg]) -> usize
The length of the sequence at path (0 for a non-sequence) — the index an
append will land at.
Sourcepub fn delete_selected(&mut self)
pub fn delete_selected(&mut self)
x: delete the selected mapping entry or sequence item.