-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Format API #10209
Format API #10209
Conversation
602ea12
to
e121387
Compare
e121387
to
b8ad7bd
Compare
Rebased after #7890 merge. |
fa41550
to
7e0c850
Compare
* @return {boolean} True if the parameter is a valid icon and false otherwise. | ||
*/ | ||
|
||
export function isValidIcon( icon ) { |
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.
Ideally this needs to be shared with the blocks
package,
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.
Can we use the one from blocks both isValidIcon
and normalizeIconObject
? Inline block is one of the special formatter options, so this would make sense. Any blockers?
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.
I'm not sure I'm understanding this. Should I import them from the blocks package?
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.
I assume, yes we can. Is there any reason to not do it? The inline image is very similar to a block, so they should share the same logic.
I'm moving it to 4.2 as we decided that 4.1 should be UI freeze focused. 4.2 is planned to be focused on API freeze and this PR fits perfectly to that description :) |
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.
I did my first pass of review. This PR is very big. I will play with it in the browser later today.
@@ -71,28 +70,11 @@ function Toolbar( { controls = [], children, className, isCollapsed, icon, label | |||
<ToolbarContainer className={ classnames( 'components-toolbar', className ) }> | |||
{ flatMap( controlSets, ( controlSet, indexOfSet ) => ( | |||
controlSet.map( ( control, indexOfControl ) => ( | |||
<ToolbarButtonContainer | |||
<ToolbarButton | |||
key={ [ indexOfSet, indexOfControl ].join() } | |||
className={ indexOfSet > 0 && indexOfControl === 0 ? 'has-left-divider' : null } |
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.
It looks like this should be renamed to containerClassName
.
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.
I'm not following :)
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.
packages/edit-post/src/index.js
Outdated
@@ -59,6 +60,7 @@ export function initializeEditor( id, postType, postId, settings, overridePost ) | |||
const reboot = reinitializeEditor.bind( null, postType, postId, target, settings, overridePost ); | |||
|
|||
registerCoreBlocks(); | |||
registerCoreFormats(); |
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.
I'm wondering if we should register core formats right away instead. In effect, don't offer this method at all.
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.
I'm wondering if we should register core formats right away instead. In effect, don't offer this method at all.
💯 registerCoreBlock
is a necessary hack, and certainly shouldn't serve as an ideal precedent.
@@ -123,7 +123,7 @@ export class BlockSwitcher extends Component { | |||
title={ __( 'Transform To:' ) } | |||
initialOpen | |||
> | |||
<BlockTypesList | |||
<InserterList |
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.
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.
I also feel like it would be better to keep this change out of the scope of this PR to make it smaller. It isn't part of the public API.
* @return {boolean} True if the parameter is a valid icon and false otherwise. | ||
*/ | ||
|
||
export function isValidIcon( icon ) { |
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.
Can we use the one from blocks both isValidIcon
and normalizeIconObject
? Inline block is one of the special formatter options, so this would make sense. Any blockers?
import * as selectors from './selectors'; | ||
import * as actions from './actions'; | ||
|
||
registerStore( 'core/formats', { reducer, selectors, actions } ); |
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.
It should be core/rich-text
namespace.
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.
Ok
expect( formatTypes( undefined, {} ) ).toEqual( {} ); | ||
} ); | ||
|
||
it( 'should add add a new block type', () => { |
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.
Copy and paste -> block
} ); | ||
} ); | ||
|
||
it( 'should remove block types', () => { |
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.
Copy and paste -> block
import { applyFormat } from './apply-format'; | ||
|
||
/** | ||
* Toggle a format object to a Rich Text value at the current selection. |
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.
Nit: it should start with Toggles
Added buggy support for keyboard shortcuts with 5c052ce. For some reasons, you have to use keys combination twice to ensure it takes effect ... |
Removing from the milestone as the parent issue is already listed. |
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 is really cool. The fact that one can write a format which is then usable across all blocks that use RichText
is amazing.
The annotations API will work great on top of this. The only thing that's missing here is a way to have a format apply only to the editor, but not the serialization. But that could be added in the annotations PR.
5c052ce
to
a688ac8
Compare
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.
Can we not have registerCoreFormats
?
https://github.com/WordPress/gutenberg/pull/10209/files#r225149941
24ef98a
to
7fd020f
Compare
Let's merge and iterate! |
…rnmobile/merge-blocks-on-backspace * 'master' of https://github.com/WordPress/gutenberg: Do not add isDirty prop to DOM (#11093) Format API (#10209) Remove 4.2 deprecated features (#10952) Update `@wordpress/hooks` README to include namespace mention (#11061) Feature: save lock control via actions (#10649) Fix usage of `preg_quote()` (#10998) Update plugin version to 4.1.1 (#11078) Improve preloading request code (#11007) Fix dynamic blocks not rendering in the frontend (#11050) Media & Text: Fixing vertical alignment of the image (#11025) Date: Mark getSettings as experimental (#10636) Improve handling of centered 1-col galleries with small images (#11040) Use better help text for ALT text input; fixes #8391. (#11052) # Conflicts: # packages/editor/src/components/rich-text/index.native.js
Description
Fixes: #10068, #4658.
This PR does a couple of things:
rich-text
package, which will also be used by Gutenberg itself for the "core" formats in theformat-library
package.For more information, see #10068.
How has this been tested?
Screenshots
Types of changes
Checklist: