Skip to content

feat(ui): host selection actions and comment mention source seams; ui 0.43.0 - #1572

Merged
backnotprop merged 5 commits into
mainfrom
feat/ui-host-toolbar-seams
Sep 19, 2026
Merged

backnotprop merged 5 commits into
mainfrom
feat/ui-host-toolbar-seams

Conversation

@backnotprop

Copy link
Copy Markdown
Owner

Problem

Two host asks of the same shape have been sitting behind an owner ruling. A host that installs @plannotator/ui cannot put its own commands on a selection (the quick-label list is package-owned and cookie-backed, and no prop lets a host add rows or turn the zap off), and it cannot offer @ mentions in the package's comment composer (the composer already runs a / and $ skill-reference autocomplete, but the host only ever receives finished text). Both were being worked around host-side; neither should be a fork.

The ruling: yes to both, on the condition that each is an opt-in host capability that changes nothing for Plannotator's own users when it is not supplied — Plannotator as the provider of these capabilities, not a product that uses them. Shipped together as ui 0.43.0 with a HANDOFF entry.

Change, per prop

1. AnnotationToolbar selectionActions (threaded from Viewer and HtmlViewer)

Array<{ id, label, detail?, icon?, onSelect(ctx) }> renders as one toolbar button — a wand, data-selection-actions — that opens the package's own dropdown directly below it, in FloatingQuickLabelPicker's placement and QuickLabelDropdown's chrome (components/SelectionActionsDropdown). Selecting an item calls onSelect(ctx) with { text, blockId, startOffset, endOffset, element } and closes the toolbar exactly as a quick label does. The package creates no annotation — what an action means is the host's business.

  • Keyboard: ArrowDown/ArrowUp, Enter, Escape (Escape closes the dropdown only, never the toolbar). Nothing is preselected until the first arrow, the package-wide rule, so a stray Enter never fires a host command. Hover highlights, click invokes. While it is open the toolbar's type-to-comment and Alt+digit listeners stand down, as they already do for the quick-label picker.
  • Slot choice: the wand takes the slot the zap occupied and the zap moves one right (Copy | Delete | Comment | Actions | Quick label | 👍 | Cancel). Picked over "actions to the right of the zap" because one geometry rule then covers both host configurations: with quickLabels: false — the expected host setup — the wand sits exactly where the zap sat, and a host that keeps both gets its own actions in the primary slot it opted into.
  • undefined and [] render no button (the empty array is a real state and is pinned).
  • The selection context is derived, not threaded: buildSelectionActionContext (pure) walks up for [data-block-id] and computes the offset by splitting the block's text — deliberately the same arithmetic createAnnotationFromSource uses, so an action sees the coordinates an annotation from that selection would carry. No extra props at the mount sites. On a block-less surface (raw HTML) it degrades to ''/0/0, which is what an HTML annotation already stores.

2. AnnotationToolbar quickLabels (default true)

false hides the zap picker and makes the Alt+digit label shortcuts inert on that toolbar (hiding the button while leaving the keys live was the obvious bug; both halves are pinned). It does not touch the one-click 👍, and it does not clamp editor mode — same contract as AnnotationToolstrip's hideQuickLabel.

3. CommentPopover mentionSource

mentionSource?: {
  people: readonly MentionPerson[];              // { id, kind, label, detail, canOpen }
  emptyNotice?: string | null;                   // honest-empty row
  onMentionsChange?(ids: readonly string[]): void;
  onPickBlocked?(person: MentionPerson): void;
}

MentionPerson is copied field for field from the Workspaces host's own plannotator/mention-extension.ts, so the host fills people from its existing candidate hook with nothing to map. The package owns the typing rules and the picker; the host owns the people.

  • The grammar is ported, not reinvented into utils/mentions (pure, unit-tested): the same MENTION_QUERY_RE = /@[\w .-]*$/, the same word-boundary guard that makes [email protected] never open a menu, the same users-only / not-already-tagged filtering on label OR detail, the same @Label insertion with the caret after it, and the same surviving-token rule — deleting a token untags that person, so the body and the reported ids can never disagree about who was named.
  • The picker (components/MentionPicker) is portaled and position: fixed, measured from the textarea, above by default and below without headroom (the composer card clips its own box, so an in-wrapper menu is cut off). role="listbox", rows data-mention-option="<id>", empty notice data-mention-empty; people: [] with no notice keeps the menu closed.
  • Keyboard (hooks/useMentionAutocomplete, modelled on useSkillReferenceAutocomplete and living in the same textarea beside it): nothing preselected, so Enter is a newline and Tab leaves the field until an arrow engages a row. One deliberate difference from the //$ trigger, documented in the hook: the arrows engage a bare @ and Escape closes the menu whenever it is visible. $ and / are ordinary prose characters whose menu must yield the arrows back to caret navigation; @ at a word boundary is an unambiguous tag gesture, and @ + ArrowDown is how the host's own reply box already behaves.
  • onPickBlocked: a canOpen: false person picked with the handler supplied fires it and inserts nothing (the host shows its no-access dialog); without the handler that person inserts like anyone else — the package never renders a disabled row it cannot explain. Both branches tested.
  • Ids reach the host two ways: onMentionsChange(ids) on every text change, and an optional third onSubmit(text, images?, mentions?) argument passed only when mentionSource is supplied.
  • Not wired to any Plannotator data, and not a configurePlannotatorUI seam — there is no mention provider in this repo. It is a prop where you render the composer, the HtmlViewer pattern.

Reuse check (asked for explicitly): the composer's existing skill-reference autocomplete (/ and $, #1488) is reused for its rules, not duplicated — the mention hook mirrors its no-preselection state machine, its dismissal memory, its caret-restore timer and its "return true when consumed" keydown contract, and handleKeyDown offers each event to the skill hook first. Its menu component is not reused: SkillReferenceMenu is absolutely positioned inside the textarea's wrapper, while the mention picker must match the host's own portaled/fixed MentionPicker (and the host's picker is what a Workspaces user is already used to). The pure grammar lives in utils/mentions for the same reason skillReferences.ts exists.

No-op guarantee and how it is pinned

Plannotator passes neither prop anywhere: packages/editor and packages/review-editor are untouched by this PR.

  1. Byte-level proof against the base commit. The default AnnotationToolbar and the default CommentPopover were mounted in the same harness on origin/main (a second worktree) and on this branch, and their outerHTML diffed: identical, 6376 bytes each. Artifacts: scratchpad/base-dom.txt and scratchpad/branch-dom.txt.
  2. Committed structural pins (the durable guard, since a snapshot would be copy-pinning): the default toolbar's exact button set and order (Copy, Delete, Comment, Quick label, Looks good, Cancel), no [data-selection-actions] and no picker anywhere in the DOM, the exact attribute list on the zap button, [] rendering no button — and for the composer, that typing @ opens nothing and that submit stays a two-argument call (arguments.length === 2).
  3. By construction: useMentionAutocomplete with no source registers no listener, never opens menu state and returns one frozen empty array; AnnotationToolbar renders no extra element and spreads no extra attributes.

Tests

Behavior only, no copy snapshots.

  • New: utils/mentions.test.ts (11, DOM-free), components/AnnotationToolbar.selectionActions.test.tsx (8, DOM-gated), components/CommentPopover.mentionSource.test.tsx (11, DOM-gated) — 30 tests. Covered: no wand + zap present with props absent; wand present and zap hidden with quickLabels: false; dropdown opens, arrow + Enter calls onSelect with the right text/blockId/offsets/element; click invokes; Escape closes the dropdown and not the toolbar; Alt+digit live by default and dead with quickLabels: false; mention list appears after @ and never on an email; Enter/Tab inert until an arrow; ArrowDown+Enter inserts, reports and submits the id; deleting the token untags; onPickBlocked both branches; empty notice; absent source renders no list and no extra DOM.
  • Both new DOM files are added to the workflow's DOM_TESTS step — scripts/dom-test-allowlist.test.ts fails otherwise (it caught this).

Counts on this branch:

run result
bun test packages/ui packages/editor packages/review-editor 1562 pass, 1086 skip, 0 fail (2648 across 293 files)
DOM_TESTS=1 bun test packages/ui packages/editor packages/review-editor 2633 pass, 1 skip, 5 fail (2639 across 293 files)
bun test (full) 4929 pass, 1134 skip, 0 fail (6063 across 525 files)
bun run typecheck clean

The 5 DOM failures are exactly the pre-existing set on origin/main, diffed name for name (same run on a base worktree: 2603 pass / 5 fail, +30 tests and +3 files on the branch): 4 × DocBadges open-in placement, 1 × artifactContentProxyUrl. The paste-service E2E failures from the known list are outside these three packages and do not appear in the full run here.

Evidence

  • Wand dropdown open (host actions, arrowed to the second row), real Chromium, headless: scratchpad/seam-selection-actions.png
  • @ menu open in the composer: scratchpad/seam-mention-source.png
  • Byte-identical default DOM vs origin/main: scratchpad/base-dom.txt vs scratchpad/branch-dom.txt
  • The throwaway harness that rendered them (Vite + the package source + theme.css, never committed): scratchpad/harness/

Full paths under /private/tmp/claude-501/-Users-ramos-plannotator-plannotator/34d56d5a-33a8-4878-92b2-3f4318214ae2/scratchpad/.

Deviations and open choices

  • Mention shape. Matched to the host's existing reply box exactly (MentionPerson verbatim; the pure helpers keep their names and semantics), rather than to the generic { trigger, search, insert } sketch — the host's list is synchronous and already loaded, so an async search() would have added a state machine nobody needs. A host that needs async can memoize into people; say the word and it becomes a union.
  • The spec's mentions: [{ id, label }] return shape was not used; the host's own NewComment carries readonly string[], so ids are what is reported. Labels are recoverable from the people list the host supplied.
  • canOpen: false rows render normally (not disabled-with-a-reason as in the host's CM6 picker), per the ruling: the package has no reason string and no dialog, so the host gets onPickBlocked instead.
  • Viewer does not forward mentionSource. It owns several composers, and choosing which of them takes a mention source belongs to the host rendering them. Easy to add if you would rather pass it once.
  • PlanCleanDiffView is not threaded — a Plannotator-only surface, not on the supported-import list.
  • The mention picker opens above the textarea and therefore overlaps the composer's own header row, which is the same thing SkillReferenceMenu does today. Left as-is for consistency; anchoring to the card instead is a small follow-up if it bothers anyone.

…tionToolbar

Two opt-in props on the selection toolbar, both defaulting to today's
behavior so Plannotator (which passes neither) is unchanged:

- selectionActions: the host's own commands for the current selection,
  rendered as ONE wand button (data-selection-actions) that opens the
  package's own dropdown below it, in the quick-label picker's placement
  and chrome. Arrow keys + Enter + Escape, nothing preselected until the
  first arrow. Selecting an item calls onSelect with
  { text, blockId, startOffset, endOffset, element } and closes the
  toolbar exactly as a quick label does — the package creates no
  annotation of its own.
- quickLabels (default true): false hides the Zap picker AND makes the
  Alt+digit label shortcuts inert on that toolbar. The one-click thumbs-up
  is a separate affordance and is unaffected.

The wand takes the slot the Zap occupied and the Zap moves one place
right, so one geometry rule covers both host configurations: with
quickLabels:false the wand sits exactly where the Zap sat.

The context is derived from what the toolbar already has —
buildSelectionActionContext reproduces createAnnotationFromSource's block
lookup and offset arithmetic — so no extra props are threaded through the
mount sites. Viewer forwards both props to both of its toolbars;
HtmlViewer forwards selectionActions (its surface is already commentOnly,
so quickLabels has nothing left to hide). PlanCleanDiffView is
deliberately not threaded: it is a Plannotator-only surface.
mentionSource?: { people, emptyNotice?, onMentionsChange?, onPickBlocked? }
over MentionPerson { id, kind, label, detail, canOpen } — the shape the
host's own reply box already uses, so it fills `people` from its existing
candidate hook with nothing to map. The package owns the typing rules and
the picker; the host owns the people and what a mention means. Nothing is
wired to Plannotator data: there is no provider in this repo, and
configurePlannotatorUI gains no seam.

The grammar is ported, not reinvented (utils/mentions, pure + unit
tested): the same trigger regex, the same word-boundary guard that keeps
[email protected] from opening a menu, the same users-only / not-already-tagged
filtering, the same "@Label " insertion, and the same surviving-token rule
so the body and the reported ids never disagree about who was named.

The picker is portaled and fixed, measured from the textarea, above it by
default and below when there is no headroom. Keyboard follows the
package's no-preselection rule (Enter is a newline and Tab leaves the
field until an arrow engages a row), with one deliberate difference from
the / and $ skill trigger documented in the hook: the arrows engage a bare
@, because @ at a word boundary is an unambiguous tag gesture while $ and
/ are ordinary prose characters.

A canOpen:false person inserts nothing when the host supplied
onPickBlocked (the host shows its own no-access dialog) and inserts
normally when it did not. Ids reach the host through onMentionsChange and
through an optional third onSubmit argument that is passed ONLY when a
source is supplied — without one the call stays the two-argument call it
has always been.
@plannotator/core is unchanged at 0.25.5, so ui 0.43.0 publishes alone.
Exports SelectionAction / SelectionActionContext / MentionPerson /
MentionSource / MentionTrigger from @plannotator/ui/types, adds the
HANDOFF entry ("Host toolbar seams (0.43.0)") with both props, their
defaults, the no-op guarantee and the threading points, the matching
README section and supported-import rows, and names the two new DOM-gated
test files in the workflow's DOM_TESTS step (scripts/dom-test-allowlist
fails otherwise).
…ion listbox to the textarea

Review follow-ups on the 0.43.0 host seams, all inert without the props.

- AnnotationToolbar: a picker counts as open only while the button that
  opens it still renders. A host whose selectionActions go empty (or who
  flips quickLabels off) while the dropdown is open unmounted the dropdown
  and its Escape handler but left the flag set, which stood the toolbar's
  own Escape, type-to-comment and outside-dismiss listeners down for good.
  Regression test added.
- AnnotationToolbar: read the action text at invoke time instead of on every
  render, so a toolbar with no host actions never walks the element's text.
- CommentPopover: the generated mention listbox id was passed to the picker
  but referenced by nothing. Point the textarea's aria-controls and
  aria-activedescendant at whichever menu is open, and honor those props in
  the plain (non-skill-reference) textarea, where a mention menu can also
  open. Every value is undefined with no menu open.
- Docs: endOffset on a block-less surface is the selection's length, not 0,
  and the block-spanning selection is the one place the derived context
  deliberately differs from createAnnotationFromSource.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant