foldkit-mixins-form 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +118 -12
- package/dist/index.d.mts +184 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +194 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -105,6 +105,8 @@ EditForm.view(model, h, {
|
|
|
105
105
|
|
|
106
106
|
- `FormView.define(Edit)` alone is a complete, unstyled form. `field` is only
|
|
107
107
|
for changing how fields are drawn.
|
|
108
|
+
- `submits: false` draws the form without its submit button, for someone who
|
|
109
|
+
may not submit it (a writer, where the submit publishes).
|
|
108
110
|
- `options` is keyed by the form's keys and is where a relation picker's choices
|
|
109
111
|
come from. The form names the target Entity; listing it is a query you make,
|
|
110
112
|
so the choices are yours to load, filter, and label.
|
|
@@ -118,17 +120,23 @@ EditForm.view(model, h, {
|
|
|
118
120
|
| `Multiline` | `textarea` | `multiline` |
|
|
119
121
|
| `Number` | `input type="text" inputmode="decimal"` | `number` |
|
|
120
122
|
| `Toggle` | `input type="checkbox"` | `toggle` |
|
|
121
|
-
| `Select` | `select` of the control's own options, with a blank while nothing is chosen | `select` |
|
|
122
|
-
| `RelationOne` | `select` of `options[key]`, with a blank | `select` |
|
|
123
|
-
| `RelationMany` | a `role="group"` of checkboxes over `options[key]` | `choices`, `choice` |
|
|
123
|
+
| `Select` | `select` of the control's own options, with a blank while nothing is chosen | `select`, `option` |
|
|
124
|
+
| `RelationOne` | `select` of `options[key]`, with a blank | `select`, `option` |
|
|
125
|
+
| `RelationMany` | a `role="group"` of checkboxes over `options[key]`, each in a `label` with its words | `choices`, `choiceLabel`, `choice` |
|
|
124
126
|
| `Nested` | a `fieldset` with a `legend`, a `div` per row holding the nested form's fields, and `button type="button"`s to add and remove a row | `group`, `legend`, `row`, `add`, `remove` |
|
|
125
127
|
|
|
126
128
|
A `RelationOne` or `RelationMany` that searches (`Input.search()`) gets an
|
|
127
129
|
`input type="search"` above it, in the `search` slot, labelled `Search <label>`
|
|
128
130
|
and naming the picker it controls with `aria-controls`. `words.search` in the
|
|
129
|
-
view inputs replaces the word.
|
|
130
|
-
|
|
131
|
-
|
|
131
|
+
view inputs replaces the word. The blank choice of a `select` has no words
|
|
132
|
+
unless `words.none` gives it some ("none"). All of the view's words (`submit`,
|
|
133
|
+
`submitting`, `checking`, `search`, `none`, `add`, `remove`) are text, with `{label}` and `{position}` as
|
|
134
|
+
blanks; see [words in one place](../form/README.md#words-as-text-in-one-place).
|
|
135
|
+
|
|
136
|
+
A chosen value its choices lack stays in sight: after the choices comes
|
|
137
|
+
`? value`, chosen, in a `select` and in a `RelationMany`'s checkboxes. It is a
|
|
138
|
+
stored id whose row is gone, or one the application has not loaded yet, and
|
|
139
|
+
the author can see it and let it go.
|
|
132
140
|
|
|
133
141
|
### Renderers
|
|
134
142
|
|
|
@@ -157,13 +165,70 @@ attributes, to put on the element that holds the value. A control whose kind has
|
|
|
157
165
|
no renderer throws when it is drawn, naming the kind and the key.
|
|
158
166
|
`FormView.field(form, { renderers })` takes them too, for a field view you style.
|
|
159
167
|
|
|
168
|
+
### Per-key overrides: `fields`
|
|
169
|
+
|
|
170
|
+
`FormView.fields` is `define` with per-key overrides, and one flat key's
|
|
171
|
+
control for a layout the caller owns:
|
|
172
|
+
|
|
173
|
+
```ts
|
|
174
|
+
const Fields = FormView.fields(PriceForm, {
|
|
175
|
+
overrides: {
|
|
176
|
+
// Drawn through the whole-form view, in the form's own universe.
|
|
177
|
+
code: (input, h) => h.input([h.Id(input.id), h.Value(String(input.field.value))]),
|
|
178
|
+
},
|
|
179
|
+
styles: {
|
|
180
|
+
// A style around one key's base field view.
|
|
181
|
+
total: Style.forSlots(FieldSlots)({ root: Style.class('total') }),
|
|
182
|
+
},
|
|
183
|
+
attrs: {
|
|
184
|
+
// What one key's element takes: an email type, a placeholder, textarea rows.
|
|
185
|
+
email: { type: 'email' },
|
|
186
|
+
},
|
|
187
|
+
})
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Keys with no override render through the base field view, so a new key of a
|
|
191
|
+
known kind needs nothing new; unknown keys in every map are type errors.
|
|
192
|
+
`Fields.view` is the whole form. `Fields.field(control, model, id, h)` draws
|
|
193
|
+
one flat key for a custom layout, or with the override it is given, in any `h`:
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
Fields.field(control, formModel, control.key, h, (input, draw) =>
|
|
197
|
+
draw.input([draw.Id(input.id), draw.Value(String(input.field.value))]),
|
|
198
|
+
)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
A override receives the control, its field, id, validity, errors, element
|
|
202
|
+
attrs, and the `changed`/`blurred` Messages, so a custom layout reconstructs
|
|
203
|
+
no form plumbing. A renderer reads the attrs that fit its element — `type` and
|
|
204
|
+
`placeholder` on a text input, `placeholder` and `rows` on a textarea — and
|
|
205
|
+
ignores the rest. Nested keys and Bundle-backed keys draw only through `view`
|
|
206
|
+
(or a override); `field` without one refuses them, naming the key.
|
|
207
|
+
|
|
160
208
|
A number is a text input because its draft is text: `"4."` is a fine thing to
|
|
161
209
|
have typed, and `type="number"` would refuse to report it.
|
|
162
210
|
|
|
211
|
+
A control backed by a Bundle ([`Input.bundle`](../form/README.md#a-control-with-a-model-of-its-own))
|
|
212
|
+
is drawn with the Bundle's own view when no renderer names its kind, inside the
|
|
213
|
+
field's `control` slot, which carries the control's id and accessibility state.
|
|
214
|
+
A renderer for its kind receives `bundle`: the Bundle's Model, and `send`, which
|
|
215
|
+
turns one of the Bundle's Messages into the form's (wrapped for its row inside a
|
|
216
|
+
nested form). Such a key has no draft, so `draft` and `input.field.value` are
|
|
217
|
+
`''`; its validation state is `input.field`'s. A Bundle with no view needs a
|
|
218
|
+
renderer.
|
|
219
|
+
|
|
163
220
|
Around each control, `FieldSlots` also publishes `root`, `label`, `description`,
|
|
164
|
-
|
|
221
|
+
`checking`, `error`, `control` (around a Bundle's own view), and `group` and `affix`, for a
|
|
222
|
+
renderer that draws text beside its control (a prefix, a unit) with the two
|
|
223
|
+
together. `FormSlots` publishes `root` (the `form`), `errors` (failures that
|
|
165
224
|
belong to no one field), `submit`, and the five slots of a nested key.
|
|
166
225
|
|
|
226
|
+
A Bundle's own view that takes inputs gets them from the view input
|
|
227
|
+
`controls`, by key: `placed.view(model, h, { controls: { document: inputs } })`.
|
|
228
|
+
The entry is the application's, typed where it is made, such as the page
|
|
229
|
+
Builder's `BuilderView.inputs({ data })`; a key given none draws its view
|
|
230
|
+
without inputs.
|
|
231
|
+
|
|
167
232
|
A nested row's fields are drawn through the same field view, so a styled `field`
|
|
168
233
|
styles them too. A row that must be there has no remove button, and a `one`
|
|
169
234
|
loses its add button once it has its row. View inputs for nested keys:
|
|
@@ -171,13 +236,54 @@ loses its add button once it has its row. View inputs for nested keys:
|
|
|
171
236
|
same for every row), and `words.add` / `words.remove` word the buttons (defaults
|
|
172
237
|
`Add <label>`, `Remove <label> <position>`).
|
|
173
238
|
|
|
239
|
+
### A check running, and a submit in flight
|
|
240
|
+
|
|
241
|
+
A form's own check ([`checks`](../form/README.md)) leaves its key `Validating`
|
|
242
|
+
until it answers. Meanwhile the control carries `aria-busy`, and under it a line
|
|
243
|
+
in the `checking` slot, `role="status"`, says so (`words.checking`, default
|
|
244
|
+
`Checking…`); the control names that line in `aria-describedby`. Each field's
|
|
245
|
+
`root` carries `data-validation`, the field's state by Foldkit's own tag
|
|
246
|
+
(`NotValidated`, `Validating`, `Valid` or `Invalid`), so a stylesheet can mark it
|
|
247
|
+
without a Style: `[data-validation='Valid'] label::after { content: ' ✓' }`. A
|
|
248
|
+
Style reads the same state as `input.field` through `Style.whenInput`.
|
|
249
|
+
|
|
250
|
+
The form is submitting while a submit waits for a check to pass (the form's
|
|
251
|
+
`submitPending`), or while the application says its own work with the value is
|
|
252
|
+
in flight: the view input `submitting`. The form hands the value over through
|
|
253
|
+
`onOut` and cannot see the request that follows, so that part is the
|
|
254
|
+
application's to pass. While submitting, the `form` carries `aria-busy` and
|
|
255
|
+
`data-submitting`, and the submit button is disabled and reads
|
|
256
|
+
`words.submitting` (default `Submitting…`). Where `saving` is the parent's own
|
|
257
|
+
record of a save in flight:
|
|
258
|
+
|
|
259
|
+
```ts
|
|
260
|
+
EditForm.view(model, h, {
|
|
261
|
+
submitting: model.saving,
|
|
262
|
+
words: { submit: 'Save', submitting: 'Saving…', checking: 'Checking…' },
|
|
263
|
+
})
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
The submit button is enabled while a check runs and nothing is invalid: a submit
|
|
267
|
+
then waits for the answer, rather than being refused. That leniency is
|
|
268
|
+
`form.canSubmit`, and `FormView.submodel` takes the predicate explicitly so
|
|
269
|
+
the choice stays visible: pass a strict one to disable through checks, or
|
|
270
|
+
`() => true` to never pre-disable and validate wholly at submit.
|
|
271
|
+
|
|
272
|
+
```ts
|
|
273
|
+
const Drawn = Edit.bundle.pipe(
|
|
274
|
+
Bundle.withView(FormView.submodel(Edit, View, { canSubmit: () => true })),
|
|
275
|
+
)
|
|
276
|
+
```
|
|
277
|
+
|
|
174
278
|
### Accessibility
|
|
175
279
|
|
|
176
280
|
Each control has an `id` of `<form name>-<key>` (in a row,
|
|
177
281
|
`<form name>-<key>-<row id>-<key>`) and a `label for` it. It carries
|
|
178
|
-
`aria-busy` while a check runs, `aria-invalid`, `aria-required` when the key is
|
|
179
|
-
|
|
180
|
-
|
|
282
|
+
`aria-busy` while a check runs, `aria-invalid`, `aria-required` when the key is
|
|
283
|
+
required, and `aria-describedby` naming its description, the `checking` line
|
|
284
|
+
while a check runs, and its error while invalid. An error is `role="alert"`.
|
|
285
|
+
The submit button is disabled until the form would submit, and while it is
|
|
286
|
+
submitting.
|
|
181
287
|
|
|
182
288
|
Those attributes belong to the view: an attachment that also supplies one is an
|
|
183
289
|
attribute conflict, reported when the view renders. The slots declare
|
|
@@ -185,8 +291,8 @@ attribute conflict, reported when the view renders. The slots declare
|
|
|
185
291
|
|
|
186
292
|
## Limits
|
|
187
293
|
|
|
188
|
-
- One layout: label, control, description, error, in that
|
|
189
|
-
the input's order. For another arrangement, draw from `form.controls`
|
|
294
|
+
- One layout: label, control, description, the checking line, error, in that
|
|
295
|
+
order, and fields in the input's order. For another arrangement, draw from `form.controls`
|
|
190
296
|
yourself; this package is the default, not the only way.
|
|
191
297
|
- A relation picker is a `select`, or checkboxes for a `many`. With
|
|
192
298
|
`Input.search()` it searches, but it is not a combobox: the choices are the
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Control, Draft, FormControl, FormRow } from "foldkit-form";
|
|
2
|
-
import { Attr, Capability, Event, Slot, SlotBuilders, SlotView, Slots } from "foldkit-mixins";
|
|
2
|
+
import { Attr, Capability, Event, NamedStyle, Slot, SlotBuilders, SlotView, Slots } from "foldkit-mixins";
|
|
3
3
|
import * as FieldValidation from "foldkit/fieldValidation";
|
|
4
4
|
import * as Submodel from "foldkit/submodel";
|
|
5
5
|
import { Attribute, Html, HtmlBuilder } from "foldkit/html";
|
|
@@ -21,10 +21,16 @@ export interface FormViewWords {
|
|
|
21
21
|
readonly submit?: string | undefined;
|
|
22
22
|
/** Before the label on a picker's search box (`Search Author`). Default `Search`. */
|
|
23
23
|
readonly search?: string | undefined;
|
|
24
|
+
/** The choice of nothing, in a picker that may be left empty. Default: blank. */
|
|
25
|
+
readonly none?: string | undefined;
|
|
24
26
|
/** On the button that adds a row to a nested key. Default `Add {label}`. */
|
|
25
27
|
readonly add?: string | undefined;
|
|
26
28
|
/** On the button that removes a row; `{position}` counts from 1. Default `Remove {label} {position}`. */
|
|
27
29
|
readonly remove?: string | undefined;
|
|
30
|
+
/** Under a control while its check runs. Default `Checking…`. */
|
|
31
|
+
readonly checking?: string | undefined;
|
|
32
|
+
/** On the submit button while the form is submitting. Default `Submitting…`. */
|
|
33
|
+
readonly submitting?: string | undefined;
|
|
28
34
|
}
|
|
29
35
|
/**
|
|
30
36
|
* What the view needs that the form does not own: the choices of each relation
|
|
@@ -37,8 +43,27 @@ export interface FormViewInputs<Key extends string = string> {
|
|
|
37
43
|
* row: `'author.country'`.
|
|
38
44
|
*/
|
|
39
45
|
readonly nestedOptions?: Readonly<Record<string, ReadonlyArray<Option>>> | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* What a control backed by a Bundle is drawn with, by key: its view's inputs,
|
|
48
|
+
* such as the page Builder's `BuilderView.inputs({ data })`. A key in a nested
|
|
49
|
+
* row is named by its path, as in `nestedOptions`. Keyed by text, as those
|
|
50
|
+
* paths are, and typed where each entry is made, since only the control's
|
|
51
|
+
* Bundle knows its view's inputs.
|
|
52
|
+
*/
|
|
53
|
+
readonly controls?: Readonly<Record<string, unknown>> | undefined;
|
|
40
54
|
/** The view's own words, for wording and for translation. */
|
|
41
55
|
readonly words?: FormViewWords | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Whether the form is drawn with its submit button. Default: it is. `false`
|
|
58
|
+
* for someone who may not submit it, such as a writer where submitting
|
|
59
|
+
* publishes, so what would be refused is not offered.
|
|
60
|
+
*/
|
|
61
|
+
readonly submits?: boolean | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Whether the application's own work with a submitted value is in flight, such
|
|
64
|
+
* as its request: the form hands the value over and cannot see what follows.
|
|
65
|
+
*/
|
|
66
|
+
readonly submitting?: boolean | undefined;
|
|
42
67
|
}
|
|
43
68
|
/** What a field's Style and Behavior attachments may read. */
|
|
44
69
|
export interface FieldInput<Key extends string = string> {
|
|
@@ -51,6 +76,10 @@ export interface FieldInput<Key extends string = string> {
|
|
|
51
76
|
readonly id: string;
|
|
52
77
|
/** The word before the label on its search box: the view's `words.search`. */
|
|
53
78
|
readonly searchWord?: string | undefined;
|
|
79
|
+
/** The choice of nothing in a picker: the view's `words.none`. */
|
|
80
|
+
readonly noneWord?: string | undefined;
|
|
81
|
+
/** What is said while the key's check runs: the view's `words.checking`. */
|
|
82
|
+
readonly checkingWord?: string | undefined;
|
|
54
83
|
/**
|
|
55
84
|
* Set for a field in a row of a nested key: its Messages, wrapped for the row.
|
|
56
85
|
* A field of the form itself sends the form's own.
|
|
@@ -60,6 +89,12 @@ export interface FieldInput<Key extends string = string> {
|
|
|
60
89
|
readonly blurred: unknown;
|
|
61
90
|
readonly searched: (text: string) => unknown;
|
|
62
91
|
} | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Set for a key edited by a control backed by a Bundle (`Input.bundle`): the
|
|
94
|
+
* Bundle's Model, and the Message that carries one of its own. Such a key has
|
|
95
|
+
* no draft, so `field.value` is `''`; its validation state is `field`'s.
|
|
96
|
+
*/
|
|
97
|
+
readonly bundle?: BundleInput | undefined;
|
|
63
98
|
/** What was typed to find a choice, for a relation picker that searches. */
|
|
64
99
|
readonly search: string;
|
|
65
100
|
/**
|
|
@@ -68,11 +103,23 @@ export interface FieldInput<Key extends string = string> {
|
|
|
68
103
|
*/
|
|
69
104
|
readonly following: boolean;
|
|
70
105
|
}
|
|
106
|
+
/** A control backed by a Bundle, as its field is drawn: its Model, and how its Messages leave. */
|
|
107
|
+
export interface BundleInput {
|
|
108
|
+
readonly model: unknown;
|
|
109
|
+
readonly send: (message: unknown) => unknown;
|
|
110
|
+
/** What the view's `controls` gives this key, for the Bundle's own view. */
|
|
111
|
+
readonly viewInputs?: unknown;
|
|
112
|
+
}
|
|
71
113
|
/** What the form's own Style and Behavior attachments may read. */
|
|
72
114
|
export interface FormInput<Model, Key extends string = string> extends FormViewInputs<Key> {
|
|
73
115
|
readonly model: Model;
|
|
74
116
|
readonly errors: ReadonlyArray<string>;
|
|
75
117
|
readonly canSubmit: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Whether the form is submitting: a submit waits for a check, or the
|
|
120
|
+
* application's work with the value is in flight. `FormView.submodel` reads both.
|
|
121
|
+
*/
|
|
122
|
+
readonly submitting?: boolean | undefined;
|
|
76
123
|
}
|
|
77
124
|
/** One field: the control for a key, and what stands around it. */
|
|
78
125
|
export declare const FieldSlots: Slots.Contract<{
|
|
@@ -80,15 +127,27 @@ export declare const FieldSlots: Slots.Contract<{
|
|
|
80
127
|
readonly label: Slot.UnnamedSlot<Capability.Capability<"Base", readonly []>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
|
|
81
128
|
readonly description: Slot.UnnamedSlot<Capability.Capability<"Base", readonly []>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
|
|
82
129
|
readonly error: Slot.UnnamedSlot<Capability.Capability<"Base", readonly []>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
|
|
130
|
+
/** Says the key's check is running, while it runs. The control names it in `aria-describedby`. */
|
|
131
|
+
readonly checking: Slot.UnnamedSlot<Capability.Capability<"Base", readonly []>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
|
|
83
132
|
readonly text: Slot.UnnamedSlot<Capability.Capability<"TextInput", readonly [Capability.Capability<"Focusable", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>]>, readonly [Event.EventToken<"input">, Event.EventToken<"blur">], readonly [Attr.AttrToken<"aria-invalid">, Attr.AttrToken<"aria-describedby">], readonly Slot.RequirementName[], boolean>;
|
|
84
133
|
readonly multiline: Slot.UnnamedSlot<Capability.Capability<"TextInput", readonly [Capability.Capability<"Focusable", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>]>, readonly [Event.EventToken<"input">, Event.EventToken<"blur">], readonly [Attr.AttrToken<"aria-invalid">, Attr.AttrToken<"aria-describedby">], readonly Slot.RequirementName[], boolean>;
|
|
85
134
|
readonly number: Slot.UnnamedSlot<Capability.Capability<"TextInput", readonly [Capability.Capability<"Focusable", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>]>, readonly [Event.EventToken<"input">, Event.EventToken<"blur">], readonly [Attr.AttrToken<"aria-invalid">, Attr.AttrToken<"aria-describedby">], readonly Slot.RequirementName[], boolean>;
|
|
86
135
|
readonly toggle: Slot.UnnamedSlot<Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>, readonly [Event.EventToken<"click">, Event.EventToken<"blur">], readonly [Attr.AttrToken<"aria-invalid">, Attr.AttrToken<"aria-describedby">], readonly Slot.RequirementName[], boolean>;
|
|
87
136
|
/** A `Select`, and a `RelationOne` picker. */
|
|
88
137
|
readonly select: Slot.UnnamedSlot<Capability.Capability<"Focusable", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly [Event.EventToken<"change">, Event.EventToken<"blur">], readonly [Attr.AttrToken<"aria-invalid">, Attr.AttrToken<"aria-describedby">], readonly Slot.RequirementName[], boolean>;
|
|
138
|
+
/** One choice of a `select`. */
|
|
139
|
+
readonly option: Slot.UnnamedSlot<Capability.Capability<"Base", readonly []>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
|
|
140
|
+
/** Around the view of a control backed by a Bundle, when it is drawn with the Bundle's own view. */
|
|
141
|
+
readonly control: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
|
|
142
|
+
/** Around a control and its affixes, such as an address's prefix and its input. */
|
|
143
|
+
readonly group: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
|
|
144
|
+
/** Text beside a control, before or after it: a prefix, or a unit. */
|
|
145
|
+
readonly affix: Slot.UnnamedSlot<Capability.Capability<"Base", readonly []>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
|
|
89
146
|
/** A `RelationMany` picker: the group, and each thing in it. */
|
|
90
147
|
readonly choices: Slot.UnnamedSlot<Capability.Capability<"Collection", readonly [Capability.Capability<"Base", readonly []>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
|
|
91
148
|
readonly choice: Slot.UnnamedSlot<Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>, readonly [Event.EventToken<"click">], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
|
|
149
|
+
/** Around one choice's checkbox and its words. */
|
|
150
|
+
readonly choiceLabel: Slot.UnnamedSlot<Capability.Capability<"Base", readonly []>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
|
|
92
151
|
/** Over a relation picker that searches: where the user types to find a choice. */
|
|
93
152
|
readonly search: Slot.UnnamedSlot<Capability.Capability<"TextInput", readonly [Capability.Capability<"Focusable", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>]>, readonly [Event.EventToken<"input">], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
|
|
94
153
|
}>;
|
|
@@ -110,6 +169,10 @@ interface FormLike<Key extends string, Model, Message> {
|
|
|
110
169
|
/** Every key, nested ones too; `Key` is the keys that hold a draft. */
|
|
111
170
|
readonly controls: ReadonlyArray<FormControl>;
|
|
112
171
|
readonly field: (model: Model, key: Key) => FieldValidation.Field<Draft>;
|
|
172
|
+
/** A key edited by a control backed by a Bundle. A form with none takes no key here. */
|
|
173
|
+
readonly control: (key: never) => {
|
|
174
|
+
readonly field: (model: Model) => FieldValidation.Field<unknown>;
|
|
175
|
+
};
|
|
113
176
|
/** The rows of a nested key. A form with none takes no key here. */
|
|
114
177
|
readonly rows: (model: Model, key: never) => ReadonlyArray<FormRow>;
|
|
115
178
|
readonly search: (model: Model, key: Key) => string;
|
|
@@ -130,6 +193,10 @@ interface FormLike<Key extends string, Model, Message> {
|
|
|
130
193
|
readonly text: string;
|
|
131
194
|
}) => NoInfer<Message>;
|
|
132
195
|
readonly Submitted: () => NoInfer<Message>;
|
|
196
|
+
readonly Control: (payload: {
|
|
197
|
+
readonly key: never;
|
|
198
|
+
readonly message: unknown;
|
|
199
|
+
}) => NoInfer<Message>;
|
|
133
200
|
readonly Nested: (payload: {
|
|
134
201
|
readonly key: string;
|
|
135
202
|
readonly row: string;
|
|
@@ -153,8 +220,20 @@ export interface RenderContext<Message> {
|
|
|
153
220
|
readonly draft: Draft;
|
|
154
221
|
readonly change: (value: Draft) => Message;
|
|
155
222
|
readonly blurred: Message;
|
|
223
|
+
/**
|
|
224
|
+
* For a control backed by a Bundle: its Model, and the Message carrying one of
|
|
225
|
+
* its own. Its `draft` is `''`.
|
|
226
|
+
*/
|
|
227
|
+
readonly bundle: {
|
|
228
|
+
readonly model: unknown;
|
|
229
|
+
readonly send: (message: unknown) => Message;
|
|
230
|
+
/** The inputs its view is drawn with: the form view's `controls` entry for this key. */
|
|
231
|
+
readonly viewInputs: unknown;
|
|
232
|
+
} | undefined;
|
|
156
233
|
/** The control's id and its accessibility state. Put them on the element that holds the value. */
|
|
157
234
|
readonly state: ReadonlyArray<Attribute<Message>>;
|
|
235
|
+
/** What the key's element takes beyond the base field view. */
|
|
236
|
+
readonly attrs: FieldAttrs;
|
|
158
237
|
readonly slots: SlotBuilders<typeof FieldSlots, Message>;
|
|
159
238
|
readonly h: HtmlBuilder<Message>;
|
|
160
239
|
}
|
|
@@ -162,12 +241,78 @@ export interface RenderContext<Message> {
|
|
|
162
241
|
export type Renderer<Message> = (context: RenderContext<Message>) => Html;
|
|
163
242
|
/** Renderers by the `kind` of control they draw. */
|
|
164
243
|
export type Renderers<Message> = Readonly<Record<string, Renderer<Message>>>;
|
|
244
|
+
/**
|
|
245
|
+
* What a per-key override receives: everything to draw the control, and the
|
|
246
|
+
* Messages that leave it, in the form's own universe. The `h` an override
|
|
247
|
+
* draws with stays the caller's: the whole-form view's, or a custom layout's.
|
|
248
|
+
*/
|
|
249
|
+
export interface FieldOverrideInput<Key extends string = string, Changed = unknown> {
|
|
250
|
+
readonly control: FormControl<Key>;
|
|
251
|
+
readonly field: FieldValidation.Field<Draft>;
|
|
252
|
+
readonly id: string;
|
|
253
|
+
readonly invalid: boolean;
|
|
254
|
+
readonly errors: ReadonlyArray<string>;
|
|
255
|
+
readonly changed: (value: Draft) => Changed;
|
|
256
|
+
readonly blurred: Changed;
|
|
257
|
+
/** What the key's element takes beyond the base field view. */
|
|
258
|
+
readonly attrs: FieldAttrs;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Draws one key's control, for a layout the base field view does not own.
|
|
262
|
+
* `Changed` is the form's Message; `Message` the universe of the `h` that
|
|
263
|
+
* draws, which is the form's in the whole-form view and the application's
|
|
264
|
+
* in a custom layout.
|
|
265
|
+
*/
|
|
266
|
+
export type FieldOverride<Key extends string = string, Changed = unknown, Message = unknown> = (input: FieldOverrideInput<Key, Changed>, h: HtmlBuilder<Message>) => Html;
|
|
267
|
+
/**
|
|
268
|
+
* What one key's element takes beyond the base field view: an HTML input
|
|
269
|
+
* type, a placeholder, a textarea's rows. A renderer reads what fits its
|
|
270
|
+
* element and ignores the rest.
|
|
271
|
+
*/
|
|
272
|
+
export interface FieldAttrs {
|
|
273
|
+
readonly type?: string | undefined;
|
|
274
|
+
readonly placeholder?: string | undefined;
|
|
275
|
+
readonly rows?: number | undefined;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Per-key overrides for `FormView.fields`. `overrides` draw through the
|
|
279
|
+
* whole-form view; `styles` style one key's base field view there. Unknown
|
|
280
|
+
* keys in either are type errors. A custom layout passes its override to
|
|
281
|
+
* `field` itself, with its own `h`.
|
|
282
|
+
*/
|
|
283
|
+
export interface FieldsOptions<Key extends string, Changed> {
|
|
284
|
+
/** A key drawn by this instead of the base field view (or its styled one). */
|
|
285
|
+
readonly overrides?: { readonly [K in Key]?: FieldOverride<Key, Changed, Changed>; } | undefined;
|
|
286
|
+
/** A style around a key's base field view, kept for keys with no override. */
|
|
287
|
+
readonly styles?: { readonly [K in Key]?: NamedStyle<typeof FieldSlots>; } | undefined;
|
|
288
|
+
/**
|
|
289
|
+
* What one key's element takes beyond the base field view. Only the
|
|
290
|
+
* text, multiline, and number renderers read attrs; bundle-backed kinds
|
|
291
|
+
* (drawn by `bundleRenderer`) and per-key overrides ignore them. Passing
|
|
292
|
+
* `field` draws through it directly, skipping both `renderers` and `attrs`.
|
|
293
|
+
*/
|
|
294
|
+
readonly attrs?: { readonly [K in Key]?: FieldAttrs; } | undefined;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* One flat key's control, for a layout the caller owns: through the base
|
|
298
|
+
* field view with a form-universe `h`, or through the override it is given,
|
|
299
|
+
* with any `h`. A call with neither a form `h` nor an override is a type
|
|
300
|
+
* error, since the base view's Messages are the form's own.
|
|
301
|
+
*/
|
|
302
|
+
export interface FieldsField<Key extends string, Model, FormMessage extends {
|
|
303
|
+
readonly _tag: string;
|
|
304
|
+
}> {
|
|
305
|
+
(control: FormControl<Key>, model: Model, id: string, h: HtmlBuilder<FormMessage>, override?: FieldOverride<Key, FormMessage, FormMessage>): Html;
|
|
306
|
+
<Message>(control: FormControl<Key>, model: Model, id: string, h: HtmlBuilder<Message>, override: FieldOverride<Key, FormMessage, Message>): Html;
|
|
307
|
+
}
|
|
165
308
|
export declare const FormView: {
|
|
166
309
|
field: <Key extends string, Model, Message extends {
|
|
167
310
|
readonly _tag: string;
|
|
168
311
|
}>(form: FormLike<Key, Model, Message>, options?: {
|
|
169
312
|
/** Renderers by kind, beside the ones shipped: a new kind, or another way to draw a shipped one. */
|
|
170
313
|
readonly renderers?: Renderers<Message>;
|
|
314
|
+
/** What one key's element takes beyond the base field view. */
|
|
315
|
+
readonly attrs?: { readonly [K in Key]?: FieldAttrs; };
|
|
171
316
|
}) => FieldView<Key, Message>;
|
|
172
317
|
/**
|
|
173
318
|
* The view of the whole form: each control through `field`, in the input's
|
|
@@ -185,6 +330,30 @@ export declare const FormView: {
|
|
|
185
330
|
/** Renderers by kind, for the field view this makes. With `field` given, give them to `FormView.field`. */
|
|
186
331
|
readonly renderers?: Renderers<Message>;
|
|
187
332
|
}) => SlotView.SlotView<typeof FormSlots, FormInput<Model, Key>, Message>;
|
|
333
|
+
/**
|
|
334
|
+
* The whole form, as `define` draws it, with per-key overrides; and one flat
|
|
335
|
+
* key's control, for a layout the caller owns. Keys with no override render
|
|
336
|
+
* through the base field view (a new key of a known kind needs nothing new),
|
|
337
|
+
* each through its style when one is given and with its element attrs. `field`
|
|
338
|
+
* draws through the base view with a form-universe `h`, or through the
|
|
339
|
+
* override it is given, with any `h`. Nested keys and Bundle-backed keys draw
|
|
340
|
+
* only through `view` (or an override); `field` without one refuses them,
|
|
341
|
+
* naming the key.
|
|
342
|
+
*/
|
|
343
|
+
fields: <Key extends string, Model, FormMessage extends {
|
|
344
|
+
readonly _tag: string;
|
|
345
|
+
}>(form: FormLike<Key, Model, FormMessage> & {
|
|
346
|
+
readonly bundle: {
|
|
347
|
+
readonly name: string;
|
|
348
|
+
};
|
|
349
|
+
}, options?: {
|
|
350
|
+
readonly field?: FieldView<Key, FormMessage>;
|
|
351
|
+
/** Renderers by kind, for the field views this makes. */
|
|
352
|
+
readonly renderers?: Renderers<FormMessage>;
|
|
353
|
+
} & FieldsOptions<Key, FormMessage>) => {
|
|
354
|
+
readonly view: SlotView.SlotView<typeof FormSlots, FormInput<Model, Key>, FormMessage>;
|
|
355
|
+
readonly field: FieldsField<Key, Model, FormMessage>;
|
|
356
|
+
};
|
|
188
357
|
/**
|
|
189
358
|
* For `Bundle.withView`: the Submodel view that draws `view`, so a placement
|
|
190
359
|
* renders the form with `placed.view(model, h, { options })`.
|
|
@@ -195,9 +364,22 @@ export declare const FormView: {
|
|
|
195
364
|
*/
|
|
196
365
|
submodel: <Key extends string, Model extends {
|
|
197
366
|
readonly errors: ReadonlyArray<string>;
|
|
367
|
+
readonly submitPending: boolean;
|
|
198
368
|
}, Message extends {
|
|
199
369
|
readonly _tag: string;
|
|
200
|
-
}>(form: FormLike<Key, Model, Message>, view: SlotView.SlotView<typeof FormSlots, FormInput<Model, Key>, Message
|
|
370
|
+
}>(form: FormLike<Key, Model, Message>, view: SlotView.SlotView<typeof FormSlots, FormInput<Model, Key>, Message>, options?: {
|
|
371
|
+
/**
|
|
372
|
+
* When the submit waits instead of staying disabled. `true` while a
|
|
373
|
+
* check is running means submitted work waits for it, and the button
|
|
374
|
+
* stays enabled; `false` keeps the button disabled until every key is
|
|
375
|
+
* valid. Default `form.canSubmit` (lenient): a submit made mid-check
|
|
376
|
+
* waits for it. Pass a strict predicate to disable through checks
|
|
377
|
+
* instead, such as `model => PostForm.engine.value(model.form) !==
|
|
378
|
+
* undefined`, or `() => true` to never pre-disable and validate wholly
|
|
379
|
+
* at submit.
|
|
380
|
+
*/
|
|
381
|
+
readonly canSubmit?: (model: Model) => boolean;
|
|
382
|
+
}) => Submodel.View<Model, Message, FormViewInputs<Key>>;
|
|
201
383
|
};
|
|
202
384
|
//#endregion
|
|
203
385
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;iBAiCiB;WACN;WACA;;;;;;;;;iBAUM;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;;iBAOM,eAAe;WACrB,sBAAsB,KAAK,OAAO,cAAc;;;;;WAKhD,gBAAgB,SAAS,eAAe,cAAc;;;;;;;;WAQtD,WAAW,SAAS;;WAEpB,QAAQ;;;;;;WAMR;;;;;WAKA;;;iBAIM,WAAW;WACjB,SAAS,YAAY;WACrB,OAAO,gBAAgB,MAAM;WAC7B;WACA,QAAQ;WACR,SAAS,cAAc;;WAEvB;;WAEA;;WAEA;;WAEA;;;;;WAKA;aAEM,UAAU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;aAAgC;KACjE;aAA2B;KAAc,MAEnC,SAAS,KAAK,OAAO,UAAQ,MAC7B,SAAS,gBAAgB,WAAW,UAAU,OAAO,MAAM,UAAQ;;;;;;;;;;;aAY9D,aAAa,OAAO;QAE9B,SAAS,KAAK,OAAO,SAAS,eAAe"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Input, fillWords } from "foldkit-form";
|
|
2
|
-
import { Attr, Capability, Event, Slot, SlotView, Slots } from "foldkit-mixins";
|
|
2
|
+
import { Attr, Capability, Event, Slot, SlotView, Slots, Style } from "foldkit-mixins";
|
|
3
3
|
import * as FieldValidation from "foldkit/fieldValidation";
|
|
4
4
|
import * as Submodel from "foldkit/submodel";
|
|
5
5
|
//#region src/index.ts
|
|
@@ -22,6 +22,8 @@ const FieldSlots = Slots.define({
|
|
|
22
22
|
label: Slot.make({ capability: Capability.Base }),
|
|
23
23
|
description: Slot.make({ capability: Capability.Base }),
|
|
24
24
|
error: Slot.make({ capability: Capability.Base }),
|
|
25
|
+
/** Says the key's check is running, while it runs. The control names it in `aria-describedby`. */
|
|
26
|
+
checking: Slot.make({ capability: Capability.Base }),
|
|
25
27
|
text: Slot.make(textual),
|
|
26
28
|
multiline: Slot.make(textual),
|
|
27
29
|
number: Slot.make(textual),
|
|
@@ -36,12 +38,22 @@ const FieldSlots = Slots.define({
|
|
|
36
38
|
events: [Event.Change, Event.Blur],
|
|
37
39
|
attributes: [Attr.AriaInvalid, Attr.AriaDescribedby]
|
|
38
40
|
}),
|
|
41
|
+
/** One choice of a `select`. */
|
|
42
|
+
option: Slot.make({ capability: Capability.Base }),
|
|
43
|
+
/** Around the view of a control backed by a Bundle, when it is drawn with the Bundle's own view. */
|
|
44
|
+
control: Slot.make({ capability: Capability.Container }),
|
|
45
|
+
/** Around a control and its affixes, such as an address's prefix and its input. */
|
|
46
|
+
group: Slot.make({ capability: Capability.Container }),
|
|
47
|
+
/** Text beside a control, before or after it: a prefix, or a unit. */
|
|
48
|
+
affix: Slot.make({ capability: Capability.Base }),
|
|
39
49
|
/** A `RelationMany` picker: the group, and each thing in it. */
|
|
40
50
|
choices: Slot.make({ capability: Capability.Collection }),
|
|
41
51
|
choice: Slot.make({
|
|
42
52
|
capability: Capability.Interactive,
|
|
43
53
|
events: [Event.Click]
|
|
44
54
|
}),
|
|
55
|
+
/** Around one choice's checkbox and its words. */
|
|
56
|
+
choiceLabel: Slot.make({ capability: Capability.Base }),
|
|
45
57
|
/** Over a relation picker that searches: where the user types to find a choice. */
|
|
46
58
|
search: Slot.make({
|
|
47
59
|
capability: Capability.TextInput,
|
|
@@ -77,6 +89,7 @@ const FormSlots = Slots.define({
|
|
|
77
89
|
const rowWalk = (parent, key, row, form) => ({
|
|
78
90
|
controls: form.controls,
|
|
79
91
|
field: (inner) => form.field(row.model, inner),
|
|
92
|
+
controlField: (inner) => form.control(inner).field(row.model),
|
|
80
93
|
rows: (inner) => form.rows(row.model, inner),
|
|
81
94
|
search: (inner) => form.search(row.model, inner),
|
|
82
95
|
following: (inner) => form.isFollowing(row.model, inner),
|
|
@@ -89,10 +102,51 @@ const rowWalk = (parent, key, row, form) => ({
|
|
|
89
102
|
});
|
|
90
103
|
const errorsOf = (field) => field._tag === "Invalid" ? field.errors : [];
|
|
91
104
|
/**
|
|
105
|
+
* The state of a key a control backed by a Bundle edits, as a field is drawn:
|
|
106
|
+
* its validation state, with no draft. The Bundle's Model travels as `bundle`.
|
|
107
|
+
*/
|
|
108
|
+
const withoutDraft = (field) => field._tag === "Invalid" ? FieldValidation.Invalid({
|
|
109
|
+
value: "",
|
|
110
|
+
errors: field.errors
|
|
111
|
+
}) : field._tag === "Valid" ? FieldValidation.Valid({ value: "" }) : field._tag === "Validating" ? FieldValidation.Validating({ value: "" }) : FieldValidation.NotValidated({ value: "" });
|
|
112
|
+
/**
|
|
113
|
+
* A control backed by a Bundle that no renderer names is drawn with the
|
|
114
|
+
* Bundle's own view, inside the field's `control` slot, which carries the
|
|
115
|
+
* control's id and accessibility state. A Bundle with no view needs a renderer.
|
|
116
|
+
*/
|
|
117
|
+
const bundleRenderer = (control) => ({ bundle, input, state, slots, h }) => {
|
|
118
|
+
const view = Input.isBundle(control) ? control.data.bundle.view : void 0;
|
|
119
|
+
if (bundle === void 0 || view === void 0) throw new Error(`FormView: the "${control.kind}" control ("${input.control.key}") has no view; pass a renderer under "renderers"`);
|
|
120
|
+
return h.div(slots.control.attrs(state.filter((attribute) => attribute._tag !== "Name")), [h.submodel(bundle.viewInputs === void 0 ? {
|
|
121
|
+
slotId: input.id,
|
|
122
|
+
model: bundle.model,
|
|
123
|
+
view,
|
|
124
|
+
toParentMessage: bundle.send
|
|
125
|
+
} : {
|
|
126
|
+
slotId: input.id,
|
|
127
|
+
model: bundle.model,
|
|
128
|
+
view,
|
|
129
|
+
toParentMessage: bundle.send,
|
|
130
|
+
viewInputs: bundle.viewInputs
|
|
131
|
+
})]);
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
92
134
|
* The renderers this package ships, by kind. They are entries like any other: an
|
|
93
135
|
* application adds `Date`, or replaces `RelationOne` with a combobox, by passing
|
|
94
136
|
* its own beside them.
|
|
95
137
|
*/
|
|
138
|
+
/**
|
|
139
|
+
* The choices, and after them each chosen value they lack, as `? value`: a
|
|
140
|
+
* stored id whose row is gone, or a value the choices have not loaded yet,
|
|
141
|
+
* stays shown and can be let go, rather than dropped from sight.
|
|
142
|
+
*/
|
|
143
|
+
const withChosen = (options, chosen) => {
|
|
144
|
+
const known = new Set(options.map((option) => option.value));
|
|
145
|
+
return [...options, ...chosen.filter((value) => value !== "" && !known.has(value)).map((value) => ({
|
|
146
|
+
value,
|
|
147
|
+
label: `? ${value}`
|
|
148
|
+
}))];
|
|
149
|
+
};
|
|
96
150
|
const defaultRenderers = () => {
|
|
97
151
|
const typed = ({ state, draft, change, blurred, h }) => [
|
|
98
152
|
...state,
|
|
@@ -100,18 +154,27 @@ const defaultRenderers = () => {
|
|
|
100
154
|
h.OnInput(change),
|
|
101
155
|
h.OnBlur(blurred)
|
|
102
156
|
];
|
|
103
|
-
const pick = ({ state, draft, change, blurred, slots, h }, options, blank) => h.select(slots.select.attrs([
|
|
157
|
+
const pick = ({ state, draft, change, blurred, input, slots, h }, options, blank) => h.select(slots.select.attrs([
|
|
104
158
|
...state,
|
|
105
159
|
h.OnChange(change),
|
|
106
160
|
h.OnBlur(blurred)
|
|
107
|
-
]), [...blank || draft === "" ? [h.option([h.Value(""), h.Selected(draft === "")], [""])] : [], ...options.map((option) => h.option([h.Value(option.value), h.Selected(draft === option.value)], [option.label]))]);
|
|
161
|
+
]), [...blank || draft === "" ? [h.option(slots.option.attrs([h.Value(""), h.Selected(draft === "")]), [input.noneWord ?? ""])] : [], ...withChosen(options, typeof draft === "string" ? [draft] : []).map((option) => h.option(slots.option.attrs([h.Value(option.value), h.Selected(draft === option.value)]), [option.label]))]);
|
|
108
162
|
return {
|
|
109
|
-
[Input.Text.kind]: (context) => context.h.input(context.slots.text.attrs([
|
|
110
|
-
|
|
163
|
+
[Input.Text.kind]: (context) => context.h.input(context.slots.text.attrs([
|
|
164
|
+
...typed(context),
|
|
165
|
+
context.h.Type(context.attrs.type ?? "text"),
|
|
166
|
+
...context.attrs.placeholder === void 0 ? [] : [context.h.Placeholder(context.attrs.placeholder)]
|
|
167
|
+
])),
|
|
168
|
+
[Input.Multiline.kind]: (context) => context.h.textarea(context.slots.multiline.attrs([
|
|
169
|
+
...typed(context),
|
|
170
|
+
...context.attrs.placeholder === void 0 ? [] : [context.h.Placeholder(context.attrs.placeholder)],
|
|
171
|
+
...context.attrs.rows === void 0 ? [] : [context.h.Attribute("rows", String(context.attrs.rows))]
|
|
172
|
+
])),
|
|
111
173
|
[Input.Number.kind]: (context) => context.h.input(context.slots.number.attrs([
|
|
112
174
|
...typed(context),
|
|
113
175
|
context.h.Type("text"),
|
|
114
|
-
context.h.InputMode("decimal")
|
|
176
|
+
context.h.InputMode("decimal"),
|
|
177
|
+
...context.attrs.placeholder === void 0 ? [] : [context.h.Placeholder(context.attrs.placeholder)]
|
|
115
178
|
])),
|
|
116
179
|
[Input.Toggle.kind]: ({ state, draft, change, blurred, slots, h }) => h.input(slots.toggle.attrs([
|
|
117
180
|
...state,
|
|
@@ -120,27 +183,35 @@ const defaultRenderers = () => {
|
|
|
120
183
|
h.OnClick(change(draft !== true)),
|
|
121
184
|
h.OnBlur(blurred)
|
|
122
185
|
])),
|
|
123
|
-
[Input.Select.kind]: (context) => pick(context, (Input.Select.is(context.control) ? context.control.data.options : []).map((
|
|
124
|
-
value,
|
|
125
|
-
label:
|
|
186
|
+
[Input.Select.kind]: (context) => pick(context, (Input.Select.is(context.control) ? context.control.data.options : []).map((option) => ({
|
|
187
|
+
value: String(option),
|
|
188
|
+
label: String(option)
|
|
126
189
|
})), !context.input.control.required),
|
|
127
190
|
[Input.RelationOne.kind]: (context) => pick(context, context.input.options, true),
|
|
128
191
|
[Input.RelationMany.kind]: ({ input, draft, change, slots, h }) => {
|
|
129
192
|
const chosen = Array.isArray(draft) ? draft : [];
|
|
193
|
+
const isChosen = new Set(chosen);
|
|
130
194
|
return h.div(slots.choices.attrs([
|
|
131
195
|
h.Id(input.id),
|
|
132
196
|
h.Role("group"),
|
|
133
197
|
h.AriaLabel(input.control.label)
|
|
134
|
-
]), input.options.map((option) => h.label(
|
|
198
|
+
]), withChosen(input.options, chosen).map((option) => h.label(slots.choiceLabel.attrs(), [h.input(slots.choice.attrs([
|
|
135
199
|
h.Type("checkbox"),
|
|
136
200
|
h.Name(input.control.key),
|
|
137
201
|
h.Value(option.value),
|
|
138
|
-
h.Checked(
|
|
139
|
-
h.OnClick(change(
|
|
202
|
+
h.Checked(isChosen.has(option.value)),
|
|
203
|
+
h.OnClick(change(isChosen.has(option.value) ? chosen.filter((value) => value !== option.value) : [...chosen, option.value]))
|
|
140
204
|
])), option.label])));
|
|
141
205
|
}
|
|
142
206
|
};
|
|
143
207
|
};
|
|
208
|
+
/** The Messages of one key, through its row's send or the form's own. */
|
|
209
|
+
const changedOf = (form, key, send) => (value) => send === void 0 ? form.Message.Changed({
|
|
210
|
+
key,
|
|
211
|
+
value
|
|
212
|
+
}) : send.changed(value);
|
|
213
|
+
/** The blur Message of one key, through its row's send or the form's own. */
|
|
214
|
+
const blurredOf = (form, key, send) => send === void 0 ? form.Message.Blurred({ key }) : send.blurred;
|
|
144
215
|
/** The view of one field, to style or extend before handing it to `FormView.define`. */
|
|
145
216
|
const field = (form, options = {}) => {
|
|
146
217
|
const renderers = {
|
|
@@ -152,26 +223,34 @@ const field = (form, options = {}) => {
|
|
|
152
223
|
const { key, label, description, required } = control;
|
|
153
224
|
const draft = input.field.value;
|
|
154
225
|
const { send } = input;
|
|
155
|
-
const change = (
|
|
156
|
-
|
|
157
|
-
value
|
|
158
|
-
}) : send.changed(value);
|
|
159
|
-
const blurred = send === void 0 ? form.Message.Blurred({ key }) : send.blurred;
|
|
226
|
+
const change = changedOf(form, key, send);
|
|
227
|
+
const blurred = blurredOf(form, key, send);
|
|
160
228
|
const searched = (text) => send === void 0 ? form.Message.Searched({
|
|
161
229
|
key,
|
|
162
230
|
text
|
|
163
231
|
}) : send.searched(text);
|
|
164
232
|
const searches = control.control.searches;
|
|
165
|
-
const
|
|
233
|
+
const checking = input.field._tag === "Validating";
|
|
234
|
+
const describedBy = [
|
|
235
|
+
...description === void 0 ? [] : [`${id}-description`],
|
|
236
|
+
...checking ? [`${id}-checking`] : [],
|
|
237
|
+
...invalid ? [`${id}-error`] : []
|
|
238
|
+
];
|
|
166
239
|
const state = [
|
|
167
240
|
h.Id(id),
|
|
168
241
|
h.Name(key),
|
|
169
242
|
h.AriaInvalid(invalid),
|
|
170
|
-
...
|
|
243
|
+
...checking ? [h.AriaBusy(true)] : [],
|
|
171
244
|
...required ? [h.AriaRequired(true)] : [],
|
|
172
245
|
...describedBy.length === 0 ? [] : [h.AriaDescribedBy(describedBy.join(" "))]
|
|
173
246
|
];
|
|
174
|
-
const
|
|
247
|
+
const held = input.bundle;
|
|
248
|
+
const bundle = held === void 0 ? void 0 : {
|
|
249
|
+
model: held.model,
|
|
250
|
+
send: (message) => held.send(message),
|
|
251
|
+
viewInputs: held.viewInputs
|
|
252
|
+
};
|
|
253
|
+
const render = renderers[control.control.kind] ?? (bundle !== void 0 ? bundleRenderer(control.control) : void 0);
|
|
175
254
|
if (render === void 0) throw new Error(`FormView: no renderer for a "${control.control.kind}" control ("${key}"); pass one under "renderers"`);
|
|
176
255
|
const body = render({
|
|
177
256
|
input,
|
|
@@ -179,11 +258,13 @@ const field = (form, options = {}) => {
|
|
|
179
258
|
draft,
|
|
180
259
|
change,
|
|
181
260
|
blurred,
|
|
261
|
+
bundle,
|
|
182
262
|
state,
|
|
263
|
+
attrs: options.attrs?.[key] ?? {},
|
|
183
264
|
slots,
|
|
184
265
|
h
|
|
185
266
|
});
|
|
186
|
-
return h.div(slots.root.attrs(), [
|
|
267
|
+
return h.div(slots.root.attrs([h.DataAttribute("validation", input.field._tag)]), [
|
|
187
268
|
h.label(slots.label.attrs([h.For(id)]), [label]),
|
|
188
269
|
...searches ? [h.input(slots.search.attrs([
|
|
189
270
|
h.Id(`${id}-search`),
|
|
@@ -195,6 +276,7 @@ const field = (form, options = {}) => {
|
|
|
195
276
|
]))] : [],
|
|
196
277
|
body,
|
|
197
278
|
...description === void 0 ? [] : [h.p(slots.description.attrs([h.Id(`${id}-description`)]), [description])],
|
|
279
|
+
...checking ? [h.p(slots.checking.attrs([h.Id(`${id}-checking`), h.Role("status")]), [input.checkingWord ?? "Checking…"])] : [],
|
|
198
280
|
...invalid ? [h.p(slots.error.attrs([h.Id(`${id}-error`), h.Role("alert")]), [...input.errors])] : []
|
|
199
281
|
]);
|
|
200
282
|
}, { name: "FormField" });
|
|
@@ -213,15 +295,26 @@ const FormView = {
|
|
|
213
295
|
...input.nestedOptions,
|
|
214
296
|
...input.options
|
|
215
297
|
};
|
|
298
|
+
const controls = input.controls ?? {};
|
|
216
299
|
/** The controls of a form or of a row. `id` and `path` say where: both are empty for the form itself. */
|
|
217
300
|
const draw = (walk, id, path) => walk.controls.filter((control) => control.control.shown).map((control) => {
|
|
218
301
|
const { key, label } = control;
|
|
219
302
|
const here = `${id}-${key}`;
|
|
220
303
|
if (!Input.Nested.is(control.control)) {
|
|
221
|
-
const
|
|
304
|
+
const bundled = Input.isBundle(control.control);
|
|
305
|
+
const held = bundled ? walk.controlField(key) : walk.field(key);
|
|
306
|
+
const state = bundled ? withoutDraft(held) : held;
|
|
222
307
|
return fieldView({
|
|
223
308
|
control,
|
|
224
309
|
field: state,
|
|
310
|
+
bundle: bundled ? {
|
|
311
|
+
model: held.value,
|
|
312
|
+
send: (message) => walk.wrap(walk.make.Control({
|
|
313
|
+
key,
|
|
314
|
+
message
|
|
315
|
+
})),
|
|
316
|
+
viewInputs: controls[`${path}${key}`]
|
|
317
|
+
} : void 0,
|
|
225
318
|
invalid: FieldValidation.isInvalid(state),
|
|
226
319
|
errors: errorsOf(state),
|
|
227
320
|
options: options[`${path}${key}`] ?? [],
|
|
@@ -229,6 +322,8 @@ const FormView = {
|
|
|
229
322
|
search: walk.search(key),
|
|
230
323
|
following: walk.following(key),
|
|
231
324
|
searchWord: input.words?.search,
|
|
325
|
+
noneWord: input.words?.none,
|
|
326
|
+
checkingWord: input.words?.checking,
|
|
232
327
|
send: {
|
|
233
328
|
changed: (value) => walk.wrap(walk.make.Changed({
|
|
234
329
|
key,
|
|
@@ -260,20 +355,92 @@ const FormView = {
|
|
|
260
355
|
const top = {
|
|
261
356
|
controls: form.controls,
|
|
262
357
|
field: (key) => form.field(input.model, key),
|
|
358
|
+
controlField: (key) => form.control(key).field(input.model),
|
|
263
359
|
rows: (key) => form.rows(input.model, key),
|
|
264
360
|
search: (key) => form.search(input.model, key),
|
|
265
361
|
following: (key) => form.isFollowing(input.model, key),
|
|
266
362
|
wrap: (message) => message,
|
|
267
363
|
make: form.Message
|
|
268
364
|
};
|
|
269
|
-
|
|
365
|
+
const submitting = input.submitting === true;
|
|
366
|
+
return h.form(slots.root.attrs([h.OnSubmit(form.Message.Submitted()), ...submitting ? [h.AriaBusy(true), h.DataAttribute("submitting", "")] : []]), [
|
|
270
367
|
...draw(top, form.bundle.name, ""),
|
|
271
368
|
...input.errors.length === 0 ? [] : [h.p(slots.errors.attrs([h.Role("alert")]), [...input.errors])],
|
|
272
|
-
h.button(slots.submit.attrs([h.Type("submit"), h.Disabled(!input.canSubmit)]), [input.words?.submit ?? "Submit"])
|
|
369
|
+
...input.submits === false ? [] : [h.button(slots.submit.attrs([h.Type("submit"), h.Disabled(!input.canSubmit || submitting)]), [submitting ? input.words?.submitting ?? "Submitting…" : input.words?.submit ?? "Submit"])]
|
|
273
370
|
]);
|
|
274
371
|
}, { name: form.bundle.name });
|
|
275
372
|
},
|
|
276
373
|
/**
|
|
374
|
+
* The whole form, as `define` draws it, with per-key overrides; and one flat
|
|
375
|
+
* key's control, for a layout the caller owns. Keys with no override render
|
|
376
|
+
* through the base field view (a new key of a known kind needs nothing new),
|
|
377
|
+
* each through its style when one is given and with its element attrs. `field`
|
|
378
|
+
* draws through the base view with a form-universe `h`, or through the
|
|
379
|
+
* override it is given, with any `h`. Nested keys and Bundle-backed keys draw
|
|
380
|
+
* only through `view` (or an override); `field` without one refuses them,
|
|
381
|
+
* naming the key.
|
|
382
|
+
*/
|
|
383
|
+
fields: (form, options = {}) => {
|
|
384
|
+
const base = options.field ?? field(form, options.renderers === void 0 && options.attrs === void 0 ? {} : {
|
|
385
|
+
...options.renderers === void 0 ? {} : { renderers: options.renderers },
|
|
386
|
+
...options.attrs === void 0 ? {} : { attrs: options.attrs }
|
|
387
|
+
});
|
|
388
|
+
const styled = /* @__PURE__ */ new Map();
|
|
389
|
+
const viewOf = (key) => {
|
|
390
|
+
const known = styled.get(key);
|
|
391
|
+
if (known !== void 0) return known;
|
|
392
|
+
const style = options.styles?.[key];
|
|
393
|
+
const made = style === void 0 ? base : Style.attach(style)(base);
|
|
394
|
+
styled.set(key, made);
|
|
395
|
+
return made;
|
|
396
|
+
};
|
|
397
|
+
const drawn = (input, h) => {
|
|
398
|
+
const override = options.overrides?.[input.control.key];
|
|
399
|
+
if (override === void 0) return viewOf(input.control.key)(input, h);
|
|
400
|
+
return override({
|
|
401
|
+
control: input.control,
|
|
402
|
+
field: input.field,
|
|
403
|
+
id: input.id,
|
|
404
|
+
invalid: input.invalid,
|
|
405
|
+
errors: input.errors,
|
|
406
|
+
changed: changedOf(form, input.control.key, input.send),
|
|
407
|
+
blurred: blurredOf(form, input.control.key, input.send),
|
|
408
|
+
attrs: options.attrs?.[input.control.key] ?? {}
|
|
409
|
+
}, h);
|
|
410
|
+
};
|
|
411
|
+
return {
|
|
412
|
+
view: FormView.define(form, { field: SlotView.forMessages().define(FieldSlots, (input, _slots, h) => drawn(input, h), { name: `${form.bundle.name}Fields` }) }),
|
|
413
|
+
field: ((control, model, id, h, override) => {
|
|
414
|
+
const state = form.field(model, control.key);
|
|
415
|
+
if (override !== void 0) return override({
|
|
416
|
+
control,
|
|
417
|
+
field: state,
|
|
418
|
+
id,
|
|
419
|
+
invalid: FieldValidation.isInvalid(state),
|
|
420
|
+
errors: errorsOf(state),
|
|
421
|
+
changed: (value) => form.Message.Changed({
|
|
422
|
+
key: control.key,
|
|
423
|
+
value
|
|
424
|
+
}),
|
|
425
|
+
blurred: form.Message.Blurred({ key: control.key }),
|
|
426
|
+
attrs: options.attrs?.[control.key] ?? {}
|
|
427
|
+
}, h);
|
|
428
|
+
if (Input.Nested.is(control.control) || Input.isBundle(control.control)) throw new Error(`FormView.fields: "${control.key}" nests rows or a Bundle; draw it with the whole-form view, or give an override for it`);
|
|
429
|
+
return viewOf(control.key)({
|
|
430
|
+
control,
|
|
431
|
+
field: state,
|
|
432
|
+
bundle: void 0,
|
|
433
|
+
invalid: FieldValidation.isInvalid(state),
|
|
434
|
+
errors: errorsOf(state),
|
|
435
|
+
options: [],
|
|
436
|
+
id,
|
|
437
|
+
search: form.search(model, control.key),
|
|
438
|
+
following: form.isFollowing(model, control.key)
|
|
439
|
+
}, h);
|
|
440
|
+
})
|
|
441
|
+
};
|
|
442
|
+
},
|
|
443
|
+
/**
|
|
277
444
|
* For `Bundle.withView`: the Submodel view that draws `view`, so a placement
|
|
278
445
|
* renders the form with `placed.view(model, h, { options })`.
|
|
279
446
|
*
|
|
@@ -281,11 +448,12 @@ const FormView = {
|
|
|
281
448
|
* const Drawn = EditPost.bundle.pipe(Bundle.withView(FormView.submodel(EditPost, View)))
|
|
282
449
|
* ```
|
|
283
450
|
*/
|
|
284
|
-
submodel: (form, view) => Submodel.defineView((model, inputs, h) => view({
|
|
451
|
+
submodel: (form, view, options = {}) => Submodel.defineView((model, inputs, h) => view({
|
|
285
452
|
...inputs,
|
|
286
453
|
model,
|
|
287
454
|
errors: model.errors,
|
|
288
|
-
canSubmit: form.canSubmit(model)
|
|
455
|
+
canSubmit: (options.canSubmit ?? form.canSubmit)(model),
|
|
456
|
+
submitting: model.submitPending || inputs.submitting === true
|
|
289
457
|
}, h))
|
|
290
458
|
};
|
|
291
459
|
//#endregion
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * `foldkit-mixins-form` — a `foldkit-form` form drawn through slots.\n *\n * `foldkit-form` describes each control and draws nothing. This package draws\n * them as plain, accessible HTML and publishes every element as a Slot, so an\n * application styles and extends a generated form the way it does any other\n * SlotView, and the form stays free of a view dependency.\n */\nimport {\n Input,\n fillWords,\n type Control,\n type Draft,\n type FormControl,\n type FormRow,\n type NestedForm,\n} from 'foldkit-form'\nimport { Attr, Capability, Event, Slot, Slots, SlotView, type SlotBuilders } from 'foldkit-mixins'\nimport * as FieldValidation from 'foldkit/fieldValidation'\nimport type { Attribute, Html, HtmlBuilder } from 'foldkit/html'\nimport * as Submodel from 'foldkit/submodel'\n\n/** One thing a select or a relation picker offers. */\nexport interface Option {\n readonly value: string\n readonly label: string\n}\n\n/**\n * The words the drawn form says itself. Its keys are its own, so one object can\n * hold these, `foldkit-mixins-crud`'s `ViewWords`, and a form's `FormMessages`:\n * an application's words, written and translated in one place. They are text\n * with blanks (`{label}`), never functions: Foldkit admits no function nested in\n * a placed view's inputs.\n */\nexport interface FormViewWords {\n /** On the submit button. Default `Submit`. */\n readonly submit?: string | undefined\n /** Before the label on a picker's search box (`Search Author`). Default `Search`. */\n readonly search?: string | undefined\n /** On the button that adds a row to a nested key. Default `Add {label}`. */\n readonly add?: string | undefined\n /** On the button that removes a row; `{position}` counts from 1. Default `Remove {label} {position}`. */\n readonly remove?: string | undefined\n}\n\n/**\n * What the view needs that the form does not own: the choices of each relation\n * picker (a query the application makes), and the submit button's words.\n */\nexport interface FormViewInputs<Key extends string = string> {\n readonly options?: { readonly [K in Key]?: ReadonlyArray<Option> } | undefined\n /**\n * The choices of a picker inside a nested key, by its path, the same for every\n * row: `'author.country'`.\n */\n readonly nestedOptions?: Readonly<Record<string, ReadonlyArray<Option>>> | undefined\n /** The view's own words, for wording and for translation. */\n readonly words?: FormViewWords | undefined\n}\n\n/** What a field's Style and Behavior attachments may read. */\nexport interface FieldInput<Key extends string = string> {\n readonly control: FormControl<Key>\n readonly field: FieldValidation.Field<Draft>\n readonly invalid: boolean\n readonly errors: ReadonlyArray<string>\n readonly options: ReadonlyArray<Option>\n /** Unique within the form, for `label for`, and as the prefix of the ids beside it. */\n readonly id: string\n /** The word before the label on its search box: the view's `words.search`. */\n readonly searchWord?: string | undefined\n /**\n * Set for a field in a row of a nested key: its Messages, wrapped for the row.\n * A field of the form itself sends the form's own.\n */\n readonly send?:\n | {\n readonly changed: (value: Draft) => unknown\n readonly blurred: unknown\n readonly searched: (text: string) => unknown\n }\n | undefined\n /** What was typed to find a choice, for a relation picker that searches. */\n readonly search: string\n /**\n * Whether the key is still written from the key it follows. A renderer offers\n * \"regenerate\" when it is not, by sending the key an empty draft.\n */\n readonly following: boolean\n}\n\n/** What the form's own Style and Behavior attachments may read. */\nexport interface FormInput<Model, Key extends string = string> extends FormViewInputs<Key> {\n readonly model: Model\n readonly errors: ReadonlyArray<string>\n readonly canSubmit: boolean\n}\n\nconst textual = {\n capability: Capability.TextInput,\n events: [Event.Input, Event.Blur],\n attributes: [Attr.AriaInvalid, Attr.AriaDescribedby],\n} as const\n\n/** One field: the control for a key, and what stands around it. */\nexport const FieldSlots = Slots.define({\n root: Slot.make({ capability: Capability.Container }),\n label: Slot.make({ capability: Capability.Base }),\n description: Slot.make({ capability: Capability.Base }),\n error: Slot.make({ capability: Capability.Base }),\n text: Slot.make(textual),\n multiline: Slot.make(textual),\n number: Slot.make(textual),\n toggle: Slot.make({\n capability: Capability.Interactive,\n events: [Event.Click, Event.Blur],\n attributes: [Attr.AriaInvalid, Attr.AriaDescribedby],\n }),\n /** A `Select`, and a `RelationOne` picker. */\n select: Slot.make({\n capability: Capability.Focusable,\n events: [Event.Change, Event.Blur],\n attributes: [Attr.AriaInvalid, Attr.AriaDescribedby],\n }),\n /** A `RelationMany` picker: the group, and each thing in it. */\n choices: Slot.make({ capability: Capability.Collection }),\n choice: Slot.make({ capability: Capability.Interactive, events: [Event.Click] }),\n /** Over a relation picker that searches: where the user types to find a choice. */\n search: Slot.make({ capability: Capability.TextInput, events: [Event.Input] }),\n})\n\n/** The form around its fields. */\nexport const FormSlots = Slots.define({\n root: Slot.make({ capability: Capability.Container, events: [Event.Submit] }),\n /** Failures that belong to no one field: a rule that spans keys. */\n errors: Slot.make({ capability: Capability.Base }),\n submit: Slot.make({\n capability: Capability.Interactive,\n events: [Event.Click],\n attributes: [Attr.Disabled],\n }),\n /** A nested key: the group around its rows, its name, each row, and the buttons that add and remove one. */\n group: Slot.make({ capability: Capability.Container }),\n legend: Slot.make({ capability: Capability.Base }),\n row: Slot.make({ capability: Capability.Container }),\n add: Slot.make({ capability: Capability.Interactive, events: [Event.Click] }),\n remove: Slot.make({ capability: Capability.Interactive, events: [Event.Click] }),\n})\n\n/** The parts of a `Form.make` result the view reads. */\ninterface FormLike<Key extends string, Model, Message> {\n /** Every key, nested ones too; `Key` is the keys that hold a draft. */\n readonly controls: ReadonlyArray<FormControl>\n readonly field: (model: Model, key: Key) => FieldValidation.Field<Draft>\n /** The rows of a nested key. A form with none takes no key here. */\n readonly rows: (model: Model, key: never) => ReadonlyArray<FormRow>\n readonly search: (model: Model, key: Key) => string\n readonly isFollowing: (model: Model, key: Key) => boolean\n readonly canSubmit: (model: Model) => boolean\n readonly Message: {\n /** The union, so `Message` is inferred from it and not from one constructor's case. */\n readonly Type: Message\n readonly Changed: (payload: { readonly key: Key; readonly value: Draft }) => NoInfer<Message>\n readonly Blurred: (payload: { readonly key: Key }) => NoInfer<Message>\n readonly Searched: (payload: { readonly key: Key; readonly text: string }) => NoInfer<Message>\n readonly Submitted: () => NoInfer<Message>\n readonly Nested: (payload: {\n readonly key: string\n readonly row: string\n readonly message: unknown\n }) => NoInfer<Message>\n readonly RowAdded: (payload: { readonly key: string }) => NoInfer<Message>\n readonly RowRemoved: (payload: {\n readonly key: string\n readonly row: string\n }) => NoInfer<Message>\n }\n}\n\n/**\n * A form or a row of one, as the view walks it: what to draw, and how each\n * Message leaves. A row's Messages leave wrapped, once per form they pass through.\n */\ninterface Walk<Message> {\n readonly controls: ReadonlyArray<FormControl>\n readonly field: (key: string) => FieldValidation.Field<Draft>\n readonly rows: (key: string) => ReadonlyArray<FormRow>\n readonly search: (key: string) => string\n readonly following: (key: string) => boolean\n readonly wrap: (message: unknown) => Message\n readonly make: NestedForm['Message']\n}\n\nconst rowWalk = <Message>(\n parent: Walk<Message>,\n key: string,\n row: FormRow,\n form: NestedForm,\n): Walk<Message> => ({\n controls: form.controls as ReadonlyArray<FormControl>,\n field: inner =>\n (form.field as (model: unknown, key: string) => FieldValidation.Field<Draft>)(row.model, inner),\n rows: inner =>\n (form.rows as (model: unknown, key: string) => ReadonlyArray<FormRow>)(row.model, inner),\n search: inner => (form.search as (model: unknown, key: string) => string)(row.model, inner),\n following: inner =>\n (form.isFollowing as (model: unknown, key: string) => boolean)(row.model, inner),\n wrap: message =>\n parent.wrap(\n (parent.make.Nested as (payload: object) => unknown)({ key, row: row.id, message }),\n ),\n make: form.Message,\n})\n\ntype FieldView<Key extends string, Message> = SlotView.SlotView<\n typeof FieldSlots,\n FieldInput<Key>,\n Message\n>\n\nconst errorsOf = (field: FieldValidation.Field<Draft>): ReadonlyArray<string> =>\n field._tag === 'Invalid' ? field.errors : []\n\n/** What a renderer draws one control from. */\nexport interface RenderContext<Message> {\n readonly input: FieldInput\n /** The control, whose `data` is its kind's: narrow it with the kind's `is`. */\n readonly control: Control\n readonly draft: Draft\n readonly change: (value: Draft) => Message\n readonly blurred: Message\n /** The control's id and its accessibility state. Put them on the element that holds the value. */\n readonly state: ReadonlyArray<Attribute<Message>>\n readonly slots: SlotBuilders<typeof FieldSlots, Message>\n readonly h: HtmlBuilder<Message>\n}\n\n/** Draws the control of one kind. The label, description and error around it are the field's. */\nexport type Renderer<Message> = (context: RenderContext<Message>) => Html\n\n/** Renderers by the `kind` of control they draw. */\nexport type Renderers<Message> = Readonly<Record<string, Renderer<Message>>>\n\n/**\n * The renderers this package ships, by kind. They are entries like any other: an\n * application adds `Date`, or replaces `RelationOne` with a combobox, by passing\n * its own beside them.\n */\nconst defaultRenderers = <Message>(): Renderers<Message> => {\n const typed = ({ state, draft, change, blurred, h }: RenderContext<Message>) => [\n ...state,\n h.Value(String(draft)),\n h.OnInput(change),\n h.OnBlur(blurred),\n ]\n // A blank option whenever nothing is chosen, required or not: without one the\n // browser shows its first option as chosen while the draft is still empty.\n const pick = (\n { state, draft, change, blurred, slots, h }: RenderContext<Message>,\n options: ReadonlyArray<Option>,\n blank: boolean,\n ): Html =>\n h.select(slots.select.attrs([...state, h.OnChange(change), h.OnBlur(blurred)]), [\n ...(blank || draft === '' ? [h.option([h.Value(''), h.Selected(draft === '')], [''])] : []),\n ...options.map(option =>\n h.option([h.Value(option.value), h.Selected(draft === option.value)], [option.label]),\n ),\n ])\n return {\n [Input.Text.kind]: context =>\n context.h.input(context.slots.text.attrs([...typed(context), context.h.Type('text')])),\n [Input.Multiline.kind]: context =>\n // A textarea's attributes exclude `InnerHTML`, which a slot's type admits\n // and no mixin can supply, so the narrowing loses nothing.\n context.h.textarea(\n context.slots.multiline.attrs(typed(context)) as Parameters<typeof context.h.textarea>[0],\n ),\n // A number is a text input because its draft is text: `\"4.\"` is a fine thing to\n // have typed, and `type=\"number\"` would refuse to report it.\n [Input.Number.kind]: context =>\n context.h.input(\n context.slots.number.attrs([\n ...typed(context),\n context.h.Type('text'),\n context.h.InputMode('decimal'),\n ]),\n ),\n [Input.Toggle.kind]: ({ state, draft, change, blurred, slots, h }) =>\n h.input(\n slots.toggle.attrs([\n ...state,\n h.Type('checkbox'),\n h.Checked(draft === true),\n h.OnClick(change(draft !== true)),\n h.OnBlur(blurred),\n ]),\n ),\n [Input.Select.kind]: context =>\n pick(\n context,\n (Input.Select.is(context.control) ? context.control.data.options : []).map(value => ({\n value,\n label: value,\n })),\n !context.input.control.required,\n ),\n [Input.RelationOne.kind]: context => pick(context, context.input.options, true),\n [Input.RelationMany.kind]: ({ input, draft, change, slots, h }) => {\n const chosen = Array.isArray(draft) ? (draft as ReadonlyArray<string>) : []\n return h.div(\n slots.choices.attrs([h.Id(input.id), h.Role('group'), h.AriaLabel(input.control.label)]),\n input.options.map(option =>\n h.label(\n [],\n [\n h.input(\n slots.choice.attrs([\n h.Type('checkbox'),\n h.Name(input.control.key),\n h.Value(option.value),\n h.Checked(chosen.includes(option.value)),\n h.OnClick(\n change(\n chosen.includes(option.value)\n ? chosen.filter(value => value !== option.value)\n : [...chosen, option.value],\n ),\n ),\n ]),\n ),\n option.label,\n ],\n ),\n ),\n )\n },\n }\n}\n\n/** The view of one field, to style or extend before handing it to `FormView.define`. */\nconst field = <Key extends string, Model, Message extends { readonly _tag: string }>(\n form: FormLike<Key, Model, Message>,\n options: {\n /** Renderers by kind, beside the ones shipped: a new kind, or another way to draw a shipped one. */\n readonly renderers?: Renderers<Message>\n } = {},\n): FieldView<Key, Message> => {\n const renderers: Renderers<Message> = { ...defaultRenderers<Message>(), ...options.renderers }\n return SlotView.forMessages<Message>().define(\n FieldSlots,\n (input: FieldInput<Key>, slots, h) => {\n const { control, id, invalid } = input\n const { key, label, description, required } = control\n const draft = input.field.value\n const { send } = input\n const change = (value: Draft): Message =>\n send === undefined ? form.Message.Changed({ key, value }) : (send.changed(value) as Message)\n const blurred = send === undefined ? form.Message.Blurred({ key }) : (send.blurred as Message)\n const searched = (text: string): Message =>\n send === undefined ? form.Message.Searched({ key, text }) : (send.searched(text) as Message)\n const searches = control.control.searches\n const describedBy = [\n ...(description === undefined ? [] : [`${id}-description`]),\n ...(invalid ? [`${id}-error`] : []),\n ]\n const state = [\n h.Id(id),\n // The key is the field's name, so a form posts its drafts with scripts off.\n h.Name(key),\n h.AriaInvalid(invalid),\n // A check is running: the control is neither valid nor invalid yet.\n ...(input.field._tag === 'Validating' ? [h.AriaBusy(true)] : []),\n ...(required ? [h.AriaRequired(true)] : []),\n ...(describedBy.length === 0 ? [] : [h.AriaDescribedBy(describedBy.join(' '))]),\n ]\n const render = renderers[control.control.kind]\n if (render === undefined)\n throw new Error(\n `FormView: no renderer for a \"${control.control.kind}\" control (\"${key}\"); pass one under \"renderers\"`,\n )\n const body = render({\n input: input as FieldInput,\n control: control.control,\n draft,\n change,\n blurred,\n state,\n slots,\n h,\n })\n\n return h.div(slots.root.attrs(), [\n h.label(slots.label.attrs([h.For(id)]), [label]),\n // Typing here changes which choices the picker below is offered.\n ...(searches\n ? [\n h.input(\n slots.search.attrs([\n h.Id(`${id}-search`),\n h.Type('search'),\n h.AriaLabel(`${input.searchWord ?? 'Search'} ${label}`),\n h.AriaControls(id),\n h.Value(input.search),\n h.OnInput(searched),\n ]),\n ),\n ]\n : []),\n body,\n ...(description === undefined\n ? []\n : [h.p(slots.description.attrs([h.Id(`${id}-description`)]), [description])]),\n ...(invalid\n ? [h.p(slots.error.attrs([h.Id(`${id}-error`), h.Role('alert')]), [...input.errors])]\n : []),\n ])\n },\n { name: 'FormField' },\n )\n}\n\nexport const FormView = {\n field,\n\n /**\n * The view of the whole form: each control through `field`, in the input's\n * order, a hidden key left out. Pass a styled `field` to change how fields\n * look; attach Style and Behavior to the result to change the form around them.\n */\n define: <Key extends string, Model, Message extends { readonly _tag: string }>(\n form: FormLike<Key, Model, Message> & { readonly bundle: { readonly name: string } },\n options: {\n readonly field?: FieldView<Key, Message>\n /** Renderers by kind, for the field view this makes. With `field` given, give them to `FormView.field`. */\n readonly renderers?: Renderers<Message>\n } = {},\n ): SlotView.SlotView<typeof FormSlots, FormInput<Model, Key>, Message> => {\n const fieldView =\n options.field ??\n field(form, options.renderers === undefined ? {} : { renderers: options.renderers })\n type Make = (payload: object) => unknown\n return SlotView.forMessages<Message>().define(\n FormSlots,\n (input: FormInput<Model, Key>, slots, h) => {\n const options: Readonly<Record<string, ReadonlyArray<Option> | undefined>> = {\n ...input.nestedOptions,\n ...input.options,\n }\n\n /** The controls of a form or of a row. `id` and `path` say where: both are empty for the form itself. */\n const draw = (walk: Walk<Message>, id: string, path: string): ReadonlyArray<Html> =>\n walk.controls\n .filter(control => control.control.shown)\n .map((control): Html => {\n const { key, label } = control\n const here = `${id}-${key}`\n if (!Input.Nested.is(control.control)) {\n const state = walk.field(key)\n return fieldView(\n {\n control: control as FormControl<Key>,\n field: state,\n invalid: FieldValidation.isInvalid(state),\n errors: errorsOf(state),\n options: options[`${path}${key}`] ?? [],\n id: here,\n search: walk.search(key),\n following: walk.following(key),\n searchWord: input.words?.search,\n send: {\n changed: value => walk.wrap((walk.make.Changed as Make)({ key, value })),\n blurred: walk.wrap((walk.make.Blurred as Make)({ key })),\n searched: text => walk.wrap((walk.make.Searched as Make)({ key, text })),\n },\n },\n h,\n )\n }\n const { form: nested, cardinality, optional } = control.control.data\n const rows = walk.rows(key)\n const addLabel = fillWords(input.words?.add ?? 'Add {label}', { label })\n return h.fieldset(slots.group.attrs([h.Id(here)]), [\n h.legend(slots.legend.attrs(), [label]),\n ...rows.map((row, index) =>\n h.div(slots.row.attrs([h.Id(`${here}-${row.id}`)]), [\n ...draw(rowWalk(walk, key, row, nested), `${here}-${row.id}`, `${path}${key}.`),\n // A row that must be there has no way out.\n ...(optional\n ? [\n h.button(\n slots.remove.attrs([\n h.Type('button'),\n h.OnClick(\n walk.wrap((walk.make.RowRemoved as Make)({ key, row: row.id })),\n ),\n ]),\n [\n fillWords(input.words?.remove ?? 'Remove {label} {position}', {\n label,\n position: index + 1,\n }),\n ],\n ),\n ]\n : []),\n ]),\n ),\n // A `one` takes one row: the way in goes once it is there.\n ...(cardinality === 'many' || rows.length === 0\n ? [\n h.button(\n slots.add.attrs([\n h.Type('button'),\n h.OnClick(walk.wrap((walk.make.RowAdded as Make)({ key }))),\n ]),\n [addLabel],\n ),\n ]\n : []),\n ])\n })\n\n const top: Walk<Message> = {\n controls: form.controls,\n field: key => form.field(input.model, key as Key),\n rows: key => form.rows(input.model, key as never),\n search: key => form.search(input.model, key as Key),\n following: key => form.isFollowing(input.model, key as Key),\n wrap: message => message as Message,\n make: form.Message as unknown as NestedForm['Message'],\n }\n return h.form(slots.root.attrs([h.OnSubmit(form.Message.Submitted())]), [\n ...draw(top, form.bundle.name, ''),\n ...(input.errors.length === 0\n ? []\n : [h.p(slots.errors.attrs([h.Role('alert')]), [...input.errors])]),\n h.button(slots.submit.attrs([h.Type('submit'), h.Disabled(!input.canSubmit)]), [\n input.words?.submit ?? 'Submit',\n ]),\n ])\n },\n { name: form.bundle.name },\n )\n },\n\n /**\n * For `Bundle.withView`: the Submodel view that draws `view`, so a placement\n * renders the form with `placed.view(model, h, { options })`.\n *\n * ```ts\n * const Drawn = EditPost.bundle.pipe(Bundle.withView(FormView.submodel(EditPost, View)))\n * ```\n */\n submodel: <\n Key extends string,\n Model extends { readonly errors: ReadonlyArray<string> },\n Message extends { readonly _tag: string },\n >(\n form: FormLike<Key, Model, Message>,\n view: SlotView.SlotView<typeof FormSlots, FormInput<Model, Key>, Message>,\n ): Submodel.View<Model, Message, FormViewInputs<Key>> =>\n Submodel.defineView<Model, Message, FormViewInputs<Key>>((model, inputs, h) =>\n view({ ...inputs, model, errors: model.errors, canSubmit: form.canSubmit(model) }, h),\n ),\n}\n"],"mappings":";;;;;;;;;;;;;AAmGA,MAAM,UAAU;CACd,YAAY,WAAW;CACvB,QAAQ,CAAC,MAAM,OAAO,MAAM,IAAI;CAChC,YAAY,CAAC,KAAK,aAAa,KAAK,eAAe;AACrD;;AAGA,MAAa,aAAa,MAAM,OAAO;CACrC,MAAM,KAAK,KAAK,EAAE,YAAY,WAAW,UAAU,CAAC;CACpD,OAAO,KAAK,KAAK,EAAE,YAAY,WAAW,KAAK,CAAC;CAChD,aAAa,KAAK,KAAK,EAAE,YAAY,WAAW,KAAK,CAAC;CACtD,OAAO,KAAK,KAAK,EAAE,YAAY,WAAW,KAAK,CAAC;CAChD,MAAM,KAAK,KAAK,OAAO;CACvB,WAAW,KAAK,KAAK,OAAO;CAC5B,QAAQ,KAAK,KAAK,OAAO;CACzB,QAAQ,KAAK,KAAK;EAChB,YAAY,WAAW;EACvB,QAAQ,CAAC,MAAM,OAAO,MAAM,IAAI;EAChC,YAAY,CAAC,KAAK,aAAa,KAAK,eAAe;CACrD,CAAC;;CAED,QAAQ,KAAK,KAAK;EAChB,YAAY,WAAW;EACvB,QAAQ,CAAC,MAAM,QAAQ,MAAM,IAAI;EACjC,YAAY,CAAC,KAAK,aAAa,KAAK,eAAe;CACrD,CAAC;;CAED,SAAS,KAAK,KAAK,EAAE,YAAY,WAAW,WAAW,CAAC;CACxD,QAAQ,KAAK,KAAK;EAAE,YAAY,WAAW;EAAa,QAAQ,CAAC,MAAM,KAAK;CAAE,CAAC;;CAE/E,QAAQ,KAAK,KAAK;EAAE,YAAY,WAAW;EAAW,QAAQ,CAAC,MAAM,KAAK;CAAE,CAAC;AAC/E,CAAC;;AAGD,MAAa,YAAY,MAAM,OAAO;CACpC,MAAM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AAU,KAAK;CAAE,GAAG,CAAC,CACtF;AACJ"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * `foldkit-mixins-form` — a `foldkit-form` form drawn through slots.\n *\n * `foldkit-form` describes each control and draws nothing. This package draws\n * them as plain, accessible HTML and publishes every element as a Slot, so an\n * application styles and extends a generated form the way it does any other\n * SlotView, and the form stays free of a view dependency.\n */\nimport {\n Input,\n fillWords,\n type Control,\n type Draft,\n type FormControl,\n type FormRow,\n type NestedForm,\n} from 'foldkit-form'\nimport {\n Attr,\n Capability,\n Event,\n Slot,\n Slots,\n SlotView,\n Style,\n type NamedStyle,\n type SlotBuilders,\n} from 'foldkit-mixins'\nimport * as FieldValidation from 'foldkit/fieldValidation'\nimport type { Attribute, Html, HtmlBuilder } from 'foldkit/html'\nimport * as Submodel from 'foldkit/submodel'\n\n/** One thing a select or a relation picker offers. */\nexport interface Option {\n readonly value: string\n readonly label: string\n}\n\n/**\n * The words the drawn form says itself. Its keys are its own, so one object can\n * hold these, `foldkit-mixins-crud`'s `ViewWords`, and a form's `FormMessages`:\n * an application's words, written and translated in one place. They are text\n * with blanks (`{label}`), never functions: Foldkit admits no function nested in\n * a placed view's inputs.\n */\nexport interface FormViewWords {\n /** On the submit button. Default `Submit`. */\n readonly submit?: string | undefined\n /** Before the label on a picker's search box (`Search Author`). Default `Search`. */\n readonly search?: string | undefined\n /** The choice of nothing, in a picker that may be left empty. Default: blank. */\n readonly none?: string | undefined\n /** On the button that adds a row to a nested key. Default `Add {label}`. */\n readonly add?: string | undefined\n /** On the button that removes a row; `{position}` counts from 1. Default `Remove {label} {position}`. */\n readonly remove?: string | undefined\n /** Under a control while its check runs. Default `Checking…`. */\n readonly checking?: string | undefined\n /** On the submit button while the form is submitting. Default `Submitting…`. */\n readonly submitting?: string | undefined\n}\n\n/**\n * What the view needs that the form does not own: the choices of each relation\n * picker (a query the application makes), and the submit button's words.\n */\nexport interface FormViewInputs<Key extends string = string> {\n readonly options?: { readonly [K in Key]?: ReadonlyArray<Option> } | undefined\n /**\n * The choices of a picker inside a nested key, by its path, the same for every\n * row: `'author.country'`.\n */\n readonly nestedOptions?: Readonly<Record<string, ReadonlyArray<Option>>> | undefined\n /**\n * What a control backed by a Bundle is drawn with, by key: its view's inputs,\n * such as the page Builder's `BuilderView.inputs({ data })`. A key in a nested\n * row is named by its path, as in `nestedOptions`. Keyed by text, as those\n * paths are, and typed where each entry is made, since only the control's\n * Bundle knows its view's inputs.\n */\n readonly controls?: Readonly<Record<string, unknown>> | undefined\n /** The view's own words, for wording and for translation. */\n readonly words?: FormViewWords | undefined\n /**\n * Whether the form is drawn with its submit button. Default: it is. `false`\n * for someone who may not submit it, such as a writer where submitting\n * publishes, so what would be refused is not offered.\n */\n readonly submits?: boolean | undefined\n /**\n * Whether the application's own work with a submitted value is in flight, such\n * as its request: the form hands the value over and cannot see what follows.\n */\n readonly submitting?: boolean | undefined\n}\n\n/** What a field's Style and Behavior attachments may read. */\nexport interface FieldInput<Key extends string = string> {\n readonly control: FormControl<Key>\n readonly field: FieldValidation.Field<Draft>\n readonly invalid: boolean\n readonly errors: ReadonlyArray<string>\n readonly options: ReadonlyArray<Option>\n /** Unique within the form, for `label for`, and as the prefix of the ids beside it. */\n readonly id: string\n /** The word before the label on its search box: the view's `words.search`. */\n readonly searchWord?: string | undefined\n /** The choice of nothing in a picker: the view's `words.none`. */\n readonly noneWord?: string | undefined\n /** What is said while the key's check runs: the view's `words.checking`. */\n readonly checkingWord?: string | undefined\n /**\n * Set for a field in a row of a nested key: its Messages, wrapped for the row.\n * A field of the form itself sends the form's own.\n */\n readonly send?:\n | {\n readonly changed: (value: Draft) => unknown\n readonly blurred: unknown\n readonly searched: (text: string) => unknown\n }\n | undefined\n /**\n * Set for a key edited by a control backed by a Bundle (`Input.bundle`): the\n * Bundle's Model, and the Message that carries one of its own. Such a key has\n * no draft, so `field.value` is `''`; its validation state is `field`'s.\n */\n readonly bundle?: BundleInput | undefined\n /** What was typed to find a choice, for a relation picker that searches. */\n readonly search: string\n /**\n * Whether the key is still written from the key it follows. A renderer offers\n * \"regenerate\" when it is not, by sending the key an empty draft.\n */\n readonly following: boolean\n}\n\n/** A control backed by a Bundle, as its field is drawn: its Model, and how its Messages leave. */\nexport interface BundleInput {\n readonly model: unknown\n readonly send: (message: unknown) => unknown\n /** What the view's `controls` gives this key, for the Bundle's own view. */\n readonly viewInputs?: unknown\n}\n\n/** What the form's own Style and Behavior attachments may read. */\nexport interface FormInput<Model, Key extends string = string> extends FormViewInputs<Key> {\n readonly model: Model\n readonly errors: ReadonlyArray<string>\n readonly canSubmit: boolean\n /**\n * Whether the form is submitting: a submit waits for a check, or the\n * application's work with the value is in flight. `FormView.submodel` reads both.\n */\n readonly submitting?: boolean | undefined\n}\n\nconst textual = {\n capability: Capability.TextInput,\n events: [Event.Input, Event.Blur],\n attributes: [Attr.AriaInvalid, Attr.AriaDescribedby],\n} as const\n\n/** One field: the control for a key, and what stands around it. */\nexport const FieldSlots = Slots.define({\n root: Slot.make({ capability: Capability.Container }),\n label: Slot.make({ capability: Capability.Base }),\n description: Slot.make({ capability: Capability.Base }),\n error: Slot.make({ capability: Capability.Base }),\n /** Says the key's check is running, while it runs. The control names it in `aria-describedby`. */\n checking: Slot.make({ capability: Capability.Base }),\n text: Slot.make(textual),\n multiline: Slot.make(textual),\n number: Slot.make(textual),\n toggle: Slot.make({\n capability: Capability.Interactive,\n events: [Event.Click, Event.Blur],\n attributes: [Attr.AriaInvalid, Attr.AriaDescribedby],\n }),\n /** A `Select`, and a `RelationOne` picker. */\n select: Slot.make({\n capability: Capability.Focusable,\n events: [Event.Change, Event.Blur],\n attributes: [Attr.AriaInvalid, Attr.AriaDescribedby],\n }),\n /** One choice of a `select`. */\n option: Slot.make({ capability: Capability.Base }),\n /** Around the view of a control backed by a Bundle, when it is drawn with the Bundle's own view. */\n control: Slot.make({ capability: Capability.Container }),\n /** Around a control and its affixes, such as an address's prefix and its input. */\n group: Slot.make({ capability: Capability.Container }),\n /** Text beside a control, before or after it: a prefix, or a unit. */\n affix: Slot.make({ capability: Capability.Base }),\n /** A `RelationMany` picker: the group, and each thing in it. */\n choices: Slot.make({ capability: Capability.Collection }),\n choice: Slot.make({ capability: Capability.Interactive, events: [Event.Click] }),\n /** Around one choice's checkbox and its words. */\n choiceLabel: Slot.make({ capability: Capability.Base }),\n /** Over a relation picker that searches: where the user types to find a choice. */\n search: Slot.make({ capability: Capability.TextInput, events: [Event.Input] }),\n})\n\n/** The form around its fields. */\nexport const FormSlots = Slots.define({\n root: Slot.make({ capability: Capability.Container, events: [Event.Submit] }),\n /** Failures that belong to no one field: a rule that spans keys. */\n errors: Slot.make({ capability: Capability.Base }),\n submit: Slot.make({\n capability: Capability.Interactive,\n events: [Event.Click],\n attributes: [Attr.Disabled],\n }),\n /** A nested key: the group around its rows, its name, each row, and the buttons that add and remove one. */\n group: Slot.make({ capability: Capability.Container }),\n legend: Slot.make({ capability: Capability.Base }),\n row: Slot.make({ capability: Capability.Container }),\n add: Slot.make({ capability: Capability.Interactive, events: [Event.Click] }),\n remove: Slot.make({ capability: Capability.Interactive, events: [Event.Click] }),\n})\n\n/** The parts of a `Form.make` result the view reads. */\ninterface FormLike<Key extends string, Model, Message> {\n /** Every key, nested ones too; `Key` is the keys that hold a draft. */\n readonly controls: ReadonlyArray<FormControl>\n readonly field: (model: Model, key: Key) => FieldValidation.Field<Draft>\n /** A key edited by a control backed by a Bundle. A form with none takes no key here. */\n readonly control: (key: never) => {\n readonly field: (model: Model) => FieldValidation.Field<unknown>\n }\n /** The rows of a nested key. A form with none takes no key here. */\n readonly rows: (model: Model, key: never) => ReadonlyArray<FormRow>\n readonly search: (model: Model, key: Key) => string\n readonly isFollowing: (model: Model, key: Key) => boolean\n readonly canSubmit: (model: Model) => boolean\n readonly Message: {\n /** The union, so `Message` is inferred from it and not from one constructor's case. */\n readonly Type: Message\n readonly Changed: (payload: { readonly key: Key; readonly value: Draft }) => NoInfer<Message>\n readonly Blurred: (payload: { readonly key: Key }) => NoInfer<Message>\n readonly Searched: (payload: { readonly key: Key; readonly text: string }) => NoInfer<Message>\n readonly Submitted: () => NoInfer<Message>\n readonly Control: (payload: {\n readonly key: never\n readonly message: unknown\n }) => NoInfer<Message>\n readonly Nested: (payload: {\n readonly key: string\n readonly row: string\n readonly message: unknown\n }) => NoInfer<Message>\n readonly RowAdded: (payload: { readonly key: string }) => NoInfer<Message>\n readonly RowRemoved: (payload: {\n readonly key: string\n readonly row: string\n }) => NoInfer<Message>\n }\n}\n\n/**\n * A form or a row of one, as the view walks it: what to draw, and how each\n * Message leaves. A row's Messages leave wrapped, once per form they pass through.\n */\ninterface Walk<Message> {\n readonly controls: ReadonlyArray<FormControl>\n readonly field: (key: string) => FieldValidation.Field<Draft>\n /** The state of a key edited by a control backed by a Bundle, its Model as the value. */\n readonly controlField: (key: string) => FieldValidation.Field<unknown>\n readonly rows: (key: string) => ReadonlyArray<FormRow>\n readonly search: (key: string) => string\n readonly following: (key: string) => boolean\n readonly wrap: (message: unknown) => Message\n readonly make: NestedForm['Message']\n}\n\nconst rowWalk = <Message>(\n parent: Walk<Message>,\n key: string,\n row: FormRow,\n form: NestedForm,\n): Walk<Message> => ({\n controls: form.controls as ReadonlyArray<FormControl>,\n field: inner =>\n (form.field as (model: unknown, key: string) => FieldValidation.Field<Draft>)(row.model, inner),\n controlField: inner =>\n (\n form.control as (key: string) => {\n readonly field: (model: unknown) => FieldValidation.Field<unknown>\n }\n )(inner).field(row.model),\n rows: inner =>\n (form.rows as (model: unknown, key: string) => ReadonlyArray<FormRow>)(row.model, inner),\n search: inner => (form.search as (model: unknown, key: string) => string)(row.model, inner),\n following: inner =>\n (form.isFollowing as (model: unknown, key: string) => boolean)(row.model, inner),\n wrap: message =>\n parent.wrap(\n (parent.make.Nested as (payload: object) => unknown)({ key, row: row.id, message }),\n ),\n make: form.Message,\n})\n\ntype FieldView<Key extends string, Message> = SlotView.SlotView<\n typeof FieldSlots,\n FieldInput<Key>,\n Message\n>\n\nconst errorsOf = (field: FieldValidation.Field<unknown>): ReadonlyArray<string> =>\n field._tag === 'Invalid' ? field.errors : []\n\n/**\n * The state of a key a control backed by a Bundle edits, as a field is drawn:\n * its validation state, with no draft. The Bundle's Model travels as `bundle`.\n */\nconst withoutDraft = (field: FieldValidation.Field<unknown>): FieldValidation.Field<Draft> =>\n field._tag === 'Invalid'\n ? FieldValidation.Invalid({ value: '', errors: field.errors })\n : field._tag === 'Valid'\n ? FieldValidation.Valid({ value: '' })\n : field._tag === 'Validating'\n ? FieldValidation.Validating({ value: '' })\n : FieldValidation.NotValidated({ value: '' })\n\n/** What a renderer draws one control from. */\nexport interface RenderContext<Message> {\n readonly input: FieldInput\n /** The control, whose `data` is its kind's: narrow it with the kind's `is`. */\n readonly control: Control\n readonly draft: Draft\n readonly change: (value: Draft) => Message\n readonly blurred: Message\n /**\n * For a control backed by a Bundle: its Model, and the Message carrying one of\n * its own. Its `draft` is `''`.\n */\n readonly bundle:\n | {\n readonly model: unknown\n readonly send: (message: unknown) => Message\n /** The inputs its view is drawn with: the form view's `controls` entry for this key. */\n readonly viewInputs: unknown\n }\n | undefined\n /** The control's id and its accessibility state. Put them on the element that holds the value. */\n readonly state: ReadonlyArray<Attribute<Message>>\n /** What the key's element takes beyond the base field view. */\n readonly attrs: FieldAttrs\n readonly slots: SlotBuilders<typeof FieldSlots, Message>\n readonly h: HtmlBuilder<Message>\n}\n\n/** Draws the control of one kind. The label, description and error around it are the field's. */\nexport type Renderer<Message> = (context: RenderContext<Message>) => Html\n\n/**\n * A control backed by a Bundle that no renderer names is drawn with the\n * Bundle's own view, inside the field's `control` slot, which carries the\n * control's id and accessibility state. A Bundle with no view needs a renderer.\n */\nconst bundleRenderer =\n <Message>(control: Control): Renderer<Message> =>\n ({ bundle, input, state, slots, h }) => {\n const view = Input.isBundle(control) ? control.data.bundle.view : undefined\n if (bundle === undefined || view === undefined)\n throw new Error(\n `FormView: the \"${control.kind}\" control (\"${input.control.key}\") has no view; pass a renderer under \"renderers\"`,\n )\n return h.div(slots.control.attrs(state.filter(attribute => attribute._tag !== 'Name')), [\n h.submodel(\n bundle.viewInputs === undefined\n ? { slotId: input.id, model: bundle.model, view, toParentMessage: bundle.send }\n : // A Bundle's view takes the inputs its application gives it in `controls`,\n // whose type the form cannot know. A view given inputs is called with them.\n ({\n slotId: input.id,\n model: bundle.model,\n view,\n toParentMessage: bundle.send,\n viewInputs: bundle.viewInputs,\n } as Parameters<typeof h.submodel>[0]),\n ),\n ])\n }\n\n/** Renderers by the `kind` of control they draw. */\nexport type Renderers<Message> = Readonly<Record<string, Renderer<Message>>>\n\n/**\n * The renderers this package ships, by kind. They are entries like any other: an\n * application adds `Date`, or replaces `RelationOne` with a combobox, by passing\n * its own beside them.\n */\n/**\n * The choices, and after them each chosen value they lack, as `? value`: a\n * stored id whose row is gone, or a value the choices have not loaded yet,\n * stays shown and can be let go, rather than dropped from sight.\n */\nconst withChosen = (\n options: ReadonlyArray<Option>,\n chosen: ReadonlyArray<string>,\n): ReadonlyArray<Option> => {\n const known = new Set(options.map(option => option.value))\n return [\n ...options,\n ...chosen\n .filter(value => value !== '' && !known.has(value))\n .map(value => ({ value, label: `? ${value}` })),\n ]\n}\n\nconst defaultRenderers = <Message>(): Renderers<Message> => {\n const typed = ({ state, draft, change, blurred, h }: RenderContext<Message>) => [\n ...state,\n h.Value(String(draft)),\n h.OnInput(change),\n h.OnBlur(blurred),\n ]\n // A blank option whenever nothing is chosen, required or not: without one the\n // browser shows its first option as chosen while the draft is still empty.\n const pick = (\n { state, draft, change, blurred, input, slots, h }: RenderContext<Message>,\n options: ReadonlyArray<Option>,\n blank: boolean,\n ): Html =>\n h.select(slots.select.attrs([...state, h.OnChange(change), h.OnBlur(blurred)]), [\n ...(blank || draft === ''\n ? [\n h.option(slots.option.attrs([h.Value(''), h.Selected(draft === '')]), [\n input.noneWord ?? '',\n ]),\n ]\n : []),\n ...withChosen(options, typeof draft === 'string' ? [draft] : []).map(option =>\n h.option(slots.option.attrs([h.Value(option.value), h.Selected(draft === option.value)]), [\n option.label,\n ]),\n ),\n ])\n return {\n [Input.Text.kind]: context =>\n context.h.input(\n context.slots.text.attrs([\n ...typed(context),\n context.h.Type(context.attrs.type ?? 'text'),\n ...(context.attrs.placeholder === undefined\n ? []\n : [context.h.Placeholder(context.attrs.placeholder)]),\n ]),\n ),\n [Input.Multiline.kind]: context =>\n // A textarea's attributes exclude `InnerHTML`, which a slot's type admits\n // and no mixin can supply, so the narrowing loses nothing.\n context.h.textarea(\n context.slots.multiline.attrs([\n ...typed(context),\n ...(context.attrs.placeholder === undefined\n ? []\n : [context.h.Placeholder(context.attrs.placeholder)]),\n ...(context.attrs.rows === undefined\n ? []\n : [context.h.Attribute('rows', String(context.attrs.rows))]),\n ]) as Parameters<typeof context.h.textarea>[0],\n ),\n // A number is a text input because its draft is text: `\"4.\"` is a fine thing to\n // have typed, and `type=\"number\"` would refuse to report it.\n [Input.Number.kind]: context =>\n context.h.input(\n context.slots.number.attrs([\n ...typed(context),\n context.h.Type('text'),\n context.h.InputMode('decimal'),\n ...(context.attrs.placeholder === undefined\n ? []\n : [context.h.Placeholder(context.attrs.placeholder)]),\n ]),\n ),\n [Input.Toggle.kind]: ({ state, draft, change, blurred, slots, h }) =>\n h.input(\n slots.toggle.attrs([\n ...state,\n h.Type('checkbox'),\n h.Checked(draft === true),\n h.OnClick(change(draft !== true)),\n h.OnBlur(blurred),\n ]),\n ),\n [Input.Select.kind]: context =>\n pick(\n context,\n (Input.Select.is(context.control) ? context.control.data.options : []).map(option => ({\n value: String(option),\n label: String(option),\n })),\n !context.input.control.required,\n ),\n [Input.RelationOne.kind]: context => pick(context, context.input.options, true),\n [Input.RelationMany.kind]: ({ input, draft, change, slots, h }) => {\n const chosen = Array.isArray(draft) ? (draft as ReadonlyArray<string>) : []\n const isChosen = new Set(chosen)\n return h.div(\n slots.choices.attrs([h.Id(input.id), h.Role('group'), h.AriaLabel(input.control.label)]),\n withChosen(input.options, chosen).map(option =>\n h.label(slots.choiceLabel.attrs(), [\n h.input(\n slots.choice.attrs([\n h.Type('checkbox'),\n h.Name(input.control.key),\n h.Value(option.value),\n h.Checked(isChosen.has(option.value)),\n h.OnClick(\n change(\n isChosen.has(option.value)\n ? chosen.filter(value => value !== option.value)\n : [...chosen, option.value],\n ),\n ),\n ]),\n ),\n option.label,\n ]),\n ),\n )\n },\n }\n}\n\n/**\n * What a per-key override receives: everything to draw the control, and the\n * Messages that leave it, in the form's own universe. The `h` an override\n * draws with stays the caller's: the whole-form view's, or a custom layout's.\n */\nexport interface FieldOverrideInput<Key extends string = string, Changed = unknown> {\n readonly control: FormControl<Key>\n readonly field: FieldValidation.Field<Draft>\n readonly id: string\n readonly invalid: boolean\n readonly errors: ReadonlyArray<string>\n readonly changed: (value: Draft) => Changed\n readonly blurred: Changed\n /** What the key's element takes beyond the base field view. */\n readonly attrs: FieldAttrs\n}\n\n/**\n * Draws one key's control, for a layout the base field view does not own.\n * `Changed` is the form's Message; `Message` the universe of the `h` that\n * draws, which is the form's in the whole-form view and the application's\n * in a custom layout.\n */\nexport type FieldOverride<Key extends string = string, Changed = unknown, Message = unknown> = (\n input: FieldOverrideInput<Key, Changed>,\n h: HtmlBuilder<Message>,\n) => Html\n\n/**\n * What one key's element takes beyond the base field view: an HTML input\n * type, a placeholder, a textarea's rows. A renderer reads what fits its\n * element and ignores the rest.\n */\nexport interface FieldAttrs {\n readonly type?: string | undefined\n readonly placeholder?: string | undefined\n readonly rows?: number | undefined\n}\n\n/**\n * Per-key overrides for `FormView.fields`. `overrides` draw through the\n * whole-form view; `styles` style one key's base field view there. Unknown\n * keys in either are type errors. A custom layout passes its override to\n * `field` itself, with its own `h`.\n */\nexport interface FieldsOptions<Key extends string, Changed> {\n /** A key drawn by this instead of the base field view (or its styled one). */\n readonly overrides?: { readonly [K in Key]?: FieldOverride<Key, Changed, Changed> } | undefined\n /** A style around a key's base field view, kept for keys with no override. */\n readonly styles?: { readonly [K in Key]?: NamedStyle<typeof FieldSlots> } | undefined\n /**\n * What one key's element takes beyond the base field view. Only the\n * text, multiline, and number renderers read attrs; bundle-backed kinds\n * (drawn by `bundleRenderer`) and per-key overrides ignore them. Passing\n * `field` draws through it directly, skipping both `renderers` and `attrs`.\n */\n readonly attrs?: { readonly [K in Key]?: FieldAttrs } | undefined\n}\n\n/**\n * One flat key's control, for a layout the caller owns: through the base\n * field view with a form-universe `h`, or through the override it is given,\n * with any `h`. A call with neither a form `h` nor an override is a type\n * error, since the base view's Messages are the form's own.\n */\nexport interface FieldsField<\n Key extends string,\n Model,\n FormMessage extends { readonly _tag: string },\n> {\n (\n control: FormControl<Key>,\n model: Model,\n id: string,\n h: HtmlBuilder<FormMessage>,\n override?: FieldOverride<Key, FormMessage, FormMessage>,\n ): Html\n <Message>(\n control: FormControl<Key>,\n model: Model,\n id: string,\n h: HtmlBuilder<Message>,\n override: FieldOverride<Key, FormMessage, Message>,\n ): Html\n}\n\n/** The Messages of one key, through its row's send or the form's own. */\nconst changedOf =\n <Key extends string, Model, Message>(\n form: FormLike<Key, Model, Message>,\n key: Key,\n send: FieldInput<Key>['send'],\n ): ((value: Draft) => Message) =>\n value =>\n (send === undefined ? form.Message.Changed({ key, value }) : send.changed(value)) as Message\n\n/** The blur Message of one key, through its row's send or the form's own. */\nconst blurredOf = <Key extends string, Model, Message>(\n form: FormLike<Key, Model, Message>,\n key: Key,\n send: FieldInput<Key>['send'],\n): Message => (send === undefined ? form.Message.Blurred({ key }) : send.blurred) as Message\n\n/** The view of one field, to style or extend before handing it to `FormView.define`. */\nconst field = <Key extends string, Model, Message extends { readonly _tag: string }>(\n form: FormLike<Key, Model, Message>,\n options: {\n /** Renderers by kind, beside the ones shipped: a new kind, or another way to draw a shipped one. */\n readonly renderers?: Renderers<Message>\n /** What one key's element takes beyond the base field view. */\n readonly attrs?: { readonly [K in Key]?: FieldAttrs }\n } = {},\n): FieldView<Key, Message> => {\n const renderers: Renderers<Message> = { ...defaultRenderers<Message>(), ...options.renderers }\n return SlotView.forMessages<Message>().define(\n FieldSlots,\n (input: FieldInput<Key>, slots, h) => {\n const { control, id, invalid } = input\n const { key, label, description, required } = control\n const draft = input.field.value\n const { send } = input\n const change = changedOf(form, key, send)\n const blurred = blurredOf(form, key, send)\n const searched = (text: string): Message =>\n send === undefined ? form.Message.Searched({ key, text }) : (send.searched(text) as Message)\n const searches = control.control.searches\n // A check is running: the control is neither valid nor invalid yet.\n const checking = input.field._tag === 'Validating'\n const describedBy = [\n ...(description === undefined ? [] : [`${id}-description`]),\n ...(checking ? [`${id}-checking`] : []),\n ...(invalid ? [`${id}-error`] : []),\n ]\n const state = [\n h.Id(id),\n // The key is the field's name, so a form posts its drafts with scripts off.\n h.Name(key),\n h.AriaInvalid(invalid),\n ...(checking ? [h.AriaBusy(true)] : []),\n ...(required ? [h.AriaRequired(true)] : []),\n ...(describedBy.length === 0 ? [] : [h.AriaDescribedBy(describedBy.join(' '))]),\n ]\n // The Message leaves the way the input says: wrapped for a row, or the form's own.\n const held = input.bundle\n const bundle =\n held === undefined\n ? undefined\n : {\n model: held.model,\n send: (message: unknown) => held.send(message) as Message,\n viewInputs: held.viewInputs,\n }\n const render =\n renderers[control.control.kind] ??\n (bundle !== undefined ? bundleRenderer<Message>(control.control) : undefined)\n if (render === undefined)\n throw new Error(\n `FormView: no renderer for a \"${control.control.kind}\" control (\"${key}\"); pass one under \"renderers\"`,\n )\n const body = render({\n input: input as FieldInput,\n control: control.control,\n draft,\n change,\n blurred,\n bundle,\n state,\n attrs: options.attrs?.[key] ?? {},\n slots,\n h,\n })\n\n // The field's state by Foldkit's own tag, for a stylesheet: `[data-validation='Valid']`.\n return h.div(slots.root.attrs([h.DataAttribute('validation', input.field._tag)]), [\n h.label(slots.label.attrs([h.For(id)]), [label]),\n // Typing here changes which choices the picker below is offered.\n ...(searches\n ? [\n h.input(\n slots.search.attrs([\n h.Id(`${id}-search`),\n h.Type('search'),\n h.AriaLabel(`${input.searchWord ?? 'Search'} ${label}`),\n h.AriaControls(id),\n h.Value(input.search),\n h.OnInput(searched),\n ]),\n ),\n ]\n : []),\n body,\n ...(description === undefined\n ? []\n : [h.p(slots.description.attrs([h.Id(`${id}-description`)]), [description])]),\n ...(checking\n ? [\n h.p(slots.checking.attrs([h.Id(`${id}-checking`), h.Role('status')]), [\n input.checkingWord ?? 'Checking…',\n ]),\n ]\n : []),\n ...(invalid\n ? [h.p(slots.error.attrs([h.Id(`${id}-error`), h.Role('alert')]), [...input.errors])]\n : []),\n ])\n },\n { name: 'FormField' },\n )\n}\n\nexport const FormView = {\n field,\n\n /**\n * The view of the whole form: each control through `field`, in the input's\n * order, a hidden key left out. Pass a styled `field` to change how fields\n * look; attach Style and Behavior to the result to change the form around them.\n */\n define: <Key extends string, Model, Message extends { readonly _tag: string }>(\n form: FormLike<Key, Model, Message> & { readonly bundle: { readonly name: string } },\n options: {\n readonly field?: FieldView<Key, Message>\n /** Renderers by kind, for the field view this makes. With `field` given, give them to `FormView.field`. */\n readonly renderers?: Renderers<Message>\n } = {},\n ): SlotView.SlotView<typeof FormSlots, FormInput<Model, Key>, Message> => {\n const fieldView =\n options.field ??\n field(form, options.renderers === undefined ? {} : { renderers: options.renderers })\n type Make = (payload: object) => unknown\n return SlotView.forMessages<Message>().define(\n FormSlots,\n (input: FormInput<Model, Key>, slots, h) => {\n const options: Readonly<Record<string, ReadonlyArray<Option> | undefined>> = {\n ...input.nestedOptions,\n ...input.options,\n }\n const controls: Readonly<Record<string, unknown>> = input.controls ?? {}\n\n /** The controls of a form or of a row. `id` and `path` say where: both are empty for the form itself. */\n const draw = (walk: Walk<Message>, id: string, path: string): ReadonlyArray<Html> =>\n walk.controls\n .filter(control => control.control.shown)\n .map((control): Html => {\n const { key, label } = control\n const here = `${id}-${key}`\n if (!Input.Nested.is(control.control)) {\n const bundled = Input.isBundle(control.control)\n const held = bundled ? walk.controlField(key) : walk.field(key)\n const state = bundled ? withoutDraft(held) : (held as FieldValidation.Field<Draft>)\n return fieldView(\n {\n control: control as FormControl<Key>,\n field: state,\n bundle: bundled\n ? {\n model: held.value,\n send: message => walk.wrap((walk.make.Control as Make)({ key, message })),\n viewInputs: controls[`${path}${key}`],\n }\n : undefined,\n invalid: FieldValidation.isInvalid(state),\n errors: errorsOf(state),\n options: options[`${path}${key}`] ?? [],\n id: here,\n search: walk.search(key),\n following: walk.following(key),\n searchWord: input.words?.search,\n noneWord: input.words?.none,\n checkingWord: input.words?.checking,\n send: {\n changed: value => walk.wrap((walk.make.Changed as Make)({ key, value })),\n blurred: walk.wrap((walk.make.Blurred as Make)({ key })),\n searched: text => walk.wrap((walk.make.Searched as Make)({ key, text })),\n },\n },\n h,\n )\n }\n const { form: nested, cardinality, optional } = control.control.data\n const rows = walk.rows(key)\n const addLabel = fillWords(input.words?.add ?? 'Add {label}', { label })\n return h.fieldset(slots.group.attrs([h.Id(here)]), [\n h.legend(slots.legend.attrs(), [label]),\n ...rows.map((row, index) =>\n h.div(slots.row.attrs([h.Id(`${here}-${row.id}`)]), [\n ...draw(rowWalk(walk, key, row, nested), `${here}-${row.id}`, `${path}${key}.`),\n // A row that must be there has no way out.\n ...(optional\n ? [\n h.button(\n slots.remove.attrs([\n h.Type('button'),\n h.OnClick(\n walk.wrap((walk.make.RowRemoved as Make)({ key, row: row.id })),\n ),\n ]),\n [\n fillWords(input.words?.remove ?? 'Remove {label} {position}', {\n label,\n position: index + 1,\n }),\n ],\n ),\n ]\n : []),\n ]),\n ),\n // A `one` takes one row: the way in goes once it is there.\n ...(cardinality === 'many' || rows.length === 0\n ? [\n h.button(\n slots.add.attrs([\n h.Type('button'),\n h.OnClick(walk.wrap((walk.make.RowAdded as Make)({ key }))),\n ]),\n [addLabel],\n ),\n ]\n : []),\n ])\n })\n\n const top: Walk<Message> = {\n controls: form.controls,\n field: key => form.field(input.model, key as Key),\n controlField: key => form.control(key as never).field(input.model),\n rows: key => form.rows(input.model, key as never),\n search: key => form.search(input.model, key as Key),\n following: key => form.isFollowing(input.model, key as Key),\n wrap: message => message as Message,\n make: form.Message as unknown as NestedForm['Message'],\n }\n const submitting = input.submitting === true\n return h.form(\n slots.root.attrs([\n h.OnSubmit(form.Message.Submitted()),\n ...(submitting ? [h.AriaBusy(true), h.DataAttribute('submitting', '')] : []),\n ]),\n [\n ...draw(top, form.bundle.name, ''),\n ...(input.errors.length === 0\n ? []\n : [h.p(slots.errors.attrs([h.Role('alert')]), [...input.errors])]),\n ...(input.submits === false\n ? []\n : [\n h.button(\n slots.submit.attrs([\n h.Type('submit'),\n h.Disabled(!input.canSubmit || submitting),\n ]),\n [\n submitting\n ? (input.words?.submitting ?? 'Submitting…')\n : (input.words?.submit ?? 'Submit'),\n ],\n ),\n ]),\n ],\n )\n },\n { name: form.bundle.name },\n )\n },\n\n /**\n * The whole form, as `define` draws it, with per-key overrides; and one flat\n * key's control, for a layout the caller owns. Keys with no override render\n * through the base field view (a new key of a known kind needs nothing new),\n * each through its style when one is given and with its element attrs. `field`\n * draws through the base view with a form-universe `h`, or through the\n * override it is given, with any `h`. Nested keys and Bundle-backed keys draw\n * only through `view` (or an override); `field` without one refuses them,\n * naming the key.\n */\n fields: <Key extends string, Model, FormMessage extends { readonly _tag: string }>(\n form: FormLike<Key, Model, FormMessage> & { readonly bundle: { readonly name: string } },\n options: {\n readonly field?: FieldView<Key, FormMessage>\n /** Renderers by kind, for the field views this makes. */\n readonly renderers?: Renderers<FormMessage>\n } & FieldsOptions<Key, FormMessage> = {},\n ): {\n readonly view: SlotView.SlotView<typeof FormSlots, FormInput<Model, Key>, FormMessage>\n readonly field: FieldsField<Key, Model, FormMessage>\n } => {\n const base =\n options.field ??\n field(\n form,\n options.renderers === undefined && options.attrs === undefined\n ? {}\n : {\n ...(options.renderers === undefined ? {} : { renderers: options.renderers }),\n ...(options.attrs === undefined ? {} : { attrs: options.attrs }),\n },\n )\n const styled = new Map<Key, FieldView<Key, FormMessage>>()\n const viewOf = (key: Key): FieldView<Key, FormMessage> => {\n const known = styled.get(key)\n if (known !== undefined) return known\n const style = options.styles?.[key]\n const made = style === undefined ? base : Style.attach(style)(base)\n styled.set(key, made)\n return made\n }\n const drawn = (input: FieldInput<Key>, h: HtmlBuilder<FormMessage>): Html => {\n const override = options.overrides?.[input.control.key]\n if (override === undefined) return viewOf(input.control.key)(input, h)\n return override(\n {\n control: input.control,\n field: input.field,\n id: input.id,\n invalid: input.invalid,\n errors: input.errors,\n changed: changedOf(form, input.control.key, input.send),\n blurred: blurredOf(form, input.control.key, input.send),\n attrs: options.attrs?.[input.control.key] ?? {},\n },\n h,\n )\n }\n return {\n view: FormView.define(form, {\n field: SlotView.forMessages<FormMessage>().define(\n FieldSlots,\n (input: FieldInput<Key>, _slots, h) => drawn(input, h),\n { name: `${form.bundle.name}Fields` },\n ),\n }),\n field: (<M>(\n control: FormControl<Key>,\n model: Model,\n id: string,\n h: HtmlBuilder<M> | HtmlBuilder<FormMessage>,\n override?: FieldOverride<Key, FormMessage, M>,\n ): Html => {\n const state = form.field(model, control.key)\n if (override !== undefined)\n return override(\n {\n control,\n field: state,\n id,\n invalid: FieldValidation.isInvalid(state),\n errors: errorsOf(state),\n changed: value => form.Message.Changed({ key: control.key, value }),\n blurred: form.Message.Blurred({ key: control.key }),\n attrs: options.attrs?.[control.key] ?? {},\n },\n h as HtmlBuilder<M>,\n )\n if (Input.Nested.is(control.control) || Input.isBundle(control.control))\n throw new Error(\n `FormView.fields: \"${control.key}\" nests rows or a Bundle; draw it with the whole-form view, or give an override for it`,\n )\n return viewOf(control.key)(\n {\n control,\n field: state,\n bundle: undefined,\n invalid: FieldValidation.isInvalid(state),\n errors: errorsOf(state),\n options: [],\n id,\n search: form.search(model, control.key),\n following: form.isFollowing(model, control.key),\n },\n h as HtmlBuilder<FormMessage>,\n )\n }) as FieldsField<Key, Model, FormMessage>,\n }\n },\n\n /**\n * For `Bundle.withView`: the Submodel view that draws `view`, so a placement\n * renders the form with `placed.view(model, h, { options })`.\n *\n * ```ts\n * const Drawn = EditPost.bundle.pipe(Bundle.withView(FormView.submodel(EditPost, View)))\n * ```\n */\n submodel: <\n Key extends string,\n Model extends { readonly errors: ReadonlyArray<string>; readonly submitPending: boolean },\n Message extends { readonly _tag: string },\n >(\n form: FormLike<Key, Model, Message>,\n view: SlotView.SlotView<typeof FormSlots, FormInput<Model, Key>, Message>,\n options: {\n /**\n * When the submit waits instead of staying disabled. `true` while a\n * check is running means submitted work waits for it, and the button\n * stays enabled; `false` keeps the button disabled until every key is\n * valid. Default `form.canSubmit` (lenient): a submit made mid-check\n * waits for it. Pass a strict predicate to disable through checks\n * instead, such as `model => PostForm.engine.value(model.form) !==\n * undefined`, or `() => true` to never pre-disable and validate wholly\n * at submit.\n */\n readonly canSubmit?: (model: Model) => boolean\n } = {},\n ): Submodel.View<Model, Message, FormViewInputs<Key>> =>\n Submodel.defineView<Model, Message, FormViewInputs<Key>>((model, inputs, h) =>\n view(\n {\n ...inputs,\n model,\n errors: model.errors,\n canSubmit: (options.canSubmit ?? form.canSubmit)(model),\n submitting: model.submitPending || inputs.submitting === true,\n },\n h,\n ),\n ),\n}\n"],"mappings":";;;;;;;;;;;;;AA6JA,MAAM,UAAU;CACd,YAAY,WAAW;CACvB,QAAQ,CAAC,MAAM,OAAO,MAAM,IAAI;CAChC,YAAY,CAAC,KAAK,aAAa,KAAK,eAAe;AACrD;;AAGA,MAAa,aAAa,MAAM,OAAO;CACrC,MAAM,KAAK,KAAK,EAAE,YAAY,WAAW,UAAU,CAAC;CACpD,OAAO,KAAK,KAAK,EAAE,YAAY,WAAW,KAAK,CAAC;CAChD,aAAa,KAAK,KAAK,EAAE,YAAY,WAAW,KAAK,CAAC;CACtD,OAAO,KAAK,KAAK,EAAE,YAAY,WAAW,KAAK,CAAC;;CAEhD,UAAU,KAAK,KAAK,EAAE,YAAY,WAAW,KAAK,CAAC;CACnD,MAAM,KAAK,KAAK,OAAO;CACvB,WAAW,KAAK,KAAK,OAAO;CAC5B,QAAQ,KAAK,KAAK,OAAO;CACzB,Q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AO,eAAe;CAC3D,GACA,CACF,CACF;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foldkit-mixins-form",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A foldkit-form form drawn through foldkit-mixins slots: styleable, extensible, and accessible by contract.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"foldkit",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"exports": {
|
|
30
30
|
".": {
|
|
31
|
+
"foldkit-plus:source": "./src/index.ts",
|
|
31
32
|
"types": "./dist/index.d.mts",
|
|
32
33
|
"import": "./dist/index.mjs"
|
|
33
34
|
}
|
|
@@ -38,12 +39,12 @@
|
|
|
38
39
|
"LICENSE"
|
|
39
40
|
],
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"foldkit-bundle": "0.
|
|
42
|
-
"foldkit-form": "0.
|
|
43
|
-
"foldkit-mixins": "0.
|
|
42
|
+
"foldkit-bundle": "0.4.0",
|
|
43
|
+
"foldkit-form": "0.3.0",
|
|
44
|
+
"foldkit-mixins": "0.5.0"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
46
|
-
"effect": "
|
|
47
|
+
"effect": ">=4.0.0-rc.116 <4.0.0-rc.118",
|
|
47
48
|
"foldkit": "^0.163.0"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
@@ -53,7 +54,7 @@
|
|
|
53
54
|
"jsdom": "26.1.0",
|
|
54
55
|
"tsdown": "^0.23.0",
|
|
55
56
|
"typescript": "5.9.3",
|
|
56
|
-
"foldkit-entity": "0.
|
|
57
|
+
"foldkit-entity": "0.5.0"
|
|
57
58
|
},
|
|
58
59
|
"scripts": {
|
|
59
60
|
"build": "tsdown",
|