This repository was archived by the owner on Jul 9, 2026. It is now read-only.
Repository navigation
Move BlockList and related components to Gutenberg repository #789
Closed
Closed
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
a8acbef
Move BlockList and related components to Gutenberg repository
Tug 203def2
Merge remote-tracking branch 'origin/develop' into update/move-block-…
Tug d721eed
Fix tests
Tug b2fd526
Fix lint errors
Tug 1854229
Remove SafeArea for the HTML editor
Tug e567f58
Update gutenberg ref
Tug 2a5848f
Merge remote-tracking branch 'origin/develop' into update/move-block-…
Tug b2d6c1e
Merge remote-tracking branch 'origin/develop' into update/move-block-…
Tug 07075ee
Get latest changes from gb mobile
Tug 355b03d
Merge remote-tracking branch 'origin/develop' into update/move-block-…
Tug cf7a578
Update gutenberg ref
Tug e051a59
Merge remote-tracking branch 'origin/develop' into update/move-block-…
Tug 94067e2
Merge remote-tracking branch 'origin/develop' into update/move-block-…
Tug c0652c9
Extract VisualEditor from AppContainer
Tug 0ec70e4
Update gutenberg ref
Tug b842900
Merge remote-tracking branch 'origin/develop' into update/move-block-…
Tug b8e55cd
Merge remote-tracking branch 'origin/develop' into update/move-block-…
Tug 763a396
Add MainScreen component that deals with switching the type of editor
Tug e88e4a6
Remove unused StateType in AppContainer
Tug ed9a548
Fix focus on title on mount
Tug 66d6f26
Merge remote-tracking branch 'origin/develop' into update/move-block-…
Tug e762945
Merge remote-tracking branch 'origin/develop' into update/move-block-…
Tug 4a89fb1
Add back ReadableContentView around PostTitle
Tug 0563a76
Revert "Fix focus on title on mount"
Tug 7010a2a
Remove unused prop definition setTitleAction
Tug e6c2571
Reduce diff size by reordering orders of methods in AppContainer
Tug 9ab0d9a
Fix post modified when opened and closed
Tug 619f72d
Revert to old logic and add comment explaining why it is there
Tug File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,12 +5,14 @@ | |
| * External dependencies | ||
| */ | ||
| import React from 'react'; | ||
| import type { EmitterSubscription } from 'react-native'; | ||
| import { type EmitterSubscription, type InputText } from 'react-native'; | ||
| import RNReactNativeGutenbergBridge, { | ||
| subscribeParentGetHtml, | ||
| subscribeParentToggleHTMLMode, | ||
| subscribeSetTitle, | ||
| subscribeUpdateHtml, | ||
| subscribeSetFocusOnTitle, | ||
| subscribeSetTitle, | ||
| sendNativeEditorDidLayout, | ||
| } from 'react-native-gutenberg-bridge'; | ||
| import { isEmpty } from 'lodash'; | ||
|
|
||
|
|
@@ -20,32 +22,35 @@ import { isEmpty } from 'lodash'; | |
| import { parse, serialize, getUnregisteredTypeHandlerName } from '@wordpress/blocks'; | ||
| import { withDispatch, withSelect } from '@wordpress/data'; | ||
| import { compose } from '@wordpress/compose'; | ||
| import { BlockEditorProvider } from '@wordpress/block-editor'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import type { BlockType } from '../store/types'; | ||
| import BlockManager from '../block-management/block-manager'; | ||
| import MainScreen from './MainScreen'; | ||
|
|
||
| type PostType = { | ||
| id: number; | ||
| title: { raw: string }; | ||
| content: { raw: string }; | ||
| type: string; | ||
| }; | ||
|
|
||
| type PropsType = { | ||
| initialHtmlModeEnabled: boolean, | ||
| editorMode: string, | ||
| editedPostContent: string, | ||
| title: string, | ||
| initialTitle: string, | ||
| initialHtml: string, | ||
| editTitle: string => mixed, | ||
| resetEditorBlocks: Array<BlockType> => mixed, | ||
| resetEditorBlocksWithoutUndoLevel: Array<BlockType> => mixed, | ||
| setupEditor: ( mixed, ?mixed ) => mixed, | ||
| toggleEditorMode: ?string => mixed, | ||
| blocks: Array<BlockType>, | ||
| isReady: boolean, | ||
| mode: string, | ||
| post: ?mixed, | ||
| post: ?PostType, | ||
| getEditorBlocks: () => Array<BlockType>, | ||
| getEditedPostAttribute: ( string ) => string, | ||
| getEditedPostContent: () => string, | ||
| switchMode: string => mixed, | ||
| editTitle: string => void, | ||
| }; | ||
|
|
||
| /* | ||
|
|
@@ -54,17 +59,20 @@ type PropsType = { | |
| * - `gutenberg/packages/edit-post/src/components/layout/index.js` | ||
| */ | ||
| class AppContainer extends React.Component<PropsType> { | ||
| lastHtml: ?string; | ||
| lastTitle: ?string; | ||
| post: PostType; | ||
| postTitleRef: ?InputText; | ||
| subscriptionParentGetHtml: ?EmitterSubscription; | ||
| subscriptionParentToggleHTMLMode: ?EmitterSubscription; | ||
| subscriptionParentSetTitle: ?EmitterSubscription; | ||
| subscriptionParentUpdateHtml: ?EmitterSubscription; | ||
| subscriptionParentSetFocusOnTitle: ?EmitterSubscription; | ||
|
|
||
| constructor( props: PropsType ) { | ||
| super( props ); | ||
|
|
||
| const post = props.post || { | ||
| ( this: any ).setTitleRef = this.setTitleRef.bind( this ); | ||
|
|
||
| this.post = props.post || { | ||
| id: 1, | ||
| title: { | ||
| raw: props.initialTitle, | ||
|
|
@@ -75,9 +83,12 @@ class AppContainer extends React.Component<PropsType> { | |
| type: 'draft', | ||
| }; | ||
|
|
||
| props.setupEditor( post ); | ||
| this.lastHtml = serialize( parse( props.initialHtml || '' ) ); | ||
| this.lastTitle = props.initialTitle; | ||
| props.setupEditor( this.post ); | ||
|
|
||
| // make sure the post content is in sync with gutenberg store | ||
| // to avoid marking the post as modified when simply loaded | ||
| // For now, let's assume: serialize( parse( html ) ) !== html | ||
| this.post.content.raw = serialize( this.props.getEditorBlocks() ); | ||
|
|
||
| if ( props.initialHtmlModeEnabled && props.mode === 'visual' ) { | ||
| // enable html mode if the initial mode the parent wants it but we're not already in it | ||
|
|
@@ -101,37 +112,52 @@ class AppContainer extends React.Component<PropsType> { | |
| this.subscriptionParentUpdateHtml = subscribeUpdateHtml( ( payload ) => { | ||
| this.updateHtmlAction( payload.html ); | ||
| } ); | ||
|
|
||
| this.subscriptionParentSetFocusOnTitle = subscribeSetFocusOnTitle( () => { | ||
| if ( this.postTitleRef ) { | ||
| this.postTitleRef.focus(); | ||
| } | ||
| } ); | ||
| } | ||
|
|
||
| componentWillUnmount() { | ||
| if ( this.subscriptionParentGetHtml ) { | ||
| this.subscriptionParentGetHtml.remove(); | ||
| } | ||
|
|
||
| if ( this.subscriptionParentToggleHTMLMode ) { | ||
| this.subscriptionParentToggleHTMLMode.remove(); | ||
| } | ||
|
|
||
| if ( this.subscriptionParentSetTitle ) { | ||
| this.subscriptionParentSetTitle.remove(); | ||
| } | ||
|
|
||
| if ( this.subscriptionParentUpdateHtml ) { | ||
| this.subscriptionParentUpdateHtml.remove(); | ||
| } | ||
|
|
||
| if ( this.subscriptionParentSetFocusOnTitle ) { | ||
| this.subscriptionParentSetFocusOnTitle.remove(); | ||
| } | ||
| } | ||
|
|
||
| serializeToNativeAction() { | ||
| if ( this.props.mode === 'text' ) { | ||
| this.updateHtmlAction( this.props.getEditedPostContent() ); | ||
| } | ||
|
|
||
| const html = serialize( this.props.blocks ); | ||
| const title = this.props.title; | ||
| const html = serialize( this.props.getEditorBlocks() ); | ||
| const title = this.props.getEditedPostAttribute( 'title' ); | ||
|
|
||
| const hasChanges = title !== this.lastTitle || html !== this.lastHtml; | ||
| const hasChanges = title !== this.post.title.raw || html !== this.post.content.raw; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder, is the serialization/parsing pair symmetric nowadays? I remember we needed the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't tried but I can have a look with our sample post ( |
||
|
|
||
| RNReactNativeGutenbergBridge.provideToNative_Html( html, title, hasChanges ); | ||
|
|
||
| this.lastTitle = title; | ||
| this.lastHtml = html; | ||
| if ( hasChanges ) { | ||
| this.post.title.raw = title; | ||
| this.post.content.raw = html; | ||
| } | ||
| } | ||
|
|
||
| updateHtmlAction( html: string = '' ) { | ||
|
|
@@ -145,8 +171,8 @@ class AppContainer extends React.Component<PropsType> { | |
| } | ||
|
|
||
| componentDidUpdate( prevProps ) { | ||
| if ( ! prevProps.isReady && ( prevProps.isReady !== this.props.isReady ) ) { | ||
| const { blocks } = this.props; | ||
| if ( ! prevProps.isReady && this.props.isReady ) { | ||
|
hypest marked this conversation as resolved.
Resolved
|
||
| const blocks = this.props.getEditorBlocks(); | ||
| const isUnsupportedBlock = ( { name } ) => name === getUnregisteredTypeHandlerName(); | ||
| const unsupportedBlocks = blocks.filter( isUnsupportedBlock ); | ||
| const hasUnsupportedBlocks = ! isEmpty( unsupportedBlocks ); | ||
|
|
@@ -155,34 +181,16 @@ class AppContainer extends React.Component<PropsType> { | |
| } | ||
| } | ||
|
|
||
| render() { | ||
| const { | ||
| blocks, | ||
| editTitle, | ||
| isReady, | ||
| mode, | ||
| resetEditorBlocks, | ||
| resetEditorBlocksWithoutUndoLevel, | ||
| title, | ||
| } = this.props; | ||
|
|
||
| if ( ! isReady ) { | ||
| return null; | ||
| } | ||
| setTitleRef( titleRef: ?InputText ) { | ||
| this.postTitleRef = titleRef; | ||
| } | ||
|
|
||
| render() { | ||
| return ( | ||
| <BlockEditorProvider | ||
| value={ blocks } | ||
| onInput={ resetEditorBlocksWithoutUndoLevel } | ||
| onChange={ resetEditorBlocks } | ||
| settings={ null } | ||
| > | ||
| <BlockManager | ||
| title={ title } | ||
| setTitleAction={ editTitle } | ||
| showHtml={ mode === 'text' } | ||
| /> | ||
| </BlockEditorProvider> | ||
| <MainScreen | ||
| setTitleRef={ this.setTitleRef } | ||
| onNativeEditorDidLayout={ sendNativeEditorDidLayout } | ||
| /> | ||
| ); | ||
| } | ||
| } | ||
|
|
@@ -200,10 +208,10 @@ export default compose( [ | |
| } = select( 'core/edit-post' ); | ||
|
|
||
| return { | ||
| isReady: isEditorReady(), | ||
| blocks: getEditorBlocks(), | ||
| mode: getEditorMode(), | ||
| title: getEditedPostAttribute( 'title' ), | ||
| isReady: isEditorReady(), | ||
| getEditorBlocks, | ||
| getEditedPostAttribute, | ||
| getEditedPostContent, | ||
| }; | ||
| } ), | ||
|
|
@@ -221,7 +229,6 @@ export default compose( [ | |
| editTitle( title ) { | ||
| editPost( { title } ); | ||
| }, | ||
| resetEditorBlocks, | ||
| resetEditorBlocksWithoutUndoLevel( blocks ) { | ||
| resetEditorBlocks( blocks, { | ||
| __unstableShouldCreateUndoLevel: false, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Will this prop set override the
editTitleprovided inside theHTMLInputViewitself viawithDispatch?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.
Yes because we're not importing the default
HTMLInputViewcomponent here but the original class exported hereThere 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.
Ah, I see. Gosh, that pattern is super confusing :(. I wish we could make it better.