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

Plugin: Quote Block Initial Attempt #327

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions editor/blocks/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import './text';
import './quote';
42 changes: 42 additions & 0 deletions editor/blocks/quote/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const Editable = wp.blocks.Editable;
const { html } = wp.blocks.query;

wp.blocks.registerBlock( 'core/quote', {
title: 'Quote',
icon: 'format-quote',
category: 'common',

attributes: {
value: html( 'blockquote > p' ),
Copy link
Member

Choose a reason for hiding this comment

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

A blockquote could contain multiple paragraphs. In my explorer demo I use text: query( 'p', html() ) instead which assigns text as an array of each paragraph's HTML.

https://aduth.github.io/hpq/

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh my bad, it was my recommendation

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we join the output directly using hpq?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We will probably want to map the values in value to its of <p> component as well right?

Copy link
Member

Choose a reason for hiding this comment

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

Could we join the output directly using hpq?

Not super cleanly, but possible. Since each matcher is just a function receiving a node, you can create your own pass-through:

attributes: {
	value: ( node ) => query( 'p', html() )( node ).join()
}

Or some compose-y equivalent.

I don't know that it's necessary a big issue to need to deal with this in the render behavior though.

citation: html( 'footer' )
},

edit( attributes, onChange ) {
const { value, citation } = attributes;

return (
<blockquote>
<Editable
value={ value }
onChange={ ( newValue ) => onChange( { value: newValue } ) } />
<footer>
<Editable
value={ citation }
onChange={ ( newValue ) => onChange( { citation: newValue } ) } />
</footer>
</blockquote>
);
},

save( attributes ) {
const { value, citation } = attributes;
return (
<blockquote>
{ value }
<footer>
Copy link
Member

Choose a reason for hiding this comment

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

We may want to account for the case that citation is empty and avoid including the footer if possible. This was one of the reasons for hpq: to account for cases where the markup isn't always necessarily the same in the generated output (maybe a quote citation, maybe an image caption, but not necessarily).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup sounds good! For some reason this slipped my brain, great catch. Does hpq return an empty value if there is nothing matched by the query?

Copy link
Member

Choose a reason for hiding this comment

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

Does hpq return an empty value if there is nothing matched by the query?

Yeah, specifically an undefined value if I recall correctly.

{ citation }
</footer>
</blockquote>
);
}
} );