DOCX Sources
retab-ui/docx-sources-blockFreeBlock
Values extracted from a Word document linked back to where they came from — hover to highlight the text and scroll to it.
Install it
npx shadcn@latest add https://ui.retab.com/r/docx-sources-block.jsonSource
1"use client";23import * as React from "react";45import type { Source } from "@/lib/document-source";6import {7 sourceToDocxHighlight,8 useDocxSourceTarget,9} from "@/components/ui/docx-source";10import { DocxViewer, type DocxViewerHandle } from "@/components/ui/docx-viewer";11import {12 FileViewer,13 FileViewerContent,14 FileViewerHeader,15 FileViewerTitle,16 FileViewerProvider,17 FileViewerSidebar,18 FileViewerSidebarContent,19 FileViewerInset,20 FileViewerControls,21 FileViewerViewport,22} from "@/components/ui/file-viewer";23import { SegmentedDocumentProvider } from "@/components/ui/segmented-document-provider";24import { useSegmentedSourceFieldLink } from "@/components/ui/source-field-link";25import {26 SourceFieldList,27 type SourceField,28} from "@/components/ui/source-field-list";29import { createSourcesSegmentedDocumentModel } from "@/components/ui/source-segmented-document-model";30import docxSample from "@/components/viewers/sample-data/docx-sources.json";3132const DOCX_URL = "/samples/quarterly-business-review.docx";33const DOCX_SOURCE = {34 kind: "url" as const,35 url: DOCX_URL,36 fileName: "quarterly-business-review.docx",37};3839type DocxField = SourceField & { source: Source };4041/** A short locator hint per anchor kind, matching the other source blocks. */42function hintFor(source: Source): string | undefined {43 const a = source.anchor;44 if (a.kind === "docx_text_span") return `¶ ${a.paragraph + 1}`;45 if (a.kind === "docx_table_cell")46 return `Table ${a.table + 1} · R${a.row + 1}C${a.column + 1}`;47 return undefined;48}4950const FIELDS = (docxSample as DocxField[]).map((field) => ({51 ...field,52 hint: hintFor(field.source),53}));54const FIELD_BY_KEY = new Map(FIELDS.map((field) => [field.key, field]));55const SEGMENTED_DOCUMENT = createSourcesSegmentedDocumentModel(56 FIELDS.map((field) => ({57 id: field.key,58 label: field.label,59 source: field.source,60 })),61);6263/**64 * DOCX sources block — values extracted from a Word document, linked to where65 * they came from. Hovering a field highlights its text in the document and66 * scrolls to it. Segmented source interaction owns preview/selection while the67 * DOCX source adapter owns rendered-document target navigation.68 */69export function DocxSourcesBlock() {70 const viewerRef = React.useRef<DocxViewerHandle>(null);7172 return (73 <SegmentedDocumentProvider model={SEGMENTED_DOCUMENT}>74 <DocxSourcesContent viewerRef={viewerRef} />75 </SegmentedDocumentProvider>76 );77}7879// … 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 | |
| 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 |
