@nivaro/react 0.2.51 → 0.2.53

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 (117) hide show
  1. package/dist/full.css +1 -1
  2. package/dist/hooks/useSessionRecorder.js +1 -1
  3. package/dist/index.d.ts +207 -6
  4. package/dist/index.js +442 -439
  5. package/dist/layout-editor.d.ts +80 -0
  6. package/dist/layout-editor.js +11 -0
  7. package/dist/shared/components/ItemEditForm.js +4015 -3835
  8. package/dist/shared/components/RecordDrilldownSheet.js +114 -97
  9. package/dist/shared/components/RecordReadView.js +637 -570
  10. package/dist/shared/components/ai/ExplainButton.js +1 -1
  11. package/dist/shared/components/item-edit/GroupSection.js +489 -466
  12. package/dist/shared/components/item-edit/HeaderBand.js +47 -44
  13. package/dist/shared/components/item-edit/M2MStagingContext.js +3 -3
  14. package/dist/shared/components/item-edit/O2MStagingContext.js +1 -1
  15. package/dist/shared/components/item-edit/RecordGrantTools.js +206 -0
  16. package/dist/shared/components/item-edit/StepsBar.js +49 -43
  17. package/dist/shared/components/item-edit/SummaryPanel.js +1 -1
  18. package/dist/shared/components/item-edit/config-update.js +6 -0
  19. package/dist/shared/components/item-edit/layout-editing-quiet.js +25 -0
  20. package/dist/shared/components/layout-editor/AddPanel.js +301 -0
  21. package/dist/shared/components/layout-editor/DesignNode.js +173 -0
  22. package/dist/shared/components/layout-editor/EditorCanvas.js +52 -0
  23. package/dist/shared/components/layout-editor/EditorTopBar.js +241 -0
  24. package/dist/shared/components/layout-editor/HistoryPanel.js +179 -0
  25. package/dist/shared/components/layout-editor/LayoutEditor.js +393 -0
  26. package/dist/shared/components/layout-editor/LayoutsRail.js +89 -0
  27. package/dist/shared/components/layout-editor/add-target.js +103 -0
  28. package/dist/shared/components/layout-editor/bundle-to-active.js +86 -0
  29. package/dist/shared/components/layout-editor/canvases/PdfCanvas.js +90 -0
  30. package/dist/shared/components/layout-editor/canvases/TableColumnsCanvas.js +246 -0
  31. package/dist/shared/components/layout-editor/collection-meta.js +22 -0
  32. package/dist/shared/components/layout-editor/design-canvas.js +81 -0
  33. package/dist/shared/components/layout-editor/design-context.js +21 -0
  34. package/dist/shared/components/layout-editor/dnd/LayoutDndProvider.js +225 -0
  35. package/dist/shared/components/layout-editor/dnd/collision.js +107 -0
  36. package/dist/shared/components/layout-editor/dnd/node.js +164 -0
  37. package/dist/shared/components/layout-editor/dnd/order.js +122 -0
  38. package/dist/shared/components/layout-editor/editors/DefaultValuesEditor.js +223 -0
  39. package/dist/shared/components/layout-editor/editors/QuickPickerStepsEditor.js +129 -0
  40. package/dist/shared/components/layout-editor/editors/ReadPresentationEditor.js +134 -0
  41. package/dist/shared/components/layout-editor/editors/RecordConditionsEditor.js +249 -0
  42. package/dist/shared/components/layout-editor/editors/RolesPicker.js +77 -0
  43. package/dist/shared/components/layout-editor/editors/cascade-filters.js +556 -0
  44. package/dist/shared/components/layout-editor/editors/cascade-rule-row.js +150 -0
  45. package/dist/shared/components/layout-editor/editors/controls.js +73 -0
  46. package/dist/shared/components/layout-editor/editors/editor-api.js +21 -0
  47. package/dist/shared/components/layout-editor/editors/editor-queries.js +25 -0
  48. package/dist/shared/components/layout-editor/editors/field-default-value.js +131 -0
  49. package/dist/shared/components/layout-editor/editors/grid-presets.js +310 -0
  50. package/dist/shared/components/layout-editor/editors/inline-display.js +157 -0
  51. package/dist/shared/components/layout-editor/editors/layout-picker.js +80 -0
  52. package/dist/shared/components/layout-editor/editors/layout-rows.js +55 -0
  53. package/dist/shared/components/layout-editor/editors/lock-conditions.js +109 -0
  54. package/dist/shared/components/layout-editor/editors/o2m-agg-field.js +25 -0
  55. package/dist/shared/components/layout-editor/editors/pdf-field-config.js +107 -0
  56. package/dist/shared/components/layout-editor/editors/report-widget-config.js +94 -0
  57. package/dist/shared/components/layout-editor/editors/row-rule-check.js +225 -0
  58. package/dist/shared/components/layout-editor/editors/row-rule-row.js +1353 -0
  59. package/dist/shared/components/layout-editor/editors/swap-config.js +245 -0
  60. package/dist/shared/components/layout-editor/focus-buffer.js +32 -0
  61. package/dist/shared/components/layout-editor/host.js +15 -0
  62. package/dist/shared/components/layout-editor/inspector/AdvancedTab.js +296 -0
  63. package/dist/shared/components/layout-editor/inspector/GridTab.js +767 -0
  64. package/dist/shared/components/layout-editor/inspector/GroupInspector.js +456 -0
  65. package/dist/shared/components/layout-editor/inspector/HeaderItemInspector.js +268 -0
  66. package/dist/shared/components/layout-editor/inspector/Inspector.js +332 -0
  67. package/dist/shared/components/layout-editor/inspector/LookTab.js +310 -0
  68. package/dist/shared/components/layout-editor/inspector/PickerTab.js +333 -0
  69. package/dist/shared/components/layout-editor/inspector/RulesTab.js +323 -0
  70. package/dist/shared/components/layout-editor/inspector/SlotInspector.js +179 -0
  71. package/dist/shared/components/layout-editor/inspector/SubtitleInspector.js +154 -0
  72. package/dist/shared/components/layout-editor/inspector/WidgetInspector.js +262 -0
  73. package/dist/shared/components/layout-editor/inspector/applies.js +27 -0
  74. package/dist/shared/components/layout-editor/inspector/field-context.js +134 -0
  75. package/dist/shared/components/layout-editor/inspector/interfaces.js +126 -0
  76. package/dist/shared/components/layout-editor/inspector/kit.js +595 -0
  77. package/dist/shared/components/layout-editor/inspector/model.js +307 -0
  78. package/dist/shared/components/layout-editor/overview/OverviewActions.js +15 -0
  79. package/dist/shared/components/layout-editor/overview/describe-conditions.js +121 -0
  80. package/dist/shared/components/layout-editor/overview/overview-api.js +141 -0
  81. package/dist/shared/components/layout-editor/overview/purpose.js +62 -0
  82. package/dist/shared/components/layout-editor/overview/record-count.js +65 -0
  83. package/dist/shared/components/layout-editor/panel-frame.js +99 -0
  84. package/dist/shared/components/layout-editor/panel-style.js +19 -0
  85. package/dist/shared/components/layout-editor/pickers/field-picker.js +230 -0
  86. package/dist/shared/components/layout-editor/pickers/icon-picker.js +233 -0
  87. package/dist/shared/components/layout-editor/pickers/relation-label.js +34 -0
  88. package/dist/shared/components/layout-editor/pickers/relation-picker.js +136 -0
  89. package/dist/shared/components/layout-editor/record-queries.js +15 -0
  90. package/dist/shared/components/layout-editor/settings/AddendumSection.js +52 -0
  91. package/dist/shared/components/layout-editor/settings/ButtonsSection.js +45 -0
  92. package/dist/shared/components/layout-editor/settings/DefaultsSection.js +67 -0
  93. package/dist/shared/components/layout-editor/settings/FormSettings.js +146 -0
  94. package/dist/shared/components/layout-editor/settings/InheritanceSection.js +37 -0
  95. package/dist/shared/components/layout-editor/settings/LayoutSection.js +70 -0
  96. package/dist/shared/components/layout-editor/settings/PdfSection.js +176 -0
  97. package/dist/shared/components/layout-editor/settings/ReadSection.js +79 -0
  98. package/dist/shared/components/layout-editor/settings/TextSetting.js +55 -0
  99. package/dist/shared/components/layout-editor/settings/ToggleSetting.js +33 -0
  100. package/dist/shared/components/layout-editor/settings/ToolsSection.js +179 -0
  101. package/dist/shared/components/layout-editor/settings/WhoSection.js +213 -0
  102. package/dist/shared/components/layout-editor/settings/controls.js +214 -0
  103. package/dist/shared/components/layout-editor/settings/section-props.js +17 -0
  104. package/dist/shared/components/layout-editor/settings/settings-api.js +151 -0
  105. package/dist/shared/components/layout-editor/settings/settings-registry.js +445 -0
  106. package/dist/shared/components/layout-editor/slot-names.js +20 -0
  107. package/dist/shared/components/layout-editor/summary-pref.js +21 -0
  108. package/dist/shared/components/layout-editor/useLayoutDraft.js +474 -0
  109. package/dist/shared/components/pipeline/relations.js +28 -23
  110. package/dist/shared/components/ui/popover.js +17 -17
  111. package/dist/shared/components/ui/scroll-area.js +38 -0
  112. package/dist/shared/hooks/useRelationOptions.js +60 -0
  113. package/dist/shared/lib/layout-grants.js +9 -0
  114. package/dist/shared/lib/layout-ops.js +348 -0
  115. package/dist/shared/lib/layout-slots.js +11 -7
  116. package/dist/shared/lib/request-gate.js +1 -1
  117. package/package.json +5 -1
@@ -0,0 +1,241 @@
1
+ import { jsxs as a, jsx as e, Fragment as O } from "react/jsx-runtime";
2
+ import { ChevronLeft as T, Undo2 as j, Redo2 as B, Eye as E, History as Z, UserRound as A, X as I } from "lucide-react";
3
+ import { useState as N, useMemo as D } from "react";
4
+ import { useNivaroClient as H } from "../../context.js";
5
+ import { useDebounced as $ } from "../../hooks/useDebounced.js";
6
+ import { useRelationOptions as F } from "../../hooks/useRelationOptions.js";
7
+ import { cn as g } from "../../lib/utils.js";
8
+ import { Popover as P, PopoverTrigger as R, PopoverContent as L } from "../ui/popover.js";
9
+ import { SimpleSelect as M } from "../ui/SimpleSelect.js";
10
+ import { HistoryPanel as X } from "./HistoryPanel.js";
11
+ import { useRuleChoiceLabels as Y, useDisplayTemplate as _, useRoleNames as q } from "./overview/overview-api.js";
12
+ import { rowPill as z, purposeSegments as G, TYPE_USE as y, Pill as J, Sentence as K } from "./overview/purpose.js";
13
+ const C = "inline-flex h-8 w-8 items-center justify-center rounded-md text-slate-600 transition-colors hover:bg-muted hover:text-slate-900 disabled:pointer-events-none disabled:opacity-40 dark:text-muted-foreground dark:hover:text-foreground", U = "inline-flex h-8 max-w-[220px] items-center gap-1.5 whitespace-nowrap rounded-md border border-slate-200 bg-white px-2.5 text-[12.5px] font-medium text-slate-700 transition-colors hover:bg-slate-50 dark:border-border dark:bg-card dark:text-foreground dark:hover:bg-muted", Q = "h-8 w-full rounded-md border border-slate-200 bg-white px-2.5 text-[12.5px] text-slate-800 outline-none placeholder:text-slate-400 focus:border-nvr-cyan dark:border-border dark:bg-background dark:text-foreground dark:placeholder:text-muted-foreground", S = "mb-1 block text-[11.5px] font-semibold text-slate-600 dark:text-muted-foreground";
14
+ function V({ draft: s }) {
15
+ const { status: t, error: l } = s, i = t === "saving" ? "Saving…" : t === "error" ? l ?? "Not saved" : t === "conflict" ? "Reloaded — someone else saved" : "Saved";
16
+ return /* @__PURE__ */ e(
17
+ "span",
18
+ {
19
+ role: "status",
20
+ "data-save-status": t,
21
+ "data-tip": t === "error" && l ? l : void 0,
22
+ className: g(
23
+ "inline-flex max-w-[260px] items-center truncate whitespace-nowrap rounded-full px-2 py-px text-[11px] font-semibold",
24
+ t === "saving" && "bg-slate-100 text-slate-600 dark:bg-muted dark:text-muted-foreground",
25
+ (t === "saved" || t === "idle") && "bg-emerald-50 text-emerald-700 dark:bg-emerald-500/15 dark:text-emerald-300",
26
+ t === "error" && "bg-red-50 text-red-700 dark:bg-red-500/15 dark:text-red-300",
27
+ t === "conflict" && "bg-amber-50 text-amber-700 dark:bg-amber-500/15 dark:text-amber-300"
28
+ ),
29
+ children: i
30
+ }
31
+ );
32
+ }
33
+ function W({
34
+ collection: s,
35
+ value: t,
36
+ onChange: l
37
+ }) {
38
+ var c, b;
39
+ const i = H(), [o, m] = N(!1), [n, f] = N(""), k = $(n, 250), { data: d } = _(s, o), { data: u = [] } = q(!0), { options: p, loading: v } = F(o ? i : null, s, {
40
+ search: k,
41
+ limit: 8,
42
+ displayTemplate: d ?? null,
43
+ enabled: o && d !== void 0
44
+ }), h = ((c = u.find((r) => r.id === t.roleId)) == null ? void 0 : c.name) ?? null, x = [(b = t.record) == null ? void 0 : b.label, h].filter(Boolean).join(" · ") || "No record";
45
+ return /* @__PURE__ */ a(P, { open: o, onOpenChange: m, children: [
46
+ /* @__PURE__ */ e("span", { className: "hidden text-[12px] text-slate-500 lg:inline dark:text-muted-foreground", children: "Preview as" }),
47
+ /* @__PURE__ */ e(R, { asChild: !0, children: /* @__PURE__ */ a(
48
+ "button",
49
+ {
50
+ type: "button",
51
+ className: U,
52
+ "aria-label": "Preview as",
53
+ "data-tip": "Show the form with a real record’s values, as a role sees it",
54
+ children: [
55
+ /* @__PURE__ */ e(A, { className: "h-3.5 w-3.5 shrink-0" }),
56
+ /* @__PURE__ */ e("span", { className: "truncate", children: x })
57
+ ]
58
+ }
59
+ ) }),
60
+ /* @__PURE__ */ a(L, { align: "end", className: "w-[320px] p-3", children: [
61
+ /* @__PURE__ */ e("p", { className: S, children: "Record" }),
62
+ t.record ? /* @__PURE__ */ a("span", { className: "inline-flex max-w-full items-center gap-1.5 rounded-full bg-nvr-cyan/10 px-2.5 py-1 text-[12px] font-medium text-slate-800 dark:text-foreground", children: [
63
+ /* @__PURE__ */ e("span", { className: "truncate", children: t.record.label }),
64
+ /* @__PURE__ */ e(
65
+ "button",
66
+ {
67
+ type: "button",
68
+ "aria-label": "Preview without a record",
69
+ onClick: () => l({ ...t, record: null }),
70
+ className: "text-slate-500 hover:text-slate-800 dark:text-muted-foreground dark:hover:text-foreground",
71
+ children: /* @__PURE__ */ e(I, { className: "h-3 w-3" })
72
+ }
73
+ )
74
+ ] }) : /* @__PURE__ */ a(O, { children: [
75
+ /* @__PURE__ */ e(
76
+ "input",
77
+ {
78
+ value: n,
79
+ onChange: (r) => f(r.target.value),
80
+ placeholder: "Search records…",
81
+ "aria-label": "Search records",
82
+ className: Q
83
+ }
84
+ ),
85
+ /* @__PURE__ */ a("div", { className: "mt-1 max-h-[220px] overflow-y-auto overscroll-contain", children: [
86
+ p.map((r) => /* @__PURE__ */ e(
87
+ "button",
88
+ {
89
+ type: "button",
90
+ onClick: () => l({ ...t, record: { id: String(r.id), label: r.label } }),
91
+ className: "block w-full truncate rounded px-2 py-1.5 text-left text-[12.5px] text-slate-700 hover:bg-muted dark:text-foreground",
92
+ children: r.label
93
+ },
94
+ String(r.id)
95
+ )),
96
+ !v && p.length === 0 && /* @__PURE__ */ e("p", { className: "px-2 py-1.5 text-[12px] text-slate-500 dark:text-muted-foreground", children: "No records match." })
97
+ ] })
98
+ ] }),
99
+ /* @__PURE__ */ e("p", { className: g(S, "mt-3"), children: "As a role" }),
100
+ /* @__PURE__ */ e(
101
+ M,
102
+ {
103
+ value: t.roleId ?? "",
104
+ onChange: (r) => l({ ...t, roleId: r || null }),
105
+ ariaLabel: "Preview as role",
106
+ className: "h-8 text-[12.5px]",
107
+ options: [
108
+ { value: "", label: "Any role" },
109
+ ...u.map((r) => ({ value: r.id, label: r.name }))
110
+ ]
111
+ }
112
+ ),
113
+ /* @__PURE__ */ e("p", { className: "mt-2 text-[11.5px] leading-snug text-slate-500 dark:text-muted-foreground", children: "The form shows this record’s values, steps and rules. Nothing you do here changes the record." })
114
+ ] })
115
+ ] });
116
+ }
117
+ function ue({
118
+ collection: s,
119
+ layoutId: t,
120
+ layoutName: l,
121
+ layoutType: i,
122
+ row: o,
123
+ fields: m,
124
+ draft: n,
125
+ preview: f,
126
+ onPreview: k,
127
+ showHidden: d,
128
+ onShowHidden: u,
129
+ onBack: p,
130
+ backLabel: v = "Layouts"
131
+ }) {
132
+ const [h, x] = N(!1), c = o ? z(o) : null, b = D(() => o ? [o] : [], [o]), r = Y(s, m, b), w = o ? G(o, m, r) : y[i] ? [{ text: y[i] }] : [];
133
+ return /* @__PURE__ */ a(
134
+ "header",
135
+ {
136
+ "data-editor-topbar": "",
137
+ className: "flex shrink-0 flex-wrap items-center gap-x-2.5 gap-y-1.5 border-b border-slate-200 bg-white px-3 py-2 dark:border-border dark:bg-card",
138
+ children: [
139
+ /* @__PURE__ */ a(
140
+ "button",
141
+ {
142
+ type: "button",
143
+ onClick: p,
144
+ className: "inline-flex h-8 items-center gap-0.5 rounded-md pl-1 pr-2 text-[12px] text-slate-500 transition-colors hover:bg-muted hover:text-slate-800 dark:text-muted-foreground dark:hover:text-foreground",
145
+ children: [
146
+ /* @__PURE__ */ e(T, { className: "h-4 w-4" }),
147
+ v
148
+ ]
149
+ }
150
+ ),
151
+ /* @__PURE__ */ a("div", { className: "flex min-w-0 flex-1 items-center gap-2", children: [
152
+ /* @__PURE__ */ e("h2", { className: "truncate text-[14px] font-semibold text-slate-900 dark:text-foreground", children: l }),
153
+ c && /* @__PURE__ */ e(J, { tone: c.tone, children: c.text }),
154
+ w.length > 0 && /* @__PURE__ */ a("span", { className: "hidden min-w-0 truncate text-[12px] text-slate-500 md:inline dark:text-muted-foreground", children: [
155
+ "· ",
156
+ /* @__PURE__ */ e(K, { segs: w, muted: !0 })
157
+ ] })
158
+ ] }),
159
+ /* @__PURE__ */ a("div", { className: "flex items-center gap-0.5", children: [
160
+ /* @__PURE__ */ e(
161
+ "button",
162
+ {
163
+ type: "button",
164
+ "aria-label": "Undo",
165
+ className: C,
166
+ disabled: !n.canUndo,
167
+ onClick: n.undo,
168
+ "data-tip": n.undoLabel ? `Undo ${n.undoLabel} (⌘Z)` : "Undo (⌘Z)",
169
+ children: /* @__PURE__ */ e(j, { className: "h-4 w-4" })
170
+ }
171
+ ),
172
+ /* @__PURE__ */ e(
173
+ "button",
174
+ {
175
+ type: "button",
176
+ "aria-label": "Redo",
177
+ className: C,
178
+ disabled: !n.canRedo,
179
+ onClick: n.redo,
180
+ "data-tip": n.redoLabel ? `Redo ${n.redoLabel} (⇧⌘Z)` : "Redo (⇧⌘Z)",
181
+ children: /* @__PURE__ */ e(B, { className: "h-4 w-4" })
182
+ }
183
+ )
184
+ ] }),
185
+ /* @__PURE__ */ e(W, { collection: s, value: f, onChange: k }),
186
+ /* @__PURE__ */ a(
187
+ "label",
188
+ {
189
+ className: "inline-flex h-8 cursor-pointer items-center gap-1.5 text-[12px] text-slate-600 dark:text-muted-foreground",
190
+ "data-tip": "Show fields and sections the preview would hide, faintly, so you can select them",
191
+ children: [
192
+ /* @__PURE__ */ e(E, { className: "h-3.5 w-3.5" }),
193
+ "Show hidden",
194
+ /* @__PURE__ */ e(
195
+ "button",
196
+ {
197
+ type: "button",
198
+ role: "switch",
199
+ "aria-checked": d,
200
+ "aria-label": "Show hidden",
201
+ onClick: () => u(!d),
202
+ className: g(
203
+ "relative h-4 w-7 shrink-0 rounded-full transition-colors",
204
+ d ? "bg-nvr-cyan" : "bg-slate-300 dark:bg-border"
205
+ ),
206
+ children: /* @__PURE__ */ e(
207
+ "span",
208
+ {
209
+ className: g(
210
+ "absolute left-0 top-0.5 h-3 w-3 rounded-full bg-white transition-transform",
211
+ d ? "translate-x-3.5" : "translate-x-0.5"
212
+ )
213
+ }
214
+ )
215
+ }
216
+ )
217
+ ]
218
+ }
219
+ ),
220
+ /* @__PURE__ */ a(P, { open: h, onOpenChange: x, children: [
221
+ /* @__PURE__ */ e(R, { asChild: !0, children: /* @__PURE__ */ a("button", { type: "button", className: U, "aria-label": "History", children: [
222
+ /* @__PURE__ */ e(Z, { className: "h-3.5 w-3.5" }),
223
+ "History"
224
+ ] }) }),
225
+ /* @__PURE__ */ e(
226
+ L,
227
+ {
228
+ align: "end",
229
+ className: "max-h-[min(70vh,560px)] w-[400px] overflow-y-auto overscroll-contain p-0",
230
+ children: h && /* @__PURE__ */ e(X, { layoutId: t, onRestored: () => x(!1) })
231
+ }
232
+ )
233
+ ] }),
234
+ /* @__PURE__ */ e(V, { draft: n })
235
+ ]
236
+ }
237
+ );
238
+ }
239
+ export {
240
+ ue as EditorTopBar
241
+ };
@@ -0,0 +1,179 @@
1
+ import { jsxs as r, jsx as s, Fragment as q } from "react/jsx-runtime";
2
+ import { useQueryClient as S, useQuery as b, useMutation as F } from "@tanstack/react-query";
3
+ import { useState as g } from "react";
4
+ import { useNivaroClient as _ } from "../../context.js";
5
+ import { get as k, post as K } from "../../lib/commands.js";
6
+ import { layoutDraftKeys as v } from "./useLayoutDraft.js";
7
+ function L(e) {
8
+ return /^before\b/i.test(e) ? e : `Before: ${e}`;
9
+ }
10
+ const N = v.versions, j = v.bundle;
11
+ function u(e) {
12
+ if (e == null || e === "") return "empty";
13
+ if (typeof e == "object") {
14
+ const t = JSON.stringify(e);
15
+ return t.length > 60 ? `${t.slice(0, 57)}…` : t;
16
+ }
17
+ return String(e);
18
+ }
19
+ const w = (e) => e.map((t) => `${t.field} ${u(t.from)} → ${u(t.to)}`);
20
+ function D(e) {
21
+ const t = [];
22
+ for (const a of e.layout)
23
+ t.push({ kind: "Layout", text: `${a.field}: ${u(a.from)} → ${u(a.to)}` });
24
+ for (const a of e.groups.added) t.push({ kind: "Group added", text: a });
25
+ for (const a of e.groups.removed) t.push({ kind: "Group removed", text: a });
26
+ for (const a of e.groups.changed)
27
+ t.push({ kind: "Group", text: `${a.label}: ${w(a.changes).join(" · ")}` });
28
+ for (const a of e.assignments.added) t.push({ kind: "Field added", text: a });
29
+ for (const a of e.assignments.removed) t.push({ kind: "Field removed", text: a });
30
+ for (const a of e.assignments.changed)
31
+ t.push({ kind: "Field", text: `${a.label}: ${w(a.changes).join(" · ")}` });
32
+ return t;
33
+ }
34
+ function Q({ diff: e }) {
35
+ const [t, a] = g(!1);
36
+ if (e.total === 0)
37
+ return /* @__PURE__ */ s("p", { className: "mt-1 text-[12px] text-slate-500 dark:text-slate-400", children: "Nothing differs from that version. The layout is exactly as it was saved." });
38
+ const i = D(e), l = t ? i : i.slice(0, 12);
39
+ return /* @__PURE__ */ r("div", { className: "mt-1", children: [
40
+ e.warnings.map((o) => /* @__PURE__ */ s(
41
+ "p",
42
+ {
43
+ "data-layout-diff-warning": !0,
44
+ className: "mb-1 rounded bg-[#fae6eb] px-1.5 py-1 text-[12px] text-[#9c2f47] dark:bg-[#3d1621] dark:text-[#f08aa1]",
45
+ children: o
46
+ },
47
+ o
48
+ )),
49
+ /* @__PURE__ */ r("p", { className: "text-[12px] text-slate-500 dark:text-slate-400", children: [
50
+ e.total,
51
+ " change",
52
+ e.total === 1 ? "" : "s",
53
+ e.from.created_at ? ` since ${new Date(e.from.created_at).toLocaleString()}` : ""
54
+ ] }),
55
+ /* @__PURE__ */ s("ul", { className: "mt-1 space-y-0.5", children: l.map((o, m) => (
56
+ // biome-ignore lint/suspicious/noArrayIndexKey: ordered diff rows
57
+ /* @__PURE__ */ r("li", { className: "flex gap-2 text-[12px]", children: [
58
+ /* @__PURE__ */ s("span", { className: "w-24 shrink-0 text-[11px] text-slate-500 dark:text-slate-400", children: o.kind }),
59
+ /* @__PURE__ */ s("span", { className: "min-w-0 break-words text-slate-700 dark:text-slate-200", children: o.text })
60
+ ] }, m)
61
+ )) }),
62
+ i.length > 12 && /* @__PURE__ */ s(
63
+ "button",
64
+ {
65
+ type: "button",
66
+ onClick: () => a((o) => !o),
67
+ className: "mt-1 text-[11px] text-slate-500 underline dark:text-slate-400",
68
+ children: t ? "Show fewer" : `Show all ${i.length}`
69
+ }
70
+ )
71
+ ] });
72
+ }
73
+ function B({
74
+ layoutId: e,
75
+ onRestored: t
76
+ }) {
77
+ const a = _(), i = S(), [l, o] = g(null), [m, p] = g(null), { data: d = [], isLoading: $ } = b({
78
+ queryKey: N(e),
79
+ queryFn: () => a.request(k(`/collection-layouts/${e}/versions`)).then((n) => n.data ?? []),
80
+ staleTime: 0,
81
+ refetchOnMount: "always"
82
+ }), h = l ?? (d.length > 0 ? "newest" : null), { data: y, isLoading: C } = b({
83
+ queryKey: ["layout-editor", "version-diff", e, h],
84
+ queryFn: () => a.request(
85
+ k(`/collection-layouts/${e}/versions/${h}/diff`, { against: "current" })
86
+ ).then((n) => n.data),
87
+ enabled: h != null,
88
+ staleTime: 0,
89
+ refetchOnMount: "always"
90
+ }), c = F({
91
+ mutationFn: (n) => a.request(K(`/collection-layouts/${e}/versions/${n}/restore`)),
92
+ onSuccess: () => {
93
+ p(null), i.invalidateQueries({ queryKey: j(e) }), i.invalidateQueries({ queryKey: N(e) }), i.invalidateQueries({ queryKey: ["layout-editor", "version-diff", e] }), t == null || t();
94
+ }
95
+ }), x = d.find((n) => n.id === l), f = "rounded border border-slate-200 px-1.5 py-0.5 text-[11px] hover:bg-slate-50 dark:border-border dark:hover:bg-muted";
96
+ return /* @__PURE__ */ r("div", { className: "flex flex-col gap-2 text-[12px]", "data-layout-history": !0, children: [
97
+ d.length > 0 && /* @__PURE__ */ r("div", { className: "rounded-lg border border-slate-200 bg-slate-50 p-2 dark:border-border dark:bg-muted/40", children: [
98
+ /* @__PURE__ */ r("div", { className: "flex items-center justify-between gap-2", children: [
99
+ /* @__PURE__ */ s("p", { className: "text-[11px] font-semibold text-slate-600 dark:text-slate-300", children: l == null ? "What the last save changed" : `Version ${(x == null ? void 0 : x.version) ?? "?"} compared with now` }),
100
+ l != null && /* @__PURE__ */ s(
101
+ "button",
102
+ {
103
+ type: "button",
104
+ onClick: () => o(null),
105
+ className: "text-[11px] text-slate-500 underline dark:text-slate-400",
106
+ children: "Show last save"
107
+ }
108
+ )
109
+ ] }),
110
+ C && /* @__PURE__ */ s("p", { className: "mt-1 text-slate-500", children: "Comparing…" }),
111
+ y && /* @__PURE__ */ s(Q, { diff: y })
112
+ ] }),
113
+ c.isError && /* @__PURE__ */ s("p", { className: "text-[12px] text-[#9c2f47] dark:text-[#f08aa1]", children: "Restore failed. Nothing was changed." }),
114
+ $ ? /* @__PURE__ */ s("p", { className: "text-slate-500", children: "Loading history…" }) : d.length === 0 ? /* @__PURE__ */ s("p", { className: "text-slate-500 dark:text-slate-400", children: "No versions yet. One is saved before every change." }) : /* @__PURE__ */ s("ul", { className: "max-h-48 space-y-1 overflow-y-auto", children: d.map((n) => /* @__PURE__ */ r(
115
+ "li",
116
+ {
117
+ className: "flex items-center justify-between gap-2 rounded border border-slate-100 px-2 py-1 dark:border-border/60",
118
+ children: [
119
+ /* @__PURE__ */ r("span", { className: "min-w-0", children: [
120
+ /* @__PURE__ */ r("span", { className: "font-medium", children: [
121
+ "v",
122
+ n.version
123
+ ] }),
124
+ " ",
125
+ /* @__PURE__ */ r("span", { className: "text-slate-500 dark:text-slate-400", children: [
126
+ n.note ? `${L(n.note)} · ` : "",
127
+ new Date(n.created_at).toLocaleString(),
128
+ n.created_by_name ? ` · ${n.created_by_name}` : ""
129
+ ] })
130
+ ] }),
131
+ /* @__PURE__ */ r("span", { className: "flex shrink-0 items-center gap-1", children: [
132
+ /* @__PURE__ */ s(
133
+ "button",
134
+ {
135
+ type: "button",
136
+ "data-tip": "See what differs from the layout now",
137
+ "data-version-diff": n.version,
138
+ "data-setting": "tool.version_diff",
139
+ onClick: () => o(n.id),
140
+ className: `${f} ${l === n.id ? "border-nvr-cyan text-nvr-navy dark:text-nvr-cyan" : ""}`,
141
+ children: "Compare"
142
+ }
143
+ ),
144
+ m === n.id ? /* @__PURE__ */ r(q, { children: [
145
+ /* @__PURE__ */ s(
146
+ "button",
147
+ {
148
+ type: "button",
149
+ "data-restore-confirm": n.id,
150
+ disabled: c.isPending,
151
+ onClick: () => c.mutate(n.id),
152
+ className: "rounded bg-nvr-cyan px-1.5 py-0.5 text-[11px] text-white disabled:opacity-60",
153
+ children: c.isPending ? "Restoring…" : "Yes, restore"
154
+ }
155
+ ),
156
+ /* @__PURE__ */ s("button", { type: "button", onClick: () => p(null), className: f, children: "Cancel" })
157
+ ] }) : /* @__PURE__ */ s(
158
+ "button",
159
+ {
160
+ type: "button",
161
+ "data-restore": n.id,
162
+ "data-setting": "tool.version_restore",
163
+ "data-tip": "Replace the layout with this version. The current one is kept as a version first.",
164
+ onClick: () => p(n.id),
165
+ className: f,
166
+ children: "Restore"
167
+ }
168
+ )
169
+ ] })
170
+ ]
171
+ },
172
+ n.id
173
+ )) })
174
+ ] });
175
+ }
176
+ export {
177
+ B as HistoryPanel,
178
+ L as versionNoteLabel
179
+ };