Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
ab27506
feat(edgeless): build a mind map with no editor, text measurement inj…
Nov 10, 2026
bb75335
fix(edgeless): bound a built mind map's text and wrap long words in l…
Nov 10, 2026
65767d7
chore(edgeless): regenerate the architecture map for the mind map bui…
Nov 10, 2026
b9b1c58
test(edgeless): read node boxes through the surface in the mind map p…
Nov 10, 2026
14cdacd
fix(edgeless): draw the canvas viewer under a strict content security…
Nov 10, 2026
78416b6
fix(edgeless): settle synced docs of named pages and follow only the …
Nov 10, 2026
13357b1
fix(blocks): keep emotion's rules out of a style element a strict pol…
Nov 10, 2026
70e5257
feat(edgeless): make the canvas viewer the editor itself, derived fro…
Nov 10, 2026
b3d0470
test(edgeless): paint the canvas viewer in a browser under a strict p…
Nov 10, 2026
aa0d642
fix(edgeless): viewer guard reads the mounted list, keys and clicks a…
Nov 10, 2026
50664cd
Merge remote-tracking branch 'origin/blocksuite-labre-main' into feat…
Nov 12, 2026
e97977c
chore(edgeless): regenerate the architecture map after the merge
Nov 12, 2026
d7f2d34
fix(database): read a malformed cell as its property default
Nov 12, 2026
a66a21c
fix(blocks): keep a fractional index key before its next neighbour
Nov 12, 2026
6d1f01e
feat(blocks): open the icon picker outside an editor from a public entry
Nov 12, 2026
6503e18
fix(blocks): keep the canvas selection when a table selects or clears
Nov 12, 2026
86eda11
fix(blocks): keep the start number of a numbered list on export
Nov 12, 2026
02a15cb
fix(edgeless): wrap a built mind map's text exactly as the editor does
Nov 12, 2026
730ca5b
test(edgeless): guard the mind map style colour past the palette
Nov 12, 2026
5247d70
feat(playground): build a mind map with no editor from the debug menu
Nov 12, 2026
918df2c
chore(playground): regenerate the architecture map for the mind map r…
Nov 12, 2026
ec83bf3
fix(edgeless): show a focused frame's title badge in the canvas viewer
Nov 12, 2026
b7952a6
test(edgeless): paint the canvas viewer under the site's own policy
Nov 12, 2026
4cb4426
docs: tell a host what a strict policy needs from the canvas viewer
Nov 12, 2026
9cb0812
feat(playground): open the document in the canvas viewer
Nov 12, 2026
f30fdd1
fix(blocks): flip the code toolbar wrap and line-number switches once
Nov 12, 2026
de965d5
fix(database): draw a blank select option as untitled
Nov 12, 2026
cfd83e2
test(edgeless): report the stage a framed canvas viewer stalls at
Nov 12, 2026
15c1284
fix(playground): keep the canvas viewer page's status off window.status
Nov 12, 2026
1020225
chore: refresh the architecture map for the canvas viewer
Nov 12, 2026
27ad2e4
fix(database): open a document row from a read-only desktop view
Nov 12, 2026
0256ac4
chore(database): refresh the architecture map for the tag label
Nov 12, 2026
4508572
fix(edgeless): ignore a pinch step whose fingers started on one point
Nov 12, 2026
73d8e84
fix(edgeless): name a frozen canvas view and repaint it when page fon…
Nov 12, 2026
d7d63f7
docs: say the canvas viewer repaints when the page's fonts load
Nov 12, 2026
56549a5
fix(blocks): keep a native modal dialog open when escape closes the i…
Nov 12, 2026
93d6697
fix(blocks): flip a menu toggle row once per click
Nov 12, 2026
ade058f
fix(blocks): bound the steps moving a fractional index key towards b
Nov 12, 2026
7d642d1
fix(blocks): write no list start past nine digits
Nov 12, 2026
c959280
fix(database): open a read-only kanban card from its cells
Nov 12, 2026
40f98a9
test(blocks): leave the column select-and-clear case to the unit spec
Nov 12, 2026
a1455f1
test(blocks): drop the words path from the code toggle unit spec
Nov 12, 2026
7e6fb0e
docs(edgeless): say why the export options menu rebuilds its rows
Nov 12, 2026
bab59d4
refactor(edgeless): carry the palette values in the library's theme
Nov 12, 2026
de28885
fix(blocks): keep the random postfix past the fractional index step b…
Nov 12, 2026
8004e3b
test(edgeless): drop a duplicate type check and a repeated comment
Nov 12, 2026
54a9907
fix(blocks): give a menu toggle row's focus back after a switch click
Nov 12, 2026
0069e9d
fix(blocks): give the library an emotion instance of its own
Nov 12, 2026
a140c46
fix(edgeless): deny the pages a canvas viewer is not given, free its …
Nov 12, 2026
c327fd2
docs: canvas viewer pages, host seams and emotion instance
Nov 12, 2026
4c08e54
fix(database): decide a kanban card's read-only open at the click
Nov 12, 2026
8c1aafa
fix(blocks): bound the last list number, not the start, on export
Nov 12, 2026
3e69def
chore: refresh the architecture map for the viewer's styles module
Nov 12, 2026
0179f24
docs(blocks): say why the fractional index fallback guard is required
Nov 12, 2026
3213bdc
fix(database): keep a read-only kanban card from opening a row twice
Nov 12, 2026
e6998e3
fix(edgeless): read the host's translation in the canvas viewer's own…
Nov 12, 2026
fe62de7
chore: refresh the architecture map after the viewer translation fix
Nov 12, 2026
aa5c39c
fix(playground): show the interactive canvas viewer across the whole …
Nov 12, 2026
54bf8cd
fix(page): store the outline type-icon switch's own value
Nov 12, 2026
c89de83
docs: record the unpushed host-session work and the browser-start fal…
Nov 12, 2026
bbb78fc
fix(database): read a malformed data-view cell as its column default
Nov 12, 2026
7385047
fix(blocks): refuse an oversized fractional index key with a named error
Nov 12, 2026
83af34d
fix(blocks): keep a shadow-held portal open on a click inside it
Nov 12, 2026
1982460
fix(blocks): count only list items when importing an html start number
Nov 12, 2026
33d8b68
fix(edgeless): cache a canvas character's width by the whole character
Nov 12, 2026
44335e0
docs(database): record the virtual table's missing row open button
Nov 12, 2026
09c9e1c
test(blocks): take every deep shadow query from the shared helper
Nov 12, 2026
b1c6ce3
feat(blocks): unify the emoji picker on the callout's emoji-mart picker
Nov 12, 2026
549b801
fix(blocks): write list markers in plain text
Nov 12, 2026
eb08a8e
fix(blocks): keep frequently used for every emoji picker after one wi…
Nov 12, 2026
945e2b0
fix(database): give a duplicated column its own option ids
Nov 12, 2026
1bc03d0
fix(edgeless): follow a middle click in the canvas viewer through its…
Nov 12, 2026
a49fc3f
fix(blocks): open no emoji picker on a read-only callout
Nov 12, 2026
e37de3f
fix(database): keep a rich-text cell stored as a string in a data-view
Nov 12, 2026
1367140
fix(database): keep a rich-text cell stored as a string
Nov 12, 2026
9d7d485
fix(blocks): name the fractional index stack overflow instead of boun…
Nov 12, 2026
47901a7
fix(blocks): separate copied blocks by a newline in plain text
Nov 12, 2026
d000e2c
fix(database): drag-to-fill a rich-text cell stored as a string
Nov 12, 2026
5e4f935
fix(blocks): name the fractional index overflow on firefox too
Nov 12, 2026
9b1226e
fix(edgeless): drop the canvas viewer's auxclick branch for other but…
Nov 12, 2026
de75035
refactor(blocks): move the list start number rule to affine-shared
Nov 12, 2026
66f812d
fix(blocks): copy the text alone from inside one list item
Nov 12, 2026
0de5685
Merge branch 'fix/fractional-index-between' into recette/2026-11-12
Nov 12, 2026
e5fcb33
Merge branch 'fix/list-export-start' into recette/2026-11-12
Nov 12, 2026
d1cb264
Merge branch 'fix/database-cell-default' into recette/2026-11-12
Nov 12, 2026
4163d80
Merge branch 'fix/select-tag-blank-name' into recette/2026-11-12
Nov 12, 2026
7fb6da6
Merge branch 'fix/database-readonly-row-open' into recette/2026-11-12
Nov 12, 2026
9d43478
Merge branch 'fix/table-selection-keeps-canvas' into recette/2026-11-12
Nov 12, 2026
2a56c1c
Merge branch 'fix/code-toggle-double' into recette/2026-11-12
Nov 12, 2026
1d2f5d2
Merge branch 'fix/menu-toggle-row' into recette/2026-11-12
Nov 12, 2026
91f4f67
Merge branch 'feat/icon-picker-standalone' into recette/2026-11-12
Nov 12, 2026
e4a9135
Merge branch 'feat/unified-emoji-picker' into recette/2026-11-12
Nov 12, 2026
08aa090
Merge branch 'feat/mindmap-headless-builder' into recette/2026-11-12
Nov 12, 2026
babac7d
Merge branch 'feat/canvas-viewer-editor' into recette/2026-11-12
Nov 12, 2026
3235c76
Merge branch 'fix/data-view-cell-default' into recette/2026-11-12
Nov 12, 2026
5bb7118
Merge branch 'fix/database-duplicate-property-options' into recette/2…
Nov 12, 2026
3586ae2
Merge branch 'fix/outline-setting-toggle' into recette/2026-11-12
Nov 12, 2026
4f5d947
Merge branch 'fix/portal-click-away-composed' into recette/2026-11-12
Nov 12, 2026
bff0877
Merge branch 'fix/text-char-width-codepoint' into recette/2026-11-12
Nov 12, 2026
e2c578e
Merge branch 'fix/list-html-import-order' into recette/2026-11-12
Nov 12, 2026
406824a
Merge branch 'fix/plain-text-list-markers' into recette/2026-11-12
Nov 12, 2026
d1d7c97
Merge branch 'fix/plain-text-block-separator' into recette/2026-11-12
Nov 12, 2026
a94136b
Merge branch 'docs/lessons-3-5-0' into recette/2026-11-12
Nov 12, 2026
bbbfb00
chore: refresh the architecture map for the recette merge
Nov 12, 2026
7cb87b5
chore(blocks): drop the switch click stop the toggle fix made redundant
Nov 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(playground): open the document in the canvas viewer
The debug menu's "Open in Canvas Viewer" serializes the document and posts
it to examples/canvas-viewer, a page of its own (importing the viewer moves
the page's styles to adopted sheets). A selected frame or group opens
frozen; a click expands it. The strict variant loads under Labre Sites'
policy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Loading branch information
r and claude committed Nov 12, 2026
commit 9cb0812a0da95e26021913f8fccf65425df67739
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ import { toast } from '@labre/affine/components/toast';
import { StoreExtensionManagerIdentifier } from '@labre/affine/ext-loader';
import { BlockSuiteError, ErrorCode } from '@labre/affine/global/exceptions';
import type { SerializedXYWH } from '@labre/affine/global/gfx';
import { ColorScheme, type DocMode } from '@labre/affine/model';
import {
ColorScheme,
type DocMode,
FrameBlockModel,
GroupElementModel,
} from '@labre/affine/model';
import {
defaultImageProxyMiddleware,
docLinkBaseURLMiddleware,
Expand Down Expand Up @@ -71,6 +76,7 @@ import { css, html } from 'lit';
import { customElement, property, query, state } from 'lit/decorators.js';
import * as lz from 'lz-string';
import type { Pane } from 'tweakpane';
import { encodeStateAsUpdate } from 'yjs';

import type { CommentPanel } from '../../comment/index.js';
import { createTestEditor } from '../../starter/utils/extensions.js';
Expand Down Expand Up @@ -549,6 +555,48 @@ export class StarterDebugMenu extends ShadowlessElement {
}, duration);
}

/**
* Opens the document in the read-only canvas viewer, on a page of its own
* (`examples/canvas-viewer`): importing the viewer here would move the
* editor's own styles to adopted sheets. A selected frame or group is shown
* frozen, as a host shows a frame inserted in a page; `strict` loads it
* under Labre Sites' Content-Security-Policy.
*/
private _openCanvasViewer(strict: boolean) {
const selected = this.editor.std
? this.editor.std.get(GfxControllerIdentifier).selection.selectedElements
: [];
const [first] = selected;
const focus =
selected.length !== 1
? undefined
: first instanceof FrameBlockModel
? { kind: 'frame' as const, id: first.id }
: first instanceof GroupElementModel
? { kind: 'group' as const, id: first.id }
: undefined;
const docTitles = Object.fromEntries(
this.collection.meta.docMetas.map(meta => [meta.id, meta.title])
);
const state = encodeStateAsUpdate(this.doc.spaceDoc);
const page = strict ? 'strict.html' : 'index.html';
const viewer = window.open(`/examples/canvas-viewer/${page}`, '_blank');
if (!viewer) return;
const onReady = (event: MessageEvent) => {
if (event.source !== viewer) return;
if (
(event.data as { type?: string })?.type !== 'labre:canvas-viewer-ready'
)
return;
window.removeEventListener('message', onReady);
viewer.postMessage(
{ type: 'labre:canvas-viewer', state, focus, docTitles },
window.location.origin
);
};
window.addEventListener('message', onReady);
}

private _present() {
if (!this.editor.std || !this.editor.host) return;
const gfx = this.editor.std.get(GfxControllerIdentifier);
Expand Down Expand Up @@ -932,6 +980,17 @@ export class StarterDebugMenu extends ShadowlessElement {
</sl-menu-item>
</sl-menu>
</sl-menu-item>
<sl-menu-item>
Open in Canvas Viewer
<sl-menu slot="submenu">
<sl-menu-item @click="${() => this._openCanvasViewer(false)}">
Canvas Viewer
</sl-menu-item>
<sl-menu-item @click="${() => this._openCanvasViewer(true)}">
Canvas Viewer, Strict CSP
</sl-menu-item>
</sl-menu>
</sl-menu-item>
<sl-menu-item @click="${this._toggleStyleDebugMenu}">
Toggle CSS Debug Menu
</sl-menu-item>
Expand Down
11 changes: 11 additions & 0 deletions packages/playground/examples/canvas-viewer/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Canvas viewer</title>
</head>
<body>
<script type="module" src="./main.ts"></script>
</body>
</html>
88 changes: 88 additions & 0 deletions packages/playground/examples/canvas-viewer/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* The read-only canvas viewer (ADR 0050, ADR 0051), opened from the starter's
* debug menu ("Open in canvas viewer") on the document being edited.
*
* A page of its own, never the starter: importing the viewer moves the
* library's styles to adopted sheets for the whole page, which the editor
* beside it must not get. `strict.html` loads this same script under Labre
* Sites' Content-Security-Policy. The opener posts the state once this page
* says it is ready.
*/
type ViewerRequest = {
type: 'labre:canvas-viewer';
state: Uint8Array;
focus?: { kind: 'frame' | 'group'; id: string };
docTitles: Record<string, string>;
};

const violations: string[] = [];
document.addEventListener('securitypolicyviolation', event => {
violations.push(`${event.violatedDirective} ${event.sourceFile}`);
console.warn('[canvas viewer] refused:', event.violatedDirective, event);
});

// CSSOM only: a strict policy refuses `<style>` and `style` attributes.
const page = document.body.style;
page.margin = '0';
page.fontFamily = 'sans-serif';

const status = document.createElement('p');
status.textContent = 'Waiting for the starter to send its document…';
const host = document.createElement('div');
host.style.width = 'min(960px, 100vw)';
host.style.margin = '0 auto';
document.body.append(status, host);

let dispose: (() => void) | null = null;

/** The policy reports arrive as the canvas paints: read them a moment later. */
const REPORT_DELAY_MS = 1500;

async function mount(request: ViewerRequest, interactive?: boolean) {
const { mountCanvasViewer } = await import('@labre/affine/canvas-viewer');
dispose?.();
const frozen = request.focus && !interactive;
host.style.height = frozen ? '' : 'calc(100vh - 80px)';
const viewer = mountCanvasViewer(host, request.state, {
focus: request.focus,
interactive,
docTitles: request.docTitles,
onOpenDoc: docId => {
status.textContent = `onOpenDoc("${docId}")`;
},
onLinkClick: url => {
status.textContent = `onLinkClick("${url}")`;
},
// The host opens the larger view: the same focus, interactive.
onExpand: () => void show(request, true),
});
dispose = viewer.dispose;
const what = request.focus
? `${request.focus.kind} ${request.focus.id}, ${
frozen ? 'frozen: a click, Enter or Space expands' : 'interactive'
}`
: 'whole canvas, interactive';
setTimeout(() => {
status.textContent = `${what} · policy reports: ${violations.length}`;
}, REPORT_DELAY_MS);
}

async function show(request: ViewerRequest, interactive?: boolean) {
try {
await mount(request, interactive);
} catch (error) {
status.textContent = `The viewer refused this document: ${String(error)}`;
}
}

window.addEventListener('message', event => {
if (event.origin !== window.location.origin) return;
const request = event.data as ViewerRequest | null;
if (request?.type !== 'labre:canvas-viewer') return;
void show(request);
});

(window.opener as Window | null)?.postMessage(
{ type: 'labre:canvas-viewer-ready' },
window.location.origin
);
19 changes: 19 additions & 0 deletions packages/playground/examples/canvas-viewer/strict.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<!-- Labre Sites' policy, plus `connect-src` for the dev server's own
socket. Vite's dev server injects each CSS module as a <style>, which
this policy refuses: those reports are the dev server's, a production
bundle links its CSS from 'self'. -->
<meta
http-equiv="Content-Security-Policy"
content="default-src 'none'; script-src 'self'; style-src 'self'; font-src 'self'; connect-src 'self' ws:"
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Canvas viewer, strict policy</title>
</head>
<body>
<script type="module" src="./main.ts"></script>
</body>
</html>
8 changes: 8 additions & 0 deletions packages/playground/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ export default defineConfig(({ mode }) => {
input: {
main: resolve(__dirname, 'index.html'),
'examples/inline': resolve(__dirname, 'examples/inline/index.html'),
'examples/canvas-viewer': resolve(
__dirname,
'examples/canvas-viewer/index.html'
),
'examples/canvas-viewer/strict': resolve(
__dirname,
'examples/canvas-viewer/strict.html'
),
},
treeshake: true,
output: {
Expand Down