@nivaro/react 0.3.73 → 0.3.74

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.
@@ -13,10 +13,10 @@ import { FieldDefaultValueControl as Y } from "../editors/field-default-value.js
13
13
  import { RoleConditionRow as Z, PipelineStateConditionRow as ee } from "../editors/lock-conditions.js";
14
14
  import { useLayoutEditorHost as le } from "../host.js";
15
15
  import { tintCard as te } from "../panel-style.js";
16
- import { RecommendedToggle as ie, PersonalDefaultToggle as oe, PersonalDefaultInlineToggle as ae, ConfirmChangeSetting as ne, RepeatLastToggle as re, FileChipToggles as de } from "./BehaviourSettings.js";
17
- import { useFieldCtx as se } from "./field-context.js";
18
- import { Toggle as v, Setting as p, Segmented as ce, AddButton as ue, Section as S, TextInput as T, Choice as L } from "./kit.js";
19
- import { lockConditionsOf as fe, layoutGrids as pe, asObject as me, defaultValuesOf as he, withDefaultValue as ye, lockConditionsColumn as be } from "./model.js";
16
+ import { RecommendedToggle as ie, PersonalDefaultToggle as oe, PersonalDefaultInlineToggle as ae, ConfirmChangeSetting as ne, RepeatLastToggle as re, FileChipToggles as de, SummaryToggleSetting as se } from "./BehaviourSettings.js";
17
+ import { useFieldCtx as ce } from "./field-context.js";
18
+ import { Toggle as v, Setting as f, Segmented as ue, AddButton as me, Section as T, TextInput as R, Choice as L } from "./kit.js";
19
+ import { lockConditionsOf as fe, layoutGrids as pe, asObject as he, defaultValuesOf as ye, withDefaultValue as ge, lockConditionsColumn as be } from "./model.js";
20
20
  const P = /* @__PURE__ */ new Set([
21
21
  "inline-table",
22
22
  "inline-grid",
@@ -27,33 +27,33 @@ const P = /* @__PURE__ */ new Set([
27
27
  "o2m",
28
28
  "relation-path"
29
29
  ]);
30
- function ge(t, o) {
31
- const f = j();
30
+ function ve(t, o) {
31
+ const m = j();
32
32
  return V({
33
33
  queryKey: ["layout-editor", "field-rows", t, o ?? null],
34
- queryFn: () => f.request(
34
+ queryFn: () => m.request(
35
35
  E(`/field-config/${t}`, o ? { layout_id: o } : void 0)
36
- ).then((m) => Array.isArray(m.data) ? m.data : []),
36
+ ).then((p) => Array.isArray(p.data) ? p.data : []),
37
37
  enabled: !!t,
38
38
  staleTime: 6e4
39
39
  });
40
40
  }
41
- function Be() {
42
- const t = se(), { info: o, ov: f, opts: m, env: s, row: u } = t, a = o.label, y = s.bundle.layout, b = u.field.startsWith("__") || o.isPath, g = fe(u), _ = (e, i) => t.setPlacement({ lock_conditions: be(e) }, i), w = (e, i, n) => _(
43
- g.map((d, h) => h === e ? { ...d, ...i } : d),
41
+ function De() {
42
+ const t = ce(), { info: o, ov: m, opts: p, env: s, row: u } = t, a = o.label, y = s.bundle.layout, g = u.field.startsWith("__") || o.isPath, b = fe(u), _ = (e, i) => t.setPlacement({ lock_conditions: be(e) }, i), w = (e, i, n) => _(
43
+ b.map((d, h) => h === e ? { ...d, ...i } : d),
44
44
  n
45
- ), x = pe(s.bundle, t.globals, t.relations), N = !b && o.relKind !== "M2M" && o.relKind !== "O2M" && !P.has(o.iface ?? "") && x.length > 0, r = me(f.apply_to_lines), $ = x.find((e) => e.field === r.grid) ?? null, { data: F = [] } = ge(N ? $ == null ? void 0 : $.childCollection : null), K = F.filter(
45
+ ), x = pe(s.bundle, t.globals, t.relations), N = !g && o.relKind !== "M2M" && o.relKind !== "O2M" && !P.has(o.iface ?? "") && x.length > 0, r = he(m.apply_to_lines), $ = x.find((e) => e.field === r.grid) ?? null, { data: F = [] } = ve(N ? $ == null ? void 0 : $.childCollection : null), K = F.filter(
46
46
  (e) => e.field !== "id" && !e.field.startsWith("__") && !e.field.includes(".") && !["alias", "o2m", "m2m"].includes(e.type ?? "")
47
- ), M = (e, i) => t.setOverride("apply_to_lines", e ?? void 0, i), I = le().isAdmin && !b && !o.relKind && !P.has(o.iface ?? "") && o.type !== "alias" && o.computedType !== "virtual", O = b ? null : X(t.globals, t.relations, s.collection)[u.field] ?? null, q = he(y), A = typeof m.max_values == "number" ? m.max_values : null;
47
+ ), S = (e, i) => t.setOverride("apply_to_lines", e ?? void 0, i), I = le().isAdmin && !g && !o.relKind && !P.has(o.iface ?? "") && o.type !== "alias" && o.computedType !== "virtual", M = g ? null : X(t.globals, t.relations, s.collection)[u.field] ?? null, q = ye(y), A = typeof p.max_values == "number" ? p.max_values : null;
48
48
  return /* @__PURE__ */ c("div", { className: "space-y-5", children: [
49
- O && /* @__PURE__ */ c(
49
+ M && /* @__PURE__ */ c(
50
50
  "div",
51
51
  {
52
52
  "data-setting": "field.source",
53
53
  className: "rounded-md border border-slate-200 bg-slate-50 p-2.5 dark:border-border dark:bg-muted/40",
54
54
  children: [
55
55
  /* @__PURE__ */ l("p", { className: "mb-1 text-[11px] font-medium uppercase tracking-wide text-slate-400", children: "Where the value comes from" }),
56
- /* @__PURE__ */ l(H, { source: O })
56
+ /* @__PURE__ */ l(H, { source: M })
57
57
  ]
58
58
  }
59
59
  ),
@@ -63,7 +63,7 @@ function Be() {
63
63
  k: "field.required",
64
64
  label: "Required",
65
65
  effect: "The form will not save without a value.",
66
- checked: f.required === !0,
66
+ checked: m.required === !0,
67
67
  onChange: (e) => t.setOverride(
68
68
  "required",
69
69
  e ? !0 : void 0,
@@ -78,7 +78,7 @@ function Be() {
78
78
  k: "field.readonly",
79
79
  label: "Read-only",
80
80
  effect: "Shown but not editable on this form.",
81
- checked: f.readonly === !0,
81
+ checked: m.readonly === !0,
82
82
  onChange: (e) => t.setOverride(
83
83
  "readonly",
84
84
  e ? !0 : void 0,
@@ -91,13 +91,14 @@ function Be() {
91
91
  /* @__PURE__ */ l(ne, {}),
92
92
  /* @__PURE__ */ l(re, {}),
93
93
  /* @__PURE__ */ l(de, {}),
94
+ /* @__PURE__ */ l(se, {}),
94
95
  (o.computedType === "rollup" || o.computedType === "write") && /* @__PURE__ */ l(
95
96
  v,
96
97
  {
97
98
  k: "field.editable_computed",
98
99
  label: "Allow manual entry",
99
100
  effect: "Lets people type over the calculated value here; the next recalculation still overwrites it.",
100
- checked: f.editable_computed === !0,
101
+ checked: m.editable_computed === !0,
101
102
  onChange: (e) => t.setOverride(
102
103
  "editable_computed",
103
104
  e ? !0 : void 0,
@@ -106,20 +107,20 @@ function Be() {
106
107
  }
107
108
  ),
108
109
  /* @__PURE__ */ l(
109
- p,
110
+ f,
110
111
  {
111
112
  k: "field.lock_conditions",
112
113
  label: "Read-only when",
113
114
  effect: "Locks the field while any of these holds. No conditions: always editable.",
114
115
  children: /* @__PURE__ */ c("div", { className: "space-y-2", children: [
115
- g.map((e, i) => /* @__PURE__ */ c(
116
+ b.map((e, i) => /* @__PURE__ */ c(
116
117
  "div",
117
118
  {
118
119
  className: G(te, "space-y-3 p-3"),
119
120
  children: [
120
121
  /* @__PURE__ */ c("div", { className: "flex items-center gap-1.5", children: [
121
122
  /* @__PURE__ */ l("div", { className: "flex-1", "data-setting": "field.lock_conditions.type", children: /* @__PURE__ */ l(
122
- ce,
123
+ ue,
123
124
  {
124
125
  value: e.type,
125
126
  options: [
@@ -127,7 +128,7 @@ function Be() {
127
128
  { value: "role", label: "Role" }
128
129
  ],
129
130
  onChange: (n) => _(
130
- g.map(
131
+ b.map(
131
132
  (d, h) => h === i ? n === "role" ? { type: "role", role_ids: [] } : { type: "pipeline_state", state_keys: [] } : d
132
133
  ),
133
134
  `Change a lock condition of ${a}`
@@ -140,7 +141,7 @@ function Be() {
140
141
  type: "button",
141
142
  "aria-label": "Remove condition",
142
143
  onClick: () => _(
143
- g.filter((n, d) => d !== i),
144
+ b.filter((n, d) => d !== i),
144
145
  `Remove a lock condition from ${a}`
145
146
  ),
146
147
  "data-tip": "Remove condition",
@@ -175,16 +176,16 @@ function Be() {
175
176
  )),
176
177
  /* @__PURE__ */ c("div", { className: "flex flex-wrap items-center gap-1.5", children: [
177
178
  /* @__PURE__ */ l(
178
- ue,
179
+ me,
179
180
  {
180
181
  onClick: () => _(
181
- [...g, { type: "pipeline_state", state_keys: [] }],
182
+ [...b, { type: "pipeline_state", state_keys: [] }],
182
183
  `Add a lock condition to ${a}`
183
184
  ),
184
185
  children: "+ Add condition"
185
186
  }
186
187
  ),
187
- !b && /* @__PURE__ */ l(
188
+ !g && /* @__PURE__ */ l(
188
189
  J,
189
190
  {
190
191
  layoutId: Number(y.id),
@@ -198,8 +199,8 @@ function Be() {
198
199
  ] })
199
200
  }
200
201
  ),
201
- !b && o.relKind !== "O2M" && /* @__PURE__ */ c(
202
- p,
202
+ !g && o.relKind !== "O2M" && /* @__PURE__ */ c(
203
+ f,
203
204
  {
204
205
  k: "field.default_value",
205
206
  label: "Default for new records",
@@ -213,7 +214,7 @@ function Be() {
213
214
  [
214
215
  {
215
216
  op: "layout_update",
216
- patch: { default_values: ye(y, u.field, e) }
217
+ patch: { default_values: ge(y, u.field, e) }
217
218
  }
218
219
  ],
219
220
  { label: `Change the default of ${a}`, text: i }
@@ -237,7 +238,7 @@ function Be() {
237
238
  }
238
239
  ),
239
240
  I && /* @__PURE__ */ l(
240
- p,
241
+ f,
241
242
  {
242
243
  k: "field.validation_rules",
243
244
  label: "Checks",
@@ -250,22 +251,22 @@ function Be() {
250
251
  field: u.field,
251
252
  disabled: t.readOnly,
252
253
  onApply: (e, i, n) => t.proposeGlobal("field.validation_rules", e.length, n, (d) => {
253
- const h = d.columns.validation_rules, R = Array.isArray(h) ? h : i, B = (k, C) => k.type === C.type && String(k.value ?? "") === String(C.value ?? ""), D = e.filter((k) => !R.some((C) => B(C, k)));
254
- return { ...d, columns: { ...d.columns, validation_rules: [...R, ...D] } };
254
+ const h = d.columns.validation_rules, O = Array.isArray(h) ? h : i, B = (k, C) => k.type === C.type && String(k.value ?? "") === String(C.value ?? ""), D = e.filter((k) => !O.some((C) => B(C, k)));
255
+ return { ...d, columns: { ...d.columns, validation_rules: [...O, ...D] } };
255
256
  })
256
257
  }
257
258
  )
258
259
  }
259
260
  ),
260
- o.relKind === "M2M" && /* @__PURE__ */ c(S, { title: "How many", children: [
261
+ o.relKind === "M2M" && /* @__PURE__ */ c(T, { title: "How many", children: [
261
262
  /* @__PURE__ */ l(
262
- p,
263
+ f,
263
264
  {
264
265
  k: "field.max_values",
265
266
  label: "Most values",
266
267
  effect: "Empty: no limit. 1 makes it a single pick.",
267
268
  children: /* @__PURE__ */ l(
268
- T,
269
+ R,
269
270
  {
270
271
  type: "number",
271
272
  ariaLabel: "Most values",
@@ -286,7 +287,7 @@ function Be() {
286
287
  label: "Refuse more on the server too",
287
288
  effect: "Imports, the API and other forms cannot store more than the limit.",
288
289
  enforced: !0,
289
- checked: m.enforce_on_write === !0,
290
+ checked: p.enforce_on_write === !0,
290
291
  onChange: (e) => t.setOption(
291
292
  "enforce_on_write",
292
293
  e ? !0 : void 0,
@@ -295,10 +296,10 @@ function Be() {
295
296
  }
296
297
  )
297
298
  ] }),
298
- N && /* @__PURE__ */ c(S, { title: "Apply to lines", children: [
299
+ N && /* @__PURE__ */ c(T, { title: "Apply to lines", children: [
299
300
  /* @__PURE__ */ l("p", { className: "text-[12px] leading-snug text-slate-500 dark:text-muted-foreground", children: "A button beside the field copies its value into one column of every line of a grid." }),
300
301
  /* @__PURE__ */ l(
301
- p,
302
+ f,
302
303
  {
303
304
  k: "field.apply_to_lines.grid",
304
305
  label: "Grid",
@@ -312,7 +313,7 @@ function Be() {
312
313
  { value: "", label: "Off" },
313
314
  ...x.map((e) => ({ value: e.field, label: e.label }))
314
315
  ],
315
- onChange: (e) => M(
316
+ onChange: (e) => S(
316
317
  e ? { grid: e, target: "", ...r.label ? { label: r.label } : {} } : null,
317
318
  e ? `Copy ${a} into lines` : `Stop copying ${a} into lines`
318
319
  )
@@ -321,7 +322,7 @@ function Be() {
321
322
  }
322
323
  ),
323
324
  /* @__PURE__ */ l(
324
- p,
325
+ f,
325
326
  {
326
327
  k: "field.apply_to_lines.target",
327
328
  label: "Column",
@@ -336,19 +337,19 @@ function Be() {
336
337
  { value: "", label: r.grid ? "Pick a column…" : "Pick a grid first" },
337
338
  ...K.map((e) => ({ value: e.field, label: e.label || Q(e.field) }))
338
339
  ],
339
- onChange: (e) => M({ ...r, target: e }, `Copy ${a} into a column`)
340
+ onChange: (e) => S({ ...r, target: e }, `Copy ${a} into a column`)
340
341
  }
341
342
  )
342
343
  }
343
344
  ),
344
345
  /* @__PURE__ */ l(
345
- p,
346
+ f,
346
347
  {
347
348
  k: "field.apply_to_lines.label",
348
349
  label: "Button label",
349
350
  effect: "The words on the button.",
350
351
  children: /* @__PURE__ */ l(
351
- T,
352
+ R,
352
353
  {
353
354
  ariaLabel: "Button label",
354
355
  disabled: !r.grid,
@@ -374,7 +375,7 @@ function Be() {
374
375
  k: "field.prefill_from_parent",
375
376
  label: "Prefill from the record",
376
377
  effect: "A new addendum starts with the record's current value.",
377
- checked: f.prefill_from_parent !== !1,
378
+ checked: m.prefill_from_parent !== !1,
378
379
  onChange: (e) => t.setOverride(
379
380
  "prefill_from_parent",
380
381
  e ? void 0 : !1,
@@ -385,6 +386,6 @@ function Be() {
385
386
  ] });
386
387
  }
387
388
  export {
388
- Be as RulesTab,
389
- ge as useFieldRows
389
+ De as RulesTab,
390
+ ve as useFieldRows
390
391
  };
@@ -1,38 +1,44 @@
1
- import { useQueryClient as f } from "@tanstack/react-query";
2
- import { useMemo as m } from "react";
3
- import { useOptionalNivaroClient as p } from "../context.js";
4
- import { get as a } from "./commands.js";
5
- const y = "nvr-record-row", d = 1e4;
6
- function R(r) {
1
+ import { useQueryClient as m } from "@tanstack/react-query";
2
+ import { useMemo as d } from "react";
3
+ import { useOptionalNivaroClient as y } from "../context.js";
4
+ import { get as c } from "./commands.js";
5
+ const l = "nvr-record-row", R = 1e4;
6
+ function p(r) {
7
7
  if (r == null) return null;
8
- const e = (Array.isArray(r) ? r : r.split(",")).map((n) => n.trim()).filter(Boolean);
8
+ const e = (Array.isArray(r) ? r : r.split(",")).map((t) => t.trim()).filter(Boolean);
9
9
  return e.length ? e : null;
10
10
  }
11
- async function v(r, e, n, i, s) {
12
- const o = R(s), c = !o || o.every((t) => !t.includes(".") && !t.includes("*"));
13
- if (!e || !c)
11
+ async function v(r, e, t, i, s) {
12
+ const o = p(s), f = !o || o.every((n) => !n.includes(".") && !n.includes("*"));
13
+ if (!e || !f)
14
14
  return r.request(
15
- a(`/items/${n}/${i}`, o ? { fields: o.join(",") } : void 0)
16
- ).then((t) => t.data ?? null);
15
+ c(`/items/${t}/${i}`, o ? { fields: o.join(",") } : void 0)
16
+ ).then((n) => n.data ?? null);
17
17
  const u = await e.fetchQuery({
18
- queryKey: [y, n, String(i)],
19
- queryFn: () => r.request(a(`/items/${n}/${i}`)).then((t) => t.data ?? null),
20
- staleTime: d
18
+ queryKey: [l, t, String(i)],
19
+ queryFn: () => r.request(c(`/items/${t}/${i}`)).then((n) => n.data ?? null),
20
+ staleTime: R
21
21
  });
22
22
  if (!u || !o) return u;
23
- const l = {};
24
- for (const t of ["id", ...o]) t in u && (l[t] = u[t]);
25
- return l;
23
+ const a = {};
24
+ for (const n of ["id", ...o]) n in u && (a[n] = u[n]);
25
+ return a;
26
26
  }
27
- function _() {
28
- const r = p(), e = f();
29
- return m(
30
- () => (n, i, s) => r ? v(r, e, n, i, s) : Promise.resolve(null),
27
+ function O() {
28
+ const r = y(), e = m();
29
+ return d(
30
+ () => (t, i, s) => r ? v(r, e, t, i, s) : Promise.resolve(null),
31
31
  [r, e]
32
32
  );
33
33
  }
34
+ function S(r, e, t) {
35
+ r.invalidateQueries({
36
+ queryKey: t == null ? [l, e] : [l, e, String(t)]
37
+ });
38
+ }
34
39
  export {
35
- y as RECORD_ROW_KEY,
40
+ l as RECORD_ROW_KEY,
41
+ S as invalidateRecordRow,
36
42
  v as readRecordRow,
37
- _ as useRecordReader
43
+ O as useRecordReader
38
44
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nivaro/react",
3
- "version": "0.3.73",
3
+ "version": "0.3.74",
4
4
  "description": "React hooks and components for Nivaro CMS forms",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",