@nivaro/react 0.2.51 → 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 (117) 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 +4044 -3866
  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,474 @@
1
+ var F = Object.defineProperty;
2
+ var L = (s, t, e) => t in s ? F(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
+ var a = (s, t, e) => L(s, typeof t != "symbol" ? t + "" : t, e);
4
+ import { useQueryClient as $, useQuery as A } from "@tanstack/react-query";
5
+ import { useRef as U, useSyncExternalStore as W, useEffect as S, useCallback as p } from "react";
6
+ import { toast as K } from "sonner";
7
+ import { useNivaroClient as q } from "../../context.js";
8
+ import { get as I, post as P } from "../../lib/commands.js";
9
+ import { applyLayoutOps as h, isCanvasSlot as V, GROUP_PATCH_KEYS as M, PLACEMENT_PATCH_KEYS as R } from "../../lib/layout-ops.js";
10
+ const E = {
11
+ bundle: (s) => ["layout-editor", "bundle", s],
12
+ versions: (s) => ["layout-editor", "versions", s]
13
+ }, j = /* @__PURE__ */ new Set([
14
+ "name",
15
+ "slug",
16
+ "create_label",
17
+ "create_hidden",
18
+ "sort",
19
+ "is_active",
20
+ "conditions",
21
+ "layout_type",
22
+ "record_conditions",
23
+ "parent_layout_id",
24
+ "tab_mode"
25
+ ]);
26
+ function ue(s) {
27
+ return s ? s.some(
28
+ (t) => t.op === "layout_update" && Object.keys(t.patch ?? {}).some((e) => j.has(e))
29
+ ) : !0;
30
+ }
31
+ const B = 600, D = "Someone else changed this layout — reloaded", N = 100;
32
+ function w(s) {
33
+ const t = (r) => !!r && typeof r == "object" && Array.isArray(r.groups) && Array.isArray(r.placements) && typeof r.rev == "string";
34
+ if (t(s)) return s;
35
+ const e = s == null ? void 0 : s.data;
36
+ return t(e) ? e : null;
37
+ }
38
+ function z(s) {
39
+ return /^No group "/.test(s) ? "That section is no longer on this form" : /^"[^"]*" is not placed in /.test(s) ? "That field is no longer where it was" : /^"[^"]*" is already in /.test(s) ? "That field is already there" : /^"[^"]*" is not on this form/.test(s) ? "That item is no longer on this form" : /^"[^"]*" is not a container/.test(s) ? "Tabs can only go inside a tab group" : /^"[^"]*" is a reserved name/.test(s) ? "That name is reserved" : /^A group "[^"]*" already exists/.test(s) ? "A section with that key already exists" : /^Unknown setting "/.test(s) ? "That setting can’t be saved on this form" : s;
40
+ }
41
+ function O(s, t = "The layout could not be saved") {
42
+ var i, u;
43
+ const e = s, r = (e == null ? void 0 : e.status) ?? ((i = e == null ? void 0 : e.response) == null ? void 0 : i.status) ?? null, n = ((u = e == null ? void 0 : e.response) == null ? void 0 : u.data) ?? (e == null ? void 0 : e.response), o = typeof (n == null ? void 0 : n.error) == "string" && n.error || typeof (n == null ? void 0 : n.message) == "string" && n.message || typeof (e == null ? void 0 : e.message) == "string" && e.message || t;
44
+ return { status: r, message: z(o), bundle: w(n == null ? void 0 : n.bundle) };
45
+ }
46
+ const Q = (s) => h(s, [{ op: "layout_update", patch: {} }]), m = (s, t) => s.placements.find((e) => e.field === t.field && e.group_key === (t.group_key ?? null));
47
+ function T(s) {
48
+ const t = {};
49
+ for (const e of R) t[e] = s[e];
50
+ return t;
51
+ }
52
+ function Y(s) {
53
+ const t = {};
54
+ for (const e of M) t[e] = s[e];
55
+ return t;
56
+ }
57
+ function v(s, t) {
58
+ const e = {};
59
+ for (const r of Object.keys(t)) e[r] = s[r] === void 0 ? null : s[r];
60
+ return e;
61
+ }
62
+ function G(s, t) {
63
+ switch (t.op) {
64
+ case "place":
65
+ return [{ op: "remove", at: { field: t.field, group_key: t.group_key ?? null } }];
66
+ case "move": {
67
+ const e = m(s, t.from);
68
+ return e ? [
69
+ {
70
+ op: "move",
71
+ from: { field: e.field, group_key: t.to_group_key ?? null },
72
+ to_group_key: e.group_key,
73
+ index: e.sort
74
+ }
75
+ ] : [];
76
+ }
77
+ case "update_placement": {
78
+ const e = m(s, t.at);
79
+ return e ? [
80
+ {
81
+ op: "update_placement",
82
+ at: t.at,
83
+ patch: v(e, t.patch ?? {})
84
+ }
85
+ ] : [];
86
+ }
87
+ case "remove": {
88
+ const e = m(s, t.at);
89
+ return e ? [
90
+ {
91
+ op: "place",
92
+ field: e.field,
93
+ group_key: e.group_key,
94
+ index: e.sort,
95
+ patch: T(e)
96
+ }
97
+ ] : [];
98
+ }
99
+ case "group_create":
100
+ return [{ op: "group_remove", key: t.key, placements: "delete" }];
101
+ case "group_update": {
102
+ const e = s.groups.find((r) => r.key === t.key);
103
+ return e ? [
104
+ {
105
+ op: "group_update",
106
+ key: t.key,
107
+ patch: v(e, t.patch ?? {})
108
+ }
109
+ ] : [];
110
+ }
111
+ case "group_move": {
112
+ const e = s.groups.find((n) => n.key === t.key);
113
+ if (e) return [{ op: "group_move", key: t.key, parent_key: e.parent_key, index: e.sort }];
114
+ const r = s.placements.find((n) => n.field === t.key && V(n));
115
+ return r ? [{ op: "group_move", key: t.key, parent_key: null, index: r.sort }] : [];
116
+ }
117
+ case "group_remove": {
118
+ const e = s.groups.find((i) => i.key === t.key);
119
+ if (!e) return [];
120
+ const r = [
121
+ {
122
+ op: "group_create",
123
+ key: e.key,
124
+ label: e.label,
125
+ group_type: e.type,
126
+ parent_key: e.parent_key,
127
+ index: e.sort,
128
+ patch: Y(e)
129
+ }
130
+ ];
131
+ return s.groups.filter((i) => i.parent_key === e.key).sort((i, u) => i.sort - u.sort).forEach((i, u) => {
132
+ r.push({ op: "group_move", key: i.key, parent_key: e.key, index: u });
133
+ }), s.placements.filter((i) => i.group_key === e.key).sort((i, u) => i.sort - u.sort).forEach((i, u) => {
134
+ const c = t.placements === "ungroup" && !s.placements.some((l) => l.field === i.field && l.group_key === null);
135
+ r.push(
136
+ c ? {
137
+ op: "move",
138
+ from: { field: i.field, group_key: null },
139
+ to_group_key: e.key,
140
+ index: u
141
+ } : { op: "place", field: i.field, group_key: e.key, index: u, patch: T(i) }
142
+ );
143
+ }), r;
144
+ }
145
+ case "layout_update":
146
+ return [{ op: "layout_update", patch: v(s.layout, t.patch ?? {}) }];
147
+ default:
148
+ return [];
149
+ }
150
+ }
151
+ function _(s, t) {
152
+ let e = Q(s), r = [];
153
+ for (const n of t)
154
+ r = [...G(e, n), ...r], e = h(e, [n]);
155
+ return r;
156
+ }
157
+ function H(s) {
158
+ const t = [];
159
+ for (const e of s)
160
+ if (e.op === "update_placement")
161
+ for (const [r, n] of Object.entries(e.patch ?? {}))
162
+ t.push({
163
+ key: `p\0${e.at.field}\0${e.at.group_key ?? ""}\0${r}`,
164
+ op: { op: "update_placement", at: e.at, patch: { [r]: n } }
165
+ });
166
+ else if (e.op === "group_update")
167
+ for (const [r, n] of Object.entries(e.patch ?? {}))
168
+ t.push({
169
+ key: `g\0${e.key}\0${r}`,
170
+ op: { op: "group_update", key: e.key, patch: { [r]: n } }
171
+ });
172
+ else if (e.op === "layout_update")
173
+ for (const [r, n] of Object.entries(e.patch ?? {}))
174
+ t.push({ key: `l\0${r}`, op: { op: "layout_update", patch: { [r]: n } } });
175
+ else return null;
176
+ return t;
177
+ }
178
+ const y = (s) => s instanceof Error ? s.message : String(s);
179
+ class X {
180
+ constructor(t) {
181
+ a(this, "server", null);
182
+ a(this, "draft", null);
183
+ a(this, "queue", []);
184
+ a(this, "inFlight", !1);
185
+ a(this, "text", /* @__PURE__ */ new Map());
186
+ a(this, "undoStack", []);
187
+ a(this, "redoStack", []);
188
+ a(this, "outcome", "idle");
189
+ a(this, "error", null);
190
+ a(this, "nextId", 1);
191
+ a(this, "listeners", /* @__PURE__ */ new Set());
192
+ a(this, "idleWaiters", []);
193
+ a(this, "view");
194
+ a(this, "subscribe", (t) => (this.listeners.add(t), () => {
195
+ this.listeners.delete(t);
196
+ }));
197
+ a(this, "getView", () => this.view);
198
+ this.transport = t, this.view = this.buildView();
199
+ }
200
+ /**
201
+ * A fetched bundle. Ignored while anything is pending, so typing is never
202
+ * overwritten. Our own saves arrive here with the rev we already hold; a new
203
+ * rev means someone else saved, and the undo steps (index-based inverses of
204
+ * the old state) would undo over their change — so the history goes.
205
+ */
206
+ receive(t) {
207
+ this.pending() || this.server && this.server.rev === t.rev || (this.server && (this.undoStack = [], this.redoStack = []), this.server = t, this.draft = t, this.emit());
208
+ }
209
+ apply(t, e) {
210
+ if (!this.draft || t.length === 0) return;
211
+ const r = (e == null ? void 0 : e.label) ?? "Edit", n = e != null && e.text ? H(t) : null;
212
+ if (n) return this.applyText(n, r);
213
+ this.flushText();
214
+ const o = this.draft;
215
+ let i;
216
+ try {
217
+ h(o, t), i = _(o, t);
218
+ } catch (c) {
219
+ this.fail(y(c));
220
+ return;
221
+ }
222
+ this.clearOutcome();
223
+ const u = this.enqueue("do", t, r);
224
+ (e == null ? void 0 : e.undoable) !== !1 && (this.pushUndo({ label: r, forward: t, inverse: i, batchId: u.id }), this.redoStack = []), this.refresh();
225
+ }
226
+ // Undo / redo pop the step before checking it still applies: a step that no
227
+ // longer fits the draft is discarded with an error, not retried.
228
+ undo() {
229
+ this.flushText();
230
+ const t = this.undoStack.pop();
231
+ if (!(!t || !this.draft)) {
232
+ try {
233
+ h(this.draft, t.inverse);
234
+ } catch (e) {
235
+ this.fail(`Could not undo: ${y(e)}`);
236
+ return;
237
+ }
238
+ this.clearOutcome(), t.batchId = this.enqueue("undo", t.inverse, `Undo ${t.label}`).id, this.redoStack.push(t), this.refresh();
239
+ }
240
+ }
241
+ redo() {
242
+ this.flushText();
243
+ const t = this.redoStack.pop();
244
+ if (!(!t || !this.draft)) {
245
+ try {
246
+ h(this.draft, t.forward), t.inverse = _(this.draft, t.forward);
247
+ } catch (e) {
248
+ this.fail(`Could not redo: ${y(e)}`);
249
+ return;
250
+ }
251
+ this.clearOutcome(), t.batchId = this.enqueue("redo", t.forward, `Redo ${t.label}`).id, this.undoStack.push(t), this.refresh();
252
+ }
253
+ }
254
+ /** Send every pending text edit now (blur, unmount, before another op). */
255
+ flushText() {
256
+ for (const t of [...this.text.keys()]) this.flushTextKey(t);
257
+ }
258
+ /** Anything typed, queued or in flight. */
259
+ isBusy() {
260
+ return this.pending();
261
+ }
262
+ whenIdle(t = 15e3) {
263
+ return this.flushText(), this.pending() ? new Promise((e) => {
264
+ let r = !1;
265
+ const n = () => {
266
+ r || (r = !0, clearTimeout(o), e());
267
+ }, o = setTimeout(() => {
268
+ this.idleWaiters = this.idleWaiters.filter((i) => i !== n), n();
269
+ }, t);
270
+ this.idleWaiters.push(n);
271
+ }) : Promise.resolve();
272
+ }
273
+ applyText(t, e) {
274
+ const r = this.draft;
275
+ try {
276
+ h(
277
+ r,
278
+ t.map((n) => n.op)
279
+ );
280
+ } catch (n) {
281
+ this.fail(y(n));
282
+ return;
283
+ }
284
+ this.clearOutcome();
285
+ for (const { key: n, op: o } of t) {
286
+ const i = this.text.get(n);
287
+ i && clearTimeout(i.timer);
288
+ const u = setTimeout(() => this.flushTextKey(n), B), c = (i == null ? void 0 : i.inverse) ?? _(r, [o])[0];
289
+ this.text.set(n, { op: o, inverse: c, label: e, timer: u });
290
+ }
291
+ this.redoStack = [], this.refresh();
292
+ }
293
+ flushTextKey(t) {
294
+ const e = this.text.get(t);
295
+ if (!e) return;
296
+ clearTimeout(e.timer), this.text.delete(t);
297
+ const r = this.enqueue("do", [e.op], e.label);
298
+ this.pushUndo({
299
+ label: e.label,
300
+ forward: [e.op],
301
+ inverse: e.inverse ? [e.inverse] : [],
302
+ batchId: r.id
303
+ }), this.refresh();
304
+ }
305
+ enqueue(t, e, r) {
306
+ const n = { id: this.nextId++, kind: t, ops: e, note: r };
307
+ return this.queue.push(n), n;
308
+ }
309
+ pushUndo(t) {
310
+ this.undoStack.push(t), this.undoStack.length > N && this.undoStack.shift();
311
+ }
312
+ pending() {
313
+ return this.inFlight || this.queue.length > 0 || this.text.size > 0;
314
+ }
315
+ clearOutcome() {
316
+ this.error = null, (this.outcome === "error" || this.outcome === "conflict") && (this.outcome = "idle");
317
+ }
318
+ fail(t) {
319
+ this.error = t, this.outcome = "error", this.emit();
320
+ }
321
+ /** A batch the server refused: forget its step (or hand an undo/redo back). */
322
+ rollback(t) {
323
+ const e = (r) => {
324
+ const n = r.findIndex((o) => o.batchId === t.id);
325
+ return n < 0 ? null : r.splice(n, 1)[0];
326
+ };
327
+ if (t.kind === "do") e(this.undoStack);
328
+ else if (t.kind === "undo") {
329
+ const r = e(this.redoStack);
330
+ r && this.undoStack.push(r);
331
+ } else {
332
+ const r = e(this.undoStack);
333
+ r && this.redoStack.push(r);
334
+ }
335
+ }
336
+ conflict(t) {
337
+ for (const e of this.text.values()) clearTimeout(e.timer);
338
+ this.text.clear(), this.queue = [], this.undoStack = [], this.redoStack = [], t ? (this.server = t, this.transport.saved(t, null)) : this.transport.reload(), this.outcome = "conflict", this.error = null, this.transport.notify(D);
339
+ }
340
+ /** Draft = server bundle + queued batches + typed text; then send the next batch. */
341
+ refresh() {
342
+ this.recompute(), this.pump(), this.emit();
343
+ }
344
+ recompute() {
345
+ if (!this.server) return;
346
+ let t = this.server;
347
+ const e = [];
348
+ for (const [r, n] of this.queue.entries())
349
+ try {
350
+ t = h(t, n.ops), e.push(n);
351
+ } catch (o) {
352
+ r === 0 && this.inFlight ? e.push(n) : (this.rollback(n), this.error ?? (this.error = y(o)), this.outcome = "error");
353
+ }
354
+ this.queue = e;
355
+ for (const [r, n] of this.text)
356
+ try {
357
+ t = h(t, [n.op]);
358
+ } catch {
359
+ clearTimeout(n.timer), this.text.delete(r);
360
+ }
361
+ this.draft = t;
362
+ }
363
+ pump() {
364
+ if (this.inFlight || !this.server || this.queue.length === 0) return;
365
+ const t = this.queue[0];
366
+ this.inFlight = !0, this.transport.send(t.ops, this.server.rev, t.note).then((e) => {
367
+ this.server = e, this.queue.shift(), this.transport.saved(e, t.ops), this.outcome !== "error" && (this.outcome = "saved");
368
+ }).catch((e) => {
369
+ const r = O(e);
370
+ r.status === 409 ? this.conflict(r.bundle) : (this.queue.shift(), this.rollback(t), this.error = r.message, this.outcome = "error");
371
+ }).finally(() => {
372
+ this.inFlight = !1, this.refresh();
373
+ });
374
+ }
375
+ buildView() {
376
+ var r;
377
+ const t = this.undoStack[this.undoStack.length - 1], e = [...this.text.values()].pop();
378
+ return {
379
+ bundle: this.draft,
380
+ canUndo: this.undoStack.length > 0 || this.text.size > 0,
381
+ canRedo: this.redoStack.length > 0,
382
+ undoLabel: (e == null ? void 0 : e.label) ?? (t == null ? void 0 : t.label) ?? null,
383
+ redoLabel: ((r = this.redoStack[this.redoStack.length - 1]) == null ? void 0 : r.label) ?? null,
384
+ status: this.pending() ? "saving" : this.outcome,
385
+ error: this.error
386
+ };
387
+ }
388
+ emit() {
389
+ this.view = this.buildView();
390
+ for (const t of this.listeners) t();
391
+ if (this.idleWaiters.length > 0 && !this.pending()) {
392
+ const t = this.idleWaiters;
393
+ this.idleWaiters = [];
394
+ for (const e of t) e();
395
+ }
396
+ }
397
+ }
398
+ const x = /* @__PURE__ */ new WeakMap();
399
+ function J(s, t) {
400
+ let e = x.get(t.qc);
401
+ e || (e = /* @__PURE__ */ new Map(), x.set(t.qc, e));
402
+ const r = e.get(s);
403
+ if (r != null && r.engine.isBusy()) return r;
404
+ const n = E.bundle(s), o = { current: t }, u = { engine: new X({
405
+ send: async (c, l, d) => {
406
+ const f = await o.current.client.request(
407
+ P(`/collection-layouts/${s}/ops`, { ops: c, base_rev: l, note: d })
408
+ ), k = w(f);
409
+ if (!k) throw new Error("The server answered without the saved layout");
410
+ return k;
411
+ },
412
+ saved: (c, l) => {
413
+ var d, f;
414
+ o.current.qc.setQueryData(n, c), (f = (d = o.current).onSaved) == null || f.call(d, c, l);
415
+ },
416
+ reload: () => {
417
+ o.current.qc.invalidateQueries({ queryKey: n });
418
+ },
419
+ notify: (c) => {
420
+ K.warning(c);
421
+ }
422
+ }), live: o };
423
+ return e.set(s, u), u;
424
+ }
425
+ function Z(s, t = !0) {
426
+ const e = q();
427
+ return A({
428
+ queryKey: E.bundle(s ?? 0),
429
+ queryFn: async () => {
430
+ const r = await e.request(I(`/collection-layouts/${s}/bundle`)), n = w(r);
431
+ if (!n) throw new Error("The layout could not be read");
432
+ return n;
433
+ },
434
+ enabled: t && s != null,
435
+ staleTime: 15e3,
436
+ refetchOnWindowFocus: !1
437
+ });
438
+ }
439
+ function ae(s, t = {}) {
440
+ const e = q(), r = $(), n = Z(s), o = U(null);
441
+ (!o.current || o.current.id !== s || o.current.qc !== r) && (o.current = { id: s, qc: r, ...J(s, { client: e, qc: r, ...t }) }), o.current.live.current = { client: e, qc: r, onSaved: t.onSaved };
442
+ const i = o.current.engine, u = W(i.subscribe, i.getView, i.getView);
443
+ S(() => {
444
+ n.data && i.receive(n.data);
445
+ }, [i, n.data]), S(() => () => i.flushText(), [i]);
446
+ const c = p(
447
+ (g, C) => i.apply(g, C),
448
+ [i]
449
+ ), l = p(() => i.undo(), [i]), d = p(() => i.redo(), [i]), f = p(() => i.flushText(), [i]), k = p((g) => i.whenIdle(g), [i]), b = !u.bundle && n.error != null;
450
+ return {
451
+ ...u,
452
+ status: b ? "error" : u.status,
453
+ error: u.error ?? (b ? O(n.error, "The layout could not be read").message : null),
454
+ apply: c,
455
+ undo: l,
456
+ redo: d,
457
+ flush: f,
458
+ whenIdle: k,
459
+ isLoading: n.isLoading
460
+ };
461
+ }
462
+ export {
463
+ D as CONFLICT_MESSAGE,
464
+ X as LayoutDraftEngine,
465
+ B as TEXT_DEBOUNCE_MS,
466
+ z as humanizeOpError,
467
+ _ as inverseOps,
468
+ E as layoutDraftKeys,
469
+ w as parseBundle,
470
+ O as parseSaveFailure,
471
+ ue as touchesOverview,
472
+ Z as useLayoutBundle,
473
+ ae as useLayoutDraft
474
+ };
@@ -1,39 +1,44 @@
1
- const r = ["name", "title", "label", "display_name", "subject", "email", "slug"];
2
- function c(t, n) {
3
- if (!t) {
4
- for (const l of r)
5
- if (n[l] != null && n[l] !== "") return String(n[l]);
6
- return String(n.id ?? "");
1
+ const a = ["name", "title", "label", "display_name", "subject", "email", "slug"], f = /* @__PURE__ */ new Set(["nivaro_users", "directus_users"]);
2
+ function c(n) {
3
+ return [n.first_name, n.last_name].filter(Boolean).join(" ").trim() || String(n.email ?? n.id ?? "");
4
+ }
5
+ function u(n, e) {
6
+ if (!n) {
7
+ for (const l of a)
8
+ if (e[l] != null && e[l] !== "") return String(e[l]);
9
+ return String(e.id ?? "");
7
10
  }
8
- return t.replace(/\{\{([\w.]+)\}\}/g, (l, e) => {
9
- const o = e.split(".");
10
- let i = n;
11
- for (const f of o) {
11
+ return n.replace(/\{\{([\w.]+)\}\}/g, (l, t) => {
12
+ const o = t.split(".");
13
+ let i = e;
14
+ for (const r of o) {
12
15
  if (i == null || typeof i != "object") {
13
16
  i = null;
14
17
  break;
15
18
  }
16
- i = i[f];
19
+ i = i[r];
17
20
  }
18
21
  return String(i ?? "");
19
22
  });
20
23
  }
21
- function u(t) {
22
- return t ? ["id", ...[...t.matchAll(/\{\{([\w.]+)\}\}/g)].map((l) => l[1])] : ["*"];
24
+ function s(n) {
25
+ return n ? ["id", ...[...n.matchAll(/\{\{([\w.]+)\}\}/g)].map((l) => l[1])] : ["*"];
23
26
  }
24
- function a(t, n, l) {
25
- return t.find(
26
- (e) => e.many_collection === n && e.many_field === l && e.junction_field === null && e.one_collection !== null
27
+ function d(n, e, l) {
28
+ return n.find(
29
+ (t) => t.many_collection === e && t.many_field === l && t.junction_field === null && t.one_collection !== null
27
30
  );
28
31
  }
29
- function d(t, n, l) {
30
- return t.find(
31
- (e) => e.one_collection === n && e.one_field === l && e.junction_field === null
32
+ function _(n, e, l) {
33
+ return n.find(
34
+ (t) => t.one_collection === e && t.one_field === l && t.junction_field === null
32
35
  );
33
36
  }
34
37
  export {
35
- u as extractTemplateFields,
36
- a as findM2ORelation,
37
- d as findO2MRelation,
38
- c as renderDisplayTemplate
38
+ f as USER_SYSTEM_COLS,
39
+ s as extractTemplateFields,
40
+ d as findM2ORelation,
41
+ _ as findO2MRelation,
42
+ u as renderDisplayTemplate,
43
+ c as userDisplayLabel
39
44
  };
@@ -1,8 +1,8 @@
1
- import { jsxs as l, Fragment as c, jsx as a } from "react/jsx-runtime";
1
+ import { jsxs as c, Fragment as f, jsx as a } from "react/jsx-runtime";
2
2
  import * as t from "@radix-ui/react-popover";
3
3
  import * as n from "react";
4
- import { cn as f } from "../../lib/utils.js";
5
- function u(e) {
4
+ import { cn as u } from "../../lib/utils.js";
5
+ function g(e) {
6
6
  let r = (e == null ? void 0 : e.parentElement) ?? null;
7
7
  for (; r; ) {
8
8
  const o = r.closest('[role="dialog"]');
@@ -11,30 +11,30 @@ function u(e) {
11
11
  r = o.parentElement;
12
12
  }
13
13
  }
14
- const P = t.Root, x = t.Trigger, w = t.Anchor, g = n.forwardRef(({ className: e, align: r = "center", sideOffset: o = 4, ...d }, s) => {
15
- const [i, p] = n.useState(null), m = n.useMemo(() => u(i), [i]);
16
- return /* @__PURE__ */ l(c, { children: [
17
- /* @__PURE__ */ a("span", { ref: p, hidden: !0, "data-nvr-popover-marker": "" }),
18
- /* @__PURE__ */ a(t.Portal, { container: m, children: /* @__PURE__ */ a(
14
+ const x = t.Root, w = t.Trigger, b = t.Anchor, v = n.forwardRef(({ className: e, align: r = "center", sideOffset: o = 4, container: i, ...s }, p) => {
15
+ const [d, m] = n.useState(null), l = n.useMemo(() => i ?? g(d), [i, d]);
16
+ return /* @__PURE__ */ c(f, { children: [
17
+ /* @__PURE__ */ a("span", { ref: m, hidden: !0, "data-nvr-popover-marker": "" }),
18
+ /* @__PURE__ */ a(t.Portal, { container: l, children: /* @__PURE__ */ a(
19
19
  t.Content,
20
20
  {
21
- ref: s,
21
+ ref: p,
22
22
  align: r,
23
23
  sideOffset: o,
24
- className: f(
24
+ className: u(
25
25
  "z-[110] w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-popover-content-transform-origin]",
26
26
  e
27
27
  ),
28
- ...d
28
+ ...s
29
29
  }
30
30
  ) })
31
31
  ] });
32
32
  });
33
- g.displayName = t.Content.displayName;
33
+ v.displayName = t.Content.displayName;
34
34
  export {
35
- P as Popover,
36
- w as PopoverAnchor,
37
- g as PopoverContent,
38
- x as PopoverTrigger,
39
- u as modalHostOf
35
+ x as Popover,
36
+ b as PopoverAnchor,
37
+ v as PopoverContent,
38
+ w as PopoverTrigger,
39
+ g as modalHostOf
40
40
  };
@@ -0,0 +1,38 @@
1
+ import { jsxs as d, jsx as e } from "react/jsx-runtime";
2
+ import * as r from "@radix-ui/react-scroll-area";
3
+ import * as s from "react";
4
+ import { cn as t } from "../../lib/utils.js";
5
+ const m = s.forwardRef(({ className: o, children: l, ...a }, c) => /* @__PURE__ */ d(
6
+ r.Root,
7
+ {
8
+ ref: c,
9
+ className: t("relative overflow-hidden", o),
10
+ ...a,
11
+ children: [
12
+ /* @__PURE__ */ e(r.Viewport, { className: "h-full w-full rounded-[inherit]", children: l }),
13
+ /* @__PURE__ */ e(i, {}),
14
+ /* @__PURE__ */ e(r.Corner, {})
15
+ ]
16
+ }
17
+ ));
18
+ m.displayName = r.Root.displayName;
19
+ const i = s.forwardRef(({ className: o, orientation: l = "vertical", ...a }, c) => /* @__PURE__ */ e(
20
+ r.ScrollAreaScrollbar,
21
+ {
22
+ ref: c,
23
+ orientation: l,
24
+ className: t(
25
+ "flex touch-none select-none transition-colors",
26
+ l === "vertical" && "h-full w-2.5 border-l border-l-transparent p-[1px]",
27
+ l === "horizontal" && "h-2.5 flex-col border-t border-t-transparent p-[1px]",
28
+ o
29
+ ),
30
+ ...a,
31
+ children: /* @__PURE__ */ e(r.ScrollAreaThumb, { className: "relative flex-1 rounded-full bg-border" })
32
+ }
33
+ ));
34
+ i.displayName = r.ScrollAreaScrollbar.displayName;
35
+ export {
36
+ m as ScrollArea,
37
+ i as ScrollBar
38
+ };