@epam/ai-dial-attachment-canvas 1.2.0-dev.319 → 1.2.0-dev.321
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.
- package/PdfContent-ELaDSyFF.js +266 -0
- package/components/AttachmentCanvasBody/AttachmentCanvasBody.d.ts.map +1 -1
- package/components/PdfContent/PdfContent.d.ts +2 -0
- package/components/PdfContent/PdfContent.d.ts.map +1 -1
- package/index.js +306 -296
- package/package.json +4 -4
- package/PdfContent-BoAtghsO.js +0 -260
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import "./PdfContent.css";
|
|
2
|
+
import { a as e, n as t, r as n } from "./LazyContentBoundary-tNE1ExbI.js";
|
|
3
|
+
import { mergeClasses as r } from "@epam/ai-dial-chat-shared";
|
|
4
|
+
import { DIAL_ICON_SIZE as i, DIAL_KIT_ICON_STROKE as a, Dropdown as o, ElementSize as s, FabButton as c, Input as ee } from "@epam/ai-dial-ui-kit";
|
|
5
|
+
import { IconMenu2 as te, IconX as ne } from "@tabler/icons-react";
|
|
6
|
+
import { useCallback as l, useEffect as u, useId as d, useRef as f, useState as p } from "react";
|
|
7
|
+
import { jsx as m, jsxs as h } from "react/jsx-runtime";
|
|
8
|
+
import { DocumentPreview as re, PageThumbnail as ie } from "@epam/ai-dial-react-pdf-highlighter";
|
|
9
|
+
var g = { viewer: "_viewer_1gfxm_1" }, _ = null, ae = (e) => (_ ||= new Promise((t, n) => {
|
|
10
|
+
try {
|
|
11
|
+
t(e());
|
|
12
|
+
} catch (e) {
|
|
13
|
+
n(e);
|
|
14
|
+
}
|
|
15
|
+
}).catch((e) => {
|
|
16
|
+
throw _ = null, e;
|
|
17
|
+
}), _), oe = 15, v = 3, se = 172, ce = 400, y = 150, le = 60, b = ({ url: _, highlights: b, selectedHighlightId: x, selectedPageNumber: S, loadPdf: C, configurePdfWorker: w, hideHeader: ue = !1, onLoadError: T, labels: { thumbnailsLabel: de = "Thumbnails", showThumbnailsLabel: fe = "Show thumbnails", hideThumbnailsLabel: pe = "Hide thumbnails", pageNumberLabel: me = "Page number", loadingLabel: he = "Loading…", errorLabel: ge = "Failed to load content", retryLabel: _e = "Retry" } = {} }) => {
|
|
18
|
+
let [E, D] = p(() => w ? "preparing" : "ready"), [ve, ye] = p(0), be = l(async (t) => {
|
|
19
|
+
try {
|
|
20
|
+
return await (C ?? e)(t);
|
|
21
|
+
} catch (e) {
|
|
22
|
+
throw T?.(t), e;
|
|
23
|
+
}
|
|
24
|
+
}, [C, T]);
|
|
25
|
+
u(() => {
|
|
26
|
+
if (!w) return;
|
|
27
|
+
D("preparing");
|
|
28
|
+
let e = !1;
|
|
29
|
+
return ae(w).then(() => {
|
|
30
|
+
e || D("ready");
|
|
31
|
+
}).catch(() => {
|
|
32
|
+
e || D("error");
|
|
33
|
+
}), () => {
|
|
34
|
+
e = !0;
|
|
35
|
+
};
|
|
36
|
+
}, [w, ve]);
|
|
37
|
+
let xe = l(() => {
|
|
38
|
+
ye((e) => e + 1);
|
|
39
|
+
}, []), O = d(), [k, Se] = p(0), [A, j] = p(/* @__PURE__ */ new Map()), [M, Ce] = p(!1), [N, P] = p(() => S ?? (x ? b.find((e) => e.id === x)?.bboxes[0]?.page ?? 1 : 1)), F = f(null), I = f(null), [we, L] = p([]), [R, Te] = p(se), [z, Ee] = p(ce), [De, B] = p(0), V = f(!1), H = f(0), U = f(null);
|
|
40
|
+
u(() => {
|
|
41
|
+
if (S != null) {
|
|
42
|
+
P(S);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (!x) return;
|
|
46
|
+
let e = b.find((e) => e.id === x)?.bboxes[0]?.page;
|
|
47
|
+
e != null && P(e);
|
|
48
|
+
}, [
|
|
49
|
+
S,
|
|
50
|
+
x,
|
|
51
|
+
b
|
|
52
|
+
]), u(() => {
|
|
53
|
+
let e = I.current;
|
|
54
|
+
if (!M || !e) return;
|
|
55
|
+
let t = new ResizeObserver((e) => {
|
|
56
|
+
let t = e[0]?.contentRect.height;
|
|
57
|
+
t && Ee(t);
|
|
58
|
+
});
|
|
59
|
+
return t.observe(e), () => t.disconnect();
|
|
60
|
+
}, [M]);
|
|
61
|
+
let Oe = l((e) => {
|
|
62
|
+
if (!e || V.current) return;
|
|
63
|
+
let t = e.getBoundingClientRect().height;
|
|
64
|
+
t > 0 && (V.current = !0, Te(t));
|
|
65
|
+
}, []), ke = l((e) => {
|
|
66
|
+
H.current = e.currentTarget.scrollTop, U.current ??= requestAnimationFrame(() => {
|
|
67
|
+
U.current = null, B(H.current);
|
|
68
|
+
});
|
|
69
|
+
}, []);
|
|
70
|
+
u(() => () => {
|
|
71
|
+
U.current != null && cancelAnimationFrame(U.current);
|
|
72
|
+
}, []);
|
|
73
|
+
let W = l((e) => {
|
|
74
|
+
if (k === 0) return;
|
|
75
|
+
let t = Math.max(0, (N - 1) * R - e.clientHeight / 2 + R / 2);
|
|
76
|
+
H.current = t, B(t), e.scrollTop = t;
|
|
77
|
+
}, [
|
|
78
|
+
N,
|
|
79
|
+
k,
|
|
80
|
+
R
|
|
81
|
+
]), Ae = l((e) => {
|
|
82
|
+
I.current = e, e && W(e);
|
|
83
|
+
}, [W]);
|
|
84
|
+
u(() => {
|
|
85
|
+
let e = I.current;
|
|
86
|
+
e && W(e);
|
|
87
|
+
}, [W]);
|
|
88
|
+
let G = Math.max(0, Math.floor(De / R) - v), je = Math.ceil(z / R) + v * 2, K = Math.min(k - 1, G + je);
|
|
89
|
+
u(() => {
|
|
90
|
+
if (k === 0) return;
|
|
91
|
+
let e = Math.min(k, oe);
|
|
92
|
+
L(Array.from({ length: e }, (e, t) => t + 1));
|
|
93
|
+
}, [k]), u(() => {
|
|
94
|
+
if (!M || k === 0) return;
|
|
95
|
+
let e = setTimeout(() => {
|
|
96
|
+
L((e) => {
|
|
97
|
+
let t = new Set(e), n = !1;
|
|
98
|
+
for (let e = G + 1; e <= K + 1; e++) t.has(e) || (t.add(e), n = !0);
|
|
99
|
+
return n ? Array.from(t).sort((e, t) => e - t) : e;
|
|
100
|
+
});
|
|
101
|
+
}, y);
|
|
102
|
+
return () => clearTimeout(e);
|
|
103
|
+
}, [
|
|
104
|
+
M,
|
|
105
|
+
G,
|
|
106
|
+
K,
|
|
107
|
+
k
|
|
108
|
+
]), u(() => {
|
|
109
|
+
if (k === 0) return;
|
|
110
|
+
let e = setTimeout(() => {
|
|
111
|
+
let e = Math.ceil(z / R / 2) + v, t = Math.max(0, N - 1 - e), n = Math.min(k - 1, N - 1 + e);
|
|
112
|
+
L((e) => {
|
|
113
|
+
let r = new Set(e), i = !1;
|
|
114
|
+
for (let e = t + 1; e <= n + 1; e++) r.has(e) || (r.add(e), i = !0);
|
|
115
|
+
return i ? Array.from(r).sort((e, t) => e - t) : e;
|
|
116
|
+
});
|
|
117
|
+
}, y);
|
|
118
|
+
return () => clearTimeout(e);
|
|
119
|
+
}, [
|
|
120
|
+
N,
|
|
121
|
+
k,
|
|
122
|
+
z,
|
|
123
|
+
R
|
|
124
|
+
]);
|
|
125
|
+
let Me = l((e) => {
|
|
126
|
+
j((t) => new Map([...t, ...e]));
|
|
127
|
+
}, []), [q, Ne] = p(!1), Pe = l((e) => {
|
|
128
|
+
F.current = e, Ne(!0);
|
|
129
|
+
}, []), J = f(null);
|
|
130
|
+
u(() => {
|
|
131
|
+
if (!q) return;
|
|
132
|
+
let e = J.current, t = e?.querySelector(".pdf-container"), n = e?.querySelector(".pdf-highlight-viewer");
|
|
133
|
+
if (!t || !n) return;
|
|
134
|
+
let r = () => {
|
|
135
|
+
let e = n.scrollWidth - n.clientWidth;
|
|
136
|
+
e > 0 && (n.scrollLeft = e / 2);
|
|
137
|
+
};
|
|
138
|
+
r();
|
|
139
|
+
let i = new ResizeObserver(r);
|
|
140
|
+
i.observe(t), i.observe(n);
|
|
141
|
+
let a = F.current?.getZoom(), o = 0, s, c = () => {
|
|
142
|
+
let e = F.current?.getZoom();
|
|
143
|
+
e !== a && (a = e, o = le), o > 0 && (r(), --o), s = requestAnimationFrame(c);
|
|
144
|
+
};
|
|
145
|
+
return s = requestAnimationFrame(c), () => {
|
|
146
|
+
cancelAnimationFrame(s), i.disconnect();
|
|
147
|
+
};
|
|
148
|
+
}, [q]), u(() => {
|
|
149
|
+
if (!q || x || S != null) return;
|
|
150
|
+
let e = requestAnimationFrame(() => {
|
|
151
|
+
F.current?.navigateToPage(1);
|
|
152
|
+
});
|
|
153
|
+
return () => cancelAnimationFrame(e);
|
|
154
|
+
}, [
|
|
155
|
+
q,
|
|
156
|
+
x,
|
|
157
|
+
S
|
|
158
|
+
]);
|
|
159
|
+
let Y = l((e) => {
|
|
160
|
+
P(e), F.current?.navigateToPage(e);
|
|
161
|
+
}, []), Fe = l((e) => {
|
|
162
|
+
P(e);
|
|
163
|
+
}, []), [X, Z] = p(() => String(N));
|
|
164
|
+
u(() => {
|
|
165
|
+
Z(String(N));
|
|
166
|
+
}, [N]);
|
|
167
|
+
let Q = l((e) => {
|
|
168
|
+
let t = Number(e);
|
|
169
|
+
Number.isInteger(t) && t >= 1 && t <= k ? Y(t) : Z(String(N));
|
|
170
|
+
}, [
|
|
171
|
+
k,
|
|
172
|
+
N,
|
|
173
|
+
Y
|
|
174
|
+
]);
|
|
175
|
+
if (!_) return null;
|
|
176
|
+
if (E === "preparing") return /* @__PURE__ */ m(n, { loadingLabel: he });
|
|
177
|
+
if (E === "error") return /* @__PURE__ */ m(t, {
|
|
178
|
+
errorLabel: ge,
|
|
179
|
+
retryLabel: _e,
|
|
180
|
+
onRetry: xe
|
|
181
|
+
});
|
|
182
|
+
let $ = [];
|
|
183
|
+
for (let e = G + 1; e <= K + 1 && e <= k; e++) $.push(/* @__PURE__ */ m("div", {
|
|
184
|
+
ref: e === G + 1 ? Oe : void 0,
|
|
185
|
+
children: /* @__PURE__ */ m(ie, {
|
|
186
|
+
pageNum: e,
|
|
187
|
+
onSelectPage: Y,
|
|
188
|
+
isSelected: N === e,
|
|
189
|
+
isLoading: !A.has(e),
|
|
190
|
+
thumbnailUrl: A.get(e) ?? null
|
|
191
|
+
})
|
|
192
|
+
}, e));
|
|
193
|
+
let Ie = G * R, Le = Math.max(0, k - K - 1) * R;
|
|
194
|
+
return /* @__PURE__ */ h("div", {
|
|
195
|
+
className: "relative flex h-full overflow-hidden",
|
|
196
|
+
children: [k > 0 && /* @__PURE__ */ m("div", {
|
|
197
|
+
className: "absolute start-3 top-3 z-10",
|
|
198
|
+
children: /* @__PURE__ */ m(o, {
|
|
199
|
+
open: M,
|
|
200
|
+
onOpenChange: Ce,
|
|
201
|
+
placement: "bottom-start",
|
|
202
|
+
matchReferenceWidth: !1,
|
|
203
|
+
renderOverlay: () => /* @__PURE__ */ h("div", {
|
|
204
|
+
className: "flex w-36 flex-col",
|
|
205
|
+
children: [/* @__PURE__ */ m("div", {
|
|
206
|
+
className: "shrink-0 p-1",
|
|
207
|
+
children: /* @__PURE__ */ m(ee, {
|
|
208
|
+
size: s.Small,
|
|
209
|
+
"aria-label": me,
|
|
210
|
+
value: X,
|
|
211
|
+
postfix: `/ ${k}`,
|
|
212
|
+
inputMode: "numeric",
|
|
213
|
+
onChange: (e) => Z(e ?? ""),
|
|
214
|
+
onBlur: () => Q(X),
|
|
215
|
+
onKeyDown: (e) => {
|
|
216
|
+
e.key === "Enter" && Q(X);
|
|
217
|
+
}
|
|
218
|
+
})
|
|
219
|
+
}), /* @__PURE__ */ h("div", {
|
|
220
|
+
ref: Ae,
|
|
221
|
+
id: O,
|
|
222
|
+
role: "region",
|
|
223
|
+
"aria-label": de,
|
|
224
|
+
onScroll: ke,
|
|
225
|
+
className: "max-h-[70vh] min-h-0 overflow-y-auto overflow-x-hidden p-1 [scrollbar-gutter:stable]",
|
|
226
|
+
children: [
|
|
227
|
+
/* @__PURE__ */ m("div", { style: { height: Ie } }),
|
|
228
|
+
$,
|
|
229
|
+
/* @__PURE__ */ m("div", { style: { height: Le } })
|
|
230
|
+
]
|
|
231
|
+
})]
|
|
232
|
+
}),
|
|
233
|
+
children: /* @__PURE__ */ m(c, {
|
|
234
|
+
icon: m(M ? ne : te, {
|
|
235
|
+
size: i.LG,
|
|
236
|
+
stroke: a,
|
|
237
|
+
"aria-hidden": !0
|
|
238
|
+
}),
|
|
239
|
+
"aria-label": M ? pe : fe,
|
|
240
|
+
"aria-expanded": M,
|
|
241
|
+
"aria-controls": M ? O : void 0
|
|
242
|
+
})
|
|
243
|
+
})
|
|
244
|
+
}), /* @__PURE__ */ m("div", {
|
|
245
|
+
ref: J,
|
|
246
|
+
className: r("min-w-0 flex-1 overflow-hidden", g.viewer),
|
|
247
|
+
children: /* @__PURE__ */ m(re, {
|
|
248
|
+
fileUrl: _,
|
|
249
|
+
loadFileCb: be,
|
|
250
|
+
highlights: b,
|
|
251
|
+
selectedHighlightId: x,
|
|
252
|
+
selectedPageNumber: S,
|
|
253
|
+
showOccurrences: !1,
|
|
254
|
+
onTotalPagesChange: Se,
|
|
255
|
+
thumbnailPageNumbers: we,
|
|
256
|
+
onThumbnailsLoaded: Me,
|
|
257
|
+
onViewerReady: Pe,
|
|
258
|
+
onCurrentPageChange: Fe,
|
|
259
|
+
viewerOptions: { enableVirtualScrolling: !0 },
|
|
260
|
+
containerClassName: ue ? "[&>div:first-child]:hidden" : void 0
|
|
261
|
+
})
|
|
262
|
+
})]
|
|
263
|
+
});
|
|
264
|
+
};
|
|
265
|
+
//#endregion
|
|
266
|
+
export { b as PdfContent };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AttachmentCanvasBody.d.ts","sourceRoot":"","sources":["../../../src/components/AttachmentCanvasBody/AttachmentCanvasBody.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AttachmentCanvasBody.d.ts","sourceRoot":"","sources":["../../../src/components/AttachmentCanvasBody/AttachmentCanvasBody.tsx"],"names":[],"mappings":"AAmBA,OAAO,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAqiBhF,uNAAuN;AACvN,eAAO,MAAM,oBAAoB,iEAAiC,CAAC"}
|
|
@@ -61,6 +61,8 @@ export interface PdfContentProps {
|
|
|
61
61
|
hideHeader?: boolean;
|
|
62
62
|
/** User-visible strings for the thumbnails section. All fields have English defaults. */
|
|
63
63
|
labels?: PdfContentLabels;
|
|
64
|
+
/** Called with the document URL when fetching the PDF blob rejects. */
|
|
65
|
+
onLoadError?: (url: string) => void;
|
|
64
66
|
}
|
|
65
67
|
/** Renders a PDF with highlight annotations, a floating collapsible thumbnails panel, and page navigation. */
|
|
66
68
|
export declare const PdfContent: FC<PdfContentProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PdfContent.d.ts","sourceRoot":"","sources":["../../../src/components/PdfContent/PdfContent.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,OAAO,EACL,KAAK,EAAE,EAQR,MAAM,OAAO,CAAC;AAgBf,OAAO,kBAAkB,CAAC;AAkF1B,mEAAmE;AACnE,MAAM,WAAW,gBAAgB;IAC/B,iGAAiG;IACjG,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gHAAgH;IAChH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,8GAA8G;IAC9G,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,0HAA0H;IAC1H,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,0GAA0G;IAC1G,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,4GAA4G;IAC5G,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6FAA6F;IAC7F,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,4CAA4C;AAC5C,MAAM,WAAW,eAAe;IAC9B,sCAAsC;IACtC,GAAG,EAAE,MAAM,CAAC;IACZ,wDAAwD;IACxD,UAAU,EAAE,kBAAkB,EAAE,CAAC;IACjC,sEAAsE;IACtE,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;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