-
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
Implement list block in React Native #14636
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
bd83d8f
Make sure multiline property is filtered out of props on save.
SergioEstevao 8ed9cc0
Send block edit parameters using the context.
SergioEstevao e0d7cf6
Add multiline variables to allow proper parsing and saving of propert…
SergioEstevao eb33f84
Add list edit toolbar options
SergioEstevao c64dd5a
Add multiline property.
SergioEstevao f0a1e21
Add list block to mobile gb.
SergioEstevao 73aaa4f
Move list-edit.native.js to new location.
SergioEstevao b6938aa
Make block edit send down the onFocus property.
SergioEstevao 74f77cf
Handle case where unstableSplit is passed has prop.
SergioEstevao 79f408c
Pass multiline tags to serialiser.
SergioEstevao 1f12a9f
Use the format-lib for handling "Enter" in lists
hypest cc8a4e8
Merge branch 'master' into rnmobile/lists2
SergioEstevao ca338c2
Force selection reset on split
hypest 076936f
Add multiline wrapper tags to formatToValue.
SergioEstevao 6ff97b8
Merge branch 'rnmobile/lists2' of https://github.com/WordPress/gutenb…
SergioEstevao 73fbd38
Remove unnecessary code.
SergioEstevao e07498e
Force rich-text text update on list type change
hypest f40852c
Merge branch 'master' into rnmobile/lists2
SergioEstevao 7fb36f6
Merge branch 'master' into rnmobile/lists2
SergioEstevao 9145a6d
Merge branch 'master' into rnmobile/lists2
SergioEstevao 58eae26
Disable indent and outdent.
SergioEstevao 08318ca
Enable toggling list type of nested lists
hypest 9dcd23b
Update list type toolbar button on native mobile
hypest fd62f01
Include diff missed by previous commit
hypest 66e971d
Rename to denote that it's about lines
hypest da0e1a7
Split into separate functions and mark unstable
hypest eb009e8
Add missing JSDoc param
Tug cc5666e
Update snapshot for BlockControls
Tug 91f790c
Merge branch 'master' into rnmobile/lists2
SergioEstevao 4451cb3
Move isActiveListType, isListRootSelected to rich-text package
hypest 97ac0fb
Remove excess empty line
hypest 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 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 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 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
55 changes: 55 additions & 0 deletions
55
packages/block-editor/src/components/rich-text/list-edit.native.js
This file contains 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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
|
||
import { Toolbar } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
changeListType, | ||
__unstableIsListRootSelected, | ||
__unstableIsActiveListType, | ||
} from '@wordpress/rich-text'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
|
||
import BlockFormatControls from '../block-format-controls'; | ||
|
||
export const ListEdit = ( { | ||
onTagNameChange, | ||
tagName, | ||
value, | ||
onChange, | ||
} ) => ( | ||
<BlockFormatControls> | ||
<Toolbar | ||
controls={ [ | ||
onTagNameChange && { | ||
icon: 'editor-ul', | ||
title: __( 'Convert to unordered list' ), | ||
isActive: __unstableIsActiveListType( 'ul', tagName, value ), | ||
onClick() { | ||
onChange( changeListType( value, { type: 'ul' } ) ); | ||
|
||
if ( __unstableIsListRootSelected( value ) ) { | ||
onTagNameChange( 'ul' ); | ||
} | ||
}, | ||
}, | ||
onTagNameChange && { | ||
icon: 'editor-ol', | ||
title: __( 'Convert to ordered list' ), | ||
isActive: __unstableIsActiveListType( 'ol', tagName, value ), | ||
onClick() { | ||
onChange( changeListType( value, { type: 'ol' } ) ); | ||
|
||
if ( __unstableIsListRootSelected( value ) ) { | ||
onTagNameChange( 'ol' ); | ||
} | ||
}, | ||
}, | ||
].filter( Boolean ) } | ||
/> | ||
</BlockFormatControls> | ||
); |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
|
||
import { getLineIndex } from './get-line-index'; | ||
|
||
/** | ||
* Returns the list format of the line at the selection start position. | ||
* | ||
* @param {Object} value The rich-text value | ||
* | ||
* @return {Array} Array of the list formats on the selected line. | ||
*/ | ||
export function getLineListFormats( value ) { | ||
const { replacements, start } = value; | ||
const startingLineIndex = getLineIndex( value, start ); | ||
const startLineFormats = replacements[ startingLineIndex ] || []; | ||
return startLineFormats; | ||
} |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
|
||
import { getLineListFormats } from './get-line-list-formats'; | ||
|
||
/** | ||
* Wether or not the selected list has the given tag name. | ||
* | ||
* @param {string} tagName The tag name the list should have. | ||
* @param {string} rootTagName The current root tag name, to compare with in | ||
* case nothing is selected. | ||
* @param {Object} value The internal rich-text value. | ||
* | ||
* @return {boolean} [description] | ||
*/ | ||
export function isActiveListType( tagName, rootTagName, value ) { | ||
const startLineFormats = getLineListFormats( value ); | ||
const [ deepestListFormat ] = startLineFormats.slice( -1 ); | ||
|
||
if ( ! deepestListFormat || ! deepestListFormat.type ) { | ||
return tagName === rootTagName; | ||
} | ||
|
||
return deepestListFormat.type.toLowerCase() === tagName; | ||
} |
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.
In the web implementation
context.setFocusedElement
is used instead to mark whichRichText
component is active:https://github.com/WordPress/gutenberg/blob/master/packages/block-editor/src/components/rich-text/index.js#L1179-L1200
https://github.com/WordPress/gutenberg/blob/master/packages/block-editor/src/components/rich-text/index.js#L173-L177
https://github.com/WordPress/gutenberg/blob/master/packages/block-editor/src/components/rich-text/index.js#L1100-L1103
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 saw that but it looks we don't use the same logic on the native part on our block manager.
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 is going your solution work with multiple
RichText
controls included in a single block?