Skip to main content

Module admin

Module admin 

Source
Expand description

Admin-side editor rendering for WidgetKind::Stream widgets.

The page-edit form pre-renders the entire stream editor HTML in Rust before passing it through Tera — mirrors the existing Widget::custom_html stash pattern in src/admin/handlers.rs. The output is one big string of <div data-stream-block> nodes plus <template> clones the client-side JS uses on insert.

§Walk shape

Top-level entrypoint: render_stream_editor.

For each existing block in the stored JSON:

  1. Look up the crate::Block via the registry.
  2. Render its header (icon + verbose_name + reorder/remove buttons).
  3. Render its body — one wrapper per crate::BlockField:
    • Widget: build a one-off crate::Widget with name = "" so it doesn’t accidentally submit, then call the existing widgets::render(w) Tera macro.
    • Stream / Repeat: recurse.
    • Computed: render inline via the field’s render fn.

For each registered block type, render an empty-block clone into a <template data-block-template="X"> element — the JS clones these on insert so new blocks land with the right shape without an admin round-trip.

§Form submission

Every nested <input> / <select> / <textarea> is rendered with name="" so the browser skips it on submit per HTML5 § 4.10.18.3 (5.5). Only the single hidden <input> carrying the serialized JSON tree (name="{stream_name}") participates in the POST. The JS rewrites this hidden value on every input event.

Structs§

PickerOption
Picker option metadata stamped into the page-edit Tera context. The block-picker dialog reads from picker_options and filters by data-allowed at click time.

Functions§

picker_options
Build the picker-option list from the global registry. Stamped into Tera context as picker_options by page_edit_form.
render_stream_editor
Top-level entry: render the entire editor HTML for one WidgetKind::Stream widget.
render_stream_editor_with
render_stream_editor with a page-builder dyn-block overlay: UI-defined block types resolve through dyn_set before the inventory registry, so their entries + clone-templates render exactly like code blocks — stream_editor.js needs no changes.
render_widget_via_macro
Render a single widget by calling the existing widgets::render(w) Tera macro — same path the rest of the admin uses. We thread it through a one-shot inline template so we get the exact same HTML.
render_widget_via_macro_with
render_widget_via_macro with an explicit block picker. A Stream widget’s _widget.html arm reads picker_options from context to populate its block-picker dialog; the plain macro path leaves it empty. Page-builder flex zones / repeaters need their allowed dyn blocks in the picker so editors can add entries.