@arbidocs/react 0.5.145 → 0.5.147
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/PdfViewerImpl-DC5K3TYK.cjs +22 -0
- package/dist/{PdfViewerImpl-ZVJZ4KNW.cjs.map → PdfViewerImpl-DC5K3TYK.cjs.map} +1 -1
- package/dist/{PdfViewerImpl.d-CqnEzQO7.d.ts → PdfViewerImpl.d-DcM6iPY_.d.ts} +6 -1
- package/dist/annotations/freeze/index.d.ts +1 -1
- package/dist/artifacts/index.cjs +14 -14
- package/dist/calls/livekit/index.cjs +48 -48
- package/dist/chat/conversation-cache.js +5 -0
- package/dist/chat/conversation-cache.js.map +2 -2
- package/dist/chat/useConversation.js +10 -5
- package/dist/chat/useConversation.js.map +2 -2
- package/dist/chat/useConversationActions.js +4 -0
- package/dist/chat/useConversationActions.js.map +2 -2
- package/dist/chat/useConversationSettings.js +4 -10
- package/dist/chat/useConversationSettings.js.map +2 -2
- package/dist/{chunk-FE6ZSNZE.cjs → chunk-5FQB5F2F.cjs} +9 -4
- package/dist/chunk-5FQB5F2F.cjs.map +1 -0
- package/dist/{chunk-4B2GW3AY.cjs → chunk-FK33RWIO.cjs} +3 -3
- package/dist/{chunk-4B2GW3AY.cjs.map → chunk-FK33RWIO.cjs.map} +1 -1
- package/dist/{chunk-2F24LLVZ.cjs → chunk-MHYTO2EX.cjs} +38 -38
- package/dist/{chunk-2F24LLVZ.cjs.map → chunk-MHYTO2EX.cjs.map} +1 -1
- package/dist/{chunk-26SZ3DS4.cjs → chunk-MJIXYLI4.cjs} +66 -66
- package/dist/{chunk-26SZ3DS4.cjs.map → chunk-MJIXYLI4.cjs.map} +1 -1
- package/dist/{chunk-MAOGK7IC.cjs → chunk-PGD4ZWI3.cjs} +3 -3
- package/dist/{chunk-MAOGK7IC.cjs.map → chunk-PGD4ZWI3.cjs.map} +1 -1
- package/dist/{chunk-ZZZYVNFW.cjs → chunk-VBUEDJMK.cjs} +57 -57
- package/dist/{chunk-ZZZYVNFW.cjs.map → chunk-VBUEDJMK.cjs.map} +1 -1
- package/dist/{chunk-ICBT2XGF.cjs → chunk-WGCFGA3L.cjs} +3 -3
- package/dist/chunk-WGCFGA3L.cjs.map +1 -0
- package/dist/{chunk-FDYZA6NO.cjs → chunk-XBY4RLC6.cjs} +4 -4
- package/dist/{chunk-FDYZA6NO.cjs.map → chunk-XBY4RLC6.cjs.map} +1 -1
- package/dist/{chunk-VO7OWQP6.cjs → chunk-ZFTWH6B6.cjs} +44 -44
- package/dist/{chunk-VO7OWQP6.cjs.map → chunk-ZFTWH6B6.cjs.map} +1 -1
- package/dist/databases.js +9 -6
- package/dist/databases.js.map +2 -2
- package/dist/datasets/index.js +25 -21
- package/dist/datasets/index.js.map +2 -2
- package/dist/datasets/pages.js +208 -0
- package/dist/datasets/pages.js.map +7 -0
- package/dist/datasets/registry.js.map +2 -2
- package/dist/datasets/sources/database.js +21 -23
- package/dist/datasets/sources/database.js.map +2 -2
- package/dist/document-tools/core.cjs +98 -98
- package/dist/document-tools/core.d.ts +2 -2
- package/dist/document-tools/index.cjs +100 -100
- package/dist/document-tools/index.d.ts +1 -1
- package/dist/documents/documents-writes.js +45 -14
- package/dist/documents/documents-writes.js.map +2 -2
- package/dist/documents/index.js +8 -0
- package/dist/documents/index.js.map +2 -2
- package/dist/documents/tag-when-processed.js +47 -0
- package/dist/documents/tag-when-processed.js.map +7 -0
- package/dist/host/config.js.map +1 -1
- package/dist/index.cjs +1880 -1583
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +319 -97
- package/dist/index.js +27 -5
- package/dist/index.js.map +2 -2
- package/dist/notifications/notification-types.js +7 -0
- package/dist/notifications/notification-types.js.map +2 -2
- package/dist/notifications/server-notifications.js +66 -10
- package/dist/notifications/server-notifications.js.map +2 -2
- package/dist/{pdf-region-impl-ZG5G2OX2.cjs → pdf-region-impl-J2TVABQU.cjs} +9 -9
- package/dist/{pdf-region-impl-ZG5G2OX2.cjs.map → pdf-region-impl-J2TVABQU.cjs.map} +1 -1
- package/dist/{query-keys.d-d2M4FAq2.d.ts → query-keys.d-pgq-4jyZ.d.ts} +7 -2
- package/dist/query-keys.js +7 -2
- package/dist/query-keys.js.map +2 -2
- package/dist/table-views.js +166 -0
- package/dist/table-views.js.map +7 -0
- package/dist/viewers/PdfViewer.cjs +3 -3
- package/dist/viewers/PdfViewer.d.ts +2 -2
- package/dist/viewers/PdfViewerImpl.js +1 -1
- package/dist/viewers/PdfViewerImpl.js.map +2 -2
- package/dist/viewers/index.cjs +10 -10
- package/dist/viewers/index.d.ts +2 -2
- package/package.json +3 -3
- package/dist/PdfViewerImpl-ZVJZ4KNW.cjs +0 -22
- package/dist/account/table-views.js +0 -16
- package/dist/account/table-views.js.map +0 -7
- package/dist/chunk-FE6ZSNZE.cjs.map +0 -1
- package/dist/chunk-ICBT2XGF.cjs.map +0 -1
- package/dist/datasets/store.js +0 -194
- package/dist/datasets/store.js.map +0 -7
|
@@ -9,7 +9,7 @@ require('react-pdf/dist/Page/TextLayer.css');
|
|
|
9
9
|
var jsxRuntime = require('react/jsx-runtime');
|
|
10
10
|
|
|
11
11
|
var DEFAULT_ASSETS = {
|
|
12
|
-
workerSrc: "/pdf.worker.min.mjs",
|
|
12
|
+
workerSrc: reactPdf.pdfjs.version ? `/pdf.worker.min.mjs?v=${reactPdf.pdfjs.version}` : "/pdf.worker.min.mjs",
|
|
13
13
|
cMapUrl: "/cmaps/",
|
|
14
14
|
standardFontDataUrl: "/standard_fonts/",
|
|
15
15
|
wasmUrl: "/wasm/"
|
|
@@ -379,5 +379,5 @@ function PdfViewer({
|
|
|
379
379
|
exports.DEFAULT_ASSETS = DEFAULT_ASSETS;
|
|
380
380
|
exports.PdfViewer = PdfViewer;
|
|
381
381
|
exports.ensurePdfWorker = ensurePdfWorker;
|
|
382
|
-
//# sourceMappingURL=chunk-
|
|
383
|
-
//# sourceMappingURL=chunk-
|
|
382
|
+
//# sourceMappingURL=chunk-WGCFGA3L.cjs.map
|
|
383
|
+
//# sourceMappingURL=chunk-WGCFGA3L.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/viewers/PdfViewerImpl.tsx"],"names":["pdfjs","installPdfjsPolyfills","useState","INITIAL_LAZY_LOAD_BUFFER","useMemo","useEffect","useRef","useCallback","LAZY_LOAD_BUFFER_BEFORE","LAZY_LOAD_BUFFER_AFTER","handle","fitPageWidth","contentBoxWidth","currentPage","usePageIntersectionObserver","useScrollAnchor","usePinchZoom","jsx","Document","jsxs","Fragment","Page","ratio","renderDpr"],"mappings":";;;;;;;;;;AAsDO,IAAM,cAAA,GAA4C;AAAA,EACvD,WAAWA,cAAA,CAAM,OAAA,GAAU,CAAA,sBAAA,EAAyBA,cAAA,CAAM,OAAO,CAAA,CAAA,GAAK,qBAAA;AAAA,EACtE,OAAA,EAAS,SAAA;AAAA,EACT,mBAAA,EAAqB,kBAAA;AAAA,EACrB,OAAA,EAAS;AACX;AAMO,SAAS,gBAAgB,SAAA,EAAmB;AACjD,EAAAC,uCAAA,EAAsB;AACtB,EAAA,IAAID,cAAA,CAAM,mBAAA,CAAoB,SAAA,KAAc,SAAA,EAAW;AACrD,IAAAA,cAAA,CAAM,oBAAoB,SAAA,GAAY,SAAA;AAAA,EACxC;AACF;AAMA,IAAM,yBAAA,GAA4B,KAAA;AAElC,IAAM,cAAA,GAAiB,CAAA;AAEvB,IAAM,oBAAA,GAAuB,GAAA;AAE7B,IAAM,uBAAA,GAA0B,GAAA;AAGhC,SAAS,OAAA,CAAQ,GAAwB,CAAA,EAAiC;AACxE,EAAA,IAAI,CAAA,CAAE,IAAA,KAAS,CAAA,CAAE,IAAA,EAAM,OAAO,KAAA;AAC9B,EAAA,KAAA,MAAW,CAAA,IAAK,GAAG,IAAI,CAAC,EAAE,GAAA,CAAI,CAAC,GAAG,OAAO,KAAA;AACzC,EAAA,OAAO,IAAA;AACT;AAIA,IAAM,iBAAA,GAAoB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8BACV,OAAO,EAAE,KAAA,EAAO,WAAA,EAAa,MAAA,EAAQ,cAAc,KAAA,EAAM;AAAA,8BAEzD,QAAA,kBAAAE,eAAA,CAAC,KAAA,EAAA,EAAI,SAAA,EAAU,+BAAA,EAAgC,QAAA,EAAA;AAAA,gCAAA,eAAA;AAAA,gCAC/B,UAAA;AAAA,gCAAW;AAAA,+BAAA,EAC3B;AAAA;AAAA;AACF;AAAA;AAEJ;AAAA,mBACF,mBAEAF,cAAA;AAAA,oBAAC,KAAA;AAAA,oBAAA;AAAA,sBACC,SAAA,EAAU,2CAAA;AAAA,sBACV,KAAA,EAAO,EAAE,KAAA,EAAO,SAAA,EAAW,QAAQ,UAAA,EAAW;AAAA,sBAE9C,QAAA,kBAAAE,eAAA,CAAC,KAAA,EAAA,EAAI,SAAA,EAAU,+BAAA,EAAgC,QAAA,EAAA;AAAA,wBAAA,OAAA;AAAA,wBAAM;AAAA,uBAAA,EAAW;AAAA;AAAA,mBAClE;AAAA,kBAED,iBAAA,GAAoB,EAAE,UAAA,EAAY,WAAA,EAAa,aAAa,GAAA,CAAI,UAAU,GAAG;AAAA;AAAA,eAAA;AAAA,cAvEzE,QAAQ,UAAU,CAAA;AAAA,aAwEzB;AAAA,UAEJ,CAAC;AAAA,SAAA;AAAA,QA/HE;AAAA;AAgIP;AAAA,GACF;AAEJ","file":"chunk-WGCFGA3L.cjs","sourcesContent":["/**\n * PdfViewer — paged PDF rendering with bidirectional page synchronisation.\n *\n * Uses IntersectionObserver to track the visible page and to drive two separate\n * lazy-load windows: a wide canvas buffer (so a page image is ready before the\n * user scrolls to it) and a narrow text-layer window (text spans are expensive\n * DOM, so they only exist for the active reading area).\n *\n * DECOUPLED FOR REUSE: page changes are reported through `onPageChange` rather\n * than written to an app store, and the pdf.js asset URLs are props rather than\n * hardcoded paths, because a consuming app decides where it serves the worker,\n * cmaps and standard fonts from.\n *\n * `react-pdf` and `pdfjs-dist` are OPTIONAL peer dependencies — install them\n * only if you render PDFs. The consuming app must also serve the pdf.js worker\n * (see `assets.workerSrc`).\n */\n\nimport { useState, useEffect, useRef, useCallback, useMemo, type ReactNode } from 'react'\nimport { Document, Page, pdfjs } from 'react-pdf'\nimport 'react-pdf/dist/Page/AnnotationLayer.css'\nimport 'react-pdf/dist/Page/TextLayer.css'\nimport { installPdfjsPolyfills } from './pdfjs-polyfills'\nimport { usePageIntersectionObserver } from './usePageIntersectionObserver'\nimport { useScrollAnchor } from './page-scroll'\nimport { contentBoxWidth, fitPageWidth, renderDpr, usePinchZoom } from './viewer-zoom'\nimport {\n LAZY_LOAD_BUFFER_BEFORE,\n LAZY_LOAD_BUFFER_AFTER,\n INITIAL_LAZY_LOAD_BUFFER,\n} from './pdf-viewer-constants'\n\n/** Where the app serves the pdf.js runtime assets from. */\nexport interface PdfViewerAssets {\n /**\n * pdf.js worker bundle. Default `/pdf.worker.min.mjs?v=<pdf.js version>`: the version in the\n * URL means a new pdf.js is never served a worker an earlier visit left in a cache, which\n * pdf.js rejects (\"API version does not match Worker version\"). If you set your own, version it\n * the same way or serve it `no-cache`.\n */\n workerSrc?: string\n /** Directory of pdf.js character maps. Default `/cmaps/`. */\n cMapUrl?: string\n /** Directory of pdf.js standard font data. Default `/standard_fonts/`. */\n standardFontDataUrl?: string\n /**\n * Directory of the pdf.js wasm decoders (openjpeg for JPEG 2000, jbig2,\n * qcms). Scanned PDFs routinely embed JPX/JBIG2-compressed page images;\n * without these modules pdf.js fails image decoding with only a console\n * warning and renders blank white pages. Default `/wasm/`.\n */\n wasmUrl?: string\n}\n\nexport const DEFAULT_ASSETS: Required<PdfViewerAssets> = {\n workerSrc: pdfjs.version ? `/pdf.worker.min.mjs?v=${pdfjs.version}` : '/pdf.worker.min.mjs',\n cMapUrl: '/cmaps/',\n standardFontDataUrl: '/standard_fonts/',\n wasmUrl: '/wasm/',\n}\n\n/**\n * Ready pdf.js before any Document mounts: the built-ins it needs on this thread (older browsers\n * lack them and every page render would throw), and the worker, re-set only if it changed.\n */\nexport function ensurePdfWorker(workerSrc: string) {\n installPdfjsPolyfills()\n if (pdfjs.GlobalWorkerOptions.workerSrc !== workerSrc) {\n pdfjs.GlobalWorkerOptions.workerSrc = workerSrc\n }\n}\n\n// Page rendering constants\n// Height / width used for a page until its real size is known (the first page is read as soon as\n// the document opens, every other page as it renders). A placeholder that differs from the real\n// page shifts everything below it when the page renders.\nconst DEFAULT_PAGE_ASPECT_RATIO = 1.414 // A4 (√2)\n/** The page wrapper's own border (border, top + bottom), included in its fixed height. */\nconst PAGE_BORDER_PX = 2\n/** Wait for the zoom to settle before re-rasterising every visible page. */\nconst RERENDER_DEBOUNCE_MS = 250\n/** Above this zoom a page canvas is large enough that the render window shrinks. */\nconst ZOOMED_BUFFER_THRESHOLD = 1.5\n\n/** Same set contents: lets a state setter bail out instead of re-rendering on every scroll tick. */\nfunction sameSet(a: ReadonlySet<number>, b: ReadonlySet<number>): boolean {\n if (a.size !== b.size) return false\n for (const v of a) if (!b.has(v)) return false\n return true\n}\n\n// Text layer is enabled for pages within 1 page of the visible set — enough for smooth\n// scrolling while keeping DOM node count low on large documents.\nconst TEXT_LAYER_BUFFER = 1\n\ninterface PdfPageSize {\n getViewport: (options: { scale: number }) => { width: number; height: number }\n}\nconst ratioOf = (page: PdfPageSize): number => {\n const { width, height } = page.getViewport({ scale: 1 })\n return width > 0 && height > 0 ? height / width : DEFAULT_PAGE_ASPECT_RATIO\n}\n\nexport interface PdfViewerProps {\n file: string | Blob\n currentPage?: number\n onLoadSuccess?: (numPages: number) => void\n /** Incremented to trigger scroll to currentPage */\n scrollTrigger?: number\n /** Zoom as a multiplier of the fit-width size (1 = fit width). Default 1. */\n zoom?: number\n /** Called by pinch and double-tap; the host owns the value (its buttons change it too). */\n onZoomChange?: (zoom: number) => void\n /**\n * Called as the user scrolls, with the page occupying most of the viewport.\n * This is the reusable form of the monolith's `setViewingDocumentPage`.\n */\n onPageChange?: (pageNumber: number) => void\n /**\n * Force pdf.js to rasterise fonts onto the canvas instead of using @font-face.\n * Required when rendering into a different document (e.g. a popped-out window),\n * where @font-face rules from the opener do not apply.\n */\n disableFontFace?: boolean\n /** Where the app serves the pdf.js worker, cmaps and standard fonts from. */\n assets?: PdfViewerAssets\n /**\n * Content drawn over every page, inside its border box (e.g. the annotation layer). It fills the\n * page area and moves and scales with it. `pageWidthPt` is the page's width in PDF points once\n * known, so overlays can size strokes and text to match what a later export draws.\n */\n renderPageOverlay?: (page: { pageNumber: number; pageWidthPt: number | undefined }) => ReactNode\n}\n\nexport function PdfViewer({\n file,\n currentPage,\n onLoadSuccess,\n scrollTrigger,\n zoom = 1,\n onZoomChange,\n onPageChange,\n disableFontFace = false,\n assets,\n renderPageOverlay,\n}: PdfViewerProps) {\n const workerSrc = assets?.workerSrc ?? DEFAULT_ASSETS.workerSrc\n const cMapUrl = assets?.cMapUrl ?? DEFAULT_ASSETS.cMapUrl\n const standardFontDataUrl = assets?.standardFontDataUrl ?? DEFAULT_ASSETS.standardFontDataUrl\n const wasmUrl = assets?.wasmUrl ?? DEFAULT_ASSETS.wasmUrl\n\n // Ensure the pdf.js worker is configured before any Document mounts\n ensurePdfWorker(workerSrc)\n\n const [numPages, setNumPages] = useState<number>(0)\n const [containerWidth, setContainerWidth] = useState<number>(0)\n // Real height/width of the document's pages: the first page's, then each page as it loads.\n const [defaultRatio, setDefaultRatio] = useState<number>(DEFAULT_PAGE_ASPECT_RATIO)\n const [pageRatios, setPageRatios] = useState<ReadonlyMap<number, number>>(new Map())\n // Each page's width in PDF points, for overlays that must size strokes and text like an export.\n const [pageWidthsPt, setPageWidthsPt] = useState<ReadonlyMap<number, number>>(new Map())\n const [loadError, setLoadError] = useState<Error | null>(null)\n const [documentKey, setDocumentKey] = useState<string>(() => `pdf-${Date.now()}`)\n\n // Initialize with pages around the current page (or first 3 pages if no current page).\n // Start with a small initial buffer so the first paint is cheap; expand to the full\n // buffer lazily via requestIdleCallback after the first render settles.\n const initialPage = currentPage || 1\n const [renderedPages, setRenderedPages] = useState<Set<number>>(\n new Set([\n Math.max(1, initialPage - INITIAL_LAZY_LOAD_BUFFER.before),\n initialPage,\n initialPage + INITIAL_LAZY_LOAD_BUFFER.after,\n ])\n )\n\n // Pages currently in/near the viewport — used to gate the text layer.\n // Keeping this separate from renderedPages lets the canvas still render on buffer pages\n // while text DOM nodes are only created for the user's active reading area.\n const [visiblePages, setVisiblePages] = useState<Set<number>>(new Set([initialPage]))\n\n // A late PDF.js completion belongs only to the file that started it.\n const loadLifetime = useMemo(() => ({ file, active: true }), [file])\n useEffect(() => {\n loadLifetime.active = true\n return () => {\n loadLifetime.active = false\n }\n }, [loadLifetime])\n\n // Reset document key when file changes to force remount\n useEffect(() => {\n setDocumentKey(`pdf-${Date.now()}`)\n setNumPages(0)\n setLoadError(null)\n }, [file])\n\n const containerRef = useRef<HTMLDivElement>(null)\n const pageRefs = useRef<Map<number, HTMLDivElement>>(new Map())\n\n // Handle document load success\n const onDocumentLoadSuccess = useCallback(\n (pdf: { numPages: number; getPage?: (n: number) => Promise<PdfPageSize> }) => {\n if (!loadLifetime.active) return\n const n = pdf.numPages\n void pdf\n .getPage?.(1)\n .then((page) => {\n if (loadLifetime.active) setDefaultRatio(ratioOf(page))\n })\n .catch(() => {})\n setNumPages(n)\n setLoadError(null) // Clear any previous errors\n\n try {\n onLoadSuccess?.(n)\n } catch (error) {\n console.error('Error in onLoadSuccess callback:', error)\n }\n },\n [onLoadSuccess, loadLifetime]\n )\n\n // Expand only while this file is mounted. Cancellation also guards callbacks\n // that were already queued when the idle/timer handle was cancelled.\n useEffect(() => {\n if (numPages === 0) return\n let cancelled = false\n const expand = () => {\n if (cancelled || !loadLifetime.active) return\n setRenderedPages((prev) => {\n if (prev.size === 0) return prev\n const newSet = new Set(prev)\n const anchor = currentPage || 1\n for (\n let i = Math.max(1, anchor - LAZY_LOAD_BUFFER_BEFORE);\n i <= Math.min(numPages, anchor + LAZY_LOAD_BUFFER_AFTER);\n i++\n ) {\n newSet.add(i)\n }\n return newSet\n })\n }\n if (typeof requestIdleCallback !== 'undefined') {\n const handle = requestIdleCallback(expand, { timeout: 500 })\n return () => {\n cancelled = true\n if (typeof cancelIdleCallback !== 'undefined') cancelIdleCallback(handle)\n }\n }\n const handle = setTimeout(expand, 500)\n return () => {\n cancelled = true\n clearTimeout(handle)\n }\n }, [numPages, currentPage, loadLifetime])\n\n // Handle document load error\n const onDocumentLoadError = useCallback((error: Error) => {\n console.error('PDF loading error:', error)\n setLoadError(error)\n setNumPages(0)\n }, [])\n\n // react-pdf calls this when the PDF is encrypted (reason === 1) or the\n // supplied password was wrong (reason === 2). Default behaviour is a\n // window.prompt() that, when cancelled, never resolves the password\n // callback — pdf.js then leaves the document load Promise pending forever\n // and the viewer is stuck on \"Loading PDF...\".\n //\n // Always call updatePassword exactly once. On cancel we surface a\n // synthetic load error so onLoadError → setLoadError fires the standard\n // error UI instead of the indefinite spinner.\n const onPassword = useCallback((updatePassword: (password: string) => void, reason: number) => {\n const message =\n reason === 2\n ? 'Incorrect password. Enter the password to unlock this PDF:'\n : 'This PDF is password-protected. Enter the password to view it:'\n const password = window.prompt(message)\n if (password === null) {\n // Cancelled. Synthesise a load error so the error UI takes over.\n setLoadError(new Error('Password required to open this PDF'))\n setNumPages(0)\n return\n }\n updatePassword(password)\n }, [])\n\n // Fit width: the scroller's content box (inside its padding AND its vertical scrollbar) less the\n // page's own border. `offsetWidth` would count the scrollbar and overflow sideways by its width.\n useEffect(() => {\n const container = containerRef.current\n if (!container) return\n const setFromContentWidth = (contentWidth: number) =>\n setContainerWidth(fitPageWidth(contentWidth, PAGE_BORDER_PX))\n\n setFromContentWidth(contentBoxWidth(container))\n\n // Re-measure on any change of the content box: a panel resize, or the vertical scrollbar\n // appearing once the pages are taller than the scroller.\n const resizeObserver = new ResizeObserver((entries) => {\n const entry = entries[entries.length - 1]\n const box = entry?.contentBoxSize?.[0]\n setFromContentWidth(box ? box.inlineSize : (entry?.contentRect.width ?? 0))\n })\n resizeObserver.observe(container)\n\n return () => {\n resizeObserver.disconnect()\n }\n }, [])\n\n // Track whether initial scroll has completed to prevent feedback loop\n const scrollCompleteRef = useRef(false)\n\n // Scroll to page ONLY when PDF loads - not when page number updates from scrolling\n useEffect(() => {\n if (numPages === 0) return\n\n // If we already scrolled, don't scroll again\n if (scrollCompleteRef.current) return\n\n // Ensure the target page and surrounding pages are rendered\n if (currentPage) {\n setRenderedPages((prev) => {\n const newSet = new Set(prev)\n for (\n let i = Math.max(1, currentPage - LAZY_LOAD_BUFFER_BEFORE);\n i <= Math.min(numPages, currentPage + LAZY_LOAD_BUFFER_AFTER);\n i++\n ) {\n newSet.add(i)\n }\n return newSet\n })\n\n // Wait for DOM update, then scroll\n requestAnimationFrame(() => {\n const pageElement = pageRefs.current.get(currentPage)\n if (pageElement) {\n pageElement.scrollIntoView({ behavior: 'auto', block: 'start' })\n }\n // Wait for scroll to complete before allowing page number updates\n setTimeout(() => {\n scrollCompleteRef.current = true\n }, 100)\n })\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [numPages]) // Note: currentPage is intentionally NOT a dependency to prevent feedback loop\n\n // The page the last explicit request (overlay arrows, typed number) asked for. Read when the\n // trigger fires; scrolling itself changes `currentPage` and must NOT re-run the scroll below,\n // or every page the user scrolls past would pull the view back to that page's top.\n const currentPageRef = useRef(currentPage)\n currentPageRef.current = currentPage\n\n // Scroll to page when scrollTrigger changes (user entered a page number)\n useEffect(() => {\n const currentPage = currentPageRef.current\n if (!scrollTrigger || numPages === 0 || !currentPage) return\n\n // Temporarily disable observer updates during manual scroll\n scrollCompleteRef.current = false\n\n // Ensure the target page and surrounding pages are rendered\n setRenderedPages((prev) => {\n const newSet = new Set(prev)\n for (\n let i = Math.max(1, currentPage - LAZY_LOAD_BUFFER_BEFORE);\n i <= Math.min(numPages, currentPage + LAZY_LOAD_BUFFER_AFTER);\n i++\n ) {\n newSet.add(i)\n }\n return newSet\n })\n\n // Double-rAF: first frame lets React commit the setRenderedPages update so\n // pages before the target are in the DOM at their correct heights; second\n // frame scrolls after layout has settled. Instant scroll avoids a race\n // where smooth-scroll animation is still running when the observer\n // re-enables and reports the wrong page.\n requestAnimationFrame(() => {\n requestAnimationFrame(() => {\n const pageElement = pageRefs.current.get(currentPage)\n if (pageElement) {\n pageElement.scrollIntoView({ behavior: 'instant', block: 'start' })\n }\n scrollCompleteRef.current = true\n })\n })\n }, [scrollTrigger, numPages])\n\n // Handle lazy loading based on visible pages\n const handleVisibilityUpdate = useCallback(\n (visibilityMap: Map<number, number>) => {\n const visiblePageNums = Array.from(visibilityMap.entries())\n .filter(([, ratio]) => ratio > 0)\n .map(([pageNum]) => pageNum)\n\n if (visiblePageNums.length > 0) {\n const minVisible = Math.min(...visiblePageNums)\n const maxVisible = Math.max(...visiblePageNums)\n\n // Update canvas render buffer (wider window for smooth pre-loading). Zoomed pages are\n // big canvases: keep fewer of them alive so far pages release their memory.\n const zoomed = zoom > ZOOMED_BUFFER_THRESHOLD\n const before = zoomed ? 1 : LAZY_LOAD_BUFFER_BEFORE\n const after = zoomed ? 2 : LAZY_LOAD_BUFFER_AFTER\n const pagesToRender = new Set<number>()\n for (\n let i = Math.max(1, minVisible - before);\n i <= Math.min(numPages, maxVisible + after);\n i++\n ) {\n pagesToRender.add(i)\n }\n setRenderedPages((prev) => (sameSet(prev, pagesToRender) ? prev : pagesToRender))\n\n // Update text-layer set (narrow window — text layer is expensive DOM)\n const nearViewport = new Set<number>()\n for (\n let i = Math.max(1, minVisible - TEXT_LAYER_BUFFER);\n i <= Math.min(numPages, maxVisible + TEXT_LAYER_BUFFER);\n i++\n ) {\n nearViewport.add(i)\n }\n setVisiblePages((prev) => (sameSet(prev, nearViewport) ? prev : nearViewport))\n }\n },\n [numPages, zoom]\n )\n\n // Memoize options to prevent unnecessary Document reloads.\n // When the options object changes reference, react-pdf reloads the document,\n // which fails if the source Blob's ArrayBuffer was already transferred to the worker.\n const documentOptions = useMemo(\n () => ({\n standardFontDataUrl,\n cMapUrl,\n cMapPacked: true,\n wasmUrl,\n ...(disableFontFace && { disableFontFace: true }),\n }),\n [standardFontDataUrl, cMapUrl, wasmUrl, disableFontFace]\n )\n\n // Observer callback is optional for consumers that don't track the page.\n const handlePageChange = useCallback(\n (pageNumber: number) => onPageChange?.(pageNumber),\n [onPageChange]\n )\n\n // Use IntersectionObserver to track visible pages and update page number\n usePageIntersectionObserver({\n containerRef,\n scrollCompleteRef,\n isEnabled: numPages > 0,\n getPageElements: () => Array.from(pageRefs.current.values()),\n getPageNumber: (element) => parseInt(element.getAttribute('data-page-number') ?? '0'),\n onPageChange: handlePageChange,\n onVisibilityUpdate: handleVisibilityUpdate,\n observeKey: `${numPages}:${containerWidth > 0}`,\n })\n\n // Pages above the reading position change height as they load their real size.\n useScrollAnchor(containerRef, `${numPages}:${containerWidth > 0}`)\n\n // Pinch / double-tap, and the focal point kept still for every zoom change.\n usePinchZoom({ containerRef, zoom, onZoomChange })\n\n // Layout follows `zoom` at once (a CSS scale of the already rendered canvas, so the gesture is\n // smooth); the canvases are re-rendered at the new resolution once the zoom has settled. Without\n // this the bitmap is only magnified and stays blurry.\n const [renderZoom, setRenderZoom] = useState(zoom)\n useEffect(() => {\n if (zoom === renderZoom) return\n const timer = setTimeout(() => setRenderZoom(zoom), RERENDER_DEBOUNCE_MS)\n return () => clearTimeout(timer)\n }, [zoom, renderZoom])\n\n return (\n <div\n ref={containerRef}\n className=\"w-full h-full overflow-auto bg-muted flex flex-col items-start p-4 pb-20\"\n // Two-finger gestures belong to the viewer (real zoom), not to the browser (bitmap zoom).\n // The scrollbar's gutter is always reserved, so the fit width does not change (and every page\n // re-rasterise) when the scrollbar appears, and cannot flip back and forth at the threshold.\n style={{ touchAction: 'pan-x pan-y', scrollbarGutter: 'stable' }}\n role=\"region\"\n aria-label=\"PDF document viewer\"\n data-slot=\"pdf-scroller\"\n data-testid=\"pdf-viewer\"\n >\n <Document\n // Wider than the scroller when zoomed in: the scroller pans horizontally over it.\n className=\"flex w-max min-w-full flex-col\"\n key={documentKey}\n // react-pdf 11 suspends while loading and sends failures to an error boundary. This viewer\n // owns its loading and error UI (and the password flow), so keep the callback behaviour.\n suspense={false}\n file={file}\n onLoadSuccess={onDocumentLoadSuccess}\n onLoadError={onDocumentLoadError}\n onPassword={onPassword}\n options={documentOptions}\n loading={\n <div className=\"flex items-center justify-center h-full\">\n <div className=\"text-sm text-muted-foreground\">Loading PDF...</div>\n </div>\n }\n error={\n <div className=\"flex flex-col items-center justify-center h-full gap-4 p-8\">\n <div className=\"text-destructive text-center\">\n {loadError?.message ===\n \"Cannot read properties of null (reading 'sendWithPromise')\" ? (\n <>\n <p className=\"font-semibold mb-2\">PDF viewer initialization failed</p>\n <p className=\"text-sm text-muted-foreground\">Please refresh the page to retry</p>\n </>\n ) : (\n <>\n <p className=\"font-semibold mb-2\">Failed to load PDF</p>\n {loadError && (\n <p className=\"text-sm text-muted-foreground\">{loadError.message}</p>\n )}\n </>\n )}\n </div>\n </div>\n }\n >\n {containerWidth > 0 &&\n Array.from(new Array(numPages), (_, index) => {\n const pageNumber = index + 1\n const shouldRender = renderedPages.has(pageNumber)\n const ratio = pageRatios.get(pageNumber) ?? defaultRatio\n const pageWidth = containerWidth * zoom\n const pageHeight = pageWidth * ratio\n // Resolution the canvas is (re-)rendered at, and how far it is CSS-scaled meanwhile.\n const renderWidth = containerWidth * renderZoom\n const scale = zoom / renderZoom\n // Only enable the text layer for pages in/near the viewport.\n // Pages in the wider render buffer get a canvas (so the image is ready when\n // the user scrolls to them) but no text spans until they're nearby — this\n // avoids committing thousands of DOM nodes synchronously on large documents.\n const shouldRenderTextLayer = visiblePages.has(pageNumber)\n\n return (\n <div\n key={`page_${pageNumber}`}\n ref={(el) => {\n if (el) {\n pageRefs.current.set(pageNumber, el)\n } else {\n pageRefs.current.delete(pageNumber)\n }\n }}\n data-page-number={pageNumber}\n // Fixed height in every state: a flex item would otherwise shrink (it is a\n // scroller itself via blocks.css) and a placeholder/real mismatch would shift the\n // pages below.\n className=\"relative mx-auto mb-6 shrink-0 shadow-xl bg-white border border-border\"\n style={{ width: pageWidth + PAGE_BORDER_PX, height: pageHeight + PAGE_BORDER_PX }}\n role=\"article\"\n aria-label={`Page ${pageNumber} of ${numPages}`}\n >\n {shouldRender ? (\n <div\n data-testid={`pdf-page-scaler-${pageNumber}`}\n style={\n scale === 1\n ? undefined\n : { transform: `scale(${scale})`, transformOrigin: '0 0' }\n }\n >\n <Page\n pageNumber={pageNumber}\n width={renderWidth}\n renderTextLayer={shouldRenderTextLayer}\n renderAnnotationLayer={false}\n onLoadSuccess={(page: { originalWidth: number; originalHeight: number }) => {\n setPageWidthsPt((prev) =>\n prev.get(pageNumber) === page.originalWidth\n ? prev\n : new Map(prev).set(pageNumber, page.originalWidth)\n )\n const ratio = page.originalHeight / page.originalWidth\n setPageRatios((prev) =>\n Math.abs((prev.get(pageNumber) ?? defaultRatio) - ratio) < 0.001\n ? prev\n : new Map(prev).set(pageNumber, ratio)\n )\n }}\n // DPR capped at 2x and lowered further when the page would exceed the canvas\n // pixel budget (zoomed pages are big; iOS Safari fails above ~16.7M pixels).\n devicePixelRatio={renderDpr(\n renderWidth,\n renderWidth * ratio,\n window.devicePixelRatio || 1\n )}\n loading={\n <div\n className=\"flex items-center justify-center bg-muted\"\n style={{ width: renderWidth, height: renderWidth * ratio }}\n >\n <div className=\"text-sm text-muted-foreground\">\n Loading page {pageNumber}...\n </div>\n </div>\n }\n />\n </div>\n ) : (\n <div\n className=\"flex items-center justify-center bg-muted\"\n style={{ width: pageWidth, height: pageHeight }}\n >\n <div className=\"text-sm text-muted-foreground\">Page {pageNumber}</div>\n </div>\n )}\n {renderPageOverlay?.({ pageNumber, pageWidthPt: pageWidthsPt.get(pageNumber) })}\n </div>\n )\n })}\n </Document>\n </div>\n )\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunk5FQB5F2F_cjs = require('./chunk-5FQB5F2F.cjs');
|
|
4
4
|
var chunkKULS4YWP_cjs = require('./chunk-KULS4YWP.cjs');
|
|
5
5
|
var react = require('react');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
@@ -47,7 +47,7 @@ function certificateLink(signature, certificateUrl) {
|
|
|
47
47
|
}
|
|
48
48
|
var DocumentToolsContext = react.createContext(null);
|
|
49
49
|
function DocumentToolsProvider({ children, ...env }) {
|
|
50
|
-
const arbiDeploymentDomain =
|
|
50
|
+
const arbiDeploymentDomain = chunk5FQB5F2F_cjs.useDeploymentDomain();
|
|
51
51
|
const guards = react.useRef(/* @__PURE__ */ new Map());
|
|
52
52
|
const pendingFlushes = react.useRef(/* @__PURE__ */ new Map());
|
|
53
53
|
const registerBeforeFileShare = react.useCallback((id, flush) => {
|
|
@@ -260,5 +260,5 @@ exports.isSignedVersion = isSignedVersion;
|
|
|
260
260
|
exports.uploadQueryString = uploadQueryString;
|
|
261
261
|
exports.useDocumentTools = useDocumentTools;
|
|
262
262
|
exports.useOptionalDocumentTools = useOptionalDocumentTools;
|
|
263
|
-
//# sourceMappingURL=chunk-
|
|
264
|
-
//# sourceMappingURL=chunk-
|
|
263
|
+
//# sourceMappingURL=chunk-XBY4RLC6.cjs.map
|
|
264
|
+
//# sourceMappingURL=chunk-XBY4RLC6.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/document-tools/environment.tsx","../src/document-tools/document-pdf.ts","../src/document-tools/markup-download.ts"],"names":["createContext","useDeploymentDomain","useRef","useCallback","useMemo","jsx","useContext","parseVersionRef"],"mappings":";;;;;;;AAmEO,SAAS,kBAAkB,KAAA,EAAoC;AACpE,EAAA,MAAM,MAAA,GAAS,IAAI,eAAA,EAAgB;AACnC,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA,EAAG;AAChD,IAAA,IAAI,KAAA,KAAU,IAAA,IAAQ,KAAA,KAAU,MAAA,EAAW;AAC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M,IAAA,GAAO,4BAAA,CAA6B,IAAA,CAAK,WAAW,IAAI,CAAC,CAAA;AAC/D,EAAA,MAAM,KAAA,GAAQ,qBAAA,CAAsB,IAAA,CAAK,WAAW,IAAI,CAAC,CAAA;AACzD,EAAA,MAAM,QAAA,GAAW,IAAA,GAAO,kBAAA,CAAmB,IAAI,IAAK,KAAA,IAAS,YAAA;AAC7D,EAAA,OAAO,EAAE,IAAA,EAAM,IAAA,EAAc,QAAA,EAAS;AACxC","file":"chunk-FDYZA6NO.cjs","sourcesContent":["/**\n * The host app's side of the document tools (markup, freeze, e-signing, versions): the one place\n * the tools reach the app. They never import a store, a router, a toast library or app API code;\n * the host passes what it has to `<DocumentToolsProvider>` and every optional field has a default.\n *\n * `client` is an openapi-fetch client for the ARBI API (`ArbiClient['fetch']` from\n * `@arbidocs/client`, or `arbi.getClient().fetch` from an `@arbidocs/sdk` `Arbi`), signed in with the\n * user's session; it carries the auth.\n */\n\nimport { createContext, useCallback, useContext, useMemo, useRef, type ReactNode } from 'react'\nimport type { ArbiClient, operations } from '@arbidocs/client'\nimport { useDeploymentDomain } from '../useArbi'\n\nexport type DocumentToolsClient = ArbiClient['fetch']\n\nexport type DocumentToolsNoticeKind = 'success' | 'error' | 'info' | 'warning'\n\nexport interface DocumentToolsNoticeOptions {\n /** A second line under the message. */\n description?: string\n /** One action button on the notice (\"Email it\"). */\n action?: { label: string; onClick: () => void }\n}\n\nexport type DocumentToolsNotify = (\n message: string,\n kind: DocumentToolsNoticeKind,\n options?: DocumentToolsNoticeOptions\n) => void\n\nexport interface DocumentToolsUser {\n /** The name marks are authored as and the signer's name is prefilled with. */\n name: string\n /** The sign-in email: signing re-derives the user's key from it and the password. */\n email?: string | null\n /** The user's id (usr-*): which fields of a signature request are theirs. */\n externalId?: string | null\n}\n\n/** What changed about a document, so the host can refresh its own lists and caches. */\nexport type DocumentChange =\n /** A version's markup got its first mark or lost its last one. */\n | 'markup'\n /** A signature was added: the document has a new current version. */\n | 'signed'\n /** A new document was made from it (a frozen copy). The ids are the NEW documents. */\n | 'copy'\n /** A new version was saved (the Word editor's Save version): the document's current version. */\n | 'version'\n\n/**\n * The `/v1/document/upload` query, typed from the API schema: `derived_from` is a list (a\n * production set is derived from every document in it), `shared` a boolean.\n */\nexport type DocumentUploadQuery = NonNullable<operations['upload_documents']['parameters']['query']>\n\nexport interface DocumentUploadRequest {\n file: File\n /** `/v1/document/upload` query: `derived_from`, `derived_role`, `shared`, `folder`. */\n query: DocumentUploadQuery\n}\n\n/**\n * The upload query as a URL query string, for a host that posts the upload itself (an XHR with\n * progress): a list repeats its key (`derived_from=a&derived_from=b`), empty values are left out.\n */\nexport function uploadQueryString(query: DocumentUploadQuery): string {\n const params = new URLSearchParams()\n for (const [key, value] of Object.entries(query)) {\n if (value === null || value === undefined) continue\n for (const item of Array.isArray(value) ? value : [value]) params.append(key, String(item))\n }\n return params.toString()\n}\n\nexport interface DocumentToolsEnvironment {\n client: DocumentToolsClient\n /**\n * The deployment domain the user's keys are derived for. Needed for signing. Default: the one\n * the host's `Arbi` computes (`arbi.getDeploymentDomain()`), if any.\n */\n deploymentDomain?: string\n /** The signed-in user; marks are authored as \"You\" without one, and signing is unavailable. */\n user?: DocumentToolsUser | null\n /** Surface a transient message. Default: none (errors still show inline where they can). */\n notify?: DocumentToolsNotify\n /** Open a document or a version reference (`doc-…@v2`): the copy just made, the signed copy. */\n openDocument?: (documentRef: string) => void\n /**\n * Documents changed on the server (see {@link DocumentChange}); refresh the host's lists. The\n * tools wait for it before opening the document, so a copy is listed when it opens.\n */\n onDocumentsChanged?: (documentIds: string[], change: DocumentChange) => void | Promise<void>\n /** Upload a derived copy. Default: `POST /v1/document/upload` through `client`. */\n uploadDocument?: (\n request: DocumentUploadRequest\n ) => Promise<{ doc_ext_ids?: string[] } | undefined>\n /** Save a file to the user's computer. Default: a temporary download link. */\n saveFile?: (blob: Blob, fileName: string) => void\n /** Email a document (offered once it is signed). Omitted: no \"Email it\". */\n emailDocument?: (documentRef: string) => void\n /**\n * The public page that checks a signature (the certificate) in this app. When given, \"View\n * certificate\" opens it in preference to the backend's `certificate_url` (which is on the\n * deployment domain, like the link embedded in the signed PDF). Without it: the backend's\n * `certificate_url`, else `/verify/{reference}` on this origin.\n */\n certificateUrl?: (reference: string) => string\n}\n\n/** The environment with every default filled in. */\nexport interface ResolvedDocumentToolsEnvironment extends DocumentToolsEnvironment {\n prepareFileShare: (documentId: string) => Promise<void>\n registerBeforeFileShare: (documentId: string, flush: () => Promise<void>) => () => void\n notify: DocumentToolsNotify\n saveFile: (blob: Blob, fileName: string) => void\n uploadDocument: (\n request: DocumentUploadRequest\n ) => Promise<{ doc_ext_ids?: string[] } | undefined>\n}\n\n/**\n * Save a blob through a temporary `<a download>`. The object URL is revoked a minute later, not at\n * once: revoking straight after `click()` can cancel the download (Safari, and large files\n * elsewhere) before the browser has read the blob.\n */\nexport function downloadBlob(blob: Blob, fileName: string): void {\n const url = URL.createObjectURL(blob)\n const a = document.createElement('a')\n a.href = url\n a.download = fileName\n document.body.appendChild(a)\n a.click()\n a.remove()\n setTimeout(() => URL.revokeObjectURL(url), 60_000)\n}\n\n/** The default upload: multipart `files` to `/v1/document/upload` through the API client. */\nexport function clientUpload(client: DocumentToolsClient) {\n return async ({ file, query }: DocumentUploadRequest) => {\n const formData = new FormData()\n formData.append('files', file)\n const { data, response } = await client.POST('/v1/document/upload', {\n params: { query },\n // The schema types the multipart body as `{ files: string[] }`; the FormData is sent as is.\n body: formData as unknown as { files: string[] },\n bodySerializer: () => formData,\n })\n if (!response.ok) throw new Error(`Upload failed with status ${response.status}`)\n return data\n }\n}\n\nexport function defaultCertificateUrl(reference: string): string {\n const origin = typeof location === 'undefined' ? '' : location.origin\n return `${origin}/verify/${encodeURIComponent(reference)}`\n}\n\n/**\n * Where \"View certificate\" goes for a signature: the host's `certificateUrl(reference)` when it\n * gives one, else the `certificate_url` the backend returned, else `/verify/{reference}` here.\n */\nexport function certificateLink(\n signature: { reference: string; certificate_url?: string | null },\n certificateUrl?: (reference: string) => string\n): string {\n if (certificateUrl) return certificateUrl(signature.reference)\n return signature.certificate_url || defaultCertificateUrl(signature.reference)\n}\n\nconst DocumentToolsContext = createContext<ResolvedDocumentToolsEnvironment | null>(null)\n\nexport interface DocumentToolsProviderProps extends DocumentToolsEnvironment {\n children: ReactNode\n}\n\nexport function DocumentToolsProvider({ children, ...env }: DocumentToolsProviderProps) {\n const arbiDeploymentDomain = useDeploymentDomain()\n const guards = useRef(new Map<string, () => Promise<void>>())\n const pendingFlushes = useRef(new Map<string, Promise<void>>())\n const registerBeforeFileShare = useCallback((id: string, flush: () => Promise<void>) => {\n guards.current.set(id, flush)\n return () => {\n if (guards.current.get(id) !== flush) return\n guards.current.delete(id)\n const pending = flush()\n pendingFlushes.current.set(id, pending)\n void pending.then(\n () => {\n if (pendingFlushes.current.get(id) === pending) pendingFlushes.current.delete(id)\n },\n () => {}\n )\n }\n }, [])\n const prepareFileShare = useCallback(async (id: string) => {\n const guard = guards.current.get(id)\n if (guard) {\n await guard()\n pendingFlushes.current.delete(id)\n } else await pendingFlushes.current.get(id)\n }, [])\n const {\n client,\n deploymentDomain,\n user,\n notify,\n openDocument,\n onDocumentsChanged,\n uploadDocument,\n saveFile,\n emailDocument,\n certificateUrl,\n } = env\n const value = useMemo<ResolvedDocumentToolsEnvironment>(\n () => ({\n client,\n prepareFileShare,\n registerBeforeFileShare,\n deploymentDomain: deploymentDomain ?? arbiDeploymentDomain,\n user,\n openDocument,\n onDocumentsChanged,\n emailDocument,\n notify: notify ?? (() => {}),\n saveFile: saveFile ?? downloadBlob,\n uploadDocument: uploadDocument ?? clientUpload(client),\n certificateUrl,\n }),\n [\n client,\n prepareFileShare,\n registerBeforeFileShare,\n deploymentDomain,\n arbiDeploymentDomain,\n user,\n notify,\n openDocument,\n onDocumentsChanged,\n uploadDocument,\n saveFile,\n emailDocument,\n certificateUrl,\n ]\n )\n return <DocumentToolsContext.Provider value={value}>{children}</DocumentToolsContext.Provider>\n}\n\n/** The host's environment, or `null` outside a `<DocumentToolsProvider>`. */\nexport function useOptionalDocumentTools(): ResolvedDocumentToolsEnvironment | null {\n return useContext(DocumentToolsContext)\n}\n\n/** The host's environment; throws outside a `<DocumentToolsProvider>`. */\nexport function useDocumentTools(): ResolvedDocumentToolsEnvironment {\n const env = useContext(DocumentToolsContext)\n if (!env) throw new Error('The document tools must be used within a <DocumentToolsProvider>')\n return env\n}\n","/**\n * A document's bytes, through the host's API client: the PDF the viewer and the tools draw on\n * (`/view`: the file itself for a PDF, its PDF rendering for a Word or text file) and the stored\n * file (`/download`). Either takes a document id or a version reference `doc-…@v{n}`.\n */\n\nimport { parseVersionRef } from '../artifacts/versions'\nimport type { DocumentToolsClient } from './environment'\n\nexport interface DocumentFetchOptions {\n /** The version to fetch. Default: the one `documentRef` names, else the current version. */\n version?: number | null\n workspaceExtId?: string\n signal?: AbortSignal\n}\n\n/** A document's bytes could not be fetched; `status` is the HTTP status. */\nexport class DocumentFetchError extends Error {\n readonly status: number\n constructor(message: string, status: number) {\n super(message)\n this.name = 'DocumentFetchError'\n this.status = status\n }\n}\n\nasync function fetchDocumentBytes(\n client: DocumentToolsClient,\n endpoint: '/v1/document/{document_ext_id}/view' | '/v1/document/{document_ext_id}/download',\n documentRef: string,\n options: DocumentFetchOptions,\n headers: Record<string, string>,\n what: string\n): Promise<{ blob: Blob; response: Response }> {\n const ref = parseVersionRef(documentRef)\n const version = options.version ?? ref.version\n const { data, response } = await client.GET(endpoint, {\n params: {\n path: { document_ext_id: ref.docId },\n query: {\n ...(version ? { version } : {}),\n ...(options.workspaceExtId ? { workspace_ext_id: options.workspaceExtId } : {}),\n },\n },\n headers,\n parseAs: 'blob',\n signal: options.signal,\n })\n if (!response.ok || !(data instanceof Blob)) {\n throw new DocumentFetchError(\n `${what} could not be loaded (${response.status})`,\n response.status\n )\n }\n return { blob: data, response }\n}\n\n/**\n * The file name a `Content-Disposition` header gives, or `undefined`. Prefers the RFC 5987\n * `filename*=UTF-8''…` form (percent-encoded, any script) over the plain `filename=`.\n */\nexport function contentDispositionFileName(header: string | null | undefined): string | undefined {\n if (!header) return undefined\n const extended = /filename\\*\\s*=\\s*(?:[\\w-]+)?'[^']*'([^;]+)/i.exec(header)\n if (extended) {\n try {\n return decodeURIComponent(extended[1].trim().replace(/^\"|\"$/g, '')) || undefined\n } catch {\n // A malformed escape: fall back to the plain parameter.\n }\n }\n const plain = /filename\\s*=\\s*(\"((?:[^\"\\\\]|\\\\.)*)\"|[^;]+)/i.exec(header)\n if (!plain) return undefined\n const name = plain[2] !== undefined ? plain[2].replace(/\\\\(.)/g, '$1') : plain[1].trim()\n return name || undefined\n}\n\n/**\n * The PDF of a document version: `GET /v1/document/{id}/view?version=` with\n * `Accept: application/pdf`. Throws a {@link DocumentFetchError} when there is none (yet).\n */\nexport async function fetchDocumentPdf(\n client: DocumentToolsClient,\n documentRef: string,\n options: DocumentFetchOptions = {}\n): Promise<Blob> {\n const { blob } = await fetchDocumentBytes(\n client,\n '/v1/document/{document_ext_id}/view',\n documentRef,\n options,\n { Accept: 'application/pdf' },\n 'The PDF'\n )\n return blob\n}\n\n/**\n * The stored file of a document version, as uploaded: `GET /v1/document/{id}/download`. When the\n * server names the file (`Content-Disposition`), the result is a `File` carrying that name.\n */\nexport async function fetchDocumentFile(\n client: DocumentToolsClient,\n documentRef: string,\n options: DocumentFetchOptions = {}\n): Promise<Blob | File> {\n const { blob, response } = await fetchDocumentBytes(\n client,\n '/v1/document/{document_ext_id}/download',\n documentRef,\n options,\n {},\n 'The file'\n )\n const name = contentDispositionFileName(response.headers.get('Content-Disposition'))\n return name ? new File([blob], name, { type: blob.type }) : blob\n}\n","/**\n * \"Download with markup\": a document version's markup PDF, the PDF with its annotations as native\n * PDF annotations (comments, highlights, stamps, unapplied redactions), which Acrobat and Preview\n * show. The plain Download serves the original. Kept apart from the annotation layer code so a\n * documents list can offer it without loading the annotation tools.\n *\n * A SIGNED version is locked: nothing but a further signature changes it. Its markup stays in the\n * separate markup layer (a title beside the signature, say) and is never written into its PDF, so\n * it has no \"Download with markup\"; the plain Download is the signed file as it is.\n */\n\nimport type { DocumentToolsClient } from './environment'\n\ninterface DocumentVersions {\n current_version?: number | null\n versions?: Array<{ n: number; markup_count?: number | null; reason?: string | null }> | null\n}\n\n/** Why \"Download with markup\" is off for a signed version. */\nexport const SIGNED_LOCKED_REASON =\n \"Signed documents can't be changed — download the signed file instead\"\n\n/** Whether a version (default: the current one) is a signed copy, per its version entry. */\nexport function isSignedVersion(doc: DocumentVersions, version?: number): boolean {\n const n = version ?? doc.current_version ?? 1\n return (doc.versions ?? []).some((v) => v.n === n && v.reason === 'signed')\n}\n\nexport class MarkupDownloadError extends Error {\n constructor(\n message: string,\n readonly status?: number\n ) {\n super(message)\n this.name = 'MarkupDownloadError'\n }\n}\n\n/** Whether a document's current version has markup (per its version entries). */\nexport function currentHasMarkup(doc: DocumentVersions): boolean {\n const n = doc.current_version ?? 1\n return (doc.versions ?? []).some((v) => v.n === n && (v.markup_count ?? 0) > 0)\n}\n\n/** Fetch a version's markup PDF (default: the current version's). */\nexport async function fetchMarkupPdf(\n client: DocumentToolsClient,\n documentId: string,\n version?: number,\n workspaceExtId?: string\n): Promise<{ blob: Blob; fileName: string }> {\n const { data, response } = await client.GET('/v1/document/{document_ext_id}/markup/pdf', {\n params: {\n path: { document_ext_id: documentId },\n query: {\n ...(version ? { version } : {}),\n ...(workspaceExtId ? { workspace_ext_id: workspaceExtId } : {}),\n },\n },\n parseAs: 'blob',\n })\n if (!response.ok || !data) {\n throw new MarkupDownloadError(\n response.status === 404\n ? 'This document has no markup yet'\n : // The server refuses a signed version: its PDF takes no more changes.\n response.status === 409\n ? SIGNED_LOCKED_REASON\n : 'The markup could not be downloaded',\n response.status\n )\n }\n const disposition = response.headers.get('content-disposition') ?? ''\n const utf8 = /filename\\*=UTF-8''([^;]+)/i.exec(disposition)?.[1]\n const plain = /filename=\"([^\"]+)\"/i.exec(disposition)?.[1]\n const fileName = utf8 ? decodeURIComponent(utf8) : (plain ?? 'markup.pdf')\n return { blob: data as Blob, fileName }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/document-tools/environment.tsx","../src/document-tools/document-pdf.ts","../src/document-tools/markup-download.ts"],"names":["createContext","useDeploymentDomain","useRef","useCallback","useMemo","jsx","useContext","parseVersionRef"],"mappings":";;;;;;;AAmEO,SAAS,kBAAkB,KAAA,EAAoC;AACpE,EAAA,MAAM,MAAA,GAAS,IAAI,eAAA,EAAgB;AACnC,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA,EAAG;AAChD,IAAA,IAAI,KAAA,KAAU,IAAA,IAAQ,KAAA,KAAU,MAAA,EAAW;AAC3C,IAAA,KAAA,MAAW,IAAA,IAAQ,KAAA,CAAM,OAAA,CAAQ,KAAK,IAAI,KAAA,GAAQ,CAAC,KAAK,CAAA,EAAG,MAAA,CAAO,MAAA,CAAO,GAAA,EAAK,MAAA,CAAO,IAAI,CAAC,CAAA;AAAA,EAC5F;AACA,EAAA,OAAO,OAAO,QAAA,EAAS;AACzB;AAqDO,SAAS,YAAA,CAAa,MAAY,QAAA,EAAwB;AAC/D,EAAA,MAAM,GAAA,GAAM,GAAA,CAAI,eAAA,CAAgB,IAAI,CAAA;AACpC,EAAA,MAAM,CAAA,GAAI,QAAA,CAAS,aAAA,CAAc,GAAG,CAAA;AACpC,EAAA,CAAA,CAAE,IAAA,GAAO,GAAA;AACT,EAAA,CAAA,CAAE,QAAA,GAAW,QAAA;AACb,EAAA,QAAA,CAAS,IAAA,CAAK,YAAY,CAAC,CAAA;AAC3B,EAAA,CAAA,CAAE,KAAA,EAAM;AACR,EAAA,CAAA,CAAE,MAAA,EAAO;AACT,EAAA,UAAA,CAAW,MAAM,GAAA,CAAI,eAAA,CAAgB,GAAG,GAAG,GAAM,CAAA;AACnD;AAGO,SAAS,aAAa,MAAA,EAA6B;AACxD,EAAA,OAAO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I,cAAA,GAAiB,EAAE,gBAAA,EAAkB,cAAA,KAAmB;AAAC;AAC/D,KACF;AAAA,IACA,OAAA,EAAS;AAAA,GACV,CAAA;AACD,EAAA,IAAI,CAAC,QAAA,CAAS,EAAA,IAAM,CAAC,IAAA,EAAM;AACzB,IAAA,MAAM,IAAI,mBAAA;AAAA,MACR,QAAA,CAAS,WAAW,GAAA,GAChB,iCAAA;AAAA;AAAA,QAEA,QAAA,CAAS,MAAA,KAAW,GAAA,GAClB,oBAAA,GACA;AAAA,OAAA;AAAA,MACN,QAAA,CAAS;AAAA,KACX;AAAA,EACF;AACA,EAAA,MAAM,WAAA,GAAc,QAAA,CAAS,OAAA,CAAQ,GAAA,CAAI,qBAAqB,CAAA,IAAK,EAAA;AACnE,EAAA,MAAM,IAAA,GAAO,4BAAA,CAA6B,IAAA,CAAK,WAAW,IAAI,CAAC,CAAA;AAC/D,EAAA,MAAM,KAAA,GAAQ,qBAAA,CAAsB,IAAA,CAAK,WAAW,IAAI,CAAC,CAAA;AACzD,EAAA,MAAM,QAAA,GAAW,IAAA,GAAO,kBAAA,CAAmB,IAAI,IAAK,KAAA,IAAS,YAAA;AAC7D,EAAA,OAAO,EAAE,IAAA,EAAM,IAAA,EAAc,QAAA,EAAS;AACxC","file":"chunk-XBY4RLC6.cjs","sourcesContent":["/**\n * The host app's side of the document tools (markup, freeze, e-signing, versions): the one place\n * the tools reach the app. They never import a store, a router, a toast library or app API code;\n * the host passes what it has to `<DocumentToolsProvider>` and every optional field has a default.\n *\n * `client` is an openapi-fetch client for the ARBI API (`ArbiClient['fetch']` from\n * `@arbidocs/client`, or `arbi.getClient().fetch` from an `@arbidocs/sdk` `Arbi`), signed in with the\n * user's session; it carries the auth.\n */\n\nimport { createContext, useCallback, useContext, useMemo, useRef, type ReactNode } from 'react'\nimport type { ArbiClient, operations } from '@arbidocs/client'\nimport { useDeploymentDomain } from '../useArbi'\n\nexport type DocumentToolsClient = ArbiClient['fetch']\n\nexport type DocumentToolsNoticeKind = 'success' | 'error' | 'info' | 'warning'\n\nexport interface DocumentToolsNoticeOptions {\n /** A second line under the message. */\n description?: string\n /** One action button on the notice (\"Email it\"). */\n action?: { label: string; onClick: () => void }\n}\n\nexport type DocumentToolsNotify = (\n message: string,\n kind: DocumentToolsNoticeKind,\n options?: DocumentToolsNoticeOptions\n) => void\n\nexport interface DocumentToolsUser {\n /** The name marks are authored as and the signer's name is prefilled with. */\n name: string\n /** The sign-in email: signing re-derives the user's key from it and the password. */\n email?: string | null\n /** The user's id (usr-*): which fields of a signature request are theirs. */\n externalId?: string | null\n}\n\n/** What changed about a document, so the host can refresh its own lists and caches. */\nexport type DocumentChange =\n /** A version's markup got its first mark or lost its last one. */\n | 'markup'\n /** A signature was added: the document has a new current version. */\n | 'signed'\n /** A new document was made from it (a frozen copy). The ids are the NEW documents. */\n | 'copy'\n /** A new version was saved (the Word editor's Save version): the document's current version. */\n | 'version'\n\n/**\n * The `/v1/document/upload` query, typed from the API schema: `derived_from` is a list (a\n * production set is derived from every document in it), `shared` a boolean.\n */\nexport type DocumentUploadQuery = NonNullable<operations['upload_documents']['parameters']['query']>\n\nexport interface DocumentUploadRequest {\n file: File\n /** `/v1/document/upload` query: `derived_from`, `derived_role`, `shared`, `folder`. */\n query: DocumentUploadQuery\n}\n\n/**\n * The upload query as a URL query string, for a host that posts the upload itself (an XHR with\n * progress): a list repeats its key (`derived_from=a&derived_from=b`), empty values are left out.\n */\nexport function uploadQueryString(query: DocumentUploadQuery): string {\n const params = new URLSearchParams()\n for (const [key, value] of Object.entries(query)) {\n if (value === null || value === undefined) continue\n for (const item of Array.isArray(value) ? value : [value]) params.append(key, String(item))\n }\n return params.toString()\n}\n\nexport interface DocumentToolsEnvironment {\n client: DocumentToolsClient\n /**\n * The deployment domain the user's keys are derived for. Needed for signing. Default: the one\n * the host's `Arbi` computes (`arbi.getDeploymentDomain()`), if any.\n */\n deploymentDomain?: string\n /** The signed-in user; marks are authored as \"You\" without one, and signing is unavailable. */\n user?: DocumentToolsUser | null\n /** Surface a transient message. Default: none (errors still show inline where they can). */\n notify?: DocumentToolsNotify\n /** Open a document or a version reference (`doc-…@v2`): the copy just made, the signed copy. */\n openDocument?: (documentRef: string) => void\n /**\n * Documents changed on the server (see {@link DocumentChange}); refresh the host's lists. The\n * tools wait for it before opening the document, so a copy is listed when it opens.\n */\n onDocumentsChanged?: (documentIds: string[], change: DocumentChange) => void | Promise<void>\n /** Upload a derived copy. Default: `POST /v1/document/upload` through `client`. */\n uploadDocument?: (\n request: DocumentUploadRequest\n ) => Promise<{ doc_ext_ids?: string[] } | undefined>\n /** Save a file to the user's computer. Default: a temporary download link. */\n saveFile?: (blob: Blob, fileName: string) => void\n /** Email a document (offered once it is signed). Omitted: no \"Email it\". */\n emailDocument?: (documentRef: string) => void\n /**\n * The public page that checks a signature (the certificate) in this app. When given, \"View\n * certificate\" opens it in preference to the backend's `certificate_url` (which is on the\n * deployment domain, like the link embedded in the signed PDF). Without it: the backend's\n * `certificate_url`, else `/verify/{reference}` on this origin.\n */\n certificateUrl?: (reference: string) => string\n}\n\n/** The environment with every default filled in. */\nexport interface ResolvedDocumentToolsEnvironment extends DocumentToolsEnvironment {\n prepareFileShare: (documentId: string) => Promise<void>\n registerBeforeFileShare: (documentId: string, flush: () => Promise<void>) => () => void\n notify: DocumentToolsNotify\n saveFile: (blob: Blob, fileName: string) => void\n uploadDocument: (\n request: DocumentUploadRequest\n ) => Promise<{ doc_ext_ids?: string[] } | undefined>\n}\n\n/**\n * Save a blob through a temporary `<a download>`. The object URL is revoked a minute later, not at\n * once: revoking straight after `click()` can cancel the download (Safari, and large files\n * elsewhere) before the browser has read the blob.\n */\nexport function downloadBlob(blob: Blob, fileName: string): void {\n const url = URL.createObjectURL(blob)\n const a = document.createElement('a')\n a.href = url\n a.download = fileName\n document.body.appendChild(a)\n a.click()\n a.remove()\n setTimeout(() => URL.revokeObjectURL(url), 60_000)\n}\n\n/** The default upload: multipart `files` to `/v1/document/upload` through the API client. */\nexport function clientUpload(client: DocumentToolsClient) {\n return async ({ file, query }: DocumentUploadRequest) => {\n const formData = new FormData()\n formData.append('files', file)\n const { data, response } = await client.POST('/v1/document/upload', {\n params: { query },\n // The schema types the multipart body as `{ files: string[] }`; the FormData is sent as is.\n body: formData as unknown as { files: string[] },\n bodySerializer: () => formData,\n })\n if (!response.ok) throw new Error(`Upload failed with status ${response.status}`)\n return data\n }\n}\n\nexport function defaultCertificateUrl(reference: string): string {\n const origin = typeof location === 'undefined' ? '' : location.origin\n return `${origin}/verify/${encodeURIComponent(reference)}`\n}\n\n/**\n * Where \"View certificate\" goes for a signature: the host's `certificateUrl(reference)` when it\n * gives one, else the `certificate_url` the backend returned, else `/verify/{reference}` here.\n */\nexport function certificateLink(\n signature: { reference: string; certificate_url?: string | null },\n certificateUrl?: (reference: string) => string\n): string {\n if (certificateUrl) return certificateUrl(signature.reference)\n return signature.certificate_url || defaultCertificateUrl(signature.reference)\n}\n\nconst DocumentToolsContext = createContext<ResolvedDocumentToolsEnvironment | null>(null)\n\nexport interface DocumentToolsProviderProps extends DocumentToolsEnvironment {\n children: ReactNode\n}\n\nexport function DocumentToolsProvider({ children, ...env }: DocumentToolsProviderProps) {\n const arbiDeploymentDomain = useDeploymentDomain()\n const guards = useRef(new Map<string, () => Promise<void>>())\n const pendingFlushes = useRef(new Map<string, Promise<void>>())\n const registerBeforeFileShare = useCallback((id: string, flush: () => Promise<void>) => {\n guards.current.set(id, flush)\n return () => {\n if (guards.current.get(id) !== flush) return\n guards.current.delete(id)\n const pending = flush()\n pendingFlushes.current.set(id, pending)\n void pending.then(\n () => {\n if (pendingFlushes.current.get(id) === pending) pendingFlushes.current.delete(id)\n },\n () => {}\n )\n }\n }, [])\n const prepareFileShare = useCallback(async (id: string) => {\n const guard = guards.current.get(id)\n if (guard) {\n await guard()\n pendingFlushes.current.delete(id)\n } else await pendingFlushes.current.get(id)\n }, [])\n const {\n client,\n deploymentDomain,\n user,\n notify,\n openDocument,\n onDocumentsChanged,\n uploadDocument,\n saveFile,\n emailDocument,\n certificateUrl,\n } = env\n const value = useMemo<ResolvedDocumentToolsEnvironment>(\n () => ({\n client,\n prepareFileShare,\n registerBeforeFileShare,\n deploymentDomain: deploymentDomain ?? arbiDeploymentDomain,\n user,\n openDocument,\n onDocumentsChanged,\n emailDocument,\n notify: notify ?? (() => {}),\n saveFile: saveFile ?? downloadBlob,\n uploadDocument: uploadDocument ?? clientUpload(client),\n certificateUrl,\n }),\n [\n client,\n prepareFileShare,\n registerBeforeFileShare,\n deploymentDomain,\n arbiDeploymentDomain,\n user,\n notify,\n openDocument,\n onDocumentsChanged,\n uploadDocument,\n saveFile,\n emailDocument,\n certificateUrl,\n ]\n )\n return <DocumentToolsContext.Provider value={value}>{children}</DocumentToolsContext.Provider>\n}\n\n/** The host's environment, or `null` outside a `<DocumentToolsProvider>`. */\nexport function useOptionalDocumentTools(): ResolvedDocumentToolsEnvironment | null {\n return useContext(DocumentToolsContext)\n}\n\n/** The host's environment; throws outside a `<DocumentToolsProvider>`. */\nexport function useDocumentTools(): ResolvedDocumentToolsEnvironment {\n const env = useContext(DocumentToolsContext)\n if (!env) throw new Error('The document tools must be used within a <DocumentToolsProvider>')\n return env\n}\n","/**\n * A document's bytes, through the host's API client: the PDF the viewer and the tools draw on\n * (`/view`: the file itself for a PDF, its PDF rendering for a Word or text file) and the stored\n * file (`/download`). Either takes a document id or a version reference `doc-…@v{n}`.\n */\n\nimport { parseVersionRef } from '../artifacts/versions'\nimport type { DocumentToolsClient } from './environment'\n\nexport interface DocumentFetchOptions {\n /** The version to fetch. Default: the one `documentRef` names, else the current version. */\n version?: number | null\n workspaceExtId?: string\n signal?: AbortSignal\n}\n\n/** A document's bytes could not be fetched; `status` is the HTTP status. */\nexport class DocumentFetchError extends Error {\n readonly status: number\n constructor(message: string, status: number) {\n super(message)\n this.name = 'DocumentFetchError'\n this.status = status\n }\n}\n\nasync function fetchDocumentBytes(\n client: DocumentToolsClient,\n endpoint: '/v1/document/{document_ext_id}/view' | '/v1/document/{document_ext_id}/download',\n documentRef: string,\n options: DocumentFetchOptions,\n headers: Record<string, string>,\n what: string\n): Promise<{ blob: Blob; response: Response }> {\n const ref = parseVersionRef(documentRef)\n const version = options.version ?? ref.version\n const { data, response } = await client.GET(endpoint, {\n params: {\n path: { document_ext_id: ref.docId },\n query: {\n ...(version ? { version } : {}),\n ...(options.workspaceExtId ? { workspace_ext_id: options.workspaceExtId } : {}),\n },\n },\n headers,\n parseAs: 'blob',\n signal: options.signal,\n })\n if (!response.ok || !(data instanceof Blob)) {\n throw new DocumentFetchError(\n `${what} could not be loaded (${response.status})`,\n response.status\n )\n }\n return { blob: data, response }\n}\n\n/**\n * The file name a `Content-Disposition` header gives, or `undefined`. Prefers the RFC 5987\n * `filename*=UTF-8''…` form (percent-encoded, any script) over the plain `filename=`.\n */\nexport function contentDispositionFileName(header: string | null | undefined): string | undefined {\n if (!header) return undefined\n const extended = /filename\\*\\s*=\\s*(?:[\\w-]+)?'[^']*'([^;]+)/i.exec(header)\n if (extended) {\n try {\n return decodeURIComponent(extended[1].trim().replace(/^\"|\"$/g, '')) || undefined\n } catch {\n // A malformed escape: fall back to the plain parameter.\n }\n }\n const plain = /filename\\s*=\\s*(\"((?:[^\"\\\\]|\\\\.)*)\"|[^;]+)/i.exec(header)\n if (!plain) return undefined\n const name = plain[2] !== undefined ? plain[2].replace(/\\\\(.)/g, '$1') : plain[1].trim()\n return name || undefined\n}\n\n/**\n * The PDF of a document version: `GET /v1/document/{id}/view?version=` with\n * `Accept: application/pdf`. Throws a {@link DocumentFetchError} when there is none (yet).\n */\nexport async function fetchDocumentPdf(\n client: DocumentToolsClient,\n documentRef: string,\n options: DocumentFetchOptions = {}\n): Promise<Blob> {\n const { blob } = await fetchDocumentBytes(\n client,\n '/v1/document/{document_ext_id}/view',\n documentRef,\n options,\n { Accept: 'application/pdf' },\n 'The PDF'\n )\n return blob\n}\n\n/**\n * The stored file of a document version, as uploaded: `GET /v1/document/{id}/download`. When the\n * server names the file (`Content-Disposition`), the result is a `File` carrying that name.\n */\nexport async function fetchDocumentFile(\n client: DocumentToolsClient,\n documentRef: string,\n options: DocumentFetchOptions = {}\n): Promise<Blob | File> {\n const { blob, response } = await fetchDocumentBytes(\n client,\n '/v1/document/{document_ext_id}/download',\n documentRef,\n options,\n {},\n 'The file'\n )\n const name = contentDispositionFileName(response.headers.get('Content-Disposition'))\n return name ? new File([blob], name, { type: blob.type }) : blob\n}\n","/**\n * \"Download with markup\": a document version's markup PDF, the PDF with its annotations as native\n * PDF annotations (comments, highlights, stamps, unapplied redactions), which Acrobat and Preview\n * show. The plain Download serves the original. Kept apart from the annotation layer code so a\n * documents list can offer it without loading the annotation tools.\n *\n * A SIGNED version is locked: nothing but a further signature changes it. Its markup stays in the\n * separate markup layer (a title beside the signature, say) and is never written into its PDF, so\n * it has no \"Download with markup\"; the plain Download is the signed file as it is.\n */\n\nimport type { DocumentToolsClient } from './environment'\n\ninterface DocumentVersions {\n current_version?: number | null\n versions?: Array<{ n: number; markup_count?: number | null; reason?: string | null }> | null\n}\n\n/** Why \"Download with markup\" is off for a signed version. */\nexport const SIGNED_LOCKED_REASON =\n \"Signed documents can't be changed — download the signed file instead\"\n\n/** Whether a version (default: the current one) is a signed copy, per its version entry. */\nexport function isSignedVersion(doc: DocumentVersions, version?: number): boolean {\n const n = version ?? doc.current_version ?? 1\n return (doc.versions ?? []).some((v) => v.n === n && v.reason === 'signed')\n}\n\nexport class MarkupDownloadError extends Error {\n constructor(\n message: string,\n readonly status?: number\n ) {\n super(message)\n this.name = 'MarkupDownloadError'\n }\n}\n\n/** Whether a document's current version has markup (per its version entries). */\nexport function currentHasMarkup(doc: DocumentVersions): boolean {\n const n = doc.current_version ?? 1\n return (doc.versions ?? []).some((v) => v.n === n && (v.markup_count ?? 0) > 0)\n}\n\n/** Fetch a version's markup PDF (default: the current version's). */\nexport async function fetchMarkupPdf(\n client: DocumentToolsClient,\n documentId: string,\n version?: number,\n workspaceExtId?: string\n): Promise<{ blob: Blob; fileName: string }> {\n const { data, response } = await client.GET('/v1/document/{document_ext_id}/markup/pdf', {\n params: {\n path: { document_ext_id: documentId },\n query: {\n ...(version ? { version } : {}),\n ...(workspaceExtId ? { workspace_ext_id: workspaceExtId } : {}),\n },\n },\n parseAs: 'blob',\n })\n if (!response.ok || !data) {\n throw new MarkupDownloadError(\n response.status === 404\n ? 'This document has no markup yet'\n : // The server refuses a signed version: its PDF takes no more changes.\n response.status === 409\n ? SIGNED_LOCKED_REASON\n : 'The markup could not be downloaded',\n response.status\n )\n }\n const disposition = response.headers.get('content-disposition') ?? ''\n const utf8 = /filename\\*=UTF-8''([^;]+)/i.exec(disposition)?.[1]\n const plain = /filename=\"([^\"]+)\"/i.exec(disposition)?.[1]\n const fileName = utf8 ? decodeURIComponent(utf8) : (plain ?? 'markup.pdf')\n return { blob: data as Blob, fileName }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunk5FQB5F2F_cjs = require('./chunk-5FQB5F2F.cjs');
|
|
4
4
|
var zustand = require('zustand');
|
|
5
5
|
var react = require('react');
|
|
6
6
|
var reactQuery = require('@tanstack/react-query');
|
|
@@ -17,10 +17,10 @@ function subscribeDocumentRows(listener) {
|
|
|
17
17
|
}
|
|
18
18
|
function getCachedDocuments(qc, workspaceId) {
|
|
19
19
|
if (!workspaceId) return void 0;
|
|
20
|
-
return qc.getQueryData(
|
|
20
|
+
return qc.getQueryData(chunk5FQB5F2F_cjs.arbiQueryKeys.documents(workspaceId));
|
|
21
21
|
}
|
|
22
22
|
function cachedLists(qc) {
|
|
23
|
-
return qc.getQueriesData({ queryKey:
|
|
23
|
+
return qc.getQueriesData({ queryKey: chunk5FQB5F2F_cjs.arbiQueryKeys.allDocuments() }).flatMap(
|
|
24
24
|
([key, data]) => typeof key[2] === "string" && Array.isArray(data) ? [[key[2], data]] : []
|
|
25
25
|
);
|
|
26
26
|
}
|
|
@@ -46,13 +46,13 @@ function patchDocuments(qc, reducer, workspaceId) {
|
|
|
46
46
|
for (const [id, before] of lists) {
|
|
47
47
|
const after = reducer(before);
|
|
48
48
|
if (after === before) continue;
|
|
49
|
-
qc.setQueryData(
|
|
49
|
+
qc.setQueryData(chunk5FQB5F2F_cjs.arbiQueryKeys.documents(id), after);
|
|
50
50
|
const change = diffRows(id, before, after);
|
|
51
51
|
const beforeById = new Map(before.map((doc) => [doc.external_id, doc]));
|
|
52
52
|
if (change.update.some(
|
|
53
53
|
(doc) => doc.current_version !== beforeById.get(doc.external_id)?.current_version
|
|
54
54
|
))
|
|
55
|
-
void qc.invalidateQueries({ queryKey:
|
|
55
|
+
void qc.invalidateQueries({ queryKey: chunk5FQB5F2F_cjs.arbiQueryKeys.allDocumentVersions() });
|
|
56
56
|
if (change.add.length || change.update.length || change.remove.length)
|
|
57
57
|
for (const listener of rowListeners) listener(change);
|
|
58
58
|
}
|
|
@@ -80,11 +80,11 @@ function upsertDocuments(qc, documents, workspaceId) {
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
function setCachedDocument(qc, doc) {
|
|
83
|
-
qc.setQueryData(
|
|
83
|
+
qc.setQueryData(chunk5FQB5F2F_cjs.arbiQueryKeys.document(doc.external_id), doc);
|
|
84
84
|
}
|
|
85
85
|
function patchCachedDocument(qc, docId, reducer) {
|
|
86
|
-
const current = qc.getQueryData(
|
|
87
|
-
if (current) qc.setQueryData(
|
|
86
|
+
const current = qc.getQueryData(chunk5FQB5F2F_cjs.arbiQueryKeys.document(docId));
|
|
87
|
+
if (current) qc.setQueryData(chunk5FQB5F2F_cjs.arbiQueryKeys.document(docId), reducer(current));
|
|
88
88
|
}
|
|
89
89
|
function dropTagFromCachedDocuments(qc, tagId) {
|
|
90
90
|
const strip = (doc) => {
|
|
@@ -101,9 +101,9 @@ function dropTagFromCachedDocuments(qc, tagId) {
|
|
|
101
101
|
}
|
|
102
102
|
function forgetDocuments(qc, docIds) {
|
|
103
103
|
for (const id of docIds) {
|
|
104
|
-
qc.removeQueries({ queryKey:
|
|
105
|
-
qc.removeQueries({ queryKey:
|
|
106
|
-
qc.removeQueries({ queryKey:
|
|
104
|
+
qc.removeQueries({ queryKey: chunk5FQB5F2F_cjs.arbiQueryKeys.document(id) });
|
|
105
|
+
qc.removeQueries({ queryKey: chunk5FQB5F2F_cjs.arbiQueryKeys.documentVersions(id) });
|
|
106
|
+
qc.removeQueries({ queryKey: chunk5FQB5F2F_cjs.arbiQueryKeys.parsedDocument(id) });
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
var useEntityExtractionStore = zustand.create(() => ({ docIds: [] }));
|
|
@@ -173,7 +173,7 @@ function useCapturingWorkspace(mutation, capture) {
|
|
|
173
173
|
// src/tags.ts
|
|
174
174
|
function workspaceOfTag(qc, tagId) {
|
|
175
175
|
for (const [key, tags] of qc.getQueriesData({
|
|
176
|
-
queryKey:
|
|
176
|
+
queryKey: chunk5FQB5F2F_cjs.arbiQueryKeys.allTags()
|
|
177
177
|
})) {
|
|
178
178
|
if (Array.isArray(tags) && tags.some((t) => t.external_id === tagId))
|
|
179
179
|
return key[2] ?? null;
|
|
@@ -184,23 +184,23 @@ function openWorkspaceId(arbi) {
|
|
|
184
184
|
return arbi.hasWorkspace ? arbi.getWorkspaceId() : null;
|
|
185
185
|
}
|
|
186
186
|
function patchWorkspaceTags(qc, workspaceId, reducer) {
|
|
187
|
-
const key =
|
|
187
|
+
const key = chunk5FQB5F2F_cjs.arbiQueryKeys.tags(workspaceId);
|
|
188
188
|
const current = qc.getQueryData(key);
|
|
189
189
|
if (!current) return;
|
|
190
190
|
const next = reducer(current);
|
|
191
191
|
if (next !== current) qc.setQueryData(key, next);
|
|
192
192
|
}
|
|
193
193
|
function invalidateTagTables(qc, workspaceId) {
|
|
194
|
-
return qc.invalidateQueries({ queryKey:
|
|
194
|
+
return qc.invalidateQueries({ queryKey: chunk5FQB5F2F_cjs.arbiQueryKeys.tagLists(workspaceId) });
|
|
195
195
|
}
|
|
196
196
|
function invalidateTagData(qc, workspaceId) {
|
|
197
197
|
return Promise.all([
|
|
198
|
-
qc.invalidateQueries({ queryKey:
|
|
199
|
-
qc.invalidateQueries({ queryKey:
|
|
198
|
+
qc.invalidateQueries({ queryKey: chunk5FQB5F2F_cjs.arbiQueryKeys.tags(workspaceId) }),
|
|
199
|
+
qc.invalidateQueries({ queryKey: chunk5FQB5F2F_cjs.arbiQueryKeys.facts(workspaceId) })
|
|
200
200
|
]);
|
|
201
201
|
}
|
|
202
202
|
function useInvalidateTagData() {
|
|
203
|
-
const arbi =
|
|
203
|
+
const arbi = chunk5FQB5F2F_cjs.useArbi();
|
|
204
204
|
const qc = reactQuery.useQueryClient();
|
|
205
205
|
return react.useCallback(() => {
|
|
206
206
|
const workspaceId = openWorkspaceId(arbi);
|
|
@@ -227,19 +227,19 @@ function settleChangedTag(qc, tag) {
|
|
|
227
227
|
}
|
|
228
228
|
var replayableTagMutations = [
|
|
229
229
|
{
|
|
230
|
-
mutationKey:
|
|
230
|
+
mutationKey: chunk5FQB5F2F_cjs.arbiMutationKeys.createTag(),
|
|
231
231
|
// In the workspace it was made in (named on the request), opened for this session first.
|
|
232
232
|
run: (client, input) => inWorkspace(primeOnClient(client), input.workspaceId, () => browser.tags.createTag(client, input)),
|
|
233
233
|
settle: (qc, created) => settleCreatedTag(qc, created)
|
|
234
234
|
}
|
|
235
235
|
];
|
|
236
236
|
function useCreateTag() {
|
|
237
|
-
const arbi =
|
|
237
|
+
const arbi = chunk5FQB5F2F_cjs.useArbi();
|
|
238
238
|
const qc = reactQuery.useQueryClient();
|
|
239
239
|
const capture = (input) => input.workspaceId || !arbi.hasWorkspace ? input : { ...input, workspaceId: arbi.getWorkspaceId() };
|
|
240
240
|
return useCapturingWorkspace(
|
|
241
241
|
reactQuery.useMutation({
|
|
242
|
-
mutationKey:
|
|
242
|
+
mutationKey: chunk5FQB5F2F_cjs.arbiMutationKeys.createTag(),
|
|
243
243
|
mutationFn: (input) => inWorkspace(primeOnArbi(arbi), input.workspaceId, () => arbi.tags.create(input)),
|
|
244
244
|
onSuccess: (created) => settleCreatedTag(qc, created),
|
|
245
245
|
...QUEUED_WRITE_RETRY
|
|
@@ -253,7 +253,7 @@ function useIsCreatingTag() {
|
|
|
253
253
|
(name) => {
|
|
254
254
|
const wanted = name.trim().toLowerCase();
|
|
255
255
|
return qc.getMutationCache().findAll({
|
|
256
|
-
mutationKey:
|
|
256
|
+
mutationKey: chunk5FQB5F2F_cjs.arbiMutationKeys.createTag(),
|
|
257
257
|
predicate: (m) => m.state.status === "pending" && m.state.variables?.name.trim().toLowerCase() === wanted
|
|
258
258
|
}).length > 0;
|
|
259
259
|
},
|
|
@@ -261,19 +261,19 @@ function useIsCreatingTag() {
|
|
|
261
261
|
);
|
|
262
262
|
}
|
|
263
263
|
function useUpdateTag() {
|
|
264
|
-
const arbi =
|
|
264
|
+
const arbi = chunk5FQB5F2F_cjs.useArbi();
|
|
265
265
|
const qc = reactQuery.useQueryClient();
|
|
266
266
|
return reactQuery.useMutation({
|
|
267
|
-
mutationKey:
|
|
267
|
+
mutationKey: chunk5FQB5F2F_cjs.arbiMutationKeys.updateTag(),
|
|
268
268
|
mutationFn: ({ tagId, change }) => arbi.tags.update(tagId, change),
|
|
269
269
|
onSuccess: (tag) => settleChangedTag(qc, tag)
|
|
270
270
|
});
|
|
271
271
|
}
|
|
272
272
|
function useSetTagValues() {
|
|
273
|
-
const arbi =
|
|
273
|
+
const arbi = chunk5FQB5F2F_cjs.useArbi();
|
|
274
274
|
const qc = reactQuery.useQueryClient();
|
|
275
275
|
return reactQuery.useMutation({
|
|
276
|
-
mutationKey:
|
|
276
|
+
mutationKey: chunk5FQB5F2F_cjs.arbiMutationKeys.updateTag(),
|
|
277
277
|
mutationFn: ({
|
|
278
278
|
tagId,
|
|
279
279
|
values
|
|
@@ -282,10 +282,10 @@ function useSetTagValues() {
|
|
|
282
282
|
});
|
|
283
283
|
}
|
|
284
284
|
function useDeleteTag() {
|
|
285
|
-
const arbi =
|
|
285
|
+
const arbi = chunk5FQB5F2F_cjs.useArbi();
|
|
286
286
|
const qc = reactQuery.useQueryClient();
|
|
287
287
|
return reactQuery.useMutation({
|
|
288
|
-
mutationKey:
|
|
288
|
+
mutationKey: chunk5FQB5F2F_cjs.arbiMutationKeys.deleteTag(),
|
|
289
289
|
mutationFn: (tagId) => arbi.tags.delete(tagId),
|
|
290
290
|
// The tag's own workspace (the cached list holding it), else the one open when it is sent: a
|
|
291
291
|
// switch while the delete runs must not patch the next workspace's list.
|
|
@@ -301,33 +301,33 @@ function useDeleteTag() {
|
|
|
301
301
|
);
|
|
302
302
|
return Promise.all([
|
|
303
303
|
invalidateTagTables(qc, workspaceId),
|
|
304
|
-
qc.invalidateQueries({ queryKey:
|
|
304
|
+
qc.invalidateQueries({ queryKey: chunk5FQB5F2F_cjs.arbiQueryKeys.facts(workspaceId) })
|
|
305
305
|
]);
|
|
306
306
|
}
|
|
307
307
|
});
|
|
308
308
|
}
|
|
309
309
|
function useExtractEntities() {
|
|
310
|
-
const arbi =
|
|
310
|
+
const arbi = chunk5FQB5F2F_cjs.useArbi();
|
|
311
311
|
return reactQuery.useMutation({
|
|
312
|
-
mutationKey:
|
|
312
|
+
mutationKey: chunk5FQB5F2F_cjs.arbiMutationKeys.extractEntities(),
|
|
313
313
|
mutationFn: (docIds) => arbi.tags.extractEntities(docIds),
|
|
314
314
|
onSuccess: (data) => startEntityExtraction(data.doc_ext_ids)
|
|
315
315
|
});
|
|
316
316
|
}
|
|
317
317
|
function useTagKindSchema(kind, options) {
|
|
318
|
-
const arbi =
|
|
318
|
+
const arbi = chunk5FQB5F2F_cjs.useArbi();
|
|
319
319
|
const workspaceId = openWorkspaceId(arbi) ?? "";
|
|
320
320
|
return reactQuery.useQuery({
|
|
321
|
-
queryKey:
|
|
321
|
+
queryKey: chunk5FQB5F2F_cjs.arbiQueryKeys.tagKind(workspaceId, kind ?? ""),
|
|
322
322
|
queryFn: () => arbi.readInWorkspace(workspaceId, () => arbi.tagKinds.get(kind)),
|
|
323
323
|
enabled: (options?.enabled ?? true) && !!kind && !!workspaceId
|
|
324
324
|
});
|
|
325
325
|
}
|
|
326
326
|
function useUpdateTagKindSchema() {
|
|
327
|
-
const arbi =
|
|
327
|
+
const arbi = chunk5FQB5F2F_cjs.useArbi();
|
|
328
328
|
const qc = reactQuery.useQueryClient();
|
|
329
329
|
return reactQuery.useMutation({
|
|
330
|
-
mutationKey:
|
|
330
|
+
mutationKey: chunk5FQB5F2F_cjs.arbiMutationKeys.updateTagKindSchema(),
|
|
331
331
|
mutationFn: ({
|
|
332
332
|
kind,
|
|
333
333
|
fields
|
|
@@ -338,7 +338,7 @@ function useUpdateTagKindSchema() {
|
|
|
338
338
|
onSuccess: (schema, _input, context) => {
|
|
339
339
|
const workspaceId = context?.workspaceId;
|
|
340
340
|
if (!workspaceId) return;
|
|
341
|
-
qc.setQueryData(
|
|
341
|
+
qc.setQueryData(chunk5FQB5F2F_cjs.arbiQueryKeys.tagKind(workspaceId, schema.kind), schema);
|
|
342
342
|
return invalidateTagData(qc, workspaceId);
|
|
343
343
|
}
|
|
344
344
|
});
|
|
@@ -548,11 +548,11 @@ function openWorkspaceId2(arbi) {
|
|
|
548
548
|
return arbi.hasWorkspace ? arbi.getWorkspaceId() : null;
|
|
549
549
|
}
|
|
550
550
|
function useDocuments(workspaceId, options) {
|
|
551
|
-
const arbi =
|
|
551
|
+
const arbi = chunk5FQB5F2F_cjs.useArbi();
|
|
552
552
|
const qc = reactQuery.useQueryClient();
|
|
553
553
|
const workspace = workspaceId ?? openWorkspaceId2(arbi) ?? "";
|
|
554
554
|
return reactQuery.useQuery({
|
|
555
|
-
queryKey:
|
|
555
|
+
queryKey: chunk5FQB5F2F_cjs.arbiQueryKeys.documents(workspace),
|
|
556
556
|
queryFn: ({ signal }) => {
|
|
557
557
|
if (openWorkspaceId2(arbi) !== workspace)
|
|
558
558
|
return Promise.reject(new Error("The selected workspace changed."));
|
|
@@ -570,9 +570,9 @@ function processingInterval(doc) {
|
|
|
570
570
|
return doc?.status && !FINISHED_DOCUMENT_STATUSES.has(doc.status) ? DOCUMENT_STATUS_POLL_MS : false;
|
|
571
571
|
}
|
|
572
572
|
function useDocument(docId, options) {
|
|
573
|
-
const arbi =
|
|
573
|
+
const arbi = chunk5FQB5F2F_cjs.useArbi();
|
|
574
574
|
return reactQuery.useQuery({
|
|
575
|
-
queryKey:
|
|
575
|
+
queryKey: chunk5FQB5F2F_cjs.arbiQueryKeys.document(docId ?? ""),
|
|
576
576
|
queryFn: async () => (await arbi.documents.get([docId]))[0] ?? null,
|
|
577
577
|
enabled: (options?.enabled ?? true) && !!docId && arbi.isLoggedIn,
|
|
578
578
|
refetchInterval: options?.pollWhileProcessing ? (query) => processingInterval(query.state.data) : false
|
|
@@ -580,10 +580,10 @@ function useDocument(docId, options) {
|
|
|
580
580
|
}
|
|
581
581
|
var SIMILARITY_THRESHOLD = 0.98;
|
|
582
582
|
function useSimilarDocuments(options) {
|
|
583
|
-
const arbi =
|
|
583
|
+
const arbi = chunk5FQB5F2F_cjs.useArbi();
|
|
584
584
|
const workspace = openWorkspaceId2(arbi) ?? "";
|
|
585
585
|
return reactQuery.useQuery({
|
|
586
|
-
queryKey:
|
|
586
|
+
queryKey: chunk5FQB5F2F_cjs.arbiQueryKeys.similarDocuments(workspace, SIMILARITY_THRESHOLD),
|
|
587
587
|
queryFn: () => arbi.readInWorkspace(
|
|
588
588
|
workspace,
|
|
589
589
|
() => arbi.documents.similar({ threshold: SIMILARITY_THRESHOLD })
|
|
@@ -644,7 +644,7 @@ async function refreshDocuments(qc, arbi, docIds) {
|
|
|
644
644
|
}
|
|
645
645
|
function useRefreshDocuments() {
|
|
646
646
|
const qc = reactQuery.useQueryClient();
|
|
647
|
-
const arbi =
|
|
647
|
+
const arbi = chunk5FQB5F2F_cjs.useArbi();
|
|
648
648
|
return react.useCallback((docIds) => refreshDocuments(qc, arbi, docIds), [qc, arbi]);
|
|
649
649
|
}
|
|
650
650
|
function reconcileTagCounts(qc, fresh) {
|
|
@@ -744,5 +744,5 @@ exports.useSimilarDocuments = useSimilarDocuments;
|
|
|
744
744
|
exports.useTagKindSchema = useTagKindSchema;
|
|
745
745
|
exports.useUpdateTag = useUpdateTag;
|
|
746
746
|
exports.useUpdateTagKindSchema = useUpdateTagKindSchema;
|
|
747
|
-
//# sourceMappingURL=chunk-
|
|
748
|
-
//# sourceMappingURL=chunk-
|
|
747
|
+
//# sourceMappingURL=chunk-ZFTWH6B6.cjs.map
|
|
748
|
+
//# sourceMappingURL=chunk-ZFTWH6B6.cjs.map
|