@atlaskit/editor-plugin-block-controls
Version:
Block controls plugin for @atlaskit/editor-core
20 lines (19 loc) • 646 B
JavaScript
/**
* Check if the fragment has only one node of the specified type
*/
export const isFragmentOfType = (fragment, type) => {
var _fragment$firstChild;
return fragment.childCount === 1 && ((_fragment$firstChild = fragment.firstChild) === null || _fragment$firstChild === void 0 ? void 0 : _fragment$firstChild.type.name) === type;
};
/**
* Check if the fragment contains at least a node of the specified type
*/
export const containsNodeOfType = (fragment, type) => {
for (let i = 0; i < fragment.childCount; i++) {
const child = fragment.child(i);
if (child.type.name === type) {
return true;
}
}
return false;
};