@nextgensoftwares/folio-plugin-file-preview
Previews inside file cards and an in-page file viewer. Guide: File previews.
Plugin
| Export | Signature | Description |
|---|---|---|
filePreviewPlugin | (options: FilePreviewOptions) => FilePreviewPlugin | size-aware fileAttachment renderer and painter, Enter binding, context-menu items, PDF/DOCX exporters |
type FilePreviewOptions | media, defaultSize?, limits?, cache?, worker?, pdfWorker?, viewer?, onOpen?, exportThumbnails? | |
type FilePreviewPlugin | FolioPlugin plus previews (PreviewService), viewer (ViewerStore), open(file, from?), prepareExport(doc) |
Types
| Export | Description |
|---|---|
PreviewKind | 'pdf' | 'sheet' | 'csv' | 'docx' | 'odt' | 'pptx' | 'text' | 'image' | 'video' | 'audio' | 'none' |
CardSize, CARD_SIZES | 'compact' | 'preview' | 'large' |
PreviewData | card preview: image (url), table (rows, sheet?, more?), lines (PreviewLine[], mono?), none (reason) |
PreviewLine | { text, level? } (level 1–6 = heading) |
ViewerData, SheetBook | viewer content: sheet, html (unsanitized; sanitized on insertion), lines, slides |
FileRef | normalized file attrs: src, name, mime, size, pages?, kind, attrs |
PreviewLimits, DEFAULT_LIMITS | maxBytes (50 MB), viewerMaxBytes (100 MB), timeoutMs (15 s), rows 6, cols 5, lines 8, maxCells, maxTextChars |
Detection and layout
| Export | Description |
|---|---|
previewKindOf(name, mime) | kind from the extension, then the MIME type |
extensionOf(name) | lowercase extension |
fileRefOf(attrs) | FileRef from a node's attrs |
hasPreview(kind) | false for none/audio (those cards stay compact) |
PARSED_KINDS | kinds parsed from bytes (worker) |
PREVIEW_SIZE_ATTR | 'previewSize', the global attr on fileAttachment |
previewSchema | the schema contribution declaring it |
CARD_GEOMETRY, CARD_ROW | card height/max width per size; info-row height |
cardSizeOf(attrs, fallback) | the size a card is laid out at (synchronous) |
createPreviewRenderer(defaultSize) | the fileAttachment block renderer |
Previews and cache
| Export | Description |
|---|---|
PreviewService, type PreviewServiceOptions | memory LRU → store → generate; key, peek, request(file, size, signal?), generate, viewerData, bytes |
THUMB_WIDTH | thumbnail width rendered per card size |
indexedDbPreviewStore(opts?), memoryPreviewStore(), type PreviewStore | persistent cache backends (get, set, clear?) |
Lru | small LRU map |
WorkQueue | deduplicating, delayed, bounded-concurrency queue (newest first; dropped when every caller aborts) |
createExtractor(opts), type ExtractorOptions, type RunExtract | worker runner with time limits and in-thread fallback |
defaultWorker(), type WorkerLike | the bundled parsing worker |
TimeoutError, InterruptedError | a task overran / was stopped by another task's overrun |
type ExtractTask, type ExtractLimits | a unit of parsing work (plain data) |
loadBytes(url, opts), type LoadOptions, TooLargeError | capped fetch |
resolveUrl(src, resolve), isLoadableUrl(url) | stored src → loadable URL; scheme allowlist |
Parsing and safety
| Export | Description |
|---|---|
sanitizeHtml(html, opts?) | strict DOM-free allowlist; balanced output, ids prefixed (idPrefix, default fp-) |
parseCsv(text, opts?), sniffDelimiter(text) | RFC 4180, text-only cells, row/cell caps |
decodeText(bytes, maxChars?), textLines(text, max, opts?) | BOM-aware decoding; first lines (Markdown headings) |
loadPdfJs(createWorker?), openPdf(bytes, createWorker?) | pdf.js (legacy build) with eval/XFA/fetching off |
defaultPdfWorker(), type PdfWorkerFactory | the bundled pdf.js worker |
safePdfLink(url) | only http(s)/mailto links |
Commands, export, React
| Export | Description |
|---|---|
selectedFile(state) | the selected file card ({ pos, file }) or null |
setCardSize(size) | command: set the selected card's size |
openSelected(open) | command (bound to Enter): open the selected card; declines otherwise |
createExporters(service, defaultSize, mode), type ExportThumbnails | PDF/DOCX mappings returning PrintFallback + image |
exportImage(service, attrs, size, mode) | the thumbnail image for one card, or undefined |
previewToImage(data, width, height) | table/lines preview → JPEG data URL (canvas) |
createCardPainter(deps), type CardDeps | the card painter |
PreviewBody | draws a PreviewData |
usePreview(service, file, size, enabled), useVisible(ref, margin?) | hooks |
Viewer
| Export | Description |
|---|---|
ViewerStore | get, subscribe, open(state, restoreFocus), close() (focus goes back) |
type ViewerState, type FileViewerProps, type ViewerComponent | what a (host) viewer component receives: file, url, dark, service, onClose |
loadFileViewer() | the default viewer component, loaded on demand |
nextFocus(list, active, back) | the focus trap's Tab order |