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,nullclears, redaction, user-edited fields skipped unlessoverwrite). The current step is read from and written throughcurrentAdapter()when it returns a form; otherwise it is written into parent data andresetCurrent(values)is called (with neither, theerroreventwizard_current_step_unsyncedfires once). Other steps are written with onesetDatacall. Any invalid step →invalid(paths<step>.<path>) and nothing is written; otherwiseok({ 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 throughsetData.<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 →invalidand no confirmation is created. A confirmation approved after the wizard's data changed is refusedstale.<name>.options— when any step declaresoptions;fieldis<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
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