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: split RichText component (part 1) #15212

Merged
merged 12 commits into from Jun 25, 2019
Merged

Conversation

ellatrix
Copy link
Member

@ellatrix ellatrix commented Apr 26, 2019

Description

What?

This PR splits out general RichText logic from the block-editor package to the rich-text package. It leaves block related context. That's all it does!

Why?

  • A RichText component can be used outside of the block or post context, such as in a sidebar, note...
  • It's easier to maintain.

How?

There will be two RichText components in each package, where the one in the block-editor package wraps the one in the rich-text package and adds block context.

There's a few temporary unstable props added that aid this wrapping, but in the future these props should be stabilised. Some props might disappears, some need to be renamed for the "bare" RichText component.

How has this been tested?

Nothing should have changed. Just ensure all e2e tests pass.

Screenshots

Types of changes

Refactoring.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@ellatrix ellatrix added [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Package] Rich text /packages/rich-text labels Apr 26, 2019
@ellatrix ellatrix added the [Status] In Progress Tracking issues with work in progress label Apr 26, 2019
@ellatrix ellatrix mentioned this pull request May 28, 2019
5 tasks
@ellatrix ellatrix force-pushed the try/move-rich-text branch 3 times, most recently from d57587b to 068c5e4 Compare June 9, 2019 21:29
@ellatrix
Copy link
Member Author

@hypest Do you foresee any problems with mobile? Who could help check?

@hypest
Copy link
Contributor

hypest commented Jun 19, 2019

Who could help check?

@SergioEstevao has already picked this up from the native mobile side 👍

@hypest
Copy link
Contributor

hypest commented Jun 19, 2019

👋 @ellatrix , I wonder, can you expand the PR description to include explanation/mention of the non-obvious changes in the PR? For example, this change from controls.map to [ 'bold', 'italic', 'link' ].map is not obvious and would be helpful to describe for the reader to understand. Such descriptions tend to be super useful when trying to debug issues later on.

@ellatrix ellatrix changed the title Framework: move RichText component to rich-text package Framework: split RichText component (part 1) Jun 25, 2019
__unstableOnEnterFormattedText={ onEnterFormattedText }
__unstableOnExitFormattedText={ onExitFormattedText }
__unstableCanUserUseUnfilteredHTML={ canUserUseUnfilteredHTML }
__unstableOnCreateUndoLevel={ onCreateUndoLevel }
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like a lot of unstable Props :) How do we plan to solve these in the future?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes! :) But I don't want to rewrite it all at once so I temporarily marked them unstable.

<FormatToolbar />
</IsolatedEventContainer>
) }
{ isSelected && <RemoveBrowserShortcuts /> }
Copy link
Contributor

Choose a reason for hiding this comment

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

Why aren't these absorb by the underlying component (toolbars and RemoveBrowserShortcuts)?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's block editor specific?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what RemoveBrowserShortcuts is but don't we want the format toolbar support by default in the RichText component?

Copy link
Member Author

Choose a reason for hiding this comment

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

It has toolbar support, but not a specific toolbar. This is the toolbar implementation for RichText instances in blocks. When using RichText (without the context), you could create your own custom toolbars.

format: 'string',
value: '',
};

const RichTextContainer = compose( [
withInstanceId,
withBlockEditContext( ( { clientId } ) => ( { clientId } ) ),
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: The withSelect here, could become a useSelect

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I've merely moved this code, I don't want to do a rewrite here to avoid making the PR more complex. I'm hoping for a quick merge so I don't have to do painful rebases. :)

@@ -22,11 +22,21 @@
"react-native": "src/index",
"dependencies": {
"@babel/runtime": "^7.4.4",
"@wordpress/blob": "file:../blob",
Copy link
Contributor

Choose a reason for hiding this comment

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

These changes make me think we need to update Core to support the webpack plugin to extract the dependencies, otherwise, we could miss these changes once we update Core. cc @gziolo @sirreal

Copy link
Member

Choose a reason for hiding this comment

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

Sorry for overlooking this. Is there an open issue somewhere to track this or can you provide more details? I don't know what would be involved in that work.

Copy link
Member Author

Choose a reason for hiding this comment

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

What's different here from other dependencies being added to packages?

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

Left some small comments, but this makes sense to me.

@ellatrix
Copy link
Member Author

Thanks for the review @youknowriad! I will now merge the mobile PR into this one, then wait for tests to pass, then merge it into master.

@hypest
Copy link
Contributor

hypest commented Jun 25, 2019

then wait for tests to pass, then merge it into master

👋 @ellatrix , what do you think about #16219, can we have that updated first?

@ellatrix
Copy link
Member Author

@hypest yes, that’s what I mean, the mobile PR needs to be merged into this branch?

@hypest
Copy link
Contributor

hypest commented Jun 25, 2019

#16219 seems to have conflicts currently. Are you planning to update it to resolve @ellatrix?

@ellatrix
Copy link
Member Author

ellatrix commented Jun 25, 2019 via email

@hypest
Copy link
Contributor

hypest commented Jun 25, 2019

I’ll have to do it later tonight

Thanks! I think I'll be able to help tomorrow if not done by then. Sérgio is AFK so, happy to help.

* Move React Native RichText to new package

* Fix multiline reading.

* Move default styles to component.

* Move tests to component.

* Fix paste on title
@ellatrix ellatrix merged commit ebd94e2 into master Jun 25, 2019
@ellatrix ellatrix deleted the try/move-rich-text branch June 25, 2019 21:12
@ellatrix
Copy link
Member Author

Thanks everyone!

return (
<div className="editor-format-toolbar block-editor-format-toolbar">
<Toolbar>
{ controls.map( ( format ) =>
{ [ 'bold', 'italic', 'link' ].map( ( format ) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Forgot to ask, why is this hardcoded now?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, good question! These names are kind of hardcoded already in the formatting library. You cannot really add anything else here. But I forgot about the case where you'd remove the controls by setting an empty array. That case was already only partially working in master, see #14542. Let's try to correct it there again.

Copy link
Member Author

Choose a reason for hiding this comment

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

Now fixed in #14542.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Package] Rich text /packages/rich-text [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants