@declarion/react 0.39.0 → 0.40.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.
@@ -1,1827 +0,0 @@
1
- import { s as e, t } from "./DynamicIcon-DeRpAaXm.js";
2
- import { $ as n, B as r, Gn as i, I as a, Kn as o, L as s, Nn as c, S as l, W as u, Wn as d, Xt as f, Z as p, _t as m, an as h, b as g, bn as _, cn as v, fn as y, g as b, gt as ee, h as te, i as x, ln as ne, lt as S, mn as C, nt as w, on as re, ot as T, sn as ie, un as E, ut as D, v as O, z as k, zn as ae } from "./useCurrentScreen-BA2lb-d7.js";
3
- import { E as oe, L as se, R as ce, V as le, _ as A, b as ue, c as de, d as fe, f as j, m as M, n as N, o as pe, r as P, t as me, w as he } from "./RefreshControl--UAgflh7.js";
4
- import { D as ge, G as _e, J as ve, K as ye, O as be, Ot as xe, P as Se, V as Ce, W as we, Y as Te, _ as Ee, _t as De, a as Oe, at as ke, ct as Ae, i as je, it as Me, nt as Ne, ot as Pe, q as Fe, rt as Ie, s as Le, st as Re, vt as ze, w as Be, wt as Ve, z as He } from "./registry-DXNFRlbB.js";
5
- import { n as Ue, r as We, t as Ge } from "./dataTableStyles-vwD1mVOP.js";
6
- import { n as Ke, t as qe } from "./LayoutRenderer-CwMERoPJ.js";
7
- import { Fragment as Je, useCallback as F, useEffect as Ye, useMemo as I, useRef as Xe, useState as L } from "react";
8
- import { useLocation as Ze, useParams as Qe, useSearchParams as $e } from "react-router-dom";
9
- import { useQuery as et, useQueryClient as tt } from "@tanstack/react-query";
10
- import { Fragment as nt, jsx as R, jsxs as z } from "react/jsx-runtime";
11
- //#region src/components/shared/AssociationTabs.tsx
12
- function rt({ entityCode: e, recordId: n, associations: r, schema: i }) {
13
- let a = I(() => Object.entries(r), [r]), [o, s] = L(0);
14
- if (a.length === 0) return null;
15
- let [c, l] = a[o];
16
- return /* @__PURE__ */ R(xe, {
17
- title: /* @__PURE__ */ R("div", {
18
- style: {
19
- display: "flex",
20
- alignItems: "center",
21
- gap: 4,
22
- borderBottom: "1px solid var(--divider)",
23
- margin: "-10px -14px 0 -14px",
24
- padding: "0 14px"
25
- },
26
- children: a.map(([e, n], r) => {
27
- let i = r === o;
28
- return /* @__PURE__ */ z("button", {
29
- onClick: (e) => {
30
- e.stopPropagation(), s(r);
31
- },
32
- style: {
33
- display: "inline-flex",
34
- alignItems: "center",
35
- gap: 6,
36
- padding: "10px 12px",
37
- fontSize: 12.5,
38
- background: "transparent",
39
- border: 0,
40
- borderBottom: `2px solid ${i ? "var(--accent)" : "transparent"}`,
41
- marginBottom: -1,
42
- color: i ? "var(--text)" : "var(--text-3)",
43
- cursor: "pointer",
44
- fontWeight: i ? 600 : 500
45
- },
46
- children: [n.display?.icon && /* @__PURE__ */ R(t, {
47
- name: n.display.icon,
48
- size: 13
49
- }), E(n.display?.name) || e]
50
- }, e);
51
- })
52
- }),
53
- collapsible: !1,
54
- padding: "0",
55
- children: /* @__PURE__ */ R(it, {
56
- entityCode: e,
57
- recordId: n,
58
- assocKey: c,
59
- association: l,
60
- schema: i
61
- })
62
- });
63
- }
64
- function it({ entityCode: t, recordId: n, assocKey: r, association: i, schema: a }) {
65
- let s = De(), c = te(), l = `${t}.${r}`, { data: u, isLoading: d } = et({
66
- queryKey: [
67
- "association",
68
- l,
69
- n
70
- ],
71
- queryFn: () => D(l, [n])
72
- }), f = u?.target_entity ?? i.target, p = a.entities[f], m = I(() => u?.ids ?? [], [u?.ids]), h = I(() => p?.fields.names().find((e) => p.fields.get(e)?.primary) ?? "id", [p]), g = I(() => m.slice(0, 50), [m]), { data: _, isLoading: v } = et({
73
- queryKey: [
74
- "association-records",
75
- f,
76
- g
77
- ],
78
- queryFn: () => S(f, {
79
- per_page: 50,
80
- filters: [{
81
- field: h,
82
- op: "in",
83
- value: g
84
- }]
85
- }),
86
- enabled: g.length > 0 && !!p
87
- }), y = _?.data ?? [], ee = _?.$refs, x = I(() => p ? p.fields.names().filter((e) => {
88
- let t = p.fields.get(e);
89
- return t && !t.primary && !t.auto && t.display?.is_listable !== !1;
90
- }).slice(0, 6) : [], [p]), ne = () => {
91
- let e = He(a, f);
92
- if (!e) return;
93
- let t = E(i.display?.name) || r, n = new URLSearchParams();
94
- n.set("filters", JSON.stringify([{
95
- field: h,
96
- op: "in",
97
- value: m
98
- }])), s(e.route, {
99
- title: t,
100
- icon: i.display?.icon || e.icon,
101
- search: n.toString()
102
- });
103
- }, C = {
104
- fontSize: 12.5,
105
- color: "var(--text-3)",
106
- padding: "14px 16px"
107
- };
108
- if (d || v) return /* @__PURE__ */ R("div", {
109
- style: C,
110
- children: "Loading…"
111
- });
112
- if (!p) return /* @__PURE__ */ R("div", {
113
- style: C,
114
- children: "Entity not found."
115
- });
116
- if (m.length === 0) return /* @__PURE__ */ R("div", {
117
- style: C,
118
- children: "No related records."
119
- });
120
- let w = He(a, f);
121
- return /* @__PURE__ */ z("div", {
122
- style: { padding: "8px 0" },
123
- children: [
124
- /* @__PURE__ */ z("table", {
125
- style: We,
126
- children: [/* @__PURE__ */ R("thead", { children: /* @__PURE__ */ R("tr", { children: x.map((e) => /* @__PURE__ */ R("th", {
127
- style: Ue,
128
- children: ie(p.fields.get(e), e, a.entities)
129
- }, e)) }) }), /* @__PURE__ */ R("tbody", { children: y.map((e, t) => /* @__PURE__ */ R("tr", { children: x.map((t) => {
130
- let n = p.fields.get(t);
131
- return n ? /* @__PURE__ */ R("td", {
132
- style: Ge,
133
- children: b({
134
- field: n,
135
- fieldName: t,
136
- value: e[t],
137
- mode: "display",
138
- record: e,
139
- refs: ee,
140
- locale: c
141
- })
142
- }, t) : /* @__PURE__ */ R("td", {}, t);
143
- }) }, t)) })]
144
- }),
145
- w && u && u.count > y.length && /* @__PURE__ */ R("div", {
146
- style: {
147
- padding: "10px 16px",
148
- textAlign: "center"
149
- },
150
- children: /* @__PURE__ */ z(o, {
151
- icon: /* @__PURE__ */ R(e.external, { size: 12 }),
152
- onClick: ne,
153
- children: [
154
- "View all ",
155
- u.count,
156
- " records"
157
- ]
158
- })
159
- }),
160
- w && y.length > 0 && u && u.count <= y.length && /* @__PURE__ */ R("div", {
161
- style: {
162
- padding: "10px 16px",
163
- textAlign: "center"
164
- },
165
- children: /* @__PURE__ */ R(o, {
166
- kind: "ghost",
167
- icon: /* @__PURE__ */ R(e.external, { size: 12 }),
168
- onClick: ne,
169
- children: "Open in list view"
170
- })
171
- })
172
- ]
173
- });
174
- }
175
- //#endregion
176
- //#region src/components/pages/RecordDocumentsPanel.tsx
177
- var B = 4e3;
178
- function at(e) {
179
- return e?.some((e) => e.status === "pending") ? B : !1;
180
- }
181
- function ot({ entityCode: t, objectId: n, canGenerateOne: r, canManageTemplates: i }) {
182
- let { data: a, isLoading: o, error: s } = et({
183
- queryKey: [
184
- A,
185
- t,
186
- n
187
- ],
188
- queryFn: async () => (await T("document.object_links", {
189
- entity: t,
190
- object_id: n
191
- })).result?.documents ?? [],
192
- enabled: !!(t && n) && (!!r || !!i),
193
- refetchInterval: (e) => at(e.state.data)
194
- }), c = (a?.length ?? 0) > 0;
195
- return !r && !c ? null : /* @__PURE__ */ z(xe, {
196
- title: /* @__PURE__ */ R(V, {}),
197
- collapsible: !1,
198
- padding: "0",
199
- children: [
200
- o && /* @__PURE__ */ R(H, {
201
- icon: /* @__PURE__ */ R(e.loader, { size: 14 }),
202
- text: "Loading documents..."
203
- }),
204
- s && /* @__PURE__ */ R(H, {
205
- icon: /* @__PURE__ */ R(e.warning, { size: 14 }),
206
- text: s instanceof Error ? s.message : String(s)
207
- }),
208
- !o && !s && (a?.length ?? 0) === 0 && /* @__PURE__ */ R(H, {
209
- icon: /* @__PURE__ */ R(e.file, { size: 14 }),
210
- text: "No generated documents"
211
- }),
212
- !o && !s && a && a.length > 0 && /* @__PURE__ */ R("div", {
213
- style: {
214
- display: "flex",
215
- flexDirection: "column"
216
- },
217
- children: a.map((e) => /* @__PURE__ */ R(st, {
218
- entityCode: t,
219
- objectId: n,
220
- doc: e
221
- }, e.generated_document_id))
222
- })
223
- ]
224
- });
225
- }
226
- function V() {
227
- return /* @__PURE__ */ z("div", {
228
- style: {
229
- display: "flex",
230
- alignItems: "center",
231
- gap: 6,
232
- margin: "-10px -14px 0 -14px",
233
- padding: "10px 14px",
234
- fontSize: 12.5,
235
- fontWeight: 600,
236
- color: "var(--text)"
237
- },
238
- children: [/* @__PURE__ */ R(e.file, { size: 13 }), "Documents"]
239
- });
240
- }
241
- function st({ entityCode: t, objectId: n, doc: i }) {
242
- let a = tt(), [s, c] = L(!1), [l, u] = L(!1), [d, f] = L(!1), [p, m] = L(!1), [h, g] = L(null), _ = E(i.title) || i.filename || i.template_code, v = i.status === "ready" && i.download_url && !p;
243
- async function y() {
244
- c(!0), g(null);
245
- try {
246
- let e = (await T("document.download_format", {
247
- generated_document_id: i.generated_document_id,
248
- format: "pdf"
249
- })).result;
250
- e?.download_url && await k(e.download_url, e.filename);
251
- } catch (e) {
252
- r(e) ? (m(!0), g("Artifact unavailable")) : g(e instanceof Error ? e.message : String(e));
253
- } finally {
254
- c(!1);
255
- }
256
- }
257
- async function b() {
258
- if (i.download_url) {
259
- u(!0), g(null);
260
- try {
261
- await k(i.download_url, i.filename);
262
- } catch (e) {
263
- r(e) ? (m(!0), g("Artifact unavailable")) : g(e instanceof Error ? e.message : String(e));
264
- } finally {
265
- u(!1);
266
- }
267
- }
268
- }
269
- async function ee() {
270
- f(!0), g(null);
271
- try {
272
- await T("document.generate", {
273
- ...i.input ?? {},
274
- template_code: i.template_code,
275
- template_source: i.template_source,
276
- output_format: i.output_format
277
- }), await a.invalidateQueries({ queryKey: [
278
- A,
279
- t,
280
- n
281
- ] });
282
- } catch (e) {
283
- g(e instanceof Error ? e.message : String(e));
284
- } finally {
285
- f(!1);
286
- }
287
- }
288
- return /* @__PURE__ */ z("div", {
289
- style: {
290
- display: "grid",
291
- gridTemplateColumns: "minmax(0, 1fr) auto",
292
- gap: 12,
293
- alignItems: "center",
294
- padding: "11px 14px",
295
- borderTop: "1px solid var(--divider)"
296
- },
297
- children: [/* @__PURE__ */ z("div", {
298
- style: { minWidth: 0 },
299
- children: [
300
- /* @__PURE__ */ R("div", {
301
- style: {
302
- fontSize: 13,
303
- fontWeight: 600,
304
- color: "var(--text)",
305
- overflow: "hidden",
306
- textOverflow: "ellipsis",
307
- whiteSpace: "nowrap"
308
- },
309
- children: _
310
- }),
311
- /* @__PURE__ */ z("div", {
312
- style: {
313
- marginTop: 3,
314
- display: "flex",
315
- gap: 8,
316
- alignItems: "center",
317
- color: "var(--text-3)",
318
- fontSize: 11.5
319
- },
320
- children: [
321
- /* @__PURE__ */ R("span", { children: i.output_format.toUpperCase() }),
322
- /* @__PURE__ */ R("span", { children: p ? "artifact unavailable" : i.status }),
323
- /* @__PURE__ */ R("span", { children: i.ready_at || i.created_at })
324
- ]
325
- }),
326
- i.status === "failed" && i.error_text && /* @__PURE__ */ R("div", {
327
- style: {
328
- marginTop: 5,
329
- color: "var(--danger)",
330
- fontSize: 12
331
- },
332
- children: i.error_text
333
- }),
334
- h && /* @__PURE__ */ R("div", {
335
- style: {
336
- marginTop: 5,
337
- color: "var(--danger)",
338
- fontSize: 12
339
- },
340
- children: h
341
- })
342
- ]
343
- }), v ? /* @__PURE__ */ z("div", {
344
- style: {
345
- display: "flex",
346
- gap: 6
347
- },
348
- children: [/* @__PURE__ */ R(o, {
349
- kind: "ghost",
350
- size: "sm",
351
- icon: R(s ? e.loader : e.file, { size: 12 }),
352
- onClick: y,
353
- disabled: s,
354
- children: "PDF"
355
- }), /* @__PURE__ */ R(o, {
356
- kind: "default",
357
- size: "sm",
358
- icon: R(l ? e.loader : e.download, { size: 12 }),
359
- onClick: b,
360
- disabled: l,
361
- children: "Download"
362
- })]
363
- }) : p ? /* @__PURE__ */ R(o, {
364
- kind: "ghost",
365
- size: "sm",
366
- icon: R(d ? e.loader : e.file, { size: 12 }),
367
- onClick: ee,
368
- disabled: d,
369
- children: "Regenerate"
370
- }) : /* @__PURE__ */ R(o, {
371
- kind: "ghost",
372
- size: "sm",
373
- disabled: !0,
374
- children: i.status === "pending" ? "Pending" : "Unavailable"
375
- })]
376
- });
377
- }
378
- function H({ icon: e, text: t }) {
379
- return /* @__PURE__ */ z("div", {
380
- style: {
381
- display: "flex",
382
- alignItems: "center",
383
- gap: 8,
384
- padding: "14px",
385
- color: "var(--text-3)",
386
- fontSize: 12.5
387
- },
388
- children: [e, t]
389
- });
390
- }
391
- //#endregion
392
- //#region src/components/detail-layout/ErrorSummary.tsx
393
- function ct({ errors: t, onJump: n }) {
394
- if (t.length === 0) return null;
395
- let r = t.length !== 1;
396
- return /* @__PURE__ */ z("div", {
397
- role: "alert",
398
- style: {
399
- display: "flex",
400
- gap: 10,
401
- padding: "10px 12px",
402
- marginBottom: 12,
403
- borderRadius: 8,
404
- background: "var(--danger-soft)",
405
- border: "1px solid var(--danger-border)",
406
- color: "var(--text)"
407
- },
408
- children: [/* @__PURE__ */ R("span", {
409
- style: {
410
- color: "var(--danger)",
411
- marginTop: 1,
412
- display: "flex"
413
- },
414
- children: /* @__PURE__ */ R(e.warning, { size: 14 })
415
- }), /* @__PURE__ */ z("div", {
416
- style: {
417
- flex: 1,
418
- minWidth: 0
419
- },
420
- children: [/* @__PURE__ */ z("div", {
421
- style: {
422
- fontSize: 12.5,
423
- fontWeight: 600,
424
- marginBottom: 4
425
- },
426
- children: [
427
- t.length,
428
- " ",
429
- r ? "fields need" : "field needs",
430
- " attention"
431
- ]
432
- }), /* @__PURE__ */ R("ul", {
433
- style: {
434
- margin: 0,
435
- padding: 0,
436
- listStyle: "none",
437
- display: "flex",
438
- flexDirection: "column",
439
- gap: 2
440
- },
441
- children: t.map((e) => /* @__PURE__ */ R("li", { children: /* @__PURE__ */ z("button", {
442
- type: "button",
443
- onClick: n ? () => n(e.name) : void 0,
444
- style: {
445
- background: "transparent",
446
- border: 0,
447
- padding: 0,
448
- cursor: n ? "pointer" : "default",
449
- fontSize: 12,
450
- textAlign: "left",
451
- fontFamily: "inherit"
452
- },
453
- children: [
454
- /* @__PURE__ */ R("span", {
455
- style: {
456
- color: "var(--danger)",
457
- marginRight: 6
458
- },
459
- children: "•"
460
- }),
461
- /* @__PURE__ */ R("span", {
462
- style: {
463
- fontWeight: 500,
464
- color: "var(--text-2)"
465
- },
466
- children: e.label
467
- }),
468
- /* @__PURE__ */ z("span", {
469
- style: { color: "var(--text-3)" },
470
- children: [" - ", e.message]
471
- })
472
- ]
473
- }) }, e.name))
474
- })]
475
- })]
476
- });
477
- }
478
- //#endregion
479
- //#region src/components/shared/HighlightsStrip.tsx
480
- function lt({ items: e }) {
481
- return e.length === 0 ? null : /* @__PURE__ */ R("div", {
482
- style: {
483
- display: "flex",
484
- alignItems: "center",
485
- flexWrap: "wrap",
486
- gap: "6px 0",
487
- fontSize: 12
488
- },
489
- children: e.map((e, t) => /* @__PURE__ */ z(Je, { children: [t > 0 && /* @__PURE__ */ R("span", { style: {
490
- width: 1,
491
- height: 12,
492
- background: "var(--divider)",
493
- marginInline: 12
494
- } }), /* @__PURE__ */ z("span", {
495
- style: {
496
- display: "inline-flex",
497
- alignItems: "center",
498
- gap: 6,
499
- lineHeight: 1.3
500
- },
501
- children: [/* @__PURE__ */ R("span", {
502
- style: {
503
- color: "var(--text-3)",
504
- fontSize: 11.5
505
- },
506
- children: e.label
507
- }), /* @__PURE__ */ R("span", {
508
- style: { color: "var(--text)" },
509
- children: e.value
510
- })]
511
- })] }, t))
512
- });
513
- }
514
- //#endregion
515
- //#region src/components/detail-layout/DetailHighlights.tsx
516
- function ut({ screen: e, entity: t, entityCode: n, record: r, refs: i, objectStatuses: a, schema: o, locale: s }) {
517
- let c = e.highlights;
518
- if (!c || c.length === 0) return null;
519
- let l = [];
520
- for (let e of c) {
521
- let c = t.status_groups?.[e];
522
- if (c) {
523
- let t = a?.find((t) => t.group_code === e), n = t ? c.statuses.find((e) => e.code === t.status_code) : void 0;
524
- l.push({
525
- label: E(c.name),
526
- value: n ? /* @__PURE__ */ R(d, {
527
- tone: n.color ?? "slate",
528
- size: "xs",
529
- children: E(n.name)
530
- }) : /* @__PURE__ */ R("span", {
531
- style: { color: "var(--text-4)" },
532
- children: "—"
533
- })
534
- });
535
- continue;
536
- }
537
- if (t.fields.get(e) || t.files?.get(e)) {
538
- let a = Pe({
539
- entity: t,
540
- entityCode: n,
541
- fieldName: e,
542
- record: r,
543
- mode: "display",
544
- refs: i,
545
- entities: o.entities,
546
- screens: o.screens,
547
- surface: "list",
548
- locale: s
549
- });
550
- l.push({
551
- label: Re(t, e, o.entities),
552
- value: a
553
- });
554
- continue;
555
- }
556
- }
557
- return l.length === 0 ? null : /* @__PURE__ */ R(lt, { items: l });
558
- }
559
- //#endregion
560
- //#region src/components/shared/AuditMetaStrip.tsx
561
- function U(e) {
562
- return e.by != null || e.at != null;
563
- }
564
- function W({ lines: e }) {
565
- let t = e.filter(U);
566
- return t.length === 0 ? null : /* @__PURE__ */ R("div", {
567
- style: {
568
- display: "flex",
569
- flexWrap: "wrap",
570
- gap: "8px 24px",
571
- padding: "10px 14px",
572
- background: "var(--surface-2)",
573
- border: "1px solid var(--border)",
574
- borderRadius: 8,
575
- fontSize: 11.5,
576
- color: "var(--text-3)"
577
- },
578
- children: t.map((e, t) => /* @__PURE__ */ R(dt, { line: e }, t))
579
- });
580
- }
581
- function dt({ line: e }) {
582
- return /* @__PURE__ */ z("div", {
583
- style: {
584
- display: "flex",
585
- alignItems: "center",
586
- gap: 8,
587
- minWidth: 0
588
- },
589
- children: [/* @__PURE__ */ R("span", {
590
- style: {
591
- fontSize: 11,
592
- fontWeight: 600,
593
- color: "var(--text-4)",
594
- flexShrink: 0
595
- },
596
- children: e.label
597
- }), /* @__PURE__ */ z("span", {
598
- style: {
599
- display: "inline-flex",
600
- alignItems: "center",
601
- gap: 6,
602
- minWidth: 0
603
- },
604
- children: [
605
- e.by != null && /* @__PURE__ */ R("span", {
606
- style: { color: "var(--text-2)" },
607
- children: e.by
608
- }),
609
- e.by != null && e.at != null && /* @__PURE__ */ R("span", {
610
- style: { color: "var(--text-4)" },
611
- children: "·"
612
- }),
613
- e.at != null && /* @__PURE__ */ R("span", {
614
- className: "num",
615
- children: e.at
616
- })
617
- ]
618
- })]
619
- });
620
- }
621
- //#endregion
622
- //#region src/components/detail-layout/DetailAuditStrip.tsx
623
- function ft({ screen: e, entity: t, entityCode: n, record: r, refs: i, schema: a, locale: o }) {
624
- let s = e.audit;
625
- if (s?.enabled === !1) return null;
626
- let c = (e) => {
627
- if (!e || !t.fields.get(e)) return;
628
- let s = r[e];
629
- if (!(s == null || s === "")) return Pe({
630
- entity: t,
631
- entityCode: n,
632
- fieldName: e,
633
- record: r,
634
- mode: "display",
635
- refs: i,
636
- entities: a.entities,
637
- screens: a.screens,
638
- surface: "list",
639
- locale: o
640
- });
641
- };
642
- return /* @__PURE__ */ R(W, { lines: s?.lines && s.lines.length > 0 ? s.lines.map((e) => ({
643
- label: E(e.label),
644
- at: c(e.at),
645
- by: c(e.by)
646
- })) : [{
647
- label: "Created",
648
- at: c("created_at"),
649
- by: c("created_by")
650
- }, {
651
- label: "Updated",
652
- at: c("updated_at"),
653
- by: c("updated_by")
654
- }] });
655
- }
656
- //#endregion
657
- //#region src/components/detail-layout/EvidenceBlock.tsx
658
- function pt(e) {
659
- if (!e) return;
660
- let t = new Date(e);
661
- if (!Number.isNaN(t.getTime())) return t.toLocaleString();
662
- }
663
- function mt({ evidence: e }) {
664
- let t = e?.verdict ?? "unverified", n = pt(e?.verified_at), r = [];
665
- return n && r.push(`Verified ${n}`), e?.seq && r.push(`chain #${e.seq}`), e?.checkpoint_number && r.push(`checkpoint ${e.checkpoint_number}`), e?.generation && r.push(`generation ${e.generation}`), /* @__PURE__ */ z("div", {
666
- style: {
667
- display: "flex",
668
- flexDirection: "column",
669
- gap: 6
670
- },
671
- children: [/* @__PURE__ */ z("div", {
672
- style: {
673
- display: "flex",
674
- alignItems: "center",
675
- gap: 10,
676
- flexWrap: "wrap"
677
- },
678
- children: [
679
- /* @__PURE__ */ R("span", {
680
- style: {
681
- fontSize: 12,
682
- fontWeight: 600,
683
- color: "var(--muted-foreground)"
684
- },
685
- children: "Evidence"
686
- }),
687
- /* @__PURE__ */ R(d, {
688
- tone: P(t),
689
- size: "sm",
690
- dot: !0,
691
- children: N(t)
692
- }),
693
- r.length > 0 && /* @__PURE__ */ R("span", {
694
- style: {
695
- fontSize: 12,
696
- color: "var(--muted-foreground)"
697
- },
698
- children: r.join(" · ")
699
- })
700
- ]
701
- }), e?.reason && /* @__PURE__ */ R("span", {
702
- style: {
703
- fontSize: 12,
704
- color: "var(--destructive)"
705
- },
706
- children: e.reason
707
- })]
708
- });
709
- }
710
- //#endregion
711
- //#region src/components/shared/RecordHeader.tsx
712
- function ht({ icon: t, avatarName: n, title: r, recordId: a, description: o, highlights: s, mode: c, dirty: l = !1, showBack: u = !1, onBack: f, right: p, identityControls: m, showTitle: h = !0 }) {
713
- let g = ae(), _ = g.category === "phone" || g.width <= 520;
714
- return /* @__PURE__ */ z("div", {
715
- style: {
716
- display: "flex",
717
- alignItems: "flex-start",
718
- gap: 10,
719
- flexWrap: _ ? "wrap" : "nowrap",
720
- minWidth: 0
721
- },
722
- children: [
723
- h && u && /* @__PURE__ */ R("div", {
724
- style: {
725
- paddingTop: 4,
726
- flexShrink: 0
727
- },
728
- children: /* @__PURE__ */ R(i, {
729
- size: 26,
730
- icon: /* @__PURE__ */ R(e.back, { size: 14 }),
731
- title: "Back",
732
- onClick: f
733
- })
734
- }),
735
- h && (n || t) && /* @__PURE__ */ R("div", {
736
- style: {
737
- flexShrink: 0,
738
- paddingTop: 2
739
- },
740
- children: n ? /* @__PURE__ */ R(le, {
741
- name: n,
742
- size: 32
743
- }) : /* @__PURE__ */ R("span", {
744
- style: {
745
- width: 32,
746
- height: 32,
747
- borderRadius: 8,
748
- background: "var(--accent-soft)",
749
- color: "var(--accent)",
750
- display: "flex",
751
- alignItems: "center",
752
- justifyContent: "center"
753
- },
754
- children: t
755
- })
756
- }),
757
- h && /* @__PURE__ */ z("div", {
758
- style: {
759
- flex: "1 1 0",
760
- minWidth: 0
761
- },
762
- children: [/* @__PURE__ */ z("div", {
763
- style: {
764
- display: "flex",
765
- alignItems: "center",
766
- gap: 8,
767
- flexWrap: "wrap"
768
- },
769
- children: [
770
- /* @__PURE__ */ R("h1", {
771
- style: {
772
- margin: 0,
773
- fontSize: "var(--page-title-size, var(--page-title-size-detail))",
774
- fontWeight: 600,
775
- letterSpacing: 0,
776
- lineHeight: "var(--page-title-line-height, var(--page-title-line-height-detail))",
777
- color: "var(--text)",
778
- minWidth: 0,
779
- overflow: "hidden",
780
- textOverflow: "ellipsis",
781
- whiteSpace: _ ? "normal" : "nowrap",
782
- overflowWrap: "anywhere",
783
- maxWidth: "100%"
784
- },
785
- children: r
786
- }),
787
- a && /* @__PURE__ */ R(se, { value: a }),
788
- o && /* @__PURE__ */ R(ce, {
789
- label: o,
790
- "data-testid": "detail-description-info"
791
- }),
792
- m,
793
- c === "edit" && l && /* @__PURE__ */ z("span", {
794
- style: {
795
- display: "inline-flex",
796
- alignItems: "center",
797
- gap: 5,
798
- fontSize: 11,
799
- color: "var(--warn)"
800
- },
801
- children: [/* @__PURE__ */ R("span", { style: {
802
- width: 6,
803
- height: 6,
804
- borderRadius: 999,
805
- background: "var(--warn)"
806
- } }), "Unsaved"]
807
- }),
808
- c === "create" && /* @__PURE__ */ R(d, {
809
- tone: "violet",
810
- size: "xs",
811
- dot: !0,
812
- children: "New record"
813
- })
814
- ]
815
- }), s && c === "display" && /* @__PURE__ */ R("div", {
816
- style: { marginTop: 8 },
817
- children: s
818
- })]
819
- }),
820
- p && /* @__PURE__ */ R("div", {
821
- role: "toolbar",
822
- "aria-label": "Page actions",
823
- style: {
824
- display: "flex",
825
- alignItems: "center",
826
- gap: 6,
827
- flex: _ ? "1 1 100%" : "0 1 auto",
828
- flexWrap: "wrap",
829
- justifyContent: _ ? "flex-start" : "flex-end",
830
- minWidth: 0
831
- },
832
- children: p
833
- })
834
- ]
835
- });
836
- }
837
- //#endregion
838
- //#region src/lib/children-validation.ts
839
- function gt(e, t, n) {
840
- let r = [];
841
- for (let [i, a] of e.fields) {
842
- if (!a.required || a.auto || n && a.primary || e.tenant_key && i === e.tenant_key || a.default !== void 0 && a.default !== null) continue;
843
- let o = t[i];
844
- (o == null || o === "") && r.push(i);
845
- }
846
- return r;
847
- }
848
- var G = /^[^@\s]+@[^@\s]+\.[^@\s]+$/;
849
- function _t(e, t) {
850
- let n = [];
851
- for (let [r, i] of e.fields) {
852
- if (i.type !== "email") continue;
853
- let e = t[r];
854
- typeof e == "string" && e !== "" && !G.test(e) && n.push(r);
855
- }
856
- return n;
857
- }
858
- function vt(e, t) {
859
- let n = /* @__PURE__ */ new Set();
860
- for (let r of Object.values(t.entities)) if (r.children) {
861
- for (let t of r.children) if (t.entity === e && t.foreign_key) {
862
- let e = Array.isArray(t.foreign_key) ? t.foreign_key : [t.foreign_key];
863
- for (let t of e) n.add(t);
864
- }
865
- }
866
- return n;
867
- }
868
- function yt(e, t) {
869
- if (!e || !t) return {};
870
- let n = {};
871
- for (let [r, i] of Object.entries(e)) {
872
- let e = t.entities[r];
873
- if (!e) continue;
874
- let a = vt(r, t), o = [];
875
- for (let [t, n] of e.fields) e.tenant_key && t === e.tenant_key || n.required && !n.auto && !n.primary && !a.has(t) && o.push(t);
876
- if (o.length !== 0) for (let e of i) {
877
- if (e._deleted) continue;
878
- let t = [];
879
- for (let n of o) {
880
- let r = e[n];
881
- (r == null || r === "") && t.push(n);
882
- }
883
- t.length > 0 && (n[r] || (n[r] = {}), n[r][e._key] = t);
884
- }
885
- }
886
- return n;
887
- }
888
- //#endregion
889
- //#region src/components/pages/SmartDetailPage.impl.tsx
890
- var bt = () => {};
891
- function xt(e, t) {
892
- return e.length === t.length && JSON.stringify(e) === JSON.stringify(t);
893
- }
894
- function St(e, t) {
895
- if (e) {
896
- let n = C(re(e, t));
897
- if (n.replace(/^\|+|\|+$/g, "")) return n;
898
- }
899
- return t.id == null ? crypto.randomUUID() : _(t.id);
900
- }
901
- function Ct({ screenCode: e }) {
902
- return /* @__PURE__ */ R(O, { children: /* @__PURE__ */ R(wt, { screenCode: e }) });
903
- }
904
- function wt({ screenCode: t }) {
905
- let { id: r } = Qe(), o = u(), [c, d] = $e(), { data: _ } = ee(), b = m((e) => e.user), x = g(), S = ae(), w = _?.screens[t], T = w?.entity ? _?.entities[w.entity] : void 0, D = w?.entity, O = h(T, "create"), k = h(T, "update"), se = h(T, "delete"), ce = h(T, "restore"), le = (() => {
906
- if (!T || !T.singleton || !T.prefilter) return;
907
- let e = ne(T);
908
- if (e.length !== 1) return;
909
- let t = T.prefilter[e[0]];
910
- if (t === "$caller.user_id") return b?.id;
911
- if (t === "$caller.tenant_id") return b?.tenant?.id;
912
- })(), A = le !== void 0, j = A ? le : r, M = !A && j === "new", N = I(() => {
913
- if (!j || M) return;
914
- if (!T) return j;
915
- let e = ne(T);
916
- if (e.length === 1) return { [e[0]]: j };
917
- let t = y(j, e.length);
918
- if (!t) return;
919
- let n = {};
920
- for (let r = 0; r < e.length; r++) n[e[r]] = t[r] ?? "";
921
- return n;
922
- }, [
923
- j,
924
- M,
925
- T
926
- ]), P = I(() => {
927
- if (N) return typeof N == "string" ? N : C(N);
928
- }, [N]), me = Oe(D, N), { data: ge, isLoading: be, error: xe } = me, Se = Te((e) => e.degradedEntities), Ce = D ? ve(T?.realtime, Se, D) : !1;
929
- ue(je(D, N), !M);
930
- let De = we(D ?? ""), Pe = Fe(D ?? ""), Re = _e(D ?? ""), He = ye(D ?? ""), Ue = Object.keys(T?.status_groups ?? {}).length > 0, We = ge?.data, Ge = We?.$statuses, Je = We?.$properties, et = c.get("edit") === "true", [tt, it] = L(M || et), [B, at] = L({}), [V, st] = L({}), [H, lt] = L({}), [U, W] = L(void 0), [dt, pt] = L(!1), [ht, G] = L(void 0), [vt, Ct] = L({ show: !1 }), [wt, K] = L(!1), Et = M ? O : k, q = tt && Et, Ot = n();
931
- p(q && !M, Ot.enabled);
932
- let [kt, At] = L(() => {
933
- let e = parseInt(w?.sidebar_width || "380", 10);
934
- return isNaN(e) ? 380 : e;
935
- }), jt = Xe(null), J = Xe(null), Mt = F((e) => {
936
- e.preventDefault();
937
- let t = jt.current;
938
- if (!t) return;
939
- let n = t.offsetWidth;
940
- J.current = {
941
- startX: e.clientX,
942
- startW: n
943
- };
944
- let r = (e) => {
945
- if (!J.current) return;
946
- let n = J.current.startX - e.clientX, r = Math.max(280, Math.min(800, J.current.startW + n));
947
- t.style.width = `${r}px`;
948
- }, i = () => {
949
- J.current && t && At(parseInt(t.style.width, 10) || J.current.startW), J.current = null, document.removeEventListener("mousemove", r), document.removeEventListener("mouseup", i);
950
- };
951
- document.addEventListener("mousemove", r), document.addEventListener("mouseup", i);
952
- }, []), Y = ge?.data, X = typeof Y?.$row_version == "string" ? Y.$row_version : void 0, Nt = Y?.$refs, Pt = Xe(X);
953
- Ye(() => {
954
- if (!X) return;
955
- let e = Pt.current;
956
- Pt.current = X, e && e !== X && tt && pt(!0);
957
- }, [tt, X]);
958
- let Ft = !!T?.soft_delete, It = Ft && Y != null && Y[T.soft_delete] != null, Z = Ze(), Lt = Xe(null);
959
- de({ scrollElementRef: Lt });
960
- let Rt = !M && xe instanceof f && xe.status === 404, zt = Xe(null);
961
- Ye(() => {
962
- if (!Rt) return;
963
- let e = he(Z);
964
- zt.current !== e && (zt.current = e, oe.getState().kill(e));
965
- }, [Rt, Z]);
966
- let { openTab: Bt, updateTabTitle: Vt, findTabByPathname: Ht } = Ve();
967
- Ye(() => {
968
- if (!T || A || Ot.enabled) return;
969
- let e = Z.pathname, t = E(w?.display?.name) || E(T.display.name), n = w?.display?.icon || T.display.icon;
970
- Ht(e) || Bt({
971
- pathname: e,
972
- search: "",
973
- title: M ? `New ${t}` : t,
974
- icon: n,
975
- closable: !0
976
- });
977
- }, [
978
- Z.pathname,
979
- w?.display?.name?.en,
980
- T?.display.name?.en,
981
- w?.display?.icon,
982
- T?.display.icon,
983
- M,
984
- A,
985
- Ot.enabled
986
- ]), Ye(() => {
987
- if (!Y || !T || A || Ot.enabled) return;
988
- let e = Ht(Z.pathname);
989
- if (e) {
990
- let t = E(w?.display?.name) || E(T.display.name), n = v(Y, T), r = n && !String(n).startsWith("/") ? String(n) : t;
991
- Vt(e.id, r);
992
- }
993
- }, [
994
- Y,
995
- T?.display.name?.en,
996
- T?.display.display_field,
997
- Z.pathname,
998
- A,
999
- Ot.enabled
1000
- ]);
1001
- let Ut = I(() => {
1002
- if (!T || !Et) return /* @__PURE__ */ new Set();
1003
- let e = /* @__PURE__ */ new Set();
1004
- for (let [t, n] of T.fields) !n.auto && !n.primary && e.add(t);
1005
- for (let [t] of T.files ?? []) e.add(t);
1006
- return e;
1007
- }, [T, Et]);
1008
- Ye(() => {
1009
- if (!(!et || !Y || !T || !k)) {
1010
- if (tt || it(!0), Object.keys(B).length === 0) {
1011
- let e = j ? pe(j) : null;
1012
- e && Ie(Ne({
1013
- entity: T,
1014
- formData: e,
1015
- record: void 0,
1016
- isNew: !0
1017
- })).forEach((e) => {
1018
- x.registerDraft({
1019
- fileId: e,
1020
- discard: () => l(e)
1021
- });
1022
- });
1023
- let t = {};
1024
- Ut.forEach((n) => {
1025
- let r = e ? e[n] : void 0;
1026
- if (r !== void 0) {
1027
- t[n] = r;
1028
- return;
1029
- }
1030
- let i = ke(T, Y, n);
1031
- t[n] = Me(T, n) ? i ?? null : i ?? "";
1032
- }), at(t);
1033
- }
1034
- if (T.children !== void 0 && T.children.length > 0 && U === void 0) {
1035
- let e = Y.$children;
1036
- if (e && Object.keys(e).length > 0) {
1037
- let t = {};
1038
- for (let [n, r] of Object.entries(e)) {
1039
- let e = _?.entities[n];
1040
- t[n] = r.map((t) => ({
1041
- ...t,
1042
- _key: St(e, t)
1043
- }));
1044
- }
1045
- W(t), G(e);
1046
- } else W({}), G({});
1047
- }
1048
- d((e) => {
1049
- let t = new URLSearchParams(e);
1050
- return t.delete("edit"), t;
1051
- }, { replace: !0 });
1052
- }
1053
- }, [
1054
- et,
1055
- Y,
1056
- Ut,
1057
- k,
1058
- T,
1059
- U,
1060
- _
1061
- ]), Ye(() => {
1062
- !M || !O || !T?.children || T.children.length === 0 || U === void 0 && (W({}), G({}));
1063
- }, [
1064
- M,
1065
- O,
1066
- T?.children
1067
- ]);
1068
- let Wt = F(async () => {
1069
- if (await x.flushAllDrafts(), M) {
1070
- let e = w?.route?.replace("/:id", "") ?? "/";
1071
- o(e);
1072
- } else it(!1), at({}), st({}), lt({}), W(void 0), G(void 0), K(!1);
1073
- }, [
1074
- x,
1075
- M,
1076
- w,
1077
- o
1078
- ]), Gt = F((e, t) => {
1079
- at((n) => ({
1080
- ...n,
1081
- [e]: t
1082
- }));
1083
- }, []), Q = I(() => {
1084
- if (!w?.route) return "/";
1085
- let e = w.route.split("/");
1086
- return e.pop(), e.join("/") || "/";
1087
- }, [w]), Kt = I(() => !_?.screens || !Q || Q === "/" ? !1 : Object.values(_.screens).some((e) => e.route === Q), [_, Q]), qt = Ee({ fallback: F(() => {
1088
- if (!Kt) {
1089
- o("/");
1090
- return;
1091
- }
1092
- let e = Ht(Q)?.search ?? "";
1093
- o(e ? `${Q}?${e}` : Q);
1094
- }, [
1095
- Kt,
1096
- Q,
1097
- Ht,
1098
- o
1099
- ]) }), Jt = !A && (qt.hasOriginBack || qt.allowFallbackBack && !!Kt), Yt = te(), Xt = I(() => {
1100
- if (!T) return {};
1101
- let e = {};
1102
- for (let t of gt(T, B, M)) Ut.has(t) && (e[t] = "Required");
1103
- for (let t of _t(T, B)) Ut.has(t) && (e[t] = "Invalid email address");
1104
- return e;
1105
- }, [
1106
- T,
1107
- B,
1108
- M,
1109
- Ut
1110
- ]), Zt = Object.keys(Xt).length > 0, Qt = F(() => {
1111
- if (!D || !T || M && !O || !M && !k || (K(!0), Zt)) return;
1112
- let e = {}, t = Ne({
1113
- entity: T,
1114
- formData: B,
1115
- record: Y,
1116
- isNew: M
1117
- }), n = Ie(t);
1118
- if (M) for (let [t, n] of Object.entries(B)) {
1119
- if (T.files?.has(t)) continue;
1120
- let r = Ae(T, t, n);
1121
- r !== "" && r != null && (e[t] = r);
1122
- }
1123
- else {
1124
- for (let [t, n] of Object.entries(B)) {
1125
- if (T.files?.has(t)) continue;
1126
- let r = Y ? ke(T, Y, t) : void 0, i = Ae(T, t, n), a = Ae(T, t, r);
1127
- (i === "" ? null : i) !== (a === "" || a === void 0 ? null : a) && (e[t] = i);
1128
- }
1129
- X && (e.$row_version = X);
1130
- }
1131
- if (Object.keys(t).length > 0 && (e.$files = t), Object.keys(V).length > 0 && (e.$statuses = Object.entries(V).map(([e, t]) => ({
1132
- status_group_code: e,
1133
- status_code: t
1134
- }))), Object.keys(H).length > 0 && (e.$properties = Object.entries(H).map(([e, t]) => ({
1135
- property_code: e,
1136
- value: t
1137
- }))), U) {
1138
- let t = {};
1139
- for (let [e, n] of Object.entries(U)) {
1140
- let r = n.filter((e) => !e._deleted).map((e) => {
1141
- let { _key: t, _deleted: n, _dirty: r, ...i } = e;
1142
- return i;
1143
- }), i = ht?.[e] ?? [];
1144
- (M || !xt(r, i)) && (t[e] = r);
1145
- }
1146
- Object.keys(t).length > 0 && (e.$children = t);
1147
- }
1148
- if (!M && Object.keys(e).length === 0) {
1149
- it(!1), st({}), lt({}), W(void 0), G(void 0), K(!1);
1150
- return;
1151
- }
1152
- let r = () => {
1153
- it(!1), pt(!1), K(!1), st({}), lt({}), W(void 0), G(void 0);
1154
- };
1155
- M ? De.mutate(e, { onSuccess: (e) => {
1156
- n.forEach((e) => x.markCommitted(e));
1157
- let t = e.data, i = C(T ? re(T, t) : {});
1158
- o(i ? `${Q}/${encodeURIComponent(i)}` : Q, { replace: !0 }), r();
1159
- } }) : N && Pe.mutate({
1160
- pkValues: N,
1161
- data: e
1162
- }, {
1163
- onSuccess: () => {
1164
- n.forEach((e) => x.markCommitted(e)), r();
1165
- },
1166
- onError: (e) => {
1167
- e instanceof f && e.code === "STALE_OBJECT" && pt(!0);
1168
- }
1169
- });
1170
- }, [
1171
- x,
1172
- M,
1173
- O,
1174
- k,
1175
- D,
1176
- B,
1177
- Zt,
1178
- V,
1179
- H,
1180
- U,
1181
- ht,
1182
- De,
1183
- Pe,
1184
- T,
1185
- o,
1186
- Q,
1187
- Y,
1188
- X,
1189
- N
1190
- ]), $t = F((e, t) => {
1191
- W((n) => ({
1192
- ...n ?? {},
1193
- [e]: t
1194
- }));
1195
- }, []), en = F(() => {
1196
- !N || M || !se || Re.mutate(N, { onSuccess: () => {
1197
- oe.getState().kill(he(Z)), o(Q, { replace: !0 });
1198
- } });
1199
- }, [
1200
- N,
1201
- M,
1202
- se,
1203
- Re,
1204
- o,
1205
- Q,
1206
- Z
1207
- ]), tn = F(() => {
1208
- !N || M || !ce || He.mutate(N);
1209
- }, [
1210
- N,
1211
- M,
1212
- ce,
1213
- He
1214
- ]), nn = I(() => yt(U, _), [U, _]), rn = Object.keys(nn).length > 0;
1215
- if (!w || !T) return null;
1216
- if (!M && be) return /* @__PURE__ */ R(Be, {});
1217
- if (!M && !Y || Rt) return /* @__PURE__ */ z("div", {
1218
- style: { padding: 24 },
1219
- children: [/* @__PURE__ */ z("div", {
1220
- style: {
1221
- display: "flex",
1222
- alignItems: "center",
1223
- gap: 8,
1224
- marginBottom: 8
1225
- },
1226
- children: [Jt && /* @__PURE__ */ R(i, {
1227
- icon: /* @__PURE__ */ R(e.back, { size: 14 }),
1228
- onClick: qt.goBack,
1229
- title: "Back"
1230
- }), /* @__PURE__ */ R("h1", {
1231
- style: {
1232
- margin: 0,
1233
- fontSize: 18,
1234
- fontWeight: 600,
1235
- color: "var(--text)"
1236
- },
1237
- children: "Not Found"
1238
- })]
1239
- }), /* @__PURE__ */ R("p", {
1240
- style: { color: "var(--text-3)" },
1241
- children: "Record not found."
1242
- })]
1243
- });
1244
- let an = T.display, on = E(w.display?.name) || E(an.name), sn = v(Y, T), cn = M ? `New ${on}` : sn ? String(sn) : on, ln = De.isPending || Pe.isPending, un = w.responsive?.[S.category]?.layout, dn = un?.tabs ?? (S.isPhone ? "sections" : void 0), fn = un?.header_card === !0 ? Le({
1245
- entity: T,
1246
- screen: w
1247
- }) : void 0, $ = {
1248
- schema: _,
1249
- entity: T,
1250
- entityCode: D,
1251
- recordId: P ?? j ?? "",
1252
- record: q ? {
1253
- ...Y ?? {},
1254
- ...B
1255
- } : Y ?? {},
1256
- isNew: M,
1257
- mode: q ? "edit" : "display",
1258
- onFieldChange: q ? Gt : void 0,
1259
- refs: Nt,
1260
- objectProperties: (() => {
1261
- let e = Je ?? [];
1262
- if (!q || Object.keys(H).length === 0) return e.length > 0 ? e : void 0;
1263
- let t = e.map((e) => H[e.property_code] === void 0 ? e : {
1264
- ...e,
1265
- value: H[e.property_code]
1266
- });
1267
- for (let [n, r] of Object.entries(H)) e.some((e) => e.property_code === n) || t.push({
1268
- property_code: n,
1269
- name: {},
1270
- type: "string",
1271
- value: r
1272
- });
1273
- return t;
1274
- })(),
1275
- onSetProperty: M || !k ? void 0 : q ? (e, t) => lt((n) => ({
1276
- ...n,
1277
- [e]: t
1278
- })) : void 0,
1279
- isPropertyPending: !1,
1280
- objectStatuses: (() => {
1281
- let e = Ge ?? [];
1282
- if (!q || Object.keys(V).length === 0) return e.length > 0 ? e : void 0;
1283
- let t = e.map((e) => V[e.group_code] === void 0 ? e : {
1284
- ...e,
1285
- status_code: V[e.group_code]
1286
- });
1287
- for (let [n, r] of Object.entries(V)) e.some((e) => e.group_code === n) || t.push({
1288
- group_code: n,
1289
- status_code: r,
1290
- status_name: {},
1291
- set_at: s()
1292
- });
1293
- return t;
1294
- })(),
1295
- onSetStatus: M || !k ? void 0 : q ? (e, t) => st((n) => ({
1296
- ...n,
1297
- [e]: t
1298
- })) : void 0,
1299
- isStatusPending: !1,
1300
- pendingChildren: q ? U : void 0,
1301
- onChildrenChange: q ? $t : void 0,
1302
- childValidationErrors: q ? nn : void 0,
1303
- fieldErrors: q && wt ? Xt : void 0,
1304
- detailTabsPresentation: dn,
1305
- relatedRecordsPresentation: un?.related_records
1306
- }, pn = !!w.sidebar && w.sidebar.length > 0, mn = un?.sidebar === "hidden", hn = pn && !mn && !S.isDesktop, gn = pn && !mn && S.isDesktop, _n = !M && Y ? /* @__PURE__ */ R(ut, {
1307
- screen: w,
1308
- entity: T,
1309
- entityCode: D,
1310
- record: Y,
1311
- refs: Nt,
1312
- objectStatuses: Ge,
1313
- schema: _,
1314
- locale: Yt
1315
- }) : void 0, vn = /* @__PURE__ */ R(Dt, {
1316
- title: cn,
1317
- recordId: j,
1318
- editing: q,
1319
- isNew: M,
1320
- isRecordDeleted: It,
1321
- dirty: tt,
1322
- isSaving: ln,
1323
- hasChildErrors: rn,
1324
- hasFieldErrors: wt && Zt,
1325
- canRestore: ce,
1326
- entity: T,
1327
- screen: w,
1328
- globalActions: _?.actions,
1329
- entityCode: D,
1330
- record: Y,
1331
- id: j,
1332
- listRoute: Q,
1333
- listRouteExists: !!Kt,
1334
- highlights: _n,
1335
- showBack: Jt,
1336
- onBack: qt.goBack,
1337
- onCancelEdit: Wt,
1338
- onSave: Qt,
1339
- onRestore: tn,
1340
- isRestoring: He.isPending,
1341
- refreshControl: {
1342
- refetch: me.refetch,
1343
- isFetching: me.isFetching,
1344
- isLoading: me.isLoading,
1345
- isLive: Ce
1346
- },
1347
- isRealtimeEntity: T?.realtime === !0,
1348
- canManageTemplates: fe(_)
1349
- }), yn = It && /* @__PURE__ */ z("div", {
1350
- style: {
1351
- display: "flex",
1352
- alignItems: "center",
1353
- gap: 8,
1354
- padding: "10px 14px",
1355
- marginBottom: 12,
1356
- borderRadius: 8,
1357
- border: "1px solid var(--danger)",
1358
- background: "var(--danger-soft)",
1359
- color: "var(--danger)",
1360
- fontSize: 12.5
1361
- },
1362
- children: [/* @__PURE__ */ R(e.warning, { size: 14 }), /* @__PURE__ */ z("span", { children: ["This record was deleted on ", a(String(Y[T.soft_delete]))] })]
1363
- }), bn = dt && /* @__PURE__ */ z("div", {
1364
- style: {
1365
- display: "flex",
1366
- alignItems: "center",
1367
- gap: 8,
1368
- padding: "10px 14px",
1369
- marginBottom: 12,
1370
- borderRadius: 8,
1371
- border: "1px solid var(--warn)",
1372
- background: "var(--warn-soft)",
1373
- color: "var(--warn)",
1374
- fontSize: 12.5
1375
- },
1376
- children: [/* @__PURE__ */ R(e.warning, { size: 14 }), /* @__PURE__ */ R("span", { children: "This record changed on the server while you were viewing or editing it." })]
1377
- }), xn = q && wt && Zt && /* @__PURE__ */ R(ct, {
1378
- errors: Object.entries(Xt).map(([e, t]) => {
1379
- let n = T.fields.get(e);
1380
- return {
1381
- name: e,
1382
- label: n ? ie(n, e, _?.entities) : e,
1383
- message: t
1384
- };
1385
- }),
1386
- onJump: (e) => {
1387
- let t = document.getElementById(`${D}-${e}`);
1388
- t && (t.scrollIntoView({
1389
- block: "center",
1390
- behavior: "smooth"
1391
- }), t.focus?.());
1392
- }
1393
- }), Sn = Ue && !M && !(w.items && w.items.length > 0) && /* @__PURE__ */ R("div", {
1394
- className: "mb-4",
1395
- children: /* @__PURE__ */ R(Ke, {
1396
- statusGroups: T.status_groups ?? {},
1397
- objectStatuses: $.objectStatuses,
1398
- onSetStatus: k && q ? (e, t) => st((n) => ({
1399
- ...n,
1400
- [e]: t
1401
- })) : bt,
1402
- isPending: !1,
1403
- mode: q ? "edit" : "display"
1404
- })
1405
- }), Cn = T.evidence_covered && !M && Y && /* @__PURE__ */ R("div", {
1406
- className: "mb-4",
1407
- children: /* @__PURE__ */ R(mt, { evidence: Y.$evidence })
1408
- }), wn = /* @__PURE__ */ z(nt, { children: [
1409
- fn && (Y || M) && /* @__PURE__ */ R(Tt, {
1410
- card: fn,
1411
- entity: T,
1412
- record: $.record,
1413
- objectStatuses: $.objectStatuses,
1414
- objectProperties: $.objectProperties
1415
- }),
1416
- w.items && w.items.length > 0 && (Y || M) && _ && /* @__PURE__ */ R(qe, {
1417
- nodes: w.items,
1418
- ctx: $
1419
- }),
1420
- !M && j && D && T.associations && Object.keys(T.associations).length > 0 && _ && /* @__PURE__ */ R(rt, {
1421
- entityCode: D,
1422
- recordId: P ?? j ?? "",
1423
- associations: T.associations,
1424
- schema: _
1425
- }),
1426
- !M && j && D && /* @__PURE__ */ R(ot, {
1427
- entityCode: D,
1428
- objectId: P ?? j,
1429
- canGenerateOne: !!T?.documents?.generate_one,
1430
- canManageTemplates: fe(_)
1431
- }),
1432
- !M && Y && _ && /* @__PURE__ */ R(ft, {
1433
- screen: w,
1434
- entity: T,
1435
- entityCode: D,
1436
- record: Y,
1437
- refs: Nt,
1438
- schema: _,
1439
- locale: Yt
1440
- })
1441
- ] }), Tn = /* @__PURE__ */ R(ze, {
1442
- open: vt.show,
1443
- onOpenChange: (e) => !e && Ct({ show: !1 }),
1444
- title: `Delete ${on}`,
1445
- description: vt.confirmation ? vt.confirmation : Ft ? `Are you sure you want to delete this ${on.toLowerCase()}? It can be restored later by an admin.` : `Are you sure you want to delete this ${on.toLowerCase()}? This action cannot be undone.`,
1446
- confirmLabel: "Delete",
1447
- onConfirm: en,
1448
- destructive: !0
1449
- });
1450
- if (gn) return /* @__PURE__ */ z("div", {
1451
- style: {
1452
- height: "100%",
1453
- display: "flex",
1454
- overflow: "hidden",
1455
- background: "var(--background)"
1456
- },
1457
- children: [
1458
- /* @__PURE__ */ z("div", {
1459
- style: {
1460
- flex: 1,
1461
- minWidth: 0,
1462
- display: "flex",
1463
- flexDirection: "column",
1464
- height: "100%"
1465
- },
1466
- children: [/* @__PURE__ */ z("div", {
1467
- style: {
1468
- flexShrink: 0,
1469
- padding: "14px 20px 8px"
1470
- },
1471
- children: [
1472
- vn,
1473
- bn,
1474
- yn,
1475
- xn,
1476
- Sn,
1477
- Cn
1478
- ]
1479
- }), /* @__PURE__ */ R("div", {
1480
- ref: Lt,
1481
- style: {
1482
- flex: 1,
1483
- minHeight: 0,
1484
- overflowY: "auto",
1485
- padding: "4px 20px 24px",
1486
- display: "flex",
1487
- flexDirection: "column",
1488
- gap: 16
1489
- },
1490
- children: wn
1491
- })]
1492
- }),
1493
- /* @__PURE__ */ R("div", {
1494
- className: "detail-resize-handle",
1495
- onMouseDown: Mt,
1496
- title: "Drag to resize",
1497
- children: /* @__PURE__ */ R("div", { style: {
1498
- position: "absolute",
1499
- top: 0,
1500
- bottom: 0,
1501
- left: "50%",
1502
- transform: "translateX(-50%)",
1503
- width: 1,
1504
- background: "var(--border)"
1505
- } })
1506
- }),
1507
- /* @__PURE__ */ R("div", {
1508
- ref: jt,
1509
- style: {
1510
- flexShrink: 0,
1511
- height: "100%",
1512
- width: `${kt}px`
1513
- },
1514
- children: (Y || M) && _ && /* @__PURE__ */ R(qe, {
1515
- nodes: w.sidebar,
1516
- ctx: $
1517
- })
1518
- }),
1519
- Tn
1520
- ]
1521
- });
1522
- let En = S.isPhone ? 12 : 24;
1523
- return /* @__PURE__ */ z("div", {
1524
- style: {
1525
- height: "100%",
1526
- display: "flex",
1527
- flexDirection: "column",
1528
- overflow: "hidden",
1529
- background: "var(--background)"
1530
- },
1531
- children: [
1532
- /* @__PURE__ */ z("div", {
1533
- style: {
1534
- flexShrink: 0,
1535
- padding: S.isPhone ? "14px 12px 8px" : "24px 24px 8px"
1536
- },
1537
- children: [
1538
- vn,
1539
- bn,
1540
- yn,
1541
- xn,
1542
- Sn,
1543
- Cn
1544
- ]
1545
- }),
1546
- /* @__PURE__ */ z("div", {
1547
- ref: Lt,
1548
- style: {
1549
- flex: 1,
1550
- minHeight: 0,
1551
- overflowY: "auto",
1552
- padding: `4px ${En}px calc(24px + var(--safe-area-bottom, 0px))`,
1553
- display: "flex",
1554
- flexDirection: "column",
1555
- gap: 16,
1556
- minWidth: 0,
1557
- WebkitOverflowScrolling: "touch"
1558
- },
1559
- children: [wn, hn && (Y || M) && _ && /* @__PURE__ */ R("div", {
1560
- "data-testid": "detail-sidebar-inline",
1561
- style: {
1562
- display: "flex",
1563
- flexDirection: "column",
1564
- gap: 16,
1565
- minWidth: 0
1566
- },
1567
- children: /* @__PURE__ */ R(qe, {
1568
- nodes: w.sidebar,
1569
- ctx: $
1570
- })
1571
- })]
1572
- }),
1573
- Tn
1574
- ]
1575
- });
1576
- }
1577
- function Tt({ card: e, entity: t, record: n, objectStatuses: r, objectProperties: i }) {
1578
- let a = (e) => {
1579
- let a = K(t, e, n, r, i);
1580
- return a != null && _(a) !== "";
1581
- }, o = (e) => _(K(t, e, n, r, i)) || /* @__PURE__ */ R("span", {
1582
- style: { color: "var(--text-3)" },
1583
- children: "-"
1584
- }), s = _(e.titleUsesDisplay ? v(n, t) : e.titleField ? K(t, e.titleField, n, r, i) : void 0) || E(t.display?.name) || "Record", c = e.badgeFields.filter((t) => !e.hideEmptyFields || a(t)), l = e.bodyFields.filter((t) => !e.hideEmptyFields || a(t)), u = e.metaFields.filter((t) => !e.hideEmptyFields || a(t));
1585
- return /* @__PURE__ */ z("section", {
1586
- "data-testid": "detail-header-card",
1587
- style: {
1588
- width: "100%",
1589
- minWidth: 0,
1590
- border: "1px solid var(--border)",
1591
- borderRadius: 8,
1592
- background: "var(--surface)",
1593
- boxShadow: "var(--shadow-xs)",
1594
- padding: 14,
1595
- boxSizing: "border-box"
1596
- },
1597
- children: [
1598
- /* @__PURE__ */ z("div", {
1599
- style: { minWidth: 0 },
1600
- children: [/* @__PURE__ */ R("div", {
1601
- style: {
1602
- fontSize: 15,
1603
- lineHeight: 1.25,
1604
- fontWeight: 700,
1605
- color: "var(--text)",
1606
- overflowWrap: "anywhere"
1607
- },
1608
- children: s
1609
- }), e.subtitleField && /* @__PURE__ */ R("div", {
1610
- style: {
1611
- marginTop: 4,
1612
- fontSize: 12.5,
1613
- lineHeight: 1.35,
1614
- color: "var(--text-3)",
1615
- overflowWrap: "anywhere"
1616
- },
1617
- children: o(e.subtitleField)
1618
- })]
1619
- }),
1620
- c.length > 0 && /* @__PURE__ */ R("div", {
1621
- style: {
1622
- display: "flex",
1623
- flexWrap: "wrap",
1624
- gap: 6,
1625
- marginTop: 10
1626
- },
1627
- children: c.map((e) => /* @__PURE__ */ R("span", {
1628
- style: {
1629
- minWidth: 0,
1630
- maxWidth: "100%",
1631
- borderRadius: 999,
1632
- background: "var(--surface-2)",
1633
- color: "var(--text-2)",
1634
- padding: "2px 8px",
1635
- fontSize: 12,
1636
- lineHeight: 1.4,
1637
- overflowWrap: "anywhere"
1638
- },
1639
- children: o(e)
1640
- }, e))
1641
- }),
1642
- l.length > 0 && /* @__PURE__ */ R("dl", {
1643
- style: {
1644
- display: "grid",
1645
- gridTemplateColumns: "minmax(84px, max-content) minmax(0, 1fr)",
1646
- gap: "6px 10px",
1647
- margin: "12px 0 0",
1648
- fontSize: 12.5,
1649
- lineHeight: 1.35
1650
- },
1651
- children: l.map((e) => /* @__PURE__ */ z("div", {
1652
- style: { display: "contents" },
1653
- children: [/* @__PURE__ */ R("dt", {
1654
- style: { color: "var(--text-3)" },
1655
- children: Et(t, e)
1656
- }), /* @__PURE__ */ R("dd", {
1657
- style: {
1658
- margin: 0,
1659
- color: "var(--text-2)",
1660
- minWidth: 0,
1661
- overflowWrap: "anywhere"
1662
- },
1663
- children: o(e)
1664
- })]
1665
- }, e))
1666
- }),
1667
- u.length > 0 && /* @__PURE__ */ R("div", {
1668
- style: {
1669
- display: "flex",
1670
- flexWrap: "wrap",
1671
- gap: 10,
1672
- marginTop: 10,
1673
- color: "var(--text-3)",
1674
- fontSize: 11.5
1675
- },
1676
- children: u.map((e) => /* @__PURE__ */ z("span", {
1677
- style: {
1678
- minWidth: 0,
1679
- overflowWrap: "anywhere"
1680
- },
1681
- children: [
1682
- Et(t, e),
1683
- ": ",
1684
- o(e)
1685
- ]
1686
- }, e))
1687
- })
1688
- ]
1689
- });
1690
- }
1691
- function K(e, t, n, r, i) {
1692
- if (t.startsWith("$status.")) {
1693
- let e = t.slice(8), n = r?.find((t) => t.group_code === e);
1694
- return E(n?.status_name) || n?.status_code;
1695
- }
1696
- if (t.startsWith("$property.")) {
1697
- let e = t.slice(10);
1698
- return i?.find((t) => t.property_code === e)?.value;
1699
- }
1700
- return ke(e, n, t);
1701
- }
1702
- function Et(e, t) {
1703
- if (t.startsWith("$status.")) return t.slice(8);
1704
- if (t.startsWith("$property.")) return t.slice(10);
1705
- let n = e.fields.get(t);
1706
- return n ? ie(n, t) : t;
1707
- }
1708
- function Dt({ title: n, recordId: r, editing: i, isNew: a, isRecordDeleted: s, dirty: l, isSaving: d, hasChildErrors: f, hasFieldErrors: p, canRestore: m, entity: h, screen: g, globalActions: _, entityCode: v, record: y, id: b, listRoute: ee, listRouteExists: ne, highlights: S, showBack: C, onBack: re, onCancelEdit: ie, onSave: D, onRestore: O, isRestoring: k, refreshControl: ae, isRealtimeEntity: se, canManageTemplates: ce }) {
1709
- let { run: le } = x(), A = M("detail"), ue = De(), de = u(), fe = te(), N = Ce(g?.action_layout, h?.action_layout, h?.actions, _, "detail_toolbar"), pe = Se(Ce(g?.action_layout, h?.action_layout, h?.actions, _, "detail"), h?.actions, _, y ?? {}, []), P = Se(N, h?.actions, _, y ?? {}, []), _e = I(() => {
1710
- if (!h) return;
1711
- let e = b ? [b] : [];
1712
- return {
1713
- entity: h,
1714
- entityCode: v ?? "",
1715
- screen: g,
1716
- screenRoute: g?.route ?? "",
1717
- selectedRows: y ? [y] : [],
1718
- selectedIds: e,
1719
- locale: fe,
1720
- tabNavigate: (e, t) => ue(e, {
1721
- title: t?.title,
1722
- icon: t?.icon,
1723
- search: t?.search
1724
- }),
1725
- runActionApi: (e, t) => T(e, t)
1726
- };
1727
- }, [
1728
- h,
1729
- v,
1730
- g,
1731
- b,
1732
- y,
1733
- fe,
1734
- ue
1735
- ]), ve = (e, t) => {
1736
- let n = ge(e, t, { row: y ?? void 0 });
1737
- if (n === null) return;
1738
- let r = b ? [b] : [], i = e === "__delete" && ne ? ee : null;
1739
- return le({
1740
- action: t,
1741
- title: E(t.display?.name) || e,
1742
- row: y ?? void 0,
1743
- execute: (e) => T(n, w(e, r)),
1744
- onSuccess: i ? () => {
1745
- oe.getState().kill(he(location)), de(i, { replace: !0 });
1746
- } : void 0
1747
- });
1748
- }, ye = A.isVisible("show_actions") && !a && b && pe.length > 0 ? /* @__PURE__ */ R(be, {
1749
- layout: pe,
1750
- row: y,
1751
- onRun: ve,
1752
- kind: "detail",
1753
- entityActions: h?.actions,
1754
- globalActions: _,
1755
- reservedRightWidth: 0,
1756
- widgetContext: _e,
1757
- constrain: !1
1758
- }) : null, xe = !a && b ? /* @__PURE__ */ R(me, {
1759
- liveObject: ae,
1760
- realtime: se
1761
- }) : null, we = A.isVisible("show_actions") && !a && b && P.length > 0 ? /* @__PURE__ */ z("div", {
1762
- style: {
1763
- display: "flex",
1764
- justifyContent: "flex-end",
1765
- alignItems: "center",
1766
- gap: 8,
1767
- marginTop: 10
1768
- },
1769
- children: [ye ? null : xe, /* @__PURE__ */ R(be, {
1770
- layout: P,
1771
- row: y,
1772
- onRun: ve,
1773
- kind: "detail",
1774
- entityActions: h?.actions,
1775
- globalActions: _,
1776
- reservedRightWidth: 0,
1777
- widgetContext: _e,
1778
- ariaLabel: ye ? "Detail toolbar actions" : "Page actions"
1779
- })]
1780
- }) : null, Te = A.isVisible("show_actions") && !a && b && v ? /* @__PURE__ */ R(j, {
1781
- entityCode: v,
1782
- scope: "detail",
1783
- objectIds: [b],
1784
- capability: h?.documents,
1785
- canManageTemplates: ce
1786
- }) : null, Ee = s ? m ? /* @__PURE__ */ R(o, {
1787
- kind: "primary",
1788
- icon: R(k ? c : e.refresh, { size: 13 }),
1789
- onClick: O,
1790
- disabled: k,
1791
- children: k ? "Restoring…" : "Restore"
1792
- }) : null : i ? /* @__PURE__ */ z(nt, { children: [/* @__PURE__ */ R(o, {
1793
- icon: /* @__PURE__ */ R(e.x, { size: 13 }),
1794
- onClick: ie,
1795
- disabled: d,
1796
- children: "Cancel"
1797
- }), /* @__PURE__ */ R(o, {
1798
- kind: "primary",
1799
- icon: R(d ? c : e.save, { size: 13 }),
1800
- onClick: D,
1801
- disabled: d || f || p,
1802
- title: f ? "Fix errors in child rows" : p ? "Fix the highlighted fields" : void 0,
1803
- children: d ? "Saving…" : "Save"
1804
- })] }) : !a && b ? ye ? /* @__PURE__ */ z("span", {
1805
- style: { display: "contents" },
1806
- children: [Te, ye]
1807
- }) : Te : null;
1808
- return /* @__PURE__ */ z(nt, { children: [/* @__PURE__ */ R(ht, {
1809
- icon: h?.display.icon ? /* @__PURE__ */ R(t, {
1810
- name: h.display.icon,
1811
- size: 16
1812
- }) : void 0,
1813
- title: n,
1814
- description: E(g?.display?.description) || E(h?.display?.description),
1815
- recordId: r,
1816
- highlights: S,
1817
- identityControls: !s && !i && !a ? xe : null,
1818
- mode: a ? "create" : i ? "edit" : "display",
1819
- dirty: l,
1820
- showBack: C,
1821
- onBack: re,
1822
- right: Ee,
1823
- showTitle: A.isVisible("show_title")
1824
- }), we] });
1825
- }
1826
- //#endregion
1827
- export { Ct as SmartDetailPage };