Skip to content
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

Try adding a 'spotlight mode' type effect when template part or child is selected. #25656

Merged
merged 24 commits into from
Oct 9, 2020

Conversation

Addison-Stavlo
Copy link
Contributor

@Addison-Stavlo Addison-Stavlo commented Sep 25, 2020

Description

Re-exploring the idea of adding a 'spotlight mode' effect on template parts.
Here, we add a new class to pass down from the block-list if a template part or any of its children are selected. And some style rules similar to the current focus-mode.

This works as a default behavior for template part/child selection and the styles are overridden if 'spotlight mode' is enabled.

How has this been tested?

Screenshots

spotlight-mode-template-part-2

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@Addison-Stavlo Addison-Stavlo self-assigned this Sep 25, 2020
@Addison-Stavlo
Copy link
Contributor Author

Addison-Stavlo commented Sep 25, 2020

Any thoughts on how this feels @shaunandrews @jameskoster @dubielzyk @olaolusoga? It will be overridden if 'spotlight mode' becomes enabled, but I don't think thats necessarily a bad thing.

@Addison-Stavlo Addison-Stavlo changed the title Try adding a "spotlight mode" when template part or child is selected. Try adding a 'spotlight mode' type effect when template part or child is selected. Sep 25, 2020
@github-actions
Copy link

github-actions bot commented Sep 25, 2020

Size Change: +201 B (0%)

Total Size: 1.19 MB

Filename Size Change
build/annotations/index.js 3.52 kB -23 B (0%)
build/block-editor/index.js 130 kB +210 B (0%)
build/block-editor/style-rtl.css 11 kB +47 B (0%)
build/block-editor/style.css 11 kB +46 B (0%)
build/blocks/index.js 47.6 kB -4 B (0%)
build/core-data/index.js 12 kB -11 B (0%)
build/edit-site/index.js 20.9 kB -63 B (0%)
build/keyboard-shortcuts/index.js 2.39 kB +2 B (0%)
build/media-utils/index.js 5.13 kB +4 B (0%)
build/nux/index.js 3.27 kB -7 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/api-fetch/index.js 3.35 kB 0 B
build/autop/index.js 2.72 kB 0 B
build/blob/index.js 668 B 0 B
build/block-directory/index.js 8.55 kB 0 B
build/block-directory/style-rtl.css 943 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-library/editor-rtl.css 8.65 kB 0 B
build/block-library/editor.css 8.65 kB 0 B
build/block-library/index.js 145 kB 0 B
build/block-library/style-rtl.css 7.66 kB 0 B
build/block-library/style.css 7.65 kB 0 B
build/block-library/theme-rtl.css 741 B 0 B
build/block-library/theme.css 741 B 0 B
build/block-serialization-default-parser/index.js 1.78 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/components/index.js 169 kB 0 B
build/components/style-rtl.css 15.5 kB 0 B
build/components/style.css 15.5 kB 0 B
build/compose/index.js 9.43 kB 0 B
build/data-controls/index.js 685 B 0 B
build/data/index.js 8.6 kB 0 B
build/date/index.js 31.9 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 4.42 kB 0 B
build/edit-navigation/index.js 10.6 kB 0 B
build/edit-navigation/style-rtl.css 868 B 0 B
build/edit-navigation/style.css 871 B 0 B
build/edit-post/index.js 306 kB 0 B
build/edit-post/style-rtl.css 6.29 kB 0 B
build/edit-post/style.css 6.28 kB 0 B
build/edit-site/style-rtl.css 3.73 kB 0 B
build/edit-site/style.css 3.73 kB 0 B
build/edit-widgets/index.js 21.2 kB 0 B
build/edit-widgets/style-rtl.css 3.02 kB 0 B
build/edit-widgets/style.css 3.02 kB 0 B
build/editor/editor-styles-rtl.css 492 B 0 B
build/editor/editor-styles.css 493 B 0 B
build/editor/index.js 45.5 kB 0 B
build/editor/style-rtl.css 3.85 kB 0 B
build/editor/style.css 3.84 kB 0 B
build/element/index.js 4.45 kB 0 B
build/escape-html/index.js 734 B 0 B
build/format-library/index.js 7.49 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 1.74 kB 0 B
build/html-entities/index.js 621 B 0 B
build/i18n/index.js 3.54 kB 0 B
build/is-shallow-equal/index.js 710 B 0 B
build/keycodes/index.js 1.85 kB 0 B
build/list-reusable-blocks/index.js 3.02 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/notices/index.js 1.69 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.44 kB 0 B
build/primitives/index.js 1.34 kB 0 B
build/priority-queue/index.js 790 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/rich-text/index.js 13 kB 0 B
build/server-side-render/index.js 2.6 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.24 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.74 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@dubielzyk
Copy link

I quite like it. We're not communicating why we're entering spotlight mode to the user, but perhaps that's fine. Would this also trigger if you have nested template parts?

@jameskoster
Copy link
Contributor

I think spotlight is the way to go, but the finer details of what happens when inner blocks are selected, or when multiple instances of a single template part exist on the canvas, needs some refinement.

In #25452 I worked on a couple of crude prototypes that we can perhaps discuss here.

In this latest iteration:

  • The selected template part is outlined and spotlighted. The outline helps when spotlight mode is enabled.
  • Any other instances of that template part are outlined but excluded from the spotlight.
  • When an inner block is selected the entire parent template part remains spotlighted and equivalent inner blocks in other instances of the same template part are also spotlighted and outlined.

@Addison-Stavlo
Copy link
Contributor Author

Would this also trigger if you have nested template parts?

@dubielzyk - Good question, it is a little odd right now the nested template parts are spotlighted together regardless of whether the parent or child is selected. I will try to make this better so that only the child is spotlit when it is the one selected.

when multiple instances of a single template part exist on the canvas, needs some refinement.

@jameskoster - I think it is fair to follow up and reiterate regarding how to handle duplicates of the same template part that aren't selected. Currently, it isn't possible to have 2 of the same template part on one page and that bug is in the process of being worked out technically. But should that prevent us from adding the ability to spotlight for the selected template part in the meantime? If we agree that the opacity changes are the direction forward, then a small scoped change like this would be a good first step.

  • The selected template part is outlined and spotlighted. The outline helps when spotlight mode is enabled.
  • Any other instances of that template part are outlined but excluded from the spotlight.
  • When an inner block is selected the entire parent template part remains spotlighted and equivalent inner blocks in other instances of the same template part are also spotlighted and outlined.

The first outline already exists as a subtle gray border and I agree it does work well with the template part spotlight mode. The second would be a simple change in the blocks editor files, and the third would require some changes in the block-list/wrappers but should be doable as well if we determine that is the way to go. Both of these I could see as potential follow ups after we are able to successfully render 2 of the same template parts on one page.

@jameskoster
Copy link
Contributor

Both of these I could see as potential follow ups after we are able to successfully render 2 of the same template parts on one page.

Seems fair to me :)

@shaunandrews
Copy link
Contributor

This feels nice. If we can make the logic work for nested template parts, I'd love to see this merged.

@Addison-Stavlo
Copy link
Contributor Author

This feels nice. If we can make the logic work for nested template parts, I'd love to see this merged.

Nice! 848b797 + dcc2d5f should have this working for the nested cases now. 😁

@Addison-Stavlo Addison-Stavlo marked this pull request as ready for review September 28, 2020 20:46
@noahtallen
Copy link
Member

Nice, the nested case works well. I also appreciate how "spotlight mode" takes precedent over this, so it still works the same as before with template part blocks.

Copy link
Member

@noahtallen noahtallen left a comment

Choose a reason for hiding this comment

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

Nice! I like how this works.

before merging, i'd love to see if we could disable it for non-FSE sites (so we can test it out without affecting plugin consumers).

Besides that, from a code point of view, I dislike how we are tightly coupling one block type with the general block list. I wonder if there's a better way to handle it -- perhaps adding is-active-template-part to the template part block's edit method (or just adding the right CSS properties to the template part's edit div)

I can see how template-part-highlighting needs to be more general though. I'm not thinking of any alternatives to that approach off the top of my head though.

packages/block-editor/src/components/block-list/index.js Outdated Show resolved Hide resolved
packages/block-editor/src/components/block-list/index.js Outdated Show resolved Hide resolved
packages/block-editor/src/components/block-list/style.scss Outdated Show resolved Hide resolved
@Addison-Stavlo
Copy link
Contributor Author

I dislike how we are tightly coupling one block type with the general block list. I wonder if there's a better way to handle it

I understand that concern. However, we do need to access this area to handle adding the template-part-highlighting class to blocks in the editor. So using this as the place to add is-active-template-part consolidates the code for this functionality to one area. Similar to how 'spotlight mode' adds is-focus-mode and is-focused here, we are adding the equivalent versions of that for template parts.

While it is 'just one block type', it could be extended to more block type if desired in the future (post content, etc.). So maybe rebranding these to more generic terms than 'template parts' would make sense? 🤷‍♀️

-- perhaps adding is-active-template-part to the template part block's edit method

We could do that, although it would separate the code used to achieve this functionality into 2 separate packages which to me seems much less ideal.

(or just adding the right CSS properties to the template part's edit div)

Im not sure I follow what these right CSS properties would be? Opacity is a bit of a complex case in that it bleeds down, so just setting opacity: 1 on the template part won't do much if it has a parent already set down to 0.5. The styles to achieve this opacity reduction without multiplying the effect on nested blocks is very well bundled together at the moment. If we move all the styles to template part edit, it doesn't make much sense for the .template-part-highlighting to be defined in one package and have its styles defined in another. If we decouple the styles and move them across 2 different packages, that makes this much more difficult to manage in the future.

In the end, using the block-list / wrappers seems necessary for implementing an editor wide content opacity control and while we may be referencing 'one specific block type' in the general list component that seems much more manageable than splitting up the functionality and style rules between multiple packages.

@noahtallen
Copy link
Member

noahtallen commented Sep 28, 2020

Thanks for the detailed explanation!

So maybe rebranding these to more generic terms than 'template parts' would make sense

I would be in favor of this then

@Addison-Stavlo Addison-Stavlo removed the Needs Design Feedback Needs general design feedback. label Sep 29, 2020
@Addison-Stavlo
Copy link
Contributor Author

So maybe rebranding these to more generic terms than 'template parts' would make sense

I would be in favor of this then

Any ideas on names? 😆 is-active-entity/entity-highlighting ? or instead of 'entity' other ideas like content, context, region... 🤔

@Addison-Stavlo Addison-Stavlo force-pushed the try/spotlight-mode-for-template-parts branch from ca13ce1 to 1646269 Compare October 2, 2020 22:42
Copy link
Member

@vindl vindl left a comment

Choose a reason for hiding this comment

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

I really like the latest round of updates to this, the code looks much more polished now! ✨ Gave it another spin and everything still works as expected on my end. I also made sure that these changes are not affecting the post editor.

I added a few optional naming suggestions.

* @param {boolean} ascending Order results from bottom to top (true) or top to bottom (false).
* @param {Object} state Editor state.
* @param {string} clientId Block from which to find root client ID.
* @param {string|string[]} blockName Block name(s) to filter.
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: should we update this to blockNames then? Reading blockName.includes threw me off at first.

Copy link
Contributor Author

@Addison-Stavlo Addison-Stavlo Oct 7, 2020

Choose a reason for hiding this comment

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

🤔 Im not sure tbh. The original use is a string of a single blockName and this is still supported. Since it can either be a string or an array of strings, whether we use blockName or blockNames it will still read a bit funky somewhere. ( like name === blockNames ) 🤷‍♀️ At least the blockName.includes is nested in an if ( isArray( blockName )

packages/block-editor/src/components/block-list/style.scss Outdated Show resolved Hide resolved
} = select( 'core/block-editor' );

// Determine if there is an active entity area to spotlight.
const activeEntityBlockId = __experimentalGetActiveBlockIdByBlockNames(
getSettings().__experimentalSpotlightBlocks
Copy link
Member

@vindl vindl Oct 7, 2020

Choose a reason for hiding this comment

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

Would it make sense to make this a default parameter value if it's not passed? Then we could also shorten the name of the selector to __experimentalGetActiveEntityBlockId, which better aligns it with surrounding variable names that we are using. I guess it depends on how often we anticipate this selector will be used outside of this functionality.

Also I'd probably rename __experimentalSpotlightBlocks to __experimentalSpotlightEntityBlocks to avoid potential confusion with regular spotlight feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it make sense to make this a default parameter value if it's not passed?
I guess it depends on how often we anticipate this selector will be used outside of this functionality.

Yeah, I guess that 100% depends on how this selector might be used. For our purposes, that would make sense! However, without that change this selector is more general and could be used for other purposes. Whether it would be, I really don't know. 🤷‍♀️

Also I'd probably rename __experimentalSpotlightBlocks to __experimentalSpotlightEntityBlocks to avoid potential confusion with regular spotlight feature.

👍

Copy link
Member

@vindl vindl left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

@Addison-Stavlo Addison-Stavlo merged commit 4d544b7 into master Oct 9, 2020
@Addison-Stavlo Addison-Stavlo deleted the try/spotlight-mode-for-template-parts branch October 9, 2020 17:44
@github-actions github-actions bot added this to the Gutenberg 9.2 milestone Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants