Text Sources
retab-ui/text-sources-blockFreeBlock
Values extracted from a log file linked to the lines they came from — hover to highlight a line range.
Install it
npx shadcn@latest add https://ui.retab.com/r/text-sources-block.jsonSource
1"use client";23import * as React from "react";45import type { Source } from "@/lib/document-source";6import {7 FileViewer,8 FileViewerContent,9 FileViewerHeader,10 FileViewerTitle,11 FileViewerProvider,12 FileViewerSidebar,13 FileViewerSidebarContent,14 FileViewerInset,15 FileViewerControls,16 FileViewerViewport,17} from "@/components/ui/file-viewer";18import { SegmentedDocumentProvider } from "@/components/ui/segmented-document-provider";19import { useSegmentedSourceFieldLink } from "@/components/ui/source-field-link";20import {21 SourceFieldList,22 type SourceField,23} from "@/components/ui/source-field-list";24import { createSourcesSegmentedDocumentModel } from "@/components/ui/source-segmented-document-model";25import {26 sourceToTextHighlight,27 useTextSourceTarget,28} from "@/components/ui/text-source";29import { TextViewer, type TextViewerHandle } from "@/components/ui/text-viewer";30import textSample from "@/components/viewers/sample-data/text-sources.json";3132const TEXT_URL = "/samples/extraction-run.log";33const TEXT_SOURCE = {34 kind: "url" as const,35 url: TEXT_URL,36 fileName: "extraction-run.log",37};3839type TextField = SourceField & { source: Source };4041const FIELDS = (textSample as TextField[]).map((field) => ({42 ...field,43 hint:44 field.source.anchor.kind === "text_span"45 ? `Line ${field.source.anchor.line_start}`46 : undefined,47}));48const FIELD_BY_KEY = new Map(FIELDS.map((field) => [field.key, field]));49const SEGMENTED_DOCUMENT = createSourcesSegmentedDocumentModel(50 FIELDS.map((field) => ({51 id: field.key,52 label: field.label,53 source: field.source,54 })),55);5657/**58 * Text sources block — values extracted from a log file, linked to the lines59 * they came from. Hovering a field highlights its line range and scrolls to it.60 * Segmented source interaction owns field preview/selection while the text61 * source adapter owns line-range scrolling and highlighting.62 */63export function TextSourcesBlock() {64 const viewerRef = React.useRef<TextViewerHandle>(null);6566 return (67 <SegmentedDocumentProvider model={SEGMENTED_DOCUMENT}>68 <TextSourcesContent viewerRef={viewerRef} />69 </SegmentedDocumentProvider>70 );71}7273function TextSourcesContent({74 viewerRef,75}: {76 viewerRef: React.RefObject<TextViewerHandle | null>;77}) {78 const target = useTextSourceTarget(viewerRef);79 const segmentedLink = useSegmentedSourceFieldLink({80 initialSourcePath: FIELDS[0]?.key,81 });82 const link = useTargetedSourceFieldLink({83// … truncated
What it pulls in
Other registry items
Files it writes
More from retab-ui
All 130 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Classify Consensusclassify-consensus-viewer-block | retab-ui | Blocks | Free | 1 dep · 4 files | |
| CSV Sourcescsv-sources-block | retab-ui | Blocks | Free | no deps · 2 files | |
| DOCX Sourcesdocx-sources-block | retab-ui | Blocks | Free | no deps · 2 files | |
| Avatar Image Slotdropzone-avatar-image-slot | retab-ui | Blocks | Free | 1 dep · 2 files | |
| Dropzonedropzone-block | retab-ui | Blocks | Free | 1 dep · 26 files | |
| Comparison Pairdropzone-comparison-pair-upload | retab-ui | Blocks | Free | 1 dep · 2 files | |
| Controlled Queuedropzone-controlled-queue | retab-ui | Blocks | Free | 1 dep · 2 files | |
| Custom Thumbnail Griddropzone-custom-thumbnail-grid | retab-ui | Blocks | Free | 1 dep · 2 files |
