@protobase/ui 0.112.0 → 0.112.2
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/account/messages.d.ts +2 -2
- package/dist/app/app.js +4 -3
- package/dist/app/change-confirm/messages.d.ts +2 -2
- package/dist/app/charts/messages.d.ts +2 -2
- package/dist/app/comments/messages.d.ts +2 -2
- package/dist/app/confirm-sign-in-messages.d.ts +2 -2
- package/dist/app/create/messages.d.ts +2 -2
- package/dist/app/custom-section.d.ts +1 -1
- package/dist/app/delete/messages.d.ts +2 -2
- package/dist/app/displays/list-cards.d.ts +1 -1
- package/dist/app/displays/messages.d.ts +2 -2
- package/dist/app/embedded-list/messages.d.ts +2 -2
- package/dist/app/export/messages.d.ts +2 -2
- package/dist/app/field-messages.d.ts +2 -2
- package/dist/app/field-types/custom-step-container/messages.d.ts +2 -2
- package/dist/app/field-types/runner-install/messages.d.ts +2 -2
- package/dist/app/field-types/widget-part.d.ts +1 -1
- package/dist/app/field-types/workflow/definition.d.ts +1 -1
- package/dist/app/field-types/workflow/messages.d.ts +2 -2
- package/dist/app/field-types/workflow-page/messages.d.ts +2 -2
- package/dist/app/field-types/workflow-run/messages.d.ts +2 -2
- package/dist/app/file-viewers/messages.d.ts +2 -2
- package/dist/app/focus/messages.d.ts +2 -2
- package/dist/app/gallery/messages.d.ts +2 -2
- package/dist/app/hand-order/messages.d.ts +2 -2
- package/dist/app/history/messages.d.ts +2 -2
- package/dist/app/hold-start-for-first-loads.d.ts +12 -0
- package/dist/app/hold-start-for-first-loads.js +43 -0
- package/dist/app/import/messages.d.ts +2 -2
- package/dist/app/index.html +17 -0
- package/dist/app/list-edit/messages.d.ts +2 -2
- package/dist/app/list-messages.d.ts +2 -2
- package/dist/app/messages.d.ts +2 -2
- package/dist/app/meta-gate-messages.d.ts +2 -2
- package/dist/app/new-version/messages.d.ts +2 -2
- package/dist/app/pages/custom-boundary.d.ts +1 -1
- package/dist/app/pages/custom-chosen.d.ts +1 -1
- package/dist/app/pages/messages.d.ts +2 -2
- package/dist/app/record-chart/messages.d.ts +2 -2
- package/dist/app/record-messages.d.ts +2 -2
- package/dist/app/record-mode/shown-layout.d.ts +1 -1
- package/dist/app/record-row/messages.d.ts +2 -2
- package/dist/app/related-cards/messages.d.ts +2 -2
- package/dist/app/runtime/messages.d.ts +2 -2
- package/dist/app/saved/messages.d.ts +2 -2
- package/dist/app/saved/saved-list.d.ts +1 -1
- package/dist/app/saved/use-favorite.d.ts +1 -1
- package/dist/app/searches/messages.d.ts +2 -2
- package/dist/app/searches/use-save-search.d.ts +1 -1
- package/dist/app/splash-hold.d.ts +1 -0
- package/dist/app/splash-hold.js +1 -1
- package/dist/app/start-screen.d.ts +9 -0
- package/dist/app/start-screen.js +10 -1
- package/dist/app-shell/index.d.ts +2 -1
- package/dist/app-shell/index.js +2 -1
- package/dist/app-shell/logo-tap.d.ts +11 -0
- package/dist/app-shell/logo-tap.js +16 -0
- package/dist/app-shell/messages.d.ts +2 -2
- package/dist/app-shell/sidebar.js +2 -0
- package/dist/assistant-dock/messages.d.ts +2 -2
- package/dist/auth/messages.d.ts +2 -2
- package/dist/calls/messages.d.ts +2 -2
- package/dist/chat/messages.d.ts +2 -2
- package/dist/compact-table/messages.d.ts +2 -2
- package/dist/data-grid/column-spec.d.ts +1 -1
- package/dist/data-grid/messages.d.ts +2 -2
- package/dist/filter-panel/messages.d.ts +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/inline-child-table/messages.d.ts +2 -2
- package/dist/invitations/messages.d.ts +2 -2
- package/dist/mailbox/messages.d.ts +2 -2
- package/dist/markdown/messages.d.ts +2 -2
- package/dist/mentions/messages.d.ts +2 -2
- package/dist/mocks/customers.d.ts +2 -2
- package/dist/mocks/invoices.d.ts +3 -3
- package/dist/mocks/orders.d.ts +3 -3
- package/dist/notifications/bell/messages.d.ts +2 -2
- package/dist/organizations/messages.d.ts +2 -2
- package/dist/package.js +1 -1
- package/dist/plugins/before-sign-in.d.ts +1 -1
- package/dist/primitives/messages.d.ts +2 -2
- package/dist/record-view/messages.d.ts +2 -2
- package/dist/record-view/use-autosave.d.ts +1 -1
- package/dist/shell/assets/app-BbB79rGo.js +16 -0
- package/dist/shell/assets/{graph-view-BfYs6ayj.js → graph-view-DkLJGbAM.js} +2 -2
- package/dist/shell/assets/{html-viewer-C0QI0zaR.js → html-viewer-CFhG0dfK.js} +2 -2
- package/dist/shell/assets/{in-place-form-y_QOwKOi.js → in-place-form-CSZ6XQwe.js} +2 -2
- package/dist/shell/assets/{index-CW7p8b2W.js → index-CGHo79rF.js} +2 -2
- package/dist/shell/assets/{maplibre-BGA6uo19.js → maplibre-CU0FwYOr.js} +2 -2
- package/dist/shell/assets/{markdown-content-DFkH88LY.js → markdown-content-HfXJkQCt.js} +2 -2
- package/dist/shell/assets/{record-map-4A4R4ckl.js → record-map-BSsmZmbf.js} +2 -2
- package/dist/shell/assets/{records-map-BsE-mBBB.js → records-map-CCHa0cjg.js} +2 -2
- package/dist/shell/assets/{run-trace-view-CSoeovIo.js → run-trace-view-ovkKBP1m.js} +2 -2
- package/dist/shell/assets/{search-picker-DAcPiMQA.js → search-picker-DuhRI954.js} +2 -2
- package/dist/shell/assets/shared-protobase-ui-Mk2r7Wf4.js +2 -0
- package/dist/shell/assets/{step-catalog-BuUwSkK9.js → step-catalog-DxGx8yvI.js} +2 -2
- package/dist/shell/assets/{step-panel-CoOoYMdA.js → step-panel-BLv6M8fk.js} +2 -2
- package/dist/shell/assets/{use-app-address-D50fN1nP.js → use-app-address-B6k3dkV0.js} +2 -2
- package/dist/shell/assets/{use-sibling-page-Ccwp2gM-.js → use-sibling-page-DLjl_l8i.js} +3 -3
- package/dist/shell/assets/{workflow-canvas-CNpgSr9v.js → workflow-canvas-DLDb_g1s.js} +2 -2
- package/dist/shell/assets/{workflow-graph-editor-z38xU0ar.js → workflow-graph-editor-DZHTqa3R.js} +2 -2
- package/dist/shell/assets/workflow-workbench-CG8xTDx0.js +4 -0
- package/dist/shell/index.html +8 -5
- package/dist/shell/protobase.shell.json +2 -2
- package/dist/shell/protobase.sw.js +2 -2
- package/dist/shell-source-maps/assets/app-BbB79rGo.js.map +1 -0
- package/dist/shell-source-maps/assets/{graph-view-BfYs6ayj.js.map → graph-view-DkLJGbAM.js.map} +1 -1
- package/dist/shell-source-maps/assets/{html-viewer-C0QI0zaR.js.map → html-viewer-CFhG0dfK.js.map} +1 -1
- package/dist/shell-source-maps/assets/{in-place-form-y_QOwKOi.js.map → in-place-form-CSZ6XQwe.js.map} +1 -1
- package/dist/shell-source-maps/assets/{index-CW7p8b2W.js.map → index-CGHo79rF.js.map} +1 -1
- package/dist/shell-source-maps/assets/{maplibre-BGA6uo19.js.map → maplibre-CU0FwYOr.js.map} +1 -1
- package/dist/shell-source-maps/assets/{markdown-content-DFkH88LY.js.map → markdown-content-HfXJkQCt.js.map} +1 -1
- package/dist/shell-source-maps/assets/{record-map-4A4R4ckl.js.map → record-map-BSsmZmbf.js.map} +1 -1
- package/dist/shell-source-maps/assets/{records-map-BsE-mBBB.js.map → records-map-CCHa0cjg.js.map} +1 -1
- package/dist/shell-source-maps/assets/{run-trace-view-CSoeovIo.js.map → run-trace-view-ovkKBP1m.js.map} +1 -1
- package/dist/shell-source-maps/assets/{search-picker-DAcPiMQA.js.map → search-picker-DuhRI954.js.map} +1 -1
- package/dist/shell-source-maps/assets/shared-protobase-ui-Mk2r7Wf4.js.map +1 -0
- package/dist/shell-source-maps/assets/{step-catalog-BuUwSkK9.js.map → step-catalog-DxGx8yvI.js.map} +1 -1
- package/dist/shell-source-maps/assets/{step-panel-CoOoYMdA.js.map → step-panel-BLv6M8fk.js.map} +1 -1
- package/dist/shell-source-maps/assets/{use-app-address-D50fN1nP.js.map → use-app-address-B6k3dkV0.js.map} +1 -1
- package/dist/shell-source-maps/assets/{use-sibling-page-Ccwp2gM-.js.map → use-sibling-page-DLjl_l8i.js.map} +1 -1
- package/dist/shell-source-maps/assets/{workflow-canvas-CNpgSr9v.js.map → workflow-canvas-DLDb_g1s.js.map} +1 -1
- package/dist/shell-source-maps/assets/{workflow-graph-editor-z38xU0ar.js.map → workflow-graph-editor-DZHTqa3R.js.map} +1 -1
- package/dist/shell-source-maps/assets/{workflow-workbench-CAk5M4iT.js.map → workflow-workbench-CG8xTDx0.js.map} +1 -1
- package/dist/status/messages.d.ts +2 -2
- package/dist/users/messages.d.ts +2 -2
- package/package.json +5 -5
- package/dist/shell/assets/app-CYep6fHL.js +0 -16
- package/dist/shell/assets/shared-protobase-ui-BudhYj2I.js +0 -2
- package/dist/shell/assets/workflow-workbench-CAk5M4iT.js +0 -4
- package/dist/shell-source-maps/assets/app-CYep6fHL.js.map +0 -1
- package/dist/shell-source-maps/assets/shared-protobase-ui-BudhYj2I.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-sibling-page-Ccwp2gM-.js","names":["useState","useCallback","useRef","useMemo","useMemo","n","a","t","__toESM","require_react","require_jsx_runtime","useQueries","useQuery","useResourceClient","fileNamed","useViewedResource","cn","import_react","ofDocument","state","nonce","initial","useDocumentState","setState","update","next","linkAttribute","frameBridge","frameSandbox","frameCsp","scripts","frameNonce","byte","removed","frameDocument","page","html","element","policy","referrer","bridge","rounding","nextFrameHeight","previous","viewport","height","frameBox","size","maxHeight","frameMessage","frame","event","data","links","import_jsx_runtime","noLinks","scrollToPlace","bars","top","HtmlFrame","shown","setHeight","shownAgain","setShownAgain","key","loads","receive","message","onLink","loaded","times","box","className","climbs","value","siblingReference","reference","unescaped","decoded","siblings","error","rewriteSrcset","parts","candidate","resolved","resolve","rewriteCssUrls","text","whole","externalUrl","url","sources","rewriteResources","set","attribute","resource","parse","referencedSiblings","found","sibling","siblingPage","contents","link","href","target","address","siblingsKey","FileReadError","status","useFileText","client","file","response","dataUrl","reader","reject","bytes","useSiblingContents","reads","files","read","index","useSiblingPage","siblingKey","contentsKey","ready"],"sources":["../../../src/app/file-viewers/document-state.ts","../../../src/app/file-viewers/frame-bridge.ts","../../../src/app/file-viewers/frame-policy.ts","../../../src/app/file-viewers/frame-document.ts","../../../src/app/file-viewers/frame-height.ts","../../../src/app/file-viewers/frame-messages.ts","../../../src/app/file-viewers/html-frame.tsx","../../../src/app/file-viewers/sibling-references.ts","../../../src/app/file-viewers/sibling-page.ts","../../../src/app/file-viewers/siblings-key.ts","../../../src/app/file-viewers/use-file-text.ts","../../../src/app/file-viewers/use-sibling-contents.ts","../../../src/app/file-viewers/use-sibling-page.ts"],"sourcesContent":["import { useCallback, useState } from 'react'\n\n/** A value of an `HtmlFrame` that belongs to the document it shows, by that document's `nonce`. */\nexport type DocumentState<T> = { nonce: string; value: T }\n\n/** `state`'s value for the document `nonce`; `initial` for another document, which starts again. */\nexport const ofDocument = <T>(state: DocumentState<T> | undefined, nonce: string, initial: T) => (state?.nonce === nonce ? state.value : initial)\n\n/** State that starts again at `initial` (a constant) each time the frame shows another document, `nonce`. */\nexport const useDocumentState = <T>(nonce: string, initial: T) => {\n const [state, setState] = useState<DocumentState<T>>()\n const update = useCallback((next: (value: T) => T) => setState((state) => ({ nonce, value: next(ofDocument(state, nonce, initial)) })), [nonce, initial])\n return [ofDocument(state, nonce, initial), update] as const\n}\n","/** The attribute an `HtmlFrame` page's link carries, the index of its target in the frame's `links`. */\nexport const linkAttribute = 'data-protobase-link'\n\n/**\n * The script an `HtmlFrame` runs in its page, the only one a page it does not trust runs. A click on a link carrying\n * `linkAttribute` posts its index to the app, with whether it asks for a new tab. A click on a link to a place on the\n * page (`#results`) moves the focus there and posts how far down the page it is, since the app's page scrolls rather\n * than the frame. A\n * click on any other link does nothing, so the page never leaves the frame. It also posts the page's height, so the\n * frame grows with it.\n */\nexport const frameBridge = `(() => {\n const post = (message) => parent.postMessage({ protobase: 'html-frame', ...message }, '*')\n const place = (hash) => {\n const name = decodeURIComponent(hash.slice(1))\n const target = name === '' || name === 'top' ? null : document.getElementById(name) ?? document.getElementsByName(name)[0]\n if (!target) return 0\n if (target.tabIndex < 0 && !target.hasAttribute('tabindex')) target.setAttribute('tabindex', '-1')\n target.focus({ preventScroll: true })\n return target.getBoundingClientRect().top + window.scrollY\n }\n const follow = (event) => {\n const link = event.target instanceof Element ? event.target.closest('a, area') : null\n if (!link) return\n event.preventDefault()\n const index = link.getAttribute('${linkAttribute}')\n const href = link.getAttribute('href') ?? ''\n if (index !== null) post({ link: Number(index), newTab: event.button === 1 || event.ctrlKey || event.metaKey || event.shiftKey })\n else if (href.startsWith('#') && event.button === 0) post({ scroll: place(href) })\n }\n document.addEventListener('click', follow, true)\n document.addEventListener('auxclick', (event) => event.button === 1 && follow(event), true)\n const height = () => post({ height: document.documentElement.getBoundingClientRect().height })\n new ResizeObserver(height).observe(document.documentElement)\n})()`\n","/**\n * What an `HtmlFrame`'s page may run: `'bridge'`, only the frame's own link script, for a page it does not trust, such\n * as an uploaded file; `'trusted-page'`, also the page's own inline scripts, for a page an app generates itself.\n */\nexport type FrameScripts = 'bridge' | 'trusted-page'\n\n/**\n * The frame's sandbox: scripts, so the link script runs, and nothing else. Never `allow-same-origin`, so the page has an\n * opaque origin and cannot reach the app's cookies, storage or DOM; no top navigation, forms or popups.\n */\nexport const frameSandbox = 'allow-scripts'\n\n/**\n * The page's Content-Security-Policy. With `'bridge'` only the script carrying `nonce` runs: the page's own scripts,\n * inline handlers and `javascript:` links do not. `'trusted-page'` runs inline scripts and so carries no nonce, which\n * would turn `'unsafe-inline'` off. Either way nothing loads from the network: images, media, styles and fonts come\n * from `data:` URLs, and nothing is fetched, framed or submitted.\n */\nexport const frameCsp = (scripts: FrameScripts, nonce: string) =>\n [\n \"default-src 'none'\",\n scripts === 'bridge' ? `script-src 'nonce-${nonce}'` : \"script-src 'unsafe-inline'\",\n 'img-src data:',\n 'media-src data:',\n \"style-src 'unsafe-inline' data:\",\n 'font-src data:',\n \"base-uri 'none'\",\n \"form-action 'none'\",\n ].join('; ')\n\n/** A fresh 128-bit nonce, as hex. */\nexport const frameNonce = () => Array.from(crypto.getRandomValues(new Uint8Array(16)), (byte) => byte.toString(16).padStart(2, '0')).join('')\n","import { frameBridge } from './frame-bridge'\nimport { frameCsp, type FrameScripts } from './frame-policy'\n\n// What a page could use to leave its policy or the frame: its own `http-equiv` (a refresh, another policy), a `<base>`,\n// and `<noscript>`, read as markup here but as text in the frame, where scripts run, so markup hidden in it would come\n// out after these were removed.\nconst removed = 'meta[http-equiv], base, noscript'\n\n/**\n * `html` as the page an `HtmlFrame` shows: parsed, cleared of `removed`, and opened with the frame's own policy, a\n * referrer policy that sends no address on, and the frame's link script carrying `nonce`. They are the first nodes of\n * `<head>`, put there in the parsed document, so the policy covers everything of the page, even a script written before\n * its `<html>`.\n */\nexport const frameDocument = (html: string, scripts: FrameScripts, nonce: string) => {\n const page = new DOMParser().parseFromString(html, 'text/html')\n for (const element of page.querySelectorAll(removed)) element.remove()\n\n const policy = page.createElement('meta')\n policy.httpEquiv = 'Content-Security-Policy'\n policy.content = frameCsp(scripts, nonce)\n const referrer = page.createElement('meta')\n referrer.name = 'referrer'\n referrer.content = 'no-referrer'\n const bridge = page.createElement('script')\n if (scripts === 'bridge') bridge.setAttribute('nonce', nonce)\n bridge.textContent = frameBridge\n page.head.prepend(policy, referrer, bridge)\n\n return `<!doctype html>${page.documentElement.outerHTML}`\n}\n","/**\n * How tall an `HtmlFrame` is for its page: `measured`, the height its page last reported, with the frame's own height\n * when it did, or `fixed`, for a page sized by the frame's viewport, such as one `100vh` tall or `height: 100%` with a\n * margin, which reports a taller page each time the frame takes its last height.\n */\nexport type FrameHeight = { kind: 'measured'; height: number; viewport: number } | { kind: 'fixed' }\n\n// Reported heights are rounded up to whole pixels.\nconst rounding = 1\n\n/**\n * The frame's height after its page reports `height` while the frame is `viewport` tall. A page whose height changed by\n * as much as the frame did since its last report is sized by the frame, and the frame stays fixed for it.\n */\nexport const nextFrameHeight = (previous: FrameHeight | undefined, height: number, viewport: number): FrameHeight => {\n if (previous?.kind === 'fixed') return previous\n if (previous && viewport !== previous.viewport && Math.abs(height - previous.height - (viewport - previous.viewport)) <= rounding) return { kind: 'fixed' }\n return { kind: 'measured', height, viewport }\n}\n\n/**\n * The frame's box: as tall as its page's measured height, or a fixed minimum while nothing is measured, for a page\n * measured 0 tall, and for a page sized by the frame. That page scrolls inside the frame, the one inner scroll box here:\n * the app's page cannot scroll content whose height depends on the frame's own.\n */\nexport const frameBox = (size: FrameHeight | undefined) =>\n size?.kind === 'measured' && size.height > 0 ? { style: { height: size.height } } : { className: 'min-h-[60vh]' }\n","/**\n * What an `HtmlFrame`'s page asks of the app: follow its link `index`, be as tall as `height` CSS pixels, or scroll to\n * the place `top` CSS pixels down the page.\n */\nexport type FrameMessage = { kind: 'link'; index: number; newTab: boolean } | { kind: 'height'; height: number } | { kind: 'scroll'; top: number }\n\n// Tall enough for a long report, short enough that a page cannot make the app's page endless.\nconst maxHeight = 100_000\n\n/**\n * The request a message event carries from the frame's own window `frame`, with a link index below `links`; `undefined`\n * for any other source or shape. Every sandboxed page's origin is `\"null\"`, so only the window itself tells them apart.\n */\nexport const frameMessage = (event: Pick<MessageEvent, 'source' | 'data'>, frame: Window | null | undefined, links: number): FrameMessage | undefined => {\n if (!frame || event.source !== frame) return\n const data: unknown = event.data\n if (typeof data !== 'object' || data === null || !('protobase' in data) || data.protobase !== 'html-frame') return\n if ('link' in data && Number.isInteger(data.link) && (data.link as number) >= 0 && (data.link as number) < links) {\n return { kind: 'link', index: data.link as number, newTab: 'newTab' in data && data.newTab === true }\n }\n if ('height' in data && typeof data.height === 'number' && Number.isFinite(data.height) && data.height >= 0) {\n return { kind: 'height', height: Math.min(Math.ceil(data.height), maxHeight) }\n }\n if ('scroll' in data && typeof data.scroll === 'number' && Number.isFinite(data.scroll)) {\n return { kind: 'scroll', top: Math.min(Math.max(Math.round(data.scroll), 0), maxHeight) }\n }\n return\n}\n","import { useEffect, useMemo, useRef } from 'react'\nimport { cn } from '../../lib/cn'\nimport { useDocumentState } from './document-state'\nimport type { ViewedFile } from './file-viewer'\nimport { frameDocument } from './frame-document'\nimport { frameBox, nextFrameHeight, type FrameHeight } from './frame-height'\nimport { frameMessage } from './frame-messages'\nimport { frameNonce, frameSandbox, type FrameScripts } from './frame-policy'\nimport type { FrameLink } from './sibling-page'\n\nconst noLinks: readonly never[] = []\n\n// Scrolls the app's page to the place `top` pixels down the page in `frame`, below the bars that stay at the top.\nconst scrollToPlace = (frame: HTMLIFrameElement, top: number) => {\n const bars = Number.parseFloat(getComputedStyle(document.documentElement).scrollPaddingTop) || 0\n window.scrollTo({ top: frame.getBoundingClientRect().top + window.scrollY + top - bars })\n}\n\ntype HtmlFrameProps<File extends ViewedFile> = {\n /** The page, a whole HTML document or a fragment. */\n html: string\n /** The frame's accessible name, such as the file's name. */\n title: string\n /** The targets of the page's links, by the index each carries (`useSiblingPage`). */\n links?: readonly FrameLink<File>[]\n /** Follows a link of the page; `newTab` when it was a middle or modified click. */\n onLink?: (link: FrameLink<File>, options: { newTab: boolean }) => void\n /**\n * `'bridge'` (the default) runs none of the page's own scripts, for a page you do not trust, such as an uploaded file;\n * `'trusted-page'` runs them, for a page your viewer generates itself. Either way the page cannot reach the app.\n */\n scripts?: FrameScripts\n className?: string\n}\n\n/**\n * A whole HTML page drawn in a sandboxed frame with an opaque origin: it cannot read the app's cookies, storage or DOM,\n * call its API as the user, load anything from the network or navigate the app's window. Its links reach the app only\n * as the index of one of `links`, which `onLink` follows. The frame is as tall as its page, so the app's page scrolls,\n * unless the page is sized by the frame (`FrameHeight`).\n */\nexport const HtmlFrame = <File extends ViewedFile>({ html, title, links = noLinks, onLink, scripts = 'bridge', className }: HtmlFrameProps<File>) => {\n const frame = useRef<HTMLIFrameElement>(null)\n const shown = useMemo(() => {\n const nonce = frameNonce()\n return { nonce, srcDoc: frameDocument(html, scripts, nonce) }\n }, [html, scripts])\n const [height, setHeight] = useDocumentState<FrameHeight | undefined>(shown.nonce, undefined)\n // A page that navigated its frame anyway is shown again once; doing so again leaves the frame empty, until another\n // document is shown.\n const [shownAgain, setShownAgain] = useDocumentState(shown.nonce, 0)\n const key = `${shown.nonce}:${shownAgain}`\n // The loads of the frame shown as `key`: its first is its page, any later one the page leaving it.\n const loads = useRef({ key, count: 0 })\n\n useEffect(() => {\n const receive = (event: MessageEvent) => {\n const message = frameMessage(event, frame.current?.contentWindow, links.length)\n const viewport = frame.current?.clientHeight\n if (message?.kind === 'height' && viewport !== undefined) setHeight((size) => nextFrameHeight(size, message.height, viewport))\n if (message?.kind === 'link') onLink?.(links[message.index]!, { newTab: message.newTab })\n if (message?.kind === 'scroll' && frame.current) scrollToPlace(frame.current, message.top)\n }\n window.addEventListener('message', receive)\n return () => window.removeEventListener('message', receive)\n }, [links, onLink, setHeight])\n\n const loaded = () => {\n if (loads.current.key !== key) loads.current = { key, count: 0 }\n loads.current.count += 1\n if (loads.current.count > 1) setShownAgain((times) => times + 1)\n }\n\n const box = frameBox(height)\n return (\n <iframe\n key={key}\n ref={frame}\n title={title}\n sandbox={frameSandbox}\n referrerPolicy=\"no-referrer\"\n // A video's own fullscreen control; a page that does not run its scripts can ask for nothing else.\n allow={scripts === 'bridge' ? 'fullscreen' : undefined}\n srcDoc={shownAgain > 1 ? '' : shown.srcDoc}\n onLoad={loaded}\n className={cn('block w-full border-0 bg-white', box.className, className)}\n style={box.style}\n />\n )\n}\n","import { fileNamed, type ViewedFile } from './file-viewer'\n\n// Whether a reference's path climbs out of its folder with a `..` segment.\nconst climbs = (value: string) => value.split(/[?#]/, 1)[0]!.split('/').includes('..')\n\n/**\n * The sibling a page's relative reference names, such as `shots/before.png` or `my%20chart.png`, by its file name\n * (`fileNamed`), as written or with its escapes read; none for an absolute or protocol-relative address, a path from\n * the root, a fragment, or a path that climbs out with `..`, written or escaped.\n */\nexport const siblingReference = <File extends ViewedFile>(siblings: readonly File[], reference: string) => {\n const value = reference.trim()\n const unescaped = decoded(value)\n if (climbs(value) || climbs(unescaped)) return\n return fileNamed(siblings, value) ?? fileNamed(siblings, unescaped)\n}\n\n// A reference with its escapes, such as `%20`, read; as it is when one is malformed.\nconst decoded = (value: string) => {\n try {\n return decodeURI(value)\n } catch (error) {\n if (error instanceof URIError) return value\n throw error\n }\n}\n\n/** `value` of a `srcset`, each candidate's address resolved on its own; a candidate `resolve` gives nothing for stays as written. */\nexport const rewriteSrcset = (value: string, resolve: (reference: string) => string | undefined) =>\n value\n .split(',')\n .map((candidate) => {\n const parts = /^(\\s*)(\\S+)([\\s\\S]*)$/.exec(candidate)\n const resolved = parts && resolve(parts[2]!)\n return parts && resolved ? `${parts[1]}${resolved}${parts[3]}` : candidate\n })\n .join(',')\n\n/** CSS `text` with each `url(...)` resolved; one `resolve` gives nothing for stays as written. */\nexport const rewriteCssUrls = (text: string, resolve: (reference: string) => string | undefined) =>\n text.replace(/url\\(\\s*(['\"]?)([^'\")]*)\\1\\s*\\)/gi, (whole, _quote: string, reference: string) => {\n const resolved = resolve(reference.trim())\n return resolved ? `url(\"${resolved}\")` : whole\n })\n\n/** An absolute `http:` or `https:` address as the URL parser reads it, else `undefined`, such as for `javascript:` or a relative path. */\nexport const externalUrl = (reference: string) => {\n if (!URL.canParse(reference)) return\n const url = new URL(reference)\n return url.protocol === 'http:' || url.protocol === 'https:' ? url.href : undefined\n}\n","import type { ViewedFile } from './file-viewer'\nimport { linkAttribute } from './frame-bridge'\nimport { externalUrl, rewriteCssUrls, rewriteSrcset, siblingReference } from './sibling-references'\n\n/** Where a link of a page in an `HtmlFrame` leads: a sibling file, or an outside `http`/`https` address. */\nexport type FrameLink<File extends ViewedFile = ViewedFile> = { kind: 'file'; file: File } | { kind: 'external'; url: string }\n\n/** A page with its references to siblings resolved, and the targets of its links, which carry their index. */\nexport type SiblingPage<File extends ViewedFile = ViewedFile> = { html: string; links: FrameLink<File>[] }\n\n// The attributes that load a file into the page, by the elements they are on.\nconst sources = ['img[src]', 'source[src]', 'video[src]', 'audio[src]', 'track[src]', 'input[src]'].join(', ')\n\n// Each reference of `page` that loads a file, set to what `resource` gives for it; one it gives nothing for stays.\nconst rewriteResources = (page: Document, resource: (reference: string) => string | undefined) => {\n const set = (element: Element, attribute: string, value: string | undefined) => value !== undefined && element.setAttribute(attribute, value)\n for (const element of page.querySelectorAll(sources)) set(element, 'src', resource(element.getAttribute('src')!))\n for (const element of page.querySelectorAll('video[poster]')) set(element, 'poster', resource(element.getAttribute('poster')!))\n for (const element of page.querySelectorAll('img[srcset], source[srcset]')) set(element, 'srcset', rewriteSrcset(element.getAttribute('srcset')!, resource))\n for (const element of page.querySelectorAll('link[href]')) set(element, 'href', resource(element.getAttribute('href')!))\n for (const element of page.querySelectorAll('image[href]')) set(element, 'href', resource(element.getAttribute('href')!))\n for (const element of page.querySelectorAll('[style]')) set(element, 'style', rewriteCssUrls(element.getAttribute('style')!, resource))\n for (const element of page.querySelectorAll('style')) element.textContent = rewriteCssUrls(element.textContent, resource)\n}\n\nconst parse = (html: string) => new DOMParser().parseFromString(html, 'text/html')\n\n/** The siblings `html` loads as images, videos, sounds, styles or fonts, each once: those a page needs read to show. */\nexport const referencedSiblings = <File extends ViewedFile>(html: string, siblings: readonly File[]) => {\n const found = new Set<File>()\n rewriteResources(parse(html), (reference) => {\n const sibling = siblingReference(siblings, reference)\n if (sibling) found.add(sibling)\n return\n })\n return [...found]\n}\n\n/** The address a page's link shows for where it leads, for the browser's link preview and copy link; `undefined` keeps its own. */\nexport type LinkAddress<File extends ViewedFile = ViewedFile> = (link: FrameLink<File>) => string | undefined\n\n/**\n * `html` with each relative reference to a sibling resolved: one that loads a file to the `data:` URL `contents` holds\n * by its stored `uri`, a link to a sibling or to an outside `http`/`https` address to an entry of `links`, showing the\n * address `address` gives it. A reference to no sibling, or to one `contents` lacks, stays as written; a link to\n * anywhere else, such as `javascript:`, loses its address. A link to a place on the page (`#top`) stays.\n */\nexport const siblingPage = <File extends ViewedFile>(html: string, siblings: readonly File[], contents: ReadonlyMap<string, string>, address?: LinkAddress<File>): SiblingPage<File> => {\n const page = parse(html)\n for (const element of page.querySelectorAll(`[${linkAttribute}]`)) element.removeAttribute(linkAttribute)\n rewriteResources(page, (reference) => {\n const sibling = siblingReference(siblings, reference)\n return sibling && contents.get(sibling.uri)\n })\n\n const links: FrameLink<File>[] = []\n for (const link of page.querySelectorAll('a[href], area[href]')) {\n const href = link.getAttribute('href')!\n if (href.startsWith('#')) continue\n link.removeAttribute('target')\n const sibling = siblingReference(siblings, href)\n const url = sibling ? undefined : externalUrl(href)\n if (!sibling && !url) {\n link.removeAttribute('href')\n continue\n }\n const target: FrameLink<File> = sibling ? { kind: 'file', file: sibling } : { kind: 'external', url: url! }\n const shown = address?.(target)\n if (shown !== undefined) link.setAttribute('href', shown)\n link.setAttribute(linkAttribute, String(links.length))\n links.push(target)\n }\n return { html: `<!doctype html>${page.documentElement.outerHTML}`, links }\n}\n","import type { ViewedFile } from './file-viewer'\n\n/**\n * A key that changes when any of `siblings` does: its stored uri, and the record key and file field a sibling carries\n * (`SiblingFile`), which its link's address names. A missing key or field is `null`.\n */\nexport const siblingsKey = <File extends ViewedFile>(siblings: readonly File[]) =>\n JSON.stringify(siblings.map((sibling) => [sibling.uri, 'key' in sibling ? sibling.key : null, 'field' in sibling ? sibling.field : null]))\n","import { useQuery } from '@tanstack/react-query'\nimport { useResourceClient } from '../../data/api-provider'\nimport type { ViewedFile } from './file-viewer'\nimport { useViewedResource } from './viewed-resource'\n\n/** A file that could not be read, with the status its link answered. */\nexport class FileReadError extends Error {\n override name = 'FileReadError'\n constructor(readonly status: number) {\n super(`The file could not be read: its link answered ${status}`)\n }\n}\n\n/**\n * The text of a file a viewer shows, read once and kept while the file is the same: a TanStack Query result keyed by\n * its resource and stored `uri`, as the link changes each time it is signed. Parse JSON from `data` yourself. It reads\n * from the API that serves the record, which sends the bytes itself whatever store holds them or wherever the file's\n * link points, up to 10 MB; a larger file fails with a 403.\n */\nexport const useFileText = (file: ViewedFile) => {\n const resource = useViewedResource()\n const client = useResourceClient(resource)\n return useQuery({\n queryKey: ['file-text', resource, file.uri],\n staleTime: Infinity,\n queryFn: async () => {\n const response = await fetch(client.fileReadUrl(resource, file))\n if (!response.ok) throw new FileReadError(response.status)\n return response.text()\n },\n })\n}\n","import { useQueries } from '@tanstack/react-query'\nimport { useResourceClient } from '../../data/api-provider'\nimport type { ViewedFile } from './file-viewer'\nimport { FileReadError } from './use-file-text'\nimport { useViewedResource } from './viewed-resource'\n\n// The bytes as a `data:` URL of the file's own type: a sandboxed page cannot load the app's `blob:` URLs, and the URL\n// holds the bytes alone, no signed link that would open the file elsewhere.\nconst dataUrl = (bytes: Blob) =>\n new Promise<string>((resolve, reject) => {\n const reader = new FileReader()\n reader.onload = () => resolve(reader.result as string)\n reader.onerror = () => reject(reader.error)\n reader.readAsDataURL(bytes)\n })\n\n/**\n * The contents of `files` as `data:` URLs by their stored `uri`, each read once from the API that serves the viewed\n * record, with the user's own rights, as `useFileText` reads, up to 10 MB each; `ready` once every read has answered. A\n * file that could not be read is left out, so what refers to it stays as written.\n */\nexport const useSiblingContents = (files: readonly ViewedFile[]) => {\n const resource = useViewedResource()\n const client = useResourceClient(resource)\n const reads = useQueries({\n queries: files.map((file) => ({\n queryKey: ['file-data-url', resource, file.uri],\n staleTime: Infinity,\n retry: false,\n queryFn: async () => {\n const response = await fetch(client.fileReadUrl(resource, file))\n if (!response.ok) throw new FileReadError(response.status)\n return dataUrl(new Blob([await response.arrayBuffer()], { type: file.type }))\n },\n })),\n })\n const contents = new Map<string, string>()\n reads.forEach((read, index) => read.data !== undefined && contents.set(files[index]!.uri, read.data))\n return { contents, ready: reads.every((read) => !read.isPending) }\n}\n","import { useMemo } from 'react'\nimport type { ViewedFile } from './file-viewer'\nimport { referencedSiblings, siblingPage, type LinkAddress, type SiblingPage } from './sibling-page'\nimport { siblingsKey } from './siblings-key'\nimport { useSiblingContents } from './use-sibling-contents'\n\n/**\n * `html`, a page a file viewer shows, with its relative references resolved to `siblings` (`siblingPage`), for an\n * `HtmlFrame`: the images, videos and styles it names read as `data:` URLs, its links to siblings and outside addresses\n * in `links`, each showing the address `address` gives it. `undefined` while `html` or those reads are pending. Use it\n * inside a file viewer, which reads them from the API that serves the viewed record.\n */\nexport const useSiblingPage = <File extends ViewedFile>(html: string | undefined, siblings: readonly File[], address?: LinkAddress<File>): SiblingPage<File> | undefined => {\n // A viewer's siblings are a new list each render: their key, and the contents read, say when they changed.\n const siblingKey = siblingsKey(siblings)\n const named = useMemo(() => (html === undefined ? [] : referencedSiblings(html, siblings)), [html, siblingKey])\n const { contents, ready } = useSiblingContents(named)\n const contentsKey = [...contents.keys()].join('\\n')\n return useMemo(() => (html === undefined || !ready ? undefined : siblingPage(html, siblings, contents, address)), [html, siblingKey, ready, contentsKey, address])\n}\n"],"mappings":"2vBAMakB,GAAiB,EAAqC,EAAe,IAAgBC,GAAO,QAAUC,EAAQD,EAAM,MAAQE,EAG5HC,GAAuB,EAAe,IAAe,CAChE,GAAM,CAACH,EAAOI,IAAA,EAAYvB,EAAAA,SAAAA,CAA2B,EAC/CwB,GAAA,EAASvB,EAAAA,YAAAA,CAAa,GAA0BsB,EAAU,IAAW,CAAE,QAAO,MAAOE,EAAKP,EAAWC,EAAOC,EAAOC,CAAO,CAAC,CAAE,EAAE,EAAG,CAACD,EAAOC,CAAO,CAAC,EACxJ,MAAO,CAACH,EAAWC,EAAOC,EAAOC,CAAO,EAAGG,CAAM,CACnD,ECZaE,EAAgB,sBAUhBC,EAAc;;;;;;;;;;;;;;uCAcYD,EAAc;;;;;;;;;MCfxCE,EAAe,gBAQfC,GAAY,EAAuB,IAC9C,CACE,qBACAC,IAAY,SAAW,qBAAqBV,EAAM,GAAK,6BACvD,gBACA,kBACA,kCACA,iBACA,kBACA,oBACF,CAAC,CAAC,KAAK,IAAI,EAGAW,MAAmB,MAAM,KAAK,OAAO,gBAAgB,IAAI,WAAW,EAAE,CAAC,EAAI,GAASC,EAAK,SAAS,EAAE,CAAC,CAAC,SAAS,EAAG,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,ECzBtIC,EAAU,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AAI,CAAC3C,EAAMuF,CAAU,CAC9D,CAAK,EAC9CC,EAAc,CAAC,GAAGvB,EAAS,KAAK,CAAC,CAAC,CAAC,KAAK;CAAI,EAClD,OAAA,EAAOjG,EAAAA,QAAAA,KAAegC,IAAS,IAAA,IAAa,CAACyF,EAAQ,IAAA,GAAYzB,EAAYhE,EAAM2C,EAAUsB,EAAUI,CAAO,EAAI,CAACrE,EAAMuF,EAAYE,EAAOD,EAAanB,CAAO,CAAC,CACnK","debugId":"9cc29da0-33e5-466e-a365-30958c1bcafc"}
|
|
1
|
+
{"version":3,"file":"use-sibling-page-DLjl_l8i.js","names":["useState","useCallback","useRef","useMemo","useMemo","n","a","t","__toESM","require_react","require_jsx_runtime","useQueries","useQuery","useResourceClient","useViewedResource","fileNamed","cn","import_react","ofDocument","state","nonce","initial","useDocumentState","setState","update","next","linkAttribute","frameBridge","frameSandbox","frameCsp","scripts","frameNonce","byte","removed","frameDocument","page","html","element","policy","referrer","bridge","rounding","nextFrameHeight","previous","viewport","height","frameBox","size","maxHeight","frameMessage","frame","event","data","links","import_jsx_runtime","noLinks","scrollToPlace","bars","top","HtmlFrame","shown","setHeight","shownAgain","setShownAgain","key","loads","receive","message","onLink","loaded","times","box","className","climbs","value","siblingReference","reference","unescaped","decoded","siblings","error","rewriteSrcset","parts","candidate","resolved","resolve","rewriteCssUrls","text","whole","externalUrl","url","sources","rewriteResources","set","attribute","resource","parse","referencedSiblings","found","sibling","siblingPage","contents","link","href","target","address","siblingsKey","FileReadError","status","useFileText","client","file","response","dataUrl","reader","reject","bytes","useSiblingContents","reads","files","read","index","useSiblingPage","siblingKey","contentsKey","ready"],"sources":["../../../src/app/file-viewers/document-state.ts","../../../src/app/file-viewers/frame-bridge.ts","../../../src/app/file-viewers/frame-policy.ts","../../../src/app/file-viewers/frame-document.ts","../../../src/app/file-viewers/frame-height.ts","../../../src/app/file-viewers/frame-messages.ts","../../../src/app/file-viewers/html-frame.tsx","../../../src/app/file-viewers/sibling-references.ts","../../../src/app/file-viewers/sibling-page.ts","../../../src/app/file-viewers/siblings-key.ts","../../../src/app/file-viewers/use-file-text.ts","../../../src/app/file-viewers/use-sibling-contents.ts","../../../src/app/file-viewers/use-sibling-page.ts"],"sourcesContent":["import { useCallback, useState } from 'react'\n\n/** A value of an `HtmlFrame` that belongs to the document it shows, by that document's `nonce`. */\nexport type DocumentState<T> = { nonce: string; value: T }\n\n/** `state`'s value for the document `nonce`; `initial` for another document, which starts again. */\nexport const ofDocument = <T>(state: DocumentState<T> | undefined, nonce: string, initial: T) => (state?.nonce === nonce ? state.value : initial)\n\n/** State that starts again at `initial` (a constant) each time the frame shows another document, `nonce`. */\nexport const useDocumentState = <T>(nonce: string, initial: T) => {\n const [state, setState] = useState<DocumentState<T>>()\n const update = useCallback((next: (value: T) => T) => setState((state) => ({ nonce, value: next(ofDocument(state, nonce, initial)) })), [nonce, initial])\n return [ofDocument(state, nonce, initial), update] as const\n}\n","/** The attribute an `HtmlFrame` page's link carries, the index of its target in the frame's `links`. */\nexport const linkAttribute = 'data-protobase-link'\n\n/**\n * The script an `HtmlFrame` runs in its page, the only one a page it does not trust runs. A click on a link carrying\n * `linkAttribute` posts its index to the app, with whether it asks for a new tab. A click on a link to a place on the\n * page (`#results`) moves the focus there and posts how far down the page it is, since the app's page scrolls rather\n * than the frame. A\n * click on any other link does nothing, so the page never leaves the frame. It also posts the page's height, so the\n * frame grows with it.\n */\nexport const frameBridge = `(() => {\n const post = (message) => parent.postMessage({ protobase: 'html-frame', ...message }, '*')\n const place = (hash) => {\n const name = decodeURIComponent(hash.slice(1))\n const target = name === '' || name === 'top' ? null : document.getElementById(name) ?? document.getElementsByName(name)[0]\n if (!target) return 0\n if (target.tabIndex < 0 && !target.hasAttribute('tabindex')) target.setAttribute('tabindex', '-1')\n target.focus({ preventScroll: true })\n return target.getBoundingClientRect().top + window.scrollY\n }\n const follow = (event) => {\n const link = event.target instanceof Element ? event.target.closest('a, area') : null\n if (!link) return\n event.preventDefault()\n const index = link.getAttribute('${linkAttribute}')\n const href = link.getAttribute('href') ?? ''\n if (index !== null) post({ link: Number(index), newTab: event.button === 1 || event.ctrlKey || event.metaKey || event.shiftKey })\n else if (href.startsWith('#') && event.button === 0) post({ scroll: place(href) })\n }\n document.addEventListener('click', follow, true)\n document.addEventListener('auxclick', (event) => event.button === 1 && follow(event), true)\n const height = () => post({ height: document.documentElement.getBoundingClientRect().height })\n new ResizeObserver(height).observe(document.documentElement)\n})()`\n","/**\n * What an `HtmlFrame`'s page may run: `'bridge'`, only the frame's own link script, for a page it does not trust, such\n * as an uploaded file; `'trusted-page'`, also the page's own inline scripts, for a page an app generates itself.\n */\nexport type FrameScripts = 'bridge' | 'trusted-page'\n\n/**\n * The frame's sandbox: scripts, so the link script runs, and nothing else. Never `allow-same-origin`, so the page has an\n * opaque origin and cannot reach the app's cookies, storage or DOM; no top navigation, forms or popups.\n */\nexport const frameSandbox = 'allow-scripts'\n\n/**\n * The page's Content-Security-Policy. With `'bridge'` only the script carrying `nonce` runs: the page's own scripts,\n * inline handlers and `javascript:` links do not. `'trusted-page'` runs inline scripts and so carries no nonce, which\n * would turn `'unsafe-inline'` off. Either way nothing loads from the network: images, media, styles and fonts come\n * from `data:` URLs, and nothing is fetched, framed or submitted.\n */\nexport const frameCsp = (scripts: FrameScripts, nonce: string) =>\n [\n \"default-src 'none'\",\n scripts === 'bridge' ? `script-src 'nonce-${nonce}'` : \"script-src 'unsafe-inline'\",\n 'img-src data:',\n 'media-src data:',\n \"style-src 'unsafe-inline' data:\",\n 'font-src data:',\n \"base-uri 'none'\",\n \"form-action 'none'\",\n ].join('; ')\n\n/** A fresh 128-bit nonce, as hex. */\nexport const frameNonce = () => Array.from(crypto.getRandomValues(new Uint8Array(16)), (byte) => byte.toString(16).padStart(2, '0')).join('')\n","import { frameBridge } from './frame-bridge'\nimport { frameCsp, type FrameScripts } from './frame-policy'\n\n// What a page could use to leave its policy or the frame: its own `http-equiv` (a refresh, another policy), a `<base>`,\n// and `<noscript>`, read as markup here but as text in the frame, where scripts run, so markup hidden in it would come\n// out after these were removed.\nconst removed = 'meta[http-equiv], base, noscript'\n\n/**\n * `html` as the page an `HtmlFrame` shows: parsed, cleared of `removed`, and opened with the frame's own policy, a\n * referrer policy that sends no address on, and the frame's link script carrying `nonce`. They are the first nodes of\n * `<head>`, put there in the parsed document, so the policy covers everything of the page, even a script written before\n * its `<html>`.\n */\nexport const frameDocument = (html: string, scripts: FrameScripts, nonce: string) => {\n const page = new DOMParser().parseFromString(html, 'text/html')\n for (const element of page.querySelectorAll(removed)) element.remove()\n\n const policy = page.createElement('meta')\n policy.httpEquiv = 'Content-Security-Policy'\n policy.content = frameCsp(scripts, nonce)\n const referrer = page.createElement('meta')\n referrer.name = 'referrer'\n referrer.content = 'no-referrer'\n const bridge = page.createElement('script')\n if (scripts === 'bridge') bridge.setAttribute('nonce', nonce)\n bridge.textContent = frameBridge\n page.head.prepend(policy, referrer, bridge)\n\n return `<!doctype html>${page.documentElement.outerHTML}`\n}\n","/**\n * How tall an `HtmlFrame` is for its page: `measured`, the height its page last reported, with the frame's own height\n * when it did, or `fixed`, for a page sized by the frame's viewport, such as one `100vh` tall or `height: 100%` with a\n * margin, which reports a taller page each time the frame takes its last height.\n */\nexport type FrameHeight = { kind: 'measured'; height: number; viewport: number } | { kind: 'fixed' }\n\n// Reported heights are rounded up to whole pixels.\nconst rounding = 1\n\n/**\n * The frame's height after its page reports `height` while the frame is `viewport` tall. A page whose height changed by\n * as much as the frame did since its last report is sized by the frame, and the frame stays fixed for it.\n */\nexport const nextFrameHeight = (previous: FrameHeight | undefined, height: number, viewport: number): FrameHeight => {\n if (previous?.kind === 'fixed') return previous\n if (previous && viewport !== previous.viewport && Math.abs(height - previous.height - (viewport - previous.viewport)) <= rounding) return { kind: 'fixed' }\n return { kind: 'measured', height, viewport }\n}\n\n/**\n * The frame's box: as tall as its page's measured height, or a fixed minimum while nothing is measured, for a page\n * measured 0 tall, and for a page sized by the frame. That page scrolls inside the frame, the one inner scroll box here:\n * the app's page cannot scroll content whose height depends on the frame's own.\n */\nexport const frameBox = (size: FrameHeight | undefined) =>\n size?.kind === 'measured' && size.height > 0 ? { style: { height: size.height } } : { className: 'min-h-[60vh]' }\n","/**\n * What an `HtmlFrame`'s page asks of the app: follow its link `index`, be as tall as `height` CSS pixels, or scroll to\n * the place `top` CSS pixels down the page.\n */\nexport type FrameMessage = { kind: 'link'; index: number; newTab: boolean } | { kind: 'height'; height: number } | { kind: 'scroll'; top: number }\n\n// Tall enough for a long report, short enough that a page cannot make the app's page endless.\nconst maxHeight = 100_000\n\n/**\n * The request a message event carries from the frame's own window `frame`, with a link index below `links`; `undefined`\n * for any other source or shape. Every sandboxed page's origin is `\"null\"`, so only the window itself tells them apart.\n */\nexport const frameMessage = (event: Pick<MessageEvent, 'source' | 'data'>, frame: Window | null | undefined, links: number): FrameMessage | undefined => {\n if (!frame || event.source !== frame) return\n const data: unknown = event.data\n if (typeof data !== 'object' || data === null || !('protobase' in data) || data.protobase !== 'html-frame') return\n if ('link' in data && Number.isInteger(data.link) && (data.link as number) >= 0 && (data.link as number) < links) {\n return { kind: 'link', index: data.link as number, newTab: 'newTab' in data && data.newTab === true }\n }\n if ('height' in data && typeof data.height === 'number' && Number.isFinite(data.height) && data.height >= 0) {\n return { kind: 'height', height: Math.min(Math.ceil(data.height), maxHeight) }\n }\n if ('scroll' in data && typeof data.scroll === 'number' && Number.isFinite(data.scroll)) {\n return { kind: 'scroll', top: Math.min(Math.max(Math.round(data.scroll), 0), maxHeight) }\n }\n return\n}\n","import { useEffect, useMemo, useRef } from 'react'\nimport { cn } from '../../lib/cn'\nimport { useDocumentState } from './document-state'\nimport type { ViewedFile } from './file-viewer'\nimport { frameDocument } from './frame-document'\nimport { frameBox, nextFrameHeight, type FrameHeight } from './frame-height'\nimport { frameMessage } from './frame-messages'\nimport { frameNonce, frameSandbox, type FrameScripts } from './frame-policy'\nimport type { FrameLink } from './sibling-page'\n\nconst noLinks: readonly never[] = []\n\n// Scrolls the app's page to the place `top` pixels down the page in `frame`, below the bars that stay at the top.\nconst scrollToPlace = (frame: HTMLIFrameElement, top: number) => {\n const bars = Number.parseFloat(getComputedStyle(document.documentElement).scrollPaddingTop) || 0\n window.scrollTo({ top: frame.getBoundingClientRect().top + window.scrollY + top - bars })\n}\n\ntype HtmlFrameProps<File extends ViewedFile> = {\n /** The page, a whole HTML document or a fragment. */\n html: string\n /** The frame's accessible name, such as the file's name. */\n title: string\n /** The targets of the page's links, by the index each carries (`useSiblingPage`). */\n links?: readonly FrameLink<File>[]\n /** Follows a link of the page; `newTab` when it was a middle or modified click. */\n onLink?: (link: FrameLink<File>, options: { newTab: boolean }) => void\n /**\n * `'bridge'` (the default) runs none of the page's own scripts, for a page you do not trust, such as an uploaded file;\n * `'trusted-page'` runs them, for a page your viewer generates itself. Either way the page cannot reach the app.\n */\n scripts?: FrameScripts\n className?: string\n}\n\n/**\n * A whole HTML page drawn in a sandboxed frame with an opaque origin: it cannot read the app's cookies, storage or DOM,\n * call its API as the user, load anything from the network or navigate the app's window. Its links reach the app only\n * as the index of one of `links`, which `onLink` follows. The frame is as tall as its page, so the app's page scrolls,\n * unless the page is sized by the frame (`FrameHeight`).\n */\nexport const HtmlFrame = <File extends ViewedFile>({ html, title, links = noLinks, onLink, scripts = 'bridge', className }: HtmlFrameProps<File>) => {\n const frame = useRef<HTMLIFrameElement>(null)\n const shown = useMemo(() => {\n const nonce = frameNonce()\n return { nonce, srcDoc: frameDocument(html, scripts, nonce) }\n }, [html, scripts])\n const [height, setHeight] = useDocumentState<FrameHeight | undefined>(shown.nonce, undefined)\n // A page that navigated its frame anyway is shown again once; doing so again leaves the frame empty, until another\n // document is shown.\n const [shownAgain, setShownAgain] = useDocumentState(shown.nonce, 0)\n const key = `${shown.nonce}:${shownAgain}`\n // The loads of the frame shown as `key`: its first is its page, any later one the page leaving it.\n const loads = useRef({ key, count: 0 })\n\n useEffect(() => {\n const receive = (event: MessageEvent) => {\n const message = frameMessage(event, frame.current?.contentWindow, links.length)\n const viewport = frame.current?.clientHeight\n if (message?.kind === 'height' && viewport !== undefined) setHeight((size) => nextFrameHeight(size, message.height, viewport))\n if (message?.kind === 'link') onLink?.(links[message.index]!, { newTab: message.newTab })\n if (message?.kind === 'scroll' && frame.current) scrollToPlace(frame.current, message.top)\n }\n window.addEventListener('message', receive)\n return () => window.removeEventListener('message', receive)\n }, [links, onLink, setHeight])\n\n const loaded = () => {\n if (loads.current.key !== key) loads.current = { key, count: 0 }\n loads.current.count += 1\n if (loads.current.count > 1) setShownAgain((times) => times + 1)\n }\n\n const box = frameBox(height)\n return (\n <iframe\n key={key}\n ref={frame}\n title={title}\n sandbox={frameSandbox}\n referrerPolicy=\"no-referrer\"\n // A video's own fullscreen control; a page that does not run its scripts can ask for nothing else.\n allow={scripts === 'bridge' ? 'fullscreen' : undefined}\n srcDoc={shownAgain > 1 ? '' : shown.srcDoc}\n onLoad={loaded}\n className={cn('block w-full border-0 bg-white', box.className, className)}\n style={box.style}\n />\n )\n}\n","import { fileNamed, type ViewedFile } from './file-viewer'\n\n// Whether a reference's path climbs out of its folder with a `..` segment.\nconst climbs = (value: string) => value.split(/[?#]/, 1)[0]!.split('/').includes('..')\n\n/**\n * The sibling a page's relative reference names, such as `shots/before.png` or `my%20chart.png`, by its file name\n * (`fileNamed`), as written or with its escapes read; none for an absolute or protocol-relative address, a path from\n * the root, a fragment, or a path that climbs out with `..`, written or escaped.\n */\nexport const siblingReference = <File extends ViewedFile>(siblings: readonly File[], reference: string) => {\n const value = reference.trim()\n const unescaped = decoded(value)\n if (climbs(value) || climbs(unescaped)) return\n return fileNamed(siblings, value) ?? fileNamed(siblings, unescaped)\n}\n\n// A reference with its escapes, such as `%20`, read; as it is when one is malformed.\nconst decoded = (value: string) => {\n try {\n return decodeURI(value)\n } catch (error) {\n if (error instanceof URIError) return value\n throw error\n }\n}\n\n/** `value` of a `srcset`, each candidate's address resolved on its own; a candidate `resolve` gives nothing for stays as written. */\nexport const rewriteSrcset = (value: string, resolve: (reference: string) => string | undefined) =>\n value\n .split(',')\n .map((candidate) => {\n const parts = /^(\\s*)(\\S+)([\\s\\S]*)$/.exec(candidate)\n const resolved = parts && resolve(parts[2]!)\n return parts && resolved ? `${parts[1]}${resolved}${parts[3]}` : candidate\n })\n .join(',')\n\n/** CSS `text` with each `url(...)` resolved; one `resolve` gives nothing for stays as written. */\nexport const rewriteCssUrls = (text: string, resolve: (reference: string) => string | undefined) =>\n text.replace(/url\\(\\s*(['\"]?)([^'\")]*)\\1\\s*\\)/gi, (whole, _quote: string, reference: string) => {\n const resolved = resolve(reference.trim())\n return resolved ? `url(\"${resolved}\")` : whole\n })\n\n/** An absolute `http:` or `https:` address as the URL parser reads it, else `undefined`, such as for `javascript:` or a relative path. */\nexport const externalUrl = (reference: string) => {\n if (!URL.canParse(reference)) return\n const url = new URL(reference)\n return url.protocol === 'http:' || url.protocol === 'https:' ? url.href : undefined\n}\n","import type { ViewedFile } from './file-viewer'\nimport { linkAttribute } from './frame-bridge'\nimport { externalUrl, rewriteCssUrls, rewriteSrcset, siblingReference } from './sibling-references'\n\n/** Where a link of a page in an `HtmlFrame` leads: a sibling file, or an outside `http`/`https` address. */\nexport type FrameLink<File extends ViewedFile = ViewedFile> = { kind: 'file'; file: File } | { kind: 'external'; url: string }\n\n/** A page with its references to siblings resolved, and the targets of its links, which carry their index. */\nexport type SiblingPage<File extends ViewedFile = ViewedFile> = { html: string; links: FrameLink<File>[] }\n\n// The attributes that load a file into the page, by the elements they are on.\nconst sources = ['img[src]', 'source[src]', 'video[src]', 'audio[src]', 'track[src]', 'input[src]'].join(', ')\n\n// Each reference of `page` that loads a file, set to what `resource` gives for it; one it gives nothing for stays.\nconst rewriteResources = (page: Document, resource: (reference: string) => string | undefined) => {\n const set = (element: Element, attribute: string, value: string | undefined) => value !== undefined && element.setAttribute(attribute, value)\n for (const element of page.querySelectorAll(sources)) set(element, 'src', resource(element.getAttribute('src')!))\n for (const element of page.querySelectorAll('video[poster]')) set(element, 'poster', resource(element.getAttribute('poster')!))\n for (const element of page.querySelectorAll('img[srcset], source[srcset]')) set(element, 'srcset', rewriteSrcset(element.getAttribute('srcset')!, resource))\n for (const element of page.querySelectorAll('link[href]')) set(element, 'href', resource(element.getAttribute('href')!))\n for (const element of page.querySelectorAll('image[href]')) set(element, 'href', resource(element.getAttribute('href')!))\n for (const element of page.querySelectorAll('[style]')) set(element, 'style', rewriteCssUrls(element.getAttribute('style')!, resource))\n for (const element of page.querySelectorAll('style')) element.textContent = rewriteCssUrls(element.textContent, resource)\n}\n\nconst parse = (html: string) => new DOMParser().parseFromString(html, 'text/html')\n\n/** The siblings `html` loads as images, videos, sounds, styles or fonts, each once: those a page needs read to show. */\nexport const referencedSiblings = <File extends ViewedFile>(html: string, siblings: readonly File[]) => {\n const found = new Set<File>()\n rewriteResources(parse(html), (reference) => {\n const sibling = siblingReference(siblings, reference)\n if (sibling) found.add(sibling)\n return\n })\n return [...found]\n}\n\n/** The address a page's link shows for where it leads, for the browser's link preview and copy link; `undefined` keeps its own. */\nexport type LinkAddress<File extends ViewedFile = ViewedFile> = (link: FrameLink<File>) => string | undefined\n\n/**\n * `html` with each relative reference to a sibling resolved: one that loads a file to the `data:` URL `contents` holds\n * by its stored `uri`, a link to a sibling or to an outside `http`/`https` address to an entry of `links`, showing the\n * address `address` gives it. A reference to no sibling, or to one `contents` lacks, stays as written; a link to\n * anywhere else, such as `javascript:`, loses its address. A link to a place on the page (`#top`) stays.\n */\nexport const siblingPage = <File extends ViewedFile>(html: string, siblings: readonly File[], contents: ReadonlyMap<string, string>, address?: LinkAddress<File>): SiblingPage<File> => {\n const page = parse(html)\n for (const element of page.querySelectorAll(`[${linkAttribute}]`)) element.removeAttribute(linkAttribute)\n rewriteResources(page, (reference) => {\n const sibling = siblingReference(siblings, reference)\n return sibling && contents.get(sibling.uri)\n })\n\n const links: FrameLink<File>[] = []\n for (const link of page.querySelectorAll('a[href], area[href]')) {\n const href = link.getAttribute('href')!\n if (href.startsWith('#')) continue\n link.removeAttribute('target')\n const sibling = siblingReference(siblings, href)\n const url = sibling ? undefined : externalUrl(href)\n if (!sibling && !url) {\n link.removeAttribute('href')\n continue\n }\n const target: FrameLink<File> = sibling ? { kind: 'file', file: sibling } : { kind: 'external', url: url! }\n const shown = address?.(target)\n if (shown !== undefined) link.setAttribute('href', shown)\n link.setAttribute(linkAttribute, String(links.length))\n links.push(target)\n }\n return { html: `<!doctype html>${page.documentElement.outerHTML}`, links }\n}\n","import type { ViewedFile } from './file-viewer'\n\n/**\n * A key that changes when any of `siblings` does: its stored uri, and the record key and file field a sibling carries\n * (`SiblingFile`), which its link's address names. A missing key or field is `null`.\n */\nexport const siblingsKey = <File extends ViewedFile>(siblings: readonly File[]) =>\n JSON.stringify(siblings.map((sibling) => [sibling.uri, 'key' in sibling ? sibling.key : null, 'field' in sibling ? sibling.field : null]))\n","import { useQuery } from '@tanstack/react-query'\nimport { useResourceClient } from '../../data/api-provider'\nimport type { ViewedFile } from './file-viewer'\nimport { useViewedResource } from './viewed-resource'\n\n/** A file that could not be read, with the status its link answered. */\nexport class FileReadError extends Error {\n override name = 'FileReadError'\n constructor(readonly status: number) {\n super(`The file could not be read: its link answered ${status}`)\n }\n}\n\n/**\n * The text of a file a viewer shows, read once and kept while the file is the same: a TanStack Query result keyed by\n * its resource and stored `uri`, as the link changes each time it is signed. Parse JSON from `data` yourself. It reads\n * from the API that serves the record, which sends the bytes itself whatever store holds them or wherever the file's\n * link points, up to 10 MB; a larger file fails with a 403.\n */\nexport const useFileText = (file: ViewedFile) => {\n const resource = useViewedResource()\n const client = useResourceClient(resource)\n return useQuery({\n queryKey: ['file-text', resource, file.uri],\n staleTime: Infinity,\n queryFn: async () => {\n const response = await fetch(client.fileReadUrl(resource, file))\n if (!response.ok) throw new FileReadError(response.status)\n return response.text()\n },\n })\n}\n","import { useQueries } from '@tanstack/react-query'\nimport { useResourceClient } from '../../data/api-provider'\nimport type { ViewedFile } from './file-viewer'\nimport { FileReadError } from './use-file-text'\nimport { useViewedResource } from './viewed-resource'\n\n// The bytes as a `data:` URL of the file's own type: a sandboxed page cannot load the app's `blob:` URLs, and the URL\n// holds the bytes alone, no signed link that would open the file elsewhere.\nconst dataUrl = (bytes: Blob) =>\n new Promise<string>((resolve, reject) => {\n const reader = new FileReader()\n reader.onload = () => resolve(reader.result as string)\n reader.onerror = () => reject(reader.error)\n reader.readAsDataURL(bytes)\n })\n\n/**\n * The contents of `files` as `data:` URLs by their stored `uri`, each read once from the API that serves the viewed\n * record, with the user's own rights, as `useFileText` reads, up to 10 MB each; `ready` once every read has answered. A\n * file that could not be read is left out, so what refers to it stays as written.\n */\nexport const useSiblingContents = (files: readonly ViewedFile[]) => {\n const resource = useViewedResource()\n const client = useResourceClient(resource)\n const reads = useQueries({\n queries: files.map((file) => ({\n queryKey: ['file-data-url', resource, file.uri],\n staleTime: Infinity,\n retry: false,\n queryFn: async () => {\n const response = await fetch(client.fileReadUrl(resource, file))\n if (!response.ok) throw new FileReadError(response.status)\n return dataUrl(new Blob([await response.arrayBuffer()], { type: file.type }))\n },\n })),\n })\n const contents = new Map<string, string>()\n reads.forEach((read, index) => read.data !== undefined && contents.set(files[index]!.uri, read.data))\n return { contents, ready: reads.every((read) => !read.isPending) }\n}\n","import { useMemo } from 'react'\nimport type { ViewedFile } from './file-viewer'\nimport { referencedSiblings, siblingPage, type LinkAddress, type SiblingPage } from './sibling-page'\nimport { siblingsKey } from './siblings-key'\nimport { useSiblingContents } from './use-sibling-contents'\n\n/**\n * `html`, a page a file viewer shows, with its relative references resolved to `siblings` (`siblingPage`), for an\n * `HtmlFrame`: the images, videos and styles it names read as `data:` URLs, its links to siblings and outside addresses\n * in `links`, each showing the address `address` gives it. `undefined` while `html` or those reads are pending. Use it\n * inside a file viewer, which reads them from the API that serves the viewed record.\n */\nexport const useSiblingPage = <File extends ViewedFile>(html: string | undefined, siblings: readonly File[], address?: LinkAddress<File>): SiblingPage<File> | undefined => {\n // A viewer's siblings are a new list each render: their key, and the contents read, say when they changed.\n const siblingKey = siblingsKey(siblings)\n const named = useMemo(() => (html === undefined ? [] : referencedSiblings(html, siblings)), [html, siblingKey])\n const { contents, ready } = useSiblingContents(named)\n const contentsKey = [...contents.keys()].join('\\n')\n return useMemo(() => (html === undefined || !ready ? undefined : siblingPage(html, siblings, contents, address)), [html, siblingKey, ready, contentsKey, address])\n}\n"],"mappings":"2vBAMakB,GAAiB,EAAqC,EAAe,IAAgBC,GAAO,QAAUC,EAAQD,EAAM,MAAQE,EAG5HC,GAAuB,EAAe,IAAe,CAChE,GAAM,CAACH,EAAOI,IAAA,EAAYvB,EAAAA,SAAAA,CAA2B,EAC/CwB,GAAA,EAASvB,EAAAA,YAAAA,CAAa,GAA0BsB,EAAU,IAAW,CAAE,QAAO,MAAOE,EAAKP,EAAWC,EAAOC,EAAOC,CAAO,CAAC,CAAE,EAAE,EAAG,CAACD,EAAOC,CAAO,CAAC,EACxJ,MAAO,CAACH,EAAWC,EAAOC,EAAOC,CAAO,EAAGG,CAAM,CACnD,ECZaE,EAAgB,sBAUhBC,EAAc;;;;;;;;;;;;;;uCAcYD,EAAc;;;;;;;;;MCfxCE,EAAe,gBAQfC,GAAY,EAAuB,IAC9C,CACE,qBACAC,IAAY,SAAW,qBAAqBV,EAAM,GAAK,6BACvD,gBACA,kBACA,kCACA,iBACA,kBACA,oBACF,CAAC,CAAC,KAAK,IAAI,EAGAW,MAAmB,MAAM,KAAK,OAAO,gBAAgB,IAAI,WAAW,EAAE,CAAC,EAAI,GAASC,EAAK,SAAS,EAAE,CAAC,CAAC,SAAS,EAAG,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,ECzBtIC,EAAU,mCAQHC,GAAiB,EAAc,EAAuB,IAAkB,CACnF,IAAMC,EAAO,IAAI,UAAU,CAAC,CAAC,gBAAgBC,EAAM,WAAW,EAC9D,IAAK,IAAMC,KAAWF,EAAK,iBAAiBF,CAAO,EAAGI,EAAQ,OAAO,EAErE,IAAMC,EA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