@panneau/forms 5.0.0-alpha.5 → 5.0.0-alpha.7
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 +1 -0
- package/dist/ConflictDialog.js +200 -63
- package/dist/ConflictDialog.js.map +1 -1
- package/dist/ErrorSummary.js.map +1 -1
- package/dist/FieldErrorBoundary.js.map +1 -1
- package/dist/Form.css +24 -0
- package/dist/Form.d.ts +2 -1
- package/dist/Form.d.ts.map +1 -1
- package/dist/Form.js +126 -20
- package/dist/Form.js.map +1 -1
- package/dist/Form.module.js +10 -2
- package/dist/Form.module.js.map +1 -1
- package/dist/FormBinding.js.map +1 -1
- package/dist/FormSkeleton.d.ts +21 -0
- package/dist/FormSkeleton.d.ts.map +1 -0
- package/dist/FormSkeleton.js +402 -0
- package/dist/FormSkeleton.js.map +1 -0
- package/dist/FormView.d.ts +6 -1
- package/dist/FormView.d.ts.map +1 -1
- package/dist/FormView.js +194 -61
- package/dist/FormView.js.map +1 -1
- package/dist/context.js.map +1 -1
- package/dist/cx.js.map +1 -1
- package/dist/describe.js.map +1 -1
- package/dist/formatError.js.map +1 -1
- package/dist/layout/Layout.js.map +1 -1
- package/dist/locales/index.js.map +1 -1
- package/dist/paths.js.map +1 -1
- package/dist/unsaved.js.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -61,6 +61,7 @@ Under a `PanneauProvider`, forms use the field components of the plugins and the
|
|
|
61
61
|
| Unsaved changes | The page asks before closing (`guardUnsavedChanges`). Under a `LeaveGuardsProvider` of `@panneau/core`, leaving through the app's router asks in a dialog too; `useLeaveConfirmation()` gives that dialog to other routers |
|
|
62
62
|
| Broken fields | Each field has an error boundary: a field that throws shows a message, the rest of the form keeps working |
|
|
63
63
|
| Version conflicts | A dialog shows the values that differ, then loads the current version or saves the local one over it |
|
|
64
|
+
| Loading | With `isLoading`, while the item loads: a skeleton of the layout, and of each field, its label and a block of its height ([0034](../../docs/decisions/0034-skeletons-while-content-loads.md)) |
|
|
64
65
|
|
|
65
66
|
`Form` creates its state with `useForm()`. To keep the state outside, use `useForm()` and `FormView`.
|
|
66
67
|
|
package/dist/ConflictDialog.js
CHANGED
|
@@ -52,72 +52,209 @@ function _temp2(label_0) {
|
|
|
52
52
|
function _temp(entry_0) {
|
|
53
53
|
return entry_0 !== null && typeof entry_0 === "object" && "label" in entry_0 ? String(entry_0.label) : null;
|
|
54
54
|
}
|
|
55
|
-
function ConflictDialog(
|
|
55
|
+
function ConflictDialog(t0) {
|
|
56
|
+
const $ = c(58);
|
|
57
|
+
const { isOpen, fields, values, current, onReload, onOverwrite, isPending: t1, className } = t0;
|
|
58
|
+
const isPending = t1 === void 0 ? false : t1;
|
|
56
59
|
const intl = usePanneauIntl();
|
|
57
60
|
const format = useFormatValue();
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
61
|
+
let T0;
|
|
62
|
+
let t10;
|
|
63
|
+
let t11;
|
|
64
|
+
let t12;
|
|
65
|
+
let t2;
|
|
66
|
+
let t3;
|
|
67
|
+
let t4;
|
|
68
|
+
let t5;
|
|
69
|
+
let t6;
|
|
70
|
+
let t7;
|
|
71
|
+
let t8;
|
|
72
|
+
let t9;
|
|
73
|
+
if ($[0] !== className || $[1] !== current || $[2] !== fields || $[3] !== format || $[4] !== intl || $[5] !== isOpen || $[6] !== isPending || $[7] !== onOverwrite || $[8] !== onReload || $[9] !== values) {
|
|
74
|
+
const theirs = current !== null ? getItemValues(current, fields.map(_temp3)) : null;
|
|
75
|
+
const changed = theirs !== null ? fields.filter((field_0) => !isEqual(values[field_0.name] ?? null, theirs[field_0.name] ?? null)) : [];
|
|
76
|
+
T0 = Dialog;
|
|
77
|
+
t5 = isOpen;
|
|
78
|
+
t6 = "alertdialog";
|
|
79
|
+
t7 = false;
|
|
80
|
+
t8 = true;
|
|
81
|
+
if ($[22] !== intl) {
|
|
82
|
+
t9 = intl.formatMessage(messages.conflictTitle);
|
|
83
|
+
$[22] = intl;
|
|
84
|
+
$[23] = t9;
|
|
85
|
+
} else t9 = $[23];
|
|
86
|
+
t10 = "lg";
|
|
87
|
+
t11 = className;
|
|
88
|
+
let t13;
|
|
89
|
+
if ($[24] !== intl) {
|
|
90
|
+
t13 = intl.formatMessage(messages.loadCurrent);
|
|
91
|
+
$[24] = intl;
|
|
92
|
+
$[25] = t13;
|
|
93
|
+
} else t13 = $[25];
|
|
94
|
+
let t14;
|
|
95
|
+
if ($[26] !== isPending || $[27] !== onReload || $[28] !== t13) {
|
|
96
|
+
t14 = /* @__PURE__ */ jsx(Button, {
|
|
97
|
+
onPress: onReload,
|
|
98
|
+
isDisabled: isPending,
|
|
99
|
+
children: t13
|
|
100
|
+
});
|
|
101
|
+
$[26] = isPending;
|
|
102
|
+
$[27] = onReload;
|
|
103
|
+
$[28] = t13;
|
|
104
|
+
$[29] = t14;
|
|
105
|
+
} else t14 = $[29];
|
|
106
|
+
let t15;
|
|
107
|
+
if ($[30] !== intl) {
|
|
108
|
+
t15 = intl.formatMessage(messages.overwrite);
|
|
109
|
+
$[30] = intl;
|
|
110
|
+
$[31] = t15;
|
|
111
|
+
} else t15 = $[31];
|
|
112
|
+
let t16;
|
|
113
|
+
if ($[32] !== isPending || $[33] !== onOverwrite || $[34] !== t15) {
|
|
114
|
+
t16 = /* @__PURE__ */ jsx(Button, {
|
|
115
|
+
variant: "danger",
|
|
116
|
+
onPress: onOverwrite,
|
|
117
|
+
isPending,
|
|
118
|
+
children: t15
|
|
119
|
+
});
|
|
120
|
+
$[32] = isPending;
|
|
121
|
+
$[33] = onOverwrite;
|
|
122
|
+
$[34] = t15;
|
|
123
|
+
$[35] = t16;
|
|
124
|
+
} else t16 = $[35];
|
|
125
|
+
if ($[36] !== t14 || $[37] !== t16) {
|
|
126
|
+
t12 = /* @__PURE__ */ jsxs(Fragment, { children: [t14, t16] });
|
|
127
|
+
$[36] = t14;
|
|
128
|
+
$[37] = t16;
|
|
129
|
+
$[38] = t12;
|
|
130
|
+
} else t12 = $[38];
|
|
131
|
+
t2 = ConflictDialog_module_default.body;
|
|
132
|
+
let t17;
|
|
133
|
+
if ($[39] !== intl) {
|
|
134
|
+
t17 = intl.formatMessage(messages.conflictMessage);
|
|
135
|
+
$[39] = intl;
|
|
136
|
+
$[40] = t17;
|
|
137
|
+
} else t17 = $[40];
|
|
138
|
+
if ($[41] !== t17) {
|
|
139
|
+
t3 = /* @__PURE__ */ jsx("p", {
|
|
81
140
|
className: ConflictDialog_module_default.message,
|
|
82
|
-
children:
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
141
|
+
children: t17
|
|
142
|
+
});
|
|
143
|
+
$[41] = t17;
|
|
144
|
+
$[42] = t3;
|
|
145
|
+
} else t3 = $[42];
|
|
146
|
+
t4 = theirs === null ? /* @__PURE__ */ jsx("p", {
|
|
147
|
+
className: ConflictDialog_module_default.muted,
|
|
148
|
+
children: intl.formatMessage(messages.conflictUnknown)
|
|
149
|
+
}) : changed.length > 0 ? /* @__PURE__ */ jsxs("section", {
|
|
150
|
+
"aria-labelledby": "panneau-conflict-changes",
|
|
151
|
+
children: [/* @__PURE__ */ jsx("h3", {
|
|
152
|
+
id: "panneau-conflict-changes",
|
|
153
|
+
className: ConflictDialog_module_default.heading,
|
|
154
|
+
children: intl.formatMessage(messages.conflictChanges)
|
|
155
|
+
}), /* @__PURE__ */ jsx("dl", {
|
|
156
|
+
className: ConflictDialog_module_default.changes,
|
|
157
|
+
children: changed.map((field_1) => /* @__PURE__ */ jsxs("div", {
|
|
158
|
+
className: ConflictDialog_module_default.change,
|
|
159
|
+
children: [
|
|
160
|
+
/* @__PURE__ */ jsx("dt", {
|
|
161
|
+
className: ConflictDialog_module_default.label,
|
|
162
|
+
children: field_1.label ?? field_1.name
|
|
163
|
+
}),
|
|
164
|
+
/* @__PURE__ */ jsxs("dd", {
|
|
165
|
+
className: ConflictDialog_module_default.version,
|
|
166
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
167
|
+
className: ConflictDialog_module_default.which,
|
|
168
|
+
children: intl.formatMessage(messages.yours)
|
|
169
|
+
}), format(values[field_1.name], field_1)]
|
|
170
|
+
}),
|
|
171
|
+
/* @__PURE__ */ jsxs("dd", {
|
|
172
|
+
className: ConflictDialog_module_default.version,
|
|
173
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
174
|
+
className: ConflictDialog_module_default.which,
|
|
175
|
+
children: intl.formatMessage(messages.current)
|
|
176
|
+
}), format(theirs[field_1.name], field_1)]
|
|
177
|
+
})
|
|
178
|
+
]
|
|
179
|
+
}, field_1.name))
|
|
180
|
+
})]
|
|
181
|
+
}) : null;
|
|
182
|
+
$[0] = className;
|
|
183
|
+
$[1] = current;
|
|
184
|
+
$[2] = fields;
|
|
185
|
+
$[3] = format;
|
|
186
|
+
$[4] = intl;
|
|
187
|
+
$[5] = isOpen;
|
|
188
|
+
$[6] = isPending;
|
|
189
|
+
$[7] = onOverwrite;
|
|
190
|
+
$[8] = onReload;
|
|
191
|
+
$[9] = values;
|
|
192
|
+
$[10] = T0;
|
|
193
|
+
$[11] = t10;
|
|
194
|
+
$[12] = t11;
|
|
195
|
+
$[13] = t12;
|
|
196
|
+
$[14] = t2;
|
|
197
|
+
$[15] = t3;
|
|
198
|
+
$[16] = t4;
|
|
199
|
+
$[17] = t5;
|
|
200
|
+
$[18] = t6;
|
|
201
|
+
$[19] = t7;
|
|
202
|
+
$[20] = t8;
|
|
203
|
+
$[21] = t9;
|
|
204
|
+
} else {
|
|
205
|
+
T0 = $[10];
|
|
206
|
+
t10 = $[11];
|
|
207
|
+
t11 = $[12];
|
|
208
|
+
t12 = $[13];
|
|
209
|
+
t2 = $[14];
|
|
210
|
+
t3 = $[15];
|
|
211
|
+
t4 = $[16];
|
|
212
|
+
t5 = $[17];
|
|
213
|
+
t6 = $[18];
|
|
214
|
+
t7 = $[19];
|
|
215
|
+
t8 = $[20];
|
|
216
|
+
t9 = $[21];
|
|
217
|
+
}
|
|
218
|
+
let t13;
|
|
219
|
+
if ($[43] !== t2 || $[44] !== t3 || $[45] !== t4) {
|
|
220
|
+
t13 = /* @__PURE__ */ jsxs("div", {
|
|
221
|
+
className: t2,
|
|
222
|
+
children: [t3, t4]
|
|
223
|
+
});
|
|
224
|
+
$[43] = t2;
|
|
225
|
+
$[44] = t3;
|
|
226
|
+
$[45] = t4;
|
|
227
|
+
$[46] = t13;
|
|
228
|
+
} else t13 = $[46];
|
|
229
|
+
let t14;
|
|
230
|
+
if ($[47] !== T0 || $[48] !== t10 || $[49] !== t11 || $[50] !== t12 || $[51] !== t13 || $[52] !== t5 || $[53] !== t6 || $[54] !== t7 || $[55] !== t8 || $[56] !== t9) {
|
|
231
|
+
t14 = /* @__PURE__ */ jsx(T0, {
|
|
232
|
+
isOpen: t5,
|
|
233
|
+
role: t6,
|
|
234
|
+
isDismissable: t7,
|
|
235
|
+
isKeyboardDismissDisabled: t8,
|
|
236
|
+
title: t9,
|
|
237
|
+
size: t10,
|
|
238
|
+
className: t11,
|
|
239
|
+
footer: t12,
|
|
240
|
+
children: t13
|
|
241
|
+
});
|
|
242
|
+
$[47] = T0;
|
|
243
|
+
$[48] = t10;
|
|
244
|
+
$[49] = t11;
|
|
245
|
+
$[50] = t12;
|
|
246
|
+
$[51] = t13;
|
|
247
|
+
$[52] = t5;
|
|
248
|
+
$[53] = t6;
|
|
249
|
+
$[54] = t7;
|
|
250
|
+
$[55] = t8;
|
|
251
|
+
$[56] = t9;
|
|
252
|
+
$[57] = t14;
|
|
253
|
+
} else t14 = $[57];
|
|
254
|
+
return t14;
|
|
255
|
+
}
|
|
256
|
+
function _temp3(field) {
|
|
257
|
+
return field.name;
|
|
121
258
|
}
|
|
122
259
|
//#endregion
|
|
123
260
|
export { ConflictDialog };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConflictDialog.js","names":["labels","entry","label","field","_c","_Fragment","styles"],"sources":["../src/ConflictDialog.tsx"],"sourcesContent":["import { getItemValues, isEqual } from '@panneau/core';\nimport type { Field, Item } from '@panneau/protocol';\nimport { Button, Dialog, usePanneauIntl } from '@panneau/ui';\n\nimport styles from './ConflictDialog.module.css';\nimport { messages } from './messages';\n\nexport interface ConflictDialogProps {\n isOpen: boolean;\n /** The fields of the form, for their labels. */\n fields: readonly Field[];\n /** The values in the form. */\n values: Record<string, unknown>;\n /** The current item, as the backend sent it with the `412`. */\n current: Item | null;\n /** Drops the local changes and continues from the current item. */\n onReload: () => void;\n /** Saves the local values over the current version. */\n onOverwrite: () => void;\n isPending?: boolean;\n className?: string;\n}\n\ntype Formatter = (value: unknown, field?: Field) => string;\n\nfunction useFormatValue(): Formatter {\n const intl = usePanneauIntl();\n const format: Formatter = (value, field) => {\n const options = field?.options;\n if (options !== undefined) {\n const labels = (Array.isArray(value) ? value : [value]).map(\n (entry: unknown) =>\n options.find((option) => option.value === entry)?.label ?? entry,\n );\n if (value !== null && value !== undefined) {\n return labels.map((label) => format(label)).join(', ');\n }\n }\n if (value === null || value === undefined || value === '') {\n return intl.formatMessage(messages.empty);\n }\n if (typeof value === 'boolean') {\n return intl.formatMessage(value ? messages.yes : messages.no);\n }\n if (typeof value === 'string' || typeof value === 'number') {\n const text = String(value);\n return text.length > 120 ? `${text.slice(0, 117)}…` : text;\n }\n if (Array.isArray(value)) {\n const labels = value.map((entry: unknown) =>\n entry !== null && typeof entry === 'object' && 'label' in entry\n ? String((entry as { label: unknown }).label)\n : null,\n );\n return labels.every((label) => label !== null)\n ? labels.join(', ')\n : intl.formatMessage(messages.itemCount, { count: value.length });\n }\n if (typeof value === 'object') {\n const record = value as Record<string, unknown>;\n if (typeof record.label === 'string') {\n return record.label;\n }\n return Object.entries(record)\n .map(([key, entry]) => `${key}: ${format(entry)}`)\n .join(' · ');\n }\n return String(value);\n };\n return format;\n}\n\n/**\n * The dialog of a version conflict (decision 0008): someone else saved the item since the form\n * loaded it. It shows the values that differ, and lets the user load the current version or save\n * theirs over it.\n */\nexport function ConflictDialog({\n isOpen,\n fields,\n values,\n current,\n onReload,\n onOverwrite,\n isPending = false,\n className,\n}: ConflictDialogProps) {\n const intl = usePanneauIntl();\n const format = useFormatValue();\n const theirs =\n current !== null\n ? getItemValues(\n current,\n fields.map((field) => field.name),\n )\n : null;\n const changed =\n theirs !== null\n ? fields.filter(\n (field) => !isEqual(values[field.name] ?? null, theirs[field.name] ?? null),\n )\n : [];\n return (\n <Dialog\n isOpen={isOpen}\n role=\"alertdialog\"\n isDismissable={false}\n isKeyboardDismissDisabled\n title={intl.formatMessage(messages.conflictTitle)}\n size=\"lg\"\n className={className}\n footer={\n <>\n <Button onPress={onReload} isDisabled={isPending}>\n {intl.formatMessage(messages.loadCurrent)}\n </Button>\n <Button variant=\"danger\" onPress={onOverwrite} isPending={isPending}>\n {intl.formatMessage(messages.overwrite)}\n </Button>\n </>\n }\n >\n <div className={styles.body}>\n <p className={styles.message}>{intl.formatMessage(messages.conflictMessage)}</p>\n {theirs === null ? (\n <p className={styles.muted}>{intl.formatMessage(messages.conflictUnknown)}</p>\n ) : changed.length > 0 ? (\n <section aria-labelledby=\"panneau-conflict-changes\">\n <h3 id=\"panneau-conflict-changes\" className={styles.heading}>\n {intl.formatMessage(messages.conflictChanges)}\n </h3>\n <dl className={styles.changes}>\n {changed.map((field) => (\n <div key={field.name} className={styles.change}>\n <dt className={styles.label}>{field.label ?? field.name}</dt>\n <dd className={styles.version}>\n <span className={styles.which}>\n {intl.formatMessage(messages.yours)}\n </span>\n {format(values[field.name], field)}\n </dd>\n <dd className={styles.version}>\n <span className={styles.which}>\n {intl.formatMessage(messages.current)}\n </span>\n {format(theirs[field.name], field)}\n </dd>\n </div>\n ))}\n </dl>\n </section>\n ) : null}\n </div>\n </Dialog>\n );\n}\n"],"mappings":";;;;;;;AAyBA,SAAA,iBAAA;CAAA,MAAA,IAAAI,EAAA,CAAA;CACI,MAAA,OAAa,eAAe;CAAE,IAAA;CAAA,IAAA,EAAA,OAAA,MAAA;EAC9B,UAA0B,OAAA,UAAA;GACtB,MAAA,UAAgB,OAAK;GACrB,IAAI,YAAY,KAAA,GAAS;IACrB,MAAA,UAAgB,MAAK,QAAS,KAAuB,IAArC,QAAA,CAAgC,KAAK,EAAA,CAAC,KAClD,UACI,QAAO,MAAM,WAAY,OAAM,UAAW,KAAY,CAAC,EAAA,SAAvD,KACR;IACA,IAAI,UAAU,QAAQ,UAAU,KAAA,GAAS,OAC9B,OAAM,KAAK,UAAW,OAAO,KAAK,CAAC,CAAC,CAAA,KAAM,IAAI;GACxD;GAEL,IAAI,UAAU,QAAQ,UAAU,KAAA,KAAa,UAAU,IAAE,OAC9C,KAAI,cAAe,SAAQ,KAAM;GAE5C,IAAI,OAAO,UAAU,WAAS,OACnB,KAAI,cAAe,QAAQ,SAAQ,MAAO,SAAQ,EAAG;GAEhE,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,UAAQ;IACtD,MAAA,OAAa,OAAO,KAAK;IAAE,OACpB,KAAI,SA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OAAOH,QAAM,OAAOA,OAAK,CACjC;;MACH;KAdKA,GAAAA,QAAM,IAcX,CACR;IACD,CAAA,CACC;GACT,CAAA,IAAA,IACH;;CACD,CAAA;AAEhB"}
|
|
1
|
+
{"version":3,"file":"ConflictDialog.js","names":["getItemValues","isEqual","Field","Item","Button","Dialog","usePanneauIntl","styles","messages","ConflictDialogProps","isOpen","fields","values","Record","current","onReload","onOverwrite","isPending","className","Formatter","value","field","useFormatValue","$","_c","intl","format","options","undefined","labels","Array","isArray","map","entry","find","option","label","join","formatMessage","empty","yes","no","text","String","length","slice","labels_0","_temp","every","_temp2","itemCount","count","record","Object","entries","t0","key","entry_1","label_0","entry_0","ConflictDialog","t1","T0","t10","t11","t12","t2","t3","t4","t5","t6","t7","t8","t9","theirs","_temp3","changed","filter","field_0","name","conflictTitle","t13","loadCurrent","t14","t15","overwrite","t16","body","t17","conflictMessage","message","muted","conflictUnknown","heading","conflictChanges","changes","field_1","change","version","which","yours","_c","_Fragment","styles"],"sources":["../src/ConflictDialog.tsx"],"sourcesContent":["import { getItemValues, isEqual } from '@panneau/core';\nimport type { Field, Item } from '@panneau/protocol';\nimport { Button, Dialog, usePanneauIntl } from '@panneau/ui';\n\nimport styles from './ConflictDialog.module.css';\nimport { messages } from './messages';\n\nexport interface ConflictDialogProps {\n isOpen: boolean;\n /** The fields of the form, for their labels. */\n fields: readonly Field[];\n /** The values in the form. */\n values: Record<string, unknown>;\n /** The current item, as the backend sent it with the `412`. */\n current: Item | null;\n /** Drops the local changes and continues from the current item. */\n onReload: () => void;\n /** Saves the local values over the current version. */\n onOverwrite: () => void;\n isPending?: boolean;\n className?: string;\n}\n\ntype Formatter = (value: unknown, field?: Field) => string;\n\nfunction useFormatValue(): Formatter {\n const intl = usePanneauIntl();\n const format: Formatter = (value, field) => {\n const options = field?.options;\n if (options !== undefined) {\n const labels = (Array.isArray(value) ? value : [value]).map(\n (entry: unknown) =>\n options.find((option) => option.value === entry)?.label ?? entry,\n );\n if (value !== null && value !== undefined) {\n return labels.map((label) => format(label)).join(', ');\n }\n }\n if (value === null || value === undefined || value === '') {\n return intl.formatMessage(messages.empty);\n }\n if (typeof value === 'boolean') {\n return intl.formatMessage(value ? messages.yes : messages.no);\n }\n if (typeof value === 'string' || typeof value === 'number') {\n const text = String(value);\n return text.length > 120 ? `${text.slice(0, 117)}…` : text;\n }\n if (Array.isArray(value)) {\n const labels = value.map((entry: unknown) =>\n entry !== null && typeof entry === 'object' && 'label' in entry\n ? String((entry as { label: unknown }).label)\n : null,\n );\n return labels.every((label) => label !== null)\n ? labels.join(', ')\n : intl.formatMessage(messages.itemCount, { count: value.length });\n }\n if (typeof value === 'object') {\n const record = value as Record<string, unknown>;\n if (typeof record.label === 'string') {\n return record.label;\n }\n return Object.entries(record)\n .map(([key, entry]) => `${key}: ${format(entry)}`)\n .join(' · ');\n }\n return String(value);\n };\n return format;\n}\n\n/**\n * The dialog of a version conflict (decision 0008): someone else saved the item since the form\n * loaded it. It shows the values that differ, and lets the user load the current version or save\n * theirs over it.\n */\nexport function ConflictDialog({\n isOpen,\n fields,\n values,\n current,\n onReload,\n onOverwrite,\n isPending = false,\n className,\n}: ConflictDialogProps) {\n const intl = usePanneauIntl();\n const format = useFormatValue();\n const theirs =\n current !== null\n ? getItemValues(\n current,\n fields.map((field) => field.name),\n )\n : null;\n const changed =\n theirs !== null\n ? fields.filter(\n (field) => !isEqual(values[field.name] ?? null, theirs[field.name] ?? null),\n )\n : [];\n return (\n <Dialog\n isOpen={isOpen}\n role=\"alertdialog\"\n isDismissable={false}\n isKeyboardDismissDisabled\n title={intl.formatMessage(messages.conflictTitle)}\n size=\"lg\"\n className={className}\n footer={\n <>\n <Button onPress={onReload} isDisabled={isPending}>\n {intl.formatMessage(messages.loadCurrent)}\n </Button>\n <Button variant=\"danger\" onPress={onOverwrite} isPending={isPending}>\n {intl.formatMessage(messages.overwrite)}\n </Button>\n </>\n }\n >\n <div className={styles.body}>\n <p className={styles.message}>{intl.formatMessage(messages.conflictMessage)}</p>\n {theirs === null ? (\n <p className={styles.muted}>{intl.formatMessage(messages.conflictUnknown)}</p>\n ) : changed.length > 0 ? (\n <section aria-labelledby=\"panneau-conflict-changes\">\n <h3 id=\"panneau-conflict-changes\" className={styles.heading}>\n {intl.formatMessage(messages.conflictChanges)}\n </h3>\n <dl className={styles.changes}>\n {changed.map((field) => (\n <div key={field.name} className={styles.change}>\n <dt className={styles.label}>{field.label ?? field.name}</dt>\n <dd className={styles.version}>\n <span className={styles.which}>\n {intl.formatMessage(messages.yours)}\n </span>\n {format(values[field.name], field)}\n </dd>\n <dd className={styles.version}>\n <span className={styles.which}>\n {intl.formatMessage(messages.current)}\n </span>\n {format(theirs[field.name], field)}\n </dd>\n </div>\n ))}\n </dl>\n </section>\n ) : null}\n </div>\n </Dialog>\n );\n}\n"],"mappings":";;;;;;;AAyBA,SAAAsB,iBAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CACI,MAAAC,OAAanB,eAAe;CAAE,IAAAoB;CAAA,IAAAH,EAAA,OAAAE,MAAA;EAC9BC,UAA0BN,OAAAC,UAAA;GACtB,MAAAM,UAAgBN,OAAKM;GACrB,IAAIA,YAAYC,KAAAA,GAAS;IACrB,MAAAC,UAAgBC,MAAKC,QAASX,KAAuB,IAArCA,QAAA,CAAgCA,KAAK,EAAA,CAACY,KAClDC,UACIN,QAAOO,MAAMC,WAAYA,OAAMf,UAAWa,KAAY,CAAC,EAAAG,SAAvDH,KACR;IACA,IAAIb,UAAU,QAAQA,UAAUQ,KAAAA,GAAS,OAC9BC,OAAMG,KAAKI,UAAWV,OAAOU,KAAK,CAAC,CAAC,CAAAC,KAAM,IAAI;GACxD;GAEL,IAAIjB,UAAU,QAAQA,UAAUQ,KAAAA,KAAaR,UAAU,IAAE,OAC9CK,KAAIa,cAAe9B,SAAQ+B,KAAM;GAE5C,IAAI,OAAOnB,UAAU,WAAS,OACnBK,KAAIa,cAAelB,QAAQZ,SAAQgC,MAAOhC,SAAQiC,EAAG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JgB,UAAAA;EAnBG,CAAA;EAkDE1D,EAAA,MAAAuC;EAAAvC,EAAA,MAAAwC;EAAAxC,EAAA,MAAAyC;EAAAzC,EAAA,MAAA0C;EAAA1C,EAAA,MAAA0D;EAAA1D,EAAA,MAAA8C;EAAA9C,EAAA,MAAA+C;EAAA/C,EAAA,MAAAgD;EAAAhD,EAAA,MAAAiD;EAAAjD,EAAA,MAAAkD;EAAAlD,EAAA,MAAA4D;CAAA,OAAAA,MAAA5D,EAAA;CAAA,OAlDT4D;AAkDS;AA5EV,SAAAR,OAAAtD,OAAA;CAAA,OAgBiCA,MAAK0D;AAAK"}
|
package/dist/ErrorSummary.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorSummary.js","names":["
|
|
1
|
+
{"version":3,"file":"ErrorSummary.js","names":["Ref","Field","Alert","usePanneauIntl","styles","describePath","messages","ErrorSummaryProps","errors","Record","fields","onSelect","path","ref","HTMLDivElement","className","ErrorSummary","t0","$","_c","intl","T0","t1","t2","t3","t4","t5","t6","t7","t8","t9","Symbol","for","bb0","entries","Object","filter","_temp","length","summary","formatMessage","summaryTitle","count","summaryList","map","t10","list_0","name","summaryLink","list","join","t11","_c","styles"],"sources":["../src/ErrorSummary.tsx"],"sourcesContent":["import type { Ref } from 'react';\n\nimport type { Field } from '@panneau/protocol';\nimport { Alert, usePanneauIntl } from '@panneau/ui';\n\nimport styles from './Form.module.css';\nimport { describePath } from './describe';\nimport { messages } from './messages';\n\nexport interface ErrorSummaryProps {\n /** Errors by dot path, in the order to list them. */\n errors: Record<string, string[]>;\n /** The fields of the form, for the names of the paths. */\n fields: readonly Field[];\n /** Called with a path when its link is pressed. */\n onSelect: (path: string) => void;\n ref?: Ref<HTMLDivElement>;\n className?: string;\n}\n\n/**\n * The errors of a form, listed at the top after a failed submit: each one links to its field.\n * Assistive technologies announce it when it appears.\n */\nexport function ErrorSummary({ errors, fields, onSelect, ref, className }: ErrorSummaryProps) {\n const intl = usePanneauIntl();\n const entries = Object.entries(errors).filter(([, list]) => list.length > 0);\n if (entries.length === 0) {\n return null;\n }\n return (\n <Alert\n ref={ref}\n tone=\"danger\"\n role=\"alert\"\n tabIndex={-1}\n className={className ?? styles.summary}\n title={intl.formatMessage(messages.summaryTitle, { count: entries.length })}\n >\n <ul className={styles.summaryList}>\n {entries.map(([path, list]) => {\n const name = describePath(fields, path);\n return (\n <li key={path}>\n <button\n type=\"button\"\n className={styles.summaryLink}\n onClick={() => onSelect(path)}\n >\n {name}\n </button>\n {`: ${list.join(' ')}`}\n </li>\n );\n })}\n </ul>\n </Alert>\n );\n}\n"],"mappings":";;;;;;;;;;;AAwBA,SAAOgB,aAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAsB,MAAA,EAAAX,QAAAE,QAAAC,UAAAE,KAAAE,cAAAE;CACzB,MAAAG,OAAajB,eAAe;CAAE,IAAAkB;CAAA,IAAAC;CAAA,IAAAC;CAAA,IAAAC;CAAA,IAAAC;CAAA,IAAAC;CAAA,IAAAC;CAAA,IAAAC;CAAA,IAAAC;CAAA,IAAAC;CAAA,IAAAZ,EAAA,OAAAH,aAAAG,EAAA,OAAAV,UAAAU,EAAA,OAAAR,UAAAQ,EAAA,OAAAE,QAAAF,EAAA,OAAAP,YAAAO,EAAA,OAAAL,KAAA;EAGnBiB,KAAAC,OAAIC,IAAJ,6BAAG;EAACC,KAAA;GAFf,MAAAC,UAAgBC,OAAMD,QAAS1B,MAAM,CAAC,CAAA4B,OAAQC,KAA6B;GAC3E,IAAIH,QAAOI,WAAY,GAAC;IACbR,KAAA;IAAA,MAAAG;GAAI;GAGVZ,KAAAnB;GACQW,KAAAA;GACAY,KAAA;GACAC,KAAA;GACKC,KAAA;GACCC,KAAAb,aAAaX,oBAAMmC;GACvBV,KAAAT,KAAIoB,cAAelC,SAAQmC,cAAe,EAAAC,OAASR,QAAOI,OAAQ,CAAC;GAE3DhB,KAAAlB,oBAAMuC;GAChBpB,KAAAW,QA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AM,MAAAN,EAAA,QAAAO,MAAAP,EAAA,QAAAQ,MAAAR,EAAA,QAAAS,MAAAT,EAAA,QAAAU,MAAAV,EAAA,QAAAW,IAAA;EAxBTsB,MAAA,oBAAC,IAAD;GACStC,KAAAA;GACA,MAAAY;GACA,MAAAC;GACK,UAAAC;GACC,WAAAC;GACJ,OAAAC;GAEPgB,UAAAA;EARE,CAAA;EAyBE3B,EAAA,MAAAG;EAAAH,EAAA,MAAA2B;EAAA3B,EAAA,MAAAM;EAAAN,EAAA,MAAAO;EAAAP,EAAA,MAAAQ;EAAAR,EAAA,MAAAS;EAAAT,EAAA,MAAAU;EAAAV,EAAA,MAAAW;EAAAX,EAAA,MAAAiC;CAAA,OAAAA,MAAAjC,EAAA;CAAA,OAzBRiC;AAyBQ;AAhCT,SAAAd,MAAApB,IAAA;CAE4C,MAAA,GAAAgC,QAAAhC;CAAQ,OAAKgC,KAAIX,SAAU;AAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldErrorBoundary.js","names":[],"sources":["../src/FieldErrorBoundary.tsx"],"sourcesContent":["import { Component, type ErrorInfo, type ReactNode } from 'react';\n\ninterface FieldErrorBoundaryProps {\n /** What to show instead of the field, with a function that renders it again. */\n fallback: (retry: () => void) => ReactNode;\n onError?: (error: unknown, info: ErrorInfo) => void;\n children?: ReactNode;\n}\n\ninterface FieldErrorBoundaryState {\n failed: boolean;\n}\n\n/** Keeps a field that throws from taking the whole form down (decision 0006). */\nexport class FieldErrorBoundary extends Component<\n FieldErrorBoundaryProps,\n FieldErrorBoundaryState\n> {\n override state: FieldErrorBoundaryState = { failed: false };\n\n static getDerivedStateFromError(): FieldErrorBoundaryState {\n return { failed: true };\n }\n\n override componentDidCatch(error: unknown, info: ErrorInfo) {\n this.props.onError?.(error, info);\n }\n\n override render() {\n if (this.state.failed) {\n return this.props.fallback(() => this.setState({ failed: false }));\n }\n return this.props.children;\n }\n}\n"],"mappings":";;;AAcA,
|
|
1
|
+
{"version":3,"file":"FieldErrorBoundary.js","names":["Component","ErrorInfo","ReactNode","FieldErrorBoundaryProps","fallback","retry","onError","error","info","children","FieldErrorBoundaryState","failed","FieldErrorBoundary","state","getDerivedStateFromError","componentDidCatch","props","render","setState"],"sources":["../src/FieldErrorBoundary.tsx"],"sourcesContent":["import { Component, type ErrorInfo, type ReactNode } from 'react';\n\ninterface FieldErrorBoundaryProps {\n /** What to show instead of the field, with a function that renders it again. */\n fallback: (retry: () => void) => ReactNode;\n onError?: (error: unknown, info: ErrorInfo) => void;\n children?: ReactNode;\n}\n\ninterface FieldErrorBoundaryState {\n failed: boolean;\n}\n\n/** Keeps a field that throws from taking the whole form down (decision 0006). */\nexport class FieldErrorBoundary extends Component<\n FieldErrorBoundaryProps,\n FieldErrorBoundaryState\n> {\n override state: FieldErrorBoundaryState = { failed: false };\n\n static getDerivedStateFromError(): FieldErrorBoundaryState {\n return { failed: true };\n }\n\n override componentDidCatch(error: unknown, info: ErrorInfo) {\n this.props.onError?.(error, info);\n }\n\n override render() {\n if (this.state.failed) {\n return this.props.fallback(() => this.setState({ failed: false }));\n }\n return this.props.children;\n }\n}\n"],"mappings":";;;AAcA,IAAaY,qBAAb,cAAwCZ,UAGtC;CACE,QAA0C,EAAEW,QAAQ,MAAM;CAE1D,OAAOG,2BAAoD;EACvD,OAAO,EAAEH,QAAQ,KAAK;CAC1B;CAEA,kBAA2BJ,OAAgBC,MAAiB;EACxD,KAAKQ,MAAMV,UAAUC,OAAOC,IAAI;CACpC;CAEA,SAAkB;EACd,IAAI,KAAKK,MAAMF,QACX,OAAO,KAAKK,MAAMZ,eAAe,KAAKc,SAAS,EAAEP,QAAQ,MAAM,CAAC,CAAC;EAErE,OAAO,KAAKK,MAAMP;CACtB;AACJ"}
|
package/dist/Form.css
CHANGED
|
@@ -155,3 +155,27 @@
|
|
|
155
155
|
flex: 1 1 auto;
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
+
|
|
159
|
+
/* The skeleton of a form whose values load. */
|
|
160
|
+
.panneau-form-skeleton-field {
|
|
161
|
+
display: flex;
|
|
162
|
+
flex-direction: column;
|
|
163
|
+
gap: var(--panneau-space-1);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.panneau-form-skeleton-inline {
|
|
167
|
+
display: flex;
|
|
168
|
+
align-items: center;
|
|
169
|
+
gap: var(--panneau-space-2);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.panneau-form-skeleton-label {
|
|
173
|
+
font-size: var(--panneau-font-size-sm);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.panneau-form-skeleton-tabs {
|
|
177
|
+
display: flex;
|
|
178
|
+
gap: var(--panneau-space-5);
|
|
179
|
+
padding-block: var(--panneau-space-2);
|
|
180
|
+
border-bottom: var(--panneau-border-width) solid var(--panneau-color-border);
|
|
181
|
+
}
|
package/dist/Form.d.ts
CHANGED
|
@@ -14,7 +14,8 @@ export interface FormProps extends Omit<FormViewProps, 'form' | 'fields' | 'layo
|
|
|
14
14
|
* translated with react-intl.
|
|
15
15
|
*
|
|
16
16
|
* Initial values and the version are read once: give the form a new `key` to start from another
|
|
17
|
-
* item, or use `useForm()` and `FormView`.
|
|
17
|
+
* item, or use `useForm()` and `FormView`. While the item loads, `isLoading` draws a skeleton of
|
|
18
|
+
* the form, and a new `key` once it is there starts the form from its values.
|
|
18
19
|
*/
|
|
19
20
|
export declare function Form({ fields, layout, values, version, mode, store, formatError, onSubmit, locales, ...props }: FormProps): import("react").JSX.Element;
|
|
20
21
|
//# sourceMappingURL=Form.d.ts.map
|
package/dist/Form.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../src/Form.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAsC,MAAM,eAAe,CAAC;AACrF,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE3D,OAAO,EAAY,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAG1D,MAAM,WAAW,SACb,SACI,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC,EACjD,IAAI,CAAC,WAAW,EAAE,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,aAAa,GAAG,UAAU,CAAC;IAC3F,4EAA4E;IAC5E,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IACzB,4EAA4E;IAC5E,MAAM,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;CAClC;AAED
|
|
1
|
+
{"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../src/Form.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAsC,MAAM,eAAe,CAAC;AACrF,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE3D,OAAO,EAAY,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAG1D,MAAM,WAAW,SACb,SACI,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC,EACjD,IAAI,CAAC,WAAW,EAAE,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,aAAa,GAAG,UAAU,CAAC;IAC3F,4EAA4E;IAC5E,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IACzB,4EAA4E;IAC5E,MAAM,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;CAClC;AAED;;;;;;;;;GASG;AACH,wBAAgB,IAAI,CAAC,EACjB,MAAM,EACN,MAAW,EACX,MAAM,EACN,OAAO,EACP,IAAI,EACJ,KAAK,EACL,WAAW,EACX,QAAQ,EACR,OAAO,EACP,GAAG,KAAK,EACX,EAAE,SAAS,+BAwBX"}
|
package/dist/Form.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FormView } from "./FormView.js";
|
|
2
2
|
import { useFormatRuleFailure } from "./formatError.js";
|
|
3
|
+
import { c } from "react/compiler-runtime";
|
|
3
4
|
import { resolveFields, useForm, usePanneau } from "@panneau/core";
|
|
4
5
|
import { jsx } from "react/jsx-runtime";
|
|
5
6
|
//#region src/Form.tsx
|
|
@@ -10,30 +11,135 @@ import { jsx } from "react/jsx-runtime";
|
|
|
10
11
|
* translated with react-intl.
|
|
11
12
|
*
|
|
12
13
|
* Initial values and the version are read once: give the form a new `key` to start from another
|
|
13
|
-
* item, or use `useForm()` and `FormView`.
|
|
14
|
+
* item, or use `useForm()` and `FormView`. While the item loads, `isLoading` draws a skeleton of
|
|
15
|
+
* the form, and a new `key` once it is there starts the form from its values.
|
|
14
16
|
*/
|
|
15
|
-
function Form(
|
|
17
|
+
function Form(t0) {
|
|
18
|
+
const $ = c(41);
|
|
19
|
+
let fields;
|
|
20
|
+
let formatError;
|
|
21
|
+
let locales;
|
|
22
|
+
let mode;
|
|
23
|
+
let onSubmit;
|
|
24
|
+
let props;
|
|
25
|
+
let store;
|
|
26
|
+
let t1;
|
|
27
|
+
let values;
|
|
28
|
+
let version;
|
|
29
|
+
if ($[0] !== t0) {
|
|
30
|
+
({fields, layout: t1, values, version, mode, store, formatError, onSubmit, locales, ...props} = t0);
|
|
31
|
+
$[0] = t0;
|
|
32
|
+
$[1] = fields;
|
|
33
|
+
$[2] = formatError;
|
|
34
|
+
$[3] = locales;
|
|
35
|
+
$[4] = mode;
|
|
36
|
+
$[5] = onSubmit;
|
|
37
|
+
$[6] = props;
|
|
38
|
+
$[7] = store;
|
|
39
|
+
$[8] = t1;
|
|
40
|
+
$[9] = values;
|
|
41
|
+
$[10] = version;
|
|
42
|
+
} else {
|
|
43
|
+
fields = $[1];
|
|
44
|
+
formatError = $[2];
|
|
45
|
+
locales = $[3];
|
|
46
|
+
mode = $[4];
|
|
47
|
+
onSubmit = $[5];
|
|
48
|
+
props = $[6];
|
|
49
|
+
store = $[7];
|
|
50
|
+
t1 = $[8];
|
|
51
|
+
values = $[9];
|
|
52
|
+
version = $[10];
|
|
53
|
+
}
|
|
54
|
+
const layout = t1 === void 0 ? [] : t1;
|
|
16
55
|
const { definition } = usePanneau();
|
|
17
56
|
const resolved = resolveFields(fields, layout, mode !== void 0 ? { mode } : {});
|
|
18
57
|
const formatRuleFailure = useFormatRuleFailure(resolved.fields);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
58
|
+
let t2;
|
|
59
|
+
if ($[11] !== definition?.locales || $[12] !== locales) {
|
|
60
|
+
t2 = locales ?? definition?.locales ?? [];
|
|
61
|
+
$[11] = definition?.locales;
|
|
62
|
+
$[12] = locales;
|
|
63
|
+
$[13] = t2;
|
|
64
|
+
} else t2 = $[13];
|
|
65
|
+
const formLocales = t2;
|
|
66
|
+
let t3;
|
|
67
|
+
if ($[14] !== formLocales) {
|
|
68
|
+
t3 = [...formLocales];
|
|
69
|
+
$[14] = formLocales;
|
|
70
|
+
$[15] = t3;
|
|
71
|
+
} else t3 = $[15];
|
|
72
|
+
const t4 = formatError ?? formatRuleFailure;
|
|
73
|
+
let t5;
|
|
74
|
+
if ($[16] !== values) {
|
|
75
|
+
t5 = values !== void 0 ? { values } : {};
|
|
76
|
+
$[16] = values;
|
|
77
|
+
$[17] = t5;
|
|
78
|
+
} else t5 = $[17];
|
|
79
|
+
let t6;
|
|
80
|
+
if ($[18] !== version) {
|
|
81
|
+
t6 = version !== void 0 ? { version } : {};
|
|
82
|
+
$[18] = version;
|
|
83
|
+
$[19] = t6;
|
|
84
|
+
} else t6 = $[19];
|
|
85
|
+
let t7;
|
|
86
|
+
if ($[20] !== mode) {
|
|
87
|
+
t7 = mode !== void 0 ? { mode } : {};
|
|
88
|
+
$[20] = mode;
|
|
89
|
+
$[21] = t7;
|
|
90
|
+
} else t7 = $[21];
|
|
91
|
+
let t8;
|
|
92
|
+
if ($[22] !== store) {
|
|
93
|
+
t8 = store !== void 0 ? { store } : {};
|
|
94
|
+
$[22] = store;
|
|
95
|
+
$[23] = t8;
|
|
96
|
+
} else t8 = $[23];
|
|
97
|
+
let t9;
|
|
98
|
+
if ($[24] !== onSubmit) {
|
|
99
|
+
t9 = onSubmit !== void 0 ? { onSubmit } : {};
|
|
100
|
+
$[24] = onSubmit;
|
|
101
|
+
$[25] = t9;
|
|
102
|
+
} else t9 = $[25];
|
|
103
|
+
let t10;
|
|
104
|
+
if ($[26] !== resolved.fields || $[27] !== t3 || $[28] !== t4 || $[29] !== t5 || $[30] !== t6 || $[31] !== t7 || $[32] !== t8 || $[33] !== t9) {
|
|
105
|
+
t10 = {
|
|
106
|
+
fields: resolved.fields,
|
|
107
|
+
locales: t3,
|
|
108
|
+
formatError: t4,
|
|
109
|
+
...t5,
|
|
110
|
+
...t6,
|
|
111
|
+
...t7,
|
|
112
|
+
...t8,
|
|
113
|
+
...t9
|
|
114
|
+
};
|
|
115
|
+
$[26] = resolved.fields;
|
|
116
|
+
$[27] = t3;
|
|
117
|
+
$[28] = t4;
|
|
118
|
+
$[29] = t5;
|
|
119
|
+
$[30] = t6;
|
|
120
|
+
$[31] = t7;
|
|
121
|
+
$[32] = t8;
|
|
122
|
+
$[33] = t9;
|
|
123
|
+
$[34] = t10;
|
|
124
|
+
} else t10 = $[34];
|
|
125
|
+
const { form } = useForm(t10);
|
|
126
|
+
let t11;
|
|
127
|
+
if ($[35] !== form || $[36] !== formLocales || $[37] !== props || $[38] !== resolved.fields || $[39] !== resolved.layout) {
|
|
128
|
+
t11 = /* @__PURE__ */ jsx(FormView, {
|
|
129
|
+
...props,
|
|
130
|
+
form,
|
|
131
|
+
fields: resolved.fields,
|
|
132
|
+
layout: resolved.layout,
|
|
133
|
+
locales: formLocales
|
|
134
|
+
});
|
|
135
|
+
$[35] = form;
|
|
136
|
+
$[36] = formLocales;
|
|
137
|
+
$[37] = props;
|
|
138
|
+
$[38] = resolved.fields;
|
|
139
|
+
$[39] = resolved.layout;
|
|
140
|
+
$[40] = t11;
|
|
141
|
+
} else t11 = $[40];
|
|
142
|
+
return t11;
|
|
37
143
|
}
|
|
38
144
|
//#endregion
|
|
39
145
|
export { Form };
|
package/dist/Form.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form.js","names":[],"sources":["../src/Form.tsx"],"sourcesContent":["import { type FormOptions, resolveFields, useForm, usePanneau } from '@panneau/core';\nimport type { Field, LayoutNode } from '@panneau/protocol';\n\nimport { FormView, type FormViewProps } from './FormView';\nimport { useFormatRuleFailure } from './formatError';\n\nexport interface FormProps\n extends\n Omit<FormViewProps, 'form' | 'fields' | 'layout'>,\n Pick<FormOptions, 'values' | 'version' | 'mode' | 'store' | 'formatError' | 'onSubmit'> {\n /** The fields of the form. Without a layout, they are rendered in order. */\n fields: readonly Field[];\n /** The layout tree. Fields that no node references are added at the end. */\n layout?: readonly LayoutNode[];\n}\n\n/**\n * A form from a list of fields and an `onSubmit`, with or without a definition. It creates its\n * state with `useForm()` of `@panneau/core`: values, validation with the portable rules, server\n * errors (`422`) and version conflicts (`412`) from what `onSubmit` throws. Rule messages are\n * translated with react-intl.\n *\n * Initial values and the version are read once: give the form a new `key` to start from another\n * item, or use `useForm()` and `FormView
|
|
1
|
+
{"version":3,"file":"Form.js","names":["FormOptions","resolveFields","useForm","usePanneau","Field","LayoutNode","FormView","FormViewProps","useFormatRuleFailure","FormProps","Omit","Pick","fields","layout","Form","t0","$","_c","formatError","locales","mode","onSubmit","props","store","t1","values","version","undefined","definition","resolved","formatRuleFailure","t2","formLocales","t3","t4","t5","t6","t7","t8","t9","t10","form","t11","_c"],"sources":["../src/Form.tsx"],"sourcesContent":["import { type FormOptions, resolveFields, useForm, usePanneau } from '@panneau/core';\nimport type { Field, LayoutNode } from '@panneau/protocol';\n\nimport { FormView, type FormViewProps } from './FormView';\nimport { useFormatRuleFailure } from './formatError';\n\nexport interface FormProps\n extends\n Omit<FormViewProps, 'form' | 'fields' | 'layout'>,\n Pick<FormOptions, 'values' | 'version' | 'mode' | 'store' | 'formatError' | 'onSubmit'> {\n /** The fields of the form. Without a layout, they are rendered in order. */\n fields: readonly Field[];\n /** The layout tree. Fields that no node references are added at the end. */\n layout?: readonly LayoutNode[];\n}\n\n/**\n * A form from a list of fields and an `onSubmit`, with or without a definition. It creates its\n * state with `useForm()` of `@panneau/core`: values, validation with the portable rules, server\n * errors (`422`) and version conflicts (`412`) from what `onSubmit` throws. Rule messages are\n * translated with react-intl.\n *\n * Initial values and the version are read once: give the form a new `key` to start from another\n * item, or use `useForm()` and `FormView`. While the item loads, `isLoading` draws a skeleton of\n * the form, and a new `key` once it is there starts the form from its values.\n */\nexport function Form({\n fields,\n layout = [],\n values,\n version,\n mode,\n store,\n formatError,\n onSubmit,\n locales,\n ...props\n}: FormProps) {\n const { definition } = usePanneau();\n const resolved = resolveFields(fields, layout, mode !== undefined ? { mode } : {});\n const formatRuleFailure = useFormatRuleFailure(resolved.fields);\n const formLocales = locales ?? definition?.locales ?? [];\n const { form } = useForm({\n fields: resolved.fields,\n locales: [...formLocales],\n formatError: formatError ?? formatRuleFailure,\n ...(values !== undefined ? { values } : {}),\n ...(version !== undefined ? { version } : {}),\n ...(mode !== undefined ? { mode } : {}),\n ...(store !== undefined ? { store } : {}),\n ...(onSubmit !== undefined ? { onSubmit } : {}),\n });\n return (\n <FormView\n {...props}\n form={form}\n fields={resolved.fields}\n layout={resolved.layout}\n locales={formLocales}\n />\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA0BA,SAAOc,KAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAA,IAAAL;CAAA,IAAAM;CAAA,IAAAC;CAAA,IAAAC;CAAA,IAAAC;CAAA,IAAAC;CAAA,IAAAC;CAAA,IAAAC;CAAA,I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