-
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
Changes from 22 commits
bd83d8f
8ed9cc0
e0d7cf6
eb33f84
c64dd5a
f0a1e21
73aaa4f
b6938aa
74f77cf
79f408c
1f12a9f
cc8a4e8
ca338c2
076936f
6ff97b8
73fbd38
e07498e
f40852c
7fb36f6
9145a6d
58eae26
08318ca
9dcd23b
fd62f01
66e971d
da0e1a7
eb009e8
cc5666e
91f790c
4451cb3
97ac0fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
|
||
import { Toolbar } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
changeListType, | ||
getStartNestingLevel, | ||
} from '@wordpress/rich-text'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
|
||
import BlockFormatControls from '../block-format-controls'; | ||
|
||
/** | ||
* Whether or not the root list is selected. | ||
* | ||
* @return {boolean} True if the root list or nothing is selected, false if an | ||
* inner list is selected. | ||
*/ | ||
function isListRootSelected( value ) { | ||
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. Why not replace 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. 👋 @ellatrix , not sure I follow. Do you mean to completely remove getStartListFormat and implement its pieces inside 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. Yes, export 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. Done with 4451cb3. |
||
return getStartNestingLevel( value ) < 1; | ||
} | ||
|
||
/** | ||
* 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. | ||
* | ||
* @return {boolean} [description] | ||
*/ | ||
function isActiveListType( tagName, rootTagName ) { | ||
return tagName === rootTagName; | ||
} | ||
|
||
export const ListEdit = ( { | ||
onTagNameChange, | ||
tagName, | ||
value, | ||
onChange, | ||
} ) => ( | ||
<BlockFormatControls> | ||
<Toolbar | ||
controls={ [ | ||
onTagNameChange && { | ||
icon: 'editor-ul', | ||
title: __( 'Convert to unordered list' ), | ||
isActive: isActiveListType( 'ul', tagName ), | ||
onClick() { | ||
onChange( changeListType( value, { type: 'ul' } ) ); | ||
|
||
if ( isListRootSelected( value ) ) { | ||
onTagNameChange( 'ul' ); | ||
} | ||
}, | ||
}, | ||
onTagNameChange && { | ||
icon: 'editor-ol', | ||
title: __( 'Convert to ordered list' ), | ||
isActive: isActiveListType( 'ol', tagName ), | ||
onClick() { | ||
onChange( changeListType( value, { type: 'ol' } ) ); | ||
|
||
if ( isListRootSelected( value ) ) { | ||
onTagNameChange( 'ol' ); | ||
} | ||
}, | ||
}, | ||
].filter( Boolean ) } | ||
/> | ||
</BlockFormatControls> | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
|
||
import { getLineIndex } from './get-line-index'; | ||
|
||
/** | ||
* Returns the nesting level of the list at the selection start position. | ||
* | ||
* @param {Object} value The rich-text value | ||
* | ||
* @return {number} The nesting level, starting from 0. | ||
*/ | ||
export function getStartNestingLevel( value ) { | ||
hypest marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const { text, replacements, start, end } = value; | ||
const startingLineIndex = getLineIndex( value, start ); | ||
const startLineFormats = replacements[ startingLineIndex ] || []; | ||
return startLineFormats.length; | ||
} |
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?