Skip to Content
texion

API reference

The primary components, hooks, and processing APIs.

TexionInput

A composed input with editing, attachments, previews, and submission handling.

<TexionInput
  format="auto"
  mode="source"
  highlight
  preview
  previewImages
  previewPosition="above"
  submitOnEnter
  onSubmit={handleSubmit}
/>
OptionDefaultBehavior
formatautomarkdown, text, json, csv, or automatic source detection.
modesourceNative source editing, or rich for Markdown.
formatsAll built-in formatsRestricts text and attachment formats.
attachmentstrueEnables file selection, paste, and drop.
previewfalseEnables message and individual attachment preview controls.
previewImagesfalseInitially shows local image previews.
previewPositionaboveInitial preview and attachment position: above or below.
highlightfalseEnables source syntax highlighting.
submitOnEntertrueEnter submits; Shift + Enter inserts a newline. Use false in forms.
labelMessageAccessible editor label.
submitLabelSubmitSubmission button text.

onSubmit receives content, attachments, text, documents, and an optional textDocument. documents and attachments refer to the attachment collection; content is the serializable source representation.

useTexion

Build a custom interface using the same behavior as TexionInput.

const texion = useTexion({ onSubmit: handleSubmit, submitOnEnter: false });
MemberPurpose
getRootProps()Drag and drop handlers for your root element.
getTextareaProps()Native input behavior, composition handling, and text state.
getInputProps()Props for a file input, including accepted formats.
openPicker()Opens the connected file input.
documentsCurrent attachment snapshots.
addDocument(input)Adds a supported file, blob, or text input.
removeDocument(id)Removes an attachment and invalidates pending work.
submit()Processes captured input and invokes the submission handler when ready.
clear()Clears the draft and attachments.
isSubmitting, submitError, inputErrorSubmission and intake feedback.

Limits, adapters, and accepted formats are fixed when the controller mounts. Remount to change them.

Viewers and source inputs

  • DocumentViewer accepts input for processing, document to reuse a snapshot, or content and format for text previews.
  • TexionViewer renders a serialized TexionContent object.
  • HighlightedTextarea adds source highlighting to a native textarea.
  • AttachmentList renders attachment state, removal controls, and optional preview actions.
  • useDocument processes one input through the shared lifecycle.
  • useSourceInput provides source input state, highlighting, selection, and native prop getters.

processDocument

import { processDocument } from '@texion/core';

const document = await processDocument(file, { maxFileSize: 2_000_000 });
if (document.status === 'ready') {
  console.log(document.format, document.raw, document.getPreview?.());
} else {
  console.error(document.error);
}

Text documents preserve decoded source in raw. PDF and DOCX expose extracted text in raw. Images keep their original bytes without a raw string. Original file inputs remain available as file and blob.

createController

Use createController(options) when processing a collection of documents. Subscribe with subscribe(listener), read getSnapshot(), add inputs with add(input), and await whenSettled(id) or waitForIdle().

remove(id), cancel(id), and clear() invalidate outstanding results. See getting started for lifecycle and duplicate handling.

Limits

OptionDefault
maxFiles5
maxFileSize2,000,000 bytes
maxPreviewCharacters50,000
maxPreviewNodes5,000
maxPreviewDepth64
maxImagePixels40,000,000
maxExtractedCharacters1,000,000
maxDocumentPages200
maxArchiveBytes20,000,000

All limits must be positive safe integers. Preview truncation preserves source; extraction limits can reject an attachment. See supported formats for details.

Portable saved messages

Core exports createMessage, createMessageFromDocuments, isTexionMessage, isAttachmentReference, serializeMessage, and deserializeMessage. The version 1 TexionMessage stores a TexionContent and serializable TexionAttachmentReference[]. Original file storage is supplied by your application.

React exports TexionMessageViewer with an optional resolveAttachment(attachment, signal) callback, plus defaultContent and initialAttachments initial values on useTexion / TexionInput. See Saved messages for the complete save, restore, render, and edit workflow.

Independent attachment behavior

useTexionAttachments(options) exposes the attachment lifecycle without a composer UI: documents, isDragging, inputError, addDocument, removeDocument, cancelDocument, clear, whenSettled, waitForIdle, openPicker, getRootProps, getInputProps, getTextareaProps, and handlePaste. Its options are the shared attachment options, including initialAttachments.

Custom source formats

ContentFormat includes built-in format IDs and custom adapter IDs. RendererRegistry maps format IDs to components accepting PreviewRendererProps. Pass renderers to the input or viewer and register matching adapters through their options. Custom source formats preserve native text; rich editing remains Markdown-specific. See Custom adapters.

OCR

createPdfAdapter({ ocr, renderer?, canvasImport? }) opts PDF extraction into OCR. Core exports OcrEngine, OcrSession, OcrOptions, DocumentPage, DocumentProgress, OcrSummary, classifyPdfPage, recognizePdfPages, and createOcrScheduler. React exports useOcrApproval and displays lifecycle progress in attachment cards. Optional @texion/ocr-tesseract and @texion/ocr-http packages provide local worker and host-transport engines. See Scanned PDFs and OCR for the complete contract and execution limits.

On this page