Repository navigation
feat(ui): host selection actions and comment mention source seams; ui 0.43.0 - #1572
Merged
Merged
Conversation
…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.
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.
Problem
Two host asks of the same shape have been sitting behind an owner ruling. A host that installs
@plannotator/uicannot 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.
AnnotationToolbarselectionActions(threaded fromViewerandHtmlViewer)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, inFloatingQuickLabelPicker's placement andQuickLabelDropdown's chrome (components/SelectionActionsDropdown). Selecting an item callsonSelect(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.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: withquickLabels: 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.undefinedand[]render no button (the empty array is a real state and is pinned).buildSelectionActionContext(pure) walks up for[data-block-id]and computes the offset by splitting the block's text — deliberately the same arithmeticcreateAnnotationFromSourceuses, 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.
AnnotationToolbarquickLabels(defaulttrue)falsehides 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 asAnnotationToolstrip'shideQuickLabel.3.
CommentPopovermentionSourceMentionPersonis copied field for field from the Workspaces host's ownplannotator/mention-extension.ts, so the host fillspeoplefrom its existing candidate hook with nothing to map. The package owns the typing rules and the picker; the host owns the people.utils/mentions(pure, unit-tested): the sameMENTION_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@Labelinsertion 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.components/MentionPicker) is portaled andposition: 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", rowsdata-mention-option="<id>", empty noticedata-mention-empty;people: []with no notice keeps the menu closed.hooks/useMentionAutocomplete, modelled onuseSkillReferenceAutocompleteand 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: acanOpen: falseperson 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.onMentionsChange(ids)on every text change, and an optional thirdonSubmit(text, images?, mentions?)argument passed only whenmentionSourceis supplied.configurePlannotatorUIseam — there is no mention provider in this repo. It is a prop where you render the composer, theHtmlViewerpattern.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, andhandleKeyDownoffers each event to the skill hook first. Its menu component is not reused:SkillReferenceMenuis absolutely positioned inside the textarea's wrapper, while the mention picker must match the host's own portaled/fixedMentionPicker(and the host's picker is what a Workspaces user is already used to). The pure grammar lives inutils/mentionsfor the same reasonskillReferences.tsexists.No-op guarantee and how it is pinned
Plannotator passes neither prop anywhere:
packages/editorandpackages/review-editorare untouched by this PR.AnnotationToolbarand the defaultCommentPopoverwere mounted in the same harness onorigin/main(a second worktree) and on this branch, and theirouterHTMLdiffed: identical, 6376 bytes each. Artifacts:scratchpad/base-dom.txtandscratchpad/branch-dom.txt.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).useMentionAutocompletewith no source registers no listener, never opens menu state and returns one frozen empty array;AnnotationToolbarrenders no extra element and spreads no extra attributes.Tests
Behavior only, no copy snapshots.
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 withquickLabels: false; dropdown opens, arrow + Enter callsonSelectwith the righttext/blockId/offsets/element; click invokes; Escape closes the dropdown and not the toolbar; Alt+digit live by default and dead withquickLabels: 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;onPickBlockedboth branches; empty notice; absent source renders no list and no extra DOM.DOM_TESTSstep —scripts/dom-test-allowlist.test.tsfails otherwise (it caught this).Counts on this branch:
bun test packages/ui packages/editor packages/review-editorDOM_TESTS=1 bun test packages/ui packages/editor packages/review-editorbun test(full)bun run typecheckThe 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
scratchpad/seam-selection-actions.png@menu open in the composer:scratchpad/seam-mention-source.pngorigin/main:scratchpad/base-dom.txtvsscratchpad/branch-dom.txttheme.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
MentionPersonverbatim; 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 asyncsearch()would have added a state machine nobody needs. A host that needs async can memoize intopeople; say the word and it becomes a union.mentions: [{ id, label }]return shape was not used; the host's ownNewCommentcarriesreadonly string[], so ids are what is reported. Labels are recoverable from thepeoplelist the host supplied.canOpen: falserows 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 getsonPickBlockedinstead.Viewerdoes not forwardmentionSource. 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.PlanCleanDiffViewis not threaded — a Plannotator-only surface, not on the supported-import list.SkillReferenceMenudoes today. Left as-is for consistency; anchoring to the card instead is a small follow-up if it bothers anyone.