Skip to content

Commit

Permalink
Split into separate functions and mark unstable
Browse files Browse the repository at this point in the history
  • Loading branch information
hypest committed Apr 5, 2019
1 parent 66e971d commit da0e1a7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { Toolbar } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import {
changeListType,
getLineListFormat,
__unstableGetLineNestingLevel,
__unstableGetLineListFormat,
} from '@wordpress/rich-text';

/**
Expand All @@ -22,7 +23,7 @@ import BlockFormatControls from '../block-format-controls';
* inner list is selected.
*/
function isListRootSelected( value ) {
return getLineListFormat( value ).nestingLevel < 1;
return __unstableGetLineNestingLevel( value ) < 1;
}

/**
Expand All @@ -35,7 +36,7 @@ function isListRootSelected( value ) {
* @return {boolean} [description]
*/
function isActiveListType( tagName, rootTagName, value ) {

This comment has been minimized.

Copy link
@ellatrix

ellatrix Apr 5, 2019

Member

Hm, I'm still not sure why not move isActiveListType and isListRootSelected to rich-text?

This comment has been minimized.

Copy link
@hypest

hypest Apr 5, 2019

Author Contributor

No reason actually other than do that as part of the follow up PR to use this new functionality on the web side too.

This comment has been minimized.

Copy link
@ellatrix

ellatrix Apr 5, 2019

Member

Why put anything in rich-text then at all? Let's remove it then. :) not sure why to half-move it

This comment has been minimized.

Copy link
@hypest

hypest Apr 5, 2019

Author Contributor

Pushed 4451cb3 that include the moving of the isActiveListType and isListRootSelected into the rich-text package, and marking then as unsafe. Let me know what you think @ellatrix , thanks!

const listFormat = getLineListFormat( value );
const listFormat = __unstableGetLineListFormat( value );

if ( ! listFormat || ! listFormat.type ) {
return tagName === rootTagName;
Expand Down
8 changes: 4 additions & 4 deletions packages/rich-text/src/get-line-list-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
import { getLineIndex } from './get-line-index';

/**
* Returns the nesting level of the list at the selection start position.
* Returns the list format of the line at the selection start position.
*
* @param {Object} value The rich-text value
*
* @return {Object} Object with { nestingLevel, listFormat }.
* @return {Object} Object with listFormat.
*/
export function getLineListFormat( value ) {
const { text, replacements, start, end } = value;
const { replacements, start } = value;
const startingLineIndex = getLineIndex( value, start );
const startLineFormats = replacements[ startingLineIndex ] || [];
const [ listFormat ] = startLineFormats.slice( -1 );
return { nestingLevel: startLineFormats.length, ...listFormat };
return listFormat;
}
19 changes: 19 additions & 0 deletions packages/rich-text/src/get-line-nesting-level.js
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 list nesting level, starting from 0.
*/
export function getLineNestingLevel( value ) {
const { replacements, start } = value;
const startingLineIndex = getLineIndex( value, start );
const startLineFormats = replacements[ startingLineIndex ] || [];
return startLineFormats.length;
}
3 changes: 2 additions & 1 deletion packages/rich-text/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export { getActiveObject } from './get-active-object';
export { getSelectionEnd } from './get-selection-end';
export { getSelectionStart } from './get-selection-start';
export { getTextContent } from './get-text-content';
export { getLineListFormat } from './get-line-list-format';
export { getLineNestingLevel as __unstableGetLineNestingLevel } from './get-line-nesting-level';
export { getLineListFormat as __unstableGetLineListFormat } from './get-line-list-format';
export { isCollapsed } from './is-collapsed';
export { isEmpty, isEmptyLine } from './is-empty';
export { join } from './join';
Expand Down

0 comments on commit da0e1a7

Please sign in to comment.