Repository navigation
feat(edgeless): mount a read-only canvas viewer from a stored state - #653
Merged
Merged
Conversation
Builds ADR 0050. `mountCanvasViewer(host, state, options)` from
`@labre/affine/canvas-viewer` opens a stored Y.Doc state on a read-only
store and mounts the `preview-edgeless` scope with no editor around it,
for a host's public page (Labre Sites' canvas island).
One runtime watcher unlocks the viewport after `EdgelessLocker` and fits
once. The container takes every pointer, wheel and click event in
capture: a drag or one finger pans, two fingers pinch, a wheel pans,
ctrl+wheel and a trackpad pinch zoom, and a click follows a link (a page
to `onOpenDoc`, an external URL to `onLinkClick` after `isSafeLinkUrl`).
`getBlob` feeds images; the light theme is set on the container only,
from names already in the theme contract. The controller is
`{ zoomIn, zoomOut, fit, dispose }`.
The wheel and pinch maths of the edgeless root moved to
`utils/wheel-gesture.ts`, shared by both (ADR 0050 section 4); a pinch
step from a zero distance is now skipped instead of jumping to the
maximum zoom. The entry weighs 3.65 MB gzipped, the whole view graph,
as the ADR measured; the ADR is amended with what shipped.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…/canvas-viewer # Conflicts: # docs/integrate/09-static-html.md
…until expanded
PO acceptance on a published site: a frame inserted in a page must open
a view on the canvas, as the surface reference block does in the editor.
`mountCanvasViewer` takes `focus: { kind, id }`: the container takes the
element's aspect ratio and the view frames its bounds with the surface
reference's own call (a frame edge to edge with its border hidden, a
group with a 20px margin). With `focus` the view is frozen by default
(`interactive`): the page keeps the wheel and touch, no link is followed,
and a click or Enter calls `onExpand`, so the host mounts the same focus
with `interactive: true` in a larger view. A missing or mistyped element
throws at mount, like a state with no page.
The spec mounts a page whose frame holds one note and leaves another far
outside: the frozen view shows the frame and not the outside note.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…us imports Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Found by a fresh review of the viewer: - the container took the pointer capture on every press, so a browser sent the click to the container and no link, page reference or card was ever found; the capture is now taken once a press becomes a drag; - a link stored without a scheme (`example.com`) navigated as a path on the host's site; it is normalised before the safe-URL check, as the bookmark block opens it; - a frozen view's editor host was a second tab stop inside the button and woke the editor's keyboard handler on focus; it is now inert; - a drag pans in model units under a CSS-scaled host, as the editor does; - a mount that throws before the host is attached disposes the workspace. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
Round 2 (head f9c39d2)Conflict. Merged Frame inserted in a page (PO acceptance: an inserted frame must open a view on the canvas, as the surface reference does in the editor). New options, same return: mountCanvasViewer(host, state, {
onOpenDoc?, onLinkClick?, getBlob?,
focus?: { kind: 'frame' | 'group'; id: string },
interactive?: boolean, // defaults to !focus
onExpand?: () => void, // frozen view clicked, or Enter / Space
}) // → { zoomIn, zoomOut, fit, dispose }
Fresh review findings, fixed in f9c39d2.
Security review of the branch, with stored content treated as attacker-controlled for the visitor: no high-confidence finding. Verified locally on f9c39d2 (the
Not merged, not published. 🤖 Generated with Claude Code |
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
Builds ADR 0050 (design note merged in #643): a read-only canvas a host mounts from a stored Y.Doc state, with no editor around it.
readonlystore, mountsBlockStdScopewith thepreview-edgelesslist, the viewer's container as viewport element (as the surface reference does with.ref-viewport) and one runtime watcher that unlocks the viewport afterEdgelessLockerand fits once.combinedLightCssVariablesandlightThemeV2throughthemeToVar: names already in the theme contract (theme-imports.unit.spec.ts), so a host that substitutes the theme package exports nothing more. One<style>, scoped by[data-labre-canvas-viewer], gives pointer events back to the preview root inside it.edgeless-root-block.tsintoblocks/root/src/edgeless/utils/wheel-gesture.ts(zoomAtPointer,panByWheel,pinchStep), called by the root and the viewer.shift-wheel-horizontal-scroll.unit.spec.tsnow reads the moved expression, as its header asks.minoron@labre/affine.Contract reconciled
Two hosts asked for different shapes. Labre's publishing service asked for
mountEdgelessPreview(host, docState, { onNavigate, fitToContent, locale })under/preview-edgeless; its site-render island formount(host, state, { onOpenDoc, locale })returning{ zoomIn, zoomOut, fit, dispose? }. Kept: the ADR's name and sub-path, the island's controller andonOpenDoc, the ADR'sonLinkClick, the service's blob resolver asgetBlob. Dropped:locale(the viewer displays no library string) andfitToContent(it always fits at mount). Both sessions were sent this contract.Not as asked
.css.tsnot extracted, 5 184 modules, 16.24 MB, 3.65 MB gzipped (ADR: 3.62 MB). The scope filters what registers, not what is imported; a lighter graph means splittinggetInternalViewExtensions, which the ADR keeps as a separate decision. Hosts load it with a dynamicimport().packages/integration-test(painting, pan, zoom, a link click on a real canvas), is not written.Behaviour change in the editor
None intended. One guard added in
pinchStep: a step whose previous finger distance is zero is skipped, where the old code divided by zero and jumped to the maximum zoom.Dependencies
yjsand@toeverything/thememove from the umbrella'sdevDependenciestodependencies(the viewer imports them;declared-dependencies.unit.spec.ts). Same ranges as@labre/storeand@labre/affine-shared, so the publishedlabre-coremanifest does not change;yarn install --immutableleaves the lockfile as is.How verified
canvas-viewer.unit.spec.ts(happy-dom): 5 tests green: mount on a fixture page with a note, a page reference and a frame, read-only store, theme on the container only; refusal of a state with no page; zoom buttons, ctrl+wheel and a drag; a page reference reachingonOpenDoc, ajavascript:link reaching nothing; dispose twice.blocks/root:shift-wheel-horizontal-scrollandpinch-zoomspecs green.packages/affine/all, whole suite: 1 057 of 1 059 green on the first run. The two failures were the theme contract (fixed as above, guard green) andcore-database-boundarytiming out at 10 s while a build ran beside it (green rerun alone). Rerun after the fix:theme-imports,brand-hex,canvas-viewer,core-database-boundary,literals,manifest,declared-dependencies,architecture-mapgreen.tsc -b tsconfig.json(whole workspace): green.yarn architecture --check: up to date. Prettier on every touched file, commitlint and lint-staged hooks: green.packages/affine/all/src/canvas-viewer.ts.Not published to npm:
ci:version/ci:publishis the product owner's call.🤖 Generated with Claude Code