@algenium/blocks 1.21.0 → 1.22.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.
package/dist/index.cjs CHANGED
@@ -7991,6 +7991,94 @@ function useChatRoom(roomId, config, options = {}) {
7991
7991
  isInitialLoading
7992
7992
  };
7993
7993
  }
7994
+ function AuthenticatedAttachment({
7995
+ url,
7996
+ getToken,
7997
+ fileName,
7998
+ fileSize,
7999
+ mimeType,
8000
+ formatFileSize
8001
+ }) {
8002
+ const [blobUrl, setBlobUrl] = React7.useState(null);
8003
+ const [failed, setFailed] = React7.useState(false);
8004
+ const isImage2 = mimeType.startsWith("image/");
8005
+ React7.useEffect(() => {
8006
+ let cancelled = false;
8007
+ let objectUrl = null;
8008
+ void (async () => {
8009
+ try {
8010
+ const jwt = await getToken();
8011
+ if (!jwt) throw new Error("No auth token");
8012
+ const res = await fetch(url, {
8013
+ headers: { Authorization: `Bearer ${jwt}` }
8014
+ });
8015
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
8016
+ const blob = await res.blob();
8017
+ if (cancelled) return;
8018
+ objectUrl = URL.createObjectURL(blob);
8019
+ setBlobUrl(objectUrl);
8020
+ } catch {
8021
+ if (!cancelled) setFailed(true);
8022
+ }
8023
+ })();
8024
+ return () => {
8025
+ cancelled = true;
8026
+ if (objectUrl) URL.revokeObjectURL(objectUrl);
8027
+ };
8028
+ }, [url, getToken]);
8029
+ if (failed) {
8030
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 rounded-lg border border-destructive/30 bg-destructive/5 px-2 py-1.5 text-xs text-destructive", children: [
8031
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.FileIcon, { className: "h-3.5 w-3.5 flex-shrink-0" }),
8032
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: fileName })
8033
+ ] });
8034
+ }
8035
+ if (!blobUrl) {
8036
+ return /* @__PURE__ */ jsxRuntime.jsx(
8037
+ "div",
8038
+ {
8039
+ className: isImage2 ? "flex h-24 w-[200px] items-center justify-center rounded-lg border bg-muted/30" : "flex items-center gap-2 rounded-lg border bg-muted/30 px-2 py-1.5 text-xs",
8040
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "h-4 w-4 animate-spin text-muted-foreground" })
8041
+ }
8042
+ );
8043
+ }
8044
+ if (isImage2) {
8045
+ return /* @__PURE__ */ jsxRuntime.jsx(
8046
+ "a",
8047
+ {
8048
+ href: blobUrl,
8049
+ target: "_blank",
8050
+ rel: "noopener noreferrer",
8051
+ className: "block max-w-[200px] overflow-hidden rounded-lg border",
8052
+ children: /* @__PURE__ */ jsxRuntime.jsx(
8053
+ "img",
8054
+ {
8055
+ src: blobUrl,
8056
+ alt: fileName,
8057
+ className: "h-auto w-full object-cover"
8058
+ }
8059
+ )
8060
+ }
8061
+ );
8062
+ }
8063
+ return /* @__PURE__ */ jsxRuntime.jsxs(
8064
+ "a",
8065
+ {
8066
+ href: blobUrl,
8067
+ download: fileName,
8068
+ target: "_blank",
8069
+ rel: "noopener noreferrer",
8070
+ className: "flex items-center gap-2 rounded-lg border bg-muted/50 px-2 py-1.5 text-xs transition-colors hover:bg-muted",
8071
+ children: [
8072
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.FileIcon, { className: "h-3.5 w-3.5 flex-shrink-0 text-muted-foreground" }),
8073
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0 flex-1", children: [
8074
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "truncate font-medium", children: fileName }),
8075
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-[10px] text-muted-foreground", children: formatFileSize(fileSize) })
8076
+ ] }),
8077
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Download, { className: "h-3.5 w-3.5 flex-shrink-0 text-muted-foreground" })
8078
+ ]
8079
+ }
8080
+ );
8081
+ }
7994
8082
  var roleColors = {
7995
8083
  client: "bg-blue-500/10 text-blue-600 dark:text-blue-400",
7996
8084
  seller: "bg-emerald-500/10 text-emerald-600 dark:text-emerald-400",
@@ -8278,44 +8366,18 @@ function ChatRoomView({
8278
8366
  children: message.content
8279
8367
  }
8280
8368
  ),
8281
- message.attachments.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 flex flex-col gap-1", children: message.attachments.map(
8282
- (att) => att.mimeType.startsWith("image/") ? /* @__PURE__ */ jsxRuntime.jsx(
8283
- "a",
8284
- {
8285
- href: getAttachmentUrl(att.id),
8286
- target: "_blank",
8287
- rel: "noopener noreferrer",
8288
- className: "block max-w-[200px] overflow-hidden rounded-lg border",
8289
- children: /* @__PURE__ */ jsxRuntime.jsx(
8290
- "img",
8291
- {
8292
- src: getAttachmentUrl(att.id),
8293
- alt: att.fileName,
8294
- className: "h-auto w-full object-cover",
8295
- loading: "lazy"
8296
- }
8297
- )
8298
- },
8299
- att.id
8300
- ) : /* @__PURE__ */ jsxRuntime.jsxs(
8301
- "a",
8302
- {
8303
- href: getAttachmentUrl(att.id),
8304
- target: "_blank",
8305
- rel: "noopener noreferrer",
8306
- className: "flex items-center gap-2 rounded-lg border bg-muted/50 px-2 py-1.5 text-xs transition-colors hover:bg-muted",
8307
- children: [
8308
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.FileIcon, { className: "h-3.5 w-3.5 flex-shrink-0 text-muted-foreground" }),
8309
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0 flex-1", children: [
8310
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "truncate font-medium", children: att.fileName }),
8311
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-[10px] text-muted-foreground", children: formatFileSize(att.fileSize) })
8312
- ] }),
8313
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Download, { className: "h-3.5 w-3.5 flex-shrink-0 text-muted-foreground" })
8314
- ]
8315
- },
8316
- att.id
8317
- )
8318
- ) }),
8369
+ message.attachments.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 flex flex-col gap-1", children: message.attachments.map((att) => /* @__PURE__ */ jsxRuntime.jsx(
8370
+ AuthenticatedAttachment,
8371
+ {
8372
+ url: getAttachmentUrl(att.id),
8373
+ getToken: config.getToken,
8374
+ fileName: att.fileName,
8375
+ fileSize: att.fileSize,
8376
+ mimeType: att.mimeType,
8377
+ formatFileSize
8378
+ },
8379
+ att.id
8380
+ )) }),
8319
8381
  isCurrentUser && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-0.5 flex items-center gap-0.5 text-[10px] text-muted-foreground", children: seen ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
8320
8382
  /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CheckCheck, { className: "h-3 w-3 text-primary" }),
8321
8383
  /* @__PURE__ */ jsxRuntime.jsx("span", { children: labels.seen ?? "Seen" })