@nivaro/react 0.2.52 → 0.2.54

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 (191) hide show
  1. package/dist/full.css +1 -1
  2. package/dist/hooks/useSessionRecorder.js +1 -1
  3. package/dist/index.d.ts +116 -2
  4. package/dist/layout-editor.d.ts +248 -2
  5. package/dist/shared/components/FormWhatsNew.js +60 -0
  6. package/dist/shared/components/ItemEditForm.js +3994 -3876
  7. package/dist/shared/components/RecordReadView.js +219 -211
  8. package/dist/shared/components/TipLayer.js +27 -27
  9. package/dist/shared/components/help-videos/api.js +51 -41
  10. package/dist/shared/components/help-videos/editor/DetailsTab.js +147 -130
  11. package/dist/shared/components/item-edit/FieldAffordances.js +7 -6
  12. package/dist/shared/components/item-edit/FieldRow.js +353 -304
  13. package/dist/shared/components/item-edit/FormHelpVideoButton.js +59 -0
  14. package/dist/shared/components/item-edit/GroupSection.js +419 -396
  15. package/dist/shared/components/item-edit/HeaderTools.js +59 -56
  16. package/dist/shared/components/item-edit/LayoutContentBlock.js +47 -24
  17. package/dist/shared/components/item-edit/lock-why.js +87 -0
  18. package/dist/shared/components/item-edit/useFormUsageBeacon.js +59 -0
  19. package/dist/shared/components/layout-editor/AddPanel.js +204 -146
  20. package/dist/shared/components/layout-editor/ArrangeButton.js +34 -0
  21. package/dist/shared/components/layout-editor/AutoArrange.js +86 -0
  22. package/dist/shared/components/layout-editor/CanvasCompare.js +79 -0
  23. package/dist/shared/components/layout-editor/ChangeNote.js +146 -0
  24. package/dist/shared/components/layout-editor/CollabParts.js +170 -0
  25. package/dist/shared/components/layout-editor/DesignNode.js +304 -115
  26. package/dist/shared/components/layout-editor/EditorCanvas.js +21 -20
  27. package/dist/shared/components/layout-editor/EditorTopBar.js +452 -175
  28. package/dist/shared/components/layout-editor/FindReplace.js +188 -0
  29. package/dist/shared/components/layout-editor/FormMapButton.js +141 -0
  30. package/dist/shared/components/layout-editor/HistoryPanel.js +234 -109
  31. package/dist/shared/components/layout-editor/LayoutEditor.js +1101 -307
  32. package/dist/shared/components/layout-editor/LayoutsRail.js +94 -67
  33. package/dist/shared/components/layout-editor/NoteMarker.js +38 -0
  34. package/dist/shared/components/layout-editor/PlacementsTable.js +187 -0
  35. package/dist/shared/components/layout-editor/ScheduleChange.js +106 -0
  36. package/dist/shared/components/layout-editor/SessionHistory.js +84 -0
  37. package/dist/shared/components/layout-editor/StructureMenu.js +413 -0
  38. package/dist/shared/components/layout-editor/UnsavedConfirm.js +103 -0
  39. package/dist/shared/components/layout-editor/ai/AiToolsButton.js +625 -0
  40. package/dist/shared/components/layout-editor/ai/ChangeCheck.js +153 -0
  41. package/dist/shared/components/layout-editor/ai/ai-tools-api.js +80 -0
  42. package/dist/shared/components/layout-editor/ai/assist-ops.js +38 -0
  43. package/dist/shared/components/layout-editor/ai/autofill-ops.js +73 -0
  44. package/dist/shared/components/layout-editor/ai/canvas-capture.js +41 -0
  45. package/dist/shared/components/layout-editor/ai-forms/AiComposer.js +271 -0
  46. package/dist/shared/components/layout-editor/ai-forms/AiFormsButton.js +182 -0
  47. package/dist/shared/components/layout-editor/ai-forms/MeaningSuggestions.js +109 -0
  48. package/dist/shared/components/layout-editor/ai-forms/SlimPanel.js +170 -0
  49. package/dist/shared/components/layout-editor/ai-forms/ai-forms-api.js +40 -0
  50. package/dist/shared/components/layout-editor/ai-forms/pending.js +25 -0
  51. package/dist/shared/components/layout-editor/ai-forms/plan.js +263 -0
  52. package/dist/shared/components/layout-editor/ai-rules/AiAskPopover.js +160 -0
  53. package/dist/shared/components/layout-editor/ai-rules/CascadeWriter.js +175 -0
  54. package/dist/shared/components/layout-editor/ai-rules/FieldRuleWriter.js +97 -0
  55. package/dist/shared/components/layout-editor/ai-rules/RuleWriter.js +94 -0
  56. package/dist/shared/components/layout-editor/ai-rules/ValidationSuggest.js +153 -0
  57. package/dist/shared/components/layout-editor/ai-rules/api.js +6 -0
  58. package/dist/shared/components/layout-editor/ai-text/AiTextTools.js +383 -0
  59. package/dist/shared/components/layout-editor/ai-text/text-ops.js +125 -0
  60. package/dist/shared/components/layout-editor/assist/AskPanel.js +278 -0
  61. package/dist/shared/components/layout-editor/assist/ExplainDiff.js +93 -0
  62. package/dist/shared/components/layout-editor/assist/ProposalsButton.js +150 -0
  63. package/dist/shared/components/layout-editor/assist/assist-api.js +63 -0
  64. package/dist/shared/components/layout-editor/assist/jump.js +142 -0
  65. package/dist/shared/components/layout-editor/assist/settings-index.js +118 -0
  66. package/dist/shared/components/layout-editor/auto-arrange.js +101 -0
  67. package/dist/shared/components/layout-editor/bulk/BulkChangesButton.js +221 -0
  68. package/dist/shared/components/layout-editor/bulk/BulkRun.js +237 -0
  69. package/dist/shared/components/layout-editor/bulk/MacrosPanel.js +230 -0
  70. package/dist/shared/components/layout-editor/bulk/bulk-api.js +65 -0
  71. package/dist/shared/components/layout-editor/bulk/field-labels.js +22 -0
  72. package/dist/shared/components/layout-editor/bulk/macro-record.js +142 -0
  73. package/dist/shared/components/layout-editor/bulk/useMacroRecorder.js +65 -0
  74. package/dist/shared/components/layout-editor/bundle-to-active.js +1 -0
  75. package/dist/shared/components/layout-editor/canvas-diff.js +157 -0
  76. package/dist/shared/components/layout-editor/collab/FormFollowShare.js +342 -0
  77. package/dist/shared/components/layout-editor/collab/collab-api.js +77 -0
  78. package/dist/shared/components/layout-editor/commands/CommandPalette.js +221 -0
  79. package/dist/shared/components/layout-editor/commands/intents.js +214 -0
  80. package/dist/shared/components/layout-editor/commands/parse.js +242 -0
  81. package/dist/shared/components/layout-editor/design-context.js +26 -6
  82. package/dist/shared/components/layout-editor/dnd/LayoutDndProvider.js +179 -163
  83. package/dist/shared/components/layout-editor/dnd/collision.js +25 -23
  84. package/dist/shared/components/layout-editor/dnd/rail-drop.js +56 -0
  85. package/dist/shared/components/layout-editor/draft-recovery.js +61 -0
  86. package/dist/shared/components/layout-editor/editor-notes.js +78 -0
  87. package/dist/shared/components/layout-editor/editors/swap-config.js +1 -0
  88. package/dist/shared/components/layout-editor/explain/CanvasRules.js +142 -0
  89. package/dist/shared/components/layout-editor/explain/default-ghosts.js +81 -0
  90. package/dist/shared/components/layout-editor/explain/driver-hover.js +62 -0
  91. package/dist/shared/components/layout-editor/explain/field-sources.js +246 -0
  92. package/dist/shared/components/layout-editor/explain/rule-graph.js +215 -0
  93. package/dist/shared/components/layout-editor/explain/use-explain.js +132 -0
  94. package/dist/shared/components/layout-editor/field-zones.js +116 -0
  95. package/dist/shared/components/layout-editor/form-map.js +138 -0
  96. package/dist/shared/components/layout-editor/history-api.js +87 -0
  97. package/dist/shared/components/layout-editor/inheritance.js +55 -0
  98. package/dist/shared/components/layout-editor/inspect/inspect-api.js +66 -0
  99. package/dist/shared/components/layout-editor/inspect/picker-preview.js +48 -0
  100. package/dist/shared/components/layout-editor/inspect/width-fit.js +87 -0
  101. package/dist/shared/components/layout-editor/inspector/AiFillSetting.js +85 -0
  102. package/dist/shared/components/layout-editor/inspector/Breadcrumb.js +36 -0
  103. package/dist/shared/components/layout-editor/inspector/BulkInspector.js +175 -0
  104. package/dist/shared/components/layout-editor/inspector/ColumnFit.js +112 -0
  105. package/dist/shared/components/layout-editor/inspector/GroupInspector.js +146 -92
  106. package/dist/shared/components/layout-editor/inspector/HelpTab.js +174 -0
  107. package/dist/shared/components/layout-editor/inspector/Inspector.js +256 -175
  108. package/dist/shared/components/layout-editor/inspector/LookTab.js +46 -40
  109. package/dist/shared/components/layout-editor/inspector/OverrideNotice.js +61 -0
  110. package/dist/shared/components/layout-editor/inspector/PickerPreview.js +134 -0
  111. package/dist/shared/components/layout-editor/inspector/PickerTab.js +167 -141
  112. package/dist/shared/components/layout-editor/inspector/RulesTab.js +175 -128
  113. package/dist/shared/components/layout-editor/inspector/Translations.js +156 -0
  114. package/dist/shared/components/layout-editor/inspector/kit.js +3 -3
  115. package/dist/shared/components/layout-editor/inspector/tab-request.js +21 -0
  116. package/dist/shared/components/layout-editor/is-typing.js +9 -0
  117. package/dist/shared/components/layout-editor/keyboard-move.js +66 -0
  118. package/dist/shared/components/layout-editor/lint/LintPanel.js +190 -0
  119. package/dist/shared/components/layout-editor/lint/lint-api.js +52 -0
  120. package/dist/shared/components/layout-editor/load-error.js +37 -0
  121. package/dist/shared/components/layout-editor/matrix/FieldStateMatrix.js +305 -0
  122. package/dist/shared/components/layout-editor/matrix/MatrixGrid.js +181 -0
  123. package/dist/shared/components/layout-editor/matrix/RoleSectionMatrix.js +147 -0
  124. package/dist/shared/components/layout-editor/matrix/matrix-api.js +48 -0
  125. package/dist/shared/components/layout-editor/matrix/role-matrix.js +36 -0
  126. package/dist/shared/components/layout-editor/matrix/state-matrix.js +145 -0
  127. package/dist/shared/components/layout-editor/nav/FindPanel.js +109 -0
  128. package/dist/shared/components/layout-editor/nav/NavTools.js +114 -0
  129. package/dist/shared/components/layout-editor/nav/OutlinePanel.js +228 -0
  130. package/dist/shared/components/layout-editor/nav/ShortcutSheet.js +31 -0
  131. package/dist/shared/components/layout-editor/nav/find.js +20 -0
  132. package/dist/shared/components/layout-editor/nav/tree.js +142 -0
  133. package/dist/shared/components/layout-editor/nav/useEditorNav.js +101 -0
  134. package/dist/shared/components/layout-editor/nav/view-prefs.js +34 -0
  135. package/dist/shared/components/layout-editor/ops/ChangeRequestsPanel.js +143 -0
  136. package/dist/shared/components/layout-editor/ops/DependencyDiagram.js +179 -0
  137. package/dist/shared/components/layout-editor/ops/LayoutOpsBlocks.js +92 -0
  138. package/dist/shared/components/layout-editor/ops/PromotePanel.js +287 -0
  139. package/dist/shared/components/layout-editor/ops/ops-api.js +122 -0
  140. package/dist/shared/components/layout-editor/overview/OverviewActions.js +15 -3
  141. package/dist/shared/components/layout-editor/overview/describe-conditions.js +18 -14
  142. package/dist/shared/components/layout-editor/overview/overview-api.js +105 -88
  143. package/dist/shared/components/layout-editor/panel-style.js +8 -7
  144. package/dist/shared/components/layout-editor/parity-keys.json.js +4 -0
  145. package/dist/shared/components/layout-editor/pin.js +25 -0
  146. package/dist/shared/components/layout-editor/presence.js +111 -0
  147. package/dist/shared/components/layout-editor/preview/PreviewModes.js +224 -0
  148. package/dist/shared/components/layout-editor/preview/PreviewPanes.js +262 -0
  149. package/dist/shared/components/layout-editor/preview/preview-api.js +57 -0
  150. package/dist/shared/components/layout-editor/preview/preview-model.js +157 -0
  151. package/dist/shared/components/layout-editor/reuse/FieldMapStep.js +70 -0
  152. package/dist/shared/components/layout-editor/reuse/FormMoreMenu.js +127 -0
  153. package/dist/shared/components/layout-editor/reuse/LibraryRows.js +150 -0
  154. package/dist/shared/components/layout-editor/reuse/NewFormStart.js +20 -0
  155. package/dist/shared/components/layout-editor/reuse/SectionReuseActions.js +291 -0
  156. package/dist/shared/components/layout-editor/reuse/field-match.js +77 -0
  157. package/dist/shared/components/layout-editor/reuse/reuse-api.js +73 -0
  158. package/dist/shared/components/layout-editor/reuse/seed.js +13 -0
  159. package/dist/shared/components/layout-editor/reuse/useFormFromRecord.js +43 -0
  160. package/dist/shared/components/layout-editor/reuse/useRailCopy.js +34 -0
  161. package/dist/shared/components/layout-editor/settings/FormSettings.js +123 -103
  162. package/dist/shared/components/layout-editor/settings/InheritanceSection.js +1 -1
  163. package/dist/shared/components/layout-editor/settings/ToolsSection.js +174 -100
  164. package/dist/shared/components/layout-editor/settings/WhoSection.js +136 -100
  165. package/dist/shared/components/layout-editor/settings/controls.js +8 -8
  166. package/dist/shared/components/layout-editor/settings/settings-registry.js +35 -11
  167. package/dist/shared/components/layout-editor/shortcuts.js +88 -0
  168. package/dist/shared/components/layout-editor/show-when.js +35 -0
  169. package/dist/shared/components/layout-editor/slot-names.js +4 -3
  170. package/dist/shared/components/layout-editor/structure-ops.js +399 -0
  171. package/dist/shared/components/layout-editor/testing/CostLimitSetting.js +42 -0
  172. package/dist/shared/components/layout-editor/testing/TestingPanels.js +551 -0
  173. package/dist/shared/components/layout-editor/testing/testing-api.js +67 -0
  174. package/dist/shared/components/layout-editor/testing/testing-model.js +393 -0
  175. package/dist/shared/components/layout-editor/testing/use-record-check.js +44 -0
  176. package/dist/shared/components/layout-editor/toolbar-kit.js +242 -0
  177. package/dist/shared/components/layout-editor/unsaved-marks.js +72 -0
  178. package/dist/shared/components/layout-editor/usage/FillChip.js +27 -0
  179. package/dist/shared/components/layout-editor/usage/UsagePanel.js +158 -0
  180. package/dist/shared/components/layout-editor/usage/suggest-sections.js +55 -0
  181. package/dist/shared/components/layout-editor/usage/usage-api.js +104 -0
  182. package/dist/shared/components/layout-editor/useLayoutDraft.js +573 -307
  183. package/dist/shared/components/support/SuggestFormChange.js +143 -0
  184. package/dist/shared/lib/ai-fill.js +37 -0
  185. package/dist/shared/lib/form-usage-beacon.js +84 -0
  186. package/dist/shared/lib/layout-i18n.js +66 -0
  187. package/dist/shared/lib/layout-lint.js +490 -0
  188. package/dist/shared/lib/layout-ops.js +110 -106
  189. package/dist/shared/lib/screenshot.js +54 -28
  190. package/dist/shared/lib/visible-when.js +34 -0
  191. package/package.json +1 -1
@@ -1,43 +1,53 @@
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}`;
1
+ import { jsxs as s, jsx as a, Fragment as X } from "react/jsx-runtime";
2
+ import { useQueryClient as Z, useQuery as M, useMutation as U } from "@tanstack/react-query";
3
+ import { Bookmark as Q } from "lucide-react";
4
+ import { useState as h } from "react";
5
+ import { toast as G } from "sonner";
6
+ import { useNivaroClient as I } from "../../context.js";
7
+ import { get as P, post as ee } from "../../lib/commands.js";
8
+ import { ExplainDiffButton as te } from "./assist/ExplainDiff.js";
9
+ import { useVersionNaming as ae, fetchVersionBundle as ne } from "./history-api.js";
10
+ import { SessionHistory as re } from "./SessionHistory.js";
11
+ import { slotName as se } from "./slot-names.js";
12
+ import { layoutDraftKeys as A, parseSaveFailure as R } from "./useLayoutDraft.js";
13
+ function oe(t) {
14
+ return /^before\b/i.test(t) ? t : `Before: ${t}`;
9
15
  }
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
+ const V = A.versions, ie = A.bundle;
17
+ function N(t) {
18
+ if (t == null || t === "") return "empty";
19
+ if (typeof t == "object") {
20
+ const r = JSON.stringify(t);
21
+ return r.length > 60 ? `${r.slice(0, 57)}…` : r;
16
22
  }
17
- return String(e);
23
+ return String(t);
18
24
  }
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;
25
+ const D = (t) => t.map((r) => `${r.field} ${N(r.from)} → ${N(r.to)}`), F = (t) => t.startsWith("__") ? se(t) : t;
26
+ function le(t) {
27
+ const r = [];
28
+ for (const n of t.layout)
29
+ r.push({ kind: "Form", text: `${n.field}: ${N(n.from)} → ${N(n.to)}` });
30
+ for (const n of t.groups.added) r.push({ kind: "Group added", text: n });
31
+ for (const n of t.groups.removed) r.push({ kind: "Group removed", text: n });
32
+ for (const n of t.groups.changed)
33
+ r.push({ kind: "Group", text: `${n.label}: ${D(n.changes).join(" · ")}` });
34
+ for (const n of t.assignments.added) r.push({ kind: "Field added", text: F(n) });
35
+ for (const n of t.assignments.removed)
36
+ r.push({ kind: "Field removed", text: F(n) });
37
+ for (const n of t.assignments.changed)
38
+ r.push({
39
+ kind: "Field",
40
+ text: `${F(n.label)}: ${D(n.changes).join(" · ")}`
41
+ });
42
+ return r;
33
43
  }
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(
44
+ function de({ diff: t }) {
45
+ const [r, n] = h(!1);
46
+ if (t.total === 0)
47
+ return /* @__PURE__ */ a("p", { className: "mt-1 text-[12px] text-slate-500 dark:text-slate-400", children: "Nothing differs from that version. The form is exactly as it was saved." });
48
+ const l = le(t), x = r ? l : l.slice(0, 12);
49
+ return /* @__PURE__ */ s("div", { className: "mt-1", children: [
50
+ t.warnings.map((o) => /* @__PURE__ */ a(
41
51
  "p",
42
52
  {
43
53
  "data-layout-diff-warning": !0,
@@ -46,134 +56,249 @@ function Q({ diff: e }) {
46
56
  },
47
57
  o
48
58
  )),
49
- /* @__PURE__ */ r("p", { className: "text-[12px] text-slate-500 dark:text-slate-400", children: [
50
- e.total,
59
+ /* @__PURE__ */ s("p", { className: "text-[12px] text-slate-500 dark:text-slate-400", children: [
60
+ t.total,
51
61
  " change",
52
- e.total === 1 ? "" : "s",
53
- e.from.created_at ? ` since ${new Date(e.from.created_at).toLocaleString()}` : ""
62
+ t.total === 1 ? "" : "s",
63
+ t.from.created_at ? ` since ${new Date(t.from.created_at).toLocaleString()}` : ""
54
64
  ] }),
55
- /* @__PURE__ */ s("ul", { className: "mt-1 space-y-0.5", children: l.map((o, m) => (
65
+ /* @__PURE__ */ a("ul", { className: "mt-1 space-y-0.5", children: x.map((o, d) => (
56
66
  // 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)
67
+ /* @__PURE__ */ s("li", { className: "flex gap-2 text-[12px]", children: [
68
+ /* @__PURE__ */ a("span", { className: "w-24 shrink-0 text-[11px] text-slate-500 dark:text-slate-400", children: o.kind }),
69
+ /* @__PURE__ */ a("span", { className: "min-w-0 break-words text-slate-700 dark:text-slate-200", children: o.text })
70
+ ] }, d)
61
71
  )) }),
62
- i.length > 12 && /* @__PURE__ */ s(
72
+ l.length > 12 && /* @__PURE__ */ a(
63
73
  "button",
64
74
  {
65
75
  type: "button",
66
- onClick: () => a((o) => !o),
76
+ onClick: () => n((o) => !o),
67
77
  className: "mt-1 text-[11px] text-slate-500 underline dark:text-slate-400",
68
- children: t ? "Show fewer" : `Show all ${i.length}`
78
+ children: r ? "Show fewer" : `Show all ${l.length}`
69
79
  }
70
80
  )
71
81
  ] });
72
82
  }
73
- function B({
74
- layoutId: e,
75
- onRestored: t
83
+ function ve({
84
+ layoutId: t,
85
+ onRestored: r,
86
+ unsavedCount: n = 0,
87
+ onDiscardUnsaved: l,
88
+ session: x,
89
+ onJump: o,
90
+ onShowOnCanvas: d
76
91
  }) {
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 ?? []),
92
+ const g = I(), k = Z(), [f, _] = h(null), [H, v] = h(null), { data: c = [], isLoading: O } = M({
93
+ queryKey: V(t),
94
+ queryFn: () => g.request(P(`/collection-layouts/${t}/versions`)).then((e) => e.data ?? []),
80
95
  staleTime: 0,
81
96
  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,
97
+ }), m = f ?? (c.length > 0 ? "newest" : null), { data: u, isLoading: W } = M({
98
+ queryKey: ["layout-editor", "version-diff", t, m],
99
+ queryFn: () => g.request(
100
+ P(`/collection-layouts/${t}/versions/${m}/diff`, { against: "current" })
101
+ ).then((e) => e.data),
102
+ enabled: m != null,
88
103
  staleTime: 0,
89
104
  refetchOnMount: "always"
90
- }), c = F({
91
- mutationFn: (n) => a.request(K(`/collection-layouts/${e}/versions/${n}/restore`)),
105
+ }), b = U({
106
+ mutationFn: (e) => g.request(ee(`/collection-layouts/${t}/versions/${e}/restore`)),
92
107
  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();
108
+ v(null), l == null || l(), k.invalidateQueries({ queryKey: ie(t) }), k.invalidateQueries({ queryKey: V(t) }), k.invalidateQueries({ queryKey: ["layout-editor", "version-diff", t] }), r == null || r();
94
109
  }
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
- )
110
+ }), y = c.find((e) => e.id === f), { nameVersion: Y, nameCurrent: z } = ae(t), [w, $] = h(null), [S, q] = h(""), [C, K] = h(null), L = (e, i = "") => {
111
+ $(e), q(i);
112
+ }, j = () => {
113
+ const e = w, i = S.trim();
114
+ if ($(null), e == null) return;
115
+ const E = { onError: (J) => G.error(R(J, "Not named").message) };
116
+ e === "current" ? i && z.mutate(i, E) : Y.mutate({ versionId: e, name: i || null }, E);
117
+ }, T = async (e) => {
118
+ if (d) {
119
+ K(e.id);
120
+ try {
121
+ const i = await ne(g, t, e.id);
122
+ d(i, e.name ? `“${e.name}” (v${e.version})` : `version ${e.version}`);
123
+ } catch (i) {
124
+ G.error(R(i, "That version could not be read").message);
125
+ } finally {
126
+ K(null);
127
+ }
128
+ }
129
+ }, B = /* @__PURE__ */ a(
130
+ "input",
131
+ {
132
+ autoFocus: !0,
133
+ "aria-label": "Version name",
134
+ value: S,
135
+ maxLength: 120,
136
+ placeholder: "e.g. Go-live baseline",
137
+ onChange: (e) => q(e.target.value),
138
+ onKeyDown: (e) => {
139
+ e.key === "Enter" && j(), e.key === "Escape" && (e.stopPropagation(), $(null));
140
+ },
141
+ onBlur: j,
142
+ className: "h-6 w-full min-w-0 rounded border border-nvr-cyan bg-white px-1.5 text-[12px] outline-none dark:bg-background dark:text-foreground"
143
+ }
144
+ ), p = "rounded border border-slate-200 px-1.5 py-0.5 text-[11px] hover:bg-slate-50 dark:border-border dark:hover:bg-muted";
145
+ return /* @__PURE__ */ s("div", { className: "flex flex-col gap-2 text-[12px]", "data-layout-history": !0, children: [
146
+ x && o && /* @__PURE__ */ a(re, { session: x, onJump: o }),
147
+ c.length > 0 && /* @__PURE__ */ s("div", { className: "rounded-lg border border-slate-200 bg-slate-50 p-2 dark:border-border dark:bg-muted/40", children: [
148
+ /* @__PURE__ */ s("div", { className: "flex items-center justify-between gap-2", children: [
149
+ /* @__PURE__ */ a("p", { className: "text-[11px] font-semibold text-slate-600 dark:text-slate-300", children: f == null ? "What the last save changed" : `Version ${(y == null ? void 0 : y.version) ?? "?"} compared with now` }),
150
+ /* @__PURE__ */ s("span", { className: "flex items-center gap-2", children: [
151
+ d && u && u.total > 0 && /* @__PURE__ */ a(
152
+ "button",
153
+ {
154
+ type: "button",
155
+ "data-show-on-canvas": "",
156
+ disabled: C != null,
157
+ onClick: () => {
158
+ const e = y ?? c[0];
159
+ e && T(e);
160
+ },
161
+ "data-tip": "Mark what differs on the form itself: added, moved, changed, removed",
162
+ className: "text-[11px] text-slate-600 underline dark:text-slate-300",
163
+ children: "Show on canvas"
164
+ }
165
+ ),
166
+ f != null && /* @__PURE__ */ a(
167
+ "button",
168
+ {
169
+ type: "button",
170
+ onClick: () => _(null),
171
+ className: "text-[11px] text-slate-500 underline dark:text-slate-400",
172
+ children: "Show last save"
173
+ }
174
+ )
175
+ ] })
109
176
  ] }),
110
- C && /* @__PURE__ */ s("p", { className: "mt-1 text-slate-500", children: "Comparing…" }),
111
- y && /* @__PURE__ */ s(Q, { diff: y })
177
+ W && /* @__PURE__ */ a("p", { className: "mt-1 text-slate-500", children: "Comparing…" }),
178
+ u && /* @__PURE__ */ a(de, { diff: u }),
179
+ u && u.total > 0 && m != null && /* @__PURE__ */ a(
180
+ te,
181
+ {
182
+ className: "mt-2",
183
+ a: { layout_id: t, version: m },
184
+ b: { layout_id: t, version: "current" }
185
+ },
186
+ String(m)
187
+ )
112
188
  ] }),
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(
189
+ b.isError && /* @__PURE__ */ a("p", { className: "text-[12px] text-[#9c2f47] dark:text-[#f08aa1]", children: "Restore failed. Nothing was changed." }),
190
+ /* @__PURE__ */ a("div", { className: "flex items-center gap-2", "data-name-current": "", children: w === "current" ? B : /* @__PURE__ */ s(
191
+ "button",
192
+ {
193
+ type: "button",
194
+ onClick: () => L("current"),
195
+ "data-tip": "Keep the form as it is saved now, under a name, beyond the rolling 30 versions",
196
+ className: `${p} inline-flex items-center gap-1`,
197
+ children: [
198
+ /* @__PURE__ */ a(Q, { className: "h-3 w-3" }),
199
+ "Name the saved form…"
200
+ ]
201
+ }
202
+ ) }),
203
+ O ? /* @__PURE__ */ a("p", { className: "text-slate-500", children: "Loading history…" }) : c.length === 0 ? /* @__PURE__ */ a("p", { className: "text-slate-500 dark:text-slate-400", children: "No versions yet. One is saved before every change." }) : /* @__PURE__ */ a("ul", { className: "max-h-64 space-y-1 overflow-y-auto", children: c.map((e) => /* @__PURE__ */ s(
115
204
  "li",
116
205
  {
117
206
  className: "flex items-center justify-between gap-2 rounded border border-slate-100 px-2 py-1 dark:border-border/60",
118
207
  children: [
119
- /* @__PURE__ */ r("span", { className: "min-w-0", children: [
120
- /* @__PURE__ */ r("span", { className: "font-medium", children: [
208
+ /* @__PURE__ */ s("span", { className: "min-w-0 flex-1", children: [
209
+ w === e.id ? B : e.name && /* @__PURE__ */ s(
210
+ "span",
211
+ {
212
+ "data-version-name": e.name,
213
+ "data-tip": "Named: kept beyond the rolling 30 versions",
214
+ className: "mr-1 inline-flex max-w-full items-center gap-0.5 rounded bg-slate-100 px-1 text-[11px] font-medium text-slate-700 dark:bg-muted dark:text-slate-200",
215
+ children: [
216
+ /* @__PURE__ */ a(Q, { className: "h-3 w-3 shrink-0" }),
217
+ /* @__PURE__ */ a("span", { className: "truncate", children: e.name })
218
+ ]
219
+ }
220
+ ),
221
+ /* @__PURE__ */ s("span", { className: "font-medium", children: [
121
222
  "v",
122
- n.version
223
+ e.version
123
224
  ] }),
124
225
  " ",
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}` : ""
226
+ /* @__PURE__ */ s("span", { className: "text-slate-500 dark:text-slate-400", children: [
227
+ e.note ? `${oe(e.note)} · ` : "",
228
+ new Date(e.created_at).toLocaleString(),
229
+ e.created_by_name ? ` · ${e.created_by_name}` : ""
129
230
  ] })
130
231
  ] }),
131
- /* @__PURE__ */ r("span", { className: "flex shrink-0 items-center gap-1", children: [
132
- /* @__PURE__ */ s(
232
+ /* @__PURE__ */ s("span", { className: "flex shrink-0 items-center gap-1", children: [
233
+ /* @__PURE__ */ a(
234
+ "button",
235
+ {
236
+ type: "button",
237
+ "data-version-name-edit": e.version,
238
+ onClick: () => L(e.id, e.name ?? ""),
239
+ "data-tip": e.name ? "Rename, or clear the name to let it be pruned again" : "Name this version so it is kept beyond the rolling 30",
240
+ className: p,
241
+ children: e.name ? "Rename" : "Name"
242
+ }
243
+ ),
244
+ /* @__PURE__ */ a(
133
245
  "button",
134
246
  {
135
247
  type: "button",
136
- "data-tip": "See what differs from the layout now",
137
- "data-version-diff": n.version,
248
+ "data-tip": "See what differs from the form now",
249
+ "data-version-diff": e.version,
138
250
  "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" : ""}`,
251
+ onClick: () => _(e.id),
252
+ className: `${p} ${f === e.id ? "border-nvr-cyan text-nvr-navy dark:text-nvr-cyan" : ""}`,
141
253
  children: "Compare"
142
254
  }
143
255
  ),
144
- m === n.id ? /* @__PURE__ */ r(q, { children: [
145
- /* @__PURE__ */ s(
256
+ d && /* @__PURE__ */ a(
257
+ "button",
258
+ {
259
+ type: "button",
260
+ "data-version-canvas": e.version,
261
+ disabled: C != null,
262
+ onClick: () => void T(e),
263
+ "data-tip": "Mark on the form what differs from this version",
264
+ className: p,
265
+ children: C === e.id ? "…" : "Canvas"
266
+ }
267
+ ),
268
+ H === e.id ? /* @__PURE__ */ s(X, { children: [
269
+ /* @__PURE__ */ a(
146
270
  "button",
147
271
  {
148
272
  type: "button",
149
- "data-restore-confirm": n.id,
150
- disabled: c.isPending,
151
- onClick: () => c.mutate(n.id),
273
+ "data-restore-confirm": e.id,
274
+ disabled: b.isPending,
275
+ onClick: () => b.mutate(e.id),
276
+ "data-tip": n > 0 ? `Your ${n} unsaved ${n === 1 ? "change is" : "changes are"} dropped` : void 0,
152
277
  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"
278
+ children: b.isPending ? "Restoring…" : n > 0 ? "Restore, drop unsaved" : "Yes, restore"
154
279
  }
155
280
  ),
156
- /* @__PURE__ */ s("button", { type: "button", onClick: () => p(null), className: f, children: "Cancel" })
157
- ] }) : /* @__PURE__ */ s(
281
+ /* @__PURE__ */ a("button", { type: "button", onClick: () => v(null), className: p, children: "Cancel" })
282
+ ] }) : /* @__PURE__ */ a(
158
283
  "button",
159
284
  {
160
285
  type: "button",
161
- "data-restore": n.id,
286
+ "data-restore": e.id,
162
287
  "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,
288
+ "data-tip": "Replace the form with this version. The current one is kept as a version first.",
289
+ onClick: () => v(e.id),
290
+ className: p,
166
291
  children: "Restore"
167
292
  }
168
293
  )
169
294
  ] })
170
295
  ]
171
296
  },
172
- n.id
297
+ e.id
173
298
  )) })
174
299
  ] });
175
300
  }
176
301
  export {
177
- B as HistoryPanel,
178
- L as versionNoteLabel
302
+ ve as HistoryPanel,
303
+ oe as versionNoteLabel
179
304
  };