WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.57k stars 4.22k forks source link

Consider a generic API for programatically navigating interfaces #46347

Closed talldan closed 4 months ago

talldan commented 1 year ago

What problem does this address?

TLDR - it's too difficult to implement a button or a shortcut that opens up another specific part of the editor interface.

Long version: A common requirement in our editors (and really all applications) is a user action that opens up a specific part of the interface. Some examples:

At the moment the code to do this isn't always easy to write. It often involves:

This means a poor developer experience for many contributors, code with high bug-potential, and also the potential for bad practices like introducing incorrect dependencies.

What is your proposed solution?

TLDR - lets do something about it, what are some options? Below I present one.

Long version: I think it's worth discussing the qualities such an API should have, my thoughts are:

Based on that, the best thing I can think of is a signals style API, somewhat similar to the keyboard shortcuts API.

This kind of API isn't without problems, but I still think it could be an improvement over what Gutenberg has now.

Thoughts? What are some other options?

(cc @WordPress/gutenberg-core)

draganescu commented 1 year ago

Yes! At this moment we have a hotch potch of prefferences and settings that we read from various state places. It's always confusing to decide in which store to save UI related stuff and not all the stuff is in @wordpress/interface.

While working on distraction free mode and recently on #46907 I've needed to make the UI behave differently based on one general toggle or situation and it was both times more complicated than expected. Also as #46907 shows the lack of such an API is an invitation to worse ideas :)

talldan commented 1 year ago

I'm wondering now whether commands (those used by the command center) might be the best way to do this, as they share the same set of concerns (focus management, history management, they're groupings of actions).

I guess the only change is that we would be able to call commands programatically, and not just from the command center UI, and that might have implications.