checkIntentCoverage
re-export| Package | @formscript/render |
|---|---|
| Specification | 4.25, 5.1, 7.13, 7.14, 8.1, 8.9, 12.6, 15.2, 15.3 |
| Depends on | ast, types |
@formscript/render
Render intents, per §15.2 and §15.3 of the specification.
FormScript emits intents, never markup (§15.2). This package computes the intent a renderer should present; the renderer maps it to a platform widget.
The fourteen intents
import { RENDER_INTENT_KINDS } from '@formscript/render';
RENDER_INTENT_KINDS; // ['RenderTextInput', 'RenderNumberInput', 'RenderChoice', …]
RenderTextInput, RenderNumberInput, RenderChoice, RenderMultiSelect,
RenderDate, RenderToggle, RenderFile, RenderSignature, RenderLocation,
RenderGroup, RenderRepeat, RenderProgress, RenderErrorSummary,
RenderMessage — the fourteen of §15.2, in the order the specification lists
them. RenderIntent is a discriminated union with one variant per intent, so
intent.intent === 'RenderChoice' narrows the payload.
Computing an intent
The intent is computed from the declaration alone. The input is a plain record: no expression, no evaluator, no locale, no clock.
import { computeRenderIntent } from '@formscript/render';
const intent = computeRenderIntent({
kind: 'field',
id: 'email',
name: 'email',
type: { kind: 'scalar', name: 'string' },
required: true,
readOnly: false,
derived: false,
overridable: false,
label: 'Email address',
});
intent?.intent; // 'RenderTextInput'
renderDeclarationFromBlock reads a parsed field, choice, group,
repeat, section or page block into that record. It resolves only what is
written down: a t("key") label needs a catalogue and a locale, and a dynamic
required needs an evaluation, so the host supplies both.
| Function | Purpose |
|---|---|
computeRenderIntent |
the intent to present; undefined when the entity is not rendered |
selectRenderIntent |
the widget the declaration selects, whatever its applicability |
renderSkipReason |
why no intent was produced: inapplicable, missing-type, options-type-conflict |
computeRenderIntents |
the intents of a set of declarations, in order |
renderDeclarationFromBlock |
reads a parsed block into a declaration |
renderTypeFromRef |
the presentation view of a type reference |
presentationPlane |
the presentation-plane properties of a declaration (§12.6) |
checkRenderObligations |
the statically checkable obligations of §15.3 |
checkIntentCoverage |
the unmapped-intent warning of Spec-15.2 |
errorSummaryIntent, messageIntent |
the two intents a document does not derive from a field |
The rules that select an intent
optionsoroptionsFrommakes a field a constrained selection, andRenderChoice(Spec-4.24, Spec-4.27).type = enum(…)makes a field a constrained selection, andRenderChoice.type = array(…)makes a field a multiple selection, andRenderMultiSelect; its options come from the element type when the element is anenum.- A
groupisRenderGroup, arepeatisRenderRepeat, apageisRenderProgress, achoiceisRenderChoice. - A derived field (
value = expr) is not editable unless it isoverridable(Spec-7.4, §8.9).
The two planes
label, hint, help, placeholder, unit, addLabel, removeLabel and
format are the presentation plane (§12.6). presentationPlane returns them;
the data plane never reads them, and this package never evaluates a value
expression, so an intent cannot depend on a presentation read. The analyzer
reports E-TYPE-08 when a display value reaches a data position; this
package does not report it again.
Judgement calls
The specification lists the fourteen intents but never says which declaration selects which. The rules above are the most literal reading; the choices that the text leaves open are recorded here.
section→RenderGroup. §15.2 has no section intent. §7.14 makes a section a presentation grouping that introduces no data level, so it renders as the labelled composite agrouprenders as.page→RenderProgress. The only page-level intent in §15.2 isRenderProgress("Page progress").duration→RenderTextInput. §15.2 has no duration intent. §5.1 listsdurationbesidedate, sodateanddatetimegiveRenderDateanddurationfalls back to the free-text widget.object→RenderGroup,any→RenderTextInput. §15.2 has no composite-value intent and no untyped intent.- A declared
optionslist wins over theenumtype's own options. §4.25 attaches labels to keys and does not say how the two sets combine; the analyzer reports a document whose two sets disagree. - A field with no
typeproduces no intent (Spec-7.6 makestyperequired) and a field whoseoptionsconflict with its type produces no intent (Spec-4.24). Neither is re-reported here: the analyzer owns those diagnostics. - An inapplicable entity produces no intent (Spec-8.3: it is not
rendered).
selectRenderIntentstill reports the widget it would use, so a renderer can keep the identity of a field that comes back. formatis treated as presentation-plane. §12.6 puts formatted numbers, dates and currency in the presentation plane, andformatis a display format (§8.1).- §15.3 is only partly checkable. A label for every control, a stable
identity and the placeholder prohibition are checkable from the intents and
are implemented by
checkRenderObligations. The focus and cursor obligations (Spec-15.4 bullets 4–5, Spec-15.5) are renderer behaviour; the stableidon every intent is what makes them achievable.
Ambiguities in the specification
- §15.2 does not say which properties select an intent, and it has no intent
for a
duration, anobjector ananyvalue. - §7.13 says a
choiceis semantically a field whose type isenum, but §8.1 giveschoiceatypeproperty of its own and Spec-4.27 lets a field withoptionsbe astring. This package therefore treats achoiceas a choice whatever its type, and reportsoptions-type-conflictonly for a field whose type may not carry a choice set. - §15.2 describes
RenderProgressas "Page progress" without saying whether it stands for the page or for a progress element inside it.
Public API
53 exported symbols.
checkRenderObligations
re-exportcomputeRenderIntent
re-exportcomputeRenderIntents
re-exporterrorSummaryIntent
re-exportErrorSummaryOptions
interfacefindRenderNode
function
The node a path names, or `undefined` when no node has it.
flattenRenderNodes
function
Every node of the tree, in document order.
messageIntent
re-exportMessageOptions
interfacePRESENTATION_PROPERTIES
const
The presentation-plane properties of §12.6.
presentationPlane
function
Extracts the presentation plane; the data plane never reads these (§12.6).
PresentationProperty
typeRENDER_INTENT_KINDS
re-exportRenderBound
interfaceRenderChoiceIntent
interfaceRenderDateIntent
interfaceRenderDeclaration
interface
Everything a renderer needs to choose a widget, resolved from the declaration alone.
renderDeclarationFromBlock
function
Reads a block into a declaration; only written-down values are resolved.
RenderDeclarationOptions
interfaceRenderEntityKind
type
The entity kinds that render (§7.1: a `state` declaration renders nothing).
RenderErrorEntry
interface
One failing field in the error summary of §13.4.
RenderErrorSummaryIntent
interfaceRenderFileIntent
interfacerenderFormTree
function
The form's entities, in document order, with the intent each one selects.
RenderFormTreeOptions
interfaceRenderGroupIntent
interfaceRenderIntent
typeRenderIntentCommon
interface
What every intent carries, whatever its widget.
RenderIntentIdentity
interfaceRenderIntentKind
typeRenderLocationIntent
interfaceRenderMember
interfaceRenderMessageIntent
interfaceRenderMessageLevel
typeRenderMultiSelectIntent
interfaceRenderNode
interface
One entity of the form, with the declaration and the intent it selects.
RenderNumberInputIntent
interfaceRenderObligation
interface
A renderer obligation that a set of intents does not satisfy.
RenderOption
interface
A choice option: the stored value and the label a person reads (Spec-4.25).
RenderOptionsSource
type
Where the choice set of a declaration comes from (Spec-4.25, Spec-4.26).
RenderPresentation
interface
The presentation plane of a declaration, as a person reads it (§12.6).
RenderProgressIntent
interfaceRenderRepeatIntent
interfaceRenderSignatureIntent
interfacerenderSkipReason
re-exportRenderSkipReason
type
Why a declaration produced no intent.
RenderTextInputIntent
interfaceRenderTextResolver
type
Resolves a presentation expression to the text a person reads.
RenderToggleIntent
interfaceRenderType
type
The presentation view of a type reference; it keeps the labels a person reads.
renderTypeFromRef
function
Converts a parsed type reference into the presentation view of a type.
selectRenderIntent
re-export