@nivaro/react 0.3.36 → 0.3.37

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 (102) hide show
  1. package/dist/components/slots/CommentsSlot.js +44 -36
  2. package/dist/full.css +1 -1
  3. package/dist/hooks/useSessionRecorder.js +1 -1
  4. package/dist/index.d.ts +9 -1
  5. package/dist/shared/components/AgentBadge.js +26 -0
  6. package/dist/shared/components/AgentQuestionsCard.js +198 -0
  7. package/dist/shared/components/ItemEditForm.js +3329 -3263
  8. package/dist/shared/components/McpConnectionScope.js +480 -0
  9. package/dist/shared/components/MyWorkView.js +223 -208
  10. package/dist/shared/components/RecordReadView.js +620 -575
  11. package/dist/shared/components/chat/ChatPanel.js +683 -671
  12. package/dist/shared/components/imports/DownloadSampleButton.js +69 -0
  13. package/dist/shared/components/imports/ImportConsole.js +106 -104
  14. package/dist/shared/components/imports/RunDetailSheet.js +11 -10
  15. package/dist/shared/components/item-edit/FieldAffordances.js +32 -32
  16. package/dist/shared/components/item-edit/FormTour.js +279 -0
  17. package/dist/shared/components/item-edit/GroupSection.js +377 -360
  18. package/dist/shared/components/item-edit/PersonalDefaultControl.js +28 -28
  19. package/dist/shared/components/item-edit/entry/EntryStrip.js +30 -26
  20. package/dist/shared/components/item-edit/form-density.js +36 -0
  21. package/dist/shared/components/item-edit/useFormUsageBeacon.js +59 -46
  22. package/dist/shared/components/item-edit/usePersonalDefaults.js +312 -296
  23. package/dist/shared/components/layout-editor/AddPanel.js +349 -192
  24. package/dist/shared/components/layout-editor/DesignNode.js +126 -112
  25. package/dist/shared/components/layout-editor/EditorTopBar.js +123 -103
  26. package/dist/shared/components/layout-editor/LayoutEditor.js +829 -751
  27. package/dist/shared/components/layout-editor/PlaceTools.js +334 -0
  28. package/dist/shared/components/layout-editor/SlashInsert.js +252 -0
  29. package/dist/shared/components/layout-editor/StructureMenu.js +285 -242
  30. package/dist/shared/components/layout-editor/add-target.js +54 -43
  31. package/dist/shared/components/layout-editor/ai-forms/AiComposer.js +238 -155
  32. package/dist/shared/components/layout-editor/ai-forms/AiFormsButton.js +1 -1
  33. package/dist/shared/components/layout-editor/ai-forms/ai-forms-api.js +15 -12
  34. package/dist/shared/components/layout-editor/dnd/LayoutDndProvider.js +347 -189
  35. package/dist/shared/components/layout-editor/dnd/TrashZone.js +60 -32
  36. package/dist/shared/components/layout-editor/dnd/UndoChip.js +76 -0
  37. package/dist/shared/components/layout-editor/dnd/merge-drop.js +33 -0
  38. package/dist/shared/components/layout-editor/dnd/multi-drop.js +87 -0
  39. package/dist/shared/components/layout-editor/dnd/node.js +115 -105
  40. package/dist/shared/components/layout-editor/dnd/sensors.js +23 -0
  41. package/dist/shared/components/layout-editor/dnd/trash-drop.js +34 -28
  42. package/dist/shared/components/layout-editor/dnd/trash-links.js +97 -0
  43. package/dist/shared/components/layout-editor/even-row.js +86 -0
  44. package/dist/shared/components/layout-editor/field-list.js +99 -0
  45. package/dist/shared/components/layout-editor/format-painter.js +102 -0
  46. package/dist/shared/components/layout-editor/grid-guides.js +15 -13
  47. package/dist/shared/components/layout-editor/inspector/BehaviourSettings.js +150 -132
  48. package/dist/shared/components/layout-editor/inspector/BulkInspector.js +57 -53
  49. package/dist/shared/components/layout-editor/inspector/EvenRowAction.js +31 -0
  50. package/dist/shared/components/layout-editor/inspector/GroupInspector.js +154 -141
  51. package/dist/shared/components/layout-editor/inspector/Inspector.js +209 -178
  52. package/dist/shared/components/layout-editor/inspector/LookTab.js +106 -98
  53. package/dist/shared/components/layout-editor/inspector/RulesTab.js +38 -37
  54. package/dist/shared/components/layout-editor/inspector/kit.js +280 -223
  55. package/dist/shared/components/layout-editor/keyboard-move.js +15 -15
  56. package/dist/shared/components/layout-editor/lint/LabelStyle.js +201 -0
  57. package/dist/shared/components/layout-editor/lint/LintPanel.js +132 -84
  58. package/dist/shared/components/layout-editor/lint/lint-api.js +65 -28
  59. package/dist/shared/components/layout-editor/nav/NavTools.js +14 -12
  60. package/dist/shared/components/layout-editor/nav/ZoomControls.js +145 -0
  61. package/dist/shared/components/layout-editor/nav/useEditorNav.js +34 -32
  62. package/dist/shared/components/layout-editor/nav/view-prefs.js +100 -15
  63. package/dist/shared/components/layout-editor/outputs/LayoutFile.js +89 -0
  64. package/dist/shared/components/layout-editor/outputs/OutputsButton.js +272 -195
  65. package/dist/shared/components/layout-editor/outputs/layout-file-plan.js +176 -0
  66. package/dist/shared/components/layout-editor/outputs/output-api.js +71 -37
  67. package/dist/shared/components/layout-editor/overview/describe-conditions.js +16 -11
  68. package/dist/shared/components/layout-editor/overview/purpose.js +5 -5
  69. package/dist/shared/components/layout-editor/parity-keys.json.js +1 -1
  70. package/dist/shared/components/layout-editor/pin.js +37 -19
  71. package/dist/shared/components/layout-editor/place-clip.js +257 -0
  72. package/dist/shared/components/layout-editor/preview/PreviewModes.js +27 -26
  73. package/dist/shared/components/layout-editor/preview/PreviewPanes.js +148 -117
  74. package/dist/shared/components/layout-editor/preview/SampleRecord.js +113 -0
  75. package/dist/shared/components/layout-editor/preview/preview-model.js +79 -60
  76. package/dist/shared/components/layout-editor/preview/sample-record.js +105 -0
  77. package/dist/shared/components/layout-editor/removed-log.js +151 -0
  78. package/dist/shared/components/layout-editor/reuse/LibraryRows.js +109 -78
  79. package/dist/shared/components/layout-editor/reuse/linked-sections.js +373 -0
  80. package/dist/shared/components/layout-editor/revert-element.js +140 -0
  81. package/dist/shared/components/layout-editor/section-structure.js +193 -170
  82. package/dist/shared/components/layout-editor/settings/EntrySection.js +63 -45
  83. package/dist/shared/components/layout-editor/settings/LayoutSection.js +63 -32
  84. package/dist/shared/components/layout-editor/settings/ResolveSettings.js +179 -137
  85. package/dist/shared/components/layout-editor/settings/WhoSection.js +18 -17
  86. package/dist/shared/components/layout-editor/settings/settings-registry.js +24 -0
  87. package/dist/shared/components/layout-editor/shortcuts.js +21 -16
  88. package/dist/shared/components/layout-editor/structure-ops.js +221 -195
  89. package/dist/shared/components/layout-editor/usage/UsagePanel.js +133 -85
  90. package/dist/shared/components/layout-editor/usage/refusal-lens.js +130 -0
  91. package/dist/shared/components/layout-editor/usage/usage-api.js +12 -11
  92. package/dist/shared/components/panels/CommentPanel.js +47 -45
  93. package/dist/shared/components/panels/RevisionsPanel.js +66 -64
  94. package/dist/shared/components/panels/TaskPanel.js +395 -332
  95. package/dist/shared/components/profile/AgentsPanel.js +196 -147
  96. package/dist/shared/components/profile/ConnectionRollback.js +329 -0
  97. package/dist/shared/components/profile/MyDefaultsCard.js +526 -520
  98. package/dist/shared/lib/entry-config.js +22 -22
  99. package/dist/shared/lib/form-usage-beacon.js +91 -55
  100. package/dist/shared/lib/layout-lint.js +530 -284
  101. package/dist/shared/lib/layout-resolve.js +58 -44
  102. package/package.json +1 -1
@@ -0,0 +1,334 @@
1
+ import { jsx as u, jsxs as K, Fragment as J } from "react/jsx-runtime";
2
+ import { ClipboardCopy as Q, ClipboardPaste as X, Paintbrush as N, Undo2 as U } from "lucide-react";
3
+ import { useRef as x, useState as ee, useCallback as b, useEffect as V, useMemo as W, createContext as te, useContext as ne } from "react";
4
+ import { toast as v } from "sonner";
5
+ import { titleCase as M, cn as oe } from "../../lib/utils.js";
6
+ import { targetKey as re } from "./design-context.js";
7
+ import { looksLikeFieldList as D, placeListPlan as ie } from "./field-list.js";
8
+ import { paintBlocked as le, lookFrom as q, paintPlan as ce } from "./format-painter.js";
9
+ import { isTyping as j } from "./is-typing.js";
10
+ import { makeClip as se, parseClip as T, pastePlan as ae, CLIP_STORAGE_KEY as z, serializeClip as R } from "./place-clip.js";
11
+ import { revertPlan as B } from "./revert-element.js";
12
+ import { MenuItem as E } from "./StructureMenu.js";
13
+ import { isMacLike as Y, registerShortcut as I } from "./shortcuts.js";
14
+ I({
15
+ id: "copy-piece",
16
+ area: "Editing",
17
+ keys: [["mod", "c"]],
18
+ label: "Copy the selected field or section (paste it on any form of this collection)"
19
+ });
20
+ I({
21
+ id: "paste-piece",
22
+ area: "Editing",
23
+ keys: [["mod", "v"]],
24
+ label: "Paste after the selection: a copied field or section, or a list of field names"
25
+ });
26
+ I({
27
+ id: "copy-look",
28
+ area: "Editing",
29
+ keys: [["alt", "mod", "c"]],
30
+ label: "Copy the selected field’s look and rules"
31
+ });
32
+ I({
33
+ id: "paste-look",
34
+ area: "Editing",
35
+ keys: [["alt", "mod", "v"]],
36
+ label: "Paint that look onto the selected fields"
37
+ });
38
+ const Z = te(null), $e = Z.Provider, de = () => ne(Z), A = () => !!document.querySelector('[data-radix-popper-content-wrapper], [role="menu"]'), F = (i) => Y() ? `⌘${i}` : `Ctrl+${i}`, _ = (i) => Y() ? `⌥⌘${i}` : `Ctrl+Alt+${i}`;
39
+ function ue(i) {
40
+ try {
41
+ localStorage.setItem(z, R(i));
42
+ } catch {
43
+ }
44
+ }
45
+ function G() {
46
+ try {
47
+ return T(localStorage.getItem(z));
48
+ } catch {
49
+ return null;
50
+ }
51
+ }
52
+ function Ke(i) {
53
+ const n = x(i);
54
+ n.current = i;
55
+ const [k, f] = ee(null), C = x(k);
56
+ C.current = k;
57
+ const d = x({}), p = i.savedBundle ?? i.bundle;
58
+ p && !d.current[i.layoutId] && (d.current[i.layoutId] = p);
59
+ const a = b((e) => {
60
+ const t = n.current.fields.find((l) => l.field === e);
61
+ return (t == null ? void 0 : t.label) || M(e);
62
+ }, []), S = b((e, t) => {
63
+ const l = n.current.fields, o = l.find((c) => c.field === e), r = l.find((c) => c.field === t);
64
+ return !!o && !!r && (o.type ?? "") === (r.type ?? "") && (o.interface ?? "") === (r.interface ?? "");
65
+ }, []), s = b((e, t = {}) => e.ok ? (n.current.apply(e.ops, { label: e.label }), e.select && n.current.onSelection([e.select]), t.toastNotes !== !1 && v.success(
66
+ e.label,
67
+ e.notes.length ? { description: e.notes.join(". ") } : void 0
68
+ ), !0) : (v(e.reason), !1), []), P = b(
69
+ (e) => {
70
+ const { bundle: t, collection: l, layoutId: o, layoutName: r } = n.current;
71
+ if (!t) return null;
72
+ const c = se(t, e, { collection: l, layoutId: o, layoutName: r, fieldLabel: a });
73
+ return c.ok ? (ue(c.clip), v.success(`Copied ${c.clip.label}`, {
74
+ description: `Paste with ${F("V")} on this form or another ${M(l)} form`
75
+ }), c.clip) : (v(c.reason), null);
76
+ },
77
+ [a]
78
+ ), m = b(
79
+ (e) => {
80
+ const { bundle: t, collection: l, fields: o, selection: r } = n.current;
81
+ if (!t) return !1;
82
+ const c = r.length ? r[r.length - 1] : null, h = T(e) ?? (e != null && e.trim() ? null : G());
83
+ if (h) {
84
+ const L = o.length ? new Set(o.map((H) => H.field)) : null;
85
+ return s(
86
+ ae(t, h, { collection: l, knownFields: L, selected: c, fieldLabel: a })
87
+ );
88
+ }
89
+ if (e && D(e)) {
90
+ const L = (c == null ? void 0 : c.kind) === "header" ? "header" : "form";
91
+ return s(ie(t, e, o, c, L));
92
+ }
93
+ return e != null && e.trim() || v("Nothing to paste: copy a field or section first"), !1;
94
+ },
95
+ [s, a]
96
+ ), g = b(
97
+ (e) => {
98
+ const { bundle: t } = n.current, l = le(e), o = !l && t && e ? q(t, e) : null;
99
+ if (!o || !e || e.kind === "group") {
100
+ v(l ?? "Select a field first");
101
+ return;
102
+ }
103
+ f({ ...o, name: a(e.field) }), v.success(`Copied the look of ${a(e.field)}`, {
104
+ description: `Select other fields and press ${_("V")}, or right-click them`
105
+ });
106
+ },
107
+ [a]
108
+ ), w = b(
109
+ (e, t) => {
110
+ const { bundle: l } = n.current;
111
+ return l ? s(ce(l, e, t, { sameKind: S, fieldLabel: a })) : !1;
112
+ },
113
+ [s, S, a]
114
+ ), y = b(
115
+ (e) => {
116
+ const { bundle: t, savedBundle: l, layoutId: o } = n.current;
117
+ if (!t) return { ok: !1, reason: "The form is still loading" };
118
+ const r = B(t, l, e, { fieldLabel: a, baseline: "saved" });
119
+ if (r.ok) return r;
120
+ const c = d.current[o];
121
+ if (c && c !== l) {
122
+ const h = B(t, c, e, { fieldLabel: a, baseline: "opened" });
123
+ if (h.ok) return h;
124
+ }
125
+ return r;
126
+ },
127
+ [a]
128
+ );
129
+ V(() => {
130
+ const e = (o) => {
131
+ const r = n.current.rootRef.current;
132
+ if (!(r != null && r.isConnected) || j(o.target) || A()) return !1;
133
+ const c = o.target;
134
+ return !c || c === document.body || c === document.documentElement || r.contains(c);
135
+ }, t = (o) => {
136
+ var h, L;
137
+ if (!e(o) || n.current.selection.length === 0) return;
138
+ const r = (h = window.getSelection) == null ? void 0 : h.call(window);
139
+ if (r && !r.isCollapsed && r.toString().trim()) return;
140
+ const c = P(n.current.selection);
141
+ c && (o.preventDefault(), (L = o.clipboardData) == null || L.setData("text/plain", R(c)));
142
+ }, l = (o) => {
143
+ var h;
144
+ if (!e(o)) return;
145
+ const r = ((h = o.clipboardData) == null ? void 0 : h.getData("text/plain")) ?? null;
146
+ !(T(r) ?? (r != null && r.trim() ? null : G())) && !(r && D(r)) || (o.preventDefault(), m(r));
147
+ };
148
+ return document.addEventListener("copy", t), document.addEventListener("paste", l), () => {
149
+ document.removeEventListener("copy", t), document.removeEventListener("paste", l);
150
+ };
151
+ }, [P, m]), V(() => {
152
+ const e = (t) => {
153
+ if (!(t.metaKey || t.ctrlKey) || !t.altKey || t.shiftKey || t.defaultPrevented || t.code !== "KeyC" && t.code !== "KeyV") return;
154
+ const l = n.current.rootRef.current;
155
+ if (!(l != null && l.isConnected) || j(t.target) || A()) return;
156
+ const o = n.current.selection;
157
+ if (t.preventDefault(), t.code === "KeyC") {
158
+ if (o.length !== 1) {
159
+ v("Select one field to copy its look");
160
+ return;
161
+ }
162
+ g(o[0]);
163
+ return;
164
+ }
165
+ const r = C.current;
166
+ if (!r) {
167
+ v(`Copy a field’s look first (${_("C")})`);
168
+ return;
169
+ }
170
+ w(r, o);
171
+ };
172
+ return window.addEventListener("keydown", e), () => window.removeEventListener("keydown", e);
173
+ }, [g, w]);
174
+ const $ = b(
175
+ (e) => /* @__PURE__ */ u(
176
+ fe,
177
+ {
178
+ ctx: e,
179
+ tools: { copy: P, paste: m, copyLook: g, paintOnto: w, revertFor: y },
180
+ look: C.current,
181
+ bundle: n.current.bundle,
182
+ fieldLabel: a
183
+ }
184
+ ),
185
+ [P, m, g, w, y, a]
186
+ );
187
+ return W(() => ({ menuItems: $, revertFor: y, run: s }), [$, y, s]);
188
+ }
189
+ function fe({
190
+ ctx: i,
191
+ tools: n,
192
+ look: k,
193
+ bundle: f,
194
+ fieldLabel: C
195
+ }) {
196
+ const { targets: d, origin: p, close: a, run: S } = i, s = d.length === 1 ? d[0] : null, P = d.filter((e) => e.kind !== "group" && !e.field.startsWith("__")), m = s ? n.revertFor(s) : null, g = p && p.kind !== "group" ? P.filter((e) => e !== p && !pe(e, p)) : [], w = p && g.length && f ? q(f, p) : null, y = k ? P.filter(
197
+ (e) => !(e.kind !== "group" && e.field === k.field && O(e) === k.group_key)
198
+ ) : [], $ = d.some((e) => e.kind !== "group") || (s == null ? void 0 : s.kind) === "group";
199
+ return /* @__PURE__ */ K(J, { children: [
200
+ /* @__PURE__ */ u("hr", { className: "my-1 h-px border-0 bg-slate-100 dark:bg-border" }),
201
+ $ && /* @__PURE__ */ u(
202
+ E,
203
+ {
204
+ icon: /* @__PURE__ */ u(Q, {}),
205
+ hint: F("C"),
206
+ "data-place-action": "copy",
207
+ onPick: () => {
208
+ var t;
209
+ const e = n.copy(d);
210
+ if (e)
211
+ try {
212
+ (t = navigator.clipboard) == null || t.writeText(R(e)).catch(() => {
213
+ });
214
+ } catch {
215
+ }
216
+ a();
217
+ },
218
+ children: (s == null ? void 0 : s.kind) === "group" ? "Copy this section" : d.length > 1 ? `Copy ${d.length} fields` : "Copy"
219
+ }
220
+ ),
221
+ /* @__PURE__ */ u(
222
+ E,
223
+ {
224
+ icon: /* @__PURE__ */ u(X, {}),
225
+ hint: F("V"),
226
+ "data-place-action": "paste",
227
+ onPick: () => {
228
+ var t, l;
229
+ a();
230
+ const e = (l = (t = navigator.clipboard) == null ? void 0 : t.readText) == null ? void 0 : l.bind(navigator.clipboard);
231
+ if (!e) {
232
+ n.paste(null);
233
+ return;
234
+ }
235
+ e().then((o) => n.paste(T(o) || D(o) ? o : null)).catch(() => n.paste(null));
236
+ },
237
+ children: "Paste after this"
238
+ }
239
+ ),
240
+ s && s.kind !== "group" && !s.field.startsWith("__") && /* @__PURE__ */ u(
241
+ E,
242
+ {
243
+ icon: /* @__PURE__ */ u(N, {}),
244
+ hint: _("C"),
245
+ "data-place-action": "copy-look",
246
+ onPick: () => {
247
+ n.copyLook(s), a();
248
+ },
249
+ children: "Copy look and rules"
250
+ }
251
+ ),
252
+ w && p && p.kind !== "group" && /* @__PURE__ */ K(
253
+ E,
254
+ {
255
+ icon: /* @__PURE__ */ u(N, {}),
256
+ "data-place-action": "paint-from-origin",
257
+ onPick: () => {
258
+ n.paintOnto(w, g) && a();
259
+ },
260
+ children: [
261
+ "Give the other ",
262
+ g.length === 1 ? "field" : `${g.length} fields`,
263
+ " the look of",
264
+ " ",
265
+ C(p.field)
266
+ ]
267
+ }
268
+ ),
269
+ k && y.length > 0 && /* @__PURE__ */ K(
270
+ E,
271
+ {
272
+ icon: /* @__PURE__ */ u(N, {}),
273
+ hint: _("V"),
274
+ "data-place-action": "paint",
275
+ onPick: () => {
276
+ n.paintOnto(k, y) && a();
277
+ },
278
+ children: [
279
+ "Paint the look of ",
280
+ k.name,
281
+ " onto",
282
+ " ",
283
+ y.length === 1 ? "this" : `these ${y.length}`
284
+ ]
285
+ }
286
+ ),
287
+ s && m && /* @__PURE__ */ u(
288
+ E,
289
+ {
290
+ icon: /* @__PURE__ */ u(U, {}),
291
+ blocked: m.ok ? null : m.reason,
292
+ "data-place-action": "revert",
293
+ onPick: () => {
294
+ m.ok && S(m, { toastNotes: !0 });
295
+ },
296
+ children: m.ok ? m.label : "Put back as saved"
297
+ }
298
+ )
299
+ ] });
300
+ }
301
+ const O = (i) => i.kind === "group" ? null : i.kind === "header" ? "__header__" : i.group_key;
302
+ function pe(i, n) {
303
+ return i.kind === "group" || n.kind === "group" ? i.kind === n.kind && i.kind === "group" && n.kind === "group" && i.key === n.key : i.kind === n.kind && i.field === n.field && O(i) === O(n);
304
+ }
305
+ function Te({
306
+ target: i,
307
+ bundle: n,
308
+ className: k
309
+ }) {
310
+ const f = de(), C = re(i), d = W(() => (f == null ? void 0 : f.revertFor(i)) ?? null, [f, n, C]);
311
+ return d != null && d.ok ? /* @__PURE__ */ K(
312
+ "button",
313
+ {
314
+ type: "button",
315
+ "data-revert-element": "",
316
+ "data-tip": d.notes[0] ?? "Only this changes; the rest of the form stays as it is. Undo with ⌘Z.",
317
+ onClick: () => f == null ? void 0 : f.run(d),
318
+ className: oe(
319
+ "inline-flex h-7 max-w-full items-center gap-1.5 rounded-md border border-slate-200 px-2 text-[12px] font-medium text-slate-700 transition-colors hover:bg-slate-50 dark:border-border dark:text-foreground dark:hover:bg-muted",
320
+ k
321
+ ),
322
+ children: [
323
+ /* @__PURE__ */ u(U, { className: "h-3.5 w-3.5 shrink-0 text-slate-500 dark:text-muted-foreground" }),
324
+ /* @__PURE__ */ u("span", { className: "truncate", children: d.label })
325
+ ]
326
+ }
327
+ ) : null;
328
+ }
329
+ export {
330
+ $e as PlaceToolsProvider,
331
+ Te as RevertInline,
332
+ Ke as usePlaceTools,
333
+ de as usePlaceToolsContext
334
+ };
@@ -0,0 +1,252 @@
1
+ import { jsxs as N, Fragment as q, jsx as u } from "react/jsx-runtime";
2
+ import { LayoutPanelTop as z } from "lucide-react";
3
+ import { useState as W, useRef as F, useEffect as X, useMemo as U, useCallback as J } from "react";
4
+ import { createPortal as Q } from "react-dom";
5
+ import { HEADER_GROUP_KEY as T, isCanvasSlot as V, UNGROUPED_KEY as Z } from "../../lib/layout-ops.js";
6
+ import { listLayoutSlots as ee } from "../../lib/layout-slots.js";
7
+ import { titleCase as te } from "../../lib/utils.js";
8
+ import { Command as ne, CommandInput as oe, CommandList as ie, CommandEmpty as re, CommandGroup as $, CommandItem as se } from "../ui/command.js";
9
+ import { Popover as le, PopoverAnchor as ae, PopoverContent as de } from "../ui/popover.js";
10
+ import { typeWord as ce, BUILT_IN_SLOTS as ue, SLOT_HINTS as j } from "./AddPanel.js";
11
+ import { sectionOp as G, slotSpot as pe, placeOp as fe, gapSpot as me } from "./add-target.js";
12
+ import { sectionLabel as he } from "./canvas-diff.js";
13
+ import { isTyping as ge } from "./is-typing.js";
14
+ import { parseTargetKey as ke } from "./StructureMenu.js";
15
+ import { registerShortcut as we } from "./shortcuts.js";
16
+ import { slotName as H } from "./slot-names.js";
17
+ we({
18
+ id: "slash-insert",
19
+ area: "Editing",
20
+ keys: [["/"]],
21
+ label: "Add a field, panel or section in the gap under the pointer (or after the focused field)"
22
+ });
23
+ const L = "[data-design-target]";
24
+ function P(e) {
25
+ return ke(e.getAttribute("data-design-target"));
26
+ }
27
+ function B(e, d) {
28
+ var a;
29
+ const c = ((a = e.parentElement) == null ? void 0 : a.closest(L)) ?? e.parentElement, p = (c == null ? void 0 : c.getBoundingClientRect().width) ?? d.width;
30
+ return p <= 0 || d.width >= p * 0.6;
31
+ }
32
+ function O(e, d, c) {
33
+ return c ? {
34
+ left: e.left,
35
+ top: d ? e.top - 2 : e.bottom,
36
+ width: e.width,
37
+ height: 2
38
+ } : { left: d ? e.left - 2 : e.right, top: e.top, width: 2, height: e.height };
39
+ }
40
+ function _e(e, d, c, p) {
41
+ var C;
42
+ const a = ((C = document.elementFromPoint) == null ? void 0 : C.call(document, c, p)) ?? null;
43
+ if (!a || !d.contains(a) || !a.closest("[data-design-canvas]")) return null;
44
+ const h = a.closest(L);
45
+ if (!h) return null;
46
+ const i = P(h);
47
+ if (!i) return null;
48
+ if (i.kind !== "group") {
49
+ const r = h.getBoundingClientRect(), s = B(h, r), x = s ? p < r.top + r.height / 2 : c < r.left + r.width / 2;
50
+ return A(e, i, x, O(r, x, s));
51
+ }
52
+ const R = i.key, w = Array.from(h.querySelectorAll(L)).filter((r) => {
53
+ var x;
54
+ const s = P(r);
55
+ return s && s.kind !== "group" && s.kind !== "header" && (s.group_key ?? Z) === R && ((x = r.parentElement) == null ? void 0 : x.closest(L)) === h;
56
+ });
57
+ let _ = null;
58
+ for (const r of w) {
59
+ const s = r.getBoundingClientRect();
60
+ (s.bottom <= p || s.top <= p && s.right <= c) && (_ = r);
61
+ }
62
+ if (_) {
63
+ const r = _.getBoundingClientRect(), s = B(_, r);
64
+ return A(e, P(_), !1, O(r, !1, s));
65
+ }
66
+ if (w.length > 0) {
67
+ const r = w[0].getBoundingClientRect(), s = B(w[0], r);
68
+ return A(e, P(w[0]), !0, O(r, !0, s));
69
+ }
70
+ const v = h.getBoundingClientRect();
71
+ return A(e, i, !1, {
72
+ left: v.left + 12,
73
+ top: v.bottom - 14,
74
+ width: Math.max(0, v.width - 24),
75
+ height: 2
76
+ });
77
+ }
78
+ function A(e, d, c, p) {
79
+ const a = me(e, d, c);
80
+ if (!a) return null;
81
+ const h = a.top ? "between the form’s sections" : a.group_key === T ? "in the header strip" : `in ${he(e.groups, a.group_key)}`;
82
+ return { gap: a, near: d, line: p, where: h };
83
+ }
84
+ const ye = () => !!document.querySelector('[data-radix-popper-content-wrapper], [role="menu"]');
85
+ function Ke({
86
+ bundle: e,
87
+ fields: d,
88
+ apply: c,
89
+ onSelect: p,
90
+ rootRef: a,
91
+ enabled: h
92
+ }) {
93
+ const [i, R] = W(null), w = F(null), _ = F({ bundle: e, enabled: h });
94
+ _.current = { bundle: e, enabled: h }, X(() => {
95
+ const t = (l) => {
96
+ w.current = { x: l.clientX, y: l.clientY };
97
+ }, f = (l) => {
98
+ var n, y;
99
+ if (l.key !== "/" || l.metaKey || l.ctrlKey || l.altKey || l.defaultPrevented) return;
100
+ const k = a.current, { bundle: g, enabled: o } = _.current;
101
+ if (!o || !g || !(k != null && k.isConnected) || ge(l.target) || ye()) return;
102
+ let m = null;
103
+ const S = w.current;
104
+ if (S && (m = _e(g, k, S.x, S.y)), !m) {
105
+ const E = ((y = (n = document.activeElement) == null ? void 0 : n.closest) == null ? void 0 : y.call(n, L)) ?? null, I = E && k.contains(E) && E.closest("[data-design-canvas]") ? P(E) : null;
106
+ if (E && I) {
107
+ const Y = E.getBoundingClientRect();
108
+ m = A(g, I, !1, O(Y, !1, !0));
109
+ }
110
+ }
111
+ m && (l.preventDefault(), R(m));
112
+ };
113
+ return document.addEventListener("pointermove", t, { passive: !0 }), window.addEventListener("keydown", f), () => {
114
+ document.removeEventListener("pointermove", t), window.removeEventListener("keydown", f);
115
+ };
116
+ }, [a]);
117
+ const v = U(() => {
118
+ if (!i || !e) return [];
119
+ const t = [], f = i.gap, l = !f.top && f.group_key === T;
120
+ if (!f.top) {
121
+ const o = new Set(
122
+ e.placements.filter((n) => n.group_key === f.group_key).map((n) => n.field)
123
+ ), m = new Set(e.placements.map((n) => n.field)), S = d.filter((n) => n.field && !n.field.startsWith("__") && !o.has(n.field)).map((n) => ({ f: n, title: n.label || te(n.field) })).sort(
124
+ (n, y) => Number(m.has(n.f.field)) - Number(m.has(y.f.field)) || n.title.localeCompare(y.title)
125
+ );
126
+ for (const { f: n, title: y } of S)
127
+ t.push({
128
+ id: n.field,
129
+ kind: "field",
130
+ title: y,
131
+ sub: [n.field, ce(n), m.has(n.field) ? "also elsewhere on the form" : null].filter(Boolean).join(" · "),
132
+ value: `${y} ${n.field}`
133
+ });
134
+ }
135
+ const k = [...ue, ...ee().map((o) => `__ext_${o}__`)].filter(
136
+ (o) => o !== "__subtitle__" && (l ? o === "__owners__" : !0)
137
+ ), g = new Set(e.placements.map((o) => o.field));
138
+ for (const o of k)
139
+ g.has(o) || t.push({
140
+ id: o,
141
+ kind: "slot",
142
+ title: H(o),
143
+ sub: j[o] ?? "Extension panel",
144
+ value: `${H(o)} panel ${j[o] ?? ""}`
145
+ });
146
+ if (!l) {
147
+ const o = G(e, i.near.kind === "header" ? null : i.near);
148
+ if (o.op === "group_create") {
149
+ const m = o.label.replace(/^New /, "");
150
+ t.push({
151
+ id: "__section__",
152
+ kind: "section",
153
+ title: `New ${m}`,
154
+ sub: `A new ${m} after this one`,
155
+ value: `new ${m} section tab step layout`
156
+ });
157
+ }
158
+ }
159
+ return t;
160
+ }, [i, e, d]), C = J(
161
+ (t) => {
162
+ const f = i;
163
+ if (R(null), !f || !e) return;
164
+ const l = f.gap;
165
+ if (t.kind === "section") {
166
+ const o = G(e, f.near.kind === "header" ? null : f.near);
167
+ c([o], {
168
+ label: `Add ${o.op === "group_create" ? o.label.toLowerCase() : "section"}`
169
+ }), o.op === "group_create" && p({ kind: "group", key: o.key });
170
+ return;
171
+ }
172
+ const k = V({ field: t.id, group_key: null }), g = t.kind === "slot" && k ? l.top ? { group_key: null, index: l.index } : pe(e, f.near) : l.top ? null : { group_key: l.group_key, index: l.index };
173
+ g && (c([fe(t.id, g)], { label: `Add ${t.title}` }), p(
174
+ g.group_key === T ? { kind: "header", field: t.id } : { kind: t.kind === "slot" ? "slot" : "field", field: t.id, group_key: g.group_key }
175
+ ));
176
+ },
177
+ [i, e, c, p]
178
+ ), r = U(() => {
179
+ const t = i == null ? void 0 : i.line;
180
+ return {
181
+ current: {
182
+ getBoundingClientRect: () => t ? new DOMRect(t.left + t.width / 2, t.top + t.height, 0, 0) : new DOMRect()
183
+ }
184
+ };
185
+ }, [i]);
186
+ if (!i || !e) return null;
187
+ const s = a.current, x = (s == null ? void 0 : s.closest('[role="dialog"]')) ?? document.body, D = v.filter((t) => t.kind === "field"), K = v.filter((t) => t.kind === "slot"), M = v.find((t) => t.kind === "section");
188
+ return /* @__PURE__ */ N(q, { children: [
189
+ Q(
190
+ /* @__PURE__ */ u(
191
+ "div",
192
+ {
193
+ "aria-hidden": "true",
194
+ "data-slash-gap": "",
195
+ className: "pointer-events-none fixed z-[100] rounded-full bg-nvr-cyan",
196
+ style: {
197
+ left: i.line.left,
198
+ top: i.line.top,
199
+ width: Math.max(i.line.width, 2),
200
+ height: Math.max(i.line.height, 2)
201
+ }
202
+ }
203
+ ),
204
+ x
205
+ ),
206
+ /* @__PURE__ */ N(le, { open: !0, onOpenChange: (t) => !t && R(null), children: [
207
+ /* @__PURE__ */ u(ae, { virtualRef: r }),
208
+ /* @__PURE__ */ u(
209
+ de,
210
+ {
211
+ align: "start",
212
+ sideOffset: 6,
213
+ className: "w-[300px] p-0",
214
+ "data-slash-insert": "",
215
+ onCloseAutoFocus: (t) => t.preventDefault(),
216
+ children: /* @__PURE__ */ N(ne, { children: [
217
+ /* @__PURE__ */ u(oe, { placeholder: `Add ${i.where}…`, "aria-label": `Add ${i.where}` }),
218
+ /* @__PURE__ */ N(ie, { className: "max-h-[min(50vh,320px)] overscroll-contain", children: [
219
+ /* @__PURE__ */ u(re, { children: "Nothing matches." }),
220
+ M && /* @__PURE__ */ u($, { heading: "Layout", children: /* @__PURE__ */ u(b, { c: M, onPick: C }) }),
221
+ D.length > 0 && /* @__PURE__ */ u($, { heading: "Fields", children: D.map((t) => /* @__PURE__ */ u(b, { c: t, onPick: C }, t.id)) }),
222
+ K.length > 0 && /* @__PURE__ */ u($, { heading: "Panels", children: K.map((t) => /* @__PURE__ */ u(b, { c: t, onPick: C }, t.id)) })
223
+ ] })
224
+ ] })
225
+ }
226
+ )
227
+ ] })
228
+ ] });
229
+ }
230
+ function b({ c: e, onPick: d }) {
231
+ return /* @__PURE__ */ N(
232
+ se,
233
+ {
234
+ value: e.value,
235
+ onSelect: () => d(e),
236
+ "data-slash-choice": e.id,
237
+ className: "flex items-center gap-2",
238
+ children: [
239
+ /* @__PURE__ */ N("span", { className: "flex min-w-0 flex-1 flex-col", children: [
240
+ /* @__PURE__ */ u("span", { className: "truncate text-[12.5px] font-medium text-slate-900 dark:text-foreground", children: e.title }),
241
+ /* @__PURE__ */ u("span", { className: "truncate text-[11.5px] text-slate-500 dark:text-muted-foreground", children: e.sub })
242
+ ] }),
243
+ e.kind === "section" && /* @__PURE__ */ u(z, { className: "h-3.5 w-3.5 shrink-0 text-slate-400 dark:text-muted-foreground" })
244
+ ]
245
+ }
246
+ );
247
+ }
248
+ export {
249
+ Ke as SlashInsert,
250
+ _e as gapAtPoint,
251
+ A as gapBeside
252
+ };