@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,157 @@
1
+ import { parseVisibleWhen as m, matchesVisibleWhen as h } from "../../../lib/visible-when.js";
2
+ const k = {
3
+ desktop: null,
4
+ tablet: 768,
5
+ phone: 390
6
+ };
7
+ function u(e) {
8
+ if (e == null || e === "") return [];
9
+ try {
10
+ const o = typeof e == "string" ? JSON.parse(e) : e;
11
+ return Array.isArray(o) ? o.map((n) => String(n).toUpperCase()) : [];
12
+ } catch {
13
+ return [];
14
+ }
15
+ }
16
+ function _(e) {
17
+ if (e == null || e === "") return [];
18
+ try {
19
+ const o = typeof e == "string" ? JSON.parse(e) : e;
20
+ return Array.isArray(o) ? o.flatMap(
21
+ (n) => (n == null ? void 0 : n.type) === "role" && Array.isArray(n.role_ids) ? n.role_ids.map((i) => String(i).toUpperCase()) : []
22
+ ) : [];
23
+ } catch {
24
+ return [];
25
+ }
26
+ }
27
+ function a(e, o) {
28
+ const n = String(e.role.id ?? "").toUpperCase(), i = e.role.admin_access, t = new Set(e.hidden_fields), s = new Set(e.readonly_fields), d = /* @__PURE__ */ new Map();
29
+ if (!i)
30
+ for (const l of o.groups) {
31
+ const f = l;
32
+ u(f.hidden_for_roles).includes(n) ? d.set(f.key, "hidden") : u(f.locked_for_roles).includes(n) && d.set(f.key, "locked");
33
+ }
34
+ const r = /* @__PURE__ */ new Map();
35
+ for (const l of o.assignments) {
36
+ if (l.field.startsWith("__")) continue;
37
+ const f = l.group_key ? d.get(l.group_key) : void 0;
38
+ let c;
39
+ !e.can_read || t.has(l.field) || f === "hidden" ? c = "hidden" : !e.can_update || s.has(l.field) || f === "locked" || _(l.lock_conditions).includes(n) ? c = "readonly" : c = "editable";
40
+ const p = r.get(l.field);
41
+ (!p || g(c) > g(p)) && r.set(l.field, c);
42
+ }
43
+ return r;
44
+ }
45
+ const g = (e) => e === "editable" ? 2 : e === "readonly" ? 1 : 0, y = {
46
+ hidden: "hidden",
47
+ readonly: "read-only",
48
+ editable: "can edit"
49
+ };
50
+ function S(e, o, n) {
51
+ const i = a(o, e), t = a(n, e), s = (r, l) => !r.role.admin_access && u(l).includes(String(r.role.id ?? "").toUpperCase()), d = /* @__PURE__ */ new Map();
52
+ for (const r of e.groups) {
53
+ const l = r.hidden_for_roles, f = s(o, l), c = s(n, l);
54
+ f !== c && d.set(r.key, `${f ? o.role.name : n.role.name} does not see this section`);
55
+ }
56
+ return (r) => {
57
+ if (r.kind === "group") {
58
+ const c = d.get(r.key);
59
+ return c ? [{ text: "Differs", tone: "violet", tip: c, highlight: !0 }] : [];
60
+ }
61
+ if (r.kind !== "field" && r.kind !== "header") return [];
62
+ const l = i.get(r.field), f = t.get(r.field);
63
+ return !l || !f || l === f ? [] : [
64
+ {
65
+ text: "Differs",
66
+ tone: "violet",
67
+ tip: `${o.role.name}: ${y[l]} · ${n.role.name}: ${y[f]}`,
68
+ highlight: !0
69
+ }
70
+ ];
71
+ };
72
+ }
73
+ function b(e, o) {
74
+ const n = /* @__PURE__ */ new Map();
75
+ for (const i of e)
76
+ for (const [t, s] of a(i, o)) {
77
+ const d = n.get(t) ?? { edit: [], read: [], hidden: [] };
78
+ s === "editable" ? d.edit.push(i.role.name) : s === "readonly" ? d.read.push(i.role.name) : d.hidden.push(i.role.name), n.set(t, d);
79
+ }
80
+ return n;
81
+ }
82
+ function A(e) {
83
+ const o = e.edit.length + e.read.length + e.hidden.length, n = e.edit.length + e.read.length;
84
+ if (o === 0 || n === 0) return "none";
85
+ if (n === o) return "all";
86
+ const i = n / o;
87
+ return i < 1 / 3 ? "few" : i < 2 / 3 ? "some" : "most";
88
+ }
89
+ function C(e, o) {
90
+ const n = [];
91
+ for (const i of e.assignments)
92
+ if (i.lock_conditions)
93
+ try {
94
+ const t = JSON.parse(i.lock_conditions);
95
+ Array.isArray(t) && t.some((s) => {
96
+ var d;
97
+ return (s == null ? void 0 : s.type) === "pipeline_state" && ((d = s.state_keys) == null ? void 0 : d.includes(o));
98
+ }) && n.push(i.field);
99
+ } catch {
100
+ }
101
+ return [...new Set(n)];
102
+ }
103
+ function w(e, o) {
104
+ const n = [];
105
+ for (const i of e)
106
+ if (!(i.from_state != null && i.from_state !== o))
107
+ for (const t of i.requirements ?? []) {
108
+ const s = Array.isArray(t == null ? void 0 : t.fields) ? t.fields.map(String) : [];
109
+ s.length !== 0 && n.push({
110
+ label: i.label,
111
+ fields: s,
112
+ collection: typeof t.collection == "string" && t.collection ? t.collection : null
113
+ });
114
+ }
115
+ return n;
116
+ }
117
+ function M(e) {
118
+ const o = /* @__PURE__ */ new Map();
119
+ for (const n of e.groups) {
120
+ const i = m(n.visible_when);
121
+ for (const t of i) {
122
+ if (!t.field) continue;
123
+ const s = o.get(t.field) ?? { field: t.field, values: [], drives: [] };
124
+ if (t.op === "in")
125
+ for (const r of String(t.value ?? "").split(","))
126
+ r.trim() && !s.values.includes(r.trim()) && s.values.push(r.trim());
127
+ if ((t.op ?? "eq") === "eq" || t.op === "neq") {
128
+ const r = String(t.value ?? "");
129
+ r && !s.values.includes(r) && s.values.push(r);
130
+ }
131
+ const d = n.label || n.key;
132
+ s.drives.includes(d) || s.drives.push(d), o.set(t.field, s);
133
+ }
134
+ }
135
+ return [...o.values()].sort((n, i) => n.field.localeCompare(i.field));
136
+ }
137
+ function D(e, o, n) {
138
+ const i = [], t = [];
139
+ for (const s of e.groups) {
140
+ const d = s.visible_when;
141
+ if (m(d).length === 0) continue;
142
+ const r = h(d, o), l = h(d, n);
143
+ r !== l && (l ? i : t).push(s.key);
144
+ }
145
+ return { shown: i, hidden: t };
146
+ }
147
+ export {
148
+ k as DEVICE_WIDTH,
149
+ S as compareMarks,
150
+ M as drivingFields,
151
+ a as fieldAccessForRole,
152
+ C as fieldsLockedInState,
153
+ w as leavingNeeds,
154
+ D as visibilityChanges,
155
+ b as whoSeesFields,
156
+ A as whoTint
157
+ };
@@ -0,0 +1,70 @@
1
+ import { jsxs as c, jsx as d } from "react/jsx-runtime";
2
+ import { ArrowRight as v } from "lucide-react";
3
+ import { useMemo as u, useState as w, useEffect as N } from "react";
4
+ import { titleCase as M } from "../../../lib/utils.js";
5
+ import { SimpleSelect as $ } from "../../ui/SimpleSelect.js";
6
+ import { useOverviewFields as h } from "../overview/overview-api.js";
7
+ import { suggestFieldMap as b } from "./field-match.js";
8
+ const f = "";
9
+ function O(a, m, s) {
10
+ const { data: t, isLoading: i } = h(s), { data: r = [] } = h(m ?? s), p = u(() => new Set((t ?? []).map((l) => l.field)), [t]), e = u(
11
+ () => t ? a.filter((l) => !l.startsWith("__") && !p.has(l)) : [],
12
+ [a, p, t]
13
+ ), n = `${s}|${e.join(",")}`, [x, g] = w({});
14
+ return N(() => {
15
+ if (!t) return;
16
+ const l = new Map(r.map((o) => [o.field, o.label ?? null]));
17
+ g(
18
+ b(
19
+ e.map((o) => ({ field: o, label: l.get(o) ?? null })),
20
+ t
21
+ )
22
+ );
23
+ }, [n, t]), { map: x, setMap: g, needed: e, loading: i, sourceFields: r };
24
+ }
25
+ function W({
26
+ needed: a,
27
+ map: m,
28
+ onChange: s,
29
+ targetCollection: t,
30
+ sourceLabels: i
31
+ }) {
32
+ const { data: r = [] } = h(t), p = u(
33
+ () => [
34
+ { value: f, label: "Leave out" },
35
+ ...r.filter((e) => !e.field.startsWith("__")).map((e) => ({ value: e.field, label: `${e.label || M(e.field)} · ${e.field}` })).sort((e, n) => e.label.localeCompare(n.label))
36
+ ],
37
+ [r]
38
+ );
39
+ return a.length ? /* @__PURE__ */ c("div", { "data-reuse-map": "", className: "space-y-1.5", children: [
40
+ /* @__PURE__ */ c("p", { className: "text-[12px] leading-snug text-slate-600 dark:text-muted-foreground", children: [
41
+ a.length === 1 ? "One field has" : `${a.length} fields have`,
42
+ " no field of the same name here. Pick where each goes:"
43
+ ] }),
44
+ /* @__PURE__ */ d("div", { className: "max-h-[240px] space-y-1 overflow-y-auto overscroll-contain pr-0.5", children: a.map((e) => /* @__PURE__ */ c("div", { "data-reuse-map-row": e, className: "flex items-center gap-1.5", children: [
45
+ /* @__PURE__ */ d(
46
+ "span",
47
+ {
48
+ className: "min-w-0 flex-1 truncate font-mono text-[11.5px] text-slate-700 dark:text-foreground",
49
+ "data-tip": (i == null ? void 0 : i.get(e)) ?? void 0,
50
+ children: e
51
+ }
52
+ ),
53
+ /* @__PURE__ */ d(v, { className: "h-3 w-3 shrink-0 text-slate-400" }),
54
+ /* @__PURE__ */ d(
55
+ $,
56
+ {
57
+ value: m[e] ?? f,
58
+ onChange: (n) => s({ ...m, [e]: n || null }),
59
+ ariaLabel: `Where ${e} goes`,
60
+ className: "h-7 w-[150px] shrink-0 text-[12px]",
61
+ options: p
62
+ }
63
+ )
64
+ ] }, e)) })
65
+ ] }) : null;
66
+ }
67
+ export {
68
+ W as FieldMapStep,
69
+ O as useFieldMapping
70
+ };
@@ -0,0 +1,127 @@
1
+ import { jsxs as t, Fragment as P, jsx as a } from "react/jsx-runtime";
2
+ import { BookmarkPlus as j, FilePlus2 as B, Download as M } from "lucide-react";
3
+ import { useState as n } from "react";
4
+ import { toast as d } from "sonner";
5
+ import { useNivaroClient as O } from "../../../context.js";
6
+ import { Popover as L, PopoverContent as $ } from "../../ui/popover.js";
7
+ import { downloadLayout as A } from "../ops/ops-api.js";
8
+ import { apiFailure as w } from "../overview/overview-api.js";
9
+ import { ToolButton as f } from "../toolbar-kit.js";
10
+ import { useRefreshTemplates as E, saveTemplate as I } from "./reuse-api.js";
11
+ import { reuseLabel as k, reuseInput as C, reusePrimary as K } from "./SectionReuseActions.js";
12
+ import { useFormFromRecord as R } from "./useFormFromRecord.js";
13
+ function Z({
14
+ collection: x,
15
+ bundle: o,
16
+ previewRecord: s,
17
+ onOpenLayout: S
18
+ }) {
19
+ const p = O(), F = E(), r = R(x), [T, l] = n(!1), [u, h] = n(""), [y, v] = n(""), [i, N] = n(!1), m = String((o == null ? void 0 : o.layout.name) ?? "Form"), g = () => {
20
+ l(!1), h(""), v("");
21
+ }, b = async () => {
22
+ if (!o || i) return;
23
+ const e = (u || m).trim();
24
+ N(!0);
25
+ try {
26
+ await I(p, {
27
+ kind: "form",
28
+ name: e,
29
+ description: y || null,
30
+ layout_id: Number(o.layout.id),
31
+ bundle: o
32
+ }), F("form"), d.success(`Saved ${e} as a template. Use it from New form → Template.`), g();
33
+ } catch (D) {
34
+ d.error(w(D, "Could not save the template").message);
35
+ } finally {
36
+ N(!1);
37
+ }
38
+ }, c = o ? Number(o.layout.id) : null;
39
+ return /* @__PURE__ */ t(P, { children: [
40
+ /* @__PURE__ */ t(L, { open: T, onOpenChange: (e) => e ? l(!0) : g(), children: [
41
+ /* @__PURE__ */ a(
42
+ f,
43
+ {
44
+ popover: !0,
45
+ onOpen: () => l(!0),
46
+ label: "Save as template…",
47
+ icon: /* @__PURE__ */ a(j, { className: "h-3.5 w-3.5" }),
48
+ hint: "Start new forms on any collection from this one",
49
+ disabled: !o,
50
+ data: { "data-more-save-template": "" }
51
+ }
52
+ ),
53
+ /* @__PURE__ */ t($, { align: "end", className: "w-[300px] p-3", children: [
54
+ /* @__PURE__ */ a("p", { className: "mb-2 text-[12px] leading-snug text-slate-600 dark:text-muted-foreground", children: "Sections, fields and how the form behaves are saved by field name. Rules for who gets it, defaults and links stay with this form." }),
55
+ /* @__PURE__ */ t("label", { className: "block", children: [
56
+ /* @__PURE__ */ a("span", { className: k, children: "Template name" }),
57
+ /* @__PURE__ */ a(
58
+ "input",
59
+ {
60
+ value: u,
61
+ placeholder: m,
62
+ onChange: (e) => h(e.target.value),
63
+ onKeyDown: (e) => {
64
+ e.key === "Enter" && b();
65
+ },
66
+ className: C
67
+ }
68
+ )
69
+ ] }),
70
+ /* @__PURE__ */ t("label", { className: "mt-2 block", children: [
71
+ /* @__PURE__ */ a("span", { className: k, children: "Description (optional)" }),
72
+ /* @__PURE__ */ a(
73
+ "input",
74
+ {
75
+ value: y,
76
+ onChange: (e) => v(e.target.value),
77
+ placeholder: "What it is for",
78
+ className: C
79
+ }
80
+ )
81
+ ] }),
82
+ /* @__PURE__ */ a("div", { className: "mt-3 flex justify-end", children: /* @__PURE__ */ a(
83
+ "button",
84
+ {
85
+ type: "button",
86
+ className: K,
87
+ disabled: i,
88
+ onClick: () => void b(),
89
+ children: i ? "Saving…" : "Save template"
90
+ }
91
+ ) })
92
+ ] })
93
+ ] }),
94
+ s && /* @__PURE__ */ a(
95
+ f,
96
+ {
97
+ label: r.busy ? "Making…" : "New form from this record",
98
+ icon: /* @__PURE__ */ a(B, { className: "h-3.5 w-3.5" }),
99
+ hint: `The fields ${s.label} has filled in, in one section`,
100
+ disabled: r.busy || !r.ready,
101
+ data: { "data-more-from-record": "" },
102
+ onClick: async () => {
103
+ const e = await r.make(s.id, s.label);
104
+ e != null && S(e);
105
+ }
106
+ }
107
+ ),
108
+ /* @__PURE__ */ a(
109
+ f,
110
+ {
111
+ label: "Download this form",
112
+ icon: /* @__PURE__ */ a(M, { className: "h-3.5 w-3.5" }),
113
+ hint: "A file another environment can bring in",
114
+ disabled: c == null,
115
+ data: { "data-more-download": "" },
116
+ onClick: () => {
117
+ c != null && A(p, c, m).catch(
118
+ (e) => d.error(w(e, "Could not download").message)
119
+ );
120
+ }
121
+ }
122
+ )
123
+ ] });
124
+ }
125
+ export {
126
+ Z as FormMoreMenu
127
+ };
@@ -0,0 +1,150 @@
1
+ import { jsxs as i, Fragment as w, jsx as o } from "react/jsx-runtime";
2
+ import { BookMarked as C, X as R } from "lucide-react";
3
+ import { useState as u } from "react";
4
+ import { toast as p } from "sonner";
5
+ import { useNivaroClient as $ } from "../../../context.js";
6
+ import { cn as j } from "../../../lib/utils.js";
7
+ import { sectionOp as F } from "../add-target.js";
8
+ import { apiFailure as v } from "../overview/overview-api.js";
9
+ import { useFieldMapping as M, FieldMapStep as B } from "./FieldMapStep.js";
10
+ import { useTemplates as S, useRefreshTemplates as A, planBlock as T, leftOutWords as L, deleteTemplate as O } from "./reuse-api.js";
11
+ import { reusePrimary as E } from "./SectionReuseActions.js";
12
+ const I = "px-2 pb-1 pt-3 text-[11.5px] font-semibold text-slate-500 dark:text-muted-foreground";
13
+ function K(e, t) {
14
+ const r = F(e, t);
15
+ return r.op === "group_create" && r.parent_key === null ? r.index : void 0;
16
+ }
17
+ function P({ t: e, ...t }) {
18
+ const r = $(), n = A(), [f, c] = u(!1), [y, h] = u(!1), [s, x] = u(!1), m = !!e.source_collection && e.source_collection !== t.collection, a = M(m ? e.fields : [], e.source_collection, t.collection), b = async () => {
19
+ if (!s) {
20
+ if (m && !f && a.needed.length) {
21
+ c(!0);
22
+ return;
23
+ }
24
+ x(!0);
25
+ try {
26
+ const l = await T(r, {
27
+ source: { template_id: e.id },
28
+ target_collection: t.collection,
29
+ target_bundle: t.bundle,
30
+ field_map: m ? a.map : void 0,
31
+ index: K(t.bundle, t.selected)
32
+ });
33
+ if (!l.ops.length) throw new Error("Nothing to add");
34
+ t.apply(l.ops, { label: `Add ${e.name}` });
35
+ const d = l.ops.find((_) => _.op === "group_create");
36
+ (d == null ? void 0 : d.op) === "group_create" && t.onSelect({ kind: "group", key: d.key });
37
+ const g = L(l);
38
+ g && p(`${e.name} added: ${g}`), c(!1);
39
+ } catch (l) {
40
+ p.error(v(l, "Could not add the section").message);
41
+ } finally {
42
+ x(!1);
43
+ }
44
+ }
45
+ }, k = async () => {
46
+ try {
47
+ await O(r, e.id), n("section");
48
+ } catch (l) {
49
+ p.error(v(l, "Could not remove it").message);
50
+ }
51
+ }, N = [
52
+ `${e.fields.length} ${e.fields.length === 1 ? "field" : "fields"}`,
53
+ e.source_collection && e.source_collection !== t.collection ? `from ${e.source_collection}` : null,
54
+ e.description
55
+ ].filter(Boolean).join(" · ");
56
+ return /* @__PURE__ */ i("div", { "data-library-section": e.id, children: [
57
+ /* @__PURE__ */ i("div", { className: "group flex items-center gap-0.5", children: [
58
+ /* @__PURE__ */ i(
59
+ "button",
60
+ {
61
+ type: "button",
62
+ disabled: s || a.loading,
63
+ onClick: () => void b(),
64
+ className: "flex w-full min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors hover:bg-muted disabled:opacity-60",
65
+ children: [
66
+ /* @__PURE__ */ i("span", { className: "flex min-w-0 flex-1 flex-col", children: [
67
+ /* @__PURE__ */ o("span", { className: "truncate text-[12.5px] font-medium text-slate-900 dark:text-foreground", children: e.name }),
68
+ /* @__PURE__ */ o("span", { className: "truncate text-[11.5px] text-slate-500 dark:text-muted-foreground", children: N })
69
+ ] }),
70
+ /* @__PURE__ */ o(C, { className: "h-3.5 w-3.5 shrink-0 text-slate-400" })
71
+ ]
72
+ }
73
+ ),
74
+ /* @__PURE__ */ o(
75
+ "button",
76
+ {
77
+ type: "button",
78
+ "aria-label": `Remove ${e.name} from the library`,
79
+ "data-tip": "Remove from the library",
80
+ onClick: () => h(!0),
81
+ className: "invisible inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-slate-400 transition-colors hover:bg-muted hover:text-slate-700 group-hover:visible focus-visible:visible dark:hover:text-foreground",
82
+ children: /* @__PURE__ */ o(R, { className: "h-3.5 w-3.5" })
83
+ }
84
+ )
85
+ ] }),
86
+ y && /* @__PURE__ */ i("div", { className: "mx-2 mb-1 flex items-center gap-2 text-[12px] text-slate-600 dark:text-muted-foreground", children: [
87
+ /* @__PURE__ */ o("span", { className: "flex-1", children: "Remove from the library? Forms keep their copies." }),
88
+ /* @__PURE__ */ o(
89
+ "button",
90
+ {
91
+ type: "button",
92
+ onClick: () => void k(),
93
+ className: "font-medium text-red-600 hover:underline dark:text-red-400",
94
+ children: "Remove"
95
+ }
96
+ ),
97
+ /* @__PURE__ */ o("button", { type: "button", onClick: () => h(!1), className: "hover:underline", children: "Keep" })
98
+ ] }),
99
+ f && /* @__PURE__ */ i(
100
+ "div",
101
+ {
102
+ className: j(
103
+ "mx-1 mb-2 rounded-md border border-slate-200 bg-slate-50 p-2 dark:border-border dark:bg-muted/40"
104
+ ),
105
+ children: [
106
+ /* @__PURE__ */ o(
107
+ B,
108
+ {
109
+ needed: a.needed,
110
+ map: a.map,
111
+ onChange: a.setMap,
112
+ targetCollection: t.collection
113
+ }
114
+ ),
115
+ /* @__PURE__ */ i("div", { className: "mt-2 flex justify-end gap-2", children: [
116
+ /* @__PURE__ */ o(
117
+ "button",
118
+ {
119
+ type: "button",
120
+ onClick: () => c(!1),
121
+ className: "text-[12px] text-slate-500 hover:underline dark:text-muted-foreground",
122
+ children: "Cancel"
123
+ }
124
+ ),
125
+ /* @__PURE__ */ o(
126
+ "button",
127
+ {
128
+ type: "button",
129
+ className: E,
130
+ disabled: s,
131
+ onClick: () => void b(),
132
+ children: s ? "Adding…" : "Add section"
133
+ }
134
+ )
135
+ ] })
136
+ ]
137
+ }
138
+ )
139
+ ] });
140
+ }
141
+ function Y(e) {
142
+ const { data: t = [] } = S("section"), r = t.filter((n) => e.matches(n.name, n.description, ...n.fields));
143
+ return r.length ? /* @__PURE__ */ i(w, { children: [
144
+ /* @__PURE__ */ o("p", { className: I, children: "Section library" }),
145
+ r.map((n) => /* @__PURE__ */ o(P, { t: n, ...e }, n.id))
146
+ ] }) : null;
147
+ }
148
+ export {
149
+ Y as LibraryRows
150
+ };
@@ -0,0 +1,20 @@
1
+ import "react/jsx-runtime";
2
+ import "lucide-react";
3
+ import "react";
4
+ import "sonner";
5
+ import { post as r } from "../../../lib/commands.js";
6
+ async function s(l, t) {
7
+ var i;
8
+ const o = await l.request(
9
+ r("/collection-layouts", {
10
+ collection: t.collection,
11
+ name: t.name,
12
+ layout_type: "grouped",
13
+ seed_fields: t.fields
14
+ })
15
+ ), e = (i = o == null ? void 0 : o.data) == null ? void 0 : i.id;
16
+ return e == null ? null : Number(e);
17
+ }
18
+ export {
19
+ s as createFormFromFields
20
+ };