@nivaro/react 0.2.51 → 0.2.53

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 (117) hide show
  1. package/dist/full.css +1 -1
  2. package/dist/hooks/useSessionRecorder.js +1 -1
  3. package/dist/index.d.ts +207 -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 +4015 -3835
  8. package/dist/shared/components/RecordDrilldownSheet.js +114 -97
  9. package/dist/shared/components/RecordReadView.js +637 -570
  10. package/dist/shared/components/ai/ExplainButton.js +1 -1
  11. package/dist/shared/components/item-edit/GroupSection.js +489 -466
  12. package/dist/shared/components/item-edit/HeaderBand.js +47 -44
  13. package/dist/shared/components/item-edit/M2MStagingContext.js +3 -3
  14. package/dist/shared/components/item-edit/O2MStagingContext.js +1 -1
  15. package/dist/shared/components/item-edit/RecordGrantTools.js +206 -0
  16. package/dist/shared/components/item-edit/StepsBar.js +49 -43
  17. package/dist/shared/components/item-edit/SummaryPanel.js +1 -1
  18. package/dist/shared/components/item-edit/config-update.js +6 -0
  19. package/dist/shared/components/item-edit/layout-editing-quiet.js +25 -0
  20. package/dist/shared/components/layout-editor/AddPanel.js +301 -0
  21. package/dist/shared/components/layout-editor/DesignNode.js +173 -0
  22. package/dist/shared/components/layout-editor/EditorCanvas.js +52 -0
  23. package/dist/shared/components/layout-editor/EditorTopBar.js +241 -0
  24. package/dist/shared/components/layout-editor/HistoryPanel.js +179 -0
  25. package/dist/shared/components/layout-editor/LayoutEditor.js +393 -0
  26. package/dist/shared/components/layout-editor/LayoutsRail.js +89 -0
  27. package/dist/shared/components/layout-editor/add-target.js +103 -0
  28. package/dist/shared/components/layout-editor/bundle-to-active.js +86 -0
  29. package/dist/shared/components/layout-editor/canvases/PdfCanvas.js +90 -0
  30. package/dist/shared/components/layout-editor/canvases/TableColumnsCanvas.js +246 -0
  31. package/dist/shared/components/layout-editor/collection-meta.js +22 -0
  32. package/dist/shared/components/layout-editor/design-canvas.js +81 -0
  33. package/dist/shared/components/layout-editor/design-context.js +21 -0
  34. package/dist/shared/components/layout-editor/dnd/LayoutDndProvider.js +225 -0
  35. package/dist/shared/components/layout-editor/dnd/collision.js +107 -0
  36. package/dist/shared/components/layout-editor/dnd/node.js +164 -0
  37. package/dist/shared/components/layout-editor/dnd/order.js +122 -0
  38. package/dist/shared/components/layout-editor/editors/DefaultValuesEditor.js +223 -0
  39. package/dist/shared/components/layout-editor/editors/QuickPickerStepsEditor.js +129 -0
  40. package/dist/shared/components/layout-editor/editors/ReadPresentationEditor.js +134 -0
  41. package/dist/shared/components/layout-editor/editors/RecordConditionsEditor.js +249 -0
  42. package/dist/shared/components/layout-editor/editors/RolesPicker.js +77 -0
  43. package/dist/shared/components/layout-editor/editors/cascade-filters.js +556 -0
  44. package/dist/shared/components/layout-editor/editors/cascade-rule-row.js +150 -0
  45. package/dist/shared/components/layout-editor/editors/controls.js +73 -0
  46. package/dist/shared/components/layout-editor/editors/editor-api.js +21 -0
  47. package/dist/shared/components/layout-editor/editors/editor-queries.js +25 -0
  48. package/dist/shared/components/layout-editor/editors/field-default-value.js +131 -0
  49. package/dist/shared/components/layout-editor/editors/grid-presets.js +310 -0
  50. package/dist/shared/components/layout-editor/editors/inline-display.js +157 -0
  51. package/dist/shared/components/layout-editor/editors/layout-picker.js +80 -0
  52. package/dist/shared/components/layout-editor/editors/layout-rows.js +55 -0
  53. package/dist/shared/components/layout-editor/editors/lock-conditions.js +109 -0
  54. package/dist/shared/components/layout-editor/editors/o2m-agg-field.js +25 -0
  55. package/dist/shared/components/layout-editor/editors/pdf-field-config.js +107 -0
  56. package/dist/shared/components/layout-editor/editors/report-widget-config.js +94 -0
  57. package/dist/shared/components/layout-editor/editors/row-rule-check.js +225 -0
  58. package/dist/shared/components/layout-editor/editors/row-rule-row.js +1353 -0
  59. package/dist/shared/components/layout-editor/editors/swap-config.js +245 -0
  60. package/dist/shared/components/layout-editor/focus-buffer.js +32 -0
  61. package/dist/shared/components/layout-editor/host.js +15 -0
  62. package/dist/shared/components/layout-editor/inspector/AdvancedTab.js +296 -0
  63. package/dist/shared/components/layout-editor/inspector/GridTab.js +767 -0
  64. package/dist/shared/components/layout-editor/inspector/GroupInspector.js +456 -0
  65. package/dist/shared/components/layout-editor/inspector/HeaderItemInspector.js +268 -0
  66. package/dist/shared/components/layout-editor/inspector/Inspector.js +332 -0
  67. package/dist/shared/components/layout-editor/inspector/LookTab.js +310 -0
  68. package/dist/shared/components/layout-editor/inspector/PickerTab.js +333 -0
  69. package/dist/shared/components/layout-editor/inspector/RulesTab.js +323 -0
  70. package/dist/shared/components/layout-editor/inspector/SlotInspector.js +179 -0
  71. package/dist/shared/components/layout-editor/inspector/SubtitleInspector.js +154 -0
  72. package/dist/shared/components/layout-editor/inspector/WidgetInspector.js +262 -0
  73. package/dist/shared/components/layout-editor/inspector/applies.js +27 -0
  74. package/dist/shared/components/layout-editor/inspector/field-context.js +134 -0
  75. package/dist/shared/components/layout-editor/inspector/interfaces.js +126 -0
  76. package/dist/shared/components/layout-editor/inspector/kit.js +595 -0
  77. package/dist/shared/components/layout-editor/inspector/model.js +307 -0
  78. package/dist/shared/components/layout-editor/overview/OverviewActions.js +15 -0
  79. package/dist/shared/components/layout-editor/overview/describe-conditions.js +121 -0
  80. package/dist/shared/components/layout-editor/overview/overview-api.js +141 -0
  81. package/dist/shared/components/layout-editor/overview/purpose.js +62 -0
  82. package/dist/shared/components/layout-editor/overview/record-count.js +65 -0
  83. package/dist/shared/components/layout-editor/panel-frame.js +99 -0
  84. package/dist/shared/components/layout-editor/panel-style.js +19 -0
  85. package/dist/shared/components/layout-editor/pickers/field-picker.js +230 -0
  86. package/dist/shared/components/layout-editor/pickers/icon-picker.js +233 -0
  87. package/dist/shared/components/layout-editor/pickers/relation-label.js +34 -0
  88. package/dist/shared/components/layout-editor/pickers/relation-picker.js +136 -0
  89. package/dist/shared/components/layout-editor/record-queries.js +15 -0
  90. package/dist/shared/components/layout-editor/settings/AddendumSection.js +52 -0
  91. package/dist/shared/components/layout-editor/settings/ButtonsSection.js +45 -0
  92. package/dist/shared/components/layout-editor/settings/DefaultsSection.js +67 -0
  93. package/dist/shared/components/layout-editor/settings/FormSettings.js +146 -0
  94. package/dist/shared/components/layout-editor/settings/InheritanceSection.js +37 -0
  95. package/dist/shared/components/layout-editor/settings/LayoutSection.js +70 -0
  96. package/dist/shared/components/layout-editor/settings/PdfSection.js +176 -0
  97. package/dist/shared/components/layout-editor/settings/ReadSection.js +79 -0
  98. package/dist/shared/components/layout-editor/settings/TextSetting.js +55 -0
  99. package/dist/shared/components/layout-editor/settings/ToggleSetting.js +33 -0
  100. package/dist/shared/components/layout-editor/settings/ToolsSection.js +179 -0
  101. package/dist/shared/components/layout-editor/settings/WhoSection.js +213 -0
  102. package/dist/shared/components/layout-editor/settings/controls.js +214 -0
  103. package/dist/shared/components/layout-editor/settings/section-props.js +17 -0
  104. package/dist/shared/components/layout-editor/settings/settings-api.js +151 -0
  105. package/dist/shared/components/layout-editor/settings/settings-registry.js +445 -0
  106. package/dist/shared/components/layout-editor/slot-names.js +20 -0
  107. package/dist/shared/components/layout-editor/summary-pref.js +21 -0
  108. package/dist/shared/components/layout-editor/useLayoutDraft.js +474 -0
  109. package/dist/shared/components/pipeline/relations.js +28 -23
  110. package/dist/shared/components/ui/popover.js +17 -17
  111. package/dist/shared/components/ui/scroll-area.js +38 -0
  112. package/dist/shared/hooks/useRelationOptions.js +60 -0
  113. package/dist/shared/lib/layout-grants.js +9 -0
  114. package/dist/shared/lib/layout-ops.js +348 -0
  115. package/dist/shared/lib/layout-slots.js +11 -7
  116. package/dist/shared/lib/request-gate.js +1 -1
  117. package/package.json +5 -1
@@ -0,0 +1,307 @@
1
+ import { HEADER_GROUP_KEY as E, PLACEMENT_PATCH_KEYS as M, isCanvasSlot as j } from "../../../lib/layout-ops.js";
2
+ import { titleCase as w } from "../../../lib/utils.js";
3
+ function f(n) {
4
+ let e = n;
5
+ for (let t = 0; t < 3 && typeof e == "string"; t++) {
6
+ const i = e.trim();
7
+ if (!i) return null;
8
+ try {
9
+ e = JSON.parse(i);
10
+ } catch {
11
+ return null;
12
+ }
13
+ }
14
+ return e ?? null;
15
+ }
16
+ function _(n) {
17
+ const e = f(n);
18
+ return e && typeof e == "object" && !Array.isArray(e) ? e : {};
19
+ }
20
+ function C(n) {
21
+ const e = f(n);
22
+ return Array.isArray(e) ? e : [];
23
+ }
24
+ function d(n, e) {
25
+ if (e.find(
26
+ (o) => o.junction_field != null && (o.one_field && o.one_field !== "id" && o.one_field === n || (!o.one_field || o.one_field === "id") && o.many_collection === n)
27
+ )) return "M2M";
28
+ if (e.find(
29
+ (o) => o.junction_field == null && (o.one_field === n || o.many_collection === n)
30
+ )) return "O2M";
31
+ const r = e.find((o) => o.many_field === n);
32
+ return r != null && r.one_collection ? "M2O" : null;
33
+ }
34
+ function g(n, e) {
35
+ var i, r;
36
+ const t = d(n, e);
37
+ if (t === "M2O") return ((i = e.find((o) => o.many_field === n)) == null ? void 0 : i.one_collection) ?? null;
38
+ if (t === "M2M") {
39
+ const o = e.find(
40
+ (l) => l.junction_field != null && (l.one_field === n || (!l.one_field || l.one_field === "id") && l.many_collection === n)
41
+ );
42
+ return o ? ((r = e.find(
43
+ (l) => l.many_collection === o.many_collection && l.many_field === o.junction_field && l.one_field !== n
44
+ )) == null ? void 0 : r.one_collection) ?? null : null;
45
+ }
46
+ if (t === "O2M") {
47
+ const o = e.find(
48
+ (l) => !l.junction_field && (l.one_field === n || l.one_field === "id" && l.many_collection === n)
49
+ );
50
+ return (o == null ? void 0 : o.many_collection) ?? null;
51
+ }
52
+ return null;
53
+ }
54
+ function p(n) {
55
+ return n ? _(n.overrides) : {};
56
+ }
57
+ function I(n) {
58
+ return _(p(n).options);
59
+ }
60
+ function v(n, e, t, i) {
61
+ const r = e.find((S) => S.field === n) ?? null, o = p(i), l = d(n, t), c = (r == null ? void 0 : r.type) ?? (l === "O2M" || l === "M2M" ? "alias" : "string"), s = l ? l.toLowerCase() : c, u = typeof o.label == "string" && o.label !== "" ? o.label : null, A = typeof o.interface == "string" && o.interface ? o.interface : (r == null ? void 0 : r.interface) ?? null;
62
+ return {
63
+ field: n,
64
+ label: u ?? (r == null ? void 0 : r.label) ?? w(n.split(".").pop() ?? n),
65
+ type: c,
66
+ abstractType: s,
67
+ relKind: l,
68
+ relatedCollection: g(n, t),
69
+ iface: A,
70
+ computedType: (r == null ? void 0 : r.computed_type) ?? null,
71
+ global: r,
72
+ isPath: n.includes(".") && !n.startsWith("__")
73
+ };
74
+ }
75
+ const J = /* @__PURE__ */ new Set([
76
+ "integer",
77
+ "bigInteger",
78
+ "decimal",
79
+ "float",
80
+ "money",
81
+ "smallmoney",
82
+ "tinyint",
83
+ "smallint",
84
+ "bigint"
85
+ ]);
86
+ function a(n, e, t) {
87
+ const i = { ...n };
88
+ return t === void 0 ? delete i[e] : i[e] = t, Object.keys(i).length ? i : null;
89
+ }
90
+ function K(n, e, t) {
91
+ return a(p(n), e, t);
92
+ }
93
+ function W(n, e, t) {
94
+ const i = p(n);
95
+ return a(i, "options", a(_(i.options), e, t) ?? void 0);
96
+ }
97
+ function F(n, e, t) {
98
+ return n.placements.find((i) => i.field === e && i.group_key === t) ?? null;
99
+ }
100
+ function B(n) {
101
+ const e = n.layout_type ?? "grouped";
102
+ return !!n.is_active && e === "grouped";
103
+ }
104
+ function G(n) {
105
+ return n.layout_type || "grouped";
106
+ }
107
+ function U(n) {
108
+ return n ? C(n.lock_conditions) : [];
109
+ }
110
+ function V(n) {
111
+ return n.length ? JSON.stringify(n) : null;
112
+ }
113
+ function h(n) {
114
+ if (!n) return [];
115
+ const e = f(n.input_bindings);
116
+ return Array.isArray(e) ? e.filter((t) => !!t && typeof t == "object") : e && typeof e == "object" ? Object.entries(e).map(([t, i]) => ({
117
+ key: t,
118
+ binding_type: "static",
119
+ binding_value: i
120
+ })) : [];
121
+ }
122
+ function O(n, e) {
123
+ var t;
124
+ return (t = h(n).find((i) => i.key === e)) == null ? void 0 : t.binding_value;
125
+ }
126
+ function x(n, e, t) {
127
+ const i = h(n).filter((o) => o.key !== e), r = t == null || t === "" ? i : [...i, { key: e, binding_type: "static", binding_value: t }];
128
+ return r.length ? r : null;
129
+ }
130
+ function Y(n) {
131
+ const e = f(O(n, "__inline_display__"));
132
+ if (Array.isArray(e)) return { entries: e, separator: null };
133
+ if (e && typeof e == "object") {
134
+ const t = e;
135
+ return {
136
+ entries: Array.isArray(t.fields) ? t.fields : [],
137
+ separator: typeof t.separator == "string" ? t.separator : null
138
+ };
139
+ }
140
+ return { entries: [], separator: null };
141
+ }
142
+ function H(n, e) {
143
+ const t = e.entries.length || e.separator !== null ? JSON.stringify({ fields: e.entries, separator: e.separator }) : null;
144
+ return x(n, "__inline_display__", t);
145
+ }
146
+ const P = "__subtitle__";
147
+ function z(n) {
148
+ const e = n.placements.find((i) => i.field === P);
149
+ if (!e) return null;
150
+ const t = _(O(e, "__subtitle_config__"));
151
+ return {
152
+ fields: Array.isArray(t.fields) ? t.fields : [],
153
+ separator: typeof t.separator == "string" ? t.separator : " | "
154
+ };
155
+ }
156
+ function X(n) {
157
+ return [
158
+ { key: "__subtitle_config__", binding_type: "static", binding_value: JSON.stringify(n) }
159
+ ];
160
+ }
161
+ function T(n) {
162
+ return _(n.default_values);
163
+ }
164
+ function q(n, e, t) {
165
+ const i = t == null || t === "" || Array.isArray(t) && !t.length;
166
+ return a(T(n), e, i ? void 0 : t);
167
+ }
168
+ function Q(n, e, t) {
169
+ const i = /* @__PURE__ */ new Set(), r = [];
170
+ for (const o of n.placements)
171
+ o.field.startsWith("__") || o.field.includes(".") || i.has(o.field) || d(o.field, t) === "O2M" && (i.add(o.field), r.push({
172
+ field: o.field,
173
+ label: v(o.field, e, t, o).label,
174
+ childCollection: g(o.field, t)
175
+ }));
176
+ return r.sort((o, l) => o.label.localeCompare(l.label));
177
+ }
178
+ function D(n) {
179
+ const e = {};
180
+ for (const t of M) e[t] = n[t];
181
+ return e;
182
+ }
183
+ function L(n) {
184
+ const { id: e, key: t, parent_key: i, sort: r, label: o, ...l } = n;
185
+ return l;
186
+ }
187
+ function Z(n, e, t) {
188
+ const i = [];
189
+ let r = t.group_key;
190
+ if (r && r !== E && !n.groups.some((l) => l.key === r)) {
191
+ const l = e.groups.find((c) => c.key === r);
192
+ l ? i.push(...k(n, e, l)) : r = null;
193
+ }
194
+ const o = n.placements.filter((l) => l.group_key === r);
195
+ return i.push({
196
+ op: "place",
197
+ field: t.field,
198
+ group_key: r,
199
+ index: Math.min(t.sort, o.length),
200
+ patch: D(t)
201
+ }), i;
202
+ }
203
+ function k(n, e, t) {
204
+ if (n.groups.some((l) => l.key === t.key)) return [];
205
+ const i = [];
206
+ let r = t.parent_key;
207
+ if (r && !n.groups.some((l) => l.key === r)) {
208
+ const l = e.groups.find((c) => c.key === r);
209
+ l ? i.push(...k(n, e, l)) : r = null;
210
+ }
211
+ const o = n.groups.filter((l) => l.parent_key === r);
212
+ return i.push({
213
+ op: "group_create",
214
+ key: t.key,
215
+ label: t.label,
216
+ group_type: r ? "tab" : t.type,
217
+ parent_key: r,
218
+ index: Math.min(t.sort, o.length),
219
+ patch: { ...L(t), type: r ? "tab" : t.type }
220
+ }), i;
221
+ }
222
+ function $(n, e) {
223
+ const t = /* @__PURE__ */ new Set([
224
+ e,
225
+ ...n.groups.filter((i) => i.parent_key === e).map((i) => i.key)
226
+ ]);
227
+ return n.placements.filter((i) => i.group_key && t.has(i.group_key) && !i.field.startsWith("__")).map((i) => i.field);
228
+ }
229
+ const y = [
230
+ "__pipeline__",
231
+ "__tasks__",
232
+ "__related_records__",
233
+ "__referenced_by__",
234
+ "__comments__",
235
+ "__addendums__"
236
+ ], b = {
237
+ __pipeline__: !1,
238
+ __tasks__: !1,
239
+ __related_records__: !1,
240
+ __referenced_by__: !0,
241
+ __comments__: !1,
242
+ __addendums__: !0,
243
+ __owners__: !1
244
+ };
245
+ function m(n) {
246
+ return b[n] ?? !0;
247
+ }
248
+ function nn(n, e, t, i) {
249
+ const r = e in b ? { default_expanded: m(e), ...i } : i;
250
+ if (t !== null) {
251
+ const s = n.placements.filter((u) => u.group_key === t).length;
252
+ return [{ op: "place", field: e, group_key: t, index: s, patch: r }];
253
+ }
254
+ const o = n.groups.filter((s) => s.parent_key === null).length + n.placements.filter(j).length, l = y.indexOf(e), c = (l < 0 ? [] : y.slice(0, l)).filter(
255
+ (s) => !n.placements.some((u) => u.field === s)
256
+ );
257
+ return [
258
+ ...c.map(
259
+ (s, u) => ({
260
+ op: "place",
261
+ field: s,
262
+ group_key: null,
263
+ index: o + u,
264
+ patch: { default_expanded: m(s) }
265
+ })
266
+ ),
267
+ { op: "place", field: e, group_key: null, index: o + c.length, patch: r }
268
+ ];
269
+ }
270
+ export {
271
+ J as NUMERIC_TYPES,
272
+ b as ROWLESS_SLOT_EXPANDED,
273
+ y as ROWLESS_SLOT_ORDER,
274
+ P as SUBTITLE_FIELD,
275
+ C as asArray,
276
+ _ as asObject,
277
+ O as bindingValue,
278
+ h as bindingsOf,
279
+ T as defaultValuesOf,
280
+ v as describeField,
281
+ F as findPlacement,
282
+ $ as groupFields,
283
+ Y as inlineDisplayOf,
284
+ B as isDefaultForm,
285
+ Q as layoutGrids,
286
+ G as layoutTypeOf,
287
+ V as lockConditionsColumn,
288
+ U as lockConditionsOf,
289
+ k as overrideGroupOps,
290
+ Z as overridePlacementOps,
291
+ f as parseJsonish,
292
+ nn as placeSlotOps,
293
+ D as placementPatchOf,
294
+ I as readOptions,
295
+ p as readOverrides,
296
+ d as relKindOf,
297
+ g as relatedCollectionOf,
298
+ m as rowlessExpanded,
299
+ X as subtitleBindings,
300
+ z as subtitleOf,
301
+ q as withDefaultValue,
302
+ H as withInlineDisplay,
303
+ a as withKey,
304
+ W as withOption,
305
+ K as withOverride,
306
+ x as withStaticBinding
307
+ };
@@ -0,0 +1,15 @@
1
+ import "react/jsx-runtime";
2
+ import "lucide-react";
3
+ import "react";
4
+ import "sonner";
5
+ const t = [
6
+ { type: "grouped", label: "Form", detail: "What people fill in and edit" },
7
+ { type: "summary", label: "Summary", detail: "Read mode for a saved record" },
8
+ { type: "detail", label: "Detail", detail: "The panel a list opens when you drill in" },
9
+ { type: "file", label: "PDF", detail: "A PDF generated from the record" },
10
+ { type: "addendum", label: "Addendum", detail: "The form for a change to a saved record" },
11
+ { type: "table", label: "Grid columns", detail: "Columns when shown as a grid in another record" }
12
+ ];
13
+ export {
14
+ t as LAYOUT_TYPES
15
+ };
@@ -0,0 +1,121 @@
1
+ import { choiceLabel as d, titleCase as b } from "../../../lib/utils.js";
2
+ const $ = /^\{\{\s*([A-Za-z_][A-Za-z0-9_]*)\s*\}\}(?:\s*([*+])\s*(-?\d+(?:\.\d+)?))?$/, _ = {
3
+ gt: "is over",
4
+ gte: "is at least",
5
+ lt: "is under",
6
+ lte: "is at most",
7
+ contains: "contains"
8
+ };
9
+ function q(t) {
10
+ if (!t) return null;
11
+ if (typeof t == "object") return t;
12
+ if (typeof t != "string") return null;
13
+ try {
14
+ const e = JSON.parse(t);
15
+ return e && typeof e == "object" ? e : null;
16
+ } catch {
17
+ return null;
18
+ }
19
+ }
20
+ function C(t) {
21
+ var o;
22
+ const e = {};
23
+ for (const n of t) {
24
+ const s = (o = q(n.options)) == null ? void 0 : o.choices;
25
+ if (!Array.isArray(s)) continue;
26
+ const r = {};
27
+ for (const i of s) {
28
+ if (!i || typeof i != "object") continue;
29
+ const { value: c, text: u } = i;
30
+ c != null && (r[String(c)] = d(u == null ? String(c) : String(u)));
31
+ }
32
+ e[n.field] = r;
33
+ }
34
+ return e;
35
+ }
36
+ function x(t, e) {
37
+ var n;
38
+ const o = (n = e.get(t)) == null ? void 0 : n.label;
39
+ return o != null && o.trim() ? o.trim() : b(t);
40
+ }
41
+ function A(t) {
42
+ return typeof t == "boolean" ? t : t === "true" ? !0 : t === "false" ? !1 : null;
43
+ }
44
+ function S(t) {
45
+ const e = /^(is|has)\s+(.+)$/i.exec(t), o = e && e[1].toLowerCase() === "has" ? "has" : "is", s = (e ? e[2] : t).split(/\s+/).map((r) => /^[A-Z][a-z][a-z-]*$/.test(r) ? r.toLowerCase() : r).join(" ");
46
+ return { verb: o, name: s };
47
+ }
48
+ function E(t, e, o, n) {
49
+ var r;
50
+ if (e == null || e === "") return "empty";
51
+ if (typeof e == "string") {
52
+ const i = $.exec(e.trim());
53
+ if (i) {
54
+ const c = x(i[1], o);
55
+ return i[2] ? `${c} ${i[2] === "*" ? "×" : "+"} ${i[3]}` : c;
56
+ }
57
+ }
58
+ return ((r = n[t]) == null ? void 0 : r[String(e)]) ?? String(e);
59
+ }
60
+ function L(t, e, o) {
61
+ var l;
62
+ const n = x(t.field, e), s = { text: n, strong: !0 };
63
+ if (t.op === "nnull") return [s, { text: " is set" }];
64
+ if (t.op === "null") return [s, { text: " is empty" }];
65
+ const r = t.value == null || t.value === "";
66
+ if (r && t.op === "eq") return [s, { text: " is empty" }];
67
+ if (r && t.op === "neq") return [s, { text: " is set" }];
68
+ const i = t.op === "neq" ? [{ text: " (or empty)" }] : [], u = ((l = e.get(t.field)) == null ? void 0 : l.type) === "boolean" || typeof t.value == "boolean" ? A(t.value) : null;
69
+ if (u !== null && (t.op === "eq" || t.op === "neq")) {
70
+ const h = t.op === "eq" ? u : !u, { verb: p, name: a } = S(n), y = p === "has" ? `no ${a}` : `not ${a}`;
71
+ return [{ text: `${p} ` }, { text: h ? a : y, strong: !0 }, ...i];
72
+ }
73
+ const f = E(t.field, t.value, e, o);
74
+ if (t.op === "eq") return [{ text: `${n} is ` }, { text: f, strong: !0 }];
75
+ if (t.op === "neq")
76
+ return [{ text: `${n} is not ` }, { text: f, strong: !0 }, ...i];
77
+ const m = _[t.op] ?? t.op;
78
+ return [{ text: `${n} ${m} ` }, { text: f, strong: !0 }];
79
+ }
80
+ function g(t) {
81
+ const e = [];
82
+ return t.forEach((o, n) => {
83
+ n > 0 && e.push({ text: " and " }), e.push(...o);
84
+ }), e;
85
+ }
86
+ function O(t, e, o) {
87
+ if (!(t != null && t.length)) return [];
88
+ const n = new Map(e.map((s) => [s.field, s]));
89
+ return g(t.map((s) => L(s, n, o)));
90
+ }
91
+ function R(t) {
92
+ return t.length ? [
93
+ { text: "for " },
94
+ ...g(t.map((e) => [{ text: e, strong: !0 }])),
95
+ { text: " only" }
96
+ ] : [];
97
+ }
98
+ function v(t, e, o) {
99
+ const n = R(t.role_names ?? []);
100
+ switch (t.kind) {
101
+ case "record_rule": {
102
+ const s = O(t.rules, e, o);
103
+ return n.length ? s.length ? [...s, { text: ", " }, ...n] : n : s;
104
+ }
105
+ case "role":
106
+ return n.length ? n : [{ text: "for some roles only" }];
107
+ case "default":
108
+ case "fallback":
109
+ return [{ text: "anything else", strong: !0 }];
110
+ case "type_use":
111
+ return t.type_use ? [{ text: t.type_use }] : [];
112
+ default:
113
+ return [];
114
+ }
115
+ }
116
+ export {
117
+ C as choiceLabelsFrom,
118
+ O as describeConditions,
119
+ v as describeReason,
120
+ R as describeRoles
121
+ };
@@ -0,0 +1,141 @@
1
+ import { useQuery as q, useQueryClient as _, useQueries as T } from "@tanstack/react-query";
2
+ import { useCallback as F, useMemo as h } from "react";
3
+ import { useNivaroClient as d, useItemEditAuth as w } from "../../../context.js";
4
+ import { get as f } from "../../../lib/commands.js";
5
+ import { USER_SYSTEM_COLS as C, userDisplayLabel as $, renderDisplayTemplate as O } from "../../pipeline/relations.js";
6
+ import { collectionMetaKey as L, useCollectionBody as K } from "../collection-meta.js";
7
+ import { choiceLabelsFrom as E } from "./describe-conditions.js";
8
+ import { recordCountFilter as N } from "./record-count.js";
9
+ const m = {
10
+ overview: (e) => ["layout-editor", "overview", e],
11
+ fields: (e) => ["layout-editor", "fields", e],
12
+ meta: (e) => L(e),
13
+ roles: () => ["layout-editor", "roles"]
14
+ };
15
+ function Q(e, l) {
16
+ if (!e || typeof e != "object") return null;
17
+ if (l in e) return e;
18
+ const t = e.data;
19
+ return t && typeof t == "object" ? t : null;
20
+ }
21
+ function U(e) {
22
+ const l = d();
23
+ return q({
24
+ queryKey: m.overview(e),
25
+ queryFn: async () => {
26
+ const t = await l.request(f("/collection-layouts/overview", { collection: e })), n = Q(t, "rows");
27
+ return { rows: (n == null ? void 0 : n.rows) ?? [], warning: (n == null ? void 0 : n.warning) ?? null };
28
+ },
29
+ staleTime: 15e3
30
+ });
31
+ }
32
+ function b(e) {
33
+ const l = d();
34
+ return q({
35
+ queryKey: m.fields(e),
36
+ queryFn: () => l.request(f(`/field-config/${e}`)).then((t) => t.data ?? []),
37
+ staleTime: 6e4
38
+ });
39
+ }
40
+ function x(e, l) {
41
+ const t = K(e, {
42
+ enabled: l,
43
+ select: (n) => typeof (n == null ? void 0 : n.display_template) == "string" ? n.display_template : null
44
+ });
45
+ return t.isError ? { ...t, data: null } : t;
46
+ }
47
+ function z(e) {
48
+ const l = d();
49
+ return q({
50
+ queryKey: m.roles(),
51
+ queryFn: () => l.request(f("/roles")).then((t) => (t.data ?? []).map((n) => ({ id: String(n.id), name: String(n.name) }))),
52
+ enabled: e,
53
+ staleTime: 5 * 6e4
54
+ });
55
+ }
56
+ function B(e) {
57
+ const l = _();
58
+ return F(
59
+ (t) => {
60
+ const n = t != null && t.lazy ? "none" : "active";
61
+ for (const y of [
62
+ m.overview(e),
63
+ ["collection-layouts", e],
64
+ ["active-layout", e]
65
+ ])
66
+ l.invalidateQueries({ queryKey: y, refetchType: n });
67
+ },
68
+ [l, e]
69
+ );
70
+ }
71
+ function Y(e, l, t, n = !0) {
72
+ const y = d(), { userId: v } = w(), i = l ? N(l, t) : null;
73
+ return q({
74
+ queryKey: ["layout-editor", "record-count", v, e, i],
75
+ queryFn: () => y.request(
76
+ f(`/items/${e}`, {
77
+ limit: 1,
78
+ ...i && Object.keys(i).length ? { filter: JSON.stringify(i) } : {}
79
+ })
80
+ ).then((s) => typeof (s == null ? void 0 : s.total) == "number" ? s.total : null),
81
+ enabled: n && !!l && i != null,
82
+ staleTime: 6e4,
83
+ retry: !1
84
+ });
85
+ }
86
+ function G(e, l, t) {
87
+ const n = d(), y = _(), { data: v = [] } = K(e, {
88
+ select: (r) => Array.isArray(r == null ? void 0 : r.relations) ? r.relations : []
89
+ }), i = h(() => E(l), [l]), s = h(() => {
90
+ const r = /* @__PURE__ */ new Map();
91
+ for (const c of t)
92
+ for (const o of c.reason.rules ?? []) {
93
+ if (o.op !== "eq" && o.op !== "neq" || o.value == null || o.value === "" || i[o.field] || typeof o.value == "string" && o.value.includes("{{")) continue;
94
+ const u = v.find(
95
+ (p) => p.many_collection === e && p.many_field === o.field && p.junction_field == null && !!p.one_collection
96
+ );
97
+ if (!(u != null && u.one_collection)) continue;
98
+ const a = String(o.value);
99
+ r.set(`${o.field}:${a}`, { field: o.field, value: a, related: u.one_collection });
100
+ }
101
+ return [...r.values()];
102
+ }, [t, v, i, e]), S = T({
103
+ queries: s.map((r) => ({
104
+ queryKey: ["layout-editor", "rule-label", r.related, r.value],
105
+ queryFn: async () => {
106
+ const c = C.has(r.related), o = await n.request(
107
+ c ? f(`/users/${r.value}`) : f(`/items/${r.related}/${r.value}`, { fields: "*" })
108
+ ).then((a) => a.data);
109
+ if (!o) return null;
110
+ if (c) return $(o);
111
+ const u = await y.fetchQuery({
112
+ queryKey: m.meta(r.related),
113
+ queryFn: () => n.request(
114
+ f(`/collections/${r.related}`)
115
+ ).then((a) => a.data),
116
+ staleTime: 5 * 6e4
117
+ });
118
+ return O((u == null ? void 0 : u.display_template) ?? null, o) || null;
119
+ },
120
+ staleTime: 30 * 6e4,
121
+ retry: !1
122
+ }))
123
+ }), g = JSON.stringify(S.map((r) => r.data ?? null));
124
+ return h(() => {
125
+ const r = JSON.parse(g), c = { ...i };
126
+ return s.forEach((o, u) => {
127
+ const a = r[u];
128
+ a && (c[o.field] = { ...c[o.field] ?? {}, [o.value]: a });
129
+ }), c;
130
+ }, [i, s, g]);
131
+ }
132
+ export {
133
+ m as overviewKeys,
134
+ Y as useApproxRecordCount,
135
+ x as useDisplayTemplate,
136
+ B as useInvalidateLayouts,
137
+ U as useLayoutOverview,
138
+ b as useOverviewFields,
139
+ z as useRoleNames,
140
+ G as useRuleChoiceLabels
141
+ };
@@ -0,0 +1,62 @@
1
+ import { jsx as l } from "react/jsx-runtime";
2
+ import { Fragment as a } from "react";
3
+ import { cn as i } from "../../../lib/utils.js";
4
+ import { describeReason as d } from "./describe-conditions.js";
5
+ const o = {
6
+ summary: "Read mode",
7
+ detail: "Drill-down panel",
8
+ file: "PDF",
9
+ addendum: "Addendum form",
10
+ table: "Grid columns"
11
+ };
12
+ function m({ segs: e, muted: n }) {
13
+ return e.length ? /* @__PURE__ */ l("span", { className: n ? "text-slate-500 dark:text-muted-foreground" : void 0, children: e.map(
14
+ (r, t) => r.strong ? (
15
+ // biome-ignore lint/suspicious/noArrayIndexKey: segments are positional
16
+ /* @__PURE__ */ l("b", { className: "font-semibold text-slate-900 dark:text-foreground", children: r.text }, t)
17
+ ) : (
18
+ // biome-ignore lint/suspicious/noArrayIndexKey: segments are positional
19
+ /* @__PURE__ */ l(a, { children: r.text }, t)
20
+ )
21
+ ) }) : /* @__PURE__ */ l("span", { className: "text-slate-400 dark:text-muted-foreground", children: "—" });
22
+ }
23
+ function x({ tone: e, children: n }) {
24
+ return /* @__PURE__ */ l(
25
+ "span",
26
+ {
27
+ className: i(
28
+ "inline-flex items-center whitespace-nowrap rounded-full px-2 py-px text-[11px] font-semibold",
29
+ e === "default" && "bg-nvr-cyan/15 text-[#0089ad] dark:text-nvr-cyan",
30
+ e === "rule" && "bg-indigo-50 text-indigo-700 dark:bg-indigo-500/15 dark:text-indigo-300",
31
+ e === "role" && "bg-amber-50 text-amber-700 dark:bg-amber-500/15 dark:text-amber-300",
32
+ (e === "link" || e === "view") && "bg-slate-100 text-slate-600 dark:bg-muted dark:text-muted-foreground"
33
+ ),
34
+ children: n
35
+ }
36
+ );
37
+ }
38
+ function k(e) {
39
+ return e.section === "forms" ? e.is_default ? { tone: "default", text: "default" } : e.reason.kind === "record_rule" ? { tone: "rule", text: "rule" } : e.reason.kind === "role" ? { tone: "role", text: "role" } : null : e.section === "link_only" ? { tone: "link", text: "link only" } : e.section === "other_views" && e.is_default ? { tone: "default", text: "default" } : null;
40
+ }
41
+ function p(e, n, r) {
42
+ switch (e.section) {
43
+ case "unused":
44
+ return [{ text: "not used by anything" }];
45
+ case "link_only":
46
+ return e.references.length ? [{ text: e.references.map((t) => t.label).join(" · ") }] : [{ text: "opened by a link only" }];
47
+ case "other_views":
48
+ return [{ text: e.reason.type_use || o[e.layout_type] || e.layout_type }];
49
+ default: {
50
+ if (e.reason.kind === "slug") return [{ text: "opened by a link only" }];
51
+ const t = d(e.reason, n, r);
52
+ return e.reason.kind === "default" || e.reason.kind === "fallback" ? [{ text: "for " }, ...t] : e.reason.kind === "record_rule" && t.length ? [{ text: "when the record " }, ...t] : t;
53
+ }
54
+ }
55
+ }
56
+ export {
57
+ x as Pill,
58
+ m as Sentence,
59
+ o as TYPE_USE,
60
+ p as purposeSegments,
61
+ k as rowPill
62
+ };