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

Framework: Move components from the blocks to the editor module #6521

Merged
merged 12 commits into from
May 7, 2018

Conversation

youknowriad
Copy link
Contributor

Spoiler alert: Huge PR coming with big implications.

Related #6275

Sorry for the huge PR but sometimes big changes are unavoidable. The idea of this PR is to move the reusable components to build blocks from the blocks module to the editor module (the reasoning behind this is explained in #6275)

Notes

  • I'm polyfilling wp.blocks.* components to ensure backward compatibility
  • There are some "todos" still: (renaming filters and moving tests) that I left for a separate PR

Questions

  • We should communicate about this change, we'll leave time for people to upgrade their code but this is definitely going to impact all custom blocks.

How can we move forward with this?

@youknowriad youknowriad added the Framework Issues related to broader framework topics, especially as it relates to javascript label May 1, 2018
@youknowriad youknowriad self-assigned this May 1, 2018
@youknowriad youknowriad requested a review from a team May 1, 2018 12:43
@youknowriad youknowriad force-pushed the try/move-components-2-editor branch from 7a9c1d8 to c7f3d23 Compare May 1, 2018 12:45
@noisysocks
Copy link
Member

We should communicate about this change, we'll leave time for people to upgrade their code but this is definitely going to impact all custom blocks.

A polyfill with a deprecated message that we leave in for 3-5 minor versions seems totally reasonable to me.

@@ -0,0 +1 @@
export { default as PlainText } from './components/plain-text';
Copy link
Member

Choose a reason for hiding this comment

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

@hypest is it enough to make it work on mobile?

Copy link
Contributor

@hypest hypest May 4, 2018

Choose a reason for hiding this comment

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

Thanks for asking @gziolo , yes, that's enough to make it work on mobile. I wonder though, wdyt about "native-ize" ./components/index.native.js instead of ./editor/index.native.js? Is the components module too web-specific you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The difference between editor and components is that components is meant to be generic UI components independent from WP backend or the editor while the editor is for components used to build blocks/editor.

PlainText and RichText can be bound to the editor state, that's wy they live in editor.

Copy link
Contributor

@hypest hypest May 4, 2018

Choose a reason for hiding this comment

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

Thanks for the insight @youknowriad , that's helpful!

In this particular case, I'm actually referring to the editor/components mobule, not the top-level components. If I understand it correctly, PlainText and RichText live in the submodule in this PR, the index.js of which I'm suggesting to "native-ize". So, editor/index.native.js will still import * from './components' but editor/components/index.native.js will only export PlainText for now. Does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, Understood and actually, I don't know. I don't really know how your react-native setup works, I thought the most important thing would be the root module (editor/index) but yeah if you need to keep the rest of the editor/index as is. I can update to move this to editor/components/index.native.js

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought the most important thing would be the root module (editor/index)

Glad you mention that so we can expand a bit. I guess the main premise for now is to use the index.jss that serve as muster points as a good opportunity for specialization/nativization. Not necessarily the root module ones though. All index.jss can fall under that pattern. Hope this makes sense.

I can update to move this to editor/components/index.native.js

Yes, let's go with that, thanks! 🙇

export { default as RichText } from './rich-text';
export { default as RichTextProvider } from './rich-text/provider';
export { default as UrlInput } from './url-input';
export { default as UrlInputButton } from './url-input/button';
export { default as EditorSettings, withEditorSettings } from './editor-settings';
Copy link
Member

Choose a reason for hiding this comment

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

Why do editor-settings and editor-media-upload remain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because I was planning to them separately. See #6500 for the editor settings. And both require the components to be moved first.

@@ -1,3 +1,28 @@
// Block Creation Component
Copy link
Member

Choose a reason for hiding this comment

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

Nit: "Component" -> "Components"

alternative: 'wp.editor.' + key,
plugin: 'Gutenberg',
} );
wrappedFunction( ...args );
Copy link
Member

Choose a reason for hiding this comment

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

Should this return ?

@youknowriad youknowriad force-pushed the try/move-components-2-editor branch from 0d97455 to 93f9bfc Compare May 4, 2018 13:03
@gziolo
Copy link
Member

gziolo commented May 4, 2018

@youknowriad, can we list all the remaining task so we could split work with follow-ups?
I can help with all test related and filter related tasks if you need want.

@gziolo
Copy link
Member

gziolo commented May 4, 2018

Pushed c3463ca with RN changes.

@youknowriad
Copy link
Contributor Author

@gziolo Sure, I updated the issue description with a todo list, feel free to add what I missed #6275

withColorContext,
getColorClass,
getColorName,
withColors,
Copy link
Member

Choose a reason for hiding this comment

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

@jorgefilipecosta what's the difference between withColors and withColorContext?
It's the last chance to rename them to make it less confusing.

@youknowriad youknowriad force-pushed the try/move-components-2-editor branch 3 times, most recently from 40920e9 to 2673327 Compare May 7, 2018 08:23
@youknowriad youknowriad force-pushed the try/move-components-2-editor branch from ec95203 to d12ff98 Compare May 7, 2018 09:12
Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

I tested with a plugin that registers block that uses deprecated wp.blocks.* component and it worked properly and I could see the warning:

wp.blocks.InspectorControls is deprecated and will be removed from Gutenberg in 3.1. Please use wp.editor.InspectorControls instead.

There is one small debugging change introduced which should be removed. I also see the React warning coming from the Custom HTML block. It needs to be confirmed it isn't regression introduced by this PR:

Warning: Failed prop type: You provided a value prop to a form field without an onChange handler. This will render a read-only field. If the field should be mutable use defaultValue. Otherwise, set either onChange or readOnly.
in textarea (created by CodeEditor)
in CodeEditor (created by LazyCodeEditor)

In overall, this works as expected and looks great. I think we should proceed as soon as two issues raised are sorted out. :shipit:

@@ -471,10 +452,10 @@ function gutenberg_preload_api_request( $memo, $path ) {
* @since 0.1.0
*/
function gutenberg_register_vendor_scripts() {
$suffix = SCRIPT_DEBUG ? '' : '.min';
$suffix = SCRIPT_DEBUG || true ? '' : '.min';
Copy link
Member

Choose a reason for hiding this comment

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

|| true shouldn't be included here and in the next statement :)

@youknowriad
Copy link
Contributor Author

Confirmed the React warning is also present in master, let's address separately.

@youknowriad youknowriad merged commit f95b2d5 into master May 7, 2018
@youknowriad youknowriad deleted the try/move-components-2-editor branch May 7, 2018 11:25
@gziolo
Copy link
Member

gziolo commented May 7, 2018

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework Issues related to broader framework topics, especially as it relates to javascript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants