@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,245 @@
1
+ import { jsxs as a, jsx as l } from "react/jsx-runtime";
2
+ import { ChevronDown as O, Search as v, Plus as F } from "lucide-react";
3
+ import { useState as c } from "react";
4
+ import { titleCase as A } from "../../../lib/utils.js";
5
+ function W({
6
+ group: s,
7
+ allFields: p,
8
+ onGroupSettings: y
9
+ }) {
10
+ const [_, x] = c(!1), [w, h] = c(!1), [m, f] = c(""), [u, b] = c(""), t = (() => {
11
+ try {
12
+ if (!s.swap_config) return null;
13
+ const e = JSON.parse(s.swap_config), d = (e.alternate_fields ?? []).map(
14
+ (n) => typeof n == "string" ? { field: n, width: 2 } : n
15
+ );
16
+ return { ...e, alternate_fields: d };
17
+ } catch {
18
+ return null;
19
+ }
20
+ })(), r = (e) => {
21
+ const d = {
22
+ enabled: (t == null ? void 0 : t.enabled) ?? !1,
23
+ primary_field: (t == null ? void 0 : t.primary_field) ?? "",
24
+ alternate_fields: (t == null ? void 0 : t.alternate_fields) ?? [],
25
+ toggle_label: t == null ? void 0 : t.toggle_label,
26
+ back_label: t == null ? void 0 : t.back_label,
27
+ ...e
28
+ };
29
+ y(s.id, { swap_config: JSON.stringify(d) });
30
+ }, o = (e) => A(e), S = new Set(((t == null ? void 0 : t.alternate_fields) ?? []).map((e) => e.field)), g = p.filter(
31
+ (e) => !e.field.startsWith("__") && e.field.toLowerCase().includes(m.toLowerCase())
32
+ ), k = p.filter(
33
+ (e) => !e.field.startsWith("__") && e.field.toLowerCase().includes(u.toLowerCase()) && !S.has(e.field)
34
+ ), i = (t == null ? void 0 : t.alternate_fields) ?? [], N = (e, d) => {
35
+ r({ alternate_fields: i.map((n) => n.field === e ? { ...n, width: d } : n) });
36
+ }, j = (e) => {
37
+ r({ alternate_fields: i.filter((d) => d.field !== e) });
38
+ };
39
+ return /* @__PURE__ */ a("div", { className: "border-t border-slate-100 dark:border-border pt-3 space-y-2", children: [
40
+ /* @__PURE__ */ l("p", { className: "text-[11px] font-medium text-slate-600 dark:text-slate-300", children: "Field Swap" }),
41
+ /* @__PURE__ */ l("p", { className: "text-[11px] text-slate-400", children: "Toggle between a M2O picker and manual entry fields." }),
42
+ /* @__PURE__ */ a(
43
+ "label",
44
+ {
45
+ className: "flex items-center gap-2 text-[11px] text-slate-600 dark:text-muted-foreground",
46
+ "data-setting": "group.swap_config.enabled",
47
+ children: [
48
+ /* @__PURE__ */ l(
49
+ "input",
50
+ {
51
+ type: "checkbox",
52
+ checked: !!(t != null && t.enabled),
53
+ onChange: (e) => r({ enabled: e.target.checked }),
54
+ className: "h-3.5 w-3.5 rounded accent-nvr-cyan"
55
+ }
56
+ ),
57
+ "Enable field swap"
58
+ ]
59
+ }
60
+ ),
61
+ (t == null ? void 0 : t.enabled) && /* @__PURE__ */ a("div", { className: "space-y-2 pl-1", children: [
62
+ /* @__PURE__ */ a("div", { "data-setting": "group.swap_config.primary_field", children: [
63
+ /* @__PURE__ */ l("p", { className: "text-[11px] text-slate-400 mb-1", children: "Primary field (M2O)" }),
64
+ /* @__PURE__ */ a(
65
+ "button",
66
+ {
67
+ type: "button",
68
+ onClick: () => {
69
+ x((e) => !e), f("");
70
+ },
71
+ className: "w-full h-7 rounded border border-slate-200 dark:border-border bg-white dark:bg-background px-2 text-left text-[11px] flex items-center justify-between gap-1 hover:border-nvr-cyan/50",
72
+ children: [
73
+ t.primary_field ? /* @__PURE__ */ a("span", { className: "flex-1 truncate", children: [
74
+ /* @__PURE__ */ l("span", { className: "font-medium", children: o(t.primary_field) }),
75
+ " ",
76
+ /* @__PURE__ */ l("span", { className: "font-mono text-[11px] text-slate-400", children: t.primary_field })
77
+ ] }) : /* @__PURE__ */ l("span", { className: "text-slate-400", children: "Select field…" }),
78
+ /* @__PURE__ */ l(O, { className: "h-3 w-3 shrink-0 text-slate-400" })
79
+ ]
80
+ }
81
+ ),
82
+ _ && /* @__PURE__ */ a("div", { className: "mt-0.5 rounded border border-slate-200 dark:border-border bg-white dark:bg-card shadow-sm overflow-hidden", children: [
83
+ /* @__PURE__ */ a("div", { className: "flex items-center border-b border-slate-100 dark:border-border px-2", children: [
84
+ /* @__PURE__ */ l(v, { className: "h-3 w-3 text-slate-400 shrink-0" }),
85
+ /* @__PURE__ */ l(
86
+ "input",
87
+ {
88
+ autoFocus: !0,
89
+ value: m,
90
+ onChange: (e) => f(e.target.value),
91
+ placeholder: "Search…",
92
+ className: "flex-1 h-7 bg-transparent px-2 text-[11px] outline-none"
93
+ }
94
+ )
95
+ ] }),
96
+ /* @__PURE__ */ l("div", { className: "max-h-36 overflow-y-auto", children: g.length === 0 ? /* @__PURE__ */ l("p", { className: "px-3 py-2 text-[11px] text-slate-400", children: "No fields" }) : g.map((e) => /* @__PURE__ */ a(
97
+ "button",
98
+ {
99
+ type: "button",
100
+ onClick: () => {
101
+ r({ primary_field: e.field }), x(!1);
102
+ },
103
+ className: [
104
+ "w-full text-left px-3 py-1.5 text-[11px] hover:bg-muted dark:hover:bg-muted flex items-center justify-between gap-2",
105
+ t.primary_field === e.field ? "bg-nvr-cyan/5 text-nvr-cyan" : ""
106
+ ].join(" "),
107
+ children: [
108
+ /* @__PURE__ */ l("span", { className: "font-medium truncate", children: o(e.field) }),
109
+ /* @__PURE__ */ l("span", { className: "font-mono text-[11px] text-slate-400 shrink-0", children: e.type ?? "" })
110
+ ]
111
+ },
112
+ e.field
113
+ )) })
114
+ ] })
115
+ ] }),
116
+ /* @__PURE__ */ a("div", { "data-setting": "group.swap_config.alternate_fields", children: [
117
+ /* @__PURE__ */ l("p", { className: "text-[11px] text-slate-400 mb-1", children: "Alternate fields" }),
118
+ i.length > 0 && /* @__PURE__ */ l("div", { className: "mb-1 space-y-1", children: i.map((e) => /* @__PURE__ */ a(
119
+ "div",
120
+ {
121
+ className: "flex items-center gap-1.5 rounded border border-slate-100 dark:border-border bg-white dark:bg-card px-2 py-1",
122
+ children: [
123
+ /* @__PURE__ */ l("span", { className: "flex-1 truncate text-[11px] font-medium text-slate-700 dark:text-slate-200", children: o(e.field) }),
124
+ /* @__PURE__ */ a("div", { className: "flex rounded border border-slate-200 dark:border-border overflow-hidden shrink-0", children: [
125
+ /* @__PURE__ */ l(
126
+ "button",
127
+ {
128
+ type: "button",
129
+ onClick: () => N(e.field, 1),
130
+ className: [
131
+ "px-1.5 py-0.5 text-[11px] font-medium transition-colors",
132
+ e.width === 1 ? "bg-nvr-cyan text-white" : "text-slate-400 hover:text-slate-600"
133
+ ].join(" "),
134
+ title: "Half width",
135
+ children: "½"
136
+ }
137
+ ),
138
+ /* @__PURE__ */ l(
139
+ "button",
140
+ {
141
+ type: "button",
142
+ onClick: () => N(e.field, 2),
143
+ className: [
144
+ "px-1.5 py-0.5 text-[11px] font-medium transition-colors border-l border-slate-200 dark:border-border",
145
+ e.width === 2 ? "bg-nvr-cyan text-white" : "text-slate-400 hover:text-slate-600"
146
+ ].join(" "),
147
+ title: "Full width",
148
+ children: "1"
149
+ }
150
+ )
151
+ ] }),
152
+ /* @__PURE__ */ l(
153
+ "button",
154
+ {
155
+ type: "button",
156
+ onClick: () => j(e.field),
157
+ className: "text-slate-300 hover:text-red-500 text-[14px] leading-none shrink-0",
158
+ children: "×"
159
+ }
160
+ )
161
+ ]
162
+ },
163
+ e.field
164
+ )) }),
165
+ /* @__PURE__ */ a(
166
+ "button",
167
+ {
168
+ type: "button",
169
+ onClick: () => {
170
+ h((e) => !e), b("");
171
+ },
172
+ className: "w-full h-7 rounded border border-dashed border-slate-200 dark:border-border bg-white dark:bg-background px-2 text-left text-[11px] flex items-center gap-1.5 text-slate-400 hover:border-nvr-cyan/50 hover:text-nvr-cyan",
173
+ children: [
174
+ /* @__PURE__ */ l(F, { className: "h-3 w-3" }),
175
+ " Add field…"
176
+ ]
177
+ }
178
+ ),
179
+ w && /* @__PURE__ */ a("div", { className: "mt-0.5 rounded border border-slate-200 dark:border-border bg-white dark:bg-card shadow-sm overflow-hidden", children: [
180
+ /* @__PURE__ */ a("div", { className: "flex items-center border-b border-slate-100 dark:border-border px-2", children: [
181
+ /* @__PURE__ */ l(v, { className: "h-3 w-3 text-slate-400 shrink-0" }),
182
+ /* @__PURE__ */ l(
183
+ "input",
184
+ {
185
+ autoFocus: !0,
186
+ value: u,
187
+ onChange: (e) => b(e.target.value),
188
+ placeholder: "Search…",
189
+ className: "flex-1 h-7 bg-transparent px-2 text-[11px] outline-none"
190
+ }
191
+ )
192
+ ] }),
193
+ /* @__PURE__ */ l("div", { className: "max-h-36 overflow-y-auto", children: k.length === 0 ? /* @__PURE__ */ l("p", { className: "px-3 py-2 text-[11px] text-slate-400", children: "No more fields" }) : k.map((e) => /* @__PURE__ */ a(
194
+ "button",
195
+ {
196
+ type: "button",
197
+ onClick: () => {
198
+ r({ alternate_fields: [...i, { field: e.field, width: 2 }] }), b(""), h(!1);
199
+ },
200
+ className: "w-full text-left px-3 py-1.5 text-[11px] hover:bg-muted dark:hover:bg-muted flex items-center justify-between gap-2",
201
+ children: [
202
+ /* @__PURE__ */ l("span", { className: "font-medium truncate", children: o(e.field) }),
203
+ /* @__PURE__ */ l("span", { className: "font-mono text-[11px] text-slate-400 shrink-0", children: e.type ?? "" })
204
+ ]
205
+ },
206
+ e.field
207
+ )) })
208
+ ] })
209
+ ] }),
210
+ /* @__PURE__ */ a("div", { className: "flex gap-2", children: [
211
+ /* @__PURE__ */ a("div", { className: "flex-1", "data-setting": "group.swap_config.toggle_label", children: [
212
+ /* @__PURE__ */ l("p", { className: "text-[11px] text-slate-400 mb-1", children: "Toggle label" }),
213
+ /* @__PURE__ */ l(
214
+ "input",
215
+ {
216
+ type: "text",
217
+ placeholder: "Enter custom",
218
+ defaultValue: t.toggle_label ?? "",
219
+ onBlur: (e) => r({ toggle_label: e.target.value || void 0 }),
220
+ className: "w-full h-6 rounded border border-slate-200 dark:border-border bg-white dark:bg-background px-2 text-[11px]"
221
+ },
222
+ `tl-${s.id}`
223
+ )
224
+ ] }),
225
+ /* @__PURE__ */ a("div", { className: "flex-1", "data-setting": "group.swap_config.back_label", children: [
226
+ /* @__PURE__ */ l("p", { className: "text-[11px] text-slate-400 mb-1", children: "Back label" }),
227
+ /* @__PURE__ */ l(
228
+ "input",
229
+ {
230
+ type: "text",
231
+ placeholder: "Use saved",
232
+ defaultValue: t.back_label ?? "",
233
+ onBlur: (e) => r({ back_label: e.target.value || void 0 }),
234
+ className: "w-full h-6 rounded border border-slate-200 dark:border-border bg-white dark:bg-background px-2 text-[11px]"
235
+ },
236
+ `bl-${s.id}`
237
+ )
238
+ ] })
239
+ ] })
240
+ ] })
241
+ ] });
242
+ }
243
+ export {
244
+ W as SwapConfigEditor
245
+ };
@@ -0,0 +1,32 @@
1
+ import { useState as i, useRef as t, useEffect as a } from "react";
2
+ function p(n, s) {
3
+ const [l, c] = i(null), o = t(!1), e = t(null), f = t(n);
4
+ f.current = n;
5
+ const u = t(s);
6
+ return u.current = s, a(
7
+ () => () => {
8
+ e.current && clearTimeout(e.current);
9
+ },
10
+ []
11
+ ), {
12
+ value: l ? l.v : n,
13
+ /** Record an edit. Without focus inside there is nothing to protect: the draft shows. */
14
+ set: (r) => {
15
+ o.current && c({ v: r });
16
+ },
17
+ props: {
18
+ onFocusCapture: () => {
19
+ e.current && clearTimeout(e.current), e.current = null, o.current = !0, c((r) => r ?? { v: f.current });
20
+ },
21
+ onBlurCapture: () => {
22
+ var r;
23
+ (r = u.current) == null || r.call(u), e.current && clearTimeout(e.current), e.current = setTimeout(() => {
24
+ e.current = null, o.current = !1, c(null);
25
+ }, 0);
26
+ }
27
+ }
28
+ };
29
+ }
30
+ export {
31
+ p as useFocusBuffer
32
+ };
@@ -0,0 +1,15 @@
1
+ import { createContext as n, useContext as e } from "react";
2
+ const r = {
3
+ isAdmin: !1,
4
+ navigate: () => {
5
+ },
6
+ warning: null,
7
+ recordLink: (t, o) => `/collections/${t}/${o}`
8
+ }, i = n(r);
9
+ function a() {
10
+ return e(i);
11
+ }
12
+ export {
13
+ i as LayoutEditorHostContext,
14
+ a as useLayoutEditorHost
15
+ };
@@ -0,0 +1,296 @@
1
+ import { jsxs as s, jsx as a } from "react/jsx-runtime";
2
+ import { useQuery as D } from "@tanstack/react-query";
3
+ import { useContext as G } from "react";
4
+ import { useNivaroClient as I } from "../../../context.js";
5
+ import { get as U } from "../../../lib/commands.js";
6
+ import { cn as V } from "../../../lib/utils.js";
7
+ import { tintCard as j } from "../panel-style.js";
8
+ import { showsRawOption as E } from "./applies.js";
9
+ import { useFieldCtx as q } from "./field-context.js";
10
+ import { useGlobalValue as $, GlobalWriterContext as K, Setting as n, Section as u, Toggle as A, DraftInput as Q, JsonInput as f } from "./kit.js";
11
+ import { asArray as S, withKey as O } from "./model.js";
12
+ const M = [
13
+ {
14
+ key: "row_bulk_actions",
15
+ label: "Row bulk actions",
16
+ effect: "Actions offered on selected rows."
17
+ },
18
+ { key: "picker_facets", label: "Picker facets", effect: "Filter chips inside the picker." },
19
+ {
20
+ key: "option_filter",
21
+ label: "Option filter",
22
+ effect: "A filter the picker applies to its options."
23
+ },
24
+ { key: "row_filter", label: "Row filter", effect: "Which child rows this grid shows." },
25
+ { key: "row_defaults", label: "Row defaults", effect: "Values a new row starts with." },
26
+ {
27
+ key: "allocate_drawer",
28
+ label: "Allocation drawer",
29
+ effect: "The allocation panel of each row."
30
+ },
31
+ { key: "auto_allocate", label: "Auto-allocate", effect: "Fills allocations automatically." },
32
+ { key: "upload_template", label: "Upload template", effect: "Rows from an uploaded file." },
33
+ {
34
+ key: "quick_create",
35
+ label: "Quick create",
36
+ effect: "Creating a related record from the picker."
37
+ }
38
+ ];
39
+ function Y(l) {
40
+ const d = /^(.*?)\s*'(.*)'$/.exec(l.label);
41
+ return d ? `${d[2]} (${d[1].toLowerCase()})` : l.label;
42
+ }
43
+ function z(l) {
44
+ switch (l.source) {
45
+ case "layout":
46
+ return l.detail === "field assignment" ? "Shows this field" : "Shows a value reached through this field";
47
+ case "display-template":
48
+ return "Names records in lists and pickers";
49
+ case "picker-filter":
50
+ return "Narrows a picker";
51
+ case "field-rule":
52
+ return l.detail === "trigger field" ? "Starts a field rule" : "Filled in by a field rule";
53
+ case "at-risk-rule":
54
+ return "Part of an at-risk condition";
55
+ case "alert":
56
+ return "Watched by an alert";
57
+ case "field-watch":
58
+ return "Watched for changes";
59
+ case "rule":
60
+ return "Used by a rule";
61
+ case "workflow-transition":
62
+ return "Checked before a step can move on";
63
+ case "saved-view":
64
+ return "May be a column or filter of a saved view";
65
+ default:
66
+ return l.detail ? l.detail.charAt(0).toUpperCase() + l.detail.slice(1) : "";
67
+ }
68
+ }
69
+ function ne() {
70
+ var x;
71
+ const l = q(), d = I(), { info: r, ov: b, opts: p, env: y, globalDependency: L } = l, o = r.label, c = r.global, w = $("field.deprecated", !!(c != null && c.deprecated_at)), F = $("field.deprecation_note", (c == null ? void 0 : c.deprecation_note) ?? ""), m = r.field.startsWith("__"), { data: g, isLoading: J } = D({
72
+ queryKey: ["layout-editor", "field-impact", y.collection, r.field],
73
+ queryFn: () => d.request(
74
+ U(`/data-model/${y.collection}/fields/${encodeURIComponent(r.field)}/impact`)
75
+ ).then((e) => e.data ?? []),
76
+ enabled: !m,
77
+ staleTime: 6e4
78
+ }), R = (x = G(K)) == null ? void 0 : x.draft.dependency_config, k = S(
79
+ (R ?? L).cascade_filters
80
+ ), h = (e, t, i, C, W) => l.proposeGlobal(
81
+ e,
82
+ C,
83
+ W,
84
+ (_) => {
85
+ const T = S(_.dependency_config.cascade_filters).map((N, P) => P === t ? O(N, i, C) ?? {} : N);
86
+ return {
87
+ ..._,
88
+ dependency_config: O(_.dependency_config, "cascade_filters", T) ?? {}
89
+ };
90
+ },
91
+ `${e}#${t}`
92
+ ), v = M.filter((e) => E(e.key, r, p[e.key]));
93
+ return /* @__PURE__ */ s("div", { className: "space-y-5", children: [
94
+ !m && /* @__PURE__ */ a(
95
+ n,
96
+ {
97
+ k: "field.impact",
98
+ label: "Where this field is used",
99
+ effect: "Check here before renaming or deleting the field.",
100
+ children: J ? /* @__PURE__ */ a("p", { className: "text-[12px] leading-snug text-slate-500 dark:text-muted-foreground", children: "Looking…" }) : (g ?? []).length === 0 ? /* @__PURE__ */ s("p", { className: "text-[12px] leading-snug text-slate-500 dark:text-muted-foreground", children: [
101
+ "Nothing else refers to ",
102
+ o,
103
+ "."
104
+ ] }) : /* @__PURE__ */ a("ul", { className: "space-y-1.5 text-[12px]", children: (g ?? []).slice(0, 30).map((e, t) => (
105
+ // biome-ignore lint/suspicious/noArrayIndexKey: impact rows can repeat a label
106
+ /* @__PURE__ */ s("li", { "data-impact": e.source, className: "min-w-0", children: [
107
+ /* @__PURE__ */ a("p", { className: "truncate text-slate-800 dark:text-foreground", children: Y(e) }),
108
+ /* @__PURE__ */ a("p", { className: "truncate text-slate-500 dark:text-muted-foreground", children: z(e) })
109
+ ] }, t)
110
+ )) })
111
+ }
112
+ ),
113
+ !m && /* @__PURE__ */ s(u, { title: "For API callers", children: [
114
+ /* @__PURE__ */ a(
115
+ A,
116
+ {
117
+ k: "field.deprecated",
118
+ label: "Deprecated",
119
+ scope: "field",
120
+ effect: "GraphQL marks the field deprecated; it is removed only after the policy window.",
121
+ checked: w,
122
+ onChange: (e) => l.proposeGlobal(
123
+ "field.deprecated",
124
+ e,
125
+ e ? `Deprecate ${o}` : `Stop deprecating ${o}`,
126
+ (t) => ({
127
+ ...t,
128
+ columns: e ? { ...t.columns, deprecated: !0 } : { ...t.columns, deprecated: !1, deprecation_note: null }
129
+ })
130
+ )
131
+ }
132
+ ),
133
+ /* @__PURE__ */ a(
134
+ n,
135
+ {
136
+ k: "field.deprecation_note",
137
+ label: "What callers should use instead",
138
+ effect: "API callers see it as the deprecation reason.",
139
+ scope: "field",
140
+ children: /* @__PURE__ */ a(
141
+ Q,
142
+ {
143
+ ariaLabel: "What callers should use instead",
144
+ value: F ?? "",
145
+ placeholder: w ? "e.g. use vendor_id" : "Deprecate the field first",
146
+ onCommit: (e) => l.proposeGlobal(
147
+ "field.deprecation_note",
148
+ e,
149
+ `Change the deprecation note of ${o}`,
150
+ (t) => ({ ...t, columns: { ...t.columns, deprecation_note: e || null } })
151
+ )
152
+ }
153
+ )
154
+ }
155
+ )
156
+ ] }),
157
+ k.length > 0 && /* @__PURE__ */ a(u, { title: "Cascade filters (raw)", collapsible: !0, children: k.map((e, t) => /* @__PURE__ */ s(
158
+ "div",
159
+ {
160
+ className: V(j, "space-y-4 p-3"),
161
+ children: [
162
+ /* @__PURE__ */ s("p", { className: "text-[12px] leading-snug text-slate-500 dark:text-muted-foreground", children: [
163
+ "Filter ",
164
+ t + 1,
165
+ ": by ",
166
+ /* @__PURE__ */ a("span", { className: "font-mono", children: e.parent_field }),
167
+ " on",
168
+ " ",
169
+ /* @__PURE__ */ a("span", { className: "font-mono", children: e.filter_column })
170
+ ] }),
171
+ /* @__PURE__ */ a(
172
+ A,
173
+ {
174
+ k: "field.cascade_filters.filter_via_many",
175
+ confirmAt: `field.cascade_filters.filter_via_many#${t}`,
176
+ label: "Filter through the many side",
177
+ effect: "Matches options through a many-to-many link instead of a column on the option.",
178
+ scope: "field",
179
+ checked: e.filter_via_many === !0,
180
+ onChange: (i) => h(
181
+ "field.cascade_filters.filter_via_many",
182
+ t,
183
+ "filter_via_many",
184
+ i || void 0,
185
+ `Change filter ${t + 1} of ${o}`
186
+ )
187
+ }
188
+ ),
189
+ /* @__PURE__ */ a(
190
+ n,
191
+ {
192
+ k: "field.cascade_filters.value_map",
193
+ confirmAt: `field.cascade_filters.value_map#${t}`,
194
+ label: "Value map",
195
+ effect: 'Turns the parent value into the option value before filtering: {"parent": "option"}.',
196
+ scope: "field",
197
+ children: /* @__PURE__ */ a(
198
+ f,
199
+ {
200
+ ariaLabel: "Value map",
201
+ rows: 3,
202
+ value: e.value_map ?? null,
203
+ onCommit: (i) => h(
204
+ "field.cascade_filters.value_map",
205
+ t,
206
+ "value_map",
207
+ i,
208
+ `Change the value map of filter ${t + 1} of ${o}`
209
+ )
210
+ }
211
+ )
212
+ }
213
+ ),
214
+ /* @__PURE__ */ a(
215
+ n,
216
+ {
217
+ k: "field.cascade_filters.value_map_default",
218
+ confirmAt: `field.cascade_filters.value_map_default#${t}`,
219
+ label: "Value map default",
220
+ effect: "Used when the parent value is not in the value map.",
221
+ scope: "field",
222
+ children: /* @__PURE__ */ a(
223
+ f,
224
+ {
225
+ ariaLabel: "Value map default",
226
+ rows: 1,
227
+ value: e.value_map_default ?? null,
228
+ onCommit: (i) => h(
229
+ "field.cascade_filters.value_map_default",
230
+ t,
231
+ "value_map_default",
232
+ i,
233
+ `Change the value map default of filter ${t + 1} of ${o}`
234
+ )
235
+ }
236
+ )
237
+ }
238
+ )
239
+ ]
240
+ },
241
+ `${e.parent_field}:${e.filter_column}`
242
+ )) }),
243
+ /* @__PURE__ */ s(u, { title: "Edit as JSON", collapsible: !0, children: [
244
+ /* @__PURE__ */ a(
245
+ n,
246
+ {
247
+ k: "field.overrides_raw",
248
+ label: "This form’s settings as JSON",
249
+ effect: "Everything this form changes about the field. Saved when you leave the box, if it parses.",
250
+ children: /* @__PURE__ */ a(
251
+ f,
252
+ {
253
+ ariaLabel: "This form’s settings as JSON",
254
+ rows: 6,
255
+ value: Object.keys(b).length ? b : null,
256
+ validate: (e) => e && typeof e == "object" && !Array.isArray(e) ? null : "Needs a JSON object",
257
+ onCommit: (e) => l.setPlacement({ overrides: e ?? null }, `Edit the settings of ${o} as JSON`)
258
+ }
259
+ )
260
+ }
261
+ ),
262
+ r.iface === "inline-table" && /* @__PURE__ */ a(
263
+ n,
264
+ {
265
+ k: "field.row_rules.sources_when",
266
+ label: "Row rules as JSON",
267
+ effect: "For settings the rule editor does not show, such as a source gate (sources[].when).",
268
+ children: /* @__PURE__ */ a(
269
+ f,
270
+ {
271
+ ariaLabel: "Row rules as JSON",
272
+ rows: 6,
273
+ value: p.row_rules ?? null,
274
+ validate: (e) => Array.isArray(e) ? null : "Needs a list of rules",
275
+ onCommit: (e) => l.setOption("row_rules", e, `Edit the rules of ${o} as JSON`)
276
+ }
277
+ )
278
+ }
279
+ )
280
+ ] }),
281
+ v.length > 0 && /* @__PURE__ */ a(u, { title: "Stored settings without an editor", collapsible: !0, children: v.map((e) => /* @__PURE__ */ a(n, { k: `field.${e.key}`, label: e.label, effect: e.effect, children: /* @__PURE__ */ a(
282
+ f,
283
+ {
284
+ ariaLabel: e.label,
285
+ rows: 2,
286
+ value: p[e.key] ?? null,
287
+ onCommit: (t) => l.setOption(e.key, t, `Change the ${e.label.toLowerCase()} of ${o}`)
288
+ }
289
+ ) }, e.key)) })
290
+ ] });
291
+ }
292
+ export {
293
+ ne as AdvancedTab,
294
+ Y as impactPlace,
295
+ z as impactUse
296
+ };