@nivaro/react 0.3.108 → 0.3.109

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.
@@ -1,19 +1,19 @@
1
1
  import { jsxs as s, jsx as l, Fragment as I } from "react/jsx-runtime";
2
- import { useState as B, useEffect as ne } from "react";
3
- import { readGroupStructure as oe } from "../../../lib/form-structure.js";
4
- import { lazySectionsOf as ie, quietHiddenSectionsOf as se, lazySectionPatch as re, quietHiddenSectionPatch as de } from "../../../lib/layout-resolve.js";
2
+ import { useState as B, useEffect as ie } from "react";
3
+ import { readGroupStructure as se } from "../../../lib/form-structure.js";
4
+ import { lazySectionsOf as re, quietHiddenSectionsOf as de, lazySectionPatch as he, quietHiddenSectionPatch as ce } from "../../../lib/layout-resolve.js";
5
5
  import { titleCase as W } from "../../../lib/utils.js";
6
- import { RuleWriter as ce } from "../ai-rules/RuleWriter.js";
6
+ import { RuleWriter as pe } from "../ai-rules/RuleWriter.js";
7
7
  import { RoleConditionRow as U } from "../editors/lock-conditions.js";
8
- import { O2MAggFieldCombobox as he } from "../editors/o2m-agg-field.js";
9
- import { SwapConfigEditor as pe } from "../editors/swap-config.js";
10
- import { IconPicker as fe } from "../pickers/icon-picker.js";
11
- import { SectionReuseActions as ue } from "../reuse/SectionReuseActions.js";
12
- import { emptyTextOp as me, stickyPlan as be, rowUpdatePlan as X } from "../section-structure.js";
13
- import { useCollectionMeta as ye } from "./field-context.js";
14
- import { useInspectorEnv as ge, Setting as d, TextInput as N, Choice as P, Segmented as k, Toggle as y, TextArea as Y, Section as $, FieldMultiPicker as ke, ConditionBuilder as we } from "./kit.js";
15
- import { groupFields as _e, asArray as w, describeField as Z, relKindOf as ve, relatedCollectionOf as xe } from "./model.js";
16
- import { GroupTranslations as Ce } from "./Translations.js";
8
+ import { O2MAggFieldCombobox as fe } from "../editors/o2m-agg-field.js";
9
+ import { SwapConfigEditor as ue } from "../editors/swap-config.js";
10
+ import { IconPicker as me } from "../pickers/icon-picker.js";
11
+ import { SectionReuseActions as be } from "../reuse/SectionReuseActions.js";
12
+ import { emptyTextOp as ye, stickyPlan as ge, rowUpdatePlan as X } from "../section-structure.js";
13
+ import { useCollectionMeta as ke } from "./field-context.js";
14
+ import { useInspectorEnv as we, Setting as d, TextInput as N, Choice as P, Segmented as y, Toggle as g, TextArea as Y, Section as $, FieldMultiPicker as _e, ConditionBuilder as ve } from "./kit.js";
15
+ import { groupFields as xe, asArray as w, describeField as Z, relKindOf as Ce, relatedCollectionOf as Se } from "./model.js";
16
+ import { GroupTranslations as Ne } from "./Translations.js";
17
17
  const T = {
18
18
  section: "Section",
19
19
  tab: "Tab or step",
@@ -21,10 +21,10 @@ const T = {
21
21
  container: "Tabs or steps holder",
22
22
  content: "Text block"
23
23
  };
24
- function Se(t) {
24
+ function $e(t) {
25
25
  return typeof t == "string" ? { field: t } : t && typeof t == "object" && typeof t.field == "string" ? t : null;
26
26
  }
27
- function Ne(t) {
27
+ function Te(t) {
28
28
  const { field: u, label: o, agg: p, agg_field: m, field_options: f } = t;
29
29
  return !o && !p ? u : {
30
30
  field: u,
@@ -33,15 +33,15 @@ function Ne(t) {
33
33
  };
34
34
  }
35
35
  const _ = (t) => t.length ? JSON.stringify(t) : null;
36
- function Je({ group: t, readOnly: u }) {
36
+ function Ke({ group: t, readOnly: u }) {
37
37
  var K, z;
38
- const o = ge(), { data: p } = ye(o.collection), m = (p == null ? void 0 : p.fields) ?? [], f = (p == null ? void 0 : p.relations) ?? [], n = t.label || W(t.key), i = t.type, r = (e, a, c) => o.apply([{ op: "group_update", key: t.key, patch: e }], { label: a, text: c }), L = o.bundle.groups.filter((e) => e.parent_key === t.key), Q = o.bundle.groups.filter((e) => e.type === "container" && e.key !== t.key), F = o.bundle.placements.some((e) => e.group_key === t.key), V = (t.parent_key ? ["tab"] : Object.keys(T)).filter((e) => e === i || !(F && (e === "container" || e === "content"))).map((e) => ({ value: e, label: T[e] })), v = i === "section" || i === "metadata" || i === "tab", R = ie(o.bundle.layout.conditions).includes(t.key), ee = !se(o.bundle.layout.conditions).includes(t.key), M = !!o.bundle.layout.accordion_mode, x = oe(t.swap_config), D = m.filter((e) => !e.field.startsWith("__") && e.type !== "alias").map((e) => ({ value: e.field, label: e.label || W(e.field) })).sort((e, a) => e.label.localeCompare(a.label)), j = _e(o.bundle, t.key), b = w(t.summary_fields).map(Se).filter((e) => !!e), H = (e, a, c) => r({ summary_fields: _(e.map(Ne)) }, a, c), G = w(t.visible_when), C = JSON.stringify(G), [te, J] = B(G);
39
- ne(() => {
38
+ const o = we(), { data: p } = ke(o.collection), m = (p == null ? void 0 : p.fields) ?? [], f = (p == null ? void 0 : p.relations) ?? [], n = t.label || W(t.key), i = t.type, r = (e, a, h) => o.apply([{ op: "group_update", key: t.key, patch: e }], { label: a, text: h }), L = o.bundle.groups.filter((e) => e.parent_key === t.key), Q = o.bundle.groups.filter((e) => e.type === "container" && e.key !== t.key), F = o.bundle.placements.some((e) => e.group_key === t.key), V = (t.parent_key ? ["tab"] : Object.keys(T)).filter((e) => e === i || !(F && (e === "container" || e === "content"))).map((e) => ({ value: e, label: T[e] })), v = i === "section" || i === "metadata" || i === "tab", ee = (i === "section" || i === "metadata") && !t.parent_key, te = o.bundle.groups.some((e) => e.type === "tab" && !e.parent_key), R = re(o.bundle.layout.conditions).includes(t.key), le = !de(o.bundle.layout.conditions).includes(t.key), M = !!o.bundle.layout.accordion_mode, x = se(t.swap_config), D = m.filter((e) => !e.field.startsWith("__") && e.type !== "alias").map((e) => ({ value: e.field, label: e.label || W(e.field) })).sort((e, a) => e.label.localeCompare(a.label)), j = xe(o.bundle, t.key), b = w(t.summary_fields).map($e).filter((e) => !!e), H = (e, a, h) => r({ summary_fields: _(e.map(Te)) }, a, h), G = w(t.visible_when), C = JSON.stringify(G), [ae, J] = B(G);
39
+ ie(() => {
40
40
  J(
41
41
  (e) => JSON.stringify(e.filter((a) => a.field)) === C ? e : JSON.parse(C)
42
42
  );
43
43
  }, [C]);
44
- const [le, q] = B(!1);
44
+ const [ne, q] = B(!1);
45
45
  return /* @__PURE__ */ s("fieldset", { disabled: u, className: "min-w-0 space-y-5", children: [
46
46
  /* @__PURE__ */ l(d, { k: "group.label", label: "Name", effect: "The heading people see.", children: /* @__PURE__ */ l(
47
47
  N,
@@ -52,7 +52,7 @@ function Je({ group: t, readOnly: u }) {
52
52
  }
53
53
  ) }),
54
54
  /* @__PURE__ */ l(d, { k: "group.icon", label: "Icon", effect: "Shown before the section title.", children: /* @__PURE__ */ l(
55
- fe,
55
+ me,
56
56
  {
57
57
  className: "h-8 rounded-md border-slate-200 bg-white px-2.5 text-[13px] hover:bg-white dark:border-border dark:bg-background dark:hover:bg-background",
58
58
  value: t.icon ?? "",
@@ -90,7 +90,7 @@ function Je({ group: t, readOnly: u }) {
90
90
  label: "Show its tabs as",
91
91
  effect: "Steps walk people through in order.",
92
92
  children: /* @__PURE__ */ l(
93
- k,
93
+ y,
94
94
  {
95
95
  value: t.tab_mode === "steps" ? "steps" : "tabs",
96
96
  options: [
@@ -133,7 +133,7 @@ function Je({ group: t, readOnly: u }) {
133
133
  }
134
134
  ),
135
135
  (i === "section" || i === "metadata") && /* @__PURE__ */ l(
136
- y,
136
+ g,
137
137
  {
138
138
  k: "group.is_collapsed",
139
139
  label: "Starts collapsed",
@@ -143,7 +143,7 @@ function Je({ group: t, readOnly: u }) {
143
143
  }
144
144
  ),
145
145
  (i === "section" || i === "metadata") && /* @__PURE__ */ l(
146
- y,
146
+ g,
147
147
  {
148
148
  k: "group.load_on_open",
149
149
  label: "Load when opened",
@@ -154,7 +154,7 @@ function Je({ group: t, readOnly: u }) {
154
154
  [
155
155
  {
156
156
  op: "layout_update",
157
- patch: re(o.bundle.layout.conditions, t.key, e)
157
+ patch: he(o.bundle.layout.conditions, t.key, e)
158
158
  }
159
159
  ],
160
160
  { label: e ? `Load ${n} when opened` : `Load ${n} with the form` }
@@ -169,7 +169,7 @@ function Je({ group: t, readOnly: u }) {
169
169
  label: "Style",
170
170
  effect: "Note and Warning are coloured boxes; Divider is a line with the text.",
171
171
  children: /* @__PURE__ */ l(
172
- k,
172
+ y,
173
173
  {
174
174
  value: t.content_tone ?? "info",
175
175
  options: [
@@ -215,7 +215,7 @@ function Je({ group: t, readOnly: u }) {
215
215
  label: "Intro style",
216
216
  effect: "Note is a quiet box; Warning is amber.",
217
217
  children: /* @__PURE__ */ l(
218
- k,
218
+ y,
219
219
  {
220
220
  value: t.content_tone === "warn" ? "warn" : "info",
221
221
  options: [
@@ -236,7 +236,7 @@ function Je({ group: t, readOnly: u }) {
236
236
  label: "Show",
237
237
  effect: "On new records, existing ones or both.",
238
238
  children: /* @__PURE__ */ l(
239
- k,
239
+ y,
240
240
  {
241
241
  value: t.visibility_mode ?? "always",
242
242
  options: [
@@ -250,7 +250,7 @@ function Je({ group: t, readOnly: u }) {
250
250
  }
251
251
  ),
252
252
  /* @__PURE__ */ l(
253
- y,
253
+ g,
254
254
  {
255
255
  k: "group.hide_when_empty",
256
256
  label: "Hide when all its fields are empty",
@@ -259,6 +259,28 @@ function Je({ group: t, readOnly: u }) {
259
259
  onChange: (e) => r({ hide_when_empty: e }, `Change when ${n} hides`)
260
260
  }
261
261
  ),
262
+ ee && /* @__PURE__ */ l(
263
+ d,
264
+ {
265
+ k: "group.form_width",
266
+ label: "Width on the form",
267
+ effect: te ? "Two half-width sections next to each other share a row. Phones always stack. This form opens on tabs or steps, so its sections do not sit side by side." : "Two half-width sections next to each other share a row. Phones always stack.",
268
+ children: /* @__PURE__ */ l(
269
+ y,
270
+ {
271
+ value: t.form_width === "half" ? "half" : "full",
272
+ options: [
273
+ { value: "full", label: "Full" },
274
+ { value: "half", label: "½" }
275
+ ],
276
+ onChange: (e) => r(
277
+ { form_width: e === "half" ? "half" : null },
278
+ `Change the form width of ${n}`
279
+ )
280
+ }
281
+ )
282
+ }
283
+ ),
262
284
  /* @__PURE__ */ l(
263
285
  d,
264
286
  {
@@ -266,7 +288,7 @@ function Je({ group: t, readOnly: u }) {
266
288
  label: "Width when reading",
267
289
  effect: "On the read view, summary and detail panels. Automatic: half for a short list, full for grids.",
268
290
  children: /* @__PURE__ */ l(
269
- k,
291
+ y,
270
292
  {
271
293
  value: t.read_width ?? "",
272
294
  options: [
@@ -292,7 +314,7 @@ function Je({ group: t, readOnly: u }) {
292
314
  ariaLabel: "When nothing is filled",
293
315
  value: x.emptyText ?? "",
294
316
  placeholder: "No details yet",
295
- onChange: (e) => o.apply([me(t, e)], {
317
+ onChange: (e) => o.apply([ye(t, e)], {
296
318
  label: `Change the empty text of ${n}`,
297
319
  text: !0
298
320
  })
@@ -301,14 +323,14 @@ function Je({ group: t, readOnly: u }) {
301
323
  }
302
324
  ),
303
325
  i === "section" && !t.parent_key && /* @__PURE__ */ l(
304
- y,
326
+ g,
305
327
  {
306
328
  k: "group.sticky",
307
329
  label: "Stick to the top",
308
330
  effect: "Stays at the top of the form while people scroll the rest, for totals or status. One section per form; not on phones.",
309
331
  checked: x.sticky,
310
332
  onChange: (e) => {
311
- const a = be(o.bundle, t.key, e);
333
+ const a = ge(o.bundle, t.key, e);
312
334
  a.ok && o.apply(a.ops, { label: a.label });
313
335
  }
314
336
  }
@@ -328,8 +350,8 @@ function Je({ group: t, readOnly: u }) {
328
350
  ariaLabel: `Label of the row ${e.label}`,
329
351
  value: e.label,
330
352
  onChange: (a) => {
331
- const c = X(o.bundle, t.key, e.key, { label: a });
332
- c.ok && o.apply(c.ops, { label: c.label, text: !0 });
353
+ const h = X(o.bundle, t.key, e.key, { label: a });
354
+ h.ok && o.apply(h.ops, { label: h.label, text: !0 });
333
355
  }
334
356
  }
335
357
  ) }),
@@ -347,10 +369,10 @@ function Je({ group: t, readOnly: u }) {
347
369
  )
348
370
  ] }),
349
371
  /* @__PURE__ */ l("p", { className: "truncate text-[12px] text-slate-500 dark:text-muted-foreground", children: e.fields.map((a) => {
350
- const c = o.bundle.placements.find(
372
+ const h = o.bundle.placements.find(
351
373
  (S) => S.field === a && S.group_key === t.key
352
374
  ) ?? null;
353
- return Z(a, m, f, c).label;
375
+ return Z(a, m, f, h).label;
354
376
  }).join(" · ") })
355
377
  ] }, e.key)) })
356
378
  }
@@ -363,7 +385,7 @@ function Je({ group: t, readOnly: u }) {
363
385
  label: "Skip as the first step when filled",
364
386
  effect: "Opens on a later step when these fields already have values.",
365
387
  children: /* @__PURE__ */ l(
366
- ke,
388
+ _e,
367
389
  {
368
390
  ariaLabel: "Skip as the first step when filled",
369
391
  value: w(t.skip_if_filled),
@@ -381,19 +403,19 @@ function Je({ group: t, readOnly: u }) {
381
403
  effect: "The step shows only while every condition holds. No conditions: always.",
382
404
  children: [
383
405
  /* @__PURE__ */ l(
384
- we,
406
+ ve,
385
407
  {
386
- value: te,
408
+ value: ae,
387
409
  fields: D,
388
410
  onChange: (e) => {
389
411
  J(e);
390
- const a = e.filter((c) => c.field);
412
+ const a = e.filter((h) => h.field);
391
413
  JSON.stringify(a) !== C && r({ visible_when: _(a) }, `Change when ${n} shows`, !0);
392
414
  }
393
415
  }
394
416
  ),
395
417
  /* @__PURE__ */ l(
396
- ce,
418
+ pe,
397
419
  {
398
420
  layoutId: Number(o.bundle.layout.id),
399
421
  target: { kind: "step", group: t.key },
@@ -406,17 +428,17 @@ function Je({ group: t, readOnly: u }) {
406
428
  }
407
429
  ),
408
430
  /* @__PURE__ */ l(
409
- y,
431
+ g,
410
432
  {
411
433
  k: "group.rule_hint",
412
434
  label: "Say why it is hidden",
413
435
  effect: `While its conditions hide it, the form shows one quiet line ("${n} shows when …") with a read-only Show anyway. Off: it vanishes without a word.`,
414
- checked: ee,
436
+ checked: le,
415
437
  onChange: (e) => o.apply(
416
438
  [
417
439
  {
418
440
  op: "layout_update",
419
- patch: de(o.bundle.layout.conditions, t.key, e)
441
+ patch: ce(o.bundle.layout.conditions, t.key, e)
420
442
  }
421
443
  ],
422
444
  { label: e ? `Say why ${n} is hidden` : `Hide ${n} without a word` }
@@ -469,10 +491,10 @@ function Je({ group: t, readOnly: u }) {
469
491
  n,
470
492
  " first."
471
493
  ] }) : /* @__PURE__ */ l("div", { className: "space-y-1.5", children: j.map((e) => {
472
- const a = b.find((h) => h.field === e), c = ve(e, f) === "O2M", S = o.bundle.placements.find((h) => h.field === e) ?? null, O = Z(e, m, f, S).label, E = (h, g, ae) => H(
473
- b.map((A) => A.field === e ? { ...A, ...h } : A),
474
- g,
475
- ae
494
+ const a = b.find((c) => c.field === e), h = Ce(e, f) === "O2M", S = o.bundle.placements.find((c) => c.field === e) ?? null, O = Z(e, m, f, S).label, A = (c, k, oe) => H(
495
+ b.map((E) => E.field === e ? { ...E, ...c } : E),
496
+ k,
497
+ oe
476
498
  );
477
499
  return /* @__PURE__ */ s("div", { className: "space-y-1", children: [
478
500
  /* @__PURE__ */ s("label", { className: "flex items-center gap-2 text-[12px]", children: [
@@ -481,15 +503,15 @@ function Je({ group: t, readOnly: u }) {
481
503
  {
482
504
  type: "checkbox",
483
505
  checked: !!a,
484
- onChange: (h) => H(
485
- h.target.checked ? [...b, c ? { field: e, agg: "count" } : { field: e }] : b.filter((g) => g.field !== e),
506
+ onChange: (c) => H(
507
+ c.target.checked ? [...b, h ? { field: e, agg: "count" } : { field: e }] : b.filter((k) => k.field !== e),
486
508
  `Change the summary of ${n}`
487
509
  ),
488
510
  className: "h-3.5 w-3.5 accent-nvr-cyan"
489
511
  }
490
512
  ),
491
513
  /* @__PURE__ */ l("span", { className: "flex-1 truncate", children: O }),
492
- c && /* @__PURE__ */ l("span", { className: "text-[12px] leading-snug text-slate-500 dark:text-muted-foreground", children: "list" })
514
+ h && /* @__PURE__ */ l("span", { className: "text-[12px] leading-snug text-slate-500 dark:text-muted-foreground", children: "list" })
493
515
  ] }),
494
516
  a && /* @__PURE__ */ s("div", { className: "space-y-1 pl-5", children: [
495
517
  /* @__PURE__ */ l("div", { "data-setting": "group.summary_fields.label", children: /* @__PURE__ */ l(
@@ -498,14 +520,14 @@ function Je({ group: t, readOnly: u }) {
498
520
  ariaLabel: `Label for ${O}`,
499
521
  value: a.label ?? "",
500
522
  placeholder: `Label (${O})`,
501
- onChange: (h) => E(
502
- { label: h || null },
523
+ onChange: (c) => A(
524
+ { label: c || null },
503
525
  `Change the summary of ${n}`,
504
526
  !0
505
527
  )
506
528
  }
507
529
  ) }),
508
- c && /* @__PURE__ */ s("div", { className: "flex gap-1", children: [
530
+ h && /* @__PURE__ */ s("div", { className: "flex gap-1", children: [
509
531
  /* @__PURE__ */ l("div", { className: "flex-1", "data-setting": "group.summary_fields.agg", children: /* @__PURE__ */ l(
510
532
  P,
511
533
  {
@@ -518,8 +540,8 @@ function Je({ group: t, readOnly: u }) {
518
540
  { value: "min", label: "Smallest" },
519
541
  { value: "max", label: "Largest" }
520
542
  ],
521
- onChange: (h) => E(
522
- h === "count" ? { agg: h, agg_field: void 0, field_options: void 0 } : { agg: h },
543
+ onChange: (c) => A(
544
+ c === "count" ? { agg: c, agg_field: void 0, field_options: void 0 } : { agg: c },
523
545
  `Change the summary of ${n}`
524
546
  )
525
547
  }
@@ -530,12 +552,12 @@ function Je({ group: t, readOnly: u }) {
530
552
  className: "flex-1",
531
553
  "data-setting": "group.summary_fields.agg_field",
532
554
  children: /* @__PURE__ */ l(
533
- he,
555
+ fe,
534
556
  {
535
- relatedCollection: xe(e, f),
557
+ relatedCollection: Se(e, f),
536
558
  value: a.agg_field ?? "",
537
- onChange: (h, g) => E(
538
- { agg_field: h, field_options: g },
559
+ onChange: (c, k) => A(
560
+ { agg_field: c, field_options: k },
539
561
  `Change the summary of ${n}`
540
562
  )
541
563
  }
@@ -561,7 +583,7 @@ function Je({ group: t, readOnly: u }) {
561
583
  }
562
584
  ),
563
585
  /* @__PURE__ */ l(
564
- y,
586
+ g,
565
587
  {
566
588
  k: "group.summary_hide_empty",
567
589
  label: "Leave out empty values",
@@ -572,21 +594,21 @@ function Je({ group: t, readOnly: u }) {
572
594
  )
573
595
  ] }),
574
596
  v && /* @__PURE__ */ l(
575
- pe,
597
+ ue,
576
598
  {
577
599
  group: { id: t.id ?? 0, swap_config: t.swap_config },
578
600
  allFields: m.map((e) => ({ field: e.field, type: e.type ?? void 0 })),
579
601
  onGroupSettings: (e, a) => r(a, `Change the field swap of ${n}`)
580
602
  }
581
603
  ),
582
- !u && /* @__PURE__ */ l(ue, { bundle: o.bundle, collection: o.collection, group: t }),
583
- /* @__PURE__ */ l(Ce, { group: t }),
604
+ !u && /* @__PURE__ */ l(be, { bundle: o.bundle, collection: o.collection, group: t }),
605
+ /* @__PURE__ */ l(Ne, { group: t }),
584
606
  /* @__PURE__ */ l(
585
607
  "div",
586
608
  {
587
609
  "data-setting": "group.delete",
588
610
  className: "border-t border-slate-200 pt-3 dark:border-border",
589
- children: le ? /* @__PURE__ */ s("div", { className: "space-y-2 rounded-md border border-red-200 bg-red-50 p-2.5 text-[12px] text-red-900 dark:border-red-800/60 dark:bg-red-950/30 dark:text-red-100", children: [
611
+ children: ne ? /* @__PURE__ */ s("div", { className: "space-y-2 rounded-md border border-red-200 bg-red-50 p-2.5 text-[12px] text-red-900 dark:border-red-800/60 dark:bg-red-950/30 dark:text-red-100", children: [
590
612
  /* @__PURE__ */ s("p", { children: [
591
613
  "Delete ",
592
614
  n,
@@ -633,5 +655,5 @@ function Je({ group: t, readOnly: u }) {
633
655
  ] });
634
656
  }
635
657
  export {
636
- Je as GroupInspector
658
+ Ke as GroupInspector
637
659
  };