-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
base: main
Are you sure you want to change the base?
Improve indicators API #6395
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
packages/editor/src/lib/components/default-components/DefaultShapeIndicators.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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; |
There was a problem hiding this comment.
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
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 | ||
} |
There was a problem hiding this comment.
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?
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
shouldShowIndicators()
toStateNode
, used to configure whether indicators should be shown when in the state