@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/layout/Layout.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { messages } from "../messages.js";
|
|
2
2
|
import Form_module_default from "../Form.module.js";
|
|
3
|
-
import { RevealContext, useFormContext, useFormState } from "../context.js";
|
|
3
|
+
import { ErrorSectionsContext, RevealContext, useFormContext, useFormState } from "../context.js";
|
|
4
|
+
import { cx } from "../cx.js";
|
|
4
5
|
import { c } from "react/compiler-runtime";
|
|
5
6
|
import { getLayoutFieldNames, selectErrorCount, selectVisible, usePlugins } from "@panneau/core";
|
|
6
7
|
import { Badge, Disclosure, Tab, TabList, TabPanel, Tabs, usePanneauIntl } from "@panneau/ui";
|
|
7
8
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
9
|
import { createElement, use, useEffect, useId, useState } from "react";
|
|
9
|
-
import { NestedField } from "@panneau/fields";
|
|
10
|
+
import { NestedField, isWideField } from "@panneau/fields";
|
|
10
11
|
//#region src/layout/Layout.tsx
|
|
11
12
|
/** Whether a path belongs to one of the field names (`title.fr` to `title`). */
|
|
12
13
|
function containsPath(names, path) {
|
|
@@ -108,10 +109,11 @@ function _temp(tab) {
|
|
|
108
109
|
return getLayoutFieldNames(tab.children ?? []);
|
|
109
110
|
}
|
|
110
111
|
function SectionNode(t0) {
|
|
111
|
-
const $ = c(
|
|
112
|
+
const $ = c(38);
|
|
112
113
|
const { node, fields } = t0;
|
|
113
114
|
const form = useFormContext();
|
|
114
115
|
const registry = use(RevealContext);
|
|
116
|
+
const errorSections = use(ErrorSectionsContext);
|
|
115
117
|
const titleId = useId();
|
|
116
118
|
let t1;
|
|
117
119
|
if ($[0] !== node.children) {
|
|
@@ -129,37 +131,50 @@ function SectionNode(t0) {
|
|
|
129
131
|
const [expanded, setExpanded] = useState(node.collapsed !== true);
|
|
130
132
|
let t3;
|
|
131
133
|
let t4;
|
|
132
|
-
if ($[4] !==
|
|
133
|
-
t3 = () =>
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
134
|
+
if ($[4] !== errorSections || $[5] !== names || $[6] !== registry) {
|
|
135
|
+
t3 = () => {
|
|
136
|
+
const open = (path) => {
|
|
137
|
+
if (containsPath(names, path)) setExpanded(true);
|
|
138
|
+
};
|
|
139
|
+
const removeRevealer = registry.add(open);
|
|
140
|
+
const removeOpener = errorSections.add(open);
|
|
141
|
+
return () => {
|
|
142
|
+
removeRevealer();
|
|
143
|
+
removeOpener();
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
t4 = [
|
|
147
|
+
registry,
|
|
148
|
+
errorSections,
|
|
149
|
+
names
|
|
150
|
+
];
|
|
151
|
+
$[4] = errorSections;
|
|
152
|
+
$[5] = names;
|
|
153
|
+
$[6] = registry;
|
|
154
|
+
$[7] = t3;
|
|
155
|
+
$[8] = t4;
|
|
141
156
|
} else {
|
|
142
|
-
t3 = $[
|
|
143
|
-
t4 = $[
|
|
157
|
+
t3 = $[7];
|
|
158
|
+
t4 = $[8];
|
|
144
159
|
}
|
|
145
160
|
useEffect(t3, t4);
|
|
146
161
|
let t5;
|
|
147
|
-
if ($[
|
|
162
|
+
if ($[9] !== node.description) {
|
|
148
163
|
t5 = node.description !== void 0 ? /* @__PURE__ */ jsx("p", {
|
|
149
164
|
className: Form_module_default.sectionDescription,
|
|
150
165
|
children: node.description
|
|
151
166
|
}) : null;
|
|
152
|
-
$[
|
|
153
|
-
$[
|
|
154
|
-
} else t5 = $[
|
|
167
|
+
$[9] = node.description;
|
|
168
|
+
$[10] = t5;
|
|
169
|
+
} else t5 = $[10];
|
|
155
170
|
let t6;
|
|
156
|
-
if ($[
|
|
171
|
+
if ($[11] !== node.children) {
|
|
157
172
|
t6 = node.children ?? [];
|
|
158
|
-
$[
|
|
159
|
-
$[
|
|
160
|
-
} else t6 = $[
|
|
173
|
+
$[11] = node.children;
|
|
174
|
+
$[12] = t6;
|
|
175
|
+
} else t6 = $[12];
|
|
161
176
|
let t7;
|
|
162
|
-
if ($[
|
|
177
|
+
if ($[13] !== fields || $[14] !== t6) {
|
|
163
178
|
t7 = /* @__PURE__ */ jsx("div", {
|
|
164
179
|
className: Form_module_default.stack,
|
|
165
180
|
children: /* @__PURE__ */ jsx(LayoutNodes, {
|
|
@@ -167,40 +182,40 @@ function SectionNode(t0) {
|
|
|
167
182
|
fields
|
|
168
183
|
})
|
|
169
184
|
});
|
|
170
|
-
$[
|
|
171
|
-
$[
|
|
172
|
-
$[
|
|
173
|
-
} else t7 = $[
|
|
185
|
+
$[13] = fields;
|
|
186
|
+
$[14] = t6;
|
|
187
|
+
$[15] = t7;
|
|
188
|
+
} else t7 = $[15];
|
|
174
189
|
let t8;
|
|
175
|
-
if ($[
|
|
190
|
+
if ($[16] !== t5 || $[17] !== t7) {
|
|
176
191
|
t8 = /* @__PURE__ */ jsxs(Fragment, { children: [t5, t7] });
|
|
177
|
-
$[
|
|
178
|
-
$[
|
|
179
|
-
$[
|
|
180
|
-
} else t8 = $[
|
|
192
|
+
$[16] = t5;
|
|
193
|
+
$[17] = t7;
|
|
194
|
+
$[18] = t8;
|
|
195
|
+
} else t8 = $[18];
|
|
181
196
|
const content = t8;
|
|
182
197
|
if (node.collapsible === true) {
|
|
183
198
|
let t9;
|
|
184
|
-
if ($[
|
|
199
|
+
if ($[19] !== form || $[20] !== names) {
|
|
185
200
|
t9 = /* @__PURE__ */ jsx(ErrorBadge, {
|
|
186
201
|
form,
|
|
187
202
|
names
|
|
188
203
|
});
|
|
189
|
-
$[
|
|
190
|
-
$[
|
|
191
|
-
$[
|
|
192
|
-
} else t9 = $[
|
|
204
|
+
$[19] = form;
|
|
205
|
+
$[20] = names;
|
|
206
|
+
$[21] = t9;
|
|
207
|
+
} else t9 = $[21];
|
|
193
208
|
let t10;
|
|
194
|
-
if ($[
|
|
209
|
+
if ($[22] !== content) {
|
|
195
210
|
t10 = /* @__PURE__ */ jsx("div", {
|
|
196
211
|
className: Form_module_default.stack,
|
|
197
212
|
children: content
|
|
198
213
|
});
|
|
199
|
-
$[
|
|
200
|
-
$[
|
|
201
|
-
} else t10 = $[
|
|
214
|
+
$[22] = content;
|
|
215
|
+
$[23] = t10;
|
|
216
|
+
} else t10 = $[23];
|
|
202
217
|
let t11;
|
|
203
|
-
if ($[
|
|
218
|
+
if ($[24] !== expanded || $[25] !== node.label || $[26] !== t10 || $[27] !== t9) {
|
|
204
219
|
t11 = /* @__PURE__ */ jsx("div", {
|
|
205
220
|
className: Form_module_default.section,
|
|
206
221
|
children: /* @__PURE__ */ jsx(Disclosure, {
|
|
@@ -211,17 +226,17 @@ function SectionNode(t0) {
|
|
|
211
226
|
children: t10
|
|
212
227
|
})
|
|
213
228
|
});
|
|
214
|
-
$[
|
|
215
|
-
$[
|
|
216
|
-
$[
|
|
217
|
-
$[
|
|
218
|
-
$[
|
|
219
|
-
} else t11 = $[
|
|
229
|
+
$[24] = expanded;
|
|
230
|
+
$[25] = node.label;
|
|
231
|
+
$[26] = t10;
|
|
232
|
+
$[27] = t9;
|
|
233
|
+
$[28] = t11;
|
|
234
|
+
} else t11 = $[28];
|
|
220
235
|
return t11;
|
|
221
236
|
}
|
|
222
237
|
const t9 = node.label !== void 0 ? titleId : void 0;
|
|
223
238
|
let t10;
|
|
224
|
-
if ($[
|
|
239
|
+
if ($[29] !== form || $[30] !== names || $[31] !== node.label || $[32] !== titleId) {
|
|
225
240
|
t10 = node.label !== void 0 ? /* @__PURE__ */ jsx("div", {
|
|
226
241
|
className: Form_module_default.sectionHeader,
|
|
227
242
|
children: /* @__PURE__ */ jsxs("h3", {
|
|
@@ -237,61 +252,83 @@ function SectionNode(t0) {
|
|
|
237
252
|
]
|
|
238
253
|
})
|
|
239
254
|
}) : null;
|
|
240
|
-
$[
|
|
241
|
-
$[
|
|
242
|
-
$[
|
|
243
|
-
$[
|
|
244
|
-
$[
|
|
245
|
-
} else t10 = $[
|
|
255
|
+
$[29] = form;
|
|
256
|
+
$[30] = names;
|
|
257
|
+
$[31] = node.label;
|
|
258
|
+
$[32] = titleId;
|
|
259
|
+
$[33] = t10;
|
|
260
|
+
} else t10 = $[33];
|
|
246
261
|
let t11;
|
|
247
|
-
if ($[
|
|
262
|
+
if ($[34] !== content || $[35] !== t10 || $[36] !== t9) {
|
|
248
263
|
t11 = /* @__PURE__ */ jsxs("section", {
|
|
249
264
|
className: Form_module_default.section,
|
|
250
265
|
"aria-labelledby": t9,
|
|
251
266
|
children: [t10, content]
|
|
252
267
|
});
|
|
253
|
-
$[
|
|
254
|
-
$[
|
|
255
|
-
$[
|
|
256
|
-
$[
|
|
257
|
-
} else t11 = $[
|
|
268
|
+
$[34] = content;
|
|
269
|
+
$[35] = t10;
|
|
270
|
+
$[36] = t9;
|
|
271
|
+
$[37] = t11;
|
|
272
|
+
} else t11 = $[37];
|
|
258
273
|
return t11;
|
|
259
274
|
}
|
|
275
|
+
/**
|
|
276
|
+
* A `component` node: the plugin's component, with the node's children rendered. Without the
|
|
277
|
+
* plugin, the children show as in a column, so that the fields the node frames stay in the form
|
|
278
|
+
* (decision 0065).
|
|
279
|
+
*/
|
|
260
280
|
function ComponentNode(t0) {
|
|
261
|
-
const $ = c(
|
|
262
|
-
const { node } = t0;
|
|
281
|
+
const $ = c(9);
|
|
282
|
+
const { node, fields } = t0;
|
|
263
283
|
const form = useFormContext();
|
|
264
284
|
const { components } = usePlugins();
|
|
265
285
|
let t1;
|
|
266
286
|
let t2;
|
|
267
|
-
if ($[0] !== components || $[1] !==
|
|
287
|
+
if ($[0] !== components || $[1] !== fields || $[2] !== form || $[3] !== node) {
|
|
268
288
|
t2 = Symbol.for("react.early_return_sentinel");
|
|
269
289
|
bb0: {
|
|
270
290
|
const Component = node.component !== void 0 ? components.get(node.component) : void 0;
|
|
291
|
+
let t3;
|
|
292
|
+
if ($[6] !== fields || $[7] !== node.children) {
|
|
293
|
+
t3 = node.children !== void 0 && node.children.length > 0 ? /* @__PURE__ */ jsx("div", {
|
|
294
|
+
className: Form_module_default.stack,
|
|
295
|
+
children: /* @__PURE__ */ jsx(LayoutNodes, {
|
|
296
|
+
nodes: node.children,
|
|
297
|
+
fields
|
|
298
|
+
})
|
|
299
|
+
}) : null;
|
|
300
|
+
$[6] = fields;
|
|
301
|
+
$[7] = node.children;
|
|
302
|
+
$[8] = t3;
|
|
303
|
+
} else t3 = $[8];
|
|
304
|
+
const children = t3;
|
|
271
305
|
if (Component === void 0) {
|
|
272
|
-
t2 =
|
|
306
|
+
t2 = children;
|
|
273
307
|
break bb0;
|
|
274
308
|
}
|
|
275
309
|
t1 = createElement(Component, {
|
|
276
310
|
...node.props,
|
|
277
311
|
node,
|
|
278
|
-
form
|
|
312
|
+
form,
|
|
313
|
+
fields,
|
|
314
|
+
children
|
|
279
315
|
});
|
|
280
316
|
}
|
|
281
317
|
$[0] = components;
|
|
282
|
-
$[1] =
|
|
283
|
-
$[2] =
|
|
284
|
-
$[3] =
|
|
285
|
-
$[4] =
|
|
318
|
+
$[1] = fields;
|
|
319
|
+
$[2] = form;
|
|
320
|
+
$[3] = node;
|
|
321
|
+
$[4] = t1;
|
|
322
|
+
$[5] = t2;
|
|
286
323
|
} else {
|
|
287
|
-
t1 = $[
|
|
288
|
-
t2 = $[
|
|
324
|
+
t1 = $[4];
|
|
325
|
+
t2 = $[5];
|
|
289
326
|
}
|
|
290
327
|
if (t2 !== Symbol.for("react.early_return_sentinel")) return t2;
|
|
291
328
|
return t1;
|
|
292
329
|
}
|
|
293
330
|
function LayoutNodeView(t0) {
|
|
294
|
-
const $ = c(
|
|
331
|
+
const $ = c(31);
|
|
295
332
|
const { node, fields } = t0;
|
|
296
333
|
const form = useFormContext();
|
|
297
334
|
const state = useFormState(form);
|
|
@@ -398,22 +435,26 @@ function LayoutNodeView(t0) {
|
|
|
398
435
|
}
|
|
399
436
|
case "component": {
|
|
400
437
|
let t1;
|
|
401
|
-
if ($[23] !== node) {
|
|
402
|
-
t1 = /* @__PURE__ */ jsx(ComponentNode, {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
438
|
+
if ($[23] !== fields || $[24] !== node) {
|
|
439
|
+
t1 = /* @__PURE__ */ jsx(ComponentNode, {
|
|
440
|
+
node,
|
|
441
|
+
fields
|
|
442
|
+
});
|
|
443
|
+
$[23] = fields;
|
|
444
|
+
$[24] = node;
|
|
445
|
+
$[25] = t1;
|
|
446
|
+
} else t1 = $[25];
|
|
406
447
|
return t1;
|
|
407
448
|
}
|
|
408
449
|
default: {
|
|
409
450
|
let t1;
|
|
410
|
-
if ($[
|
|
451
|
+
if ($[26] !== node.children) {
|
|
411
452
|
t1 = node.children ?? [];
|
|
412
|
-
$[
|
|
413
|
-
$[
|
|
414
|
-
} else t1 = $[
|
|
453
|
+
$[26] = node.children;
|
|
454
|
+
$[27] = t1;
|
|
455
|
+
} else t1 = $[27];
|
|
415
456
|
let t2;
|
|
416
|
-
if ($[
|
|
457
|
+
if ($[28] !== fields || $[29] !== t1) {
|
|
417
458
|
t2 = /* @__PURE__ */ jsx("div", {
|
|
418
459
|
className: Form_module_default.stack,
|
|
419
460
|
children: /* @__PURE__ */ jsx(LayoutNodes, {
|
|
@@ -421,10 +462,10 @@ function LayoutNodeView(t0) {
|
|
|
421
462
|
fields
|
|
422
463
|
})
|
|
423
464
|
});
|
|
424
|
-
$[
|
|
425
|
-
$[
|
|
426
|
-
$[
|
|
427
|
-
} else t2 = $[
|
|
465
|
+
$[28] = fields;
|
|
466
|
+
$[29] = t1;
|
|
467
|
+
$[30] = t2;
|
|
468
|
+
} else t2 = $[30];
|
|
428
469
|
return t2;
|
|
429
470
|
}
|
|
430
471
|
}
|
|
@@ -436,7 +477,47 @@ function LayoutNodes({ nodes, fields }) {
|
|
|
436
477
|
fields
|
|
437
478
|
}, index));
|
|
438
479
|
}
|
|
480
|
+
/**
|
|
481
|
+
* Fields that the layout doesn't place, in columns: short fields side by side, wide ones
|
|
482
|
+
* (`isWideField()`) on their own row.
|
|
483
|
+
*/
|
|
484
|
+
function FieldFlow(t0) {
|
|
485
|
+
const $ = c(7);
|
|
486
|
+
const { nodes, fields } = t0;
|
|
487
|
+
let t1;
|
|
488
|
+
if ($[0] !== fields || $[1] !== nodes) {
|
|
489
|
+
let t2;
|
|
490
|
+
if ($[3] !== fields) {
|
|
491
|
+
t2 = (node, index) => {
|
|
492
|
+
const field = node.name !== void 0 ? fields.get(node.name) : void 0;
|
|
493
|
+
return /* @__PURE__ */ jsx("div", {
|
|
494
|
+
className: cx(Form_module_default.flowCell, (field === void 0 || isWideField(field)) && Form_module_default.flowWide),
|
|
495
|
+
children: /* @__PURE__ */ jsx(LayoutNodeView, {
|
|
496
|
+
node,
|
|
497
|
+
fields
|
|
498
|
+
})
|
|
499
|
+
}, index);
|
|
500
|
+
};
|
|
501
|
+
$[3] = fields;
|
|
502
|
+
$[4] = t2;
|
|
503
|
+
} else t2 = $[4];
|
|
504
|
+
t1 = nodes.map(t2);
|
|
505
|
+
$[0] = fields;
|
|
506
|
+
$[1] = nodes;
|
|
507
|
+
$[2] = t1;
|
|
508
|
+
} else t1 = $[2];
|
|
509
|
+
let t2;
|
|
510
|
+
if ($[5] !== t1) {
|
|
511
|
+
t2 = /* @__PURE__ */ jsx("div", {
|
|
512
|
+
className: Form_module_default.flow,
|
|
513
|
+
children: t1
|
|
514
|
+
});
|
|
515
|
+
$[5] = t1;
|
|
516
|
+
$[6] = t2;
|
|
517
|
+
} else t2 = $[6];
|
|
518
|
+
return t2;
|
|
519
|
+
}
|
|
439
520
|
//#endregion
|
|
440
|
-
export { LayoutNodes };
|
|
521
|
+
export { FieldFlow, LayoutNodes };
|
|
441
522
|
|
|
442
523
|
//# sourceMappingURL=Layout.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Layout.js","names":["count","index","tab","fields","selected","form","names","content","expanded","setExpanded","titleId","field","child","node","_c","styles","_Fragment"],"sources":["../../src/layout/Layout.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type ReactNode,\n createElement,\n use,\n useEffect,\n useId,\n useState,\n} from 'react';\n\nimport {\n type Form,\n getLayoutFieldNames,\n selectErrorCount,\n selectVisible,\n usePlugins,\n} from '@panneau/core';\nimport { NestedField } from '@panneau/fields';\nimport type { Field, LayoutNode } from '@panneau/protocol';\nimport { Badge, Disclosure, Tab, TabList, TabPanel, Tabs, usePanneauIntl } from '@panneau/ui';\n\nimport styles from '../Form.module.css';\nimport { RevealContext, useFormContext, useFormState } from '../context';\nimport { messages } from '../messages';\n\nexport interface LayoutProps {\n nodes: readonly LayoutNode[];\n fields: ReadonlyMap<string, Field>;\n}\n\n/** Whether a path belongs to one of the field names (`title.fr` to `title`). */\nfunction containsPath(names: readonly string[], path: string): boolean {\n const name = path.split('.')[0];\n return name !== undefined && names.includes(name);\n}\n\nfunction ErrorBadge({ form, names }: { form: Form; names: readonly string[] }) {\n const intl = usePanneauIntl();\n const count = selectErrorCount(useFormState(form), names);\n if (count === 0) {\n return null;\n }\n return (\n <Badge tone=\"danger\" label={intl.formatMessage(messages.errorCount, { count })}>\n {count}\n </Badge>\n );\n}\n\nfunction TabsNode({ node, fields }: { node: LayoutNode; fields: ReadonlyMap<string, Field> }) {\n const form = useFormContext();\n const state = useFormState(form);\n const registry = use(RevealContext);\n const id = useId();\n const tabs = (node.children ?? []).filter(\n (child) => child.type === 'tab' && selectVisible(state, child),\n );\n const names = tabs.map((tab) => getLayoutFieldNames(tab.children ?? []));\n const [selected, setSelected] = useState<string>(`${id}-0`);\n\n useEffect(\n () =>\n registry.add((path) => {\n const index = names.findIndex((tabNames) => containsPath(tabNames, path));\n if (index !== -1) {\n setSelected(`${id}-${index}`);\n }\n }),\n [registry, names, id],\n );\n\n return (\n <Tabs selectedKey={selected} onSelectionChange={(key) => setSelected(String(key))}>\n <TabList aria-label={node.label ?? tabs.map((tab) => tab.label ?? '').join(', ')}>\n {tabs.map((tab, index) => (\n <Tab key={index} id={`${id}-${index}`}>\n {tab.label} <ErrorBadge form={form} names={names[index] ?? []} />\n </Tab>\n ))}\n </TabList>\n {tabs.map((tab, index) => (\n // Panels stay mounted: fields keep their state, and errors can be revealed.\n <TabPanel key={index} id={`${id}-${index}`} shouldForceMount>\n <div className={styles.stack}>\n <LayoutNodes nodes={tab.children ?? []} fields={fields} />\n </div>\n </TabPanel>\n ))}\n </Tabs>\n );\n}\n\nfunction SectionNode({ node, fields }: { node: LayoutNode; fields: ReadonlyMap<string, Field> }) {\n const form = useFormContext();\n const registry = use(RevealContext);\n const titleId = useId();\n const names = getLayoutFieldNames(node.children ?? []);\n const [expanded, setExpanded] = useState(node.collapsed !== true);\n\n useEffect(\n () =>\n registry.add((path) => {\n if (containsPath(names, path)) {\n setExpanded(true);\n }\n }),\n [registry, names],\n );\n\n const content = (\n <>\n {node.description !== undefined ? (\n <p className={styles.sectionDescription}>{node.description}</p>\n ) : null}\n <div className={styles.stack}>\n <LayoutNodes nodes={node.children ?? []} fields={fields} />\n </div>\n </>\n );\n if (node.collapsible === true) {\n return (\n <div className={styles.section}>\n <Disclosure\n title={node.label}\n titleEnd={<ErrorBadge form={form} names={names} />}\n isExpanded={expanded}\n onExpandedChange={setExpanded}\n >\n <div className={styles.stack}>{content}</div>\n </Disclosure>\n </div>\n );\n }\n return (\n <section\n className={styles.section}\n aria-labelledby={node.label !== undefined ? titleId : undefined}\n >\n {node.label !== undefined ? (\n <div className={styles.sectionHeader}>\n <h3 id={titleId} className={styles.sectionTitle}>\n {node.label} <ErrorBadge form={form} names={names} />\n </h3>\n </div>\n ) : null}\n {content}\n </section>\n );\n}\n\nfunction ComponentNode({ node }: { node: LayoutNode }) {\n const form = useFormContext();\n const { components } = usePlugins();\n const Component = node.component !== undefined ? components.get(node.component) : undefined;\n if (Component === undefined) {\n return null;\n }\n // A component of the plugin registry, looked up by name: not created during render.\n return createElement(Component, { ...node.props, node, form });\n}\n\nfunction LayoutNodeView({\n node,\n fields,\n}: {\n node: LayoutNode;\n fields: ReadonlyMap<string, Field>;\n}) {\n const form = useFormContext();\n const state = useFormState(form);\n if (!selectVisible(state, node)) {\n return null;\n }\n switch (node.type) {\n case 'field': {\n const field = node.name !== undefined ? fields.get(node.name) : undefined;\n return field !== undefined ? (\n <NestedField field={field} path={field.name} parentValue={state.values} />\n ) : null;\n }\n case 'row':\n return (\n <div className={styles.row}>\n {(node.children ?? []).map((child, index) => (\n <div\n key={index}\n className={styles.cell}\n style={{ '--panneau-span': child.width ?? 12 } as CSSProperties}\n >\n <LayoutNodeView node={child} fields={fields} />\n </div>\n ))}\n </div>\n );\n case 'tabs':\n return <TabsNode node={node} fields={fields} />;\n case 'section':\n return <SectionNode node={node} fields={fields} />;\n case 'text':\n return <p className={styles.text}>{node.text ?? node.label}</p>;\n case 'component':\n return <ComponentNode node={node} />;\n default:\n // `column`, a `tab` or a `sidebar` out of place, and unknown containers.\n return (\n <div className={styles.stack}>\n <LayoutNodes nodes={node.children ?? []} fields={fields} />\n </div>\n );\n }\n}\n\n/** Renders layout nodes in order. */\nexport function LayoutNodes({ nodes, fields }: LayoutProps): ReactNode {\n return nodes.map((node, index) => <LayoutNodeView key={index} node={node} fields={fields} />);\n}\n"],"mappings":";;;;;;;;;;;AA+BA,SAAS,aAAa,OAA0B,MAAuB;CACnE,MAAM,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC;CAC7B,OAAO,SAAS,KAAA,KAAa,MAAM,SAAS,IAAI;AACpD;AAEA,SAAA,WAAA,IAAA;CAAA,MAAA,IAAAc,EAAA,CAAA;CAAoB,MAAA,EAAA,MAAA,UAAA;CAChB,MAAA,OAAa,eAAe;CAC5B,MAAA,QAAc,iBAAiB,aAAa,IAAI,GAAG,KAAK;CACxD,IAAI,UAAU,GAAC,OACJ;CAGN,MAAA,KAAA;CAAW,MAAA,KAAA;CAAgB,MAAA,KAAA,KAAI,cAAe,SAAQ,YAA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MAAA,KAAA;IAAA,EAAA,MAAA;GAAA,OAAA,KAAA,EAAA;GAAA,IAAA;GAAA,IAAA,EAAA,QAAA,UAAA,EAAA,QAAA,IAAA;IAD3C,KAAA,oBAAA,OAAA;KAAgB,WAAAA,oBAAM;KAClB,UAAA,oBAAC,aAAD;MAAoB,OAAA;MAA6B;KAAM,CAAA;IACrD,CAAA;IAAA,EAAA,MAAA;IAAA,EAAA,MAAA;IAAA,EAAA,MAAA;GAAA,OAAA,KAAA,EAAA;GAAA,OAFN;EAEM;CAElB;AAAC;;AAIL,SAAgB,YAAY,EAAE,OAAO,UAAkC;CACnE,OAAO,MAAM,KAAK,MAAM,UAAU,oBAAC,gBAAD;EAAkC;EAAc;CAAO,GAAlC,KAAkC,CAAG;AAChG"}
|
|
1
|
+
{"version":3,"file":"Layout.js","names":["CSSProperties","ReactNode","createElement","use","useEffect","useId","useState","Form","getLayoutFieldNames","selectErrorCount","selectVisible","usePlugins","NestedField","isWideField","Field","LayoutNode","Badge","Disclosure","Tab","TabList","TabPanel","Tabs","usePanneauIntl","styles","ErrorSectionsContext","RevealContext","useFormContext","useFormState","cx","messages","LayoutProps","nodes","fields","ReadonlyMap","containsPath","names","path","name","split","undefined","includes","ErrorBadge","t0","$","_c","form","intl","count","T0","t1","t2","formatMessage","errorCount","t3","TabsNode","node","state","registry","id","child","type","tabs","children","filter","map","_temp","selected","setSelected","add","index","findIndex","tabNames","Symbol","for","key","String","tab_2","index_1","stack","tab","label","_temp2","join","tab_1","index_0","tab_0","SectionNode","errorSections","titleId","expanded","setExpanded","collapsed","t4","open","removeRevealer","removeOpener","t5","description","sectionDescription","t6","t7","t8","content","collapsible","t9","t10","t11","section","sectionHeader","sectionTitle","LayoutComponentProps","ComponentNode","components","bb0","Component","component","get","length","props","LayoutNodeView","field","values","cell","width","row","text","LayoutNodes","FieldFlow","flowCell","flowWide","flow","_c","styles","_Fragment"],"sources":["../../src/layout/Layout.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type ReactNode,\n createElement,\n use,\n useEffect,\n useId,\n useState,\n} from 'react';\n\nimport {\n type Form,\n getLayoutFieldNames,\n selectErrorCount,\n selectVisible,\n usePlugins,\n} from '@panneau/core';\nimport { NestedField, isWideField } from '@panneau/fields';\nimport type { Field, LayoutNode } from '@panneau/protocol';\nimport { Badge, Disclosure, Tab, TabList, TabPanel, Tabs, usePanneauIntl } from '@panneau/ui';\n\nimport styles from '../Form.module.css';\nimport { ErrorSectionsContext, RevealContext, useFormContext, useFormState } from '../context';\nimport { cx } from '../cx';\nimport { messages } from '../messages';\n\nexport interface LayoutProps {\n nodes: readonly LayoutNode[];\n fields: ReadonlyMap<string, Field>;\n}\n\n/** Whether a path belongs to one of the field names (`title.fr` to `title`). */\nfunction containsPath(names: readonly string[], path: string): boolean {\n const name = path.split('.')[0];\n return name !== undefined && names.includes(name);\n}\n\nfunction ErrorBadge({ form, names }: { form: Form; names: readonly string[] }) {\n const intl = usePanneauIntl();\n const count = selectErrorCount(useFormState(form), names);\n if (count === 0) {\n return null;\n }\n return (\n <Badge tone=\"danger\" label={intl.formatMessage(messages.errorCount, { count })}>\n {count}\n </Badge>\n );\n}\n\nfunction TabsNode({ node, fields }: { node: LayoutNode; fields: ReadonlyMap<string, Field> }) {\n const form = useFormContext();\n const state = useFormState(form);\n const registry = use(RevealContext);\n const id = useId();\n const tabs = (node.children ?? []).filter(\n (child) => child.type === 'tab' && selectVisible(state, child),\n );\n const names = tabs.map((tab) => getLayoutFieldNames(tab.children ?? []));\n const [selected, setSelected] = useState<string>(`${id}-0`);\n\n useEffect(\n () =>\n registry.add((path) => {\n const index = names.findIndex((tabNames) => containsPath(tabNames, path));\n if (index !== -1) {\n setSelected(`${id}-${index}`);\n }\n }),\n [registry, names, id],\n );\n\n return (\n <Tabs selectedKey={selected} onSelectionChange={(key) => setSelected(String(key))}>\n <TabList aria-label={node.label ?? tabs.map((tab) => tab.label ?? '').join(', ')}>\n {tabs.map((tab, index) => (\n <Tab key={index} id={`${id}-${index}`}>\n {tab.label} <ErrorBadge form={form} names={names[index] ?? []} />\n </Tab>\n ))}\n </TabList>\n {tabs.map((tab, index) => (\n // Panels stay mounted: fields keep their state, and errors can be revealed.\n <TabPanel key={index} id={`${id}-${index}`} shouldForceMount>\n <div className={styles.stack}>\n <LayoutNodes nodes={tab.children ?? []} fields={fields} />\n </div>\n </TabPanel>\n ))}\n </Tabs>\n );\n}\n\nfunction SectionNode({ node, fields }: { node: LayoutNode; fields: ReadonlyMap<string, Field> }) {\n const form = useFormContext();\n const registry = use(RevealContext);\n const errorSections = use(ErrorSectionsContext);\n const titleId = useId();\n const names = getLayoutFieldNames(node.children ?? []);\n const [expanded, setExpanded] = useState(node.collapsed !== true);\n\n // Opens to reveal a field, and after a failed save when it holds an error\n useEffect(() => {\n const open = (path: string) => {\n if (containsPath(names, path)) {\n setExpanded(true);\n }\n };\n const removeRevealer = registry.add(open);\n const removeOpener = errorSections.add(open);\n return () => {\n removeRevealer();\n removeOpener();\n };\n }, [registry, errorSections, names]);\n\n const content = (\n <>\n {node.description !== undefined ? (\n <p className={styles.sectionDescription}>{node.description}</p>\n ) : null}\n <div className={styles.stack}>\n <LayoutNodes nodes={node.children ?? []} fields={fields} />\n </div>\n </>\n );\n if (node.collapsible === true) {\n return (\n <div className={styles.section}>\n <Disclosure\n title={node.label}\n titleEnd={<ErrorBadge form={form} names={names} />}\n isExpanded={expanded}\n onExpandedChange={setExpanded}\n >\n <div className={styles.stack}>{content}</div>\n </Disclosure>\n </div>\n );\n }\n return (\n <section\n className={styles.section}\n aria-labelledby={node.label !== undefined ? titleId : undefined}\n >\n {node.label !== undefined ? (\n <div className={styles.sectionHeader}>\n <h3 id={titleId} className={styles.sectionTitle}>\n {node.label} <ErrorBadge form={form} names={names} />\n </h3>\n </div>\n ) : null}\n {content}\n </section>\n );\n}\n\n/** What the component of a `component` node of a form layout gets, with the node's `props`. */\nexport interface LayoutComponentProps {\n node: LayoutNode;\n form: Form;\n /** The fields of the form, by name. */\n fields: ReadonlyMap<string, Field>;\n /** The node's children, rendered: the fields a component frames (decision 0065). */\n children: ReactNode;\n}\n\n/**\n * A `component` node: the plugin's component, with the node's children rendered. Without the\n * plugin, the children show as in a column, so that the fields the node frames stay in the form\n * (decision 0065).\n */\nfunction ComponentNode({ node, fields }: { node: LayoutNode; fields: ReadonlyMap<string, Field> }) {\n const form = useFormContext();\n const { components } = usePlugins();\n const Component = node.component !== undefined ? components.get(node.component) : undefined;\n const children =\n node.children !== undefined && node.children.length > 0 ? (\n <div className={styles.stack}>\n <LayoutNodes nodes={node.children} fields={fields} />\n </div>\n ) : null;\n if (Component === undefined) {\n return children;\n }\n // A component of the plugin registry, looked up by name: not created during render.\n return createElement(Component, { ...node.props, node, form, fields, children });\n}\n\nfunction LayoutNodeView({\n node,\n fields,\n}: {\n node: LayoutNode;\n fields: ReadonlyMap<string, Field>;\n}) {\n const form = useFormContext();\n const state = useFormState(form);\n if (!selectVisible(state, node)) {\n return null;\n }\n switch (node.type) {\n case 'field': {\n const field = node.name !== undefined ? fields.get(node.name) : undefined;\n return field !== undefined ? (\n <NestedField field={field} path={field.name} parentValue={state.values} />\n ) : null;\n }\n case 'row':\n return (\n <div className={styles.row}>\n {(node.children ?? []).map((child, index) => (\n <div\n key={index}\n className={styles.cell}\n style={{ '--panneau-span': child.width ?? 12 } as CSSProperties}\n >\n <LayoutNodeView node={child} fields={fields} />\n </div>\n ))}\n </div>\n );\n case 'tabs':\n return <TabsNode node={node} fields={fields} />;\n case 'section':\n return <SectionNode node={node} fields={fields} />;\n case 'text':\n return <p className={styles.text}>{node.text ?? node.label}</p>;\n case 'component':\n return <ComponentNode node={node} fields={fields} />;\n default:\n // `column`, a `tab` or a `sidebar` out of place, and unknown containers.\n return (\n <div className={styles.stack}>\n <LayoutNodes nodes={node.children ?? []} fields={fields} />\n </div>\n );\n }\n}\n\n/** Renders layout nodes in order. */\nexport function LayoutNodes({ nodes, fields }: LayoutProps): ReactNode {\n return nodes.map((node, index) => <LayoutNodeView key={index} node={node} fields={fields} />);\n}\n\n/**\n * Fields that the layout doesn't place, in columns: short fields side by side, wide ones\n * (`isWideField()`) on their own row.\n */\nexport function FieldFlow({ nodes, fields }: LayoutProps): ReactNode {\n return (\n <div className={styles.flow}>\n {nodes.map((node, index) => {\n const field = node.name !== undefined ? fields.get(node.name) : undefined;\n return (\n <div\n key={index}\n className={cx(\n styles.flowCell,\n (field === undefined || isWideField(field)) && styles.flowWide,\n )}\n >\n <LayoutNodeView node={node} fields={fields} />\n </div>\n );\n })}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAgCA,SAASkC,aAAaC,OAA0BC,MAAuB;CACnE,MAAMC,OAAOD,KAAKE,MAAM,GAAG,CAAC,CAAC;CAC7B,OAAOD,SAASE,KAAAA,KAAaJ,MAAMK,SAASH,IAAI;AACpD;AAEA,SAAAI,WAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAoB,MAAA,EAAAC,MAAAV,UAAAO;CAChB,MAAAI,OAAaxB,eAAe;CAC5B,MAAAyB,QAActC,iBAAiBkB,aAAakB,IAAI,GAAGV,KAAK;CACxD,IAAIY,UAAU,GAAC,OACJ;CAGN,MAAAC,KAAAhC;CAAW,MAAAiC,KAAA;CAAgB,MAAAC,KAAAJ,KAAIK,cAAetB,SAAQuB,YAAa,EAAAL,MAAQ,CAAC;CAAC,IAAAM;CAAA,IAAAV,EAAA,OAAAK,MAAAL,EAAA,OAAAI,SAAAJ,EAAA,OAAAO,IAAA;EAA9EG,KAAA,oBAAC,IAAD;GAAY,MAAAJ;GAAgB,OAAAC;GACvBH,UAAAA;EADC,CAAA;EAEEJ,EAAA,KAAAK;EAAAL,EAAA,KAAAI;EAAAJ,EAAA,KAAAO;EAAAP,EAAA,KAAAU;CAAA,OAAAA,KAAAV,EAAA;CAAA,OAFRU;AAEQ;AAIhB,SAAAC,SAAAZ,IAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAkB,MAAA,EAAAW,MAAAv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AAA,KAAa1B,YAAY2G,KAAK,MAAMjG,oBAAM0G,QACzD;KAEA,UAAA,oBAAC,gBAAD;MAAsB1E;MAAcvB;KAAM,CAAA;IACxC,GAPGqC,KAOH;GAAA;GAEb1B,EAAA,KAAAX;GAAAW,EAAA,KAAAO;EAAA,OAAAA,KAAAP,EAAA;EAbAM,KAAAlB,MAAKiC,IAAKd,EAaV;EAACP,EAAA,KAAAX;EAAAW,EAAA,KAAAZ;EAAAY,EAAA,KAAAM;CAAA,OAAAA,KAAAN,EAAA;CAAA,IAAAO;CAAA,IAAAP,EAAA,OAAAM,IAAA;EAdNC,KAAA,oBAAA,OAAA;GAAgB,WAAA3B,oBAAM2G;GACjBjF,UAAAA;EAcC,CAAA;EAAAN,EAAA,KAAAM;EAAAN,EAAA,KAAAO;CAAA,OAAAA,KAAAP,EAAA;CAAA,OAfNO;AAeM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["allFr"],"sources":["../../src/locales/index.ts"],"sourcesContent":["import { fr as allFr, getDefaultMessages } from '@panneau/intl';\n\nimport { messages } from '../messages';\n\n/**\n * The English messages of `@panneau/forms`, by id. They are also the default messages.\n *\n * @deprecated Use `en`, or `withPanneauMessages()`, from `@panneau/intl`: they have the messages\n * of every package.\n */\nexport const en: Record<string, string> = getDefaultMessages(messages);\n\n/**\n * The French messages of `@panneau/forms`, by id.\n *\n * @deprecated Use `fr`, or `withPanneauMessages()`, from `@panneau/intl`: they have the messages\n * of every package.\n */\nexport const fr: Record<string, string> = Object.fromEntries(\n Object.entries(allFr).filter(([id]) => id in en),\n);\n"],"mappings":";;;;;;;;;AAUA,
|
|
1
|
+
{"version":3,"file":"index.js","names":["fr","allFr","getDefaultMessages","messages","en","Record","Object","fromEntries","entries","filter","id","allFr"],"sources":["../../src/locales/index.ts"],"sourcesContent":["import { fr as allFr, getDefaultMessages } from '@panneau/intl';\n\nimport { messages } from '../messages';\n\n/**\n * The English messages of `@panneau/forms`, by id. They are also the default messages.\n *\n * @deprecated Use `en`, or `withPanneauMessages()`, from `@panneau/intl`: they have the messages\n * of every package.\n */\nexport const en: Record<string, string> = getDefaultMessages(messages);\n\n/**\n * The French messages of `@panneau/forms`, by id.\n *\n * @deprecated Use `fr`, or `withPanneauMessages()`, from `@panneau/intl`: they have the messages\n * of every package.\n */\nexport const fr: Record<string, string> = Object.fromEntries(\n Object.entries(allFr).filter(([id]) => id in en),\n);\n"],"mappings":";;;;;;;;;AAUA,IAAaI,KAA6BF,mBAAmBC,QAAQ;;;;;;;AAQrE,IAAaH,KAA6BM,OAAOC,YAC7CD,OAAOE,QAAQP,IAAK,CAAC,CAACQ,QAAQ,CAACC,QAAQA,MAAMN,EAAE,CACnD"}
|
package/dist/paths.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG/C,4FAA4F;AAC5F,MAAM,WAAW,QAAQ;IACrB,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAMD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,EAAE,CA2B/E;AAED,sDAAsD;AACtD,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,CAExF"}
|
package/dist/paths.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getNestedShape } from "@panneau/protocol/runtime";
|
|
1
2
|
//#region src/paths.ts
|
|
2
3
|
function nested(field) {
|
|
3
4
|
return [...field.fields ?? [], ...(field.types ?? []).flatMap((type) => type.fields)];
|
|
@@ -20,7 +21,7 @@ function getPathSteps(fields, path) {
|
|
|
20
21
|
step.locale = next;
|
|
21
22
|
index += 1;
|
|
22
23
|
}
|
|
23
|
-
if (field
|
|
24
|
+
if (getNestedShape(field) === "repeater" && next !== void 0 && /^\d+$/.test(segments[index + 1] ?? "")) {
|
|
24
25
|
step.index = Number(segments[index + 1]);
|
|
25
26
|
index += 1;
|
|
26
27
|
}
|
package/dist/paths.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.js","names":[],"sources":["../src/paths.ts"],"sourcesContent":["import type { Field } from '@panneau/protocol';\n\n/** A step from a field to the value at a path: the field, and a locale or an item index. */\nexport interface PathStep {\n field: Field;\n locale?: string;\n index?: number;\n}\n\nfunction nested(field: Field): Field[] {\n return [...(field.fields ?? []), ...(field.types ?? []).flatMap((type) => type.fields)];\n}\n\n/**\n * The fields that a dot path goes through (`blocks.2.body.fr`: `blocks`, item 3, `body` in\n * French). Typed blocks are searched in all their types. Returns `[]` for an unknown path.\n */\nexport function getPathSteps(fields: readonly Field[], path: string): PathStep[] {\n const steps: PathStep[] = [];\n const segments = path.split('.');\n let candidates: readonly Field[] = fields;\n for (let index = 0; index < segments.length; index += 1) {\n const field = candidates.find((candidate) => candidate.name === segments[index]);\n if (field === undefined) {\n return [];\n }\n const step: PathStep = { field };\n steps.push(step);\n const next = segments[index + 1];\n if (field.localized === true && next !== undefined) {\n step.locale = next;\n index += 1;\n }\n if (\n field
|
|
1
|
+
{"version":3,"file":"paths.js","names":["Field","getNestedShape","PathStep","field","locale","index","nested","fields","types","flatMap","type","getPathSteps","path","steps","segments","split","candidates","length","find","candidate","name","undefined","step","push","next","localized","test","Number","getFieldAtPath","at"],"sources":["../src/paths.ts"],"sourcesContent":["import type { Field } from '@panneau/protocol';\nimport { getNestedShape } from '@panneau/protocol/runtime';\n\n/** A step from a field to the value at a path: the field, and a locale or an item index. */\nexport interface PathStep {\n field: Field;\n locale?: string;\n index?: number;\n}\n\nfunction nested(field: Field): Field[] {\n return [...(field.fields ?? []), ...(field.types ?? []).flatMap((type) => type.fields)];\n}\n\n/**\n * The fields that a dot path goes through (`blocks.2.body.fr`: `blocks`, item 3, `body` in\n * French). Typed blocks are searched in all their types. Returns `[]` for an unknown path.\n */\nexport function getPathSteps(fields: readonly Field[], path: string): PathStep[] {\n const steps: PathStep[] = [];\n const segments = path.split('.');\n let candidates: readonly Field[] = fields;\n for (let index = 0; index < segments.length; index += 1) {\n const field = candidates.find((candidate) => candidate.name === segments[index]);\n if (field === undefined) {\n return [];\n }\n const step: PathStep = { field };\n steps.push(step);\n const next = segments[index + 1];\n if (field.localized === true && next !== undefined) {\n step.locale = next;\n index += 1;\n }\n if (\n getNestedShape(field) === 'repeater' &&\n next !== undefined &&\n /^\\d+$/.test(segments[index + 1] ?? '')\n ) {\n step.index = Number(segments[index + 1]);\n index += 1;\n }\n candidates = nested(field);\n }\n return steps;\n}\n\n/** The field a path ends on, if the path is known. */\nexport function getFieldAtPath(fields: readonly Field[], path: string): Field | undefined {\n return getPathSteps(fields, path).at(-1)?.field;\n}\n"],"mappings":";;AAUA,SAASM,OAAOH,OAAuB;CACnC,OAAO,CAAC,GAAIA,MAAMI,UAAU,CAAA,GAAK,IAAIJ,MAAMK,SAAS,CAAA,EAAA,CAAIC,SAASC,SAASA,KAAKH,MAAM,CAAC;AAC1F;;;;;AAMA,SAAgBI,aAAaJ,QAA0BK,MAA0B;CAC7E,MAAMC,QAAoB,CAAA;CAC1B,MAAMC,WAAWF,KAAKG,MAAM,GAAG;CAC/B,IAAIC,aAA+BT;CACnC,KAAK,IAAIF,QAAQ,GAAGA,QAAQS,SAASG,QAAQZ,SAAS,GAAG;EACrD,MAAMF,QAAQa,WAAWE,MAAMC,cAAcA,UAAUC,SAASN,SAAST,MAAM;EAC/E,IAAIF,UAAUkB,KAAAA,GACV,OAAO,CAAA;EAEX,MAAMC,OAAiB,EAAEnB,MAAM;EAC/BU,MAAMU,KAAKD,IAAI;EACf,MAAME,OAAOV,SAAST,QAAQ;EAC9B,IAAIF,MAAMsB,cAAc,QAAQD,SAASH,KAAAA,GAAW;GAChDC,KAAKlB,SAASoB;GACdnB,SAAS;EACb;EACA,IACIJ,eAAeE,KAAK,MAAM,cAC1BqB,SAASH,KAAAA,KACT,QAAQK,KAAKZ,SAAST,QAAQ,MAAM,EAAE,GACxC;GACEiB,KAAKjB,QAAQsB,OAAOb,SAAST,QAAQ,EAAE;GACvCA,SAAS;EACb;EACAW,aAAaV,OAAOH,KAAK;CAC7B;CACA,OAAOU;AACX"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { LayoutComponentProps } from '../layout/Layout.js';
|
|
2
|
+
export interface PublicationProps extends LayoutComponentProps {
|
|
3
|
+
/** The field that says whether the item is published, a `boolean`. Defaults to `published`. */
|
|
4
|
+
published?: string;
|
|
5
|
+
/** The field of the publication date, a `date` or a `datetime`. Defaults to `published_at`. */
|
|
6
|
+
publishedAt?: string;
|
|
7
|
+
/** The field of the status, a `select` whose options have tones. Defaults to `status`. */
|
|
8
|
+
status?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The publication of an item (decision 0065): a `component` node of the form layout that frames
|
|
12
|
+
* the fields of its children (whether it is published, its date, its status) under a summary of
|
|
13
|
+
* the state, `Published`, `Scheduled` or `Not published`, with its date. A status with an option
|
|
14
|
+
* gives the state its label and tone. The fields stay at the top of the resource, where lists can
|
|
15
|
+
* filter and sort them.
|
|
16
|
+
*
|
|
17
|
+
* ```jsonc
|
|
18
|
+
* { "type": "component", "component": "publication", "children": [
|
|
19
|
+
* { "type": "field", "name": "published" },
|
|
20
|
+
* { "type": "field", "name": "published_at" },
|
|
21
|
+
* { "type": "field", "name": "status" }
|
|
22
|
+
* ] }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function Publication({ node, form, fields, children, published, publishedAt, status, }: PublicationProps): import("react").JSX.Element;
|
|
26
|
+
/** The `publication` layout component, as a `@panneau/core` plugin. */
|
|
27
|
+
export declare const publicationPlugin: {
|
|
28
|
+
id: string;
|
|
29
|
+
components: {
|
|
30
|
+
publication: typeof Publication;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=Publication.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Publication.d.ts","sourceRoot":"","sources":["../../src/publication/Publication.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAG7D,MAAM,WAAW,gBAAiB,SAAQ,oBAAoB;IAC1D,+FAA+F;IAC/F,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+FAA+F;IAC/F,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0FAA0F;IAC1F,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAiBD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,EACxB,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,SAAuB,EACvB,WAA4B,EAC5B,MAAiB,GACpB,EAAE,gBAAgB,+BA8DlB;AAED,uEAAuE;AACvE,eAAO,MAAM,iBAAiB;;;;;CAG7B,CAAC"}
|