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

Use same mappings for the style properties everywhere #24320

Closed
wants to merge 8 commits into from

Conversation

oandregal
Copy link
Member

Follow-up to this conversation #24298 (comment)

The way we declared the style properties within block.json's supports key was inconsistent with how the properties were stored in the theme.json and the block attributes, which followed the theme.json specification.

'line-height' => array( '__experimentalLineHeight' ),
$mappings = array_merge(
gutenberg_experimental_global_styles_get_mappings(),
// TODO: remove from here and access directly from lib/blocks.php
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that the block-align property was added 0d08cda I think we can fix this in a subsequent PR: it should be removed from here and lib/blocks.php refactored to use the block registry instead of global-styles.php

@github-actions
Copy link

github-actions bot commented Aug 2, 2020

Size Change: +50 B (0%)

Total Size: 1.16 MB

Filename Size Change
build/block-editor/index.js 125 kB +6 B (0%)
build/block-library/index.js 133 kB +44 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.67 kB 0 B
build/api-fetch/index.js 3.44 kB 0 B
build/autop/index.js 2.82 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 7.93 kB 0 B
build/block-directory/style-rtl.css 953 B 0 B
build/block-directory/style.css 952 B 0 B
build/block-editor/style-rtl.css 10.8 kB 0 B
build/block-editor/style.css 10.8 kB 0 B
build/block-library/editor-rtl.css 7.59 kB 0 B
build/block-library/editor.css 7.59 kB 0 B
build/block-library/style-rtl.css 7.76 kB 0 B
build/block-library/style.css 7.77 kB 0 B
build/block-library/theme-rtl.css 728 B 0 B
build/block-library/theme.css 729 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 48.3 kB 0 B
build/components/index.js 200 kB 0 B
build/components/style-rtl.css 15.7 kB 0 B
build/components/style.css 15.7 kB 0 B
build/compose/index.js 9.68 kB 0 B
build/core-data/index.js 11.8 kB 0 B
build/data-controls/index.js 1.29 kB 0 B
build/data/index.js 8.45 kB 0 B
build/date/index.js 5.38 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 3.23 kB 0 B
build/edit-navigation/index.js 10.9 kB 0 B
build/edit-navigation/style-rtl.css 1.08 kB 0 B
build/edit-navigation/style.css 1.08 kB 0 B
build/edit-post/index.js 304 kB 0 B
build/edit-post/style-rtl.css 5.61 kB 0 B
build/edit-post/style.css 5.61 kB 0 B
build/edit-site/index.js 17 kB 0 B
build/edit-site/style-rtl.css 3.06 kB 0 B
build/edit-site/style.css 3.06 kB 0 B
build/edit-widgets/index.js 9.38 kB 0 B
build/edit-widgets/style-rtl.css 2.45 kB 0 B
build/edit-widgets/style.css 2.45 kB 0 B
build/editor/editor-styles-rtl.css 537 B 0 B
build/editor/editor-styles.css 539 B 0 B
build/editor/index.js 45.3 kB 0 B
build/editor/style-rtl.css 3.8 kB 0 B
build/editor/style.css 3.79 kB 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 7.72 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 2.13 kB 0 B
build/html-entities/index.js 621 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/is-shallow-equal/index.js 711 B 0 B
build/keyboard-shortcuts/index.js 2.52 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.11 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/media-utils/index.js 5.33 kB 0 B
build/notices/index.js 1.79 kB 0 B
build/nux/index.js 3.4 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.56 kB 0 B
build/primitives/index.js 1.41 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/rich-text/index.js 13.9 kB 0 B
build/server-side-render/index.js 2.71 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.85 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

"linkColor": true
"__experimentalStyles": {
"color": {
"background": true,
Copy link
Member Author

Choose a reason for hiding this comment

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

In the client, the background and text keys are not used, only support for __experimentalStyles.color is checked. Although we could remove them from here and make the server verification do the same, this will make the support keys to have different shape than the block attributes and theme.json. I lean towards making the client be more strict about these checks in a subsequent PR and actually verify that background and text are true.

Thoughts?

Copy link
Member Author

@oandregal oandregal Aug 2, 2020

Choose a reason for hiding this comment

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

See #24298 (comment) as an example where conflating background and text is forcing us to do things that we may not want to do.

"__experimentalColor": {
"gradients": true,
"linkColor": true
"__experimentalStyles": {
Copy link
Contributor

Choose a reason for hiding this comment

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

In this config, we'd want to:

  • Define whether something is enabled or not
  • Potentially define whether it uses presets
  • Potentially enable/disable custom values
  • Potentially choose whether to show selectors in inspector/toolbar
  • Potentially other configs I'm not thinking of right now.

Do you think this new config scales properly to all these kind of configs?
I do wonder whether this new config is more tailored toward applying styles and not configuring available controls for a block. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right. I'm thinking about separate keys per each thing. This is matching the styles subtree of the theme.json, the same way __experimentalFeatures in block.json matches the features subtree of the theme.json (which, atm, is only implemented by the paragraph block, though). If we wanted to add presets or UI configurations, we can do as separate keys within supports as well.

A couple of questions that I have are:

  1. Is this enough granularity for blocks that define many contexts (ex: heading block => core/heading/h1, core/heading/h2)? Both the current mechanism and this reorganization make all headings share the same features they support.

  2. What's the relation between block.json and the lib/experimental-theme.json that comes with core? Is block.json for enabling/disabling things and the experimental-theme.json for setting the values? Does it make sense to conflate the two? If we conflate them, the first question takes more importance as, for values, we do need different things per context.

All in all, given that this is a mere reorganization and that it doesn't introduce any block deprecations, etc, I think it's fine to go with this. It brings some needed clarity and alignment between block.json and theme.json.

Copy link
Contributor

Choose a reason for hiding this comment

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

Even if theme.json and block.json work in coordination, I'm not sure we should map one over the other tbh.

If I'm a block author's, I want to enable colors and configure how the controls show, I don't really care about applying styles aside maybe a default value, and it's weird tbh if these are in separate keys.

If I'm a theme author, I want to define a color palette for the editor, potentially define separate palettes for specific blocks and I want to enable/disable custom colors or palettes. I also want to give default values for colors. In this case, separate keys may be good.

It seems like two different ways of thinking about these configs.

I do wonder if it's too early to be aligning configs and thinking about what keys to use... Maybe we should focus now to adding more features and configs to all blocks and themes and once we have all of these under experimental flags or keys, we can decide how to align with a clear view.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I may have introduced some confusion. What we currently have is:

  1. If core blocks want to

    1. Declare support for a style property => use the block.json
    2. Set a default value for a style property => use core's lib/experimental-theme.json
  2. Theme authors want to set palettes, styles, etc => use the theme's theme.json

  3. Plugin authors want to

    1. Declare support for a style property => use the block.json
    2. Set a default value for a style property => we don't have an API for this.

I was referring to conflating 1.1 and 1.2. I think I may agree with you that probably is a good idea to keep them separated. However, we'd then need to find a solution for 3.2. I don't have an answer for this yet, just sharing early thoughts to get the conversation started.


As for the tree organization, I'm not too opinionated, as long as we use the same shape everywhere (block attributes, theme.json spec, and block supports). At the moment, block supports is the only place that uses a different shape. I guess we can fix what we have now for clarity and iterate later when we gain a better knowledge about this?

Copy link
Contributor

Choose a reason for hiding this comment

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

At the moment, block supports is the only place that uses a different shape. I guess we can fix what we have now for clarity and iterate later when we gain a better knowledge about this?

I was personally arguing that given the fact that block authors and theme authors think differently about these features, it make sense to have a different shape.

A block author think about the color support for his block wholistically and not separately (enabling, configuring presets, and potentially a default value)

which means: (block.json)

color: {
   enabled: true,
   gradients: true,
   ui: ['toolbar']
   palette: {} // Can define a palette that overrides the default editor palette
   default: "somevalue"  // may or may not be needed,
   allowCustomColor: true,
   allowCustomGradients:  true, 
}

but for a theme author (theme.json), he thinks differently, he thinks first about applying config globally and then go specific per block if needed. We also don't want to control the UI for blocks here. so for me:

presets: {
    global: {
       color: {}
    },
    core/some-block: {
       color: {}
    },
},

features: {
    global: {
       allowCustomColors: true,
    },
    core/some-block: {
      allowCustomColors: false,
    },
},

styles: {
    global: {
       color: 'black',
    },
    core/some-block: {
      color: 'red',
    },
}

also from a theme's author perspective, presets and features might be the same thing (just controlling the editor) so I wonder if they should be separate but I guess that's a separate discussion.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, let's put this PR in the backburner.

After some PRs I'm working on are merged (example: #24416) I was thinking of starting to port some of the theme_supports features to this new system. That may be a good opportunity to re-evaluate.

Copy link
Member Author

Choose a reason for hiding this comment

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

Riad, in case you missed it, more food for thought that's related to what we discussed here: #22887

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.

2 participants