Repository navigation
Click elements in the viewer and playground (0.5.0) - #7
Merged
Merged
Conversation
onElementClick(hit, hits, event), onElementHover and selected (a line or lines), on tsquare 0.14's viewer events. Hovered elements get a dashed outline when the board is clickable. The board is measured only when one of the three props is set; while the text has problems, nothing is clickable or outlined (the last valid board's lines no longer match). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clicking an element selects its line in the editor; the caret's element
is outlined on the board. On by default; linkBoard={false} turns it off
and skips measuring. WireframeEditor gets onCursorLine, to connect your
own editor and viewer. A hover outline now goes as soon as the board
stops being clickable, instead of at the next redraw.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ether After Enter in the playground, the caret's new line was matched against the board still on show (the older text's lines) and briefly outlined a neighbor. useBoard now knows a board is behind from the render that brings the new text (pending was set in an effect, a render late), and the viewer keeps its outline until the board catches up. A test records every outline drawn and checks the old board's line is never used. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
While the board is behind the text the outline is held, but a board for text edited since can land in that window (its draw started before the last edit). The held outline was drawn on the board before and doesn't fit the new one, so it's cleared until a board matches the text. Tested with BoardViewer's states in exact order (Copilot on tsquare#50 found the same window in the library's playground). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Pending-board handling leaves cleared selection outlines visible and delivers clicks using stale line numbers, which can select the wrong editor line before redraw.
2 open issues
What changed in this PR
This PR brings tsquare 0.14’s element interactions to the React components in release 0.5.0, connecting viewer selections with editor caret positions.
Changes:
- Adds viewer click and hover callbacks, line-based outlines, and optional element measurement.
- Adds playground selection syncing and editor cursor-line notifications, with pending-board handling.
- Updates dependencies, public types, documentation, and interaction tests.
| File | Description |
|---|---|
test/react.test.tsx |
Adds interaction, selection, measurement, and pending-board tests. |
src/viewer.tsx |
Adds element callbacks and hover/selection outlines. |
src/use-board.ts |
Adds optional measurements and render-time pending detection. |
src/playground.tsx |
Connects board clicks and editor caret selection. |
src/index.ts |
Exports measured-element types. |
src/editor.tsx |
Exposes cursor-line notifications. |
README.md |
Highlights viewer element interactions. |
package.json |
Sets version 0.5.0 and requires tsquare 0.14. |
package-lock.json |
Locks the updated release and dependency versions. |
docs/viewer.md |
Documents callbacks, outlines, and pending-board behavior. |
docs/styling.md |
Documents highlight colors and classes. |
docs/README.md |
Adds element interaction guidance. |
docs/playground.md |
Documents selection syncing and its opt-out. |
docs/editor.md |
Shows editor/viewer integration by line. |
CHANGELOG.md |
Summarizes the 0.5.0 release. |
Review effort: Balanced
…ed doesn't wait A click on a board that's behind its text reported the older text's line, so the playground could put the caret on a neighbor after a line was inserted above. Clicks now wait for the board, like the outline. Clearing selected (null, [], syncSelection off) while behind left the outline showing until the redraw; it now clears right away. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Brings tsquare 0.14's viewer events to the React components.
<WireframeViewer>onElementClick(hit, hits, event): the element or flow arrow clicked (a press that hardly moves; dragging still pans) and everything under the point, most likely first. Empty board outside the screens gives the board (type: "Board").onElementHover(hit, hits): follows the pointer;nullwhen it leaves.selected: a line or a list of lines to outline (solid). A line inside a block outlines that block, so an editor's caret line works.onElementClickis set; it goes as soon as the board stops being clickable.sourceandselectedchange together (Enter in an editor), the outline waits for the new board instead of matching the new line against the old board's lines.useBoard'spendingis now true from the render that brings the text (it was set in an effect, a render late). A board for older text that lands in that window clears the outline (it was drawn on the board before) until a board matches the text.<WireframePlayground syncSelection>(defaulttrue): click an element to select its line in the editor; move the caret and its element is outlined on the board.syncSelection={false}turns both off and skips measuring.<WireframeEditor onCursorLine>: the caret's line when it moves to another one, to connect your own editor and viewer (selected+goToLine).Behavior
useBoardmeasures the elements (measureElements, about one more render) only when needed: an element prop on the viewer, orsyncSelectionin the playground. Other boards cost the same as before.Measured,MeasuredElement,MeasuredFlow,MeasuredBoxtypes exported. Needs tsquare^0.14.0. Version 0.5.0.Docs: WireframeViewer: props and a "Clicking elements" section. Playground:
syncSelectionand "Clicking the board". Editor:onCursorLineand "Next to a viewer" (editor + viewer connected by line). Styling:--tsquare-highlightand thetsquare-highlightclasses. Overview, README and CHANGELOG.Tests (32 pass): viewer click (button with
["Button", "Screen", "Board"]under it, drag isn't a click, empty board gives the board); hover reports, outlines only when clickable, clears on leave and whenonElementClickgoes;selected(line, list, container, board line,null, problems); measuring only when asked; playground click → caret line → outline, caret move → outline, hover,syncSelection={false}turning all of it off; editoronCursorLine; clicks on a board that is behind are not reported and clearingselectedclears at once; text andselectedchanging together never outline the old board's element on the new line (every drawn outline recorded; both halves of the fix mutation-checked; a real Enter checked in Chrome). Mutation-checked: removing each behavior fails its test. Checked in Chrome on demo pages for the viewer and the playground (with the toggle).🤖 Generated with Claude Code