@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,214 @@
1
+ import { applyLayoutOps as v, isCanvasSlot as _, HEADER_GROUP_KEY as A, TABLE_FORM_GROUP_KEYS as I } from "../../../lib/layout-ops.js";
2
+ import { titleCase as q } from "../../../lib/utils.js";
3
+ import { readOverrides as w, withKey as L, asObject as N } from "../inspector/model.js";
4
+ import { humanizeOpError as z } from "../useLayoutDraft.js";
5
+ const K = { 12: "full", 6: "½", 4: "⅓", 3: "¼" }, T = (o) => o !== A && !(o !== null && I.includes(o));
6
+ function x(o, s) {
7
+ return o.placements.find(
8
+ (e) => e.field === s && T(e.group_key) && !_(e)
9
+ ) ?? null;
10
+ }
11
+ function P(o) {
12
+ return o.placements.filter(
13
+ (s) => !s.field.startsWith("__") && s.widget_id == null && T(s.group_key) && !_(s)
14
+ );
15
+ }
16
+ function S(o) {
17
+ return o.groups.filter((s) => !s.key.startsWith("__"));
18
+ }
19
+ function m(o, s) {
20
+ var f;
21
+ const e = typeof s == "string" ? s : s.field;
22
+ if (typeof s != "string") {
23
+ const i = w(s);
24
+ if (typeof i.label == "string" && i.label.trim()) return i.label.trim();
25
+ if (s.label_override) return s.label_override;
26
+ }
27
+ return ((f = o.fields.find((i) => i.field === e)) == null ? void 0 : f.label) || q(e.split(".").pop() ?? e);
28
+ }
29
+ function R(o) {
30
+ return o ? o.type === "tab" ? "step" : o.type === "container" ? "tab group" : o.type === "content" ? "text block" : "section" : "section";
31
+ }
32
+ function g(o, s) {
33
+ if (s === null) return "Ungrouped";
34
+ const e = o.groups.find((t) => t.key === s);
35
+ return e ? e.label || q(e.key) : s;
36
+ }
37
+ function $(o, s) {
38
+ const e = o.groups.filter((t) => t.parent_key === s).map((t) => ({ key: t.key, sort: t.sort }));
39
+ if (s === null)
40
+ for (const t of o.placements)
41
+ _(t) && e.push({ key: t.field, sort: t.sort });
42
+ return e.sort((t, f) => t.sort - f.sort);
43
+ }
44
+ function E(o, s, e) {
45
+ return o.placements.filter((t) => t.group_key === s && !_(t) && t !== e).sort((t, f) => t.sort - f.sort);
46
+ }
47
+ function M(o, s) {
48
+ const e = o.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 40) || "section", t = new Set(s.groups.map((i) => i.key));
49
+ let f = e;
50
+ for (let i = 2; t.has(f); i++) f = `${e}_${i}`;
51
+ return f;
52
+ }
53
+ function U(o) {
54
+ const s = N(o.layout.conditions);
55
+ return Array.isArray(s.role_ids) ? s.role_ids.map(String) : [];
56
+ }
57
+ class W extends Error {
58
+ }
59
+ function C(o) {
60
+ return v(o, [{ op: "layout_update", patch: {} }]);
61
+ }
62
+ function G(o, s, e) {
63
+ var O;
64
+ const t = (r) => {
65
+ throw new W(r);
66
+ }, f = (r) => x(o, r) ?? t(`${m(s, r)} is not on this form`), i = (r) => o.groups.find((a) => a.key === r) ?? t(`There is no section "${r}" on this form`);
67
+ switch (e.kind) {
68
+ case "move_field": {
69
+ const r = f(e.field), a = m(s, r), l = e.before ?? e.after;
70
+ let p = e.to_group;
71
+ l ? (l === e.field && t(`${a} cannot move next to itself`), p = f(l).group_key) : p !== null && i(p);
72
+ const c = E(o, p, r);
73
+ let n = c.length;
74
+ if (l) {
75
+ const y = c.findIndex((h) => h.field === l);
76
+ n = e.before ? y : y + 1;
77
+ }
78
+ const d = l ? `${e.before ? "before" : "after"} ${m(s, f(l))}` : `to ${g(o, p)}`;
79
+ return {
80
+ ops: [
81
+ {
82
+ op: "move",
83
+ from: { field: r.field, group_key: r.group_key },
84
+ to_group_key: p,
85
+ index: n
86
+ }
87
+ ],
88
+ steps: [`Move ${a} ${d}`],
89
+ notes: []
90
+ };
91
+ }
92
+ case "move_group": {
93
+ const r = i(e.group), a = e.before ?? e.after ?? t("Say where the section goes"), l = i(a);
94
+ l.key === r.key && t(`${r.label} cannot move next to itself`);
95
+ const c = $(o, l.parent_key).filter((n) => n.key !== r.key).findIndex((n) => n.key === l.key);
96
+ return {
97
+ ops: [
98
+ {
99
+ op: "group_move",
100
+ key: r.key,
101
+ parent_key: l.parent_key,
102
+ index: e.before ? c : c + 1
103
+ }
104
+ ],
105
+ steps: [
106
+ `Move ${R(r)} ${r.label} ${e.before ? "before" : "after"} ${l.label}`
107
+ ],
108
+ notes: []
109
+ };
110
+ }
111
+ case "set_field": {
112
+ const r = f(e.field), a = m(s, r);
113
+ let l = w(r);
114
+ const p = (h, u) => {
115
+ l = L(l, h, u) ?? {};
116
+ }, c = {}, n = [], d = [];
117
+ if (e.required !== void 0 && (p("required", e.required ? !0 : void 0), n.push(`Make ${a} ${e.required ? "required" : "optional"}`), e.role)) {
118
+ const h = s.roles.find((k) => k.id === e.role), u = (h == null ? void 0 : h.name) ?? "that role", b = U(o);
119
+ b.length > 0 && b.every((k) => k === e.role) ? d.push(`This form is only for ${u}, so this applies to ${u} alone.`) : d.push(
120
+ `Required is set per form, not per role. This form is ${b.length ? "also used by other roles" : "used by everyone it reaches"}, so ${a} becomes ${e.required ? "required" : "optional"} for them too. To limit it to ${u}, give ${u} its own form (Who gets this form) and run the command there.`
121
+ );
122
+ }
123
+ e.readonly !== void 0 && (p("readonly", e.readonly ? !0 : void 0), n.push(`Make ${a} ${e.readonly ? "read-only" : "editable"}`)), e.hidden !== void 0 && (p("hidden", e.hidden ? !0 : void 0), !e.hidden && r.is_visible === !1 && (c.is_visible = !0), n.push(`${e.hidden ? "Hide" : "Show"} ${a}`)), e.label !== void 0 && (p("label", e.label ?? void 0), n.push(
124
+ e.label ? `Rename ${a} to "${e.label}"` : `Use the field's own label for ${a}`
125
+ )), e.help !== void 0 && (p("note", e.help ?? void 0), n.push(e.help ? `Set the help text of ${a}` : `Remove the help text of ${a}`)), e.width !== void 0 && (c.col_span = e.width === 12 ? null : e.width, n.push(`Set the width of ${a} to ${K[e.width]}`)), n.length === 0 && t(`Nothing to change on ${a}`);
126
+ const y = JSON.stringify(w(r));
127
+ return JSON.stringify(l) !== y && (c.overrides = Object.keys(l).length ? l : null), Object.keys(c).length === 0 && t(`${a} is already like that`), {
128
+ ops: [
129
+ { op: "update_placement", at: { field: r.field, group_key: r.group_key }, patch: c }
130
+ ],
131
+ steps: n,
132
+ notes: d
133
+ };
134
+ }
135
+ case "add_field": {
136
+ const r = m(s, e.field), a = x(o, e.field);
137
+ return a && t(`${r} is already on this form (in ${g(o, a.group_key)}) — use move`), s.fields.some((l) => l.field === e.field) || t(`${r} is not a field of this collection`), e.to_group !== null && i(e.to_group), {
138
+ ops: [
139
+ {
140
+ op: "place",
141
+ field: e.field,
142
+ group_key: e.to_group,
143
+ index: E(o, e.to_group).length
144
+ }
145
+ ],
146
+ steps: [`Add ${r} to ${g(o, e.to_group)}`],
147
+ notes: []
148
+ };
149
+ }
150
+ case "remove_field": {
151
+ const r = f(e.field);
152
+ return {
153
+ ops: [{ op: "remove", at: { field: r.field, group_key: r.group_key } }],
154
+ steps: [`Take ${m(s, r)} off this form (its data is kept)`],
155
+ notes: []
156
+ };
157
+ }
158
+ case "add_group": {
159
+ const r = e.label.trim();
160
+ r || t("Give the new section a name");
161
+ const a = e.group_type;
162
+ let l = null, p;
163
+ if (e.after) {
164
+ let d = i(e.after);
165
+ a !== "tab" && d.parent_key !== null && (d = i(d.parent_key)), l = d.parent_key, p = $(o, l).findIndex((y) => y.key === d.key) + 1;
166
+ } else {
167
+ const d = S(o).filter((u) => u.type === a);
168
+ a === "tab" && d.length && (l = d[d.length - 1].parent_key);
169
+ const y = $(o, l), h = d.filter((u) => u.parent_key === l).pop() ?? S(o).filter((u) => u.parent_key === l).pop();
170
+ p = h ? y.findIndex((u) => u.key === h.key) + 1 : 0;
171
+ }
172
+ const c = M(r, o), n = e.after ? ` after ${g(o, e.after)}` : "";
173
+ return {
174
+ ops: [{ op: "group_create", key: c, label: r, group_type: a, parent_key: l, index: p }],
175
+ steps: [`Add ${a === "tab" ? "step" : "section"} "${r}"${n}`],
176
+ notes: []
177
+ };
178
+ }
179
+ case "update_group": {
180
+ const r = i(e.group), a = {}, l = [];
181
+ return (O = e.label) != null && O.trim() && e.label.trim() !== r.label && (a.label = e.label.trim(), l.push(`Rename ${R(r)} ${r.label} to "${a.label}"`)), e.collapsed !== void 0 && e.collapsed !== r.is_collapsed && (r.type !== "section" && t("Only sections can start collapsed"), a.is_collapsed = e.collapsed, l.push(`${r.label} starts ${e.collapsed ? "collapsed" : "open"}`)), l.length === 0 && t(`${r.label} is already like that`), { ops: [{ op: "group_update", key: r.key, patch: a }], steps: l, notes: [] };
182
+ }
183
+ default:
184
+ return t("Unknown command");
185
+ }
186
+ }
187
+ function J(o, s) {
188
+ if (o.length === 0) return { ok: !1, error: "Nothing to do" };
189
+ try {
190
+ let e = C(s.bundle);
191
+ const t = { ops: [], steps: [], notes: [] };
192
+ for (const f of o) {
193
+ const i = G(e, s, f);
194
+ e = v(e, i.ops), t.ops.push(...i.ops), t.steps.push(...i.steps), t.notes.push(...i.notes);
195
+ }
196
+ return v(s.bundle, t.ops), { ok: !0, ...t };
197
+ } catch (e) {
198
+ return { ok: !1, error: z(e instanceof Error ? e.message : String(e)) };
199
+ }
200
+ }
201
+ function Y(o) {
202
+ const [s, ...e] = o.steps;
203
+ return s ? e.length ? `${s} and ${e.length} more change${e.length === 1 ? "" : "s"}` : s : "Command";
204
+ }
205
+ export {
206
+ K as WIDTH_WORDS,
207
+ m as fieldLabel,
208
+ R as groupNoun,
209
+ J as intentsToOps,
210
+ S as namedGroups,
211
+ P as placedFields,
212
+ x as placementOf,
213
+ Y as planLabel
214
+ };
@@ -0,0 +1,242 @@
1
+ import { titleCase as w } from "../../../lib/utils.js";
2
+ import { placedFields as y, fieldLabel as v, namedGroups as C, placementOf as q } from "./intents.js";
3
+ const S = /^(the|a|an|field|section|step|tab|group)\s+|\s+(field|section|step|tab|group)$/g;
4
+ function $(s) {
5
+ let a = s.toLowerCase().replace(/[“”"'‘’`]/g, "").replace(/[^a-z0-9]+/g, " ").trim();
6
+ for (let o = 0; o < 3; o++) a = a.replace(S, "").trim();
7
+ return a;
8
+ }
9
+ function L(s, a) {
10
+ if (!s || !a) return 0;
11
+ const o = s.length, i = a.length;
12
+ if (Math.abs(o - i) > 3) return 0;
13
+ let n = Array.from({ length: i + 1 }, (t, e) => e);
14
+ for (let t = 1; t <= o; t++) {
15
+ const e = [t];
16
+ for (let f = 1; f <= i; f++)
17
+ e[f] = Math.min(n[f] + 1, e[f - 1] + 1, n[f - 1] + (s[t - 1] === a[f - 1] ? 0 : 1));
18
+ n = e;
19
+ }
20
+ return 1 - n[i] / Math.max(o, i);
21
+ }
22
+ function W(s, a) {
23
+ const o = $(s), i = $(a);
24
+ if (!o || !i) return 0;
25
+ if (o === i) return 100;
26
+ const n = o.replace(/ /g, ""), t = i.replace(/ /g, "");
27
+ if (n === t) return 95;
28
+ if (i.startsWith(o)) return 80;
29
+ if (i.includes(o)) return 60;
30
+ const e = i.split(" ");
31
+ if (o.split(" ").every((h) => e.some((r) => r.startsWith(h)))) return 50;
32
+ const f = L(n, t);
33
+ return f >= 0.75 ? Math.round(40 * f) : 0;
34
+ }
35
+ function b(s, a, o) {
36
+ let i = 0, n = [];
37
+ for (const e of a) {
38
+ const f = Math.max(0, ...e.names.map((h) => W(s, h)));
39
+ f === 0 || f < i || (f > i ? (i = f, n = [e]) : n.push(e));
40
+ }
41
+ const t = s.trim();
42
+ if (n.length === 0) return { ok: !1, error: `No ${o} called “${t}” on this form` };
43
+ if (n.length > 1) {
44
+ const e = n.slice(0, 4).map((f) => f.display);
45
+ return {
46
+ ok: !1,
47
+ error: `“${t}” could be ${e.slice(0, -1).join(", ")} or ${e[e.length - 1]} — be more specific`
48
+ };
49
+ }
50
+ return { ok: !0, value: n[0].value, score: i };
51
+ }
52
+ const N = /^(ungrouped|no section|outside( (of )?(the )?sections?)?|top( of the form)?)$/;
53
+ function x(s) {
54
+ const a = y(s.bundle), o = new Set(a.map((e) => e.field)), i = a.map((e) => ({
55
+ value: e.field,
56
+ names: [v(s, e), e.field],
57
+ display: v(s, e)
58
+ })), n = s.fields.filter((e) => !o.has(e.field) && !e.field.startsWith("__")).map((e) => ({
59
+ value: e.field,
60
+ names: [e.label || w(e.field), e.field],
61
+ display: e.label || w(e.field)
62
+ })), t = C(s.bundle).map((e) => ({
63
+ value: e.key,
64
+ names: [e.label, e.key],
65
+ display: e.label || w(e.key)
66
+ }));
67
+ return {
68
+ field: (e) => b(e, i, "field"),
69
+ newField: (e) => b(e, n, "field (not on the form yet)"),
70
+ group: (e) => b(e, t, "section"),
71
+ target: (e) => N.test($(e).replace(/^the /, "")) ? { ok: !0, value: null, score: 100 } : b(e, t, "section")
72
+ };
73
+ }
74
+ function k(s, a, o, i) {
75
+ const n = new RegExp(`\\s+(?:${a.source})\\s+`, "gi");
76
+ let t = null, e = null;
77
+ for (const f of s.matchAll(n)) {
78
+ const h = o(s.slice(0, f.index)), r = i(s.slice((f.index ?? 0) + f[0].length));
79
+ if (h.ok && r.ok) {
80
+ const l = h.score + r.score;
81
+ (!t || l > t.score) && (t = { a: h.value, b: r.value, score: l });
82
+ } else e ?? (e = h.ok ? r.ok ? null : r.error : h.error);
83
+ }
84
+ return t ? { ok: !0, a: t.a, b: t.b } : { ok: !1, error: e ?? "Say where it goes" };
85
+ }
86
+ function _(s) {
87
+ const a = s.toLowerCase().replace(/[-\s]*width$/, "").trim();
88
+ return /^(12|full|whole|1\/1)$/.test(a) ? 12 : /^(6|half|½|1\/2)$/.test(a) ? 6 : /^(4|a third|one third|third|⅓|1\/3)$/.test(a) ? 4 : /^(3|a quarter|one quarter|quarter|¼|1\/4)$/.test(a) ? 3 : null;
89
+ }
90
+ const E = "not required|required|mandatory|optional|read[- ]?only|editable|hidden|visible|full[- ]width|full|half[- ]width|half|(?:a |one )?third(?:[- ]width)?|(?:a |one )?quarter(?:[- ]width)?";
91
+ function G(s, a, o) {
92
+ var f, h;
93
+ const i = s.trim().replace(/[.!]+$/, "").replace(/\s+/g, " "), n = (r) => ({ ok: !1, error: r, unknown: !1 }), t = (r) => ({ ok: !0, intent: r });
94
+ let e;
95
+ if (e = i.match(/^(?:move|put|drag) (.+)$/i), e) {
96
+ const r = e[1], l = k(
97
+ r,
98
+ /before|above|after|below/,
99
+ (d) => o.field(d),
100
+ (d) => o.field(d)
101
+ ), u = (f = r.match(/\s(before|above|after|below)\s/i)) == null ? void 0 : f[1].toLowerCase(), p = u === "before" || u === "above";
102
+ if (l.ok)
103
+ return t({
104
+ kind: "move_field",
105
+ field: l.a,
106
+ to_group: null,
107
+ ...p ? { before: l.b } : { after: l.b }
108
+ });
109
+ if (u) {
110
+ const d = k(
111
+ r,
112
+ /before|above|after|below/,
113
+ (m) => o.group(m),
114
+ (m) => o.group(m)
115
+ );
116
+ if (d.ok)
117
+ return t({
118
+ kind: "move_group",
119
+ group: d.a,
120
+ ...p ? { before: d.b } : { after: d.b }
121
+ });
122
+ const g = k(
123
+ r,
124
+ /before|above|after|below/,
125
+ (m) => o.field(m),
126
+ (m) => o.target(m)
127
+ );
128
+ return g.ok ? t({ kind: "move_field", field: g.a, to_group: g.b }) : n(l.error);
129
+ }
130
+ const c = k(
131
+ r,
132
+ /to|into|in|under|onto/,
133
+ (d) => o.field(d),
134
+ (d) => o.target(d)
135
+ );
136
+ return c.ok ? t({ kind: "move_field", field: c.a, to_group: c.b }) : n(c.error);
137
+ }
138
+ if (e = i.match(/^set (?:the )?width (?:of )?(.+?) (?:to )?(\S+(?:[- ]width)?)$/i) ?? i.match(/^set (?:the )?(.+?)(?:'s)? width (?:to )?(\S+)$/i), e) {
139
+ const r = _(e[2]);
140
+ if (!r) return n("Width is full, half, third or quarter (12, 6, 4 or 3)");
141
+ const l = o.field(e[1]);
142
+ return l.ok ? t({ kind: "set_field", field: l.value, width: r }) : n(l.error);
143
+ }
144
+ if (e = i.match(
145
+ new RegExp(
146
+ `^(?:make|set|mark) (.+?) (?:to )?(${E})(?: (?:for|to) (?:the )?(.+?)(?: role)?)?$`,
147
+ "i"
148
+ )
149
+ ), e) {
150
+ const r = o.field(e[1]);
151
+ if (!r.ok) return n(r.error);
152
+ const l = e[2].toLowerCase().replace(/[- ]/g, "");
153
+ let u;
154
+ if (e[3]) {
155
+ const c = b(
156
+ e[3],
157
+ a.roles.map((d) => ({ value: d.id, names: [d.name], display: d.name })),
158
+ "role"
159
+ );
160
+ if (!c.ok) return n(c.error.replace(" on this form", ""));
161
+ u = c.value;
162
+ }
163
+ const p = _(e[2]);
164
+ return t(p ? { kind: "set_field", field: r.value, width: p } : l === "required" || l === "mandatory" ? { kind: "set_field", field: r.value, required: !0, ...u ? { role: u } : {} } : l === "notrequired" || l === "optional" ? { kind: "set_field", field: r.value, required: !1, ...u ? { role: u } : {} } : l === "readonly" ? { kind: "set_field", field: r.value, readonly: !0 } : l === "editable" ? { kind: "set_field", field: r.value, readonly: !1 } : l === "hidden" ? { kind: "set_field", field: r.value, hidden: !0 } : { kind: "set_field", field: r.value, hidden: !1 });
165
+ }
166
+ if (e = i.match(/^(hide|show|unhide) (.+)$/i), e) {
167
+ const r = o.field(e[2]);
168
+ return r.ok ? t({ kind: "set_field", field: r.value, hidden: e[1].toLowerCase() === "hide" }) : n(r.error);
169
+ }
170
+ if (e = i.match(/^rename (?:the )?(?:(section|step|tab|group|field) )?(.+)$/i), e) {
171
+ const r = (h = e[1]) == null ? void 0 : h.toLowerCase(), l = r && r !== "field", u = (c) => {
172
+ const d = c.trim().replace(/^["“'‘]|["”'’]$/g, "").trim();
173
+ return d ? { ok: !0, value: d.slice(0, 80), score: 0 } : { ok: !1, error: "Say the new name" };
174
+ };
175
+ if (!l) {
176
+ const c = k(e[2], /to|as/, (d) => o.field(d), u);
177
+ if (c.ok) return t({ kind: "set_field", field: c.a, label: c.b });
178
+ if (r === "field") return n(c.error);
179
+ }
180
+ const p = k(e[2], /to|as/, (c) => o.group(c), u);
181
+ return p.ok ? t({ kind: "update_group", group: p.a, label: p.b }) : n(p.error);
182
+ }
183
+ if (e = i.match(
184
+ /^add (?:a |an |new |another )*(section|step|tab) (?:called |named )?(.+?)(?: after (.+))?$/i
185
+ ), e) {
186
+ const r = e[1].toLowerCase() === "section" ? "section" : "tab";
187
+ let l = e[2].trim().replace(/^["“'‘]|["”'’]$/g, ""), u;
188
+ if (e[3]) {
189
+ const p = o.group(e[3]);
190
+ p.ok ? u = p.value : l = `${l} after ${e[3]}`;
191
+ }
192
+ return l ? t({ kind: "add_group", label: l, group_type: r, ...u ? { after: u } : {} }) : n("Give the new section a name");
193
+ }
194
+ if (e = i.match(/^add (.+)$/i), e) {
195
+ const r = k(
196
+ e[1],
197
+ /to|into|in|under/,
198
+ (u) => o.newField(u),
199
+ (u) => o.target(u)
200
+ );
201
+ if (r.ok) return t({ kind: "add_field", field: r.a, to_group: r.b });
202
+ const l = o.field(e[1].split(/\s+(?:to|into|in)\s+/i)[0]);
203
+ return l.ok && q(a.bundle, l.value) ? n(`${v(a, l.value)} is already on the form — use “move”`) : /\s(to|into|in|under)\s/i.test(e[1]) ? n(r.error) : n("Say where it goes: add <field> to <section>");
204
+ }
205
+ if (e = i.match(/^(?:remove|delete|drop) (.+?)(?: from (?:the |this )?(?:form|layout))?$/i), e) {
206
+ const r = o.field(e[1]);
207
+ return r.ok ? t({ kind: "remove_field", field: r.value }) : n(r.error);
208
+ }
209
+ if (e = i.match(/^(collapse|expand|open|close) (.+)$/i), e) {
210
+ const r = o.group(e[2]);
211
+ if (!r.ok) return n(r.error);
212
+ const l = e[1].toLowerCase();
213
+ return t({
214
+ kind: "update_group",
215
+ group: r.value,
216
+ collapsed: l === "collapse" || l === "close"
217
+ });
218
+ }
219
+ return { ok: !1, error: "That is not a command the palette knows", unknown: !0 };
220
+ }
221
+ function T(s, a) {
222
+ const o = s.split(/[;\n]+/).map((t) => t.trim()).filter(Boolean);
223
+ if (o.length === 0) return { ok: !1, error: "Type a command", unknown: !1 };
224
+ const i = x(a), n = [];
225
+ for (const t of o) {
226
+ const e = G(t, a, i);
227
+ if (!e.ok)
228
+ return {
229
+ ok: !1,
230
+ error: o.length > 1 ? `“${t}”: ${e.error}` : e.error,
231
+ unknown: e.unknown
232
+ };
233
+ n.push(e.intent);
234
+ }
235
+ return { ok: !0, intents: n };
236
+ }
237
+ export {
238
+ W as nameScore,
239
+ $ as normName,
240
+ T as parseCommand,
241
+ _ as parseWidth
242
+ };
@@ -1,7 +1,11 @@
1
- import { createContext as r, useContext as n } from "react";
2
- const t = r(null);
3
- function u() {
4
- return n(t);
1
+ import { createContext as l, useContext as c } from "react";
2
+ import { isCanvasSlot as f } from "../../lib/layout-ops.js";
3
+ function k(e) {
4
+ return e.kind === "group" ? e.key : e.kind === "header" ? null : e.group_key;
5
+ }
6
+ const s = l(null);
7
+ function y() {
8
+ return c(s);
5
9
  }
6
10
  function i(e) {
7
11
  switch (e.kind) {
@@ -14,8 +18,24 @@ function i(e) {
14
18
  return `header:${e.field}`;
15
19
  }
16
20
  }
21
+ function o(e) {
22
+ return e.kind === "field" ? !0 : e.kind === "slot" && !f(e);
23
+ }
24
+ function m(e, n, r) {
25
+ if (!(r != null && r.additive) || !o(n) || !e.every(o)) return [n];
26
+ const t = i(n);
27
+ return e.some((u) => i(u) === t) ? e.filter((u) => i(u) !== t) : [...e, n];
28
+ }
29
+ function g(e, n) {
30
+ const r = i(n);
31
+ return e.selection ? e.selection.some((t) => i(t) === r) : e.selected != null && i(e.selected) === r;
32
+ }
17
33
  export {
18
- t as LayoutDesignContext,
34
+ s as LayoutDesignContext,
35
+ o as isMultiSelectable,
36
+ g as isSelectedIn,
37
+ m as nextSelection,
38
+ k as revealGroupKey,
19
39
  i as targetKey,
20
- u as useLayoutDesign
40
+ y as useLayoutDesign
21
41
  };