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

Remove and prevent DOM access in block attributes matchers #624

Merged
merged 2 commits into from
May 5, 2017

Conversation

aduth
Copy link
Member

@aduth aduth commented May 3, 2017

Closes #608

This pull request seeks to remove existing attributes matchers which operate on the DOM; currently image and quote blocks pulling attribute values from element class names. Instead, these attributes are to be encoded into the block comment. Further, it seeks to prevent future attributes created in this pattern by applying an internal flag to acceptable attribute matcher creators (attr, children, etc).

Copying an included code comment which elaborates:

// Matchers are implemented as functions that receive a DOM node from
// which to select data. Use of the DOM is incidental and we shouldn't
// guarantee a contract that this be provided, else block implementers
// may feel compelled to use the node. Instead, matchers are intended
// as a generic interface to query data from any tree shape. Here we
// pick only matchers which include an internal flag.

Testing instructions:

Ensure that tests pass:

npm test

Verify that image alignment and quote styles are still respected, including after changing the values and switching back and forth between Visual and HTML modes.

@aduth aduth added the [Feature] Block API API that allows to express the block paradigm. label May 3, 2017
},

controls: [ 1, 2 ].map( ( variation ) => ( {
icon: 'format-quote',
title: wp.i18n.sprintf( wp.i18n.__( 'Quote style %d' ), variation ),
isActive: ( { style = 1 } ) => style === variation,
isActive: ( { style = 1 } ) => Number( style ) === variation,
Copy link
Member Author

Choose a reason for hiding this comment

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

Ideally we'd not need to coerce style to a number, but instead incorporate into attributes (#609) or serialize comment attributes as typed-ish JSON (#482 (comment)).

@mtias
Copy link
Member

mtias commented May 3, 2017

I like this.

@aduth aduth force-pushed the update/608-remove-attributes-dom branch from 7e7c901 to 3e14439 Compare May 5, 2017 12:37
@aduth
Copy link
Member Author

aduth commented May 5, 2017

Rebased with consideration of #616, #623, and #626.

Will plan to merge shortly.

@aduth aduth merged commit 6f5deec into master May 5, 2017
@aduth aduth deleted the update/608-remove-attributes-dom branch May 5, 2017 12:49
@aduth aduth mentioned this pull request May 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants