@panneau/forms 5.0.0-alpha.0 → 5.0.0-alpha.10
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 +11 -10
- package/dist/ConflictDialog.css +15 -10
- package/dist/ConflictDialog.js +201 -61
- package/dist/ConflictDialog.js.map +1 -1
- package/dist/ConflictDialog.module.js +11 -9
- package/dist/ConflictDialog.module.js.map +1 -1
- package/dist/ErrorSummary.js.map +1 -1
- package/dist/FieldErrorBoundary.js.map +1 -1
- package/dist/Form.css +52 -22
- package/dist/Form.d.ts +3 -2
- package/dist/Form.d.ts.map +1 -1
- package/dist/Form.js +122 -21
- package/dist/Form.js.map +1 -1
- package/dist/Form.module.js +29 -21
- 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 +22 -3
- package/dist/FormView.d.ts.map +1 -1
- package/dist/FormView.js +234 -92
- 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.d.ts +2 -2
- package/dist/formatError.d.ts.map +1 -1
- package/dist/formatError.js +10 -2
- package/dist/formatError.js.map +1 -1
- package/dist/index.d.ts +9 -9
- 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 +9 -9
package/dist/FormView.js
CHANGED
|
@@ -5,9 +5,11 @@ import { ErrorSummary } from "./ErrorSummary.js";
|
|
|
5
5
|
import { FormContext, RevealContext, createRevealRegistry, useFormState } from "./context.js";
|
|
6
6
|
import { FormBinding } from "./FormBinding.js";
|
|
7
7
|
import { cx } from "./cx.js";
|
|
8
|
+
import { FormSkeleton } from "./FormSkeleton.js";
|
|
8
9
|
import { LayoutNodes } from "./layout/Layout.js";
|
|
9
|
-
import { useBeforeUnloadGuard } from "./unsaved.js";
|
|
10
|
-
import {
|
|
10
|
+
import { useBeforeUnloadGuard, useLeaveConfirmation } from "./unsaved.js";
|
|
11
|
+
import { c } from "react/compiler-runtime";
|
|
12
|
+
import { getLayoutFieldNames, getProblem, resolveFields, selectVisible, useLeaveGuard, usePanneau, usePlugins } from "@panneau/core";
|
|
11
13
|
import { Alert, Button, usePanneauIntl, useToast } from "@panneau/ui";
|
|
12
14
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
15
|
import { useRef, useState } from "react";
|
|
@@ -42,7 +44,13 @@ function orderErrors(names, errors) {
|
|
|
42
44
|
* unsaved changes and the dialog of version conflicts. Saving is the job of the form's
|
|
43
45
|
* `onSubmit`.
|
|
44
46
|
*/
|
|
45
|
-
function FormView(
|
|
47
|
+
function FormView(t0) {
|
|
48
|
+
const $ = c(46);
|
|
49
|
+
const { form, fields, layout: t1, locales, relationSource, uploadSource, checkSource, components, submitLabel, actions, onSubmitted, onReload, guardUnsavedChanges: t2, showSavedToast: t3, isLoading: t4, id, "aria-label": ariaLabel, className, layoutClassName, sidebarClassName, footerClassName, summaryClassName } = t0;
|
|
50
|
+
const layout = t1 === void 0 ? [] : t1;
|
|
51
|
+
const guardUnsavedChanges = t2 === void 0 ? true : t2;
|
|
52
|
+
const showSavedToast = t3 === void 0 ? true : t3;
|
|
53
|
+
const isLoading = t4 === void 0 ? false : t4;
|
|
46
54
|
const intl = usePanneauIntl();
|
|
47
55
|
const toasts = useToast();
|
|
48
56
|
const { definition } = usePanneau();
|
|
@@ -51,17 +59,39 @@ function FormView({ form, fields, layout = [], locales, relationSource, componen
|
|
|
51
59
|
const [registry] = useState(createRevealRegistry);
|
|
52
60
|
const [resolving, setResolving] = useState(false);
|
|
53
61
|
const root = useRef(null);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
const guarded = guardUnsavedChanges && state.dirty;
|
|
63
|
+
useBeforeUnloadGuard(guarded);
|
|
64
|
+
const leave = useLeaveConfirmation(guarded);
|
|
65
|
+
useLeaveGuard(guarded, leave.confirmLeave);
|
|
66
|
+
const resolved = resolveFields(fields, layout, { mode: form.mode });
|
|
67
|
+
const main = resolved.layout.filter(_temp);
|
|
68
|
+
let t5;
|
|
69
|
+
if ($[0] !== state) {
|
|
70
|
+
t5 = (node_0) => node_0.type === "sidebar" && selectVisible(state, node_0);
|
|
71
|
+
$[0] = state;
|
|
72
|
+
$[1] = t5;
|
|
73
|
+
} else t5 = $[1];
|
|
74
|
+
const sidebar = resolved.layout.filter(t5);
|
|
75
|
+
const order = [...getLayoutFieldNames(main), ...getLayoutFieldNames(sidebar.flatMap(_temp2))];
|
|
76
|
+
let t6;
|
|
77
|
+
if ($[2] !== plugins.fields) {
|
|
78
|
+
t6 = Object.fromEntries(plugins.fields);
|
|
79
|
+
$[2] = plugins.fields;
|
|
80
|
+
$[3] = t6;
|
|
81
|
+
} else t6 = $[3];
|
|
82
|
+
const t7 = t6;
|
|
83
|
+
let t8;
|
|
84
|
+
if ($[4] !== components || $[5] !== t7) {
|
|
85
|
+
t8 = {
|
|
86
|
+
...builtInFields,
|
|
87
|
+
...t7,
|
|
88
|
+
...components
|
|
89
|
+
};
|
|
90
|
+
$[4] = components;
|
|
91
|
+
$[5] = t7;
|
|
92
|
+
$[6] = t8;
|
|
93
|
+
} else t8 = $[6];
|
|
94
|
+
const entries = t8;
|
|
65
95
|
const goTo = (path) => {
|
|
66
96
|
registry.reveal(path);
|
|
67
97
|
requestAnimationFrame(() => {
|
|
@@ -101,102 +131,214 @@ function FormView({ form, fields, layout = [], locales, relationSource, componen
|
|
|
101
131
|
return;
|
|
102
132
|
}
|
|
103
133
|
setResolving(true);
|
|
104
|
-
|
|
105
|
-
handle(await form.resolveConflict(choice));
|
|
106
|
-
} finally {
|
|
107
|
-
setResolving(false);
|
|
108
|
-
}
|
|
134
|
+
await form.resolveConflict(choice).then(handle).finally(() => setResolving(false));
|
|
109
135
|
};
|
|
110
|
-
|
|
136
|
+
let t9;
|
|
137
|
+
if ($[7] !== state.error || $[8] !== state.status) {
|
|
138
|
+
t9 = state.status === "error" ? getProblem(state.error) : null;
|
|
139
|
+
$[7] = state.error;
|
|
140
|
+
$[8] = state.status;
|
|
141
|
+
$[9] = t9;
|
|
142
|
+
} else t9 = $[9];
|
|
143
|
+
const problem = t9;
|
|
111
144
|
const errorDetail = problem?.detail ?? (problem === null && state.error instanceof Error ? state.error.message : void 0);
|
|
112
145
|
const showSummary = state.status === "invalid" && state.submitCount > 0;
|
|
146
|
+
if (isLoading) return /* @__PURE__ */ jsx(FormSkeleton, {
|
|
147
|
+
main,
|
|
148
|
+
sidebar: resolved.layout.filter(_temp3),
|
|
149
|
+
fields: resolved.fieldsByName,
|
|
150
|
+
footer: submitLabel !== null || actions !== void 0,
|
|
151
|
+
className,
|
|
152
|
+
layoutClassName,
|
|
153
|
+
sidebarClassName,
|
|
154
|
+
footerClassName
|
|
155
|
+
});
|
|
156
|
+
let t10;
|
|
157
|
+
if ($[10] !== definition?.locales || $[11] !== locales) {
|
|
158
|
+
t10 = locales ?? definition?.locales ?? [];
|
|
159
|
+
$[10] = definition?.locales;
|
|
160
|
+
$[11] = locales;
|
|
161
|
+
$[12] = t10;
|
|
162
|
+
} else t10 = $[12];
|
|
163
|
+
let t11;
|
|
164
|
+
if ($[13] !== relationSource) {
|
|
165
|
+
t11 = relationSource !== void 0 ? { relationSource } : {};
|
|
166
|
+
$[13] = relationSource;
|
|
167
|
+
$[14] = t11;
|
|
168
|
+
} else t11 = $[14];
|
|
169
|
+
let t12;
|
|
170
|
+
if ($[15] !== uploadSource) {
|
|
171
|
+
t12 = uploadSource !== void 0 ? { uploadSource } : {};
|
|
172
|
+
$[15] = uploadSource;
|
|
173
|
+
$[16] = t12;
|
|
174
|
+
} else t12 = $[16];
|
|
175
|
+
let t13;
|
|
176
|
+
if ($[17] !== checkSource) {
|
|
177
|
+
t13 = checkSource !== void 0 ? { checkSource } : {};
|
|
178
|
+
$[17] = checkSource;
|
|
179
|
+
$[18] = t13;
|
|
180
|
+
} else t13 = $[18];
|
|
181
|
+
let t14;
|
|
182
|
+
if ($[19] !== className) {
|
|
183
|
+
t14 = cx(Form_module_default.form, className);
|
|
184
|
+
$[19] = className;
|
|
185
|
+
$[20] = t14;
|
|
186
|
+
} else t14 = $[20];
|
|
187
|
+
let t15;
|
|
188
|
+
if ($[21] !== errorDetail || $[22] !== intl || $[23] !== state.status) {
|
|
189
|
+
t15 = state.status === "error" ? /* @__PURE__ */ jsx(Alert, {
|
|
190
|
+
tone: "danger",
|
|
191
|
+
role: "alert",
|
|
192
|
+
title: intl.formatMessage(messages.saveFailed),
|
|
193
|
+
actions: /* @__PURE__ */ jsx(Button, {
|
|
194
|
+
size: "sm",
|
|
195
|
+
type: "submit",
|
|
196
|
+
children: intl.formatMessage(messages.retry)
|
|
197
|
+
}),
|
|
198
|
+
children: errorDetail
|
|
199
|
+
}) : null;
|
|
200
|
+
$[21] = errorDetail;
|
|
201
|
+
$[22] = intl;
|
|
202
|
+
$[23] = state.status;
|
|
203
|
+
$[24] = t15;
|
|
204
|
+
} else t15 = $[24];
|
|
205
|
+
const t16 = sidebar.length > 0 && Form_module_default.withSidebar;
|
|
206
|
+
let t17;
|
|
207
|
+
if ($[25] !== layoutClassName || $[26] !== t16) {
|
|
208
|
+
t17 = cx(Form_module_default.layout, t16, layoutClassName);
|
|
209
|
+
$[25] = layoutClassName;
|
|
210
|
+
$[26] = t16;
|
|
211
|
+
$[27] = t17;
|
|
212
|
+
} else t17 = $[27];
|
|
213
|
+
let t18;
|
|
214
|
+
if ($[28] !== actions || $[29] !== footerClassName || $[30] !== intl || $[31] !== state.dirty || $[32] !== state.status || $[33] !== submitLabel) {
|
|
215
|
+
t18 = submitLabel !== null || actions !== void 0 ? /* @__PURE__ */ jsxs("div", {
|
|
216
|
+
className: cx(Form_module_default.footer, footerClassName),
|
|
217
|
+
children: [
|
|
218
|
+
state.dirty ? /* @__PURE__ */ jsx("span", {
|
|
219
|
+
className: Form_module_default.dirty,
|
|
220
|
+
role: "status",
|
|
221
|
+
children: intl.formatMessage(messages.unsaved)
|
|
222
|
+
}) : null,
|
|
223
|
+
actions,
|
|
224
|
+
submitLabel !== null ? /* @__PURE__ */ jsx(Button, {
|
|
225
|
+
type: "submit",
|
|
226
|
+
variant: "primary",
|
|
227
|
+
isPending: state.status === "submitting",
|
|
228
|
+
children: submitLabel ?? intl.formatMessage(messages.save)
|
|
229
|
+
}) : null
|
|
230
|
+
]
|
|
231
|
+
}) : null;
|
|
232
|
+
$[28] = actions;
|
|
233
|
+
$[29] = footerClassName;
|
|
234
|
+
$[30] = intl;
|
|
235
|
+
$[31] = state.dirty;
|
|
236
|
+
$[32] = state.status;
|
|
237
|
+
$[33] = submitLabel;
|
|
238
|
+
$[34] = t18;
|
|
239
|
+
} else t18 = $[34];
|
|
240
|
+
const t19 = state.status === "conflict" || resolving;
|
|
241
|
+
const t20 = state.conflict?.current ?? null;
|
|
242
|
+
let t21;
|
|
243
|
+
let t22;
|
|
244
|
+
if ($[35] !== resolve) {
|
|
245
|
+
t21 = () => void resolve("reload");
|
|
246
|
+
t22 = () => void resolve("overwrite");
|
|
247
|
+
$[35] = resolve;
|
|
248
|
+
$[36] = t21;
|
|
249
|
+
$[37] = t22;
|
|
250
|
+
} else {
|
|
251
|
+
t21 = $[36];
|
|
252
|
+
t22 = $[37];
|
|
253
|
+
}
|
|
254
|
+
let t23;
|
|
255
|
+
if ($[38] !== resolved.fields || $[39] !== resolving || $[40] !== state.values || $[41] !== t19 || $[42] !== t20 || $[43] !== t21 || $[44] !== t22) {
|
|
256
|
+
t23 = /* @__PURE__ */ jsx(ConflictDialog, {
|
|
257
|
+
isOpen: t19,
|
|
258
|
+
fields: resolved.fields,
|
|
259
|
+
values: state.values,
|
|
260
|
+
current: t20,
|
|
261
|
+
isPending: resolving,
|
|
262
|
+
onReload: t21,
|
|
263
|
+
onOverwrite: t22
|
|
264
|
+
});
|
|
265
|
+
$[38] = resolved.fields;
|
|
266
|
+
$[39] = resolving;
|
|
267
|
+
$[40] = state.values;
|
|
268
|
+
$[41] = t19;
|
|
269
|
+
$[42] = t20;
|
|
270
|
+
$[43] = t21;
|
|
271
|
+
$[44] = t22;
|
|
272
|
+
$[45] = t23;
|
|
273
|
+
} else t23 = $[45];
|
|
113
274
|
return /* @__PURE__ */ jsx(FormContext, {
|
|
114
275
|
value: form,
|
|
115
276
|
children: /* @__PURE__ */ jsx(RevealContext, {
|
|
116
277
|
value: registry,
|
|
117
278
|
children: /* @__PURE__ */ jsxs(FieldsProvider, {
|
|
118
279
|
components: entries,
|
|
119
|
-
locales:
|
|
120
|
-
...
|
|
280
|
+
locales: t10,
|
|
281
|
+
...t11,
|
|
282
|
+
...t12,
|
|
283
|
+
...t13,
|
|
121
284
|
binding: FormBinding,
|
|
122
|
-
children: [
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
event
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
size: "sm",
|
|
145
|
-
type: "submit",
|
|
146
|
-
children: intl.formatMessage(messages.retry)
|
|
147
|
-
}),
|
|
148
|
-
children: errorDetail
|
|
149
|
-
}) : null,
|
|
150
|
-
/* @__PURE__ */ jsxs("div", {
|
|
151
|
-
className: cx(Form_module_default.layout, sidebar.length > 0 && Form_module_default.withSidebar, layoutClassName),
|
|
152
|
-
children: [/* @__PURE__ */ jsx("div", {
|
|
153
|
-
className: Form_module_default.stack,
|
|
154
|
-
children: /* @__PURE__ */ jsx(LayoutNodes, {
|
|
155
|
-
nodes: main,
|
|
156
|
-
fields: resolved.fieldsByName
|
|
157
|
-
})
|
|
158
|
-
}), sidebar.length > 0 ? /* @__PURE__ */ jsx("aside", {
|
|
159
|
-
className: cx(Form_module_default.sidebar, sidebarClassName),
|
|
160
|
-
children: sidebar.map((node_2, index) => /* @__PURE__ */ jsx("div", {
|
|
285
|
+
children: [
|
|
286
|
+
/* @__PURE__ */ jsxs("form", {
|
|
287
|
+
ref: root,
|
|
288
|
+
id,
|
|
289
|
+
"aria-label": ariaLabel,
|
|
290
|
+
noValidate: true,
|
|
291
|
+
className: t14,
|
|
292
|
+
onSubmit: (event) => {
|
|
293
|
+
event.preventDefault();
|
|
294
|
+
form.submit().then(handle);
|
|
295
|
+
},
|
|
296
|
+
children: [
|
|
297
|
+
showSummary ? /* @__PURE__ */ jsx(ErrorSummary, {
|
|
298
|
+
errors: orderErrors(order, state.errors),
|
|
299
|
+
fields: resolved.fields,
|
|
300
|
+
onSelect: goTo,
|
|
301
|
+
...summaryClassName !== void 0 ? { className: summaryClassName } : {}
|
|
302
|
+
}) : null,
|
|
303
|
+
t15,
|
|
304
|
+
/* @__PURE__ */ jsxs("div", {
|
|
305
|
+
className: t17,
|
|
306
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
161
307
|
className: Form_module_default.stack,
|
|
162
308
|
children: /* @__PURE__ */ jsx(LayoutNodes, {
|
|
163
|
-
nodes:
|
|
309
|
+
nodes: main,
|
|
164
310
|
fields: resolved.fieldsByName
|
|
165
311
|
})
|
|
166
|
-
},
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}) : null
|
|
184
|
-
]
|
|
185
|
-
}) : null
|
|
186
|
-
]
|
|
187
|
-
}), /* @__PURE__ */ jsx(ConflictDialog, {
|
|
188
|
-
isOpen: state.status === "conflict" || resolving,
|
|
189
|
-
fields: resolved.fields,
|
|
190
|
-
values: state.values,
|
|
191
|
-
current: state.conflict?.current ?? null,
|
|
192
|
-
isPending: resolving,
|
|
193
|
-
onReload: () => void resolve("reload"),
|
|
194
|
-
onOverwrite: () => void resolve("overwrite")
|
|
195
|
-
})]
|
|
312
|
+
}), sidebar.length > 0 ? /* @__PURE__ */ jsx("aside", {
|
|
313
|
+
className: cx(Form_module_default.sidebar, sidebarClassName),
|
|
314
|
+
children: sidebar.map((node_3, index) => /* @__PURE__ */ jsx("div", {
|
|
315
|
+
className: Form_module_default.stack,
|
|
316
|
+
children: /* @__PURE__ */ jsx(LayoutNodes, {
|
|
317
|
+
nodes: node_3.children ?? [],
|
|
318
|
+
fields: resolved.fieldsByName
|
|
319
|
+
})
|
|
320
|
+
}, index))
|
|
321
|
+
}) : null]
|
|
322
|
+
}),
|
|
323
|
+
t18
|
|
324
|
+
]
|
|
325
|
+
}),
|
|
326
|
+
t23,
|
|
327
|
+
leave.dialog
|
|
328
|
+
]
|
|
196
329
|
})
|
|
197
330
|
})
|
|
198
331
|
});
|
|
199
332
|
}
|
|
333
|
+
function _temp3(node_2) {
|
|
334
|
+
return node_2.type === "sidebar";
|
|
335
|
+
}
|
|
336
|
+
function _temp2(node_1) {
|
|
337
|
+
return node_1.children ?? [];
|
|
338
|
+
}
|
|
339
|
+
function _temp(node) {
|
|
340
|
+
return node.type !== "sidebar";
|
|
341
|
+
}
|
|
200
342
|
//#endregion
|
|
201
343
|
export { FormView };
|
|
202
344
|
|
package/dist/FormView.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormView.js","names":["node","styles"],"sources":["../src/FormView.tsx"],"sourcesContent":["import { type ReactNode, useRef, useState } from 'react';\n\nimport {\n type Form,\n type SubmitResult,\n getLayoutFieldNames,\n getProblem,\n resolveFields,\n selectVisible,\n usePanneau,\n usePlugins,\n} from '@panneau/core';\nimport {\n type FieldEntry,\n FieldsProvider,\n type RelationSource,\n builtInFields,\n} from '@panneau/fields';\nimport type { Field, LayoutNode } from '@panneau/protocol';\nimport { Alert, Button, usePanneauIntl, useToast } from '@panneau/ui';\n\nimport { ConflictDialog } from './ConflictDialog';\nimport { ErrorSummary } from './ErrorSummary';\nimport styles from './Form.module.css';\nimport { FormBinding } from './FormBinding';\nimport { FormContext, RevealContext, createRevealRegistry, useFormState } from './context';\nimport { cx } from './cx';\nimport { LayoutNodes } from './layout/Layout';\nimport { messages } from './messages';\nimport { useBeforeUnloadGuard } from './unsaved';\n\nexport interface FormViewProps {\n /** The form state, from `useForm()` or `createForm()` of `@panneau/core`. */\n form: Form;\n /** The fields of the form. */\n fields: readonly Field[];\n /** The layout tree. Fields that no node references are added at the end. */\n layout?: readonly LayoutNode[];\n /** Locales of localized fields. Defaults to the definition's, from `PanneauProvider`. */\n locales?: readonly string[];\n /** Where relation fields search. Defaults to the one of a parent `FieldsProvider`. */\n relationSource?: RelationSource | null;\n /** Field entries by type, over the built-in ones and those of the plugins. */\n components?: Readonly<Record<string, FieldEntry>>;\n /** Label of the submit button. Defaults to \"Save\". `null` hides the button. */\n submitLabel?: ReactNode;\n /** Other buttons, next to the submit button. */\n actions?: ReactNode;\n /** Called after a successful submit, with what `onSubmit` returned. */\n onSubmitted?: (result: unknown) => void;\n /**\n * Called by \"Load the current version\" in the conflict dialog when the backend didn't send the\n * current item: fetch it, and `form.reset()` with it.\n */\n onReload?: () => void;\n /** Asks for confirmation before the page is left with unsaved changes. Defaults to true. */\n guardUnsavedChanges?: boolean;\n /** Shows a toast after a successful submit. Defaults to true. */\n showSavedToast?: boolean;\n id?: string;\n 'aria-label'?: string;\n className?: string;\n layoutClassName?: string;\n sidebarClassName?: string;\n footerClassName?: string;\n summaryClassName?: string;\n}\n\nconst FOCUSABLE =\n 'input:not([type=\"hidden\"]):not([disabled]), textarea:not([disabled]), select:not([disabled]), button:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\n/** The element of the field at a path, or of the closest field that holds it. */\nfunction findFieldElement(root: HTMLElement, path: string): HTMLElement | null {\n let current = path;\n while (current !== '') {\n const element = root.querySelector<HTMLElement>(\n `[data-panneau-path=\"${CSS.escape(current)}\"]`,\n );\n if (element !== null) {\n return element;\n }\n current = current.includes('.') ? current.slice(0, current.lastIndexOf('.')) : '';\n }\n return null;\n}\n\n/**\n * Error paths in the order of their fields: the order of the layout for top-level fields, then\n * the order of the paths inside them (`blocks.2.body` before `blocks.10.body`).\n */\nfunction orderErrors(\n names: readonly string[],\n errors: Record<string, string[]>,\n): Record<string, string[]> {\n const rank = (path: string) => {\n const index = names.indexOf(path.split('.')[0] ?? '');\n return index === -1 ? names.length : index;\n };\n const compare = (a: string, b: string) =>\n rank(a) - rank(b) || a.localeCompare(b, undefined, { numeric: true });\n return Object.fromEntries(Object.entries(errors).sort(([a], [b]) => compare(a, b)));\n}\n\n/**\n * Renders a form: its fields in their layout, bound to the form state of `@panneau/core`, with\n * an error summary, a scroll to the first error, error counts on tabs and sections, a guard for\n * unsaved changes and the dialog of version conflicts. Saving is the job of the form's\n * `onSubmit`.\n */\nexport function FormView({\n form,\n fields,\n layout = [],\n locales,\n relationSource,\n components,\n submitLabel,\n actions,\n onSubmitted,\n onReload,\n guardUnsavedChanges = true,\n showSavedToast = true,\n id,\n 'aria-label': ariaLabel,\n className,\n layoutClassName,\n sidebarClassName,\n footerClassName,\n summaryClassName,\n}: FormViewProps) {\n const intl = usePanneauIntl();\n const toasts = useToast();\n const { definition } = usePanneau();\n const plugins = usePlugins();\n const state = useFormState(form);\n const [registry] = useState(createRevealRegistry);\n const [resolving, setResolving] = useState(false);\n const root = useRef<HTMLFormElement>(null);\n useBeforeUnloadGuard(guardUnsavedChanges && state.dirty);\n\n const resolved = resolveFields(fields, layout);\n const main = resolved.layout.filter((node) => node.type !== 'sidebar');\n const sidebar = resolved.layout.filter(\n (node) => node.type === 'sidebar' && selectVisible(state, node),\n );\n const order = [\n ...getLayoutFieldNames(main),\n ...getLayoutFieldNames(sidebar.flatMap((node) => node.children ?? [])),\n ];\n const entries: Record<string, FieldEntry> = {\n ...builtInFields,\n ...(Object.fromEntries(plugins.fields) as Record<string, FieldEntry>),\n ...components,\n };\n\n /** Opens the tab or section of a path, then scrolls to its field and focuses it. */\n const goTo = (path: string) => {\n registry.reveal(path);\n // Wait for the tab or section to open before scrolling.\n requestAnimationFrame(() => {\n const element = root.current !== null ? findFieldElement(root.current, path) : null;\n if (element === null) {\n return;\n }\n const reduced = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;\n element.scrollIntoView?.({ block: 'center', behavior: reduced ? 'auto' : 'smooth' });\n const target =\n element.querySelector<HTMLElement>('[aria-invalid=\"true\"]') ??\n element.querySelector<HTMLElement>(FOCUSABLE);\n target?.focus({ preventScroll: true });\n });\n };\n\n const handle = (result: SubmitResult | null) => {\n if (result === null) {\n return;\n }\n if (result.status === 'invalid') {\n const first = Object.keys(orderErrors(order, result.errors))[0];\n if (first !== undefined) {\n goTo(first);\n }\n } else if (result.status === 'submitted') {\n if (showSavedToast) {\n toasts.show({ title: intl.formatMessage(messages.saved), tone: 'success' });\n }\n onSubmitted?.(result.result);\n } else if (result.status === 'error') {\n toasts.show(\n {\n title: intl.formatMessage(messages.saveFailed),\n tone: 'danger',\n action: {\n label: intl.formatMessage(messages.retry),\n onAction: () => void form.submit().then(handle),\n },\n },\n { timeout: 8000 },\n );\n }\n };\n\n const resolve = async (choice: 'reload' | 'overwrite') => {\n if (choice === 'reload' && state.conflict?.current === null && onReload !== undefined) {\n onReload();\n return;\n }\n setResolving(true);\n try {\n handle(await form.resolveConflict(choice));\n } finally {\n setResolving(false);\n }\n };\n\n const problem = state.status === 'error' ? getProblem(state.error) : null;\n const errorDetail =\n problem?.detail ??\n (problem === null && state.error instanceof Error ? state.error.message : undefined);\n const showSummary = state.status === 'invalid' && state.submitCount > 0;\n\n return (\n <FormContext value={form}>\n <RevealContext value={registry}>\n <FieldsProvider\n components={entries}\n locales={locales ?? definition?.locales ?? []}\n {...(relationSource !== undefined ? { relationSource } : {})}\n binding={FormBinding}\n >\n <form\n ref={root}\n id={id}\n aria-label={ariaLabel}\n noValidate\n className={cx(styles.form, className)}\n onSubmit={(event) => {\n event.preventDefault();\n void form.submit().then(handle);\n }}\n >\n {showSummary ? (\n <ErrorSummary\n errors={orderErrors(order, state.errors)}\n fields={resolved.fields}\n onSelect={goTo}\n {...(summaryClassName !== undefined\n ? { className: summaryClassName }\n : {})}\n />\n ) : null}\n {state.status === 'error' ? (\n <Alert\n tone=\"danger\"\n role=\"alert\"\n title={intl.formatMessage(messages.saveFailed)}\n actions={\n <Button size=\"sm\" type=\"submit\">\n {intl.formatMessage(messages.retry)}\n </Button>\n }\n >\n {errorDetail}\n </Alert>\n ) : null}\n <div\n className={cx(\n styles.layout,\n sidebar.length > 0 && styles.withSidebar,\n layoutClassName,\n )}\n >\n <div className={styles.stack}>\n <LayoutNodes nodes={main} fields={resolved.fieldsByName} />\n </div>\n {sidebar.length > 0 ? (\n <aside className={cx(styles.sidebar, sidebarClassName)}>\n {sidebar.map((node, index) => (\n <div key={index} className={styles.stack}>\n <LayoutNodes\n nodes={node.children ?? []}\n fields={resolved.fieldsByName}\n />\n </div>\n ))}\n </aside>\n ) : null}\n </div>\n {submitLabel !== null || actions !== undefined ? (\n <div className={cx(styles.footer, footerClassName)}>\n {state.dirty ? (\n <span className={styles.dirty} role=\"status\">\n {intl.formatMessage(messages.unsaved)}\n </span>\n ) : null}\n {actions}\n {submitLabel !== null ? (\n <Button\n type=\"submit\"\n variant=\"primary\"\n isPending={state.status === 'submitting'}\n >\n {submitLabel ?? intl.formatMessage(messages.save)}\n </Button>\n ) : null}\n </div>\n ) : null}\n </form>\n <ConflictDialog\n isOpen={state.status === 'conflict' || resolving}\n fields={resolved.fields}\n values={state.values}\n current={state.conflict?.current ?? null}\n isPending={resolving}\n onReload={() => void resolve('reload')}\n onOverwrite={() => void resolve('overwrite')}\n />\n </FieldsProvider>\n </RevealContext>\n </FormContext>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAoEA,IAAM,YACF;;AAGJ,SAAS,iBAAiB,MAAmB,MAAkC;CAC3E,IAAI,UAAU;CACd,OAAO,YAAY,IAAI;EACnB,MAAM,UAAU,KAAK,cACjB,uBAAuB,IAAI,OAAO,OAAO,EAAC,GAC9C;EACA,IAAI,YAAY,MACZ,OAAO;EAEX,UAAU,QAAQ,SAAS,GAAG,IAAI,QAAQ,MAAM,GAAG,QAAQ,YAAY,GAAG,CAAC,IAAI;CACnF;CACA,OAAO;AACX;;;;;AAMA,SAAS,YACL,OACA,QACwB;CACxB,MAAM,QAAQ,SAAiB;EAC3B,MAAM,QAAQ,MAAM,QAAQ,KAAK,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE;EACpD,OAAO,UAAU,KAAK,MAAM,SAAS;CACzC;CACA,MAAM,WAAW,GAAW,MACxB,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,EAAE,cAAc,GAAG,KAAA,GAAW,EAAE,SAAS,KAAK,CAAC;CACxE,OAAO,OAAO,YAAY,OAAO,QAAQ,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,QAAQ,GAAG,CAAC,CAAC,CAAC;AACtF;;;;;;;AAQA,SAAgB,SAAS,EACrB,MACA,QACA,SAAS,CAAA,GACT,SACA,gBACA,YACA,aACA,SACA,aACA,UACA,sBAAsB,MACtB,iBAAiB,MACjB,IACA,cAAc,WACd,WACA,iBACA,kBACA,iBACA,oBACc;CACd,MAAM,OAAO,eAAe;CAC5B,MAAM,SAAS,SAAS;CACxB,MAAM,EAAE,eAAe,WAAW;CAClC,MAAM,UAAU,WAAW;CAC3B,MAAM,QAAQ,aAAa,IAAI;CAC/B,MAAM,CAAC,YAAY,SAAS,oBAAoB;CAChD,MAAM,CAAC,WA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C,QAAQ,SAAS;KACjB,QAAQ,MAAM;KACd,SAAS,MAAM,UAAU,WAAW;KACpC,WAAW;KACX,gBAAgB,KAAK,QAAQ,QAAQ;KACrC,mBAAmB,KAAK,QAAQ,WAAW;IAAE,CAAA,CAErC;;EACL,CAAA;CACN,CAAA;AAErB"}
|
|
1
|
+
{"version":3,"file":"FormView.js","names":["ReactNode","useRef","useState","Form","SubmitResult","getLayoutFieldNames","getProblem","resolveFields","selectVisible","useLeaveGuard","usePanneau","usePlugins","FieldCheckSource","FieldEntry","FieldsProvider","RelationSource","UploadSource","builtInFields","Field","LayoutNode","Alert","Button","usePanneauIntl","useToast","ConflictDialog","ErrorSummary","styles","FormBinding","FormSkeleton","FormContext","RevealContext","createRevealRegistry","useFormState","cx","LayoutNodes","messages","useBeforeUnloadGuard","useLeaveConfirmation","FormViewProps","form","fields","layout","locales","relationSource","uploadSource","checkSource","components","Readonly","Record","submitLabel","actions","onSubmitted","result","onReload","guardUnsavedChanges","showSavedToast","isLoading","id","className","layoutClassName","sidebarClassName","footerClassName","summaryClassName","FOCUSABLE","findFieldElement","root","HTMLElement","path","current","element","querySelector","CSS","escape","includes","slice","lastIndexOf","orderErrors","names","errors","rank","index","indexOf","split","length","compare","a","b","localeCompare","undefined","numeric","Object","fromEntries","entries","sort","FormView","t0","$","_c","t1","t2","t3","t4","ariaLabel","intl","toasts","definition","plugins","state","registry","resolving","setResolving","guarded","dirty","leave","confirmLeave","resolved","mode","main","filter","_temp","t5","node_0","node","type","sidebar","order","flatMap","_temp2","t6","t7","t8","goTo","reveal","requestAnimationFrame","reduced","window","matchMedia","matches","scrollIntoView","block","behavior","target","focus","preventScroll","handle","status","first","keys","show","title","formatMessage","saved","tone","saveFailed","action","label","retry","onAction","submit","then","timeout","resolve","choice","conflict","resolveConflict","finally","t9","error","problem","errorDetail","detail","Error","message","showSummary","submitCount","_temp3","fieldsByName","t10","t11","t12","t13","t14","t15","t16","withSidebar","t17","t18","footer","unsaved","save","t19","t20","t21","t22","t23","values","event","preventDefault","stack","map","node_3","children","dialog","node_2","node_1","_c","styles"],"sources":["../src/FormView.tsx"],"sourcesContent":["import { type ReactNode, useRef, useState } from 'react';\n\nimport {\n type Form,\n type SubmitResult,\n getLayoutFieldNames,\n getProblem,\n resolveFields,\n selectVisible,\n useLeaveGuard,\n usePanneau,\n usePlugins,\n} from '@panneau/core';\nimport {\n type FieldCheckSource,\n type FieldEntry,\n FieldsProvider,\n type RelationSource,\n type UploadSource,\n builtInFields,\n} from '@panneau/fields';\nimport type { Field, LayoutNode } from '@panneau/protocol';\nimport { Alert, Button, usePanneauIntl, useToast } from '@panneau/ui';\n\nimport { ConflictDialog } from './ConflictDialog';\nimport { ErrorSummary } from './ErrorSummary';\nimport styles from './Form.module.css';\nimport { FormBinding } from './FormBinding';\nimport { FormSkeleton } from './FormSkeleton';\nimport { FormContext, RevealContext, createRevealRegistry, useFormState } from './context';\nimport { cx } from './cx';\nimport { LayoutNodes } from './layout/Layout';\nimport { messages } from './messages';\nimport { useBeforeUnloadGuard, useLeaveConfirmation } from './unsaved';\n\nexport interface FormViewProps {\n /** The form state, from `useForm()` or `createForm()` of `@panneau/core`. */\n form: Form;\n /** The fields of the form. */\n fields: readonly Field[];\n /** The layout tree. Fields that no node references are added at the end. */\n layout?: readonly LayoutNode[];\n /** Locales of localized fields. Defaults to the definition's, from `PanneauProvider`. */\n locales?: readonly string[];\n /** Where relation fields search. Defaults to the one of a parent `FieldsProvider`. */\n relationSource?: RelationSource | null;\n /**\n * Where fields that take files upload them directly to storage. Defaults to the one of a\n * parent `FieldsProvider`. Without one, values hold the files themselves.\n */\n uploadSource?: UploadSource | null;\n /**\n * Where fields with `check` check their value, such as a slug's availability:\n * `createFieldCheckSource(adapter, resource, id)`. Defaults to the one of a parent\n * `FieldsProvider`.\n */\n checkSource?: FieldCheckSource | null;\n /** Field entries by type, over the built-in ones and those of the plugins. */\n components?: Readonly<Record<string, FieldEntry>>;\n /** Label of the submit button. Defaults to \"Save\". `null` hides the button. */\n submitLabel?: ReactNode;\n /** Other buttons, next to the submit button. */\n actions?: ReactNode;\n /** Called after a successful submit, with what `onSubmit` returned. */\n onSubmitted?: (result: unknown) => void;\n /**\n * Called by \"Load the current version\" in the conflict dialog when the backend didn't send the\n * current item: fetch it, and `form.reset()` with it.\n */\n onReload?: () => void;\n /**\n * Asks for confirmation before the page is left with unsaved changes: closed or reloaded, or,\n * under a `LeaveGuardsProvider`, left through the app's router. Defaults to true.\n */\n guardUnsavedChanges?: boolean;\n /** Shows a toast after a successful submit. Defaults to true. */\n showSavedToast?: boolean;\n /**\n * The values load, such as the item to edit: the form draws a skeleton of its layout and\n * fields instead (decision 0034).\n */\n isLoading?: boolean;\n id?: string;\n 'aria-label'?: string;\n className?: string;\n layoutClassName?: string;\n sidebarClassName?: string;\n footerClassName?: string;\n summaryClassName?: string;\n}\n\nconst FOCUSABLE =\n 'input:not([type=\"hidden\"]):not([disabled]), textarea:not([disabled]), select:not([disabled]), button:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\n/** The element of the field at a path, or of the closest field that holds it. */\nfunction findFieldElement(root: HTMLElement, path: string): HTMLElement | null {\n let current = path;\n while (current !== '') {\n const element = root.querySelector<HTMLElement>(\n `[data-panneau-path=\"${CSS.escape(current)}\"]`,\n );\n if (element !== null) {\n return element;\n }\n current = current.includes('.') ? current.slice(0, current.lastIndexOf('.')) : '';\n }\n return null;\n}\n\n/**\n * Error paths in the order of their fields: the order of the layout for top-level fields, then\n * the order of the paths inside them (`blocks.2.body` before `blocks.10.body`).\n */\nfunction orderErrors(\n names: readonly string[],\n errors: Record<string, string[]>,\n): Record<string, string[]> {\n const rank = (path: string) => {\n const index = names.indexOf(path.split('.')[0] ?? '');\n return index === -1 ? names.length : index;\n };\n const compare = (a: string, b: string) =>\n rank(a) - rank(b) || a.localeCompare(b, undefined, { numeric: true });\n return Object.fromEntries(Object.entries(errors).sort(([a], [b]) => compare(a, b)));\n}\n\n/**\n * Renders a form: its fields in their layout, bound to the form state of `@panneau/core`, with\n * an error summary, a scroll to the first error, error counts on tabs and sections, a guard for\n * unsaved changes and the dialog of version conflicts. Saving is the job of the form's\n * `onSubmit`.\n */\nexport function FormView({\n form,\n fields,\n layout = [],\n locales,\n relationSource,\n uploadSource,\n checkSource,\n components,\n submitLabel,\n actions,\n onSubmitted,\n onReload,\n guardUnsavedChanges = true,\n showSavedToast = true,\n isLoading = false,\n id,\n 'aria-label': ariaLabel,\n className,\n layoutClassName,\n sidebarClassName,\n footerClassName,\n summaryClassName,\n}: FormViewProps) {\n const intl = usePanneauIntl();\n const toasts = useToast();\n const { definition } = usePanneau();\n const plugins = usePlugins();\n const state = useFormState(form);\n const [registry] = useState(createRevealRegistry);\n const [resolving, setResolving] = useState(false);\n const root = useRef<HTMLFormElement>(null);\n const guarded = guardUnsavedChanges && state.dirty;\n useBeforeUnloadGuard(guarded);\n // Leaving through the app's router asks first, in a dialog\n const leave = useLeaveConfirmation(guarded);\n useLeaveGuard(guarded, leave.confirmLeave);\n\n // In the mode of the form, as its rules are checked: the required mark of a password\n // required on create shows on create only\n const resolved = resolveFields(fields, layout, { mode: form.mode });\n const main = resolved.layout.filter((node) => node.type !== 'sidebar');\n const sidebar = resolved.layout.filter(\n (node) => node.type === 'sidebar' && selectVisible(state, node),\n );\n const order = [\n ...getLayoutFieldNames(main),\n ...getLayoutFieldNames(sidebar.flatMap((node) => node.children ?? [])),\n ];\n const entries: Record<string, FieldEntry> = {\n ...builtInFields,\n ...(Object.fromEntries(plugins.fields) as Record<string, FieldEntry>),\n ...components,\n };\n\n /** Opens the tab or section of a path, then scrolls to its field and focuses it. */\n const goTo = (path: string) => {\n registry.reveal(path);\n // Wait for the tab or section to open before scrolling.\n requestAnimationFrame(() => {\n const element = root.current !== null ? findFieldElement(root.current, path) : null;\n if (element === null) {\n return;\n }\n const reduced = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;\n element.scrollIntoView?.({ block: 'center', behavior: reduced ? 'auto' : 'smooth' });\n const target =\n element.querySelector<HTMLElement>('[aria-invalid=\"true\"]') ??\n element.querySelector<HTMLElement>(FOCUSABLE);\n target?.focus({ preventScroll: true });\n });\n };\n\n const handle = (result: SubmitResult | null) => {\n if (result === null) {\n return;\n }\n if (result.status === 'invalid') {\n const first = Object.keys(orderErrors(order, result.errors))[0];\n if (first !== undefined) {\n goTo(first);\n }\n } else if (result.status === 'submitted') {\n if (showSavedToast) {\n toasts.show({ title: intl.formatMessage(messages.saved), tone: 'success' });\n }\n onSubmitted?.(result.result);\n } else if (result.status === 'error') {\n toasts.show(\n {\n title: intl.formatMessage(messages.saveFailed),\n tone: 'danger',\n action: {\n label: intl.formatMessage(messages.retry),\n onAction: () => void form.submit().then(handle),\n },\n },\n { timeout: 8000 },\n );\n }\n };\n\n const resolve = async (choice: 'reload' | 'overwrite') => {\n if (choice === 'reload' && state.conflict?.current === null && onReload !== undefined) {\n onReload();\n return;\n }\n setResolving(true);\n await form\n .resolveConflict(choice)\n .then(handle)\n .finally(() => setResolving(false));\n };\n\n const problem = state.status === 'error' ? getProblem(state.error) : null;\n const errorDetail =\n problem?.detail ??\n (problem === null && state.error instanceof Error ? state.error.message : undefined);\n const showSummary = state.status === 'invalid' && state.submitCount > 0;\n\n if (isLoading) {\n return (\n <FormSkeleton\n main={main}\n sidebar={resolved.layout.filter((node) => node.type === 'sidebar')}\n fields={resolved.fieldsByName}\n footer={submitLabel !== null || actions !== undefined}\n className={className}\n layoutClassName={layoutClassName}\n sidebarClassName={sidebarClassName}\n footerClassName={footerClassName}\n />\n );\n }\n\n return (\n <FormContext value={form}>\n <RevealContext value={registry}>\n <FieldsProvider\n components={entries}\n locales={locales ?? definition?.locales ?? []}\n {...(relationSource !== undefined ? { relationSource } : {})}\n {...(uploadSource !== undefined ? { uploadSource } : {})}\n {...(checkSource !== undefined ? { checkSource } : {})}\n binding={FormBinding}\n >\n <form\n ref={root}\n id={id}\n aria-label={ariaLabel}\n noValidate\n className={cx(styles.form, className)}\n onSubmit={(event) => {\n event.preventDefault();\n void form.submit().then(handle);\n }}\n >\n {showSummary ? (\n <ErrorSummary\n errors={orderErrors(order, state.errors)}\n fields={resolved.fields}\n onSelect={goTo}\n {...(summaryClassName !== undefined\n ? { className: summaryClassName }\n : {})}\n />\n ) : null}\n {state.status === 'error' ? (\n <Alert\n tone=\"danger\"\n role=\"alert\"\n title={intl.formatMessage(messages.saveFailed)}\n actions={\n <Button size=\"sm\" type=\"submit\">\n {intl.formatMessage(messages.retry)}\n </Button>\n }\n >\n {errorDetail}\n </Alert>\n ) : null}\n <div\n className={cx(\n styles.layout,\n sidebar.length > 0 && styles.withSidebar,\n layoutClassName,\n )}\n >\n <div className={styles.stack}>\n <LayoutNodes nodes={main} fields={resolved.fieldsByName} />\n </div>\n {sidebar.length > 0 ? (\n <aside className={cx(styles.sidebar, sidebarClassName)}>\n {sidebar.map((node, index) => (\n <div key={index} className={styles.stack}>\n <LayoutNodes\n nodes={node.children ?? []}\n fields={resolved.fieldsByName}\n />\n </div>\n ))}\n </aside>\n ) : null}\n </div>\n {submitLabel !== null || actions !== undefined ? (\n <div className={cx(styles.footer, footerClassName)}>\n {state.dirty ? (\n <span className={styles.dirty} role=\"status\">\n {intl.formatMessage(messages.unsaved)}\n </span>\n ) : null}\n {actions}\n {submitLabel !== null ? (\n <Button\n type=\"submit\"\n variant=\"primary\"\n isPending={state.status === 'submitting'}\n >\n {submitLabel ?? intl.formatMessage(messages.save)}\n </Button>\n ) : null}\n </div>\n ) : null}\n </form>\n <ConflictDialog\n isOpen={state.status === 'conflict' || resolving}\n fields={resolved.fields}\n values={state.values}\n current={state.conflict?.current ?? null}\n isPending={resolving}\n onReload={() => void resolve('reload')}\n onOverwrite={() => void resolve('overwrite')}\n />\n {leave.dialog}\n </FieldsProvider>\n </RevealContext>\n </FormContext>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA2FA,IAAM+D,YACF;;AAGJ,SAASC,iBAAiBC,MAAmBE,MAAkC;CAC3E,IAAIC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MAAO;QAC/B,QAAAqC,SAAQ3E;QACN2F,UAAAA;QAAI,GACTrE,qBAAqB0B,KAAAA,IAArB,EAAA9B,WACcI,iBACZ,IAFF,CAEE;OAAC,CAAA,IAPf;OAUAwH;OAcD,qBAAA,OAAA;QACe,WAAAG;QADf,UAAA,CAOI,oBAAA,OAAA;SAAgB,WAAA/J,oBAAM4K;SAClB,UAAA,oBAAC,aAAD;UAAoBjF,OAAAA;UAAc,QAAAF,SAAQ6D;SAAa,CAAA;QACrD,CAAA,GACLpD,QAAOzC,SAAU,IACd,oBAAA,SAAA;SAAkB,WAAAlD,GAAGP,oBAAMkG,SAAUhE,gBAAgB;SAChDgE,UAAAA,QAAO2E,KAAKC,QAAAxH,UACT,oBAAA,OAAA;UAA4B,WAAAtD,oBAAM4K;UAC9B,UAAA,oBAAC,aAAD;WACW,OAAA5E,OAAI+E,YAAJ,CAAA;WACC,QAAAtF,SAAQ6D;UAAa,CAAA;SAE/B,GALIhG,KAKJ,CACT;QACG,CAAA,IAVX,IAYC;;OACL0G;MAmBE;;KACPQ;KASCjF,MAAKyF;IA/FK;;EADL,CAAA;CADN,CAAA;AAoGE;AA5Of,SAAA3B,OAAA4B,QAAA;CAAA,OA4HmDjF,OAAIC,SAAU;AAAS;AA5H1E,SAAAI,OAAA6E,QAAA;CAAA,OA+CkDlF,OAAI+E,YAAJ,CAAA;AAAmB;AA/CrE,SAAAlF,MAAAG,MAAA;CAAA,OAyC2CA,KAAIC,SAAU;AAAS"}
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","names":[],"sources":["../src/context.ts"],"sourcesContent":["import { createContext, use, useSyncExternalStore } from 'react';\n\nimport type { Form, FormState } from '@panneau/core';\n\nexport const FormContext = createContext<Form | null>(null);\n\n/** The form of the closest `FormView`. */\nexport function useFormContext(): Form {\n const form = use(FormContext);\n if (form === null) {\n throw new Error('This component must be rendered inside a <Form> or a <FormView>.');\n }\n return form;\n}\n\n/** The state of a form, updated on every change. */\nexport function useFormState(form: Form): FormState {\n return useSyncExternalStore(form.subscribe, form.getState, form.getState);\n}\n\n/** Opens the containers (tabs, sections) that hold a path, so that its field can be reached. */\nexport type Revealer = (path: string) => void;\n\nexport interface RevealRegistry {\n add(revealer: Revealer): () => void;\n reveal(path: string): void;\n}\n\nexport function createRevealRegistry(): RevealRegistry {\n const revealers = new Set<Revealer>();\n return {\n add(revealer) {\n revealers.add(revealer);\n return () => {\n revealers.delete(revealer);\n };\n },\n reveal(path) {\n revealers.forEach((revealer) => revealer(path));\n },\n };\n}\n\nexport const RevealContext = createContext<RevealRegistry>(createRevealRegistry());\n"],"mappings":";;AAIA,
|
|
1
|
+
{"version":3,"file":"context.js","names":["createContext","use","useSyncExternalStore","Form","FormState","FormContext","useFormContext","form","Error","useFormState","subscribe","getState","Revealer","path","RevealRegistry","add","revealer","reveal","createRevealRegistry","revealers","Set","delete","forEach","RevealContext"],"sources":["../src/context.ts"],"sourcesContent":["import { createContext, use, useSyncExternalStore } from 'react';\n\nimport type { Form, FormState } from '@panneau/core';\n\nexport const FormContext = createContext<Form | null>(null);\n\n/** The form of the closest `FormView`. */\nexport function useFormContext(): Form {\n const form = use(FormContext);\n if (form === null) {\n throw new Error('This component must be rendered inside a <Form> or a <FormView>.');\n }\n return form;\n}\n\n/** The state of a form, updated on every change. */\nexport function useFormState(form: Form): FormState {\n return useSyncExternalStore(form.subscribe, form.getState, form.getState);\n}\n\n/** Opens the containers (tabs, sections) that hold a path, so that its field can be reached. */\nexport type Revealer = (path: string) => void;\n\nexport interface RevealRegistry {\n add(revealer: Revealer): () => void;\n reveal(path: string): void;\n}\n\nexport function createRevealRegistry(): RevealRegistry {\n const revealers = new Set<Revealer>();\n return {\n add(revealer) {\n revealers.add(revealer);\n return () => {\n revealers.delete(revealer);\n };\n },\n reveal(path) {\n revealers.forEach((revealer) => revealer(path));\n },\n };\n}\n\nexport const RevealContext = createContext<RevealRegistry>(createRevealRegistry());\n"],"mappings":";;AAIA,IAAaK,cAAcL,cAA2B,IAAI;;AAG1D,SAAgBM,iBAAuB;CACnC,MAAMC,OAAON,IAAII,WAAW;CAC5B,IAAIE,SAAS,MACT,MAAM,IAAIC,MAAM,kEAAkE;CAEtF,OAAOD;AACX;;AAGA,SAAOE,aAAAF,MAAA;CAAA,OACIL,qBAAqBK,KAAIG,WAAYH,KAAII,UAAWJ,KAAII,QAAS;AAAC;AAW7E,SAAgBO,uBAAuC;CACnD,MAAMC,4BAAY,IAAIC,IAAc;CACpC,OAAO;EACHL,IAAIC,UAAU;GACVG,UAAUJ,IAAIC,QAAQ;GACtB,aAAa;IACTG,UAAUE,OAAOL,QAAQ;GAC7B;EACJ;EACAC,OAAOJ,MAAM;GACTM,UAAUG,SAASN,aAAaA,SAASH,IAAI,CAAC;EAClD;CACJ;AACJ;AAEA,IAAaU,gBAAgBvB,cAA8BkB,qBAAqB,CAAC"}
|
package/dist/cx.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cx.js","names":[],"sources":["../src/cx.ts"],"sourcesContent":["/** Joins class names, skipping empty ones. */\nexport function cx(...classNames: (string | false | null | undefined)[]): string {\n return classNames.filter(Boolean).join(' ');\n}\n"],"mappings":";;AACA,
|
|
1
|
+
{"version":3,"file":"cx.js","names":["cx","classNames","filter","Boolean","join"],"sources":["../src/cx.ts"],"sourcesContent":["/** Joins class names, skipping empty ones. */\nexport function cx(...classNames: (string | false | null | undefined)[]): string {\n return classNames.filter(Boolean).join(' ');\n}\n"],"mappings":";;AACA,SAAgBA,GAAG,GAAGC,YAA2D;CAC7E,OAAOA,WAAWC,OAAOC,OAAO,CAAC,CAACC,KAAK,GAAG;AAC9C"}
|
package/dist/describe.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"describe.js","names":[],"sources":["../src/describe.ts"],"sourcesContent":["import type { Field } from '@panneau/protocol';\n\nimport { getPathSteps } from './paths';\n\n/**\n * A readable name for the value at a path, from the labels of its fields: `Blocks › 3 › Body`,\n * `Title (fr)`. Unknown paths are returned as is.\n */\nexport function describePath(fields: readonly Field[], path: string): string {\n const steps = getPathSteps(fields, path);\n if (steps.length === 0) {\n return path;\n }\n return steps\n .map((step) => {\n const label = step.field.label ?? step.field.name;\n const locale = step.locale !== undefined ? ` (${step.locale})` : '';\n const index = step.index !== undefined ? ` › ${step.index + 1}` : '';\n return `${label}${locale}${index}`;\n })\n .join(' › ');\n}\n"],"mappings":";;;;;;AAQA,
|
|
1
|
+
{"version":3,"file":"describe.js","names":["Field","getPathSteps","describePath","fields","path","steps","length","map","step","label","field","name","locale","undefined","index","join"],"sources":["../src/describe.ts"],"sourcesContent":["import type { Field } from '@panneau/protocol';\n\nimport { getPathSteps } from './paths';\n\n/**\n * A readable name for the value at a path, from the labels of its fields: `Blocks › 3 › Body`,\n * `Title (fr)`. Unknown paths are returned as is.\n */\nexport function describePath(fields: readonly Field[], path: string): string {\n const steps = getPathSteps(fields, path);\n if (steps.length === 0) {\n return path;\n }\n return steps\n .map((step) => {\n const label = step.field.label ?? step.field.name;\n const locale = step.locale !== undefined ? ` (${step.locale})` : '';\n const index = step.index !== undefined ? ` › ${step.index + 1}` : '';\n return `${label}${locale}${index}`;\n })\n .join(' › ');\n}\n"],"mappings":";;;;;;AAQA,SAAgBE,aAAaC,QAA0BC,MAAsB;CACzE,MAAMC,QAAQJ,aAAaE,QAAQC,IAAI;CACvC,IAAIC,MAAMC,WAAW,GACjB,OAAOF;CAEX,OAAOC,MACFE,KAAKC,SAAS;EAIX,OAAO,GAHOA,KAAKE,MAAMD,SAASD,KAAKE,MAAMC,OAC9BH,KAAKI,WAAWC,KAAAA,IAAY,KAAKL,KAAKI,OAAM,KAAM,KACnDJ,KAAKM,UAAUD,KAAAA,IAAY,MAAML,KAAKM,QAAQ,MAAM;CAEtE,CAAC,CAAC,CACDC,KAAK,KAAK;AACnB"}
|
package/dist/formatError.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Field, RuleFailure } from '@panneau/protocol';
|
|
2
2
|
/**
|
|
3
3
|
* Translates the failures of the portable rules with react-intl, for `formatError`. `min` and
|
|
4
|
-
* `max` say "characters" for texts and "items" for lists, from the field at the path
|
|
5
|
-
* `message` wins.
|
|
4
|
+
* `max` say "characters" for texts and "items" for lists, from the field at the path, and `crop`
|
|
5
|
+
* names its ratios. A rule's own `message` wins.
|
|
6
6
|
*/
|
|
7
7
|
export declare function useFormatRuleFailure(fields: readonly Field[]): (failure: RuleFailure, path: string) => string;
|
|
8
8
|
//# sourceMappingURL=formatError.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatError.d.ts","sourceRoot":"","sources":["../src/formatError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAQ5D;;;;GAIG;AACH,wBAAgB,oBAAoB,CAChC,MAAM,EAAE,SAAS,KAAK,EAAE,GACzB,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,
|
|
1
|
+
{"version":3,"file":"formatError.d.ts","sourceRoot":"","sources":["../src/formatError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAQ5D;;;;GAIG;AACH,wBAAgB,oBAAoB,CAChC,MAAM,EAAE,SAAS,KAAK,EAAE,GACzB,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CA4DhD"}
|
package/dist/formatError.js
CHANGED
|
@@ -11,8 +11,8 @@ var COUNTED = /* @__PURE__ */ new Set([
|
|
|
11
11
|
]);
|
|
12
12
|
/**
|
|
13
13
|
* Translates the failures of the portable rules with react-intl, for `formatError`. `min` and
|
|
14
|
-
* `max` say "characters" for texts and "items" for lists, from the field at the path
|
|
15
|
-
* `message` wins.
|
|
14
|
+
* `max` say "characters" for texts and "items" for lists, from the field at the path, and `crop`
|
|
15
|
+
* names its ratios. A rule's own `message` wins.
|
|
16
16
|
*/
|
|
17
17
|
function useFormatRuleFailure(fields) {
|
|
18
18
|
const $ = c(3);
|
|
@@ -30,6 +30,11 @@ function useFormatRuleFailure(fields) {
|
|
|
30
30
|
const key = list ? failure.rule === "min" ? "minItems" : "maxItems" : numeric ? failure.rule : failure.rule === "min" ? "minLength" : "maxLength";
|
|
31
31
|
return intl.formatMessage(messages.rule[key], { value });
|
|
32
32
|
}
|
|
33
|
+
if (failure.rule === "crop") {
|
|
34
|
+
const given = typeof failure.value === "object" && failure.value !== null ? failure.value.ratios : void 0;
|
|
35
|
+
const ratios = Array.isArray(given) ? given.filter(_temp) : [];
|
|
36
|
+
return ratios.length > 0 ? intl.formatMessage(messages.rule.cropRatios, { ratios: intl.formatList(ratios, { type: "disjunction" }) }) : intl.formatMessage(messages.rule.crop);
|
|
37
|
+
}
|
|
33
38
|
const rule = failure.rule;
|
|
34
39
|
if (rule in messages.rule && rule !== "min" && rule !== "max") return intl.formatMessage(messages.rule[rule]);
|
|
35
40
|
return intl.formatMessage(messages.rule.invalid);
|
|
@@ -40,6 +45,9 @@ function useFormatRuleFailure(fields) {
|
|
|
40
45
|
} else t0 = $[2];
|
|
41
46
|
return t0;
|
|
42
47
|
}
|
|
48
|
+
function _temp(ratio) {
|
|
49
|
+
return typeof ratio === "string";
|
|
50
|
+
}
|
|
43
51
|
//#endregion
|
|
44
52
|
export { useFormatRuleFailure };
|
|
45
53
|
|
package/dist/formatError.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatError.js","names":["_c"],"sources":["../src/formatError.ts"],"sourcesContent":["import type { Field, RuleFailure } from '@panneau/protocol';\nimport { usePanneauIntl } from '@panneau/ui';\n\nimport { messages } from './messages';\nimport { getPathSteps } from './paths';\n\nconst COUNTED = new Set(['repeater', 'relation', 'media', 'select']);\n\n/**\n * Translates the failures of the portable rules with react-intl, for `formatError`. `min` and\n * `max` say \"characters\" for texts and \"items\" for lists, from the field at the path. A rule's own
|
|
1
|
+
{"version":3,"file":"formatError.js","names":["Field","RuleFailure","usePanneauIntl","messages","getPathSteps","COUNTED","Set","useFormatRuleFailure","fields","$","_c","intl","t0","failure","path","message","undefined","step","at","field","value","rule","list","index","has","type","multiple","numeric","key","formatMessage","given","ratios","Array","isArray","filter","_temp","length","cropRatios","formatList","crop","Exclude","invalid","ratio","_c"],"sources":["../src/formatError.ts"],"sourcesContent":["import type { Field, RuleFailure } from '@panneau/protocol';\nimport { usePanneauIntl } from '@panneau/ui';\n\nimport { messages } from './messages';\nimport { getPathSteps } from './paths';\n\nconst COUNTED = new Set(['repeater', 'relation', 'media', 'select']);\n\n/**\n * Translates the failures of the portable rules with react-intl, for `formatError`. `min` and\n * `max` say \"characters\" for texts and \"items\" for lists, from the field at the path, and `crop`\n * names its ratios. A rule's own `message` wins.\n */\nexport function useFormatRuleFailure(\n fields: readonly Field[],\n): (failure: RuleFailure, path: string) => string {\n const intl = usePanneauIntl();\n return (failure, path) => {\n if (failure.message !== undefined) {\n return failure.message;\n }\n const step = getPathSteps(fields, path).at(-1);\n const field = step?.field;\n const value = typeof failure.value === 'number' ? failure.value : 0;\n if (failure.rule === 'min' || failure.rule === 'max') {\n const list =\n field !== undefined &&\n step?.index === undefined &&\n COUNTED.has(field.type) &&\n (field.type === 'repeater' || field.multiple === true);\n const numeric = field?.type === 'number';\n const key = list\n ? failure.rule === 'min'\n ? 'minItems'\n : 'maxItems'\n : numeric\n ? failure.rule\n : failure.rule === 'min'\n ? 'minLength'\n : 'maxLength';\n return intl.formatMessage(messages.rule[key], { value });\n }\n if (failure.rule === 'crop') {\n const given =\n typeof failure.value === 'object' && failure.value !== null\n ? (failure.value as { ratios?: unknown }).ratios\n : undefined;\n const ratios = Array.isArray(given)\n ? given.filter((ratio): ratio is string => typeof ratio === 'string')\n : [];\n return ratios.length > 0\n ? intl.formatMessage(messages.rule.cropRatios, {\n ratios: intl.formatList(ratios, { type: 'disjunction' }),\n })\n : intl.formatMessage(messages.rule.crop);\n }\n const rule = failure.rule as keyof typeof messages.rule;\n if (rule in messages.rule && rule !== 'min' && rule !== 'max') {\n return intl.formatMessage(\n messages.rule[\n rule as Exclude<\n typeof rule,\n | 'min'\n | 'max'\n | 'minLength'\n | 'maxLength'\n | 'minItems'\n | 'maxItems'\n | 'cropRatios'\n >\n ],\n );\n }\n return intl.formatMessage(messages.rule.invalid);\n };\n}\n"],"mappings":";;;;;AAMA,IAAMK,0BAAU,IAAIC,IAAI;CAAC;CAAY;CAAY;CAAS;AAAQ,CAAC;;;;;;AAOnE,SAAOC,qBAAAC,QAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAGH,MAAAC,OAAaT,eAAe;CAAE,IAAAU;CAAA,IAAAH,EAAA,OAAAD,UAAAC,EAAA,OAAAE,MAAA;EACvBC,MAAAC,SAAAC,SAAA;GACH,IAAID,QAAOE,YAAaC,KAAAA,GAAS,OACtBH,QAAOE;GAElB,MAAAE,OAAab,aAAaI,QAAQM,IAAI,CAAC,CAAAI,GAAI,EAAE;GAC7C,MAAAC,QAAcF,MAAIE;GAClB,MAAAC,QAAc,OAAOP,QAAOO,UAAW,WAAWP,QAAOO,QAA3C;GACd,IAAIP,QAAOQ,SAAU,SAASR,QAAOQ,SAAU,OAAK;IAChD,MAAAC,OACIH,UAAUH,KAAAA,KACVC,MAAIM,UAAYP,KAAAA,KAChBX,QAAOmB,IAAKL,MAAKM,IAAK,MACrBN,MAAKM,SAAU,cAAcN,MAAKO,aAAc;IACrD,MAAAC,UAAgBR,OAAKM,SAAW;IAChC,MAAAG,MAAYN,OACNT,QAAOQ,SAAU,QAAjB,aAAA,aAGAM,UACEd,QAAOQ,OACPR,QAAOQ,SAAU,QAAjB,cAAA;IAEc,OACfV,KAAIkB,cAAe1B,SAAQkB,KAAMO,MAAM,EAAAR,MAAQ,CAAC;GAAC;GAE5D,IAAIP,QAAOQ,SAAU,QAAM;IACvB,MAAAS,QACI,OAAOjB,QAAOO,UAAW,YAAYP,QAAOO,UAAW,OAChDP,QAAOO,MAA8BW,SAD5Cf,KAAAA;IAGJ,MAAAe,SAAeC,MAAKC,QAASH,KAEtB,IADDA,MAAKI,OAAQC,KACZ,IAFQ,CAAA;IAEN,OACFJ,OAAMK,SAAU,IACjBzB,KAAIkB,cAAe1B,SAAQkB,KAAKgB,YAAa,EAAAN,QACjCpB,KAAI2B,WAAYP,QAAQ,EAAAN,MAAQ,cAAc,CAAC,EAC3D,CACqC,IAArCd,KAAIkB,cAAe1B,SAAQkB,KAAKkB,IAAK;GAAC;GAEhD,MAAAlB,OAAaR,QAAOQ;GACpB,IAAIA,QAAQlB,SAAQkB,QAASA,SAAS,SAASA,SAAS,OAAK,OAClDV,KAAIkB,cACP1B,SAAQkB,KACJA,KAWR;GACH,OACMV,KAAIkB,cAAe1B,SAAQkB,KAAKoB,OAAQ;EAAC;EACnDhC,EAAA,KAAAD;EAAAC,EAAA,KAAAE;EAAAF,EAAA,KAAAG;CAAA,OAAAA,KAAAH,EAAA;CAAA,OAzDMG;AAyDN;AA7DE,SAAAuB,MAAAO,OAAA;CAAA,OAmCoD,OAAOA,UAAU;AAAQ"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export { ConflictDialog, type ConflictDialogProps } from './ConflictDialog';
|
|
2
|
-
export { describePath } from './describe';
|
|
3
|
-
export { ErrorSummary, type ErrorSummaryProps } from './ErrorSummary';
|
|
4
|
-
export { Form, type FormProps } from './Form';
|
|
5
|
-
export { FormBinding } from './FormBinding';
|
|
6
|
-
export { FormView, type FormViewProps } from './FormView';
|
|
7
|
-
export { useFormContext, useFormState } from './context';
|
|
8
|
-
export { useFormatRuleFailure } from './formatError';
|
|
9
|
-
export { type LeaveConfirmation, useBeforeUnloadGuard, useLeaveConfirmation } from './unsaved';
|
|
1
|
+
export { ConflictDialog, type ConflictDialogProps } from './ConflictDialog.js';
|
|
2
|
+
export { describePath } from './describe.js';
|
|
3
|
+
export { ErrorSummary, type ErrorSummaryProps } from './ErrorSummary.js';
|
|
4
|
+
export { Form, type FormProps } from './Form.js';
|
|
5
|
+
export { FormBinding } from './FormBinding.js';
|
|
6
|
+
export { FormView, type FormViewProps } from './FormView.js';
|
|
7
|
+
export { useFormContext, useFormState } from './context.js';
|
|
8
|
+
export { useFormatRuleFailure } from './formatError.js';
|
|
9
|
+
export { type LeaveConfirmation, useBeforeUnloadGuard, useLeaveConfirmation } from './unsaved.js';
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|