@nivaro/react 0.2.50 → 0.2.52

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 (121) hide show
  1. package/dist/full.css +1 -1
  2. package/dist/hooks/useSessionRecorder.js +1 -1
  3. package/dist/index.d.ts +204 -6
  4. package/dist/index.js +442 -439
  5. package/dist/layout-editor.d.ts +80 -0
  6. package/dist/layout-editor.js +11 -0
  7. package/dist/shared/components/ItemEditForm.js +4117 -3882
  8. package/dist/shared/components/RecordDrilldownSheet.js +114 -97
  9. package/dist/shared/components/RecordReadView.js +662 -596
  10. package/dist/shared/components/ai/ExplainButton.js +1 -1
  11. package/dist/shared/components/chat/ChatPanel.js +1053 -993
  12. package/dist/shared/components/import/DocumentAutofillButton.js +141 -129
  13. package/dist/shared/components/item-edit/GroupSection.js +489 -466
  14. package/dist/shared/components/item-edit/HeaderBand.js +47 -44
  15. package/dist/shared/components/item-edit/M2MStagingContext.js +3 -3
  16. package/dist/shared/components/item-edit/O2MStagingContext.js +1 -1
  17. package/dist/shared/components/item-edit/RecordGrantTools.js +206 -0
  18. package/dist/shared/components/item-edit/StepsBar.js +49 -43
  19. package/dist/shared/components/item-edit/SummaryPanel.js +2 -1
  20. package/dist/shared/components/item-edit/config-update.js +6 -0
  21. package/dist/shared/components/item-edit/layout-editing-quiet.js +25 -0
  22. package/dist/shared/components/layout-editor/AddPanel.js +301 -0
  23. package/dist/shared/components/layout-editor/DesignNode.js +173 -0
  24. package/dist/shared/components/layout-editor/EditorCanvas.js +52 -0
  25. package/dist/shared/components/layout-editor/EditorTopBar.js +241 -0
  26. package/dist/shared/components/layout-editor/HistoryPanel.js +179 -0
  27. package/dist/shared/components/layout-editor/LayoutEditor.js +393 -0
  28. package/dist/shared/components/layout-editor/LayoutsRail.js +89 -0
  29. package/dist/shared/components/layout-editor/add-target.js +103 -0
  30. package/dist/shared/components/layout-editor/bundle-to-active.js +86 -0
  31. package/dist/shared/components/layout-editor/canvases/PdfCanvas.js +90 -0
  32. package/dist/shared/components/layout-editor/canvases/TableColumnsCanvas.js +246 -0
  33. package/dist/shared/components/layout-editor/collection-meta.js +22 -0
  34. package/dist/shared/components/layout-editor/design-canvas.js +81 -0
  35. package/dist/shared/components/layout-editor/design-context.js +21 -0
  36. package/dist/shared/components/layout-editor/dnd/LayoutDndProvider.js +225 -0
  37. package/dist/shared/components/layout-editor/dnd/collision.js +107 -0
  38. package/dist/shared/components/layout-editor/dnd/node.js +164 -0
  39. package/dist/shared/components/layout-editor/dnd/order.js +122 -0
  40. package/dist/shared/components/layout-editor/editors/DefaultValuesEditor.js +223 -0
  41. package/dist/shared/components/layout-editor/editors/QuickPickerStepsEditor.js +129 -0
  42. package/dist/shared/components/layout-editor/editors/ReadPresentationEditor.js +134 -0
  43. package/dist/shared/components/layout-editor/editors/RecordConditionsEditor.js +249 -0
  44. package/dist/shared/components/layout-editor/editors/RolesPicker.js +77 -0
  45. package/dist/shared/components/layout-editor/editors/cascade-filters.js +556 -0
  46. package/dist/shared/components/layout-editor/editors/cascade-rule-row.js +150 -0
  47. package/dist/shared/components/layout-editor/editors/controls.js +73 -0
  48. package/dist/shared/components/layout-editor/editors/editor-api.js +21 -0
  49. package/dist/shared/components/layout-editor/editors/editor-queries.js +25 -0
  50. package/dist/shared/components/layout-editor/editors/field-default-value.js +131 -0
  51. package/dist/shared/components/layout-editor/editors/grid-presets.js +310 -0
  52. package/dist/shared/components/layout-editor/editors/inline-display.js +157 -0
  53. package/dist/shared/components/layout-editor/editors/layout-picker.js +80 -0
  54. package/dist/shared/components/layout-editor/editors/layout-rows.js +55 -0
  55. package/dist/shared/components/layout-editor/editors/lock-conditions.js +109 -0
  56. package/dist/shared/components/layout-editor/editors/o2m-agg-field.js +25 -0
  57. package/dist/shared/components/layout-editor/editors/pdf-field-config.js +107 -0
  58. package/dist/shared/components/layout-editor/editors/report-widget-config.js +94 -0
  59. package/dist/shared/components/layout-editor/editors/row-rule-check.js +225 -0
  60. package/dist/shared/components/layout-editor/editors/row-rule-row.js +1353 -0
  61. package/dist/shared/components/layout-editor/editors/swap-config.js +245 -0
  62. package/dist/shared/components/layout-editor/focus-buffer.js +32 -0
  63. package/dist/shared/components/layout-editor/host.js +15 -0
  64. package/dist/shared/components/layout-editor/inspector/AdvancedTab.js +296 -0
  65. package/dist/shared/components/layout-editor/inspector/GridTab.js +767 -0
  66. package/dist/shared/components/layout-editor/inspector/GroupInspector.js +456 -0
  67. package/dist/shared/components/layout-editor/inspector/HeaderItemInspector.js +268 -0
  68. package/dist/shared/components/layout-editor/inspector/Inspector.js +332 -0
  69. package/dist/shared/components/layout-editor/inspector/LookTab.js +310 -0
  70. package/dist/shared/components/layout-editor/inspector/PickerTab.js +333 -0
  71. package/dist/shared/components/layout-editor/inspector/RulesTab.js +323 -0
  72. package/dist/shared/components/layout-editor/inspector/SlotInspector.js +179 -0
  73. package/dist/shared/components/layout-editor/inspector/SubtitleInspector.js +154 -0
  74. package/dist/shared/components/layout-editor/inspector/WidgetInspector.js +262 -0
  75. package/dist/shared/components/layout-editor/inspector/applies.js +27 -0
  76. package/dist/shared/components/layout-editor/inspector/field-context.js +134 -0
  77. package/dist/shared/components/layout-editor/inspector/interfaces.js +126 -0
  78. package/dist/shared/components/layout-editor/inspector/kit.js +595 -0
  79. package/dist/shared/components/layout-editor/inspector/model.js +307 -0
  80. package/dist/shared/components/layout-editor/overview/OverviewActions.js +15 -0
  81. package/dist/shared/components/layout-editor/overview/describe-conditions.js +121 -0
  82. package/dist/shared/components/layout-editor/overview/overview-api.js +141 -0
  83. package/dist/shared/components/layout-editor/overview/purpose.js +62 -0
  84. package/dist/shared/components/layout-editor/overview/record-count.js +65 -0
  85. package/dist/shared/components/layout-editor/panel-frame.js +99 -0
  86. package/dist/shared/components/layout-editor/panel-style.js +19 -0
  87. package/dist/shared/components/layout-editor/pickers/field-picker.js +230 -0
  88. package/dist/shared/components/layout-editor/pickers/icon-picker.js +233 -0
  89. package/dist/shared/components/layout-editor/pickers/relation-label.js +34 -0
  90. package/dist/shared/components/layout-editor/pickers/relation-picker.js +136 -0
  91. package/dist/shared/components/layout-editor/record-queries.js +15 -0
  92. package/dist/shared/components/layout-editor/settings/AddendumSection.js +52 -0
  93. package/dist/shared/components/layout-editor/settings/ButtonsSection.js +45 -0
  94. package/dist/shared/components/layout-editor/settings/DefaultsSection.js +67 -0
  95. package/dist/shared/components/layout-editor/settings/FormSettings.js +146 -0
  96. package/dist/shared/components/layout-editor/settings/InheritanceSection.js +37 -0
  97. package/dist/shared/components/layout-editor/settings/LayoutSection.js +70 -0
  98. package/dist/shared/components/layout-editor/settings/PdfSection.js +176 -0
  99. package/dist/shared/components/layout-editor/settings/ReadSection.js +79 -0
  100. package/dist/shared/components/layout-editor/settings/TextSetting.js +55 -0
  101. package/dist/shared/components/layout-editor/settings/ToggleSetting.js +33 -0
  102. package/dist/shared/components/layout-editor/settings/ToolsSection.js +179 -0
  103. package/dist/shared/components/layout-editor/settings/WhoSection.js +213 -0
  104. package/dist/shared/components/layout-editor/settings/controls.js +214 -0
  105. package/dist/shared/components/layout-editor/settings/section-props.js +17 -0
  106. package/dist/shared/components/layout-editor/settings/settings-api.js +151 -0
  107. package/dist/shared/components/layout-editor/settings/settings-registry.js +445 -0
  108. package/dist/shared/components/layout-editor/slot-names.js +20 -0
  109. package/dist/shared/components/layout-editor/summary-pref.js +21 -0
  110. package/dist/shared/components/layout-editor/useLayoutDraft.js +474 -0
  111. package/dist/shared/components/pipeline/relations.js +28 -23
  112. package/dist/shared/components/ui/dialog.js +11 -11
  113. package/dist/shared/components/ui/popover.js +17 -17
  114. package/dist/shared/components/ui/scroll-area.js +38 -0
  115. package/dist/shared/hooks/useRelationOptions.js +60 -0
  116. package/dist/shared/lib/layout-grants.js +9 -0
  117. package/dist/shared/lib/layout-ops.js +348 -0
  118. package/dist/shared/lib/layout-slots.js +11 -7
  119. package/dist/shared/lib/presence-state.js +43 -13
  120. package/dist/shared/lib/request-gate.js +1 -1
  121. package/package.json +5 -1
@@ -0,0 +1,393 @@
1
+ import { jsxs as f, jsx as s, Fragment as V } from "react/jsx-runtime";
2
+ import { useQueryClient as de, useQuery as ie } from "@tanstack/react-query";
3
+ import { AlertTriangle as ue, Plus as ce } from "lucide-react";
4
+ import { useState as g, useEffect as v, useCallback as L, useRef as A, useMemo as P } from "react";
5
+ import { createPortal as me } from "react-dom";
6
+ import { useNivaroClient as fe } from "../../context.js";
7
+ import { get as pe } from "../../lib/commands.js";
8
+ import { UNGROUPED_KEY as ye, HEADER_GROUP_KEY as he } from "../../lib/layout-ops.js";
9
+ import { cn as J } from "../../lib/utils.js";
10
+ import { modalHostOf as be } from "../ui/popover.js";
11
+ import { Skeleton as j } from "../ui/skeleton.js";
12
+ import { AddPanel as ge } from "./AddPanel.js";
13
+ import { bundleToActiveLayout as xe, previewForRole as ve, roleMarker as ke } from "./bundle-to-active.js";
14
+ import { targetKey as we } from "./design-context.js";
15
+ import { LayoutDndProvider as Le, useLayoutDnd as Ne } from "./dnd/LayoutDndProvider.js";
16
+ import { EditorCanvas as Ee } from "./EditorCanvas.js";
17
+ import { EditorTopBar as Ie } from "./EditorTopBar.js";
18
+ import { useLayoutEditorHost as Se } from "./host.js";
19
+ import { LayoutsRail as Pe } from "./LayoutsRail.js";
20
+ import { useLayoutOverview as Re, useOverviewFields as Ke, useInvalidateLayouts as W, useRuleChoiceLabels as Ce, useApproxRecordCount as De } from "./overview/overview-api.js";
21
+ import { purposeSegments as _e, Sentence as Oe } from "./overview/purpose.js";
22
+ import { useRolePreview as Ae } from "./settings/settings-api.js";
23
+ import { useLayoutDraft as Fe, useLayoutBundle as Te, layoutDraftKeys as qe, touchesOverview as Ue } from "./useLayoutDraft.js";
24
+ import { FormSettings as $e } from "./settings/FormSettings.js";
25
+ import { Inspector as ze } from "./inspector/Inspector.js";
26
+ const X = (e) => {
27
+ const r = e;
28
+ return r != null && r.closest ? r.isContentEditable || !!r.closest(
29
+ 'input, textarea, select, [role="textbox"], [contenteditable]:not([contenteditable="false"])'
30
+ ) : !1;
31
+ };
32
+ function Be(e) {
33
+ v(() => {
34
+ const r = (t) => {
35
+ if (!(t.metaKey || t.ctrlKey) || t.altKey) return;
36
+ const n = t.key.toLowerCase(), l = n === "z" && t.shiftKey || n === "y" && !t.shiftKey;
37
+ n !== "z" && !l || X(t.target) || (t.preventDefault(), l ? e.redo() : e.undo());
38
+ };
39
+ return window.addEventListener("keydown", r), () => window.removeEventListener("keydown", r);
40
+ }, [e.undo, e.redo]);
41
+ }
42
+ function He(e) {
43
+ const r = e.status === "saving";
44
+ v(() => {
45
+ if (!r) return;
46
+ const t = (n) => {
47
+ e.flush(), n.preventDefault(), n.returnValue = "";
48
+ };
49
+ return window.addEventListener("beforeunload", t), () => window.removeEventListener("beforeunload", t);
50
+ }, [r, e.flush]), v(() => {
51
+ const t = () => e.flush();
52
+ return window.addEventListener("pagehide", t), () => window.removeEventListener("pagehide", t);
53
+ }, [e.flush]);
54
+ }
55
+ function Me(e) {
56
+ const r = de(), t = W(e);
57
+ return L(
58
+ (n, l) => {
59
+ const d = Number(n.layout.id);
60
+ Number.isFinite(d) && r.invalidateQueries({ queryKey: qe.versions(d) }), t({ lazy: !Ue(l) });
61
+ },
62
+ [r, t]
63
+ );
64
+ }
65
+ function Ge(e, r) {
66
+ const t = fe();
67
+ return ie({
68
+ queryKey: ["layout-editor", "preview-record", e, r],
69
+ queryFn: () => t.request(
70
+ pe(`/items/${encodeURIComponent(e)}/${encodeURIComponent(String(r))}`)
71
+ ).then((n) => n.data ?? null),
72
+ enabled: r != null,
73
+ staleTime: 3e4
74
+ });
75
+ }
76
+ function Qe(e, r, t = null) {
77
+ const n = (l) => {
78
+ if (e.kind === "group") return e.key === ye || l.groups.some((c) => c.key === e.key);
79
+ const d = e.kind === "header" ? he : e.group_key;
80
+ return l.placements.some((c) => c.field === e.field && c.group_key === d);
81
+ };
82
+ return n(r) || t != null && n(t);
83
+ }
84
+ function je(e, r, t) {
85
+ const n = A(null), l = A(r);
86
+ return l.current = r, v(() => {
87
+ var m;
88
+ if (!e) return;
89
+ const d = document.activeElement;
90
+ (m = n.current) == null || m.focus();
91
+ const c = (i) => {
92
+ i.key !== "Escape" || i.defaultPrevented || t.current || X(i.target) || document.querySelector('[data-radix-popper-content-wrapper], [role="menu"]') || (i.preventDefault(), l.current());
93
+ };
94
+ return document.addEventListener("keydown", c), () => {
95
+ document.removeEventListener("keydown", c), d != null && d.isConnected && d.focus();
96
+ };
97
+ }, [e, t]), n;
98
+ }
99
+ function Ye({
100
+ collection: e,
101
+ bundle: r,
102
+ parent: t,
103
+ preview: n,
104
+ record: l,
105
+ selected: d,
106
+ onSelect: c,
107
+ showHidden: m,
108
+ apply: i,
109
+ whenIdle: N
110
+ }) {
111
+ const E = Ne(), a = P(() => xe(r, t), [r, t]), o = P(
112
+ () => ve(a.active, n.roleId, m),
113
+ [a.active, n.roleId, m]
114
+ ), { data: y = null } = Ae(e, n.roleId), k = P(
115
+ () => n.roleId ? ke(y) : void 0,
116
+ [n.roleId, y]
117
+ ), I = P(
118
+ () => ({
119
+ selected: d,
120
+ onSelect: c,
121
+ showHidden: m,
122
+ inheritedFrom: (w) => a.inherited.get(we(w)) ?? null,
123
+ dnd: E,
124
+ roleMark: k
125
+ }),
126
+ [d, c, m, a.inherited, E, k]
127
+ );
128
+ return /* @__PURE__ */ s(
129
+ Ee,
130
+ {
131
+ collection: e,
132
+ bundle: r,
133
+ layout: o,
134
+ record: l,
135
+ design: I,
136
+ apply: i,
137
+ whenIdle: N
138
+ }
139
+ );
140
+ }
141
+ function Ve({
142
+ collection: e,
143
+ name: r,
144
+ row: t,
145
+ rows: n,
146
+ fields: l,
147
+ onDone: d
148
+ }) {
149
+ const c = Ce(e, l, n), { data: m } = De(e, t, n), i = t ? t.section === "forms" && (t.reason.kind === "default" || t.reason.kind === "fallback") ? [{ text: "used by every record no rule catches" }] : _e(t, l, c) : [];
150
+ return i.length > 0 && typeof m == "number" && i.push({ text: ` (≈ ${m.toLocaleString()} ${m === 1 ? "record" : "records"})` }), /* @__PURE__ */ f(
151
+ "div",
152
+ {
153
+ "data-editing-banner": "",
154
+ className: "flex shrink-0 items-center gap-3 border-b border-nvr-cyan/30 bg-nvr-cyan/10 px-4 py-1.5 text-[12.5px] text-slate-700 dark:text-slate-200",
155
+ children: [
156
+ /* @__PURE__ */ f("p", { className: "m-0 min-w-0 flex-1 truncate", children: [
157
+ "Editing ",
158
+ /* @__PURE__ */ s("b", { className: "font-semibold text-slate-900 dark:text-foreground", children: r }),
159
+ i.length > 0 && /* @__PURE__ */ f(V, { children: [
160
+ " — ",
161
+ /* @__PURE__ */ s(Oe, { segs: i, muted: !0 })
162
+ ] })
163
+ ] }),
164
+ /* @__PURE__ */ s(
165
+ "button",
166
+ {
167
+ type: "button",
168
+ onClick: d,
169
+ className: "inline-flex h-7 shrink-0 items-center rounded-md bg-nvr-cyan px-3 text-[12px] font-medium text-white transition-opacity hover:opacity-90",
170
+ children: "Done"
171
+ }
172
+ )
173
+ ]
174
+ }
175
+ );
176
+ }
177
+ const Y = (e) => J(
178
+ "inline-flex h-7 items-center gap-1 rounded-md px-2.5 text-[12px] font-medium transition-colors",
179
+ e ? "bg-accent text-slate-900 dark:text-foreground" : "text-slate-500 hover:bg-muted hover:text-slate-800 dark:text-muted-foreground dark:hover:text-foreground"
180
+ );
181
+ function kt({
182
+ collection: e,
183
+ layoutId: r,
184
+ onBack: t,
185
+ mode: n,
186
+ onLayoutChange: l,
187
+ previewRecordId: d = null,
188
+ portalContainer: c
189
+ }) {
190
+ var Q;
191
+ const m = Se(), [i, N] = g(r);
192
+ v(() => N(r), [r]);
193
+ const E = Me(e), a = Fe(i, { onSaved: E }), o = a.bundle, [y, k] = g("layouts"), [I, w] = g("inspector"), [x, R] = g(null), [F, Z] = g(!1), [S, T] = g({
194
+ record: d ? { id: d, label: `#${d}` } : null,
195
+ roleId: null
196
+ }), { data: p } = Re(e), { data: q = [] } = Ke(e), h = p == null ? void 0 : p.rows.find((u) => u.layout_id === i), ee = (o == null ? void 0 : o.layout.parent_layout_id) != null ? Number(o.layout.parent_layout_id) : null, { data: K = null } = Te(ee), { data: te = null } = Ge(e, ((Q = S.record) == null ? void 0 : Q.id) ?? null);
197
+ Be(a), He(a);
198
+ const U = W(e), C = L(() => {
199
+ const u = a.whenIdle();
200
+ u.then(() => U()), t(u);
201
+ }, [a.whenIdle, U, t]);
202
+ v(() => {
203
+ x && o && !Qe(x, o, K) && R(null);
204
+ }, [x, o, K]);
205
+ const b = n === "overlay", [D, re] = g(null), $ = A(!1), ne = L((u) => {
206
+ $.current = u;
207
+ }, []), oe = je(b && D != null, C, $), z = L((u) => {
208
+ R(u), w("inspector");
209
+ }, []), ae = L(
210
+ (u) => T((O) => O.roleId === u ? O : { ...O, roleId: u }),
211
+ []
212
+ ), B = (u) => {
213
+ w("inspector"), u !== i && (a.flush(), R(null), N(u), l == null || l(u));
214
+ }, _ = String((o == null ? void 0 : o.layout.name) ?? (h == null ? void 0 : h.name) ?? ""), se = String((o == null ? void 0 : o.layout.layout_type) ?? (h == null ? void 0 : h.layout_type) ?? "grouped"), H = m.warning ?? (p == null ? void 0 : p.warning) ?? null, le = b ? {
215
+ role: "dialog",
216
+ "aria-modal": !0,
217
+ "aria-label": `Edit layout ${_}`,
218
+ tabIndex: -1
219
+ } : {}, M = /* @__PURE__ */ f(
220
+ "div",
221
+ {
222
+ ref: b ? oe : void 0,
223
+ "data-layout-editor": "",
224
+ "data-mode": n,
225
+ ...le,
226
+ className: J(
227
+ "flex min-h-0 flex-col bg-slate-50 outline-none dark:bg-background",
228
+ b ? "fixed inset-0 z-[90]" : "flex-1"
229
+ ),
230
+ children: [
231
+ /* @__PURE__ */ s(
232
+ Ie,
233
+ {
234
+ collection: e,
235
+ layoutId: i,
236
+ layoutName: _,
237
+ layoutType: se,
238
+ row: h,
239
+ fields: q,
240
+ draft: a,
241
+ preview: S,
242
+ onPreview: T,
243
+ showHidden: F,
244
+ onShowHidden: Z,
245
+ onBack: C,
246
+ backLabel: b ? "Back to record" : "Layouts"
247
+ }
248
+ ),
249
+ b && /* @__PURE__ */ s(
250
+ Ve,
251
+ {
252
+ collection: e,
253
+ name: _,
254
+ row: h,
255
+ rows: (p == null ? void 0 : p.rows) ?? [],
256
+ fields: q,
257
+ onDone: C
258
+ }
259
+ ),
260
+ H && /* @__PURE__ */ f(
261
+ "div",
262
+ {
263
+ role: "note",
264
+ className: "flex shrink-0 items-center gap-2 border-b border-amber-200 bg-amber-50 px-4 py-1.5 text-[12.5px] text-amber-800 dark:border-amber-500/30 dark:bg-amber-500/10 dark:text-amber-200",
265
+ children: [
266
+ /* @__PURE__ */ s(ue, { className: "h-3.5 w-3.5 shrink-0" }),
267
+ H
268
+ ]
269
+ }
270
+ ),
271
+ /* @__PURE__ */ s(Le, { bundle: o, apply: a.apply, onDragActive: ne, children: /* @__PURE__ */ f("div", { className: "flex min-h-0 flex-1 overflow-hidden", children: [
272
+ /* @__PURE__ */ f("aside", { className: "flex w-[260px] shrink-0 flex-col border-r border-slate-200 bg-white dark:border-border dark:bg-card", children: [
273
+ /* @__PURE__ */ f(
274
+ "div",
275
+ {
276
+ role: "tablist",
277
+ "aria-label": "Left panel",
278
+ className: "flex shrink-0 items-center gap-1 border-b border-slate-200 px-2 py-1.5 dark:border-border",
279
+ children: [
280
+ /* @__PURE__ */ s(
281
+ "button",
282
+ {
283
+ type: "button",
284
+ role: "tab",
285
+ "aria-selected": y === "layouts",
286
+ "data-editor-tab": "layouts",
287
+ className: Y(y === "layouts"),
288
+ onClick: () => k("layouts"),
289
+ children: "Layouts"
290
+ }
291
+ ),
292
+ /* @__PURE__ */ f(
293
+ "button",
294
+ {
295
+ type: "button",
296
+ role: "tab",
297
+ "aria-selected": y === "add",
298
+ "data-editor-tab": "add",
299
+ className: Y(y === "add"),
300
+ onClick: () => k("add"),
301
+ disabled: !o,
302
+ "data-tip": "Add a field, section, panel or widget after the selection",
303
+ children: [
304
+ /* @__PURE__ */ s(ce, { className: "h-3.5 w-3.5" }),
305
+ "Add"
306
+ ]
307
+ }
308
+ )
309
+ ]
310
+ }
311
+ ),
312
+ /* @__PURE__ */ s("div", { className: "min-h-0 flex-1 overflow-y-auto", children: y === "add" && o ? /* @__PURE__ */ s(
313
+ ge,
314
+ {
315
+ bundle: o,
316
+ collection: e,
317
+ selected: x,
318
+ apply: a.apply,
319
+ onSelect: z
320
+ }
321
+ ) : /* @__PURE__ */ s(
322
+ Pe,
323
+ {
324
+ collection: e,
325
+ currentId: i,
326
+ onOpen: B,
327
+ settingsOpen: I === "settings",
328
+ onSettings: () => w("settings")
329
+ }
330
+ ) })
331
+ ] }),
332
+ /* @__PURE__ */ s("main", { className: "min-w-0 flex-1 overflow-y-auto", children: o ? /* @__PURE__ */ s(
333
+ Ye,
334
+ {
335
+ collection: e,
336
+ bundle: o,
337
+ parent: K,
338
+ preview: S,
339
+ record: te,
340
+ selected: x,
341
+ onSelect: z,
342
+ showHidden: F,
343
+ apply: a.apply,
344
+ whenIdle: a.whenIdle
345
+ }
346
+ ) : a.error ? /* @__PURE__ */ s("p", { className: "p-6 text-[13px] text-red-700 dark:text-red-300", children: a.error }) : /* @__PURE__ */ f("div", { className: "flex flex-col gap-3 p-6", children: [
347
+ /* @__PURE__ */ s(j, { className: "h-10 w-full rounded-lg" }),
348
+ /* @__PURE__ */ s(j, { className: "h-48 w-full rounded-lg" })
349
+ ] }) }),
350
+ /* @__PURE__ */ s(
351
+ "aside",
352
+ {
353
+ "data-editor-inspector": "",
354
+ className: "flex w-[344px] shrink-0 flex-col overflow-hidden border-l border-slate-200 bg-white dark:border-border dark:bg-card",
355
+ children: o && (I === "settings" ? /* @__PURE__ */ s(
356
+ $e,
357
+ {
358
+ bundle: o,
359
+ apply: a.apply,
360
+ flush: a.flush,
361
+ collection: e,
362
+ previewRoleId: S.roleId,
363
+ onPreviewRoleChange: ae
364
+ }
365
+ ) : /* @__PURE__ */ s(
366
+ ze,
367
+ {
368
+ bundle: o,
369
+ target: x,
370
+ apply: a.apply,
371
+ flush: a.flush,
372
+ collection: e,
373
+ openLayout: B
374
+ }
375
+ ))
376
+ }
377
+ )
378
+ ] }) })
379
+ ]
380
+ }
381
+ );
382
+ if (!b) return M;
383
+ const G = c ?? (D ? be(D) ?? document.body : null);
384
+ return /* @__PURE__ */ f(V, { children: [
385
+ /* @__PURE__ */ s("span", { ref: re, hidden: !0, "data-layout-editor-marker": "" }),
386
+ G && me(M, G)
387
+ ] });
388
+ }
389
+ export {
390
+ kt as LayoutEditor,
391
+ X as isTyping,
392
+ Qe as targetExists
393
+ };
@@ -0,0 +1,89 @@
1
+ import { jsxs as l, jsx as t } from "react/jsx-runtime";
2
+ import { SlidersHorizontal as y } from "lucide-react";
3
+ import { useMemo as N } from "react";
4
+ import { cn as d } from "../../lib/utils.js";
5
+ import { Skeleton as k } from "../ui/skeleton.js";
6
+ import { useLayoutOverview as v, useOverviewFields as _, useRuleChoiceLabels as L } from "./overview/overview-api.js";
7
+ import { rowPill as S, Pill as C, Sentence as F, purposeSegments as R } from "./overview/purpose.js";
8
+ const j = [
9
+ { id: "forms", title: "Forms" },
10
+ { id: "link_only", title: "Link only" },
11
+ { id: "other_views", title: "Other views" },
12
+ { id: "unused", title: "Unused" }
13
+ ], x = "px-2 pb-1 pt-3 text-[11.5px] font-semibold text-slate-500 dark:text-muted-foreground";
14
+ function O({
15
+ collection: n,
16
+ currentId: i,
17
+ onOpen: p,
18
+ settingsOpen: s,
19
+ onSettings: f
20
+ }) {
21
+ const { data: o, isLoading: h } = v(n), { data: m = [] } = _(n), u = N(() => (o == null ? void 0 : o.rows) ?? [], [o]), g = L(n, m, u);
22
+ return /* @__PURE__ */ l("nav", { "data-editor-rail": "", "aria-label": "Layouts", className: "flex flex-col gap-0.5 px-2 pb-4", children: [
23
+ h && [0, 1, 2].map((a) => /* @__PURE__ */ t(k, { className: "mx-2 mt-3 h-9 rounded-md" }, a)),
24
+ j.map((a) => {
25
+ const c = u.filter((e) => e.section === a.id);
26
+ return c.length ? /* @__PURE__ */ l("div", { className: "flex flex-col gap-0.5", children: [
27
+ /* @__PURE__ */ t("p", { className: x, children: a.title }),
28
+ c.map((e) => {
29
+ const b = e.layout_id === i && !s, r = S(e);
30
+ return /* @__PURE__ */ l(
31
+ "button",
32
+ {
33
+ type: "button",
34
+ "data-rail-layout": e.layout_id,
35
+ "aria-current": e.layout_id === i ? "page" : void 0,
36
+ onClick: () => p(e.layout_id),
37
+ className: d(
38
+ "flex flex-col gap-px rounded-md px-2 py-1.5 text-left transition-colors",
39
+ b ? "bg-accent" : "hover:bg-muted",
40
+ e.layout_id === i && s && "bg-muted"
41
+ ),
42
+ children: [
43
+ /* @__PURE__ */ l(
44
+ "span",
45
+ {
46
+ className: d(
47
+ "flex min-w-0 items-center gap-1.5 text-[12.5px] font-semibold text-slate-900 dark:text-foreground",
48
+ a.id === "unused" && "font-medium text-slate-500 dark:text-muted-foreground"
49
+ ),
50
+ children: [
51
+ /* @__PURE__ */ t("span", { className: "truncate", children: e.name }),
52
+ r && /* @__PURE__ */ t(C, { tone: r.tone, children: r.text })
53
+ ]
54
+ }
55
+ ),
56
+ /* @__PURE__ */ t("span", { className: "line-clamp-2 text-[12px] leading-snug text-slate-500 dark:text-muted-foreground [&_b]:font-medium [&_b]:text-slate-600 dark:[&_b]:text-muted-foreground", children: /* @__PURE__ */ t(F, { segs: R(e, m, g) }) })
57
+ ]
58
+ },
59
+ e.layout_id
60
+ );
61
+ })
62
+ ] }, a.id) : null;
63
+ }),
64
+ /* @__PURE__ */ t("p", { className: x, children: "Form settings" }),
65
+ /* @__PURE__ */ l(
66
+ "button",
67
+ {
68
+ type: "button",
69
+ "data-rail-settings": "",
70
+ "aria-pressed": s,
71
+ onClick: f,
72
+ className: d(
73
+ "flex items-start gap-2 rounded-md px-2 py-1.5 text-left transition-colors",
74
+ s ? "bg-accent" : "hover:bg-muted"
75
+ ),
76
+ children: [
77
+ /* @__PURE__ */ t(y, { className: "mt-0.5 h-3.5 w-3.5 shrink-0 text-slate-500 dark:text-muted-foreground" }),
78
+ /* @__PURE__ */ l("span", { className: "flex flex-col gap-px", children: [
79
+ /* @__PURE__ */ t("span", { className: "text-[12.5px] font-medium text-slate-900 dark:text-foreground", children: "Steps, buttons, panels…" }),
80
+ /* @__PURE__ */ t("span", { className: "text-[12px] text-slate-500 dark:text-muted-foreground", children: "Who gets this form and how it behaves" })
81
+ ] })
82
+ ]
83
+ }
84
+ )
85
+ ] });
86
+ }
87
+ export {
88
+ O as LayoutsRail
89
+ };
@@ -0,0 +1,103 @@
1
+ import { applyLayoutOps as E, HEADER_GROUP_KEY as y, isCanvasSlot as s, UNGROUPED_KEY as d } from "../../lib/layout-ops.js";
2
+ const a = (r) => E(r, [{ op: "layout_update", patch: {} }]), x = /* @__PURE__ */ new Set(["section", "tab", "metadata"]), k = (r, n) => r.placements.filter((o) => o.group_key === n && !s(o)).length, m = (r) => r.groups.filter((n) => n.parent_key === null);
3
+ function O(r) {
4
+ const n = [...m(r)].sort((o, e) => o.sort - e.sort);
5
+ for (const o of n) {
6
+ if (x.has(o.type)) return o;
7
+ if (o.type === "container") {
8
+ const e = r.groups.filter((u) => u.parent_key === o.key).sort((u, i) => u.sort - i.sort)[0];
9
+ if (e) return e;
10
+ }
11
+ }
12
+ return null;
13
+ }
14
+ function _(r) {
15
+ return r ? r.kind === "header" ? { field: r.field, group_key: y } : r.kind === "field" || r.kind === "slot" ? { field: r.field, group_key: r.group_key } : null : null;
16
+ }
17
+ function L(r, n, o = "form") {
18
+ const e = a(r), u = _(n);
19
+ if (o === "header") {
20
+ if ((u == null ? void 0 : u.group_key) === y) {
21
+ const t = e.placements.find((p) => p.field === u.field && p.group_key === y);
22
+ if (t) return { group_key: y, index: t.sort + 1 };
23
+ }
24
+ return { group_key: y, index: k(e, y) };
25
+ }
26
+ if (u && u.group_key !== y) {
27
+ const t = e.placements.find((p) => p.field === u.field && p.group_key === u.group_key);
28
+ if (t && !s(t)) return { group_key: t.group_key, index: t.sort + 1 };
29
+ }
30
+ if ((n == null ? void 0 : n.kind) === "group") {
31
+ if (n.key === d) return { group_key: null, index: k(e, null) };
32
+ const t = e.groups.find((p) => p.key === n.key);
33
+ if (t && x.has(t.type)) return { group_key: t.key, index: k(e, t.key) };
34
+ if ((t == null ? void 0 : t.type) === "container") {
35
+ const p = e.groups.filter((f) => f.parent_key === t.key).sort((f, l) => f.sort - l.sort)[0];
36
+ if (p) return { group_key: p.key, index: k(e, p.key) };
37
+ }
38
+ }
39
+ const i = O(e);
40
+ return i ? { group_key: i.key, index: k(e, i.key) } : { group_key: null, index: k(e, null) };
41
+ }
42
+ function h(r, n) {
43
+ const o = m(r).length + r.placements.filter(s).length;
44
+ if (!n) return o;
45
+ const e = _(n);
46
+ if (e) {
47
+ const u = r.placements.find((t) => t.field === e.field && t.group_key === e.group_key);
48
+ if (u && s(u)) return u.sort + 1;
49
+ const i = e.group_key === null ? d : e.group_key;
50
+ return g(r, i, o);
51
+ }
52
+ return n.kind === "group" ? g(r, n.key, o) : o;
53
+ }
54
+ function g(r, n, o) {
55
+ let e = r.groups.find((u) => u.key === n);
56
+ return e != null && e.parent_key && (e = r.groups.find((u) => u.key === (e == null ? void 0 : e.parent_key))), e ? e.sort + 1 : o;
57
+ }
58
+ function b(r, n) {
59
+ return { group_key: null, index: h(a(r), n) };
60
+ }
61
+ function c(r, n) {
62
+ const o = new Set(r.groups.map((e) => e.key));
63
+ if (!o.has(n)) return n;
64
+ for (let e = 2; ; e++) if (!o.has(`${n}_${e}`)) return `${n}_${e}`;
65
+ }
66
+ function v(r, n) {
67
+ const o = a(r), e = _(n), u = (n == null ? void 0 : n.kind) === "group" ? n.key : (e == null ? void 0 : e.group_key) ?? null, i = u ? o.groups.find((p) => p.key === u) : void 0, t = (i == null ? void 0 : i.type) === "container" ? i : i != null && i.parent_key ? o.groups.find((p) => p.key === i.parent_key) : null;
68
+ if (t) {
69
+ const p = (t.tab_mode ?? o.layout.tab_mode) === "steps", f = o.groups.filter((w) => w.parent_key === t.key), l = i && i.parent_key === t.key ? i.sort + 1 : f.length;
70
+ return {
71
+ op: "group_create",
72
+ key: c(o, p ? "step" : "tab"),
73
+ label: p ? "New step" : "New tab",
74
+ group_type: "tab",
75
+ parent_key: t.key,
76
+ index: l
77
+ };
78
+ }
79
+ return {
80
+ op: "group_create",
81
+ key: c(o, "section"),
82
+ label: "New section",
83
+ group_type: "section",
84
+ parent_key: null,
85
+ index: h(o, n)
86
+ };
87
+ }
88
+ function D(r, n, o) {
89
+ return {
90
+ op: "place",
91
+ field: r,
92
+ group_key: n.group_key,
93
+ index: n.index,
94
+ ...o ? { patch: o } : {}
95
+ };
96
+ }
97
+ export {
98
+ L as fieldSpot,
99
+ c as newGroupKey,
100
+ D as placeOp,
101
+ v as sectionOp,
102
+ b as slotSpot
103
+ };
@@ -0,0 +1,86 @@
1
+ import { UNGROUPED_KEY as d } from "../../lib/layout-ops.js";
2
+ import { targetKey as y } from "./design-context.js";
3
+ function m(e) {
4
+ const n = /* @__PURE__ */ new Map();
5
+ let r = -1;
6
+ for (const o of e) n.set(o.key, o.id ?? r--);
7
+ return n;
8
+ }
9
+ function g(e, n) {
10
+ return {
11
+ ...e,
12
+ id: n.get(e.key),
13
+ container_id: e.parent_key == null ? null : n.get(e.parent_key) ?? null
14
+ };
15
+ }
16
+ const S = (e) => e == null ? null : typeof e == "string" ? e : JSON.stringify(e);
17
+ function x(e) {
18
+ return {
19
+ ...e,
20
+ overrides: e.overrides ?? null,
21
+ input_bindings: S(e.input_bindings)
22
+ };
23
+ }
24
+ function N(e) {
25
+ return e.group_key === "__header__" ? { kind: "header", field: e.field } : {
26
+ kind: e.field.startsWith("__") ? "slot" : "field",
27
+ field: e.field,
28
+ group_key: e.group_key
29
+ };
30
+ }
31
+ function K(e, n) {
32
+ const r = /* @__PURE__ */ new Map(), o = e.groups.find((l) => l.key === d), s = e.groups.filter((l) => l.key !== d), i = m(s), f = s.map((l) => g(l, i));
33
+ let u = e.placements;
34
+ if (n) {
35
+ const l = String(n.layout.name ?? "the parent layout"), h = new Set(u.map((t) => t.field)), k = new Set(s.map((t) => t.key)), c = n.groups.filter((t) => t.key !== d), b = m(c), _ = c.filter((t) => !k.has(t.key)), p = n.placements.filter((t) => !h.has(t.field));
36
+ for (const t of p) r.set(y(N(t)), l);
37
+ for (const t of _) r.set(y({ kind: "group", key: t.key }), l);
38
+ f.push(..._.map((t) => g(t, b))), u = [...u, ...p];
39
+ }
40
+ const a = e.layout;
41
+ return {
42
+ active: {
43
+ layout: {
44
+ ...a,
45
+ id: Number(a.id),
46
+ name: String(a.name ?? ""),
47
+ tab_mode: a.tab_mode ?? null,
48
+ validate_before_next: !!a.validate_before_next,
49
+ summary_enabled: !!a.summary_enabled,
50
+ summary_show_all: !1,
51
+ ai_enabled: !!a.ai_enabled
52
+ },
53
+ groups: f,
54
+ assignments: u.map(x),
55
+ ungrouped_sort: o ? o.sort : null
56
+ },
57
+ inherited: r
58
+ };
59
+ }
60
+ function A(e) {
61
+ if (e == null || e === "") return [];
62
+ try {
63
+ const n = typeof e == "string" ? JSON.parse(e) : e;
64
+ return Array.isArray(n) ? n.map((r) => String(r).toUpperCase()) : [];
65
+ } catch {
66
+ return [];
67
+ }
68
+ }
69
+ function M(e, n, r) {
70
+ if (!n || r) return e;
71
+ const o = n.toUpperCase(), s = e.groups.filter(
72
+ (i) => !A(i.hidden_for_roles).includes(o)
73
+ );
74
+ return s.length === e.groups.length ? e : { ...e, groups: s };
75
+ }
76
+ function O(e) {
77
+ if (!e || e.role.admin_access) return;
78
+ const n = new Set(e.hidden_fields), r = new Set(e.readonly_fields), o = e.can_read && !e.can_update, s = e.role.name;
79
+ if (!(!n.size && !r.size && !o))
80
+ return (i) => i.kind !== "field" && i.kind !== "header" || i.field.startsWith("__") ? null : n.has(i.field) ? { kind: "hidden", role: s } : o || r.has(i.field) ? { kind: "readonly", role: s } : null;
81
+ }
82
+ export {
83
+ K as bundleToActiveLayout,
84
+ M as previewForRole,
85
+ O as roleMarker
86
+ };