RazorWire JavaScript API
RazorWire JavaScript API
Public JavaScript contracts harvested from documented source comments.
window.RazorWire
SourceBrowser global that exposes RazorWire runtime managers and runtime configuration for diagnostics and advanced integrations.
window.RazorWirewindow.RazorWireIslandModules
SourceOptional island module manifest that maps logical `data-rw-module` names to host-provided module specifiers before RazorWire imports them.
window.RazorWireIslandModules- Type: {Record<string, string>}
- Source: host page script or bundled app script
Properties
moduleNamestring - Logical island module name keyed by the value rendered in `data-rw-module`.
window.RazorWire.config
SourceRuntime configuration merged from the `<rw:scripts />` script tag.
window.RazorWire.config- Type: {object}
- Source: <rw:scripts />
Properties
developmentDiagnosticsboolean - Whether development diagnostics can be exposed.failureUxEnabledboolean - Whether failed-form request markers, events, fallback rendering, and diagnostics are enabled.failureMode"auto"|"manual"|"off" - Default failed-form behavior.defaultFailureMessagestring - Reader-facing fallback copy for unhandled form failures.
RazorWireBehaviorDefinition
SourceBehavior definition registered with the RazorWire Behavior Kit.
RazorWireBehaviorDefinitionProperties
namestring - Stable behavior name. Names are immutable for the page lifetime; repeated registrations with the same selector are idempotent.selectorstring - CSS selector for roots that should receive one connected behavior controller.connectFunction - Callback invoked once per matching connected root. It receives `(root, context)` and may return a cleanup function.
RazorWireLifecycleDefinition
SourcePage-lifecycle definition registered with the RazorWire Behavior Kit.
RazorWireLifecycleDefinitionProperties
namestring - Stable lifecycle behavior name. Names are immutable for the page lifetime; repeated registrations with the same lifecycle options are idempotent.[events]Array<"initial"|"turbo:load"|"turbo:render"> - Logical page lifecycle events that should run the behavior. Defaults to `["initial", "turbo:load"]`.[frames]boolean - Set to `true` to run on `turbo:frame-load`; frame loads are ignored by default.connectFunction - Callback invoked for each matching lifecycle pass. It receives `context` and may return a cleanup function.
RazorWireBehaviorDiagnostic
SourceDiagnostic emitted by the RazorWire Behavior Kit.
RazorWireBehaviorDiagnosticProperties
codeRazorWireBehaviorDiagnosticCode - Stable diagnostic code.Type preview: RazorWireBehaviorDiagnosticCode - Stable Behavior Kit diagnostic codes.
messagestring - Required problem statement for the invalid registration or lifecycle failure.impactstring - Required explanation of the behavior RazorWire skipped, changed, or could not guarantee.fixstring - Required remediation guidance suitable for docs, tests, and development diagnostics.docsstring - Required repository documentation path for troubleshooting guidance.[behaviorName]string - Behavior name associated with the diagnostic when available.[rootId]string - Runtime-generated behavior/root identity when available.
window.RazorWire.behaviors
SourceBehavior Kit manager for app-authored progressive enhancement on replaceable server-rendered DOM and logical browser visits.
window.RazorWire.behaviors- Type: {object}
- Source: <rw:scripts behavior-kit="true" />
Properties
registerFunction - Registers a root-scoped behavior definition with `name`, `selector`, and `connect(root, context)`.registerLifecycleFunction - Registers a page-lifecycle behavior definition with `name`, optional `events`, optional `frames`, and `connect(context)`.scanFunction - Re-scans the document or supplied root for registered behavior selectors.pruneFunction - Disconnects controllers whose roots left the document or no longer match their selector.getDiagnosticsFunction - Returns stable Behavior Kit diagnostics recorded since startup.clearDiagnosticsFunction - Clears recorded Behavior Kit diagnostics.
RazorWireBehaviorContext
SourceRoot-scoped Behavior Kit context passed to `window.RazorWire.behaviors.register(...).connect`.
RazorWireBehaviorContextProperties
signalAbortSignal - Signal aborted before cleanup when RazorWire disconnects the root.behaviorNamestring - Registered behavior name.rootIdstring - Stable runtime identity for the current behavior/root pair.queryFunction - Scoped `querySelector` helper rooted at the connected element.queryAllFunction - Scoped `querySelectorAll` helper rooted at the connected element.diagnosticFunction - Records an app-owned behavior diagnostic with a message and fix.
RazorWireLifecycleContext
SourcePage-lifecycle Behavior Kit context passed to `window.RazorWire.behaviors.registerLifecycle(...).connect`.
RazorWireLifecycleContextProperties
signalAbortSignal - Signal aborted before cleanup when the lifecycle behavior reconnects on a later pass.behaviorNamestring - Registered lifecycle behavior name.urlstring - Current browser URL for the lifecycle pass.renderKind"initial"|"turbo:load"|"turbo:render"|"turbo:frame-load" - Logical render lifecycle that triggered the pass.rootDocument|Element - Document or frame element that owns the lifecycle pass.diagnosticFunction - Records an app-owned lifecycle diagnostic with a message and fix.
RazorWireBehaviorDiagnosticCode
SourceStable Behavior Kit diagnostic codes.
RazorWireBehaviorDiagnosticCodewindow.RazorWire.sectionCopyManager
SourceSection copy manager for framework-neutral section permalink buttons, generated copy controls, clipboard fallback UI, and lifecycle-safe rebinding.
window.RazorWire.sectionCopyManager- Type: {object}
- Source: <rw:scripts /> with rendered `[data-rw-section-copy]` or `[data-rw-section-copy-target]` markup
Properties
scanFunction - Re-scans the document for section-copy roots and markers after custom DOM updates.pruneFunction - Removes controllers for disconnected roots.getDiagnosticsFunction - Returns an array of stable section-copy diagnostic objects recorded since startup.getDiagnostics[].messagestring - Required reader-facing problem statement for the invalid marker or runtime state.getDiagnostics[].impactstring - Required explanation of the behavior RazorWire skipped, changed, or could not guarantee.getDiagnostics[].fixstring - Required remediation guidance suitable for docs, tests, and development diagnostics.getDiagnostics[].docsstring - Required repository documentation path for the related troubleshooting guidance.clearDiagnosticsFunction - Clears recorded section copy diagnostics.
razorwire:form:submit-start
SourceA RazorWire-enhanced form started submitting through Turbo.
razorwire:form:submit-start- Target: form[data-rw-form="true"]
- Fires when: Turbo begins submitting a RazorWire-enhanced form and RazorWire marks it busy.
- Bubbles: true
- Cancelable: false
Detail fields
detail.formHTMLFormElement - Submitted form.detail.submitterHTMLElement|null - Button or submit control that initiated the submission.
FormFailureDetail
SourceFailure payload passed through event.detail for a failed RazorWire-enhanced form submission.
FormFailureDetailProperties
formHTMLFormElement - Submitted form.submitterHTMLElement|null - Button or submit control that initiated the submission.statusCodenumber|null - HTTP status code when available.handledboolean - Whether the server response already handled the failure.responseKind"turbo-stream"|"html"|"json"|"unknown"|"network" - Failure category.targetElement - Stream target or form that should own the failure UI.messagestring - Reader-facing fallback message.developmentDiagnosticObject|null - Development diagnostic payload when enabled.
razorwire:form:failure
SourceA RazorWire-enhanced form submission failed and custom UI may handle the failure.
razorwire:form:failure- Target: form[data-rw-form="true"]
- Fires when: Turbo reports a failed form submission or RazorWire catches a network failure.
- Bubbles: true
- Cancelable: true
Detail fields
detailFormFailureDetail - Failure payload.Type preview: FormFailureDetail - Failure payload passed through event.detail for a failed RazorWire-enhanced form submission.
formHTMLFormElement - Submitted form.submitterHTMLElement|null - Button or submit control that initiated the submission.statusCodenumber|null - HTTP status code when available.handledboolean - Whether the server response already handled the failure.responseKind"turbo-stream"|"html"|"json"|"unknown"|"network" - Failure category.- View full FormFailureDetail contract
detail.formHTMLFormElement - Submitted form.detail.submitterHTMLElement|null - Button or submit control that initiated the submission.detail.statusCodenumber|null - HTTP status code when available.detail.handledboolean - Whether the server response already handled the failure.detail.responseKind"turbo-stream"|"html"|"json"|"unknown"|"network" - Failure category.detail.targetElement - Stream target or form that should own the failure UI.detail.messagestring - Reader-facing fallback message.detail.developmentDiagnosticObject|null - Development diagnostic payload when enabled.
razorwire:form:diagnostic
SourceDevelopment diagnostics are available for a failed RazorWire-enhanced form submission.
razorwire:form:diagnostic- Target: form[data-rw-form="true"]
- Fires when: development diagnostics are enabled for a failed RazorWire-enhanced form.
- Bubbles: true
- Cancelable: false
Detail fields
detail.formHTMLFormElement - Submitted form.detail.statusCodenumber|null - HTTP status code when available.detail.titlestring - Short diagnostic title.detail.detailstring - Diagnostic explanation.detail.docsHrefstring - Documentation link target.detail.hintsstring[] - Suggested fixes.
razorwire:form:submit-end
SourceA RazorWire-enhanced form finished submitting.
razorwire:form:submit-end- Target: form[data-rw-form="true"]
- Fires when: Turbo finishes a RazorWire-enhanced form submission or RazorWire handles a fetch error.
- Bubbles: true
- Cancelable: false
Detail fields
detail.formHTMLFormElement - Submitted form.detail.submitterHTMLElement|null - Button or submit control that initiated the submission.detail.successboolean - Whether the submission succeeded.detail.statusCodenumber|null - HTTP status code when available.detail.handledboolean - Whether the server response already handled the result.
razorwire:stream:error
SourceA RazorWire stream source reported a native EventSource error.
razorwire:stream:error- Target: rw-stream-source
- Fires when: The browser reports an EventSource error for a registered RazorWire stream source. Native EventSource does not expose HTTP status codes or response bodies to application JavaScript, so use server logs and the Network tab for exact rejection reasons.
- Bubbles: true
- Cancelable: false
Detail fields
detail.channelstring|null - Client-derived channel token for the stream source.detail.sourceElement - Stream source element that observed the error.detail.state"connecting"|"connected"|"disconnected"|string - Last RazorWire stream state before the error callback.detail.readyStatenumber - Native EventSource readyState value.detail.srcstring - Stream source URL.
data-rw-form
SourceEnables RazorWire form failure handling on a form.
data-rw-form- Target: form
- Type: {"true"}
data-rw-section-copy-root
SourceMarks an optional root that scopes section-copy status, generated buttons, feedback timers, and cleanup.
data-rw-section-copy-root- Target: section, article, main, div
- Type: {"true"}
data-rw-section-copy
SourceMarks a button that copies a section permalink for the referenced target id.
data-rw-section-copy- Target: button
- Type: {string}
data-rw-section-copy-title
SourceProvides reader-facing section title copy for `aria-label`, live status, and fallback dialog labels.
data-rw-section-copy-title- Target: button[data-rw-section-copy], [data-rw-section-copy-target]
- Type: {string}
data-rw-section-copy-status
SourceMarks an optional live status region for section-copy feedback.
data-rw-section-copy-status- Target: span, div
- Type: {"true"}
data-rw-section-copy-target
SourceMarks a heading or section container that should receive a generated plain-text copy button.
data-rw-section-copy-target- Target: h1, h2, h3, h4, h5, h6, header, section, div
- Type: {"true"}
scroll-padding-block
SourceLogical CSS inset contract for active page navigation reveal inside overflowing vertical nav surfaces.
scroll-padding-block- Target: visible vertical scrollable ancestor between `a[data-rw-page-nav-link]` and `[data-rw-page-nav]`
- Hook kind: css-property
- Stability: stable
scroll-padding-top
SourceStart-side CSS inset contract for active page navigation reveal inside overflowing vertical nav surfaces.
scroll-padding-top- Target: visible vertical scrollable ancestor between `a[data-rw-page-nav-link]` and `[data-rw-page-nav]`
- Hook kind: css-property
- Stability: stable
scroll-padding-bottom
SourceEnd-side CSS inset contract for active page navigation reveal inside overflowing vertical nav surfaces.
scroll-padding-bottom- Target: visible vertical scrollable ancestor between `a[data-rw-page-nav-link]` and `[data-rw-page-nav]`
- Hook kind: css-property
- Stability: stable
[data-rw-section-copy-enhanced="true"]
SourceStable selector for roots enhanced by the section-copy runtime.
[data-rw-section-copy-enhanced="true"]- Target: [data-rw-section-copy-root], body
- Hook kind: data-attribute
- Stability: stable
[data-rw-section-copy-inserted="true"]
SourceStable selector for generated section-copy buttons.
[data-rw-section-copy-inserted="true"]- Target: button[data-rw-section-copy]
- Hook kind: data-attribute
- Stability: stable
[data-rw-section-copy-state="copied|fallback"]
SourceStable selector for transient copy feedback state.
[data-rw-section-copy-state="copied|fallback"]- Target: button[data-rw-section-copy]
- Hook kind: data-attribute
- Stability: stable
[data-rw-section-copy-message]
SourceStable selector for generated section-copy feedback text attached to a button.
[data-rw-section-copy-message]- Target: button[data-rw-section-copy]
- Hook kind: data-attribute
- Stability: stable
[data-rw-section-copy-fallback="true"]
SourceStable selector for runtime-generated section-copy clipboard fallback UI.
[data-rw-section-copy-fallback="true"]- Target: generated fallback dialog
- Hook kind: data-attribute
- Stability: stable
[data-rw-section-copy-status-generated="true"]
SourceStable selector for runtime-generated section-copy status regions.
[data-rw-section-copy-status-generated="true"]- Target: generated status region
- Hook kind: data-attribute
- Stability: stable
data-rw-form-failure
SourceSelects how RazorWire renders unhandled form failures.
data-rw-form-failure- Target: form[data-rw-form="true"]
- Type: {"auto"|"manual"|"off"}
- Default: auto
[data-rw-form-error-generated="true"]
SourceStable selector for generated form failure UI.
[data-rw-form-error-generated="true"]- Target: generated form failure UI
- Hook kind: data-attribute
- Stability: stable
--rw-form-error-text
SourceControls generated form failure text color.
--rw-form-error-text- Target: [data-rw-form-error-generated="true"]
- Default: #3f3f46
- Syntax: <color>
mount
SourceIsland modules may export mount to hydrate a server-rendered root.
mount(root, props)- Target: module referenced by data-rw-module
- Signature: mount(root, props)
Parameters
rootHTMLElement - Island root element.propsRecord<string, unknown> - Parsed island props.
data-rw-module
SourceNames the browser module that should hydrate an island root.
data-rw-module- Target: [data-rw-module]
- Type: {string}
window.RazorWire.formInteractionsManager
SourceForm interactions manager for conditional form targets and one-dimensional model-bound collection mechanics.
window.RazorWire.formInteractionsManager- Type: {object}
- Source: <rw:scripts /> with rendered `[data-rw-form-toggle]` or `[data-rw-form-collection]` markup
Properties
scanFunction - Re-scans the document for forms containing form-interaction markers after custom DOM updates.pruneFunction - Removes controllers for disconnected forms.getDiagnosticsFunction - Returns stable form-interaction diagnostic objects recorded since startup.getDiagnostics[].messagestring - Required problem statement for invalid form-interaction markup.getDiagnostics[].impactstring - Required explanation of skipped behavior or submit-semantics risk.getDiagnostics[].fixstring - Required remediation guidance.getDiagnostics[].docsstring - Required repository documentation path for troubleshooting.clearDiagnosticsFunction - Clears recorded diagnostics.
razorwire:form-toggle:before-change
SourceA conditional form toggle is about to reveal or hide its targets.
razorwire:form-toggle:before-change- Target: [data-rw-form-toggle]
- Fires when: A form toggle value changes and RazorWire has resolved the same-form targets that may be shown or hidden.
- Bubbles: true
- Cancelable: true
Detail fields
detail.formHTMLFormElement - Owning form.detail.controlHTMLElement - Toggle control.detail.targetHTMLElement - First matched target.detail.visibleboolean - Whether targets will be shown.
razorwire:form-toggle:change
SourceA conditional form toggle finished revealing or hiding its targets.
razorwire:form-toggle:change- Target: [data-rw-form-toggle]
- Fires when: RazorWire finishes applying visibility, state hooks, and optional disabled state for a conditional form target.
- Bubbles: true
- Cancelable: false
Detail fields
detail.formHTMLFormElement - Owning form.detail.controlHTMLElement - Toggle control.detail.targetHTMLElement - First matched target.detail.visibleboolean - Whether targets are shown.
razorwire:form-collection:before-add
SourceA model-bound collection command is about to add a row.
razorwire:form-collection:before-add- Target: [data-rw-form-collection-add]
- Fires when: An add command has cloned the app-authored template and allocated a sparse collection index, before insertion.
- Bubbles: true
- Cancelable: true
Detail fields
detail.formHTMLFormElement - Owning form.detail.rootHTMLElement - Collection root.detail.controlHTMLElement - Command button.detail.rowHTMLElement - Row that will be inserted.detail.indexstring - New sparse model-binding index.detail.action"add" - Collection action.
razorwire:form-collection:add
SourceA model-bound collection command added a row.
razorwire:form-collection:add- Target: [data-rw-form-collection-add]
- Fires when: RazorWire inserts a new collection row and enables its hidden `.index` marker.
- Bubbles: true
- Cancelable: false
Detail fields
detail.formHTMLFormElement - Owning form.detail.rootHTMLElement - Collection root.detail.controlHTMLElement - Command button.detail.rowHTMLElement - Inserted row.detail.indexstring - New sparse model-binding index.detail.action"add" - Collection action.
razorwire:form-collection:before-duplicate
SourceA model-bound collection command is about to duplicate a row.
razorwire:form-collection:before-duplicate- Target: [data-rw-form-collection-duplicate]
- Fires when: A duplicate command has cloned the source row, rewritten index tokens, and prepared copyable user values before insertion.
- Bubbles: true
- Cancelable: true
Detail fields
detail.formHTMLFormElement - Owning form.detail.rootHTMLElement - Collection root.detail.controlHTMLElement - Command button.detail.rowHTMLElement - Cloned row that will be inserted.detail.previousIndexstring|null - Source row index.detail.indexstring - New sparse model-binding index.detail.action"duplicate" - Collection action.
razorwire:form-collection:duplicate
SourceA model-bound collection command duplicated a row.
razorwire:form-collection:duplicate- Target: [data-rw-form-collection-duplicate]
- Fires when: RazorWire inserts a duplicated collection row with a new sparse model-binding index.
- Bubbles: true
- Cancelable: false
Detail fields
detail.formHTMLFormElement - Owning form.detail.rootHTMLElement - Collection root.detail.controlHTMLElement - Command button.detail.rowHTMLElement - Inserted clone.detail.previousIndexstring|null - Source row index.detail.indexstring - New sparse model-binding index.detail.action"duplicate" - Collection action.
razorwire:form-collection:before-remove
SourceA model-bound collection command is about to remove or mark a row.
razorwire:form-collection:before-remove- Target: [data-rw-form-collection-remove]
- Fires when: A remove command resolves its physical-remove or mark-remove mode, before RazorWire mutates the row.
- Bubbles: true
- Cancelable: true
Detail fields
detail.formHTMLFormElement - Owning form.detail.rootHTMLElement - Collection root.detail.controlHTMLElement - Command button.detail.rowHTMLElement - Row that will be removed or marked.detail.action"physical-remove"|"mark-remove" - Remove action.detail.removeMode"physical"|"mark" - Remove mode.detail.indexstring - Existing model-binding index.
razorwire:form-collection:remove
SourceA model-bound collection command removed or marked a row.
razorwire:form-collection:remove- Target: [data-rw-form-collection-remove]
- Fires when: RazorWire finishes physically removing a row or marking it for app-owned deletion.
- Bubbles: true
- Cancelable: false
Detail fields
detail.formHTMLFormElement - Owning form.detail.rootHTMLElement - Collection root.detail.controlHTMLElement - Command button.detail.rowHTMLElement - Row that was removed or marked.detail.action"physical-remove"|"mark-remove" - Remove action.detail.removeMode"physical"|"mark" - Remove mode.detail.indexstring - Existing model-binding index.
data-rw-form-toggle
SourceMarks a control that reveals or hides conditional form targets inside the same form.
data-rw-form-toggle- Target: input, select, textarea, button
- Type: {string}
data-rw-form-toggle-target
SourceMarks an app-authored target revealed or hidden by a matching form toggle.
data-rw-form-toggle-target- Target: fieldset, section, div
- Type: {string}
data-rw-form-collection
SourceMarks a one-dimensional ASP.NET Core model-bound collection root.
data-rw-form-collection- Target: div, section, fieldset
- Type: {string}
data-rw-form-collection-row
SourceMarks an app-authored collection row.
data-rw-form-collection-row- Target: fieldset, div, tr
- Type: {"true"}
data-rw-form-collection-template
SourceMarks the app-authored row template that contains the `__index__` token.
data-rw-form-collection-template- Target: template
- Type: {"true"}
data-rw-form-collection-add
SourceMarks a button that adds a row from the collection template.
data-rw-form-collection-add- Target: button
- Type: {"true"}
data-rw-form-collection-duplicate
SourceMarks a button that duplicates the nearest collection row.
data-rw-form-collection-duplicate- Target: button
- Type: {"true"}
data-rw-form-collection-remove
SourceMarks a button that physically removes or marks the nearest collection row.
data-rw-form-collection-remove- Target: button
- Type: {"physical"|"mark"|"true"}
[data-rw-form-interactions-enhanced="true"]
SourceStable selector for forms enhanced by the form-interactions runtime.
[data-rw-form-interactions-enhanced="true"]- Target: form
- Hook kind: data-attribute
- Stability: stable
data-rw-strategy
SourceSelects when an island module hydrates.
data-rw-strategy- Target: [data-rw-module]
- Type: {"load"|"idle"|"visible"|"only"}
- Default: load
data-rw-props
SourceJSON props passed to an island module's mount function.
data-rw-props- Target: [data-rw-module]
- Type: {string}