@declarion/react 0.57.0 → 0.59.2

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 (166) hide show
  1. package/README.md +0 -2
  2. package/dist-lib/AgentChatPanel.impl-DBH1Ff4G.js +1200 -0
  3. package/dist-lib/DetailAuditStrip-9eJM2Fml.js +288 -0
  4. package/dist-lib/{DraggableChildrenTable-BV5sb8Uo.js → DraggableChildrenTable-4RZC351U.js} +87 -86
  5. package/dist-lib/Grid-CQabaBLx.js +405 -0
  6. package/dist-lib/{LayoutRenderer-C9AH9cXf.js → LayoutRenderer-DGKWZKpW.js} +1000 -1114
  7. package/dist-lib/{ListCardsBody-DXcDg536.js → ListCardsBody-DfGmyNIu.js} +84 -84
  8. package/dist-lib/MarkdownRenderer-BDbzDv_y.js +87 -0
  9. package/dist-lib/{RefreshControl-CNtN8zSl.js → RefreshControl-Bhoib0ZA.js} +126 -155
  10. package/dist-lib/SmartDetailPage.impl-DFjz29Ff.js +1565 -0
  11. package/dist-lib/SmartListPage.impl-BrZLE_Gb.js +3046 -0
  12. package/dist-lib/{SmartRecordListPage.impl-Bkl9aZJ8.js → SmartRecordListPage.impl-C1FJLr80.js} +281 -280
  13. package/dist-lib/SortHeaderMenu-Cijxk4cX.js +107 -0
  14. package/dist-lib/action-dispatch-DY0c8U81.js +1967 -0
  15. package/dist-lib/api/client.d.ts +5 -0
  16. package/dist-lib/api/data.d.ts +2 -4
  17. package/dist-lib/api/entities.d.ts +8 -15
  18. package/dist-lib/api/events.d.ts +3 -3
  19. package/dist-lib/cardProjection-Bkl2SSYz.js +499 -0
  20. package/dist-lib/components/actions/ResponsiveActionBar.d.ts +17 -16
  21. package/dist-lib/components/agents/AgentChatPanel.d.ts +3 -13
  22. package/dist-lib/components/agents/AgentChatPanel.impl.d.ts +14 -0
  23. package/dist-lib/components/agents/AgentPicker.d.ts +1 -2
  24. package/dist-lib/components/chrome/PageShell.d.ts +7 -0
  25. package/dist-lib/components/chrome/RecordHeader.d.ts +1 -2
  26. package/dist-lib/components/chrome/headerActionZone.d.ts +27 -0
  27. package/dist-lib/components/detail-layout/DetailAuditStrip.d.ts +1 -2
  28. package/dist-lib/components/detail-layout/DetailHighlights.d.ts +1 -2
  29. package/dist-lib/components/detail-layout/blockMeta.d.ts +2 -1
  30. package/dist-lib/components/fields/BoolField.d.ts +1 -1
  31. package/dist-lib/components/fields/EnumField.d.ts +1 -1
  32. package/dist-lib/components/fields/IntArrayField.d.ts +1 -1
  33. package/dist-lib/components/fields/MultilangArrayField.d.ts +2 -0
  34. package/dist-lib/components/fields/MultilangField.d.ts +1 -1
  35. package/dist-lib/components/fields/MultilangTextField.d.ts +1 -1
  36. package/dist-lib/components/fields/NumberField.d.ts +1 -1
  37. package/dist-lib/components/fields/PasswordField.d.ts +1 -1
  38. package/dist-lib/components/fields/RefCombobox.d.ts +1 -1
  39. package/dist-lib/components/fields/SecretField.d.ts +1 -1
  40. package/dist-lib/components/fields/StringArrayField.d.ts +1 -1
  41. package/dist-lib/components/fields/TimestampField.d.ts +1 -1
  42. package/dist-lib/components/fields/cells/registry.d.ts +2 -1
  43. package/dist-lib/components/fields/index.d.ts +2 -1
  44. package/dist-lib/components/fields/langMap.d.ts +2 -0
  45. package/dist-lib/components/fields/secretValue.d.ts +2 -0
  46. package/dist-lib/components/file-widgets/UnknownFileWidget.d.ts +3 -0
  47. package/dist-lib/components/file-widgets/UploadFailureText.d.ts +4 -0
  48. package/dist-lib/components/file-widgets/helpers.d.ts +1 -1
  49. package/dist-lib/components/file-widgets/host.d.ts +4 -3
  50. package/dist-lib/components/file-widgets/types.d.ts +1 -0
  51. package/dist-lib/components/file-widgets/upload.d.ts +18 -3
  52. package/dist-lib/components/filters/filter-op-label.d.ts +3 -0
  53. package/dist-lib/components/layout/ImpersonationBanner.d.ts +1 -1
  54. package/dist-lib/components/layout/ImpersonationFrame.d.ts +1 -1
  55. package/dist-lib/components/layout/Layout.d.ts +2 -1
  56. package/dist-lib/components/layout/Sidebar.d.ts +2 -1
  57. package/dist-lib/components/layout/TenantChip.d.ts +1 -1
  58. package/dist-lib/components/list/ViewSwitcher.d.ts +4 -2
  59. package/dist-lib/components/pages/DocumentsMenu.d.ts +1 -2
  60. package/dist-lib/components/pages/ExportMenu.d.ts +3 -5
  61. package/dist-lib/components/pages/RecordDocumentsPanel.d.ts +1 -2
  62. package/dist-lib/components/pages/auth/AuthShell.d.ts +4 -31
  63. package/dist-lib/components/pages/exportRequest.d.ts +4 -6
  64. package/dist-lib/components/pages/list/DeleteViewDialog.d.ts +8 -0
  65. package/dist-lib/components/pages/list/ListCardRow.d.ts +1 -2
  66. package/dist-lib/components/pages/list/ListCardsBody.d.ts +0 -1
  67. package/dist-lib/components/pages/list/ListFloatbar.d.ts +2 -2
  68. package/dist-lib/components/pages/list/ListHeader.d.ts +2 -2
  69. package/dist-lib/components/pages/list/ListNoRows.d.ts +4 -5
  70. package/dist-lib/components/pages/list/ListToolbar.d.ts +3 -2
  71. package/dist-lib/components/pages/list/ListUrlBanner.d.ts +10 -0
  72. package/dist-lib/components/pages/list/RowActionsCell.d.ts +2 -4
  73. package/dist-lib/components/pages/list/RowContextMenu.d.ts +1 -2
  74. package/dist-lib/components/pages/list/columns.d.ts +2 -1
  75. package/dist-lib/components/pages/list/filter-meta.d.ts +2 -1
  76. package/dist-lib/components/pages/list/useActiveView.d.ts +38 -0
  77. package/dist-lib/components/pages/list/useListColumnLayout.d.ts +6 -5
  78. package/dist-lib/components/pages/list/useListQuery.d.ts +4 -4
  79. package/dist-lib/components/pages/list/useListSort.d.ts +5 -4
  80. package/dist-lib/components/pages/list/useListViews.d.ts +18 -8
  81. package/dist-lib/components/pages/list/useRowMenu.d.ts +2 -3
  82. package/dist-lib/components/pages/profile/Profile.d.ts +3 -0
  83. package/dist-lib/components/params/ParamsBlock.d.ts +1 -13
  84. package/dist-lib/components/params/param-editors.d.ts +3 -11
  85. package/dist-lib/components/primitives/ClassifiedFieldLocked.d.ts +1 -2
  86. package/dist-lib/components/shared/DynamicIcon.d.ts +2 -2
  87. package/dist-lib/components/shared/LoadingSkeleton.d.ts +1 -0
  88. package/dist-lib/components/shared/LucideIcon.d.ts +1 -1
  89. package/dist-lib/components/shared/useOwnRefresh.d.ts +1 -1
  90. package/dist-lib/declarion-react.css +1 -1
  91. package/dist-lib/embed/theme.d.ts +1 -1
  92. package/dist-lib/embed/useEmbedNavigate.d.ts +1 -1
  93. package/dist-lib/failure-v-uGSpbX.js +158 -0
  94. package/dist-lib/{field-classification-D6xQYn-h.js → field-classification-C28XE-_P.js} +514 -307
  95. package/dist-lib/format-count-DA4wmmWR.js +1771 -0
  96. package/dist-lib/hooks/useEntityData.d.ts +1 -1
  97. package/dist-lib/hooks/useFilters.d.ts +7 -5
  98. package/dist-lib/hooks/useLanguage.d.ts +4 -0
  99. package/dist-lib/hooks/useParams.d.ts +4 -51
  100. package/dist-lib/hooks/useRegisterScreenTab.d.ts +1 -1
  101. package/dist-lib/hooks/useSSE.d.ts +3 -3
  102. package/dist-lib/hooks/useTabTitle.d.ts +2 -0
  103. package/dist-lib/hooks/useText.d.ts +3 -3
  104. package/dist-lib/hooks/useVersionWatcher.d.ts +1 -1
  105. package/dist-lib/hooks/useViews.d.ts +20 -0
  106. package/dist-lib/index.d.ts +8 -7
  107. package/dist-lib/index.js +2716 -5803
  108. package/dist-lib/lib/action-dispatch.d.ts +2 -1
  109. package/dist-lib/lib/actions.d.ts +30 -42
  110. package/dist-lib/lib/anchor.d.ts +3 -4
  111. package/dist-lib/lib/decimal-text.d.ts +1 -0
  112. package/dist-lib/lib/document-templates.d.ts +1 -2
  113. package/dist-lib/lib/download.d.ts +2 -1
  114. package/dist-lib/lib/evidence-verdict.d.ts +2 -1
  115. package/dist-lib/lib/failure.d.ts +2 -0
  116. package/dist-lib/lib/field-classification.d.ts +3 -3
  117. package/dist-lib/lib/filters.d.ts +18 -2
  118. package/dist-lib/lib/format-count.d.ts +8 -7
  119. package/dist-lib/lib/language.d.ts +19 -0
  120. package/dist-lib/lib/mass-edit.d.ts +2 -1
  121. package/dist-lib/lib/realtime-query-keys.d.ts +1 -1
  122. package/dist-lib/lib/realtime-reconcile.d.ts +3 -4
  123. package/dist-lib/lib/screen-back.d.ts +4 -6
  124. package/dist-lib/lib/sort.d.ts +9 -9
  125. package/dist-lib/lib/timestamp.d.ts +5 -7
  126. package/dist-lib/lib/ui-actions.d.ts +2 -1
  127. package/dist-lib/peekDraftStore-D-cTbiIr.js +199 -0
  128. package/dist-lib/registry-Cb3W-czW.js +1950 -0
  129. package/dist-lib/safe-url-oSJw5pzO.js +34 -0
  130. package/dist-lib/stores/icon-registry.d.ts +2 -2
  131. package/dist-lib/stores/list-layout.d.ts +3 -4
  132. package/dist-lib/stores/realtime.d.ts +1 -1
  133. package/dist-lib/stores/tabs.d.ts +3 -2
  134. package/dist-lib/testing.d.ts +6 -0
  135. package/dist-lib/testing.js +98 -76
  136. package/dist-lib/types/api.d.ts +7 -8
  137. package/dist-lib/types/fieldType.d.ts +1 -1
  138. package/dist-lib/types/files.d.ts +4 -4
  139. package/dist-lib/types/schema.d.ts +44 -50
  140. package/dist-lib/useAgentConversation-D97IqE-J.js +623 -0
  141. package/dist-lib/{useCurrentScreen-CzwzQpoW.js → useCurrentScreen-BL5NZFCw.js} +2777 -3768
  142. package/dist-lib/useListQuery-BG1GyKtJ.js +103 -0
  143. package/dist-lib/useProperties-4Lg3odrt.js +83 -0
  144. package/dist-lib/{useTabSearchMirror-C39U85cg.js → useTabSearchMirror-ZVLlINBX.js} +49 -51
  145. package/dist-lib/useText-BFDCTUSo.js +952 -0
  146. package/dist-lib/{value-Bo8C8WMU.js → value-By1-WJ8J.js} +74 -76
  147. package/dist-lib/vite/fingerprint-plugin.d.ts +2 -3
  148. package/package.json +9 -9
  149. package/dist-lib/Grid-DWgUPuZ3.js +0 -404
  150. package/dist-lib/MarkdownRenderer-CcSFc2N3.js +0 -85
  151. package/dist-lib/RecordIdBadge-CGxPR-8q.js +0 -24
  152. package/dist-lib/SmartDetailPage.impl-lskCd-WG.js +0 -1846
  153. package/dist-lib/SmartListPage.impl-CrGbdzyK.js +0 -2854
  154. package/dist-lib/SortHeaderMenu-SYSAaqQJ.js +0 -106
  155. package/dist-lib/action-dispatch-CR4ajBtT.js +0 -1985
  156. package/dist-lib/cardProjection-CW5RIMko.js +0 -699
  157. package/dist-lib/components/pages/home/HomeStub.d.ts +0 -6
  158. package/dist-lib/components/pages/jobs/Jobs.d.ts +0 -1
  159. package/dist-lib/components/pages/pipeline/Pipeline.d.ts +0 -1
  160. package/dist-lib/format-count-Dobmi-Ji.js +0 -1551
  161. package/dist-lib/hooks/useUserLocale.d.ts +0 -1
  162. package/dist-lib/lib/messages.d.ts +0 -12
  163. package/dist-lib/peekDraftStore-5wQ7lq_V.js +0 -194
  164. package/dist-lib/registry-CjgUaF7C.js +0 -1768
  165. package/dist-lib/useListQuery-D7Hr5WM1.js +0 -96
  166. package/dist-lib/useProperties-CqtCzFCr.js +0 -81
@@ -0,0 +1,952 @@
1
+ import { Fragment as e, createContext as t, createElement as n, useContext as r, useEffect as i, useMemo as a } from "react";
2
+ import { useQuery as o } from "@tanstack/react-query";
3
+ import { jsx as s } from "react/jsx-runtime";
4
+ import { create as c } from "zustand";
5
+ //#region src/types/api.ts
6
+ var l = class extends Error {
7
+ status;
8
+ code;
9
+ type;
10
+ retryable;
11
+ detail;
12
+ index;
13
+ raw;
14
+ constructor(e, t, n) {
15
+ super(t.title ?? ""), this.name = "ApiError", this.status = t.status ?? e, this.type = t.type ?? "", this.code = u(t.type), this.retryable = t.retryable ?? !1, this.detail = t.detail;
16
+ let r = t.index;
17
+ typeof r == "number" && (this.index = r), this.raw = n;
18
+ }
19
+ ext(e) {
20
+ return this.raw?.[e];
21
+ }
22
+ };
23
+ function u(e) {
24
+ if (!e || e === "about:blank") return "";
25
+ let t = e.lastIndexOf("/");
26
+ return t >= 0 ? e.slice(t + 1) : e;
27
+ }
28
+ function d(e) {
29
+ return typeof e == "object" && !!e && typeof e.type == "string";
30
+ }
31
+ var f = "cursor.semantics_mismatch", ee = "cursor.language_changed";
32
+ function te(e) {
33
+ return e instanceof l && (e.code === "cursor.semantics_mismatch" || e.code === "cursor.language_changed" || e.code === "cursor.archive_invalid");
34
+ }
35
+ async function p(e) {
36
+ let t;
37
+ try {
38
+ t = await e.json();
39
+ } catch {}
40
+ return {
41
+ raw: t,
42
+ body: d(t) ? t : {}
43
+ };
44
+ }
45
+ //#endregion
46
+ //#region src/api/auth-redirect.ts
47
+ var m = "/", h = "/login", ne = "/signup", re = "https://declarion.local";
48
+ function ie(e) {
49
+ let t = e.split(/[?#]/, 1)[0];
50
+ return t === h || t.startsWith(`${h}/`) || t === ne || t.startsWith(`${ne}/`);
51
+ }
52
+ function ae(e) {
53
+ if (!e) return m;
54
+ let t = e.toLowerCase();
55
+ if (!e.startsWith("/") || e.startsWith("//") || e.includes("\\") || t.includes("%5c")) return m;
56
+ try {
57
+ let t = new URL(e, re);
58
+ if (t.origin !== re) return m;
59
+ let n = `${t.pathname}${t.search}${t.hash}`;
60
+ return !n.startsWith("/") || n.startsWith("//") || n.includes("\\") ? m : n || m;
61
+ } catch {
62
+ return m;
63
+ }
64
+ }
65
+ function oe(e) {
66
+ let t = ae(e);
67
+ return t === m || ie(t) ? h : `${h}?next=${encodeURIComponent(t)}`;
68
+ }
69
+ function se() {
70
+ if (typeof window > "u") return h;
71
+ let { pathname: e, search: t, hash: n } = window.location;
72
+ return oe(`${e}${t}${n}`);
73
+ }
74
+ //#endregion
75
+ //#region src/embed/protocol.ts
76
+ var ce = "declarion-embed", g = {
77
+ ready: "ready",
78
+ setToken: "set-token",
79
+ tokenExpired: "token-expired",
80
+ reloadRequired: "reload-required",
81
+ resized: "resized",
82
+ navigated: "navigated",
83
+ navigationRequested: "navigation-requested",
84
+ dirtyChanged: "dirty-changed",
85
+ navigationFailed: "navigation-failed",
86
+ navigate: "navigate",
87
+ setTheme: "set-theme"
88
+ };
89
+ function _(e, t, n) {
90
+ if (!e || typeof window > "u" || window.parent === window) return !1;
91
+ let r = {
92
+ source: ce,
93
+ protocol: 1,
94
+ type: t,
95
+ payload: n
96
+ };
97
+ return window.parent.postMessage(r, e), !0;
98
+ }
99
+ //#endregion
100
+ //#region src/embed/token.ts
101
+ var v = 15e3, le = 5e3, y = {
102
+ active: !1,
103
+ parentOrigin: null,
104
+ current: null,
105
+ pending: null
106
+ };
107
+ function ue(e) {
108
+ y.active = !0, y.parentOrigin = e;
109
+ }
110
+ function b() {
111
+ return y.active;
112
+ }
113
+ function de() {
114
+ return y.current?.token ?? null;
115
+ }
116
+ function fe() {
117
+ return y.parentOrigin;
118
+ }
119
+ function pe() {
120
+ return !y.current || Date.now() >= y.current.expiresAt - le;
121
+ }
122
+ function me(e) {
123
+ if (!e.token || typeof e.token != "string") return;
124
+ let t = Date.parse(e.expires_at);
125
+ if (!Number.isNaN(t) && (y.current = {
126
+ token: e.token,
127
+ expiresAt: t
128
+ }, y.pending)) {
129
+ let t = y.pending;
130
+ y.pending = null, clearTimeout(t.timer), t.resolve(e.token);
131
+ }
132
+ }
133
+ function he() {
134
+ y.current = null;
135
+ }
136
+ function x() {
137
+ if (!pe() && y.current) return Promise.resolve(y.current.token);
138
+ if (y.pending) return y.pending.promise;
139
+ let e, t, n = new Promise((n, r) => {
140
+ e = n, t = r;
141
+ }), r = setTimeout(() => {
142
+ y.pending && y.pending.promise === n && (y.pending = null), t(/* @__PURE__ */ Error(`embed token wait timed out after ${v}ms`));
143
+ }, v);
144
+ return y.pending = {
145
+ promise: n,
146
+ resolve: e,
147
+ reject: t,
148
+ timer: r
149
+ }, _(y.parentOrigin, g.tokenExpired, {}), n;
150
+ }
151
+ //#endregion
152
+ //#region src/lib/versionTracker.ts
153
+ var ge = "X-Declarion-Version", _e = "declarion-version";
154
+ function ve() {
155
+ if (typeof BroadcastChannel > "u") return null;
156
+ try {
157
+ return new BroadcastChannel(_e);
158
+ } catch {
159
+ return null;
160
+ }
161
+ }
162
+ var S = {
163
+ firstSeen: null,
164
+ firstComponents: null,
165
+ hasReportedDrift: !1,
166
+ pendingReload: null,
167
+ listeners: /* @__PURE__ */ new Set(),
168
+ channel: null
169
+ };
170
+ function C() {
171
+ S.channel || typeof BroadcastChannel > "u" || (S.channel = ve(), S.channel && S.channel.addEventListener("message", (e) => {
172
+ let t = e.data;
173
+ if (t && t.type === "drift" && t.delta && !S.hasReportedDrift) {
174
+ S.hasReportedDrift = !0;
175
+ for (let e of S.listeners) e(t.delta);
176
+ }
177
+ }));
178
+ }
179
+ function ye(e) {
180
+ if (C(), !e) return;
181
+ let t = e.get(ge);
182
+ if (t) {
183
+ if (!S.firstSeen) {
184
+ S.firstSeen = t;
185
+ return;
186
+ }
187
+ t !== S.firstSeen && (S.hasReportedDrift || be().catch(() => {
188
+ Se({
189
+ kind: "unknown",
190
+ observed: t
191
+ });
192
+ }));
193
+ }
194
+ }
195
+ async function be() {
196
+ C();
197
+ let e;
198
+ try {
199
+ let t = {};
200
+ S.firstSeen && (t["If-None-Match"] = `"${S.firstSeen}"`), e = await fetch("/api/version", {
201
+ method: "GET",
202
+ credentials: b() ? "omit" : "include",
203
+ headers: t
204
+ });
205
+ } catch {
206
+ throw Error("version probe network error");
207
+ }
208
+ if (e.status === 304) return;
209
+ if (!e.ok) throw await p(e), Error(`version probe ${e.status}`);
210
+ let t;
211
+ try {
212
+ t = await e.json();
213
+ } catch {
214
+ throw Error("version probe malformed body");
215
+ }
216
+ let n = t.fingerprint;
217
+ if (typeof n != "string" || n === "") throw Error("version probe missing fingerprint");
218
+ let r = typeof t.schema_fingerprint == "string" && typeof t.asset_fingerprint == "string" && typeof t.binary_fingerprint == "string" ? {
219
+ schema: t.schema_fingerprint,
220
+ asset: t.asset_fingerprint,
221
+ binary: t.binary_fingerprint
222
+ } : void 0;
223
+ S.firstSeen ||= n, !S.firstComponents && r && n === S.firstSeen && (S.firstComponents = r), n !== S.firstSeen && Se({
224
+ kind: xe(S.firstComponents, r),
225
+ observed: n,
226
+ components: r
227
+ });
228
+ }
229
+ function xe(e, t) {
230
+ if (!e || !t) return "unknown";
231
+ let n = e.schema !== t.schema, r = e.asset !== t.asset, i = e.binary !== t.binary;
232
+ return n && !r && !i ? "schema-only" : r || i ? "asset-or-binary" : "unknown";
233
+ }
234
+ function Se(e) {
235
+ if (!S.hasReportedDrift) {
236
+ S.hasReportedDrift = !0, e.kind !== "schema-only" && (S.pendingReload = e);
237
+ for (let t of S.listeners) t(e);
238
+ if (S.channel) try {
239
+ S.channel.postMessage({
240
+ type: "drift",
241
+ delta: e
242
+ });
243
+ } catch {}
244
+ b() && e.kind !== "schema-only" && _(fe(), g.reloadRequired, { reason: `version drift: ${e.kind}` });
245
+ }
246
+ }
247
+ function Ce() {
248
+ return S.pendingReload;
249
+ }
250
+ function we(e) {
251
+ return S.listeners.add(e), () => {
252
+ S.listeners.delete(e);
253
+ };
254
+ }
255
+ //#endregion
256
+ //#region src/api/client.ts
257
+ var Te = (e) => JSON.stringify(e ?? {}), w = null, T = "declarion.auth.refresh.lock", E = "declarion.auth.refresh.result", Ee = "declarion.auth.refresh", De = 3e4, Oe = 100, D = typeof crypto < "u" && "randomUUID" in crypto ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2)}`;
258
+ function O() {
259
+ if (typeof window > "u") return !1;
260
+ try {
261
+ let e = window.localStorage, t = `${T}.probe`;
262
+ return e.setItem(t, "1"), e.removeItem(t), !0;
263
+ } catch {
264
+ return !1;
265
+ }
266
+ }
267
+ function ke() {
268
+ return typeof navigator > "u" ? null : navigator.locks ?? null;
269
+ }
270
+ function k(e) {
271
+ if (!e) return null;
272
+ try {
273
+ let t = JSON.parse(e);
274
+ return typeof t.owner != "string" || typeof t.expires_at != "number" ? null : {
275
+ owner: t.owner,
276
+ expires_at: t.expires_at
277
+ };
278
+ } catch {
279
+ return null;
280
+ }
281
+ }
282
+ function Ae(e) {
283
+ if (!e) return null;
284
+ try {
285
+ let t = JSON.parse(e);
286
+ return typeof t.owner != "string" || typeof t.ok != "boolean" || typeof t.updated_at != "number" ? null : {
287
+ owner: t.owner,
288
+ ok: t.ok,
289
+ status: typeof t.status == "number" ? t.status : void 0,
290
+ updated_at: t.updated_at
291
+ };
292
+ } catch {
293
+ return null;
294
+ }
295
+ }
296
+ function je(e) {
297
+ if (!O()) return null;
298
+ let t = Ae(window.localStorage.getItem(E));
299
+ return !t || t.updated_at < e ? null : t;
300
+ }
301
+ function Me(e) {
302
+ if (!e.ok) throw new j(e.status ?? 401);
303
+ }
304
+ function Ne(e = Date.now()) {
305
+ let t = k(window.localStorage.getItem(T));
306
+ if (t && t.expires_at > e && t.owner !== D) return !1;
307
+ let n = {
308
+ owner: D,
309
+ expires_at: e + De
310
+ };
311
+ return window.localStorage.setItem(T, JSON.stringify(n)), k(window.localStorage.getItem(T))?.owner === D;
312
+ }
313
+ function Pe() {
314
+ k(window.localStorage.getItem(T))?.owner === D && window.localStorage.removeItem(T);
315
+ }
316
+ function A(e) {
317
+ let t = {
318
+ owner: D,
319
+ updated_at: Date.now(),
320
+ ...e
321
+ };
322
+ window.localStorage.setItem(E, JSON.stringify(t));
323
+ }
324
+ async function Fe(e) {
325
+ return new Promise((t, n) => {
326
+ let r = !1, i = null, a = (e) => {
327
+ r || (r = !0, i && clearTimeout(i), window.removeEventListener("storage", c), t(e));
328
+ }, o = (e) => {
329
+ r || (r = !0, i && clearTimeout(i), window.removeEventListener("storage", c), n(new j(e)));
330
+ }, s = () => {
331
+ let t = Ae(window.localStorage.getItem(E));
332
+ if (t && t.updated_at >= e) {
333
+ t.ok ? a("complete") : o(t.status ?? 401);
334
+ return;
335
+ }
336
+ let n = k(window.localStorage.getItem(T));
337
+ if (!n) {
338
+ a("complete");
339
+ return;
340
+ }
341
+ if (n.expires_at <= Date.now()) {
342
+ a("expired");
343
+ return;
344
+ }
345
+ i = setTimeout(s, Oe);
346
+ }, c = (e) => {
347
+ (e.key === T || e.key === E) && (i && clearTimeout(i), s());
348
+ };
349
+ window.addEventListener("storage", c), s();
350
+ });
351
+ }
352
+ async function Ie(e) {
353
+ let t = ke();
354
+ return t ? (await t.request(Ee, { mode: "exclusive" }, async () => {
355
+ let t = je(e);
356
+ if (t) {
357
+ Me(t);
358
+ return;
359
+ }
360
+ try {
361
+ await L(), O() && A({ ok: !0 });
362
+ } catch (e) {
363
+ throw e instanceof j && O() && A({
364
+ ok: !1,
365
+ status: e.status
366
+ }), e;
367
+ }
368
+ }), !0) : !1;
369
+ }
370
+ async function Le() {
371
+ let e = Date.now();
372
+ if (!await Ie(e)) {
373
+ if (!O()) {
374
+ await L();
375
+ return;
376
+ }
377
+ if (Ne(e)) try {
378
+ await L(), A({ ok: !0 });
379
+ return;
380
+ } catch (e) {
381
+ throw e instanceof j && A({
382
+ ok: !1,
383
+ status: e.status
384
+ }), e;
385
+ } finally {
386
+ Pe();
387
+ }
388
+ await Fe(e) === "expired" && await Le();
389
+ }
390
+ }
391
+ var j = class extends Error {
392
+ status;
393
+ constructor(e) {
394
+ super(`refresh failed terminally (${e})`), this.status = e, this.name = "RefreshDeadError";
395
+ }
396
+ }, M = null, N = null, P = 3e4, Re = 5e3;
397
+ function F() {
398
+ z().catch((e) => {
399
+ e instanceof j && B();
400
+ });
401
+ }
402
+ function I(e) {
403
+ if (R = null, M &&= (clearTimeout(M), null), N = null, !e || typeof window > "u") return;
404
+ let t = Date.parse(e);
405
+ if (Number.isNaN(t)) return;
406
+ N = t;
407
+ let n = Math.max(t - Date.now() - P, Re);
408
+ M = setTimeout(() => {
409
+ M = null, F();
410
+ }, n);
411
+ }
412
+ function ze() {
413
+ M &&= (clearTimeout(M), null), N = null;
414
+ }
415
+ typeof document < "u" && document.addEventListener("visibilitychange", () => {
416
+ document.visibilityState === "visible" && N !== null && Date.now() >= N - P && F();
417
+ });
418
+ async function Be(e) {
419
+ try {
420
+ let t = await e.json();
421
+ I(t?.result?.expires_at ?? t?.expires_at);
422
+ } catch {}
423
+ }
424
+ async function L() {
425
+ let e = {
426
+ method: "POST",
427
+ credentials: "include",
428
+ headers: { "Content-Type": "application/json" },
429
+ body: Te({})
430
+ }, t = await fetch("/api/actions/auth.refresh", e);
431
+ if (t.status === 429) {
432
+ let n = parseInt(t.headers.get("Retry-After") || "1", 10);
433
+ await new Promise((e) => setTimeout(e, n * 1e3));
434
+ let r = await fetch("/api/actions/auth.refresh", e);
435
+ if (!r.ok) throw await p(r), new j(r.status);
436
+ await Be(r);
437
+ return;
438
+ }
439
+ if (!t.ok) throw await p(t), new j(t.status);
440
+ await Be(t);
441
+ }
442
+ var R = null;
443
+ async function z() {
444
+ if (R !== null) throw new j(R);
445
+ return w || (w = Le().catch((e) => {
446
+ throw e instanceof j && (R = e.status), e;
447
+ }).finally(() => {
448
+ w = null;
449
+ }), w);
450
+ }
451
+ var B = () => {
452
+ if (typeof window > "u") return;
453
+ let { pathname: e } = window.location;
454
+ e.startsWith("/login") || e.startsWith("/signup") || e === "/reset" || e === "/forgot" || e === "/2fa" || (window.location.href = se());
455
+ };
456
+ function Ve(e) {
457
+ let t = B;
458
+ return B = e, t;
459
+ }
460
+ function He() {
461
+ return B;
462
+ }
463
+ var Ue = ({ status: e, code: t, message: n }) => {
464
+ console.error(`[API ${e}] ${t}: ${n}`);
465
+ };
466
+ function We(e, t, n, r) {
467
+ let i = new Headers(e);
468
+ return !i.has("Content-Type") && t && i.set("Content-Type", "application/json"), n.setAccept && !i.has("Accept") && i.set("Accept", "*/*"), r && i.set("Authorization", `Bearer ${r}`), i;
469
+ }
470
+ var V = null, H = 0;
471
+ function Ge(e) {
472
+ e || H++, V = e || null;
473
+ }
474
+ function Ke() {
475
+ return H;
476
+ }
477
+ function qe(e, t) {
478
+ e === H && (V = t || null);
479
+ }
480
+ function Je() {
481
+ return V;
482
+ }
483
+ function Ye(e) {
484
+ return !V || !e.startsWith("/api/") || /[?&]language=/.test(e) ? e : `${e}${e.includes("?") ? "&" : "?"}language=${encodeURIComponent(V)}`;
485
+ }
486
+ async function Xe(e, t, n, r) {
487
+ let i = Ye(e), a = b(), o = a ? "omit" : "include", s = We(t.headers, !!t.body, n, a ? de() : null), c = await fetch(i, {
488
+ ...t,
489
+ headers: s,
490
+ credentials: o
491
+ });
492
+ if (ye(c.headers), !c.ok) {
493
+ let { raw: e, body: s } = await p(c), d = u(s.type), f = s.title ?? "";
494
+ if (c.status === 401 && (d === "auth.token_refresh_needed" || d === "auth.unauthorized")) try {
495
+ let e = null;
496
+ a ? (he(), e = await x()) : await z();
497
+ let s = We(t.headers, !!t.body, n, e), c = await fetch(i, {
498
+ ...t,
499
+ headers: s,
500
+ credentials: o
501
+ });
502
+ if (!c.ok) {
503
+ B();
504
+ let e = await p(c);
505
+ throw new l(c.status, e.body, e.raw);
506
+ }
507
+ return r(c);
508
+ } catch (t) {
509
+ throw t instanceof l ? t : (B(), new l(401, s, e));
510
+ }
511
+ throw c.status === 401 && B(), Ue({
512
+ status: c.status,
513
+ code: d,
514
+ message: f
515
+ }), new l(c.status, s, e);
516
+ }
517
+ return r(c);
518
+ }
519
+ function Ze(e) {
520
+ return e.status === 204 ? Promise.resolve(void 0) : e.json();
521
+ }
522
+ async function U(e, t = {}) {
523
+ return Xe(e, t, { setAccept: !1 }, Ze);
524
+ }
525
+ async function Qe(e) {
526
+ return {
527
+ blob: await e.blob(),
528
+ filename: et(e.headers),
529
+ headers: e.headers
530
+ };
531
+ }
532
+ async function $e(e, t = {}) {
533
+ return Xe(e, t, { setAccept: !0 }, Qe);
534
+ }
535
+ function et(e) {
536
+ let t = e.get("Content-Disposition");
537
+ if (!t) return "";
538
+ let n = t.match(/filename\*\s*=\s*([^']*)'([^']*)'([^;]+)/i);
539
+ if (n) try {
540
+ return decodeURIComponent(n[3].trim());
541
+ } catch {}
542
+ let r = t.match(/filename\s*=\s*("([^"]+)"|([^;]+))/i);
543
+ return r ? (r[2] ?? r[3] ?? "").trim() : "";
544
+ }
545
+ async function W(e, t = {}) {
546
+ return (await U(`/api/actions/${encodeURIComponent(e)}`, {
547
+ method: "POST",
548
+ body: Te(t)
549
+ })).result;
550
+ }
551
+ //#endregion
552
+ //#region src/types/ordmap.ts
553
+ var G = class e {
554
+ #e;
555
+ #t;
556
+ constructor(e) {
557
+ this.#e = e;
558
+ let t = /* @__PURE__ */ new Map();
559
+ for (let n = 0; n < e.length; n++) {
560
+ let r = e[n].name;
561
+ r !== void 0 && t.set(r, n);
562
+ }
563
+ this.#t = t;
564
+ }
565
+ static fromObject(t) {
566
+ return e.#n(t);
567
+ }
568
+ static fromWire(t) {
569
+ return e.#n(t);
570
+ }
571
+ static #n(t) {
572
+ if (!t) return new e([]);
573
+ let n = [];
574
+ for (let [e, r] of Object.entries(t)) n.push({
575
+ ...r,
576
+ name: e
577
+ });
578
+ return new e(n);
579
+ }
580
+ get length() {
581
+ return this.#e.length;
582
+ }
583
+ has(e) {
584
+ return this.#t.has(e);
585
+ }
586
+ get(e) {
587
+ let t = this.#t.get(e);
588
+ return t === void 0 ? void 0 : this.#e[t];
589
+ }
590
+ items() {
591
+ return this.#e;
592
+ }
593
+ names() {
594
+ return this.#e.map((e) => e.name ?? "");
595
+ }
596
+ *[Symbol.iterator]() {
597
+ for (let e of this.#e) yield [e.name ?? "", e];
598
+ }
599
+ };
600
+ //#endregion
601
+ //#region src/api/schema.ts
602
+ function tt(e) {
603
+ return {
604
+ ...e,
605
+ params: e.params ? G.fromWire(e.params) : void 0
606
+ };
607
+ }
608
+ function nt(e) {
609
+ return {
610
+ ...e,
611
+ resolved_params: e.resolved_params ? G.fromWire(e.resolved_params) : void 0
612
+ };
613
+ }
614
+ function rt(e) {
615
+ let t = {};
616
+ if (e.handlers) for (let [n, r] of Object.entries(e.handlers)) t[n] = tt(r);
617
+ let n = {};
618
+ if (e.actions) for (let [t, r] of Object.entries(e.actions)) n[t] = nt(r);
619
+ return {
620
+ ...e,
621
+ fields: G.fromWire(e.fields),
622
+ files: e.files ? G.fromWire(e.files) : void 0,
623
+ variants: e.variants ? G.fromWire(e.variants) : void 0,
624
+ handlers: e.handlers ? t : void 0,
625
+ actions: e.actions ? n : void 0
626
+ };
627
+ }
628
+ function it(e) {
629
+ let t = {};
630
+ if (e.entities) for (let [n, r] of Object.entries(e.entities)) t[n] = rt(r);
631
+ let n = {};
632
+ if (e.structures) for (let [t, r] of Object.entries(e.structures)) n[t] = {
633
+ ...r,
634
+ fields: G.fromWire(r.fields)
635
+ };
636
+ let r = {};
637
+ if (e.handlers) for (let [t, n] of Object.entries(e.handlers)) r[t] = tt(n);
638
+ let i = {};
639
+ if (e.actions) for (let [t, n] of Object.entries(e.actions)) i[t] = nt(n);
640
+ let a = { ...e.screens };
641
+ for (let [e, t] of Object.entries(a)) {
642
+ let n = t;
643
+ a[e] = {
644
+ ...t,
645
+ variants: n.variants ? G.fromWire(n.variants) : void 0
646
+ };
647
+ }
648
+ return {
649
+ ...e,
650
+ entities: t,
651
+ structures: n,
652
+ handlers: r,
653
+ actions: i,
654
+ screens: a
655
+ };
656
+ }
657
+ async function at() {
658
+ let e = Ke(), t = it(await U("/api/schema", { cache: "no-cache" }));
659
+ return qe(e, t.language), t;
660
+ }
661
+ //#endregion
662
+ //#region src/lib/html-state.ts
663
+ function ot(e) {
664
+ typeof document > "u" || (document.documentElement.dataset.viewport = e);
665
+ }
666
+ function st(e) {
667
+ typeof document > "u" || (document.documentElement.dataset.embed = e ? "true" : "false");
668
+ }
669
+ //#endregion
670
+ //#region src/embed/params.ts
671
+ var ct = "self", K = "embed", q = "parent_origin", J = "theme", lt = [
672
+ K,
673
+ q,
674
+ J,
675
+ "nav"
676
+ ];
677
+ function ut(e) {
678
+ if (!e) return null;
679
+ let t;
680
+ try {
681
+ t = new URL(e);
682
+ } catch {
683
+ return null;
684
+ }
685
+ return t.origin === "null" ? null : e === t.origin ? t.origin : null;
686
+ }
687
+ function dt(e) {
688
+ return e === "light" || e === "dark" ? e : null;
689
+ }
690
+ function ft(e) {
691
+ return e === "delegated" ? "delegated" : ct;
692
+ }
693
+ function pt(e) {
694
+ let t = typeof e == "string" ? new URLSearchParams(e) : e;
695
+ return {
696
+ enabled: t.get(K) === "1",
697
+ parentOrigin: ut(t.get(q)),
698
+ theme: dt(t.get(J)),
699
+ navigationMode: ft(t.get("nav"))
700
+ };
701
+ }
702
+ function mt(e, t) {
703
+ if (!t.enabled) return e;
704
+ let n = /^[a-z][a-z0-9+.-]*:/i.test(e), r;
705
+ try {
706
+ r = new URL(e, "http://embed.invalid");
707
+ } catch {
708
+ return e;
709
+ }
710
+ let i = r.searchParams;
711
+ return t.enabled && i.set(K, "1"), t.parentOrigin && i.set(q, t.parentOrigin), t.theme && i.set(J, t.theme), i.set("nav", t.navigationMode), n ? r.toString() : `${r.pathname}${r.search}${r.hash}`;
712
+ }
713
+ //#endregion
714
+ //#region src/embed/EmbedContext.tsx
715
+ var Y = t({
716
+ enabled: !1,
717
+ parentOrigin: null,
718
+ theme: null,
719
+ navigationMode: "self",
720
+ appendEmbedParams: (e) => e
721
+ });
722
+ function ht(e) {
723
+ return {
724
+ enabled: e.enabled,
725
+ parentOrigin: e.parentOrigin,
726
+ theme: e.theme,
727
+ navigationMode: e.navigationMode,
728
+ appendEmbedParams: (t) => mt(t, e)
729
+ };
730
+ }
731
+ function gt({ children: e, query: t }) {
732
+ let n = a(() => ht(pt(t ?? (typeof window < "u" ? window.location.search : ""))), [t]);
733
+ return i(() => {
734
+ st(n.enabled);
735
+ }, [n.enabled]), /* @__PURE__ */ s(Y.Provider, {
736
+ value: n,
737
+ children: e
738
+ });
739
+ }
740
+ function _t() {
741
+ return r(Y);
742
+ }
743
+ //#endregion
744
+ //#region src/api/auth.ts
745
+ async function vt() {
746
+ return W("auth.check_setup");
747
+ }
748
+ async function yt(e, t, n = !0) {
749
+ let r = await W("auth.login", {
750
+ email: e,
751
+ password: t,
752
+ remember: n
753
+ });
754
+ return I(r.expires_at), r;
755
+ }
756
+ async function bt(e, t, n) {
757
+ let r = await W("auth.signup", {
758
+ email: e,
759
+ password: t,
760
+ display_name: n
761
+ });
762
+ return I(r.expires_at), r;
763
+ }
764
+ async function X() {
765
+ return W("auth.me");
766
+ }
767
+ async function xt() {
768
+ return (await W("auth.list_tenants")).tenants;
769
+ }
770
+ async function St(e) {
771
+ let t = await W("auth.switch_tenant", { tenant_id: e });
772
+ return I(t.expires_at), t;
773
+ }
774
+ async function Ct() {
775
+ await W("auth.logout");
776
+ }
777
+ async function wt(e) {
778
+ return (await W("sso_provider.list", e ? { tenant_code: e } : {})).providers;
779
+ }
780
+ function Tt(e, t, n) {
781
+ let r = new URLSearchParams();
782
+ t && r.set("tenant", t), n && r.set("redirect", n);
783
+ let i = r.toString();
784
+ return `/api/auth/sso/authorize/${encodeURIComponent(e)}${i ? `?${i}` : ""}`;
785
+ }
786
+ async function Et(e, t, n) {
787
+ let r = {
788
+ target_user_id: e,
789
+ reason: t
790
+ };
791
+ return n != null && (r.duration_minutes = n), W("impersonation.start", r);
792
+ }
793
+ async function Dt() {
794
+ return W("impersonation.stop");
795
+ }
796
+ async function Ot(e) {
797
+ await W("impersonation.revoke", { session_id: e });
798
+ }
799
+ async function kt(e, t) {
800
+ await W("auth.change_password", {
801
+ current_password: e,
802
+ new_password: t
803
+ });
804
+ }
805
+ //#endregion
806
+ //#region src/stores/auth.ts
807
+ var Z = c((e) => ({
808
+ user: null,
809
+ isAuthenticated: !1,
810
+ isLoading: !0,
811
+ activeTenant: null,
812
+ tenants: [],
813
+ initialize: async () => {
814
+ try {
815
+ let t = await X(), n = t.tenant ?? null, r = [];
816
+ try {
817
+ r = await xt();
818
+ } catch {}
819
+ e({
820
+ user: t,
821
+ isAuthenticated: !0,
822
+ isLoading: !1,
823
+ activeTenant: n,
824
+ tenants: r
825
+ });
826
+ } catch {
827
+ e({
828
+ user: null,
829
+ isAuthenticated: !1,
830
+ isLoading: !1
831
+ });
832
+ }
833
+ },
834
+ refreshMe: async () => {
835
+ try {
836
+ let t = await X();
837
+ e({
838
+ user: t,
839
+ activeTenant: t.tenant ?? null
840
+ });
841
+ } catch {}
842
+ },
843
+ setUser: (t, n) => {
844
+ e({
845
+ user: t,
846
+ isAuthenticated: !0,
847
+ isLoading: !1,
848
+ activeTenant: n ?? null
849
+ });
850
+ },
851
+ setTenants: (t) => {
852
+ e({ tenants: t });
853
+ },
854
+ setActiveTenant: (t) => {
855
+ e({ activeTenant: t });
856
+ },
857
+ logout: async () => {
858
+ ze();
859
+ try {
860
+ await Ct();
861
+ } catch {}
862
+ e({
863
+ user: null,
864
+ isAuthenticated: !1,
865
+ activeTenant: null,
866
+ tenants: []
867
+ });
868
+ }
869
+ }));
870
+ Z.subscribe((e, t) => {
871
+ e.isAuthenticated !== t.isAuthenticated && Ge(null);
872
+ });
873
+ //#endregion
874
+ //#region src/hooks/useSchema.ts
875
+ function Q() {
876
+ let e = Z((e) => e.isAuthenticated), t = _t().enabled;
877
+ return o({
878
+ queryKey: ["schema", e],
879
+ queryFn: at,
880
+ staleTime: Infinity,
881
+ enabled: e || !t
882
+ });
883
+ }
884
+ //#endregion
885
+ //#region src/lib/language.ts
886
+ var At = "en", jt = "ui_language";
887
+ function Mt(e, t, n) {
888
+ if (e) for (let r of [
889
+ t,
890
+ n,
891
+ "en"
892
+ ]) {
893
+ let t = e[r];
894
+ if (t) return [r, t];
895
+ }
896
+ }
897
+ function $(e, t, n) {
898
+ return Mt(e, t, n)?.[1];
899
+ }
900
+ function Nt(e, t, n) {
901
+ function r(r, i, a) {
902
+ if (typeof r != "string") return $(r, t, n) ?? "";
903
+ let o = $(e?.[r], t, n) ?? i ?? "";
904
+ return a ? o.replace(/\{(\w+)\}/g, (e, t) => Object.hasOwn(a, t) ? String(a[t]) : e) : o;
905
+ }
906
+ return Object.assign(r, {
907
+ language: t,
908
+ deploymentLanguage: n
909
+ });
910
+ }
911
+ function Pt(e, t, n, r, i) {
912
+ let a = new Intl.PluralRules(e.language).select(n), o = {
913
+ ...i,
914
+ count: n
915
+ };
916
+ return e(`${t}.${a}`, "", o) || e(`${t}.other`, a === "one" ? r.one : r.other, o);
917
+ }
918
+ function Ft(t, r) {
919
+ return t.split(/(\{[A-Za-z_][A-Za-z0-9_]*\})/).filter((e) => e !== "").map((t, i) => {
920
+ let a = /^\{(\w+)\}$/.exec(t)?.[1];
921
+ return n(e, { key: i }, a !== void 0 && Object.hasOwn(r, a) ? r[a] : t);
922
+ });
923
+ }
924
+ //#endregion
925
+ //#region src/hooks/useLanguage.ts
926
+ function It() {
927
+ let { data: e } = Q();
928
+ return e?.language || "en";
929
+ }
930
+ function Lt() {
931
+ let { data: e } = Q();
932
+ return e?.deployment_language || "en";
933
+ }
934
+ async function Rt(e) {
935
+ let t = Je();
936
+ Ge(null), await e.refetchQueries({
937
+ queryKey: ["schema"],
938
+ type: "active"
939
+ }), Je() !== t && await e.invalidateQueries({ predicate: (e) => e.queryKey[0] !== "schema" });
940
+ }
941
+ //#endregion
942
+ //#region src/hooks/useText.ts
943
+ function zt(e = "messages") {
944
+ let { data: t } = Q(), n = It(), r = Lt(), i = e === "errors" ? t?.errors : t?.messages;
945
+ return a(() => Nt(i, n, r), [
946
+ i,
947
+ n,
948
+ r
949
+ ]);
950
+ }
951
+ //#endregion
952
+ export { l as $, G as A, Ce as B, bt as C, _t as D, gt as E, z as F, ue as G, x as H, He as I, ce as J, b as K, Ve as L, U as M, $e as N, lt as O, W as P, ae as Q, Ye as R, yt as S, St as T, he as U, we as V, de as W, _ as X, g as Y, oe as Z, Ot as _, jt as a, p as at, wt as b, $ as c, Ft as d, ee as et, Q as f, X as g, vt as h, It as i, te as it, j, ot as k, Mt as l, kt as m, Rt as n, u as nt, At as o, Z as p, me as q, Lt as r, d as rt, Nt as s, zt as t, f as tt, Pt as u, Et as v, Tt as w, xt as x, Dt as y, be as z };