CSV Sources
retab-ui/csv-sources-blockFreeBlock
Extracted values linked to spreadsheet cells — hover to highlight a cell and scroll to it.
Install it
npx shadcn@latest add https://ui.retab.com/r/csv-sources-block.jsonSource
1"use client";23import * as React from "react";45import type { Source } from "@/lib/document-source";6import {7 sourceToCsvCell,8 useCsvSourceTarget,9} from "@/components/ui/csv-source";10import {11 CsvViewerDocument,12 type CsvViewerHandle,13} from "@/components/ui/csv-viewer";14import {15 FileViewer,16 FileViewerContent,17 FileViewerHeader,18 FileViewerTitle,19 FileViewerProvider,20 FileViewerSidebar,21 FileViewerSidebarContent,22 FileViewerInset,23 FileViewerControls,24 FileViewerViewport,25} from "@/components/ui/file-viewer";26import { SegmentedDocumentProvider } from "@/components/ui/segmented-document-provider";27import { useSegmentedSourceFieldLink } from "@/components/ui/source-field-link";28import {29 SourceFieldList,30 type SourceField,31} from "@/components/ui/source-field-list";32import { createSourcesSegmentedDocumentModel } from "@/components/ui/source-segmented-document-model";33import csvSample from "@/components/viewers/sample-data/csv-sources.json";3435const CSV_TEXT = `region,quarter,revenue,customers,nrr36North America,Q1,1240000,48,1.1237North America,Q2,1510000,61,1.2138EMEA,Q1,820000,33,1.0839EMEA,Q2,910000,39,1.1540APAC,Q1,430000,18,1.0441APAC,Q2,560000,24,1.11`;42const CSV_SOURCE = {43 kind: "text" as const,44 text: CSV_TEXT,45 fileName: "sales.csv",46};4748type CsvField = SourceField & { source: Source };4950const FIELDS = (csvSample as CsvField[]).map((field) => ({51 ...field,52 hint:53 field.source.anchor.kind === "csv_cell"54 ? `Cell ${field.source.anchor.coordinate ?? field.source.anchor.column}`55 : undefined,56}));57const FIELD_BY_KEY = new Map(FIELDS.map((field) => [field.key, field]));58const SEGMENTED_DOCUMENT = createSourcesSegmentedDocumentModel(59 FIELDS.map((field) => ({60 id: field.key,61 label: field.label,62 source: field.source,63 })),64);6566/**67 * CSV sources block — extracted values linked to the spreadsheet cells they came68 * from. Hovering a field highlights its cell and scrolls to it. Segmented69 * source interaction owns preview/selection while the CSV source adapter owns70 * cell navigation.71 */72export function CsvSourcesBlock() {73 const viewerRef = React.useRef<CsvViewerHandle>(null);7475 return (76 <SegmentedDocumentProvider model={SEGMENTED_DOCUMENT}>77 <CsvSourcesContent viewerRef={viewerRef} />78 </SegmentedDocumentProvider>79 );80}8182function CsvSourcesContent({83 viewerRef,84}: {85 viewerRef: React.RefObject<CsvViewerHandle | null>;86}) {87 const target = useCsvSourceTarget(viewerRef);88// … 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 | |
| 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 | |
| Disabled Dropzonedropzone-disabled-dropzone | retab-ui | Blocks | Free | 1 dep · 2 files |
