-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement list block in React Native (#14636)
* Make sure multiline property is filtered out of props on save. * Send block edit parameters using the context. * Add multiline variables to allow proper parsing and saving of properties. * Add list edit toolbar options * Add multiline property. * Add list block to mobile gb. * Move list-edit.native.js to new location. * Make block edit send down the onFocus property. * Handle case where unstableSplit is passed has prop. * Pass multiline tags to serialiser. * Use the format-lib for handling "Enter" in lists * Force selection reset on split * Add multiline wrapper tags to formatToValue. * Remove unnecessary code. * Force rich-text text update on list type change * Disable indent and outdent. * Enable toggling list type of nested lists * Update list type toolbar button on native mobile * Include diff missed by previous commit * Rename to denote that it's about lines * Split into separate functions and mark unstable * Add missing JSDoc param * Update snapshot for BlockControls * Move isActiveListType, isListRootSelected to rich-text package * Remove excess empty line
- Loading branch information
1 parent
37bc735
commit 45da3cf
Showing
9 changed files
with
230 additions
and
18 deletions.
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.