-
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.
Move isActiveListType, isListRootSelected to rich-text package
- Loading branch information
Showing
6 changed files
with
56 additions
and
63 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 was deleted.
Oops, something went wrong.
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,27 @@ | ||
/** | ||
* 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; | ||
} | ||
|
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,18 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
|
||
import { getLineListFormats } from './get-line-list-formats'; | ||
|
||
/** | ||
* Whether or not the root list is selected. | ||
* | ||
* @param {Object} value The internal rich-text value. | ||
* | ||
* @return {boolean} True if the root list or nothing is selected, false if an | ||
* inner list is selected. | ||
*/ | ||
export function isListRootSelected( value ) { | ||
const startLineFormats = getLineListFormats( value ); | ||
return startLineFormats.length < 1; | ||
} |