Skip to content

feat(blocks): canvas viewer, headless mind map, icon picker and fixes for 3.5.0 - #664

Merged
formicoidea merged 105 commits into
blocksuite-labre-mainfrom
feat/lib-3-5-0
Nov 13, 2026
Merged

formicoidea merged 105 commits into
blocksuite-labre-mainfrom
feat/lib-3-5-0

Conversation

@formicoidea

Copy link
Copy Markdown
Owner

Intention — The PO asked to finish everything started on the library side so that 3.5.0 can be published, even where hosts had only taken part of it, then to clear the debt that the reviews turned up. One consolidated PR, which the PO chose over 21 single-topic PRs: each topic was developed, reviewed and accepted on its own branch, and those branches are merged here as they are. Four groups of work:

Test — usine check (format, build, unit, architecture map, couplings) is green on 7cb87b5, and so are the integration specs this branch touches. Details below.

Risque

  • Red zone: packages/affine/model (mind map styles; the library's palette values now live in its theme). No stored field is added or changed: a parity spec against @toeverything/theme and a deep equality of DefaultTheme hold the stored colours.
  • Dependencies move between packages without changing the core bundle's set: @emotion/css into affine-shared, emoji-mart into affine-components.
  • Host-visible changes are listed in the changesets: new public entries @labre/affine/canvas-viewer and @labre/affine/components/icon-picker, buildMindmap, and listStartNumber / listPlainTextPrefix / storedShapeIsReadable. Plain-text exports now carry list markers. Five new com.labre.* keys and eleven com.labre.emoji-picker.* keys.

Revert — Squash revert of this PR. Nothing is migrated and no stored format changes, so documents written in between stay readable by 3.4.0.

What is in it

Topic Branch merged here Issue / ADR
Canvas viewer. The viewer is the editor on a read-only store. It draws under the public sites' strict CSP (adopted sheets, the library's own emotion instance, shiki's JavaScript engine). External links render as the author placed them. Pages missing from docTitles show "Access denied". It repaints when the page's fonts load, its frozen view has an accessible name, and a middle click goes through the link checks. feat/canvas-viewer-editor ADR 0050 (amended), ADR 0051
Headless mind map builder. Text measure is injected by the host. Text wraps exactly as the editor wraps it. Headless entries stay zod-only because the theme carries its own palette values. feat/mindmap-headless-builder #662, ADR 0045 (amended)
Host icon picker. openIconPicker(anchor, options) returns IconData, null for Remove, or undefined when cancelled. feat/icon-picker-standalone #636
One emoji picker. The callout's emoji-mart picker is the Emoji tab, beside the Icons tab. No network request. Read-only callouts open nothing. feat/unified-emoji-picker PO decision
A fractional index key no longer sorts after b. A forged key cannot freeze the tab, and a stack overflow becomes a named error. fix/fractional-index-between #655
A malformed database cell reads as its default, with no write. Rich text stored as a string is kept, and drag-to-fill accepts it. fix/database-cell-default #656
A blank select option is drawn as "Untitled". fix/select-tag-blank-name #657
Numbered lists keep their start number in Markdown and HTML export, through one shared rule. fix/list-export-start #658
A table selection keeps the canvas selection. fix/table-selection-keeps-canvas #659
The code toolbar switches flip once. fix/code-toggle-double #660
A read-only desktop table or kanban opens document rows through the host's opener. fix/database-readonly-row-open host need
A menu toggle row flips once and keeps keyboard focus. fix/menu-toggle-row backlog
A malformed data-view cell reads as its default. fix/data-view-cell-default debt
A duplicated column gets its own option ids. fix/database-duplicate-property-options debt
The outline "Show type icon" switch stores its own value. fix/outline-setting-toggle debt
A click inside a shadow-held portal keeps it open (zoom menu). fix/portal-click-away-composed debt
Emoji widths are cached per whole character. fix/text-char-width-codepoint debt
Indented <ol start> imports with the right numbers. fix/list-html-import-order debt
Plain text writes list markers. A copy from inside one item stays bare text. fix/plain-text-list-markers PO decision
Copied blocks are separated by a newline in text/plain. fix/plain-text-block-separator debt
Lessons 37 and 38. docs/lessons-3-5-0 —

How it was verified

  • Per branch. A test that fails on the base and passes after, the package suites, and yarn build.
  • Reviews. One fresh Opus reviewer per branch and a Sonnet second reviewer with a pruning pass. The canvas viewer also had a dedicated security review. The reviews went up to four rounds for the read-only row opening and three for Fractional indexing: generateFractionalIndexingKeyBetween can return a key that sorts after b #655.
  • PO acceptance. Done on a local recette server, for both rounds.
  • Recette branch, all 21 merged. Format, build and architecture map are green, and the 15 touched integration spec files pass. Unit: 709 of 711 files pass. The other 2 hit timeouts under machine load and pass when rerun alone.
  • This tree. usine check is green on 7cb87b5, with Vitest held to 4 workers (VITEST_MAX_FORKS=4, VITEST_MAX_THREADS=4). The same tests ran with the same limits. Four earlier runs at full parallelism on this 8-core workstation each failed on a different load-bound test: timeouts of 0.5 s, 1 s or 10 s, and the two Wardley validation benches. No assertion failed. Every one of those tests passes when run alone, the viewer spec 25/25 and svg-import in 18 ms.

Host follow-ups

These are information for the host sessions only; nothing here changes the host.

  • Labre Sites:
    • bump every @formicoidea/* package to 3.5.0;
    • pass viewExtensions, which carries the framework providers and the link-preview and image-proxy seams;
    • use onLinkClick, and take CommunityCanvasTextFonts from @labre/affine/canvas-viewer;
    • add img-src blob: to the CSP (PO accepted);
    • import the viewer only on site pages, first.
  • Connector: wire buildMindmap with Poppins/Kalam width tables.
  • Shell: use openIconPicker for the workspace icon.
  • FR catalogue: 5 new keys plus 11 emoji-picker keys.

🤖 Generated with Claude Code

r and others added 30 commits November 10, 2026 19:20
…ected

buildMindmap on @labre/affine-gfx-mindmap/interchange (core:
gfx/mindmap/interchange) returns the elements the toolbar's mind map
writes: one styled shape per node, sized as fitContent sizes it from the
caller's MindmapTextMeasure, placed by the view's layout, then the
mindmap element naming them by local id. materializeInterchangeImport
rewrites a mind map's children and their parent onto the minted ids.

layout.ts is typed against a structural LayoutNode; style.ts loads no
lodash (applyNodeStyle moves to apply-style.ts) and joins model
./headless; the headless guard allows @toeverything/theme (data only).

ADR 0045, amendment of 2026-11-10. Refs #662.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…inear time

A server builds what a model sent: a node holds at most 2,000
characters, a word wider than the line is cut searching forward (a line
costs its own width), the widest line is a reduce rather than a spread,
and the materializer passes a mind map entry that is not a record
through instead of throwing after the nodes are written.

Refs #662.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lder

Refs #662.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…arity spec

Refs #662.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… policy

Labre's site serves the viewer with `style-src 'self'` and no
`'wasm-unsafe-eval'`. The 3.5.0-rc.0 viewer mounted there and drew
nothing. Reproduced in a browser against that policy (203 reports),
then fixed:

- every light-DOM component appended its styles as a `<style>` in
  `<head>`: `adoptShadowlessStyles()` (std) moves the registered ones,
  and every later one, to `document.adoptedStyleSheets`, which a CSP
  does not block; the viewer calls it, the editor keeps `<style>`;
- the viewer's own rule was a `<style>`: it is an adopted sheet now, and
  it carries the two declarations `@blocksuite/icons` binds as a `style`
  attribute;
- the code block highlighter compiled Oniguruma to WebAssembly at mount:
  `CodeBlockConfig.engine` picks shiki's JavaScript engine, which the
  viewer asks for (the editor keeps Oniguruma);
- emotion's one `<style>` (tables, databases) has a null sheet under the
  policy: its registered and later rules go to an adopted sheet too;
- the paragraph block rendered a `<style>` in its template: the rule
  moved to its static styles, a higher specificity than the heading
  icon's own rule, so the editor's cascade is unchanged;
- the file drop is not mounted by the viewer (its indicator in `<body>`).

Two reports remain and change nothing on screen: emotion's `<style>`,
created at import, and the icons' `style` attribute.

Found on the way, also fixed: a click on a note's content never reached
its link in a browser, because the note's mask covers it; the link is
now resolved from the elements under the pointer. And `docTitles` names
the other pages, which page references showed as deleted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…clicked block

Found by a fresh review of the strict-CSP round:

- a page listed in `docTitles` became an empty doc with no root, so a
  synced-doc card of it waited forever for content; it now gets an empty
  page with its title and settles;
- the click read every element under the pointer, so a card hidden under
  another note could be followed; the lookup stops at the first block
  under the pointer, and reads the container's root node, so it also
  works inside a shadow root;
- in a shadow root, a class leaving removed every copy of a shared sheet;
  it now removes one occurrence per sheet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…icy blocks

Emotion (the table and database blocks) created its `<style>` at import,
before any canvas viewer existed: one report under the published site's
`style-src`, whose criterion is none.

Every `css` now comes from `@labre/affine-shared/styles`, the library's
one emotion instance, whose rules wait for the next microtask before
reaching emotion's `<style>`. The editor gets them there as before,
before its first render. The canvas viewer calls `adoptEmotionStyles()`
(with `adoptShadowlessStyles()`) at import, while the modules are still
evaluating, so the rules go to an adopted sheet and no `<style>` is ever
created. The replay from `cache.registered` in the viewer is gone.

`@emotion/css` moves from the table and database packages to
`@labre/affine-shared`, the one place that imports it now.

Checked in a browser under the viewer pages' policy (`script-src 'self'
'wasm-unsafe-eval'; style-src 'self'; style-src-attr 'unsafe-inline'`):
no report, no `<style>` in `<head>`, the table styled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…m the registry

The PO's principle for the viewer: a mirror of the interactive editor,
generated by the library so that changing the editor changes it, with no
maintenance of its own (ADR 0051, superseding in part ADR 0050).

`mountCanvasViewer` now mounts the `edgeless` scope of the view registry
(every flag on) plus the host's providers (`viewExtensions`: each
framework bundle, which the published core leaves to the bundles), minus
`READ_ONLY_EXCLUDED_VIEW_EXTENSIONS` and `READ_ONLY_EXCLUDED_EXTENSIONS`,
the one list of tooling, kept beside the registry in `extensions/view.ts`
with `getReadOnlyViewProviders`. On the read-only store the editor takes
the pan tool, so the viewer's own pan, wheel and pinch handlers are gone,
and with them the shared wheel module ADR 0050 asked for: the edgeless
root is back to the default branch, unchanged.

The viewer keeps only the host's integration (links resolved under a
note's mask, the frozen view of a frame, framing, the light theme) and
the strict-policy measures.

`read-only-view.unit.spec.ts` compares what the editor and the viewer
register in a real DI container: no excluded entry may paint content (a
block view, a canvas element's view or renderer), nothing may be missing
unless excluded, no exclusion may be stale. Excluding the paragraph
provider makes it fail on `BlockView|affine:paragraph`.

Checked in a browser under the viewer pages' policy: the editor root
mounts, no report, the drag pans, a click on a page reference reaches
`onOpenDoc`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…olicy

The 3.5.0-rc.0 viewer mounted on Labre's site and drew nothing under the
page's Content-Security-Policy. This spec mounts the viewer in a frame
whose policy is stricter than the site's (`script-src 'self'`, no
`'wasm-unsafe-eval'`; `style-src 'self'`; `style-src-attr
'unsafe-inline'`), on a page whose frame holds a filled shape, and counts
the shape's pixels on the canvases: a whole canvas and one frame frozen
in a page. It also fails on any `<style>` element or any policy report
whose source is the library rather than Vite's own dev CSS injection.

With `adoptShadowlessStyles()` switched off, it fails as the site did:
0 pixels on the whole canvas.

A shim module defines `__vitest_browser_runner__.wrapDynamicImport`,
which Vitest's browser mode writes into every dynamic `import()` it
serves and which only its own frame defines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fter a drag

- getReadOnlyViewExtensions is the one list mountCanvasViewer mounts; the
  guard reads it instead of recomposing it, and counts AffineInlineSpec as
  content
- a key typed while the pointer rests on an interactive canvas reaches the
  page: the editor's dispatcher pauses for that key, then resumes
- a keyboard click (detail 0) never counts as the end of a drag
- the spec names its constants and no longer leaves an unused variable

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DatabaseBlockDataSource.getCellValue returned undefined when the stored
value failed the property's rawValue.schema (a type change, an import, a
peer on another version). It now returns rawValue.default(), at the read
boundary only: the stored value is kept as is and nothing is written.

Port of toeverything/AFFiNE#15809 (1433ac7). Closes #656.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the subkeys of a and b share a prefix,
generateFractionalIndexingKeyBetween(a, b) appended '0' and a random
postfix to generateKeyBetween(a, b). If b itself continues with that key
plus '0', the postfix decided the order and the new key could sort after
b: inserting a table row or column right after the first one reordered
it within about twenty inserts. The key now moves towards b until b no
longer continues with key + '0' (upstream toeverything/AFFiNE#15709).

Only newly generated keys change; stored keys are read and compared as
before.

Closes #655

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`@labre/affine/components/icon-picker` re-exports the icon picker so a host
importing only public entries can reuse it (issue 636: the Labre shell's
workspace icon). `openIconPicker(anchor, options)` opens `affine-icon-picker`
in a portal anchored to the element and resolves with the picked `IconData`
(plain JSON), `null` for Remove, or `undefined` on Escape, a click outside,
the host's `signal`, the anchor leaving or a second opening; the popup
closes in every case and Escape stops before a host dialog.

The three elements take an optional `translation` (the host's
`TranslationService`) so the picker reads in the host's language without
`std`, English otherwise. `effects()` is now idempotent; nothing is defined
at import. The playground debug bar gains an "Icon Picker (host demo)"
button that goes through the public entry only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The table selection controller wrote its selection with `set` and
cleared it with `clear()`, both of which replace every selection group.
In edgeless that dropped the `gfx` group: the note being edited left edit
mode when the caret entered a cell, and selecting then clearing a column
wiped an unrelated canvas selection. `setSelected` now writes only the
`TableSelection` group through `setGroup` (issue #659, upstream
toeverything/AFFiNE#15791).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A numbered list that does not start at 1 keeps its start number in the
order prop of its first list block, and the Markdown and HTML imports
already read it from the list start. Both exports dropped it, so the
exported list restarted at 1 and an export then import round trip lost
the numbering. The markdown and html list adapters now write start on a
new numbered list when the first item's order is an integer above 1
(upstream toeverything/AFFiNE#15726). A list at 1 or without an order
exports unchanged. The clipboard's text/html copy uses the same adapter.

Closes #658

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The builder's own wrap dropped the trailing space wrapText keeps on a line
broken before a word, ignored hyphens and cut long words one character later,
so a node long enough to break was stored 4 to 9 px narrower than the editor
lays it out. wrapMindmapText is now wrapText line for line with the injected
width, held to the real function on a corpus by mindmap-headless.spec.ts.

A measure answering NaN, a negative or an infinite size throws
MindmapMeasureError instead of looping. The parity spec now covers the four
styles and three layouts, a wrapping node, and a toolbar-made map read prop
for prop; the unit spec tests both caps at their bound, a refusal that quotes
no text, the measure as the only source of size, and the child index against
generateKeyBetween up to the node cap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dropping lodash last from the style getters must leave a node deeper than
style two's palette on its last colour. Checked once against the getters
before the change on 12 000 paths of the four styles; this keeps the branch
that changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Build Mind Map (headless) calls buildMindmap with the browser's measure,
writes the result with the materializer at the top-left of the view, and
reports how many nodes the editor's own layout moved on landing (zero is the
expected answer). Each click takes the next of the four styles.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ecette

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A frozen frame was framed edge to edge, so the badge the editor draws above
the frame's top edge was clipped. The view now keeps a strip of the badge's
height (28px) above a titled frame: its aspect-ratio adds that strip for the
current width and is read again on each resize, and fit() frames the frame
under it.

The viewer's adopted sheet also carries vertical-align: middle for a page
reference's icon, which @blocksuite/icons asks for in a style attribute that
a strict policy refuses. CommunityCanvasTextFonts is re-exported from the
canvas-viewer entry for a public page that serves the faces itself.

Guards: the read-only view spec names the frame-title widget among the
viewer's and the editing toolbars outside it (excluding the widget made the
four other cases pass and this one fail); the viewer spec asserts that mount,
zoom and a click leave the shown Y.Doc's state vector unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The spec ran with style-src-attr 'unsafe-inline', so it could not see an
attribute report. It now runs under default-src 'none'; script-src 'self';
style-src 'self'; font-src 'self', waits until the shape is painted instead
of a fixed delay (180s deadline, cold dev-server imports took over 60s here),
and its page holds a linked-doc card, a formatted note and a page-only note.

Both cases assert painted pixels, no style element, the frame badge shown
inside the view and no editing chrome. The two known reports are named and
let through: one style-src-attr per icon whose declarations the viewer's
sheet carries, and the data: drag image pragmatic-drag-and-drop preloads.
Any other report fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The static HTML guide says what importing the viewer already calls
(adoptShadowlessStyles, adoptEmotionStyles, the JavaScript regex engine),
what the policy still needs from the host, which reports remain and why the
viewer belongs on a page without the editor. ADR 0051 gains an amendment
with the measurements under the site's policy and the frame badge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
In the code block's "more" menu, a click on the Wrap or Line number
switch flipped the switch and bubbled up to its `editor-menu-action`
row, which flipped the setting a second time; the switch was bound
through the `checked` attribute, so its drawn state drifted from the
model (issue #660, upstream toeverything/AFFiNE#15782).

`ToggleSwitch` now stops the click at its label, reads the new value from
the checkbox and binds `.checked` as a property. Each code toolbar row
hands its switch an `onChange` that shares the row's write, so a click on
the switch or on the row flips the setting once, and both refuse a
readonly store before writing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A select or multi-select option whose name is empty or blank drew an
empty pill: invisible in cells and in the tag menu, and as a kanban group
title a zero-height strip that could not be clicked to rename it.

The pill, the cell tag, the mobile picker and the group title now draw
TAG_UNTITLED (com.labre.data-view.tag.untitled, "Untitled") through one
tagLabel helper, the tag menu finds blank options by that label, the
rename fields take it as placeholder, and the group title keeps a
min-height. Display only: the stored option name is never rewritten.
The manifest's chrome dedupe keeps the word apart from the page's
DOC_UNTITLED (a name, not a title).

Port of toeverything/AFFiNE#15807 (a2d1584). Closes #657.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A shell edit had left the deadline's Error without its message, and the
stage it reads unused (TS6133 in yarn build).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The page is a script with no top-level import, so a top-level status
clashed with the global (TS2451 in yarn build).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The viewer imports the frame-title widget's style constants; the playground
gains its examples/canvas-viewer page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
r and others added 20 commits November 12, 2026 20:45
# Conflicts:
#	architecture/code.c4
#	packages/playground/apps/_common/components/starter-debug-menu.ts
# Conflicts:
#	architecture/code.c4
#	packages/playground/apps/_common/components/starter-debug-menu.ts
Both toggle fixes are in this branch: <toggle-switch> stops its own click
at its label, so the menu row's extra stop on the switch's host is
redundant, as its ponytail line said. The icon picker's comment no longer
says the portal reads event.target.

Land-Verified: 2026-11-12T22:30:00+01:00 rounds=4
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@formicoidea

Copy link
Copy Markdown
Owner Author

Résumé de session

  • Demande du PO : terminer pour la 3.5.0 tout ce qui avait été démarré côté lib (viewer ADR 0051 et carte mentale sans éditeur, laissés non poussés par des sessions hôte ; sélecteur d'icônes Export the icon picker so a host can reuse it (workspace icon) #636 ; correctifs amont Fractional indexing: generateFractionalIndexingKeyBetween can return a key that sorts after b #655–code block: wrap and line-number switches toggle twice and drift from the stored setting #660), puis, après une première recette, traiter la dette relevée par les relectures.
  • Réorientations : un seul sélecteur d'emoji (celui du callout, avec l'onglet Icônes) ; marqueurs de liste dans le texte brut ; échec propre, sans borne de longueur, pour une clé d'ordre forgée ; valeurs de palette déplacées dans le thème de la lib plutôt que d'admettre @toeverything/theme dans les entrées sans éditeur ; liens externes du viewer rendus comme posés, pages non fournies affichées « Access denied ». Une PR consolidée a été préférée à 21 PR.
  • Écarté : un champ d'icône dans le modèle du callout (ADR et zone rouge) ; la vie privée par défaut dans le viewer ; un bouton d'ouverture inventé pour la table virtuelle (dette notée par une ligne ponytail:).
  • Relectures : un relecteur Opus et un second relecteur par branche, plus une revue de sécurité du viewer, jusqu'à quatre tours. Chaque défaut trouvé a été corrigé avec un test rouge avant et vert après.
  • Contrôle : usine check vert avec 4 workers Vitest. À pleine parallélisation sur un poste à 8 cœurs, des délais sautent sous la charge (leçon 38).
  • Livré : 3.5.0 publiée sur npm (chore: version packages (3.5.0) #665). Les sessions hôte ont reçu les entrées et les 16 clés FR. La dette restante est listée dans la section 11 du compte rendu Notion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant