Text Splitting
retab-ui/txt-splitting-viewer-blockFreeBlock
One plain-text batch file separated into several documents — each carved-out document rendered in the viewer, with a left sidebar listing the source file first, then every document the splitter emitted, its type, line count, and the boundary cue that detected it. Selecting one opens that document.
Install it
npx shadcn@latest add https://ui.retab.com/r/txt-splitting-viewer-block.jsonSource
1"use client";23import * as React from "react";4import { FileText, WrapText } from "lucide-react";56import { cn } from "@/lib/utils";7import {8 FileViewer,9 FileViewerContent,10 FileViewerControls,11 FileViewerHeader,12 FileViewerInset,13 FileViewerProvider,14 FileViewerSidebar,15 FileViewerSidebarContent,16 FileViewerSidebarTrigger,17 FileViewerTitle,18 FileViewerViewport,19} from "@/components/ui/file-viewer";20import { TextViewer } from "@/components/ui/text-viewer";21import { SEGMENT_PALETTE } from "@/lib/segments";22import txtOutputs from "@/components/viewers/sample-data/txt-splitting.json";2324const SOURCE_ID = "source";25const SOURCE_NAME = "intake-batch.txt";26const TEXT_URL = "/samples/intake-batch.txt";2728const SOURCE_SOURCE = {29 kind: "url" as const,30 url: TEXT_URL,31 fileName: SOURCE_NAME,32};3334type TxtId = keyof typeof txtOutputs;3536/**37 * One document the text splitter carved out of the batch file. `kind` is the38 * document type it was classified as; `detection` is the boundary cue that39 * separated it from its neighbours. The document text itself lives in the40 * sample-data JSON, keyed by `id`.41 */42type TxtOutput = {43 id: TxtId;44 fileName: string;45 kind: string;46 detection: string;47};4849const TXT_OUTPUTS: TxtOutput[] = [50 {51 id: "cover-letter",52 fileName: "cover-letter.txt",53 kind: "Cover letter",54 detection: "Salutation and signature block",55 },56 {57 id: "invoice",58 fileName: "invoice.txt",59 kind: "Invoice",60 detection: "Invoice number and line-item table",61 },62 {63 id: "delivery-receipt",64 fileName: "delivery-receipt.txt",65 kind: "Delivery receipt",66 detection: "Received-by header and gate pass",67 },68 {69 id: "purchase-order",70 fileName: "purchase-order.txt",71 kind: "Purchase order",72 detection: "PO number and not-to-exceed amount",73 },74];7576// Stable {kind:"text"} source per document so selecting one swaps the viewer77// without re-creating the resource on every render.78const TXT_SOURCE_BY_ID = new Map(79 TXT_OUTPUTS.map((output) => [80 output.id,81 {82 kind: "text" as const,83 text: txtOutputs[output.id],84 fileName: output.fileName,85 },86 ]),87);8889function lineCount(id: TxtId) {90 return txtOutputs[id].split("\n").length;91}9293function outputColor(index: number) {94 return SEGMENT_PALETTE[index % SEGMENT_PALETTE.length];95}9697/**98 * Text splitting block — one plain-text batch file separated into several99// … truncated
What it pulls in
npm packages
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 |
