@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,399 @@
1
+ import { isCanvasSlot as R, UNGROUPED_KEY as S, applyLayoutOps as C, GROUP_PATCH_KEYS as Y } from "../../lib/layout-ops.js";
2
+ import { titleCase as I } from "../../lib/utils.js";
3
+ import { newGroupKey as H } from "./add-target.js";
4
+ import { normalizedBundle as T, inPageOrder as K, plural as g, selectedPlacements as j, moveToZoneOps as J, zoneItems as U, FIELD_HOLDERS as Z } from "./field-zones.js";
5
+ import { readOverrides as D, withKey as X, asArray as P, placementPatchOf as q } from "./inspector/model.js";
6
+ import { isPinned as F, withPin as B } from "./pin.js";
7
+ import { PIN_KEY as Me, pinLocked as Ie, pinnedZone as Ue } from "./pin.js";
8
+ import { humanizeOpError as Q } from "./useLayoutDraft.js";
9
+ const y = (o) => ({ ok: !1, reason: o });
10
+ function m(o, e) {
11
+ if (e.ops.length === 0) return y("Nothing would change");
12
+ try {
13
+ return C(o, e.ops), e;
14
+ } catch (t) {
15
+ return y(Q(t.message));
16
+ }
17
+ }
18
+ const d = (o) => o.label || I(o.key), _ = (o, e) => o.groups.find((t) => t.key === e) ?? null, O = (o, e) => o.groups.filter((t) => t.parent_key === e).sort((t, n) => t.sort - n.sort);
19
+ function x(o, e) {
20
+ const t = e.parent_key ? _(o, e.parent_key) : null;
21
+ return (t ? t.tab_mode : o.layout.tab_mode) === "steps" ? "steps" : "tabs";
22
+ }
23
+ function V(o, e) {
24
+ return e.type === "tab" ? x(o, e) === "steps" ? "step" : "tab" : e.type === "container" ? e.tab_mode === "steps" ? "steps holder" : "tabs holder" : e.type === "content" ? "text block" : e.type === "metadata" ? "record info section" : "section";
25
+ }
26
+ function ke(o, e, t) {
27
+ const n = _(o, e);
28
+ return n ? F(n) === t ? y(t ? "Already pinned" : "Not pinned") : m(o, {
29
+ ok: !0,
30
+ ops: [{ op: "group_update", key: e, patch: { swap_config: B(n.swap_config, t) } }],
31
+ label: `${t ? "Pin" : "Unpin"} ${d(n)}`,
32
+ notes: []
33
+ }) : y("That section is no longer on this form");
34
+ }
35
+ function ee(o) {
36
+ const e = {};
37
+ for (const t of Y) t !== "label" && (e[t] = o[t]);
38
+ return e;
39
+ }
40
+ function te(o, e) {
41
+ return e ? e.kind === "header" ? "A header tile shows once in the header strip" : e.kind === "slot" && R(e) ? "This panel shows once on a form" : e.kind === "field" || e.kind === "slot" ? "A field shows once per section. Duplicate its section, or add the field to another section from Add" : e.key === S ? "Ungrouped is not a section" : _(o, e.key) ? null : "This comes from the parent form: override it here first" : "Select a section or field first";
42
+ }
43
+ function ye(o, e) {
44
+ const t = te(o, e);
45
+ if (t) return y(t);
46
+ const n = T(o), a = _(n, e.key), r = new Set(n.groups.map((c) => c.key)), i = [];
47
+ let l = 0;
48
+ const u = (c, p, v, $) => {
49
+ let h = `${c.key}_copy`;
50
+ for (let k = 2; r.has(h); k++) h = `${c.key}_copy_${k}`;
51
+ r.add(h);
52
+ const b = ee(c);
53
+ return b.swap_config = B(c.swap_config, !1), i.push({
54
+ op: "group_create",
55
+ key: h,
56
+ label: $,
57
+ group_type: c.type,
58
+ parent_key: p,
59
+ index: v,
60
+ patch: b
61
+ }), U(n, c.key).forEach((k, M) => {
62
+ k.field.startsWith("__") || l++, i.push({
63
+ op: "place",
64
+ field: k.field,
65
+ group_key: h,
66
+ index: M,
67
+ patch: q(k)
68
+ });
69
+ }), O(n, c.key).forEach((k, M) => {
70
+ u(k, h, M, k.label);
71
+ }), h;
72
+ }, f = u(a, a.parent_key, a.sort + 1, `${d(a)} (copy)`), s = l ? [`Its ${g(l, "field")} now ${l === 1 ? "shows" : "show"} in both copies`] : [];
73
+ return m(o, {
74
+ ok: !0,
75
+ ops: i,
76
+ label: `Duplicate ${d(a)}`,
77
+ notes: s,
78
+ select: { kind: "group", key: f }
79
+ });
80
+ }
81
+ function _e(o, e) {
82
+ const t = T(o);
83
+ if (t.layout.layout_type === "table") return y("Table layouts have no sections");
84
+ const n = K(t, j(t, e));
85
+ if (n.length === 0) return y("Select one or more fields first");
86
+ const a = n[0], r = a.group_key ? _(t, a.group_key) : null;
87
+ if (a.group_key && !r) return y("Those fields are not in a section of this form");
88
+ const i = (r == null ? void 0 : r.type) === "tab", l = (r == null ? void 0 : r.parent_key) ?? null, u = r && i ? x(t, r) : null, f = u === "steps" ? "step" : u === "tabs" ? "tab" : "section", s = r ?? _(t, S), c = s ? s.sort + 1 : Number.MAX_SAFE_INTEGER, p = H(t, f), v = {
89
+ op: "group_create",
90
+ key: p,
91
+ label: `New ${f}`,
92
+ group_type: i ? "tab" : "section",
93
+ parent_key: l,
94
+ index: c
95
+ }, $ = C(t, [v]), h = J($, n, p), b = [], k = n.length - h.ops.length;
96
+ return k > 0 && b.push(`${g(k, "field")} placed twice ${k === 1 ? "goes" : "go"} in once`), m(o, {
97
+ ok: !0,
98
+ ops: [v, ...h.ops],
99
+ label: `Wrap ${g(h.ops.length, "field")} in a new ${f}`,
100
+ notes: b,
101
+ select: { kind: "group", key: p }
102
+ });
103
+ }
104
+ function oe(o, e) {
105
+ if (e === S) return "Ungrouped is not a section";
106
+ const t = _(o, e);
107
+ return t ? t.type === "container" ? "Use Convert to turn its tabs into sections" : Z.has(t.type) ? null : "Only sections, tabs and steps hold fields" : "This comes from the parent form: override it here first";
108
+ }
109
+ function be(o, e) {
110
+ const t = oe(o, e);
111
+ if (t) return y(t);
112
+ const n = T(o), a = _(n, e), r = U(n, e), i = new Set(U(n, null).map((c) => c.field)), l = [], u = [], f = a.parent_key === null && i.size === 0 && !!_(n, S);
113
+ f && r.length > 0 && l.push({ op: "group_move", key: S, parent_key: null, index: a.sort }), l.push({ op: "group_remove", key: e, placements: "ungroup" }), r.length === 0 ? u.push("It holds no fields") : f ? u.push("Its fields stay where they are, as ungrouped fields") : u.push(`Its ${g(r.length, "field")} move to the end of Ungrouped`);
114
+ const s = r.filter((c) => i.has(c.field)).length;
115
+ return s > 0 && u.push(
116
+ `${g(s, "field")} already in Ungrouped ${s === 1 ? "stays" : "stay"} once`
117
+ ), m(o, {
118
+ ok: !0,
119
+ ops: l,
120
+ label: `Unwrap ${d(a)}`,
121
+ notes: u,
122
+ select: { kind: "group", key: S }
123
+ });
124
+ }
125
+ function ne(o) {
126
+ const e = [];
127
+ return o.is_collapsed && e.push("“Starts collapsed” does not apply to tabs or steps (kept, unused)"), P(o.summary_fields).length && e.push("The collapsed summary does not apply to tabs or steps (kept, unused)"), e;
128
+ }
129
+ function G(o) {
130
+ const e = [];
131
+ return P(o.visible_when).length && e.push("Its “Only when” rule works on steps and tabs only (kept, unused)"), P(o.skip_if_filled).length && e.push("“Skip when filled” works on steps only (kept, unused)"), e;
132
+ }
133
+ function A(o, e, t) {
134
+ const n = t === "steps" ? "step" : "tab", a = o.groups.filter((u) => u.parent_key === null).sort((u, f) => u.sort - f.sort), r = a[a.indexOf(e) - 1], i = ne(e), l = [{ op: "group_update", key: e.key, patch: { type: "tab" } }];
135
+ if ((r == null ? void 0 : r.type) === "container" && (r.tab_mode === "steps" ? "steps" : "tabs") === t && !F(r))
136
+ l.push({
137
+ op: "group_move",
138
+ key: e.key,
139
+ parent_key: r.key,
140
+ index: O(o, r.key).length
141
+ }), i.unshift(`Joins ${d(r)} as its last ${n}`);
142
+ else {
143
+ const u = H(o, t);
144
+ l.unshift({
145
+ op: "group_create",
146
+ key: u,
147
+ label: t === "steps" ? "Steps" : "Tabs",
148
+ group_type: "container",
149
+ parent_key: null,
150
+ index: e.sort,
151
+ patch: { tab_mode: t }
152
+ }), l.push({ op: "group_move", key: e.key, parent_key: u, index: 0 }), i.unshift(`A new ${t} holder takes its place, with it as the first ${n}`);
153
+ }
154
+ return m(o, {
155
+ ok: !0,
156
+ ops: l,
157
+ label: `Make ${d(e)} a ${n}`,
158
+ notes: i,
159
+ select: { kind: "group", key: e.key }
160
+ });
161
+ }
162
+ function L(o, e, t) {
163
+ const n = O(o, e.key), a = t ? [t] : n, r = [];
164
+ a.forEach((f, s) => {
165
+ r.push({ op: "group_move", key: f.key, parent_key: null, index: e.sort + 1 + s }), r.push({ op: "group_update", key: f.key, patch: { type: "section" } });
166
+ });
167
+ const i = a.flatMap(
168
+ (f) => G(f).map((s) => a.length > 1 ? `${d(f)}: ${s}` : s)
169
+ );
170
+ a.length === n.length && (r.push({ op: "group_remove", key: e.key, placements: "ungroup" }), i.unshift(`${d(e)} is removed: it would be empty`)), t ? i.unshift(`Moves out of ${d(e)}, just below it`) : i.unshift(`${g(n.length, "tab")} become sections below one another`);
171
+ const u = t ? `Make ${d(t)} a section` : `Turn the ${x(o, n[0] ?? e) === "steps" ? "steps" : "tabs"} of ${d(e)} into sections`;
172
+ return m(o, {
173
+ ok: !0,
174
+ ops: r,
175
+ label: u,
176
+ notes: i,
177
+ select: { kind: "group", key: (t ?? n[0] ?? e).key }
178
+ });
179
+ }
180
+ function E(o, e, t, n) {
181
+ const a = n === "steps" ? "steps" : "tabs", r = t ? O(o, t.key) : o.groups.filter((s) => s.parent_key === null && s.type === "tab"), i = r.filter((s) => s.key !== e.key).length, l = [];
182
+ e.type === "tab" && i > 0 ? l.push(
183
+ t ? `All ${r.length} tabs of ${d(t)} become ${a}: a holder shows its tabs one way` : `All ${r.length} tabs at the top of the form become ${a}: the form shows them one way`
184
+ ) : r.length > 0 && l.push(`${g(r.length, "tab")} show as ${a}`), n === "steps" && o.layout.validate_before_next && l.push("People must complete each step before the next");
185
+ const u = t ? [{ op: "group_update", key: t.key, patch: { tab_mode: n } }] : [{ op: "layout_update", patch: { tab_mode: n } }], f = e.type === "tab" ? d(e) : d(t ?? e);
186
+ return m(o, {
187
+ ok: !0,
188
+ ops: u,
189
+ label: e.type === "tab" ? `Make ${f} a ${a.slice(0, -1)}` : `Show ${f} as ${a}`,
190
+ notes: l,
191
+ select: { kind: "group", key: e.key }
192
+ });
193
+ }
194
+ function ge(o, e) {
195
+ const t = T(o), n = _(t, e);
196
+ if (!n) return [];
197
+ const a = n.parent_key ? _(t, n.parent_key) : null, r = [];
198
+ if (n.type === "section" && n.parent_key === null)
199
+ r.push({ to: "tab", title: "Make it a tab", plan: A(t, n, "tabs") }), r.push({ to: "step", title: "Make it a step", plan: A(t, n, "steps") });
200
+ else if (n.type === "tab") {
201
+ const i = x(t, n);
202
+ r.push({
203
+ to: "section",
204
+ title: "Make it a section",
205
+ plan: a ? L(t, a, n) : m(t, {
206
+ ok: !0,
207
+ ops: [{ op: "group_update", key: n.key, patch: { type: "section" } }],
208
+ label: `Make ${d(n)} a section`,
209
+ notes: G(n),
210
+ select: { kind: "group", key: n.key }
211
+ })
212
+ }), r.push(
213
+ i === "tabs" ? { to: "step", title: "Make it a step", plan: E(t, n, a, "steps") } : { to: "tab", title: "Make it a tab", plan: E(t, n, a, "tabs") }
214
+ );
215
+ } else if (n.type === "container") {
216
+ const i = n.tab_mode === "steps" ? "steps" : "tabs";
217
+ r.push(
218
+ i === "tabs" ? { to: "steps", title: "Turn its tabs into steps", plan: E(t, n, n, "steps") } : { to: "tabs", title: "Turn its steps into tabs", plan: E(t, n, n, "tabs") }
219
+ ), r.push({
220
+ to: "sections",
221
+ title: `Turn its ${i} into sections`,
222
+ plan: O(t, n.key).length ? L(t, n) : y(`It holds no ${i}`)
223
+ });
224
+ }
225
+ return r;
226
+ }
227
+ const se = ["visible_when", "hidden_for_roles", "locked_for_roles"], me = {
228
+ visible_when: "Only when (step conditions)",
229
+ hidden_for_roles: "Hidden for roles",
230
+ locked_for_roles: "Read-only for roles"
231
+ }, W = /* @__PURE__ */ new Set(["section", "metadata", "tab"]), $e = (o, e) => P(o[e]).length > 0, N = (o) => JSON.stringify(P(o));
232
+ function we(o) {
233
+ return W.has(o.type) ? se.filter((e) => e !== "visible_when" || o.type === "tab") : [];
234
+ }
235
+ function ve(o, e) {
236
+ return z(T(o)).filter(
237
+ (t) => t.key !== e && W.has(t.type)
238
+ );
239
+ }
240
+ function Se(o, e, t, n) {
241
+ const a = _(o, e);
242
+ if (!a) return y("That section is no longer on this form");
243
+ if (n.length === 0) return y("Pick at least one rule");
244
+ if (t.length === 0) return y("Pick the sections to copy onto");
245
+ const r = [], i = [];
246
+ let l = 0, u = 0;
247
+ for (const f of t) {
248
+ const s = _(o, f);
249
+ if (!s) continue;
250
+ const c = {};
251
+ for (const p of n) {
252
+ if (p === "visible_when" && s.type !== "tab") {
253
+ u++;
254
+ continue;
255
+ }
256
+ N(s[p]) !== N(a[p]) && (c[p] = a[p]);
257
+ }
258
+ Object.keys(c).length ? r.push({ op: "group_update", key: f, patch: c }) : l++;
259
+ }
260
+ return u && i.push(
261
+ `Step conditions skipped on ${g(u, "section")}: they work on steps and tabs only`
262
+ ), l && i.push(`${g(l, "section")} already ${l === 1 ? "has" : "have"} these rules`), m(o, {
263
+ ok: !0,
264
+ ops: r,
265
+ label: `Copy the rules of ${d(a)} to ${g(r.length, "section")}`,
266
+ notes: i
267
+ });
268
+ }
269
+ const Te = {
270
+ group_label: "Section name",
271
+ text_block: "Text block",
272
+ label: "Field label on this form",
273
+ label_override: "Field label on this form",
274
+ help: "Help text on this form",
275
+ field_label: "Field label (sets this form’s own)",
276
+ field_help: "Help text (sets this form’s own)"
277
+ }, re = (o) => o.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
278
+ function ie(o, e) {
279
+ return o ? new RegExp(re(o), e ? "g" : "gi") : null;
280
+ }
281
+ const w = (o) => typeof o == "string" && o !== "" ? o : null;
282
+ function Oe(o, e, t, n = {}) {
283
+ const a = ie(e, !!n.matchCase);
284
+ if (!a) return [];
285
+ const r = T(o), i = [], l = (s) => {
286
+ var p;
287
+ const c = ((p = s.before.match(a)) == null ? void 0 : p.length) ?? 0;
288
+ c !== 0 && i.push({ ...s, after: s.before.replace(a, () => t), count: c });
289
+ };
290
+ for (const s of z(r))
291
+ l({
292
+ id: `group:${s.key}`,
293
+ kind: "group_label",
294
+ group: s.key,
295
+ where: le(r, s),
296
+ before: s.label
297
+ }), s.type === "content" && w(s.content) && l({
298
+ id: `content:${s.key}`,
299
+ kind: "text_block",
300
+ group: s.key,
301
+ where: d(s),
302
+ before: s.content
303
+ });
304
+ const u = new Map((n.globals ?? []).map((s) => [s.field, s])), f = (s) => {
305
+ if (s === null) return "Ungrouped";
306
+ if (s === "__header__") return "Header strip";
307
+ const c = _(r, s);
308
+ return c ? d(c) : I(s);
309
+ };
310
+ for (const s of K(
311
+ r,
312
+ r.placements.filter((c) => !R(c))
313
+ )) {
314
+ const c = D(s), p = u.get(s.field), $ = `${w(c.label) ?? w(s.label_override) ?? w(p == null ? void 0 : p.label) ?? I(s.field)} · ${f(s.group_key)}`, h = { field: s.field, group_key: s.group_key }, b = (k) => `${k}:${s.field}:${s.group_key ?? ""}`;
315
+ w(c.label) ? l({ id: b("label"), kind: "label", at: h, where: $, before: c.label }) : w(s.label_override) ? l({
316
+ id: b("label_override"),
317
+ kind: "label_override",
318
+ at: h,
319
+ where: $,
320
+ before: s.label_override
321
+ }) : w(p == null ? void 0 : p.label) && !s.field.startsWith("__") && l({
322
+ id: b("field_label"),
323
+ kind: "field_label",
324
+ at: h,
325
+ where: $,
326
+ before: p == null ? void 0 : p.label
327
+ }), w(c.note) ? l({ id: b("help"), kind: "help", at: h, where: $, before: c.note }) : w(p == null ? void 0 : p.note) && !s.field.startsWith("__") && l({ id: b("field_help"), kind: "field_help", at: h, where: $, before: p == null ? void 0 : p.note });
328
+ }
329
+ return i;
330
+ }
331
+ function z(o) {
332
+ return o.groups.filter((t) => t.parent_key === null && t.key !== S).sort((t, n) => t.sort - n.sort).flatMap((t) => [t, ...O(o, t.key)]);
333
+ }
334
+ function le(o, e) {
335
+ const t = V(o, e);
336
+ return `${t[0].toUpperCase()}${t.slice(1)}`;
337
+ }
338
+ function Pe(o, e) {
339
+ if (e.length === 0) return y("Pick at least one match");
340
+ const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
341
+ for (const i of e)
342
+ if (i.group) {
343
+ const l = t.get(i.group) ?? {};
344
+ i.kind === "group_label" ? l.label = i.after : l.content = i.after, t.set(i.group, l);
345
+ } else if (i.at) {
346
+ const l = `${i.at.field}\0${i.at.group_key ?? ""}`;
347
+ n.set(l, [...n.get(l) ?? [], i]);
348
+ }
349
+ const a = [];
350
+ for (const [i, l] of t) a.push({ op: "group_update", key: i, patch: l });
351
+ for (const i of n.values()) {
352
+ const l = i[0].at, u = o.placements.find(
353
+ (p) => p.field === l.field && p.group_key === l.group_key
354
+ );
355
+ if (!u) continue;
356
+ let f = D(u);
357
+ const s = {};
358
+ let c = !1;
359
+ for (const p of i)
360
+ if (p.kind === "label_override") s.label_override = p.after;
361
+ else {
362
+ const v = p.kind === "label" || p.kind === "field_label" ? "label" : "note";
363
+ f = X(f ?? {}, v, p.after === "" ? void 0 : p.after), c = !0;
364
+ }
365
+ c && (s.overrides = f), a.push({ op: "update_placement", at: l, patch: s });
366
+ }
367
+ const r = e.reduce((i, l) => i + l.count, 0);
368
+ return m(o, {
369
+ ok: !0,
370
+ ops: a,
371
+ label: `Replace ${g(r, "match", "matches")} in labels`,
372
+ notes: []
373
+ });
374
+ }
375
+ export {
376
+ Te as HIT_KIND_LABELS,
377
+ Me as PIN_KEY,
378
+ se as RULE_KEYS,
379
+ me as RULE_LABELS,
380
+ ge as convertChoices,
381
+ Se as copyRulesPlan,
382
+ te as duplicateBlocked,
383
+ ye as duplicatePlan,
384
+ Oe as findHits,
385
+ d as groupName,
386
+ F as isPinned,
387
+ V as kindWord,
388
+ Ie as pinLocked,
389
+ ke as pinPlan,
390
+ Ue as pinnedZone,
391
+ Pe as replacePlan,
392
+ $e as ruleSet,
393
+ ve as ruleTargets,
394
+ we as rulesOf,
395
+ oe as unwrapBlocked,
396
+ be as unwrapPlan,
397
+ B as withPin,
398
+ _e as wrapPlan
399
+ };
@@ -0,0 +1,42 @@
1
+ import { jsx as m } from "react/jsx-runtime";
2
+ import { useState as u, useEffect as g } from "react";
3
+ import { cn as a } from "../../../lib/utils.js";
4
+ import { Setting as f, inputCls as p } from "../settings/controls.js";
5
+ import { readTesting as S, DEFAULT_COST_LIMIT as d, testingPatch as h } from "./testing-model.js";
6
+ function y(r) {
7
+ const { layout: s } = r, l = S(s.conditions), o = l.cost_limit, [n, e] = u(o == null ? "" : String(o));
8
+ g(() => e(o == null ? "" : String(o)), [o]);
9
+ const c = () => {
10
+ const t = Number(n.trim()), i = n.trim() === "" || !Number.isFinite(t) || t <= 0 ? null : Math.round(t);
11
+ if (i === o) return e(i == null ? "" : String(i));
12
+ r.set(
13
+ h(s.conditions, { ...l, cost_limit: i }),
14
+ i == null ? "Reset the form cost limit" : `Set the form cost limit to ${i}`
15
+ );
16
+ };
17
+ return /* @__PURE__ */ m(
18
+ f,
19
+ {
20
+ k: "tool.cost_limit",
21
+ htmlFor: "setting-cost_limit",
22
+ control: /* @__PURE__ */ m(
23
+ "input",
24
+ {
25
+ id: "setting-cost_limit",
26
+ inputMode: "numeric",
27
+ value: n,
28
+ placeholder: String(d),
29
+ onChange: (t) => e(t.target.value.replace(/[^0-9]/g, "")),
30
+ onBlur: c,
31
+ onKeyDown: (t) => {
32
+ t.key === "Enter" && t.target.blur();
33
+ },
34
+ className: a(p, "w-24 font-mono")
35
+ }
36
+ )
37
+ }
38
+ );
39
+ }
40
+ export {
41
+ y as CostLimitSetting
42
+ };