@declarion/react 0.38.5 → 0.40.0

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 (50) hide show
  1. package/dist-lib/{DraggableChildrenTable-DvJO6-m0.js → DraggableChildrenTable-Ctmn0liO.js} +27 -27
  2. package/dist-lib/{Grid-D2ArPFCz.js → Grid-BsIkTp3u.js} +42 -42
  3. package/dist-lib/{LayoutRenderer-C8DQ61Vo.js → LayoutRenderer-D4oTfZhV.js} +833 -731
  4. package/dist-lib/{MarkdownRenderer-CSuODN70.js → MarkdownRenderer-B-2CrtjU.js} +1 -1
  5. package/dist-lib/{RefreshControl-CHvOUn0o.js → RefreshControl-VQf34HKZ.js} +302 -220
  6. package/dist-lib/SmartDetailPage.impl-HMaLVDlV.js +1802 -0
  7. package/dist-lib/SmartRecordListPage.impl-Cxm7qvlZ.js +763 -0
  8. package/dist-lib/api/params.d.ts +12 -11
  9. package/dist-lib/components/columns/ColumnPicker.d.ts +11 -1
  10. package/dist-lib/components/detail-layout/EvidenceBlock.d.ts +6 -0
  11. package/dist-lib/components/detail-layout/useManualColumnResize.d.ts +25 -0
  12. package/dist-lib/components/list/QuickPeek.d.ts +11 -2
  13. package/dist-lib/components/pages/list/{ListBulkBar.d.ts → ListFloatbar.d.ts} +3 -3
  14. package/dist-lib/components/pages/list/RowActionsCell.d.ts +8 -10
  15. package/dist-lib/components/pages/list/RowContextMenu.d.ts +29 -0
  16. package/dist-lib/components/pages/list/SaveViewDialog.d.ts +5 -1
  17. package/dist-lib/components/pages/list/cardProjection.d.ts +1 -1
  18. package/dist-lib/components/pages/list/column-sizing.d.ts +15 -0
  19. package/dist-lib/components/pages/list/columns.d.ts +3 -0
  20. package/dist-lib/components/pages/list/useHeaderReorder.d.ts +26 -0
  21. package/dist-lib/components/pages/list/useRowMenu.d.ts +47 -0
  22. package/dist-lib/components/pages/profile/Profile.d.ts +3 -0
  23. package/dist-lib/components/pages/tenant-params/TenantParamsPage.d.ts +2 -0
  24. package/dist-lib/components/params/ParamsBlock.d.ts +25 -0
  25. package/dist-lib/components/params/param-editors.d.ts +28 -0
  26. package/dist-lib/components/primitives/Dropdown.d.ts +10 -1
  27. package/dist-lib/components/shared/ActionButton.d.ts +1 -7
  28. package/dist-lib/components/shared/ActionDialog.d.ts +2 -2
  29. package/dist-lib/components/shared/ResponsiveActionBar.d.ts +45 -23
  30. package/dist-lib/declarion-react.css +1 -1
  31. package/dist-lib/hooks/useParams.d.ts +45 -1
  32. package/dist-lib/index.d.ts +0 -2
  33. package/dist-lib/index.js +3561 -2570
  34. package/dist-lib/lib/actions.d.ts +44 -3
  35. package/dist-lib/lib/evidence-verdict.d.ts +11 -0
  36. package/dist-lib/lib/rowClickGesture.d.ts +14 -0
  37. package/dist-lib/registry-DFtAh6zc.js +4991 -0
  38. package/dist-lib/stores/list-layout.d.ts +86 -0
  39. package/dist-lib/testing.js +27 -27
  40. package/dist-lib/types/api.d.ts +29 -1
  41. package/dist-lib/types/schema.d.ts +12 -0
  42. package/dist-lib/{useCurrentScreen-DD3KdlMj.js → useCurrentScreen-mw8TfE8q.js} +596 -382
  43. package/dist-lib/{useProperties-CliP5qvg.js → useProperties-gMdnhdhO.js} +117 -117
  44. package/dist-lib/{value-CNy3_xCA.js → value-t9ETvWIJ.js} +4 -4
  45. package/package.json +1 -1
  46. package/dist-lib/SmartDetailPage.impl-Cl306lX3.js +0 -1768
  47. package/dist-lib/SmartRecordListPage.impl-j8bhyL4e.js +0 -763
  48. package/dist-lib/components/list/RowMenu.d.ts +0 -23
  49. package/dist-lib/components/shared/ActionConfirmDialog.d.ts +0 -10
  50. package/dist-lib/registry-C3hbFTDQ.js +0 -5400
@@ -0,0 +1,4991 @@
1
+ import { s as e, t } from "./DynamicIcon-DeRpAaXm.js";
2
+ import { A as n, At as r, B as i, C as a, Ct as o, Dn as s, E as c, Et as l, Fn as u, I as d, In as f, Jn as p, K as m, Kn as h, Kt as g, L as _, Nn as v, O as y, P as b, R as x, Sn as S, T as C, Tn as w, Tt as T, U as E, Un as D, V as O, W as k, X as A, Yn as j, _ as M, _t as N, ar as P, b as F, bn as I, bt as ee, ct as L, d as te, er as ne, g as R, hn as z, i as re, it as B, j as V, jn as ie, jt as ae, mt as oe, or as H, rr as se, sr as U, st as ce, u as le, v as ue, vt as de, wn as fe, xn as pe, xt as me, yt as he, z as ge } from "./useCurrentScreen-mw8TfE8q.js";
3
+ import { a as _e, c as ve, d as ye, f as be, i as xe, l as Se, n as Ce, o as we, p as Te, r as Ee, s as De, t as Oe, u as ke } from "./value-t9ETvWIJ.js";
4
+ import { n as Ae, r as je, t as Me } from "./dataTableStyles-vwD1mVOP.js";
5
+ import { Component as Ne, Suspense as Pe, lazy as Fe, useCallback as W, useEffect as G, useId as Ie, useLayoutEffect as Le, useMemo as K, useRef as q, useState as J } from "react";
6
+ import { parsePath as Re, useNavigate as ze } from "react-router-dom";
7
+ import { useInfiniteQuery as Be, useMutation as Ve, useQuery as He, useQueryClient as Ue } from "@tanstack/react-query";
8
+ import { Fragment as Y, jsx as X, jsxs as Z } from "react/jsx-runtime";
9
+ import { create as We } from "zustand";
10
+ import { clsx as Ge } from "clsx";
11
+ import { twMerge as Ke } from "tailwind-merge";
12
+ //#region src/components/primitives/SectionCard.tsx
13
+ var qe = {
14
+ primary: {
15
+ surface: "var(--surface)",
16
+ shadow: "var(--shadow-xs)"
17
+ },
18
+ secondary: {
19
+ surface: "var(--surface-2)",
20
+ shadow: "none"
21
+ }
22
+ };
23
+ function Je({ title: t, subtitle: n, right: r, badge: i, count: a, children: o, footer: s, collapsible: c = !0, defaultOpen: l = !0, icon: u, emphasis: d = "primary", headingLevel: f = 2, padding: p = "16px" }) {
24
+ let [m, h] = J(l), g = qe[d] ?? qe.primary;
25
+ return /* @__PURE__ */ Z("div", {
26
+ "data-emphasis": d,
27
+ style: {
28
+ background: g.surface,
29
+ border: "1px solid var(--border)",
30
+ borderRadius: 10,
31
+ overflow: "hidden",
32
+ boxShadow: g.shadow,
33
+ flexShrink: 0
34
+ },
35
+ children: [
36
+ /* @__PURE__ */ Z("div", {
37
+ style: {
38
+ display: "flex",
39
+ alignItems: "center",
40
+ gap: 10,
41
+ padding: "10px 14px",
42
+ borderBottom: m ? "1px solid var(--divider)" : "none",
43
+ minHeight: 40
44
+ },
45
+ children: [
46
+ /* @__PURE__ */ X("div", {
47
+ role: "heading",
48
+ "aria-level": f,
49
+ style: {
50
+ display: "flex",
51
+ flex: 1,
52
+ minWidth: 0
53
+ },
54
+ children: /* @__PURE__ */ Z("div", {
55
+ role: c ? "button" : void 0,
56
+ tabIndex: c ? 0 : void 0,
57
+ "aria-expanded": c ? m : void 0,
58
+ onClick: c ? () => h((e) => !e) : void 0,
59
+ onKeyDown: c ? (e) => {
60
+ (e.key === "Enter" || e.key === " ") && (e.preventDefault(), h((e) => !e));
61
+ } : void 0,
62
+ style: {
63
+ display: "flex",
64
+ alignItems: "center",
65
+ gap: 8,
66
+ flex: 1,
67
+ minWidth: 0,
68
+ cursor: c ? "pointer" : "default",
69
+ userSelect: "none"
70
+ },
71
+ children: [
72
+ u && /* @__PURE__ */ X("span", {
73
+ style: {
74
+ color: "var(--text-3)",
75
+ display: "flex",
76
+ flexShrink: 0
77
+ },
78
+ children: u
79
+ }),
80
+ /* @__PURE__ */ X("div", {
81
+ style: {
82
+ fontSize: 12.5,
83
+ fontWeight: 600,
84
+ color: "var(--text)",
85
+ letterSpacing: "-0.005em",
86
+ overflow: "hidden",
87
+ textOverflow: "ellipsis",
88
+ whiteSpace: "nowrap",
89
+ minWidth: 0
90
+ },
91
+ children: t
92
+ }),
93
+ a !== void 0 && /* @__PURE__ */ X("span", {
94
+ className: "num",
95
+ style: {
96
+ fontSize: 11,
97
+ fontWeight: 600,
98
+ color: "var(--text-3)",
99
+ background: "var(--surface-3)",
100
+ borderRadius: 999,
101
+ padding: "1px 7px",
102
+ minWidth: 20,
103
+ textAlign: "center",
104
+ flexShrink: 0
105
+ },
106
+ children: a
107
+ }),
108
+ n && /* @__PURE__ */ X("div", {
109
+ style: {
110
+ fontSize: 11.5,
111
+ color: "var(--text-3)",
112
+ flexShrink: 0,
113
+ borderLeft: "1px solid var(--divider)",
114
+ paddingLeft: 8,
115
+ marginLeft: 2
116
+ },
117
+ children: n
118
+ })
119
+ ]
120
+ })
121
+ }),
122
+ i && /* @__PURE__ */ X(P, {
123
+ tone: i.tone ?? "violet",
124
+ size: "xs",
125
+ dot: i.dot,
126
+ children: i.text
127
+ }),
128
+ r,
129
+ c && /* @__PURE__ */ X(H, {
130
+ size: 24,
131
+ icon: X(m ? e.up : e.down, { size: 14 }),
132
+ onClick: () => h((e) => !e),
133
+ title: m ? "Collapse" : "Expand"
134
+ })
135
+ ]
136
+ }),
137
+ m && /* @__PURE__ */ X("div", {
138
+ style: { padding: p },
139
+ children: o
140
+ }),
141
+ s && m && /* @__PURE__ */ X("div", {
142
+ style: {
143
+ padding: "8px 14px",
144
+ borderTop: "1px solid var(--divider)",
145
+ background: "var(--surface-2)",
146
+ fontSize: 11.5,
147
+ color: "var(--text-3)"
148
+ },
149
+ children: s
150
+ })
151
+ ]
152
+ });
153
+ }
154
+ //#endregion
155
+ //#region src/components/primitives/ClassifiedFieldLocked.tsx
156
+ function Ye({ tier: t, tierDef: n, requiredPermission: r, locale: i = "en", variant: a = "value" }) {
157
+ let o = n?.name?.[i] ?? n?.name?.en ?? t, s = r ? `Locked: requires permission "${r}". Ask your administrator to grant it to your role.` : `Locked: ${o} classification — requires explicit grant.`;
158
+ return /* @__PURE__ */ Z("span", {
159
+ title: s,
160
+ "aria-label": s,
161
+ className: `inline-flex items-center gap-1 text-muted-foreground italic select-none ${a === "input" ? "border border-divider rounded-md px-2 py-1 bg-surface" : ""}`,
162
+ children: [/* @__PURE__ */ X(e.lock, { size: 12 }), /* @__PURE__ */ X("span", { children: o })]
163
+ });
164
+ }
165
+ //#endregion
166
+ //#region src/stores/preferences.ts
167
+ var Xe = {
168
+ colorScheme: "light",
169
+ accent: "violet",
170
+ density: "compact",
171
+ sidebar: "wide",
172
+ tabsPosition: "top",
173
+ tabsMaxOpen: 12,
174
+ tabsPersist: !0,
175
+ radius: 7,
176
+ zebra: !0,
177
+ aiSurface: "both",
178
+ toastPosition: "bottom-right"
179
+ }, Ze = ["light", "dark"], Qe = [
180
+ "violet",
181
+ "blue",
182
+ "teal",
183
+ "amber",
184
+ "rose"
185
+ ], $e = [
186
+ "compact",
187
+ "comfortable",
188
+ "cozy"
189
+ ], et = ["wide", "collapsed"], tt = ["top", "bottom"], nt = [
190
+ "command",
191
+ "panel",
192
+ "both",
193
+ "off"
194
+ ], rt = [
195
+ "top-left",
196
+ "top-center",
197
+ "top-right",
198
+ "bottom-left",
199
+ "bottom-center",
200
+ "bottom-right"
201
+ ];
202
+ function it(e, t) {
203
+ return typeof t == "string" && e.includes(t) ? t : void 0;
204
+ }
205
+ function at(e) {
206
+ let t = {}, n = it(Ze, e.colorScheme);
207
+ n && (t.colorScheme = n);
208
+ let r = it(Qe, e.accent);
209
+ r && (t.accent = r);
210
+ let i = it($e, e.density);
211
+ i && (t.density = i);
212
+ let a = it(et, e.sidebar);
213
+ a && (t.sidebar = a);
214
+ let o = it(tt, e.tabsPosition);
215
+ o && (t.tabsPosition = o);
216
+ let s = it(nt, e.aiSurface);
217
+ s && (t.aiSurface = s);
218
+ let c = it(rt, e.toastPosition);
219
+ return c && (t.toastPosition = c), typeof e.tabsMaxOpen == "number" && e.tabsMaxOpen > 0 && (t.tabsMaxOpen = e.tabsMaxOpen), typeof e.radius == "number" && e.radius >= 0 && e.radius <= 32 && (t.radius = e.radius), typeof e.zebra == "boolean" && (t.zebra = e.zebra), typeof e.tabsPersist == "boolean" && (t.tabsPersist = e.tabsPersist), t;
220
+ }
221
+ var ot = ["declarion-preferences", "declarion-appearance"];
222
+ function st() {
223
+ if (!(typeof window > "u")) try {
224
+ for (let e of ot) localStorage.removeItem(e);
225
+ } catch {}
226
+ }
227
+ function ct(e) {
228
+ if (typeof document > "u") return;
229
+ let t = document.documentElement;
230
+ t.dataset.colorScheme = e.colorScheme, t.dataset.accent = e.accent, t.dataset.density = e.density, t.dataset.sidebar = e.sidebar, t.dataset.tabbar = e.tabsPosition, t.dataset.zebra = e.zebra ? "on" : "off", t.dataset.ai = e.aiSurface, t.style.setProperty("--radius-md", `${e.radius}px`), t.style.setProperty("--radius-lg", `${e.radius + 3}px`);
231
+ }
232
+ function lt(e) {
233
+ return {
234
+ colorScheme: e.color_scheme,
235
+ accent: e.accent,
236
+ density: e.density,
237
+ sidebar: e.sidebar,
238
+ tabsPosition: e.tabs_position,
239
+ tabsMaxOpen: e.tabs_max_open,
240
+ tabsPersist: e.tabs_persist,
241
+ radius: e.radius,
242
+ zebra: e.zebra_rows,
243
+ aiSurface: e.ai_surface,
244
+ toastPosition: e.toast_position
245
+ };
246
+ }
247
+ st();
248
+ var ut = /* @__PURE__ */ new Set(), dt = { ...Xe };
249
+ typeof window < "u" && ct(dt);
250
+ var ft = We((e, t) => ({
251
+ ...dt,
252
+ set: (n, r) => {
253
+ let i = at({ [n]: r });
254
+ i[n] !== void 0 && (ct({
255
+ ...t(),
256
+ ...i
257
+ }), ut.add(n), e(i));
258
+ },
259
+ setMany: (n) => {
260
+ let r = at(n);
261
+ if (Object.keys(r).length) {
262
+ ct({
263
+ ...t(),
264
+ ...r
265
+ });
266
+ for (let e of Object.keys(r)) ut.add(e);
267
+ e(r);
268
+ }
269
+ },
270
+ hydrateFromBranding: (t) => {
271
+ if (!t) return;
272
+ let n = lt(t), r = {};
273
+ for (let [e, t] of Object.entries(n)) ut.has(e) || t !== void 0 && (r[e] = t);
274
+ let i = at(r);
275
+ Object.keys(i).length && (ct({
276
+ ...ft.getState(),
277
+ ...i
278
+ }), e(i));
279
+ },
280
+ resetToDefaults: (t) => {
281
+ ut.clear(), st();
282
+ let n = t ? at(lt(t)) : {}, r = {
283
+ ...Xe,
284
+ ...n
285
+ };
286
+ ct(r), e(r);
287
+ }
288
+ })), pt = ["/login", "/signup"];
289
+ function mt(e) {
290
+ return pt.includes(e);
291
+ }
292
+ function ht(e) {
293
+ return typeof e == "string" && e.startsWith("/") && !e.startsWith("//");
294
+ }
295
+ var gt = 4096;
296
+ function _t(e) {
297
+ return typeof e == "string" && e.length <= gt;
298
+ }
299
+ function vt(e) {
300
+ if (e === null) return null;
301
+ if (e === void 0 || typeof e != "object" || Array.isArray(e)) return;
302
+ let t = e;
303
+ if (!ht(t.pathname) || t.pathname.length > gt || t.pathname.includes("?") || t.pathname.includes("#")) return;
304
+ let n = { pathname: t.pathname };
305
+ if (t.search !== void 0) {
306
+ if (!_t(t.search) || t.search.startsWith("?")) return;
307
+ t.search && (n.search = t.search);
308
+ }
309
+ if (t.hash !== void 0) {
310
+ if (!_t(t.hash) || t.hash && !t.hash.startsWith("#")) return;
311
+ t.hash && (n.hash = t.hash);
312
+ }
313
+ for (let e of [
314
+ "tabId",
315
+ "title",
316
+ "icon",
317
+ "screen"
318
+ ]) if (t[e] !== void 0) {
319
+ if (!_t(t[e])) return;
320
+ t[e] && (n[e] = t[e]);
321
+ }
322
+ return n;
323
+ }
324
+ function yt(e) {
325
+ return e.closable !== !1;
326
+ }
327
+ function bt(e, t, n, r) {
328
+ if (n === "all") return e.filter(yt).map((e) => e.id);
329
+ let i = r ?? t;
330
+ if (!i) return [];
331
+ let a = e.findIndex((e) => e.id === i);
332
+ return a === -1 ? [] : n === "current" ? yt(e[a]) ? [e[a].id] : [] : n === "others" ? e.filter((e, t) => t !== a && yt(e)).map((e) => e.id) : e.slice(a + 1).filter(yt).map((e) => e.id);
333
+ }
334
+ var xt = null, St = null;
335
+ function Ct(e, t) {
336
+ return `declarion::${e}::${t}::tabs`;
337
+ }
338
+ function wt() {
339
+ return !xt || !St ? null : Ct(xt, St);
340
+ }
341
+ function Tt(e) {
342
+ let t;
343
+ try {
344
+ t = JSON.parse(e);
345
+ } catch {
346
+ return null;
347
+ }
348
+ if (typeof t != "object" || !t) return null;
349
+ let n = t;
350
+ return Array.isArray(n.tabs) ? {
351
+ tabs: n.tabs.filter((e) => typeof e == "object" && !!e && typeof e.id == "string" && typeof e.pathname == "string").map((e) => {
352
+ let t = vt(e.returnTo);
353
+ if (t === void 0) {
354
+ let { returnTo: t, ...n } = e;
355
+ return n;
356
+ }
357
+ return {
358
+ ...e,
359
+ returnTo: t
360
+ };
361
+ }),
362
+ activeTabId: typeof n.activeTabId == "string" ? n.activeTabId : null
363
+ } : null;
364
+ }
365
+ function Et(e, t) {
366
+ if (typeof window > "u") return null;
367
+ let n = localStorage.getItem(Ct(e, t));
368
+ if (!n) return null;
369
+ let r = Tt(n);
370
+ if (!r) return null;
371
+ let i = r.tabs.find((e) => e.id === r.activeTabId), a = i?.pathname;
372
+ if (ht(a)) {
373
+ let e = typeof i?.search == "string" ? i.search : "", t = e.startsWith("?") ? e.slice(1) : e;
374
+ return t ? `${a}?${t}` : a;
375
+ }
376
+ return null;
377
+ }
378
+ function Dt(e, t) {
379
+ if (typeof window > "u") return;
380
+ let n = ft.getState().tabsPersist, r = wt();
381
+ if (r) {
382
+ if (!n) {
383
+ try {
384
+ localStorage.removeItem(r);
385
+ } catch {}
386
+ return;
387
+ }
388
+ try {
389
+ localStorage.setItem(r, JSON.stringify({
390
+ tabs: e,
391
+ activeTabId: t
392
+ }));
393
+ } catch {}
394
+ }
395
+ }
396
+ function Ot() {
397
+ if (typeof window > "u" || !ft.getState().tabsPersist) return null;
398
+ let e = wt();
399
+ if (!e) return null;
400
+ let t = localStorage.getItem(e);
401
+ return t ? Tt(t) : null;
402
+ }
403
+ var kt = We((e, t) => ({
404
+ tabs: [],
405
+ activeTabId: null,
406
+ openTab: (n) => {
407
+ if (mt(n.pathname)) return "";
408
+ let r = t(), i = r.tabs.find((e) => e.pathname === n.pathname);
409
+ if (i) return e({ activeTabId: i.id }), Dt(r.tabs, i.id), i.id;
410
+ let a = crypto.randomUUID(), o = {
411
+ ...n,
412
+ id: a
413
+ }, s = [...r.tabs, o], c = ft.getState().tabsMaxOpen;
414
+ if (c > 0 && s.length > c) {
415
+ let e = s.findIndex((e) => e.id !== a && e.closable !== !1 && !e.dirty);
416
+ e !== -1 && (s = s.filter((t, n) => n !== e));
417
+ }
418
+ return e({
419
+ tabs: s,
420
+ activeTabId: a
421
+ }), Dt(s, a), a;
422
+ },
423
+ closeTab: (e) => {
424
+ let n = t(), r = n.tabs.findIndex((t) => t.id === e);
425
+ r !== -1 && n.tabs[r].closable && n.tabs.length !== 1 && t().closeTabs([e]);
426
+ },
427
+ closeTabs: (n) => {
428
+ let r = t(), i = new Set(n);
429
+ if (i.size === 0) return r.tabs.find((e) => e.id === r.activeTabId) ?? null;
430
+ let a = r.tabs.findIndex((e) => e.id === r.activeTabId), o = r.tabs.filter((e) => !(i.has(e.id) && yt(e))), s = r.activeTabId;
431
+ return s && !o.some((e) => e.id === s) ? s = o.length === 0 ? null : o[Math.min(Math.max(a, 0), o.length - 1)].id : o.length === 0 && (s = null), e({
432
+ tabs: o,
433
+ activeTabId: s
434
+ }), Dt(o, s), o.find((e) => e.id === s) ?? null;
435
+ },
436
+ switchTab: (n) => {
437
+ e({ activeTabId: n }), Dt(t().tabs, n);
438
+ },
439
+ reorderTabs: (t, n) => {
440
+ e((e) => {
441
+ let r = e.tabs.findIndex((e) => e.id === t), i = e.tabs.findIndex((e) => e.id === n);
442
+ if (r === -1 || i === -1 || r === i) return e;
443
+ let a = [...e.tabs], [o] = a.splice(r, 1);
444
+ return a.splice(i, 0, o), { tabs: a };
445
+ });
446
+ },
447
+ findTabByPathname: (e) => t().tabs.find((t) => t.pathname === e),
448
+ updateTabTitle: (t, n) => {
449
+ e((e) => ({ tabs: e.tabs.map((e) => e.id === t ? {
450
+ ...e,
451
+ title: n
452
+ } : e) }));
453
+ },
454
+ updateTabSearch: (t, n) => {
455
+ e((e) => ({ tabs: e.tabs.map((e) => e.id === t ? {
456
+ ...e,
457
+ search: n
458
+ } : e) }));
459
+ },
460
+ setReturnTarget: (n, r) => {
461
+ e((e) => ({ tabs: e.tabs.map((e) => e.id === n ? {
462
+ ...e,
463
+ returnTo: r
464
+ } : e) })), Dt(t().tabs, t().activeTabId);
465
+ },
466
+ commitTabNavigation: (n, r) => {
467
+ let i = "returnTo" in r;
468
+ e((e) => ({
469
+ tabs: e.tabs.map((e) => e.id === n ? {
470
+ ...e,
471
+ search: r.search,
472
+ ...i ? { returnTo: r.returnTo } : {}
473
+ } : e),
474
+ activeTabId: n
475
+ })), Dt(t().tabs, t().activeTabId);
476
+ },
477
+ setDirty: (n, r) => {
478
+ e((e) => ({ tabs: e.tabs.map((e) => e.id === n ? {
479
+ ...e,
480
+ dirty: r
481
+ } : e) })), Dt(t().tabs, t().activeTabId);
482
+ },
483
+ setMode: (n, r) => {
484
+ e((e) => ({ tabs: e.tabs.map((e) => e.id === n ? {
485
+ ...e,
486
+ mode: r
487
+ } : e) })), Dt(t().tabs, t().activeTabId);
488
+ },
489
+ updateTab: (n, r) => {
490
+ e((e) => ({ tabs: e.tabs.map((e) => e.id === n ? {
491
+ ...e,
492
+ ...r
493
+ } : e) })), Dt(t().tabs, t().activeTabId);
494
+ },
495
+ setScope: (e, t) => {
496
+ xt = e, St = t;
497
+ },
498
+ hydrate: () => {
499
+ let t = Ot();
500
+ t && e({
501
+ tabs: t.tabs,
502
+ activeTabId: t.activeTabId
503
+ });
504
+ }
505
+ })), At = We((e) => ({
506
+ depth: 0,
507
+ nextIsRoot: !1,
508
+ applyNavigation: (t) => e((e) => e.nextIsRoot ? {
509
+ depth: 0,
510
+ nextIsRoot: !1
511
+ } : t === "PUSH" ? { depth: e.depth + 1 } : t === "POP" ? { depth: Math.max(0, e.depth - 1) } : e),
512
+ markRoot: () => e({ nextIsRoot: !0 }),
513
+ reset: () => e({
514
+ depth: 0,
515
+ nextIsRoot: !1
516
+ })
517
+ }));
518
+ //#endregion
519
+ //#region src/lib/utils.ts
520
+ function jt(...e) {
521
+ return Ke(Ge(e));
522
+ }
523
+ function Mt(e) {
524
+ return e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button !== 0;
525
+ }
526
+ //#endregion
527
+ //#region src/lib/screen-back.ts
528
+ function Nt(e) {
529
+ return e ? e.startsWith("?") ? e.slice(1) : e : "";
530
+ }
531
+ function Pt(e) {
532
+ if (e) return e.startsWith("?") ? e : `?${e}`;
533
+ }
534
+ function Ft(e, t, n) {
535
+ if (!ht(e.pathname) || mt(e.pathname) || e.pathname === t) return;
536
+ let r = Nt(e.search), i = { pathname: e.pathname };
537
+ return r && (i.search = r), e.hash && (i.hash = e.hash), n?.id && (i.tabId = n.id), n?.title && (i.title = n.title), n?.icon && (i.icon = n.icon), n?.screen && (i.screen = n.screen), i;
538
+ }
539
+ function It(e, t) {
540
+ return t ? {
541
+ hasOriginBack: !1,
542
+ allowFallbackBack: !0
543
+ } : e === null ? {
544
+ hasOriginBack: !1,
545
+ allowFallbackBack: !1
546
+ } : e && ht(e.pathname) ? {
547
+ hasOriginBack: !0,
548
+ allowFallbackBack: !0
549
+ } : {
550
+ hasOriginBack: !1,
551
+ allowFallbackBack: !0
552
+ };
553
+ }
554
+ function Lt(e, t, n) {
555
+ if (n || !e || !ht(e.pathname)) return null;
556
+ let r = (e.tabId ? t.find((t) => t.id === e.tabId) : void 0) ?? t.find((t) => t.pathname === e.pathname);
557
+ return {
558
+ kind: r ? "live" : "reopen",
559
+ tabId: r?.id,
560
+ pathname: e.pathname,
561
+ search: e.search,
562
+ hash: e.hash,
563
+ title: e.title,
564
+ icon: e.icon,
565
+ screen: e.screen
566
+ };
567
+ }
568
+ //#endregion
569
+ //#region src/hooks/useTabNavigate.ts
570
+ function Rt(e, t) {
571
+ let n = Re(e);
572
+ return {
573
+ pathname: n.pathname ?? e,
574
+ search: zt(n.search) ?? zt(t),
575
+ hash: n.hash
576
+ };
577
+ }
578
+ function zt(e) {
579
+ if (!(!e || e === "?")) return e.startsWith("?") ? e : `?${e}`;
580
+ }
581
+ function Bt() {
582
+ let e = ze(), { data: t } = ae(), n = oe(), r = L();
583
+ return W((i, a) => {
584
+ let { pathname: o, search: s, hash: c } = Rt(i, a?.search);
585
+ if (n.enabled) {
586
+ r(`${o}${s ?? ""}${c ?? ""}`, { replace: a?.replace });
587
+ return;
588
+ }
589
+ let l = kt.getState(), u = a?.topLevel ?? !1, d = Nt(s), f = u || typeof window > "u" ? void 0 : Ft({
590
+ pathname: window.location.pathname,
591
+ search: window.location.search,
592
+ hash: window.location.hash
593
+ }, o, l.findTabByPathname(window.location.pathname)), p = l.findTabByPathname(o);
594
+ if (p) {
595
+ if (u) {
596
+ let t = d || p.search;
597
+ l.commitTabNavigation(p.id, {
598
+ search: t,
599
+ returnTo: null
600
+ }), e({
601
+ pathname: o,
602
+ search: t ? `?${t}` : "",
603
+ hash: c
604
+ }, { replace: a?.replace });
605
+ return;
606
+ }
607
+ f ? l.commitTabNavigation(p.id, {
608
+ search: d,
609
+ returnTo: f
610
+ }) : l.commitTabNavigation(p.id, { search: d }), e({
611
+ pathname: o,
612
+ search: s,
613
+ hash: c
614
+ }, { replace: a?.replace });
615
+ return;
616
+ }
617
+ let m = a?.title ? void 0 : v(o, t?.screens, t?.entities), h = a?.title ?? m?.title ?? o, g = a?.icon ?? m?.icon;
618
+ l.openTab({
619
+ pathname: o,
620
+ search: d,
621
+ title: h,
622
+ icon: g,
623
+ closable: !0,
624
+ returnTo: u ? null : f
625
+ }), e({
626
+ pathname: o,
627
+ search: s,
628
+ hash: c
629
+ }, { replace: a?.replace });
630
+ }, [
631
+ e,
632
+ t?.screens,
633
+ t?.entities,
634
+ n.enabled,
635
+ r
636
+ ]);
637
+ }
638
+ //#endregion
639
+ //#region src/components/file-widgets/registry.ts
640
+ var Vt = /* @__PURE__ */ new Map();
641
+ function Ht(e, t) {
642
+ Vt.set(e, t);
643
+ }
644
+ function Ut(e) {
645
+ return Vt.get(e);
646
+ }
647
+ function Wt(e) {
648
+ return Vt.has(e);
649
+ }
650
+ //#endregion
651
+ //#region src/components/file-widgets/cropper.ts
652
+ var Gt = ({ file: e }) => Promise.resolve({
653
+ blob: e,
654
+ filename: e.name
655
+ }), Kt = Gt;
656
+ function qt(e) {
657
+ Kt = e ?? Gt;
658
+ }
659
+ function Jt() {
660
+ return Kt;
661
+ }
662
+ //#endregion
663
+ //#region src/components/file-widgets/ImageWidget.tsx
664
+ function Yt(e, t) {
665
+ return ve(e, t);
666
+ }
667
+ function Xt(e) {
668
+ let t = e.trim().split(/\s+/).filter(Boolean);
669
+ return t.length === 0 ? "?" : t.length === 1 ? t[0].slice(0, 2).toUpperCase() : (t[0][0] + t[1][0]).toUpperCase();
670
+ }
671
+ function Zt(e) {
672
+ let { field: t, fieldName: n, value: r, onChange: a, mode: o, alt: s, disabled: c, visual: l, uploadFieldCode: u, uploadSlotCode: f } = e, p = Ce(r), [m, h] = J("idle"), [g, v] = J(null), [y, x] = J(null), [S, C] = J(null), [w, T] = J(!1), E = q(null), D = q(!1), O = q(null), { register: k, unregister: A, isDraft: j } = b();
673
+ G(() => () => {
674
+ E.current && E.current.abort();
675
+ }, []);
676
+ let M = K(() => be(p, s, t.display?.placeholder || n), [
677
+ s,
678
+ t.display?.placeholder,
679
+ n,
680
+ p
681
+ ]), N = (t.accepts ?? ["image/*"]).join(","), P = W(async (r) => {
682
+ let o = i(r, t.accepts, t.max_size_bytes);
683
+ if (o) {
684
+ x(o), h("error");
685
+ return;
686
+ }
687
+ let s = r;
688
+ if (t.display?.crop_on_upload) try {
689
+ let { blob: e, filename: n } = await Jt()({
690
+ file: r,
691
+ aspectRatio: tn(t.display.aspect_ratio)
692
+ });
693
+ s = new File([e], n, { type: e.type || r.type });
694
+ } catch (e) {
695
+ x({
696
+ code: "CROP_FAILED",
697
+ message: e instanceof Error ? e.message : "Crop failed"
698
+ }), h("error");
699
+ return;
700
+ }
701
+ x(null), D.current = !1, h("uploading"), v({
702
+ loaded: 0,
703
+ total: s.size,
704
+ pct: 0
705
+ });
706
+ let c = new AbortController();
707
+ E.current = c;
708
+ try {
709
+ let r = await ge({
710
+ file: s,
711
+ entityCode: e.entityCode,
712
+ fieldCode: u ?? n,
713
+ slotCode: f,
714
+ signal: c.signal,
715
+ onProgress: v
716
+ });
717
+ if (D.current) {
718
+ _(r.id).catch(() => {}), A(r.id);
719
+ return;
720
+ }
721
+ p && j(p.id) && (_(p.id).catch(() => {}), A(p.id)), k(r.id, () => _(r.id)), C(r.id), h("idle"), v(null);
722
+ let i = {
723
+ id: r.id,
724
+ filename: r.filename,
725
+ content_type: r.content_type,
726
+ size_bytes: r.size_bytes,
727
+ sha256: r.sha256,
728
+ width: r.width,
729
+ height: r.height,
730
+ url: r.url,
731
+ metadata: r.metadata
732
+ };
733
+ a?.(t.mode === "array" ? [i] : i);
734
+ } catch (e) {
735
+ if (e instanceof d && e.code === "ABORTED") return;
736
+ let t = e instanceof d ? {
737
+ code: e.code,
738
+ message: e.message
739
+ } : {
740
+ code: "UNKNOWN",
741
+ message: e instanceof Error ? e.message : "Upload failed"
742
+ };
743
+ x(t), h("error"), v(null);
744
+ }
745
+ }, [
746
+ t.accepts,
747
+ t.max_size_bytes,
748
+ t.display?.crop_on_upload,
749
+ t.display?.aspect_ratio,
750
+ t.mode,
751
+ n,
752
+ a,
753
+ e.entityCode,
754
+ k,
755
+ j,
756
+ p,
757
+ A,
758
+ u,
759
+ f
760
+ ]), F = W(() => {
761
+ m === "uploading" && E.current && (D.current = !0, E.current.abort(), E.current = null, h("idle"), v(null)), S && (_(S).catch(() => {}), A(S), C(null));
762
+ }, [
763
+ m,
764
+ S,
765
+ A
766
+ ]), I = W(() => {
767
+ p && j(p.id) && (_(p.id).catch(() => {}), A(p.id), C(null)), a?.(t.mode === "array" ? [] : null);
768
+ }, [
769
+ p,
770
+ t.mode,
771
+ j,
772
+ a,
773
+ A
774
+ ]), ee = W(() => {
775
+ x(null), h("idle"), O.current?.click();
776
+ }, []), L = W(() => {
777
+ c || O.current?.click();
778
+ }, [c]), te = W((e) => {
779
+ c || (e.key === "Enter" || e.key === " ") && (e.preventDefault(), L());
780
+ }, [c, L]), ne = W((e) => {
781
+ c || (e.preventDefault(), e.dataTransfer.dropEffect = "copy");
782
+ }, [c]), R = W((e) => {
783
+ if (c) return;
784
+ e.preventDefault();
785
+ let t = e.dataTransfer.files?.[0];
786
+ t && P(t);
787
+ }, [c, P]), z = W((e) => {
788
+ let t = e.target.files?.[0];
789
+ e.target.value = "", t && P(t);
790
+ }, [P]), re = l.aspectRatio ?? en(l.shape, t.display?.aspect_ratio), B = ye(p), V = {
791
+ aspectRatio: re,
792
+ width: l.width ?? (l.shape === "wide" ? "100%" : "120px")
793
+ }, ie = !!p, ae = Yt(p, t.display?.listable_thumbnail), oe = Se(p, t.display?.listable_thumbnail), H = xe(p?.id, oe, ae), se = o === "display", U = W((e) => {
794
+ e.stopPropagation(), T((e) => !e);
795
+ }, []), ce = W((e) => {
796
+ if (!p || !w) return;
797
+ let n = e.currentTarget.getBoundingClientRect(), r = n.width > 0 ? (e.clientX - n.left) / n.width : .5, i = n.height > 0 ? (e.clientY - n.top) / n.height : .5, o = Te(p, {
798
+ x: Math.max(0, Math.min(1, r)),
799
+ y: Math.max(0, Math.min(1, i))
800
+ });
801
+ a?.(t.mode === "array" ? [o] : o), T(!1);
802
+ }, [
803
+ t.mode,
804
+ p,
805
+ w,
806
+ a
807
+ ]);
808
+ return se ? /* @__PURE__ */ X("div", {
809
+ className: Qt(l.shape, !1),
810
+ style: V,
811
+ "aria-label": M,
812
+ children: ie && H ? /* @__PURE__ */ X("img", {
813
+ src: H,
814
+ alt: M,
815
+ className: $t(l.shape),
816
+ style: { objectPosition: De(B) },
817
+ loading: "lazy"
818
+ }) : /* @__PURE__ */ X(nn, {
819
+ shape: l.shape,
820
+ label: M,
821
+ placeholder: t.display?.placeholder
822
+ })
823
+ }) : /* @__PURE__ */ Z("div", {
824
+ className: Qt(l.shape, !c),
825
+ style: V,
826
+ tabIndex: c ? -1 : 0,
827
+ role: "button",
828
+ "aria-label": M,
829
+ "aria-disabled": c || void 0,
830
+ "aria-busy": m === "uploading" || void 0,
831
+ "aria-invalid": m === "error" || void 0,
832
+ onClick: m === "idle" && !ie ? L : void 0,
833
+ onMouseDown: w ? ce : void 0,
834
+ onKeyDown: te,
835
+ onDragOver: ne,
836
+ onDrop: R,
837
+ "data-testid": w ? "focal-point-target" : `file-widget-${n}`,
838
+ children: [
839
+ /* @__PURE__ */ X("input", {
840
+ ref: O,
841
+ type: "file",
842
+ accept: N,
843
+ onChange: z,
844
+ style: { display: "none" },
845
+ "data-testid": `file-input-${n}`
846
+ }),
847
+ ie && H ? /* @__PURE__ */ X("img", {
848
+ src: H,
849
+ alt: M,
850
+ className: $t(l.shape),
851
+ style: { objectPosition: De(B) },
852
+ loading: "lazy"
853
+ }) : m === "uploading" ? null : /* @__PURE__ */ X(nn, {
854
+ shape: l.shape,
855
+ label: M,
856
+ placeholder: t.display?.placeholder
857
+ }),
858
+ m === "uploading" && /* @__PURE__ */ X(rn, { pct: g?.pct ?? 0 }),
859
+ S && /* @__PURE__ */ X("span", {
860
+ className: "absolute right-1 top-1 h-2 w-2 rounded-full bg-warning",
861
+ "aria-hidden": "true",
862
+ "data-testid": "draft-indicator"
863
+ }),
864
+ ie && m === "idle" && !c && /* @__PURE__ */ Z("div", {
865
+ className: "absolute inset-0 flex items-center justify-center gap-2 bg-black/40 opacity-0 transition-opacity hover:opacity-100 focus-within:opacity-100",
866
+ children: [
867
+ t.display?.focal_point && /* @__PURE__ */ X("button", {
868
+ type: "button",
869
+ className: "rounded-sm border border-border bg-card px-2 py-1 text-xs text-foreground hover:bg-surface-2",
870
+ onClick: U,
871
+ "data-testid": "focal-point-toggle",
872
+ children: w ? "Cancel focus" : "Set focus"
873
+ }),
874
+ /* @__PURE__ */ X("button", {
875
+ type: "button",
876
+ className: "rounded-sm border border-border bg-card px-2 py-1 text-xs text-foreground hover:bg-surface-2",
877
+ onClick: (e) => {
878
+ e.stopPropagation(), L();
879
+ },
880
+ children: "Change"
881
+ }),
882
+ /* @__PURE__ */ X("button", {
883
+ type: "button",
884
+ className: "rounded-sm border border-border bg-card px-2 py-1 text-xs text-destructive hover:bg-surface-2",
885
+ onClick: (e) => {
886
+ e.stopPropagation(), I();
887
+ },
888
+ children: "Remove"
889
+ })
890
+ ]
891
+ }),
892
+ B && ie && /* @__PURE__ */ X("span", {
893
+ className: "absolute h-3 w-3 -translate-x-1/2 -translate-y-1/2 rounded-full border border-white bg-black/70",
894
+ style: {
895
+ left: `${B.x * 100}%`,
896
+ top: `${B.y * 100}%`
897
+ },
898
+ "data-testid": "focal-point-marker"
899
+ }),
900
+ m === "uploading" && /* @__PURE__ */ X("button", {
901
+ type: "button",
902
+ className: "absolute bottom-1 right-1 rounded-sm border border-border bg-card px-2 py-0.5 text-xs",
903
+ onClick: (e) => {
904
+ e.stopPropagation(), F();
905
+ },
906
+ "data-testid": "cancel-upload",
907
+ children: "Cancel"
908
+ }),
909
+ m === "error" && y && /* @__PURE__ */ Z("div", {
910
+ className: "absolute inset-x-0 bottom-0 flex items-center justify-between gap-2 bg-destructive-soft px-2 py-1 text-xs text-destructive",
911
+ role: "alert",
912
+ children: [/* @__PURE__ */ X("span", {
913
+ className: "truncate",
914
+ title: y.message,
915
+ children: y.message
916
+ }), /* @__PURE__ */ X("button", {
917
+ type: "button",
918
+ className: "underline",
919
+ onClick: (e) => {
920
+ e.stopPropagation(), ee();
921
+ },
922
+ "data-testid": "retry-upload",
923
+ children: "Retry"
924
+ })]
925
+ })
926
+ ]
927
+ });
928
+ }
929
+ function Qt(e, t) {
930
+ return [
931
+ "relative overflow-hidden border border-border bg-surface-2",
932
+ e === "circle" ? "rounded-full" : "rounded-md",
933
+ t ? "cursor-pointer focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent" : ""
934
+ ].filter(Boolean).join(" ");
935
+ }
936
+ function $t(e) {
937
+ return "h-full w-full object-cover";
938
+ }
939
+ function en(e, t) {
940
+ return t ? t.replace(":", " / ") : e === "wide" ? "16 / 9" : "1 / 1";
941
+ }
942
+ function tn(e) {
943
+ if (!e) return;
944
+ let t = e.replace(/\s/g, "").match(/^(\d+(?:\.\d+)?)[:/](\d+(?:\.\d+)?)$/);
945
+ if (!t) return;
946
+ let n = Number(t[1]), r = Number(t[2]);
947
+ if (!(!n || !r)) return n / r;
948
+ }
949
+ function nn({ shape: e, label: t, placeholder: n }) {
950
+ return n === "initials" ? /* @__PURE__ */ X("div", {
951
+ className: "flex h-full w-full items-center justify-center bg-surface-3 text-text-3",
952
+ children: /* @__PURE__ */ X("span", {
953
+ className: e === "circle" ? "text-lg font-medium" : "text-base font-medium",
954
+ children: Xt(t)
955
+ })
956
+ }) : /* @__PURE__ */ X("div", {
957
+ className: "flex h-full w-full items-center justify-center bg-surface-3 text-text-4",
958
+ children: /* @__PURE__ */ X("span", {
959
+ className: "text-xs",
960
+ children: e === "wide" ? "Drop image here" : "+"
961
+ })
962
+ });
963
+ }
964
+ function rn({ pct: e }) {
965
+ let t = 2 * Math.PI * 18, n = t - Math.max(0, Math.min(100, e)) / 100 * t;
966
+ return /* @__PURE__ */ Z("div", {
967
+ className: "absolute inset-0 flex items-center justify-center bg-black/30",
968
+ "data-testid": "upload-progress",
969
+ "aria-label": `Uploading ${Math.round(e)}%`,
970
+ role: "progressbar",
971
+ "aria-valuenow": Math.round(e),
972
+ "aria-valuemin": 0,
973
+ "aria-valuemax": 100,
974
+ children: [/* @__PURE__ */ Z("svg", {
975
+ width: "48",
976
+ height: "48",
977
+ viewBox: "0 0 48 48",
978
+ children: [/* @__PURE__ */ X("circle", {
979
+ cx: "24",
980
+ cy: "24",
981
+ r: 18,
982
+ stroke: "currentColor",
983
+ strokeOpacity: "0.25",
984
+ strokeWidth: "4",
985
+ fill: "none",
986
+ className: "text-foreground"
987
+ }), /* @__PURE__ */ X("circle", {
988
+ cx: "24",
989
+ cy: "24",
990
+ r: 18,
991
+ stroke: "currentColor",
992
+ strokeWidth: "4",
993
+ fill: "none",
994
+ strokeDasharray: t,
995
+ strokeDashoffset: n,
996
+ strokeLinecap: "round",
997
+ className: "text-accent",
998
+ transform: "rotate(-90 24 24)"
999
+ })]
1000
+ }), /* @__PURE__ */ Z("span", {
1001
+ className: "absolute text-xs text-foreground",
1002
+ children: [Math.round(e), "%"]
1003
+ })]
1004
+ });
1005
+ }
1006
+ //#endregion
1007
+ //#region src/components/file-widgets/SquareImage.tsx
1008
+ function an(e) {
1009
+ return /* @__PURE__ */ X(Zt, {
1010
+ ...e,
1011
+ visual: { shape: "square" }
1012
+ });
1013
+ }
1014
+ //#endregion
1015
+ //#region src/components/file-widgets/CircleImage.tsx
1016
+ function on(e) {
1017
+ return /* @__PURE__ */ X(Zt, {
1018
+ ...e,
1019
+ visual: { shape: "circle" }
1020
+ });
1021
+ }
1022
+ //#endregion
1023
+ //#region src/components/file-widgets/WideBanner.tsx
1024
+ function sn(e) {
1025
+ return /* @__PURE__ */ X(Zt, {
1026
+ ...e,
1027
+ visual: { shape: "wide" }
1028
+ });
1029
+ }
1030
+ //#endregion
1031
+ //#region src/components/file-widgets/GridLazy.tsx
1032
+ var cn = Fe(() => import("./Grid-BsIkTp3u.js").then((e) => ({ default: e.Grid })));
1033
+ function ln() {
1034
+ return /* @__PURE__ */ X("div", { className: "h-24 w-full rounded-md bg-muted animate-pulse" });
1035
+ }
1036
+ function un(e) {
1037
+ return /* @__PURE__ */ X(Pe, {
1038
+ fallback: /* @__PURE__ */ X(ln, {}),
1039
+ children: /* @__PURE__ */ X(cn, { ...e })
1040
+ });
1041
+ }
1042
+ //#endregion
1043
+ //#region src/components/file-widgets/DocumentCard.tsx
1044
+ function dn({ contentType: e }) {
1045
+ return /* @__PURE__ */ X("div", {
1046
+ className: "flex h-16 w-16 flex-none items-center justify-center rounded-md border border-border bg-surface-3 text-xs font-medium text-muted-foreground",
1047
+ children: e ? e.includes("pdf") ? "PDF" : e.includes("word") ? "DOC" : e.includes("sheet") || e.includes("excel") ? "XLS" : e.startsWith("image/") ? "IMG" : e.split("/")[1]?.slice(0, 4).toUpperCase() ?? "FILE" : "FILE"
1048
+ });
1049
+ }
1050
+ function fn(e) {
1051
+ let { field: t, fieldName: n, value: r, onChange: a, mode: o, disabled: s, uploadFieldCode: c, uploadSlotCode: l } = e, u = Ce(r), [f, p] = J("idle"), [m, h] = J(null), [g, v] = J(null), [y, S] = J(!1), [C, w] = J(u?.filename ?? ""), T = q(null), E = q(!1), D = q(null), { register: O, unregister: k, isDraft: A } = b(), { open: j } = Ee();
1052
+ G(() => () => {
1053
+ T.current && T.current.abort();
1054
+ }, []), G(() => {
1055
+ w(u?.filename ?? "");
1056
+ }, [u?.filename]);
1057
+ let M = (t.accepts ?? []).join(","), N = W(async (r) => {
1058
+ let o = i(r, t.accepts, t.max_size_bytes);
1059
+ if (o) {
1060
+ v(o), p("error");
1061
+ return;
1062
+ }
1063
+ v(null), E.current = !1, p("uploading"), h({
1064
+ loaded: 0,
1065
+ total: r.size,
1066
+ pct: 0
1067
+ });
1068
+ let s = new AbortController();
1069
+ T.current = s;
1070
+ try {
1071
+ let i = await ge({
1072
+ file: r,
1073
+ entityCode: e.entityCode,
1074
+ fieldCode: c ?? n,
1075
+ slotCode: l,
1076
+ signal: s.signal,
1077
+ onProgress: h
1078
+ });
1079
+ if (E.current) {
1080
+ _(i.id).catch(() => {}), k(i.id);
1081
+ return;
1082
+ }
1083
+ u && A(u.id) && (_(u.id).catch(() => {}), k(u.id)), O(i.id, () => _(i.id)), p("idle"), h(null);
1084
+ let o = {
1085
+ id: i.id,
1086
+ filename: i.filename,
1087
+ content_type: i.content_type,
1088
+ size_bytes: i.size_bytes,
1089
+ sha256: i.sha256,
1090
+ width: i.width,
1091
+ height: i.height,
1092
+ url: i.url,
1093
+ metadata: i.metadata
1094
+ };
1095
+ a?.(t.mode === "array" ? [o] : o);
1096
+ } catch (e) {
1097
+ if (e instanceof d && e.code === "ABORTED") return;
1098
+ let t = e instanceof d ? {
1099
+ code: e.code,
1100
+ message: e.message
1101
+ } : {
1102
+ code: "UNKNOWN",
1103
+ message: e instanceof Error ? e.message : "Upload failed"
1104
+ };
1105
+ v(t), p("error"), h(null);
1106
+ }
1107
+ }, [
1108
+ t.accepts,
1109
+ t.max_size_bytes,
1110
+ t.mode,
1111
+ n,
1112
+ u,
1113
+ A,
1114
+ a,
1115
+ e.entityCode,
1116
+ O,
1117
+ k,
1118
+ c,
1119
+ l
1120
+ ]), P = W(() => {
1121
+ s || D.current?.click();
1122
+ }, [s]), F = W((e) => {
1123
+ let t = e.target.files?.[0];
1124
+ e.target.value = "", t && N(t);
1125
+ }, [N]), I = W(() => {
1126
+ u && A(u.id) && (_(u.id).catch(() => {}), k(u.id)), a?.(t.mode === "array" ? [] : null);
1127
+ }, [
1128
+ u,
1129
+ t.mode,
1130
+ A,
1131
+ a,
1132
+ k
1133
+ ]), ee = W(() => {
1134
+ f === "uploading" && T.current && (E.current = !0, T.current.abort(), T.current = null, p("idle"), h(null));
1135
+ }, [f]), L = W(() => {
1136
+ u && j(u.id, "download", we(u));
1137
+ }, [u, j]), te = u ? _e(u) : !1, ne = W(() => {
1138
+ !u || !_e(u) || j(u.id, "preview", ke(u));
1139
+ }, [u, j]), R = W(() => {
1140
+ if (!u) {
1141
+ S(!1);
1142
+ return;
1143
+ }
1144
+ let e = C.trim();
1145
+ if (S(!1), !e || e === u.filename) {
1146
+ w(u.filename);
1147
+ return;
1148
+ }
1149
+ let n = {
1150
+ ...u,
1151
+ filename: e
1152
+ };
1153
+ a?.(t.mode === "array" ? [n] : n);
1154
+ }, [
1155
+ C,
1156
+ u,
1157
+ a,
1158
+ t.mode
1159
+ ]), z = o === "display";
1160
+ return !u && f !== "uploading" ? /* @__PURE__ */ Z("div", {
1161
+ "data-testid": `file-widget-${n}`,
1162
+ className: "flex items-center gap-3 rounded-md border border-dashed border-border bg-surface p-3",
1163
+ children: [
1164
+ /* @__PURE__ */ X(dn, {}),
1165
+ /* @__PURE__ */ Z("div", {
1166
+ className: "flex flex-col gap-1",
1167
+ children: [/* @__PURE__ */ X("span", {
1168
+ className: "text-sm text-foreground",
1169
+ children: t.display?.placeholder || "No document attached"
1170
+ }), !z && /* @__PURE__ */ X("button", {
1171
+ type: "button",
1172
+ className: "self-start rounded-sm border border-border bg-card px-2 py-1 text-xs text-foreground hover:bg-surface-2",
1173
+ onClick: P,
1174
+ disabled: s,
1175
+ "data-testid": "upload",
1176
+ children: "Upload"
1177
+ })]
1178
+ }),
1179
+ !z && /* @__PURE__ */ X("input", {
1180
+ ref: D,
1181
+ type: "file",
1182
+ accept: M || void 0,
1183
+ onChange: F,
1184
+ style: { display: "none" },
1185
+ "data-testid": `file-input-${n}`
1186
+ }),
1187
+ f === "error" && g && /* @__PURE__ */ X("div", {
1188
+ className: "ml-auto text-xs text-destructive",
1189
+ role: "alert",
1190
+ children: g.message
1191
+ })
1192
+ ]
1193
+ }) : /* @__PURE__ */ Z("div", {
1194
+ "data-testid": `file-widget-${n}`,
1195
+ className: "flex items-center gap-3 rounded-md border border-border bg-surface p-3",
1196
+ "aria-busy": f === "uploading" || void 0,
1197
+ "aria-invalid": f === "error" || void 0,
1198
+ children: [
1199
+ /* @__PURE__ */ X(dn, { contentType: u?.content_type }),
1200
+ /* @__PURE__ */ Z("div", {
1201
+ className: "flex min-w-0 flex-1 flex-col gap-1",
1202
+ children: [
1203
+ y && u ? /* @__PURE__ */ X("input", {
1204
+ type: "text",
1205
+ className: "rounded-sm border border-border bg-card px-1 py-0.5 text-sm text-foreground",
1206
+ value: C,
1207
+ autoFocus: !0,
1208
+ onChange: (e) => w(e.target.value),
1209
+ onBlur: R,
1210
+ onKeyDown: (e) => {
1211
+ e.key === "Enter" ? R() : e.key === "Escape" && (S(!1), w(u.filename));
1212
+ },
1213
+ "data-testid": "filename-input"
1214
+ }) : /* @__PURE__ */ X("button", {
1215
+ type: "button",
1216
+ className: "truncate text-left text-sm font-medium text-foreground hover:underline",
1217
+ onClick: () => !z && u && S(!0),
1218
+ disabled: z || s || !u,
1219
+ title: u?.filename,
1220
+ "data-testid": "filename",
1221
+ children: u?.filename ?? "Uploading…"
1222
+ }),
1223
+ /* @__PURE__ */ Z("div", {
1224
+ className: "flex flex-wrap gap-2 text-xs text-muted-foreground",
1225
+ children: [
1226
+ u && /* @__PURE__ */ X("span", { children: x(u.size_bytes) }),
1227
+ u?.page_count != null && /* @__PURE__ */ Z("span", { children: [u.page_count, " pages"] }),
1228
+ u?.uploaded_at && /* @__PURE__ */ X("span", { children: pn(u.uploaded_at) }),
1229
+ u?.uploaded_by && /* @__PURE__ */ Z("span", { children: ["by ", u.uploaded_by] }),
1230
+ u?.version?.number != null && /* @__PURE__ */ Z("span", {
1231
+ "data-testid": "version-badge",
1232
+ children: ["v", u.version.number]
1233
+ })
1234
+ ]
1235
+ }),
1236
+ f === "uploading" && /* @__PURE__ */ Z("div", {
1237
+ className: "text-xs text-muted-foreground",
1238
+ role: "progressbar",
1239
+ "aria-valuenow": m?.pct ?? 0,
1240
+ "aria-valuemin": 0,
1241
+ "aria-valuemax": 100,
1242
+ "data-testid": "upload-progress",
1243
+ children: [
1244
+ "Uploading ",
1245
+ m?.pct ?? 0,
1246
+ "%"
1247
+ ]
1248
+ }),
1249
+ f === "error" && g && /* @__PURE__ */ X("div", {
1250
+ className: "text-xs text-destructive",
1251
+ role: "alert",
1252
+ children: g.message
1253
+ })
1254
+ ]
1255
+ }),
1256
+ /* @__PURE__ */ Z("div", {
1257
+ className: "flex flex-none items-center gap-1",
1258
+ children: [u && f !== "uploading" && /* @__PURE__ */ Z(Y, { children: [
1259
+ /* @__PURE__ */ X("button", {
1260
+ type: "button",
1261
+ className: "rounded-sm border border-border bg-card px-2 py-1 text-xs text-foreground hover:bg-surface-2",
1262
+ onClick: L,
1263
+ "data-testid": "download",
1264
+ children: "Download"
1265
+ }),
1266
+ /* @__PURE__ */ X("button", {
1267
+ type: "button",
1268
+ className: "rounded-sm border border-border bg-card px-2 py-1 text-xs text-foreground hover:bg-surface-2 disabled:cursor-not-allowed disabled:opacity-50",
1269
+ onClick: ne,
1270
+ disabled: !te,
1271
+ title: te ? void 0 : "Preview is available only for images and PDFs",
1272
+ "data-testid": "preview",
1273
+ children: "Preview"
1274
+ }),
1275
+ !z && /* @__PURE__ */ Z(Y, { children: [/* @__PURE__ */ X("button", {
1276
+ type: "button",
1277
+ className: "rounded-sm border border-border bg-card px-2 py-1 text-xs text-foreground hover:bg-surface-2",
1278
+ onClick: P,
1279
+ disabled: s,
1280
+ "data-testid": "replace",
1281
+ children: "Replace"
1282
+ }), /* @__PURE__ */ X("button", {
1283
+ type: "button",
1284
+ className: "rounded-sm border border-border bg-card px-2 py-1 text-xs text-destructive hover:bg-surface-2",
1285
+ onClick: I,
1286
+ disabled: s,
1287
+ "data-testid": "remove",
1288
+ children: "Remove"
1289
+ })] })
1290
+ ] }), f === "uploading" && /* @__PURE__ */ X("button", {
1291
+ type: "button",
1292
+ className: "rounded-sm border border-border bg-card px-2 py-1 text-xs",
1293
+ onClick: ee,
1294
+ "data-testid": "cancel-upload",
1295
+ children: "Cancel"
1296
+ })]
1297
+ }),
1298
+ !z && /* @__PURE__ */ X("input", {
1299
+ ref: D,
1300
+ type: "file",
1301
+ accept: M || void 0,
1302
+ onChange: F,
1303
+ style: { display: "none" },
1304
+ "data-testid": `file-input-${n}`
1305
+ })
1306
+ ]
1307
+ });
1308
+ }
1309
+ function pn(e) {
1310
+ let t = new Date(e);
1311
+ return isNaN(t.getTime()) ? e : t.toISOString().slice(0, 10);
1312
+ }
1313
+ //#endregion
1314
+ //#region src/components/file-widgets/FileList.tsx
1315
+ function mn(e) {
1316
+ return e ? (e.split("/")[1] ?? e).toUpperCase().slice(0, 6) : "";
1317
+ }
1318
+ function hn(e) {
1319
+ let { field: t, fieldName: n, value: r, onChange: a, mode: o, disabled: s } = e, c = Oe(r), [l, u] = J([]), { register: f, unregister: p, isDraft: m } = b(), h = q(c);
1320
+ h.current = c;
1321
+ let g = q(null), v = q(/* @__PURE__ */ new Set()), y = q([]);
1322
+ y.current = l;
1323
+ let { open: S } = Ee();
1324
+ G(() => () => {
1325
+ y.current.forEach((e) => e.abort());
1326
+ }, []);
1327
+ let C = (t.accepts ?? []).join(","), w = o === "display", T = W(async (r) => {
1328
+ let o = i(r, t.accepts, t.max_size_bytes), s = `row-${Math.random().toString(36).slice(2)}-${Date.now()}`, c = new AbortController();
1329
+ if (o) {
1330
+ u((e) => [...e, {
1331
+ localId: s,
1332
+ filename: r.name,
1333
+ progress: null,
1334
+ error: o,
1335
+ abort: () => {}
1336
+ }]);
1337
+ return;
1338
+ }
1339
+ u((e) => [...e, {
1340
+ localId: s,
1341
+ filename: r.name,
1342
+ progress: {
1343
+ loaded: 0,
1344
+ total: r.size,
1345
+ pct: 0
1346
+ },
1347
+ error: null,
1348
+ abort: () => c.abort()
1349
+ }]);
1350
+ try {
1351
+ let t = await ge({
1352
+ file: r,
1353
+ entityCode: e.entityCode,
1354
+ fieldCode: n,
1355
+ signal: c.signal,
1356
+ onProgress: (e) => u((t) => t.map((t) => t.localId === s ? {
1357
+ ...t,
1358
+ progress: e
1359
+ } : t))
1360
+ });
1361
+ if (v.current.delete(s)) {
1362
+ _(t.id).catch(() => {}), p(t.id);
1363
+ return;
1364
+ }
1365
+ f(t.id, () => _(t.id));
1366
+ let i = {
1367
+ id: t.id,
1368
+ filename: t.filename,
1369
+ content_type: t.content_type,
1370
+ size_bytes: t.size_bytes,
1371
+ sha256: t.sha256,
1372
+ width: t.width,
1373
+ height: t.height,
1374
+ url: t.url,
1375
+ metadata: t.metadata
1376
+ }, o = [...h.current, i];
1377
+ h.current = o, a?.(o), u((e) => e.filter((e) => e.localId !== s));
1378
+ } catch (e) {
1379
+ if (e instanceof d && e.code === "ABORTED") {
1380
+ u((e) => e.filter((e) => e.localId !== s));
1381
+ return;
1382
+ }
1383
+ let t = e instanceof d ? {
1384
+ code: e.code,
1385
+ message: e.message
1386
+ } : {
1387
+ code: "UNKNOWN",
1388
+ message: e instanceof Error ? e.message : "Upload failed"
1389
+ };
1390
+ u((e) => e.map((e) => e.localId === s ? {
1391
+ ...e,
1392
+ error: t,
1393
+ progress: null,
1394
+ abort: () => {}
1395
+ } : e));
1396
+ }
1397
+ }, [
1398
+ t.accepts,
1399
+ t.max_size_bytes,
1400
+ n,
1401
+ a,
1402
+ e.entityCode,
1403
+ f,
1404
+ p
1405
+ ]), E = W((e) => {
1406
+ Array.from(e).forEach((e) => void T(e));
1407
+ }, [T]), D = W(() => {
1408
+ s || g.current?.click();
1409
+ }, [s]), O = W((e) => {
1410
+ let t = e.target.files;
1411
+ e.target.value = "", t && t.length > 0 && E(t);
1412
+ }, [E]), k = W((e) => {
1413
+ m(e) && (_(e).catch(() => {}), p(e)), a?.(c.filter((t) => t.id !== e));
1414
+ }, [
1415
+ m,
1416
+ c,
1417
+ a,
1418
+ p
1419
+ ]), A = W((e) => {
1420
+ S(e.id, "download", we(e));
1421
+ }, [S]);
1422
+ return /* @__PURE__ */ Z("div", {
1423
+ "data-testid": `file-widget-${n}`,
1424
+ className: "flex flex-col gap-2",
1425
+ children: [/* @__PURE__ */ Z("ul", {
1426
+ className: "flex flex-col divide-y divide-divider rounded-md border border-border bg-surface",
1427
+ children: [
1428
+ c.length === 0 && l.length === 0 && /* @__PURE__ */ X("li", {
1429
+ className: "px-3 py-4 text-center text-sm text-muted-foreground",
1430
+ children: t.display?.placeholder || "No files"
1431
+ }),
1432
+ c.map((e) => /* @__PURE__ */ Z("li", {
1433
+ className: "flex items-center gap-3 px-3 py-2",
1434
+ "data-testid": `row-${e.id}`,
1435
+ children: [
1436
+ /* @__PURE__ */ X("span", {
1437
+ className: "flex-none rounded-sm border border-border bg-surface-3 px-1.5 py-0.5 text-[10px] text-muted-foreground",
1438
+ children: mn(e.content_type)
1439
+ }),
1440
+ /* @__PURE__ */ X("button", {
1441
+ type: "button",
1442
+ onClick: () => A(e),
1443
+ className: "min-w-0 flex-1 truncate text-left text-sm text-foreground hover:underline",
1444
+ title: e.filename,
1445
+ children: e.filename
1446
+ }),
1447
+ /* @__PURE__ */ X("span", {
1448
+ className: "flex-none text-xs text-muted-foreground",
1449
+ children: x(e.size_bytes)
1450
+ }),
1451
+ /* @__PURE__ */ X("button", {
1452
+ type: "button",
1453
+ className: "flex-none rounded-sm border border-border bg-card px-2 py-0.5 text-xs text-foreground hover:bg-surface-2",
1454
+ onClick: () => A(e),
1455
+ "data-testid": `download-${e.id}`,
1456
+ children: "Download"
1457
+ }),
1458
+ !w && /* @__PURE__ */ X("button", {
1459
+ type: "button",
1460
+ className: "flex-none rounded-sm border border-border bg-card px-2 py-0.5 text-xs text-destructive hover:bg-surface-2",
1461
+ onClick: () => k(e.id),
1462
+ disabled: s,
1463
+ "data-testid": `remove-${e.id}`,
1464
+ children: "Remove"
1465
+ })
1466
+ ]
1467
+ }, e.id)),
1468
+ l.map((e) => /* @__PURE__ */ Z("li", {
1469
+ className: "flex items-center gap-3 px-3 py-2",
1470
+ "data-testid": `pending-row-${e.localId}`,
1471
+ "aria-busy": !e.error,
1472
+ "aria-invalid": !!e.error || void 0,
1473
+ children: [
1474
+ /* @__PURE__ */ X("span", {
1475
+ className: "flex-none truncate text-sm text-foreground",
1476
+ title: e.filename,
1477
+ children: e.filename
1478
+ }),
1479
+ /* @__PURE__ */ X("span", { className: "flex-1" }),
1480
+ e.error ? /* @__PURE__ */ X("span", {
1481
+ role: "alert",
1482
+ className: "text-xs text-destructive",
1483
+ children: e.error.message
1484
+ }) : /* @__PURE__ */ Z("span", {
1485
+ className: "text-xs text-muted-foreground",
1486
+ role: "progressbar",
1487
+ "aria-valuenow": e.progress?.pct ?? 0,
1488
+ "aria-valuemin": 0,
1489
+ "aria-valuemax": 100,
1490
+ children: [e.progress?.pct ?? 0, "%"]
1491
+ }),
1492
+ /* @__PURE__ */ X("button", {
1493
+ type: "button",
1494
+ className: "flex-none rounded-sm border border-border bg-card px-2 py-0.5 text-xs",
1495
+ onClick: () => {
1496
+ e.abort(), v.current.add(e.localId), u((t) => t.filter((t) => t.localId !== e.localId));
1497
+ },
1498
+ children: e.error ? "Dismiss" : "Cancel"
1499
+ })
1500
+ ]
1501
+ }, e.localId))
1502
+ ]
1503
+ }), !w && /* @__PURE__ */ Z(Y, { children: [/* @__PURE__ */ X("button", {
1504
+ type: "button",
1505
+ className: "self-start rounded-sm border border-border bg-card px-2 py-1 text-xs text-foreground hover:bg-surface-2",
1506
+ onClick: D,
1507
+ disabled: s,
1508
+ "data-testid": "add-files",
1509
+ children: "Add files"
1510
+ }), /* @__PURE__ */ X("input", {
1511
+ ref: g,
1512
+ type: "file",
1513
+ accept: C || void 0,
1514
+ multiple: !0,
1515
+ onChange: O,
1516
+ style: { display: "none" },
1517
+ "data-testid": `file-input-${n}`
1518
+ })] })]
1519
+ });
1520
+ }
1521
+ //#endregion
1522
+ //#region src/components/file-widgets/LabeledSlots.tsx
1523
+ function gn(e) {
1524
+ return !e || Array.isArray(e) || typeof e != "object" ? {} : e;
1525
+ }
1526
+ function _n(e) {
1527
+ return e.split("_").filter(Boolean).map((e) => e.slice(0, 1).toUpperCase() + e.slice(1)).join(" ");
1528
+ }
1529
+ function vn(e, t) {
1530
+ return t?.content_type?.startsWith("image/") ? !0 : (e?.accepts ?? []).some((e) => e === "image/*" || e.startsWith("image/"));
1531
+ }
1532
+ function yn(e, t, n, r) {
1533
+ return {
1534
+ ...e,
1535
+ name: `${e.name}.${t}`,
1536
+ mode: "single",
1537
+ accepts: n?.accepts ?? e.accepts,
1538
+ max_size_bytes: n?.max_size_bytes ?? e.max_size_bytes,
1539
+ slots: void 0,
1540
+ display: {
1541
+ ...e.display ?? { widget: "document_card" },
1542
+ widget: vn(n, r) ? "square_image" : "document_card",
1543
+ aspect_ratio: n?.aspect_ratio ?? e.display?.aspect_ratio,
1544
+ placeholder: e.display?.placeholder ?? _n(t)
1545
+ }
1546
+ };
1547
+ }
1548
+ function bn(e) {
1549
+ let { field: t, fieldName: n, entityCode: r, value: i, onChange: a, mode: o, disabled: s } = e, c = Object.entries(t.slots ?? {}), l = gn(i);
1550
+ return c.length === 0 ? /* @__PURE__ */ X("span", {
1551
+ className: "text-sm text-muted-foreground",
1552
+ children: "No slots configured"
1553
+ }) : /* @__PURE__ */ X("div", {
1554
+ style: {
1555
+ display: "grid",
1556
+ gap: 12
1557
+ },
1558
+ children: c.map(([e, i]) => {
1559
+ let c = l[e] ?? null, u = yn(t, e, i, c), d = u.display?.widget ?? "document_card", f = Ut(d);
1560
+ return f ? /* @__PURE__ */ Z("div", {
1561
+ style: {
1562
+ display: "grid",
1563
+ gap: 6
1564
+ },
1565
+ children: [/* @__PURE__ */ X("div", {
1566
+ style: {
1567
+ fontSize: 12,
1568
+ fontWeight: 600,
1569
+ color: "var(--text-2)"
1570
+ },
1571
+ children: _n(e)
1572
+ }), /* @__PURE__ */ X(f, {
1573
+ field: u,
1574
+ fieldName: e,
1575
+ entityCode: r,
1576
+ value: c,
1577
+ mode: o,
1578
+ disabled: s,
1579
+ uploadFieldCode: n,
1580
+ uploadSlotCode: e,
1581
+ onChange: (t) => {
1582
+ a && a({
1583
+ ...l,
1584
+ [e]: t ?? null
1585
+ });
1586
+ }
1587
+ })]
1588
+ }, e) : /* @__PURE__ */ Z("div", {
1589
+ style: {
1590
+ display: "grid",
1591
+ gap: 6
1592
+ },
1593
+ children: [/* @__PURE__ */ X("div", {
1594
+ style: {
1595
+ fontSize: 12,
1596
+ fontWeight: 600,
1597
+ color: "var(--text-2)"
1598
+ },
1599
+ children: _n(e)
1600
+ }), /* @__PURE__ */ X("span", {
1601
+ className: "text-sm text-muted-foreground",
1602
+ children: `Unknown file widget: ${d}`
1603
+ })]
1604
+ }, e);
1605
+ })
1606
+ });
1607
+ }
1608
+ //#endregion
1609
+ //#region src/components/file-widgets/builtins.ts
1610
+ var xn = !1;
1611
+ function Sn() {
1612
+ xn ||= (Ht("square_image", an), Ht("circle_image", on), Ht("wide_banner", sn), Ht("grid", un), Ht("document_card", fn), Ht("file_list", hn), Ht("labeled_slots", bn), !0);
1613
+ }
1614
+ //#endregion
1615
+ //#region src/components/file-widgets/host.tsx
1616
+ Sn();
1617
+ function Cn(e, t) {
1618
+ return e.files?.get(t);
1619
+ }
1620
+ function wn(e, t) {
1621
+ return Object.prototype.hasOwnProperty.call(e, t) ? e[t] ?? null : e.$files?.[t] ?? null;
1622
+ }
1623
+ function Tn(e, t, n) {
1624
+ if (Cn(e, n)) return wn(t, n);
1625
+ let r = e.fields.get(n);
1626
+ return r?.type === "rich_text" && r.files?.mode === "rich_text_inline" ? O(t[n], wn(t, n)) : t[n];
1627
+ }
1628
+ function En(e, t, n) {
1629
+ let r = e.fields.get(t);
1630
+ return r?.type === "rich_text" && r.files?.mode === "rich_text_inline" ? k(n) : n;
1631
+ }
1632
+ function Dn(e, t, n) {
1633
+ let r = Cn(e, t);
1634
+ if (r) return r.name || t;
1635
+ let i = e.fields.get(t);
1636
+ return i ? S(i, t, n) : t;
1637
+ }
1638
+ function On(e) {
1639
+ let { entity: t, entityCode: n, fieldName: r, record: i, mode: a, onChange: o, refs: s, disabled: c, surface: l, entities: u, screens: d, locale: f, fieldId: p, labelId: m } = e, h = Cn(t, r);
1640
+ if (h) {
1641
+ let e = h.display?.widget ?? "", t = Ut(e);
1642
+ return t ? /* @__PURE__ */ X(t, {
1643
+ field: h,
1644
+ fieldName: r,
1645
+ entityCode: n,
1646
+ value: wn(i, r),
1647
+ mode: a,
1648
+ onChange: o,
1649
+ disabled: c,
1650
+ fieldId: p
1651
+ }) : /* @__PURE__ */ X("span", {
1652
+ className: "text-sm text-muted-foreground",
1653
+ children: e ? `Unknown file widget: ${e}` : "Missing file widget"
1654
+ });
1655
+ }
1656
+ let g = t.fields.get(r);
1657
+ return g ? V({
1658
+ field: g,
1659
+ entityCode: n,
1660
+ fieldName: r,
1661
+ value: Tn(t, i, r),
1662
+ mode: a,
1663
+ onChange: o,
1664
+ record: i,
1665
+ refs: s,
1666
+ surface: l,
1667
+ entity: n && u ? u[n] : void 0,
1668
+ entities: u,
1669
+ screens: d,
1670
+ locale: f,
1671
+ fieldId: p,
1672
+ labelId: m
1673
+ }) : null;
1674
+ }
1675
+ //#endregion
1676
+ //#region src/components/file-widgets/payload.ts
1677
+ function kn(e) {
1678
+ return !e || Array.isArray(e) ? null : e;
1679
+ }
1680
+ function An(e) {
1681
+ return Array.isArray(e) ? e : [];
1682
+ }
1683
+ function jn(e) {
1684
+ return !e || Array.isArray(e) || typeof e != "object" ? {} : e;
1685
+ }
1686
+ function Mn(e, t) {
1687
+ return e.mode === "array" ? An(t) : e.mode === "named_map" ? jn(t) : kn(t);
1688
+ }
1689
+ function Nn(e, t, n, r) {
1690
+ let i = {
1691
+ file_id: e.id,
1692
+ filename: e.filename
1693
+ };
1694
+ return r && (i.slot = r), n && (i.position = t), e.metadata !== void 0 && (i.metadata = e.metadata), i;
1695
+ }
1696
+ function Pn(e, t) {
1697
+ if (e.mode === "array") {
1698
+ let e = An(t);
1699
+ return e.length === 0 ? { clear: !0 } : { set: e.map((e, t) => Nn(e, t, !0)) };
1700
+ }
1701
+ if (e.mode === "named_map") {
1702
+ let e = jn(t), n = Object.entries(e).filter(([, e]) => e != null).map(([e, t]) => Nn(t, 0, !1, e));
1703
+ return n.length === 0 ? { clear: !0 } : { set: n };
1704
+ }
1705
+ let n = kn(t);
1706
+ return n ? { set: [Nn(n, 0, !0)] } : { clear: !0 };
1707
+ }
1708
+ function Fn(e) {
1709
+ return JSON.stringify(e);
1710
+ }
1711
+ function In(e) {
1712
+ let { entity: t, formData: n, record: r, isNew: i } = e, a = {};
1713
+ for (let e of t.files?.names() ?? []) {
1714
+ if (!Object.prototype.hasOwnProperty.call(n, e)) continue;
1715
+ let o = Cn(t, e);
1716
+ if (!o) continue;
1717
+ let s = Mn(o, n[e]);
1718
+ if (i) {
1719
+ if (o.mode === "array" ? An(s).length === 0 : o.mode === "named_map" ? Object.values(jn(s)).every((e) => e == null) : kn(s) == null) continue;
1720
+ a[e] = Pn(o, s);
1721
+ continue;
1722
+ }
1723
+ let c = Mn(o, r ? wn(r, e) : null), l = Pn(o, s), u = Pn(o, c);
1724
+ Fn(l) !== Fn(u) && (a[e] = l);
1725
+ }
1726
+ let o = t.fields;
1727
+ if (!o) return a;
1728
+ for (let e of o.names()) {
1729
+ let s = o.get(e)?.files;
1730
+ if (!s || s.mode !== "rich_text_inline" || !Object.prototype.hasOwnProperty.call(n, e)) continue;
1731
+ let c = Rn(s, n[e]);
1732
+ if (i) {
1733
+ if (c.clear) continue;
1734
+ a[e] = c;
1735
+ continue;
1736
+ }
1737
+ let l = Rn(s, r ? Tn({
1738
+ ...t,
1739
+ fields: o
1740
+ }, r, e) : null);
1741
+ Fn(c) !== Fn(l) && (a[e] = c);
1742
+ }
1743
+ return a;
1744
+ }
1745
+ function Ln(e) {
1746
+ let t = [];
1747
+ for (let n of Object.values(e)) for (let e of n.set ?? []) t.push(e.file_id);
1748
+ return t;
1749
+ }
1750
+ function Rn(e, t) {
1751
+ if (e.mode !== "rich_text_inline") return { clear: !0 };
1752
+ let n = E(k(t));
1753
+ return n.length === 0 ? { clear: !0 } : { set: n.map((e, t) => ({
1754
+ file_id: e,
1755
+ position: t
1756
+ })) };
1757
+ }
1758
+ var zn = 1200, Bn = null, Vn = null;
1759
+ function Hn() {
1760
+ return !Bn || !Vn ? null : `declarion::${Bn}::${Vn}::listlayout`;
1761
+ }
1762
+ function Un() {
1763
+ return {
1764
+ v: 2,
1765
+ widths: {},
1766
+ resizeEduShown: !1
1767
+ };
1768
+ }
1769
+ function Wn(e) {
1770
+ if (typeof e != "object" || !e) return {};
1771
+ let t = {};
1772
+ for (let [n, r] of Object.entries(e)) typeof r == "number" && Number.isFinite(r) && r >= 60 && (t[n] = r);
1773
+ return t;
1774
+ }
1775
+ function Gn(e) {
1776
+ let t;
1777
+ try {
1778
+ t = JSON.parse(e);
1779
+ } catch {
1780
+ return null;
1781
+ }
1782
+ if (typeof t != "object" || !t) return null;
1783
+ let n = t;
1784
+ if (n.v !== 2) return null;
1785
+ let r = {};
1786
+ if (n.widths && typeof n.widths == "object") for (let [e, t] of Object.entries(n.widths)) r[e] = Wn(t);
1787
+ return {
1788
+ v: 2,
1789
+ widths: r,
1790
+ resizeEduShown: n.resizeEduShown === !0
1791
+ };
1792
+ }
1793
+ function Kn(e) {
1794
+ if (typeof window > "u") return;
1795
+ let t = Hn();
1796
+ if (t) try {
1797
+ localStorage.setItem(t, JSON.stringify(e));
1798
+ } catch {}
1799
+ }
1800
+ function qn(e, t) {
1801
+ return {
1802
+ v: 2,
1803
+ widths: {
1804
+ ...e.widths,
1805
+ ...t.widths
1806
+ },
1807
+ resizeEduShown: e.resizeEduShown || t.resizeEduShown
1808
+ };
1809
+ }
1810
+ function Jn(e) {
1811
+ return Math.min(zn, Math.max(60, Math.round(e)));
1812
+ }
1813
+ var Yn = We((e) => ({
1814
+ ...Un(),
1815
+ setScope: (e, t) => {
1816
+ Bn = e, Vn = t;
1817
+ },
1818
+ hydrate: () => {
1819
+ if (typeof window > "u") return;
1820
+ let t = Hn();
1821
+ if (!t) {
1822
+ e(Un());
1823
+ return;
1824
+ }
1825
+ let n = localStorage.getItem(t);
1826
+ e((n ? Gn(n) : null) ?? Un());
1827
+ },
1828
+ setWidth: (t, n, r) => {
1829
+ e((e) => {
1830
+ let i = {
1831
+ ...e.widths[t] ?? {},
1832
+ [n]: Jn(r)
1833
+ }, a = {
1834
+ ...e,
1835
+ widths: {
1836
+ ...e.widths,
1837
+ [t]: i
1838
+ }
1839
+ };
1840
+ return Kn(a), a;
1841
+ });
1842
+ },
1843
+ setWidths: (t, n) => {
1844
+ e((e) => {
1845
+ let r = {};
1846
+ for (let [e, t] of Object.entries(n)) r[e] = Jn(t);
1847
+ let i = {
1848
+ ...e.widths[t] ?? {},
1849
+ ...r
1850
+ }, a = {
1851
+ ...e,
1852
+ widths: {
1853
+ ...e.widths,
1854
+ [t]: i
1855
+ }
1856
+ };
1857
+ return Kn(a), a;
1858
+ });
1859
+ },
1860
+ resetWidths: (t) => {
1861
+ e((e) => {
1862
+ let n = {
1863
+ ...e,
1864
+ widths: {
1865
+ ...e.widths,
1866
+ [t]: {}
1867
+ }
1868
+ };
1869
+ return Kn(n), n;
1870
+ });
1871
+ },
1872
+ prune: (t, n) => {
1873
+ let r = new Set(n);
1874
+ e((e) => {
1875
+ let n = e.widths[t];
1876
+ if (!n) return e;
1877
+ let i = {}, a = !1;
1878
+ for (let [e, t] of Object.entries(n)) r.has(e) ? i[e] = t : a = !0;
1879
+ if (!a) return e;
1880
+ let o = {
1881
+ ...e,
1882
+ widths: {
1883
+ ...e.widths,
1884
+ [t]: i
1885
+ }
1886
+ };
1887
+ return Kn(o), o;
1888
+ });
1889
+ },
1890
+ markResizeEduShown: () => {
1891
+ e((e) => {
1892
+ if (e.resizeEduShown) return e;
1893
+ let t = {
1894
+ ...e,
1895
+ resizeEduShown: !0
1896
+ };
1897
+ return Kn(t), t;
1898
+ });
1899
+ }
1900
+ })), Xn = !1;
1901
+ function Zn() {
1902
+ typeof window > "u" || Xn || (Xn = !0, window.addEventListener("storage", (e) => {
1903
+ let t = Hn();
1904
+ if (!t || e.key !== t || e.newValue == null) return;
1905
+ let n = Gn(e.newValue);
1906
+ n && Yn.setState((e) => qn(e, n));
1907
+ }));
1908
+ }
1909
+ var Qn = {}, $n = () => {};
1910
+ function er(e) {
1911
+ let t = !!e && Hn() !== null, n = Yn((t) => e ? t.widths[e] : void 0), r = Yn((e) => e.resizeEduShown === !0), i = W((n, r) => {
1912
+ t && e && Yn.getState().setWidth(e, n, r);
1913
+ }, [t, e]), a = W((n) => {
1914
+ t && e && Yn.getState().setWidths(e, n);
1915
+ }, [t, e]), o = W(() => {
1916
+ t && e && Yn.getState().resetWidths(e);
1917
+ }, [t, e]), s = W((n) => {
1918
+ t && e && Yn.getState().prune(e, n);
1919
+ }, [t, e]), c = W(() => {
1920
+ t && Yn.getState().markResizeEduShown();
1921
+ }, [t]);
1922
+ return {
1923
+ widths: t ? n ?? Qn : Qn,
1924
+ resizeEduShown: r,
1925
+ setWidth: t ? i : $n,
1926
+ setWidths: t ? a : $n,
1927
+ resetWidths: t ? o : $n,
1928
+ prune: t ? s : $n,
1929
+ markResizeEduShown: t ? c : $n
1930
+ };
1931
+ }
1932
+ //#endregion
1933
+ //#region src/hooks/useChildrenData.ts
1934
+ var tr = "entity-children";
1935
+ function nr(e, t, n, r, i, a) {
1936
+ let o = Array.isArray(r) ? r : [r], c = Array.isArray(r) ? s(t, o.length) : [t];
1937
+ return He({
1938
+ queryKey: [
1939
+ tr,
1940
+ e,
1941
+ t,
1942
+ n,
1943
+ i,
1944
+ a
1945
+ ],
1946
+ queryFn: () => {
1947
+ let e = new URLSearchParams();
1948
+ if (!c) throw Error("invalid composite parent id");
1949
+ let t = o.map((e, t) => ({
1950
+ field: e,
1951
+ op: "eq",
1952
+ value: c[t]
1953
+ }));
1954
+ return e.set("filters", JSON.stringify(t)), e.set("preview", "true"), i && e.set("sort", i), a && e.set("limit", String(a)), g(`/api/data/${n}?${e.toString()}`);
1955
+ },
1956
+ enabled: !!e && !!t && !!n && !!r && c !== null
1957
+ });
1958
+ }
1959
+ //#endregion
1960
+ //#region src/stores/realtime.ts
1961
+ var rr = We((e, t) => ({
1962
+ degradedEntities: /* @__PURE__ */ new Set(),
1963
+ markDegraded: (n) => {
1964
+ if (!n || t().degradedEntities.has(n)) return;
1965
+ let r = new Set(t().degradedEntities);
1966
+ r.add(n), e({ degradedEntities: r });
1967
+ }
1968
+ }));
1969
+ function ir(e, t, n) {
1970
+ return e === !0 && !t.has(n);
1971
+ }
1972
+ //#endregion
1973
+ //#region src/hooks/useAssociatedData.ts
1974
+ function ar(e, t, n, r, i, a, o, s) {
1975
+ return Be({
1976
+ queryKey: [
1977
+ tr,
1978
+ e,
1979
+ t,
1980
+ n,
1981
+ i,
1982
+ a,
1983
+ o,
1984
+ s ? JSON.stringify(Object.entries(s).sort()) : void 0
1985
+ ],
1986
+ queryFn: ({ pageParam: e }) => {
1987
+ let c = new URLSearchParams(), l = [{
1988
+ field: r,
1989
+ op: "eq",
1990
+ value: t
1991
+ }];
1992
+ if (s) for (let [e, t] of Object.entries(s)) t && t !== "__all__" && l.push({
1993
+ field: e,
1994
+ op: "eq",
1995
+ value: t
1996
+ });
1997
+ return c.set("filters", JSON.stringify(l)), i && c.set("sort", i), a && c.set("limit", String(a)), o && c.set("search", o), e && c.set("after", e), g(`/api/data/${n}?${c.toString()}`);
1998
+ },
1999
+ getNextPageParam: (e) => e.meta?.has_more ? e.meta.cursor : void 0,
2000
+ initialPageParam: void 0,
2001
+ enabled: !!e && !!t && !!n && !!r
2002
+ });
2003
+ }
2004
+ //#endregion
2005
+ //#region src/components/shared/ActionButton.tsx
2006
+ function or({ actionCode: n, action: r, entityCode: i, objectIds: o = [], row: s, variant: c = "outline", size: l = "default", onSuccess: u }) {
2007
+ let [d, f] = J(!1), [p, m] = J(!1), { data: h } = ae(), g = Bt(), { run: _ } = re(), v = C(r), b = !s || F(r.conditions, s), x = W(async () => {
2008
+ if (!(!r.association || o.length === 0)) {
2009
+ f(!0);
2010
+ try {
2011
+ let e = await T(i ? `${i}.${r.association}` : r.association, o), t = a(h, e.target_entity);
2012
+ if (!t) {
2013
+ B.error(`No list screen found for ${e.target_entity}`);
2014
+ return;
2015
+ }
2016
+ let n = h?.entities[e.target_entity], s = w(r.display?.name) || e.target_entity;
2017
+ if (e.ids.length === 0) {
2018
+ B.info(`No related ${s} found`);
2019
+ return;
2020
+ }
2021
+ let c = n?.fields.names().find((e) => n.fields.get(e)?.primary) ?? "id", l = new URLSearchParams();
2022
+ l.set(`filter_${c}`, e.ids.join(",")), g(t.route, {
2023
+ title: s,
2024
+ icon: r.display?.icon || t.icon,
2025
+ search: l.toString()
2026
+ }), u?.();
2027
+ } catch (e) {
2028
+ B.error(e instanceof Error ? e.message : "Failed to resolve association");
2029
+ } finally {
2030
+ f(!1);
2031
+ }
2032
+ }
2033
+ }, [
2034
+ r,
2035
+ i,
2036
+ o,
2037
+ h,
2038
+ g,
2039
+ u
2040
+ ]), S = r.entity ? `${r.entity}.${n}` : n, E = o.length > 0 ? o : void 0, D = W(() => {
2041
+ m(!0), _({
2042
+ action: r,
2043
+ title: w(r.display?.name) || n,
2044
+ row: s,
2045
+ entity: i,
2046
+ execute: (e) => me(S, N(e, E)),
2047
+ onSuccess: () => u?.()
2048
+ }).finally(() => m(!1));
2049
+ }, [
2050
+ _,
2051
+ r,
2052
+ n,
2053
+ s,
2054
+ i,
2055
+ S,
2056
+ E,
2057
+ u
2058
+ ]), O = W(() => {
2059
+ if (te(r)) {
2060
+ le(r.ui_steps, { row: s }).then(() => u?.());
2061
+ return;
2062
+ }
2063
+ if (v) {
2064
+ x();
2065
+ return;
2066
+ }
2067
+ if (r.href && !r.handler && !r.association) {
2068
+ let e = y(s, i ? h?.entities[i] : void 0), t = r.href;
2069
+ i && (t = t.replaceAll("${entity}", i)), e && (t = t.replaceAll("${id}", encodeURIComponent(e))), g(t, {
2070
+ title: w(r.display?.name) || n,
2071
+ icon: r.display?.icon
2072
+ }), u?.();
2073
+ return;
2074
+ }
2075
+ D();
2076
+ }, [
2077
+ r,
2078
+ s,
2079
+ i,
2080
+ h?.entities,
2081
+ n,
2082
+ g,
2083
+ v,
2084
+ x,
2085
+ D,
2086
+ u
2087
+ ]), k = w(r.display?.name), A = r.display?.icon, j = A && e[A], M = j ? /* @__PURE__ */ X(j, { size: 13 }) : A ? /* @__PURE__ */ X(t, {
2088
+ name: A,
2089
+ size: 13
2090
+ }) : null, P = !b || p || d;
2091
+ return l === "icon" ? /* @__PURE__ */ X(H, {
2092
+ icon: M ?? /* @__PURE__ */ X(e.bolt, { size: 13 }),
2093
+ onClick: O,
2094
+ title: k
2095
+ }) : /* @__PURE__ */ X(U, {
2096
+ kind: c === "default" ? "primary" : c === "ghost" ? "ghost" : "default",
2097
+ size: "sm",
2098
+ icon: M,
2099
+ danger: r.destructive,
2100
+ onClick: O,
2101
+ disabled: P,
2102
+ title: k,
2103
+ "aria-label": k,
2104
+ children: k
2105
+ });
2106
+ }
2107
+ //#endregion
2108
+ //#region src/components/shared/ResponsiveActionBar.tsx
2109
+ function sr(e, t) {
2110
+ return e.replace(/\$\{([^}]+)\}/g, (e, n) => Object.prototype.hasOwnProperty.call(t, n) ? t[n] : e);
2111
+ }
2112
+ function cr(e) {
2113
+ return e.widget ? "widget" : e.href ? "href" : e.handler ? "handler" : e.association ? "association" : e.ui_steps && e.ui_steps.length > 0 ? "ui_steps" : "unknown";
2114
+ }
2115
+ function lr(e, t, n, r, i) {
2116
+ let a = cr(t), o = y(n, r?.entity), s = r?.entityCode ?? "";
2117
+ if (e === "__peek") return i?.({
2118
+ code: e,
2119
+ entity: s,
2120
+ mode: "peek",
2121
+ rowId: o
2122
+ }), r?.openPeek?.(n), !0;
2123
+ if (i?.({
2124
+ code: e,
2125
+ entity: s,
2126
+ mode: a,
2127
+ rowId: o
2128
+ }), a === "widget") return console.warn(`[ResponsiveActionBar] widget "${t.widget}" requested for action "${e}" but the widget registry ships in Phase 2; falling back to onRun.`), !1;
2129
+ if (a === "href" && r) {
2130
+ let e = sr(t.href ?? "", {
2131
+ entity: s,
2132
+ id: encodeURIComponent(o)
2133
+ }), n = e.indexOf("?");
2134
+ return n === -1 ? r.tabNavigate(e) : r.tabNavigate(e.slice(0, n), { search: e.slice(n + 1) }), !0;
2135
+ }
2136
+ return a === "handler" || a === "association" || a === "ui_steps" || a === "unknown" && console.warn(`[ResponsiveActionBar] no dispatch mode set on action "${e}" (none of handler/association/widget/href/ui_steps).`), !1;
2137
+ }
2138
+ function ur(e) {
2139
+ let t = 0;
2140
+ for (let n of e) n.kind === "action" ? t++ : t += ur(n.items);
2141
+ return t;
2142
+ }
2143
+ function dr(e, t, n) {
2144
+ let r = [], i = [];
2145
+ for (let a of e) a.kind === "action" && pr(a.code, t, n)?.destructive ? i.push(a) : r.push(a);
2146
+ return {
2147
+ normal: r,
2148
+ destructive: i
2149
+ };
2150
+ }
2151
+ function fr(e, t, n) {
2152
+ let r = [], i = [], a = [];
2153
+ for (let o of e) {
2154
+ if (o.kind !== "action") {
2155
+ i.push(o);
2156
+ continue;
2157
+ }
2158
+ let e = pr(o.code, t, n), s = e?.destructive === !0, c = e?.display?.primary === !0;
2159
+ if (s && c) {
2160
+ console.warn(`[ResponsiveActionBar] action "${o.code}" declares both primary and destructive; treating as destructive.`), a.push(o);
2161
+ continue;
2162
+ }
2163
+ if (s) {
2164
+ a.push(o);
2165
+ continue;
2166
+ }
2167
+ if (c) {
2168
+ r.push(o);
2169
+ continue;
2170
+ }
2171
+ i.push(o);
2172
+ }
2173
+ return {
2174
+ primary: r,
2175
+ regular: i,
2176
+ destructive: a
2177
+ };
2178
+ }
2179
+ function pr(e, t, n) {
2180
+ if (t && e in t) return t[e];
2181
+ if (n && e in n) return n[e];
2182
+ }
2183
+ function mr(e, t, n) {
2184
+ return w(pr(e, t, n)?.display?.name) || e;
2185
+ }
2186
+ function hr(e, t, n) {
2187
+ return pr(e, t, n)?.display?.icon || void 0;
2188
+ }
2189
+ function gr(e) {
2190
+ return `action-tooltip-${e}`;
2191
+ }
2192
+ function _r({ leaf: e, entityActions: n, globalActions: r, onRun: i, loading: a, onLoadingChange: o, measureRef: s, style: c, row: l, widgetContext: u, onActionClick: d }) {
2193
+ let f = pr(e.code, n, r), m = mr(e.code, n, r), h = hr(e.code, n, r), g = f?.destructive ?? !1, _ = !g && f?.display?.primary === !0, v = !e.enabled, y = v ? gr(e.code) : void 0, b = W(async () => {
2194
+ if (!(!f || v || a)) {
2195
+ o(!0);
2196
+ try {
2197
+ lr(e.code, f, l, u, d) || await Promise.resolve(i(e.code, f));
2198
+ } finally {
2199
+ o(!1);
2200
+ }
2201
+ }
2202
+ }, [
2203
+ f,
2204
+ v,
2205
+ a,
2206
+ i,
2207
+ e.code,
2208
+ o,
2209
+ l,
2210
+ u,
2211
+ d
2212
+ ]), x = a ? /* @__PURE__ */ X(p, { size: 12 }) : h ? /* @__PURE__ */ X(t, {
2213
+ name: h,
2214
+ size: 12
2215
+ }) : null;
2216
+ return /* @__PURE__ */ Z(Y, { children: [y && e.reason && /* @__PURE__ */ X("span", {
2217
+ id: y,
2218
+ role: "tooltip",
2219
+ style: {
2220
+ position: "absolute",
2221
+ width: 1,
2222
+ height: 1,
2223
+ overflow: "hidden",
2224
+ clip: "rect(0,0,0,0)"
2225
+ },
2226
+ children: e.reason
2227
+ }), /* @__PURE__ */ X(U, {
2228
+ ref: s,
2229
+ kind: _ ? "primary" : "default",
2230
+ danger: g,
2231
+ icon: x,
2232
+ disabled: v || a,
2233
+ "aria-disabled": v ? "true" : void 0,
2234
+ "aria-describedby": y,
2235
+ title: R(f, m, v, e.reason),
2236
+ onClick: b,
2237
+ style: c,
2238
+ children: m
2239
+ })] });
2240
+ }
2241
+ function vr({ group: n, entityActions: r, globalActions: i, onRun: a, loading: o, onLoadingChange: s, measureRef: c, style: l, row: u, widgetContext: d, onActionClick: f }) {
2242
+ let m = q(null), [h, g] = J(!1), _ = n.name ? w(n.name) : "Actions", v = W((e) => {
2243
+ m.current = e, c?.(e);
2244
+ }, [c]), y = W((e, t) => (g(!1), a(e, t)), [a]);
2245
+ return /* @__PURE__ */ Z(Y, { children: [/* @__PURE__ */ X(U, {
2246
+ ref: v,
2247
+ kind: "default",
2248
+ icon: o == null ? n.icon ? /* @__PURE__ */ X(t, {
2249
+ name: n.icon,
2250
+ size: 12
2251
+ }) : void 0 : /* @__PURE__ */ X(p, { size: 12 }),
2252
+ iconRight: /* @__PURE__ */ X(e.down, { size: 10 }),
2253
+ "aria-haspopup": "menu",
2254
+ "aria-expanded": h ? "true" : "false",
2255
+ title: _,
2256
+ onClick: () => g((e) => !e),
2257
+ style: l,
2258
+ children: _
2259
+ }), /* @__PURE__ */ X(se, {
2260
+ open: h,
2261
+ anchor: m.current,
2262
+ onClose: () => g(!1),
2263
+ align: "start",
2264
+ width: 200,
2265
+ children: /* @__PURE__ */ X("div", {
2266
+ role: "menu",
2267
+ "aria-label": _,
2268
+ children: n.items.map((e) => e.kind === "action" ? /* @__PURE__ */ X(yr, {
2269
+ leaf: e,
2270
+ entityActions: r,
2271
+ globalActions: i,
2272
+ onRun: y,
2273
+ loading: o === e.code,
2274
+ onLoadingChange: (t) => s(t ? e.code : null),
2275
+ row: u,
2276
+ widgetContext: d,
2277
+ onActionClick: f
2278
+ }, e.code) : /* @__PURE__ */ X(br, {
2279
+ group: e,
2280
+ entityActions: r,
2281
+ globalActions: i,
2282
+ onRun: y,
2283
+ loading: o,
2284
+ onLoadingChange: s,
2285
+ row: u,
2286
+ widgetContext: d,
2287
+ onActionClick: f
2288
+ }, e.items[0]?.kind === "action" ? e.items[0].code : e.icon ?? "group"))
2289
+ })
2290
+ })] });
2291
+ }
2292
+ function yr({ leaf: e, entityActions: n, globalActions: r, onRun: i, loading: a, onLoadingChange: o, row: s, widgetContext: c, onActionClick: l }) {
2293
+ let u = pr(e.code, n, r), d = mr(e.code, n, r), f = hr(e.code, n, r), m = u?.destructive ?? !1, h = !e.enabled, g = h ? gr(e.code) : void 0, _ = a ? /* @__PURE__ */ X(p, { size: 12 }) : f ? /* @__PURE__ */ X(t, {
2294
+ name: f,
2295
+ size: 12
2296
+ }) : null;
2297
+ return /* @__PURE__ */ Z(Y, { children: [g && e.reason && /* @__PURE__ */ X("span", {
2298
+ id: g,
2299
+ role: "tooltip",
2300
+ style: {
2301
+ position: "absolute",
2302
+ width: 1,
2303
+ height: 1,
2304
+ overflow: "hidden",
2305
+ clip: "rect(0,0,0,0)"
2306
+ },
2307
+ children: e.reason
2308
+ }), /* @__PURE__ */ Z("div", {
2309
+ role: "menuitem",
2310
+ "aria-disabled": h ? "true" : void 0,
2311
+ "aria-describedby": g,
2312
+ title: R(u, d, h, e.reason),
2313
+ onClick: async () => {
2314
+ if (!(!u || h || a)) {
2315
+ o(!0);
2316
+ try {
2317
+ lr(e.code, u, s, c, l) || await Promise.resolve(i(e.code, u));
2318
+ } finally {
2319
+ o(!1);
2320
+ }
2321
+ }
2322
+ },
2323
+ style: {
2324
+ display: "flex",
2325
+ alignItems: "center",
2326
+ gap: 8,
2327
+ padding: "6px 10px",
2328
+ borderRadius: 5,
2329
+ fontSize: 12.5,
2330
+ color: m ? "var(--danger)" : h ? "var(--text-3)" : "var(--text-2)",
2331
+ cursor: h ? "not-allowed" : "pointer",
2332
+ opacity: h ? .6 : 1
2333
+ },
2334
+ onMouseEnter: (e) => {
2335
+ h || (e.currentTarget.style.background = "var(--surface-3)");
2336
+ },
2337
+ onMouseLeave: (e) => {
2338
+ e.currentTarget.style.background = "transparent";
2339
+ },
2340
+ children: [_ && /* @__PURE__ */ X("span", {
2341
+ style: {
2342
+ color: m ? "var(--danger)" : "var(--text-3)",
2343
+ display: "flex"
2344
+ },
2345
+ children: _
2346
+ }), /* @__PURE__ */ X("span", {
2347
+ style: { flex: 1 },
2348
+ children: d
2349
+ })]
2350
+ })] });
2351
+ }
2352
+ function br({ group: e, entityActions: t, globalActions: n, onRun: r, loading: i, onLoadingChange: a, row: o, widgetContext: s, onActionClick: c }) {
2353
+ let l = e.name ? w(e.name) : void 0;
2354
+ return /* @__PURE__ */ Z(Y, { children: [l && /* @__PURE__ */ X("div", {
2355
+ style: {
2356
+ padding: "4px 10px 2px",
2357
+ fontSize: 10.5,
2358
+ fontWeight: 600,
2359
+ color: "var(--text-3)",
2360
+ textTransform: "uppercase",
2361
+ letterSpacing: "0.05em"
2362
+ },
2363
+ children: l
2364
+ }), e.items.map((e) => e.kind === "action" ? /* @__PURE__ */ X(yr, {
2365
+ leaf: e,
2366
+ entityActions: t,
2367
+ globalActions: n,
2368
+ onRun: r,
2369
+ loading: i === e.code,
2370
+ onLoadingChange: (t) => a(t ? e.code : null),
2371
+ row: o,
2372
+ widgetContext: s,
2373
+ onActionClick: c
2374
+ }, e.code) : /* @__PURE__ */ X(br, {
2375
+ group: e,
2376
+ entityActions: t,
2377
+ globalActions: n,
2378
+ onRun: r,
2379
+ loading: i,
2380
+ onLoadingChange: a,
2381
+ row: o,
2382
+ widgetContext: s,
2383
+ onActionClick: c
2384
+ }, e.icon ?? "nested"))] });
2385
+ }
2386
+ function xr({ layout: t, entityActions: n, globalActions: r, onRun: i, row: a, widgetContext: o, onActionClick: s }) {
2387
+ let c = q(null), [l, u] = J(!1), [d, f] = J(null), m = W((e, t) => (u(!1), i(e, t)), [i]);
2388
+ return ur(t) === 0 ? null : /* @__PURE__ */ Z("div", {
2389
+ style: {
2390
+ display: "inline-flex",
2391
+ alignItems: "center"
2392
+ },
2393
+ children: [/* @__PURE__ */ X(H, {
2394
+ ref: c,
2395
+ icon: X(d == null ? e.more : p, { size: 14 }),
2396
+ title: "Actions",
2397
+ size: 28,
2398
+ onClick: () => u((e) => !e)
2399
+ }), /* @__PURE__ */ X(se, {
2400
+ open: l,
2401
+ anchor: c.current,
2402
+ onClose: () => u(!1),
2403
+ align: "end",
2404
+ width: 220,
2405
+ children: /* @__PURE__ */ X(Cr, {
2406
+ layout: t,
2407
+ entityActions: n,
2408
+ globalActions: r,
2409
+ onRun: m,
2410
+ loading: d,
2411
+ onLoadingChange: f,
2412
+ row: a,
2413
+ widgetContext: o,
2414
+ onActionClick: s
2415
+ })
2416
+ })]
2417
+ });
2418
+ }
2419
+ function Sr(e) {
2420
+ let t = 0;
2421
+ for (let n of e) if (n.kind === "action" && c(n.code)) t++;
2422
+ else break;
2423
+ return t;
2424
+ }
2425
+ function Cr({ layout: e, entityActions: t, globalActions: n, onRun: r, loading: i, onLoadingChange: a, row: o, widgetContext: s, onActionClick: c, ariaLabel: l = "Row actions" }) {
2426
+ let { normal: u, destructive: d } = dr(e, t, n), f = Sr(u), p = u.slice(0, f), m = u.slice(f), h = d.length > 0, g = m.length > 0, _ = (e) => /* @__PURE__ */ X(yr, {
2427
+ leaf: e,
2428
+ entityActions: t,
2429
+ globalActions: n,
2430
+ onRun: r,
2431
+ loading: i === e.code,
2432
+ onLoadingChange: (t) => a(t ? e.code : null),
2433
+ row: o,
2434
+ widgetContext: s,
2435
+ onActionClick: c
2436
+ }, e.code);
2437
+ return /* @__PURE__ */ Z("div", {
2438
+ role: "menu",
2439
+ "aria-label": l,
2440
+ children: [
2441
+ p.map((e) => e.kind === "action" ? _(e) : null),
2442
+ p.length > 0 && g && /* @__PURE__ */ X(j, { divider: !0 }),
2443
+ m.map((e) => e.kind === "action" ? _(e) : /* @__PURE__ */ X(br, {
2444
+ group: e,
2445
+ entityActions: t,
2446
+ globalActions: n,
2447
+ onRun: r,
2448
+ loading: i,
2449
+ onLoadingChange: a,
2450
+ row: o,
2451
+ widgetContext: s,
2452
+ onActionClick: c
2453
+ }, e.icon ?? "group")),
2454
+ h && /* @__PURE__ */ X(j, { divider: !0 }),
2455
+ d.map((e) => _(e))
2456
+ ]
2457
+ });
2458
+ }
2459
+ var wr = "__overflow_trigger__", Tr = 90, Er = 80;
2460
+ function Dr(e) {
2461
+ return e + 8;
2462
+ }
2463
+ function Or(e, t, n, r, i, a, o, s) {
2464
+ let { primary: c, regular: l, destructive: u } = fr(e, i, a), d = c.length > 0 ? c.reduce((e, t) => e + (r.get(Q(t)) ?? 0), 0) : 0, f = u.length > 0 ? u.reduce((e, t) => e + (r.get(Q(t)) ?? Er), 0) : 0, p = t - n - d - f, m = r.get(wr) ?? Tr, h = 0, g = [], _ = [], v = !1;
2465
+ for (let e of l) {
2466
+ let t = r.get(Q(e)) ?? 0;
2467
+ if (o) {
2468
+ o(e) ? (g.push(e), h += t) : (_.push(e), v = !0);
2469
+ continue;
2470
+ }
2471
+ let n = l.length - g.length - _.length - 1 > 0 || _.length > 0 ? m : 0, i = s && !s.has(Q(e)) ? Dr(m) : 0;
2472
+ h + t + n + i <= p ? (g.push(e), h += t) : (_.push(e), v = !0);
2473
+ }
2474
+ return {
2475
+ primaryInline: c,
2476
+ inline: g,
2477
+ overflow: v ? _ : [],
2478
+ destructiveInline: u
2479
+ };
2480
+ }
2481
+ function Q(e) {
2482
+ return e.kind === "action" ? `action:${e.code}` : `group:${e.name ? w(e.name) : ""}`;
2483
+ }
2484
+ function kr({ layout: n, entityActions: r, globalActions: i, onRun: a, reservedRightWidth: o = 0, measurementOverride: s, ariaLabel: c = "Actions", align: l = "trailing", constrain: u = !0, row: d, widgetContext: f, onActionClick: p }) {
2485
+ let m = q(null), h = q(null), [g, _] = J(0), [v, y] = J(/* @__PURE__ */ new Map()), [b, x] = J(!1), [S, C] = J(null), [T, E] = J(() => typeof document < "u" && document.documentElement.dir === "rtl");
2486
+ G(() => {
2487
+ if (typeof MutationObserver > "u") return;
2488
+ let e = new MutationObserver((e) => {
2489
+ for (let t of e) t.attributeName === "dir" && E(document.documentElement.dir === "rtl"), t.attributeName === "lang" && x(!1);
2490
+ });
2491
+ return e.observe(document.documentElement, {
2492
+ attributes: !0,
2493
+ attributeFilter: ["dir", "lang"]
2494
+ }), () => e.disconnect();
2495
+ }, []);
2496
+ let D = q(null), [O, k] = J(!1), A = W((e, t) => (k(!1), a(e, t)), [a]), j = ur(n), M = !!s, N = W(() => {
2497
+ if (M || !h.current) return;
2498
+ let e = Array.from(h.current.children), t = /* @__PURE__ */ new Map();
2499
+ e.forEach((e) => {
2500
+ let n = e.dataset.nodeKey;
2501
+ n && t.set(n, e.getBoundingClientRect().width || e.offsetWidth);
2502
+ }), y(t), x(!0);
2503
+ }, [M]), P = K(() => JSON.stringify(n.map((e) => Q(e))), [n]);
2504
+ Le(() => {
2505
+ if (M) {
2506
+ x(!0);
2507
+ return;
2508
+ }
2509
+ x(!1);
2510
+ let e = requestAnimationFrame(() => {
2511
+ N();
2512
+ });
2513
+ return () => cancelAnimationFrame(e);
2514
+ }, [
2515
+ P,
2516
+ N,
2517
+ M
2518
+ ]), G(() => {
2519
+ if (M || b) return;
2520
+ let e = setTimeout(() => {
2521
+ N(), x(!0);
2522
+ }, 16);
2523
+ return () => clearTimeout(e);
2524
+ }, [
2525
+ b,
2526
+ N,
2527
+ M
2528
+ ]), G(() => {
2529
+ if (M || !u || !b || g === 0) return;
2530
+ let e = m.current;
2531
+ if (!e) return;
2532
+ let t = [...e.children].filter((e) => e.getAttribute("aria-hidden") !== "true"), n = t.length > 1 ? (t.length - 1) * 4 : 0, r = t.reduce((e, t) => e + t.getBoundingClientRect().width, 0) + n;
2533
+ r > 0 && Math.abs(g - r) < 1 && console.error(`[declarion] ResponsiveActionBar is measuring itself: its container is ${Math.round(g)}px, exactly the width of what it just rendered. The slot holding this bar is sized by its own content, so it cannot tell the bar how much room there is. Give that slot \`flex: 1 1 auto; min-width: 0\` (and justify its content to the edge the buttons sit on), or pass \`constrain={false}\` if it genuinely has no row to take space from.`);
2534
+ }, [
2535
+ M,
2536
+ u,
2537
+ b,
2538
+ g,
2539
+ v
2540
+ ]), G(() => {
2541
+ if (M) return;
2542
+ let e = m.current;
2543
+ if (!e) return;
2544
+ if (typeof ResizeObserver > "u") {
2545
+ _(e.getBoundingClientRect().width);
2546
+ return;
2547
+ }
2548
+ let t = new ResizeObserver((e) => {
2549
+ let t = e[0];
2550
+ t && _(t.contentRect.width);
2551
+ });
2552
+ return t.observe(e), _(e.getBoundingClientRect().width), () => t.disconnect();
2553
+ }, [M]);
2554
+ let F = q(void 0);
2555
+ G(() => {
2556
+ F.current = void 0;
2557
+ }, [P]);
2558
+ let I = K(() => M || !u ? Or(n, 2 ** 53 - 1, o, v, r, i, s) : b ? g === 0 ? Or(n, 2 ** 53 - 1, o, v, r, i, s) : Or(n, g, o, v, r, i, s, F.current) : {
2559
+ primaryInline: [],
2560
+ inline: [],
2561
+ overflow: [],
2562
+ destructiveInline: []
2563
+ }, [
2564
+ M,
2565
+ u,
2566
+ b,
2567
+ g,
2568
+ n,
2569
+ o,
2570
+ v,
2571
+ r,
2572
+ i,
2573
+ s
2574
+ ]);
2575
+ if (G(() => {
2576
+ F.current = new Set([...I.inline, ...I.primaryInline].map(Q));
2577
+ }, [I]), j === 0) return null;
2578
+ let ee = I.overflow.length > 0;
2579
+ return /* @__PURE__ */ Z("div", {
2580
+ ref: m,
2581
+ role: "toolbar",
2582
+ "aria-label": c,
2583
+ style: {
2584
+ display: "flex",
2585
+ flexDirection: T ? "row-reverse" : "row",
2586
+ alignItems: "center",
2587
+ gap: 4,
2588
+ visibility: b || M ? "visible" : "hidden",
2589
+ position: "relative",
2590
+ flex: u ? "1 1 auto" : "0 1 auto",
2591
+ justifyContent: l === "trailing" ? "flex-end" : "flex-start",
2592
+ minWidth: 0,
2593
+ boxSizing: "border-box"
2594
+ },
2595
+ children: [
2596
+ /* @__PURE__ */ Z("div", {
2597
+ ref: h,
2598
+ "aria-hidden": "true",
2599
+ style: {
2600
+ position: "absolute",
2601
+ visibility: "hidden",
2602
+ pointerEvents: "none",
2603
+ display: "flex",
2604
+ gap: 4,
2605
+ top: 0,
2606
+ left: 0
2607
+ },
2608
+ children: [/* @__PURE__ */ X(U, {
2609
+ "data-node-key": wr,
2610
+ iconRight: /* @__PURE__ */ X(e.down, { size: 10 }),
2611
+ tabIndex: -1,
2612
+ children: "Actions"
2613
+ }, wr), n.map((n) => {
2614
+ let a = Q(n);
2615
+ if (n.kind === "action") {
2616
+ let e = pr(n.code, r, i), o = mr(n.code, r, i), s = hr(n.code, r, i);
2617
+ return /* @__PURE__ */ X(U, {
2618
+ "data-node-key": a,
2619
+ icon: s ? /* @__PURE__ */ X(t, {
2620
+ name: s,
2621
+ size: 12
2622
+ }) : null,
2623
+ danger: e?.destructive,
2624
+ tabIndex: -1,
2625
+ children: o
2626
+ }, a);
2627
+ } else {
2628
+ let t = n.name ? w(n.name) : "Actions";
2629
+ return /* @__PURE__ */ X(U, {
2630
+ "data-node-key": a,
2631
+ iconRight: /* @__PURE__ */ X(e.down, { size: 10 }),
2632
+ tabIndex: -1,
2633
+ children: t
2634
+ }, a);
2635
+ }
2636
+ })]
2637
+ }),
2638
+ I.primaryInline.map((e) => /* @__PURE__ */ X(_r, {
2639
+ leaf: e,
2640
+ entityActions: r,
2641
+ globalActions: i,
2642
+ onRun: a,
2643
+ loading: S === e.code,
2644
+ onLoadingChange: (t) => C(t ? e.code : null),
2645
+ row: d,
2646
+ widgetContext: f,
2647
+ onActionClick: p
2648
+ }, Q(e))),
2649
+ I.inline.map((e) => {
2650
+ let t = Q(e);
2651
+ return e.kind === "action" ? /* @__PURE__ */ X(_r, {
2652
+ leaf: e,
2653
+ entityActions: r,
2654
+ globalActions: i,
2655
+ onRun: a,
2656
+ loading: S === e.code,
2657
+ onLoadingChange: (t) => C(t ? e.code : null),
2658
+ row: d,
2659
+ widgetContext: f,
2660
+ onActionClick: p
2661
+ }, t) : /* @__PURE__ */ X(vr, {
2662
+ group: e,
2663
+ entityActions: r,
2664
+ globalActions: i,
2665
+ onRun: a,
2666
+ loading: S,
2667
+ onLoadingChange: C,
2668
+ row: d,
2669
+ widgetContext: f,
2670
+ onActionClick: p
2671
+ }, t);
2672
+ }),
2673
+ ee && /* @__PURE__ */ Z(Y, { children: [/* @__PURE__ */ X(U, {
2674
+ ref: D,
2675
+ kind: "default",
2676
+ iconRight: /* @__PURE__ */ X(e.down, { size: 10 }),
2677
+ "aria-haspopup": "menu",
2678
+ "aria-expanded": O ? "true" : "false",
2679
+ onClick: () => k((e) => !e),
2680
+ children: "Actions"
2681
+ }), /* @__PURE__ */ X(se, {
2682
+ open: O,
2683
+ anchor: D.current,
2684
+ onClose: () => k(!1),
2685
+ align: T ? "start" : "end",
2686
+ width: 220,
2687
+ children: /* @__PURE__ */ X("div", {
2688
+ role: "menu",
2689
+ "aria-label": "More actions",
2690
+ children: I.overflow.map((e) => e.kind === "action" ? /* @__PURE__ */ X(yr, {
2691
+ leaf: e,
2692
+ entityActions: r,
2693
+ globalActions: i,
2694
+ onRun: A,
2695
+ loading: S === e.code,
2696
+ onLoadingChange: (t) => C(t ? e.code : null),
2697
+ row: d,
2698
+ widgetContext: f,
2699
+ onActionClick: p
2700
+ }, e.code) : /* @__PURE__ */ X(br, {
2701
+ group: e,
2702
+ entityActions: r,
2703
+ globalActions: i,
2704
+ onRun: A,
2705
+ loading: S,
2706
+ onLoadingChange: C,
2707
+ row: d,
2708
+ widgetContext: f,
2709
+ onActionClick: p
2710
+ }, Q(e)))
2711
+ })
2712
+ })] }),
2713
+ I.destructiveInline.map((e) => /* @__PURE__ */ X(_r, {
2714
+ leaf: e,
2715
+ entityActions: r,
2716
+ globalActions: i,
2717
+ onRun: a,
2718
+ loading: S === e.code,
2719
+ onLoadingChange: (t) => C(t ? e.code : null),
2720
+ row: d,
2721
+ widgetContext: f,
2722
+ onActionClick: p
2723
+ }, Q(e)))
2724
+ ]
2725
+ });
2726
+ }
2727
+ function Ar({ layout: e, rowSelection: t = [], ...n }) {
2728
+ let r = t.length > 0;
2729
+ return /* @__PURE__ */ Z("div", {
2730
+ style: {
2731
+ position: "relative",
2732
+ display: "flex",
2733
+ flex: "1 1 auto",
2734
+ minWidth: 0
2735
+ },
2736
+ children: [/* @__PURE__ */ X("div", {
2737
+ "aria-hidden": r ? "true" : void 0,
2738
+ style: {
2739
+ display: r ? "none" : "flex",
2740
+ flex: "1 1 auto",
2741
+ minWidth: 0
2742
+ },
2743
+ children: /* @__PURE__ */ X(kr, {
2744
+ layout: e,
2745
+ rowSelection: [],
2746
+ ...n
2747
+ })
2748
+ }), /* @__PURE__ */ X("div", {
2749
+ "aria-hidden": r ? void 0 : "true",
2750
+ style: {
2751
+ display: r ? "flex" : "none",
2752
+ flex: "1 1 auto",
2753
+ minWidth: 0
2754
+ },
2755
+ children: /* @__PURE__ */ X(kr, {
2756
+ layout: e,
2757
+ rowSelection: t,
2758
+ ...n
2759
+ })
2760
+ })]
2761
+ });
2762
+ }
2763
+ function jr({ layout: e, row: t, rowSelection: n, onRun: r, reservedRightWidth: i = 0, kind: a = "toolbar", align: o = "trailing", constrain: s = !0, measurementOverride: c, entityActions: l, globalActions: u, ariaLabel: d = "Actions", widgetContext: f, onActionClick: p }) {
2764
+ let m = ur(e);
2765
+ return a === "row" ? /* @__PURE__ */ X(xr, {
2766
+ layout: e,
2767
+ entityActions: l,
2768
+ globalActions: u,
2769
+ onRun: r,
2770
+ row: t,
2771
+ widgetContext: f,
2772
+ onActionClick: p
2773
+ }) : m === 0 ? null : X(a === "toolbar" ? Ar : kr, {
2774
+ layout: e,
2775
+ row: t,
2776
+ rowSelection: n,
2777
+ onRun: r,
2778
+ reservedRightWidth: i,
2779
+ measurementOverride: c,
2780
+ entityActions: l,
2781
+ globalActions: u,
2782
+ ariaLabel: d,
2783
+ align: o,
2784
+ constrain: s,
2785
+ widgetContext: f,
2786
+ onActionClick: p
2787
+ });
2788
+ }
2789
+ //#endregion
2790
+ //#region src/components/shared/RowActionsKebab.tsx
2791
+ function Mr({ actions: t, objectIds: n, row: r, onSuccess: i, preMenu: a, divider: o, size: s = 22, align: c = "end" }) {
2792
+ let l = q(null), [u, d] = J(!1), [f, p] = J(null), { run: m } = re(), h = K(() => {
2793
+ let e = {};
2794
+ for (let { code: n, action: r } of t) e[n] = r;
2795
+ return e;
2796
+ }, [t]), g = K(() => {
2797
+ let e = t.map(({ code: e }) => ({
2798
+ kind: "action",
2799
+ code: e,
2800
+ enabled: !0,
2801
+ reason: null
2802
+ }));
2803
+ return r ? M(e, h, void 0, r, []) : e;
2804
+ }, [
2805
+ t,
2806
+ h,
2807
+ r
2808
+ ]), _ = W((e, t) => {
2809
+ d(!1);
2810
+ let a = t.entity ? `${t.entity}.${e}` : e;
2811
+ return m({
2812
+ action: t,
2813
+ title: w(t.display?.name) || e,
2814
+ row: r,
2815
+ execute: async (e) => {
2816
+ let t = await me(a, N(e, n));
2817
+ return i?.(), t;
2818
+ }
2819
+ });
2820
+ }, [
2821
+ m,
2822
+ r,
2823
+ n,
2824
+ i
2825
+ ]);
2826
+ return !a && g.length === 0 ? null : /* @__PURE__ */ Z("div", {
2827
+ className: "sl-row-actions",
2828
+ "data-open": u ? "true" : void 0,
2829
+ style: {
2830
+ display: "flex",
2831
+ alignItems: "center",
2832
+ justifyContent: "flex-end"
2833
+ },
2834
+ children: [/* @__PURE__ */ X(H, {
2835
+ ref: l,
2836
+ size: s,
2837
+ icon: /* @__PURE__ */ X(e.more, { size: Math.round(s * .55) }),
2838
+ onClick: () => d((e) => !e),
2839
+ title: "Actions"
2840
+ }), /* @__PURE__ */ Z(se, {
2841
+ open: u,
2842
+ anchor: l.current,
2843
+ onClose: () => d(!1),
2844
+ width: 200,
2845
+ align: c,
2846
+ children: [
2847
+ a,
2848
+ a && o && g.length > 0 && /* @__PURE__ */ X(j, { divider: !0 }),
2849
+ /* @__PURE__ */ X(Cr, {
2850
+ layout: g,
2851
+ entityActions: h,
2852
+ onRun: _,
2853
+ loading: f,
2854
+ onLoadingChange: p,
2855
+ row: r
2856
+ })
2857
+ ]
2858
+ })]
2859
+ });
2860
+ }
2861
+ //#endregion
2862
+ //#region src/components/detail-layout/AssociatedToolbar.tsx
2863
+ function Nr({ entity: t, searchable: n, filterFields: r, searchValue: i, onSearchChange: a, filters: o, onFilterChange: s, allEntities: c }) {
2864
+ let l = n === !0, u = r && r.length > 0;
2865
+ return !l && !u ? null : /* @__PURE__ */ Z("div", {
2866
+ style: {
2867
+ display: "flex",
2868
+ alignItems: "center",
2869
+ gap: 6,
2870
+ marginBottom: 8
2871
+ },
2872
+ children: [l && /* @__PURE__ */ X("div", {
2873
+ style: {
2874
+ flex: 1,
2875
+ maxWidth: 220
2876
+ },
2877
+ children: /* @__PURE__ */ X(h, {
2878
+ value: i,
2879
+ onChange: a,
2880
+ placeholder: "Search…",
2881
+ prefix: /* @__PURE__ */ X(e.search, { size: 12 })
2882
+ })
2883
+ }), u && r.map((e) => {
2884
+ let n = t.fields.get(e);
2885
+ if (!n) return null;
2886
+ let r = o[e] ?? "__all__", i = S(n, e, c);
2887
+ return n.type === "ref" && n.ref?.entity ? /* @__PURE__ */ X(Pr, {
2888
+ field: n,
2889
+ label: i,
2890
+ value: r,
2891
+ onChange: (t) => s(e, t)
2892
+ }, e) : n.values ? /* @__PURE__ */ X("div", {
2893
+ style: { width: 160 },
2894
+ children: /* @__PURE__ */ X(D, {
2895
+ value: r,
2896
+ options: [{
2897
+ value: "__all__",
2898
+ label: `All ${i}`
2899
+ }, ...n.values.map((e) => ({
2900
+ value: e.code,
2901
+ label: w(e.name) || e.code
2902
+ }))],
2903
+ onChange: (t) => s(e, t),
2904
+ placeholder: i
2905
+ })
2906
+ }, e) : null;
2907
+ })]
2908
+ });
2909
+ }
2910
+ function Pr({ field: e, label: t, value: n, onChange: r }) {
2911
+ let i = m(e.ref?.entity), a = e.display?.ref_display_field ?? i?.display?.display_field, o = K(() => i ? [...i.fields].find(([, e]) => e.primary)?.[0] ?? "id" : "id", [i]), { data: s } = A(e.ref?.entity, {
2912
+ per_page: 200,
2913
+ sort: a ? `${a}:asc` : void 0
2914
+ }), c = s?.data ?? [], l = (e) => {
2915
+ if (e == null) return "—";
2916
+ if (typeof e == "object" && !Array.isArray(e)) {
2917
+ let t = Object.values(e)[0];
2918
+ return t == null ? "—" : u(t);
2919
+ }
2920
+ return u(e);
2921
+ };
2922
+ return /* @__PURE__ */ X("div", {
2923
+ style: { width: 160 },
2924
+ children: /* @__PURE__ */ X(D, {
2925
+ value: n,
2926
+ options: [{
2927
+ value: "__all__",
2928
+ label: `All ${t}`
2929
+ }, ...c.map((e) => {
2930
+ let t = String(e[o]), n = e[z];
2931
+ return {
2932
+ value: t,
2933
+ label: typeof n == "string" && n !== "" ? n : a ? l(e[a] ?? t) : t
2934
+ };
2935
+ })],
2936
+ onChange: r,
2937
+ placeholder: t
2938
+ })
2939
+ });
2940
+ }
2941
+ //#endregion
2942
+ //#region src/lib/action-dispatch.ts
2943
+ function Fr(e, t, n, r) {
2944
+ return te(t) ? (le(t.ui_steps, n), null) : t.entity ? `${t.entity}.${e}` : r ? `${r}.${e}` : e;
2945
+ }
2946
+ //#endregion
2947
+ //#region src/components/detail-layout/AssociatedBlock.tsx
2948
+ function Ir(e) {
2949
+ if (!e) return [];
2950
+ let t = [];
2951
+ for (let [n, r] of Object.entries(e)) (r.visibility ?? []).includes("list_row") && (r.association || c(n) || t.push({
2952
+ code: n,
2953
+ action: r
2954
+ }));
2955
+ return t;
2956
+ }
2957
+ function Lr(e, t, n) {
2958
+ if (!e) return [];
2959
+ let r = [];
2960
+ for (let [i, a] of Object.entries(e)) {
2961
+ if (!(a.visibility ?? []).includes("list_toolbar") || a.association || i.startsWith("__")) continue;
2962
+ let e = {
2963
+ ...a,
2964
+ resolved_hidden_defaults: {
2965
+ ...a.resolved_hidden_defaults ?? {},
2966
+ [t]: n
2967
+ }
2968
+ };
2969
+ if (a.resolved_params?.has(t)) {
2970
+ let n = a.resolved_params.items().filter((e) => e.name !== t);
2971
+ e = {
2972
+ ...e,
2973
+ resolved_params: new f(n)
2974
+ };
2975
+ }
2976
+ r.push({
2977
+ code: i,
2978
+ action: e
2979
+ });
2980
+ }
2981
+ return r;
2982
+ }
2983
+ function Rr(e, t, n) {
2984
+ let r = e[n];
2985
+ if (!r) return null;
2986
+ let i = e[t], a = i?.children?.find((e) => e.entity === n);
2987
+ if (a) {
2988
+ let e = a.foreign_key;
2989
+ if (typeof e == "string") return e;
2990
+ if (Array.isArray(e) && e.length === 1) return e[0];
2991
+ }
2992
+ let o = i?.table;
2993
+ for (let [n, i] of r.fields) {
2994
+ let r = i.ref?.entity;
2995
+ if (r) {
2996
+ if (r === t) return n;
2997
+ if (o) {
2998
+ let t = e[r]?.table;
2999
+ if (t && t === o) return n;
3000
+ }
3001
+ }
3002
+ }
3003
+ return null;
3004
+ }
3005
+ function zr(e, t, n) {
3006
+ let r = new Set(fe(e));
3007
+ return new Set(t.filter((t) => {
3008
+ if (t === n || r.has(t)) return !1;
3009
+ let i = e.fields.get(t);
3010
+ return !(!i || i.auto || i.primary || i.source);
3011
+ }));
3012
+ }
3013
+ function Br(e, t, n) {
3014
+ return new Set(t.filter((t) => {
3015
+ if (t === n) return !1;
3016
+ let r = e.fields.get(t);
3017
+ return !(!r || r.auto);
3018
+ }));
3019
+ }
3020
+ function Vr(e, t, n, r) {
3021
+ let i = [];
3022
+ for (let a of t) {
3023
+ let t = n.fields.get(a);
3024
+ if (!t || !t.required || t.auto || t.primary || a === r || n.tenant_key && a === n.tenant_key) continue;
3025
+ let o = e[a];
3026
+ (o == null || o === "") && i.push(a);
3027
+ }
3028
+ return i;
3029
+ }
3030
+ function Hr({ node: e, ctx: t }) {
3031
+ let n = e.associated;
3032
+ if (!n || t.isNew) return null;
3033
+ let r = t.schema.entities[n];
3034
+ if (!r) return /* @__PURE__ */ Z("div", {
3035
+ style: {
3036
+ fontSize: 12.5,
3037
+ color: "var(--text-3)",
3038
+ padding: "8px 0"
3039
+ },
3040
+ children: ["Entity not found: ", n]
3041
+ });
3042
+ let i = Rr(t.schema.entities, t.entityCode, n);
3043
+ return i ? /* @__PURE__ */ X(Ur, {
3044
+ node: e,
3045
+ ctx: t,
3046
+ assocCode: n,
3047
+ assocEntity: r,
3048
+ fkField: i
3049
+ }) : /* @__PURE__ */ Z("div", {
3050
+ style: {
3051
+ fontSize: 12.5,
3052
+ color: "var(--text-3)",
3053
+ padding: "8px 0"
3054
+ },
3055
+ children: [
3056
+ "No FK found for ",
3057
+ n,
3058
+ " → ",
3059
+ t.entityCode
3060
+ ]
3061
+ });
3062
+ }
3063
+ function Ur({ node: r, ctx: i, assocCode: a, assocEntity: o, fkField: s }) {
3064
+ let c = r.columns && r.columns.length > 0 ? r.columns.filter((e) => e !== s && !!o.fields.get(e)) : o.fields.names().filter((e) => {
3065
+ if (e === s) return !1;
3066
+ let t = o.fields.get(e);
3067
+ return !(!t || t.primary || t.display?.is_listable === !1);
3068
+ }), l = I(o, "update"), u = r.interaction ?? (l ? "navigate" : "readonly"), d = (u === "inline_edit" || u === "row_edit") && l && r.editable !== !1, f = w(o.display?.name_plural) || w(o.display?.name) || a, p = r.searchable === !0 || r.filters && r.filters.length > 0, m = K(() => Lr(o.actions, s, i.recordId), [
3069
+ o.actions,
3070
+ s,
3071
+ i.recordId
3072
+ ]), h = K(() => {
3073
+ let e = {};
3074
+ for (let { code: t, action: n } of m) e[t] = n;
3075
+ return e;
3076
+ }, [m]), g = K(() => M(o.action_layout ?? null ?? ue(h, "list_toolbar"), h, void 0, {}, []), [o.action_layout, h]), { run: _ } = re(), v = Bt(), y = n(), b = K(() => ({
3077
+ entity: o,
3078
+ entityCode: a,
3079
+ screenRoute: typeof window < "u" ? window.location.pathname : "",
3080
+ selectedRows: [],
3081
+ selectedIds: [],
3082
+ locale: y,
3083
+ tabNavigate: (e, t) => v(e, {
3084
+ title: t?.title,
3085
+ icon: t?.icon,
3086
+ search: t?.search
3087
+ }),
3088
+ runActionApi: (e, t) => me(e, t)
3089
+ }), [
3090
+ o,
3091
+ a,
3092
+ y,
3093
+ v
3094
+ ]), x = Ue(), S = W(() => {
3095
+ x.invalidateQueries({ predicate: (e) => {
3096
+ let t = e.queryKey;
3097
+ return t[0] === "entity-children" && t[3] === a;
3098
+ } });
3099
+ }, [x, a]), C = W((e, t) => {
3100
+ let n = Fr(e, t, {}, a);
3101
+ if (n !== null) return _({
3102
+ action: t,
3103
+ title: w(t.display?.name) || e,
3104
+ execute: async (e) => {
3105
+ let t = await me(n, N(e, void 0));
3106
+ return S(), t;
3107
+ }
3108
+ });
3109
+ }, [
3110
+ _,
3111
+ a,
3112
+ S
3113
+ ]), [T, E] = J(0), D = /* @__PURE__ */ Z("div", {
3114
+ style: {
3115
+ display: "flex",
3116
+ alignItems: "center",
3117
+ gap: 6,
3118
+ flex: "1 1 auto",
3119
+ minWidth: 0,
3120
+ justifyContent: "flex-end"
3121
+ },
3122
+ children: [o.action_layout ? g.length > 0 && /* @__PURE__ */ X(jr, {
3123
+ kind: "toolbar",
3124
+ layout: g,
3125
+ entityActions: h,
3126
+ onRun: C,
3127
+ widgetContext: b,
3128
+ ariaLabel: `${f} toolbar actions`
3129
+ }) : m.map(({ code: e, action: t }) => /* @__PURE__ */ X(or, {
3130
+ actionCode: e,
3131
+ action: t,
3132
+ entityCode: a,
3133
+ variant: "ghost",
3134
+ size: "sm",
3135
+ onSuccess: S
3136
+ }, e)), d && /* @__PURE__ */ X(U, {
3137
+ kind: "ghost",
3138
+ size: "xs",
3139
+ icon: /* @__PURE__ */ X(e.plus, { size: 12 }),
3140
+ onClick: () => E((e) => e + 1),
3141
+ children: "Add row"
3142
+ })]
3143
+ }), O = p ? /* @__PURE__ */ X(Gr, {
3144
+ entityCode: a,
3145
+ entity: o,
3146
+ parentEntity: i.entityCode,
3147
+ parentId: i.recordId,
3148
+ foreignKey: s,
3149
+ columns: c,
3150
+ editable: d,
3151
+ interaction: u,
3152
+ ctx: i,
3153
+ searchable: r.searchable,
3154
+ filterFields: r.filters,
3155
+ sort: r.sort,
3156
+ startDraftSignal: T
3157
+ }) : /* @__PURE__ */ X(Wr, {
3158
+ entityCode: a,
3159
+ entity: o,
3160
+ parentEntity: i.entityCode,
3161
+ parentId: i.recordId,
3162
+ foreignKey: s,
3163
+ columns: c,
3164
+ editable: d,
3165
+ interaction: u,
3166
+ ctx: i,
3167
+ sort: r.sort,
3168
+ startDraftSignal: T
3169
+ });
3170
+ return i.withinCard ? /* @__PURE__ */ Z("div", { children: [/* @__PURE__ */ X("div", {
3171
+ style: {
3172
+ display: "flex",
3173
+ justifyContent: "flex-end",
3174
+ marginBottom: 8
3175
+ },
3176
+ children: D
3177
+ }), O] }) : /* @__PURE__ */ X(Je, {
3178
+ title: f,
3179
+ icon: o.display?.icon ? /* @__PURE__ */ X(t, {
3180
+ name: o.display.icon,
3181
+ size: 14
3182
+ }) : void 0,
3183
+ right: D,
3184
+ children: O
3185
+ });
3186
+ }
3187
+ function Wr({ entityCode: e, entity: t, parentEntity: n, parentId: r, foreignKey: i, columns: a, editable: o, interaction: s, ctx: c, sort: l, startDraftSignal: u }) {
3188
+ let d = Ue(), { data: f, isLoading: p, isError: m } = nr(n, r, e, i, l), h = f?.data ?? [], g = f?.$refs;
3189
+ return /* @__PURE__ */ X(Kr, {
3190
+ entityCode: e,
3191
+ entity: t,
3192
+ parentId: r,
3193
+ foreignKey: i,
3194
+ columns: a,
3195
+ editable: o,
3196
+ interaction: s,
3197
+ ctx: c,
3198
+ rows: h,
3199
+ refs: g,
3200
+ isLoading: p,
3201
+ isError: m,
3202
+ invalidateQuery: W(() => {
3203
+ d.invalidateQueries({ queryKey: [
3204
+ tr,
3205
+ n,
3206
+ r,
3207
+ e
3208
+ ] });
3209
+ }, [
3210
+ d,
3211
+ n,
3212
+ r,
3213
+ e
3214
+ ]),
3215
+ startDraftSignal: u
3216
+ });
3217
+ }
3218
+ function Gr({ entityCode: e, entity: t, parentEntity: n, parentId: r, foreignKey: i, columns: a, editable: o, interaction: s, ctx: c, searchable: l, filterFields: u, sort: d, startDraftSignal: f }) {
3219
+ let m = Ue(), [h, g] = J(""), [_, v] = J(""), [y, b] = J({}), x = q(void 0);
3220
+ G(() => (x.current && clearTimeout(x.current), x.current = setTimeout(() => {
3221
+ v(h);
3222
+ }, 300), () => {
3223
+ x.current && clearTimeout(x.current);
3224
+ }), [h]);
3225
+ let S = W((e, t) => {
3226
+ b((n) => {
3227
+ if (t === "__all__") {
3228
+ let { [e]: t, ...r } = n;
3229
+ return r;
3230
+ }
3231
+ return {
3232
+ ...n,
3233
+ [e]: t
3234
+ };
3235
+ });
3236
+ }, []), C = K(() => Object.keys(y).length > 0 ? y : void 0, [y]), { data: w, isLoading: T, isError: E, hasNextPage: D, fetchNextPage: O, isFetchingNextPage: k } = ar(n, r, e, i, d, void 0, _ || void 0, C), { rows: A, refs: j } = K(() => {
3237
+ if (!w?.pages) return {
3238
+ rows: [],
3239
+ refs: void 0
3240
+ };
3241
+ let e = [], t;
3242
+ for (let n of w.pages) if (e.push(...n.data), n.$refs) if (!t) t = { ...n.$refs };
3243
+ else for (let [e, r] of Object.entries(n.$refs)) t[e] = {
3244
+ ...t[e],
3245
+ ...r
3246
+ };
3247
+ return {
3248
+ rows: e,
3249
+ refs: t
3250
+ };
3251
+ }, [w]), M = W(() => {
3252
+ m.invalidateQueries({ predicate: (t) => {
3253
+ let n = t.queryKey;
3254
+ return n[0] === "entity-children" && n[3] === e;
3255
+ } });
3256
+ }, [m, e]);
3257
+ return /* @__PURE__ */ Z("div", { children: [
3258
+ /* @__PURE__ */ X(Nr, {
3259
+ entity: t,
3260
+ searchable: l,
3261
+ filterFields: u,
3262
+ searchValue: h,
3263
+ onSearchChange: g,
3264
+ filters: y,
3265
+ onFilterChange: S,
3266
+ allEntities: c.schema.entities
3267
+ }),
3268
+ /* @__PURE__ */ X(Kr, {
3269
+ entityCode: e,
3270
+ entity: t,
3271
+ parentId: r,
3272
+ foreignKey: i,
3273
+ columns: a,
3274
+ editable: o,
3275
+ interaction: s,
3276
+ ctx: c,
3277
+ rows: A,
3278
+ refs: j,
3279
+ isLoading: T,
3280
+ isError: E,
3281
+ invalidateQuery: M,
3282
+ startDraftSignal: f
3283
+ }),
3284
+ D && /* @__PURE__ */ X("div", {
3285
+ style: { marginTop: 4 },
3286
+ children: /* @__PURE__ */ X(U, {
3287
+ kind: "ghost",
3288
+ size: "xs",
3289
+ icon: k ? /* @__PURE__ */ X(p, { size: 12 }) : void 0,
3290
+ onClick: () => O(),
3291
+ disabled: k,
3292
+ children: "Load more"
3293
+ })
3294
+ })
3295
+ ] });
3296
+ }
3297
+ function Kr({ entityCode: e, entity: t, parentId: n, foreignKey: i, columns: a, editable: o, interaction: s, ctx: c, rows: l, refs: u, isLoading: d, isError: f, invalidateQuery: p, startDraftSignal: m }) {
3298
+ let h = ne(), g = h.isPhone && c.relatedRecordsPresentation === "table", _ = a.find((e) => e !== i), v = K(() => s === "navigate" ? ie(void 0, t, c.schema.screens) : null, [
3299
+ s,
3300
+ t,
3301
+ c.schema.screens
3302
+ ]), y = K(() => o ? zr(t, a, i) : /* @__PURE__ */ new Set(), [
3303
+ a,
3304
+ i,
3305
+ t,
3306
+ o
3307
+ ]), b = K(() => Br(t, a, i), [
3308
+ a,
3309
+ i,
3310
+ t
3311
+ ]), x = K(() => {
3312
+ let e = /* @__PURE__ */ new Map();
3313
+ for (let n of l) {
3314
+ let r = pe(t, n);
3315
+ e.set(ee(r), r);
3316
+ }
3317
+ return e;
3318
+ }, [l, t]), C = K(() => {
3319
+ let e = /* @__PURE__ */ new Map();
3320
+ for (let n of l) {
3321
+ let r = n.$row_version;
3322
+ typeof r == "string" && r !== "" && e.set(ee(pe(t, n)), r);
3323
+ }
3324
+ return e;
3325
+ }, [l, t]), T = K(() => Ir(t.actions), [t.actions]), [E, D] = J(null), [O, k] = J(null), [A, j] = J([]), [M, N] = J({}), P = q(M);
3326
+ P.current = M;
3327
+ let F = q({});
3328
+ G(() => {
3329
+ let e = F.current;
3330
+ return () => {
3331
+ for (let t of Object.values(e)) clearTimeout(t);
3332
+ };
3333
+ }, []);
3334
+ let [I, L] = J(null), [te, R] = J([]), [z, B] = J(!1), { run: V } = re(), [ae, oe] = J(/* @__PURE__ */ new Set()), H = W(async (t, n, i) => {
3335
+ N((e) => ({
3336
+ ...e,
3337
+ [t]: {
3338
+ ...e[t],
3339
+ saving: !0,
3340
+ error: void 0
3341
+ }
3342
+ }));
3343
+ try {
3344
+ let a = C.get(t), o = a ? {
3345
+ ...n,
3346
+ $row_version: a
3347
+ } : n;
3348
+ return await r(e, x.get(t) ?? t, o), N((e) => {
3349
+ let n = e[t];
3350
+ if (!n) return e;
3351
+ if (n.ver > i) return {
3352
+ ...e,
3353
+ [t]: {
3354
+ ...n,
3355
+ saving: !1
3356
+ }
3357
+ };
3358
+ let { [t]: r, ...a } = e;
3359
+ return a;
3360
+ }), p(), !0;
3361
+ } catch (e) {
3362
+ let n = e instanceof Error ? e.message : "Save failed";
3363
+ return N((e) => ({
3364
+ ...e,
3365
+ [t]: {
3366
+ ...e[t],
3367
+ saving: !1,
3368
+ error: n
3369
+ }
3370
+ })), !1;
3371
+ }
3372
+ }, [
3373
+ e,
3374
+ p,
3375
+ x,
3376
+ C
3377
+ ]), se = W((e, t, n) => {
3378
+ N((r) => {
3379
+ let i = r[e] ?? {
3380
+ buffer: {},
3381
+ ver: 0,
3382
+ saving: !1
3383
+ }, a = i.ver + 1;
3384
+ return {
3385
+ ...r,
3386
+ [e]: {
3387
+ ...i,
3388
+ buffer: {
3389
+ ...i.buffer,
3390
+ [t]: n
3391
+ },
3392
+ ver: a
3393
+ }
3394
+ };
3395
+ }), s === "inline_edit" && (F.current[e] && clearTimeout(F.current[e]), F.current[e] = setTimeout(() => {
3396
+ let t = P.current[e];
3397
+ t && Object.keys(t.buffer).length > 0 && H(e, { ...t.buffer }, t.ver);
3398
+ }, 500));
3399
+ }, [H, s]), U = W(() => {
3400
+ let e = {};
3401
+ e[i] = n;
3402
+ for (let n of a) {
3403
+ let r = t.fields.get(n);
3404
+ r && (r.default === void 0 ? r.type === "bool" && (e[n] = !1) : e[n] = r.default);
3405
+ }
3406
+ L(e), R([]);
3407
+ }, [
3408
+ i,
3409
+ n,
3410
+ a,
3411
+ t.fields
3412
+ ]), ce = q(m);
3413
+ G(() => {
3414
+ m !== void 0 && m !== ce.current && (ce.current = m, !I && U());
3415
+ }, [
3416
+ m,
3417
+ I,
3418
+ U
3419
+ ]);
3420
+ let le = W(async () => {
3421
+ if (!I) return;
3422
+ let n = Vr(I, a, t, i);
3423
+ if (n.length > 0) {
3424
+ R(n);
3425
+ return;
3426
+ }
3427
+ B(!0);
3428
+ try {
3429
+ await de(e, I), L(null), R([]), p();
3430
+ } catch (e) {
3431
+ let t = e instanceof Error ? e.message : "Create failed";
3432
+ R([`_error:${t}`]);
3433
+ } finally {
3434
+ B(!1);
3435
+ }
3436
+ }, [
3437
+ I,
3438
+ a,
3439
+ t,
3440
+ i,
3441
+ e,
3442
+ p
3443
+ ]), ue = W((e) => {
3444
+ N({}), j([]), k(e);
3445
+ }, []), fe = W(async (e) => {
3446
+ let n = P.current[e], r = n?.buffer ?? {};
3447
+ if (Object.keys(r).length === 0) {
3448
+ k(null), j([]);
3449
+ return;
3450
+ }
3451
+ let o = Vr({
3452
+ ...l.find((n) => ee(pe(t, n)) === e) ?? {},
3453
+ ...r
3454
+ }, a, t, i);
3455
+ if (o.length > 0) {
3456
+ j(o);
3457
+ return;
3458
+ }
3459
+ await H(e, { ...r }, n?.ver ?? 0) && (k(null), j([]));
3460
+ }, [
3461
+ l,
3462
+ t,
3463
+ a,
3464
+ i,
3465
+ H
3466
+ ]), me = W((e) => {
3467
+ N((t) => {
3468
+ if (!t[e]) return t;
3469
+ let { [e]: n, ...r } = t;
3470
+ return r;
3471
+ }), j([]), k(null);
3472
+ }, []), ge = W((n, r) => {
3473
+ let i = x.get(n) ?? n;
3474
+ return V({
3475
+ action: t.actions?.__delete,
3476
+ destructive: !0,
3477
+ title: w(t.display?.name) || "Delete",
3478
+ row: r,
3479
+ entity: e,
3480
+ execute: async () => {
3481
+ oe((e) => new Set(e).add(n));
3482
+ try {
3483
+ return await he(e, i);
3484
+ } finally {
3485
+ oe((e) => {
3486
+ let t = new Set(e);
3487
+ return t.delete(n), t;
3488
+ });
3489
+ }
3490
+ },
3491
+ onSuccess: () => p()
3492
+ });
3493
+ }, [
3494
+ V,
3495
+ t,
3496
+ e,
3497
+ p,
3498
+ x
3499
+ ]);
3500
+ if (f) return /* @__PURE__ */ X("div", {
3501
+ style: {
3502
+ fontSize: 12.5,
3503
+ color: "var(--danger)",
3504
+ padding: "8px 0"
3505
+ },
3506
+ children: "Failed to load."
3507
+ });
3508
+ if (d) return /* @__PURE__ */ Z("div", {
3509
+ style: {
3510
+ display: "flex",
3511
+ flexDirection: "column",
3512
+ gap: 8,
3513
+ padding: "8px 0"
3514
+ },
3515
+ children: [/* @__PURE__ */ X("div", { style: {
3516
+ height: 32,
3517
+ background: "var(--surface-3)",
3518
+ borderRadius: 6
3519
+ } }), /* @__PURE__ */ X("div", { style: {
3520
+ height: 32,
3521
+ background: "var(--surface-3)",
3522
+ borderRadius: 6
3523
+ } })]
3524
+ });
3525
+ let _e = l.length === 0 && !I;
3526
+ return h.isPhone && !g ? /* @__PURE__ */ Z("div", { children: [_e && !o && /* @__PURE__ */ X("div", {
3527
+ style: {
3528
+ fontSize: 12.5,
3529
+ color: "var(--text-3)",
3530
+ padding: "12px 0"
3531
+ },
3532
+ children: "No records yet."
3533
+ }), (!_e || o) && /* @__PURE__ */ Z("div", {
3534
+ style: {
3535
+ display: "flex",
3536
+ flexDirection: "column",
3537
+ gap: 10
3538
+ },
3539
+ children: [l.map((n) => {
3540
+ let r = ee(pe(t, n)), i = ae.has(r), l = M[r], d = v && r ? v.replace(/:\w+/, r) : void 0;
3541
+ return /* @__PURE__ */ X(qr, {
3542
+ rowId: r,
3543
+ row: n,
3544
+ entity: t,
3545
+ entities: c.schema.entities,
3546
+ screens: c.schema.screens,
3547
+ columns: a,
3548
+ editableColumns: y,
3549
+ editable: o,
3550
+ interaction: s,
3551
+ isEditing: O === r,
3552
+ editErrors: A,
3553
+ isDeleting: i,
3554
+ activeCell: E,
3555
+ setActiveCell: D,
3556
+ rowState: l,
3557
+ onCellChange: se,
3558
+ onDeleteClick: (e) => void ge(e, n),
3559
+ onStartEdit: ue,
3560
+ onConfirmEdit: fe,
3561
+ onCancelEdit: me,
3562
+ refs: u,
3563
+ identityCol: _,
3564
+ href: d,
3565
+ rowActions: T,
3566
+ entityCode: e,
3567
+ onRowActionSuccess: p
3568
+ }, r);
3569
+ }), I && /* @__PURE__ */ X(Qr, {
3570
+ draftRow: I,
3571
+ entity: t,
3572
+ columns: a,
3573
+ editableColumns: b,
3574
+ foreignKey: i,
3575
+ draftErrors: te,
3576
+ draftSaving: z,
3577
+ onChange: (e, t) => L((n) => n && {
3578
+ ...n,
3579
+ [e]: t
3580
+ }),
3581
+ onConfirm: le,
3582
+ onCancel: () => {
3583
+ L(null), R([]);
3584
+ },
3585
+ refs: u
3586
+ })]
3587
+ })] }) : /* @__PURE__ */ Z("div", { children: [_e && !o && /* @__PURE__ */ X("div", {
3588
+ style: {
3589
+ fontSize: 12.5,
3590
+ color: "var(--text-3)",
3591
+ padding: "12px 0"
3592
+ },
3593
+ children: "No records yet."
3594
+ }), (!_e || o) && /* @__PURE__ */ X("div", {
3595
+ style: { overflowX: "auto" },
3596
+ children: /* @__PURE__ */ Z("table", {
3597
+ style: je,
3598
+ children: [/* @__PURE__ */ X("thead", { children: /* @__PURE__ */ Z("tr", { children: [
3599
+ a.map((e) => {
3600
+ let n = t.fields.get(e);
3601
+ return /* @__PURE__ */ X("th", {
3602
+ style: Ae,
3603
+ children: n ? S(n, e, c.schema.entities) : e
3604
+ }, e);
3605
+ }),
3606
+ o && /* @__PURE__ */ X("th", { style: {
3607
+ height: 30,
3608
+ width: 72
3609
+ } }),
3610
+ !o && T.length > 0 && /* @__PURE__ */ X("th", { style: {
3611
+ height: 30,
3612
+ width: 40
3613
+ } })
3614
+ ] }) }), /* @__PURE__ */ Z("tbody", { children: [l.map((n) => {
3615
+ let r = ee(pe(t, n)), i = ae.has(r), l = M[r], d = v && r ? v.replace(/:\w+/, r) : void 0;
3616
+ return /* @__PURE__ */ X(Jr, {
3617
+ rowId: r,
3618
+ row: n,
3619
+ entity: t,
3620
+ entities: c.schema.entities,
3621
+ screens: c.schema.screens,
3622
+ columns: a,
3623
+ editableColumns: y,
3624
+ editable: o,
3625
+ interaction: s,
3626
+ isEditing: O === r,
3627
+ editErrors: A,
3628
+ isDeleting: i,
3629
+ activeCell: E,
3630
+ setActiveCell: D,
3631
+ rowState: l,
3632
+ onCellChange: se,
3633
+ onDeleteClick: (e) => void ge(e, n),
3634
+ onStartEdit: ue,
3635
+ onConfirmEdit: fe,
3636
+ onCancelEdit: me,
3637
+ refs: u,
3638
+ identityCol: _,
3639
+ href: d,
3640
+ rowActions: T,
3641
+ entityCode: e,
3642
+ onRowActionSuccess: p
3643
+ }, r);
3644
+ }), I && /* @__PURE__ */ X(Zr, {
3645
+ draftRow: I,
3646
+ entity: t,
3647
+ columns: a,
3648
+ editableColumns: b,
3649
+ foreignKey: i,
3650
+ draftErrors: te,
3651
+ draftSaving: z,
3652
+ onChange: (e, t) => L((n) => n && {
3653
+ ...n,
3654
+ [e]: t
3655
+ }),
3656
+ onConfirm: le,
3657
+ onCancel: () => {
3658
+ L(null), R([]);
3659
+ },
3660
+ refs: u
3661
+ })] })]
3662
+ })
3663
+ })] });
3664
+ }
3665
+ function qr({ rowId: t, row: r, entity: i, entities: a, screens: o, columns: s, editableColumns: c, editable: l, interaction: d, isEditing: f, editErrors: m, isDeleting: h, rowState: g, onCellChange: _, onDeleteClick: v, onStartEdit: y, onConfirmEdit: b, onCancelEdit: x, refs: C, identityCol: w, href: T, rowActions: E, onRowActionSuccess: D }) {
3666
+ let O = n(), k = Ie(), A = K(() => !g || Object.keys(g.buffer).length === 0 ? r : {
3667
+ ...r,
3668
+ ...g.buffer
3669
+ }, [r, g]);
3670
+ return d === "row_edit" && f ? /* @__PURE__ */ X(Xr, {
3671
+ values: A,
3672
+ entity: i,
3673
+ columns: s,
3674
+ editableColumns: c,
3675
+ errors: g?.error ? [...m, `_error:${g.error}`] : m,
3676
+ saving: g?.saving ?? !1,
3677
+ onChange: (e, n) => _(t, e, n),
3678
+ onConfirm: () => b(t),
3679
+ onCancel: () => x(t),
3680
+ refs: C
3681
+ }) : /* @__PURE__ */ Z("div", {
3682
+ style: {
3683
+ border: "1px solid var(--border)",
3684
+ borderRadius: 8,
3685
+ background: "var(--surface)",
3686
+ opacity: h ? .58 : 1,
3687
+ overflow: "hidden"
3688
+ },
3689
+ children: [/* @__PURE__ */ X("div", {
3690
+ style: {
3691
+ padding: 10,
3692
+ display: "flex",
3693
+ flexDirection: "column",
3694
+ gap: 12
3695
+ },
3696
+ children: s.map((e) => {
3697
+ let n = i.fields.get(e), r = l && d === "inline_edit" && c.has(e), s = T && e === w, f = n ? S(n, e, a) : e, p = `${k}-${t}-${e}`, m = `${p}-label`, h = {
3698
+ fontSize: 11.5,
3699
+ fontWeight: 600,
3700
+ color: "var(--text-3)"
3701
+ }, g = n ? V({
3702
+ field: n,
3703
+ fieldName: e,
3704
+ value: A[e],
3705
+ mode: r ? "edit" : "display",
3706
+ onChange: r ? (n) => _(t, e, n) : void 0,
3707
+ record: A,
3708
+ refs: C,
3709
+ compact: r,
3710
+ entity: i,
3711
+ entities: a,
3712
+ screens: s ? void 0 : o,
3713
+ fieldId: p,
3714
+ labelId: m,
3715
+ locale: O
3716
+ }) : u(A[e]);
3717
+ return /* @__PURE__ */ Z("div", {
3718
+ style: {
3719
+ display: "flex",
3720
+ flexDirection: "column",
3721
+ gap: 5,
3722
+ minWidth: 0
3723
+ },
3724
+ children: [r && n ? /* @__PURE__ */ X("label", {
3725
+ id: m,
3726
+ htmlFor: p,
3727
+ style: h,
3728
+ children: f
3729
+ }) : /* @__PURE__ */ X("div", {
3730
+ id: m,
3731
+ style: h,
3732
+ children: f
3733
+ }), /* @__PURE__ */ X("div", {
3734
+ style: { minWidth: 0 },
3735
+ children: s && !r ? /* @__PURE__ */ X("a", {
3736
+ href: T,
3737
+ style: {
3738
+ color: "var(--accent)",
3739
+ textDecoration: "none",
3740
+ fontWeight: 500
3741
+ },
3742
+ children: g
3743
+ }) : g
3744
+ })]
3745
+ }, e);
3746
+ })
3747
+ }), (l || E && E.length > 0) && /* @__PURE__ */ Z("div", {
3748
+ style: {
3749
+ minHeight: 42,
3750
+ padding: "6px 8px",
3751
+ borderTop: "1px solid var(--divider)",
3752
+ display: "flex",
3753
+ alignItems: "center",
3754
+ justifyContent: "flex-end",
3755
+ gap: 6
3756
+ },
3757
+ children: [l && /* @__PURE__ */ Z(Y, { children: [
3758
+ g?.saving && /* @__PURE__ */ X(p, { size: 12 }),
3759
+ g?.error && /* @__PURE__ */ X("span", {
3760
+ style: {
3761
+ fontSize: 11,
3762
+ color: "var(--danger)"
3763
+ },
3764
+ title: g.error,
3765
+ children: "!"
3766
+ }),
3767
+ d === "row_edit" && /* @__PURE__ */ X(H, {
3768
+ size: 32,
3769
+ icon: /* @__PURE__ */ X(e.edit, { size: 14 }),
3770
+ onClick: () => y(t),
3771
+ title: "Edit row"
3772
+ }),
3773
+ /* @__PURE__ */ X(H, {
3774
+ size: 32,
3775
+ icon: /* @__PURE__ */ X(e.trash, { size: 14 }),
3776
+ onClick: () => v(t),
3777
+ title: "Delete row"
3778
+ })
3779
+ ] }), !l && E && E.length > 0 && /* @__PURE__ */ X(Mr, {
3780
+ actions: E,
3781
+ objectIds: [t],
3782
+ row: A,
3783
+ onSuccess: D
3784
+ })]
3785
+ })]
3786
+ });
3787
+ }
3788
+ function Jr({ rowId: t, row: r, entity: i, entities: a, screens: o, columns: s, editableColumns: c, editable: l, interaction: d, isEditing: f, editErrors: m, isDeleting: h, activeCell: g, setActiveCell: _, rowState: v, onCellChange: y, onDeleteClick: b, onStartEdit: x, onConfirmEdit: S, onCancelEdit: C, refs: w, identityCol: T, href: E, rowActions: D, onRowActionSuccess: O }) {
3789
+ let k = n(), A = K(() => !v || Object.keys(v.buffer).length === 0 ? r : {
3790
+ ...r,
3791
+ ...v.buffer
3792
+ }, [r, v]);
3793
+ if (d === "row_edit" && f) return /* @__PURE__ */ X(Yr, {
3794
+ values: A,
3795
+ entity: i,
3796
+ columns: s,
3797
+ editableColumns: c,
3798
+ errors: v?.error ? [...m, `_error:${v.error}`] : m,
3799
+ saving: v?.saving ?? !1,
3800
+ onChange: (e, n) => y(t, e, n),
3801
+ onConfirm: () => S(t),
3802
+ onCancel: () => C(t),
3803
+ refs: w
3804
+ });
3805
+ let j = Me, M = {
3806
+ padding: "4px 4px",
3807
+ borderBottom: "1px solid var(--divider)",
3808
+ verticalAlign: "middle"
3809
+ }, N = d === "inline_edit";
3810
+ return /* @__PURE__ */ Z("tr", {
3811
+ style: { opacity: h ? .5 : 1 },
3812
+ children: [
3813
+ s.map((e) => {
3814
+ let n = i.fields.get(e), r = c.has(e);
3815
+ if (N && g?.rowId === t && g?.col === e && r) return /* @__PURE__ */ X("td", {
3816
+ style: M,
3817
+ children: n ? V({
3818
+ field: n,
3819
+ fieldName: e,
3820
+ value: A[e],
3821
+ mode: "edit",
3822
+ onChange: (n) => y(t, e, n),
3823
+ record: A,
3824
+ refs: w,
3825
+ compact: !0,
3826
+ locale: k
3827
+ }) : u(A[e])
3828
+ }, e);
3829
+ let s = E && e === T, l = n ? V({
3830
+ field: n,
3831
+ fieldName: e,
3832
+ value: A[e],
3833
+ mode: "display",
3834
+ record: A,
3835
+ refs: w,
3836
+ entity: i,
3837
+ entities: a,
3838
+ screens: s ? void 0 : o,
3839
+ locale: k
3840
+ }) : u(A[e]), d = N && r && !h;
3841
+ return /* @__PURE__ */ X("td", {
3842
+ style: {
3843
+ ...j,
3844
+ cursor: d ? "pointer" : "default"
3845
+ },
3846
+ onClick: d ? () => _({
3847
+ rowId: t,
3848
+ col: e
3849
+ }) : void 0,
3850
+ children: s ? /* @__PURE__ */ X("a", {
3851
+ href: E,
3852
+ style: {
3853
+ color: "var(--accent)",
3854
+ textDecoration: "none",
3855
+ fontWeight: 500
3856
+ },
3857
+ onMouseEnter: (e) => e.currentTarget.style.textDecoration = "underline",
3858
+ onMouseLeave: (e) => e.currentTarget.style.textDecoration = "none",
3859
+ children: l
3860
+ }) : l
3861
+ }, e);
3862
+ }),
3863
+ l && /* @__PURE__ */ X("td", {
3864
+ style: {
3865
+ padding: "4px 8px",
3866
+ borderBottom: "1px solid var(--divider)",
3867
+ verticalAlign: "middle"
3868
+ },
3869
+ children: /* @__PURE__ */ Z("div", {
3870
+ style: {
3871
+ display: "flex",
3872
+ alignItems: "center",
3873
+ gap: 4
3874
+ },
3875
+ children: [
3876
+ v?.saving && /* @__PURE__ */ X(p, { size: 12 }),
3877
+ v?.error && /* @__PURE__ */ X("span", {
3878
+ style: {
3879
+ fontSize: 11,
3880
+ color: "var(--danger)"
3881
+ },
3882
+ title: v.error,
3883
+ children: "!"
3884
+ }),
3885
+ d === "row_edit" && /* @__PURE__ */ X(H, {
3886
+ size: 24,
3887
+ icon: /* @__PURE__ */ X(e.edit, { size: 12 }),
3888
+ onClick: () => x(t),
3889
+ title: "Edit row"
3890
+ }),
3891
+ /* @__PURE__ */ X(H, {
3892
+ size: 24,
3893
+ icon: /* @__PURE__ */ X(e.trash, { size: 12 }),
3894
+ onClick: () => b(t),
3895
+ title: "Delete row"
3896
+ })
3897
+ ]
3898
+ })
3899
+ }),
3900
+ !l && D && D.length > 0 && /* @__PURE__ */ X("td", {
3901
+ style: {
3902
+ padding: "4px 8px",
3903
+ borderBottom: "1px solid var(--divider)",
3904
+ verticalAlign: "middle"
3905
+ },
3906
+ children: /* @__PURE__ */ X(Mr, {
3907
+ actions: D,
3908
+ objectIds: [t],
3909
+ row: A,
3910
+ onSuccess: O
3911
+ })
3912
+ })
3913
+ ]
3914
+ });
3915
+ }
3916
+ function Yr({ values: t, entity: r, columns: i, editableColumns: a, errors: o, saving: s, onChange: c, onConfirm: l, onCancel: d, refs: f, accent: m }) {
3917
+ let h = n(), g = o.find((e) => e.startsWith("_error:")), _ = new Set(o.filter((e) => !e.startsWith("_error:"))), v = {
3918
+ padding: "6px 12px",
3919
+ borderBottom: "1px solid var(--divider)",
3920
+ verticalAlign: "middle",
3921
+ height: 40,
3922
+ minWidth: 0
3923
+ }, y = {
3924
+ display: "block",
3925
+ width: "100%",
3926
+ maxWidth: "100%",
3927
+ minWidth: 0
3928
+ };
3929
+ return /* @__PURE__ */ Z("tr", {
3930
+ style: m ? { boxShadow: "inset 3px 0 0 var(--accent)" } : void 0,
3931
+ onKeyDown: (e) => {
3932
+ e.key === "Enter" && !e.shiftKey ? (e.preventDefault(), l()) : e.key === "Escape" && (e.preventDefault(), d());
3933
+ },
3934
+ children: [i.map((e) => {
3935
+ let n = r.fields.get(e), i = a.has(e), o = _.has(e);
3936
+ return i ? /* @__PURE__ */ X("td", {
3937
+ style: {
3938
+ ...v,
3939
+ outline: o ? "1px solid var(--danger)" : "none",
3940
+ outlineOffset: -1
3941
+ },
3942
+ title: o ? `${e} is required` : void 0,
3943
+ children: /* @__PURE__ */ X("div", {
3944
+ style: y,
3945
+ children: n ? V({
3946
+ field: n,
3947
+ fieldName: e,
3948
+ value: t[e],
3949
+ mode: "edit",
3950
+ onChange: (t) => c(e, t),
3951
+ record: t,
3952
+ refs: f,
3953
+ compact: !0,
3954
+ locale: h
3955
+ }) : u(t[e])
3956
+ })
3957
+ }, e) : /* @__PURE__ */ X("td", {
3958
+ style: {
3959
+ ...v,
3960
+ color: "var(--text-3)"
3961
+ },
3962
+ children: n?.auto ? "—" : u(t[e])
3963
+ }, e);
3964
+ }), /* @__PURE__ */ X("td", {
3965
+ style: v,
3966
+ children: /* @__PURE__ */ Z("div", {
3967
+ style: {
3968
+ display: "flex",
3969
+ alignItems: "center",
3970
+ gap: 4,
3971
+ justifyContent: "flex-end"
3972
+ },
3973
+ children: [
3974
+ g && /* @__PURE__ */ X("span", {
3975
+ style: {
3976
+ fontSize: 11,
3977
+ color: "var(--danger)"
3978
+ },
3979
+ title: g.slice(7),
3980
+ children: "!"
3981
+ }),
3982
+ /* @__PURE__ */ X(H, {
3983
+ size: 24,
3984
+ icon: X(s ? p : e.check, { size: 12 }),
3985
+ onClick: l,
3986
+ title: "Confirm (Enter)"
3987
+ }),
3988
+ /* @__PURE__ */ X(H, {
3989
+ size: 24,
3990
+ icon: /* @__PURE__ */ X(e.x, { size: 12 }),
3991
+ onClick: d,
3992
+ title: "Cancel (Esc)"
3993
+ })
3994
+ ]
3995
+ })
3996
+ })]
3997
+ });
3998
+ }
3999
+ function Xr({ values: t, entity: r, columns: i, editableColumns: a, errors: o, saving: s, onChange: c, onConfirm: l, onCancel: d, refs: f, accent: m }) {
4000
+ let h = n(), g = Ie(), _ = o.find((e) => e.startsWith("_error:")), v = new Set(o.filter((e) => !e.startsWith("_error:")));
4001
+ return /* @__PURE__ */ Z("div", {
4002
+ style: {
4003
+ border: "1px solid var(--border)",
4004
+ borderRadius: 8,
4005
+ background: "var(--surface)",
4006
+ overflow: "hidden",
4007
+ boxShadow: m ? "inset 3px 0 0 var(--accent)" : void 0
4008
+ },
4009
+ onKeyDown: (e) => {
4010
+ e.key === "Enter" && !e.shiftKey ? (e.preventDefault(), l()) : e.key === "Escape" && (e.preventDefault(), d());
4011
+ },
4012
+ children: [/* @__PURE__ */ X("div", {
4013
+ style: {
4014
+ padding: 10,
4015
+ display: "flex",
4016
+ flexDirection: "column",
4017
+ gap: 12
4018
+ },
4019
+ children: i.map((e) => {
4020
+ let n = r.fields.get(e), i = a.has(e), o = v.has(e), s = n ? S(n, e) : e, l = `${g}-${e}`, d = `${l}-label`, p = {
4021
+ fontSize: 11.5,
4022
+ fontWeight: 600,
4023
+ color: "var(--text-3)"
4024
+ };
4025
+ return /* @__PURE__ */ Z("div", {
4026
+ style: {
4027
+ display: "flex",
4028
+ flexDirection: "column",
4029
+ gap: 5,
4030
+ minWidth: 0
4031
+ },
4032
+ children: [i && n ? /* @__PURE__ */ X("label", {
4033
+ id: d,
4034
+ htmlFor: l,
4035
+ style: p,
4036
+ children: s
4037
+ }) : /* @__PURE__ */ X("div", {
4038
+ id: d,
4039
+ style: p,
4040
+ children: s
4041
+ }), /* @__PURE__ */ X("div", {
4042
+ style: {
4043
+ minWidth: 0,
4044
+ outline: o ? "1px solid var(--danger)" : "none",
4045
+ outlineOffset: 3,
4046
+ borderRadius: o ? 5 : 0
4047
+ },
4048
+ title: o ? `${e} is required` : void 0,
4049
+ children: i ? n ? V({
4050
+ field: n,
4051
+ fieldName: e,
4052
+ value: t[e],
4053
+ mode: "edit",
4054
+ onChange: (t) => c(e, t),
4055
+ record: t,
4056
+ refs: f,
4057
+ compact: !0,
4058
+ fieldId: l,
4059
+ labelId: d,
4060
+ locale: h
4061
+ }) : u(t[e]) : n?.auto ? "—" : u(t[e])
4062
+ })]
4063
+ }, e);
4064
+ })
4065
+ }), /* @__PURE__ */ Z("div", {
4066
+ style: {
4067
+ minHeight: 42,
4068
+ padding: "6px 8px",
4069
+ borderTop: "1px solid var(--divider)",
4070
+ display: "flex",
4071
+ alignItems: "center",
4072
+ justifyContent: "flex-end",
4073
+ gap: 6
4074
+ },
4075
+ children: [
4076
+ _ && /* @__PURE__ */ X("span", {
4077
+ style: {
4078
+ fontSize: 11,
4079
+ color: "var(--danger)"
4080
+ },
4081
+ title: _.slice(7),
4082
+ children: "!"
4083
+ }),
4084
+ /* @__PURE__ */ X(H, {
4085
+ size: 32,
4086
+ icon: X(s ? p : e.check, { size: 14 }),
4087
+ onClick: l,
4088
+ title: "Confirm (Enter)"
4089
+ }),
4090
+ /* @__PURE__ */ X(H, {
4091
+ size: 32,
4092
+ icon: /* @__PURE__ */ X(e.x, { size: 14 }),
4093
+ onClick: d,
4094
+ title: "Cancel (Esc)"
4095
+ })
4096
+ ]
4097
+ })]
4098
+ });
4099
+ }
4100
+ function Zr({ draftRow: e, entity: t, columns: n, editableColumns: r, foreignKey: i, draftErrors: a, draftSaving: o, onChange: s, onConfirm: c, onCancel: l, refs: u }) {
4101
+ return /* @__PURE__ */ X(Yr, {
4102
+ values: e,
4103
+ entity: t,
4104
+ columns: n,
4105
+ editableColumns: K(() => {
4106
+ let e = new Set(r);
4107
+ return e.delete(i), e;
4108
+ }, [r, i]),
4109
+ errors: a,
4110
+ saving: o,
4111
+ onChange: s,
4112
+ onConfirm: c,
4113
+ onCancel: l,
4114
+ refs: u,
4115
+ accent: !0
4116
+ });
4117
+ }
4118
+ function Qr({ draftRow: e, entity: t, columns: n, editableColumns: r, foreignKey: i, draftErrors: a, draftSaving: o, onChange: s, onConfirm: c, onCancel: l, refs: u }) {
4119
+ return /* @__PURE__ */ X(Xr, {
4120
+ values: e,
4121
+ entity: t,
4122
+ columns: n,
4123
+ editableColumns: K(() => {
4124
+ let e = new Set(r);
4125
+ return e.delete(i), e;
4126
+ }, [r, i]),
4127
+ errors: a,
4128
+ saving: o,
4129
+ onChange: s,
4130
+ onConfirm: c,
4131
+ onCancel: l,
4132
+ refs: u,
4133
+ accent: !0
4134
+ });
4135
+ }
4136
+ //#endregion
4137
+ //#region src/hooks/useMutations.ts
4138
+ function $r(e) {
4139
+ B.error(e.message);
4140
+ }
4141
+ function ei(e, t, n = {}) {
4142
+ e.invalidateQueries({ queryKey: ["entity-data", t] }), e.invalidateQueries({ queryKey: ["entity-count", t] }), n.item && e.invalidateQueries({ queryKey: ["entity-item", t] }), n.children && e.invalidateQueries({ queryKey: [tr, t] }), n.objectMeta && (e.invalidateQueries({ queryKey: ["object-status", t] }), e.invalidateQueries({ queryKey: ["object-properties", t] }));
4143
+ }
4144
+ function ti(e) {
4145
+ let t = Ue();
4146
+ return Ve({
4147
+ mutationFn: (t) => de(e, t),
4148
+ onSuccess: () => {
4149
+ ei(t, e), B.success("Record created");
4150
+ },
4151
+ onError: $r
4152
+ });
4153
+ }
4154
+ function ni(e) {
4155
+ let t = Ue();
4156
+ return Ve({
4157
+ mutationFn: ({ pkValues: t, data: n }) => r(e, t, n),
4158
+ onSuccess: () => {
4159
+ ei(t, e, {
4160
+ item: !0,
4161
+ children: !0,
4162
+ objectMeta: !0
4163
+ }), B.success("Record updated");
4164
+ },
4165
+ onError: $r
4166
+ });
4167
+ }
4168
+ function ri(e) {
4169
+ let t = Ue();
4170
+ return Ve({
4171
+ mutationFn: (t) => he(e, t),
4172
+ onSuccess: () => {
4173
+ ei(t, e, { item: !0 }), B.success("Record deleted");
4174
+ },
4175
+ onError: $r
4176
+ });
4177
+ }
4178
+ function ii(e) {
4179
+ let t = Ue();
4180
+ return Ve({
4181
+ mutationFn: (t) => l(e, t),
4182
+ onSuccess: () => {
4183
+ ei(t, e, {
4184
+ item: !0,
4185
+ objectMeta: !0
4186
+ }), B.success("Record restored");
4187
+ },
4188
+ onError: $r
4189
+ });
4190
+ }
4191
+ //#endregion
4192
+ //#region src/components/shared/LoadingSkeleton.tsx
4193
+ var ai = {
4194
+ display: "block",
4195
+ background: "linear-gradient(90deg, var(--surface-3) 0%, var(--surface-2) 40%, var(--surface-3) 80%)",
4196
+ backgroundSize: "200% 100%",
4197
+ borderRadius: 6,
4198
+ animation: "declarion-shimmer 1.2s ease-in-out infinite"
4199
+ };
4200
+ function oi({ height: e, width: t }) {
4201
+ return /* @__PURE__ */ Z(Y, { children: [/* @__PURE__ */ X("style", { children: "@keyframes declarion-shimmer{from{background-position:200% 0}to{background-position:-200% 0}}" }), /* @__PURE__ */ X("span", { style: {
4202
+ ...ai,
4203
+ height: e,
4204
+ width: t ?? "100%"
4205
+ } })] });
4206
+ }
4207
+ function si({ rows: e = 8, cols: t = 4 }) {
4208
+ return /* @__PURE__ */ Z("div", {
4209
+ style: {
4210
+ padding: 16,
4211
+ display: "flex",
4212
+ flexDirection: "column",
4213
+ gap: 10
4214
+ },
4215
+ children: [/* @__PURE__ */ X("div", {
4216
+ style: {
4217
+ display: "flex",
4218
+ gap: 16
4219
+ },
4220
+ children: Array.from({ length: t }).map((e, t) => /* @__PURE__ */ X("div", {
4221
+ style: { flex: 1 },
4222
+ children: /* @__PURE__ */ X(oi, { height: 14 })
4223
+ }, t))
4224
+ }), Array.from({ length: e }).map((e, n) => /* @__PURE__ */ X("div", {
4225
+ style: {
4226
+ display: "flex",
4227
+ gap: 16
4228
+ },
4229
+ children: Array.from({ length: t }).map((e, t) => /* @__PURE__ */ X("div", {
4230
+ style: { flex: 1 },
4231
+ children: /* @__PURE__ */ X(oi, { height: 28 })
4232
+ }, t))
4233
+ }, n))]
4234
+ });
4235
+ }
4236
+ function ci() {
4237
+ return /* @__PURE__ */ Z("div", {
4238
+ style: {
4239
+ padding: 20,
4240
+ display: "flex",
4241
+ flexDirection: "column",
4242
+ gap: 16
4243
+ },
4244
+ children: [
4245
+ /* @__PURE__ */ X(oi, {
4246
+ height: 12,
4247
+ width: 160
4248
+ }),
4249
+ /* @__PURE__ */ Z("div", {
4250
+ style: {
4251
+ display: "flex",
4252
+ alignItems: "center",
4253
+ gap: 12
4254
+ },
4255
+ children: [/* @__PURE__ */ X("span", { style: {
4256
+ ...ai,
4257
+ width: 32,
4258
+ height: 32,
4259
+ borderRadius: 8
4260
+ } }), /* @__PURE__ */ X(oi, {
4261
+ height: 22,
4262
+ width: 240
4263
+ })]
4264
+ }),
4265
+ Array.from({ length: 2 }).map((e, t) => /* @__PURE__ */ Z("div", {
4266
+ style: {
4267
+ border: "1px solid var(--border)",
4268
+ borderRadius: 10,
4269
+ background: "var(--surface)",
4270
+ overflow: "hidden"
4271
+ },
4272
+ children: [/* @__PURE__ */ X("div", {
4273
+ style: {
4274
+ padding: "11px 14px",
4275
+ borderBottom: "1px solid var(--divider)"
4276
+ },
4277
+ children: /* @__PURE__ */ X(oi, {
4278
+ height: 13,
4279
+ width: 150
4280
+ })
4281
+ }), /* @__PURE__ */ X("div", {
4282
+ style: {
4283
+ padding: 16,
4284
+ display: "grid",
4285
+ gridTemplateColumns: "repeat(2, minmax(0, 1fr))",
4286
+ gap: "12px 24px"
4287
+ },
4288
+ children: Array.from({ length: 6 }).map((e, t) => /* @__PURE__ */ Z("div", {
4289
+ style: {
4290
+ display: "flex",
4291
+ gap: 16
4292
+ },
4293
+ children: [/* @__PURE__ */ X(oi, {
4294
+ height: 13,
4295
+ width: 110
4296
+ }), /* @__PURE__ */ X("div", {
4297
+ style: { flex: 1 },
4298
+ children: /* @__PURE__ */ X(oi, { height: 13 })
4299
+ })]
4300
+ }, t))
4301
+ })]
4302
+ }, t))
4303
+ ]
4304
+ });
4305
+ }
4306
+ //#endregion
4307
+ //#region src/lib/sort.ts
4308
+ var li = {
4309
+ nulls_first: "first",
4310
+ nulls_last: "last"
4311
+ };
4312
+ function ui(e) {
4313
+ if (!e) return [];
4314
+ let t = [];
4315
+ for (let n of e.split(",")) {
4316
+ let e = n.trim();
4317
+ if (!e) continue;
4318
+ let r = e.split(":"), i = r[0]?.trim();
4319
+ if (!i || i.startsWith("$property.")) continue;
4320
+ let a = {
4321
+ field: i,
4322
+ dir: r[1]?.trim().toLowerCase() === "desc" ? "desc" : "asc"
4323
+ }, o = r[2]?.trim().toLowerCase();
4324
+ if (o) {
4325
+ let e = li[o];
4326
+ e && (a.nulls = e);
4327
+ }
4328
+ t.push(a);
4329
+ }
4330
+ return t;
4331
+ }
4332
+ function di(e) {
4333
+ if (!e) return;
4334
+ let t = [];
4335
+ for (let n of e.split(",")) {
4336
+ let e = n.trim();
4337
+ if (!e) continue;
4338
+ let r = e.split(":")[0]?.trim();
4339
+ r && r.startsWith("$property.") || t.push(e);
4340
+ }
4341
+ return t.length > 0 ? t.join(",") : void 0;
4342
+ }
4343
+ function fi(e) {
4344
+ return e.map((e) => {
4345
+ let t = `${e.field}:${e.dir}`;
4346
+ return e.nulls === "first" ? `${t}:nulls_first` : e.nulls === "last" ? `${t}:nulls_last` : t;
4347
+ }).join(",");
4348
+ }
4349
+ function pi(e, t) {
4350
+ let n = e.findIndex((e) => e.field === t);
4351
+ return n >= 0 ? [...e.slice(0, n), ...e.slice(n + 1)] : e.length >= 5 ? e : [...e, {
4352
+ field: t,
4353
+ dir: "asc"
4354
+ }];
4355
+ }
4356
+ function mi(e, t) {
4357
+ let n = e.filter((e) => e.field !== t.field);
4358
+ return n.length >= 5 ? e : [...n, t];
4359
+ }
4360
+ function hi(e, t) {
4361
+ let n = e.findIndex((e) => e.field === t);
4362
+ return n < 0 ? e : [...e.slice(0, n), ...e.slice(n + 1)];
4363
+ }
4364
+ //#endregion
4365
+ //#region src/hooks/useScreenBack.ts
4366
+ function gi(e) {
4367
+ let t = ze(), n = oe(), r = ce(), i = At((e) => e.depth), { data: a } = ae(), o = e?.fallback, s = kt((e) => {
4368
+ let t = e.tabs.find((t) => t.id === e.activeTabId);
4369
+ return t ? t.returnTo : void 0;
4370
+ }), { hasOriginBack: c, allowFallbackBack: l } = K(() => It(s, n.enabled), [s, n.enabled]), u = W(() => {
4371
+ if (n.enabled) {
4372
+ At.getState().depth > 0 ? r() : o?.();
4373
+ return;
4374
+ }
4375
+ let e = kt.getState(), i = Lt(e.tabs.find((t) => t.id === e.activeTabId)?.returnTo, e.tabs, !1);
4376
+ if (!i) {
4377
+ o?.();
4378
+ return;
4379
+ }
4380
+ if (i.kind === "live" && i.tabId) e.commitTabNavigation(i.tabId, { search: i.search ?? "" });
4381
+ else if (i.kind === "reopen") {
4382
+ let t = i.title ? void 0 : v(i.pathname, a?.screens, a?.entities);
4383
+ e.openTab({
4384
+ pathname: i.pathname,
4385
+ search: i.search ?? "",
4386
+ title: i.title ?? t?.title ?? i.pathname,
4387
+ icon: i.icon ?? t?.icon,
4388
+ screen: i.screen,
4389
+ closable: !0
4390
+ });
4391
+ }
4392
+ t({
4393
+ pathname: i.pathname,
4394
+ search: Pt(i.search),
4395
+ hash: i.hash || void 0
4396
+ });
4397
+ }, [
4398
+ n.enabled,
4399
+ r,
4400
+ o,
4401
+ t,
4402
+ a?.screens,
4403
+ a?.entities
4404
+ ]);
4405
+ return {
4406
+ canGoBack: n.enabled ? i > 0 || !!o : c || !!o,
4407
+ hasOriginBack: c,
4408
+ allowFallbackBack: l,
4409
+ goBack: u
4410
+ };
4411
+ }
4412
+ //#endregion
4413
+ //#region src/lib/field-classification.ts
4414
+ function _i(e, t) {
4415
+ let n = e?.field_access?.[t];
4416
+ return !n || n.read === "granted";
4417
+ }
4418
+ function vi(e, t) {
4419
+ let n = e?.field_access?.[t];
4420
+ return !n || n.write === "granted";
4421
+ }
4422
+ function yi(e, t) {
4423
+ return e?.field_access?.[t]?.classification;
4424
+ }
4425
+ function bi(e, t) {
4426
+ return e?.field_access?.[t]?.required_permission;
4427
+ }
4428
+ function xi(e, t, n) {
4429
+ let r = yi(t, n);
4430
+ if (r) return e?.classifications?.[r];
4431
+ }
4432
+ function Si(e, t, n) {
4433
+ return !!xi(e, t, n)?.sod_protected;
4434
+ }
4435
+ function Ci(e, t) {
4436
+ return e?.field_access?.[t];
4437
+ }
4438
+ //#endregion
4439
+ //#region src/components/pages/list/cardProjection.ts
4440
+ var wi = 4, Ti = 2, Ei = 2, Di = [
4441
+ "screen_card",
4442
+ "entity_card",
4443
+ "saved_view_columns",
4444
+ "screen_default_columns",
4445
+ "screen_columns",
4446
+ "entity_inference"
4447
+ ], Oi = /* @__PURE__ */ new Set(["_select", "_actions"]), ki = /* @__PURE__ */ new Set([
4448
+ "text",
4449
+ "rich_text",
4450
+ "multilang_text",
4451
+ "json",
4452
+ "structure",
4453
+ "secret",
4454
+ "password",
4455
+ "bytes"
4456
+ ]), Ai = /* @__PURE__ */ new Set(["enum", "bool"]), ji = /* @__PURE__ */ new Set([
4457
+ "date",
4458
+ "time",
4459
+ "timestamp"
4460
+ ]), Mi = /* @__PURE__ */ new Set([
4461
+ "string",
4462
+ "text",
4463
+ "email",
4464
+ "url",
4465
+ "phone",
4466
+ "int",
4467
+ "integer",
4468
+ "bigint",
4469
+ "smallint",
4470
+ "float",
4471
+ "double",
4472
+ "decimal",
4473
+ "numeric",
4474
+ "number",
4475
+ "money",
4476
+ "percent",
4477
+ "bool",
4478
+ "boolean",
4479
+ "date",
4480
+ "datetime",
4481
+ "timestamp",
4482
+ "timestamptz",
4483
+ "enum",
4484
+ "status"
4485
+ ]);
4486
+ function Ni(e) {
4487
+ let { entity: t, screen: n, savedViewColumns: r } = e, i = n?.card;
4488
+ if (i) return Ii(t, i, "screen_card");
4489
+ if (t?.card) return Ii(t, t.card, "entity_card");
4490
+ let a = zi(t, n, r);
4491
+ return Li(t, a.columns, a.source);
4492
+ }
4493
+ function Pi(e) {
4494
+ let { entity: t, screen: n, presentation: r, visibleColumns: i, card: a, rowActions: o, toolbarActions: s, bulkActions: c, sort: l, includeDetailHandoff: u = !0, screens: d } = e, f = new ma(), p = r === "cards" ? a.renderFields : Vi(t, i, { explicit: !0 });
4495
+ for (let e of p) f.addField(e, "render"), da(t, e, f, "render");
4496
+ let m = Qi(t, f), h = ra(t, [
4497
+ o,
4498
+ s,
4499
+ c
4500
+ ], f), g = ia(t, l, f), _ = aa(t, n, d, f);
4501
+ if (u) for (let e of m) f.addField(e, "detail_handoff");
4502
+ let v = new $();
4503
+ for (let e of m) v.add(e);
4504
+ for (let e of h) v.add(e);
4505
+ for (let e of g) v.add(e);
4506
+ for (let e of _) v.add(e);
4507
+ let y = new $();
4508
+ for (let e of p) ua(t, e, y, f);
4509
+ for (let e of v.values()) ua(t, e, y, f);
4510
+ let b = y.values(), x = fa(f);
4511
+ return {
4512
+ renderFields: p,
4513
+ dependencyFields: v.values().filter((e) => !p.includes(e)),
4514
+ conditionFields: h,
4515
+ identityFields: m,
4516
+ sortFields: g,
4517
+ selectFields: b.length > 0 ? b : void 0,
4518
+ expandFields: x.length > 0 ? x : void 0,
4519
+ reasons: f.snapshot()
4520
+ };
4521
+ }
4522
+ function Fi(e, t, n) {
4523
+ if (!e || t?.on_row_click !== "peek" || t.quick_peek?.enabled === !1) return [];
4524
+ let r = t.quick_peek?.fields;
4525
+ if (r && r.length > 0) return Vi(e, r, { explicit: !0 });
4526
+ let i = t.quick_peek?.sections;
4527
+ if (i && i.length > 0) {
4528
+ let r = Object.values(n ?? {}).find((e) => e.type === "detail" && e.entity === t.entity), a = new $();
4529
+ oa(r?.items, new Set(i.map(String)), a);
4530
+ let o = Vi(e, a.values(), { explicit: !0 });
4531
+ if (o.length > 0) return o;
4532
+ }
4533
+ return la(e);
4534
+ }
4535
+ function Ii(e, t, n) {
4536
+ let r = t.max_body_fields ?? wi, i = Hi(e, t.title_field, { explicit: !0 }), a = Hi(e, t.subtitle_field, { explicit: !0 }), o = Vi(e, t.badge_fields ?? [], { explicit: !0 }), s = Vi(e, t.fields ?? [], { explicit: !0 }), c = Vi(e, t.meta_fields ?? [], { explicit: !0 });
4537
+ return Ri({
4538
+ source: n,
4539
+ explicit: !0,
4540
+ titleField: i,
4541
+ titleUsesDisplay: !i,
4542
+ subtitleField: a,
4543
+ badgeFields: o,
4544
+ bodyFields: s,
4545
+ metaFields: c,
4546
+ hideEmptyFields: t.hide_empty_fields ?? !0,
4547
+ maxBodyFields: r
4548
+ });
4549
+ }
4550
+ function Li(e, t, n) {
4551
+ let r = Vi(e, t, { explicit: !1 }), i = wi, a = Hi(e, e?.display?.display_field, { explicit: !1 }), o = a ?? Ui(e, r, {
4552
+ allowLong: !1,
4553
+ allowAuto: !1
4554
+ }), s = a !== void 0, c = o ? /* @__PURE__ */ new Set([o]) : void 0, l = r.find((t) => !c?.has(t) && Gi(e, t)), u = new Set([o, l].filter((e) => !!e)), d = qi(e, r).filter((e) => !u.has(e)).slice(0, Ti);
4555
+ for (let e of d) u.add(e);
4556
+ let f = r.filter((t) => !u.has(t) && Ji(e, t)).slice(0, Ei);
4557
+ for (let e of f) u.add(e);
4558
+ return Ri({
4559
+ source: n,
4560
+ explicit: !1,
4561
+ titleField: o,
4562
+ titleUsesDisplay: s,
4563
+ subtitleField: l,
4564
+ badgeFields: d,
4565
+ bodyFields: r.filter((t) => !u.has(t) && Wi(e, t)).slice(0, i),
4566
+ metaFields: f,
4567
+ hideEmptyFields: !0,
4568
+ maxBodyFields: i
4569
+ });
4570
+ }
4571
+ function Ri(e) {
4572
+ let t = new $(), n = [], r = (r, i) => {
4573
+ !r || t.has(r) || (t.add(r), n.push({
4574
+ field: r,
4575
+ bucket: i,
4576
+ explicit: e.explicit
4577
+ }));
4578
+ };
4579
+ r(e.titleField, "title"), r(e.subtitleField, "subtitle");
4580
+ for (let t of e.badgeFields) r(t, "badges");
4581
+ for (let t of e.bodyFields) r(t, "body");
4582
+ for (let t of e.metaFields) r(t, "meta");
4583
+ return {
4584
+ source: e.source,
4585
+ explicit: e.explicit,
4586
+ titleField: e.titleField,
4587
+ titleUsesDisplay: e.titleUsesDisplay,
4588
+ subtitleField: e.subtitleField,
4589
+ badgeFields: e.badgeFields,
4590
+ bodyFields: e.bodyFields,
4591
+ metaFields: e.metaFields,
4592
+ hideEmptyFields: e.hideEmptyFields,
4593
+ maxBodyFields: e.maxBodyFields,
4594
+ renderFields: t.values(),
4595
+ fields: n,
4596
+ sourcePrecedence: Di
4597
+ };
4598
+ }
4599
+ function zi(e, t, n) {
4600
+ return n && n.length > 0 ? {
4601
+ source: "saved_view_columns",
4602
+ columns: n
4603
+ } : t?.default_columns && t.default_columns.length > 0 ? {
4604
+ source: "screen_default_columns",
4605
+ columns: t.default_columns
4606
+ } : t?.columns && t.columns.length > 0 ? {
4607
+ source: "screen_columns",
4608
+ columns: t.columns
4609
+ } : {
4610
+ source: "entity_inference",
4611
+ columns: Bi(e)
4612
+ };
4613
+ }
4614
+ function Bi(e) {
4615
+ if (!e) return [];
4616
+ let t = [];
4617
+ e.display.display_field && t.push(e.display.display_field);
4618
+ for (let [n] of e.fields) t.push(n);
4619
+ for (let n of Object.keys(e.status_groups ?? {})) t.push(`$status.${n}`);
4620
+ for (let n of Object.keys(e.properties ?? {})) t.push(`$property.${n}`);
4621
+ if (e.evidence_covered && t.push("$evidence"), e.files) for (let [n] of e.files) t.push(n);
4622
+ return t;
4623
+ }
4624
+ function Vi(e, t, n) {
4625
+ let r = new $();
4626
+ for (let i of t) {
4627
+ let t = Hi(e, i, n);
4628
+ t && r.add(t);
4629
+ }
4630
+ return r.values();
4631
+ }
4632
+ function Hi(e, t, n) {
4633
+ if (!t || Oi.has(t)) return;
4634
+ if (!e) return t.startsWith("$") ? void 0 : t;
4635
+ if (t.startsWith("$status.")) {
4636
+ let n = t.slice(8);
4637
+ return e.status_groups?.[n] ? t : void 0;
4638
+ }
4639
+ if (t.startsWith("$property.")) {
4640
+ let n = t.slice(10);
4641
+ return e.properties?.[n] ? t : void 0;
4642
+ }
4643
+ if (t === "$evidence") return e.evidence_covered ? t : void 0;
4644
+ if (t.startsWith("$")) return;
4645
+ let r = e.fields.get(t), i = e.files?.get(t);
4646
+ if (!(!r && !i) && (n.explicit || !(r && r.display?.is_listable === !1) && !(i && i.display?.is_listable === !1))) return t;
4647
+ }
4648
+ function Ui(e, t, n) {
4649
+ return t.find((t) => n.exclude?.has(t) || !n.allowAuto && Xi(e, t) || !n.allowLong && Zi(e, t) ? !1 : Yi(e, t));
4650
+ }
4651
+ function Wi(e, t) {
4652
+ return !(!Yi(e, t) || Xi(e, t) || Zi(e, t));
4653
+ }
4654
+ function Gi(e, t) {
4655
+ return !(!Yi(e, t) || Xi(e, t) || Zi(e, t) || Ji(e, t) || Ki(e, t));
4656
+ }
4657
+ function Ki(e, t) {
4658
+ if (t.startsWith("$status.") || t.startsWith("$property.") || t === "$evidence") return !0;
4659
+ let n = pa(e, t);
4660
+ return n.kind === "field" && Ai.has(n.field.type);
4661
+ }
4662
+ function qi(e, t) {
4663
+ let n = new $();
4664
+ for (let e of t) (e.startsWith("$status.") || e.startsWith("$property.") || e === "$evidence") && n.add(e);
4665
+ for (let r of t) Ki(e, r) && n.add(r);
4666
+ return n.values();
4667
+ }
4668
+ function Ji(e, t) {
4669
+ if (Xi(e, t)) return !1;
4670
+ let n = pa(e, t);
4671
+ return n.kind === "field" && ji.has(n.field.type);
4672
+ }
4673
+ function Yi(e, t) {
4674
+ return pa(e, t).kind !== "missing";
4675
+ }
4676
+ function Xi(e, t) {
4677
+ let n = pa(e, t);
4678
+ return n.kind === "field" && (n.field.primary === !0 || n.field.auto === !0);
4679
+ }
4680
+ function Zi(e, t) {
4681
+ let n = pa(e, t);
4682
+ return n.kind === "file" ? n.file.mode !== "single" : n.kind === "field" && ki.has(n.field.type);
4683
+ }
4684
+ function Qi(e, t) {
4685
+ if (!e) return [];
4686
+ let n = new $();
4687
+ for (let r of fe(e)) n.add(r), t.addField(r, "identity");
4688
+ let r = Hi(e, e.display.display_field, { explicit: !0 });
4689
+ r && (n.add(r), t.addField(r, "display"), da(e, r, t, "display"));
4690
+ for (let r of $i(e.display.display_template)) {
4691
+ let i = Hi(e, r, { explicit: !0 });
4692
+ i && (n.add(i), t.addField(i, "display_template"), da(e, i, t, "display_template"));
4693
+ }
4694
+ return n.values();
4695
+ }
4696
+ function $i(e) {
4697
+ if (!e) return [];
4698
+ let t = new $(), n = 0;
4699
+ for (; n < e.length;) {
4700
+ let r = e.indexOf("${", n);
4701
+ if (r < 0) break;
4702
+ if (r > 0 && e[r - 1] === "\\") {
4703
+ n = r + 2;
4704
+ continue;
4705
+ }
4706
+ let i = ea(e, r + 2);
4707
+ if (i < 0) break;
4708
+ for (let n of ta(e.slice(r + 2, i))) t.add(n);
4709
+ n = i + 1;
4710
+ }
4711
+ return t.values();
4712
+ }
4713
+ function ea(e, t) {
4714
+ let n = 0;
4715
+ for (let r = t; r < e.length; r += 1) {
4716
+ let t = e[r];
4717
+ if (t === "{") {
4718
+ n += 1;
4719
+ continue;
4720
+ }
4721
+ if (t === "}") {
4722
+ if (n === 0) return r;
4723
+ --n;
4724
+ }
4725
+ }
4726
+ return -1;
4727
+ }
4728
+ function ta(e) {
4729
+ let t = new $(), n = 0;
4730
+ for (; n < e.length;) {
4731
+ let r = e.indexOf("row.", n);
4732
+ if (r < 0) break;
4733
+ if (r > 0 && na(e.charCodeAt(r - 1))) {
4734
+ n = r + 4;
4735
+ continue;
4736
+ }
4737
+ let i = r + 4, a = i;
4738
+ for (; a < e.length && na(e.charCodeAt(a));) a += 1;
4739
+ a > i && t.add(e.slice(i, a)), n = a;
4740
+ }
4741
+ return t.values();
4742
+ }
4743
+ function na(e) {
4744
+ return e >= 48 && e <= 57 || e >= 65 && e <= 90 || e >= 97 && e <= 122 || e === 95;
4745
+ }
4746
+ function ra(e, t, n) {
4747
+ let r = new $();
4748
+ for (let i of t) for (let t of i ?? []) for (let i of [
4749
+ ...t.action.visible_if ?? [],
4750
+ ...t.action.enabled_if ?? [],
4751
+ ...t.action.conditions ?? []
4752
+ ]) {
4753
+ let t = Hi(e, i.field, { explicit: !0 });
4754
+ t && (r.add(t), n.addField(t, "condition"), da(e, t, n, "condition"));
4755
+ }
4756
+ return r.values();
4757
+ }
4758
+ function ia(e, t, n) {
4759
+ let r = typeof t == "string" ? ui(t) : t ?? [], i = new $();
4760
+ for (let t of r) {
4761
+ let r = Hi(e, t.field, { explicit: !0 });
4762
+ r && (i.add(r), n.addField(r, "sort"), da(e, r, n, "sort"));
4763
+ }
4764
+ return i.values();
4765
+ }
4766
+ function aa(e, t, n, r) {
4767
+ let i = Fi(e, t, n);
4768
+ for (let t of i) r.addField(t, "quick_peek"), da(e, t, r, "quick_peek");
4769
+ return i;
4770
+ }
4771
+ function oa(e, t, n) {
4772
+ if (Array.isArray(e)) {
4773
+ for (let r of e) if (!(!r || typeof r != "object")) {
4774
+ if ("section" in r) {
4775
+ let e = r.section, i = ca(e?.name);
4776
+ i && t.has(i) && sa(e?.items, n);
4777
+ continue;
4778
+ }
4779
+ "fields" in r && sa([r], n);
4780
+ }
4781
+ }
4782
+ }
4783
+ function sa(e, t) {
4784
+ if (Array.isArray(e)) {
4785
+ for (let n of e) if (!(!n || typeof n != "object")) {
4786
+ if ("fields" in n) {
4787
+ let e = n.fields;
4788
+ if (Array.isArray(e)) {
4789
+ for (let n of e) if (typeof n == "string") t.add(n);
4790
+ else if (n && typeof n == "object" && "name" in n) {
4791
+ let e = n.name;
4792
+ typeof e == "string" && t.add(e);
4793
+ }
4794
+ }
4795
+ }
4796
+ "section" in n && sa(n.section?.items, t);
4797
+ }
4798
+ }
4799
+ }
4800
+ function ca(e) {
4801
+ if (typeof e == "string") return e;
4802
+ if (e && typeof e == "object") {
4803
+ let t = Object.values(e).find((e) => typeof e == "string");
4804
+ return typeof t == "string" ? t : "";
4805
+ }
4806
+ return "";
4807
+ }
4808
+ function la(e) {
4809
+ let t = [];
4810
+ for (let [n, r] of e.fields) {
4811
+ if (r.primary || r.auto || r.ref || r.array || r.structure || r.display?.is_listable === !1) continue;
4812
+ let e = (r.type || "").toLowerCase(), i = !!(r.enum || r.values);
4813
+ if (!(!Mi.has(e) && !i) && (t.push(n), t.length >= 8)) break;
4814
+ }
4815
+ return t;
4816
+ }
4817
+ function ua(e, t, n, r) {
4818
+ if (!t || t.startsWith("$")) return;
4819
+ let i = pa(e, t);
4820
+ i.kind !== "missing" && (n.add(t), i.kind === "file" && r.addField(t, "file_metadata"));
4821
+ }
4822
+ function da(e, t, n, r) {
4823
+ if (t.startsWith("$status.")) {
4824
+ n.addExpand("statuses", "status_expand"), r !== "status_expand" && n.addExpand("statuses", r), r !== "status_expand" && n.addField(t, r);
4825
+ return;
4826
+ }
4827
+ if (t.startsWith("$property.")) {
4828
+ n.addExpand("properties", "property_expand"), r !== "property_expand" && n.addExpand("properties", r), r !== "property_expand" && n.addField(t, r);
4829
+ let i = t.slice(10);
4830
+ e?.properties?.[i]?.ref && (n.addExpand("refs", "ref_expand"), r !== "ref_expand" && n.addExpand("refs", r));
4831
+ return;
4832
+ }
4833
+ if (t === "$evidence") {
4834
+ n.addExpand("evidence", "evidence_expand"), r !== "evidence_expand" && n.addExpand("evidence", r), r !== "evidence_expand" && n.addField(t, r);
4835
+ return;
4836
+ }
4837
+ let i = pa(e, t);
4838
+ i.kind === "field" && i.field.type === "ref" && (n.addExpand("refs", "ref_expand"), r !== "ref_expand" && n.addExpand("refs", r));
4839
+ }
4840
+ function fa(e) {
4841
+ let t = e.snapshot().expand, n = [];
4842
+ return t.refs && n.push("refs"), t.statuses && n.push("statuses"), t.properties && n.push("properties"), t.evidence && n.push("evidence"), n;
4843
+ }
4844
+ function pa(e, t) {
4845
+ if (!e) return { kind: t.startsWith("$") ? "synthetic" : "missing" };
4846
+ if (t.startsWith("$status.")) return e.status_groups?.[t.slice(8)] ? { kind: "synthetic" } : { kind: "missing" };
4847
+ if (t.startsWith("$property.")) return e.properties?.[t.slice(10)] ? { kind: "synthetic" } : { kind: "missing" };
4848
+ if (t === "$evidence") return e.evidence_covered ? { kind: "synthetic" } : { kind: "missing" };
4849
+ let n = e.fields.get(t);
4850
+ if (n) return {
4851
+ kind: "field",
4852
+ field: n
4853
+ };
4854
+ let r = e.files?.get(t);
4855
+ return r ? {
4856
+ kind: "file",
4857
+ file: r
4858
+ } : { kind: "missing" };
4859
+ }
4860
+ var $ = class {
4861
+ #e = [];
4862
+ #t = /* @__PURE__ */ new Set();
4863
+ add(e) {
4864
+ this.#t.has(e) || (this.#t.add(e), this.#e.push(e));
4865
+ }
4866
+ has(e) {
4867
+ return this.#t.has(e);
4868
+ }
4869
+ values() {
4870
+ return [...this.#e];
4871
+ }
4872
+ }, ma = class {
4873
+ #e = /* @__PURE__ */ new Map();
4874
+ #t = /* @__PURE__ */ new Map();
4875
+ addField(e, t) {
4876
+ this.add(this.#e, e, t);
4877
+ }
4878
+ addExpand(e, t) {
4879
+ this.add(this.#t, e, t);
4880
+ }
4881
+ snapshot() {
4882
+ return {
4883
+ fields: Object.fromEntries(this.#e.entries()),
4884
+ expand: Object.fromEntries(this.#t.entries())
4885
+ };
4886
+ }
4887
+ add(e, t, n) {
4888
+ let r = e.get(t);
4889
+ if (!r) {
4890
+ e.set(t, [n]);
4891
+ return;
4892
+ }
4893
+ r.includes(n) || r.push(n);
4894
+ }
4895
+ }, ha = class extends Ne {
4896
+ constructor(e) {
4897
+ super(e), this.state = {
4898
+ hasError: !1,
4899
+ error: null
4900
+ };
4901
+ }
4902
+ static getDerivedStateFromError(e) {
4903
+ return {
4904
+ hasError: !0,
4905
+ error: e
4906
+ };
4907
+ }
4908
+ componentDidCatch(e, t) {
4909
+ console.error("[ErrorBoundary]", e, t.componentStack);
4910
+ }
4911
+ handleRetry = () => {
4912
+ this.setState({
4913
+ hasError: !1,
4914
+ error: null
4915
+ });
4916
+ };
4917
+ render() {
4918
+ return this.state.hasError ? this.props.fallback ? this.props.fallback : /* @__PURE__ */ X("div", {
4919
+ style: {
4920
+ display: "flex",
4921
+ alignItems: "center",
4922
+ justifyContent: "center",
4923
+ minHeight: 200,
4924
+ padding: 32
4925
+ },
4926
+ children: /* @__PURE__ */ Z("div", {
4927
+ style: {
4928
+ textAlign: "center",
4929
+ maxWidth: 420,
4930
+ display: "flex",
4931
+ flexDirection: "column",
4932
+ gap: 10
4933
+ },
4934
+ children: [
4935
+ /* @__PURE__ */ X("h2", {
4936
+ style: {
4937
+ fontSize: 16,
4938
+ fontWeight: 600,
4939
+ margin: 0,
4940
+ color: "var(--text)"
4941
+ },
4942
+ children: "Something went wrong"
4943
+ }),
4944
+ /* @__PURE__ */ X("p", {
4945
+ style: {
4946
+ fontSize: 12.5,
4947
+ color: "var(--text-3)",
4948
+ margin: 0
4949
+ },
4950
+ children: this.state.error?.message || "An unexpected error occurred."
4951
+ }),
4952
+ /* @__PURE__ */ X("div", { children: /* @__PURE__ */ X(U, {
4953
+ onClick: this.handleRetry,
4954
+ children: "Try again"
4955
+ }) })
4956
+ ]
4957
+ })
4958
+ }) : this.props.children;
4959
+ }
4960
+ };
4961
+ //#endregion
4962
+ //#region src/hooks/useObject.ts
4963
+ function ga(e, t) {
4964
+ return [
4965
+ "entity-item",
4966
+ e,
4967
+ t === void 0 || t === "new" ? void 0 : typeof t == "string" ? t : Object.keys(t).sort().map((e) => [e, t[e]])
4968
+ ];
4969
+ }
4970
+ function _a(e, t) {
4971
+ let n = ga(e, t), r = n[2];
4972
+ return He({
4973
+ queryKey: n,
4974
+ queryFn: () => o(e, t),
4975
+ enabled: !!e && !!t && t !== "new" && r !== void 0
4976
+ });
4977
+ }
4978
+ //#endregion
4979
+ //#region src/components/detail-layout/widgets/registry.ts
4980
+ var va = /* @__PURE__ */ new Map();
4981
+ function ya(e, t) {
4982
+ va.set(e, t);
4983
+ }
4984
+ function ba(e) {
4985
+ return va.get(e);
4986
+ }
4987
+ function xa(e) {
4988
+ return va.has(e);
4989
+ }
4990
+ //#endregion
4991
+ export { Jt as $, Hr as A, Zn as B, di as C, ri as D, ti as E, ir as F, Cn as G, Yn as H, rr as I, Dn as J, Tn as K, tr as L, jr as M, Cr as N, ii as O, or as P, an as Q, nr as R, fi as S, si as T, In as U, er as V, Ln as W, sn as X, En as Y, on as Z, gi as _, _a as a, jt as at, ui as b, Pi as c, Et as ct, Ci as d, ct as dt, qt as et, yi as f, ft, vi as g, Si as h, ga as i, Bt as it, Fr as j, ni as k, Fi as l, bt as lt, _i as m, Je as mt, xa as n, Wt as nt, ha as o, Mt as ot, bi as p, Ye as pt, On as q, ya as r, Ht as rt, Ni as s, At as st, ba as t, Ut as tt, xi as u, kt as ut, mi as v, ci as w, hi as x, pi as y, zn as z };