@ethora/chat-component 26.7.6 → 26.7.8

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 (49) hide show
  1. package/dist/ChatProfileModal-k4_0ol-1.js +2135 -0
  2. package/dist/FilePreviewModal-BYoSZ4d1.js +743 -0
  3. package/dist/{ManageDataModal-CDPXcC93.js → ManageDataModal-Dje7zTG4.js} +68 -49
  4. package/dist/{MarkdownBody-DBJGraWM.js → MarkdownBody-Cm3GPQGA.js} +1 -1
  5. package/dist/{SideDrawer-Dr_lkaOW.js → SideDrawer-DWeOHKWM.js} +110 -66
  6. package/dist/UserProfileModal-CUcGYJb9.js +574 -0
  7. package/dist/{UserSettingsModal-OcAJao-d.js → UserSettingsModal-LWwOt5TY.js} +2 -2
  8. package/dist/{VideoCallOverlay-CC4sShdK.js → VideoCallOverlay-Dw_ydJ2K.js} +1 -1
  9. package/dist/{VisibilityModal-DkMhx_2k.js → VisibilityModal-D06gXwjS.js} +2 -2
  10. package/dist/components/MainComponents/ChatRoomOpeningPreview.d.ts +24 -0
  11. package/dist/components/MainComponents/ChatWrapper.d.ts +1 -0
  12. package/dist/components/MainComponents/ChooseChatMessage.d.ts +11 -1
  13. package/dist/components/Modals/Modal/Modal.d.ts +10 -0
  14. package/dist/components/Modals/Modal/ModalContent.d.ts +21 -0
  15. package/dist/components/Modals/ModalBox/ModalBox.d.ts +9 -0
  16. package/dist/components/Modals/ModalReportChat/ModalReportChat.d.ts +6 -1
  17. package/dist/components/Modals/ModalWrapper/ModalWrapper.d.ts +8 -0
  18. package/dist/components/Modals/SettingsModals/SharedStyledComponents.d.ts +12 -0
  19. package/dist/components/Modals/SideDrawer/DrawerProfileParts.d.ts +29 -0
  20. package/dist/components/Modals/SideDrawer/SideDrawer.d.ts +21 -1
  21. package/dist/components/Modals/SidePanel/SidePanel.d.ts +31 -0
  22. package/dist/components/Modals/UserProfileModal/EditUserModal.d.ts +5 -1
  23. package/dist/components/Modals/motionVariants.d.ts +37 -0
  24. package/dist/components/Modals/styledModalComponents.d.ts +0 -1
  25. package/dist/context/ModalTransitionContext.d.ts +2 -0
  26. package/dist/handleCopyClick-BOESIBUL.js +108 -0
  27. package/dist/helpers/buildChatShareLink.d.ts +20 -0
  28. package/dist/helpers/cacheScope.d.ts +15 -1
  29. package/dist/helpers/constants/MODAL_TYPES.d.ts +6 -4
  30. package/dist/helpers/createRoomFromApi.d.ts +1 -1
  31. package/dist/helpers/formatNumberWithCommas.d.ts +1 -1
  32. package/dist/hooks/useChatOpenPhase.d.ts +21 -0
  33. package/dist/hooks/useDelayedAction.d.ts +22 -0
  34. package/dist/hooks/useExclusiveRightPane.d.ts +25 -0
  35. package/dist/hooks/useExitTransition.d.ts +24 -0
  36. package/dist/hooks/useGetNewArchRoom.d.ts +3 -1
  37. package/dist/hooks/useQRCodeChatHandler.d.ts +29 -1
  38. package/dist/hooks/useRoomState.d.ts +2 -0
  39. package/dist/{main-B-8IhwaP.js → main-SdAeI1xI.js} +8449 -7889
  40. package/dist/main.css +1 -1
  41. package/dist/main.js +5 -5
  42. package/dist/roomStore/roomsSlice.d.ts +5 -1
  43. package/dist/styles/motion.d.ts +27 -0
  44. package/dist/types/models/room.model.d.ts +28 -0
  45. package/package.json +10 -2
  46. package/dist/ChatProfileModal-hxsWI8cx.js +0 -2139
  47. package/dist/FilePreviewModal-CwWnHsB1.js +0 -736
  48. package/dist/UserProfileModal-Q_jhXpsX.js +0 -568
  49. package/dist/handleCopyClick-CpmPa6VI.js +0 -32
@@ -1,736 +0,0 @@
1
- import { jsx as u, jsxs as B } from "react/jsx-runtime";
2
- import te, { useState as H, useRef as I, useEffect as O, useMemo as j, useCallback as M } from "react";
3
- import { n as le, b as pe, aK as we, af as ve, x as X, B as $, aL as xe, aM as be, aN as ye, aO as Ee, aP as Le, aQ as ue, aR as ne, a as Ce, u as Q, a7 as Re, aS as re, aT as Me, ar as q, aU as ke, aV as Pe, aW as Se, aX as Te, p as Ae, aY as Xe, aZ as Ye, a_ as ze, a$ as Ie, C as Oe, b0 as De, b1 as Fe, az as Ne, b2 as Be, v as He } from "./main-B-8IhwaP.js";
4
- function oe(n, i) {
5
- let o;
6
- return (...x) => {
7
- window.clearTimeout(o), o = window.setTimeout(() => n(...x), i);
8
- };
9
- }
10
- function Ue({ debounce: n, scroll: i, polyfill: o, offsetSize: x } = { debounce: 0, scroll: !1, offsetSize: !1 }) {
11
- const d = o || (typeof window > "u" ? class {
12
- } : window.ResizeObserver);
13
- if (!d) throw new Error("This browser does not support ResizeObserver out of the box. See: https://github.com/react-spring/react-use-measure/#resize-observer-polyfills");
14
- const [b, k] = H({ left: 0, top: 0, width: 0, height: 0, bottom: 0, right: 0, x: 0, y: 0 }), t = I({ element: null, scrollContainers: null, resizeObserver: null, lastBounds: b, orientationHandler: null }), P = n ? typeof n == "number" ? n : n.scroll : null, y = n ? typeof n == "number" ? n : n.resize : null, g = I(!1);
15
- O(() => (g.current = !0, () => {
16
- g.current = !1;
17
- }));
18
- const [E, p, w] = j(() => {
19
- const r = () => {
20
- if (!t.current.element) return;
21
- const { left: m, top: L, width: v, height: N, bottom: T, right: l, x: h, y: z } = t.current.element.getBoundingClientRect(), C = { left: m, top: L, width: v, height: N, bottom: T, right: l, x: h, y: z };
22
- t.current.element instanceof HTMLElement && x && (C.height = t.current.element.offsetHeight, C.width = t.current.element.offsetWidth), Object.freeze(C), g.current && !Ve(t.current.lastBounds, C) && k(t.current.lastBounds = C);
23
- };
24
- return [r, y ? oe(r, y) : r, P ? oe(r, P) : r];
25
- }, [k, x, P, y]);
26
- function S() {
27
- t.current.scrollContainers && (t.current.scrollContainers.forEach((r) => r.removeEventListener("scroll", w, !0)), t.current.scrollContainers = null), t.current.resizeObserver && (t.current.resizeObserver.disconnect(), t.current.resizeObserver = null), t.current.orientationHandler && ("orientation" in screen && "removeEventListener" in screen.orientation ? screen.orientation.removeEventListener("change", t.current.orientationHandler) : "onorientationchange" in window && window.removeEventListener("orientationchange", t.current.orientationHandler));
28
- }
29
- function Y() {
30
- t.current.element && (t.current.resizeObserver = new d(w), t.current.resizeObserver.observe(t.current.element), i && t.current.scrollContainers && t.current.scrollContainers.forEach((r) => r.addEventListener("scroll", w, { capture: !0, passive: !0 })), t.current.orientationHandler = () => {
31
- w();
32
- }, "orientation" in screen && "addEventListener" in screen.orientation ? screen.orientation.addEventListener("change", t.current.orientationHandler) : "onorientationchange" in window && window.addEventListener("orientationchange", t.current.orientationHandler));
33
- }
34
- const D = (r) => {
35
- !r || r === t.current.element || (S(), t.current.element = r, t.current.scrollContainers = de(r), Y());
36
- };
37
- return je(w, !!i), _e(p), O(() => {
38
- S(), Y();
39
- }, [i, w, p]), O(() => S, []), [D, b, E];
40
- }
41
- function _e(n) {
42
- O(() => {
43
- const i = n;
44
- return window.addEventListener("resize", i), () => {
45
- window.removeEventListener("resize", i);
46
- };
47
- }, [n]);
48
- }
49
- function je(n, i) {
50
- O(() => {
51
- if (i) {
52
- const o = n;
53
- return window.addEventListener("scroll", o, { capture: !0, passive: !0 }), () => {
54
- window.removeEventListener("scroll", o, !0);
55
- };
56
- }
57
- }, [n, i]);
58
- }
59
- function de(n) {
60
- const i = [];
61
- if (!n || n === document.body) return i;
62
- const { overflow: o, overflowX: x, overflowY: d } = window.getComputedStyle(n);
63
- return [o, x, d].some((b) => b === "auto" || b === "scroll") && i.push(n), [...i, ...de(n.parentElement)];
64
- }
65
- const $e = ["x", "y", "top", "bottom", "left", "right", "width", "height"], Ve = (n, i) => $e.every((o) => n[o] === i[o]), ie = X.div`
66
- display: flex;
67
- flex-direction: column;
68
- align-items: center;
69
- gap: 12px;
70
- width: 100%;
71
- height: 100%;
72
- overflow: auto;
73
- `, We = X.div`
74
- display: flex;
75
- align-items: flex-start;
76
- justify-content: center;
77
- width: 100%;
78
- flex: 1 1 auto;
79
- min-height: 0;
80
-
81
- canvas {
82
- max-width: 100%;
83
- height: auto;
84
- box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
85
- background-color: #fff;
86
- }
87
- `, Ze = X.div`
88
- display: flex;
89
- align-items: center;
90
- gap: 12px;
91
- flex: 0 0 auto;
92
- font-size: 14px;
93
- color: var(--ethora-color-text, #141414);
94
- `, ae = X($)`
95
- width: auto;
96
- min-width: 40px;
97
- padding: 0 12px;
98
- `, Ke = X.div`
99
- display: flex;
100
- flex-direction: column;
101
- align-items: center;
102
- gap: 12px;
103
- padding: 16px;
104
- border-radius: var(--ethora-radius-lg, 16px);
105
- background-color: var(--ethora-color-bg-subtle, #f5f7fa);
106
- color: var(--ethora-color-text, #141414);
107
- text-align: center;
108
-
109
- a {
110
- color: var(--ethora-color-primary, #0052cd);
111
- }
112
- `, Ge = ({ pdfUrl: n }) => {
113
- const i = le(), { config: o } = pe(), [x, d] = Ue(), b = I(null), k = I(null), t = I(null), [P, y] = H("loading"), [g, E] = H(0), [p, w] = H(1), S = Math.max(320, Math.floor(d.width || 0));
114
- O(() => {
115
- let r = !1, m;
116
- return y("loading"), w(1), E(0), (async () => {
117
- const L = await we(o?.pdfPreview?.workerSrc);
118
- if (!r) {
119
- if (!L || !n) {
120
- y("error");
121
- return;
122
- }
123
- try {
124
- m = L.getDocument({ url: n, isEvalSupported: !1 });
125
- const v = await m.promise;
126
- if (r) {
127
- v.destroy().catch(() => {
128
- });
129
- return;
130
- }
131
- k.current = v, E(v.numPages), y("ready");
132
- } catch (v) {
133
- r || (console.warn("[Ethora] PDF open failed:", v), y("error"));
134
- }
135
- }
136
- })(), () => {
137
- r = !0, t.current?.cancel(), t.current = null, k.current?.destroy?.().catch(() => {
138
- }), k.current = null, m?.destroy?.().catch(() => {
139
- });
140
- };
141
- }, [n, o?.pdfPreview?.workerSrc]), O(() => {
142
- const r = k.current, m = b.current;
143
- if (P !== "ready" || !r || !m || S <= 0) return;
144
- let L = !1;
145
- return (async () => {
146
- try {
147
- const v = await r.getPage(p);
148
- if (L) return;
149
- const N = v.getViewport({ scale: 1 }), T = N.width ? S / N.width : 1, l = v.getViewport({ scale: T });
150
- m.width = Math.max(1, Math.floor(l.width)), m.height = Math.max(1, Math.floor(l.height));
151
- const h = m.getContext("2d");
152
- if (!h) {
153
- y("error");
154
- return;
155
- }
156
- t.current?.cancel();
157
- const z = v.render({ canvasContext: h, viewport: l });
158
- t.current = z, await z.promise, v.cleanup();
159
- } catch (v) {
160
- L || console.warn("[Ethora] PDF page render failed:", v);
161
- }
162
- })(), () => {
163
- L = !0, t.current?.cancel(), t.current = null;
164
- };
165
- }, [P, p, S]);
166
- const Y = M(
167
- () => w((r) => Math.max(1, r - 1)),
168
- []
169
- ), D = M(
170
- () => w((r) => Math.min(g || 1, r + 1)),
171
- [g]
172
- );
173
- return P === "error" ? /* @__PURE__ */ u(ie, { children: /* @__PURE__ */ B(Ke, { children: [
174
- /* @__PURE__ */ u("span", { children: i("modal.filePreview.pdfUnavailable") }),
175
- /* @__PURE__ */ u("a", { href: n, target: "_blank", rel: "noopener noreferrer", children: i("modal.filePreview.openExternally") })
176
- ] }) }) : /* @__PURE__ */ B(ie, { children: [
177
- /* @__PURE__ */ u(We, { ref: x, children: P === "loading" ? /* @__PURE__ */ u(ve, { color: o?.colors?.primary }) : /* @__PURE__ */ u("canvas", { ref: b }) }),
178
- g > 1 && /* @__PURE__ */ B(Ze, { children: [
179
- /* @__PURE__ */ u(
180
- ae,
181
- {
182
- onClick: Y,
183
- disabled: p <= 1,
184
- text: "‹",
185
- "aria-label": i("modal.filePreview.previousPage")
186
- }
187
- ),
188
- /* @__PURE__ */ B("span", { children: [
189
- p,
190
- " / ",
191
- g
192
- ] }),
193
- /* @__PURE__ */ u(
194
- ae,
195
- {
196
- onClick: D,
197
- disabled: p >= g,
198
- text: "›",
199
- "aria-label": i("modal.filePreview.nextPage")
200
- }
201
- )
202
- ] })
203
- ] });
204
- }, A = 1, J = 6, Qe = 2.5, qe = 50, Je = 300, se = 24, et = 16e-4, K = (n, i, o) => Math.min(o, Math.max(i, n)), tt = X.div`
205
- position: relative;
206
- /* An explicit height, not flex growth alone: the parent lays its children
207
- out in a row and centres them, so the viewport would otherwise be sized
208
- by its content, and the image's own max-height of 100% would resolve
209
- against that auto height and never fit anything. */
210
- flex: 1 1 auto;
211
- width: 100%;
212
- height: 100%;
213
- min-height: 0;
214
- display: flex;
215
- align-items: center;
216
- justify-content: center;
217
- overflow: hidden;
218
- /* A zoomed image is dragged, not selected, and a two-finger gesture is a
219
- pinch rather than a page scroll. */
220
- touch-action: none;
221
- user-select: none;
222
- background-color: var(--ethora-color-bg, #fff);
223
- `, nt = X.img`
224
- /* Same box the single-file view always used: fill the stage and let
225
- object-fit do the letterboxing, so what the viewer sees at scale 1 is
226
- unchanged. It is also what makes the pan clamp exact, since the painted
227
- content box is then derived from the natural aspect ratio alone. */
228
- width: 100%;
229
- height: 100%;
230
- object-fit: contain;
231
- transform-origin: center center;
232
- will-change: transform;
233
- cursor: ${({ $grabbing: n, $pannable: i }) => n ? "grabbing" : i ? "grab" : "zoom-in"};
234
- transition: ${({ $animate: n }) => n ? `transform ${xe} ${be}` : "none"};
235
- ${ye}
236
- `, fe = te.forwardRef(
237
- ({ src: n, alt: i, onSwipeLeft: o, onSwipeRight: x, onError: d, onScaleChange: b }, k) => {
238
- const t = I(null), P = I(null), [y, g] = H(A), [E, p] = H({ x: 0, y: 0 }), [w, S] = H(!1), [Y, D] = H(!1), r = I({ scale: A, offset: { x: 0, y: 0 } });
239
- r.current = { scale: y, offset: E };
240
- const m = I(null), L = I(null), v = I(
241
- null
242
- ), N = M((a) => {
243
- const e = t.current, c = P.current;
244
- if (!e) return { x: 0, y: 0 };
245
- const s = e.clientWidth, f = e.clientHeight, R = c?.naturalWidth || 0, F = c?.naturalHeight || 0;
246
- let _ = s, W = f;
247
- if (R > 0 && F > 0 && s > 0 && f > 0) {
248
- const Z = Math.min(s / R, f / F);
249
- _ = R * Z, W = F * Z;
250
- }
251
- return {
252
- x: Math.max(0, (_ * a - s) / 2),
253
- y: Math.max(0, (W * a - f) / 2)
254
- };
255
- }, []), T = M(
256
- (a, e, c) => {
257
- const s = K(a, A, J), f = N(s);
258
- S(c), g(s), p({
259
- x: K(e.x, -f.x, f.x),
260
- y: K(e.y, -f.y, f.y)
261
- });
262
- },
263
- [N]
264
- ), l = M(
265
- (a, e, c, s) => {
266
- const f = r.current, R = K(a, A, J), F = R / f.scale;
267
- T(
268
- R,
269
- {
270
- x: e - (e - f.offset.x) * F,
271
- y: c - (c - f.offset.y) * F
272
- },
273
- s
274
- );
275
- },
276
- [T]
277
- ), h = M(() => {
278
- T(A, { x: 0, y: 0 }, !0);
279
- }, [T]), z = M(
280
- (a) => {
281
- l(r.current.scale * a, 0, 0, !0);
282
- },
283
- [l]
284
- );
285
- te.useImperativeHandle(
286
- k,
287
- () => ({
288
- zoomIn: () => z(1.5),
289
- zoomOut: () => z(1 / 1.5),
290
- reset: h
291
- }),
292
- [z, h]
293
- ), O(() => {
294
- S(!1), g(A), p({ x: 0, y: 0 });
295
- }, [n]), O(() => {
296
- b?.(y);
297
- }, [y, b]), O(() => {
298
- const a = t.current;
299
- if (!a) return;
300
- const e = (c) => {
301
- c.preventDefault();
302
- const s = a.getBoundingClientRect(), f = c.clientX - s.left - s.width / 2, R = c.clientY - s.top - s.height / 2, F = Math.exp(-c.deltaY * et);
303
- l(r.current.scale * F, f, R, !1);
304
- };
305
- return a.addEventListener("wheel", e, { passive: !1 }), () => a.removeEventListener("wheel", e);
306
- }, [l]);
307
- const C = M(
308
- (a, e) => {
309
- const c = t.current;
310
- if (!c) return;
311
- if (r.current.scale > A) {
312
- h();
313
- return;
314
- }
315
- const s = c.getBoundingClientRect();
316
- l(
317
- Qe,
318
- a - s.left - s.width / 2,
319
- e - s.top - s.height / 2,
320
- !0
321
- );
322
- },
323
- [h, l]
324
- ), G = M((a) => {
325
- a.button === 0 && (r.current.scale <= A || (a.preventDefault(), m.current = { x: a.clientX, y: a.clientY }, D(!0)));
326
- }, []);
327
- O(() => {
328
- if (!Y || typeof window > "u") return;
329
- const a = (c) => {
330
- const s = m.current;
331
- if (!s) return;
332
- const f = r.current;
333
- T(
334
- f.scale,
335
- {
336
- x: f.offset.x + (c.clientX - s.x),
337
- y: f.offset.y + (c.clientY - s.y)
338
- },
339
- !1
340
- ), m.current = { x: c.clientX, y: c.clientY };
341
- }, e = () => {
342
- m.current = null, D(!1);
343
- };
344
- return window.addEventListener("mousemove", a), window.addEventListener("mouseup", e), () => {
345
- window.removeEventListener("mousemove", a), window.removeEventListener("mouseup", e);
346
- };
347
- }, [Y, T]);
348
- const V = M((a) => {
349
- if (a.touches.length === 2) {
350
- const [c, s] = [a.touches[0], a.touches[1]];
351
- L.current = {
352
- startX: 0,
353
- startY: 0,
354
- lastX: 0,
355
- lastY: 0,
356
- pinchDistance: Math.hypot(
357
- c.clientX - s.clientX,
358
- c.clientY - s.clientY
359
- ),
360
- pinchScale: r.current.scale,
361
- panning: !1,
362
- moved: !1
363
- };
364
- return;
365
- }
366
- const e = a.touches[0];
367
- e && (L.current = {
368
- startX: e.clientX,
369
- startY: e.clientY,
370
- lastX: e.clientX,
371
- lastY: e.clientY,
372
- pinchDistance: 0,
373
- pinchScale: r.current.scale,
374
- panning: r.current.scale > A,
375
- moved: !1
376
- });
377
- }, []), U = M(
378
- (a) => {
379
- const e = L.current;
380
- if (!e) return;
381
- if (a.touches.length === 2 && e.pinchDistance > 0) {
382
- const [s, f] = [a.touches[0], a.touches[1]], R = Math.hypot(
383
- s.clientX - f.clientX,
384
- s.clientY - f.clientY
385
- ), F = t.current;
386
- if (!F || R <= 0) return;
387
- const _ = F.getBoundingClientRect(), W = (s.clientX + f.clientX) / 2 - _.left - _.width / 2, Z = (s.clientY + f.clientY) / 2 - _.top - _.height / 2;
388
- e.moved = !0, l(
389
- e.pinchScale * R / e.pinchDistance,
390
- W,
391
- Z,
392
- !1
393
- );
394
- return;
395
- }
396
- const c = a.touches[0];
397
- if (c) {
398
- if ((Math.abs(c.clientX - e.startX) > 6 || Math.abs(c.clientY - e.startY) > 6) && (e.moved = !0), e.panning) {
399
- const s = r.current;
400
- T(
401
- s.scale,
402
- {
403
- x: s.offset.x + (c.clientX - e.lastX),
404
- y: s.offset.y + (c.clientY - e.lastY)
405
- },
406
- !1
407
- );
408
- }
409
- e.lastX = c.clientX, e.lastY = c.clientY;
410
- }
411
- },
412
- [T, l]
413
- ), ee = M(
414
- (a) => {
415
- const e = L.current;
416
- if (!e || a.touches.length > 0) return;
417
- if (L.current = null, !e.moved && e.pinchDistance === 0) {
418
- const f = Date.now(), R = v.current;
419
- if (R && f - R.time < Je && Math.abs(R.x - e.startX) < se && Math.abs(R.y - e.startY) < se) {
420
- v.current = null, C(e.startX, e.startY);
421
- return;
422
- }
423
- v.current = {
424
- time: f,
425
- x: e.startX,
426
- y: e.startY
427
- };
428
- return;
429
- }
430
- if (e.panning || e.pinchDistance > 0 || r.current.scale > A) return;
431
- const c = e.lastX - e.startX, s = e.lastY - e.startY;
432
- Math.abs(c) < qe || Math.abs(c) <= Math.abs(s) || (c < 0 ? o?.() : x?.());
433
- },
434
- [o, x, C]
435
- ), me = M(
436
- (a) => {
437
- C(a.clientX, a.clientY);
438
- },
439
- [C]
440
- ), ge = j(
441
- () => `translate(${E.x}px, ${E.y}px) scale(${y})`,
442
- [E.x, E.y, y]
443
- );
444
- return /* @__PURE__ */ u(
445
- tt,
446
- {
447
- ref: t,
448
- "data-testid": "image-lightbox-viewport",
449
- onMouseDown: G,
450
- onDoubleClick: me,
451
- onTouchStart: V,
452
- onTouchMove: U,
453
- onTouchEnd: ee,
454
- onTouchCancel: ee,
455
- children: /* @__PURE__ */ u(
456
- nt,
457
- {
458
- ref: P,
459
- "data-testid": "image-lightbox-image",
460
- src: n,
461
- alt: i,
462
- draggable: !1,
463
- onError: d,
464
- $grabbing: Y,
465
- $pannable: y > A,
466
- $animate: w,
467
- style: { transform: ge }
468
- }
469
- )
470
- }
471
- );
472
- }
473
- );
474
- fe.displayName = "ImageLightbox";
475
- const rt = (n) => {
476
- if (!Array.isArray(n)) return [];
477
- const i = [];
478
- return n.forEach((o, x) => {
479
- !o || o.isDeleted || o.id !== "delimiter-new" && Ee(o).forEach((d, b) => {
480
- if (!d.location) return;
481
- const k = Le(d);
482
- ue(d.mimetype, k) === "image" && i.push({
483
- key: `${o.id ?? x}:${b}`,
484
- fileName: k,
485
- fileURL: d.location,
486
- mimetype: d.mimetype || ""
487
- });
488
- });
489
- }), i;
490
- }, ot = (n, i) => {
491
- if (!i?.fileURL) return -1;
492
- const o = ne(i.fileURL);
493
- return n.findIndex(
494
- (x) => ne(x.fileURL) === o
495
- );
496
- }, ce = "https://as2.ftcdn.net/v2/jpg/02/51/95/53/1000_F_251955356_FAQH0U1y1TZw3ZcdPGybwUkH90a3VAhb.jpg", it = X.div`
497
- position: relative;
498
- display: flex;
499
- flex: 1 1 auto;
500
- width: 100%;
501
- min-height: 0;
502
- align-items: center;
503
- justify-content: center;
504
- overflow: hidden;
505
- `, he = X($)`
506
- position: absolute;
507
- top: 50%;
508
- transform: translateY(-50%);
509
- width: 44px;
510
- height: 44px;
511
- border-radius: var(--ethora-radius-full, 999px);
512
- background-color: var(--ethora-color-bg, #fff);
513
- box-shadow: var(--ethora-shadow-md, 0 4px 12px rgba(16, 24, 40, 0.1));
514
- z-index: 2;
515
- `, at = X(he)`
516
- left: 8px;
517
- `, st = X(he)`
518
- right: 8px;
519
- `, ct = X.div`
520
- display: flex;
521
- align-items: center;
522
- gap: 8px;
523
- `, lt = X.div`
524
- display: flex;
525
- align-items: center;
526
- gap: 8px;
527
-
528
- @media (max-width: 480px) {
529
- display: none;
530
- }
531
- `, ut = X.span`
532
- font-size: var(--ethora-font-size-sm, 14px);
533
- color: var(--ethora-color-text-secondary, #5a5f66);
534
- white-space: nowrap;
535
- padding: 0 4px;
536
- `, mt = ({
537
- handleCloseModal: n
538
- }) => {
539
- const i = Ce(), o = le(), { activeFile: x } = Q(
540
- (l) => l.chatSettingStore
541
- ), d = j(
542
- () => x ?? { fileName: "", fileURL: "", mimetype: "" },
543
- [x]
544
- ), b = Q(
545
- (l) => l.chatSettingStore.user?.fileToken || ""
546
- ), k = Q(
547
- (l) => Re(l)?.messages
548
- ), t = I(null), [P, y] = H(A), g = ue(d?.mimetype, d?.fileName), E = j(() => rt(k), [k]), p = j(
549
- () => g === "image" ? ot(E, d) : -1,
550
- [E, d, g]
551
- ), w = p >= 0 && E.length > 1, S = w && p > 0, Y = w && p < E.length - 1, D = M(
552
- (l) => {
553
- const h = E[l];
554
- h && i(
555
- re({
556
- fileName: h.fileName,
557
- fileURL: h.fileURL,
558
- mimetype: h.mimetype
559
- })
560
- );
561
- },
562
- [i, E]
563
- ), r = M(() => {
564
- S && D(p - 1);
565
- }, [D, S, p]), m = M(() => {
566
- Y && D(p + 1);
567
- }, [D, Y, p]);
568
- O(() => {
569
- if (!w || typeof document > "u") return;
570
- const l = (h) => {
571
- if (h.key !== "ArrowLeft" && h.key !== "ArrowRight" || h.defaultPrevented || h.altKey || h.ctrlKey || h.metaKey) return;
572
- const z = h.target, C = z?.tagName;
573
- C === "INPUT" || C === "TEXTAREA" || C === "SELECT" || z?.isContentEditable || (h.preventDefault(), h.key === "ArrowLeft" ? r() : m());
574
- };
575
- return document.addEventListener("keydown", l), () => document.removeEventListener("keydown", l);
576
- }, [w, r, m]);
577
- const L = () => {
578
- fetch(Ne(d.fileURL), {
579
- method: "GET",
580
- headers: {}
581
- }).then((l) => {
582
- const C = !!Be(d.fileName) ? d.fileName : `MEDIA-ETHORA.${g === "image" ? "png" : g === "video" ? "mp4" : "bin"}`;
583
- l.arrayBuffer().then(function(G) {
584
- if (typeof window > "u")
585
- return;
586
- const V = window.URL.createObjectURL(new Blob([G])), U = document.createElement("a");
587
- U.href = V, U.setAttribute("download", C), document.body.appendChild(U), U.click(), U.remove(), window.URL.revokeObjectURL(V);
588
- });
589
- }).catch((l) => {
590
- He.log(l);
591
- });
592
- }, v = () => {
593
- i(re(void 0)), n?.();
594
- }, N = d?.fileName || o("modal.filePreview.imageAlt"), T = j(() => {
595
- switch (g) {
596
- case "image":
597
- return /* @__PURE__ */ u(
598
- fe,
599
- {
600
- ref: t,
601
- src: q(d.fileURL, b) || ce,
602
- alt: N,
603
- onScaleChange: y,
604
- onSwipeLeft: m,
605
- onSwipeRight: r,
606
- onError: (l) => {
607
- Pe(d.fileURL) && Se(), l.target.src = ce;
608
- }
609
- }
610
- );
611
- case "video":
612
- return /* @__PURE__ */ u(
613
- ke,
614
- {
615
- src: q(d.fileURL, b),
616
- controls: !0,
617
- autoPlay: !1
618
- }
619
- );
620
- case "pdf":
621
- return /* @__PURE__ */ u(Ge, { pdfUrl: q(d.fileURL, b) });
622
- default:
623
- return /* @__PURE__ */ B(
624
- "div",
625
- {
626
- style: {
627
- display: "flex",
628
- flexDirection: "column",
629
- justifyContent: "center",
630
- alignItems: "center"
631
- },
632
- children: [
633
- /* @__PURE__ */ u(Me, { style: { minWidth: "100px", minHeight: "100px" } }),
634
- /* @__PURE__ */ u(
635
- "div",
636
- {
637
- style: {
638
- backgroundColor: "var(--ethora-color-bg-subtle, #F5F7FA)",
639
- borderRadius: "var(--ethora-radius-lg, 16px)",
640
- display: "flex",
641
- padding: "16px",
642
- color: "var(--ethora-color-text, #141414)"
643
- },
644
- children: o("modal.filePreview.unsupported")
645
- }
646
- )
647
- ]
648
- }
649
- );
650
- }
651
- }, [d, b, N, g, m, r, o]);
652
- return /* @__PURE__ */ B(Te, { "aria-label": o("modal.filePreview.title"), children: [
653
- /* @__PURE__ */ u(
654
- Ae,
655
- {
656
- handleCloseModal: v,
657
- headerTitle: o("modal.filePreview.title"),
658
- rightMenu: /* @__PURE__ */ B(ct, { children: [
659
- w && /* @__PURE__ */ u(ut, { "data-testid": "lightbox-position", "aria-live": "polite", children: o("modal.filePreview.position", {
660
- current: p + 1,
661
- total: E.length
662
- }) }),
663
- g === "image" && /* @__PURE__ */ B(lt, { children: [
664
- /* @__PURE__ */ u(
665
- $,
666
- {
667
- onClick: () => t.current?.zoomOut(),
668
- disabled: P <= A,
669
- "aria-label": o("modal.filePreview.zoomOut"),
670
- children: /* @__PURE__ */ u(Xe, {})
671
- }
672
- ),
673
- /* @__PURE__ */ u(
674
- $,
675
- {
676
- onClick: () => t.current?.zoomIn(),
677
- disabled: P >= J,
678
- "aria-label": o("modal.filePreview.zoomIn"),
679
- children: /* @__PURE__ */ u(Ye, {})
680
- }
681
- ),
682
- /* @__PURE__ */ u(
683
- $,
684
- {
685
- onClick: () => t.current?.reset(),
686
- disabled: P <= A,
687
- "aria-label": o("modal.filePreview.resetZoom"),
688
- children: /* @__PURE__ */ u(ze, {})
689
- }
690
- )
691
- ] }),
692
- /* @__PURE__ */ u($, { onClick: L, "aria-label": o("action.save"), children: /* @__PURE__ */ u(Ie, {}) })
693
- ] })
694
- }
695
- ),
696
- /* @__PURE__ */ u(
697
- Oe,
698
- {
699
- style: {
700
- display: "flex",
701
- flex: "1 1 auto",
702
- height: "100%",
703
- minHeight: 0,
704
- justifyContent: "center",
705
- overflow: "hidden",
706
- padding: "16px",
707
- width: "90%"
708
- },
709
- children: /* @__PURE__ */ B(it, { children: [
710
- w && /* @__PURE__ */ u(
711
- at,
712
- {
713
- onClick: r,
714
- disabled: !S,
715
- "aria-label": o("modal.filePreview.previousImage"),
716
- children: /* @__PURE__ */ u(De, {})
717
- }
718
- ),
719
- T,
720
- w && /* @__PURE__ */ u(
721
- st,
722
- {
723
- onClick: m,
724
- disabled: !Y,
725
- "aria-label": o("modal.filePreview.nextImage"),
726
- children: /* @__PURE__ */ u(Fe, {})
727
- }
728
- )
729
- ] })
730
- }
731
- )
732
- ] });
733
- };
734
- export {
735
- mt as default
736
- };