-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Footnote numbering hooks #3685
Footnote numbering hooks #3685
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3685 +/- ##
========================================
- Coverage 38.22% 37.23% -1%
========================================
Files 282 277 -5
Lines 6864 6674 -190
Branches 1257 1215 -42
========================================
- Hits 2624 2485 -139
+ Misses 3566 3532 -34
+ Partials 674 657 -17
Continue to review full report at Codecov.
|
blocks/block-edit/index.js
Outdated
@@ -20,7 +20,14 @@ function BlockEdit( props ) { | |||
Edit = blockType.edit || blockType.save; | |||
} | |||
|
|||
return applyFilters( 'BlockEdit', <Edit key="edit" { ...editProps } />, props ); | |||
const filteredElements = applyFilters( 'BlockEdit', { edit: <Edit key="edit" { ...editProps } />, fragments: [] }, props ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aduth does it make sense separate the Edit
element here so that later hooks can rely on it being an element still (in the shape registered)? I added a fragments
key also which works for fills, this could actually be calledfills
...
blocks/block-edit/index.js
Outdated
return applyFilters( 'BlockEdit', <Edit key="edit" { ...editProps } />, props ); | ||
const filteredElements = applyFilters( 'BlockEdit', { edit: <Edit key="edit" { ...editProps } />, fragments: [] }, props ); | ||
|
||
if ( filteredElements.edit.type !== Edit ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be too limiting...
Yes, @gziolo had explored what I find to be a better approach for handling the component hooks, which is to treat each hook as a higher-order component. In other words, it doesn't return an element (which can take many shapes) but instead returns a new component. @gziolo has this since been merged? Can you link to the work here? |
The aforementioned work is #3827, where some discussion has already occurred. |
blocks/hooks/footnotes.js
Outdated
return element; | ||
} | ||
|
||
export default function footnotes( { addFilter } ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#3827 that @aduth referenced got merged. We no longer pass addFilter
from outside. It's now directly imported from @wordpress/hooks
. We also updated hook names:
getSaveContent.extraProps
->blocks.getSaveContent.extraProps
BlockEdit
->blocks.BlockEdit
Those name may change in the near future. You can also use slashes in namespaces:core-footnotes
vscore/footnotes
Thanks @aduth the BlockEdit hook returning a HoC works nicely! |
@mtias - is it something we need for 5.0? It looks like an abandoned task. |
There was no activity in this PR for over 6 months. It looks like it was abandoned. Let’s close it. We can always reopen and rebase it with master branch to align with the current state of Gutenberg. |
Description
Exploring using hooks to number/remove numbering from footnotes.
Need to use the following content in a Paragraph block:
The
getSaveContent.extraProps
hook works quite well to post-process content however theBlockEdit
hook is a little harder to get right.If I click in the Paragraph block the
custom-class-name
hook will run first and return an array with theEdit
andInspectorControls
elements so the footnotes hook needs to be aware of this structure changed by the previous hook...Is there a better way to manage this?
Also the footnotes hook will need to be able to access redux state, as I'm sure other hooks will, in order to determine the numbering of the footnotes...
How Has This Been Tested?
Screenshots (jpeg or gifs if applicable):
Types of changes
Checklist: