UNPKG

@20minutes/draft-convert

Version:

Extensibly serialize & deserialize Draft.js ContentState

19 lines (18 loc) 731 B
import React from 'react'; import splitReactElement from './splitReactElement.mjs'; const getElementTagLength = (element, type = 'start')=>{ if (/*#__PURE__*/ React.isValidElement(element)) { const splitElement = splitReactElement(element); if (typeof splitElement === 'string') { return 0; } const { length } = splitElement[type]; const child = React.Children.toArray(element.props.children)[0]; return length + (child && /*#__PURE__*/ React.isValidElement(child) ? getElementTagLength(child, type) : 0); } if (typeof element === 'object') { return element[type] ? element[type].length : 0; } return 0; }; export default getElementTagLength;