@nivaro/react 0.2.53 → 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 +113 -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 +4058 -3942
  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
@@ -0,0 +1,625 @@
1
+ import { jsxs as a, jsx as e } from "react/jsx-runtime";
2
+ import { useQuery as Q } from "@tanstack/react-query";
3
+ import { Sparkles as U, UserRound as X, ScanEye as J, FileCheck2 as V, Loader2 as G, X as Y } from "lucide-react";
4
+ import { useState as x, useRef as Z, useMemo as z, useEffect as ee } from "react";
5
+ import { useNivaroClient as E } from "../../../context.js";
6
+ import { get as te, post as H } from "../../../lib/commands.js";
7
+ import { titleCase as j, cn as S } from "../../../lib/utils.js";
8
+ import { Popover as ae, PopoverContent as re } from "../../ui/popover.js";
9
+ import { SimpleSelect as se } from "../../ui/SimpleSelect.js";
10
+ import { useLayoutEditorHost as ne } from "../host.js";
11
+ import { withOverride as oe } from "../inspector/model.js";
12
+ import { useOverviewFields as le, useRoleNames as ie } from "../overview/overview-api.js";
13
+ import { useBarMenu as de, ToolButton as P } from "../toolbar-kit.js";
14
+ import { parseSaveFailure as ce } from "../useLayoutDraft.js";
15
+ import { targetFromRef as $, sectionTarget as ue, personaPins as me, critiquePins as pe, FORM_TARGET as he } from "./ai-tools-api.js";
16
+ import { placedFields as fe, hasAutofillCheck as ge, planApplies as O, highlightPlan as M, checkSectionPlan as be } from "./autofill-ops.js";
17
+ import { canvasRoot as xe, measureSections as ye, captureCanvas as ke } from "./canvas-capture.js";
18
+ const k = "text-[12px] leading-snug text-slate-500 dark:text-muted-foreground", L = "inline-flex h-7 items-center gap-1.5 rounded-md bg-nvr-cyan px-3 text-[12px] font-medium text-white transition-opacity hover:opacity-90 disabled:pointer-events-none disabled:opacity-40", I = "inline-flex h-7 items-center gap-1 rounded-md px-2 text-[12px] font-medium 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", Ne = [
19
+ {
20
+ tab: "persona",
21
+ label: "Test as a role",
22
+ hint: "AI fills a new record as a role and says what confused it",
23
+ icon: /* @__PURE__ */ e(X, { className: "h-3.5 w-3.5" })
24
+ },
25
+ {
26
+ tab: "critique",
27
+ label: "Review the look",
28
+ hint: "Density, hierarchy and alignment of the canvas",
29
+ icon: /* @__PURE__ */ e(J, { className: "h-3.5 w-3.5" })
30
+ },
31
+ {
32
+ tab: "autofill",
33
+ label: "Tune from autofill",
34
+ hint: "Fields people often correct after Fill from document",
35
+ icon: /* @__PURE__ */ e(V, { className: "h-3.5 w-3.5" })
36
+ }
37
+ ], W = {
38
+ blocking: "bg-amber-50 text-amber-800 dark:bg-amber-500/15 dark:text-amber-200",
39
+ high: "bg-amber-50 text-amber-800 dark:bg-amber-500/15 dark:text-amber-200",
40
+ confusing: "bg-violet-50 text-violet-800 dark:bg-violet-500/15 dark:text-violet-200",
41
+ medium: "bg-violet-50 text-violet-800 dark:bg-violet-500/15 dark:text-violet-200",
42
+ minor: "bg-slate-100 text-slate-600 dark:bg-muted dark:text-muted-foreground",
43
+ low: "bg-slate-100 text-slate-600 dark:bg-muted dark:text-muted-foreground"
44
+ }, ve = {
45
+ clear: "bg-emerald-500",
46
+ unsure: "bg-amber-400",
47
+ stuck: "bg-red-500"
48
+ };
49
+ function D({ tone: g, children: o }) {
50
+ return /* @__PURE__ */ e(
51
+ "span",
52
+ {
53
+ className: S(
54
+ "inline-flex h-[18px] shrink-0 items-center rounded px-1.5 text-[10.5px] font-medium",
55
+ W[g] ?? W.minor
56
+ ),
57
+ children: o
58
+ }
59
+ );
60
+ }
61
+ function B(g, o) {
62
+ const c = ce(g, o);
63
+ return c.status === 503 ? "AI is not set up here — set it up under Settings → AI Features." : c.message;
64
+ }
65
+ function ze({
66
+ collection: g,
67
+ layoutId: o,
68
+ bundle: c,
69
+ apply: N,
70
+ previewRecordShown: R,
71
+ onPins: d,
72
+ onSelect: q
73
+ }) {
74
+ const A = ne(), b = de(), [_, u] = x(!1), [l, v] = x("persona"), w = Z(null), { data: y = [] } = le(g), i = z(() => {
75
+ const n = new Map(y.map((p) => {
76
+ var C;
77
+ return [p.field, ((C = p.label) == null ? void 0 : C.trim()) || j(p.field)];
78
+ }));
79
+ return (p) => n.get(p) ?? j(p);
80
+ }, [y]);
81
+ if (ee(() => {
82
+ d([]);
83
+ }, [o, d]), !A.isAdmin) return null;
84
+ const r = (n, p) => /* @__PURE__ */ e(
85
+ "button",
86
+ {
87
+ type: "button",
88
+ role: "tab",
89
+ "aria-selected": l === n,
90
+ "data-ai-tools-tab": n,
91
+ onClick: () => v(n),
92
+ className: S(
93
+ "inline-flex h-7 items-center rounded-md px-2.5 text-[12px] font-medium transition-colors",
94
+ l === n ? "bg-accent text-slate-900 dark:text-foreground" : "text-slate-500 hover:bg-muted hover:text-slate-800 dark:text-muted-foreground dark:hover:text-foreground"
95
+ ),
96
+ children: p
97
+ }
98
+ ), T = (n) => {
99
+ n && q(n);
100
+ };
101
+ return /* @__PURE__ */ a(ae, { open: _, onOpenChange: u, children: [
102
+ b ? Ne.map((n) => /* @__PURE__ */ e(
103
+ P,
104
+ {
105
+ popover: !0,
106
+ onOpen: () => {
107
+ v(n.tab), u(!0);
108
+ },
109
+ label: n.label,
110
+ icon: n.icon,
111
+ hint: n.hint,
112
+ disabled: !c,
113
+ data: { "data-ai-tools-row": n.tab }
114
+ },
115
+ n.tab
116
+ )) : /* @__PURE__ */ e(
117
+ P,
118
+ {
119
+ popover: !0,
120
+ buttonRef: (n) => {
121
+ w.current = n;
122
+ },
123
+ label: "AI",
124
+ ariaLabel: "AI tools",
125
+ icon: /* @__PURE__ */ e(U, { className: "h-3.5 w-3.5 text-nvr-cyan" }),
126
+ tip: "Test the form as a role, review its look, tune it from autofill",
127
+ disabled: !c,
128
+ data: { "data-ai-tools-trigger": "" }
129
+ }
130
+ ),
131
+ /* @__PURE__ */ a(re, { align: "end", className: "w-[460px] overflow-hidden p-0", "data-ai-tools": "", children: [
132
+ /* @__PURE__ */ a(
133
+ "div",
134
+ {
135
+ role: "tablist",
136
+ "aria-label": "AI tools",
137
+ className: "flex items-center gap-1 border-b border-slate-200 px-2 py-1.5 dark:border-border",
138
+ children: [
139
+ r("persona", "Test as a role"),
140
+ r("critique", "Review the look"),
141
+ r("autofill", "Tune from autofill")
142
+ ]
143
+ }
144
+ ),
145
+ /* @__PURE__ */ a("div", { className: "max-h-[min(65vh,520px)] overflow-y-auto overscroll-contain px-3 py-3", children: [
146
+ c && l === "persona" && /* @__PURE__ */ e(
147
+ we,
148
+ {
149
+ layoutId: o,
150
+ bundle: c,
151
+ apply: N,
152
+ labelOf: i,
153
+ onPins: d,
154
+ select: T
155
+ }
156
+ ),
157
+ c && l === "critique" && /* @__PURE__ */ e(
158
+ Ce,
159
+ {
160
+ layoutId: o,
161
+ bundle: c,
162
+ previewRecordShown: R,
163
+ editor: () => {
164
+ var n;
165
+ return ((n = w.current ?? (b == null ? void 0 : b.anchor.current)) == null ? void 0 : n.closest("[data-layout-editor]")) ?? null;
166
+ },
167
+ onPins: d,
168
+ select: T
169
+ }
170
+ ),
171
+ c && l === "autofill" && /* @__PURE__ */ e(Ae, { layoutId: o, bundle: c, apply: N, labelOf: i })
172
+ ] })
173
+ ] })
174
+ ] });
175
+ }
176
+ function we({
177
+ layoutId: g,
178
+ bundle: o,
179
+ apply: c,
180
+ labelOf: N,
181
+ onPins: R,
182
+ select: d
183
+ }) {
184
+ const q = E(), { data: A = [] } = ie(!0), [b, _] = x(""), [u, l] = x(""), [v, w] = x(!1), [y, i] = x(null), [r, T] = x(null), [n, p] = x(/* @__PURE__ */ new Set()), C = async () => {
185
+ if (b) {
186
+ w(!0), i(null);
187
+ try {
188
+ const t = await q.request(
189
+ H(`/ai-design/layouts/${g}/persona-test`, {
190
+ role_id: b,
191
+ goal: u.trim() || void 0
192
+ })
193
+ );
194
+ T(t.data), p(/* @__PURE__ */ new Set()), R(me(t.data, o));
195
+ } catch (t) {
196
+ i(B(t, "The persona test could not run"));
197
+ } finally {
198
+ w(!1);
199
+ }
200
+ }
201
+ }, s = (t) => {
202
+ const h = $(t.target, o);
203
+ if ((h == null ? void 0 : h.kind) !== "field" || !t.better_label) return;
204
+ const f = o.placements.find((F) => F.field === h.field && F.group_key === h.group_key);
205
+ f && (c(
206
+ [
207
+ {
208
+ op: "update_placement",
209
+ at: { field: f.field, group_key: f.group_key },
210
+ patch: { overrides: oe(f, "label", t.better_label) }
211
+ }
212
+ ],
213
+ { label: `Rename ${N(f.field)} to ${t.better_label}` }
214
+ ), p((F) => new Set(F).add(t.id)));
215
+ }, m = (t) => {
216
+ var h;
217
+ return ((h = r == null ? void 0 : r.walkthrough.find((f) => f.key === t)) == null ? void 0 : h.label) ?? null;
218
+ };
219
+ return /* @__PURE__ */ a("div", { className: "space-y-3", "data-persona-test": "", children: [
220
+ /* @__PURE__ */ e("p", { className: k, children: "The AI plays someone in a role filling in a new record, step by step, and tells you where they would hesitate. Only the form's labels, help and structure are sent. Nothing is saved." }),
221
+ /* @__PURE__ */ a("div", { className: "flex items-center gap-2", children: [
222
+ /* @__PURE__ */ e(
223
+ se,
224
+ {
225
+ value: b,
226
+ onChange: _,
227
+ ariaLabel: "Role to play",
228
+ className: "h-8 flex-1 text-[12.5px]",
229
+ options: [
230
+ { value: "", label: "Pick a role…" },
231
+ ...A.map((t) => ({ value: t.id, label: t.name }))
232
+ ]
233
+ }
234
+ ),
235
+ /* @__PURE__ */ a(
236
+ "button",
237
+ {
238
+ type: "button",
239
+ className: L,
240
+ disabled: !b || v,
241
+ onClick: C,
242
+ "data-persona-run": "",
243
+ children: [
244
+ v ? /* @__PURE__ */ e(G, { className: "h-3.5 w-3.5 animate-spin" }) : null,
245
+ v ? "Testing…" : r ? "Test again" : "Test"
246
+ ]
247
+ }
248
+ )
249
+ ] }),
250
+ /* @__PURE__ */ e(
251
+ "input",
252
+ {
253
+ value: u,
254
+ onChange: (t) => l(t.target.value),
255
+ placeholder: "What they are trying to do (optional)",
256
+ "aria-label": "Goal",
257
+ className: "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"
258
+ }
259
+ ),
260
+ y && /* @__PURE__ */ e("p", { className: "text-[12.5px] text-red-700 dark:text-red-300", children: y }),
261
+ r && /* @__PURE__ */ a("div", { className: "space-y-3", children: [
262
+ !r.ai_configured && /* @__PURE__ */ e("p", { className: "rounded-md border border-amber-200 bg-amber-50 px-2.5 py-1.5 text-[12px] text-amber-800 dark:border-amber-500/30 dark:bg-amber-500/10 dark:text-amber-200", children: "AI is not set up, so only the built-in checks ran." }),
263
+ r.summary && /* @__PURE__ */ a("p", { className: "text-[12.5px] leading-snug text-slate-700 dark:text-foreground", children: [
264
+ /* @__PURE__ */ a("span", { className: "font-medium", children: [
265
+ "As ",
266
+ r.role,
267
+ ": "
268
+ ] }),
269
+ r.summary
270
+ ] }),
271
+ /* @__PURE__ */ e("ol", { className: "space-y-1", "aria-label": "Walkthrough", children: r.walkthrough.map((t, h) => {
272
+ const f = r.steps.find((F) => F.step === t.key);
273
+ return /* @__PURE__ */ e("li", { children: /* @__PURE__ */ a(
274
+ "button",
275
+ {
276
+ type: "button",
277
+ onClick: () => d($(`group:${t.key}`, o)),
278
+ className: "flex w-full items-start gap-2 rounded-md px-1.5 py-1 text-left transition-colors hover:bg-muted",
279
+ children: [
280
+ /* @__PURE__ */ e("span", { className: "mt-0.5 w-4 shrink-0 text-right font-mono text-[11px] text-slate-400", children: h + 1 }),
281
+ /* @__PURE__ */ e(
282
+ "span",
283
+ {
284
+ className: S(
285
+ "mt-1.5 h-2 w-2 shrink-0 rounded-full",
286
+ f ? ve[f.feeling] : "bg-slate-300 dark:bg-slate-600"
287
+ )
288
+ }
289
+ ),
290
+ /* @__PURE__ */ a("span", { className: "min-w-0 flex-1", children: [
291
+ /* @__PURE__ */ a("span", { className: "block text-[12.5px] font-medium text-slate-800 dark:text-foreground", children: [
292
+ t.label,
293
+ /* @__PURE__ */ a("span", { className: "ml-1.5 font-normal text-slate-500 dark:text-muted-foreground", children: [
294
+ t.fields,
295
+ " ",
296
+ t.fields === 1 ? "field" : "fields",
297
+ t.required > 0 ? `, ${t.required} required` : ""
298
+ ] })
299
+ ] }),
300
+ f && /* @__PURE__ */ e("span", { className: S(k, "block"), children: f.note })
301
+ ] })
302
+ ]
303
+ }
304
+ ) }, t.key);
305
+ }) }),
306
+ r.findings.length === 0 ? /* @__PURE__ */ a("p", { className: k, children: [
307
+ "Nothing would confuse ",
308
+ r.role,
309
+ " here."
310
+ ] }) : /* @__PURE__ */ e("ul", { className: "space-y-1.5", "aria-label": "What would confuse them", children: r.findings.map((t) => {
311
+ const h = t.target === "form" ? null : $(t.target, o), f = m(t.step);
312
+ return /* @__PURE__ */ a(
313
+ "li",
314
+ {
315
+ "data-persona-finding": t.target,
316
+ className: "rounded-md border border-slate-200 px-2.5 py-2 dark:border-border",
317
+ children: [
318
+ /* @__PURE__ */ a("div", { className: "flex items-start gap-2", children: [
319
+ /* @__PURE__ */ e(D, { tone: t.severity, children: t.severity === "blocking" ? "Blocks" : t.severity === "confusing" ? "Confusing" : "Minor" }),
320
+ /* @__PURE__ */ a(
321
+ "button",
322
+ {
323
+ type: "button",
324
+ disabled: !h,
325
+ onClick: () => d(h),
326
+ className: "min-w-0 flex-1 text-left text-[12.5px] leading-snug text-slate-800 disabled:cursor-default dark:text-foreground",
327
+ children: [
328
+ t.problem,
329
+ f && /* @__PURE__ */ a("span", { className: "ml-1 text-slate-500 dark:text-muted-foreground", children: [
330
+ "· ",
331
+ f
332
+ ] })
333
+ ]
334
+ }
335
+ )
336
+ ] }),
337
+ t.suggestion && /* @__PURE__ */ e("p", { className: S(k, "mt-1 pl-1"), children: t.suggestion }),
338
+ t.better_label && (h == null ? void 0 : h.kind) === "field" && /* @__PURE__ */ e("div", { className: "mt-1.5 flex justify-end", children: /* @__PURE__ */ e(
339
+ "button",
340
+ {
341
+ type: "button",
342
+ className: I,
343
+ disabled: n.has(t.id),
344
+ onClick: () => s(t),
345
+ "data-persona-rename": "",
346
+ children: n.has(t.id) ? "Renamed" : `Rename to “${t.better_label}”`
347
+ }
348
+ ) })
349
+ ]
350
+ },
351
+ t.id
352
+ );
353
+ }) }),
354
+ r.dropped.length > 0 && /* @__PURE__ */ a("p", { className: k, children: [
355
+ "Left out ",
356
+ r.dropped.length,
357
+ " note",
358
+ r.dropped.length === 1 ? "" : "s",
359
+ " about names this form does not have: ",
360
+ r.dropped.join(", "),
361
+ "."
362
+ ] }),
363
+ /* @__PURE__ */ e(K, { onPins: R })
364
+ ] })
365
+ ] });
366
+ }
367
+ function K({ onPins: g }) {
368
+ return /* @__PURE__ */ e("div", { className: "flex justify-end", children: /* @__PURE__ */ a("button", { type: "button", className: I, onClick: () => g([]), "data-ai-clear-pins": "", children: [
369
+ /* @__PURE__ */ e(Y, { className: "h-3.5 w-3.5" }),
370
+ "Clear marks on the canvas"
371
+ ] }) });
372
+ }
373
+ function Ce({
374
+ layoutId: g,
375
+ bundle: o,
376
+ previewRecordShown: c,
377
+ editor: N,
378
+ onPins: R,
379
+ select: d
380
+ }) {
381
+ const q = E(), [A, b] = x(!1), [_, u] = x(null), [l, v] = x(null), w = async () => {
382
+ const i = xe(N());
383
+ if (!i) {
384
+ u("Show the canvas (not the table view) first");
385
+ return;
386
+ }
387
+ b(!0), u(null);
388
+ try {
389
+ const { canvas: r, sections: T } = ye(i), n = c ? null : await ke(i), p = await q.request(
390
+ H(`/ai-design/layouts/${g}/visual-critique`, {
391
+ canvas: r,
392
+ sections: T,
393
+ image: n ?? void 0
394
+ })
395
+ );
396
+ v(p.data), R(pe(p.data, o));
397
+ } catch (r) {
398
+ u(B(r, "The review could not run"));
399
+ } finally {
400
+ b(!1);
401
+ }
402
+ }, y = (i) => {
403
+ var r;
404
+ return i === he ? "Whole form" : ((r = o.groups.find((T) => T.key === i)) == null ? void 0 : r.label) ?? j(i);
405
+ };
406
+ return /* @__PURE__ */ a("div", { className: "space-y-3", "data-visual-critique": "", children: [
407
+ /* @__PURE__ */ a("p", { className: k, children: [
408
+ "Reviews how the form looks — density, order of sections, alignment — and pins each comment to its section.",
409
+ " ",
410
+ c ? "A preview record is shown, so only the form’s structure and sizes are sent, no picture." : "A picture of the canvas is sent with typed values hidden, when the AI can read pictures."
411
+ ] }),
412
+ /* @__PURE__ */ e("div", { className: "flex justify-end", children: /* @__PURE__ */ a(
413
+ "button",
414
+ {
415
+ type: "button",
416
+ className: L,
417
+ disabled: A,
418
+ onClick: w,
419
+ "data-critique-run": "",
420
+ children: [
421
+ A ? /* @__PURE__ */ e(G, { className: "h-3.5 w-3.5 animate-spin" }) : null,
422
+ A ? "Reviewing…" : l ? "Review again" : "Review the look"
423
+ ]
424
+ }
425
+ ) }),
426
+ _ && /* @__PURE__ */ e("p", { className: "text-[12.5px] text-red-700 dark:text-red-300", children: _ }),
427
+ l && /* @__PURE__ */ a("div", { className: "space-y-3", children: [
428
+ !l.ai_configured && /* @__PURE__ */ e("p", { className: "rounded-md border border-amber-200 bg-amber-50 px-2.5 py-1.5 text-[12px] text-amber-800 dark:border-amber-500/30 dark:bg-amber-500/10 dark:text-amber-200", children: "AI is not set up, so only the built-in checks ran." }),
429
+ l.ai_configured && /* @__PURE__ */ e("p", { className: k, children: l.used_image ? "The AI saw a picture of the canvas." : l.image_skipped === "provider" ? "This AI provider does not read pictures; it judged the structure and sizes." : "The AI judged the structure and sizes (no picture)." }),
430
+ l.summary && /* @__PURE__ */ e("p", { className: "text-[12.5px] leading-snug text-slate-700 dark:text-foreground", children: l.summary }),
431
+ l.comments.length === 0 ? /* @__PURE__ */ e("p", { className: k, children: "No comments — the form reads well." }) : /* @__PURE__ */ e("ul", { className: "space-y-1.5", "aria-label": "Comments", children: l.comments.map((i) => {
432
+ const r = ue(i.section, o);
433
+ return /* @__PURE__ */ a(
434
+ "li",
435
+ {
436
+ "data-critique-comment": i.section,
437
+ className: "rounded-md border border-slate-200 px-2.5 py-2 dark:border-border",
438
+ children: [
439
+ /* @__PURE__ */ a(
440
+ "button",
441
+ {
442
+ type: "button",
443
+ disabled: !r,
444
+ onClick: () => d(r),
445
+ className: "flex w-full items-start gap-2 text-left disabled:cursor-default",
446
+ children: [
447
+ /* @__PURE__ */ e(D, { tone: i.severity, children: j(i.topic) }),
448
+ /* @__PURE__ */ a("span", { className: "min-w-0 flex-1 text-[12.5px] leading-snug text-slate-800 dark:text-foreground", children: [
449
+ /* @__PURE__ */ a("span", { className: "font-medium", children: [
450
+ y(i.section),
451
+ ": "
452
+ ] }),
453
+ i.comment
454
+ ] })
455
+ ]
456
+ }
457
+ ),
458
+ i.suggestion && /* @__PURE__ */ e("p", { className: S(k, "mt-1 pl-1"), children: i.suggestion })
459
+ ]
460
+ },
461
+ i.id
462
+ );
463
+ }) }),
464
+ l.dropped.length > 0 && /* @__PURE__ */ a("p", { className: k, children: [
465
+ "Left out comments about sections this form does not have: ",
466
+ l.dropped.join(", "),
467
+ "."
468
+ ] }),
469
+ /* @__PURE__ */ e(K, { onPins: R })
470
+ ] })
471
+ ] });
472
+ }
473
+ function Ae({
474
+ layoutId: g,
475
+ bundle: o,
476
+ apply: c,
477
+ labelOf: N
478
+ }) {
479
+ const R = E(), { data: d, isLoading: q, error: A } = Q({
480
+ queryKey: ["layout-editor", "autofill-corrections", g],
481
+ queryFn: () => R.request(
482
+ te(`/ai-design/layouts/${g}/autofill-corrections`)
483
+ ).then((s) => s.data),
484
+ staleTime: 5 * 6e4
485
+ }), [b, _] = x(null), [u, l] = x(null), [v, w] = x(null), y = (d == null ? void 0 : d.fields) ?? [], i = z(
486
+ () => new Set(
487
+ fe(
488
+ o,
489
+ y.map((s) => s.field)
490
+ )
491
+ ),
492
+ [o, y]
493
+ ), r = b ?? new Set(y.filter((s) => s.suggest && i.has(s.field)).map((s) => s.field)), T = (s) => {
494
+ const m = new Set(r);
495
+ m.has(s) ? m.delete(s) : m.add(s), _(m), l(null);
496
+ }, n = (s) => {
497
+ const m = s();
498
+ if (!m) {
499
+ l(null), w("Nothing to change for the ticked fields.");
500
+ return;
501
+ }
502
+ const t = O(o, m);
503
+ w(t), l(t ? null : m);
504
+ }, p = () => {
505
+ if (!u) return;
506
+ const s = O(o, u);
507
+ if (s) {
508
+ w(s), l(null);
509
+ return;
510
+ }
511
+ c(u.ops, { label: u.label }), l(null);
512
+ };
513
+ if (q) return /* @__PURE__ */ e("p", { className: k, children: "Reading autofill history…" });
514
+ if (A)
515
+ return /* @__PURE__ */ e("p", { className: "text-[12.5px] text-red-700 dark:text-red-300", children: B(A, "Autofill history could not be read") });
516
+ if (!d || d.documents === 0 || y.length === 0)
517
+ return /* @__PURE__ */ a("p", { className: k, children: [
518
+ "No records were created from a document on this collection in the last ",
519
+ (d == null ? void 0 : d.days) ?? 90,
520
+ " ",
521
+ "days, so there is nothing to tune yet."
522
+ ] });
523
+ const C = [...r];
524
+ return /* @__PURE__ */ a("div", { className: "space-y-3", "data-autofill-tuning": "", children: [
525
+ /* @__PURE__ */ a("p", { className: k, children: [
526
+ "From ",
527
+ d.documents,
528
+ " ",
529
+ d.documents === 1 ? "record" : "records",
530
+ " filled from a document in the last ",
531
+ d.days,
532
+ " days: how often people changed what the AI proposed. Ticked fields changed at least ",
533
+ Math.round(d.corrected_share * 100),
534
+ "% of the time."
535
+ ] }),
536
+ /* @__PURE__ */ e("ul", { className: "space-y-0.5", "aria-label": "Fields people correct", children: y.slice(0, 30).map((s) => {
537
+ const m = i.has(s.field);
538
+ return /* @__PURE__ */ e("li", { children: /* @__PURE__ */ a(
539
+ "label",
540
+ {
541
+ className: S(
542
+ "flex items-center gap-2 rounded-md px-1.5 py-1 text-[12.5px]",
543
+ m ? "cursor-pointer hover:bg-muted" : "opacity-60"
544
+ ),
545
+ "data-tip": m ? void 0 : "Not on this form",
546
+ children: [
547
+ /* @__PURE__ */ e(
548
+ "input",
549
+ {
550
+ type: "checkbox",
551
+ disabled: !m,
552
+ checked: m && r.has(s.field),
553
+ onChange: () => T(s.field),
554
+ className: "h-3.5 w-3.5 accent-[#00ceff]"
555
+ }
556
+ ),
557
+ /* @__PURE__ */ a("span", { className: "min-w-0 flex-1 truncate text-slate-800 dark:text-foreground", children: [
558
+ N(s.field),
559
+ ge(o, s.field) && /* @__PURE__ */ e("span", { className: "ml-1.5 text-[11px] text-slate-500 dark:text-muted-foreground", children: "highlighted" })
560
+ ] }),
561
+ /* @__PURE__ */ a("span", { className: "shrink-0 font-mono text-[11.5px] text-slate-500 dark:text-muted-foreground", children: [
562
+ "changed ",
563
+ s.corrected,
564
+ " of ",
565
+ s.proposed
566
+ ] })
567
+ ]
568
+ }
569
+ ) }, s.field);
570
+ }) }),
571
+ /* @__PURE__ */ a("div", { className: "flex flex-wrap items-center justify-end gap-1.5", children: [
572
+ /* @__PURE__ */ e(
573
+ "button",
574
+ {
575
+ type: "button",
576
+ className: I,
577
+ disabled: C.length === 0,
578
+ onClick: () => n(() => M(o, C, N, !1)),
579
+ children: "Remove highlight"
580
+ }
581
+ ),
582
+ /* @__PURE__ */ e(
583
+ "button",
584
+ {
585
+ type: "button",
586
+ className: I,
587
+ disabled: C.length === 0,
588
+ onClick: () => n(() => be(o, C, N)),
589
+ "data-autofill-section": "",
590
+ children: "Add “Check these” section"
591
+ }
592
+ ),
593
+ /* @__PURE__ */ e(
594
+ "button",
595
+ {
596
+ type: "button",
597
+ className: I,
598
+ disabled: C.length === 0,
599
+ onClick: () => n(() => M(o, C, N)),
600
+ "data-autofill-highlight": "",
601
+ children: "Highlight after autofill"
602
+ }
603
+ )
604
+ ] }),
605
+ v && /* @__PURE__ */ e("p", { className: "text-[12.5px] text-red-700 dark:text-red-300", children: v }),
606
+ u && /* @__PURE__ */ a(
607
+ "div",
608
+ {
609
+ className: "space-y-2 rounded-md border border-slate-200 px-2.5 py-2 dark:border-border",
610
+ "data-autofill-plan": "",
611
+ children: [
612
+ /* @__PURE__ */ e("p", { className: "text-[12px] font-semibold text-slate-700 dark:text-foreground", children: "This will" }),
613
+ /* @__PURE__ */ e("ol", { className: "list-decimal space-y-0.5 pl-5 text-[12.5px] leading-snug text-slate-700 dark:text-foreground", children: u.steps.map((s, m) => /* @__PURE__ */ e("li", { children: s }, `${m}:${s}`)) }),
614
+ /* @__PURE__ */ a("div", { className: "flex justify-end gap-1.5", children: [
615
+ /* @__PURE__ */ e("button", { type: "button", className: I, onClick: () => l(null), children: "Cancel" }),
616
+ /* @__PURE__ */ e("button", { type: "button", className: L, onClick: p, "data-autofill-apply": "", children: u.steps.length > 1 ? `Apply ${u.steps.length} changes` : "Apply" })
617
+ ] })
618
+ ]
619
+ }
620
+ )
621
+ ] });
622
+ }
623
+ export {
624
+ ze as AiToolsButton
625
+ };