@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
@@ -0,0 +1,182 @@
1
+ import { jsxs as s, jsx as e } from "react/jsx-runtime";
2
+ import { Wand2 as b, FileImage as v, FileText as N, UserRound as A, Sparkles as C, ChevronRight as F } from "lucide-react";
3
+ import { useState as y } from "react";
4
+ import { toast as w } from "sonner";
5
+ import { Popover as R, PopoverContent as P } from "../../ui/popover.js";
6
+ import { useLayoutEditorHost as B } from "../host.js";
7
+ import { ToolButton as O } from "../toolbar-kit.js";
8
+ import { AiComposer as S } from "./AiComposer.js";
9
+ import { MeaningSuggestions as j } from "./MeaningSuggestions.js";
10
+ import { usePendingBuild as L } from "./pending.js";
11
+ import { SlimPanel as M } from "./SlimPanel.js";
12
+ function $({
13
+ collection: a,
14
+ layoutId: i,
15
+ draft: n,
16
+ onOpenLayout: p
17
+ }) {
18
+ const c = B(), [k, d] = y(!1), [r, t] = y("menu");
19
+ L(i, n);
20
+ const l = n.bundle;
21
+ if (!c.isAdmin || !l) return null;
22
+ const u = l.layout, h = (u.layout_type ?? "grouped") === "grouped" && !u.parent_layout_id, f = () => {
23
+ d(!1), t("menu");
24
+ };
25
+ return /* @__PURE__ */ s(
26
+ R,
27
+ {
28
+ open: k,
29
+ onOpenChange: (o) => {
30
+ d(o), o || t("menu");
31
+ },
32
+ children: [
33
+ /* @__PURE__ */ e(
34
+ O,
35
+ {
36
+ popover: !0,
37
+ onOpen: () => d(!0),
38
+ label: "Rebuild or lighter version",
39
+ icon: /* @__PURE__ */ e(b, { className: "h-3.5 w-3.5 text-nvr-cyan" }),
40
+ tip: "Rebuild this form with AI, or make a lighter version for a role",
41
+ hint: "From a description, a picture or a process; lighter for a role",
42
+ data: { "data-ai-forms-trigger": "" }
43
+ }
44
+ ),
45
+ /* @__PURE__ */ s(
46
+ P,
47
+ {
48
+ align: "end",
49
+ className: "max-h-[min(72vh,560px)] w-[460px] overflow-y-auto overscroll-contain p-3",
50
+ "data-ai-forms": "",
51
+ children: [
52
+ r === "menu" && /* @__PURE__ */ s("div", { className: "flex flex-col gap-0.5", children: [
53
+ /* @__PURE__ */ e("p", { className: "px-2 pb-1 text-[12px] font-semibold text-slate-700 dark:text-foreground", children: "Rebuild with AI" }),
54
+ /* @__PURE__ */ e(
55
+ m,
56
+ {
57
+ icon: /* @__PURE__ */ e(b, { className: "h-3.5 w-3.5" }),
58
+ title: "From a description",
59
+ sub: "“a returns form with a manager approval step”",
60
+ onClick: () => t("describe")
61
+ }
62
+ ),
63
+ /* @__PURE__ */ e(
64
+ m,
65
+ {
66
+ icon: /* @__PURE__ */ e(v, { className: "h-3.5 w-3.5" }),
67
+ title: "From a picture or PDF",
68
+ sub: "An old paper, PDF or Excel form, matched to fields",
69
+ onClick: () => t("picture")
70
+ }
71
+ ),
72
+ /* @__PURE__ */ e(
73
+ m,
74
+ {
75
+ icon: /* @__PURE__ */ e(N, { className: "h-3.5 w-3.5" }),
76
+ title: "From a process document",
77
+ sub: "Steps per stage, with read-only and required fields",
78
+ onClick: () => t("sop")
79
+ }
80
+ ),
81
+ /* @__PURE__ */ e("p", { className: "px-2 pb-1 pt-2 text-[12px] font-semibold text-slate-700 dark:text-foreground", children: "More" }),
82
+ /* @__PURE__ */ e(
83
+ m,
84
+ {
85
+ icon: /* @__PURE__ */ e(A, { className: "h-3.5 w-3.5" }),
86
+ title: "Lighter version for a role",
87
+ sub: h ? "Only the fields that role really fills" : "Made from a form that does not inherit from another",
88
+ disabled: !h,
89
+ onClick: () => t("slim")
90
+ }
91
+ ),
92
+ /* @__PURE__ */ e(
93
+ m,
94
+ {
95
+ icon: /* @__PURE__ */ e(C, { className: "h-3.5 w-3.5" }),
96
+ title: "Place new fields by meaning",
97
+ sub: "A section for each field not on the form",
98
+ onClick: () => t("meaning")
99
+ }
100
+ )
101
+ ] }),
102
+ (r === "describe" || r === "picture" || r === "sop") && /* @__PURE__ */ e(
103
+ S,
104
+ {
105
+ collection: a,
106
+ mode: r,
107
+ bundle: l,
108
+ onBack: () => t("menu"),
109
+ applyLabel: (o) => o.steps.length > 1 ? `Apply ${o.steps.length} changes` : "Apply",
110
+ onApply: (o) => {
111
+ const x = n.bundle;
112
+ if (!x) return;
113
+ const g = o(x);
114
+ if (g.ops.length === 0) {
115
+ w.error("Nothing left to change on the form as it is now");
116
+ return;
117
+ }
118
+ n.apply(g.ops, { label: "Rebuild with AI" }), w.success("Rebuilt. Check the form, then Save — or undo it in one step."), f();
119
+ }
120
+ }
121
+ ),
122
+ r === "slim" && /* @__PURE__ */ e(
123
+ M,
124
+ {
125
+ collection: a,
126
+ layoutId: i,
127
+ parentGroups: l.groups,
128
+ onBack: () => t("menu"),
129
+ onOpenLayout: (o) => {
130
+ f(), p(o);
131
+ }
132
+ }
133
+ ),
134
+ r === "meaning" && /* @__PURE__ */ s("div", { className: "space-y-2", children: [
135
+ /* @__PURE__ */ e(j, { bundle: l, collection: a, apply: n.apply }),
136
+ /* @__PURE__ */ e("p", { className: "text-[12px] text-slate-500 dark:text-muted-foreground", children: "Nothing shows when every field is already on the form or the form has no section yet. The same suggestions sit at the top of the Add panel." }),
137
+ /* @__PURE__ */ e("div", { className: "flex justify-end", children: /* @__PURE__ */ e(
138
+ "button",
139
+ {
140
+ type: "button",
141
+ className: "inline-flex h-7 items-center rounded-md px-2.5 text-[12px] font-medium text-slate-600 transition-colors hover:bg-muted dark:text-muted-foreground",
142
+ onClick: () => t("menu"),
143
+ children: "Back"
144
+ }
145
+ ) })
146
+ ] })
147
+ ]
148
+ }
149
+ )
150
+ ]
151
+ }
152
+ );
153
+ }
154
+ function m({
155
+ icon: a,
156
+ title: i,
157
+ sub: n,
158
+ onClick: p,
159
+ disabled: c
160
+ }) {
161
+ return /* @__PURE__ */ s(
162
+ "button",
163
+ {
164
+ type: "button",
165
+ onClick: p,
166
+ disabled: c,
167
+ "data-ai-forms-option": i,
168
+ className: "group flex w-full items-center gap-2.5 rounded-md px-2 py-1.5 text-left transition-colors hover:bg-muted disabled:pointer-events-none disabled:opacity-50",
169
+ children: [
170
+ /* @__PURE__ */ e("span", { className: "flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-nvr-cyan/10 text-[#0089ad] dark:text-nvr-cyan", children: a }),
171
+ /* @__PURE__ */ s("span", { className: "flex min-w-0 flex-1 flex-col", children: [
172
+ /* @__PURE__ */ e("span", { className: "text-[12.5px] font-medium text-slate-900 dark:text-foreground", children: i }),
173
+ /* @__PURE__ */ e("span", { className: "truncate text-[11.5px] text-slate-500 dark:text-muted-foreground", children: n })
174
+ ] }),
175
+ /* @__PURE__ */ e(F, { className: "h-3.5 w-3.5 shrink-0 text-slate-400" })
176
+ ]
177
+ }
178
+ );
179
+ }
180
+ export {
181
+ $ as AiFormsButton
182
+ };
@@ -0,0 +1,109 @@
1
+ import { jsxs as n, jsx as s, Fragment as x } from "react/jsx-runtime";
2
+ import { Sparkles as A, Plus as w } from "lucide-react";
3
+ import { useState as C, useMemo as r } from "react";
4
+ import { useNivaroClient as S } from "../../../context.js";
5
+ import { cn as l } from "../../../lib/utils.js";
6
+ import { useLayoutEditorHost as $ } from "../host.js";
7
+ import { useOverviewFields as F, apiFailure as M } from "../overview/overview-api.js";
8
+ import { tintCard as _ } from "../panel-style.js";
9
+ import { quiet as m, ghostBtn as k } from "./AiComposer.js";
10
+ import { fetchMeaning as j } from "./ai-forms-api.js";
11
+ import { unplacedFields as I, meaningGroups as T, meaningChoices as P, planMeaning as q } from "./plan.js";
12
+ function R({
13
+ bundle: a,
14
+ collection: N,
15
+ apply: g
16
+ }) {
17
+ const b = $(), y = S(), { data: o = [] } = F(N), [t, d] = C({ kind: "idle" }), p = r(() => ({ fields: o }), [o]), c = r(
18
+ () => I(a, o),
19
+ [a, o]
20
+ ), h = r(() => T(a), [a]), i = r(
21
+ () => t.kind === "done" ? P(a, t.suggestions, p) : [],
22
+ [t, a, p]
23
+ );
24
+ if (!b.isAdmin || c.length === 0 || h.length === 0) return null;
25
+ const v = async () => {
26
+ d({ kind: "asking" });
27
+ try {
28
+ const e = await j(y, Number(a.layout.id), { groups: h, fields: c });
29
+ d({ kind: "done", suggestions: e.suggestions });
30
+ } catch (e) {
31
+ const f = M(e, "The AI could not suggest sections");
32
+ d({
33
+ kind: "error",
34
+ error: f.status === 503 ? "AI is not set up here." : f.message
35
+ });
36
+ }
37
+ }, u = c.length;
38
+ return /* @__PURE__ */ n("div", { className: l(_, "mx-1 mt-3 space-y-2 px-2.5 py-2"), "data-ai-meaning": "", children: [
39
+ /* @__PURE__ */ n("p", { className: "flex items-center gap-1.5 text-[12px] font-semibold text-slate-700 dark:text-foreground", children: [
40
+ /* @__PURE__ */ s(A, { className: "h-3.5 w-3.5 text-nvr-cyan" }),
41
+ "Sections by meaning"
42
+ ] }),
43
+ t.kind !== "done" && /* @__PURE__ */ n(x, { children: [
44
+ /* @__PURE__ */ n("p", { className: m, children: [
45
+ u,
46
+ " field",
47
+ u === 1 ? " is" : "s are",
48
+ " not on this form. The AI can suggest a section for each from what it means."
49
+ ] }),
50
+ t.kind === "error" && /* @__PURE__ */ s("p", { role: "alert", className: "text-[12px] text-red-700 dark:text-red-300", children: t.error }),
51
+ /* @__PURE__ */ s(
52
+ "button",
53
+ {
54
+ type: "button",
55
+ className: l(k, "px-2"),
56
+ disabled: t.kind === "asking",
57
+ onClick: () => void v(),
58
+ "data-ai-meaning-ask": "",
59
+ children: t.kind === "asking" ? "Thinking…" : "Suggest sections"
60
+ }
61
+ )
62
+ ] }),
63
+ t.kind === "done" && (i.length === 0 ? /* @__PURE__ */ s("p", { className: m, children: "No suggestions left: no section fits the remaining fields." }) : /* @__PURE__ */ n(x, { children: [
64
+ /* @__PURE__ */ s("ul", { className: "space-y-1", "data-ai-meaning-list": "", children: i.map((e) => /* @__PURE__ */ n("li", { className: "flex items-start gap-1.5", children: [
65
+ /* @__PURE__ */ n("span", { className: "min-w-0 flex-1", children: [
66
+ /* @__PURE__ */ n("span", { className: "block truncate text-[12.5px] text-slate-800 dark:text-foreground", children: [
67
+ e.label,
68
+ " ",
69
+ /* @__PURE__ */ s("span", { className: "text-slate-400", children: "→" }),
70
+ " ",
71
+ e.group_label
72
+ ] }),
73
+ e.reason && /* @__PURE__ */ s("span", { className: l(m, "block"), children: e.reason })
74
+ ] }),
75
+ /* @__PURE__ */ s(
76
+ "button",
77
+ {
78
+ type: "button",
79
+ "aria-label": `Add ${e.label} to ${e.group_label}`,
80
+ "data-tip": `Add to ${e.group_label}`,
81
+ className: "inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-slate-500 transition-colors hover:bg-muted hover:text-slate-800 dark:hover:text-foreground",
82
+ onClick: () => g([e.op], { label: `Add ${e.label} to ${e.group_label}` }),
83
+ "data-ai-meaning-add": e.field,
84
+ children: /* @__PURE__ */ s(w, { className: "h-3.5 w-3.5" })
85
+ }
86
+ )
87
+ ] }, e.field)) }),
88
+ i.length > 1 && /* @__PURE__ */ n(
89
+ "button",
90
+ {
91
+ type: "button",
92
+ className: l(k, "px-2"),
93
+ "data-ai-meaning-all": "",
94
+ onClick: () => {
95
+ const e = q(a, i);
96
+ e.ops.length && g(e.ops, { label: `Place ${e.ops.length} fields by meaning` });
97
+ },
98
+ children: [
99
+ "Add all ",
100
+ i.length
101
+ ]
102
+ }
103
+ )
104
+ ] }))
105
+ ] });
106
+ }
107
+ export {
108
+ R as MeaningSuggestions
109
+ };
@@ -0,0 +1,170 @@
1
+ import { jsxs as s, jsx as a, Fragment as A } from "react/jsx-runtime";
2
+ import { useState as n } from "react";
3
+ import { useNivaroClient as E } from "../../../context.js";
4
+ import { cn as N } from "../../../lib/utils.js";
5
+ import { SimpleSelect as F } from "../../ui/SimpleSelect.js";
6
+ import { createLayout as I } from "../overview/OverviewActions.js";
7
+ import { useInvalidateLayouts as K, useRoleNames as O, apiFailure as b } from "../overview/overview-api.js";
8
+ import { tintCard as v, inputBase as P } from "../panel-style.js";
9
+ import { quiet as i, primaryBtn as k, ghostBtn as H } from "./AiComposer.js";
10
+ import { fetchSlim as z } from "./ai-forms-api.js";
11
+ import { stashBuild as D } from "./pending.js";
12
+ import { listNames as G, planSlimOps as J } from "./plan.js";
13
+ function se({
14
+ collection: h,
15
+ layoutId: u,
16
+ parentGroups: C,
17
+ onOpenLayout: w,
18
+ onBack: L
19
+ }) {
20
+ const f = E(), S = K(h), { data: _ = [] } = O(!0), [o, B] = n(""), [t, g] = n(null), [d, x] = n(""), [c, m] = n(!1), [y, p] = n(null), j = async () => {
21
+ if (o) {
22
+ m(!0), p(null);
23
+ try {
24
+ const e = await z(f, u, o);
25
+ g(e), x(e.name ?? "");
26
+ } catch (e) {
27
+ p(b(e, "Could not read this role’s edits").message);
28
+ } finally {
29
+ m(!1);
30
+ }
31
+ }
32
+ }, R = async () => {
33
+ const e = t == null ? void 0 : t.plan;
34
+ if (!(!t || !e || !d.trim())) {
35
+ m(!0), p(null);
36
+ try {
37
+ const r = await I(f, {
38
+ collection: h,
39
+ name: d.trim(),
40
+ layout_type: "grouped"
41
+ });
42
+ if (r == null) throw new Error("No id came back");
43
+ const $ = { id: u, groups: C };
44
+ D(r, {
45
+ label: `Lighter version for ${t.role.name}`,
46
+ plan: (q) => J(q, $, e, t.role),
47
+ done: "Lighter version drafted. Check it and Save."
48
+ }), S(), w(r);
49
+ } catch (r) {
50
+ p(b(r, "Could not create the form").message);
51
+ } finally {
52
+ m(!1);
53
+ }
54
+ }
55
+ }, l = t == null ? void 0 : t.plan;
56
+ return /* @__PURE__ */ s("div", { className: "space-y-2.5", "data-ai-slim": "", children: [
57
+ /* @__PURE__ */ a("p", { className: "text-[12px] font-semibold text-slate-700 dark:text-foreground", children: "Lighter version for a role" }),
58
+ /* @__PURE__ */ a("p", { className: i, children: "Keeps the fields that role’s people changed in the last 180 days and hides the rest, on a new form that inherits from this one and is shown to that role." }),
59
+ /* @__PURE__ */ s("div", { className: "flex items-center gap-2", children: [
60
+ /* @__PURE__ */ a(
61
+ F,
62
+ {
63
+ value: o,
64
+ onChange: (e) => {
65
+ B(e), g(null);
66
+ },
67
+ options: _.map((e) => ({ value: e.id, label: e.name })),
68
+ ariaLabel: "Role",
69
+ className: "h-8 flex-1 text-[12.5px]",
70
+ triggerProps: { "data-ai-slim-role": "" }
71
+ }
72
+ ),
73
+ /* @__PURE__ */ a(
74
+ "button",
75
+ {
76
+ type: "button",
77
+ className: k,
78
+ disabled: !o || c,
79
+ onClick: () => void j(),
80
+ "data-ai-slim-look": "",
81
+ children: c && !t ? "Reading…" : "Look at their edits"
82
+ }
83
+ )
84
+ ] }),
85
+ t && !l && /* @__PURE__ */ s("p", { className: i, "data-ai-slim-thin": "", children: [
86
+ "Only ",
87
+ t.revisions,
88
+ " save",
89
+ t.revisions === 1 ? "" : "s",
90
+ " by ",
91
+ t.role.name,
92
+ " ",
93
+ "people in the last ",
94
+ t.days,
95
+ " days: too few to tell which fields they use."
96
+ ] }),
97
+ t && l && /* @__PURE__ */ s(A, { children: [
98
+ /* @__PURE__ */ s("p", { className: i, children: [
99
+ t.revisions,
100
+ " saves by ",
101
+ t.people,
102
+ " ",
103
+ t.people === 1 ? "person" : "people",
104
+ " ",
105
+ "in the last ",
106
+ t.days,
107
+ " days. A field counts as used from ",
108
+ l.min_changes,
109
+ " change",
110
+ l.min_changes === 1 ? "" : "s",
111
+ "."
112
+ ] }),
113
+ /* @__PURE__ */ s("div", { className: N(v, "space-y-1 px-2.5 py-2"), "data-ai-slim-keep": "", children: [
114
+ /* @__PURE__ */ s("p", { className: "text-[12px] font-semibold text-slate-700 dark:text-foreground", children: [
115
+ "Keeps ",
116
+ l.keep.length
117
+ ] }),
118
+ /* @__PURE__ */ a("ul", { className: "space-y-0.5 text-[12.5px] text-slate-700 dark:text-foreground", children: l.keep.map((e) => /* @__PURE__ */ s("li", { className: "flex justify-between gap-2", children: [
119
+ /* @__PURE__ */ a("span", { className: "truncate", children: e.label }),
120
+ /* @__PURE__ */ a("span", { className: "shrink-0 text-[11.5px] text-slate-500 dark:text-muted-foreground", children: e.why === "required" ? "required" : `${e.changes} change${e.changes === 1 ? "" : "s"}` })
121
+ ] }, e.field)) })
122
+ ] }),
123
+ /* @__PURE__ */ s("div", { className: N(v, "space-y-1 px-2.5 py-2"), "data-ai-slim-drop": "", children: [
124
+ /* @__PURE__ */ s("p", { className: "text-[12px] font-semibold text-slate-700 dark:text-foreground", children: [
125
+ "Hides ",
126
+ l.drop.length
127
+ ] }),
128
+ l.drop.length === 0 ? /* @__PURE__ */ a("p", { className: i, children: "Nothing: this role uses every field on the form." }) : /* @__PURE__ */ a("ul", { className: "space-y-0.5 text-[12.5px] text-slate-700 dark:text-foreground", children: l.drop.map((e) => /* @__PURE__ */ s("li", { className: "flex justify-between gap-2", children: [
129
+ /* @__PURE__ */ a("span", { className: "truncate", children: e.label }),
130
+ e.group_label && /* @__PURE__ */ a("span", { className: "shrink-0 text-[11.5px] text-slate-500 dark:text-muted-foreground", children: e.group_label })
131
+ ] }, e.field)) }),
132
+ l.hide_groups.length > 0 && /* @__PURE__ */ s("p", { className: i, children: [
133
+ "Also hides ",
134
+ G(l.hide_groups.map((e) => `“${e.label}”`)),
135
+ ": nothing in it is used."
136
+ ] })
137
+ ] }),
138
+ /* @__PURE__ */ s("label", { className: "block", children: [
139
+ /* @__PURE__ */ a("span", { className: "mb-1 block text-[11.5px] font-semibold text-slate-600 dark:text-muted-foreground", children: "Name" }),
140
+ /* @__PURE__ */ a(
141
+ "input",
142
+ {
143
+ value: d,
144
+ onChange: (e) => x(e.target.value),
145
+ className: P,
146
+ maxLength: 80
147
+ }
148
+ )
149
+ ] })
150
+ ] }),
151
+ y && /* @__PURE__ */ a("p", { role: "alert", className: "text-[12.5px] leading-snug text-red-700 dark:text-red-300", children: y }),
152
+ /* @__PURE__ */ s("div", { className: "flex items-center justify-end gap-1.5 pt-0.5", children: [
153
+ /* @__PURE__ */ a("button", { type: "button", className: H, onClick: L, children: "Back" }),
154
+ l && /* @__PURE__ */ a(
155
+ "button",
156
+ {
157
+ type: "button",
158
+ className: k,
159
+ disabled: c || !d.trim() || l.drop.length === 0,
160
+ onClick: () => void R(),
161
+ "data-ai-slim-create": "",
162
+ children: c ? "Creating…" : "Create lighter version"
163
+ }
164
+ )
165
+ ] })
166
+ ] });
167
+ }
168
+ export {
169
+ se as SlimPanel
170
+ };
@@ -0,0 +1,40 @@
1
+ import { post as r } from "../../../lib/commands.js";
2
+ const d = ".png,.jpg,.jpeg,.gif,.webp,.pdf,.docx,.xlsx,.xls,.xlsm,.csv,.txt,.md,.eml,.html,.htm", l = 10 * 1024 * 1024;
3
+ async function m(o, e, t) {
4
+ return (await o.request(
5
+ r("/ai-design/layouts/compose", { collection: e, text: t })
6
+ )).data;
7
+ }
8
+ async function f(o, e) {
9
+ var i;
10
+ const t = new FormData();
11
+ t.append("collection", e.collection), t.append("mode", e.mode), (i = e.note) != null && i.trim() && t.append("note", e.note.trim()), t.append("file", e.file, e.file.name);
12
+ const s = o.getToken(), a = await fetch(`${o.url}/api/ai-design/layouts/compose/file`, {
13
+ method: "POST",
14
+ headers: s ? { Authorization: `Bearer ${s}` } : {},
15
+ credentials: s ? "omit" : "include",
16
+ body: t
17
+ }), n = await a.json().catch(() => ({}));
18
+ if (!a.ok || !n.data)
19
+ throw Object.assign(new Error(n.error || "The AI could not read the file"), {
20
+ status: a.status,
21
+ response: { status: a.status, data: { error: n.error } }
22
+ });
23
+ return n.data;
24
+ }
25
+ async function u(o, e, t) {
26
+ return (await o.request(
27
+ r(`/ai-design/layouts/${e}/slim`, { role_id: t })
28
+ )).data;
29
+ }
30
+ async function p(o, e, t) {
31
+ return (await o.request(r(`/ai-design/layouts/${e}/sections-by-meaning`, t))).data;
32
+ }
33
+ export {
34
+ d as COMPOSE_ACCEPT,
35
+ l as COMPOSE_MAX_BYTES,
36
+ f as composeFromFile,
37
+ m as composeFromText,
38
+ p as fetchMeaning,
39
+ u as fetchSlim
40
+ };
@@ -0,0 +1,25 @@
1
+ import { useEffect as p } from "react";
2
+ import { toast as r } from "sonner";
3
+ const s = /* @__PURE__ */ new Map();
4
+ function a(n, e) {
5
+ s.set(n, e);
6
+ }
7
+ function f(n, e) {
8
+ const t = e.bundle, i = e.apply;
9
+ p(() => {
10
+ if (!t || Number(t.layout.id) !== n) return;
11
+ const o = s.get(n);
12
+ if (!o) return;
13
+ s.delete(n);
14
+ const l = o.plan(t);
15
+ if (l.ops.length === 0) {
16
+ r.error("The AI proposal no longer fits this layout — nothing was changed");
17
+ return;
18
+ }
19
+ i(l.ops, { label: o.label }), r.success(o.done);
20
+ }, [n, t, i]);
21
+ }
22
+ export {
23
+ a as stashBuild,
24
+ f as usePendingBuild
25
+ };