funkhaus / wp-gql-gutenberg

GNU General Public License v3.0
4 stars 3 forks source link

BlockAttributes should return all attributes #17

Closed dChiamp closed 3 years ago

dChiamp commented 3 years ago

BlockAttributes is not returning all attributes set in blocks.

You can see in graphiQL that the title's textAlign is properly returning "center", but textColor is not "red". (see attached images)

ideally all blocks would include these default attributes:

     ... on BlockAttributes {
              content
              textAlign
              fontSize
              textColor
              className
              backgroundColor
            }
Screen Shot 2021-04-13 at 3 07 44 PM Screen Shot 2021-04-13 at 3 07 11 PM
rsm0128 commented 3 years ago

image image As you can see in the screenshots, the textColor, backgroundColor works for the blocks including heading block.

But in your test case, the color is not applied to the heading. Instead it is applied to the child span. You can confirm it in Code editor view. image

In my example, the markup code is <h2 class="has-text-align-center custom-class has-vivid-red-color has-pale-pink-background-color has-text-color has-background has-medium-font-size"><span>Ths is heading block</span>.</h2> As you can see all the classes appended to the h2 tag. But you should have color classes attached to the span in your markup.

rsm0128 commented 3 years ago

Here is the better example.

  1. Difference In Visual editor image image

  2. Difference in Code editor image

  3. Difference in WP-GraphQL image

drewbaker commented 3 years ago

I can confirm this not working correctly:

<!-- wp:heading {"style":{"color":{"text":"#ef275c","background":"#0d0921"}}} -->
<h2 class="has-text-color has-background" style="background-color:#0d0921;color:#ef275c">Test heading</h2>
<!-- /wp:heading -->
query MyQuery {
  page(id: "example-page", idType: URI) {
    blocks {
      ... on CoreHeadingBlock {
        name
        attributes {
          ... on CoreHeadingBlockAttributes {
            content
            fontSize
            backgroundColor
            textColor
          }
        }
      }
    }
  }
}
  "data": {
    "page": {
      "blocks": [
        {},
        {
          "name": "core/heading",
          "attributes": {
            "content": "Test heading",          
            "fontSize": "",
            "backgroundColor": "",
            "textColor": ""
          }
        },
        {}
      ]
    }
  }
rsm0128 commented 3 years ago

I can see it doesn't work with custom values. Let me handle the case.

rsm0128 commented 3 years ago

@drewbaker @dChiamp I fixed it and pushed to dev branch. Please check and let me know opinion. Thanks

dChiamp commented 3 years ago

That update is working!

Is it possible for the preset color options to return a hex like the custom colors? You can see the custom background color is a hex while the preset option returns the name string of the color:

Screen Shot 2021-04-19 at 10 26 15 AM Screen Shot 2021-04-19 at 10 26 01 AM
drewbaker commented 3 years ago

Or better yet, textColor.name and textColor.code?

rsm0128 commented 3 years ago

Please check the latest commit. I added backgroundColorCode, textColorCode, and fontSizeValue attribute

drewbaker commented 3 years ago

Please check the latest commit. I added backgroundColorCode, textColorCode, and fontSizeValue attribute

Is this on all blocks that support font/background color? Like paragraph, heading? (I think maybe blockquote too?)

rsm0128 commented 3 years ago

Yes, it supports all the blocks with backgroundColor, textColor and fontSize setting

dChiamp commented 3 years ago

awesome! tested and confirmed its working: ![Uploading Screen Shot 2021-04-19 at 1.52.23 PM.png…]()