-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 library: Allow explicit registration when using npm packages #11611
Conversation
'wp-format-library', | ||
'wp.formatLibrary.registerCoreFormatTypes();', | ||
'after' | ||
); |
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.
How can we make sure someone use the edit-post
module (via npm) get the formats by default?
Can we remove the wp_enqueue_script
(and style) in favor of an explicit dependency towards wp-format-library
in wp-edit-post
?
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.
Does it mean, we would call registerCoreFormatTypes
in edit-post
instead?
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.
Maybe, It's not perfect because people that want to unregister these styles would need edit-post
as a dependency. I'd love other opinions.
Thanks for taking care of this. |
link, | ||
strikethrough, | ||
].map( | ||
( { name, ...settings } ) => [ name, settings ] |
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.
Why did we land on an array return value here.
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.
The shape it returns would have to be defined, I opted for the simplicity of refactoring :)
We can make it { name, settings }
or reduce everything to { [ name ]: settings, ... }
. I'm fine with all of them.
import { | ||
registerFormatType, | ||
} from '@wordpress/rich-text'; | ||
export function getCoreFormatTypes() { |
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.
JSDoc.
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.
Does it mean we are good with the proposal?
#7718 is relevant to consider here, as it includes a new "core" format registered immediately in the I'm on the fence with these functions for registering as it's unclear whether we should consider the idea of registration in tandem with activation, vs. the mere availability of a thing. In practice, we don't make the distinction, which is maybe why we've needed to consider making it an explicit step to trigger the registration. Could we have more context to this:
? |
I can see the following issue. You can have more than one version of the same package installed from npm, so the issue boils down to using pure functions rather than the global registry to avoid potential conflicts. We had such reports in the past with Calypso loading 2 different versions of
For WordPress plugins, it's convenient to register them right away as site owners can opt-in for their usage. In WordPress core we need to provide some way to make it customizable. The same applies to npm where I would expect even more control because you assume it's for very advanced usage. |
I don't think we reached an agreement on this one. I'm closing it as won't fix. I don't see this as a big issue. We can revisit later as soon as we figure out how to deal with server-side registration for blocks. |
Description
At the moment we register all core format types right away when
@wordpress/format-library
is executed as discussed here #10209 (comment):Related code:
https://github.com/WordPress/gutenberg/blob/master/packages/format-library/src/index.js#L18-L25
This is not ideal when consuming npm package. This PR was opened to discuss alternative approaches. The idea is to offer more granular integration points for the usage outside of WordPress.
This PR explores the following items:
getCoreFormatTypes
returns an array with all core format types in case someone would want to filter out some of the formats. The shape it returns would have to be defined, I opted for the simplicity of refactoring :)registerCoreFormatTypes
method registers all core formats as it happens today.registerCoreFormatTypes
is executed right afterwp-format-library
is enqueued which basically mirrors what happens today.Whatever we decide here, should be also applied to
@wordpress/block-library
for consistency.