@arbidocs/react 0.5.42 → 0.5.44

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/ui/index.js CHANGED
@@ -1,8 +1,8 @@
1
- export { ARBI_MARK_SRC, AgentBadge, AiMarkdown, ArbiIcon, BASE_COLORS, Badge, COLUMN_LABEL_FALLBACKS, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, Collapsible, CollapsibleContent, CollapsibleTrigger, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, DEFAULT_METADATA_TAGS, DebouncedInput, DocumentCard, DocumentEntity, ENTITY_MAPPINGS, EntityIcon, EntityPill, HoverCard, HoverCardContent, HoverCardTrigger, IconToggle, Input, Label, MarkMenu, NEUTRAL_GRAY, PLACEHOLDER_COLOR, PassageCard, Popover, PopoverAnchor, PopoverClose, PopoverContent, PopoverTrigger, PresenceLabel, Progress, ProjectEntity, ProviderIcon, RadioGroup, RadioGroupItem, RagDot, RelevanceDot, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, ShieldIcon, Slider, StatusPill, Switch, TAG_TYPE_ICONS, TAG_TYPE_LABELS, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, TagEntity, Textarea, ThreadVisibilityIcon, Toggle, ToggleGroup, ToggleGroupItem, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, UserEntity, UserMenu, VISIBILITY_ICONS, VerifiedBadge, VerifiedToggle, VisibilityIcon, VisibilityToggle, agentAvatarColors, badgeVariants, buildFolderTree, canonicalFolderPath, cardVariants, configureEntityRegistry, configureRagLabels, configureStatusRegistry, entityNoun, extensionFromMime, formatDocDate, formatFolderLabel, formatFriendlyDate, friendlyFileType, getDocIcon, getDocumentAuthor, getDocumentDate, getDocumentNature, getDocumentSubject, getDocumentTitle, getEntityColor, getEntityColorStyles, getEntityIcon, getEntityLabel, getFileExtension, getFileTypeIcon, getStatusVariant, getTagTypeIcon, getTagTypeLabel, getWorkspaceColor, isAudioFile, isDocumentAddableToConversation, isDownloadOnlyFile, isImageDocument, isImageFile, isMediaFile, isVideoFile, markdownToPlainText, markdownToPlainTextBlocks, tagKindNouns, tagKindTitle, toggleVariants, useDictateContext, usesOriginalBytesForViewer } from '../chunk-KUGZXI7V.js';
1
+ export { ARBI_MARK_SRC, AgentBadge, AiMarkdown, ArbiIcon, BASE_COLORS, Badge, COLUMN_LABEL_FALLBACKS, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, Collapsible, CollapsibleContent, CollapsibleTrigger, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, DEFAULT_METADATA_TAGS, DebouncedInput, DocumentCard, DocumentEntity, ENTITY_MAPPINGS, EntityIcon, EntityPill, HoverCard, HoverCardContent, HoverCardTrigger, IconToggle, Input, Label, MarkMenu, NEUTRAL_GRAY, PLACEHOLDER_COLOR, PassageCard, Popover, PopoverAnchor, PopoverClose, PopoverContent, PopoverTrigger, PresenceLabel, Progress, ProjectEntity, ProviderIcon, RadioGroup, RadioGroupItem, RagDot, RelevanceDot, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, ShieldIcon, Slider, StatusPill, Switch, TAG_TYPE_ICONS, TAG_TYPE_LABELS, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, TagEntity, Textarea, ThreadVisibilityIcon, Toggle, ToggleGroup, ToggleGroupItem, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, UserEntity, UserMenu, VISIBILITY_ICONS, VerifiedBadge, VerifiedToggle, VisibilityIcon, VisibilityToggle, agentAvatarColors, badgeVariants, buildFolderTree, canonicalFolderPath, cardVariants, configureEntityRegistry, configureRagLabels, configureStatusRegistry, entityNoun, extensionFromMime, formatDocDate, formatFolderLabel, formatFriendlyDate, friendlyFileType, getDocIcon, getDocumentAuthor, getDocumentDate, getDocumentNature, getDocumentSubject, getDocumentTitle, getEntityColor, getEntityColorStyles, getEntityIcon, getEntityLabel, getFileExtension, getFileTypeIcon, getStatusVariant, getTagTypeIcon, getTagTypeLabel, getWorkspaceColor, isAudioFile, isDocumentAddableToConversation, isDownloadOnlyFile, isImageDocument, isImageFile, isMediaFile, isVideoFile, markdownToPlainText, markdownToPlainTextBlocks, tagKindNouns, tagKindTitle, toggleVariants, useDictateContext, usesOriginalBytesForViewer } from '../chunk-CE4RY7VA.js';
2
2
  export { Avatar, AvatarFallback, AvatarImage, createUserAvatarIcon, getUserAvatarColor, getUserDisplayName, getUserInitials, isAgent } from '../chunk-APZZQZ6P.js';
3
3
  export { MarkdownCode, MarkdownLink, MarkdownRenderer, MarkdownStreamingContext, markdownBaseComponents, markdownSanitizeSchema, splitMarkdownBlocks } from '../chunk-C44GO33B.js';
4
- export { Button, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, buttonVariants } from '../chunk-YNNAJJ5Z.js';
5
4
  export { ScrollArea, ScrollBar, configureEntityVocabulary, formatRelativeTime } from '../chunk-Y3MTRA7D.js';
5
+ export { Button, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, buttonVariants } from '../chunk-YNNAJJ5Z.js';
6
6
  export { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, PortalContainerProvider, usePortalContainer } from '../chunk-47CCGUWR.js';
7
7
  export { closeOpenEmphasis, trimOpenCitation } from '../chunk-QRCMKEE6.js';
8
8
  export { cn } from '../chunk-SN5YV6FF.js';
@@ -335,6 +335,13 @@ function PdfViewer({
335
335
  ])
336
336
  );
337
337
  const [visiblePages, setVisiblePages] = react.useState(/* @__PURE__ */ new Set([initialPage]));
338
+ const loadLifetime = react.useMemo(() => ({ file, active: true }), [file]);
339
+ react.useEffect(() => {
340
+ loadLifetime.active = true;
341
+ return () => {
342
+ loadLifetime.active = false;
343
+ };
344
+ }, [loadLifetime]);
338
345
  react.useEffect(() => {
339
346
  setDocumentKey(`pdf-${Date.now()}`);
340
347
  setNumPages(0);
@@ -344,35 +351,50 @@ function PdfViewer({
344
351
  const pageRefs = react.useRef(/* @__PURE__ */ new Map());
345
352
  const onDocumentLoadSuccess = react.useCallback(
346
353
  (pdf) => {
354
+ if (!loadLifetime.active) return;
347
355
  const n = pdf.numPages;
348
- void pdf.getPage?.(1).then((page) => setDefaultRatio(ratioOf(page))).catch(() => {
356
+ void pdf.getPage?.(1).then((page) => {
357
+ if (loadLifetime.active) setDefaultRatio(ratioOf(page));
358
+ }).catch(() => {
349
359
  });
350
360
  setNumPages(n);
351
361
  setLoadError(null);
352
- const expand = () => {
353
- setRenderedPages((prev) => {
354
- if (prev.size === 0) return prev;
355
- const newSet = new Set(prev);
356
- const anchor = currentPage || 1;
357
- for (let i = Math.max(1, anchor - LAZY_LOAD_BUFFER_BEFORE); i <= Math.min(n, anchor + LAZY_LOAD_BUFFER_AFTER); i++) {
358
- newSet.add(i);
359
- }
360
- return newSet;
361
- });
362
- };
363
- if (typeof requestIdleCallback !== "undefined") {
364
- requestIdleCallback(expand, { timeout: 500 });
365
- } else {
366
- setTimeout(expand, 500);
367
- }
368
362
  try {
369
363
  onLoadSuccess?.(n);
370
364
  } catch (error) {
371
365
  console.error("Error in onLoadSuccess callback:", error);
372
366
  }
373
367
  },
374
- [onLoadSuccess, currentPage]
368
+ [onLoadSuccess, loadLifetime]
375
369
  );
370
+ react.useEffect(() => {
371
+ if (numPages === 0) return;
372
+ let cancelled = false;
373
+ const expand = () => {
374
+ if (cancelled || !loadLifetime.active) return;
375
+ setRenderedPages((prev) => {
376
+ if (prev.size === 0) return prev;
377
+ const newSet = new Set(prev);
378
+ const anchor = currentPage || 1;
379
+ for (let i = Math.max(1, anchor - LAZY_LOAD_BUFFER_BEFORE); i <= Math.min(numPages, anchor + LAZY_LOAD_BUFFER_AFTER); i++) {
380
+ newSet.add(i);
381
+ }
382
+ return newSet;
383
+ });
384
+ };
385
+ if (typeof requestIdleCallback !== "undefined") {
386
+ const handle2 = requestIdleCallback(expand, { timeout: 500 });
387
+ return () => {
388
+ cancelled = true;
389
+ if (typeof cancelIdleCallback !== "undefined") cancelIdleCallback(handle2);
390
+ };
391
+ }
392
+ const handle = setTimeout(expand, 500);
393
+ return () => {
394
+ cancelled = true;
395
+ clearTimeout(handle);
396
+ };
397
+ }, [numPages, currentPage, loadLifetime]);
376
398
  const onDocumentLoadError = react.useCallback((error) => {
377
399
  console.error("PDF loading error:", error);
378
400
  setLoadError(error);