@namroodinc/liquid-editorial 0.3.2 → 0.4.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/AGENTS.md +4 -0
- package/README.md +1576 -180
- package/UPGRADING.md +215 -0
- package/dist/chunks/ColourField-CJicr3OT.cjs +2 -0
- package/dist/chunks/ColourField-CJicr3OT.cjs.map +1 -0
- package/dist/chunks/{ColourField-C2YDshDg.js → ColourField-DjHRiFDU.js} +167 -162
- package/dist/chunks/ColourField-DjHRiFDU.js.map +1 -0
- package/dist/chunks/DatePicker-D_6CQpUd.js +296 -0
- package/dist/chunks/DatePicker-D_6CQpUd.js.map +1 -0
- package/dist/chunks/DatePicker-aSlYLjtW.cjs +2 -0
- package/dist/chunks/DatePicker-aSlYLjtW.cjs.map +1 -0
- package/dist/chunks/FormEditor-M7tNidFo.js +584 -0
- package/dist/chunks/FormEditor-M7tNidFo.js.map +1 -0
- package/dist/chunks/FormEditor-UzbPdiJo.cjs +2 -0
- package/dist/chunks/FormEditor-UzbPdiJo.cjs.map +1 -0
- package/dist/chunks/Slider-k8weRl34.cjs +2 -0
- package/dist/chunks/Slider-k8weRl34.cjs.map +1 -0
- package/dist/chunks/Slider-vdMFLX-H.js +174 -0
- package/dist/chunks/Slider-vdMFLX-H.js.map +1 -0
- package/dist/chunks/dialogFocus-B9iqKl3I.cjs +2 -0
- package/dist/chunks/dialogFocus-B9iqKl3I.cjs.map +1 -0
- package/dist/chunks/dialogFocus-BFoyeTpA.js +48 -0
- package/dist/chunks/dialogFocus-BFoyeTpA.js.map +1 -0
- package/dist/components/Choice/index.cjs +1 -1
- package/dist/components/Choice/index.cjs.map +1 -1
- package/dist/components/Choice/index.d.cts.map +1 -1
- package/dist/components/Choice/index.d.ts.map +1 -1
- package/dist/components/Choice/index.js +2 -0
- package/dist/components/Choice/index.js.map +1 -1
- package/dist/components/ColourField/focus.d.cts +0 -1
- package/dist/components/ColourField/focus.d.cts.map +1 -1
- package/dist/components/ColourField/focus.d.ts +0 -1
- package/dist/components/ColourField/focus.d.ts.map +1 -1
- package/dist/components/ColourField/index.cjs +1 -1
- package/dist/components/ColourField/index.d.cts.map +1 -1
- package/dist/components/ColourField/index.d.ts.map +1 -1
- package/dist/components/ColourField/index.js +1 -1
- package/dist/components/ColourField/value.d.cts +6 -0
- package/dist/components/ColourField/value.d.cts.map +1 -1
- package/dist/components/ColourField/value.d.ts +6 -0
- package/dist/components/ColourField/value.d.ts.map +1 -1
- package/dist/components/DatePicker/date.d.cts +9 -0
- package/dist/components/DatePicker/date.d.cts.map +1 -0
- package/dist/components/DatePicker/date.d.ts +9 -0
- package/dist/components/DatePicker/date.d.ts.map +1 -0
- package/dist/components/DatePicker/index.cjs +1 -2
- package/dist/components/DatePicker/index.d.cts +9 -6
- package/dist/components/DatePicker/index.d.cts.map +1 -1
- package/dist/components/DatePicker/index.d.ts +9 -6
- package/dist/components/DatePicker/index.d.ts.map +1 -1
- package/dist/components/DatePicker/index.js +1 -259
- package/dist/components/DatePicker/style.css +5 -0
- package/dist/components/Drawer/index.cjs +1 -1
- package/dist/components/Drawer/index.cjs.map +1 -1
- package/dist/components/Drawer/index.d.cts.map +1 -1
- package/dist/components/Drawer/index.d.ts.map +1 -1
- package/dist/components/Drawer/index.js +69 -73
- package/dist/components/Drawer/index.js.map +1 -1
- package/dist/components/EditLayout/index.cjs +1 -1
- package/dist/components/EditLayout/index.cjs.map +1 -1
- package/dist/components/EditLayout/index.d.cts.map +1 -1
- package/dist/components/EditLayout/index.d.ts.map +1 -1
- package/dist/components/EditLayout/index.js +68 -55
- package/dist/components/EditLayout/index.js.map +1 -1
- package/dist/components/Field/style.css +20 -0
- package/dist/components/FormEditor/README.md +375 -0
- package/dist/components/FormEditor/additional-control.d.cts +6 -0
- package/dist/components/FormEditor/additional-control.d.cts.map +1 -0
- package/dist/components/FormEditor/additional-control.d.ts +6 -0
- package/dist/components/FormEditor/additional-control.d.ts.map +1 -0
- package/dist/components/FormEditor/choice-control.d.cts +6 -0
- package/dist/components/FormEditor/choice-control.d.cts.map +1 -0
- package/dist/components/FormEditor/choice-control.d.ts +6 -0
- package/dist/components/FormEditor/choice-control.d.ts.map +1 -0
- package/dist/components/FormEditor/control.d.cts +8 -0
- package/dist/components/FormEditor/control.d.cts.map +1 -1
- package/dist/components/FormEditor/control.d.ts +8 -0
- package/dist/components/FormEditor/control.d.ts.map +1 -1
- package/dist/components/FormEditor/index.cjs +1 -1
- package/dist/components/FormEditor/index.d.cts +1 -1
- package/dist/components/FormEditor/index.d.cts.map +1 -1
- package/dist/components/FormEditor/index.d.ts +1 -1
- package/dist/components/FormEditor/index.d.ts.map +1 -1
- package/dist/components/FormEditor/index.js +1 -1
- package/dist/components/FormEditor/model.d.cts +68 -2
- package/dist/components/FormEditor/model.d.cts.map +1 -1
- package/dist/components/FormEditor/model.d.ts +68 -2
- package/dist/components/FormEditor/model.d.ts.map +1 -1
- package/dist/components/FormEditor/style.css +12 -0
- package/dist/components/Grid/style.css +2 -1
- package/dist/components/ImageCropper/index.cjs +1 -1
- package/dist/components/ImageCropper/index.cjs.map +1 -1
- package/dist/components/ImageCropper/index.js +6 -6
- package/dist/components/ImageCropper/index.js.map +1 -1
- package/dist/components/Modal/index.cjs +1 -1
- package/dist/components/Modal/index.cjs.map +1 -1
- package/dist/components/Modal/index.d.cts.map +1 -1
- package/dist/components/Modal/index.d.ts.map +1 -1
- package/dist/components/Modal/index.js +40 -48
- package/dist/components/Modal/index.js.map +1 -1
- package/dist/components/NumberField/index.cjs +1 -1
- package/dist/components/NumberField/index.cjs.map +1 -1
- package/dist/components/NumberField/index.d.cts.map +1 -1
- package/dist/components/NumberField/index.d.ts.map +1 -1
- package/dist/components/NumberField/index.js +4 -0
- package/dist/components/NumberField/index.js.map +1 -1
- package/dist/components/Popover/index.cjs +1 -1
- package/dist/components/Popover/index.cjs.map +1 -1
- package/dist/components/Popover/index.d.cts +2 -0
- package/dist/components/Popover/index.d.cts.map +1 -1
- package/dist/components/Popover/index.d.ts +2 -0
- package/dist/components/Popover/index.d.ts.map +1 -1
- package/dist/components/Popover/index.js +45 -44
- package/dist/components/Popover/index.js.map +1 -1
- package/dist/components/SelectionCard/index.cjs +1 -1
- package/dist/components/SelectionCard/index.cjs.map +1 -1
- package/dist/components/SelectionCard/index.d.cts.map +1 -1
- package/dist/components/SelectionCard/index.d.ts.map +1 -1
- package/dist/components/SelectionCard/index.js +2 -1
- package/dist/components/SelectionCard/index.js.map +1 -1
- package/dist/components/Slider/index.cjs +1 -2
- package/dist/components/Slider/index.d.cts +14 -1
- package/dist/components/Slider/index.d.cts.map +1 -1
- package/dist/components/Slider/index.d.ts +14 -1
- package/dist/components/Slider/index.d.ts.map +1 -1
- package/dist/components/Slider/index.js +1 -127
- package/dist/components/Slider/scale.d.cts +13 -0
- package/dist/components/Slider/scale.d.cts.map +1 -0
- package/dist/components/Slider/scale.d.ts +13 -0
- package/dist/components/Slider/scale.d.ts.map +1 -0
- package/dist/elements.css +9 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -20
- package/dist/internal/dialogFocus.d.cts +17 -0
- package/dist/internal/dialogFocus.d.cts.map +1 -0
- package/dist/internal/dialogFocus.d.ts +17 -0
- package/dist/internal/dialogFocus.d.ts.map +1 -0
- package/dist/reset.css +2 -0
- package/dist/styles.css +1 -0
- package/package.json +2 -2
- package/dist/chunks/ColourField-C2YDshDg.js.map +0 -1
- package/dist/chunks/ColourField-Dc9533G6.cjs +0 -2
- package/dist/chunks/ColourField-Dc9533G6.cjs.map +0 -1
- package/dist/chunks/FormEditor-DRmPFe2E.js +0 -328
- package/dist/chunks/FormEditor-DRmPFe2E.js.map +0 -1
- package/dist/chunks/FormEditor-PVkvKep1.cjs +0 -2
- package/dist/chunks/FormEditor-PVkvKep1.cjs.map +0 -1
- package/dist/components/DatePicker/index.cjs.map +0 -1
- package/dist/components/DatePicker/index.js.map +0 -1
- package/dist/components/Slider/index.cjs.map +0 -1
- package/dist/components/Slider/index.js.map +0 -1
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
# FormEditor: integration and agent reference
|
|
2
|
+
|
|
3
|
+
Use this guide when adopting FormEditor in an application or extending it in the
|
|
4
|
+
library. The source is `src/components/FormEditor/README.md`; builds copy it
|
|
5
|
+
unchanged to `dist/components/FormEditor/README.md` in the installed package.
|
|
6
|
+
Read the package's `UPGRADING.md` when upgrading.
|
|
7
|
+
|
|
8
|
+
## Basic integration
|
|
9
|
+
|
|
10
|
+
```tsx
|
|
11
|
+
import { useState } from "react";
|
|
12
|
+
import {
|
|
13
|
+
Button,
|
|
14
|
+
FormEditor,
|
|
15
|
+
validateFormValues,
|
|
16
|
+
type FormErrors,
|
|
17
|
+
type FormSchema,
|
|
18
|
+
type FormValues,
|
|
19
|
+
} from "@namroodinc/liquid-editorial";
|
|
20
|
+
import "@namroodinc/liquid-editorial/styles.css";
|
|
21
|
+
|
|
22
|
+
const schema: FormSchema = {
|
|
23
|
+
fields: [
|
|
24
|
+
{ id: "title", type: "shortText", label: "Title", required: true },
|
|
25
|
+
{
|
|
26
|
+
id: "status", type: "select", label: "Status",
|
|
27
|
+
options: [{ value: "draft", label: "Draft" }, { value: "published", label: "Published" }],
|
|
28
|
+
},
|
|
29
|
+
{ id: "section-rule", type: "divider" },
|
|
30
|
+
{
|
|
31
|
+
id: "channels", type: "checkboxGroup", label: "Channels",
|
|
32
|
+
appearance: "card", columns: 2, required: true,
|
|
33
|
+
options: [
|
|
34
|
+
{ value: "web", label: "Web", description: "Publish online" },
|
|
35
|
+
{ value: "print", label: "Print", isDisabled: true },
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export function ArticleForm({ save }: { save: (values: FormValues) => void }) {
|
|
42
|
+
const [values, setValues] = useState<FormValues>({ title: "", status: "draft", channels: [] });
|
|
43
|
+
const [errors, setErrors] = useState<FormErrors>({});
|
|
44
|
+
const [submitted, setSubmitted] = useState(false);
|
|
45
|
+
return (
|
|
46
|
+
<form onSubmit={(event) => {
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
const nextErrors = validateFormValues(schema, values);
|
|
49
|
+
setErrors(nextErrors);
|
|
50
|
+
setSubmitted(true);
|
|
51
|
+
if (Object.keys(nextErrors).length === 0) {
|
|
52
|
+
save(values);
|
|
53
|
+
}
|
|
54
|
+
}}>
|
|
55
|
+
<FormEditor
|
|
56
|
+
schema={schema}
|
|
57
|
+
value={values}
|
|
58
|
+
showAllErrors={submitted}
|
|
59
|
+
errors={errors}
|
|
60
|
+
onValueChange={(next, { fieldId }) => {
|
|
61
|
+
setValues(next);
|
|
62
|
+
// App errors override built-in validation; clear stale messages on edit.
|
|
63
|
+
setErrors((previous) => {
|
|
64
|
+
const remaining = { ...previous };
|
|
65
|
+
delete remaining[fieldId];
|
|
66
|
+
return remaining;
|
|
67
|
+
});
|
|
68
|
+
}}
|
|
69
|
+
/>
|
|
70
|
+
<Button type="submit" variant="primary">Save</Button>
|
|
71
|
+
</form>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The root and `components/FormEditor` entry points expose the same FormEditor
|
|
77
|
+
exports. Import the aggregate stylesheet with either entry point. The optional
|
|
78
|
+
`reset.css` remains separate; it is not needed for muted horizontal rules.
|
|
79
|
+
|
|
80
|
+
## Editor props
|
|
81
|
+
|
|
82
|
+
| Prop | Accepted value | Default / behavior |
|
|
83
|
+
| --- | --- | --- |
|
|
84
|
+
| `schema` | `FormSchema` | Required; ordered `fields: readonly FormItem[]`. |
|
|
85
|
+
| `value` | `FormValues` | Omit for uncontrolled state; controlled callers must echo changes. |
|
|
86
|
+
| `defaultValue` | `FormValues` | `{}`; initial uncontrolled values only. |
|
|
87
|
+
| `onValueChange` | `(values, { fieldId }) => void` | Reports the complete next values and the edited field ID. |
|
|
88
|
+
| `pickerItems` | `Record<string, EntryItem[]>` | `{}`; available assets/entries keyed by field ID. |
|
|
89
|
+
| `errors` | `FormErrors` | `{}`; app messages override built-in errors. Clear stale app errors explicitly. |
|
|
90
|
+
| `showAllErrors` | Boolean | `false`; reveal built-in required/format errors, usually after submission. |
|
|
91
|
+
| `isDisabled` | Boolean | `false`; disables every control and blocks edits. |
|
|
92
|
+
| `columns` | `1`, `2`, `3`, `4`, `6`, `12`, `"auto"` | `1`; numeric values cap the column count. |
|
|
93
|
+
| `minColumnWidth` | CSS length | `"16rem"`; columns step down against the form's own width. |
|
|
94
|
+
| `className`, `style`, other div attributes | React HTML attributes | Forwarded to the outer div. `onChange` is excluded; use `onValueChange`. |
|
|
95
|
+
|
|
96
|
+
FormEditor renders a div, not a form. Supply the form, submission action, API
|
|
97
|
+
calls, permissions and pending state in the application. A schema may contain
|
|
98
|
+
React nodes and live choices; it is runtime UI configuration, not a persisted CMS
|
|
99
|
+
content definition. Keep schemas outside render or memoize them for cached
|
|
100
|
+
per-field validation.
|
|
101
|
+
|
|
102
|
+
## Common field options
|
|
103
|
+
|
|
104
|
+
| Option | Type / default | Applies to |
|
|
105
|
+
| --- | --- | --- |
|
|
106
|
+
| `id` | Required nonempty unique string | Every item, including dividers. |
|
|
107
|
+
| `type` | Required discriminator from the table below | Every item. |
|
|
108
|
+
| `label` | Required string | Every value-bearing field; visible and accessible name. |
|
|
109
|
+
| `hint` | Optional `ReactNode` | Every field; hidden while an error is displayed. |
|
|
110
|
+
| `required` | Boolean, `false` | Every field; checked by `validateFormValues`. |
|
|
111
|
+
| `isDisabled` | Boolean, `false` | Every field; combines with the editor's disabled state. |
|
|
112
|
+
| `placeholder` | Optional string | Text, number, rich text, select, colour, tags, date, slider and range slider controls (an unset slider's value label); ignored by other adapters. |
|
|
113
|
+
|
|
114
|
+
Dividers accept only `id` and `type`. They span every column, have no Field frame
|
|
115
|
+
or values, and ignore error entries. IDs must be unique across fields and dividers.
|
|
116
|
+
|
|
117
|
+
## Type-specific options and stored values
|
|
118
|
+
|
|
119
|
+
All controls use the shared component's standard medium size and styling.
|
|
120
|
+
Only options listed here are supported by FormEditor; standalone component props
|
|
121
|
+
are not automatically schema options.
|
|
122
|
+
|
|
123
|
+
| `type` | Additional options and defaults | Stored value |
|
|
124
|
+
| --- | --- | --- |
|
|
125
|
+
| `shortText` | `inputType: "text" \| "email"` (`text`), `maxLength`, `readOnly: false`, `autoFocus: false` | String; empty text remains `""`. |
|
|
126
|
+
| `longText` | `rows: 3`, `maxLength`, `readOnly: false`, `autoFocus: false` | String. |
|
|
127
|
+
| `richText` | `placeholder: "Write something…"`; no autofocus | TipTap JSON document rooted at `doc`. |
|
|
128
|
+
| `number` | `min`, `max`, `step: number \| "any"` (`"any"`), `hasSteppers: false`, `autoFocus: false` | Finite number. |
|
|
129
|
+
| `boolean` | `autoFocus: false`; always a Switch | Boolean; `false` satisfies required. |
|
|
130
|
+
| `dateTime` | Native browser date-and-time input; `autoFocus: false`; label gets `(UTC)` | UTC ISO string ending in `Z`, including milliseconds. |
|
|
131
|
+
| `select` | Required `options: SelectOption[]`, `autoFocus: false` | String. Optional fields add an empty choice, using `placeholder` or `"None"`. |
|
|
132
|
+
| `slider` | `min: 0`, `max: 100`, `step: 1`, `prefix`, `suffix` (strings), `hasValueLabel: true`, `autoFocus: false` | Number. Missing values place the thumb at the minimum, print `placeholder` or `"Not set"` and announce it as the value text, without storing anything. A click on the slider, or an arrow, Home, End or Page key, stores the shown position, so the minimum can be chosen directly. |
|
|
133
|
+
| `rangeSlider` | Same scale/unit options as slider, without autofocus | `{ min: number, max: number }`; endpoints must be at least one step apart. Missing values put the thumbs at both ends with no fill, print `placeholder` or `"Not set"` and announce it on each thumb, without storing anything. A click on either thumb, or an arrow, Home, End or Page key that leaves it in place, stores the full range. Loaded endpoints outside the scale are drawn clamped and reversed endpoints are drawn in order; validation still reports the stored values. |
|
|
134
|
+
| `colour` | `presets: string[]`, `showPresets: true`, `picker: "custom" \| "native"` (`custom`), `placement: "top" \| "bottom"` (`bottom`), `readOnly: false`, `autoFocus: false` | String; valid edits emit uppercase hex, including alpha when needed. Invalid typing stays a string so pre-save validation rejects it. |
|
|
135
|
+
| `radioGroup` | Required `options`, `appearance: "default" \| "card"` (`default`), `columns: 1 \| 2 \| 3` (1, or 2 for cards) | String; optional groups have a clear action after selection. |
|
|
136
|
+
| `checkboxGroup` | Same options/appearance/columns as radioGroup | String array; `[]` means no selections. |
|
|
137
|
+
| `tags` | `max` (unlimited); placeholder defaults to `"Add a tag"` | Unique, nonempty string array. Enter, comma or blur commits a tag. |
|
|
138
|
+
| `date` | Custom calendar popover; `min`, `max` (`YYYY-MM-DD`), `placement` (`bottom`); placeholder defaults to `"Pick a date"` | Calendar date string, without a time or timezone. Clearable. |
|
|
139
|
+
| `asset` | `multiple: false`, `picker` options below | `{ assetId: string }`, or ordered array when multiple. |
|
|
140
|
+
| `reference` | `multiple: false`, `picker` options below | `{ entryId: string }`, or ordered array when multiple. |
|
|
141
|
+
| `divider` | No additional options | No stored value. |
|
|
142
|
+
|
|
143
|
+
Sliders require finite `min < max` and a positive finite step. A range slider's
|
|
144
|
+
scale must fit at least one step. Numbers are checked against bounds; step
|
|
145
|
+
configures interaction rather than adding a step-alignment validation rule.
|
|
146
|
+
Step distances are compared at the operands' decimal precision, so a scale such
|
|
147
|
+
as `min: 0.2, max: 0.3, step: 0.1` is valid and its endpoints may be one step apart.
|
|
148
|
+
|
|
149
|
+
Typed number ranges and calendar date ranges are deferred from FormEditor.
|
|
150
|
+
The standalone NumberRangeField and DateRangeField APIs remain separate from
|
|
151
|
+
the supported schema types above. The two-thumb `rangeSlider` remains supported.
|
|
152
|
+
|
|
153
|
+
### Date-only and date-and-time pickers
|
|
154
|
+
|
|
155
|
+
- Use `type: "date"` for a calendar day. It renders the shared DateField with a
|
|
156
|
+
custom calendar popover, displays a long date, and stores a string such as
|
|
157
|
+
`"2026-11-02"` without a time or timezone.
|
|
158
|
+
- Use `type: "dateTime"` for a date and time in UTC. It renders TextField with the
|
|
159
|
+
browser's native `datetime-local` control, whose picker varies by browser and
|
|
160
|
+
operating system. FormEditor labels the field `(UTC)`, treats the entered
|
|
161
|
+
components as UTC, and emits a timestamp such as `"2026-11-02T09:00:00.000Z"`.
|
|
162
|
+
|
|
163
|
+
These field types carry different values. Changing between them requires the
|
|
164
|
+
application to choose and convert the time/timezone appropriately. The custom
|
|
165
|
+
calendar does not provide time selection.
|
|
166
|
+
|
|
167
|
+
### Select dropdowns
|
|
168
|
+
|
|
169
|
+
Use `type: "select"` for a dropdown. Supply its choices through `options`; the
|
|
170
|
+
stored value is the selected option's string `value`. Optional dropdowns include
|
|
171
|
+
a clear choice labelled by `placeholder` or `"None"`. Required dropdowns need a
|
|
172
|
+
selection. Choices can include descriptions and disabled options.
|
|
173
|
+
|
|
174
|
+
The select trigger uses the same `--field-radius` as text, colour and calendar
|
|
175
|
+
fields, including when Button styles load later. Floating menus and picker panels
|
|
176
|
+
use the shared overlay radius.
|
|
177
|
+
|
|
178
|
+
```tsx
|
|
179
|
+
export const dropdownSchema = {
|
|
180
|
+
fields: [{
|
|
181
|
+
id: "publicationStatus", type: "select", label: "Publication status",
|
|
182
|
+
placeholder: "Choose a status",
|
|
183
|
+
options: [
|
|
184
|
+
{ value: "draft", label: "Draft", description: "Still being written" },
|
|
185
|
+
{ value: "review", label: "In review" },
|
|
186
|
+
{ value: "published", label: "Published" },
|
|
187
|
+
],
|
|
188
|
+
}],
|
|
189
|
+
} satisfies FormSchema;
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Choice groups
|
|
193
|
+
|
|
194
|
+
`options` uses `SelectOption`: required `value: string`, `label: string`, optional
|
|
195
|
+
`description: string`, `isDisabled: boolean`. Group option values must be nonempty
|
|
196
|
+
and unique. Default appearance uses ChoiceGroup with shared Radio/Checkbox
|
|
197
|
+
controls; card appearance uses SelectionCardGroup with RadioCard/CheckboxCard.
|
|
198
|
+
Both support a single option. There are no individual radio or checkbox schema
|
|
199
|
+
types and no checkbox appearance for boolean fields.
|
|
200
|
+
|
|
201
|
+
#### Columns within each group
|
|
202
|
+
|
|
203
|
+
**Set `columns: 1 | 2 | 3` on each `radioGroup` or `checkboxGroup` field** to choose
|
|
204
|
+
the maximum number of options per row, with either `default` or `card` appearance.
|
|
205
|
+
This setting is independent of `<FormEditor columns={...}>`, which arranges whole
|
|
206
|
+
fields. Defaults are one option column for ordinary groups and two for cards.
|
|
207
|
+
Groups step down against their own width when options would be narrower than
|
|
208
|
+
`--choice-card-min-width` (default `15rem`).
|
|
209
|
+
|
|
210
|
+
```tsx
|
|
211
|
+
export const groupColumnsSchema = {
|
|
212
|
+
fields: [
|
|
213
|
+
{
|
|
214
|
+
id: "format", type: "radioGroup", label: "Format", columns: 3,
|
|
215
|
+
appearance: "default",
|
|
216
|
+
options: [{ value: "web", label: "Web" }, { value: "print", label: "Print" }, { value: "email", label: "Email" }],
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
id: "channels", type: "checkboxGroup", label: "Channels", columns: 2,
|
|
220
|
+
appearance: "card",
|
|
221
|
+
options: [{ value: "web", label: "Web" }, { value: "email", label: "Email" }],
|
|
222
|
+
},
|
|
223
|
+
],
|
|
224
|
+
} satisfies FormSchema;
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Standalone ChoiceGroup and SelectionCardGroup accept the same `columns` prop
|
|
228
|
+
directly, for example `<ChoiceGroup label="Channels" columns={3}>…</ChoiceGroup>`.
|
|
229
|
+
|
|
230
|
+
Required groups need at least one selected option. Required does not mark every
|
|
231
|
+
checkbox as individually mandatory. Checkbox groups keep their array shape even
|
|
232
|
+
with one option. The count badge shows selections, not available options.
|
|
233
|
+
|
|
234
|
+
Pass `options: []` while choices load: stored choices remain valid until options
|
|
235
|
+
arrive. Missing choices then fail validation. Disabled options cannot be changed,
|
|
236
|
+
but an existing disabled selection remains valid and is preserved. FormEditor
|
|
237
|
+
never prunes stored choices or applies defaults when a schema changes.
|
|
238
|
+
|
|
239
|
+
### Asset/reference picker options
|
|
240
|
+
|
|
241
|
+
`picker` accepts `label`, `addLabel`, `emptyLabel`, `itemLabel`, `itemsLabel`,
|
|
242
|
+
`max`, and `isReorderable`. `label` overrides the field's visible/accessibility
|
|
243
|
+
name, required message, default dialog title and action. Default item wording is
|
|
244
|
+
asset/assets or entry/entries, and the default action is `Choose {label}`.
|
|
245
|
+
Omitted or undefined options keep those defaults. Multiple selections are
|
|
246
|
+
reorderable by default. `picker.max` limits and validates multiple selections.
|
|
247
|
+
Available items are supplied through `pickerItems[field.id]`; fetching is external.
|
|
248
|
+
|
|
249
|
+
## Copyable field catalogue
|
|
250
|
+
|
|
251
|
+
```tsx
|
|
252
|
+
export const catalogue = {
|
|
253
|
+
fields: [
|
|
254
|
+
{ id: "headline", type: "shortText", label: "Headline", maxLength: 120 },
|
|
255
|
+
{ id: "summary", type: "longText", label: "Summary", rows: 4 },
|
|
256
|
+
{ id: "body", type: "richText", label: "Body" },
|
|
257
|
+
{ id: "priority", type: "number", label: "Priority", min: 0, hasSteppers: true },
|
|
258
|
+
{ id: "featured", type: "boolean", label: "Featured" },
|
|
259
|
+
{ id: "publishAt", type: "dateTime", label: "Publish at" },
|
|
260
|
+
{ id: "status", type: "select", label: "Status", options: [{ value: "draft", label: "Draft" }] },
|
|
261
|
+
{ id: "volume", type: "slider", label: "Volume", max: 10, suffix: "%" },
|
|
262
|
+
{ id: "fees", type: "rangeSlider", label: "Fees", max: 1000, prefix: "£" },
|
|
263
|
+
{ id: "accent", type: "colour", label: "Accent", presets: ["red", "transparent"] },
|
|
264
|
+
{ id: "rule", type: "divider" },
|
|
265
|
+
{
|
|
266
|
+
id: "format", type: "radioGroup", label: "Format", appearance: "default", columns: 2,
|
|
267
|
+
options: [{ value: "web", label: "Web" }, { value: "print", label: "Print" }],
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
id: "layout", type: "radioGroup", label: "Layout", appearance: "card", columns: 1,
|
|
271
|
+
options: [{ value: "feature", label: "Feature", description: "Large lead image" }],
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
id: "channels", type: "checkboxGroup", label: "Channels", appearance: "card", columns: 2,
|
|
275
|
+
options: [{ value: "web", label: "Web" }, { value: "print", label: "Print" }],
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
id: "extras", type: "checkboxGroup", label: "Extras", appearance: "default",
|
|
279
|
+
options: [{ value: "newsletter", label: "Include in newsletter" }],
|
|
280
|
+
},
|
|
281
|
+
{ id: "keywords", type: "tags", label: "Keywords", max: 5 },
|
|
282
|
+
{ id: "day", type: "date", label: "Day", min: "2026-01-01" },
|
|
283
|
+
{ id: "cover", type: "asset", label: "Cover" },
|
|
284
|
+
{ id: "gallery", type: "asset", label: "Gallery", multiple: true, picker: { max: 5 } },
|
|
285
|
+
{ id: "author", type: "reference", label: "Author" },
|
|
286
|
+
],
|
|
287
|
+
} satisfies FormSchema;
|
|
288
|
+
|
|
289
|
+
export const catalogueValues: FormValues = {
|
|
290
|
+
headline: "The view from here", summary: "A short introduction.",
|
|
291
|
+
body: { type: "doc", content: [] }, priority: 0, featured: false,
|
|
292
|
+
publishAt: "2026-11-02T09:00:00.000Z", status: "draft",
|
|
293
|
+
volume: 4, fees: { min: 100, max: 500 }, accent: "#66339980",
|
|
294
|
+
format: "web", layout: "feature", channels: ["web"], extras: [],
|
|
295
|
+
keywords: ["news"], day: "2026-11-02",
|
|
296
|
+
cover: { assetId: "cover-1" }, gallery: [{ assetId: "cover-1" }],
|
|
297
|
+
author: { entryId: "author-1" },
|
|
298
|
+
};
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
The catalogue block uses the imports from the basic example. Supply available
|
|
302
|
+
picker items before interacting with asset/reference examples.
|
|
303
|
+
|
|
304
|
+
## Values, clearing and validation
|
|
305
|
+
|
|
306
|
+
- `FormValues` is keyed by field ID; `undefined` means absent. Missing fields
|
|
307
|
+
render empty controls (sliders show fallback positions labelled `"Not set"`)
|
|
308
|
+
without emitting changes.
|
|
309
|
+
- Each edit reports the whole next value record and `{ fieldId }`. Use the ID for
|
|
310
|
+
API patches and dependent-field logic. Unrelated keys are preserved.
|
|
311
|
+
- Clearing numbers, date-times, colours, dates, selects, radio groups, or single
|
|
312
|
+
pickers removes their key. Empty text, rich-text documents and arrays retain
|
|
313
|
+
their shapes.
|
|
314
|
+
- Range sliders store two finite numeric endpoints, ordered and at least one
|
|
315
|
+
step apart. Bounds and ordering are checked even for loaded JSON. Numeric zero
|
|
316
|
+
and boolean false are populated values; required booleans accept false.
|
|
317
|
+
- Built-in messages appear after an edit or with `showAllErrors`. Loaded numeric,
|
|
318
|
+
slider, range, calendar-date and colour fields also show validation immediately,
|
|
319
|
+
so invalid displayed data has an explanation. Blank date and colour strings are
|
|
320
|
+
empty, so their required message waits like any other field's. App messages
|
|
321
|
+
take precedence.
|
|
322
|
+
- Valid colour edits use canonical uppercase hex. Invalid typing remains visible
|
|
323
|
+
and is included in FormValues so `validateFormValues` can block saving it.
|
|
324
|
+
Restoring an earlier value, such as a Discard action, replaces the invalid text.
|
|
325
|
+
This adapter behavior does not change standalone ColourField's canonical-only
|
|
326
|
+
`onValueChange` contract. Native picker support depends on the browser.
|
|
327
|
+
- `readOnly` is available on text and colour fields only. Disabled/read-only
|
|
328
|
+
fields block edits but still participate in validation; permissions and omission
|
|
329
|
+
from submitted data remain application decisions.
|
|
330
|
+
- Calendars open on the selected day, or today when empty, moved inside `min` and
|
|
331
|
+
`max`; arrow keys start from that day. Escape closes the calendar and returns to
|
|
332
|
+
its trigger without closing an enclosing Modal or Drawer, including after a click
|
|
333
|
+
on the calendar's heading or padding. Disabling a date field closes its calendar.
|
|
334
|
+
- `validateFormValues(schema, values)` checks unknown loaded data and returns
|
|
335
|
+
errors keyed by field ID. It does not mutate, normalize, or save values and
|
|
336
|
+
ignores dividers and unrelated keys. Run it immediately before saving. It uses
|
|
337
|
+
only pure helpers, without rendering or locale formatting.
|
|
338
|
+
- An optional radio group stored as `""` has no selection and shows no clear action.
|
|
339
|
+
|
|
340
|
+
Plain `hr` elements use the theme's `--rule-width` and `--rule-color` (muted border
|
|
341
|
+
by default). FormEditor dividers span the grid and use its gap instead of margins.
|
|
342
|
+
|
|
343
|
+
## Architecture and extension checklist for agents
|
|
344
|
+
|
|
345
|
+
1. **Model:** `model.ts` defines the discriminated FormField union, FormItem,
|
|
346
|
+
value shapes, schema assertions, validation and safe compound-value readers.
|
|
347
|
+
FormField means data; FormDivider means layout. Keep these separate. Import only
|
|
348
|
+
pure modules here (`Slider/scale.ts`, `DatePicker/date.ts`, `ColourField/colour.ts`),
|
|
349
|
+
never component entry points, so validation stays cheap outside the browser.
|
|
350
|
+
Slider defaults live once in `Slider/scale.ts`; resolve them with `sliderScale`.
|
|
351
|
+
2. **Adapters:** `control.tsx` maps existing fields to shared components;
|
|
352
|
+
`additional-control.tsx` and `choice-control.tsx` handle the expanded controls.
|
|
353
|
+
Translate clear events and Field bindings here. Do not copy control styling.
|
|
354
|
+
3. **State/frame:** `index.tsx` asserts the schema, owns controlled/uncontrolled
|
|
355
|
+
wiring and changed-field tracking, and supplies one Field frame per field.
|
|
356
|
+
Group bindings use fieldsets without duplicating legends or descriptions.
|
|
357
|
+
4. **Layout:** `style.css` owns responsive columns and form-specific layout only.
|
|
358
|
+
Shared controls, Button, Field and theme tokens own their appearance.
|
|
359
|
+
|
|
360
|
+
When adding or changing a field:
|
|
361
|
+
|
|
362
|
+
- Add its discriminator/options and stored-value shape. Validate malformed loaded
|
|
363
|
+
data, required/empty cases and configured limits. Update schema assertions.
|
|
364
|
+
- Add a shared-component adapter with controlled values, explicit clears, disabled
|
|
365
|
+
handling and no mount edits. Use Button for every action. Expose autofocus and
|
|
366
|
+
read-only only when the underlying control supports them.
|
|
367
|
+
- Set group semantics, unique option names, member labels and counts as needed.
|
|
368
|
+
Keep app errors above built-in errors and preserve unrelated values.
|
|
369
|
+
- Update root and component exports, this guide's tables/examples/defaults,
|
|
370
|
+
stories, behavior/accessibility tests and packed-package smoke examples.
|
|
371
|
+
- Add a decision document and Unreleased adoption/compatibility/verification notes.
|
|
372
|
+
New shared form controls need a FormEditor adapter or an explicit exclusion in
|
|
373
|
+
their decision document. Keep this architecture map current.
|
|
374
|
+
- Run library validation and package/browser checks. The release workflow owns
|
|
375
|
+
versions. Finish with verification results and suggested Git commit text.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ControlProps } from "./control.cjs";
|
|
2
|
+
import { type FieldOf } from "./model.cjs";
|
|
3
|
+
type AdditionalField = FieldOf<"slider" | "rangeSlider" | "date" | "colour" | "tags" | "radioGroup" | "checkboxGroup">;
|
|
4
|
+
export declare function AdditionalControl({ field, stored, isDisabled, required, accessibility, onChange, }: ControlProps<AdditionalField>): import("react").JSX.Element;
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=additional-control.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"additional-control.d.cts","sourceRoot":"","sources":["../../../src/components/FormEditor/additional-control.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAA6C,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAElF,KAAK,eAAe,GAAG,OAAO,CAC5B,QAAQ,GAAG,aAAa,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,YAAY,GAAG,eAAe,CACvF,CAAC;AAoEF,wBAAgB,iBAAiB,CAAC,EAChC,KAAK,EACL,MAAM,EACN,UAAU,EACV,QAAQ,EACR,aAAa,EACb,QAAQ,GACT,EAAE,YAAY,CAAC,eAAe,CAAC,+BA4E/B"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ControlProps } from "./control.js";
|
|
2
|
+
import { type FieldOf } from "./model.js";
|
|
3
|
+
type AdditionalField = FieldOf<"slider" | "rangeSlider" | "date" | "colour" | "tags" | "radioGroup" | "checkboxGroup">;
|
|
4
|
+
export declare function AdditionalControl({ field, stored, isDisabled, required, accessibility, onChange, }: ControlProps<AdditionalField>): import("react").JSX.Element;
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=additional-control.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"additional-control.d.ts","sourceRoot":"","sources":["../../../src/components/FormEditor/additional-control.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAA6C,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAElF,KAAK,eAAe,GAAG,OAAO,CAC5B,QAAQ,GAAG,aAAa,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,YAAY,GAAG,eAAe,CACvF,CAAC;AAoEF,wBAAgB,iBAAiB,CAAC,EAChC,KAAK,EACL,MAAM,EACN,UAAU,EACV,QAAQ,EACR,aAAa,EACb,QAAQ,GACT,EAAE,YAAY,CAAC,eAAe,CAAC,+BA4E/B"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ControlProps } from "./control.cjs";
|
|
2
|
+
import { type FieldOf } from "./model.cjs";
|
|
3
|
+
type ChoiceField = FieldOf<"radioGroup" | "checkboxGroup">;
|
|
4
|
+
export declare function ChoiceControl({ field, stored, isDisabled, required, accessibility, onChange, }: ControlProps<ChoiceField>): import("react").JSX.Element;
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=choice-control.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"choice-control.d.cts","sourceRoot":"","sources":["../../../src/components/FormEditor/choice-control.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAc,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAEnD,KAAK,WAAW,GAAG,OAAO,CAAC,YAAY,GAAG,eAAe,CAAC,CAAC;AAsD3D,wBAAgB,aAAa,CAAC,EAC5B,KAAK,EACL,MAAM,EACN,UAAU,EACV,QAAQ,EACR,aAAa,EACb,QAAQ,GACT,EAAE,YAAY,CAAC,WAAW,CAAC,+BAmD3B"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ControlProps } from "./control.js";
|
|
2
|
+
import { type FieldOf } from "./model.js";
|
|
3
|
+
type ChoiceField = FieldOf<"radioGroup" | "checkboxGroup">;
|
|
4
|
+
export declare function ChoiceControl({ field, stored, isDisabled, required, accessibility, onChange, }: ControlProps<ChoiceField>): import("react").JSX.Element;
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=choice-control.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"choice-control.d.ts","sourceRoot":"","sources":["../../../src/components/FormEditor/choice-control.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAc,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAEnD,KAAK,WAAW,GAAG,OAAO,CAAC,YAAY,GAAG,eAAe,CAAC,CAAC;AAsD3D,wBAAgB,aAAa,CAAC,EAC5B,KAAK,EACL,MAAM,EACN,UAAU,EACV,QAAQ,EACR,aAAa,EACb,QAAQ,GACT,EAAE,YAAY,CAAC,WAAW,CAAC,+BAmD3B"}
|
|
@@ -2,6 +2,14 @@ import { type EntryItem } from "../EntryPicker/index.cjs";
|
|
|
2
2
|
import type { FieldRenderProps } from "../Field/index.cjs";
|
|
3
3
|
import { type FormField, type FormFieldValue } from "./model.cjs";
|
|
4
4
|
type Accessibility = FieldRenderProps;
|
|
5
|
+
export interface ControlProps<F extends FormField> {
|
|
6
|
+
field: F;
|
|
7
|
+
stored: FormFieldValue | undefined;
|
|
8
|
+
isDisabled: boolean;
|
|
9
|
+
required: boolean | undefined;
|
|
10
|
+
accessibility: Omit<Accessibility, "required">;
|
|
11
|
+
onChange: (value: FormFieldValue | undefined) => void;
|
|
12
|
+
}
|
|
5
13
|
interface FormControlProps {
|
|
6
14
|
field: FormField;
|
|
7
15
|
stored: FormFieldValue | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control.d.cts","sourceRoot":"","sources":["../../../src/components/FormEditor/control.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"control.d.cts","sourceRoot":"","sources":["../../../src/components/FormEditor/control.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAQjD,OAAO,EAIL,KAAK,SAAS,EACd,KAAK,cAAc,EACpB,MAAM,SAAS,CAAC;AAcjB,KAAK,aAAa,GAAG,gBAAgB,CAAC;AAEtC,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,SAAS;IAC/C,KAAK,EAAE,CAAC,CAAC;IACT,MAAM,EAAE,cAAc,GAAG,SAAS,CAAC;IACnC,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;IAC/C,QAAQ,EAAE,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,KAAK,IAAI,CAAC;CACvD;AAmFD,UAAU,gBAAgB;IACxB,KAAK,EAAE,SAAS,CAAC;IACjB,MAAM,EAAE,cAAc,GAAG,SAAS,CAAC;IACnC,mEAAmE;IACnE,QAAQ,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC/B,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,aAAa,EAAE,aAAa,CAAC;IAC7B,QAAQ,EAAE,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,KAAK,IAAI,CAAC;CACvD;AAED,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,MAAM,EACN,QAAQ,EACR,KAAK,EACL,UAAU,EACV,aAAa,EAAE,EAAE,QAAQ,EAAE,GAAG,aAAa,EAAE,EAC7C,QAAQ,GACT,EAAE,gBAAgB,+BAqGlB"}
|
|
@@ -2,6 +2,14 @@ import { type EntryItem } from "../EntryPicker/index.js";
|
|
|
2
2
|
import type { FieldRenderProps } from "../Field/index.js";
|
|
3
3
|
import { type FormField, type FormFieldValue } from "./model.js";
|
|
4
4
|
type Accessibility = FieldRenderProps;
|
|
5
|
+
export interface ControlProps<F extends FormField> {
|
|
6
|
+
field: F;
|
|
7
|
+
stored: FormFieldValue | undefined;
|
|
8
|
+
isDisabled: boolean;
|
|
9
|
+
required: boolean | undefined;
|
|
10
|
+
accessibility: Omit<Accessibility, "required">;
|
|
11
|
+
onChange: (value: FormFieldValue | undefined) => void;
|
|
12
|
+
}
|
|
5
13
|
interface FormControlProps {
|
|
6
14
|
field: FormField;
|
|
7
15
|
stored: FormFieldValue | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control.d.ts","sourceRoot":"","sources":["../../../src/components/FormEditor/control.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"control.d.ts","sourceRoot":"","sources":["../../../src/components/FormEditor/control.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAQjD,OAAO,EAIL,KAAK,SAAS,EACd,KAAK,cAAc,EACpB,MAAM,SAAS,CAAC;AAcjB,KAAK,aAAa,GAAG,gBAAgB,CAAC;AAEtC,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,SAAS;IAC/C,KAAK,EAAE,CAAC,CAAC;IACT,MAAM,EAAE,cAAc,GAAG,SAAS,CAAC;IACnC,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;IAC/C,QAAQ,EAAE,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,KAAK,IAAI,CAAC;CACvD;AAmFD,UAAU,gBAAgB;IACxB,KAAK,EAAE,SAAS,CAAC;IACjB,MAAM,EAAE,cAAc,GAAG,SAAS,CAAC;IACnC,mEAAmE;IACnE,QAAQ,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC/B,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,aAAa,EAAE,aAAa,CAAC;IAC7B,QAAQ,EAAE,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,KAAK,IAAI,CAAC;CACvD;AAED,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,MAAM,EACN,QAAQ,EACR,KAAK,EACL,UAAU,EACV,aAAa,EAAE,EAAE,QAAQ,EAAE,GAAG,aAAa,EAAE,EAC7C,QAAQ,GACT,EAAE,gBAAgB,+BAqGlB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require("../Field/index.cjs");const e=require("../../chunks/FormEditor-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require("../Field/index.cjs");const e=require("../../chunks/FormEditor-UzbPdiJo.cjs");exports.FormEditor=e.t,exports.validateFormValues=e.n;
|
|
@@ -3,7 +3,7 @@ import type { EntryItem } from "../EntryPicker/index.cjs";
|
|
|
3
3
|
import type { GridColumns } from "../Grid/index.cjs";
|
|
4
4
|
import { type FormSchema, type FormErrors, type FormValues } from "./model.cjs";
|
|
5
5
|
export { validateFormValues } from "./model.cjs";
|
|
6
|
-
export type { AssetValue, FormField, FormSchema, FormErrors, FormFieldValue, FormValues, ReferenceValue, } from "./model.cjs";
|
|
6
|
+
export type { AssetValue, FormField, FormDivider, FormItem, FormSchema, FormErrors, FormFieldValue, FormValues, ReferenceValue, } from "./model.cjs";
|
|
7
7
|
export interface FormChange {
|
|
8
8
|
fieldId: string;
|
|
9
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/components/FormEditor/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAyC,KAAK,cAAc,EAAE,MAAM,OAAO,CAAC;AACnF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/components/FormEditor/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAyC,KAAK,cAAc,EAAE,MAAM,OAAO,CAAC;AACnF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,EAOL,KAAK,UAAU,EACf,KAAK,UAAU,EAEf,KAAK,UAAU,EAChB,MAAM,SAAS,CAAC;AACjB,OAAO,aAAa,CAAC;AAErB,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,YAAY,EACV,UAAU,EACV,SAAS,EACT,WAAW,EACX,QAAQ,EACR,UAAU,EACV,UAAU,EACV,cAAc,EACd,UAAU,EACV,cAAc,GACf,MAAM,SAAS,CAAC;AAEjB,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,eAAgB,SAAQ,IAAI,CAC3C,cAAc,CAAC,cAAc,CAAC,EAC9B,cAAc,GAAG,UAAU,CAC5B;IACC,MAAM,EAAE,UAAU,CAAC;IACnB,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,YAAY,CAAC,EAAE,UAAU,CAAC;IAC1B,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IACjE,kFAAkF;IAClF,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;IAC1C,sEAAsE;IACtE,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,0GAA0G;IAC1G,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,gEAAgE;IAChE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AA4DD,qFAAqF;AACrF,wBAAgB,UAAU,CAAC,EACzB,MAAM,EACN,KAAK,EACL,YAAiB,EACjB,aAAa,EACb,WAAgB,EAChB,MAAW,EACX,UAAkB,EAClB,aAAqB,EACrB,OAAW,EACX,cAAwB,EACxB,SAAS,EACT,KAAK,EACL,GAAG,IAAI,EACR,EAAE,eAAe,+BAwEjB"}
|
|
@@ -3,7 +3,7 @@ import type { EntryItem } from "../EntryPicker/index.js";
|
|
|
3
3
|
import type { GridColumns } from "../Grid/index.js";
|
|
4
4
|
import { type FormSchema, type FormErrors, type FormValues } from "./model.js";
|
|
5
5
|
export { validateFormValues } from "./model.js";
|
|
6
|
-
export type { AssetValue, FormField, FormSchema, FormErrors, FormFieldValue, FormValues, ReferenceValue, } from "./model.js";
|
|
6
|
+
export type { AssetValue, FormField, FormDivider, FormItem, FormSchema, FormErrors, FormFieldValue, FormValues, ReferenceValue, } from "./model.js";
|
|
7
7
|
export interface FormChange {
|
|
8
8
|
fieldId: string;
|
|
9
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/FormEditor/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAyC,KAAK,cAAc,EAAE,MAAM,OAAO,CAAC;AACnF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/FormEditor/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAyC,KAAK,cAAc,EAAE,MAAM,OAAO,CAAC;AACnF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,EAOL,KAAK,UAAU,EACf,KAAK,UAAU,EAEf,KAAK,UAAU,EAChB,MAAM,SAAS,CAAC;AACjB,OAAO,aAAa,CAAC;AAErB,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,YAAY,EACV,UAAU,EACV,SAAS,EACT,WAAW,EACX,QAAQ,EACR,UAAU,EACV,UAAU,EACV,cAAc,EACd,UAAU,EACV,cAAc,GACf,MAAM,SAAS,CAAC;AAEjB,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,eAAgB,SAAQ,IAAI,CAC3C,cAAc,CAAC,cAAc,CAAC,EAC9B,cAAc,GAAG,UAAU,CAC5B;IACC,MAAM,EAAE,UAAU,CAAC;IACnB,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,YAAY,CAAC,EAAE,UAAU,CAAC;IAC1B,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IACjE,kFAAkF;IAClF,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;IAC1C,sEAAsE;IACtE,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,0GAA0G;IAC1G,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,gEAAgE;IAChE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AA4DD,qFAAqF;AACrF,wBAAgB,UAAU,CAAC,EACzB,MAAM,EACN,KAAK,EACL,YAAiB,EACjB,aAAa,EACb,WAAgB,EAChB,MAAW,EACX,UAAkB,EAClB,aAAqB,EACrB,OAAW,EACX,cAAwB,EACxB,SAAS,EACT,KAAK,EACL,GAAG,IAAI,EACR,EAAE,eAAe,+BAwEjB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import "../Field/index.js";
|
|
2
|
-
export { t as FormEditor, n as validateFormValues } from "../../chunks/FormEditor-
|
|
2
|
+
export { t as FormEditor, n as validateFormValues } from "../../chunks/FormEditor-M7tNidFo.js";
|
|
@@ -2,6 +2,9 @@ import type { ReactNode } from "react";
|
|
|
2
2
|
import type { SelectOption } from "../Select/index.cjs";
|
|
3
3
|
import type { EntryPickerProps } from "../EntryPicker/index.cjs";
|
|
4
4
|
import type { RichTextDocument } from "../RichTextEditor/index.cjs";
|
|
5
|
+
import type { RangeSliderValue } from "../Slider/index.cjs";
|
|
6
|
+
import { type SliderScale } from "../Slider/scale.cjs";
|
|
7
|
+
import type { PopoverPlacement } from "../Popover/index.cjs";
|
|
5
8
|
interface FormFieldBase {
|
|
6
9
|
id: string;
|
|
7
10
|
label: string;
|
|
@@ -10,6 +13,23 @@ interface FormFieldBase {
|
|
|
10
13
|
required?: boolean;
|
|
11
14
|
isDisabled?: boolean;
|
|
12
15
|
}
|
|
16
|
+
interface SliderOptions {
|
|
17
|
+
multiple?: never;
|
|
18
|
+
min?: number;
|
|
19
|
+
max?: number;
|
|
20
|
+
step?: number;
|
|
21
|
+
prefix?: string;
|
|
22
|
+
suffix?: string;
|
|
23
|
+
hasValueLabel?: boolean;
|
|
24
|
+
}
|
|
25
|
+
interface ChoiceOptions {
|
|
26
|
+
multiple?: never;
|
|
27
|
+
autoFocus?: never;
|
|
28
|
+
options: SelectOption[];
|
|
29
|
+
appearance?: "default" | "card";
|
|
30
|
+
/** Maximum options per row inside this group; independent of FormEditor columns. */
|
|
31
|
+
columns?: 1 | 2 | 3;
|
|
32
|
+
}
|
|
13
33
|
export type FormField = FormFieldBase & ({
|
|
14
34
|
type: "shortText";
|
|
15
35
|
inputType?: "text" | "email";
|
|
@@ -45,6 +65,37 @@ export type FormField = FormFieldBase & ({
|
|
|
45
65
|
options: SelectOption[];
|
|
46
66
|
autoFocus?: boolean;
|
|
47
67
|
multiple?: never;
|
|
68
|
+
} | ({
|
|
69
|
+
type: "slider";
|
|
70
|
+
autoFocus?: boolean;
|
|
71
|
+
} & SliderOptions) | ({
|
|
72
|
+
type: "rangeSlider";
|
|
73
|
+
autoFocus?: never;
|
|
74
|
+
} & SliderOptions) | ({
|
|
75
|
+
type: "radioGroup";
|
|
76
|
+
} & ChoiceOptions) | ({
|
|
77
|
+
type: "checkboxGroup";
|
|
78
|
+
} & ChoiceOptions) | {
|
|
79
|
+
type: "colour";
|
|
80
|
+
multiple?: never;
|
|
81
|
+
presets?: string[];
|
|
82
|
+
showPresets?: boolean;
|
|
83
|
+
picker?: "custom" | "native";
|
|
84
|
+
placement?: PopoverPlacement;
|
|
85
|
+
readOnly?: boolean;
|
|
86
|
+
autoFocus?: boolean;
|
|
87
|
+
} | {
|
|
88
|
+
type: "tags";
|
|
89
|
+
max?: number;
|
|
90
|
+
multiple?: never;
|
|
91
|
+
autoFocus?: never;
|
|
92
|
+
} | {
|
|
93
|
+
type: "date";
|
|
94
|
+
min?: string;
|
|
95
|
+
max?: string;
|
|
96
|
+
placement?: PopoverPlacement;
|
|
97
|
+
multiple?: never;
|
|
98
|
+
autoFocus?: never;
|
|
48
99
|
} | {
|
|
49
100
|
type: "asset" | "reference";
|
|
50
101
|
multiple?: boolean;
|
|
@@ -54,8 +105,14 @@ export type FormField = FormFieldBase & ({
|
|
|
54
105
|
export type FieldOf<T extends FormField["type"]> = Extract<FormField, {
|
|
55
106
|
type: T;
|
|
56
107
|
}>;
|
|
108
|
+
/** Layout only: no label, value, disabled state, or validation. */
|
|
109
|
+
export interface FormDivider {
|
|
110
|
+
id: string;
|
|
111
|
+
type: "divider";
|
|
112
|
+
}
|
|
113
|
+
export type FormItem = FormField | FormDivider;
|
|
57
114
|
export interface FormSchema {
|
|
58
|
-
fields: readonly
|
|
115
|
+
fields: readonly FormItem[];
|
|
59
116
|
}
|
|
60
117
|
export interface AssetValue {
|
|
61
118
|
assetId: string;
|
|
@@ -63,7 +120,7 @@ export interface AssetValue {
|
|
|
63
120
|
export interface ReferenceValue {
|
|
64
121
|
entryId: string;
|
|
65
122
|
}
|
|
66
|
-
export type FormFieldValue = string | number | boolean | RichTextDocument | AssetValue | ReferenceValue | AssetValue[] | ReferenceValue[];
|
|
123
|
+
export type FormFieldValue = string | number | boolean | RichTextDocument | AssetValue | ReferenceValue | string[] | RangeSliderValue | AssetValue[] | ReferenceValue[];
|
|
67
124
|
export type FormValues = Record<string, FormFieldValue | undefined>;
|
|
68
125
|
export type FormErrors = Partial<Record<string, string>>;
|
|
69
126
|
export declare function assertModel(model: FormSchema): void;
|
|
@@ -82,6 +139,15 @@ export declare function pickerCopy(field: FieldOf<"asset" | "reference">): {
|
|
|
82
139
|
export declare function selectedIds(field: FieldOf<"asset" | "reference">, value: unknown): string[];
|
|
83
140
|
/** Accept UTC ISO strings without rolling invalid dates into the next month. */
|
|
84
141
|
export declare function parseUtcDateTime(value: unknown): string | undefined;
|
|
142
|
+
export declare function stringList(value: unknown): string[];
|
|
143
|
+
/**
|
|
144
|
+
* Display positions for loaded values: out-of-scale numbers clamp and reversed
|
|
145
|
+
* endpoints swap, without overwriting the stored data that validation reports.
|
|
146
|
+
* A value that is not a finite number has no position, so the control is unset.
|
|
147
|
+
*/
|
|
148
|
+
export declare function sliderValue(value: unknown, scale: SliderScale): number | undefined;
|
|
149
|
+
/** A range with neither endpoint usable is unset; one usable endpoint pairs with the scale's end. */
|
|
150
|
+
export declare function rangeSliderValue(value: unknown, scale: SliderScale): RangeSliderValue | undefined;
|
|
85
151
|
export declare function fieldError(field: FormField, value: unknown): string | undefined;
|
|
86
152
|
/** Validate data loaded from JSON as well as values emitted by FormEditor. */
|
|
87
153
|
export declare function validateFormValues(model: FormSchema, values: Record<string, unknown>): FormErrors;
|