foldkit-mixins-form 0.1.0 → 0.1.1

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 CHANGED
@@ -27,7 +27,7 @@ FormView.field(form) one field, as a SlotView over FieldSlots
27
27
  | .pipe(Style.attach(...))
28
28
  FormView.define(form, { field }) the whole form, as a SlotView over FormSlots
29
29
  | .pipe(Style.attach(...))
30
- FormView.submodel(form, view) a Submodel view taking { options, submitLabel }
30
+ FormView.submodel(form, view) a Submodel view taking { options, words }
31
31
  |
32
32
  form.bundle.pipe(Bundle.withView(...)) the same Bundle, now drawable
33
33
  |
@@ -76,7 +76,7 @@ Then, where the parent draws the placement:
76
76
  ```ts
77
77
  EditForm.view(model, h, {
78
78
  options: { editorId: authors.map(author => ({ value: author.id, label: author.name })) },
79
- submitLabel: 'Save',
79
+ words: { submit: 'Save' },
80
80
  })
81
81
  ```
82
82
 
@@ -101,6 +101,40 @@ EditForm.view(model, h, {
101
101
 
102
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
103
 
104
+ A `RelationOne` or `RelationMany` that searches (`Input.search()`) gets an
105
+ `input type="search"` above it, in the `search` slot, labelled `Search <label>`
106
+ and naming the picker it controls with `aria-controls`. `words.search` in the
107
+ view inputs replaces the word. All of the view's words (`submit`, `search`,
108
+ `add`, `remove`) are text, with `{label}` and `{position}` as blanks; see
109
+ [words in one place](../form/README.md#words-as-text-in-one-place).
110
+
111
+ ### Renderers
112
+
113
+ The table above is a set of renderers found by a control's `kind`, and the
114
+ shipped ones are entries like any other. Add a kind of your own, or draw a
115
+ shipped one another way, by passing renderers beside them:
116
+
117
+ ```ts
118
+ FormView.define(PriceForm, {
119
+ renderers: {
120
+ Cents: ({ control, draft, change, blurred, state, h }) =>
121
+ h.input([...state, h.Value(String(draft)), h.OnInput(change), h.OnBlur(blurred)]),
122
+ RelationOne: myCombobox, // replaces the shipped select
123
+ },
124
+ })
125
+ ```
126
+
127
+ A renderer is told `input.following`: whether the key is still written from the
128
+ key it follows ([`Input.following`](../form/README.md#a-key-that-follows-another)).
129
+ A renderer that wants a "regenerate" button shows it when that is `false` and
130
+ sends the key an empty draft.
131
+
132
+ A renderer draws the control only; the label, description, error, and a search
133
+ box are the field's. `state` is the control's `id` and its accessibility
134
+ attributes, to put on the element that holds the value. A control whose kind has
135
+ no renderer throws when it is drawn, naming the kind and the key.
136
+ `FormView.field(form, { renderers })` takes them too, for a field view you style.
137
+
104
138
  A number is a text input because its draft is text: `"4."` is a fine thing to
105
139
  have typed, and `type="number"` would refuse to report it.
106
140
 
@@ -112,7 +146,7 @@ A nested row's fields are drawn through the same field view, so a styled `field`
112
146
  styles them too. A row that must be there has no remove button, and a `one`
113
147
  loses its add button once it has its row. View inputs for nested keys:
114
148
  `nestedOptions` names a picker inside a row by path (`'author.countryId'`, the
115
- same for every row), and `addLabel` / `removeLabel` word the buttons (defaults
149
+ same for every row), and `words.add` / `words.remove` word the buttons (defaults
116
150
  `Add <label>`, `Remove <label> <position>`).
117
151
 
118
152
  ### Accessibility
@@ -132,7 +166,8 @@ attribute conflict, reported when the view renders. The slots declare
132
166
  - One layout: label, control, description, error, in that order, and fields in
133
167
  the input's order. For another arrangement, draw from `form.controls`
134
168
  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.
169
+ - A relation picker is a `select`, or checkboxes for a `many`. With
170
+ `Input.search()` it searches, but it is not a combobox: the choices are the
171
+ rows the query found, with no paging inside the picker.
137
172
  - The Bundle gains a view through `Bundle.withView`, so place the drawn Bundle,
138
173
  not `form.bundle`.
package/dist/index.d.mts CHANGED
@@ -1,13 +1,31 @@
1
- import { Attr, Capability, Event, Slot, SlotView, Slots } from "foldkit-mixins";
1
+ import { Control, Draft, FormControl, FormRow } from "foldkit-form";
2
+ import { Attr, Capability, Event, Slot, SlotBuilders, SlotView, Slots } from "foldkit-mixins";
2
3
  import * as FieldValidation from "foldkit/fieldValidation";
3
4
  import * as Submodel from "foldkit/submodel";
4
- import { Draft, FormControl, FormRow } from "foldkit-form";
5
+ import { Attribute, Html, HtmlBuilder } from "foldkit/html";
5
6
  //#region src/index.d.ts
6
7
  /** One thing a select or a relation picker offers. */
7
8
  export interface Option {
8
9
  readonly value: string;
9
10
  readonly label: string;
10
11
  }
12
+ /**
13
+ * The words the drawn form says itself. Its keys are its own, so one object can
14
+ * hold these, `foldkit-mixins-crud`'s `ViewWords`, and a form's `FormMessages`:
15
+ * an application's words, written and translated in one place. They are text
16
+ * with blanks (`{label}`), never functions: Foldkit admits no function nested in
17
+ * a placed view's inputs.
18
+ */
19
+ export interface FormViewWords {
20
+ /** On the submit button. Default `Submit`. */
21
+ readonly submit?: string | undefined;
22
+ /** Before the label on a picker's search box (`Search Author`). Default `Search`. */
23
+ readonly search?: string | undefined;
24
+ /** On the button that adds a row to a nested key. Default `Add {label}`. */
25
+ readonly add?: string | undefined;
26
+ /** On the button that removes a row; `{position}` counts from 1. Default `Remove {label} {position}`. */
27
+ readonly remove?: string | undefined;
28
+ }
11
29
  /**
12
30
  * What the view needs that the form does not own: the choices of each relation
13
31
  * picker (a query the application makes), and the submit button's words.
@@ -19,11 +37,8 @@ export interface FormViewInputs<Key extends string = string> {
19
37
  * row: `'author.country'`.
20
38
  */
21
39
  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;
40
+ /** The view's own words, for wording and for translation. */
41
+ readonly words?: FormViewWords | undefined;
27
42
  }
28
43
  /** What a field's Style and Behavior attachments may read. */
29
44
  export interface FieldInput<Key extends string = string> {
@@ -34,6 +49,8 @@ export interface FieldInput<Key extends string = string> {
34
49
  readonly options: ReadonlyArray<Option>;
35
50
  /** Unique within the form, for `label for`, and as the prefix of the ids beside it. */
36
51
  readonly id: string;
52
+ /** The word before the label on its search box: the view's `words.search`. */
53
+ readonly searchWord?: string | undefined;
37
54
  /**
38
55
  * Set for a field in a row of a nested key: its Messages, wrapped for the row.
39
56
  * A field of the form itself sends the form's own.
@@ -41,7 +58,15 @@ export interface FieldInput<Key extends string = string> {
41
58
  readonly send?: {
42
59
  readonly changed: (value: Draft) => unknown;
43
60
  readonly blurred: unknown;
61
+ readonly searched: (text: string) => unknown;
44
62
  } | undefined;
63
+ /** What was typed to find a choice, for a relation picker that searches. */
64
+ readonly search: string;
65
+ /**
66
+ * Whether the key is still written from the key it follows. A renderer offers
67
+ * "regenerate" when it is not, by sending the key an empty draft.
68
+ */
69
+ readonly following: boolean;
45
70
  }
46
71
  /** What the form's own Style and Behavior attachments may read. */
47
72
  export interface FormInput<Model, Key extends string = string> extends FormViewInputs<Key> {
@@ -64,6 +89,8 @@ export declare const FieldSlots: Slots.Contract<{
64
89
  /** A `RelationMany` picker: the group, and each thing in it. */
65
90
  readonly choices: Slot.UnnamedSlot<Capability.Capability<"Collection", readonly [Capability.Capability<"Base", readonly []>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
66
91
  readonly choice: Slot.UnnamedSlot<Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>, readonly [Event.EventToken<"click">], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
92
+ /** Over a relation picker that searches: where the user types to find a choice. */
93
+ 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>;
67
94
  }>;
68
95
  /** The form around its fields. */
69
96
  export declare const FormSlots: Slots.Contract<{
@@ -85,6 +112,8 @@ interface FormLike<Key extends string, Model, Message> {
85
112
  readonly field: (model: Model, key: Key) => FieldValidation.Field<Draft>;
86
113
  /** The rows of a nested key. A form with none takes no key here. */
87
114
  readonly rows: (model: Model, key: never) => ReadonlyArray<FormRow>;
115
+ readonly search: (model: Model, key: Key) => string;
116
+ readonly isFollowing: (model: Model, key: Key) => boolean;
88
117
  readonly canSubmit: (model: Model) => boolean;
89
118
  readonly Message: {
90
119
  /** The union, so `Message` is inferred from it and not from one constructor's case. */
@@ -96,6 +125,10 @@ interface FormLike<Key extends string, Model, Message> {
96
125
  readonly Blurred: (payload: {
97
126
  readonly key: Key;
98
127
  }) => NoInfer<Message>;
128
+ readonly Searched: (payload: {
129
+ readonly key: Key;
130
+ readonly text: string;
131
+ }) => NoInfer<Message>;
99
132
  readonly Submitted: () => NoInfer<Message>;
100
133
  readonly Nested: (payload: {
101
134
  readonly key: string;
@@ -112,10 +145,30 @@ interface FormLike<Key extends string, Model, Message> {
112
145
  };
113
146
  }
114
147
  type FieldView<Key extends string, Message> = SlotView.SlotView<typeof FieldSlots, FieldInput<Key>, Message>;
148
+ /** What a renderer draws one control from. */
149
+ export interface RenderContext<Message> {
150
+ readonly input: FieldInput;
151
+ /** The control, whose `data` is its kind's: narrow it with the kind's `is`. */
152
+ readonly control: Control;
153
+ readonly draft: Draft;
154
+ readonly change: (value: Draft) => Message;
155
+ readonly blurred: Message;
156
+ /** The control's id and its accessibility state. Put them on the element that holds the value. */
157
+ readonly state: ReadonlyArray<Attribute<Message>>;
158
+ readonly slots: SlotBuilders<typeof FieldSlots, Message>;
159
+ readonly h: HtmlBuilder<Message>;
160
+ }
161
+ /** Draws the control of one kind. The label, description and error around it are the field's. */
162
+ export type Renderer<Message> = (context: RenderContext<Message>) => Html;
163
+ /** Renderers by the `kind` of control they draw. */
164
+ export type Renderers<Message> = Readonly<Record<string, Renderer<Message>>>;
115
165
  export declare const FormView: {
116
166
  field: <Key extends string, Model, Message extends {
117
167
  readonly _tag: string;
118
- }>(form: FormLike<Key, Model, Message>) => FieldView<Key, Message>;
168
+ }>(form: FormLike<Key, Model, Message>, options?: {
169
+ /** Renderers by kind, beside the ones shipped: a new kind, or another way to draw a shipped one. */
170
+ readonly renderers?: Renderers<Message>;
171
+ }) => FieldView<Key, Message>;
119
172
  /**
120
173
  * The view of the whole form: each control through `field`, in the input's
121
174
  * order, a hidden key left out. Pass a styled `field` to change how fields
@@ -129,6 +182,8 @@ export declare const FormView: {
129
182
  };
130
183
  }, options?: {
131
184
  readonly field?: FieldView<Key, Message>;
185
+ /** Renderers by kind, for the field view this makes. With `field` given, give them to `FormView.field`. */
186
+ readonly renderers?: Renderers<Message>;
132
187
  }) => SlotView.SlotView<typeof FormSlots, FormInput<Model, Key>, Message>;
133
188
  /**
134
189
  * For `Bundle.withView`: the Submodel view that draws `view`, so a placement
@@ -1 +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,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O,UAAQ,MAC7B,SAAS,gBAAgB,WAAW,UAAU,OAAO,MAAM,aAChE,SAAS,KAAK,OAAO,SAAS,eAAe"}
package/dist/index.mjs CHANGED
@@ -1,7 +1,16 @@
1
+ import { Input, fillWords } from "foldkit-form";
1
2
  import { Attr, Capability, Event, Slot, SlotView, Slots } from "foldkit-mixins";
2
3
  import * as FieldValidation from "foldkit/fieldValidation";
3
4
  import * as Submodel from "foldkit/submodel";
4
5
  //#region src/index.ts
6
+ /**
7
+ * `foldkit-mixins-form` — a `foldkit-form` form drawn through slots.
8
+ *
9
+ * `foldkit-form` describes each control and draws nothing. This package draws
10
+ * them as plain, accessible HTML and publishes every element as a Slot, so an
11
+ * application styles and extends a generated form the way it does any other
12
+ * SlotView, and the form stays free of a view dependency.
13
+ */
5
14
  const textual = {
6
15
  capability: Capability.TextInput,
7
16
  events: [Event.Input, Event.Blur],
@@ -32,6 +41,11 @@ const FieldSlots = Slots.define({
32
41
  choice: Slot.make({
33
42
  capability: Capability.Interactive,
34
43
  events: [Event.Click]
44
+ }),
45
+ /** Over a relation picker that searches: where the user types to find a choice. */
46
+ search: Slot.make({
47
+ capability: Capability.TextInput,
48
+ events: [Event.Input]
35
49
  })
36
50
  });
37
51
  /** The form around its fields. */
@@ -64,6 +78,8 @@ const rowWalk = (parent, key, row, form) => ({
64
78
  controls: form.controls,
65
79
  field: (inner) => form.field(row.model, inner),
66
80
  rows: (inner) => form.rows(row.model, inner),
81
+ search: (inner) => form.search(row.model, inner),
82
+ following: (inner) => form.isFollowing(row.model, inner),
67
83
  wrap: (message) => parent.wrap(parent.make.Nested({
68
84
  key,
69
85
  row: row.id,
@@ -72,66 +88,114 @@ const rowWalk = (parent, key, row, form) => ({
72
88
  make: form.Message
73
89
  });
74
90
  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 = [
91
+ /**
92
+ * The renderers this package ships, by kind. They are entries like any other: an
93
+ * application adds `Date`, or replaces `RelationOne` with a combobox, by passing
94
+ * its own beside them.
95
+ */
96
+ const defaultRenderers = () => {
97
+ const typed = ({ state, draft, change, blurred, h }) => [
95
98
  ...state,
96
99
  h.Value(String(draft)),
97
100
  h.OnInput(change),
98
101
  h.OnBlur(blurred)
99
102
  ];
100
- const pick = (options, blank) => h.select(slots.select.attrs([
103
+ const pick = ({ state, draft, change, blurred, slots, h }, options, blank) => h.select(slots.select.attrs([
101
104
  ...state,
102
105
  h.OnChange(change),
103
106
  h.OnBlur(blurred)
104
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]))]);
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" });
108
+ return {
109
+ [Input.Text.kind]: (context) => context.h.input(context.slots.text.attrs([...typed(context), context.h.Type("text")])),
110
+ [Input.Multiline.kind]: (context) => context.h.textarea(context.slots.multiline.attrs(typed(context))),
111
+ [Input.Number.kind]: (context) => context.h.input(context.slots.number.attrs([
112
+ ...typed(context),
113
+ context.h.Type("text"),
114
+ context.h.InputMode("decimal")
115
+ ])),
116
+ [Input.Toggle.kind]: ({ state, draft, change, blurred, slots, h }) => h.input(slots.toggle.attrs([
117
+ ...state,
118
+ h.Type("checkbox"),
119
+ h.Checked(draft === true),
120
+ h.OnClick(change(draft !== true)),
121
+ h.OnBlur(blurred)
122
+ ])),
123
+ [Input.Select.kind]: (context) => pick(context, (Input.Select.is(context.control) ? context.control.data.options : []).map((value) => ({
124
+ value,
125
+ label: value
126
+ })), !context.input.control.required),
127
+ [Input.RelationOne.kind]: (context) => pick(context, context.input.options, true),
128
+ [Input.RelationMany.kind]: ({ input, draft, change, slots, h }) => {
129
+ const chosen = Array.isArray(draft) ? draft : [];
130
+ return h.div(slots.choices.attrs([
131
+ h.Id(input.id),
132
+ h.Role("group"),
133
+ h.AriaLabel(input.control.label)
134
+ ]), input.options.map((option) => h.label([], [h.input(slots.choice.attrs([
135
+ h.Type("checkbox"),
136
+ h.Checked(chosen.includes(option.value)),
137
+ h.OnClick(change(chosen.includes(option.value) ? chosen.filter((value) => value !== option.value) : [...chosen, option.value]))
138
+ ])), option.label])));
139
+ }
140
+ };
141
+ };
142
+ /** The view of one field, to style or extend before handing it to `FormView.define`. */
143
+ const field = (form, options = {}) => {
144
+ const renderers = {
145
+ ...defaultRenderers(),
146
+ ...options.renderers
147
+ };
148
+ return SlotView.forMessages().define(FieldSlots, (input, slots, h) => {
149
+ const { control, id, invalid } = input;
150
+ const { key, label, description, required } = control;
151
+ const draft = input.field.value;
152
+ const { send } = input;
153
+ const change = (value) => send === void 0 ? form.Message.Changed({
154
+ key,
155
+ value
156
+ }) : send.changed(value);
157
+ const blurred = send === void 0 ? form.Message.Blurred({ key }) : send.blurred;
158
+ const searched = (text) => send === void 0 ? form.Message.Searched({
159
+ key,
160
+ text
161
+ }) : send.searched(text);
162
+ const searches = control.control.searches;
163
+ const describedBy = [...description === void 0 ? [] : [`${id}-description`], ...invalid ? [`${id}-error`] : []];
164
+ const state = [
165
+ h.Id(id),
166
+ h.AriaInvalid(invalid),
167
+ ...input.field._tag === "Validating" ? [h.AriaBusy(true)] : [],
168
+ ...required ? [h.AriaRequired(true)] : [],
169
+ ...describedBy.length === 0 ? [] : [h.AriaDescribedBy(describedBy.join(" "))]
170
+ ];
171
+ const render = renderers[control.control.kind];
172
+ if (render === void 0) throw new Error(`FormView: no renderer for a "${control.control.kind}" control ("${key}"); pass one under "renderers"`);
173
+ const body = render({
174
+ input,
175
+ control: control.control,
176
+ draft,
177
+ change,
178
+ blurred,
179
+ state,
180
+ slots,
181
+ h
182
+ });
183
+ return h.div(slots.root.attrs(), [
184
+ h.label(slots.label.attrs([h.For(id)]), [label]),
185
+ ...searches ? [h.input(slots.search.attrs([
186
+ h.Id(`${id}-search`),
187
+ h.Type("search"),
188
+ h.AriaLabel(`${input.searchWord ?? "Search"} ${label}`),
189
+ h.AriaControls(id),
190
+ h.Value(input.search),
191
+ h.OnInput(searched)
192
+ ]))] : [],
193
+ body,
194
+ ...description === void 0 ? [] : [h.p(slots.description.attrs([h.Id(`${id}-description`)]), [description])],
195
+ ...invalid ? [h.p(slots.error.attrs([h.Id(`${id}-error`), h.Role("alert")]), [...input.errors])] : []
196
+ ]);
197
+ }, { name: "FormField" });
198
+ };
135
199
  const FormView = {
136
200
  field,
137
201
  /**
@@ -140,17 +204,17 @@ const FormView = {
140
204
  * look; attach Style and Behavior to the result to change the form around them.
141
205
  */
142
206
  define: (form, options = {}) => {
143
- const fieldView = options.field ?? field(form);
207
+ const fieldView = options.field ?? field(form, options.renderers === void 0 ? {} : { renderers: options.renderers });
144
208
  return SlotView.forMessages().define(FormSlots, (input, slots, h) => {
145
209
  const options = {
146
210
  ...input.nestedOptions,
147
211
  ...input.options
148
212
  };
149
213
  /** 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) => {
214
+ const draw = (walk, id, path) => walk.controls.filter((control) => control.control.shown).map((control) => {
151
215
  const { key, label } = control;
152
216
  const here = `${id}-${key}`;
153
- if (control.control._tag !== "Nested") {
217
+ if (!Input.Nested.is(control.control)) {
154
218
  const state = walk.field(key);
155
219
  return fieldView({
156
220
  control,
@@ -159,24 +223,34 @@ const FormView = {
159
223
  errors: errorsOf(state),
160
224
  options: options[`${path}${key}`] ?? [],
161
225
  id: here,
226
+ search: walk.search(key),
227
+ following: walk.following(key),
228
+ searchWord: input.words?.search,
162
229
  send: {
163
230
  changed: (value) => walk.wrap(walk.make.Changed({
164
231
  key,
165
232
  value
166
233
  })),
167
- blurred: walk.wrap(walk.make.Blurred({ key }))
234
+ blurred: walk.wrap(walk.make.Blurred({ key })),
235
+ searched: (text) => walk.wrap(walk.make.Searched({
236
+ key,
237
+ text
238
+ }))
168
239
  }
169
240
  }, h);
170
241
  }
171
- const { form: nested, cardinality, optional } = control.control;
242
+ const { form: nested, cardinality, optional } = control.control.data;
172
243
  const rows = walk.rows(key);
173
- const addLabel = input.addLabel?.(label) ?? `Add ${label}`;
244
+ const addLabel = fillWords(input.words?.add ?? "Add {label}", { label });
174
245
  return h.fieldset(slots.group.attrs([h.Id(here)]), [
175
246
  h.legend(slots.legend.attrs(), [label]),
176
247
  ...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
248
  key,
178
249
  row: row.id
179
- })))]), [input.removeLabel?.(label, index + 1) ?? `Remove ${label} ${index + 1}`])] : []])),
250
+ })))]), [fillWords(input.words?.remove ?? "Remove {label} {position}", {
251
+ label,
252
+ position: index + 1
253
+ })])] : []])),
180
254
  ...cardinality === "many" || rows.length === 0 ? [h.button(slots.add.attrs([h.Type("button"), h.OnClick(walk.wrap(walk.make.RowAdded({ key })))]), [addLabel])] : []
181
255
  ]);
182
256
  });
@@ -184,13 +258,15 @@ const FormView = {
184
258
  controls: form.controls,
185
259
  field: (key) => form.field(input.model, key),
186
260
  rows: (key) => form.rows(input.model, key),
261
+ search: (key) => form.search(input.model, key),
262
+ following: (key) => form.isFollowing(input.model, key),
187
263
  wrap: (message) => message,
188
264
  make: form.Message
189
265
  };
190
266
  return h.form(slots.root.attrs([h.OnSubmit(form.Message.Submitted())]), [
191
267
  ...draw(top, form.bundle.name, ""),
192
268
  ...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"])
269
+ h.button(slots.submit.attrs([h.Type("submit"), h.Disabled(!input.canSubmit)]), [input.words?.submit ?? "Submit"])
194
270
  ]);
195
271
  }, { name: form.bundle.name });
196
272
  },
@@ -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 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,C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-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.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 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;EAC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AAQ,GAAG,EAAE,SAAS,CAAC,MAAM,SAAS,CAAC,CAAC,GAAG,CAC7E,MAAM,OAAO,UAAU,QACzB,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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foldkit-mixins-form",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "A foldkit-form form drawn through foldkit-mixins slots: styleable, extensible, and accessible by contract.",
5
5
  "keywords": [
6
6
  "foldkit",
@@ -39,8 +39,8 @@
39
39
  ],
40
40
  "dependencies": {
41
41
  "foldkit-bundle": "0.2.0",
42
- "foldkit-mixins": "0.3.0",
43
- "foldkit-form": "0.1.0"
42
+ "foldkit-form": "0.1.1",
43
+ "foldkit-mixins": "0.3.0"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "effect": "^4.0.0-rc.112",
@@ -52,7 +52,7 @@
52
52
  "jsdom": "26.1.0",
53
53
  "tsdown": "^0.23.0",
54
54
  "typescript": "5.9.3",
55
- "foldkit-entity": "0.1.0"
55
+ "foldkit-entity": "0.2.0"
56
56
  },
57
57
  "scripts": {
58
58
  "build": "tsdown",