@nivaro/react 0.3.36 → 0.3.38

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.
Files changed (102) hide show
  1. package/dist/components/slots/CommentsSlot.js +44 -36
  2. package/dist/full.css +1 -1
  3. package/dist/hooks/useSessionRecorder.js +1 -1
  4. package/dist/index.d.ts +9 -1
  5. package/dist/shared/components/AgentBadge.js +26 -0
  6. package/dist/shared/components/AgentQuestionsCard.js +198 -0
  7. package/dist/shared/components/ItemEditForm.js +3329 -3263
  8. package/dist/shared/components/McpConnectionScope.js +480 -0
  9. package/dist/shared/components/MyWorkView.js +223 -208
  10. package/dist/shared/components/RecordReadView.js +620 -575
  11. package/dist/shared/components/chat/ChatPanel.js +683 -671
  12. package/dist/shared/components/imports/DownloadSampleButton.js +69 -0
  13. package/dist/shared/components/imports/ImportConsole.js +106 -104
  14. package/dist/shared/components/imports/RunDetailSheet.js +34 -32
  15. package/dist/shared/components/item-edit/FieldAffordances.js +32 -32
  16. package/dist/shared/components/item-edit/FormTour.js +279 -0
  17. package/dist/shared/components/item-edit/GroupSection.js +377 -360
  18. package/dist/shared/components/item-edit/PersonalDefaultControl.js +28 -28
  19. package/dist/shared/components/item-edit/entry/EntryStrip.js +30 -26
  20. package/dist/shared/components/item-edit/form-density.js +36 -0
  21. package/dist/shared/components/item-edit/useFormUsageBeacon.js +59 -46
  22. package/dist/shared/components/item-edit/usePersonalDefaults.js +312 -296
  23. package/dist/shared/components/layout-editor/AddPanel.js +349 -192
  24. package/dist/shared/components/layout-editor/DesignNode.js +126 -112
  25. package/dist/shared/components/layout-editor/EditorTopBar.js +123 -103
  26. package/dist/shared/components/layout-editor/LayoutEditor.js +829 -751
  27. package/dist/shared/components/layout-editor/PlaceTools.js +334 -0
  28. package/dist/shared/components/layout-editor/SlashInsert.js +252 -0
  29. package/dist/shared/components/layout-editor/StructureMenu.js +285 -242
  30. package/dist/shared/components/layout-editor/add-target.js +54 -43
  31. package/dist/shared/components/layout-editor/ai-forms/AiComposer.js +238 -155
  32. package/dist/shared/components/layout-editor/ai-forms/AiFormsButton.js +1 -1
  33. package/dist/shared/components/layout-editor/ai-forms/ai-forms-api.js +15 -12
  34. package/dist/shared/components/layout-editor/dnd/LayoutDndProvider.js +347 -189
  35. package/dist/shared/components/layout-editor/dnd/TrashZone.js +60 -32
  36. package/dist/shared/components/layout-editor/dnd/UndoChip.js +76 -0
  37. package/dist/shared/components/layout-editor/dnd/merge-drop.js +33 -0
  38. package/dist/shared/components/layout-editor/dnd/multi-drop.js +87 -0
  39. package/dist/shared/components/layout-editor/dnd/node.js +115 -105
  40. package/dist/shared/components/layout-editor/dnd/sensors.js +23 -0
  41. package/dist/shared/components/layout-editor/dnd/trash-drop.js +34 -28
  42. package/dist/shared/components/layout-editor/dnd/trash-links.js +97 -0
  43. package/dist/shared/components/layout-editor/even-row.js +86 -0
  44. package/dist/shared/components/layout-editor/field-list.js +99 -0
  45. package/dist/shared/components/layout-editor/format-painter.js +102 -0
  46. package/dist/shared/components/layout-editor/grid-guides.js +15 -13
  47. package/dist/shared/components/layout-editor/inspector/BehaviourSettings.js +150 -132
  48. package/dist/shared/components/layout-editor/inspector/BulkInspector.js +57 -53
  49. package/dist/shared/components/layout-editor/inspector/EvenRowAction.js +31 -0
  50. package/dist/shared/components/layout-editor/inspector/GroupInspector.js +154 -141
  51. package/dist/shared/components/layout-editor/inspector/Inspector.js +209 -178
  52. package/dist/shared/components/layout-editor/inspector/LookTab.js +106 -98
  53. package/dist/shared/components/layout-editor/inspector/RulesTab.js +38 -37
  54. package/dist/shared/components/layout-editor/inspector/kit.js +280 -223
  55. package/dist/shared/components/layout-editor/keyboard-move.js +15 -15
  56. package/dist/shared/components/layout-editor/lint/LabelStyle.js +201 -0
  57. package/dist/shared/components/layout-editor/lint/LintPanel.js +132 -84
  58. package/dist/shared/components/layout-editor/lint/lint-api.js +65 -28
  59. package/dist/shared/components/layout-editor/nav/NavTools.js +14 -12
  60. package/dist/shared/components/layout-editor/nav/ZoomControls.js +145 -0
  61. package/dist/shared/components/layout-editor/nav/useEditorNav.js +34 -32
  62. package/dist/shared/components/layout-editor/nav/view-prefs.js +100 -15
  63. package/dist/shared/components/layout-editor/outputs/LayoutFile.js +89 -0
  64. package/dist/shared/components/layout-editor/outputs/OutputsButton.js +272 -195
  65. package/dist/shared/components/layout-editor/outputs/layout-file-plan.js +176 -0
  66. package/dist/shared/components/layout-editor/outputs/output-api.js +71 -37
  67. package/dist/shared/components/layout-editor/overview/describe-conditions.js +16 -11
  68. package/dist/shared/components/layout-editor/overview/purpose.js +5 -5
  69. package/dist/shared/components/layout-editor/parity-keys.json.js +1 -1
  70. package/dist/shared/components/layout-editor/pin.js +37 -19
  71. package/dist/shared/components/layout-editor/place-clip.js +257 -0
  72. package/dist/shared/components/layout-editor/preview/PreviewModes.js +27 -26
  73. package/dist/shared/components/layout-editor/preview/PreviewPanes.js +148 -117
  74. package/dist/shared/components/layout-editor/preview/SampleRecord.js +113 -0
  75. package/dist/shared/components/layout-editor/preview/preview-model.js +79 -60
  76. package/dist/shared/components/layout-editor/preview/sample-record.js +105 -0
  77. package/dist/shared/components/layout-editor/removed-log.js +151 -0
  78. package/dist/shared/components/layout-editor/reuse/LibraryRows.js +109 -78
  79. package/dist/shared/components/layout-editor/reuse/linked-sections.js +373 -0
  80. package/dist/shared/components/layout-editor/revert-element.js +140 -0
  81. package/dist/shared/components/layout-editor/section-structure.js +193 -170
  82. package/dist/shared/components/layout-editor/settings/EntrySection.js +63 -45
  83. package/dist/shared/components/layout-editor/settings/LayoutSection.js +63 -32
  84. package/dist/shared/components/layout-editor/settings/ResolveSettings.js +179 -137
  85. package/dist/shared/components/layout-editor/settings/WhoSection.js +18 -17
  86. package/dist/shared/components/layout-editor/settings/settings-registry.js +24 -0
  87. package/dist/shared/components/layout-editor/shortcuts.js +21 -16
  88. package/dist/shared/components/layout-editor/structure-ops.js +221 -195
  89. package/dist/shared/components/layout-editor/usage/UsagePanel.js +133 -85
  90. package/dist/shared/components/layout-editor/usage/refusal-lens.js +130 -0
  91. package/dist/shared/components/layout-editor/usage/usage-api.js +12 -11
  92. package/dist/shared/components/panels/CommentPanel.js +47 -45
  93. package/dist/shared/components/panels/RevisionsPanel.js +66 -64
  94. package/dist/shared/components/panels/TaskPanel.js +395 -332
  95. package/dist/shared/components/profile/AgentsPanel.js +196 -147
  96. package/dist/shared/components/profile/ConnectionRollback.js +329 -0
  97. package/dist/shared/components/profile/MyDefaultsCard.js +526 -520
  98. package/dist/shared/lib/entry-config.js +22 -22
  99. package/dist/shared/lib/form-usage-beacon.js +91 -55
  100. package/dist/shared/lib/layout-lint.js +530 -284
  101. package/dist/shared/lib/layout-resolve.js +58 -44
  102. package/package.json +1 -1
@@ -1,667 +1,673 @@
1
- import { jsxs as p, jsx as n, Fragment as ge } from "react/jsx-runtime";
2
- import { useQueryClient as xe, useQuery as U, useMutation as ae, useQueries as Q } from "@tanstack/react-query";
3
- import { Plus as be, BookmarkCheck as ve, Pencil as ye, UserRoundX as ke, ChevronsUpDown as Ne, Check as ne, X as Ce } from "lucide-react";
4
- import { useState as w, useMemo as S, useRef as V, useEffect as le } from "react";
5
- import { toast as B } from "sonner";
6
- import { useNivaroClient as X, useItemEditAuth as Se, ParentDraftContext as we } from "../../context.js";
7
- import { get as T, del as qe, put as Pe } from "../../lib/commands.js";
8
- import { isEmptyValue as M, cascadeParents as Te } from "../../lib/personal-defaults.js";
9
- import { userErrorMessage as Ee } from "../../lib/safe-error.js";
10
- import { titleCase as _, cn as R, formatDate as Fe } from "../../lib/utils.js";
11
- import { FieldRenderer as $e } from "../item-edit/FieldRenderer.js";
12
- import { getCascadeFilters as re, buildCascadeFilter as Me } from "../item-edit/helpers.js";
13
- import { M2MStagingContext as _e } from "../item-edit/M2MStagingContext.js";
14
- import { PERSONAL_DEFAULT_GHOST_BUTTON as De } from "../item-edit/PersonalDefaultPill.js";
15
- import { pickedCollection as Ae } from "../item-edit/personal-default-checks.js";
16
- import { personalDefaultsKey as Ke } from "../item-edit/usePersonalDefaults.js";
17
- import { Command as Le, CommandInput as Ue, CommandList as Re, CommandEmpty as je, CommandGroup as Ie, CommandItem as Oe } from "../ui/command.js";
18
- import { Popover as Qe, PopoverTrigger as Ve, PopoverContent as Be } from "../ui/popover.js";
19
- import { Skeleton as D } from "../ui/skeleton.js";
20
- import { describeValue as J, loadDefaultLabels as Xe, labelKey as ze } from "./my-defaults-labels.js";
21
- import { SectionCard as Ge, EmptyLine as He, Pill as Ye, ConfirmButton as Je } from "./primitives.js";
22
- const W = { fields: [], relations: [], label: "", ready: !1 };
23
- function We(a) {
24
- const e = X(), t = Q({
25
- queries: a.map((s) => ({
26
- queryKey: ["field-config", s, null],
27
- queryFn: () => e.request(T(`/field-config/${s}`)).then((d) => d.data ?? []),
1
+ import { jsxs as o, jsx as s, Fragment as fe } from "react/jsx-runtime";
2
+ import { useQueryClient as me, useQuery as I, useMutation as te, useQueries as O } from "@tanstack/react-query";
3
+ import { BookmarkCheck as pe, Pencil as xe, UserRoundX as he, Plus as ge, X as ye, Check as be } from "lucide-react";
4
+ import { useMemo as E, useState as _, useRef as D, useEffect as X } from "react";
5
+ import { toast as V } from "sonner";
6
+ import { useNivaroClient as z, useItemEditAuth as ve, ParentDraftContext as Ne } from "../../context.js";
7
+ import { get as M, del as ke, put as we } from "../../lib/commands.js";
8
+ import { isEmptyValue as K, cascadeParents as Se } from "../../lib/personal-defaults.js";
9
+ import { userErrorMessage as Ce } from "../../lib/safe-error.js";
10
+ import { titleCase as H, cn as $, formatDate as qe } from "../../lib/utils.js";
11
+ import { FieldRenderer as Pe } from "../item-edit/FieldRenderer.js";
12
+ import { getCascadeFilters as ae, buildCascadeFilter as Te } from "../item-edit/helpers.js";
13
+ import { M2MStagingContext as Ee } from "../item-edit/M2MStagingContext.js";
14
+ import { PERSONAL_DEFAULT_GHOST_BUTTON as Y } from "../item-edit/PersonalDefaultPill.js";
15
+ import { pickedCollection as Fe } from "../item-edit/personal-default-checks.js";
16
+ import { personalDefaultsKey as Me } from "../item-edit/usePersonalDefaults.js";
17
+ import { Skeleton as U } from "../ui/skeleton.js";
18
+ import { describeValue as W, loadDefaultLabels as $e, labelKey as _e } from "./my-defaults-labels.js";
19
+ import { SectionCard as De, EmptyLine as Ke, Pill as Re, ConfirmButton as Le } from "./primitives.js";
20
+ const B = { fields: [], relations: [], label: "", ready: !1 };
21
+ function Ue(a) {
22
+ const e = z(), n = O({
23
+ queries: a.map((l) => ({
24
+ queryKey: ["field-config", l, null],
25
+ queryFn: () => e.request(M(`/field-config/${l}`)).then((c) => c.data ?? []),
28
26
  staleTime: 6e4
29
27
  }))
30
- }), o = Q({
31
- queries: a.map((s) => ({
32
- queryKey: ["relations", s],
33
- queryFn: () => e.request(T(`/data-model/relations/for/${s}`)).then((d) => d.data ?? []),
28
+ }), i = O({
29
+ queries: a.map((l) => ({
30
+ queryKey: ["relations", l],
31
+ queryFn: () => e.request(M(`/data-model/relations/for/${l}`)).then((c) => c.data ?? []),
34
32
  staleTime: 6e4
35
33
  }))
36
- }), u = Q({
37
- queries: a.map((s) => ({
38
- queryKey: ["col-meta", s],
39
- queryFn: () => e.request(T(`/collections/${s}`)).then((d) => d.data ?? null),
34
+ }), f = O({
35
+ queries: a.map((l) => ({
36
+ queryKey: ["col-meta", l],
37
+ queryFn: () => e.request(M(`/collections/${l}`)).then((c) => c.data ?? null),
40
38
  staleTime: 6e4
41
39
  }))
42
- }), i = /* @__PURE__ */ new Map();
43
- return a.forEach((s, d) => {
44
- var x, c, b, y, f, v;
45
- const m = (c = (x = u[d]) == null ? void 0 : x.data) == null ? void 0 : c.display_name;
46
- i.set(s, {
47
- fields: ((b = t[d]) == null ? void 0 : b.data) ?? [],
48
- relations: ((y = o[d]) == null ? void 0 : y.data) ?? [],
49
- label: m != null && m.trim() ? m : _(s),
50
- ready: !((f = t[d]) != null && f.isPending) && !((v = o[d]) != null && v.isPending)
40
+ }), d = /* @__PURE__ */ new Map();
41
+ return a.forEach((l, c) => {
42
+ var k, x, g, y, b, v;
43
+ const u = (x = (k = f[c]) == null ? void 0 : k.data) == null ? void 0 : x.display_name;
44
+ d.set(l, {
45
+ fields: ((g = n[c]) == null ? void 0 : g.data) ?? [],
46
+ relations: ((y = i[c]) == null ? void 0 : y.data) ?? [],
47
+ label: u != null && u.trim() ? u : H(l),
48
+ ready: !((b = n[c]) != null && b.isPending) && !((v = i[c]) != null && v.isPending)
51
49
  });
52
- }), i;
50
+ }), d;
53
51
  }
54
- function P(a, e) {
55
- var o;
56
- const t = a.fields.find((u) => u.field === e);
57
- return (o = t == null ? void 0 : t.label) != null && o.trim() ? t.label : _(e);
52
+ function T(a, e) {
53
+ var i;
54
+ const n = a.fields.find((f) => f.field === e);
55
+ return (i = n == null ? void 0 : n.label) != null && i.trim() ? n.label : H(e);
58
56
  }
59
- function Ze(a, e) {
60
- const t = Object.keys(e.context ?? {}).filter((s) => !M(e.context[s])), o = new Map(a.fields.map((s) => [s.field, s])), i = Te(
57
+ function Ae(a, e) {
58
+ const n = Object.keys(e.context ?? {}).filter((l) => !K(e.context[l])), i = new Map(a.fields.map((l) => [l.field, l])), d = Se(
61
59
  e.field,
62
- (s) => {
63
- var d;
64
- return re(((d = o.get(s)) == null ? void 0 : d.dependency_config) ?? null);
60
+ (l) => {
61
+ var c;
62
+ return ae(((c = i.get(l)) == null ? void 0 : c.dependency_config) ?? null);
65
63
  }
66
- ).reverse().filter((s) => t.includes(s));
67
- return [...i, ...t.filter((s) => !i.includes(s))];
64
+ ).reverse().filter((l) => n.includes(l));
65
+ return [...d, ...n.filter((l) => !d.includes(l))];
68
66
  }
69
67
  function Z(a, e) {
70
68
  if (a.kind === "text") return { text: a.text, state: "ok" };
71
69
  if (a.kind === "unknown") return { text: "Saved value", state: "ok" };
72
70
  if (e.loading) return { text: "", state: "loading" };
73
71
  if (e.failed) return { text: "Could not load this value", state: "failed" };
74
- const t = [];
75
- let o = 0;
76
- for (const u of a.ids) {
77
- const i = ze(a.target, u);
78
- e.map.has(i) ? t.push(e.map.get(i) ?? "Untitled record") : o++;
72
+ const n = [];
73
+ let i = 0;
74
+ for (const f of a.ids) {
75
+ const d = _e(a.target, f);
76
+ e.map.has(d) ? n.push(e.map.get(d) ?? "Untitled record") : i++;
79
77
  }
80
- return t.length === 0 ? { text: "No longer available", state: "gone" } : (o && t.push(`${o} no longer available`), { text: t.join(", "), state: "ok" });
78
+ return n.length === 0 ? { text: "No longer available", state: "gone" } : (i && n.push(`${i} no longer available`), { text: n.join(", "), state: "ok" });
81
79
  }
82
- function se(a) {
83
- var o, u;
84
- const e = a, t = ((u = (o = e == null ? void 0 : e.response) == null ? void 0 : o.data) == null ? void 0 : u.error) ?? (e == null ? void 0 : e.error);
85
- return typeof t == "string" && t.trim() ? t : Ee(a, "Could not save");
80
+ function ne(a) {
81
+ var i, f;
82
+ const e = a, n = ((f = (i = e == null ? void 0 : e.response) == null ? void 0 : i.data) == null ? void 0 : f.error) ?? (e == null ? void 0 : e.error);
83
+ return typeof n == "string" && n.trim() ? n : Ce(a, "Could not save");
86
84
  }
87
- function wt({ userId: a, name: e }) {
88
- const t = X(), o = xe(), u = Se(), i = !!a && String(a).toUpperCase() !== String(u.userId).toUpperCase(), s = !i || u.isAdmin, d = i ? `/field-defaults/users/${encodeURIComponent(String(a))}` : "/field-defaults/mine", m = i ? String(a) : "me", x = ["field-defaults-card", m], {
89
- data: c,
90
- isPending: b,
85
+ function ot({ userId: a, name: e }) {
86
+ const n = z(), i = me(), f = ve(), d = !!a && String(a).toUpperCase() !== String(f.userId).toUpperCase(), l = !d || f.isAdmin, c = d ? `/field-defaults/users/${encodeURIComponent(String(a))}` : "/field-defaults/mine", u = d ? String(a) : "me", k = ["field-defaults-card", u], {
87
+ data: x,
88
+ isPending: g,
91
89
  isError: y,
92
- refetch: f,
90
+ refetch: b,
93
91
  isRefetching: v
94
- } = U({
95
- queryKey: x,
96
- queryFn: () => t.request(T(d, { on_layout: 1 })).then((l) => l.data ?? []),
97
- enabled: s,
92
+ } = I({
93
+ queryKey: k,
94
+ queryFn: () => n.request(M(c, { on_layout: 1 })).then((t) => t.data ?? []),
95
+ enabled: l,
98
96
  staleTime: 3e4
99
- }), { data: h } = U({
100
- queryKey: ["field-defaults-allowed", m],
101
- queryFn: () => t.request(T(`${d}/allowed`)).then((l) => l.data ?? []),
102
- enabled: s && i,
97
+ }), { data: p, isPending: S } = I({
98
+ queryKey: ["field-defaults-allowed", u],
99
+ queryFn: () => n.request(M(`${c}/allowed`)).then((t) => t.data ?? []),
100
+ enabled: l,
103
101
  staleTime: 6e4
104
- }), { data: g, isPending: q } = U({
105
- queryKey: ["field-defaults-allowed-any", m],
106
- queryFn: () => t.request(T(`${d}/allowed`, { any: 1 })).then((l) => {
107
- var r;
108
- return ((r = l.data) == null ? void 0 : r.any) === !0;
109
- }),
110
- enabled: s && !i,
111
- staleTime: 6e4
112
- }), [k, F] = w(!1), [C, z] = w(""), G = S(() => {
113
- const l = new Set((c ?? []).map((r) => r.collection));
114
- return C && l.add(C), [...l];
115
- }, [c, C]), E = We(G), A = G.every((l) => {
102
+ }), w = E(() => {
103
+ const t = new Set((x ?? []).map((r) => r.collection));
104
+ for (const r of p ?? []) t.add(r.collection);
105
+ return [...t];
106
+ }, [x, p]), h = Ue(w), P = w.every((t) => {
116
107
  var r;
117
- return (r = E.get(l)) == null ? void 0 : r.ready;
118
- }), j = S(() => {
119
- const l = /* @__PURE__ */ new Map();
120
- if (!A) return l;
121
- for (const r of c ?? []) {
122
- const N = E.get(r.collection) ?? W, L = ($) => N.fields.find((he) => he.field === $);
123
- l.set(String(r.id), {
124
- value: J(L(r.field), N.relations, r.collection, r.value),
125
- context: Ze(N, r).map(($) => [
126
- $,
127
- J(L($), N.relations, r.collection, r.context[$])
108
+ return (r = h.get(t)) == null ? void 0 : r.ready;
109
+ }), C = E(() => {
110
+ const t = /* @__PURE__ */ new Map();
111
+ if (!P) return t;
112
+ for (const r of x ?? []) {
113
+ const N = h.get(r.collection) ?? B, q = (m) => N.fields.find((F) => F.field === m);
114
+ t.set(String(r.id), {
115
+ value: W(q(r.field), N.relations, r.collection, r.value),
116
+ context: Ae(N, r).map((m) => [
117
+ m,
118
+ W(q(m), N.relations, r.collection, r.context[m])
128
119
  ])
129
120
  });
130
121
  }
131
- return l;
132
- }, [c, E, A]), K = S(() => {
133
- const l = /* @__PURE__ */ new Map();
134
- for (const r of j.values())
135
- for (const N of [r.value, ...r.context.map(([, L]) => L)])
136
- N.kind === "records" && l.set(N.target, [.../* @__PURE__ */ new Set([...l.get(N.target) ?? [], ...N.ids])].sort());
137
- return l;
138
- }, [j]), ce = [...K].map(([l, r]) => `${l}:${r.join(",")}`).sort().join("|"), {
139
- data: ue,
140
- isPending: fe,
141
- isError: H
142
- } = U({
143
- queryKey: ["field-defaults-card-labels", ce],
144
- queryFn: () => Xe(
145
- t,
146
- K,
147
- (l) => o.fetchQuery({
148
- queryKey: ["col-meta", l],
149
- queryFn: () => t.request(
150
- T(`/collections/${l}`)
122
+ return t;
123
+ }, [x, h, P]), R = E(() => {
124
+ const t = /* @__PURE__ */ new Map();
125
+ for (const r of C.values())
126
+ for (const N of [r.value, ...r.context.map(([, q]) => q)])
127
+ N.kind === "records" && t.set(N.target, [.../* @__PURE__ */ new Set([...t.get(N.target) ?? [], ...N.ids])].sort());
128
+ return t;
129
+ }, [C]), oe = [...R].map(([t, r]) => `${t}:${r.join(",")}`).sort().join("|"), {
130
+ data: de,
131
+ isPending: ce,
132
+ isError: G
133
+ } = I({
134
+ queryKey: ["field-defaults-card-labels", oe],
135
+ queryFn: () => $e(
136
+ n,
137
+ R,
138
+ (t) => i.fetchQuery({
139
+ queryKey: ["col-meta", t],
140
+ queryFn: () => n.request(
141
+ M(`/collections/${t}`)
151
142
  ).then((r) => r.data ?? null),
152
143
  staleTime: 6e4
153
144
  }).then((r) => (r == null ? void 0 : r.display_template) ?? null)
154
145
  ),
155
- enabled: A && K.size > 0,
146
+ enabled: P && R.size > 0,
156
147
  staleTime: 6e4
157
- }), me = {
158
- map: ue ?? /* @__PURE__ */ new Map(),
159
- loading: K.size > 0 && !H && (!A || fe),
160
- failed: H
161
- }, I = (l) => {
162
- o.invalidateQueries({ queryKey: x }), !i && l && o.invalidateQueries({ queryKey: Ke(l) });
163
- }, O = ae({
164
- mutationFn: (l) => t.request(qe(`${d}/${l.id}`)),
165
- onSuccess: (l, r) => {
166
- I(r.collection), B.success("Default cleared");
148
+ }), ue = {
149
+ map: de ?? /* @__PURE__ */ new Map(),
150
+ loading: R.size > 0 && !G && (!P || ce),
151
+ failed: G
152
+ }, A = (t) => {
153
+ i.invalidateQueries({ queryKey: k }), !d && t && i.invalidateQueries({ queryKey: Me(t) });
154
+ }, Q = te({
155
+ mutationFn: (t) => n.request(ke(`${c}/${t.id}`)),
156
+ onSuccess: (t, r) => {
157
+ A(r.collection), V.success("Default cleared");
167
158
  },
168
- onError: (l) => B.error(se(l))
159
+ onError: (t) => V.error(ne(t))
169
160
  });
170
- if (!s || !i && (b || q && !y || !y && (c ?? []).length === 0 && g !== !0))
161
+ if (!l || !d && (g || S && !y || !y && (x ?? []).length === 0 && ((p == null ? void 0 : p.length) ?? 0) === 0))
171
162
  return null;
172
- const pe = [...new Set((c ?? []).map((l) => l.collection))].map((l) => {
173
- var r;
174
- return { collection: l, label: ((r = E.get(l)) == null ? void 0 : r.label) || _(l) };
175
- }).sort((l, r) => l.label.localeCompare(r.label)), Y = (e == null ? void 0 : e.trim()) || "This person";
176
- return /* @__PURE__ */ p(
177
- Ge,
163
+ const j = /* @__PURE__ */ new Map();
164
+ for (const t of p ?? []) {
165
+ const r = new Set(
166
+ (x ?? []).filter((m) => m.collection === t.collection).map((m) => m.field)
167
+ ), N = h.get(t.collection), q = t.fields.filter((m) => !r.has(m)).sort(
168
+ (m, F) => N ? T(N, m).localeCompare(T(N, F)) : m.localeCompare(F)
169
+ );
170
+ q.length && j.set(t.collection, q);
171
+ }
172
+ const J = w.filter((t) => (x ?? []).some((r) => r.collection === t) || j.has(t)).map((t) => {
173
+ var r, N;
174
+ return {
175
+ collection: t,
176
+ label: ((r = h.get(t)) == null ? void 0 : r.label) || ((N = (p ?? []).find((q) => q.collection === t)) == null ? void 0 : N.label) || H(t)
177
+ };
178
+ }).sort((t, r) => t.label.localeCompare(r.label)), L = (e == null ? void 0 : e.trim()) || "This person";
179
+ return /* @__PURE__ */ o(
180
+ De,
178
181
  {
179
- icon: /* @__PURE__ */ n(ve, { className: "h-4 w-4" }),
180
- title: i ? "Personal defaults" : "My defaults",
181
- hint: i ? "Starting values their new records are filled in with" : "Starting values your new records are filled in with",
182
+ icon: /* @__PURE__ */ s(pe, { className: "h-4 w-4" }),
183
+ title: d ? "Personal defaults" : "My defaults",
184
+ hint: d ? `New records ${e != null && e.trim() ? L : "they"} start are filled in with these` : "New records you start are filled in with these",
182
185
  testId: "my-defaults",
183
- actions: i && !k && ((h == null ? void 0 : h.length) ?? 0) > 0 ? /* @__PURE__ */ p(
184
- "button",
185
- {
186
- type: "button",
187
- "data-default-add": !0,
188
- onClick: () => F(!0),
189
- className: "inline-flex h-7 items-center gap-1 rounded-md px-2 text-[11.5px] font-medium text-slate-600 transition-colors hover:bg-muted hover:text-slate-900 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan/40 dark:text-slate-300 dark:hover:text-white",
190
- children: [
191
- /* @__PURE__ */ n(be, { className: "h-3.5 w-3.5" }),
192
- " Add default"
193
- ]
194
- }
195
- ) : null,
196
186
  children: [
197
- b ? /* @__PURE__ */ n("div", { className: "space-y-3", "aria-busy": "true", children: [0, 1, 2].map((l) => /* @__PURE__ */ p("div", { className: "flex items-center gap-3", children: [
198
- /* @__PURE__ */ n(D, { className: "h-3.5 w-24" }),
199
- /* @__PURE__ */ n(D, { className: "h-3.5 w-40" })
200
- ] }, l)) }) : y ? /* @__PURE__ */ p("div", { className: "flex flex-wrap items-center gap-2", children: [
201
- /* @__PURE__ */ n(He, { children: "Could not load the saved defaults." }),
202
- /* @__PURE__ */ n(
187
+ g ? /* @__PURE__ */ s("div", { className: "space-y-3", "aria-busy": "true", children: [0, 1, 2].map((t) => /* @__PURE__ */ o("div", { className: "flex items-center gap-3", children: [
188
+ /* @__PURE__ */ s(U, { className: "h-3.5 w-24" }),
189
+ /* @__PURE__ */ s(U, { className: "h-3.5 w-40" })
190
+ ] }, t)) }) : y ? /* @__PURE__ */ o("div", { className: "flex flex-wrap items-center gap-2", children: [
191
+ /* @__PURE__ */ s(Ke, { children: "Could not load the saved defaults." }),
192
+ /* @__PURE__ */ s(
203
193
  "button",
204
194
  {
205
195
  type: "button",
206
196
  "data-default-retry": !0,
207
197
  disabled: v,
208
- onClick: () => void f(),
198
+ onClick: () => void b(),
209
199
  className: "inline-flex h-7 items-center rounded-md border border-slate-200 px-2.5 text-[11.5px] font-medium text-slate-700 transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan/40 disabled:opacity-50 dark:border-border dark:text-slate-200",
210
200
  children: v ? "Trying…" : "Retry"
211
201
  }
212
202
  )
213
- ] }) : (c ?? []).length === 0 ? /* @__PURE__ */ p("p", { "data-default-empty": !0, className: "text-[12px] text-slate-500 dark:text-slate-400", children: [
214
- i ? `${Y} hasn’t saved any defaults yet.` : "No defaults yet.",
215
- " On a record form, open a field’s ⋯ menu and choose",
216
- " ",
217
- /* @__PURE__ */ n("span", { className: "font-medium text-slate-700 dark:text-slate-200", children: "Save as my default" }),
218
- i ? ((h == null ? void 0 : h.length) ?? 0) > 0 ? " — or add one here." : "." : " — new records then start with that value."
219
- ] }) : /* @__PURE__ */ n("div", { className: "space-y-4", children: pe.map((l) => /* @__PURE__ */ p("section", { "data-default-group": l.collection, children: [
220
- /* @__PURE__ */ n("h4", { className: "mb-1 text-[12px] font-semibold text-slate-700 dark:text-slate-200", children: l.label }),
221
- /* @__PURE__ */ n("ul", { className: "divide-y divide-slate-100 dark:divide-border/60", children: (c ?? []).filter((r) => r.collection === l.collection).map((r) => {
222
- var N;
223
- return /* @__PURE__ */ n(
224
- tt,
225
- {
226
- row: r,
227
- meta: E.get(r.collection) ?? W,
228
- parts: j.get(String(r.id)),
229
- labels: me,
230
- base: d,
231
- onSaved: () => I(r.collection),
232
- onClear: () => O.mutate(r),
233
- clearing: O.isPending && ((N = O.variables) == null ? void 0 : N.id) === r.id
234
- },
235
- r.id
236
- );
237
- }) })
238
- ] }, l.collection)) }),
239
- i && (h == null ? void 0 : h.length) === 0 && /* @__PURE__ */ p("p", { className: "mt-3 text-[11.5px] text-slate-500 dark:text-slate-400", children: [
240
- "No form gives ",
241
- e != null && e.trim() ? Y : "this person",
242
- " a personal default yet. Turn on Personal default for a field in the layout editor."
243
- ] }),
244
- i && k && /* @__PURE__ */ n(
245
- nt,
203
+ ] }) : J.length === 0 ? /* @__PURE__ */ s(
204
+ "p",
246
205
  {
247
- allowed: h ?? [],
248
- metas: E,
249
- collection: C,
250
- onCollection: z,
251
- base: d,
252
- onDone: () => {
253
- F(!1), z("");
254
- },
255
- onSaved: (l) => I(l)
206
+ "data-default-empty": !0,
207
+ className: "max-w-[65ch] text-[12.5px] leading-relaxed text-slate-600 dark:text-slate-300",
208
+ children: d ? `${L} hasn’t saved any defaults yet.` : "You have no defaults yet."
256
209
  }
257
- )
210
+ ) : /* @__PURE__ */ o("div", { className: "space-y-5", children: [
211
+ (x ?? []).length === 0 && /* @__PURE__ */ o(
212
+ "p",
213
+ {
214
+ "data-default-empty": !0,
215
+ className: "max-w-[65ch] text-[12.5px] leading-relaxed text-slate-600 dark:text-slate-300",
216
+ children: [
217
+ d ? `${L} hasn’t saved any defaults yet. Set one below, or they can choose ` : "Nothing set yet. Set a field below, or choose ",
218
+ /* @__PURE__ */ s("span", { className: "font-medium text-slate-800 dark:text-slate-100", children: "Make default" }),
219
+ " ",
220
+ "beside its label on a new record."
221
+ ]
222
+ }
223
+ ),
224
+ J.map((t) => {
225
+ const r = (x ?? []).filter((m) => m.collection === t.collection).length, N = j.get(t.collection) ?? [], q = h.get(t.collection) ?? B;
226
+ return /* @__PURE__ */ o("section", { "data-default-group": t.collection, children: [
227
+ /* @__PURE__ */ o("h4", { className: "flex items-baseline gap-1.5 border-b border-slate-200 pb-1.5 text-[12.5px] font-semibold text-slate-800 dark:border-border dark:text-slate-100", children: [
228
+ /* @__PURE__ */ s("span", { "data-default-group-label": !0, children: t.label }),
229
+ /* @__PURE__ */ o("span", { className: "text-[11.5px] font-normal tabular-nums text-slate-500 dark:text-slate-400", children: [
230
+ r,
231
+ " of ",
232
+ r + N.length,
233
+ " set"
234
+ ] })
235
+ ] }),
236
+ /* @__PURE__ */ o("ul", { className: "divide-y divide-slate-100 dark:divide-border/60", children: [
237
+ (x ?? []).filter((m) => m.collection === t.collection).map((m) => {
238
+ var F;
239
+ return /* @__PURE__ */ s(
240
+ Qe,
241
+ {
242
+ row: m,
243
+ meta: h.get(m.collection) ?? B,
244
+ parts: C.get(String(m.id)),
245
+ labels: ue,
246
+ base: c,
247
+ onSaved: () => A(m.collection),
248
+ onClear: () => Q.mutate(m),
249
+ clearing: Q.isPending && ((F = Q.variables) == null ? void 0 : F.id) === m.id
250
+ },
251
+ m.id
252
+ );
253
+ }),
254
+ N.map((m) => /* @__PURE__ */ s(
255
+ Ie,
256
+ {
257
+ collection: t.collection,
258
+ field: m,
259
+ meta: q,
260
+ base: c,
261
+ forOther: d,
262
+ onSaved: () => A(t.collection)
263
+ },
264
+ `unset:${m}`
265
+ ))
266
+ ] })
267
+ ] }, t.collection);
268
+ })
269
+ ] }),
270
+ d && (p == null ? void 0 : p.length) === 0 && /* @__PURE__ */ o("p", { className: "mt-3 text-[11.5px] text-slate-500 dark:text-slate-400", children: [
271
+ "No form gives ",
272
+ e != null && e.trim() ? L : "this person",
273
+ " a personal default yet. Turn on Personal default for a field in the layout editor."
274
+ ] })
258
275
  ]
259
276
  }
260
277
  );
261
278
  }
262
- const et = 'input:not([type=hidden]), textarea, [role=combobox], button, [tabindex]:not([tabindex="-1"])', ee = "No form you can be given offers a personal default for this field now, so it is not used. Clear it, or ask an admin to turn it back on.";
263
- function tt({
279
+ const le = 'input:not([type=hidden]), textarea, [role=combobox], button, [tabindex]:not([tabindex="-1"])', ee = "No form you can be given offers a personal default for this field now, so it is not used. Clear it, or ask an admin to turn it back on.";
280
+ function Qe({
264
281
  row: a,
265
282
  meta: e,
266
- parts: t,
267
- labels: o,
268
- base: u,
269
- onSaved: i,
270
- onClear: s,
271
- clearing: d
283
+ parts: n,
284
+ labels: i,
285
+ base: f,
286
+ onSaved: d,
287
+ onClear: l,
288
+ clearing: c
272
289
  }) {
273
- const [m, x] = w(!1), c = V(null), b = V(!1);
274
- le(() => {
275
- var k;
276
- m || !b.current || (b.current = !1, (k = c.current) == null || k.focus());
277
- }, [m]);
290
+ const [u, k] = _(!1), x = D(null), g = D(!1);
291
+ X(() => {
292
+ var h;
293
+ u || !g.current || (g.current = !1, (h = x.current) == null || h.focus());
294
+ }, [u]);
278
295
  const y = () => {
279
- b.current = !0, x(!1);
280
- }, f = a.on_layout === !1, v = e.fields.find((k) => k.field === a.field), h = t ? Z(t.value, o) : { text: "", state: "loading" }, g = ((t == null ? void 0 : t.context) ?? []).map(([k, F]) => {
281
- if (F.kind === "unknown") return P(e, k);
282
- const C = Z(F, o);
283
- return C.state === "loading" ? null : C.state === "gone" || C.state === "failed" ? `${P(e, k)} (unavailable)` : C.text;
284
- }), q = ((t == null ? void 0 : t.context) ?? []).length > 0 && g.some((k) => k === null);
285
- return /* @__PURE__ */ p("li", { "data-default-row": a.id, className: "group flex items-start gap-3 py-2", children: [
286
- /* @__PURE__ */ p("div", { className: "min-w-0 flex-1 gap-3 sm:grid sm:grid-cols-[minmax(0,9rem)_minmax(0,1fr)]", children: [
287
- /* @__PURE__ */ n(
288
- "p",
289
- {
290
- "data-default-field": !0,
291
- className: "truncate pt-px text-[12px] text-slate-500 dark:text-slate-400",
292
- children: P(e, a.field)
293
- }
296
+ g.current = !0, k(!1);
297
+ }, b = a.on_layout === !1, v = e.fields.find((h) => h.field === a.field), p = n ? Z(n.value, i) : { text: "", state: "loading" }, S = ((n == null ? void 0 : n.context) ?? []).map(([h, P]) => {
298
+ if (P.kind === "unknown") return T(e, h);
299
+ const C = Z(P, i);
300
+ return C.state === "loading" ? null : C.state === "gone" || C.state === "failed" ? `${T(e, h)} (unavailable)` : C.text;
301
+ }), w = ((n == null ? void 0 : n.context) ?? []).length > 0 && S.some((h) => h === null);
302
+ return /* @__PURE__ */ o(
303
+ "li",
304
+ {
305
+ "data-default-row": a.id,
306
+ "data-editing": u ? "" : void 0,
307
+ className: $(
308
+ "-mx-2 flex flex-col gap-2 rounded-md px-2 py-2.5 sm:flex-row sm:items-start sm:gap-3",
309
+ u && "bg-slate-50 dark:bg-muted/40"
294
310
  ),
295
- /* @__PURE__ */ p("div", { className: "min-w-0", children: [
296
- m && v ? /* @__PURE__ */ n(
297
- at,
298
- {
299
- row: a,
300
- field: v,
301
- relations: e.relations,
302
- base: u,
303
- onCancel: y,
304
- onSaved: () => {
305
- y(), i();
311
+ children: [
312
+ /* @__PURE__ */ o("div", { className: "min-w-0 flex-1 gap-x-4 gap-y-1 sm:grid sm:grid-cols-[minmax(0,11rem)_minmax(0,1fr)]", children: [
313
+ /* @__PURE__ */ s(
314
+ "p",
315
+ {
316
+ "data-default-field": !0,
317
+ className: $(
318
+ "truncate text-[12.5px] text-slate-600 dark:text-slate-300",
319
+ u ? "sm:pt-2" : "sm:pt-px"
320
+ ),
321
+ children: T(e, a.field)
306
322
  }
307
- }
308
- ) : h.state === "loading" ? /* @__PURE__ */ n(D, { className: "mt-0.5 h-3.5 w-32" }) : /* @__PURE__ */ n(
309
- "p",
310
- {
311
- "data-default-value": !0,
312
- "data-tip": h.state === "gone" ? "The saved record was removed, or is no longer visible to you" : void 0,
313
- className: R(
314
- "truncate text-[12.5px]",
315
- h.state === "gone" || h.state === "failed" ? "italic text-slate-500 dark:text-slate-400" : f ? "text-slate-500 dark:text-slate-400" : "font-medium text-slate-800 dark:text-slate-100"
323
+ ),
324
+ /* @__PURE__ */ o("div", { className: "min-w-0", children: [
325
+ u && v ? /* @__PURE__ */ s(
326
+ je,
327
+ {
328
+ row: a,
329
+ field: v,
330
+ relations: e.relations,
331
+ base: f,
332
+ onCancel: y,
333
+ onSaved: () => {
334
+ y(), d();
335
+ }
336
+ }
337
+ ) : p.state === "loading" ? /* @__PURE__ */ s(U, { className: "mt-0.5 h-3.5 w-32" }) : /* @__PURE__ */ s(
338
+ "p",
339
+ {
340
+ "data-default-value": !0,
341
+ "data-tip": p.state === "gone" ? "The saved record was removed, or is no longer visible to you" : void 0,
342
+ className: $(
343
+ "truncate text-[13px]",
344
+ p.state === "gone" || p.state === "failed" ? "italic text-slate-500 dark:text-slate-400" : b ? "text-slate-500 dark:text-slate-400" : "font-medium text-slate-800 dark:text-slate-100"
345
+ ),
346
+ children: p.text
347
+ }
316
348
  ),
317
- children: h.text
318
- }
319
- ),
320
- /* @__PURE__ */ p("p", { className: "mt-0.5 flex flex-wrap items-center gap-x-1.5 gap-y-1 text-[11.5px] text-slate-500 dark:text-slate-400", children: [
321
- q ? /* @__PURE__ */ n(D, { className: "h-3 w-28" }) : g.length > 0 ? /* @__PURE__ */ p("span", { "data-default-context": !0, children: [
322
- "for ",
323
- g.join(" · ")
324
- ] }) : null,
325
- (q || g.length > 0) && /* @__PURE__ */ n("span", { "aria-hidden": !0, children: "·" }),
326
- /* @__PURE__ */ p("span", { children: [
327
- "Saved ",
328
- Fe(a.updated_at),
329
- a.updated_by ? " by an admin" : ""
330
- ] }),
331
- f && /* @__PURE__ */ p("span", { "data-tip": ee, children: [
332
- /* @__PURE__ */ n(Ye, { tone: "amber", testId: "stale", children: /* @__PURE__ */ n("span", { "data-default-stale": !0, children: "No longer on any form" }) }),
333
- /* @__PURE__ */ p("span", { className: "sr-only", children: [
334
- ". ",
335
- ee
349
+ /* @__PURE__ */ o("p", { className: "mt-1 flex flex-wrap items-center gap-x-1.5 gap-y-1 text-[11.5px] text-slate-500 dark:text-slate-400", children: [
350
+ w ? /* @__PURE__ */ s(U, { className: "h-3 w-28" }) : S.length > 0 ? /* @__PURE__ */ o("span", { "data-default-context": !0, children: [
351
+ "For ",
352
+ S.join(" · ")
353
+ ] }) : null,
354
+ !u && (w || S.length > 0) && /* @__PURE__ */ s("span", { "aria-hidden": !0, children: "·" }),
355
+ !u && /* @__PURE__ */ o("span", { children: [
356
+ a.updated_by ? "Set by an admin" : "Saved",
357
+ " ",
358
+ qe(a.updated_at)
359
+ ] }),
360
+ b && /* @__PURE__ */ o("span", { "data-tip": ee, children: [
361
+ /* @__PURE__ */ s(Re, { tone: "amber", testId: "stale", children: /* @__PURE__ */ s("span", { "data-default-stale": !0, children: "No longer on any form" }) }),
362
+ /* @__PURE__ */ o("span", { className: "sr-only", children: [
363
+ ". ",
364
+ ee
365
+ ] })
366
+ ] })
336
367
  ] })
337
368
  ] })
338
- ] })
339
- ] })
340
- ] }),
341
- !m && /* @__PURE__ */ p(
342
- "div",
343
- {
344
- className: R(
345
- "flex shrink-0 items-center gap-0.5 transition-opacity duration-150",
346
- // Reserve the slot; show on hover / keyboard focus, always on touch and when stale.
347
- // …and while Clear is armed (the pointer may have left before the second press).
348
- !f && "opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 [@media(hover:none)]:opacity-100 [&:has([data-armed])]:opacity-100"
349
- ),
350
- children: [
351
- !f && v && /* @__PURE__ */ n(
369
+ ] }),
370
+ !u && // Always visible: hover-only actions hid the only way to change or clear a default.
371
+ /* @__PURE__ */ o("div", { className: "flex shrink-0 items-center gap-1 sm:pt-px", children: [
372
+ !b && v && /* @__PURE__ */ o(
352
373
  "button",
353
374
  {
354
- ref: c,
375
+ ref: x,
355
376
  type: "button",
356
377
  "data-default-change": !0,
357
- "aria-label": `Change the default for ${P(e, a.field)}`,
358
- "data-tip": "Change",
359
- onClick: () => x(!0),
360
- className: "rounded p-1.5 text-slate-500 transition-colors hover:bg-muted hover:text-slate-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan/40 dark:text-slate-400 dark:hover:text-slate-100",
361
- children: /* @__PURE__ */ n(ye, { className: "h-3.5 w-3.5" })
378
+ "aria-label": `Change the default for ${T(e, a.field)}`,
379
+ onClick: () => k(!0),
380
+ className: Y,
381
+ children: [
382
+ /* @__PURE__ */ s(xe, { className: "h-3 w-3" }),
383
+ " Change"
384
+ ]
362
385
  }
363
386
  ),
364
- /* @__PURE__ */ n(
365
- Je,
387
+ /* @__PURE__ */ s(
388
+ Le,
366
389
  {
367
- onConfirm: s,
368
- disabled: d,
369
- title: `Clear the default for ${P(e, a.field)}`,
370
- confirmTitle: `Clear the default for ${P(e, a.field)}?`,
371
- confirmLabel: /* @__PURE__ */ n("span", { "data-default-clear": !0, className: "px-1 text-[11.5px] font-semibold", children: "Clear?" }),
372
- className: "inline-flex h-7 items-center rounded px-1.5 text-slate-500 transition-colors hover:bg-muted hover:text-red-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan/40 disabled:opacity-50 dark:text-slate-400 dark:hover:text-red-400",
390
+ onConfirm: l,
391
+ disabled: c,
392
+ title: `Clear the default for ${T(e, a.field)}`,
393
+ confirmTitle: `Clear the default for ${T(e, a.field)}?`,
394
+ confirmLabel: /* @__PURE__ */ s("span", { "data-default-clear": !0, className: "px-0.5 text-[11.5px] font-semibold", children: "Clear it?" }),
395
+ className: "inline-flex h-7 items-center gap-1 rounded-md px-2 text-[11.5px] font-medium text-slate-500 transition-colors hover:bg-muted hover:text-red-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan/40 disabled:opacity-50 dark:text-slate-400 dark:hover:text-red-400",
373
396
  armedClassName: "bg-red-50 text-red-700 hover:bg-red-100 dark:bg-red-500/10 dark:text-red-400 dark:hover:bg-red-500/15",
374
- children: /* @__PURE__ */ n("span", { "data-default-clear": !0, className: "inline-flex items-center", children: /* @__PURE__ */ n(ke, { className: "h-3.5 w-3.5" }) })
397
+ children: /* @__PURE__ */ o("span", { "data-default-clear": !0, className: "inline-flex items-center gap-1", children: [
398
+ /* @__PURE__ */ s(he, { className: "h-3 w-3" }),
399
+ " Clear"
400
+ ] })
375
401
  }
376
402
  )
377
- ]
378
- }
379
- )
380
- ] });
403
+ ] })
404
+ ]
405
+ }
406
+ );
381
407
  }
382
- function ie({
408
+ function se({
383
409
  collection: a,
384
410
  field: e,
385
- relations: t,
386
- context: o,
387
- value: u,
388
- onChange: i
411
+ relations: n,
412
+ context: i,
413
+ value: f,
414
+ onChange: d
389
415
  }) {
390
- var f;
391
- const s = S(() => ({ ...e, readonly: !1, hidden: !1 }), [e]), d = ((f = Ae(t, a, e.field)) == null ? void 0 : f.kind) === "m2m", m = S(
392
- () => Array.isArray(u) ? u : M(u) ? [] : [u],
393
- [u]
394
- ), x = S(
395
- () => d ? {
396
- getStagedLinks: () => m,
416
+ var b;
417
+ const l = E(() => ({ ...e, readonly: !1, hidden: !1 }), [e]), c = ((b = Fe(n, a, e.field)) == null ? void 0 : b.kind) === "m2m", u = E(
418
+ () => Array.isArray(f) ? f : K(f) ? [] : [f],
419
+ [f]
420
+ ), k = E(
421
+ () => c ? {
422
+ getStagedLinks: () => u,
397
423
  getStagedUnlinks: () => /* @__PURE__ */ new Set(),
398
- stageLink: (v, h) => i(m.some((g) => String(g) === String(h)) ? m : [...m, h]),
399
- unstageLink: (v, h) => i(m.filter((g) => String(g) !== String(h))),
424
+ stageLink: (v, p) => d(u.some((S) => String(S) === String(p)) ? u : [...u, p]),
425
+ unstageLink: (v, p) => d(u.filter((S) => String(S) !== String(p))),
400
426
  stageUnlink: () => {
401
427
  },
402
428
  unstageUnlink: () => {
403
429
  }
404
430
  } : null,
405
- [d, m, i]
406
- ), c = S(
407
- () => Me({
408
- rules: re(e.dependency_config),
409
- parentValue: (v) => M(o[v]) ? null : o[v]
431
+ [c, u, d]
432
+ ), x = E(
433
+ () => Te({
434
+ rules: ae(e.dependency_config),
435
+ parentValue: (v) => K(i[v]) ? null : i[v]
410
436
  }).filter,
411
- [e.dependency_config, o]
412
- ), b = S(() => ({ collection: a, draft: { ...o } }), [a, o]), y = /* @__PURE__ */ n(
413
- $e,
437
+ [e.dependency_config, i]
438
+ ), g = E(() => ({ collection: a, draft: { ...i } }), [a, i]), y = /* @__PURE__ */ s(
439
+ Pe,
414
440
  {
415
- field: s,
416
- value: d ? void 0 : u,
417
- onChange: i,
418
- relations: t,
441
+ field: l,
442
+ value: c ? void 0 : f,
443
+ onChange: d,
444
+ relations: n,
419
445
  collection: a,
420
446
  itemId: "new",
421
- cascadeFilter: c
447
+ cascadeFilter: x
422
448
  }
423
449
  );
424
- return /* @__PURE__ */ n(we.Provider, { value: b, children: x ? /* @__PURE__ */ n(_e.Provider, { value: x, children: y }) : y });
450
+ return /* @__PURE__ */ s(Ne.Provider, { value: g, children: k ? /* @__PURE__ */ s(Ee.Provider, { value: k, children: y }) : y });
425
451
  }
426
- function oe({
452
+ function re({
427
453
  canSave: a,
428
454
  pending: e,
429
- onSave: t,
430
- onCancel: o
455
+ onSave: n,
456
+ onCancel: i
431
457
  }) {
432
- return /* @__PURE__ */ p("span", { className: "flex items-center gap-1.5", children: [
433
- /* @__PURE__ */ p("button", { type: "button", onClick: o, className: De, children: [
434
- /* @__PURE__ */ n(Ce, { className: "h-3 w-3" }),
458
+ return /* @__PURE__ */ o("span", { className: "flex h-9 shrink-0 items-center gap-1.5", children: [
459
+ /* @__PURE__ */ o("button", { type: "button", onClick: i, className: Y, children: [
460
+ /* @__PURE__ */ s(ye, { className: "h-3 w-3" }),
435
461
  " Cancel"
436
462
  ] }),
437
- /* @__PURE__ */ n(
463
+ /* @__PURE__ */ s(
438
464
  "button",
439
465
  {
440
466
  type: "button",
441
467
  "data-default-save": !0,
442
468
  disabled: !a || e,
443
- onClick: t,
469
+ onClick: n,
444
470
  className: "inline-flex h-7 items-center gap-1 rounded-md bg-nvr-cyan px-2.5 text-[11.5px] font-semibold text-white transition-opacity focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan/40 focus-visible:ring-offset-1 disabled:opacity-50",
445
- children: e ? "Saving…" : /* @__PURE__ */ p(ge, { children: [
446
- /* @__PURE__ */ n(ne, { className: "h-3 w-3" }),
471
+ children: e ? "Saving…" : /* @__PURE__ */ o(fe, { children: [
472
+ /* @__PURE__ */ s(be, { className: "h-3 w-3" }),
447
473
  " Save"
448
474
  ] })
449
475
  }
450
476
  )
451
477
  ] });
452
478
  }
453
- function de(a, e) {
454
- const t = X(), [o, u] = w(null);
455
- return { save: ae({
456
- mutationFn: (s) => t.request(Pe(a, s)),
479
+ function ie(a, e) {
480
+ const n = z(), [i, f] = _(null);
481
+ return { save: te({
482
+ mutationFn: (l) => n.request(we(a, l)),
457
483
  onSuccess: () => {
458
- u(null), B.success("Default saved"), e();
484
+ f(null), V.success("Default saved"), e();
459
485
  },
460
- onError: (s) => u(se(s))
461
- }), error: o };
486
+ onError: (l) => f(ne(l))
487
+ }), error: i };
462
488
  }
463
- function at({
489
+ function je({
464
490
  row: a,
465
491
  field: e,
466
- relations: t,
467
- base: o,
468
- onCancel: u,
469
- onSaved: i
492
+ relations: n,
493
+ base: i,
494
+ onCancel: f,
495
+ onSaved: d
470
496
  }) {
471
- const [s, d] = w(a.value), { save: m, error: x } = de(o, i), c = V(null);
472
- return le(() => {
473
- const b = () => {
474
- var v, h;
475
- const f = (h = (v = c.current) == null ? void 0 : v.querySelector("[data-default-control]")) == null ? void 0 : h.querySelector(et);
476
- return f == null || f.focus(), !!f;
497
+ const [l, c] = _(a.value), { save: u, error: k } = ie(i, d), x = D(null);
498
+ return X(() => {
499
+ const g = () => {
500
+ var v, p;
501
+ const b = (p = (v = x.current) == null ? void 0 : v.querySelector("[data-default-control]")) == null ? void 0 : p.querySelector(le);
502
+ return b == null || b.focus(), !!b;
477
503
  };
478
- if (b()) return;
479
- const y = window.setTimeout(b, 50);
504
+ if (g()) return;
505
+ const y = window.setTimeout(g, 50);
480
506
  return () => window.clearTimeout(y);
481
- }, []), /* @__PURE__ */ p(
507
+ }, []), /* @__PURE__ */ o(
482
508
  "fieldset",
483
509
  {
484
- ref: c,
510
+ ref: x,
485
511
  className: "m-0 min-w-0 space-y-1.5 border-0 p-0",
486
512
  "data-default-editor": !0,
487
- onKeyDown: (b) => {
513
+ onKeyDown: (g) => {
488
514
  var y;
489
- b.key !== "Escape" || b.defaultPrevented || (y = c.current) != null && y.contains(b.target) && (b.stopPropagation(), u());
515
+ g.key !== "Escape" || g.defaultPrevented || (y = x.current) != null && y.contains(g.target) && (g.stopPropagation(), f());
490
516
  },
491
517
  children: [
492
- /* @__PURE__ */ p("legend", { className: "sr-only", children: [
518
+ /* @__PURE__ */ o("legend", { className: "sr-only", children: [
493
519
  "Change the default for ",
494
520
  e.label || e.field
495
521
  ] }),
496
- /* @__PURE__ */ n("div", { "data-default-control": !0, children: /* @__PURE__ */ n(
497
- ie,
498
- {
499
- collection: a.collection,
500
- field: e,
501
- relations: t,
502
- context: a.context ?? {},
503
- value: s,
504
- onChange: d
505
- }
506
- ) }),
507
- x && /* @__PURE__ */ n("p", { role: "alert", className: "text-[11.5px] text-red-600 dark:text-red-400", children: x }),
508
- /* @__PURE__ */ n(
509
- oe,
510
- {
511
- canSave: !M(s),
512
- pending: m.isPending,
513
- onCancel: u,
514
- onSave: () => m.mutate({
522
+ /* @__PURE__ */ o("div", { className: "flex flex-wrap items-start gap-2", children: [
523
+ /* @__PURE__ */ s("div", { "data-default-control": !0, className: "min-w-[12rem] max-w-[28rem] flex-1", children: /* @__PURE__ */ s(
524
+ se,
525
+ {
515
526
  collection: a.collection,
516
- field: a.field,
517
- value: s,
518
- context: a.context ?? {}
519
- })
520
- }
521
- )
527
+ field: e,
528
+ relations: n,
529
+ context: a.context ?? {},
530
+ value: l,
531
+ onChange: c
532
+ }
533
+ ) }),
534
+ /* @__PURE__ */ s(
535
+ re,
536
+ {
537
+ canSave: !K(l),
538
+ pending: u.isPending,
539
+ onCancel: f,
540
+ onSave: () => u.mutate({
541
+ collection: a.collection,
542
+ field: a.field,
543
+ value: l,
544
+ context: a.context ?? {}
545
+ })
546
+ }
547
+ )
548
+ ] }),
549
+ k && /* @__PURE__ */ s("p", { role: "alert", className: "text-[11.5px] text-red-600 dark:text-red-400", children: k })
522
550
  ]
523
551
  }
524
552
  );
525
553
  }
526
- function te({
527
- value: a,
528
- options: e,
529
- placeholder: t,
530
- label: o,
531
- onChange: u,
532
- testId: i,
533
- disabled: s
534
- }) {
535
- const [d, m] = w(!1), x = e.find((c) => c.value === a);
536
- return /* @__PURE__ */ p(Qe, { open: d, onOpenChange: m, children: [
537
- /* @__PURE__ */ n(Ve, { asChild: !0, children: /* @__PURE__ */ p(
538
- "button",
539
- {
540
- type: "button",
541
- role: "combobox",
542
- "aria-expanded": d,
543
- "aria-label": o,
544
- "data-default-pick": i,
545
- disabled: s,
546
- className: "flex h-8 w-full items-center justify-between gap-2 rounded-md border border-slate-200 bg-white px-2.5 text-left text-[12.5px] text-slate-700 transition-colors hover:border-slate-300 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan/40 disabled:cursor-not-allowed disabled:bg-slate-50 disabled:hover:border-slate-200 dark:border-border dark:bg-background dark:text-slate-200 dark:hover:border-slate-600 dark:disabled:bg-muted/40 dark:disabled:hover:border-border",
547
- children: [
548
- /* @__PURE__ */ n("span", { className: R("truncate", !x && "text-slate-500 dark:text-slate-400"), children: (x == null ? void 0 : x.label) ?? t }),
549
- /* @__PURE__ */ n(Ne, { className: "h-3.5 w-3.5 shrink-0 text-slate-400" })
550
- ]
551
- }
552
- ) }),
553
- /* @__PURE__ */ n(Be, { className: "w-[260px] p-0", align: "start", children: /* @__PURE__ */ p(Le, { children: [
554
- /* @__PURE__ */ n(Ue, { placeholder: "Search…", className: "h-8 text-[12px]" }),
555
- /* @__PURE__ */ p(Re, { children: [
556
- /* @__PURE__ */ n(je, { className: "py-3 text-center text-[12px] text-slate-500 dark:text-slate-400", children: "No matches" }),
557
- /* @__PURE__ */ n(Ie, { children: e.map((c) => /* @__PURE__ */ p(
558
- Oe,
559
- {
560
- value: `${c.label} ${c.value}`,
561
- onSelect: () => {
562
- u(c.value), m(!1);
563
- },
564
- className: "text-[12px]",
565
- children: [
566
- /* @__PURE__ */ n(
567
- ne,
568
- {
569
- className: R("mr-2 h-3 w-3", c.value === a ? "opacity-100" : "opacity-0")
570
- }
571
- ),
572
- c.label
573
- ]
574
- },
575
- c.value
576
- )) })
577
- ] })
578
- ] }) })
579
- ] });
580
- }
581
- function nt({
582
- allowed: a,
583
- metas: e,
584
- collection: t,
585
- onCollection: o,
586
- base: u,
587
- onDone: i,
588
- onSaved: s
554
+ function Ie({
555
+ collection: a,
556
+ field: e,
557
+ meta: n,
558
+ base: i,
559
+ forOther: f,
560
+ onSaved: d
589
561
  }) {
590
- const [d, m] = w(""), [x, c] = w(null), { save: b, error: y } = de(u, () => {
591
- s(t), i();
592
- }), f = t ? e.get(t) : void 0, v = a.find((g) => g.collection === t), h = f == null ? void 0 : f.fields.find((g) => g.field === d);
593
- return /* @__PURE__ */ p(
594
- "div",
562
+ const [l, c] = _(!1), [u, k] = _(null), { save: x, error: g } = ie(i, () => {
563
+ c(!1), k(null), d();
564
+ }), y = n.fields.find((w) => w.field === e), b = T(n, e), v = D(null), p = D(null);
565
+ X(() => {
566
+ if (!l) return;
567
+ const w = window.setTimeout(() => {
568
+ var h, P, C;
569
+ (C = (P = (h = p.current) == null ? void 0 : h.querySelector("[data-default-control]")) == null ? void 0 : P.querySelector(le)) == null || C.focus();
570
+ }, 30);
571
+ return () => window.clearTimeout(w);
572
+ }, [l]);
573
+ const S = () => {
574
+ c(!1), k(null), requestAnimationFrame(() => {
575
+ var w;
576
+ return (w = v.current) == null ? void 0 : w.focus();
577
+ });
578
+ };
579
+ return /* @__PURE__ */ o(
580
+ "li",
595
581
  {
596
- "data-default-add-form": !0,
597
- className: "mt-3 space-y-2 border-t border-slate-100 pt-3 dark:border-border/60",
582
+ "data-default-unset": e,
583
+ "data-editing": l ? "" : void 0,
584
+ className: $(
585
+ "-mx-2 flex flex-col gap-2 rounded-md px-2 py-2.5 sm:flex-row sm:items-start sm:gap-3",
586
+ l && "bg-slate-50 dark:bg-muted/40"
587
+ ),
598
588
  children: [
599
- /* @__PURE__ */ p("div", { className: "grid gap-2 sm:grid-cols-2", children: [
600
- /* @__PURE__ */ n(
601
- te,
589
+ /* @__PURE__ */ o("div", { className: "min-w-0 flex-1 gap-x-4 gap-y-1 sm:grid sm:grid-cols-[minmax(0,11rem)_minmax(0,1fr)]", children: [
590
+ /* @__PURE__ */ s(
591
+ "p",
602
592
  {
603
- testId: "collection",
604
- label: "Collection",
605
- placeholder: "Choose a collection",
606
- value: t,
607
- options: a.map((g) => {
608
- var q;
609
- return {
610
- value: g.collection,
611
- label: g.label ?? ((q = e.get(g.collection)) == null ? void 0 : q.label) ?? _(g.collection)
612
- };
613
- }),
614
- onChange: (g) => {
615
- o(g), m(""), c(null);
616
- }
593
+ "data-default-field": !0,
594
+ className: $(
595
+ "truncate text-[12.5px] text-slate-600 dark:text-slate-300",
596
+ l ? "sm:pt-2" : "sm:pt-px"
597
+ ),
598
+ children: b
617
599
  }
618
600
  ),
619
- /* @__PURE__ */ n(
620
- te,
601
+ /* @__PURE__ */ s("div", { className: "min-w-0", children: l && y ? /* @__PURE__ */ o(
602
+ "fieldset",
621
603
  {
622
- testId: "field",
623
- label: "Field",
624
- disabled: !t,
625
- placeholder: t ? "Choose a field" : "Choose a collection first",
626
- value: d,
627
- options: ((v == null ? void 0 : v.fields) ?? []).map((g) => ({
628
- value: g,
629
- label: f ? P(f, g) : _(g)
630
- })),
631
- onChange: (g) => {
632
- m(g), c(null);
633
- }
604
+ ref: p,
605
+ className: "m-0 min-w-0 space-y-1.5 border-0 p-0",
606
+ "data-default-editor": !0,
607
+ onKeyDown: (w) => {
608
+ var h;
609
+ w.key !== "Escape" || w.defaultPrevented || (h = p.current) != null && h.contains(w.target) && (w.stopPropagation(), S());
610
+ },
611
+ children: [
612
+ /* @__PURE__ */ o("legend", { className: "sr-only", children: [
613
+ "Set the default for ",
614
+ b
615
+ ] }),
616
+ /* @__PURE__ */ o("div", { className: "flex flex-wrap items-start gap-2", children: [
617
+ /* @__PURE__ */ s("div", { "data-default-control": !0, className: "min-w-[12rem] max-w-[28rem] flex-1", children: /* @__PURE__ */ s(
618
+ se,
619
+ {
620
+ collection: a,
621
+ field: y,
622
+ relations: n.relations,
623
+ context: {},
624
+ value: u,
625
+ onChange: k
626
+ }
627
+ ) }),
628
+ /* @__PURE__ */ s(
629
+ re,
630
+ {
631
+ canSave: !K(u),
632
+ pending: x.isPending,
633
+ onCancel: S,
634
+ onSave: () => x.mutate({ collection: a, field: e, value: u, context: {} })
635
+ }
636
+ )
637
+ ] }),
638
+ g && /* @__PURE__ */ s("p", { role: "alert", className: "text-[11.5px] text-red-600 dark:text-red-400", children: g }),
639
+ f && /* @__PURE__ */ s("p", { className: "text-[11px] text-slate-500 dark:text-slate-400", children: "Checked as them: they must be able to set the field and pick the value." })
640
+ ]
634
641
  }
635
- )
642
+ ) : /* @__PURE__ */ s(
643
+ "p",
644
+ {
645
+ "data-default-value": !0,
646
+ className: "pt-px text-[12.5px] italic text-slate-500 dark:text-slate-400",
647
+ children: "Not set"
648
+ }
649
+ ) })
636
650
  ] }),
637
- h && (f != null && f.ready) ? /* @__PURE__ */ n(
638
- ie,
651
+ !l && /* @__PURE__ */ s("div", { className: "flex shrink-0 items-center gap-1 sm:pt-px", children: /* @__PURE__ */ o(
652
+ "button",
639
653
  {
640
- collection: t,
641
- field: h,
642
- relations: f.relations,
643
- context: {},
644
- value: x,
645
- onChange: c
654
+ ref: v,
655
+ type: "button",
656
+ "data-default-set": e,
657
+ "aria-label": `Set a default for ${b}`,
658
+ disabled: !y,
659
+ onClick: () => c(!0),
660
+ className: $(Y, "disabled:opacity-50"),
661
+ children: [
662
+ /* @__PURE__ */ s(ge, { className: "h-3 w-3" }),
663
+ " Set"
664
+ ]
646
665
  }
647
- ) : d && !(f != null && f.ready) ? /* @__PURE__ */ n(D, { className: "h-8 w-full" }) : null,
648
- y && /* @__PURE__ */ n("p", { role: "alert", className: "text-[11.5px] text-red-600 dark:text-red-400", children: y }),
649
- /* @__PURE__ */ p("div", { className: "flex items-center justify-between gap-2", children: [
650
- /* @__PURE__ */ n("p", { className: "text-[11px] text-slate-500 dark:text-slate-400", children: "Checked as them: they must be able to set the field and pick the value." }),
651
- /* @__PURE__ */ n(
652
- oe,
653
- {
654
- canSave: !!h && !M(x),
655
- pending: b.isPending,
656
- onCancel: i,
657
- onSave: () => b.mutate({ collection: t, field: d, value: x, context: {} })
658
- }
659
- )
660
- ] })
666
+ ) })
661
667
  ]
662
668
  }
663
669
  );
664
670
  }
665
671
  export {
666
- wt as MyDefaultsCard
672
+ ot as MyDefaultsCard
667
673
  };