DOCX Document Resource
retab-ui/docx-document-resourceFreeUtility
Load and cache DOCX bytes without viewer chrome.
Install it
npx shadcn@latest add https://ui.retab.com/r/docx-document-resource.jsonSource
1import type {2 ViewerContentBytes,3 ViewerContentIdentity,4} from "@/lib/viewer-resource";56const bufferCache = new Map<string, Promise<ArrayBuffer>>();78export function getDocxDocumentResource(9 content: ViewerContentBytes,10 options: { retainRejected?: boolean } = {},11): Promise<ArrayBuffer> {12 const loadKey = content.key;13 const cached = bufferCache.get(loadKey);14 if (cached) return cached;1516 const promise = readDocxBytes(content).catch((error) => {17 if (!options.retainRejected && bufferCache.get(loadKey) === promise) {18 bufferCache.delete(loadKey);19 }20 throw error;21 });22 bufferCache.set(loadKey, promise);23 return promise;24}2526export function clearDocxDocumentResource(content: ViewerContentIdentity) {27 bufferCache.delete(content.key);28}2930export function resetDocxDocumentResourceCacheForTests() {31 bufferCache.clear();32}3334function readDocxBytes(content: ViewerContentBytes): Promise<ArrayBuffer> {35 return content.readBytes();36}
Files it writes
More from retab-ui
All 130 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| CSV parsercsv | retab-ui | Utilities | Free | no deps · 4 files | |
| Document source modeldocument-source | retab-ui | Utilities | Free | no deps | |
| Effect Keyeffect-key | retab-ui | Utilities | Free | no deps | |
| PDF Document Resourcepdf-document-resource | retab-ui | Utilities | Free | 1 dep · 6 files | |
| Segment Interactionsegment-interaction | retab-ui | Utilities | Free | no deps | |
| Segments modelsegments | retab-ui | Utilities | Free | no deps | |
| Utilsutils | retab-ui | Utilities | Free | 2 deps | |
| XLSX SheetJS flattenerxlsx-sheetjs-flattener | retab-ui | Utilities | Free | 1 dep |
