Skip to content

toolmark-monorepo / @toolmark/core / createWizardTools

Function: createWizardTools() ​

createWizardTools(tm, opts): object

Defined in: packages/core/src/wizard/wizard-tools.ts:501

Registers the tools of a wizard whose data lives in the parent (spec §8.2, D25):

  • <name>.fill — { steps: { <step>: partial values }, overwrite? }. Each step is filled with the form-fill semantics of createFormTools (merge-based validation against the step schema, array ops, files, null clears, redaction, user-edited fields skipped unless overwrite). The current step is read from and written through currentAdapter() when it returns a form; otherwise it is written into parent data and resetCurrent(values) is called (with neither, the error event wizard_current_step_unsynced fires once). Other steps are written with one setData call. Any invalid step → invalid (paths <step>.<path>) and nothing is written; otherwise ok({ changes, skipped }) with <step>.<path> paths. Undoable: tm.undo(callId) restores every touched step, through the form of the step that is current at undo time, otherwise through setData.
  • <name>.goTo — { step } → goTo(step) → ok({ step }).
  • <name>.submit — consequential. Every step's full schema is validated first (the current step from its mounted form); any issue → invalid and no confirmation is created. A confirmation approved after the wizard's data changed is refused stale.
  • <name>.options — when any step declares options; field is <step>.<path>.

Tour hooks (spec §13): <name>.fill and <name>.submit expose state() → { values, issues, step } (values keyed by step — the current step from its mounted form, the others from getData() — with sensitive paths redacted; issues of the current step as <step>.<path>; step = getCurrent()) and sensitivePaths() (<step>.<path>: each step's sensitive plus every field seen sensitive while its step form was mounted, sticky after the step unmounts; declare sensitive for steps whose data exists before they are ever mounted). <name>.fill anchors resolve('<step>.<path>') to the field's element only while <step> is current (else null); both anchor to the current step's form. Interaction events of the current step's form are emitted as <name>.fill with param: '<step>.<path>' (submit → param: '<step>'); the wizard follows the current form when it is created and on every state/anchor read and fill.

Empty or duplicate step names → wizard_misconfigured (development: throws ToolmarkError; production: error event, nothing registered). Under SSR nothing is registered.

Parameters ​

tm ​

Toolmark

The registry.

opts ​

WizardToolOptions & object

Wizard options plus an optional target scope.

Returns ​

object

A handle whose dispose() removes the wizard's tools.

dispose() ​

dispose(): void

Returns ​

void