Skip to content

Add command for Style Book and improve Style Revisions command #58143

New issue

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

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

Already on ? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

richtabor
Copy link
Member

What?

Adds a command for Style Book, while also editing the Style Revisions command so they both work nicely together.

Run the "Open Style Book", "Open Style Revisions", "Close Style Book", and "Close Style Revisions" commands.

Screenshots or screencast

CleanShot 2024-01-23 at 13 29 33

@richtaborrichtabor added the [Package] Commands/packages/commandslabel Jan 23, 2024
@richtaborrichtabor self-assigned this Jan 23, 2024
@richtaborrichtabor marked this pull request as ready for review January 23, 2024 18:35
@github-actionsGitHub Actions
Copy link

-actions bot commented Jan 23, 2024

Size Change: +264 B (0%)

Total Size: 1.7 MB

FilenameSizeChange
build/edit-site/index.min.js197 kB+264 B (0%)
ℹ️ View Unchanged
FilenameSize
build/a11y/index.min.js964 B
build/annotations/index.min.js2.71 kB
build/api-fetch/index.min.js2.33 kB
build/autop/index.min.js2.11 kB
build/blob/index.min.js590 B
build/block-directory/index.min.js7.25 kB
build/block-directory/style-rtl.css1.04 kB
build/block-directory/style.css1.04 kB
build/block-editor/content-rtl.css4.42 kB
build/block-editor/content.css4.42 kB
build/block-editor/default-editor-styles-rtl.css403 B
build/block-editor/default-editor-styles.css403 B
build/block-editor/index.min.js248 kB
build/block-editor/style-rtl.css15.7 kB
build/block-editor/style.css15.7 kB
build/block-library/blocks/archives/editor-rtl.css61 B
build/block-library/blocks/archives/editor.css60 B
build/block-library/blocks/archives/style-rtl.css90 B
build/block-library/blocks/archives/style.css90 B
build/block-library/blocks/audio/editor-rtl.css150 B
build/block-library/blocks/audio/editor.css150 B
build/block-library/blocks/audio/style-rtl.css122 B
build/block-library/blocks/audio/style.css122 B
build/block-library/blocks/audio/theme-rtl.css138 B
build/block-library/blocks/audio/theme.css138 B
build/block-library/blocks/avatar/editor-rtl.css116 B
build/block-library/blocks/avatar/editor.css116 B
build/block-library/blocks/avatar/style-rtl.css104 B
build/block-library/blocks/avatar/style.css104 B
build/block-library/blocks/block/editor-rtl.css305 B
build/block-library/blocks/block/editor.css305 B
build/block-library/blocks/button/editor-rtl.css419 B
build/block-library/blocks/button/editor.css417 B
build/block-library/blocks/button/style-rtl.css632 B
build/block-library/blocks/button/style.css631 B
build/block-library/blocks/buttons/editor-rtl.css337 B
build/block-library/blocks/buttons/editor.css337 B
build/block-library/blocks/buttons/style-rtl.css332 B
build/block-library/blocks/buttons/style.css332 B
build/block-library/blocks/calendar/style-rtl.css239 B
build/block-library/blocks/calendar/style.css239 B
build/block-library/blocks/categories/editor-rtl.css113 B
build/block-library/blocks/categories/editor.css112 B
build/block-library/blocks/categories/style-rtl.css124 B
build/block-library/blocks/categories/style.css124 B
build/block-library/blocks/code/editor-rtl.css53 B
build/block-library/blocks/code/editor.css53 B
build/block-library/blocks/code/style-rtl.css121 B
build/block-library/blocks/code/style.css121 B
build/block-library/blocks/code/theme-rtl.css124 B
build/block-library/blocks/code/theme.css124 B
build/block-library/blocks/columns/editor-rtl.css108 B
build/block-library/blocks/columns/editor.css108 B
build/block-library/blocks/columns/style-rtl.css421 B
build/block-library/blocks/columns/style.css421 B
build/block-library/blocks/comment-author-avatar/editor-rtl.css125 B
build/block-library/blocks/comment-author-avatar/editor.css125 B
build/block-library/blocks/comment-content/style-rtl.css92 B
build/block-library/blocks/comment-content/style.css92 B
build/block-library/blocks/comment-template/style-rtl.css199 B
build/block-library/blocks/comment-template/style.css198 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css123 B
build/block-library/blocks/comments-pagination-numbers/editor.css121 B
build/block-library/blocks/comments-pagination/editor-rtl.css222 B
build/block-library/blocks/comments-pagination/editor.css209 B
build/block-library/blocks/comments-pagination/style-rtl.css235 B
build/block-library/blocks/comments-pagination/style.css231 B
build/block-library/blocks/comments-title/editor-rtl.css75 B
build/block-library/blocks/comments-title/editor.css75 B
build/block-library/blocks/comments/editor-rtl.css840 B
build/block-library/blocks/comments/editor.css839 B
build/block-library/blocks/comments/style-rtl.css637 B
build/block-library/blocks/comments/style.css636 B
build/block-library/blocks/cover/editor-rtl.css647 B
build/block-library/blocks/cover/editor.css650 B
build/block-library/blocks/cover/style-rtl.css1.7 kB
build/block-library/blocks/cover/style.css1.69 kB
build/block-library/blocks/details/editor-rtl.css65 B
build/block-library/blocks/details/editor.css65 B
build/block-library/blocks/details/style-rtl.css98 B
build/block-library/blocks/details/style.css98 B
build/block-library/blocks/embed/editor-rtl.css293 B
build/block-library/blocks/embed/editor.css293 B
build/block-library/blocks/embed/style-rtl.css410 B
build/block-library/blocks/embed/style.css410 B
build/block-library/blocks/embed/theme-rtl.css138 B
build/block-library/blocks/embed/theme.css138 B
build/block-library/blocks/file/editor-rtl.css316 B
build/block-library/blocks/file/editor.css316 B
build/block-library/blocks/file/style-rtl.css280 B
build/block-library/blocks/file/style.css281 B
build/block-library/blocks/file/view.min.js322 B
build/block-library/blocks/footnotes/style-rtl.css201 B
build/block-library/blocks/footnotes/style.css199 B
build/block-library/blocks/form-input/editor-rtl.css229 B
build/block-library/blocks/form-input/editor.css228 B
build/block-library/blocks/form-input/style-rtl.css343 B
build/block-library/blocks/form-input/style.css343 B
build/block-library/blocks/form-submission-notification/editor-rtl.css343 B
build/block-library/blocks/form-submission-notification/editor.css342 B
build/block-library/blocks/form-submit-button/style-rtl.css69 B
build/block-library/blocks/form-submit-button/style.css69 B
build/block-library/blocks/form/view.min.js452 B
build/block-library/blocks/freeform/editor-rtl.css2.61 kB
build/block-library/blocks/freeform/editor.css2.61 kB
build/block-library/blocks/gallery/editor-rtl.css957 B
build/block-library/blocks/gallery/editor.css962 B
build/block-library/blocks/gallery/style-rtl.css1.75 kB
build/block-library/blocks/gallery/style.css1.75 kB
build/block-library/blocks/gallery/theme-rtl.css122 B
build/block-library/blocks/gallery/theme.css122 B
build/block-library/blocks/group/editor-rtl.css654 B
build/block-library/blocks/group/editor.css654 B
build/block-library/blocks/group/style-rtl.css57 B
build/block-library/blocks/group/style.css57 B
build/block-library/blocks/group/theme-rtl.css78 B
build/block-library/blocks/group/theme.css78 B
build/block-library/blocks/heading/style-rtl.css189 B
build/block-library/blocks/heading/style.css189 B
build/block-library/blocks/html/editor-rtl.css340 B
build/block-library/blocks/html/editor.css341 B
build/block-library/blocks/image/editor-rtl.css834 B
build/block-library/blocks/image/editor.css833 B
build/block-library/blocks/image/style-rtl.css1.61 kB
build/block-library/blocks/image/style.css1.6 kB
build/block-library/blocks/image/theme-rtl.css137 B
build/block-library/blocks/image/theme.css137 B
build/block-library/blocks/image/view.min.js2.02 kB
build/block-library/blocks/latest-comments/style-rtl.css357 B
build/block-library/blocks/latest-comments/style.css357 B
build/block-library/blocks/latest-posts/editor-rtl.css213 B
build/block-library/blocks/latest-posts/editor.css212 B
build/block-library/blocks/latest-posts/style-rtl.css478 B
build/block-library/blocks/latest-posts/style.css478 B
build/block-library/blocks/list/style-rtl.css88 B
build/block-library/blocks/list/style.css88 B
build/block-library/blocks/media-text/editor-rtl.css266 B
build/block-library/blocks/media-text/editor.css263 B
build/block-library/blocks/media-text/style-rtl.css505 B
build/block-library/blocks/media-text/style.css503 B
build/block-library/blocks/more/editor-rtl.css431 B
build/block-library/blocks/more/editor.css431 B
build/block-library/blocks/navigation-link/editor-rtl.css671 B
build/block-library/blocks/navigation-link/editor.css672 B
build/block-library/blocks/navigation-link/style-rtl.css103 B
build/block-library/blocks/navigation-link/style.css103 B
build/block-library/blocks/navigation-submenu/editor-rtl.css299 B
build/block-library/blocks/navigation-submenu/editor.css299 B
build/block-library/blocks/navigation/editor-rtl.css2.26 kB
build/block-library/blocks/navigation/editor.css2.26 kB
build/block-library/blocks/navigation/style-rtl.css2.25 kB
build/block-library/blocks/navigation/style.css2.23 kB
build/block-library/blocks/navigation/view.min.js1.1 kB
build/block-library/blocks/nextpage/editor-rtl.css395 B
build/block-library/blocks/nextpage/editor.css395 B
build/block-library/blocks/page-list/editor-rtl.css377 B
build/block-library/blocks/page-list/editor.css377 B
build/block-library/blocks/page-list/style-rtl.css175 B
build/block-library/blocks/page-list/style.css175 B
build/block-library/blocks/paragraph/editor-rtl.css235 B
build/block-library/blocks/paragraph/editor.css235 B
build/block-library/blocks/paragraph/style-rtl.css335 B
build/block-library/blocks/paragraph/style.css335 B
build/block-library/blocks/post-author/style-rtl.css175 B
build/block-library/blocks/post-author/style.css176 B
build/block-library/blocks/post-comments-form/editor-rtl.css96 B
build/block-library/blocks/post-comments-form/editor.css96 B
build/block-library/blocks/post-comments-form/style-rtl.css508 B
build/block-library/blocks/post-comments-form/style.css508 B
build/block-library/blocks/post-date/style-rtl.css61 B
build/block-library/blocks/post-date/style.css61 B
build/block-library/blocks/post-excerpt/editor-rtl.css71 B
build/block-library/blocks/post-excerpt/editor.css71 B
build/block-library/blocks/post-excerpt/style-rtl.css141 B
build/block-library/blocks/post-excerpt/style.css141 B
build/block-library/blocks/post-featured-image/editor-rtl.css666 B
build/block-library/blocks/post-featured-image/editor.css662 B
build/block-library/blocks/post-featured-image/style-rtl.css345 B
build/block-library/blocks/post-featured-image/style.css345 B
build/block-library/blocks/post-navigation-link/style-rtl.css215 B
build/block-library/blocks/post-navigation-link/style.css214 B
build/block-library/blocks/post-template/editor-rtl.css99 B
build/block-library/blocks/post-template/editor.css98 B
build/block-library/blocks/post-template/style-rtl.css409 B
build/block-library/blocks/post-template/style.css408 B
build/block-library/blocks/post-terms/style-rtl.css96 B
build/block-library/blocks/post-terms/style.css96 B
build/block-library/blocks/post-time-to-read/style-rtl.css69 B
build/block-library/blocks/post-time-to-read/style.css69 B
build/block-library/blocks/post-title/style-rtl.css100 B
build/block-library/blocks/post-title/style.css100 B
build/block-library/blocks/preformatted/style-rtl.css125 B
build/block-library/blocks/preformatted/style.css125 B
build/block-library/blocks/pullquote/editor-rtl.css135 B
build/block-library/blocks/pullquote/editor.css135 B
build/block-library/blocks/pullquote/style-rtl.css354 B
build/block-library/blocks/pullquote/style.css354 B
build/block-library/blocks/pullquote/theme-rtl.css168 B
build/block-library/blocks/pullquote/theme.css168 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css122 B
build/block-library/blocks/query-pagination-numbers/editor.css121 B
build/block-library/blocks/query-pagination/editor-rtl.css221 B
build/block-library/blocks/query-pagination/editor.css211 B
build/block-library/blocks/query-pagination/style-rtl.css288 B
build/block-library/blocks/query-pagination/style.css284 B
build/block-library/blocks/query-title/style-rtl.css63 B
build/block-library/blocks/query-title/style.css63 B
build/block-library/blocks/query/editor-rtl.css486 B
build/block-library/blocks/query/editor.css486 B
build/block-library/blocks/query/style-rtl.css312 B
build/block-library/blocks/query/style.css308 B
build/block-library/blocks/query/view.min.js647 B
build/block-library/blocks/quote/style-rtl.css237 B
build/block-library/blocks/quote/style.css237 B
build/block-library/blocks/quote/theme-rtl.css223 B
build/block-library/blocks/quote/theme.css226 B
build/block-library/blocks/read-more/style-rtl.css140 B
build/block-library/blocks/read-more/style.css140 B
build/block-library/blocks/rss/editor-rtl.css149 B
build/block-library/blocks/rss/editor.css149 B
build/block-library/blocks/rss/style-rtl.css289 B
build/block-library/blocks/rss/style.css288 B
build/block-library/blocks/search/editor-rtl.css184 B
build/block-library/blocks/search/editor.css184 B
build/block-library/blocks/search/style-rtl.css602 B
build/block-library/blocks/search/style.css602 B
build/block-library/blocks/search/theme-rtl.css114 B
build/block-library/blocks/search/theme.css114 B
build/block-library/blocks/search/view.min.js475 B
build/block-library/blocks/separator/editor-rtl.css146 B
build/block-library/blocks/separator/editor.css146 B
build/block-library/blocks/separator/style-rtl.css234 B
build/block-library/blocks/separator/style.css234 B
build/block-library/blocks/separator/theme-rtl.css194 B
build/block-library/blocks/separator/theme.css194 B
build/block-library/blocks/shortcode/editor-rtl.css329 B
build/block-library/blocks/shortcode/editor.css329 B
build/block-library/blocks/site-logo/editor-rtl.css760 B
build/block-library/blocks/site-logo/editor.css760 B
build/block-library/blocks/site-logo/style-rtl.css204 B
build/block-library/blocks/site-logo/style.css204 B
build/block-library/blocks/site-tagline/editor-rtl.css86 B
build/block-library/blocks/site-tagline/editor.css86 B
build/block-library/blocks/site-title/editor-rtl.css116 B
build/block-library/blocks/site-title/editor.css116 B
build/block-library/blocks/site-title/style-rtl.css57 B
build/block-library/blocks/site-title/style.css57 B
build/block-library/blocks/social-link/editor-rtl.css184 B
build/block-library/blocks/social-link/editor.css184 B
build/block-library/blocks/social-links/editor-rtl.css682 B
build/block-library/blocks/social-links/editor.css681 B
build/block-library/blocks/social-links/style-rtl.css1.49 kB
build/block-library/blocks/social-links/style.css1.49 kB
build/block-library/blocks/spacer/editor-rtl.css359 B
build/block-library/blocks/spacer/editor.css359 B
build/block-library/blocks/spacer/style-rtl.css48 B
build/block-library/blocks/spacer/style.css48 B
build/block-library/blocks/table/editor-rtl.css395 B
build/block-library/blocks/table/editor.css395 B
build/block-library/blocks/table/style-rtl.css646 B
build/block-library/blocks/table/style.css645 B
build/block-library/blocks/table/theme-rtl.css157 B
build/block-library/blocks/table/theme.css157 B
build/block-library/blocks/tag-cloud/style-rtl.css251 B
build/block-library/blocks/tag-cloud/style.css253 B
build/block-library/blocks/template-part/editor-rtl.css403 B
build/block-library/blocks/template-part/editor.css403 B
build/block-library/blocks/template-part/theme-rtl.css101 B
build/block-library/blocks/template-part/theme.css101 B
build/block-library/blocks/term-description/style-rtl.css111 B
build/block-library/blocks/term-description/style.css111 B
build/block-library/blocks/text-columns/editor-rtl.css95 B
build/block-library/blocks/text-columns/editor.css95 B
build/block-library/blocks/text-columns/style-rtl.css166 B
build/block-library/blocks/text-columns/style.css166 B
build/block-library/blocks/verse/style-rtl.css99 B
build/block-library/blocks/verse/style.css99 B
build/block-library/blocks/video/editor-rtl.css552 B
build/block-library/blocks/video/editor.css555 B
build/block-library/blocks/video/style-rtl.css191 B
build/block-library/blocks/video/style.css191 B
build/block-library/blocks/video/theme-rtl.css139 B
build/block-library/blocks/video/theme.css139 B
build/block-library/classic-rtl.css179 B
build/block-library/classic.css179 B
build/block-library/common-rtl.css1.11 kB
build/block-library/common.css1.11 kB
build/block-library/editor-elements-rtl.css75 B
build/block-library/editor-elements.css75 B
build/block-library/editor-rtl.css12.3 kB
build/block-library/editor.css12.3 kB
build/block-library/elements-rtl.css54 B
build/block-library/elements.css54 B
build/block-library/index.min.js215 kB
build/block-library/reset-rtl.css472 B
build/block-library/reset.css472 B
build/block-library/style-rtl.css14.7 kB
build/block-library/style.css14.7 kB
build/block-library/theme-rtl.css700 B
build/block-library/theme.css705 B
build/block-serialization-default-parser/index.min.js1.13 kB
build/block-serialization-spec-parser/index.min.js2.87 kB
build/blocks/index.min.js51.6 kB
build/commands/index.min.js15.5 kB
build/commands/style-rtl.css947 B
build/commands/style.css942 B
build/components/index.min.js235 kB
build/components/style-rtl.css12.1 kB
build/components/style.css12.1 kB
build/compose/index.min.js12.6 kB
build/core-commands/index.min.js2.73 kB
build/core-data/index.min.js72.7 kB
build/customize-widgets/index.min.js12.1 kB
build/customize-widgets/style-rtl.css1.36 kB
build/customize-widgets/style.css1.36 kB
build/data-controls/index.min.js651 B
build/data/index.min.js8.96 kB
build/date/index.min.js17.9 kB
build/deprecated/index.min.js462 B
build/dom-ready/index.min.js336 B
build/dom/index.min.js4.69 kB
build/edit-post/classic-rtl.css571 B
build/edit-post/classic.css571 B
build/edit-post/index.min.js24.9 kB
build/edit-post/style-rtl.css5.68 kB
build/edit-post/style.css5.68 kB
build/edit-site/style-rtl.css15.3 kB
build/edit-site/style.css15.3 kB
build/edit-widgets/index.min.js17.4 kB
build/edit-widgets/style-rtl.css4.44 kB
build/edit-widgets/style.css4.43 kB
build/editor/index.min.js61.7 kB
build/editor/style-rtl.css5.48 kB
build/editor/style.css5.48 kB
build/element/index.min.js4.88 kB
build/escape-html/index.min.js548 B
build/format-library/index.min.js7.98 kB
build/format-library/style-rtl.css500 B
build/format-library/style.css500 B
build/hooks/index.min.js1.57 kB
build/html-entities/index.min.js454 B
build/i18n/index.min.js3.61 kB
build/interactivity/file.min.js442 B
build/interactivity/image.min.js2.15 kB
build/interactivity/index.min.js13.3 kB
build/interactivity/navigation.min.js1.23 kB
build/interactivity/query.min.js791 B
build/interactivity/search.min.js610 B
build/is-shallow-equal/index.min.js535 B
build/keyboard-shortcuts/index.min.js1.76 kB
build/keycodes/index.min.js1.49 kB
build/list-reusable-blocks/index.min.js2.11 kB
build/list-reusable-blocks/style-rtl.css865 B
build/list-reusable-blocks/style.css865 B
build/media-utils/index.min.js2.92 kB
build/modules/importmap-polyfill.min.js12.2 kB
build/notices/index.min.js964 B
build/nux/index.min.js2.01 kB
build/nux/style-rtl.css775 B
build/nux/style.css771 B
build/patterns/index.min.js5.43 kB
build/patterns/style-rtl.css564 B
build/patterns/style.css564 B
build/plugins/index.min.js1.81 kB
build/preferences-persistence/index.min.js2.08 kB
build/preferences/index.min.js2.82 kB
build/preferences/style-rtl.css725 B
build/preferences/style.css728 B
build/primitives/index.min.js994 B
build/priority-queue/index.min.js1.52 kB
build/private-apis/index.min.js1.02 kB
build/react-i18n/index.min.js631 B
build/react-refresh-entry/index.min.js9.46 kB
build/react-refresh-runtime/index.min.js6.78 kB
build/redux-routine/index.min.js2.71 kB
build/reusable-blocks/index.min.js2.74 kB
build/reusable-blocks/style-rtl.css265 B
build/reusable-blocks/style.css265 B
build/rich-text/index.min.js10.4 kB
build/router/index.min.js1.79 kB
build/server-side-render/index.min.js1.96 kB
build/shortcode/index.min.js1.4 kB
build/style-engine/index.min.js2.06 kB
build/token-list/index.min.js587 B
build/url/index.min.js3.83 kB
build/vendors/inert-polyfill.min.js2.48 kB
build/vendors/react-dom.min.js41.8 kB
build/vendors/react.min.js4.02 kB
build/viewport/index.min.js967 B
build/warning/index.min.js259 B
build/widgets/index.min.js7.22 kB
build/widgets/style-rtl.css1.18 kB
build/widgets/style.css1.18 kB
build/wordcount/index.min.js1.03 kB

compressed-size-action

@richtaborrichtabor added the [Type] EnhancementA suggestion for improvement.label Jan 23, 2024
Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I think these suggestions make sense to me too.

"Close Style Book", and "Close Style Revisions"

Both of these close commands seem to simply close the Global Style itself. However, I think Style Book and revisions are not exclusive, so I feel that the Global Styles should remain open.

Perhaps the implementation of this part will be helpful. What do you think?

The screencast below shows the Revision and Style Book buttons working independently.

2dc2abd8e9d1e862dc00bec69974e32f.mp4

Another thing to solve is to disable these commands from being executed in the classic theme. Currently, the classic theme that supports template parts gives us access to some parts of the Site Editor, but classic themes do not support Style Book.

This issue can be reproduced by following these steps:

  • Access http://localhost:8889/wp-admin/ instead of http://localhost:8888/wp-admin/
  • Activate the Emptyhybryd theme
  • Access Appearance > Template parts
  • Run "Open Style Book" from the command palette

You should be able to reuse the implementation here to deal with this problem.

const isBlockBasedTheme = useSelect( ( select ) => {
return select( coreStore ).getCurrentTheme().is_block_theme;
}, [] );
const commands = useMemo( () => {
if ( ! isBlockBasedTheme ) {
return [];
}

@@ -288,6 +310,91 @@ function useGlobalStylesOpenRevisionsCommands() {
isEditorPage,
getCanvasMode,
setCanvasMode,
closeGeneralSidebar,
Copy link
Contributor

Choose a reason for hiding this comment

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

You will also need to adjust the dependencies for the useMemo hook. Your code editor should tell you what dependencies you need and don't need.

Comment on lines +247 to +249
const { getCanvasMode, getEditorCanvasContainerView } = unlock(
useSelect( editSiteStore )
);
Copy link
Contributor

@t-hamano t-hamano Jan 24, 2024

Choose a reason for hiding this comment

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

My understanding is that instead of unlocking useSelect itself, you will need to do it inside the useSelect hook. You will probably need to modify the existing useSelect hook to look like this:

	const { canvasMode, hasRevisions, isStyleRevisionsOpened } = useSelect(
		( select ) => {
			const { getEntityRecord, __experimentalGetCurrentGlobalStylesId } =
				select( coreStore );
			const { getCanvasMode, getEditorCanvasContainerView } = unlock(
				select( editSiteStore )
			);
			const globalStylesId = __experimentalGetCurrentGlobalStylesId();
			const globalStyles = globalStylesId
				? getEntityRecord( 'root', 'globalStyles', globalStylesId )
				: undefined;
			return {
				canvasMode: getCanvasMode(),
				hasRevisions:
					!! globalStyles?._links?.[ 'version-history' ]?.[ 0 ]
						?.count,
				isStyleRevisionsOpened:
					'global-styles-revisions' ===
					getEditorCanvasContainerView(),
			};
		},
		[]
	);

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with the getEditorCanvasContainerView move inside the useSelect, as it's being used there.

getCanvasMode though is used in a callback function, so it's fine to have outside and call it when needed to get the latest value.

Copy link
Member Author

Choose a reason for hiding this comment

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

If you have a few moments, feel free to take over the PR to get this in.

Comment on lines +329 to +331
const { getCanvasMode, getEditorCanvasContainerView } = unlock(
useSelect( editSiteStore )
);
Copy link
Contributor

@t-hamano t-hamano Jan 24, 2024

Choose a reason for hiding this comment

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

Similar to this comment

@t-hamanot-hamano requested a review from ramonjd January 24, 2024 04:40
@t-hamano
Copy link
Contributor

@ramonjd I added you as a reviewer. Because I assume you have deep experience with Style Book and revision specifications 🙏

Copy link
Member

@ramonjd ramonjd left a comment

Choose a reason for hiding this comment

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

A style book command is a great addition in my opinion. Thank you!

I'm a bit skeptical of the need to allow for open/close toggling. I'm running on the idea that folks will activate or open things as they need, using commands in a forward manner.

The style book and revisions components immediately place focus on the close button anyway.

Do we have open/close toggling elsewhere?

useSelect( () => {
return {
isStyleBookOpened: 'style-book' === canvasContainerView,
isRevisionsStyleBookOpened:
Copy link
Member

@ramonjd ramonjd Jan 29, 2024

Choose a reason for hiding this comment

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

I'm thinking it might make the open/close logic more straight forward for users to have the choice to toggle revisions regardless of whether the style book view is open.

So something like:

isStyleBookOpened: 'style-book' === canvasContainerView,
isRevisionsOpened: canvasContainerView.startsWith( 'global-styles-revisions' ),

So "Open/Close Revisions" ignores which type of preview we're showing - the commands will either open or close revisions.

"Open/Close style book" would target the style book specifically.

I mention it because the command "Close style book" is present in the context of revisions:

Screenshot 2024-01-29 at 11 13 58 am

I suppose it's okay to have a command that closes the style book revisions "view" too - I just have a niggling feeling the third state is unnecessary for the user.

}
setEditorCanvasContainerView(
isStyleBookOpened ? undefined : 'style-book'
);
Copy link
Member

Choose a reason for hiding this comment

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

To allow opening from the site editor "view" sidebar, I think we'd also need to account for the canvas view mode and set it to "edit" if it isn't.

Similar to how the styles revisions callback works:

					if ( isEditorPage && getCanvasMode() !== 'edit' ) {
						setCanvasMode( 'edit' );
					}
Screenshot 2024-01-29 at 11 25 50 am

@richtabor
Copy link
Member Author

I'm a bit skeptical of the need to allow for open/close toggling. I'm running on the idea that folks will activate or open things as they need, using commands in a forward manner.

If we allow you to command it to open, we should have one to close it as well. It's essentially the same command, but the inverse.

Do we have open/close toggling elsewhere?

Yes, implemented for most of the UI-changing commands. Some are "Toggle..." while others are more specific, like "Enter Distraction Free" and "Exit Distraction Free".

@t-hamano
Copy link
Contributor

I also think that bidirectional actions should be supported, but I think the question is whether to use "Toggle" or "Open/Close" or some other terminology.

Below is a list of commands that support bidirectional actions in the Site Editor.

  • Toggle settings sidebar
  • Toggle block inspector
  • Toggle top toolbar
  • Toggle spotlight
  • Toggle top toolbar
  • Enter Distraction Free / Exit Distraction Free
  • Enter fullscreen / Exit fullscreen
  • Open List View / Close List View
  • Open code editor / Exit code editor
  • Show block breadcrumbs / Hide block breadcrumbs
  • Enable pre-publish checks / Disable pre-publish checks

In my opinion, "Open/Close" is suitable for both Style Book and Revisions.

Also, I think this problem is probably related to usability, so I will send a ping to @afercia.

@afercia
Copy link
Contributor

Thanks for the ping. The verb 'Toggle' shoud be avoided. See:

#42492
https://core.trac.wordpress.org/ticket/34753 (8 years ago)

It's hardly translatable in other languages. Typically, translators resort to using a verb pair e.g.:
Ouvrir/fermer
Attiva/disattiva
or even more complex strings and that leads to labels that are sometimes very long. See screenshots on the discussion. I'm not sure that helps providing a good user experience.

I'd tend to think the command label should be contextual. While I personally don't like contextual labels for buttons or other UI controls, I'd think the command palette should only show commands that make sense in the current, specific, state of the UI.

While the underlying action is 'toggle' a panel/sidebar/whatever, ideally the label of the command should be contextual. For example:

  • When an XYZ panel is open, the label of the command should be 'Close XYZ panel'.
  • Viceversa: 'Open XYZ panel'.

Re: Toggle settings sidebar I would like to remind that we have previously removed the term 'sidebar' from most of the strings in favor of 'panel'.

@priethorpriethor mentioned this pull request Oct 31, 2024
@richtabor
Copy link
Member Author

Closing as inactive.

@johnbillionjohnbillion deleted the tweak/commands-style-book-revisions branch February 10, 2025 16:49
Sign up for free to join this conversation on . Already have an account? Sign in to comment
Labels
[Package] Commands/packages/commands[Type] EnhancementA suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants