foldkit-mixins-form 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Patrick Glenn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,138 @@
1
+ # foldkit-mixins-form
2
+
3
+ Draws a [`foldkit-form`](../form/README.md) form as plain, accessible HTML, with
4
+ every element published as a [`foldkit-mixins`](../mixins/README.md) Slot. The
5
+ form decides what is edited and whether it is valid; this package decides which
6
+ elements show it; your Style and Behavior attachments decide how it looks and
7
+ what else it does.
8
+
9
+ ## What it owns
10
+
11
+ | Fact | Owner |
12
+ | --- | --- |
13
+ | The keys, their controls, drafts, and validity | `foldkit-form` |
14
+ | Which element draws each control, and its accessibility wiring | `foldkit-mixins-form` |
15
+ | Classes, inline style, extra attributes and events | your `Style` / `Behavior` attachments |
16
+ | The options of a relation picker, the submit button's words | the application, as view inputs |
17
+
18
+ It holds no state and adds no Messages. Every event it installs dispatches one
19
+ of the form's own Messages (`Changed`, `Blurred`, `Submitted`).
20
+
21
+ ## Mental model
22
+
23
+ ```text
24
+ Form.make(...) the form: controls + bundle (no view)
25
+ |
26
+ FormView.field(form) one field, as a SlotView over FieldSlots
27
+ | .pipe(Style.attach(...))
28
+ FormView.define(form, { field }) the whole form, as a SlotView over FormSlots
29
+ | .pipe(Style.attach(...))
30
+ FormView.submodel(form, view) a Submodel view taking { options, submitLabel }
31
+ |
32
+ form.bundle.pipe(Bundle.withView(...)) the same Bundle, now drawable
33
+ |
34
+ placed.view(model, h, { options })
35
+ ```
36
+
37
+ There are two slot contracts because a form is one thing and its fields are
38
+ many: `FieldSlots` is resolved once per field, with that field as its input, so
39
+ a Style can depend on `input.invalid` or `input.control`.
40
+
41
+ ## Install
42
+
43
+ ```sh
44
+ pnpm add effect foldkit foldkit-bundle foldkit-form foldkit-mixins foldkit-mixins-form
45
+ ```
46
+
47
+ ## Example
48
+
49
+ `Edit` is a `Form.make` result, as in the
50
+ [`foldkit-form` README](../form/README.md#example).
51
+
52
+ ```ts
53
+ import { Bundle } from 'foldkit-bundle'
54
+ import { Style } from 'foldkit-mixins'
55
+ import { FieldSlots, FormSlots, FormView, type FieldInput } from 'foldkit-mixins-form'
56
+
57
+ const Field = FormView.field(Edit).pipe(
58
+ Style.attach(
59
+ Style.forSlots(FieldSlots)({
60
+ root: Style.class('field'),
61
+ text: Style.whenInput<FieldInput>(input => input.invalid, Style.class('is-invalid')),
62
+ }),
63
+ ),
64
+ )
65
+
66
+ const View = FormView.define(Edit, { field: Field }).pipe(
67
+ Style.attach(Style.forSlots(FormSlots)({ root: Style.class('form') })),
68
+ )
69
+
70
+ // The form's own Bundle, given a view. Place this one instead of `Edit.bundle`.
71
+ const Drawn = Edit.bundle.pipe(Bundle.withView(FormView.submodel(Edit, View)))
72
+ ```
73
+
74
+ Then, where the parent draws the placement:
75
+
76
+ ```ts
77
+ EditForm.view(model, h, {
78
+ options: { editorId: authors.map(author => ({ value: author.id, label: author.name })) },
79
+ submitLabel: 'Save',
80
+ })
81
+ ```
82
+
83
+ - `FormView.define(Edit)` alone is a complete, unstyled form. `field` is only
84
+ for changing how fields are drawn.
85
+ - `options` is keyed by the form's keys and is where a relation picker's choices
86
+ come from. The form names the target Entity; listing it is a query you make,
87
+ so the choices are yours to load, filter, and label.
88
+ - A `Hidden` control is not drawn.
89
+
90
+ ## What is drawn
91
+
92
+ | Control | Element | Slot |
93
+ | --- | --- | --- |
94
+ | `Text` | `input type="text"` | `text` |
95
+ | `Multiline` | `textarea` | `multiline` |
96
+ | `Number` | `input type="text" inputmode="decimal"` | `number` |
97
+ | `Toggle` | `input type="checkbox"` | `toggle` |
98
+ | `Select` | `select` of the control's own options, with a blank while nothing is chosen | `select` |
99
+ | `RelationOne` | `select` of `options[key]`, with a blank | `select` |
100
+ | `RelationMany` | a `role="group"` of checkboxes over `options[key]` | `choices`, `choice` |
101
+
102
+ | `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` |
103
+
104
+ A number is a text input because its draft is text: `"4."` is a fine thing to
105
+ have typed, and `type="number"` would refuse to report it.
106
+
107
+ Around each control, `FieldSlots` also publishes `root`, `label`, `description`,
108
+ and `error`. `FormSlots` publishes `root` (the `form`), `errors` (failures that
109
+ belong to no one field), `submit`, and the five slots of a nested key.
110
+
111
+ A nested row's fields are drawn through the same field view, so a styled `field`
112
+ styles them too. A row that must be there has no remove button, and a `one`
113
+ loses its add button once it has its row. View inputs for nested keys:
114
+ `nestedOptions` names a picker inside a row by path (`'author.countryId'`, the
115
+ same for every row), and `addLabel` / `removeLabel` word the buttons (defaults
116
+ `Add <label>`, `Remove <label> <position>`).
117
+
118
+ ### Accessibility
119
+
120
+ Each control has an `id` of `<form name>-<key>` (in a row,
121
+ `<form name>-<key>-<row id>-<key>`) and a `label for` it. It carries
122
+ `aria-busy` while a check runs, `aria-invalid`, `aria-required` when the key is required, and `aria-describedby`
123
+ naming its description and, while invalid, its error. An error is `role="alert"`.
124
+ The submit button is disabled until the form would submit.
125
+
126
+ Those attributes belong to the view: an attachment that also supplies one is an
127
+ attribute conflict, reported when the view renders. The slots declare
128
+ `AriaInvalid` and `AriaDescribedby` so a Behavior can require them.
129
+
130
+ ## Limits
131
+
132
+ - One layout: label, control, description, error, in that order, and fields in
133
+ the input's order. For another arrangement, draw from `form.controls`
134
+ yourself; this package is the default, not the only way.
135
+ - A `select` for a relation suits tens of choices, not thousands. There is no
136
+ search or paging.
137
+ - The Bundle gains a view through `Bundle.withView`, so place the drawn Bundle,
138
+ not `form.bundle`.
@@ -0,0 +1,148 @@
1
+ import { Attr, Capability, Event, Slot, SlotView, Slots } from "foldkit-mixins";
2
+ import * as FieldValidation from "foldkit/fieldValidation";
3
+ import * as Submodel from "foldkit/submodel";
4
+ import { Draft, FormControl, FormRow } from "foldkit-form";
5
+ //#region src/index.d.ts
6
+ /** One thing a select or a relation picker offers. */
7
+ export interface Option {
8
+ readonly value: string;
9
+ readonly label: string;
10
+ }
11
+ /**
12
+ * What the view needs that the form does not own: the choices of each relation
13
+ * picker (a query the application makes), and the submit button's words.
14
+ */
15
+ export interface FormViewInputs<Key extends string = string> {
16
+ readonly options?: { readonly [K in Key]?: ReadonlyArray<Option>; } | undefined;
17
+ /**
18
+ * The choices of a picker inside a nested key, by its path, the same for every
19
+ * row: `'author.country'`.
20
+ */
21
+ readonly nestedOptions?: Readonly<Record<string, ReadonlyArray<Option>>> | undefined;
22
+ readonly submitLabel?: string | undefined;
23
+ /** The words on the button that adds a row to a nested key. Default `Add <label>`. */
24
+ readonly addLabel?: ((label: string) => string) | undefined;
25
+ /** The words on the button that removes a row; `position` counts from 1. Default `Remove <label> <position>`. */
26
+ readonly removeLabel?: ((label: string, position: number) => string) | undefined;
27
+ }
28
+ /** What a field's Style and Behavior attachments may read. */
29
+ export interface FieldInput<Key extends string = string> {
30
+ readonly control: FormControl<Key>;
31
+ readonly field: FieldValidation.Field<Draft>;
32
+ readonly invalid: boolean;
33
+ readonly errors: ReadonlyArray<string>;
34
+ readonly options: ReadonlyArray<Option>;
35
+ /** Unique within the form, for `label for`, and as the prefix of the ids beside it. */
36
+ readonly id: string;
37
+ /**
38
+ * Set for a field in a row of a nested key: its Messages, wrapped for the row.
39
+ * A field of the form itself sends the form's own.
40
+ */
41
+ readonly send?: {
42
+ readonly changed: (value: Draft) => unknown;
43
+ readonly blurred: unknown;
44
+ } | undefined;
45
+ }
46
+ /** What the form's own Style and Behavior attachments may read. */
47
+ export interface FormInput<Model, Key extends string = string> extends FormViewInputs<Key> {
48
+ readonly model: Model;
49
+ readonly errors: ReadonlyArray<string>;
50
+ readonly canSubmit: boolean;
51
+ }
52
+ /** One field: the control for a key, and what stands around it. */
53
+ export declare const FieldSlots: Slots.Contract<{
54
+ readonly root: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
55
+ readonly label: Slot.UnnamedSlot<Capability.Capability<"Base", readonly []>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
56
+ readonly description: Slot.UnnamedSlot<Capability.Capability<"Base", readonly []>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
57
+ readonly error: Slot.UnnamedSlot<Capability.Capability<"Base", readonly []>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
58
+ 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>;
59
+ 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>;
60
+ 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>;
61
+ 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>;
62
+ /** A `Select`, and a `RelationOne` picker. */
63
+ 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>;
64
+ /** A `RelationMany` picker: the group, and each thing in it. */
65
+ readonly choices: Slot.UnnamedSlot<Capability.Capability<"Collection", readonly [Capability.Capability<"Base", readonly []>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
66
+ readonly choice: Slot.UnnamedSlot<Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>, readonly [Event.EventToken<"click">], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
67
+ }>;
68
+ /** The form around its fields. */
69
+ export declare const FormSlots: Slots.Contract<{
70
+ readonly root: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly [Event.EventToken<"submit">], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
71
+ /** Failures that belong to no one field: a rule that spans keys. */
72
+ readonly errors: Slot.UnnamedSlot<Capability.Capability<"Base", readonly []>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
73
+ readonly submit: Slot.UnnamedSlot<Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>, readonly [Event.EventToken<"click">], readonly [Attr.AttrToken<"disabled">], readonly Slot.RequirementName[], boolean>;
74
+ /** A nested key: the group around its rows, its name, each row, and the buttons that add and remove one. */
75
+ 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>;
76
+ readonly legend: Slot.UnnamedSlot<Capability.Capability<"Base", readonly []>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
77
+ readonly row: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
78
+ readonly add: Slot.UnnamedSlot<Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>, readonly [Event.EventToken<"click">], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
79
+ readonly remove: Slot.UnnamedSlot<Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>, readonly [Event.EventToken<"click">], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
80
+ }>;
81
+ /** The parts of a `Form.make` result the view reads. */
82
+ interface FormLike<Key extends string, Model, Message> {
83
+ /** Every key, nested ones too; `Key` is the keys that hold a draft. */
84
+ readonly controls: ReadonlyArray<FormControl>;
85
+ readonly field: (model: Model, key: Key) => FieldValidation.Field<Draft>;
86
+ /** The rows of a nested key. A form with none takes no key here. */
87
+ readonly rows: (model: Model, key: never) => ReadonlyArray<FormRow>;
88
+ readonly canSubmit: (model: Model) => boolean;
89
+ readonly Message: {
90
+ /** The union, so `Message` is inferred from it and not from one constructor's case. */
91
+ readonly Type: Message;
92
+ readonly Changed: (payload: {
93
+ readonly key: Key;
94
+ readonly value: Draft;
95
+ }) => NoInfer<Message>;
96
+ readonly Blurred: (payload: {
97
+ readonly key: Key;
98
+ }) => NoInfer<Message>;
99
+ readonly Submitted: () => NoInfer<Message>;
100
+ readonly Nested: (payload: {
101
+ readonly key: string;
102
+ readonly row: string;
103
+ readonly message: unknown;
104
+ }) => NoInfer<Message>;
105
+ readonly RowAdded: (payload: {
106
+ readonly key: string;
107
+ }) => NoInfer<Message>;
108
+ readonly RowRemoved: (payload: {
109
+ readonly key: string;
110
+ readonly row: string;
111
+ }) => NoInfer<Message>;
112
+ };
113
+ }
114
+ type FieldView<Key extends string, Message> = SlotView.SlotView<typeof FieldSlots, FieldInput<Key>, Message>;
115
+ export declare const FormView: {
116
+ field: <Key extends string, Model, Message extends {
117
+ readonly _tag: string;
118
+ }>(form: FormLike<Key, Model, Message>) => FieldView<Key, Message>;
119
+ /**
120
+ * The view of the whole form: each control through `field`, in the input's
121
+ * order, a hidden key left out. Pass a styled `field` to change how fields
122
+ * look; attach Style and Behavior to the result to change the form around them.
123
+ */
124
+ define: <Key extends string, Model, Message extends {
125
+ readonly _tag: string;
126
+ }>(form: FormLike<Key, Model, Message> & {
127
+ readonly bundle: {
128
+ readonly name: string;
129
+ };
130
+ }, options?: {
131
+ readonly field?: FieldView<Key, Message>;
132
+ }) => SlotView.SlotView<typeof FormSlots, FormInput<Model, Key>, Message>;
133
+ /**
134
+ * For `Bundle.withView`: the Submodel view that draws `view`, so a placement
135
+ * renders the form with `placed.view(model, h, { options })`.
136
+ *
137
+ * ```ts
138
+ * const Drawn = EditPost.bundle.pipe(Bundle.withView(FormView.submodel(EditPost, View)))
139
+ * ```
140
+ */
141
+ submodel: <Key extends string, Model extends {
142
+ readonly errors: ReadonlyArray<string>;
143
+ }, Message extends {
144
+ readonly _tag: string;
145
+ }>(form: FormLike<Key, Model, Message>, view: SlotView.SlotView<typeof FormSlots, FormInput<Model, Key>, Message>) => Submodel.View<Model, Message, FormViewInputs<Key>>;
146
+ };
147
+ //#endregion
148
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;iBAeiB;WACN;WACA;;;;;;iBAOM,eAAe;WACrB,sBAAsB,KAAK,OAAO,cAAc;;;;;WAKhD,gBAAgB,SAAS,eAAe,cAAc;WACtD;;WAEA,aAAa;;WAEb,gBAAgB,eAAe;;;iBAIzB,WAAW;WACjB,SAAS,YAAY;WACrB,OAAO,gBAAgB,MAAM;WAC7B;WACA,QAAQ;WACR,SAAS,cAAc;;WAEvB;;;;;WAKA;aACI,UAAU,OAAO;aAA4B;;;;iBAI3C,UAAU,OAAO,qCAAqC,eAAe;WAC3E,OAAO;WACP,QAAQ;WACR;;;qBAUE,YAAU,MAAA;;;;;;;;;;;;;;;;qBAyBV,WAAS,MAAA;;;;;;;;;;;;;UAkBZ,SAAS,oBAAoB,OAAO;;WAEnC,UAAU,cAAc;WACxB,QAAQ,OAAO,OAAO,KAAK,QAAQ,gBAAgB,MAAM;;WAEzD,OAAO,OAAO,OAAO,eAAe,cAAc;WAClD,YAAY,OAAO;WACnB;;aAEE,MAAM;aACN,UAAU;eAAoB,KAAK;eAAc,OAAO;UAAY,QAAQ;aAC5E,UAAU;eAAoB,KAAK;UAAU,QAAQ;aACrD,iBAAiB,QAAQ;aACzB,SAAS;eACP;eACA;eACA;UACL,QAAQ;aACL,WAAW;eAAoB;UAAkB,QAAQ;aACzD,aAAa;eACX;eACA;UACL,QAAQ;;;KAkCb,UAAU,oBAAoB,WAAW,SAAS,gBAC9C,YACP,WAAW,MACX;qBA+GW;EAxGE,QAAA,oBAAoB,OAAO;aAA2B;KAAc,MAC3E,SAAS,KAAK,OAAO,aAC1B,UAAU,KAAK;;;;;;EA8GP,SAAA,oBAAoB,OAAO;aAA2B;KAAc,MACrE,SAAS,KAAK,OAAO;aAAsB;eAAmB;;KAAgB;aAChE,QAAQ,UAAU,KAAK;QAC1C,SAAS,gBAAgB,WAAW,UAAU,OAAO,MAAM;;;;;;;;;EA4G5D,WAAA,oBACA;aAAyB,QAAQ;KACjC;aAA2B;KAAc,MAEnC,SAAS,KAAK,OAAO,UAAQ,MAC7B,SAAS,gBAAgB,WAAW,UAAU,OAAO,MAAM,aAChE,SAAS,KAAK,OAAO,SAAS,eAAe"}
package/dist/index.mjs ADDED
@@ -0,0 +1,215 @@
1
+ import { Attr, Capability, Event, Slot, SlotView, Slots } from "foldkit-mixins";
2
+ import * as FieldValidation from "foldkit/fieldValidation";
3
+ import * as Submodel from "foldkit/submodel";
4
+ //#region src/index.ts
5
+ const textual = {
6
+ capability: Capability.TextInput,
7
+ events: [Event.Input, Event.Blur],
8
+ attributes: [Attr.AriaInvalid, Attr.AriaDescribedby]
9
+ };
10
+ /** One field: the control for a key, and what stands around it. */
11
+ const FieldSlots = Slots.define({
12
+ root: Slot.make({ capability: Capability.Container }),
13
+ label: Slot.make({ capability: Capability.Base }),
14
+ description: Slot.make({ capability: Capability.Base }),
15
+ error: Slot.make({ capability: Capability.Base }),
16
+ text: Slot.make(textual),
17
+ multiline: Slot.make(textual),
18
+ number: Slot.make(textual),
19
+ toggle: Slot.make({
20
+ capability: Capability.Interactive,
21
+ events: [Event.Click, Event.Blur],
22
+ attributes: [Attr.AriaInvalid, Attr.AriaDescribedby]
23
+ }),
24
+ /** A `Select`, and a `RelationOne` picker. */
25
+ select: Slot.make({
26
+ capability: Capability.Focusable,
27
+ events: [Event.Change, Event.Blur],
28
+ attributes: [Attr.AriaInvalid, Attr.AriaDescribedby]
29
+ }),
30
+ /** A `RelationMany` picker: the group, and each thing in it. */
31
+ choices: Slot.make({ capability: Capability.Collection }),
32
+ choice: Slot.make({
33
+ capability: Capability.Interactive,
34
+ events: [Event.Click]
35
+ })
36
+ });
37
+ /** The form around its fields. */
38
+ const FormSlots = Slots.define({
39
+ root: Slot.make({
40
+ capability: Capability.Container,
41
+ events: [Event.Submit]
42
+ }),
43
+ /** Failures that belong to no one field: a rule that spans keys. */
44
+ errors: Slot.make({ capability: Capability.Base }),
45
+ submit: Slot.make({
46
+ capability: Capability.Interactive,
47
+ events: [Event.Click],
48
+ attributes: [Attr.Disabled]
49
+ }),
50
+ /** A nested key: the group around its rows, its name, each row, and the buttons that add and remove one. */
51
+ group: Slot.make({ capability: Capability.Container }),
52
+ legend: Slot.make({ capability: Capability.Base }),
53
+ row: Slot.make({ capability: Capability.Container }),
54
+ add: Slot.make({
55
+ capability: Capability.Interactive,
56
+ events: [Event.Click]
57
+ }),
58
+ remove: Slot.make({
59
+ capability: Capability.Interactive,
60
+ events: [Event.Click]
61
+ })
62
+ });
63
+ const rowWalk = (parent, key, row, form) => ({
64
+ controls: form.controls,
65
+ field: (inner) => form.field(row.model, inner),
66
+ rows: (inner) => form.rows(row.model, inner),
67
+ wrap: (message) => parent.wrap(parent.make.Nested({
68
+ key,
69
+ row: row.id,
70
+ message
71
+ })),
72
+ make: form.Message
73
+ });
74
+ const errorsOf = (field) => field._tag === "Invalid" ? field.errors : [];
75
+ /** The view of one field, to style or extend before handing it to `FormView.define`. */
76
+ const field = (form) => SlotView.forMessages().define(FieldSlots, (input, slots, h) => {
77
+ const { control, id, invalid } = input;
78
+ const { key, label, description, required } = control;
79
+ const draft = input.field.value;
80
+ const { send } = input;
81
+ const change = (value) => send === void 0 ? form.Message.Changed({
82
+ key,
83
+ value
84
+ }) : send.changed(value);
85
+ const blurred = send === void 0 ? form.Message.Blurred({ key }) : send.blurred;
86
+ const describedBy = [...description === void 0 ? [] : [`${id}-description`], ...invalid ? [`${id}-error`] : []];
87
+ const state = [
88
+ h.Id(id),
89
+ h.AriaInvalid(invalid),
90
+ ...input.field._tag === "Validating" ? [h.AriaBusy(true)] : [],
91
+ ...required ? [h.AriaRequired(true)] : [],
92
+ ...describedBy.length === 0 ? [] : [h.AriaDescribedBy(describedBy.join(" "))]
93
+ ];
94
+ const typed = [
95
+ ...state,
96
+ h.Value(String(draft)),
97
+ h.OnInput(change),
98
+ h.OnBlur(blurred)
99
+ ];
100
+ const pick = (options, blank) => h.select(slots.select.attrs([
101
+ ...state,
102
+ h.OnChange(change),
103
+ h.OnBlur(blurred)
104
+ ]), [...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]))]);
105
+ const chosen = Array.isArray(draft) ? draft : [];
106
+ const body = control.control._tag === "Multiline" ? h.textarea(slots.multiline.attrs(typed)) : control.control._tag === "Number" ? h.input(slots.number.attrs([
107
+ ...typed,
108
+ h.Type("text"),
109
+ h.InputMode("decimal")
110
+ ])) : control.control._tag === "Toggle" ? h.input(slots.toggle.attrs([
111
+ ...state,
112
+ h.Type("checkbox"),
113
+ h.Checked(draft === true),
114
+ h.OnClick(change(draft !== true)),
115
+ h.OnBlur(blurred)
116
+ ])) : control.control._tag === "Select" ? pick(control.control.options.map((value) => ({
117
+ value,
118
+ label: value
119
+ })), !required) : control.control._tag === "RelationOne" ? pick(input.options, true) : control.control._tag === "RelationMany" ? h.div(slots.choices.attrs([
120
+ h.Id(id),
121
+ h.Role("group"),
122
+ h.AriaLabel(label)
123
+ ]), input.options.map((option) => h.label([], [h.input(slots.choice.attrs([
124
+ h.Type("checkbox"),
125
+ h.Checked(chosen.includes(option.value)),
126
+ h.OnClick(change(chosen.includes(option.value) ? chosen.filter((value) => value !== option.value) : [...chosen, option.value]))
127
+ ])), option.label]))) : h.input(slots.text.attrs([...typed, h.Type("text")]));
128
+ return h.div(slots.root.attrs(), [
129
+ h.label(slots.label.attrs([h.For(id)]), [label]),
130
+ body,
131
+ ...description === void 0 ? [] : [h.p(slots.description.attrs([h.Id(`${id}-description`)]), [description])],
132
+ ...invalid ? [h.p(slots.error.attrs([h.Id(`${id}-error`), h.Role("alert")]), [...input.errors])] : []
133
+ ]);
134
+ }, { name: "FormField" });
135
+ const FormView = {
136
+ field,
137
+ /**
138
+ * The view of the whole form: each control through `field`, in the input's
139
+ * order, a hidden key left out. Pass a styled `field` to change how fields
140
+ * look; attach Style and Behavior to the result to change the form around them.
141
+ */
142
+ define: (form, options = {}) => {
143
+ const fieldView = options.field ?? field(form);
144
+ return SlotView.forMessages().define(FormSlots, (input, slots, h) => {
145
+ const options = {
146
+ ...input.nestedOptions,
147
+ ...input.options
148
+ };
149
+ /** The controls of a form or of a row. `id` and `path` say where: both are empty for the form itself. */
150
+ const draw = (walk, id, path) => walk.controls.filter((control) => control.control._tag !== "Hidden").map((control) => {
151
+ const { key, label } = control;
152
+ const here = `${id}-${key}`;
153
+ if (control.control._tag !== "Nested") {
154
+ const state = walk.field(key);
155
+ return fieldView({
156
+ control,
157
+ field: state,
158
+ invalid: FieldValidation.isInvalid(state),
159
+ errors: errorsOf(state),
160
+ options: options[`${path}${key}`] ?? [],
161
+ id: here,
162
+ send: {
163
+ changed: (value) => walk.wrap(walk.make.Changed({
164
+ key,
165
+ value
166
+ })),
167
+ blurred: walk.wrap(walk.make.Blurred({ key }))
168
+ }
169
+ }, h);
170
+ }
171
+ const { form: nested, cardinality, optional } = control.control;
172
+ const rows = walk.rows(key);
173
+ const addLabel = input.addLabel?.(label) ?? `Add ${label}`;
174
+ return h.fieldset(slots.group.attrs([h.Id(here)]), [
175
+ h.legend(slots.legend.attrs(), [label]),
176
+ ...rows.map((row, index) => h.div(slots.row.attrs([h.Id(`${here}-${row.id}`)]), [...draw(rowWalk(walk, key, row, nested), `${here}-${row.id}`, `${path}${key}.`), ...optional ? [h.button(slots.remove.attrs([h.Type("button"), h.OnClick(walk.wrap(walk.make.RowRemoved({
177
+ key,
178
+ row: row.id
179
+ })))]), [input.removeLabel?.(label, index + 1) ?? `Remove ${label} ${index + 1}`])] : []])),
180
+ ...cardinality === "many" || rows.length === 0 ? [h.button(slots.add.attrs([h.Type("button"), h.OnClick(walk.wrap(walk.make.RowAdded({ key })))]), [addLabel])] : []
181
+ ]);
182
+ });
183
+ const top = {
184
+ controls: form.controls,
185
+ field: (key) => form.field(input.model, key),
186
+ rows: (key) => form.rows(input.model, key),
187
+ wrap: (message) => message,
188
+ make: form.Message
189
+ };
190
+ return h.form(slots.root.attrs([h.OnSubmit(form.Message.Submitted())]), [
191
+ ...draw(top, form.bundle.name, ""),
192
+ ...input.errors.length === 0 ? [] : [h.p(slots.errors.attrs([h.Role("alert")]), [...input.errors])],
193
+ h.button(slots.submit.attrs([h.Type("submit"), h.Disabled(!input.canSubmit)]), [input.submitLabel ?? "Submit"])
194
+ ]);
195
+ }, { name: form.bundle.name });
196
+ },
197
+ /**
198
+ * For `Bundle.withView`: the Submodel view that draws `view`, so a placement
199
+ * renders the form with `placed.view(model, h, { options })`.
200
+ *
201
+ * ```ts
202
+ * const Drawn = EditPost.bundle.pipe(Bundle.withView(FormView.submodel(EditPost, View)))
203
+ * ```
204
+ */
205
+ submodel: (form, view) => Submodel.defineView((model, inputs, h) => view({
206
+ ...inputs,
207
+ model,
208
+ errors: model.errors,
209
+ canSubmit: form.canSubmit(model)
210
+ }, h))
211
+ };
212
+ //#endregion
213
+ export { FieldSlots, FormSlots, FormView };
214
+
215
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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 type { Draft, FormControl, FormRow, NestedForm } from 'foldkit-form'\nimport { Attr, Capability, Event, Slot, Slots, SlotView } from 'foldkit-mixins'\nimport * as FieldValidation from 'foldkit/fieldValidation'\nimport type { Html } 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 * 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 readonly submitLabel?: string | undefined\n /** The words on the button that adds a row to a nested key. Default `Add <label>`. */\n readonly addLabel?: ((label: string) => string) | undefined\n /** The words on the button that removes a row; `position` counts from 1. Default `Remove <label> <position>`. */\n readonly removeLabel?: ((label: string, position: number) => string) | 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 /**\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 { readonly changed: (value: Draft) => unknown; readonly blurred: unknown } | undefined\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})\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 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 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 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 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/** 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): FieldView<Key, Message> =>\n 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 describedBy = [\n ...(description === undefined ? [] : [`${id}-description`]),\n ...(invalid ? [`${id}-error`] : []),\n ]\n const state = [\n h.Id(id),\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 typed = [...state, h.Value(String(draft)), h.OnInput(change), h.OnBlur(blurred)]\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 = (options: ReadonlyArray<Option>, blank: boolean): Html =>\n h.select(slots.select.attrs([...state, h.OnChange(change), h.OnBlur(blurred)]), [\n ...(blank || draft === ''\n ? [h.option([h.Value(''), h.Selected(draft === '')], [''])]\n : []),\n ...options.map(option =>\n h.option([h.Value(option.value), h.Selected(draft === option.value)], [option.label]),\n ),\n ])\n\n const chosen = Array.isArray(draft) ? (draft as ReadonlyArray<string>) : []\n const body: Html =\n control.control._tag === 'Multiline'\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 h.textarea(slots.multiline.attrs(typed) as Parameters<typeof h.textarea>[0])\n : control.control._tag === 'Number'\n ? h.input(slots.number.attrs([...typed, h.Type('text'), h.InputMode('decimal')]))\n : control.control._tag === 'Toggle'\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 : control.control._tag === 'Select'\n ? pick(\n control.control.options.map(value => ({ value, label: value })),\n !required,\n )\n : control.control._tag === 'RelationOne'\n ? pick(input.options, true)\n : control.control._tag === 'RelationMany'\n ? h.div(\n slots.choices.attrs([h.Id(id), h.Role('group'), h.AriaLabel(label)]),\n input.options.map(option =>\n h.label(\n [],\n [\n h.input(\n slots.choice.attrs([\n h.Type('checkbox'),\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 : h.input(slots.text.attrs([...typed, h.Type('text')]))\n\n return h.div(slots.root.attrs(), [\n h.label(slots.label.attrs([h.For(id)]), [label]),\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\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: { readonly field?: FieldView<Key, Message> } = {},\n ): SlotView.SlotView<typeof FormSlots, FormInput<Model, Key>, Message> => {\n const fieldView = options.field ?? field(form)\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._tag !== 'Hidden')\n .map((control): Html => {\n const { key, label } = control\n const here = `${id}-${key}`\n if (control.control._tag !== 'Nested') {\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 send: {\n changed: value => walk.wrap((walk.make.Changed as Make)({ key, value })),\n blurred: walk.wrap((walk.make.Blurred as Make)({ key })),\n },\n },\n h,\n )\n }\n const { form: nested, cardinality, optional } = control.control\n const rows = walk.rows(key)\n const addLabel = input.addLabel?.(label) ?? `Add ${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 input.removeLabel?.(label, index + 1) ??\n `Remove ${label} ${index + 1}`,\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 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.submitLabel ?? '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":";;;;AA8DA,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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CAAC,QAAQ,CACX,CACF,IACA,CAAC;IACP,CAAC;GACH,CAAC;GAEL,MAAM,MAAqB;IACzB,UAAU,KAAK;IACf,QAAO,QAAO,KAAK,MAAM,MAAM,OAAO,GAAU;IAChD,OAAM,QAAO,KAAK,KAAK,MAAM,OAAO,GAAY;IAChD,OAAM,YAAW;IACjB,MAAM,KAAK;GACb;GACA,OAAO,EAAE,KAAK,MAAM,KAAK,MAAM,CAAC,EAAE,SAAS,KAAK,QAAQ,UAAU,CAAC,CAAC,CAAC,GAAG;IACtE,GAAG,KAAK,KAAK,KAAK,OAAO,MAAM,EAAE;IACjC,GAAI,MAAM,OAAO,WAAW,IACxB,CAAC,IACD,CAAC,EAAE,EAAE,MAAM,OAAO,MAAM,CAAC,EAAE,KAAK,OAAO,CAAC,CAAC,GAAG,CAAC,GAAG,MAAM,MAAM,CAAC,CAAC;IAClE,EAAE,OAAO,MAAM,OAAO,MAAM,CAAC,EAAE,KAAK,QAAQ,GAAG,EAAE,SAAS,CAAC,MAAM,SAAS,CAAC,CAAC,GAAG,CAC7E,MAAM,eAAe,QACvB,CAAC;GACH,CAAC;EACH,GACA,EAAE,MAAM,KAAK,OAAO,KAAK,CAC3B;CACF;;;;;;;;;CAUA,WAKE,MACA,SAEA,SAAS,YAAiD,OAAO,QAAQ,MACvE,KAAK;EAAE,GAAG;EAAQ;EAAO,QAAQ,MAAM;EAAQ,WAAW,KAAK,UAAU,KAAK;CAAE,GAAG,CAAC,CACtF;AACJ"}
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "foldkit-mixins-form",
3
+ "version": "0.1.0",
4
+ "description": "A foldkit-form form drawn through foldkit-mixins slots: styleable, extensible, and accessible by contract.",
5
+ "keywords": [
6
+ "foldkit",
7
+ "effect",
8
+ "form",
9
+ "mixins",
10
+ "slots",
11
+ "typescript"
12
+ ],
13
+ "type": "module",
14
+ "license": "MIT",
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "author": "Patrick Glenn <doeixd@gmail.com>",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/doeixd/foldkit-plus.git",
22
+ "directory": "packages/mixins-form"
23
+ },
24
+ "homepage": "https://github.com/doeixd/foldkit-plus/tree/main/packages/mixins-form#readme",
25
+ "bugs": {
26
+ "url": "https://github.com/doeixd/foldkit-plus/issues"
27
+ },
28
+ "sideEffects": false,
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.mts",
32
+ "import": "./dist/index.mjs"
33
+ }
34
+ },
35
+ "files": [
36
+ "dist",
37
+ "README.md",
38
+ "LICENSE"
39
+ ],
40
+ "dependencies": {
41
+ "foldkit-bundle": "0.2.0",
42
+ "foldkit-mixins": "0.3.0",
43
+ "foldkit-form": "0.1.0"
44
+ },
45
+ "peerDependencies": {
46
+ "effect": "^4.0.0-rc.112",
47
+ "foldkit": "^0.158.2"
48
+ },
49
+ "devDependencies": {
50
+ "effect": "4.0.0-rc.112",
51
+ "foldkit": "0.158.2",
52
+ "jsdom": "26.1.0",
53
+ "tsdown": "^0.23.0",
54
+ "typescript": "5.9.3",
55
+ "foldkit-entity": "0.1.0"
56
+ },
57
+ "scripts": {
58
+ "build": "tsdown",
59
+ "typecheck": "tsc -b"
60
+ }
61
+ }