Caravela.Gen.SvelteForm (Caravela v0.9.2)

Copy Markdown View Source

Generates a dynamic Svelte form component from a module that declares use Caravela.Live.Form. The emitted component receives field_visibility and async_errors as props and wraps visibility- gated fields in {#if field_visibility.<name>} blocks.

Unlike Caravela.Gen.Svelte.render_component(domain, entity, :form), which emits a static <Entity>Form.svelte, this generator reads per-field visibility and async-validation metadata from the form module and emits <Entity>FormDynamic.svelte alongside it. The two coexist: plain-CRUD forms keep the static variant; forms using visible/validate_async use the dynamic one.

Caller supplies the compiled form module (with __caravela_form__/0) plus the owning Caravela.Schema.Domain — the domain provides the entity's field/type list, which drives input control selection and the TypeScript import path.

Caravela.Gen.SvelteForm.render(
  MyApp.BookFormDomain,
  MyApp.Domains.Library.__caravela_domain__()
)
#=> {"assets/svelte/library/BookFormDynamic.svelte", "<!-- ... -->"}

Returns {path, source}. Preserves content below <!-- --- CUSTOM --- --> when regenerating.

Summary

Functions

File path for the dynamic Svelte form component, relative to project root. Mirrors Caravela.Naming.svelte_file_path/3 but with the FormDynamic suffix.

Render the dynamic Svelte form. form_module must use Caravela.Live.Form; domain is the Caravela.Schema.Domain that owns the entity referenced by the form.

Functions

dynamic_file_path(domain, entity_name)

File path for the dynamic Svelte form component, relative to project root. Mirrors Caravela.Naming.svelte_file_path/3 but with the FormDynamic suffix.

render(form_module, domain, opts \\ [])

Render the dynamic Svelte form. form_module must use Caravela.Live.Form; domain is the Caravela.Schema.Domain that owns the entity referenced by the form.