@declarion/react 0.29.0 → 0.31.1

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 (32) hide show
  1. package/dist-lib/{ActionRunner-DtUDeH4F.js → ActionRunner-BzaZQtiI.js} +1150 -993
  2. package/dist-lib/{DraggableChildrenTable-D4WoV6ck.js → DraggableChildrenTable-DILqStHQ.js} +29 -29
  3. package/dist-lib/{Grid-CsK_TuK_.js → Grid-BIsiUwPh.js} +2 -2
  4. package/dist-lib/LayoutRenderer-3RvIsC9M.js +2885 -0
  5. package/dist-lib/{MarkdownRenderer-CwlNQju5.js → MarkdownRenderer-CaHhWrfm.js} +1 -1
  6. package/dist-lib/SmartDetailPage.impl--EO-9fos.js +1494 -0
  7. package/dist-lib/SmartRecordListPage.impl-B1iws8yf.js +763 -0
  8. package/dist-lib/components/detail-layout/DraggableChildrenTable.d.ts +1 -0
  9. package/dist-lib/components/detail-layout/EditableChildrenTable.d.ts +2 -1
  10. package/dist-lib/components/detail-layout/FieldRow.d.ts +2 -1
  11. package/dist-lib/components/detail-layout/LayoutRenderer.d.ts +2 -0
  12. package/dist-lib/components/layout/TenantChip.d.ts +2 -1
  13. package/dist-lib/components/layout/TopBar.d.ts +9 -1
  14. package/dist-lib/components/pages/SmartDetailPage.d.ts +2 -5
  15. package/dist-lib/components/pages/SmartDetailPage.impl.d.ts +4 -0
  16. package/dist-lib/components/pages/SmartRecordListPage.d.ts +2 -5
  17. package/dist-lib/components/pages/SmartRecordListPage.impl.d.ts +4 -0
  18. package/dist-lib/components/pages/list/ListHeader.d.ts +6 -1
  19. package/dist-lib/components/pages/list/cardProjection.d.ts +66 -0
  20. package/dist-lib/declarion-react.css +1 -1
  21. package/dist-lib/hooks/useResponsiveMode.d.ts +30 -0
  22. package/dist-lib/index.d.ts +2 -0
  23. package/dist-lib/index.js +6748 -15502
  24. package/dist-lib/lib/actions.d.ts +10 -0
  25. package/dist-lib/peekDraftStore-yyzMbaiI.js +468 -0
  26. package/dist-lib/registry-2KliNTHB.js +5177 -0
  27. package/dist-lib/testing.d.ts +3 -0
  28. package/dist-lib/testing.js +55 -52
  29. package/dist-lib/types/schema.d.ts +50 -4
  30. package/dist-lib/useProperties-Co3RdtuT.js +453 -0
  31. package/dist-lib/{value-CNUbJNK-.js → value-BooGwUik.js} +1 -1
  32. package/package.json +1 -1
@@ -0,0 +1,2885 @@
1
+ import { s as e, t } from "./DynamicIcon-DCRdxxZ7.js";
2
+ import { $ as n, B as r, Bn as i, F as a, Fn as o, H as s, Hn as c, I as l, Ot as u, Q as d, V as f, Vn as p, Xt as m, an as h, cn as g, dn as _, f as v, fn as y, gn as b, h as x, kn as S, m as C, nn as w, on as T, p as E, rn as D, sn as O, tn as k, wn as A } from "./ActionRunner-BzaZQtiI.js";
3
+ import { E as j, G as M, K as N, Q as ee, T as P, U as F, W as I, Z as L, _t as R, d as z, gt as B, k as V, o as te, r as ne, t as re, u as ie, ut as ae } from "./registry-2KliNTHB.js";
4
+ import { n as oe, r as se, t as ce } from "./dataTableStyles-vwD1mVOP.js";
5
+ import { Suspense as le, createContext as ue, lazy as de, useCallback as H, useContext as fe, useEffect as U, useId as pe, useLayoutEffect as me, useMemo as W, useRef as G, useState as K } from "react";
6
+ import { useInfiniteQuery as he, useMutation as ge, useQueryClient as _e } from "@tanstack/react-query";
7
+ import { Fragment as q, jsx as J, jsxs as Y } from "react/jsx-runtime";
8
+ //#region src/lib/size-value.ts
9
+ var ve = /^(\d+)px$/;
10
+ function ye(e) {
11
+ if (e == null || e === "") return null;
12
+ if (e === "auto") return { kind: "auto" };
13
+ if (e === "fill") return { kind: "fill" };
14
+ let t = ve.exec(e);
15
+ if (t) {
16
+ let e = parseInt(t[1], 10);
17
+ return e > 0 ? {
18
+ kind: "px",
19
+ value: e
20
+ } : null;
21
+ }
22
+ let n = parseInt(e, 10);
23
+ return !isNaN(n) && String(n) === e && n > 0 ? {
24
+ kind: "weight",
25
+ value: n
26
+ } : null;
27
+ }
28
+ //#endregion
29
+ //#region src/components/detail-layout/LayoutRow.tsx
30
+ function be({ config: e, ctx: t }) {
31
+ let { items: n, gap: r = 0, resizable: i = !1, stack_below: a } = e, o = a === "never" ? 0 : a ?? 768, [s, c] = K(!1), l = G(null);
32
+ U(() => {
33
+ if (o === 0) return;
34
+ let e = l.current;
35
+ if (!e) return;
36
+ let t = new ResizeObserver((e) => {
37
+ for (let t of e) c(t.contentRect.width < o);
38
+ });
39
+ return t.observe(e), () => t.disconnect();
40
+ }, [o]);
41
+ let [u, d] = K(null), f = G(null), p = H(() => n.map((t) => {
42
+ let n = ye(t.width ?? t.column?.width ?? t.row?.width ?? e.width);
43
+ return n && n.kind === "weight" ? n.value : 1;
44
+ }), [n, e.width]), m = H((e, t) => {
45
+ t.preventDefault();
46
+ let n = u ?? p();
47
+ f.current = {
48
+ index: e,
49
+ startX: t.clientX,
50
+ startSizes: [...n]
51
+ };
52
+ let r = (e) => {
53
+ let t = f.current;
54
+ if (!t || !l.current) return;
55
+ let n = l.current.getBoundingClientRect().width, r = e.clientX - t.startX, i = t.startSizes.reduce((e, t) => e + t, 0), a = r / n * i, o = [...t.startSizes];
56
+ o[t.index] = Math.max(.1, t.startSizes[t.index] + a), o[t.index + 1] = Math.max(.1, t.startSizes[t.index + 1] - a), d(o);
57
+ }, i = () => {
58
+ f.current = null, document.removeEventListener("mousemove", r), document.removeEventListener("mouseup", i);
59
+ };
60
+ document.addEventListener("mousemove", r), document.addEventListener("mouseup", i);
61
+ }, [u, p]), h = u ?? p(), g = e.height ? Se(e.height) : void 0;
62
+ return /* @__PURE__ */ J("div", {
63
+ ref: l,
64
+ className: ae("flex", s && "flex-col"),
65
+ style: {
66
+ gap: r ? `${r}px` : void 0,
67
+ ...g
68
+ },
69
+ children: n.map((r, a) => /* @__PURE__ */ Y("div", {
70
+ className: ae("min-w-0 flex items-stretch", s && "w-full"),
71
+ style: s ? void 0 : xe(r.width ?? r.column?.width ?? r.row?.width ?? e.width, h[a], r.min_width, r.max_width),
72
+ children: [/* @__PURE__ */ J("div", {
73
+ className: ae("flex-1 min-w-0 flex flex-col", g && "overflow-y-auto overflow-x-hidden"),
74
+ children: /* @__PURE__ */ J($, {
75
+ node: r,
76
+ ctx: t
77
+ })
78
+ }), i && !s && a < n.length - 1 && /* @__PURE__ */ J("div", {
79
+ className: "detail-resize-handle",
80
+ onMouseDown: (e) => m(a, e)
81
+ })]
82
+ }, a))
83
+ });
84
+ }
85
+ function xe(e, t, n, r) {
86
+ let i = ye(e), a;
87
+ return a = !i || i.kind === "weight" ? `${t} 1 0%` : i.kind === "px" ? `0 0 ${i.value}px` : i.kind === "fill" ? "1 1 0%" : "0 0 auto", {
88
+ flex: a,
89
+ minWidth: n,
90
+ maxWidth: r
91
+ };
92
+ }
93
+ function Se(e) {
94
+ if (!e) return;
95
+ let t = ye(e);
96
+ if (t?.kind === "px") return {
97
+ height: `${t.value}px`,
98
+ overflow: "hidden"
99
+ };
100
+ if (typeof e == "string" && (e.includes("vh") || e.includes("calc") || e.includes("%"))) return {
101
+ height: e,
102
+ overflow: "hidden"
103
+ };
104
+ }
105
+ //#endregion
106
+ //#region src/components/detail-layout/LayoutColumn.tsx
107
+ function Ce({ config: e, ctx: t }) {
108
+ let { items: n, gap: r = 12 } = e;
109
+ return /* @__PURE__ */ J("div", {
110
+ className: "flex flex-col h-full",
111
+ style: { gap: r ? `${r}px` : void 0 },
112
+ children: n.map((e, n) => /* @__PURE__ */ J($, {
113
+ node: e,
114
+ ctx: t
115
+ }, n))
116
+ });
117
+ }
118
+ //#endregion
119
+ //#region src/components/detail-layout/blockMeta.ts
120
+ function we(e) {
121
+ return e.children ?? e.associated;
122
+ }
123
+ function X(e, t) {
124
+ let n = we(e);
125
+ if (n) {
126
+ if (e.label) return T(e.label);
127
+ let r = t.entity.children?.find((e) => e.entity === n);
128
+ if (r?.display?.name) return T(r.display.name);
129
+ let i = t.schema.entities[n];
130
+ return i && (T(i.display.name_plural) || T(i.display.name)) || n;
131
+ }
132
+ return e.section ? T(e.section.name) : "Tab";
133
+ }
134
+ function Z(e, t) {
135
+ if (e.icon) return e.icon;
136
+ let n = we(e);
137
+ if (n) {
138
+ let e = t.entity.children?.find((e) => e.entity === n);
139
+ if (e?.display?.icon) return e.display.icon;
140
+ let r = t.schema.entities[n];
141
+ if (r) return r.display.icon;
142
+ }
143
+ }
144
+ //#endregion
145
+ //#region src/components/detail-layout/LayoutTabs.tsx
146
+ function Te({ config: e, ctx: n }) {
147
+ let { items: r } = e, [i, a] = K(0), s = o(), c = n.detailTabsPresentation ?? (s.isPhone ? "sections" : "scroll");
148
+ if (r.length === 0) return null;
149
+ if (c === "sections") {
150
+ let e = r.map((e, t) => `detail-tab-section-${t}`);
151
+ return /* @__PURE__ */ Y("div", {
152
+ style: {
153
+ display: "flex",
154
+ flexDirection: "column",
155
+ gap: 10,
156
+ minWidth: 0
157
+ },
158
+ children: [r.length > 1 && /* @__PURE__ */ J("nav", {
159
+ "aria-label": "Detail sections",
160
+ style: {
161
+ display: "flex",
162
+ gap: 6,
163
+ overflowX: "auto",
164
+ padding: "0 2px 2px",
165
+ WebkitOverflowScrolling: "touch"
166
+ },
167
+ children: r.map((r, i) => {
168
+ let a = X(r, n), o = Z(r, n);
169
+ return /* @__PURE__ */ Y("button", {
170
+ type: "button",
171
+ onClick: () => document.getElementById(e[i])?.scrollIntoView({
172
+ block: "start",
173
+ behavior: "smooth"
174
+ }),
175
+ style: {
176
+ display: "inline-flex",
177
+ alignItems: "center",
178
+ gap: 6,
179
+ minHeight: 36,
180
+ maxWidth: 220,
181
+ padding: "7px 10px",
182
+ border: "1px solid var(--border)",
183
+ borderRadius: 8,
184
+ background: "var(--surface)",
185
+ color: "var(--text-2)",
186
+ fontSize: 12.5,
187
+ fontWeight: 600,
188
+ whiteSpace: "nowrap",
189
+ cursor: "pointer"
190
+ },
191
+ children: [o && /* @__PURE__ */ J(t, {
192
+ name: o,
193
+ size: 13
194
+ }), /* @__PURE__ */ J("span", {
195
+ style: {
196
+ overflow: "hidden",
197
+ textOverflow: "ellipsis"
198
+ },
199
+ children: a
200
+ })]
201
+ }, i);
202
+ })
203
+ }), r.map((r, i) => {
204
+ let a = X(r, n), o = Z(r, n);
205
+ return /* @__PURE__ */ Y("section", {
206
+ id: e[i],
207
+ style: {
208
+ background: "var(--surface)",
209
+ border: "1px solid var(--border)",
210
+ borderRadius: 10,
211
+ boxShadow: "var(--shadow-xs)",
212
+ overflow: "hidden",
213
+ minWidth: 0,
214
+ scrollMarginTop: 12
215
+ },
216
+ children: [/* @__PURE__ */ Y("div", {
217
+ style: {
218
+ display: "flex",
219
+ alignItems: "center",
220
+ gap: 8,
221
+ padding: "12px 14px",
222
+ borderBottom: "1px solid var(--divider)",
223
+ color: "var(--text)",
224
+ fontSize: 13,
225
+ fontWeight: 700
226
+ },
227
+ children: [o && /* @__PURE__ */ J(t, {
228
+ name: o,
229
+ size: 14
230
+ }), /* @__PURE__ */ J("span", {
231
+ style: { overflowWrap: "anywhere" },
232
+ children: a
233
+ })]
234
+ }), /* @__PURE__ */ J("div", {
235
+ style: {
236
+ padding: 14,
237
+ minWidth: 0
238
+ },
239
+ children: /* @__PURE__ */ J($, {
240
+ node: r,
241
+ ctx: {
242
+ ...n,
243
+ withinCard: !0
244
+ }
245
+ })
246
+ })]
247
+ }, i);
248
+ })]
249
+ });
250
+ }
251
+ return /* @__PURE__ */ Y("div", {
252
+ style: {
253
+ background: "var(--surface)",
254
+ border: "1px solid var(--border)",
255
+ borderRadius: 10,
256
+ overflow: "hidden",
257
+ boxShadow: "var(--shadow-xs)",
258
+ flexShrink: 0
259
+ },
260
+ children: [/* @__PURE__ */ J("div", {
261
+ role: "tablist",
262
+ style: {
263
+ display: "flex",
264
+ alignItems: "stretch",
265
+ gap: 4,
266
+ borderBottom: "1px solid var(--divider)",
267
+ padding: "6px 10px 0 10px",
268
+ overflowX: "auto"
269
+ },
270
+ children: r.map((e, r) => {
271
+ let o = X(e, n), s = Z(e, n), c = r === i;
272
+ return /* @__PURE__ */ Y("button", {
273
+ role: "tab",
274
+ "aria-selected": c,
275
+ onClick: (e) => {
276
+ e.stopPropagation(), a(r);
277
+ },
278
+ style: {
279
+ position: "relative",
280
+ display: "inline-flex",
281
+ alignItems: "center",
282
+ gap: 6,
283
+ padding: "8px 12px",
284
+ background: "transparent",
285
+ border: 0,
286
+ cursor: "pointer",
287
+ fontSize: 12.5,
288
+ fontWeight: 500,
289
+ fontFamily: "inherit",
290
+ color: c ? "var(--text)" : "var(--text-3)",
291
+ whiteSpace: "nowrap",
292
+ transition: "color .12s"
293
+ },
294
+ onMouseEnter: (e) => {
295
+ c || (e.currentTarget.style.color = "var(--text-2)");
296
+ },
297
+ onMouseLeave: (e) => {
298
+ c || (e.currentTarget.style.color = "var(--text-3)");
299
+ },
300
+ children: [
301
+ s && /* @__PURE__ */ J(t, {
302
+ name: s,
303
+ size: 13
304
+ }),
305
+ o,
306
+ c && /* @__PURE__ */ J("span", { style: {
307
+ position: "absolute",
308
+ left: 4,
309
+ right: 4,
310
+ bottom: -1,
311
+ height: 2,
312
+ background: "var(--accent)",
313
+ borderRadius: 2
314
+ } })
315
+ ]
316
+ }, r);
317
+ })
318
+ }), /* @__PURE__ */ J("div", {
319
+ role: "tabpanel",
320
+ style: { padding: 14 },
321
+ children: /* @__PURE__ */ J($, {
322
+ node: r[i],
323
+ ctx: {
324
+ ...n,
325
+ withinCard: !0
326
+ }
327
+ }, i)
328
+ })]
329
+ });
330
+ }
331
+ //#endregion
332
+ //#region src/components/detail-layout/SectionBlock.tsx
333
+ function Ee({ config: e, ctx: n }) {
334
+ let { name: r, items: i, collapsed: a = !1, columns: o, icon: s, badge: c, emphasis: l } = e, u = {
335
+ ...n,
336
+ withinCard: !0,
337
+ ...o ? { columns: o } : null
338
+ }, d = s ? /* @__PURE__ */ J(t, {
339
+ name: s,
340
+ size: 14
341
+ }) : void 0, f = c ? {
342
+ text: T(c.text),
343
+ tone: c.tone,
344
+ dot: c.dot
345
+ } : void 0;
346
+ return /* @__PURE__ */ J(R, {
347
+ title: T(r),
348
+ defaultOpen: !a,
349
+ icon: d,
350
+ badge: f,
351
+ emphasis: l,
352
+ headingLevel: n.withinCard ? 3 : 2,
353
+ children: /* @__PURE__ */ J(Kt, {
354
+ nodes: i,
355
+ ctx: u
356
+ })
357
+ });
358
+ }
359
+ //#endregion
360
+ //#region src/lib/child-config.ts
361
+ function De(e, t, n) {
362
+ let r = e.display, i = Q(n?.mode, r?.mode, "table"), a = i === "timeline" ? 50 : 20, o = {
363
+ entity: e.entity,
364
+ foreign_key: e.foreign_key,
365
+ name: Q(n?.label, r?.name, ke(t)),
366
+ icon: Q(n?.icon, r?.icon, t.display.icon) ?? "",
367
+ mode: i,
368
+ columns: Q(n?.columns, r?.columns, je(t, e.foreign_key)),
369
+ sort: Q(n?.sort, r?.sort, Ae(t)),
370
+ limit: Q(n?.limit, r?.limit, a),
371
+ editable: Q(n?.editable, r?.editable, !0),
372
+ interaction: Q(n?.interaction, r?.interaction, Oe(t))
373
+ }, s = Q(n?.position_field, r?.position_field, void 0);
374
+ s && (o.position_field = s, o.sort = s + ":asc");
375
+ let c = n?.timeline ?? r?.timeline;
376
+ o.mode === "timeline" ? o.timeline = Me(c ?? {}, t) : c && (o.timeline = c);
377
+ let l = n?.cards ?? r?.cards;
378
+ l && (o.cards = l);
379
+ let u = n?.quick_add ?? e.quick_add;
380
+ return u && (o.quick_add = u), o;
381
+ }
382
+ function Q(e, t, n) {
383
+ return e ?? t ?? n;
384
+ }
385
+ function Oe(e) {
386
+ return k(e, "update") ? "inline_edit" : "readonly";
387
+ }
388
+ function ke(e) {
389
+ return e.display.name_plural && Object.keys(e.display.name_plural).length > 0 ? e.display.name_plural : e.display.name;
390
+ }
391
+ function Ae(e) {
392
+ if (e.fields.get("created_at")?.type === "timestamp") return "created_at:desc";
393
+ if (e.fields.get("updated_at")?.type === "timestamp") return "updated_at:desc";
394
+ for (let t of e.fields.names()) {
395
+ let n = e.fields.get(t);
396
+ if (n && n.type === "timestamp") return t + ":desc";
397
+ }
398
+ for (let t of e.fields.names()) {
399
+ let n = e.fields.get(t);
400
+ if (n && n.type === "date") return t + ":desc";
401
+ }
402
+ let t = Re(e);
403
+ return t ? t + ":asc" : "";
404
+ }
405
+ function je(e, t) {
406
+ let n = new Set(Array.isArray(t) ? t : [t]), r = [];
407
+ for (let t of e.fields.names()) {
408
+ if (r.length >= 6) break;
409
+ let i = e.fields.get(t);
410
+ i && (i.primary || i.auto || i.display?.is_listable !== !1 && (n.has(t) || r.push(t)));
411
+ }
412
+ return r;
413
+ }
414
+ function Me(e, t) {
415
+ let n = { ...e };
416
+ return n.time_field ||= Fe(t), n.type_field ||= Ie(t, "enum"), n.summary_field ||= Le(t, "string", "text", "rich_text"), n.content_field ||= Le(t, "rich_text", "text"), n.summary_field && n.content_field && n.summary_field === n.content_field && (n.summary_field = void 0), n.author_field || t.fields.get("created_by") && (n.author_field = "created_by"), n.direction_field ||= Ne(t), n.intent_field ||= Pe(t), n;
417
+ }
418
+ function Ne(e) {
419
+ let t = e.fields.get("direction");
420
+ if (t && t.type === "enum") return "direction";
421
+ for (let t of [
422
+ "is_outbound",
423
+ "outbound",
424
+ "is_inbound",
425
+ "inbound"
426
+ ]) {
427
+ let n = e.fields.get(t);
428
+ if (n && n.type === "bool") return t;
429
+ }
430
+ }
431
+ function Pe(e) {
432
+ let t = e.fields.get("intent");
433
+ if (t && t.type === "enum") return "intent";
434
+ }
435
+ function Fe(e) {
436
+ for (let t of e.fields.names()) {
437
+ let n = e.fields.get(t);
438
+ if (n && n.type === "timestamp" && !n.auto) return t;
439
+ }
440
+ if (e.fields.get("created_at")?.type === "timestamp") return "created_at";
441
+ if (e.fields.get("updated_at")?.type === "timestamp") return "updated_at";
442
+ for (let t of e.fields.names()) {
443
+ let n = e.fields.get(t);
444
+ if (n && n.type === "timestamp") return t;
445
+ }
446
+ }
447
+ function Ie(e, t) {
448
+ for (let n of e.fields.names()) {
449
+ let r = e.fields.get(n);
450
+ if (r && r.type === t) return n;
451
+ }
452
+ }
453
+ function Le(e, ...t) {
454
+ for (let n of e.fields.names()) {
455
+ let r = e.fields.get(n);
456
+ if (r) {
457
+ for (let e of t) if (r.type === e) return n;
458
+ }
459
+ }
460
+ }
461
+ function Re(e) {
462
+ let t = h(e);
463
+ return t.length > 0 ? t[0] : void 0;
464
+ }
465
+ function ze(e, t) {
466
+ return e.children?.find((e) => e.entity === t);
467
+ }
468
+ //#endregion
469
+ //#region src/lib/quick-add.ts
470
+ function Be(e, t, n, r) {
471
+ let i = {
472
+ ...t ?? {},
473
+ ...e
474
+ };
475
+ if (Array.isArray(n)) {
476
+ let e = Array.isArray(r) ? r.map(String) : g(String(r), n.length);
477
+ if (!e || e.length !== n.length) throw Error("invalid composite parent id");
478
+ for (let t = 0; t < n.length; t++) i[n[t]] = e[t];
479
+ } else i[n] = Array.isArray(r) ? r[0] : r;
480
+ return i;
481
+ }
482
+ function Ve(e, t) {
483
+ for (let n of t) {
484
+ let t = e[n];
485
+ if (t == null || t === "") return !1;
486
+ }
487
+ return !0;
488
+ }
489
+ //#endregion
490
+ //#region src/components/detail-layout/useQuickAdd.ts
491
+ function He(e, t, n, i) {
492
+ let [o, s] = K(() => {
493
+ let t = e.quick_add, n = i.entities[e.entity], r = {};
494
+ if (t?.fields) for (let e of t.fields) t.defaults?.[e] == null ? n?.fields.get(e)?.type === "timestamp" && (r[e] = a()) : r[e] = t.defaults[e];
495
+ return r;
496
+ }), c = _e(), { mutate: l, isPending: u, error: d, reset: f } = ge({
497
+ mutationFn: (t) => r(e.entity, t),
498
+ onMutate: async (r) => {
499
+ let i = [
500
+ M,
501
+ t,
502
+ Array.isArray(n) ? O(n.map(String)) : n,
503
+ e.entity
504
+ ];
505
+ await c.cancelQueries({ queryKey: i });
506
+ let a = c.getQueriesData({ queryKey: i }), o = {
507
+ ...r,
508
+ id: `__optimistic_${crypto.randomUUID()}`,
509
+ __optimistic: !0
510
+ };
511
+ return c.setQueriesData({ queryKey: i }, (e) => {
512
+ if (!e || typeof e != "object") return e;
513
+ if ("pages" in e && Array.isArray(e.pages) && e.pages.length > 0) {
514
+ let t = e, [n, ...r] = t.pages;
515
+ return {
516
+ ...t,
517
+ pages: [{
518
+ ...n,
519
+ data: [o, ...n.data]
520
+ }, ...r]
521
+ };
522
+ }
523
+ return e;
524
+ }), { snapshots: a };
525
+ },
526
+ onError: (e, t, n) => {
527
+ if (n?.snapshots) for (let [e, t] of n.snapshots) c.setQueryData(e, t);
528
+ },
529
+ onSuccess: () => {
530
+ let t = e.quick_add, n = i.entities[e.entity], r = {};
531
+ if (t?.fields) for (let e of t.fields) t?.defaults?.[e] == null ? n?.fields.get(e)?.type === "timestamp" ? r[e] = a() : r[e] = "" : r[e] = t.defaults[e];
532
+ s(r);
533
+ },
534
+ onSettled: () => {
535
+ let r = Array.isArray(n) ? O(n.map(String)) : n;
536
+ c.invalidateQueries({ queryKey: [
537
+ M,
538
+ t,
539
+ r,
540
+ e.entity
541
+ ] });
542
+ }
543
+ }), p = e.quick_add, m = i.entities[e.entity], h = Ve(o, p?.fields.filter((e) => m?.fields.get(e)?.required) ?? []);
544
+ function g(t) {
545
+ t.preventDefault(), p && l(Be(o, p.defaults, e.foreign_key, n));
546
+ }
547
+ function _(e, t) {
548
+ d && f(), s((n) => ({
549
+ ...n,
550
+ [e]: t
551
+ }));
552
+ }
553
+ return {
554
+ values: o,
555
+ quickAdd: p,
556
+ childEntity: m,
557
+ isPending: u,
558
+ error: d,
559
+ isReady: h,
560
+ handleSubmit: g,
561
+ handleFieldChange: _
562
+ };
563
+ }
564
+ //#endregion
565
+ //#region src/components/detail-layout/QuickAddForm.tsx
566
+ function Ue({ config: t, parentEntity: n, parentId: r, schema: i }) {
567
+ let { values: a, quickAdd: s, childEntity: l, isPending: u, error: d, isReady: f, handleSubmit: p, handleFieldChange: m } = He(t, n, r, i), h = E(), g = o(), _ = pe();
568
+ return !s || s.fields.length === 0 || !l ? null : /* @__PURE__ */ Y("form", {
569
+ onSubmit: p,
570
+ style: {
571
+ display: "flex",
572
+ flexDirection: g.isPhone ? "column" : "row",
573
+ alignItems: "flex-end",
574
+ gap: 8,
575
+ padding: "8px 0",
576
+ borderBottom: "1px solid var(--divider)"
577
+ },
578
+ children: [
579
+ s.fields.map((e) => {
580
+ let n = l.fields.get(e);
581
+ if (!n) return null;
582
+ let r = `${_}-quick-add-${t.entity}-${e}`, o = `${r}-label`;
583
+ return /* @__PURE__ */ Y("div", {
584
+ style: {
585
+ flex: 1,
586
+ minWidth: 0,
587
+ width: g.isPhone ? "100%" : void 0
588
+ },
589
+ children: [/* @__PURE__ */ J("label", {
590
+ id: o,
591
+ htmlFor: r,
592
+ style: {
593
+ fontSize: 11,
594
+ color: "var(--text-3)",
595
+ marginBottom: 4,
596
+ display: "block",
597
+ fontWeight: 500
598
+ },
599
+ children: D(n, e, i.entities)
600
+ }), C({
601
+ field: n,
602
+ fieldName: e,
603
+ value: a[e] ?? "",
604
+ mode: "edit",
605
+ onChange: (t) => m(e, t),
606
+ record: a,
607
+ fieldId: r,
608
+ labelId: o,
609
+ locale: h
610
+ })]
611
+ }, e);
612
+ }),
613
+ /* @__PURE__ */ J(c, {
614
+ type: "submit",
615
+ kind: "primary",
616
+ size: g.isPhone ? "md" : "sm",
617
+ icon: /* @__PURE__ */ J(e.plus, { size: 12 }),
618
+ disabled: u || !f,
619
+ style: g.isPhone ? { alignSelf: "flex-end" } : void 0,
620
+ children: "Add"
621
+ }),
622
+ d != null && /* @__PURE__ */ J("span", {
623
+ style: {
624
+ fontSize: 11,
625
+ color: "var(--danger)",
626
+ alignSelf: "flex-end",
627
+ marginBottom: 4
628
+ },
629
+ children: d.message
630
+ })
631
+ ]
632
+ });
633
+ }
634
+ //#endregion
635
+ //#region src/components/detail-layout/ChildrenTable.tsx
636
+ function We({ config: t, parentEntity: n, parentId: r, schema: a }) {
637
+ let o = a.entities[t.entity], s = E(), c = I((e) => e.degradedEntities), { data: l, isLoading: u, isError: d, isFetching: f, refetch: m } = N(n, r, t.entity, t.foreign_key, t.sort, t.limit), h = l?.data ?? [], g = l?.$refs, _ = G(g);
638
+ _.current = g;
639
+ let v = t.columns, C = t.interaction === "navigate", w = v[0], T = C && o ? y(void 0, o, a.screens) : null, O = o ? Re(o) : void 0, k = W(() => {
640
+ let e = /* @__PURE__ */ new Map();
641
+ if (!o) return e;
642
+ for (let t of v) {
643
+ let n = o.fields.get(t);
644
+ n && e.set(t, x({
645
+ field: n,
646
+ fieldName: t,
647
+ surface: "list",
648
+ entity: o,
649
+ entities: a.entities,
650
+ screens: a.screens,
651
+ refs: () => _.current,
652
+ locale: s
653
+ }));
654
+ }
655
+ return e;
656
+ }, [
657
+ o,
658
+ v,
659
+ a.entities,
660
+ a.screens,
661
+ s
662
+ ]);
663
+ if (!o) return /* @__PURE__ */ J("div", {
664
+ style: {
665
+ fontSize: 12.5,
666
+ color: "var(--text-3)",
667
+ padding: "8px 0"
668
+ },
669
+ children: "Entity not found."
670
+ });
671
+ let A = /* @__PURE__ */ J(Ue, {
672
+ config: t,
673
+ parentEntity: n,
674
+ parentId: r,
675
+ schema: a
676
+ }), j = /* @__PURE__ */ Y("div", {
677
+ style: {
678
+ display: "flex",
679
+ alignItems: "center",
680
+ gap: 6,
681
+ padding: "4px 0",
682
+ justifyContent: "flex-end"
683
+ },
684
+ children: [F(o.realtime, c, t.entity) && /* @__PURE__ */ J("span", {
685
+ "data-testid": "children-live-indicator",
686
+ title: "This table updates automatically in realtime.",
687
+ children: /* @__PURE__ */ J(i, {
688
+ tone: "emerald",
689
+ size: "xs",
690
+ dot: !0,
691
+ children: "Live"
692
+ })
693
+ }), /* @__PURE__ */ J(p, {
694
+ icon: f ? /* @__PURE__ */ J("span", {
695
+ "data-testid": "children-refresh-spinner",
696
+ style: { display: "inline-flex" },
697
+ children: /* @__PURE__ */ J(S, { size: 13 })
698
+ }) : /* @__PURE__ */ J(e.refresh, { size: 13 }),
699
+ title: "Refresh",
700
+ size: 24,
701
+ disabled: f,
702
+ onClick: () => {
703
+ m();
704
+ }
705
+ })]
706
+ });
707
+ return d ? /* @__PURE__ */ Y("div", { children: [
708
+ A,
709
+ j,
710
+ /* @__PURE__ */ J("div", {
711
+ style: {
712
+ fontSize: 12.5,
713
+ color: "var(--danger)",
714
+ padding: "8px 0"
715
+ },
716
+ children: "Failed to load. Try again."
717
+ })
718
+ ] }) : u ? /* @__PURE__ */ Y("div", { children: [
719
+ A,
720
+ j,
721
+ /* @__PURE__ */ J("div", {
722
+ style: {
723
+ display: "flex",
724
+ flexDirection: "column",
725
+ gap: 6,
726
+ padding: "8px 0"
727
+ },
728
+ children: [
729
+ 0,
730
+ 1,
731
+ 2
732
+ ].map((e) => /* @__PURE__ */ J("div", { style: {
733
+ height: 32,
734
+ background: "var(--surface-3)",
735
+ borderRadius: 4
736
+ } }, e))
737
+ })
738
+ ] }) : h.length === 0 ? /* @__PURE__ */ Y("div", { children: [
739
+ A,
740
+ j,
741
+ /* @__PURE__ */ J("div", {
742
+ style: {
743
+ fontSize: 12.5,
744
+ color: "var(--text-3)",
745
+ padding: "12px 0"
746
+ },
747
+ children: "No records yet."
748
+ })
749
+ ] }) : /* @__PURE__ */ Y("div", { children: [
750
+ A,
751
+ j,
752
+ /* @__PURE__ */ J("div", {
753
+ style: { overflowX: "auto" },
754
+ children: /* @__PURE__ */ Y("table", {
755
+ style: se,
756
+ children: [/* @__PURE__ */ J("thead", { children: /* @__PURE__ */ J("tr", { children: v.map((e) => {
757
+ let t = o.fields.get(e);
758
+ return /* @__PURE__ */ J("th", {
759
+ style: oe,
760
+ children: t ? D(t, e, a.entities) : e
761
+ }, e);
762
+ }) }) }), /* @__PURE__ */ J("tbody", { children: h.map((e, t) => {
763
+ let n = O ? b(e[O]) : "", r = C && T && n ? T.replace(/:\w+/, n) : void 0;
764
+ return /* @__PURE__ */ J("tr", { children: v.map((t) => {
765
+ let n = t === w, i = k.get(t), a = i ? i(e[t], e) : b(e[t]);
766
+ return /* @__PURE__ */ J("td", {
767
+ title: typeof a == "string" ? a : void 0,
768
+ style: ce,
769
+ children: n && r ? /* @__PURE__ */ J("a", {
770
+ href: r,
771
+ style: {
772
+ color: "var(--accent)",
773
+ textDecoration: "none",
774
+ fontWeight: 500
775
+ },
776
+ onMouseEnter: (e) => e.currentTarget.style.textDecoration = "underline",
777
+ onMouseLeave: (e) => e.currentTarget.style.textDecoration = "none",
778
+ children: a
779
+ }) : a
780
+ }, t);
781
+ }) }, b(e.id ?? t));
782
+ }) })]
783
+ })
784
+ })
785
+ ] });
786
+ }
787
+ //#endregion
788
+ //#region src/components/detail-layout/ChildrenList.tsx
789
+ function Ge({ config: e, parentEntity: t, parentId: n, schema: r }) {
790
+ let i = r.entities[e.entity], a = E(), { data: o, isLoading: s, isError: c } = N(t, n, e.entity, e.foreign_key, e.sort, e.limit), l = o?.data ?? [], u = o?.$refs, d = e.columns;
791
+ if (!i) return /* @__PURE__ */ J("div", {
792
+ style: {
793
+ fontSize: 12.5,
794
+ color: "var(--text-3)",
795
+ padding: "8px 0"
796
+ },
797
+ children: "Entity not found."
798
+ });
799
+ let f = /* @__PURE__ */ J(Ue, {
800
+ config: e,
801
+ parentEntity: t,
802
+ parentId: n,
803
+ schema: r
804
+ });
805
+ if (c) return /* @__PURE__ */ Y("div", { children: [f, /* @__PURE__ */ J("div", {
806
+ style: {
807
+ fontSize: 12.5,
808
+ color: "var(--danger)",
809
+ padding: "8px 0"
810
+ },
811
+ children: "Failed to load. Try again."
812
+ })] });
813
+ if (s) return /* @__PURE__ */ Y("div", { children: [f, /* @__PURE__ */ Y("div", {
814
+ style: {
815
+ display: "flex",
816
+ flexDirection: "column",
817
+ gap: 6,
818
+ padding: "8px 0"
819
+ },
820
+ children: [
821
+ /* @__PURE__ */ J("div", { style: {
822
+ height: 22,
823
+ background: "var(--surface-3)",
824
+ borderRadius: 4
825
+ } }),
826
+ /* @__PURE__ */ J("div", { style: {
827
+ height: 22,
828
+ background: "var(--surface-3)",
829
+ borderRadius: 4
830
+ } }),
831
+ /* @__PURE__ */ J("div", { style: {
832
+ height: 22,
833
+ background: "var(--surface-3)",
834
+ borderRadius: 4,
835
+ width: "75%"
836
+ } })
837
+ ]
838
+ })] });
839
+ if (l.length === 0) return /* @__PURE__ */ Y("div", { children: [f, /* @__PURE__ */ J("div", {
840
+ style: {
841
+ fontSize: 12.5,
842
+ color: "var(--text-3)",
843
+ padding: "12px 0"
844
+ },
845
+ children: "No records yet."
846
+ })] });
847
+ let p = d.length > 0 ? i.display.display_field ?? d[0] : i.display.display_field;
848
+ return /* @__PURE__ */ Y("div", { children: [f, /* @__PURE__ */ J("div", {
849
+ style: {
850
+ display: "flex",
851
+ flexDirection: "column"
852
+ },
853
+ children: l.map((e, t) => /* @__PURE__ */ J("div", {
854
+ style: {
855
+ display: "flex",
856
+ alignItems: "center",
857
+ gap: 12,
858
+ padding: "8px 4px",
859
+ borderBottom: "1px solid var(--divider)"
860
+ },
861
+ children: /* @__PURE__ */ Y("div", {
862
+ style: {
863
+ flex: 1,
864
+ minWidth: 0
865
+ },
866
+ children: [/* @__PURE__ */ J("div", {
867
+ style: {
868
+ fontSize: 12.5,
869
+ overflow: "hidden",
870
+ textOverflow: "ellipsis",
871
+ whiteSpace: "nowrap"
872
+ },
873
+ children: (typeof e.$display == "string" ? e[m] : "") || (p && i.fields.get(p) ? C({
874
+ field: i.fields.get(p),
875
+ fieldName: p,
876
+ value: e[p],
877
+ mode: "display",
878
+ record: e,
879
+ refs: u,
880
+ locale: a
881
+ }) : p && e[p] != null ? b(e[p]) : null)
882
+ }), d.length > 1 && (() => {
883
+ let t = d.slice(1, 3).filter((t) => e[t] != null);
884
+ return t.length === 0 ? null : /* @__PURE__ */ J("div", {
885
+ style: {
886
+ fontSize: 11.5,
887
+ color: "var(--text-3)",
888
+ overflow: "hidden",
889
+ textOverflow: "ellipsis",
890
+ whiteSpace: "nowrap"
891
+ },
892
+ children: t.map((t, n) => /* @__PURE__ */ Y("span", { children: [n > 0 && " · ", i.fields.get(t) ? C({
893
+ field: i.fields.get(t),
894
+ fieldName: t,
895
+ value: e[t],
896
+ mode: "display",
897
+ record: e,
898
+ refs: u,
899
+ locale: a
900
+ }) : String(e[t])] }, t))
901
+ });
902
+ })()]
903
+ })
904
+ }, b(e.id ?? t)))
905
+ })] });
906
+ }
907
+ //#endregion
908
+ //#region src/components/detail-layout/ChildrenCards.tsx
909
+ function Ke({ config: e, parentEntity: t, parentId: n, schema: r }) {
910
+ let a = r.entities[e.entity], o = E(), { data: s, isLoading: c, isError: l } = N(t, n, e.entity, e.foreign_key, e.sort, e.limit), u = s?.data ?? [], d = s?.$refs, f = e.columns, p = e.cards, m = p?.header_field ?? f[0], h = p?.badge_field, g = p?.columns_count ?? 3;
911
+ if (!a) return /* @__PURE__ */ J("div", {
912
+ style: {
913
+ fontSize: 12.5,
914
+ color: "var(--text-3)",
915
+ padding: "8px 0"
916
+ },
917
+ children: "Entity not found."
918
+ });
919
+ let _ = {
920
+ display: "grid",
921
+ gridTemplateColumns: `repeat(auto-fill, minmax(${g >= 4 ? 180 : 240}px, 1fr))`,
922
+ gap: 12
923
+ }, v = /* @__PURE__ */ J(Ue, {
924
+ config: e,
925
+ parentEntity: t,
926
+ parentId: n,
927
+ schema: r
928
+ });
929
+ if (l) return /* @__PURE__ */ Y("div", { children: [v, /* @__PURE__ */ J("div", {
930
+ style: {
931
+ fontSize: 12.5,
932
+ color: "var(--danger)",
933
+ padding: "8px 0"
934
+ },
935
+ children: "Failed to load. Try again."
936
+ })] });
937
+ if (c) return /* @__PURE__ */ Y("div", { children: [v, /* @__PURE__ */ J("div", {
938
+ style: _,
939
+ children: [
940
+ 0,
941
+ 1,
942
+ 2
943
+ ].map((e) => /* @__PURE__ */ J("div", { style: {
944
+ height: 96,
945
+ background: "var(--surface-3)",
946
+ borderRadius: 10
947
+ } }, e))
948
+ })] });
949
+ if (u.length === 0) return /* @__PURE__ */ Y("div", { children: [v, /* @__PURE__ */ J("div", {
950
+ style: {
951
+ fontSize: 12.5,
952
+ color: "var(--text-3)",
953
+ padding: "12px 0"
954
+ },
955
+ children: "No records yet."
956
+ })] });
957
+ let y = f.filter((e) => e !== m && e !== h);
958
+ return /* @__PURE__ */ Y("div", { children: [v, /* @__PURE__ */ J("div", {
959
+ style: _,
960
+ children: u.map((t, n) => /* @__PURE__ */ Y("div", {
961
+ style: {
962
+ background: "var(--surface)",
963
+ border: "1px solid var(--border)",
964
+ borderRadius: 10,
965
+ overflow: "hidden"
966
+ },
967
+ children: [/* @__PURE__ */ Y("div", {
968
+ style: {
969
+ padding: "10px 14px",
970
+ display: "flex",
971
+ alignItems: "center",
972
+ justifyContent: "space-between",
973
+ gap: 8,
974
+ borderBottom: y.length > 0 ? "1px solid var(--divider)" : "none"
975
+ },
976
+ children: [/* @__PURE__ */ J("div", {
977
+ style: {
978
+ fontSize: 12.5,
979
+ fontWeight: 600,
980
+ overflow: "hidden",
981
+ textOverflow: "ellipsis",
982
+ whiteSpace: "nowrap"
983
+ },
984
+ children: m && a.fields.get(m) ? C({
985
+ field: a.fields.get(m),
986
+ fieldName: m,
987
+ value: t[m],
988
+ mode: "display",
989
+ record: t,
990
+ refs: d,
991
+ locale: o
992
+ }) : `Record ${n + 1}`
993
+ }), h && t[h] != null && /* @__PURE__ */ J(i, {
994
+ tone: "slate",
995
+ size: "xs",
996
+ children: a.fields.get(h) ? C({
997
+ field: a.fields.get(h),
998
+ fieldName: h,
999
+ value: t[h],
1000
+ mode: "display",
1001
+ record: t,
1002
+ refs: d,
1003
+ locale: o
1004
+ }) : b(t[h])
1005
+ })]
1006
+ }), y.length > 0 && /* @__PURE__ */ J("div", {
1007
+ style: {
1008
+ padding: "10px 14px",
1009
+ display: "flex",
1010
+ flexDirection: "column",
1011
+ gap: 4
1012
+ },
1013
+ children: y.slice(0, 4).map((n) => {
1014
+ let i = a.fields.get(n);
1015
+ return i ? /* @__PURE__ */ Y("div", {
1016
+ style: {
1017
+ display: "flex",
1018
+ alignItems: "baseline",
1019
+ gap: 8,
1020
+ fontSize: 11.5
1021
+ },
1022
+ children: [/* @__PURE__ */ Y("span", {
1023
+ style: {
1024
+ color: "var(--text-3)",
1025
+ flexShrink: 0
1026
+ },
1027
+ children: [r.entities[e.entity]?.fields.get(n)?.display?.name ? Object.values(r.entities[e.entity].fields.get(n).display.name)[0] : n, ":"]
1028
+ }), /* @__PURE__ */ J("span", {
1029
+ style: {
1030
+ overflow: "hidden",
1031
+ textOverflow: "ellipsis",
1032
+ whiteSpace: "nowrap"
1033
+ },
1034
+ children: C({
1035
+ field: i,
1036
+ fieldName: n,
1037
+ value: t[n],
1038
+ mode: "display",
1039
+ record: t,
1040
+ refs: d,
1041
+ locale: o
1042
+ })
1043
+ })]
1044
+ }, n) : null;
1045
+ })
1046
+ })]
1047
+ }, b(t.id ?? n)))
1048
+ })] });
1049
+ }
1050
+ //#endregion
1051
+ //#region src/hooks/useTimelineData.ts
1052
+ var qe = 50;
1053
+ function Je(e, t, n, r, i, a) {
1054
+ let o = Array.isArray(r) ? r : [r], s = Array.isArray(r) ? g(t, o.length) : [t], c = a ?? qe, l = he({
1055
+ queryKey: [
1056
+ M,
1057
+ e,
1058
+ t,
1059
+ n,
1060
+ "timeline",
1061
+ i,
1062
+ c
1063
+ ],
1064
+ queryFn: ({ pageParam: e }) => {
1065
+ let t = new URLSearchParams();
1066
+ if (!s) throw Error("invalid composite parent id");
1067
+ let r = o.map((e, t) => ({
1068
+ field: e,
1069
+ op: "eq",
1070
+ value: s[t]
1071
+ }));
1072
+ return t.set("filters", JSON.stringify(r)), t.set("preview", "true"), i ? t.set("sort", `${i}:desc`) : typeof console < "u" && console.warn(`[useTimelineData] no time_field for ${n}; fetch order falls back to API default`), t.set("limit", String(c)), e && t.set("after", e), u(`/api/data/${n}?${t.toString()}`);
1073
+ },
1074
+ getNextPageParam: (e) => e.meta?.has_more ? e.meta.cursor : void 0,
1075
+ initialPageParam: void 0,
1076
+ enabled: !!e && !!t && !!n && !!r && s !== null
1077
+ });
1078
+ return {
1079
+ rows: W(() => l.data?.pages.flatMap((e) => e.data) ?? [], [l.data?.pages]),
1080
+ refs: l.data?.pages[0]?.$refs,
1081
+ fetchNextPage: l.fetchNextPage,
1082
+ hasOlder: !!l.hasNextPage,
1083
+ isFetchingOlder: l.isFetchingNextPage,
1084
+ isLoading: l.isLoading,
1085
+ isError: l.isError
1086
+ };
1087
+ }
1088
+ //#endregion
1089
+ //#region src/components/detail-layout/TimelineComposer.tsx
1090
+ var Ye = "quick_entry", Xe = 100, Ze = 240, Qe = 800, $e = 80;
1091
+ function et({ config: t, parentEntity: n, parentId: r, schema: i }) {
1092
+ let { values: a, quickAdd: o, childEntity: s, isPending: l, error: u, isReady: d, handleSubmit: f, handleFieldChange: p } = He(t, n, r, i), m = E(), [h, g] = K(Ze), _ = G(null), y = G(null), [b, x] = K(Qe);
1093
+ U(() => {
1094
+ let e = y.current?.parentElement;
1095
+ if (!e) return;
1096
+ let t = () => {
1097
+ let t = Math.max(Xe, e.clientHeight - $e);
1098
+ x(Math.min(Qe, t));
1099
+ };
1100
+ t();
1101
+ let n = new ResizeObserver(t);
1102
+ return n.observe(e), () => n.disconnect();
1103
+ }, []), U(() => {
1104
+ g((e) => Math.min(e, b));
1105
+ }, [b]);
1106
+ let S = G(a);
1107
+ S.current = a;
1108
+ let w = G(p);
1109
+ w.current = p;
1110
+ let T = G({}), D = W(() => ({
1111
+ getField: (e) => S.current[e],
1112
+ setField: (e, t) => {
1113
+ w.current(e, t);
1114
+ },
1115
+ focusField: (e) => {
1116
+ let t = T.current[e];
1117
+ t && (t.querySelector("textarea, input, select, [contenteditable]") ?? t).focus();
1118
+ }
1119
+ }), []);
1120
+ U(() => v(Ye, D), [D]);
1121
+ let O = H((e) => {
1122
+ e.preventDefault(), _.current = {
1123
+ startY: e.clientY,
1124
+ startHeight: h
1125
+ };
1126
+ let t = (e) => {
1127
+ if (!_.current) return;
1128
+ let t = _.current.startY - e.clientY;
1129
+ g(Math.min(b, Math.max(Xe, _.current.startHeight + t)));
1130
+ }, n = () => {
1131
+ _.current = null, document.removeEventListener("mousemove", t), document.removeEventListener("mouseup", n);
1132
+ };
1133
+ document.addEventListener("mousemove", t), document.addEventListener("mouseup", n);
1134
+ }, [h, b]);
1135
+ if (!o || o.fields.length === 0 || !s) return null;
1136
+ let k = o.fields.find((e) => {
1137
+ let t = s.fields.get(e);
1138
+ return t && (t.type === "text" || t.type === "string");
1139
+ }), A = [], j = [];
1140
+ for (let e of o.fields) {
1141
+ if (e === k) continue;
1142
+ let t = s.fields.get(e);
1143
+ t && (t.type === "enum" ? A.push(e) : j.push(e));
1144
+ }
1145
+ let M = (e) => {
1146
+ let t = s.fields.get(e);
1147
+ return t ? /* @__PURE__ */ J("div", {
1148
+ ref: (t) => {
1149
+ T.current[e] = t;
1150
+ },
1151
+ children: C({
1152
+ field: t,
1153
+ fieldName: e,
1154
+ value: a[e] ?? "",
1155
+ mode: "edit",
1156
+ onChange: (t) => p(e, t),
1157
+ record: a,
1158
+ locale: m
1159
+ })
1160
+ }, e) : null;
1161
+ };
1162
+ return /* @__PURE__ */ Y("div", {
1163
+ ref: y,
1164
+ style: {
1165
+ flexShrink: 0,
1166
+ borderTop: "1px solid var(--divider)",
1167
+ background: "var(--surface)",
1168
+ display: "flex",
1169
+ flexDirection: "column",
1170
+ height: `${h}px`
1171
+ },
1172
+ children: [/* @__PURE__ */ J("div", {
1173
+ onMouseDown: O,
1174
+ title: "Drag to resize",
1175
+ style: {
1176
+ height: 12,
1177
+ cursor: "row-resize",
1178
+ display: "flex",
1179
+ alignItems: "center",
1180
+ justifyContent: "center",
1181
+ flexShrink: 0
1182
+ },
1183
+ children: /* @__PURE__ */ J("div", { style: {
1184
+ width: 56,
1185
+ height: 3,
1186
+ borderRadius: 999,
1187
+ background: "var(--border)"
1188
+ } })
1189
+ }), /* @__PURE__ */ Y("form", {
1190
+ onSubmit: f,
1191
+ onKeyDown: (e) => {
1192
+ (e.metaKey || e.ctrlKey) && e.key === "Enter" && (e.preventDefault(), e.currentTarget.requestSubmit());
1193
+ },
1194
+ style: {
1195
+ flex: 1,
1196
+ minHeight: 0,
1197
+ display: "flex",
1198
+ flexDirection: "column",
1199
+ gap: 6,
1200
+ padding: "0 12px 8px"
1201
+ },
1202
+ children: [
1203
+ A.length > 0 && /* @__PURE__ */ J("div", {
1204
+ style: {
1205
+ display: "flex",
1206
+ flexWrap: "wrap",
1207
+ alignItems: "center",
1208
+ gap: 6,
1209
+ flexShrink: 0
1210
+ },
1211
+ children: A.map(M)
1212
+ }),
1213
+ k && s.fields.get(k) && /* @__PURE__ */ J("div", {
1214
+ style: {
1215
+ flex: 1,
1216
+ minHeight: 0,
1217
+ display: "flex"
1218
+ },
1219
+ ref: (e) => {
1220
+ T.current[k] = e;
1221
+ },
1222
+ children: C({
1223
+ field: s.fields.get(k),
1224
+ fieldName: k,
1225
+ value: a[k] ?? "",
1226
+ mode: "edit",
1227
+ onChange: (e) => p(k, e),
1228
+ record: a,
1229
+ fill: !0,
1230
+ locale: m
1231
+ })
1232
+ }),
1233
+ /* @__PURE__ */ Y("div", {
1234
+ style: {
1235
+ display: "flex",
1236
+ flexWrap: "wrap",
1237
+ alignItems: "center",
1238
+ gap: 6,
1239
+ flexShrink: 0
1240
+ },
1241
+ children: [j.map(M), /* @__PURE__ */ Y("div", {
1242
+ style: {
1243
+ marginLeft: "auto",
1244
+ display: "flex",
1245
+ alignItems: "center",
1246
+ gap: 8
1247
+ },
1248
+ children: [/* @__PURE__ */ Y("span", {
1249
+ style: {
1250
+ fontSize: 10.5,
1251
+ color: "var(--text-4)"
1252
+ },
1253
+ children: [
1254
+ /* @__PURE__ */ J("span", {
1255
+ className: "mono",
1256
+ children: "⌘"
1257
+ }),
1258
+ /* @__PURE__ */ J("span", {
1259
+ className: "mono",
1260
+ children: "↵"
1261
+ }),
1262
+ " to add"
1263
+ ]
1264
+ }), /* @__PURE__ */ J(c, {
1265
+ type: "submit",
1266
+ kind: "primary",
1267
+ icon: /* @__PURE__ */ J(e.plus, { size: 13 }),
1268
+ disabled: l || !d,
1269
+ children: "Add"
1270
+ })]
1271
+ })]
1272
+ }),
1273
+ u != null && /* @__PURE__ */ J("p", {
1274
+ style: {
1275
+ fontSize: 11,
1276
+ color: "var(--danger)",
1277
+ margin: 0,
1278
+ flexShrink: 0
1279
+ },
1280
+ children: u.message
1281
+ })
1282
+ ]
1283
+ })]
1284
+ });
1285
+ }
1286
+ //#endregion
1287
+ //#region src/components/detail-layout/ChildrenTimeline.tsx
1288
+ var tt = 80, nt = 200;
1289
+ function rt(e, t) {
1290
+ if (it(t)) {
1291
+ let e = t.id;
1292
+ return e == null ? "" : b(e);
1293
+ }
1294
+ return s(w(e, t));
1295
+ }
1296
+ function it(e) {
1297
+ return e.__optimistic === !0;
1298
+ }
1299
+ function at({ config: e, parentEntity: t, parentId: n, schema: r }) {
1300
+ let i = r.entities[e.entity], { rows: a, refs: o, fetchNextPage: s, hasOlder: l, isFetchingOlder: u, isLoading: d, isError: f } = Je(t, n, e.entity, e.foreign_key, e.timeline?.time_field, e.limit), p = e.timeline, m = p?.scroll ?? !1, h = (e.sort ?? "").endsWith(":asc"), g = W(() => h ? [...a].reverse() : a, [a, h]), _ = p?.auto_scroll ?? "none", v = G(null), y = G(null), b = G(!1), x = G(0), C = G(null), w = G(null), E = G(!0), D = G(null);
1301
+ U(() => {
1302
+ b.current = !1, x.current = 0, C.current = null, w.current = null, E.current = !0, D.current = null;
1303
+ }, [n]), me(() => {
1304
+ !u || !v.current || (D.current = {
1305
+ scrollHeight: v.current.scrollHeight,
1306
+ scrollTop: v.current.scrollTop
1307
+ });
1308
+ }, [u]), me(() => {
1309
+ let e = v.current;
1310
+ if (!e || g.length === 0 || !i) {
1311
+ x.current = g.length;
1312
+ return;
1313
+ }
1314
+ let t = rt(i, g[0]), n = rt(i, g[g.length - 1]), r = !b.current, a = g.length > x.current && x.current > 0, o = a && (h && t !== C.current && n === w.current || !h && n !== w.current && t === C.current), s = a && !o;
1315
+ if (r) h && _ === "bottom" && (e.scrollTop = e.scrollHeight), b.current = !0;
1316
+ else if (o && D.current) {
1317
+ let t = D.current;
1318
+ h && (e.scrollTop = t.scrollTop + (e.scrollHeight - t.scrollHeight)), D.current = null;
1319
+ } else s && h && E.current && (e.scrollTop = e.scrollHeight);
1320
+ x.current = g.length, C.current = t, w.current = n;
1321
+ }, [
1322
+ g,
1323
+ _,
1324
+ h,
1325
+ i
1326
+ ]);
1327
+ let O = H(() => {
1328
+ let e = v.current;
1329
+ e && (E.current = e.scrollHeight - e.scrollTop - e.clientHeight < tt);
1330
+ }, []);
1331
+ U(() => {
1332
+ let e = y.current;
1333
+ if (!e || typeof IntersectionObserver > "u") return;
1334
+ let t = new IntersectionObserver((e) => {
1335
+ for (let t of e) t.isIntersecting && l && !u && s();
1336
+ }, {
1337
+ root: v.current ?? null,
1338
+ rootMargin: `${nt}px 0px 0px 0px`,
1339
+ threshold: 0
1340
+ });
1341
+ return t.observe(e), () => t.disconnect();
1342
+ }, [
1343
+ l,
1344
+ u,
1345
+ s
1346
+ ]);
1347
+ let [k, A] = K(null);
1348
+ if (!i) return /* @__PURE__ */ J("div", {
1349
+ style: {
1350
+ fontSize: 12.5,
1351
+ color: "var(--text-3)",
1352
+ padding: "8px 0"
1353
+ },
1354
+ children: "Entity not found."
1355
+ });
1356
+ let j = e.quick_add?.fields ?? [p?.content_field].filter(Boolean), M = T(i.display?.name_plural) || T(i.display?.name) || e.entity, N = l ? /* @__PURE__ */ J("div", {
1357
+ style: {
1358
+ display: "flex",
1359
+ justifyContent: "center",
1360
+ padding: "6px 0"
1361
+ },
1362
+ children: /* @__PURE__ */ J(c, {
1363
+ size: "xs",
1364
+ onClick: () => s(),
1365
+ disabled: u,
1366
+ icon: u ? /* @__PURE__ */ J(S, { size: 11 }) : void 0,
1367
+ children: u ? "Loading…" : "Load older"
1368
+ })
1369
+ }) : null, ee = /* @__PURE__ */ J("div", {
1370
+ ref: y,
1371
+ "aria-hidden": "true",
1372
+ style: { height: 1 }
1373
+ }), P;
1374
+ if (f) P = /* @__PURE__ */ J("div", {
1375
+ style: {
1376
+ fontSize: 12.5,
1377
+ color: "var(--danger)",
1378
+ padding: 12
1379
+ },
1380
+ children: "Failed to load."
1381
+ });
1382
+ else if (d) P = /* @__PURE__ */ Y("div", {
1383
+ style: {
1384
+ display: "flex",
1385
+ flexDirection: "column",
1386
+ gap: 8,
1387
+ padding: 12
1388
+ },
1389
+ children: [/* @__PURE__ */ J("div", { style: {
1390
+ height: 64,
1391
+ background: "var(--surface-3)",
1392
+ borderRadius: 8
1393
+ } }), /* @__PURE__ */ J("div", { style: {
1394
+ height: 64,
1395
+ background: "var(--surface-3)",
1396
+ borderRadius: 8
1397
+ } })]
1398
+ });
1399
+ else if (g.length === 0) P = /* @__PURE__ */ Y(q, { children: [ee, /* @__PURE__ */ J("div", {
1400
+ style: {
1401
+ fontSize: 12.5,
1402
+ color: "var(--text-3)",
1403
+ padding: 12
1404
+ },
1405
+ children: "No activity yet."
1406
+ })] });
1407
+ else {
1408
+ let a = (a, s) => {
1409
+ let c = rt(i, a) || String(s);
1410
+ return /* @__PURE__ */ J(ot, {
1411
+ row: a,
1412
+ rowId: c,
1413
+ childEntity: i,
1414
+ entityCode: e.entity,
1415
+ parentEntity: t,
1416
+ parentId: n,
1417
+ timeline: p,
1418
+ editableFields: j,
1419
+ refs: o,
1420
+ isEditing: k === c,
1421
+ onStartEdit: () => A(c),
1422
+ onCancelEdit: () => A(null),
1423
+ onSaved: () => A(null),
1424
+ schema: r,
1425
+ optimistic: it(a)
1426
+ }, c);
1427
+ }, s = p?.time_field, c;
1428
+ if (s) {
1429
+ let e = [];
1430
+ g.forEach((t, n) => {
1431
+ let r = t[s], i = st(r), a = e[e.length - 1];
1432
+ !a || a.key !== i ? e.push({
1433
+ key: i,
1434
+ label: ct(r),
1435
+ rows: [{
1436
+ row: t,
1437
+ idx: n
1438
+ }]
1439
+ }) : a.rows.push({
1440
+ row: t,
1441
+ idx: n
1442
+ });
1443
+ }), c = e.map((e) => /* @__PURE__ */ Y("div", {
1444
+ style: {
1445
+ display: "flex",
1446
+ flexDirection: "column",
1447
+ gap: 8
1448
+ },
1449
+ children: [/* @__PURE__ */ J(lt, {
1450
+ label: e.label,
1451
+ count: e.rows.length
1452
+ }), e.rows.map(({ row: e, idx: t }) => a(e, t))]
1453
+ }, `day-${e.key}`));
1454
+ } else c = g.map((e, t) => a(e, t));
1455
+ P = /* @__PURE__ */ Y(q, { children: [
1456
+ ee,
1457
+ N,
1458
+ c
1459
+ ] });
1460
+ }
1461
+ return m ? /* @__PURE__ */ Y("div", {
1462
+ style: {
1463
+ display: "flex",
1464
+ flexDirection: "column",
1465
+ height: "100%",
1466
+ borderLeft: "1px solid var(--border)",
1467
+ background: "var(--surface-2)",
1468
+ color: "var(--text)"
1469
+ },
1470
+ children: [
1471
+ /* @__PURE__ */ J("div", {
1472
+ style: {
1473
+ padding: "10px 16px",
1474
+ borderBottom: "1px solid var(--divider)",
1475
+ background: "var(--surface)"
1476
+ },
1477
+ children: /* @__PURE__ */ J("h3", {
1478
+ style: {
1479
+ margin: 0,
1480
+ fontSize: 12.5,
1481
+ fontWeight: 600
1482
+ },
1483
+ children: M
1484
+ })
1485
+ }),
1486
+ /* @__PURE__ */ J("div", {
1487
+ ref: v,
1488
+ onScroll: O,
1489
+ style: {
1490
+ flex: 1,
1491
+ overflowY: "auto",
1492
+ padding: 12,
1493
+ display: "flex",
1494
+ flexDirection: "column",
1495
+ gap: 8
1496
+ },
1497
+ children: P
1498
+ }),
1499
+ /* @__PURE__ */ J(et, {
1500
+ config: e,
1501
+ parentEntity: t,
1502
+ parentId: n,
1503
+ schema: r
1504
+ })
1505
+ ]
1506
+ }) : /* @__PURE__ */ Y("div", { children: [/* @__PURE__ */ J("div", {
1507
+ style: {
1508
+ display: "flex",
1509
+ flexDirection: "column",
1510
+ gap: 8
1511
+ },
1512
+ children: P
1513
+ }), /* @__PURE__ */ J(et, {
1514
+ config: e,
1515
+ parentEntity: t,
1516
+ parentId: n,
1517
+ schema: r
1518
+ })] });
1519
+ }
1520
+ function ot({ row: t, rowId: r, childEntity: a, entityCode: o, parentEntity: s, parentId: l, timeline: u, editableFields: m, refs: h, isEditing: g, onStartEdit: _, onCancelEdit: v, onSaved: y, schema: b, optimistic: x = !1 }) {
1521
+ let w = _e(), T = E(), [O, k] = K({}), A = H(() => {
1522
+ w.invalidateQueries({ queryKey: [
1523
+ M,
1524
+ s,
1525
+ l,
1526
+ o
1527
+ ] });
1528
+ }, [
1529
+ w,
1530
+ s,
1531
+ l,
1532
+ o
1533
+ ]), j = ge({
1534
+ mutationFn: (e) => {
1535
+ let n = t.$row_version;
1536
+ return d(o, r, typeof n == "string" && n !== "" ? {
1537
+ ...e,
1538
+ $row_version: n
1539
+ } : e);
1540
+ },
1541
+ onSuccess: () => {
1542
+ A(), n.success("Updated"), y();
1543
+ },
1544
+ onError: (e) => n.error(e.message)
1545
+ }), N = ge({
1546
+ mutationFn: () => f(o, r),
1547
+ onSuccess: () => {
1548
+ A(), n.success("Deleted");
1549
+ },
1550
+ onError: (e) => n.error(e.message)
1551
+ }), ee = H(() => {
1552
+ let e = {};
1553
+ for (let n of m) e[n] = t[n] ?? "";
1554
+ k(e), _();
1555
+ }, [
1556
+ t,
1557
+ m,
1558
+ _
1559
+ ]), P = H((e, t) => {
1560
+ k((n) => ({
1561
+ ...n,
1562
+ [e]: t
1563
+ }));
1564
+ }, []), F = u?.time_field, I = u?.type_field, L = u?.summary_field, R = u?.content_field, z = u?.author_field, B = u?.direction_field, V = u?.intent_field;
1565
+ return g ? /* @__PURE__ */ Y("div", {
1566
+ style: {
1567
+ borderRadius: 10,
1568
+ border: "1px solid var(--accent)",
1569
+ background: "var(--surface)",
1570
+ padding: 12,
1571
+ display: "flex",
1572
+ flexDirection: "column",
1573
+ gap: 8
1574
+ },
1575
+ children: [m.map((e) => {
1576
+ let t = a.fields.get(e);
1577
+ return t ? /* @__PURE__ */ Y("div", { children: [/* @__PURE__ */ J("label", {
1578
+ style: {
1579
+ fontSize: 11,
1580
+ color: "var(--text-3)",
1581
+ marginBottom: 4,
1582
+ display: "block"
1583
+ },
1584
+ children: D(t, e, b.entities)
1585
+ }), C({
1586
+ field: t,
1587
+ fieldName: e,
1588
+ value: O[e] ?? "",
1589
+ mode: "edit",
1590
+ onChange: (t) => P(e, t),
1591
+ record: O,
1592
+ locale: T
1593
+ })] }, e) : null;
1594
+ }), /* @__PURE__ */ Y("div", {
1595
+ style: {
1596
+ display: "flex",
1597
+ alignItems: "center",
1598
+ gap: 6,
1599
+ paddingTop: 4
1600
+ },
1601
+ children: [/* @__PURE__ */ J(c, {
1602
+ kind: "primary",
1603
+ size: "xs",
1604
+ icon: j.isPending ? /* @__PURE__ */ J(S, { size: 12 }) : /* @__PURE__ */ J(e.check, { size: 12 }),
1605
+ onClick: () => j.mutate(O),
1606
+ disabled: j.isPending,
1607
+ children: j.isPending ? "Saving…" : "Save"
1608
+ }), /* @__PURE__ */ J(c, {
1609
+ size: "xs",
1610
+ icon: /* @__PURE__ */ J(e.x, { size: 12 }),
1611
+ onClick: () => {
1612
+ k({}), v();
1613
+ },
1614
+ disabled: j.isPending,
1615
+ children: "Cancel"
1616
+ })]
1617
+ })]
1618
+ }) : /* @__PURE__ */ Y("div", {
1619
+ className: "group",
1620
+ "data-optimistic": x || void 0,
1621
+ style: {
1622
+ borderRadius: 10,
1623
+ border: "1px solid var(--border)",
1624
+ background: "var(--surface)",
1625
+ padding: 12,
1626
+ transition: "border-color .12s",
1627
+ opacity: x ? .6 : 1
1628
+ },
1629
+ onMouseEnter: (e) => e.currentTarget.style.borderColor = "var(--border-strong)",
1630
+ onMouseLeave: (e) => e.currentTarget.style.borderColor = "var(--border)",
1631
+ children: [
1632
+ /* @__PURE__ */ Y("div", {
1633
+ style: {
1634
+ display: "flex",
1635
+ alignItems: "center",
1636
+ gap: 6,
1637
+ flexWrap: "wrap",
1638
+ fontSize: 11.5,
1639
+ color: "var(--text-3)"
1640
+ },
1641
+ children: [
1642
+ F && t[F] != null && a.fields.get(F) && /* @__PURE__ */ J("span", {
1643
+ style: { fontWeight: 500 },
1644
+ children: C({
1645
+ field: a.fields.get(F),
1646
+ fieldName: F,
1647
+ value: t[F],
1648
+ mode: "display",
1649
+ record: t,
1650
+ refs: h,
1651
+ locale: T
1652
+ })
1653
+ }),
1654
+ I && t[I] != null && a.fields.get(I) && /* @__PURE__ */ J(i, {
1655
+ tone: "slate",
1656
+ size: "xs",
1657
+ children: C({
1658
+ field: a.fields.get(I),
1659
+ fieldName: I,
1660
+ value: t[I],
1661
+ mode: "display",
1662
+ record: t,
1663
+ refs: h,
1664
+ locale: T
1665
+ })
1666
+ }),
1667
+ B && t[B] != null && a.fields.get(B) && /* @__PURE__ */ J(ut, {
1668
+ value: t[B],
1669
+ field: a.fields.get(B)
1670
+ }),
1671
+ V && t[V] != null && a.fields.get(V) && /* @__PURE__ */ J(i, {
1672
+ tone: "slate",
1673
+ size: "xs",
1674
+ children: C({
1675
+ field: a.fields.get(V),
1676
+ fieldName: V,
1677
+ value: t[V],
1678
+ mode: "display",
1679
+ record: t,
1680
+ refs: h,
1681
+ locale: T
1682
+ })
1683
+ }),
1684
+ z && t[z] != null && a.fields.get(z) && /* @__PURE__ */ Y("span", { children: [
1685
+ "by",
1686
+ " ",
1687
+ C({
1688
+ field: a.fields.get(z),
1689
+ fieldName: z,
1690
+ value: t[z],
1691
+ mode: "display",
1692
+ record: t,
1693
+ refs: h,
1694
+ locale: T
1695
+ })
1696
+ ] }),
1697
+ !x && /* @__PURE__ */ Y("div", {
1698
+ style: {
1699
+ marginLeft: "auto",
1700
+ display: "flex",
1701
+ alignItems: "center",
1702
+ gap: 2
1703
+ },
1704
+ children: [/* @__PURE__ */ J(p, {
1705
+ size: 22,
1706
+ icon: /* @__PURE__ */ J(e.edit, { size: 11 }),
1707
+ onClick: ee,
1708
+ title: "Edit"
1709
+ }), /* @__PURE__ */ J(p, {
1710
+ size: 22,
1711
+ icon: /* @__PURE__ */ J(e.trash, { size: 11 }),
1712
+ onClick: () => N.mutate(),
1713
+ title: "Delete"
1714
+ })]
1715
+ })
1716
+ ]
1717
+ }),
1718
+ L && t[L] != null && a.fields.get(L) && /* @__PURE__ */ J("div", {
1719
+ style: {
1720
+ fontSize: 12.5,
1721
+ fontWeight: 500,
1722
+ marginTop: 6
1723
+ },
1724
+ children: C({
1725
+ field: a.fields.get(L),
1726
+ fieldName: L,
1727
+ value: t[L],
1728
+ mode: "display",
1729
+ record: t,
1730
+ refs: h,
1731
+ locale: T
1732
+ })
1733
+ }),
1734
+ R && t[R] != null && R !== L && a.fields.get(R) && /* @__PURE__ */ J("div", {
1735
+ style: {
1736
+ fontSize: 12.5,
1737
+ fontWeight: 400,
1738
+ marginTop: 6
1739
+ },
1740
+ children: C({
1741
+ field: a.fields.get(R),
1742
+ fieldName: R,
1743
+ value: t[R],
1744
+ mode: "display",
1745
+ record: t,
1746
+ refs: h,
1747
+ locale: T
1748
+ })
1749
+ })
1750
+ ]
1751
+ });
1752
+ }
1753
+ function st(e) {
1754
+ if (e == null) return "";
1755
+ let t = new Date(b(e));
1756
+ return Number.isNaN(t.getTime()) ? "" : `${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`;
1757
+ }
1758
+ function ct(e) {
1759
+ if (e == null) return "—";
1760
+ let t = new Date(b(e));
1761
+ if (Number.isNaN(t.getTime())) return "—";
1762
+ let n = /* @__PURE__ */ new Date(), r = /* @__PURE__ */ new Date();
1763
+ r.setDate(n.getDate() - 1);
1764
+ let i = (e, t) => e.toDateString() === t.toDateString();
1765
+ return i(t, n) ? "Today" : i(t, r) ? "Yesterday" : t.toLocaleDateString(void 0, {
1766
+ weekday: "short",
1767
+ month: "short",
1768
+ day: "numeric"
1769
+ });
1770
+ }
1771
+ function lt({ label: e, count: t }) {
1772
+ return /* @__PURE__ */ Y("div", {
1773
+ style: {
1774
+ position: "sticky",
1775
+ top: -4,
1776
+ zIndex: 1,
1777
+ display: "flex",
1778
+ alignItems: "center",
1779
+ gap: 8,
1780
+ padding: "4px 2px",
1781
+ background: "linear-gradient(180deg, var(--surface-2) 0%, var(--surface-2) 65%, transparent 100%)"
1782
+ },
1783
+ children: [
1784
+ /* @__PURE__ */ J("span", {
1785
+ style: {
1786
+ fontSize: 11,
1787
+ fontWeight: 600,
1788
+ color: "var(--text-3)"
1789
+ },
1790
+ children: e
1791
+ }),
1792
+ /* @__PURE__ */ J("span", { style: {
1793
+ flex: 1,
1794
+ height: 1,
1795
+ background: "var(--divider)"
1796
+ } }),
1797
+ /* @__PURE__ */ J("span", {
1798
+ className: "num",
1799
+ style: {
1800
+ fontSize: 10.5,
1801
+ color: "var(--text-4)"
1802
+ },
1803
+ children: t
1804
+ })
1805
+ ]
1806
+ });
1807
+ }
1808
+ function ut({ value: t, field: n }) {
1809
+ let r = dt(t, n);
1810
+ return r === null ? null : /* @__PURE__ */ Y("span", {
1811
+ style: {
1812
+ display: "inline-flex",
1813
+ alignItems: "center",
1814
+ gap: 3,
1815
+ padding: "1px 6px 1px 4px",
1816
+ borderRadius: 999,
1817
+ fontSize: 10.5,
1818
+ fontWeight: 600,
1819
+ background: r ? "var(--accent-soft)" : "var(--info-soft)",
1820
+ color: r ? "var(--accent)" : "var(--info)"
1821
+ },
1822
+ children: [J(r ? e.arrowUp : e.arrowDown, { size: 10 }), r ? "Out" : "In"]
1823
+ });
1824
+ }
1825
+ function dt(e, t) {
1826
+ if (t.type === "bool") return e === !0;
1827
+ if (typeof e == "string") {
1828
+ let t = e.toLowerCase();
1829
+ if (t === "outbound" || t === "out") return !0;
1830
+ if (t === "inbound" || t === "in") return !1;
1831
+ }
1832
+ return null;
1833
+ }
1834
+ //#endregion
1835
+ //#region src/components/detail-layout/EditableChildrenTable.tsx
1836
+ function ft({ config: t, childEntity: n, schema: r, rows: i, onChange: a, validationErrors: s, refs: l, forceTablePresentation: u = !1 }) {
1837
+ let d = E(), f = o(), m = G(null), h = t.columns, g = t.position_field, _ = new Set(Array.isArray(t.foreign_key) ? t.foreign_key : [t.foreign_key]), v = h.filter((e) => {
1838
+ if (_.has(e) || t.position_field && e === t.position_field) return !1;
1839
+ let r = n.fields.get(e);
1840
+ return !(!r || r.auto || r.primary || r.source);
1841
+ }), y = new Set(h.filter((e) => {
1842
+ if (t.position_field && e === t.position_field) return !0;
1843
+ let r = n.fields.get(e);
1844
+ return r && (r.auto || r.primary || r.source);
1845
+ })), x = H((e, t, n) => {
1846
+ a(i.map((r) => r._key === e ? {
1847
+ ...r,
1848
+ [t]: n,
1849
+ _dirty: !0
1850
+ } : r));
1851
+ }, [i, a]), S = H(() => {
1852
+ let e = {
1853
+ _key: crypto.randomUUID(),
1854
+ _dirty: !0
1855
+ };
1856
+ g && (e[g] = i.filter((e) => !e._deleted).reduce((e, t) => {
1857
+ let n = typeof t[g] == "number" ? t[g] : -1;
1858
+ return Math.max(e, n);
1859
+ }, -1) + 1);
1860
+ let r = t.quick_add?.defaults ?? {};
1861
+ for (let t of v) {
1862
+ let i = n.fields.get(t);
1863
+ i && (r[t] === void 0 ? i.default === void 0 ? i.type === "bool" && (e[t] = !1) : e[t] = i.default : e[t] = r[t]);
1864
+ }
1865
+ a([...i, e]);
1866
+ }, [
1867
+ i,
1868
+ a,
1869
+ v,
1870
+ n,
1871
+ t.quick_add?.defaults,
1872
+ g
1873
+ ]), w = H((e) => {
1874
+ a(i.map((t) => t._key === e ? {
1875
+ ...t,
1876
+ _deleted: !0
1877
+ } : t));
1878
+ }, [i, a]), T = H((e) => {
1879
+ a(i.map((t) => t._key === e ? {
1880
+ ...t,
1881
+ _deleted: !1
1882
+ } : t));
1883
+ }, [i, a]), O = H((e, t) => {
1884
+ if (!g) return;
1885
+ let n = i.filter((e) => !e._deleted), r = i.filter((e) => e._deleted), o = n.findIndex((t) => t._key === e), s = o + t;
1886
+ if (o < 0 || s < 0 || s >= n.length) return;
1887
+ let c = [...n], [l] = c.splice(o, 1);
1888
+ c.splice(s, 0, l), a([...c.map((e, t) => ({
1889
+ ...e,
1890
+ [g]: t,
1891
+ _dirty: e[g] === t ? e._dirty : !0
1892
+ })), ...r]);
1893
+ }, [
1894
+ i,
1895
+ a,
1896
+ g
1897
+ ]), k = H((e) => {
1898
+ let t = e.target, n = t.closest("td");
1899
+ if (!n) return;
1900
+ let r = n.closest("tr");
1901
+ if (!r) return;
1902
+ let i = r.closest("tbody");
1903
+ if (!i) return;
1904
+ let a = Array.from(r.cells).indexOf(n), o = Array.from(i.rows).indexOf(r);
1905
+ if (e.key === "Tab") {
1906
+ let t = e.shiftKey ? -1 : 1, n = Array.from(i.rows), r = o, s = a + t;
1907
+ for (; r >= 0 && r < n.length;) if (s >= 0 && s < n[r].cells.length) {
1908
+ let i = n[r].cells[s].querySelector("input, select, textarea, [tabindex]");
1909
+ if (i) {
1910
+ e.preventDefault(), i.focus();
1911
+ return;
1912
+ }
1913
+ s += t;
1914
+ } else r += t, s = t > 0 ? 0 : (n[r]?.cells.length ?? 1) - 1;
1915
+ } else if (e.key === "Enter") {
1916
+ e.preventDefault();
1917
+ let t = Array.from(i.rows);
1918
+ if (o < t.length - 1) {
1919
+ let e = t[o + 1].cells[a]?.querySelector("input, select, textarea, [tabindex]");
1920
+ e && e.focus();
1921
+ } else S(), requestAnimationFrame(() => {
1922
+ let e = i.querySelectorAll("tr"), t = e[e.length - 1];
1923
+ if (t) {
1924
+ let e = t.querySelector("input, select, textarea, [tabindex]");
1925
+ e && e.focus();
1926
+ }
1927
+ });
1928
+ } else e.key === "Escape" && t.blur?.();
1929
+ }, [S]), A = oe;
1930
+ return f.isPhone && !u ? /* @__PURE__ */ Y("div", { children: [/* @__PURE__ */ J("div", {
1931
+ style: {
1932
+ display: "flex",
1933
+ flexDirection: "column",
1934
+ gap: 10
1935
+ },
1936
+ children: i.map((t, a) => {
1937
+ let o = !!t._deleted, c = s?.[t._key], u = g ? i.filter((e) => !e._deleted) : [], f = g ? u.findIndex((e) => e._key === t._key) : -1;
1938
+ return /* @__PURE__ */ Y("div", {
1939
+ style: {
1940
+ border: "1px solid var(--border)",
1941
+ borderRadius: 8,
1942
+ background: "var(--surface)",
1943
+ opacity: o ? .58 : 1,
1944
+ overflow: "hidden"
1945
+ },
1946
+ children: [/* @__PURE__ */ Y("div", {
1947
+ style: {
1948
+ minHeight: 38,
1949
+ padding: "8px 10px",
1950
+ borderBottom: "1px solid var(--divider)",
1951
+ display: "flex",
1952
+ alignItems: "center",
1953
+ justifyContent: "space-between",
1954
+ gap: 8
1955
+ },
1956
+ children: [/* @__PURE__ */ Y("div", {
1957
+ style: {
1958
+ fontSize: 12,
1959
+ fontWeight: 600,
1960
+ color: "var(--text-2)"
1961
+ },
1962
+ children: ["Row ", a + 1]
1963
+ }), /* @__PURE__ */ Y("div", {
1964
+ style: {
1965
+ display: "flex",
1966
+ alignItems: "center",
1967
+ gap: 4
1968
+ },
1969
+ children: [g && !o && /* @__PURE__ */ Y(q, { children: [/* @__PURE__ */ J(p, {
1970
+ size: 32,
1971
+ icon: /* @__PURE__ */ J(e.up, { size: 14 }),
1972
+ onClick: () => O(t._key, -1),
1973
+ disabled: f <= 0,
1974
+ title: "Move row up"
1975
+ }), /* @__PURE__ */ J(p, {
1976
+ size: 32,
1977
+ icon: /* @__PURE__ */ J(e.down, { size: 14 }),
1978
+ onClick: () => O(t._key, 1),
1979
+ disabled: f === -1 || f >= u.length - 1,
1980
+ title: "Move row down"
1981
+ })] }), o ? /* @__PURE__ */ J(p, {
1982
+ size: 32,
1983
+ icon: /* @__PURE__ */ J(e.refresh, { size: 14 }),
1984
+ onClick: () => T(t._key),
1985
+ title: "Undo delete"
1986
+ }) : /* @__PURE__ */ J(p, {
1987
+ size: 32,
1988
+ icon: /* @__PURE__ */ J(e.trash, { size: 14 }),
1989
+ onClick: () => w(t._key),
1990
+ title: "Delete row"
1991
+ })]
1992
+ })]
1993
+ }), /* @__PURE__ */ J("div", {
1994
+ style: {
1995
+ padding: 10,
1996
+ display: "flex",
1997
+ flexDirection: "column",
1998
+ gap: 12
1999
+ },
2000
+ children: h.map((e) => {
2001
+ let i = n.fields.get(e), a = c?.includes(e), s = y.has(e), u = i ? D(i, e, r.entities) : e, f = `child-${t._key}-${e}`, p = `${f}-label`, m = {
2002
+ outline: a ? "1px solid var(--danger)" : "none",
2003
+ outlineOffset: 3,
2004
+ borderRadius: a ? 5 : 0
2005
+ }, h = {
2006
+ fontSize: 11.5,
2007
+ fontWeight: 600,
2008
+ color: "var(--text-3)"
2009
+ }, g = !o && !s && !!i;
2010
+ return /* @__PURE__ */ Y("div", {
2011
+ style: {
2012
+ display: "flex",
2013
+ flexDirection: "column",
2014
+ gap: 5,
2015
+ minWidth: 0,
2016
+ textDecoration: o ? "line-through" : "none"
2017
+ },
2018
+ title: a ? `${e} is required` : void 0,
2019
+ children: [g ? /* @__PURE__ */ J("label", {
2020
+ id: p,
2021
+ htmlFor: f,
2022
+ style: h,
2023
+ children: u
2024
+ }) : /* @__PURE__ */ J("div", {
2025
+ id: p,
2026
+ style: h,
2027
+ children: u
2028
+ }), /* @__PURE__ */ J("div", {
2029
+ style: m,
2030
+ children: o || s ? i ? C({
2031
+ field: i,
2032
+ fieldName: e,
2033
+ value: t[e],
2034
+ mode: "display",
2035
+ record: t,
2036
+ refs: l,
2037
+ fieldId: f,
2038
+ labelId: p,
2039
+ locale: d
2040
+ }) : b(t[e]) : i ? C({
2041
+ field: i,
2042
+ fieldName: e,
2043
+ value: t[e],
2044
+ mode: "edit",
2045
+ onChange: (n) => x(t._key, e, n),
2046
+ record: t,
2047
+ refs: l,
2048
+ compact: !0,
2049
+ fieldId: f,
2050
+ labelId: p,
2051
+ locale: d
2052
+ }) : b(t[e])
2053
+ })]
2054
+ }, e);
2055
+ })
2056
+ })]
2057
+ }, t._key);
2058
+ })
2059
+ }), /* @__PURE__ */ J("div", {
2060
+ style: { marginTop: 10 },
2061
+ children: /* @__PURE__ */ J(c, {
2062
+ kind: "ghost",
2063
+ size: "sm",
2064
+ icon: /* @__PURE__ */ J(e.plus, { size: 14 }),
2065
+ onClick: S,
2066
+ children: "Add row"
2067
+ })
2068
+ })] }) : /* @__PURE__ */ Y("div", { children: [/* @__PURE__ */ J("div", {
2069
+ style: { overflowX: "auto" },
2070
+ children: /* @__PURE__ */ Y("table", {
2071
+ ref: m,
2072
+ style: se,
2073
+ onKeyDown: k,
2074
+ children: [/* @__PURE__ */ J("thead", { children: /* @__PURE__ */ Y("tr", { children: [h.map((e) => {
2075
+ let t = n.fields.get(e);
2076
+ return /* @__PURE__ */ J("th", {
2077
+ style: A,
2078
+ children: t ? D(t, e, r.entities) : e
2079
+ }, e);
2080
+ }), /* @__PURE__ */ J("th", { style: {
2081
+ ...A,
2082
+ width: 40
2083
+ } })] }) }), /* @__PURE__ */ J("tbody", { children: i.map((t) => {
2084
+ let r = !!t._deleted, i = s?.[t._key];
2085
+ return /* @__PURE__ */ Y("tr", {
2086
+ style: { opacity: r ? .5 : 1 },
2087
+ children: [h.map((e) => {
2088
+ let a = n.fields.get(e), o = i?.includes(e), s = y.has(e);
2089
+ return r || s ? /* @__PURE__ */ J("td", {
2090
+ style: {
2091
+ padding: "6px 12px",
2092
+ borderBottom: "1px solid var(--divider)",
2093
+ verticalAlign: "middle",
2094
+ textDecoration: r ? "line-through" : "none",
2095
+ color: "var(--text-2)"
2096
+ },
2097
+ children: a ? C({
2098
+ field: a,
2099
+ fieldName: e,
2100
+ value: t[e],
2101
+ mode: "display",
2102
+ record: t,
2103
+ refs: l,
2104
+ locale: d
2105
+ }) : b(t[e])
2106
+ }, e) : /* @__PURE__ */ J("td", {
2107
+ style: {
2108
+ padding: "4px 4px",
2109
+ borderBottom: "1px solid var(--divider)",
2110
+ verticalAlign: "middle",
2111
+ outline: o ? "1px solid var(--danger)" : "none",
2112
+ outlineOffset: -1,
2113
+ borderRadius: o ? 4 : 0
2114
+ },
2115
+ title: o ? `${e} is required` : void 0,
2116
+ children: a ? C({
2117
+ field: a,
2118
+ fieldName: e,
2119
+ value: t[e],
2120
+ mode: "edit",
2121
+ onChange: (n) => x(t._key, e, n),
2122
+ record: t,
2123
+ refs: l,
2124
+ compact: !0,
2125
+ locale: d
2126
+ }) : b(t[e])
2127
+ }, e);
2128
+ }), /* @__PURE__ */ J("td", {
2129
+ style: {
2130
+ padding: "4px 8px",
2131
+ borderBottom: "1px solid var(--divider)",
2132
+ verticalAlign: "middle"
2133
+ },
2134
+ children: r ? /* @__PURE__ */ J(p, {
2135
+ size: 24,
2136
+ icon: /* @__PURE__ */ J(e.refresh, { size: 12 }),
2137
+ onClick: () => T(t._key),
2138
+ title: "Undo delete"
2139
+ }) : /* @__PURE__ */ J(p, {
2140
+ size: 24,
2141
+ icon: /* @__PURE__ */ J(e.trash, { size: 12 }),
2142
+ onClick: () => w(t._key),
2143
+ title: "Delete row"
2144
+ })
2145
+ })]
2146
+ }, t._key);
2147
+ }) })]
2148
+ })
2149
+ }), /* @__PURE__ */ J("div", {
2150
+ style: { marginTop: 8 },
2151
+ children: /* @__PURE__ */ J(c, {
2152
+ kind: "ghost",
2153
+ size: "xs",
2154
+ icon: /* @__PURE__ */ J(e.plus, { size: 12 }),
2155
+ onClick: S,
2156
+ children: "Add row"
2157
+ })
2158
+ })] });
2159
+ }
2160
+ //#endregion
2161
+ //#region src/components/detail-layout/ChildrenBlock.tsx
2162
+ var pt = de(() => import("./DraggableChildrenTable-DILqStHQ.js").then((e) => ({ default: e.DraggableChildrenTable })));
2163
+ function mt({ node: e, ctx: n }) {
2164
+ let r = o(), i = e.children;
2165
+ if (!i) return null;
2166
+ let a = r.isPhone && n.relatedRecordsPresentation === "table";
2167
+ if (n.isNew && n.mode !== "edit") return null;
2168
+ let s = ze(n.entity, i);
2169
+ if (!s) return /* @__PURE__ */ Y("div", {
2170
+ className: "text-sm text-muted-foreground py-2",
2171
+ children: ["Unknown child relation: ", i]
2172
+ });
2173
+ let c = n.schema.entities[s.entity];
2174
+ if (!c) return /* @__PURE__ */ Y("div", {
2175
+ className: "text-sm text-muted-foreground py-2",
2176
+ children: ["Entity not found: ", s.entity]
2177
+ });
2178
+ let l = De(s, c, e), u = X(e, n), d = Z(e, n), f = (e) => l.mode === "timeline" || n.withinCard ? e : /* @__PURE__ */ J(R, {
2179
+ title: u,
2180
+ icon: d ? /* @__PURE__ */ J(t, {
2181
+ name: d,
2182
+ size: 14
2183
+ }) : void 0,
2184
+ children: e
2185
+ });
2186
+ if (n.mode === "edit" && l.editable && l.interaction !== "navigate" && l.interaction !== "readonly" && k(c, "update") && l.mode === "table" && n.pendingChildren !== void 0 && n.onChildrenChange) {
2187
+ let e = n.pendingChildren[i] ?? [], t = n.childValidationErrors?.[i], o = l.position_field ? r.isPhone && !a ? ft : pt : ft;
2188
+ return f(/* @__PURE__ */ J(le, {
2189
+ fallback: /* @__PURE__ */ J(P, {}),
2190
+ children: /* @__PURE__ */ J(o, {
2191
+ config: l,
2192
+ childEntity: c,
2193
+ schema: n.schema,
2194
+ rows: e,
2195
+ onChange: (e) => n.onChildrenChange(i, e),
2196
+ validationErrors: t,
2197
+ refs: n.refs,
2198
+ forceTablePresentation: a
2199
+ })
2200
+ }));
2201
+ }
2202
+ if (n.isNew) return null;
2203
+ let p = {
2204
+ config: l,
2205
+ parentEntity: n.entityCode,
2206
+ parentId: n.recordId,
2207
+ schema: n.schema
2208
+ };
2209
+ switch (l.mode) {
2210
+ case "list": return f(/* @__PURE__ */ J(Ge, { ...p }));
2211
+ case "cards": return f(/* @__PURE__ */ J(Ke, { ...p }));
2212
+ case "timeline": return f(/* @__PURE__ */ J(at, { ...p }));
2213
+ default: return r.isPhone && !a ? f(/* @__PURE__ */ J(Ke, { ...p })) : f(/* @__PURE__ */ J(We, { ...p }));
2214
+ }
2215
+ }
2216
+ //#endregion
2217
+ //#region src/components/detail-layout/FieldRow.tsx
2218
+ var ht = 150, gt = 560, _t = "20px", vt = 4, yt = /* @__PURE__ */ new Set([
2219
+ "text",
2220
+ "rich_text",
2221
+ "json",
2222
+ "structure",
2223
+ "multilang_text"
2224
+ ]), bt = ue({ columns: 2 });
2225
+ function xt({ columns: e = 2, children: t }) {
2226
+ let n = G(null), [r, i] = K(!1);
2227
+ U(() => {
2228
+ let t = n.current;
2229
+ if (!t || e === 1 || typeof ResizeObserver > "u") return;
2230
+ let r = new ResizeObserver(([e]) => {
2231
+ i(e.contentRect.width < gt);
2232
+ });
2233
+ return r.observe(t), () => r.disconnect();
2234
+ }, [e]);
2235
+ let a = e === 1 || r ? 1 : e;
2236
+ return /* @__PURE__ */ J(bt.Provider, {
2237
+ value: { columns: a },
2238
+ children: /* @__PURE__ */ J("div", {
2239
+ ref: n,
2240
+ style: {
2241
+ display: "grid",
2242
+ gridTemplateColumns: `repeat(${a}, minmax(0, 1fr))`,
2243
+ columnGap: 24,
2244
+ rowGap: 2
2245
+ },
2246
+ children: t
2247
+ })
2248
+ });
2249
+ }
2250
+ function St({ label: t, children: n, span: r = !1, required: i, error: a, hint: o, actions: s, copyValue: c, mode: u = "display", htmlFor: d, labelId: f, labelTitle: p, "data-testid": m }) {
2251
+ let h = fe(bt), g = r || h.columns === 1, _ = !!a;
2252
+ return /* @__PURE__ */ Y("div", {
2253
+ className: "detail-row",
2254
+ "data-error": _ || void 0,
2255
+ "data-testid": m,
2256
+ style: {
2257
+ display: "flex",
2258
+ flexDirection: g ? "column" : "row",
2259
+ gap: g ? 4 : 16,
2260
+ alignItems: g ? "stretch" : "flex-start",
2261
+ padding: "6px 0",
2262
+ ...r ? { gridColumn: "1 / -1" } : null
2263
+ },
2264
+ children: [/* @__PURE__ */ Y("div", {
2265
+ style: {
2266
+ width: g ? "auto" : ht,
2267
+ flexShrink: 0,
2268
+ paddingTop: g ? 0 : vt,
2269
+ fontSize: 12,
2270
+ lineHeight: _t,
2271
+ fontWeight: 500,
2272
+ color: "var(--text-3)",
2273
+ display: "flex",
2274
+ alignItems: "flex-start",
2275
+ gap: 2
2276
+ },
2277
+ children: [d ? /* @__PURE__ */ J("label", {
2278
+ id: f,
2279
+ htmlFor: d,
2280
+ title: p || void 0,
2281
+ children: t
2282
+ }) : /* @__PURE__ */ J("span", {
2283
+ id: f,
2284
+ title: p || void 0,
2285
+ children: t
2286
+ }), i && u === "edit" && /* @__PURE__ */ J("span", {
2287
+ "aria-hidden": "true",
2288
+ style: {
2289
+ color: "var(--danger)",
2290
+ marginLeft: 2
2291
+ },
2292
+ children: "*"
2293
+ })]
2294
+ }), /* @__PURE__ */ Y("div", {
2295
+ style: {
2296
+ flex: 1,
2297
+ minWidth: 0,
2298
+ display: "flex",
2299
+ flexDirection: "column",
2300
+ gap: 3
2301
+ },
2302
+ children: [/* @__PURE__ */ Y("div", {
2303
+ style: {
2304
+ display: "flex",
2305
+ alignItems: "flex-start",
2306
+ gap: 6,
2307
+ minHeight: 24
2308
+ },
2309
+ children: [/* @__PURE__ */ J("div", {
2310
+ style: {
2311
+ flex: 1,
2312
+ minWidth: 0,
2313
+ fontSize: 13,
2314
+ lineHeight: _t,
2315
+ color: "var(--text)",
2316
+ overflowWrap: "anywhere",
2317
+ paddingTop: u === "display" && !g ? vt : 0
2318
+ },
2319
+ children: _ && u === "edit" ? /* @__PURE__ */ J("div", {
2320
+ style: {
2321
+ borderRadius: 6,
2322
+ boxShadow: "0 0 0 1.5px var(--danger)"
2323
+ },
2324
+ children: n
2325
+ }) : n
2326
+ }), (c || s) && /* @__PURE__ */ Y("div", {
2327
+ className: "detail-row-action",
2328
+ style: {
2329
+ display: "flex",
2330
+ gap: 2,
2331
+ flexShrink: 0,
2332
+ marginTop: -2
2333
+ },
2334
+ children: [c && /* @__PURE__ */ J(l, {
2335
+ value: c,
2336
+ size: "sm",
2337
+ title: "Copy value"
2338
+ }), s]
2339
+ })]
2340
+ }), (_ || o != null) && /* @__PURE__ */ Y("div", {
2341
+ style: {
2342
+ fontSize: 11.5,
2343
+ lineHeight: 1.4,
2344
+ color: _ ? "var(--danger)" : "var(--text-3)",
2345
+ display: "flex",
2346
+ alignItems: "center",
2347
+ gap: 4
2348
+ },
2349
+ children: [_ && /* @__PURE__ */ J(e.warning, { size: 11 }), /* @__PURE__ */ J("span", { children: _ ? a : o })]
2350
+ })]
2351
+ })]
2352
+ });
2353
+ }
2354
+ //#endregion
2355
+ //#region src/components/detail-layout/FieldsBlock.tsx
2356
+ function Ct({ fields: e, ctx: t }) {
2357
+ let { entity: n, entityCode: r, record: i, mode: a, onFieldChange: o, schema: s } = t, c = E(), l = t.columns ?? 2, u = l === 1 && e.length === 1;
2358
+ return /* @__PURE__ */ J(xt, {
2359
+ columns: l,
2360
+ children: e.map((e) => {
2361
+ let l = e.name, d = `${r ?? "field"}-${l}`, f = `${d}-label`, p = n.fields.get(l), m = !!(p?.auto || p?.readonly || p?.source), h = z(n, l), g = h?.read === "denied", _ = h?.write === "denied", v = a === "display" ? g : _ || g, y = m || a === "edit" && _ ? "display" : a, x = v ? /* @__PURE__ */ J(B, {
2362
+ tier: h.classification,
2363
+ tierDef: ie(s, n, l),
2364
+ requiredPermission: h?.required_permission,
2365
+ locale: c,
2366
+ variant: y === "edit" ? "input" : "value"
2367
+ }) : L({
2368
+ entity: n,
2369
+ entityCode: r,
2370
+ fieldName: l,
2371
+ record: i,
2372
+ mode: y,
2373
+ onChange: o && !m ? (e) => o(l, e) : void 0,
2374
+ refs: t.refs,
2375
+ entities: s?.entities,
2376
+ screens: s?.screens,
2377
+ locale: c,
2378
+ fieldId: d,
2379
+ labelId: f
2380
+ });
2381
+ if (!x) return null;
2382
+ let S = a === "display" && e.actions && e.actions.length > 0 ? /* @__PURE__ */ J(q, { children: e.actions.map((e, t) => /* @__PURE__ */ J(V, {
2383
+ actionCode: `${l}.action[${t}]`,
2384
+ action: e,
2385
+ entityCode: r,
2386
+ row: i,
2387
+ variant: "ghost",
2388
+ size: "icon"
2389
+ }, t)) }) : void 0, C = !!p && yt.has(p.type), w = i?.[l], E = y === "display" && (p?.copyable || p?.type === "uuid") && w != null && w !== "" ? b(w) : void 0, D = T(p?.display?.description);
2390
+ return u ? /* @__PURE__ */ Y("div", {
2391
+ style: { gridColumn: "1 / -1" },
2392
+ children: [x, y === "edit" && D && /* @__PURE__ */ J("div", {
2393
+ style: {
2394
+ fontSize: 11.5,
2395
+ lineHeight: 1.4,
2396
+ color: "var(--text-3)",
2397
+ marginTop: 3
2398
+ },
2399
+ children: D
2400
+ })]
2401
+ }, l) : /* @__PURE__ */ J(St, {
2402
+ label: ee(n, l, s.entities),
2403
+ htmlFor: y === "edit" ? d : void 0,
2404
+ labelId: f,
2405
+ labelTitle: D || void 0,
2406
+ required: p?.required ?? !1,
2407
+ mode: y,
2408
+ span: C,
2409
+ error: t.fieldErrors?.[l],
2410
+ hint: y === "edit" && D ? D : void 0,
2411
+ actions: S,
2412
+ copyValue: E,
2413
+ children: x
2414
+ }, l);
2415
+ })
2416
+ });
2417
+ }
2418
+ //#endregion
2419
+ //#region src/components/detail-layout/PropertiesBlock.tsx
2420
+ var wt = /* @__PURE__ */ new Set([
2421
+ "string",
2422
+ "text",
2423
+ "int",
2424
+ "float",
2425
+ "decimal",
2426
+ "email",
2427
+ "url"
2428
+ ]), Tt = 500;
2429
+ function Et({ node: e, ctx: t }) {
2430
+ let { entity: n, objectProperties: r, onSetProperty: i, isNew: a, mode: o, refs: s } = t, c = n.properties ?? {};
2431
+ if (a) return null;
2432
+ let l = e.properties === !0 ? !0 : e.properties, u = l === !0 ? Object.entries(c).sort(([e], [t]) => e.localeCompare(t)) : l.filter((e) => c[e] != null).map((e) => [e, c[e]]);
2433
+ return u.length === 0 ? null : /* @__PURE__ */ J(xt, {
2434
+ columns: 2,
2435
+ children: u.map(([e, a]) => {
2436
+ let c = r?.find((t) => t.property_code === e), l = _(a), u = a.readonly || !i ? "display" : o;
2437
+ return /* @__PURE__ */ J(Dt, {
2438
+ propCode: e,
2439
+ prop: a,
2440
+ field: l,
2441
+ value: c?.value,
2442
+ mode: u,
2443
+ onSetProperty: i,
2444
+ refs: s,
2445
+ entity: n,
2446
+ schema: t.schema
2447
+ }, e);
2448
+ })
2449
+ });
2450
+ }
2451
+ function Dt({ propCode: e, prop: t, field: n, value: r, mode: i, onSetProperty: a, refs: o, entity: s, schema: c }) {
2452
+ let l = E(), u = G(null);
2453
+ U(() => () => {
2454
+ u.current && clearTimeout(u.current);
2455
+ }, []);
2456
+ let d = H((n) => {
2457
+ a && (wt.has(t.type) ? (u.current && clearTimeout(u.current), u.current = setTimeout(() => a(e, n), Tt)) : a(e, n));
2458
+ }, [
2459
+ e,
2460
+ t.type,
2461
+ a
2462
+ ]), f = z(s, e), p = f?.read === "denied", m = f?.write === "denied", h = i === "display" ? p : m || p, g = i === "edit" && m ? "display" : i;
2463
+ return /* @__PURE__ */ J(St, {
2464
+ label: T(t.display?.name ?? t.name),
2465
+ mode: g,
2466
+ span: yt.has(t.type),
2467
+ children: h ? /* @__PURE__ */ J(B, {
2468
+ tier: f.classification,
2469
+ tierDef: ie(c, s, e),
2470
+ requiredPermission: f?.required_permission,
2471
+ locale: l,
2472
+ variant: g === "edit" ? "input" : "value"
2473
+ }) : C({
2474
+ field: n,
2475
+ fieldName: e,
2476
+ value: r,
2477
+ mode: g,
2478
+ onChange: g === "edit" ? d : void 0,
2479
+ refs: o,
2480
+ locale: l
2481
+ })
2482
+ });
2483
+ }
2484
+ //#endregion
2485
+ //#region src/components/shared/StatusStepper.tsx
2486
+ function Ot({ stages: t, current: n, selectable: r, onSelect: i, compact: a = !1 }) {
2487
+ let o = t.findIndex((e) => e.code === n);
2488
+ return /* @__PURE__ */ J("div", {
2489
+ role: "list",
2490
+ style: {
2491
+ display: "flex",
2492
+ alignItems: "stretch",
2493
+ borderRadius: 6,
2494
+ overflow: "hidden",
2495
+ border: "1px solid var(--border)",
2496
+ background: "var(--surface)"
2497
+ },
2498
+ children: t.map((n, s) => {
2499
+ let c = o >= 0 && s < o, l = s === o, u = o < 0 || s > o, d = !!i && (r?.has(n.code) ?? !1), f = s === 0, p = s === t.length - 1, m = l ? "var(--accent-soft)" : c ? "var(--success-soft)" : "transparent", h = l ? "var(--accent)" : c ? "var(--success)" : "var(--text-3)", g = f && p ? void 0 : f ? "polygon(0 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 0 100%)" : p ? "polygon(0 0, 100% 0, 100% 100%, 0 100%, 10px 50%)" : "polygon(0 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 0 100%, 10px 50%)";
2500
+ return /* @__PURE__ */ Y("button", {
2501
+ role: "listitem",
2502
+ type: "button",
2503
+ disabled: !d,
2504
+ onClick: d ? () => i(n.code) : void 0,
2505
+ title: n.label,
2506
+ style: {
2507
+ flex: 1,
2508
+ minWidth: 0,
2509
+ display: "flex",
2510
+ alignItems: "center",
2511
+ gap: 6,
2512
+ padding: a ? `6px 8px 6px ${f ? 10 : 20}px` : `8px 10px 8px ${f ? 12 : 24}px`,
2513
+ border: 0,
2514
+ borderLeft: s > 0 ? "1px solid var(--divider)" : "none",
2515
+ background: m,
2516
+ color: h,
2517
+ fontSize: a ? 11.5 : 12.5,
2518
+ fontFamily: "inherit",
2519
+ fontWeight: l ? 600 : 500,
2520
+ cursor: d ? "pointer" : "default",
2521
+ clipPath: g,
2522
+ whiteSpace: "nowrap"
2523
+ },
2524
+ children: [/* @__PURE__ */ J("span", {
2525
+ style: {
2526
+ width: 16,
2527
+ height: 16,
2528
+ borderRadius: 999,
2529
+ flexShrink: 0,
2530
+ background: u ? "transparent" : h,
2531
+ border: u ? "1px solid var(--border-strong)" : "none",
2532
+ color: u ? "var(--text-4)" : l ? "var(--accent-soft)" : "var(--success-soft)",
2533
+ display: "flex",
2534
+ alignItems: "center",
2535
+ justifyContent: "center",
2536
+ fontSize: 9.5,
2537
+ fontWeight: 700
2538
+ },
2539
+ children: c ? /* @__PURE__ */ J(e.check, { size: 10 }) : s + 1
2540
+ }), /* @__PURE__ */ J("span", {
2541
+ style: {
2542
+ overflow: "hidden",
2543
+ textOverflow: "ellipsis"
2544
+ },
2545
+ children: n.label
2546
+ })]
2547
+ }, n.code);
2548
+ })
2549
+ });
2550
+ }
2551
+ //#endregion
2552
+ //#region src/components/shared/StatusGroupsDisplay.tsx
2553
+ function kt({ statusGroups: e, objectStatuses: t, onSetStatus: n, isPending: r, mode: a = "edit" }) {
2554
+ return /* @__PURE__ */ J("div", {
2555
+ style: {
2556
+ display: "flex",
2557
+ flexWrap: "wrap",
2558
+ alignItems: "center",
2559
+ gap: 16
2560
+ },
2561
+ children: Object.entries(e).map(([e, o]) => {
2562
+ let s = t?.find((t) => t.group_code === e)?.status_code, c = s ? o.statuses.find((e) => e.code === s) : void 0;
2563
+ if (o.display_mode === "stepper") {
2564
+ let t = a === "edit", i = t ? o.transitions && s ? /* @__PURE__ */ new Set([s, ...o.transitions[s] ?? []]) : new Set(o.statuses.map((e) => e.code)) : void 0;
2565
+ return /* @__PURE__ */ Y("div", {
2566
+ style: {
2567
+ display: "flex",
2568
+ alignItems: "center",
2569
+ gap: 8,
2570
+ minWidth: 0
2571
+ },
2572
+ children: [/* @__PURE__ */ Y("span", {
2573
+ style: {
2574
+ fontSize: 12,
2575
+ color: "var(--text-3)",
2576
+ flexShrink: 0
2577
+ },
2578
+ children: [T(o.name), ":"]
2579
+ }), /* @__PURE__ */ J("div", {
2580
+ style: {
2581
+ minWidth: 240,
2582
+ opacity: r ? .6 : 1,
2583
+ pointerEvents: r ? "none" : "auto"
2584
+ },
2585
+ children: /* @__PURE__ */ J(Ot, {
2586
+ stages: o.statuses.map((e) => ({
2587
+ code: e.code,
2588
+ label: T(e.name)
2589
+ })),
2590
+ current: s,
2591
+ selectable: i,
2592
+ onSelect: t ? (t) => n(e, t) : void 0,
2593
+ compact: !0
2594
+ })
2595
+ })]
2596
+ }, e);
2597
+ }
2598
+ if (a === "display") return /* @__PURE__ */ Y("div", {
2599
+ style: {
2600
+ display: "flex",
2601
+ alignItems: "center",
2602
+ gap: 8
2603
+ },
2604
+ children: [/* @__PURE__ */ Y("span", {
2605
+ style: {
2606
+ fontSize: 12,
2607
+ color: "var(--text-3)"
2608
+ },
2609
+ children: [T(o.name), ":"]
2610
+ }), c ? /* @__PURE__ */ J(i, {
2611
+ tone: c.color ?? "slate",
2612
+ size: "xs",
2613
+ children: T(c.name)
2614
+ }) : /* @__PURE__ */ J("span", {
2615
+ style: {
2616
+ fontSize: 12.5,
2617
+ color: "var(--text-4)"
2618
+ },
2619
+ children: "—"
2620
+ })]
2621
+ }, e);
2622
+ let l = (o.transitions && s ? o.statuses.filter((e) => e.code === s || (o.transitions[s]?.includes(e.code) ?? !1)) : o.statuses).map((e) => ({
2623
+ value: e.code,
2624
+ label: /* @__PURE__ */ Y("span", {
2625
+ style: {
2626
+ display: "inline-flex",
2627
+ alignItems: "center",
2628
+ gap: 6
2629
+ },
2630
+ children: [e.color && /* @__PURE__ */ J("span", { style: {
2631
+ width: 8,
2632
+ height: 8,
2633
+ borderRadius: 999,
2634
+ background: `var(--pill-${e.color}, ${e.color})`,
2635
+ display: "inline-block"
2636
+ } }), T(e.name)]
2637
+ })
2638
+ }));
2639
+ return /* @__PURE__ */ Y("div", {
2640
+ style: {
2641
+ display: "flex",
2642
+ alignItems: "center",
2643
+ gap: 8
2644
+ },
2645
+ children: [/* @__PURE__ */ Y("span", {
2646
+ style: {
2647
+ fontSize: 12,
2648
+ color: "var(--text-3)"
2649
+ },
2650
+ children: [T(o.name), ":"]
2651
+ }), /* @__PURE__ */ J("div", {
2652
+ style: {
2653
+ minWidth: 180,
2654
+ opacity: r ? .6 : 1,
2655
+ pointerEvents: r ? "none" : "auto"
2656
+ },
2657
+ children: /* @__PURE__ */ J(A, {
2658
+ value: s ?? "",
2659
+ options: l,
2660
+ onChange: (t) => n(e, t),
2661
+ placeholder: "Select…"
2662
+ })
2663
+ })]
2664
+ }, e);
2665
+ })
2666
+ });
2667
+ }
2668
+ //#endregion
2669
+ //#region src/components/detail-layout/StatusesBlock.tsx
2670
+ var At = () => {};
2671
+ function jt({ node: e, ctx: t }) {
2672
+ let { entity: n, objectStatuses: r, onSetStatus: i, isStatusPending: a, isNew: o } = t, s = n.status_groups ?? {};
2673
+ if (o) return null;
2674
+ let c = e.statuses === !0 ? !0 : e.statuses, l = Object.fromEntries(Object.entries(s).filter(([e]) => c === !0 || c.includes(e)));
2675
+ return Object.keys(l).length === 0 ? null : /* @__PURE__ */ J(kt, {
2676
+ statusGroups: l,
2677
+ objectStatuses: r,
2678
+ onSetStatus: i ?? At,
2679
+ isPending: a ?? !1,
2680
+ mode: t.mode
2681
+ });
2682
+ }
2683
+ //#endregion
2684
+ //#region src/components/detail-layout/widgets/canonicalizeJson.ts
2685
+ function Mt(e) {
2686
+ if (Array.isArray(e)) return e.map(Mt);
2687
+ if (typeof e == "object" && e) {
2688
+ let t = e, n = {};
2689
+ for (let e of Object.keys(t).sort()) n[e] = Mt(t[e]);
2690
+ return n;
2691
+ }
2692
+ return e;
2693
+ }
2694
+ function Nt(e) {
2695
+ switch (typeof e) {
2696
+ case "string": return e;
2697
+ case "number":
2698
+ case "boolean":
2699
+ case "bigint":
2700
+ case "symbol": return String(e);
2701
+ case "function": return "[function]";
2702
+ case "object": return "[unserializable]";
2703
+ default: return "";
2704
+ }
2705
+ }
2706
+ function Pt(e) {
2707
+ if (e == null) return "";
2708
+ try {
2709
+ return JSON.stringify(Mt(e), null, 2) ?? Nt(e);
2710
+ } catch {
2711
+ return Nt(e);
2712
+ }
2713
+ }
2714
+ //#endregion
2715
+ //#region src/components/detail-layout/widgets/JsonDiffWidget.tsx
2716
+ var Ft = "Audit change diff", It = de(() => import("./MonacoJson-DVjwsaBK.js").then((e) => ({ default: e.MonacoJsonDiff }))), Lt = de(() => import("./MonacoJson-DVjwsaBK.js").then((e) => ({ default: e.MonacoJsonSource }))), Rt = de(() => import("./JsonEditor-KelPV-OQ.js").then((e) => ({ default: e.JsonEditor })));
2717
+ function zt() {
2718
+ return /* @__PURE__ */ J("div", {
2719
+ className: "flex h-full w-full items-center justify-center text-sm text-muted-foreground",
2720
+ children: "Loading editor…"
2721
+ });
2722
+ }
2723
+ function Bt({ before: e, after: t }) {
2724
+ return /* @__PURE__ */ J(le, {
2725
+ fallback: /* @__PURE__ */ J(zt, {}),
2726
+ children: /* @__PURE__ */ Y("div", {
2727
+ className: "flex h-full w-full gap-2",
2728
+ role: "group",
2729
+ "aria-label": Ft,
2730
+ children: [/* @__PURE__ */ J("div", {
2731
+ className: "min-w-0 flex-1",
2732
+ children: /* @__PURE__ */ J(Rt, {
2733
+ value: e,
2734
+ readOnly: !0
2735
+ })
2736
+ }), /* @__PURE__ */ J("div", {
2737
+ className: "min-w-0 flex-1",
2738
+ children: /* @__PURE__ */ J(Rt, {
2739
+ value: t,
2740
+ readOnly: !0
2741
+ })
2742
+ })]
2743
+ })
2744
+ });
2745
+ }
2746
+ function Vt({ mode: e, onChange: t }) {
2747
+ return /* @__PURE__ */ Y("div", {
2748
+ className: "inline-flex gap-1",
2749
+ role: "group",
2750
+ "aria-label": "Diff view mode",
2751
+ children: [/* @__PURE__ */ J("button", {
2752
+ type: "button",
2753
+ "aria-pressed": e === "diff",
2754
+ onClick: () => t("diff"),
2755
+ className: `rounded px-2 py-0.5 text-xs ${e === "diff" ? "bg-accent text-accent-foreground" : "text-muted-foreground"}`,
2756
+ children: "Diff"
2757
+ }), /* @__PURE__ */ J("button", {
2758
+ type: "button",
2759
+ "aria-pressed": e === "source",
2760
+ onClick: () => t("source"),
2761
+ className: `rounded px-2 py-0.5 text-xs ${e === "source" ? "bg-accent text-accent-foreground" : "text-muted-foreground"}`,
2762
+ children: "Source"
2763
+ })]
2764
+ });
2765
+ }
2766
+ function Ht({ values: e, options: t }) {
2767
+ let n = e.before, r = e.after, [i, a] = K(t?.default_mode === "source" ? "source" : "diff"), o = Pt(n), s = Pt(r);
2768
+ return /* @__PURE__ */ Y("div", {
2769
+ className: "flex flex-col gap-2",
2770
+ children: [/* @__PURE__ */ Y("div", {
2771
+ className: "flex items-center justify-between",
2772
+ children: [/* @__PURE__ */ J(Vt, {
2773
+ mode: i,
2774
+ onChange: a
2775
+ }), o === s && /* @__PURE__ */ J("span", {
2776
+ className: "text-xs text-muted-foreground",
2777
+ role: "status",
2778
+ children: "No field changes"
2779
+ })]
2780
+ }), /* @__PURE__ */ J("div", {
2781
+ className: "h-[480px] w-full overflow-hidden rounded border",
2782
+ role: "group",
2783
+ "aria-label": Ft,
2784
+ children: /* @__PURE__ */ J(te, {
2785
+ fallback: /* @__PURE__ */ J(Bt, {
2786
+ before: n,
2787
+ after: r
2788
+ }),
2789
+ children: /* @__PURE__ */ J(le, {
2790
+ fallback: /* @__PURE__ */ J(zt, {}),
2791
+ children: i === "diff" ? /* @__PURE__ */ J(It, {
2792
+ before: o,
2793
+ after: s
2794
+ }) : /* @__PURE__ */ Y("div", {
2795
+ className: "flex h-full w-full gap-2",
2796
+ children: [/* @__PURE__ */ J("div", {
2797
+ className: "min-w-0 flex-1",
2798
+ children: /* @__PURE__ */ J(Lt, { value: o })
2799
+ }), /* @__PURE__ */ J("div", {
2800
+ className: "min-w-0 flex-1",
2801
+ children: /* @__PURE__ */ J(Lt, { value: s })
2802
+ })]
2803
+ })
2804
+ })
2805
+ })
2806
+ })]
2807
+ });
2808
+ }
2809
+ //#endregion
2810
+ //#region src/components/detail-layout/widgets/builtins.ts
2811
+ var Ut = !1;
2812
+ function Wt() {
2813
+ Ut ||= (ne("json_diff", Ht), !0);
2814
+ }
2815
+ //#endregion
2816
+ //#region src/components/detail-layout/widgets/WidgetHost.tsx
2817
+ Wt();
2818
+ function Gt({ config: e, ctx: t }) {
2819
+ let n = re(e.type);
2820
+ if (!n) return /* @__PURE__ */ J("span", {
2821
+ className: "text-sm text-muted-foreground",
2822
+ children: `unknown widget: ${e.type}`
2823
+ });
2824
+ let r = e.inputs ?? {}, i = t.record, a = {};
2825
+ for (let [e, t] of Object.entries(r)) a[e] = i[t];
2826
+ return /* @__PURE__ */ J("div", {
2827
+ style: {
2828
+ minWidth: 0,
2829
+ maxWidth: "100%",
2830
+ overflowX: "auto",
2831
+ WebkitOverflowScrolling: "touch"
2832
+ },
2833
+ children: /* @__PURE__ */ J(n, {
2834
+ inputs: r,
2835
+ values: a,
2836
+ record: i,
2837
+ options: e.options,
2838
+ ctx: t
2839
+ })
2840
+ });
2841
+ }
2842
+ //#endregion
2843
+ //#region src/components/detail-layout/LayoutRenderer.tsx
2844
+ function Kt({ nodes: e, ctx: t }) {
2845
+ return /* @__PURE__ */ J(q, { children: e.map((e, n) => /* @__PURE__ */ J($, {
2846
+ node: e,
2847
+ ctx: t
2848
+ }, n)) });
2849
+ }
2850
+ function $({ node: e, ctx: t }) {
2851
+ return e.row ? /* @__PURE__ */ J(be, {
2852
+ config: e.row,
2853
+ ctx: t
2854
+ }) : e.column ? /* @__PURE__ */ J(Ce, {
2855
+ config: e.column,
2856
+ node: e,
2857
+ ctx: t
2858
+ }) : e.tabs ? /* @__PURE__ */ J(Te, {
2859
+ config: e.tabs,
2860
+ ctx: t
2861
+ }) : e.section ? /* @__PURE__ */ J(Ee, {
2862
+ config: e.section,
2863
+ ctx: t
2864
+ }) : e.children ? /* @__PURE__ */ J(mt, {
2865
+ node: e,
2866
+ ctx: t
2867
+ }) : e.associated ? /* @__PURE__ */ J(j, {
2868
+ node: e,
2869
+ ctx: t
2870
+ }) : e.fields ? /* @__PURE__ */ J(Ct, {
2871
+ fields: e.fields,
2872
+ ctx: t
2873
+ }) : e.properties == null ? e.statuses == null ? e.widget ? /* @__PURE__ */ J(Gt, {
2874
+ config: e.widget,
2875
+ ctx: t
2876
+ }) : null : /* @__PURE__ */ J(jt, {
2877
+ node: e,
2878
+ ctx: t
2879
+ }) : /* @__PURE__ */ J(Et, {
2880
+ node: e,
2881
+ ctx: t
2882
+ });
2883
+ }
2884
+ //#endregion
2885
+ export { kt as n, Kt as t };