Repository navigation
feat(annotate): open local image links in an HTML page in the image lightbox - #1676
Merged
Merged
Conversation
…ightbox A link to a local image inside an annotated HTML page (a thumbnail linking to its full-size render) used to toast "Can't open". It now opens in the image lightbox the markdown Viewer already has, extracted to a shared ImageLightbox component. - resolveHtmlLinkIntent gains an image intent: png jpg jpeg gif webp svg avif bmp ico apng (the code-review preview set), resolved to the page's own /api/html-assets/<token>/ route and only inside the page's folder. Out-of-folder images and pages with no asset route keep a toast that says why. - The lightbox takes focus (out of the iframe) and swallows keys on the window capture phase, so Esc closes it before the HTML Esc ladder and Mod+Enter cannot submit behind it (also fixes the markdown lightbox). - Armed clicks still pin; Interact opens the lightbox, same as doc links. - The asset route also serves .bmp (shared table, vendored to Pi).
htmlAssetRouteFromDocument matched any <base> naming /api/html-assets anywhere in the page, so a comment or a later base tag could name a different token than the one the browser actually applies. Skip comments and take only the first <base> element, as the browser does. Adds tests for that and for encoded-dot and backslash escapes in image links.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
In a raw-HTML annotate session, a link to a local image (
<a href="renders/home-1440.png"><img …></a>) used to toast "Can't open home-1440.png — Only markdown, text and HTML documents open in Plannotator." It now opens in the existing image lightbox.How
resolveHtmlLinkIntent(packages/ui/utils/htmlLinkNavigation.ts) has a new{ kind: "image", path, url, label }intent for relative and root-relative links topng jpg jpeg gif webp svg avif bmp ico apng(the code-review preview set,isReviewImagePath). Theurlis the page's own/api/html-assets/<token>/…route, read from the<base href>the server already installs (htmlAssetRouteFromDocument). So the lightbox reads only what the page itself can load. Nothing new becomes readable.../x.png, or a root-relative path outside a linked page's folder), a toast says "Images open only from this page's own folder."unsupportednow carries areason(type/outside-asset-root/no-asset-root). External http(s) image URLs still open in a new tab.Viewer.tsxtopackages/ui/components/ImageLightbox.tsx. The Viewer and App both mount it. It shows the image only through<img src>. When it opens it takes focus, which pulls focus out of the iframe. While open, it swallows keys on the window capture phase, so:Esccloses it before the HTML Esc ladder runs.Mod+Entercannot submit a decision behind it. This also fixes the markdown lightbox, which did not block it before..bmpis added to the shared asset content-type table (packages/shared/html-assets.ts, vendored to Pi), so the whole preview set serves. Without it,.bmpreturned 415.Verified
bun test: the only failure was the DOM allowlist, fixed by adding the new DOM test totest.yml.no-asset-root, external images and parsing the asset route.bun run --cwd apps/review build && bun run build:hook, andpackages/uismoke:package.PLANNOTATOR_DATA_DIR, headless Chromium):/api/html-assets/<token>/renders/x.png, with focus on the lightbox.../outside.pnglink showed the out-of-folder toast.