@panneau/forms 5.0.0-alpha.2 → 5.0.0-alpha.20
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 +12 -10
- 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 +55 -2
- 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 +20 -4
- package/dist/Form.module.js.map +1 -1
- package/dist/FormBinding.d.ts.map +1 -1
- package/dist/FormBinding.js +78 -67
- package/dist/FormBinding.js.map +1 -1
- package/dist/FormSkeleton.d.ts +23 -0
- package/dist/FormSkeleton.d.ts.map +1 -0
- package/dist/FormSkeleton.js +438 -0
- package/dist/FormSkeleton.js.map +1 -0
- package/dist/FormView.d.ts +36 -4
- package/dist/FormView.d.ts.map +1 -1
- package/dist/FormView.js +313 -115
- package/dist/FormView.js.map +1 -1
- package/dist/context.d.ts +8 -8
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +8 -16
- 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 +31 -5
- package/dist/formatError.js.map +1 -1
- package/dist/index.d.ts +10 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/layout/Layout.d.ts +15 -0
- package/dist/layout/Layout.d.ts.map +1 -1
- package/dist/layout/Layout.js +169 -88
- package/dist/layout/Layout.js.map +1 -1
- package/dist/locales/index.js.map +1 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +2 -1
- package/dist/paths.js.map +1 -1
- package/dist/publication/Publication.d.ts +33 -0
- package/dist/publication/Publication.d.ts.map +1 -0
- package/dist/publication/Publication.js +218 -0
- package/dist/publication/Publication.js.map +1 -0
- package/dist/publication/index.d.ts +3 -0
- package/dist/publication/index.d.ts.map +1 -0
- package/dist/publication/index.js +1 -0
- package/dist/unsaved.js.map +1 -1
- package/package.json +16 -9
package/dist/FormView.js
CHANGED
|
@@ -2,14 +2,17 @@ import { messages } from "./messages.js";
|
|
|
2
2
|
import { ConflictDialog } from "./ConflictDialog.js";
|
|
3
3
|
import Form_module_default from "./Form.module.js";
|
|
4
4
|
import { ErrorSummary } from "./ErrorSummary.js";
|
|
5
|
-
import { FormContext, RevealContext, createRevealRegistry, useFormState } from "./context.js";
|
|
5
|
+
import { ErrorSectionsContext, FormContext, RevealContext, createRevealRegistry as createRevealRegistry$1, useFormState } from "./context.js";
|
|
6
6
|
import { FormBinding } from "./FormBinding.js";
|
|
7
7
|
import { cx } from "./cx.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
8
|
+
import { FormSkeleton } from "./FormSkeleton.js";
|
|
9
|
+
import { FieldFlow, LayoutNodes } from "./layout/Layout.js";
|
|
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";
|
|
13
|
+
import { Alert, Button, Icon, Tooltip, isApplePlatform, usePanneauIntl, useToast, useToastOffset } from "@panneau/ui";
|
|
14
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
15
|
+
import { CircleCheck } from "lucide-react";
|
|
13
16
|
import { useRef, useState } from "react";
|
|
14
17
|
import { FieldsProvider, builtInFields } from "@panneau/fields";
|
|
15
18
|
//#region src/FormView.tsx
|
|
@@ -26,74 +29,131 @@ function findFieldElement(root, path) {
|
|
|
26
29
|
}
|
|
27
30
|
/**
|
|
28
31
|
* Error paths in the order of their fields: the order of the layout for top-level fields, then
|
|
29
|
-
* the order of the paths inside them (`
|
|
32
|
+
* the order of the paths inside them: locales in their order (`title.fr` before `title.en`), and
|
|
33
|
+
* items by number (`blocks.2.body` before `blocks.10.body`).
|
|
30
34
|
*/
|
|
31
|
-
function orderErrors(names, errors) {
|
|
35
|
+
function orderErrors(names, errors, locales = []) {
|
|
32
36
|
const rank = (path) => {
|
|
33
37
|
const index = names.indexOf(path.split(".")[0] ?? "");
|
|
34
38
|
return index === -1 ? names.length : index;
|
|
35
39
|
};
|
|
36
|
-
const
|
|
40
|
+
const localeRank = (path) => {
|
|
41
|
+
const index = locales.indexOf(path.split(".")[1] ?? "");
|
|
42
|
+
return index === -1 ? locales.length : index;
|
|
43
|
+
};
|
|
44
|
+
const compare = (a, b) => rank(a) - rank(b) || localeRank(a) - localeRank(b) || a.localeCompare(b, void 0, { numeric: true });
|
|
37
45
|
return Object.fromEntries(Object.entries(errors).sort(([a], [b]) => compare(a, b)));
|
|
38
46
|
}
|
|
47
|
+
/** Whether a node is a field that the layout as given doesn't place. */
|
|
48
|
+
function isUnplacedField(node, placed) {
|
|
49
|
+
return node?.type === "field" && node.name !== void 0 && !placed.has(node.name);
|
|
50
|
+
}
|
|
51
|
+
/** Whether a key press saves: ⌘ Enter on Apple platforms, Ctrl Enter elsewhere. */
|
|
52
|
+
function isSaveShortcut(event, apple) {
|
|
53
|
+
return event.key === "Enter" && (apple ? event.metaKey : event.ctrlKey) && !event.altKey && !event.shiftKey && !event.repeat && !event.nativeEvent.isComposing;
|
|
54
|
+
}
|
|
39
55
|
/**
|
|
40
56
|
* Renders a form: its fields in their layout, bound to the form state of `@panneau/core`, with
|
|
41
57
|
* an error summary, a scroll to the first error, error counts on tabs and sections, a guard for
|
|
42
58
|
* unsaved changes and the dialog of version conflicts. Saving is the job of the form's
|
|
43
59
|
* `onSubmit`.
|
|
60
|
+
*
|
|
61
|
+
* ⌘ Enter (Ctrl Enter elsewhere) saves from any of its fields. After a failed save, every
|
|
62
|
+
* collapsed section that holds an error opens, and the first error is focused.
|
|
44
63
|
*/
|
|
45
|
-
function FormView(
|
|
64
|
+
function FormView(t0) {
|
|
65
|
+
const $ = c(49);
|
|
66
|
+
const { form, fields, layout: t1, locales, relationSource, uploadSource, checkSource, components, submitLabel, actions, onSubmitted, onReload, guardUnsavedChanges: t2, showSavedToast: t3, saved: t4, isLoading: t5, id, "aria-label": ariaLabel, className, layoutClassName, sidebarClassName, footerClassName, summaryClassName } = t0;
|
|
67
|
+
const layout = t1 === void 0 ? [] : t1;
|
|
68
|
+
const guardUnsavedChanges = t2 === void 0 ? true : t2;
|
|
69
|
+
const showSavedToast = t3 === void 0 ? true : t3;
|
|
70
|
+
const saved = t4 === void 0 ? false : t4;
|
|
71
|
+
const isLoading = t5 === void 0 ? false : t5;
|
|
46
72
|
const intl = usePanneauIntl();
|
|
47
73
|
const toasts = useToast();
|
|
48
74
|
const { definition } = usePanneau();
|
|
49
75
|
const plugins = usePlugins();
|
|
50
76
|
const state = useFormState(form);
|
|
51
|
-
const [registry] = useState(createRevealRegistry);
|
|
77
|
+
const [registry] = useState(createRevealRegistry$1);
|
|
78
|
+
const [errorSections] = useState(createRevealRegistry$1);
|
|
52
79
|
const [resolving, setResolving] = useState(false);
|
|
53
80
|
const root = useRef(null);
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
81
|
+
const footer = useRef(null);
|
|
82
|
+
const hasFooter = submitLabel !== null || actions !== void 0;
|
|
83
|
+
useToastOffset(footer, hasFooter && !isLoading);
|
|
84
|
+
const [savedShown, setSavedShown] = useState(saved);
|
|
85
|
+
if (savedShown && state.dirty) setSavedShown(false);
|
|
86
|
+
const guarded = guardUnsavedChanges && state.dirty;
|
|
87
|
+
useBeforeUnloadGuard(guarded);
|
|
88
|
+
const leave = useLeaveConfirmation(guarded);
|
|
89
|
+
useLeaveGuard(guarded, leave.confirmLeave);
|
|
90
|
+
const formLocales = locales ?? definition?.locales ?? [];
|
|
91
|
+
const resolved = resolveFields(fields, layout, { mode: form.mode });
|
|
92
|
+
const main = resolved.layout.filter(_temp);
|
|
93
|
+
const placed = new Set(getLayoutFieldNames(layout));
|
|
94
|
+
let split = main.length;
|
|
95
|
+
while (split > 0 && isUnplacedField(main[split - 1], placed)) split = split - 1;
|
|
96
|
+
const flow = main.slice(split);
|
|
97
|
+
const laidOut = main.slice(0, split);
|
|
98
|
+
let t6;
|
|
99
|
+
if ($[0] !== state) {
|
|
100
|
+
t6 = (node_0) => node_0.type === "sidebar" && selectVisible(state, node_0);
|
|
101
|
+
$[0] = state;
|
|
102
|
+
$[1] = t6;
|
|
103
|
+
} else t6 = $[1];
|
|
104
|
+
const sidebar = resolved.layout.filter(t6);
|
|
105
|
+
const order = [...getLayoutFieldNames(main), ...getLayoutFieldNames(sidebar.flatMap(_temp2))];
|
|
106
|
+
let t7;
|
|
107
|
+
if ($[2] !== plugins.fields) {
|
|
108
|
+
t7 = Object.fromEntries(plugins.fields);
|
|
109
|
+
$[2] = plugins.fields;
|
|
110
|
+
$[3] = t7;
|
|
111
|
+
} else t7 = $[3];
|
|
112
|
+
const t8 = t7;
|
|
113
|
+
let t9;
|
|
114
|
+
if ($[4] !== components || $[5] !== t8) {
|
|
115
|
+
t9 = {
|
|
116
|
+
...builtInFields,
|
|
117
|
+
...t8,
|
|
118
|
+
...components
|
|
119
|
+
};
|
|
120
|
+
$[4] = components;
|
|
121
|
+
$[5] = t8;
|
|
122
|
+
$[6] = t9;
|
|
123
|
+
} else t9 = $[6];
|
|
124
|
+
const entries = t9;
|
|
65
125
|
const goTo = (path) => {
|
|
66
126
|
registry.reveal(path);
|
|
67
|
-
|
|
127
|
+
const show = (frames) => {
|
|
68
128
|
const element = root.current !== null ? findFieldElement(root.current, path) : null;
|
|
69
129
|
if (element === null) return;
|
|
130
|
+
if (element.closest("[hidden]") !== null && frames > 0) {
|
|
131
|
+
requestAnimationFrame(() => show(frames - 1));
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
70
134
|
const reduced = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
71
135
|
element.scrollIntoView?.({
|
|
72
136
|
block: "center",
|
|
73
137
|
behavior: reduced ? "auto" : "smooth"
|
|
74
138
|
});
|
|
75
139
|
(element.querySelector("[aria-invalid=\"true\"]") ?? element.querySelector(FOCUSABLE))?.focus({ preventScroll: true });
|
|
76
|
-
}
|
|
140
|
+
};
|
|
141
|
+
requestAnimationFrame(() => show(3));
|
|
77
142
|
};
|
|
78
143
|
const handle = (result) => {
|
|
79
144
|
if (result === null) return;
|
|
80
145
|
if (result.status === "invalid") {
|
|
81
|
-
|
|
146
|
+
Object.keys(result.errors).forEach((path_0) => errorSections.reveal(path_0));
|
|
147
|
+
const first = Object.keys(orderErrors(order, result.errors, formLocales))[0];
|
|
82
148
|
if (first !== void 0) goTo(first);
|
|
83
149
|
} else if (result.status === "submitted") {
|
|
84
|
-
|
|
150
|
+
setSavedShown(true);
|
|
151
|
+
if (showSavedToast && !hasFooter) toasts.show({
|
|
85
152
|
title: intl.formatMessage(messages.saved),
|
|
86
153
|
tone: "success"
|
|
87
|
-
});
|
|
154
|
+
}, { key: "panneau-form-saved" });
|
|
88
155
|
onSubmitted?.(result.result);
|
|
89
|
-
}
|
|
90
|
-
title: intl.formatMessage(messages.saveFailed),
|
|
91
|
-
tone: "danger",
|
|
92
|
-
action: {
|
|
93
|
-
label: intl.formatMessage(messages.retry),
|
|
94
|
-
onAction: () => void form.submit().then(handle)
|
|
95
|
-
}
|
|
96
|
-
}, { timeout: 8e3 });
|
|
156
|
+
}
|
|
97
157
|
};
|
|
98
158
|
const resolve = async (choice) => {
|
|
99
159
|
if (choice === "reload" && state.conflict?.current === null && onReload !== void 0) {
|
|
@@ -101,102 +161,240 @@ function FormView({ form, fields, layout = [], locales, relationSource, componen
|
|
|
101
161
|
return;
|
|
102
162
|
}
|
|
103
163
|
setResolving(true);
|
|
104
|
-
|
|
105
|
-
handle(await form.resolveConflict(choice));
|
|
106
|
-
} finally {
|
|
107
|
-
setResolving(false);
|
|
108
|
-
}
|
|
164
|
+
await form.resolveConflict(choice).then(handle).finally(() => setResolving(false));
|
|
109
165
|
};
|
|
110
|
-
|
|
166
|
+
let t10;
|
|
167
|
+
if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
|
|
168
|
+
t10 = isApplePlatform();
|
|
169
|
+
$[7] = t10;
|
|
170
|
+
} else t10 = $[7];
|
|
171
|
+
const apple = t10;
|
|
172
|
+
let t11;
|
|
173
|
+
if ($[8] !== apple) {
|
|
174
|
+
t11 = (event) => {
|
|
175
|
+
if (!isSaveShortcut(event, apple) || !(event.target instanceof Node) || !event.currentTarget.contains(event.target)) return;
|
|
176
|
+
event.preventDefault();
|
|
177
|
+
event.currentTarget.requestSubmit();
|
|
178
|
+
};
|
|
179
|
+
$[8] = apple;
|
|
180
|
+
$[9] = t11;
|
|
181
|
+
} else t11 = $[9];
|
|
182
|
+
const onKeyDown = t11;
|
|
183
|
+
let t12;
|
|
184
|
+
if ($[10] !== state.error || $[11] !== state.status) {
|
|
185
|
+
t12 = state.status === "error" ? getProblem(state.error) : null;
|
|
186
|
+
$[10] = state.error;
|
|
187
|
+
$[11] = state.status;
|
|
188
|
+
$[12] = t12;
|
|
189
|
+
} else t12 = $[12];
|
|
190
|
+
const problem = t12;
|
|
111
191
|
const errorDetail = problem?.detail ?? (problem === null && state.error instanceof Error ? state.error.message : void 0);
|
|
112
192
|
const showSummary = state.status === "invalid" && state.submitCount > 0;
|
|
193
|
+
if (isLoading) return /* @__PURE__ */ jsx(FormSkeleton, {
|
|
194
|
+
main: laidOut,
|
|
195
|
+
flow,
|
|
196
|
+
sidebar: resolved.layout.filter(_temp3),
|
|
197
|
+
fields: resolved.fieldsByName,
|
|
198
|
+
footer: hasFooter,
|
|
199
|
+
className,
|
|
200
|
+
layoutClassName,
|
|
201
|
+
sidebarClassName,
|
|
202
|
+
footerClassName
|
|
203
|
+
});
|
|
204
|
+
let t13;
|
|
205
|
+
if ($[13] !== relationSource) {
|
|
206
|
+
t13 = relationSource !== void 0 ? { relationSource } : {};
|
|
207
|
+
$[13] = relationSource;
|
|
208
|
+
$[14] = t13;
|
|
209
|
+
} else t13 = $[14];
|
|
210
|
+
let t14;
|
|
211
|
+
if ($[15] !== uploadSource) {
|
|
212
|
+
t14 = uploadSource !== void 0 ? { uploadSource } : {};
|
|
213
|
+
$[15] = uploadSource;
|
|
214
|
+
$[16] = t14;
|
|
215
|
+
} else t14 = $[16];
|
|
216
|
+
let t15;
|
|
217
|
+
if ($[17] !== checkSource) {
|
|
218
|
+
t15 = checkSource !== void 0 ? { checkSource } : {};
|
|
219
|
+
$[17] = checkSource;
|
|
220
|
+
$[18] = t15;
|
|
221
|
+
} else t15 = $[18];
|
|
222
|
+
let t16;
|
|
223
|
+
if ($[19] !== className) {
|
|
224
|
+
t16 = cx(Form_module_default.form, className);
|
|
225
|
+
$[19] = className;
|
|
226
|
+
$[20] = t16;
|
|
227
|
+
} else t16 = $[20];
|
|
228
|
+
let t17;
|
|
229
|
+
if ($[21] !== errorDetail || $[22] !== intl || $[23] !== state.status) {
|
|
230
|
+
t17 = state.status === "error" ? /* @__PURE__ */ jsx(Alert, {
|
|
231
|
+
tone: "danger",
|
|
232
|
+
role: "alert",
|
|
233
|
+
title: intl.formatMessage(messages.saveFailed),
|
|
234
|
+
actions: /* @__PURE__ */ jsx(Button, {
|
|
235
|
+
size: "sm",
|
|
236
|
+
type: "submit",
|
|
237
|
+
children: intl.formatMessage(messages.retry)
|
|
238
|
+
}),
|
|
239
|
+
children: errorDetail
|
|
240
|
+
}) : null;
|
|
241
|
+
$[21] = errorDetail;
|
|
242
|
+
$[22] = intl;
|
|
243
|
+
$[23] = state.status;
|
|
244
|
+
$[24] = t17;
|
|
245
|
+
} else t17 = $[24];
|
|
246
|
+
const t18 = sidebar.length > 0 && Form_module_default.withSidebar;
|
|
247
|
+
let t19;
|
|
248
|
+
if ($[25] !== layoutClassName || $[26] !== t18) {
|
|
249
|
+
t19 = cx(Form_module_default.layout, t18, layoutClassName);
|
|
250
|
+
$[25] = layoutClassName;
|
|
251
|
+
$[26] = t18;
|
|
252
|
+
$[27] = t19;
|
|
253
|
+
} else t19 = $[27];
|
|
254
|
+
let t20;
|
|
255
|
+
if ($[28] !== actions || $[29] !== apple || $[30] !== footerClassName || $[31] !== hasFooter || $[32] !== intl || $[33] !== savedShown || $[34] !== state.dirty || $[35] !== state.status || $[36] !== submitLabel) {
|
|
256
|
+
t20 = hasFooter ? /* @__PURE__ */ jsxs("div", {
|
|
257
|
+
ref: footer,
|
|
258
|
+
className: cx(Form_module_default.footer, footerClassName),
|
|
259
|
+
children: [
|
|
260
|
+
/* @__PURE__ */ jsx("span", {
|
|
261
|
+
className: cx(Form_module_default.status, state.status === "error" && Form_module_default.statusError),
|
|
262
|
+
role: "status",
|
|
263
|
+
children: state.status === "error" ? intl.formatMessage(messages.saveFailed) : state.dirty ? intl.formatMessage(messages.unsaved) : savedShown && state.status !== "submitting" ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Icon, { icon: CircleCheck }), intl.formatMessage(messages.saved)] }) : null
|
|
264
|
+
}),
|
|
265
|
+
actions,
|
|
266
|
+
submitLabel !== null ? /* @__PURE__ */ jsx(Tooltip, {
|
|
267
|
+
content: intl.formatMessage(messages.saveShortcut, { modifier: apple ? "⌘" : "Ctrl" }),
|
|
268
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
269
|
+
type: "submit",
|
|
270
|
+
variant: "primary",
|
|
271
|
+
isPending: state.status === "submitting",
|
|
272
|
+
"aria-keyshortcuts": apple ? "Meta+Enter" : "Control+Enter",
|
|
273
|
+
children: submitLabel ?? intl.formatMessage(messages.save)
|
|
274
|
+
})
|
|
275
|
+
}) : null
|
|
276
|
+
]
|
|
277
|
+
}) : null;
|
|
278
|
+
$[28] = actions;
|
|
279
|
+
$[29] = apple;
|
|
280
|
+
$[30] = footerClassName;
|
|
281
|
+
$[31] = hasFooter;
|
|
282
|
+
$[32] = intl;
|
|
283
|
+
$[33] = savedShown;
|
|
284
|
+
$[34] = state.dirty;
|
|
285
|
+
$[35] = state.status;
|
|
286
|
+
$[36] = submitLabel;
|
|
287
|
+
$[37] = t20;
|
|
288
|
+
} else t20 = $[37];
|
|
289
|
+
const t21 = state.status === "conflict" || resolving;
|
|
290
|
+
const t22 = state.conflict?.current ?? null;
|
|
291
|
+
let t23;
|
|
292
|
+
let t24;
|
|
293
|
+
if ($[38] !== resolve) {
|
|
294
|
+
t23 = () => void resolve("reload");
|
|
295
|
+
t24 = () => void resolve("overwrite");
|
|
296
|
+
$[38] = resolve;
|
|
297
|
+
$[39] = t23;
|
|
298
|
+
$[40] = t24;
|
|
299
|
+
} else {
|
|
300
|
+
t23 = $[39];
|
|
301
|
+
t24 = $[40];
|
|
302
|
+
}
|
|
303
|
+
let t25;
|
|
304
|
+
if ($[41] !== resolved.fields || $[42] !== resolving || $[43] !== state.values || $[44] !== t21 || $[45] !== t22 || $[46] !== t23 || $[47] !== t24) {
|
|
305
|
+
t25 = /* @__PURE__ */ jsx(ConflictDialog, {
|
|
306
|
+
isOpen: t21,
|
|
307
|
+
fields: resolved.fields,
|
|
308
|
+
values: state.values,
|
|
309
|
+
current: t22,
|
|
310
|
+
isPending: resolving,
|
|
311
|
+
onReload: t23,
|
|
312
|
+
onOverwrite: t24
|
|
313
|
+
});
|
|
314
|
+
$[41] = resolved.fields;
|
|
315
|
+
$[42] = resolving;
|
|
316
|
+
$[43] = state.values;
|
|
317
|
+
$[44] = t21;
|
|
318
|
+
$[45] = t22;
|
|
319
|
+
$[46] = t23;
|
|
320
|
+
$[47] = t24;
|
|
321
|
+
$[48] = t25;
|
|
322
|
+
} else t25 = $[48];
|
|
113
323
|
return /* @__PURE__ */ jsx(FormContext, {
|
|
114
324
|
value: form,
|
|
115
325
|
children: /* @__PURE__ */ jsx(RevealContext, {
|
|
116
326
|
value: registry,
|
|
117
|
-
children: /* @__PURE__ */
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
noValidate: true,
|
|
127
|
-
className: cx(Form_module_default.form, className),
|
|
128
|
-
onSubmit: (event) => {
|
|
129
|
-
event.preventDefault();
|
|
130
|
-
form.submit().then(handle);
|
|
131
|
-
},
|
|
327
|
+
children: /* @__PURE__ */ jsx(ErrorSectionsContext, {
|
|
328
|
+
value: errorSections,
|
|
329
|
+
children: /* @__PURE__ */ jsxs(FieldsProvider, {
|
|
330
|
+
components: entries,
|
|
331
|
+
locales: formLocales,
|
|
332
|
+
...t13,
|
|
333
|
+
...t14,
|
|
334
|
+
...t15,
|
|
335
|
+
binding: FormBinding,
|
|
132
336
|
children: [
|
|
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", {
|
|
161
|
-
className: Form_module_default.stack,
|
|
162
|
-
children: /* @__PURE__ */ jsx(LayoutNodes, {
|
|
163
|
-
nodes: node_2.children ?? [],
|
|
164
|
-
fields: resolved.fieldsByName
|
|
165
|
-
})
|
|
166
|
-
}, index))
|
|
167
|
-
}) : null]
|
|
168
|
-
}),
|
|
169
|
-
submitLabel !== null || actions !== void 0 ? /* @__PURE__ */ jsxs("div", {
|
|
170
|
-
className: cx(Form_module_default.footer, footerClassName),
|
|
337
|
+
/* @__PURE__ */ jsxs("form", {
|
|
338
|
+
ref: root,
|
|
339
|
+
id,
|
|
340
|
+
"aria-label": ariaLabel,
|
|
341
|
+
noValidate: true,
|
|
342
|
+
className: t16,
|
|
343
|
+
onSubmit: (event_0) => {
|
|
344
|
+
event_0.preventDefault();
|
|
345
|
+
form.submit().then(handle);
|
|
346
|
+
},
|
|
347
|
+
onKeyDown,
|
|
171
348
|
children: [
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
349
|
+
showSummary ? /* @__PURE__ */ jsx(ErrorSummary, {
|
|
350
|
+
errors: orderErrors(order, state.errors, formLocales),
|
|
351
|
+
fields: resolved.fields,
|
|
352
|
+
onSelect: goTo,
|
|
353
|
+
...summaryClassName !== void 0 ? { className: summaryClassName } : {}
|
|
176
354
|
}) : null,
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
355
|
+
t17,
|
|
356
|
+
/* @__PURE__ */ jsxs("div", {
|
|
357
|
+
className: t19,
|
|
358
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
359
|
+
className: Form_module_default.stack,
|
|
360
|
+
children: [/* @__PURE__ */ jsx(LayoutNodes, {
|
|
361
|
+
nodes: laidOut,
|
|
362
|
+
fields: resolved.fieldsByName
|
|
363
|
+
}), flow.length > 0 ? /* @__PURE__ */ jsx(FieldFlow, {
|
|
364
|
+
nodes: flow,
|
|
365
|
+
fields: resolved.fieldsByName
|
|
366
|
+
}) : null]
|
|
367
|
+
}), sidebar.length > 0 ? /* @__PURE__ */ jsx("aside", {
|
|
368
|
+
className: cx(Form_module_default.sidebar, sidebarClassName),
|
|
369
|
+
children: sidebar.map((node_3, index) => /* @__PURE__ */ jsx("div", {
|
|
370
|
+
className: Form_module_default.stack,
|
|
371
|
+
children: /* @__PURE__ */ jsx(LayoutNodes, {
|
|
372
|
+
nodes: node_3.children ?? [],
|
|
373
|
+
fields: resolved.fieldsByName
|
|
374
|
+
})
|
|
375
|
+
}, index))
|
|
376
|
+
}) : null]
|
|
377
|
+
}),
|
|
378
|
+
t20
|
|
184
379
|
]
|
|
185
|
-
})
|
|
380
|
+
}),
|
|
381
|
+
t25,
|
|
382
|
+
leave.dialog
|
|
186
383
|
]
|
|
187
|
-
})
|
|
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
|
-
})]
|
|
384
|
+
})
|
|
196
385
|
})
|
|
197
386
|
})
|
|
198
387
|
});
|
|
199
388
|
}
|
|
389
|
+
function _temp3(node_2) {
|
|
390
|
+
return node_2.type === "sidebar";
|
|
391
|
+
}
|
|
392
|
+
function _temp2(node_1) {
|
|
393
|
+
return node_1.children ?? [];
|
|
394
|
+
}
|
|
395
|
+
function _temp(node) {
|
|
396
|
+
return node.type !== "sidebar";
|
|
397
|
+
}
|
|
200
398
|
//#endregion
|
|
201
399
|
export { FormView };
|
|
202
400
|
|
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;CA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M,WAAW,cAAc;KACvC,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":["CircleCheck","KeyboardEvent","ReactNode","useRef","useState","Form","SubmitResult","getLayoutFieldNames","getProblem","resolveFields","selectVisible","useLeaveGuard","usePanneau","usePlugins","FieldCheckSource","FieldEntry","FieldsProvider","RelationSource","UploadSource","builtInFields","Field","LayoutNode","Alert","Button","Icon","Tooltip","isApplePlatform","usePanneauIntl","useToast","useToastOffset","ConflictDialog","ErrorSummary","styles","FormBinding","FormSkeleton","ErrorSectionsContext","FormContext","RevealContext","createRevealRegistry","useFormState","cx","FieldFlow","LayoutNodes","messages","useBeforeUnloadGuard","useLeaveConfirmation","FormViewProps","form","fields","layout","locales","relationSource","uploadSource","checkSource","components","Readonly","Record","submitLabel","actions","onSubmitted","result","onReload","guardUnsavedChanges","showSavedToast","saved","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","localeRank","compare","a","b","localeCompare","undefined","numeric","Object","fromEntries","entries","sort","isUnplacedField","node","placed","ReadonlySet","type","name","has","isSaveShortcut","event","apple","key","metaKey","ctrlKey","altKey","shiftKey","repeat","nativeEvent","isComposing","FormView","t0","$","_c","t1","t2","t3","t4","t5","ariaLabel","intl","toasts","definition","plugins","state","registry","errorSections","resolving","setResolving","footer","hasFooter","savedShown","setSavedShown","dirty","guarded","leave","confirmLeave","formLocales","resolved","mode","main","filter","_temp","Set","flow","laidOut","t6","node_0","sidebar","order","flatMap","_temp2","t7","t8","t9","goTo","reveal","show","frames","closest","requestAnimationFrame","reduced","window","matchMedia","matches","scrollIntoView","block","behavior","target","focus","preventScroll","handle","status","keys","forEach","path_0","first","title","formatMessage","tone","resolve","choice","conflict","resolveConflict","then","finally","t10","Symbol","for","t11","Node","currentTarget","contains","preventDefault","requestSubmit","onKeyDown","t12","error","problem","errorDetail","detail","Error","message","showSummary","submitCount","_temp3","fieldsByName","t13","t14","t15","t16","t17","saveFailed","retry","t18","withSidebar","t19","t20","statusError","unsaved","saveShortcut","modifier","save","t21","t22","t23","t24","t25","values","event_0","submit","stack","map","node_3","children","dialog","node_2","node_1","_c","createRevealRegistry","styles","_Fragment"],"sources":["../src/FormView.tsx"],"sourcesContent":["import { CircleCheck } from 'lucide-react';\nimport { type KeyboardEvent, 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 {\n Alert,\n Button,\n Icon,\n Tooltip,\n isApplePlatform,\n usePanneauIntl,\n useToast,\n useToastOffset,\n} 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 {\n ErrorSectionsContext,\n FormContext,\n RevealContext,\n createRevealRegistry,\n useFormState,\n} from './context';\nimport { cx } from './cx';\nimport { FieldFlow, 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 /**\n * Shows \"Saved\" in a toast after a successful submit, when the form has no footer to say it\n * (no submit button and no `actions`). Defaults to true. A form with a footer says \"Saved\" in\n * it, next to its button, where \"Unsaved changes\" was: the page already shows it (decision\n * 0062).\n */\n showSavedToast?: boolean;\n /**\n * The item was saved just before the form started over from it (a new `key` after a save):\n * the footer says \"Saved\" until the values change.\n */\n saved?: 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: locales in their order (`title.fr` before `title.en`), and\n * items by number (`blocks.2.body` before `blocks.10.body`).\n */\nfunction orderErrors(\n names: readonly string[],\n errors: Record<string, string[]>,\n locales: readonly 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 localeRank = (path: string) => {\n const index = locales.indexOf(path.split('.')[1] ?? '');\n return index === -1 ? locales.length : index;\n };\n const compare = (a: string, b: string) =>\n rank(a) - rank(b) ||\n localeRank(a) - localeRank(b) ||\n a.localeCompare(b, undefined, { numeric: true });\n return Object.fromEntries(Object.entries(errors).sort(([a], [b]) => compare(a, b)));\n}\n\n/** Whether a node is a field that the layout as given doesn't place. */\nfunction isUnplacedField(node: LayoutNode | undefined, placed: ReadonlySet<string>): boolean {\n return node?.type === 'field' && node.name !== undefined && !placed.has(node.name);\n}\n\n/** Whether a key press saves: ⌘ Enter on Apple platforms, Ctrl Enter elsewhere. */\nfunction isSaveShortcut(event: KeyboardEvent, apple: boolean): boolean {\n return (\n event.key === 'Enter' &&\n (apple ? event.metaKey : event.ctrlKey) &&\n !event.altKey &&\n !event.shiftKey &&\n !event.repeat &&\n !event.nativeEvent.isComposing\n );\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 *\n * ⌘ Enter (Ctrl Enter elsewhere) saves from any of its fields. After a failed save, every\n * collapsed section that holds an error opens, and the first error is focused.\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 saved = false,\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 [errorSections] = useState(createRevealRegistry);\n const [resolving, setResolving] = useState(false);\n const root = useRef<HTMLFormElement>(null);\n const footer = useRef<HTMLDivElement>(null);\n const hasFooter = submitLabel !== null || actions !== undefined;\n // Toasts rise above the footer, which sticks to the bottom of the page.\n useToastOffset(footer, hasFooter && !isLoading);\n // \"Saved\" in the footer, from the last submit or from before the form started over, until the\n // values change.\n const [savedShown, setSavedShown] = useState(saved);\n if (savedShown && state.dirty) {\n setSavedShown(false);\n }\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 formLocales = locales ?? definition?.locales ?? [];\n const resolved = resolveFields(fields, layout, { mode: form.mode });\n const main = resolved.layout.filter((node) => node.type !== 'sidebar');\n // The fields that the layout doesn't place come last: they flow in columns\n const placed = new Set(getLayoutFieldNames(layout));\n let split = main.length;\n while (split > 0 && isUnplacedField(main[split - 1], placed)) {\n split -= 1;\n }\n const flow = main.slice(split);\n const laidOut = main.slice(0, split);\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, section or locale 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, section or locale to open before scrolling: a few frames at most.\n const show = (frames: number) => {\n const element = root.current !== null ? findFieldElement(root.current, path) : null;\n if (element === null) {\n return;\n }\n if (element.closest('[hidden]') !== null && frames > 0) {\n requestAnimationFrame(() => show(frames - 1));\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 requestAnimationFrame(() => show(3));\n };\n\n const handle = (result: SubmitResult | null) => {\n if (result === null) {\n return;\n }\n if (result.status === 'invalid') {\n // Every collapsed section with an error opens: what is left to fix shows while\n // scrolling down\n Object.keys(result.errors).forEach((path) => errorSections.reveal(path));\n const first = Object.keys(orderErrors(order, result.errors, formLocales))[0];\n if (first !== undefined) {\n goTo(first);\n }\n } else if (result.status === 'submitted') {\n setSavedShown(true);\n if (showSavedToast && !hasFooter) {\n toasts.show(\n { title: intl.formatMessage(messages.saved), tone: 'success' },\n { key: 'panneau-form-saved' },\n );\n }\n onSubmitted?.(result.result);\n }\n // An error shows in the page: its alert, and the footer next to the button.\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 apple = isApplePlatform();\n const onKeyDown = (event: KeyboardEvent<HTMLFormElement>) => {\n // Not `defaultPrevented`: rich text editors prevent the default of every Enter. Keys of\n // what a field opens in a portal, such as a dialog, reach the form through React: they\n // are that dialog's own.\n if (\n !isSaveShortcut(event, apple) ||\n !(event.target instanceof Node) ||\n !event.currentTarget.contains(event.target)\n ) {\n return;\n }\n event.preventDefault();\n event.currentTarget.requestSubmit();\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={laidOut}\n flow={flow}\n sidebar={resolved.layout.filter((node) => node.type === 'sidebar')}\n fields={resolved.fieldsByName}\n footer={hasFooter}\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 <ErrorSectionsContext value={errorSections}>\n <FieldsProvider\n components={entries}\n locales={formLocales}\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 onKeyDown={onKeyDown}\n >\n {showSummary ? (\n <ErrorSummary\n errors={orderErrors(order, state.errors, formLocales)}\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={laidOut} fields={resolved.fieldsByName} />\n {flow.length > 0 ? (\n <FieldFlow nodes={flow} fields={resolved.fieldsByName} />\n ) : null}\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 {hasFooter ? (\n <div ref={footer} className={cx(styles.footer, footerClassName)}>\n <span\n className={cx(\n styles.status,\n state.status === 'error' && styles.statusError,\n )}\n role=\"status\"\n >\n {state.status === 'error' ? (\n intl.formatMessage(messages.saveFailed)\n ) : state.dirty ? (\n intl.formatMessage(messages.unsaved)\n ) : savedShown && state.status !== 'submitting' ? (\n <>\n <Icon icon={CircleCheck} />\n {intl.formatMessage(messages.saved)}\n </>\n ) : null}\n </span>\n {actions}\n {submitLabel !== null ? (\n <Tooltip\n content={intl.formatMessage(messages.saveShortcut, {\n modifier: apple ? '⌘' : 'Ctrl',\n })}\n >\n <Button\n type=\"submit\"\n variant=\"primary\"\n isPending={state.status === 'submitting'}\n aria-keyshortcuts={\n apple ? 'Meta+Enter' : 'Control+Enter'\n }\n >\n {submitLabel ?? intl.formatMessage(messages.save)}\n </Button>\n </Tooltip>\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 </ErrorSectionsContext>\n </RevealContext>\n </FormContext>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqHA,IAAMwE,YACF;;AAGJ,SAASC,iBAAiBC,MAAmBE,MAAkC;CAC3E,IAAIC,UAAUD;CAC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