Skip to content

Improve indicators API #6395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Improve indicators API #6395

wants to merge 3 commits into from

Conversation

steveruizok
Copy link
Collaborator

This PR solves a long-standing todo, which replaces the hard-coded list of "show indicators" to state nodes instead. As a result, we can remove the <TldrawShapeIndicators> component that provided that logic.

Change type

  • bugfix
  • improvement
  • feature
  • api
  • other

Release notes

  • SDK: Added shouldShowIndicators() to StateNode, used to configure whether indicators should be shown when in the state

Copy link

vercel bot commented Jul 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
analytics ✅ Ready (Inspect) Visit Preview Jul 4, 2025 7:34pm
examples ✅ Ready (Inspect) Visit Preview Jul 4, 2025 7:34pm
1 Skipped Deployment
Name Status Preview Updated (UTC)
tldraw-docs ⬜️ Ignored (Inspect) Visit Preview Jul 4, 2025 7:34pm

@huppy-bot huppy-bot bot added the api API change label Jul 4, 2025
Copy link
Contributor

@SomeHats SomeHats left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

into it! some minor API nits

@@ -2735,6 +2735,7 @@ export abstract class StateNode implements Partial<TLEventHandlers> {
getCurrentToolIdMask(): string | undefined;
getIsActive(): boolean;
getPath(): string;
getShouldShowIndicators(): boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For similar flags in e.g. shape utils we drop the get and just do canDoX() etc.

For things like this where the function name is unambiguously returning a boolean and not performing an action, I think we can drop the get and have a shorter, easier to read name

Comment on lines +36 to +43
let shouldShowIndicators = false
let state: StateNode | undefined = editor.getCurrentTool()
// allow deeper state nodes to override the should show indicators value of shallower nodes
while (state) {
shouldShowIndicators = !!state.getShouldShowIndicators()
state = state.getCurrent()
if (!state) break
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd be tempted to make this a method on editor or the root state node for easier reuse. wdyt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api API change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants