@arbidocs/blocks 0.3.112 → 0.3.114

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
@@ -2,10 +2,10 @@ import { create } from 'zustand';
2
2
  import { persist } from 'zustand/middleware';
3
3
  import { createContext, useState, useEffect, useCallback, useMemo, useContext, useRef } from 'react';
4
4
  import { MessageSquare, Cpu, Code, Cloud, Layers, Target, Award, MapPin, Phone, Mail, Lock, Globe, Heart, Star, Rocket, Shield, Zap, Sparkles, Gavel, Scale, Bell, Activity, BarChart3, DollarSign, TrendingUp, Info, AlertCircle, CheckCircle, Clock, Calendar, Briefcase, Users, Folder, FileText, RotateCcw, Palette, Search, ArrowUpRight, ArrowDownRight, ImageIcon, ArrowRight, Quote, ChevronDown, XCircle, AlertTriangle, CheckCircle2, Check, ArrowLeft, Loader2, ChevronUp, BrainCircuit, Bot, LayoutGrid, FileJson, Save, Download, ImagePlus, Upload, Link2 } from 'lucide-react';
5
- import { Input, Card, CardHeader, CardTitle, CardContent, useArbi, ArbiProvider, useAiTask, useWorkspaceDocs as useWorkspaceDocs$1, useSemanticSearch as useSemanticSearch$1, cn, Table, TableHeader, TableRow, TableHead, TableBody, TableCell, Button, Avatar, AvatarImage, AvatarFallback, AiMarkdown, Badge, Switch, useConfigs, useAgents, Checkbox, Tabs as Tabs$1, TabsList, TabsTrigger, TabsContent, Separator, ArbiWebSocketProvider, useThumbnails, useDocuments } from '@arbidocs/react';
5
+ import { Input, Card, CardHeader, CardTitle, CardContent, useArbi, ArbiProvider, useAiTask, useWorkspaceDocs as useWorkspaceDocs$1, useSemanticSearch as useSemanticSearch$1, cn, Table, TableHeader, TableRow, TableHead, TableBody, TableCell, Button, Avatar, AvatarImage, AvatarFallback, AiMarkdown, Badge, Switch, useConfigs, useAgents, Checkbox, Tabs as Tabs$1, TabsList, TabsTrigger, TabsContent, Separator, ArbiWebSocketProvider, useDocuments, useThumbnails } from '@arbidocs/react';
6
6
  export { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, redlineStats, textToArtifact, toRedlineMarkdown } from '@arbidocs/react';
7
7
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
8
- import { QueryClient, QueryClientProvider, useQuery } from '@tanstack/react-query';
8
+ import { QueryClient, QueryClientProvider, useQuery, useQueryClient } from '@tanstack/react-query';
9
9
  import { AgGridReact } from 'ag-grid-react';
10
10
  import { themeQuartz, AllCommunityModule } from 'ag-grid-community';
11
11
  import { Link, useParams } from 'react-router-dom';
@@ -1450,14 +1450,35 @@ function useAssetResolverActive() {
1450
1450
  function isAssetRef(src) {
1451
1451
  return !!src && src.startsWith(ASSET_REF_PREFIX);
1452
1452
  }
1453
+ function useAssetImage(docId) {
1454
+ const arbi = useArbi();
1455
+ const { data: thumbs } = useThumbnails([docId]);
1456
+ const thumb = thumbs?.[docId];
1457
+ const { data: objectUrl } = useQuery({
1458
+ queryKey: ["arbi", "asset-image", docId],
1459
+ queryFn: async () => {
1460
+ const res = await arbi.documents.download(docId);
1461
+ const blob = await res.blob();
1462
+ return URL.createObjectURL(blob);
1463
+ },
1464
+ // Only download when the thumbnail is genuinely absent (not merely loading).
1465
+ enabled: !!docId && thumbs != null && !thumb && arbi.hasWorkspace,
1466
+ staleTime: 10 * 6e4
1467
+ });
1468
+ useEffect(() => {
1469
+ return () => {
1470
+ if (objectUrl) URL.revokeObjectURL(objectUrl);
1471
+ };
1472
+ }, [objectUrl]);
1473
+ return thumb ?? objectUrl;
1474
+ }
1453
1475
  function AssetThumb({
1454
1476
  docId,
1455
1477
  alt,
1456
1478
  className,
1457
1479
  testId
1458
1480
  }) {
1459
- const { data } = useThumbnails([docId]);
1460
- const src = data?.[docId];
1481
+ const src = useAssetImage(docId);
1461
1482
  return /* @__PURE__ */ jsx("img", { src: src ?? void 0, alt: alt ?? "", className, "data-testid": testId });
1462
1483
  }
1463
1484
  var ASPECT = {
@@ -2864,7 +2885,9 @@ function ImageFieldControl({
2864
2885
  const [busy, setBusy] = useState(false);
2865
2886
  const arbi = useArbi();
2866
2887
  const gen = useImageGen();
2888
+ const queryClient = useQueryClient();
2867
2889
  const tp = (...q) => tid(`${testIdPrefix}-image`, name, ...q);
2890
+ const refreshAssets = () => queryClient.invalidateQueries({ queryKey: ["arbi", "documents", workspaceId] });
2868
2891
  const { data: docs } = useDocuments(workspaceId);
2869
2892
  const imageDocs = useMemo(
2870
2893
  () => (docs ?? []).filter(
@@ -2885,7 +2908,10 @@ function ImageFieldControl({
2885
2908
  await arbi.selectWorkspace(workspaceId);
2886
2909
  const res = await arbi.documents.uploadFile(file, file.name, { folder });
2887
2910
  const id = res.doc_ext_ids?.[0];
2888
- if (id) onChange(asAssetRef(id));
2911
+ if (id) {
2912
+ onChange(asAssetRef(id));
2913
+ void refreshAssets();
2914
+ }
2889
2915
  } finally {
2890
2916
  setBusy(false);
2891
2917
  }
@@ -2893,7 +2919,10 @@ function ImageFieldControl({
2893
2919
  const onGenerate = async () => {
2894
2920
  if (!prompt.trim() || gen.isGenerating) return;
2895
2921
  const id = await gen.generate(prompt);
2896
- if (id) onChange(asAssetRef(id));
2922
+ if (id) {
2923
+ onChange(asAssetRef(id));
2924
+ void refreshAssets();
2925
+ }
2897
2926
  };
2898
2927
  const MODES = [
2899
2928
  { key: "asset", label: "Assets", icon: ImagePlus },