@declarion/react 0.106.0 → 0.110.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 (43) hide show
  1. package/dist-lib/api/agents.js +9 -7
  2. package/dist-lib/api/audience.js +12 -0
  3. package/dist-lib/api/auth.js +1 -1
  4. package/dist-lib/api/client.js +101 -93
  5. package/dist-lib/api/schema.js +31 -31
  6. package/dist-lib/components/agents/AgentChatPanel.impl.js +362 -301
  7. package/dist-lib/components/agents/ChatAttachments.js +154 -0
  8. package/dist-lib/components/agents/transcript-runs.js +1 -1
  9. package/dist-lib/components/chrome/AssociationTabs.js +89 -75
  10. package/dist-lib/components/detail-layout/AssociatedBlock.js +243 -235
  11. package/dist-lib/components/detail-layout/ChildrenCards.js +57 -55
  12. package/dist-lib/components/detail-layout/ChildrenList.js +45 -43
  13. package/dist-lib/components/detail-layout/ChildrenTable.js +93 -91
  14. package/dist-lib/components/detail-layout/ChildrenTimeline.js +160 -155
  15. package/dist-lib/components/detail-layout/widgets/EntityScorecardWidget.js +127 -121
  16. package/dist-lib/components/fields/RefCombobox.js +53 -48
  17. package/dist-lib/components/fields/index.js +1 -0
  18. package/dist-lib/components/file-widgets/DocumentCard.js +1 -1
  19. package/dist-lib/components/file-widgets/FileList.js +1 -1
  20. package/dist-lib/components/file-widgets/Grid.js +1 -1
  21. package/dist-lib/components/file-widgets/upload.js +64 -61
  22. package/dist-lib/components/file-widgets/useFileSelection.js +152 -0
  23. package/dist-lib/components/pages/SmartDetailPage.impl.js +506 -482
  24. package/dist-lib/components/pages/SmartRecordListPage.impl.js +335 -300
  25. package/dist-lib/components/pages/tenant-params/TenantParamsPage.impl.js +112 -109
  26. package/dist-lib/components/params/ParamsBlock.js +18 -15
  27. package/dist-lib/components/params/param-editors.js +60 -54
  28. package/dist-lib/components/primitives/RetryButton.js +14 -0
  29. package/dist-lib/components/primitives/StatTile.js +42 -34
  30. package/dist-lib/hooks/useAgentConversation.js +122 -109
  31. package/dist-lib/hooks/useAuth.js +4 -1
  32. package/dist-lib/hooks/useParams.js +54 -52
  33. package/dist-lib/hooks/useSchema.js +25 -30
  34. package/dist-lib/hooks/useTimelineData.js +26 -24
  35. package/dist-lib/index.d.ts +90 -6
  36. package/dist-lib/index.js +95 -93
  37. package/dist-lib/lib/read-display-state.js +19 -0
  38. package/dist-lib/stores/auth.js +35 -34
  39. package/dist-lib/test/seed-schema.js +4 -3
  40. package/dist-lib/testing.d.ts +1 -1
  41. package/dist-lib/types/fieldType.js +1 -1
  42. package/dist-lib/{useResponsiveMode-ECv1AEhv.d.ts → useResponsiveMode-C4MeAgoS.d.ts} +3 -1
  43. package/package.json +1 -1
@@ -1,9 +1,9 @@
1
1
  import { errorCodeOf as e, isApiErrorBody as t } from "../../types/api.js";
2
2
  import { awaitEmbedToken as n, clearEmbedToken as r, isEmbedTokenMode as i } from "../../embed/token.js";
3
- import { callHandler as a, ensureRefresh as o, getPersistentAuthFailureHandler as s, isTransientFailure as c } from "../../api/client.js";
4
- import { failureTitle as l } from "../../lib/failure.js";
3
+ import { callHandler as a, ensureRefresh as o, getPersistentAuthFailureHandler as s, isTransientFailure as c, withPublishedLanguage as l } from "../../api/client.js";
4
+ import { failureTitle as u } from "../../lib/failure.js";
5
5
  //#region src/components/file-widgets/upload.ts
6
- var u = class extends Error {
6
+ var d = class extends Error {
7
7
  code;
8
8
  status;
9
9
  raw;
@@ -14,10 +14,10 @@ var u = class extends Error {
14
14
  return this.raw?.[e];
15
15
  }
16
16
  };
17
- function d(e, n, r) {
18
- if (!(r instanceof u)) return {
17
+ function f(e, n, r) {
18
+ if (!(r instanceof d)) return {
19
19
  code: "UNKNOWN",
20
- message: l(n, r)
20
+ message: u(n, r)
21
21
  };
22
22
  if (t(r.raw)) return {
23
23
  code: r.code,
@@ -29,12 +29,12 @@ function d(e, n, r) {
29
29
  };
30
30
  return r.code === "file.upload_failed" && (i.detail = e("file.upload.status", "HTTP status {status}", { status: r.status })), i;
31
31
  }
32
- async function f(e) {
32
+ async function p(e) {
33
33
  let t = i();
34
34
  try {
35
- return await p(e, t ? await n() : null);
35
+ return await m(e, t ? await n() : null);
36
36
  } catch (i) {
37
- if (!(i instanceof u && i.status === 401 && (i.code === "auth.token_refresh_needed" || i.code === "auth.unauthorized"))) throw i;
37
+ if (!(i instanceof d && i.status === 401 && (i.code === "auth.token_refresh_needed" || i.code === "auth.unauthorized"))) throw i;
38
38
  let a = null;
39
39
  try {
40
40
  t ? (r(), a = await n()) : await o();
@@ -42,17 +42,17 @@ async function f(e) {
42
42
  throw !t && c(e) ? e : (s()(), i);
43
43
  }
44
44
  try {
45
- return await p(e, a);
45
+ return await m(e, a);
46
46
  } catch (e) {
47
- throw e instanceof u && e.status === 401 && s()(), e;
47
+ throw e instanceof d && e.status === 401 && s()(), e;
48
48
  }
49
49
  }
50
50
  }
51
- function p(n, r) {
52
- let { file: i, entityCode: a, fieldCode: o, slotCode: s, onProgress: c, signal: l } = n;
53
- return new Promise((n, d) => {
54
- let f = new XMLHttpRequest();
55
- if (f.open("POST", m(a, o, s)), f.withCredentials = r === null, r && f.setRequestHeader("Authorization", `Bearer ${r}`), f.upload.onprogress = (e) => {
51
+ function m(n, r) {
52
+ let { file: i, entityCode: a, fieldCode: o, slotCode: s, onProgress: c, signal: u } = n;
53
+ return new Promise((n, f) => {
54
+ let p = new XMLHttpRequest();
55
+ if (p.open("POST", l(h(a, o, s))), p.withCredentials = r === null, r && p.setRequestHeader("Authorization", `Bearer ${r}`), p.upload.onprogress = (e) => {
56
56
  if (!c) return;
57
57
  let t = e.lengthComputable ? e.total : i.size, n = t > 0 ? Math.min(100, Math.round(e.loaded / t * 100)) : 0;
58
58
  c({
@@ -60,72 +60,68 @@ function p(n, r) {
60
60
  total: t,
61
61
  pct: n
62
62
  });
63
- }, f.onload = () => {
64
- let r = f.responseText || "", i = null;
63
+ }, p.onload = () => {
64
+ let r = p.responseText || "", i = null;
65
65
  try {
66
66
  i = r ? JSON.parse(r) : null;
67
67
  } catch {}
68
- if (f.status >= 200 && f.status < 300) {
69
- let e = h(i);
68
+ if (p.status >= 200 && p.status < 300) {
69
+ let e = g(i);
70
70
  if (!e || !e.id) {
71
- d(new u(f.status, "file.upload_no_id", "The upload finished but returned no file identifier."));
71
+ f(new d(p.status, "file.upload_no_id", "The upload finished but returned no file identifier."));
72
72
  return;
73
73
  }
74
74
  n(e);
75
75
  return;
76
76
  }
77
77
  let a = t(i) ? e(i.type) : "", o = t(i) ? i.title : "";
78
- d(new u(f.status, a || "file.upload_failed", o, i));
79
- }, f.onerror = () => {
80
- d(new u(0, "file.upload_network", "The upload stopped because the network connection failed."));
81
- }, f.onabort = () => {
82
- d(new u(0, "ABORTED", "Upload aborted"));
83
- }, l) {
84
- if (l.aborted) {
85
- f.abort(), d(new u(0, "ABORTED", "Upload aborted"));
78
+ f(new d(p.status, a || "file.upload_failed", o, i));
79
+ }, p.onerror = () => {
80
+ f(new d(0, "file.upload_network", "The upload stopped because the network connection failed."));
81
+ }, p.onabort = () => {
82
+ f(new d(0, "ABORTED", "Upload aborted"));
83
+ }, u) {
84
+ if (u.aborted) {
85
+ p.abort(), f(new d(0, "ABORTED", "Upload aborted"));
86
86
  return;
87
87
  }
88
- l.addEventListener("abort", () => f.abort(), { once: !0 });
88
+ u.addEventListener("abort", () => p.abort(), { once: !0 });
89
89
  }
90
- let p = new FormData();
91
- p.append("file", i, i.name), f.send(p);
90
+ let m = new FormData();
91
+ m.append("file", i, i.name), p.send(m);
92
92
  });
93
93
  }
94
- function m(e, t, n) {
94
+ function h(e, t, n) {
95
95
  let r = new URLSearchParams();
96
96
  e && t && (r.set("entity_code", e), r.set("field_code", t), n && r.set("slot_code", n));
97
97
  let i = r.toString();
98
98
  return i ? `/api/files/upload?${i}` : "/api/files/upload";
99
99
  }
100
- function h(e) {
101
- return _(e) && _(e.file) ? g(e.file) : null;
102
- }
103
100
  function g(e) {
104
- let t = v(e.file_id), n = v(e.url);
101
+ return v(e) && v(e.file) ? _(e.file) : null;
102
+ }
103
+ function _(e) {
104
+ let t = y(e.file_id), n = y(e.url);
105
105
  if (!t || !n) return null;
106
- let r = v(e.filename_original) ?? v(e.filename_normalized) ?? t;
106
+ let r = y(e.filename_original) ?? y(e.filename_normalized) ?? t;
107
107
  return {
108
108
  id: t,
109
109
  url: n,
110
- presigned_url: v(e.presigned_url),
110
+ presigned_url: y(e.presigned_url),
111
111
  filename: r,
112
- content_type: v(e.content_type) ?? "application/octet-stream",
113
- size_bytes: y(e.size_bytes) ?? 0,
114
- sha256: v(e.sha256) ?? "",
115
- dedup: b(e.dedup)
112
+ content_type: y(e.content_type) ?? "application/octet-stream",
113
+ size_bytes: b(e.size_bytes) ?? 0,
114
+ sha256: y(e.sha256) ?? ""
116
115
  };
117
116
  }
118
- function _(e) {
119
- return typeof e == "object" && !!e;
120
- }
121
117
  function v(e) {
122
- return typeof e == "string" ? e : void 0;
118
+ return typeof e == "object" && !!e;
123
119
  }
124
120
  function y(e) {
125
- return typeof e == "number" ? e : void 0;
121
+ return typeof e == "string" ? e : void 0;
126
122
  }
127
123
  function b(e) {
128
- return typeof e == "boolean" ? e : void 0;
124
+ return typeof e == "number" ? e : void 0;
129
125
  }
130
126
  async function x(e) {
131
127
  await a("file.discard", { file_id: e });
@@ -153,8 +149,8 @@ function T(e, t, n) {
153
149
  code: n.code,
154
150
  message: t(n.code, S),
155
151
  detail: e("file.upload.size_limit", "{size} of {max} allowed", {
156
- size: D(n.size),
157
- max: D(n.max)
152
+ size: O(n.size, e.language),
153
+ max: O(n.max, e.language)
158
154
  })
159
155
  } : {
160
156
  code: n.code,
@@ -170,15 +166,22 @@ function E(e, t) {
170
166
  }
171
167
  return e === t;
172
168
  }
173
- function D(e) {
174
- if (e < 1024) return `${e} B`;
175
- let t = [
176
- "KB",
177
- "MB",
178
- "GB"
179
- ], n = e / 1024, r = 0;
180
- for (; n >= 1024 && r < t.length - 1;) n /= 1024, r++;
181
- return `${n.toFixed(n >= 10 ? 0 : 1)} ${t[r]}`;
169
+ var D = [
170
+ "byte",
171
+ "kilobyte",
172
+ "megabyte",
173
+ "gigabyte"
174
+ ];
175
+ function O(e, t) {
176
+ let n = e, r = 0;
177
+ for (; n >= 1024 && r < D.length - 1;) n /= 1024, r++;
178
+ let i = r === 0 || n >= 10 ? 0 : 1;
179
+ return new Intl.NumberFormat(t, {
180
+ style: "unit",
181
+ unit: D[r],
182
+ unitDisplay: "short",
183
+ maximumFractionDigits: i
184
+ }).format(n);
182
185
  }
183
186
  //#endregion
184
- export { u as UploadError, x as discardFile, D as formatBytes, T as uploadCheckFailure, d as uploadFailure, f as uploadFile, w as validateClientSide };
187
+ export { d as UploadError, x as discardFile, O as formatBytes, T as uploadCheckFailure, f as uploadFailure, p as uploadFile, w as validateClientSide };
@@ -0,0 +1,152 @@
1
+ import { useText as e } from "../../hooks/useText.js";
2
+ import { UploadError as t, discardFile as n, uploadCheckFailure as r, uploadFailure as i, uploadFile as a, validateClientSide as o } from "./upload.js";
3
+ import { useCallback as s, useEffect as c, useReducer as l, useRef as u } from "react";
4
+ //#region src/components/file-widgets/useFileSelection.ts
5
+ function d(e, t) {
6
+ let n = (t, n) => e.map((e) => e.localId === t && e.state === "uploading" ? {
7
+ ...e,
8
+ ...n
9
+ } : e);
10
+ switch (t.type) {
11
+ case "added": return [...e, {
12
+ localId: t.localId,
13
+ filename: t.filename,
14
+ sizeBytes: t.sizeBytes,
15
+ state: "uploading",
16
+ progress: {
17
+ loaded: 0,
18
+ total: t.sizeBytes,
19
+ pct: 0
20
+ },
21
+ failure: null,
22
+ uploaded: null
23
+ }];
24
+ case "refused": return [...e, {
25
+ localId: t.localId,
26
+ filename: t.filename,
27
+ sizeBytes: t.sizeBytes,
28
+ state: "failed",
29
+ progress: null,
30
+ failure: t.failure,
31
+ uploaded: null
32
+ }];
33
+ case "progressed": return n(t.localId, { progress: t.progress });
34
+ case "uploaded": return n(t.localId, {
35
+ state: "ready",
36
+ progress: null,
37
+ uploaded: t.uploaded
38
+ });
39
+ case "failed": return n(t.localId, {
40
+ state: "failed",
41
+ progress: null,
42
+ failure: t.failure
43
+ });
44
+ case "cancelled": return n(t.localId, {
45
+ state: "cancelled",
46
+ progress: null
47
+ });
48
+ case "removed": return e.filter((e) => e.localId !== t.localId);
49
+ case "released": return e.filter((e) => !t.localIds.includes(e.localId));
50
+ }
51
+ }
52
+ function f(e) {
53
+ let t = e.some((e) => e.state === "uploading"), n = e.some((e) => e.state === "failed");
54
+ return {
55
+ readyFiles: e.flatMap((e) => e.state === "ready" && e.uploaded ? [e.uploaded] : []),
56
+ uploading: t,
57
+ failed: n,
58
+ settled: !t && !n
59
+ };
60
+ }
61
+ function p({ entityCode: p, fieldCode: m, accepts: h, maxSizeBytes: g }) {
62
+ let _ = e(), v = e("errors"), [y, b] = l(d, []), x = u(/* @__PURE__ */ new Map()), S = u(y);
63
+ S.current = y, c(() => {
64
+ let e = x.current;
65
+ return () => e.forEach((e) => e.abort());
66
+ }, []);
67
+ let C = s(async (e) => {
68
+ let s = `selection-${crypto.randomUUID()}`, c = o(e, h, g);
69
+ if (c) {
70
+ b({
71
+ type: "refused",
72
+ localId: s,
73
+ filename: e.name,
74
+ sizeBytes: e.size,
75
+ failure: r(_, v, c)
76
+ });
77
+ return;
78
+ }
79
+ let l = new AbortController();
80
+ x.current.set(s, l), b({
81
+ type: "added",
82
+ localId: s,
83
+ filename: e.name,
84
+ sizeBytes: e.size
85
+ });
86
+ try {
87
+ let t = await a({
88
+ file: e,
89
+ entityCode: p,
90
+ fieldCode: m,
91
+ signal: l.signal,
92
+ onProgress: (e) => b({
93
+ type: "progressed",
94
+ localId: s,
95
+ progress: e
96
+ })
97
+ });
98
+ if (l.signal.aborted) {
99
+ n(t.id).catch(() => {});
100
+ return;
101
+ }
102
+ b({
103
+ type: "uploaded",
104
+ localId: s,
105
+ uploaded: t
106
+ });
107
+ } catch (e) {
108
+ if (e instanceof t && e.code === "ABORTED") return;
109
+ b({
110
+ type: "failed",
111
+ localId: s,
112
+ failure: i(_, v, e)
113
+ });
114
+ } finally {
115
+ x.current.delete(s);
116
+ }
117
+ }, [
118
+ h,
119
+ p,
120
+ v,
121
+ m,
122
+ g,
123
+ _
124
+ ]);
125
+ return {
126
+ selections: y,
127
+ add: s((e) => {
128
+ Array.from(e).forEach((e) => void C(e));
129
+ }, [C]),
130
+ cancel: s((e) => {
131
+ x.current.get(e)?.abort(), b({
132
+ type: "cancelled",
133
+ localId: e
134
+ });
135
+ }, []),
136
+ remove: s((e) => {
137
+ x.current.get(e)?.abort();
138
+ let t = S.current.find((t) => t.localId === e)?.uploaded, r = t && S.current.some((n) => n.localId !== e && n.uploaded?.id === t.id);
139
+ t && !r && n(t.id).catch(() => {}), b({
140
+ type: "removed",
141
+ localId: e
142
+ });
143
+ }, []),
144
+ release: s((e) => b({
145
+ type: "released",
146
+ localIds: e
147
+ }), []),
148
+ ...f(y)
149
+ };
150
+ }
151
+ //#endregion
152
+ export { d as fileSelectionReducer, f as summarizeFileSelections, p as useFileSelection };