@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.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import * as React7 from 'react';
3
3
  import { createContext, useContext, useState, useCallback, useEffect, useRef, useMemo, useId } from 'react';
4
- import { ChevronsUpDown, CheckIcon, SearchIcon, Loader2, AlertTriangle, Inbox, CircleIcon, ChevronRightIcon, Monitor, Sun, Moon, Building2, Check, Plus, Languages, FlaskConical, X, Upload, Move, ZoomOut, ZoomIn, RotateCcw, RotateCw, Grid3X3, RefreshCw, XIcon, User, Pencil, Bell, CheckCheck, XCircle, CheckCircle, Info, Trash2, Clock, MapPin, Link, CalendarDays, ExternalLink, ChevronLeft, ChevronRight, Search, CheckCircle2, Link2, HelpCircle, Circle, Wifi, WifiOff, MessageSquare, FileIcon, Download, Paperclip, Send, Store, ArrowLeft, Flag, Hash, Lightbulb, Trophy, Plane, Apple, Leaf, Hand, Smile, Play, AlertCircle, VolumeX, Pause, Volume1, Volume2, Settings, PictureInPicture2, Minimize, Maximize, CreditCard, BadgeCheck, CircleCheck, CircleDollarSign, Users } from 'lucide-react';
4
+ import { ChevronsUpDown, CheckIcon, SearchIcon, Loader2, AlertTriangle, Inbox, CircleIcon, ChevronRightIcon, Monitor, Sun, Moon, Building2, Check, Plus, Languages, FlaskConical, X, Upload, Move, ZoomOut, ZoomIn, RotateCcw, RotateCw, Grid3X3, RefreshCw, XIcon, User, Pencil, Bell, CheckCheck, XCircle, CheckCircle, Info, Trash2, Clock, MapPin, Link, CalendarDays, ExternalLink, ChevronLeft, ChevronRight, Search, CheckCircle2, Link2, HelpCircle, Circle, Wifi, WifiOff, MessageSquare, FileIcon, Paperclip, Send, Store, ArrowLeft, Flag, Hash, Lightbulb, Trophy, Plane, Apple, Leaf, Hand, Smile, Play, AlertCircle, VolumeX, Pause, Volume1, Volume2, Settings, PictureInPicture2, Minimize, Maximize, CreditCard, BadgeCheck, CircleCheck, CircleDollarSign, Users, Download } from 'lucide-react';
5
5
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
6
6
  import { useTheme } from 'next-themes';
7
7
  import { AnimatePresence, motion } from 'framer-motion';
@@ -7958,6 +7958,94 @@ function useChatRoom(roomId, config, options = {}) {
7958
7958
  isInitialLoading
7959
7959
  };
7960
7960
  }
7961
+ function AuthenticatedAttachment({
7962
+ url,
7963
+ getToken,
7964
+ fileName,
7965
+ fileSize,
7966
+ mimeType,
7967
+ formatFileSize
7968
+ }) {
7969
+ const [blobUrl, setBlobUrl] = useState(null);
7970
+ const [failed, setFailed] = useState(false);
7971
+ const isImage2 = mimeType.startsWith("image/");
7972
+ useEffect(() => {
7973
+ let cancelled = false;
7974
+ let objectUrl = null;
7975
+ void (async () => {
7976
+ try {
7977
+ const jwt = await getToken();
7978
+ if (!jwt) throw new Error("No auth token");
7979
+ const res = await fetch(url, {
7980
+ headers: { Authorization: `Bearer ${jwt}` }
7981
+ });
7982
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
7983
+ const blob = await res.blob();
7984
+ if (cancelled) return;
7985
+ objectUrl = URL.createObjectURL(blob);
7986
+ setBlobUrl(objectUrl);
7987
+ } catch {
7988
+ if (!cancelled) setFailed(true);
7989
+ }
7990
+ })();
7991
+ return () => {
7992
+ cancelled = true;
7993
+ if (objectUrl) URL.revokeObjectURL(objectUrl);
7994
+ };
7995
+ }, [url, getToken]);
7996
+ if (failed) {
7997
+ return /* @__PURE__ */ 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: [
7998
+ /* @__PURE__ */ jsx(FileIcon, { className: "h-3.5 w-3.5 flex-shrink-0" }),
7999
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: fileName })
8000
+ ] });
8001
+ }
8002
+ if (!blobUrl) {
8003
+ return /* @__PURE__ */ jsx(
8004
+ "div",
8005
+ {
8006
+ 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",
8007
+ children: /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin text-muted-foreground" })
8008
+ }
8009
+ );
8010
+ }
8011
+ if (isImage2) {
8012
+ return /* @__PURE__ */ jsx(
8013
+ "a",
8014
+ {
8015
+ href: blobUrl,
8016
+ target: "_blank",
8017
+ rel: "noopener noreferrer",
8018
+ className: "block max-w-[200px] overflow-hidden rounded-lg border",
8019
+ children: /* @__PURE__ */ jsx(
8020
+ "img",
8021
+ {
8022
+ src: blobUrl,
8023
+ alt: fileName,
8024
+ className: "h-auto w-full object-cover"
8025
+ }
8026
+ )
8027
+ }
8028
+ );
8029
+ }
8030
+ return /* @__PURE__ */ jsxs(
8031
+ "a",
8032
+ {
8033
+ href: blobUrl,
8034
+ download: fileName,
8035
+ target: "_blank",
8036
+ rel: "noopener noreferrer",
8037
+ className: "flex items-center gap-2 rounded-lg border bg-muted/50 px-2 py-1.5 text-xs transition-colors hover:bg-muted",
8038
+ children: [
8039
+ /* @__PURE__ */ jsx(FileIcon, { className: "h-3.5 w-3.5 flex-shrink-0 text-muted-foreground" }),
8040
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
8041
+ /* @__PURE__ */ jsx("p", { className: "truncate font-medium", children: fileName }),
8042
+ /* @__PURE__ */ jsx("p", { className: "text-[10px] text-muted-foreground", children: formatFileSize(fileSize) })
8043
+ ] }),
8044
+ /* @__PURE__ */ jsx(Download, { className: "h-3.5 w-3.5 flex-shrink-0 text-muted-foreground" })
8045
+ ]
8046
+ }
8047
+ );
8048
+ }
7961
8049
  var roleColors = {
7962
8050
  client: "bg-blue-500/10 text-blue-600 dark:text-blue-400",
7963
8051
  seller: "bg-emerald-500/10 text-emerald-600 dark:text-emerald-400",
@@ -8245,44 +8333,18 @@ function ChatRoomView({
8245
8333
  children: message.content
8246
8334
  }
8247
8335
  ),
8248
- message.attachments.length > 0 && /* @__PURE__ */ jsx("div", { className: "mt-1 flex flex-col gap-1", children: message.attachments.map(
8249
- (att) => att.mimeType.startsWith("image/") ? /* @__PURE__ */ jsx(
8250
- "a",
8251
- {
8252
- href: getAttachmentUrl(att.id),
8253
- target: "_blank",
8254
- rel: "noopener noreferrer",
8255
- className: "block max-w-[200px] overflow-hidden rounded-lg border",
8256
- children: /* @__PURE__ */ jsx(
8257
- "img",
8258
- {
8259
- src: getAttachmentUrl(att.id),
8260
- alt: att.fileName,
8261
- className: "h-auto w-full object-cover",
8262
- loading: "lazy"
8263
- }
8264
- )
8265
- },
8266
- att.id
8267
- ) : /* @__PURE__ */ jsxs(
8268
- "a",
8269
- {
8270
- href: getAttachmentUrl(att.id),
8271
- target: "_blank",
8272
- rel: "noopener noreferrer",
8273
- className: "flex items-center gap-2 rounded-lg border bg-muted/50 px-2 py-1.5 text-xs transition-colors hover:bg-muted",
8274
- children: [
8275
- /* @__PURE__ */ jsx(FileIcon, { className: "h-3.5 w-3.5 flex-shrink-0 text-muted-foreground" }),
8276
- /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
8277
- /* @__PURE__ */ jsx("p", { className: "truncate font-medium", children: att.fileName }),
8278
- /* @__PURE__ */ jsx("p", { className: "text-[10px] text-muted-foreground", children: formatFileSize(att.fileSize) })
8279
- ] }),
8280
- /* @__PURE__ */ jsx(Download, { className: "h-3.5 w-3.5 flex-shrink-0 text-muted-foreground" })
8281
- ]
8282
- },
8283
- att.id
8284
- )
8285
- ) }),
8336
+ message.attachments.length > 0 && /* @__PURE__ */ jsx("div", { className: "mt-1 flex flex-col gap-1", children: message.attachments.map((att) => /* @__PURE__ */ jsx(
8337
+ AuthenticatedAttachment,
8338
+ {
8339
+ url: getAttachmentUrl(att.id),
8340
+ getToken: config.getToken,
8341
+ fileName: att.fileName,
8342
+ fileSize: att.fileSize,
8343
+ mimeType: att.mimeType,
8344
+ formatFileSize
8345
+ },
8346
+ att.id
8347
+ )) }),
8286
8348
  isCurrentUser && /* @__PURE__ */ jsx("div", { className: "mt-0.5 flex items-center gap-0.5 text-[10px] text-muted-foreground", children: seen ? /* @__PURE__ */ jsxs(Fragment, { children: [
8287
8349
  /* @__PURE__ */ jsx(CheckCheck, { className: "h-3 w-3 text-primary" }),
8288
8350
  /* @__PURE__ */ jsx("span", { children: labels.seen ?? "Seen" })