@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
41 lines (40 loc) • 1.45 kB
JavaScript
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
// List type utilities
export var isBulletOrOrderedList = function isBulletOrOrderedList(nodeType) {
return nodeType.name === 'bulletList' || nodeType.name === 'orderedList';
};
export var isTaskList = function isTaskList(nodeType) {
return nodeType.name === 'taskList';
};
export var getSupportedListTypes = function getSupportedListTypes(nodes) {
return [nodes.bulletList, nodes.orderedList, nodes.taskList].filter(Boolean);
};
export var getSupportedListTypesSet = function getSupportedListTypesSet(nodes) {
return new Set(getSupportedListTypes(nodes));
};
/**
* Convert a block node to inline content suitable for task items
*/
export var convertBlockToInlineContent = function convertBlockToInlineContent(node, schema) {
var _schema$nodes = schema.nodes,
paragraph = _schema$nodes.paragraph,
hardBreak = _schema$nodes.hardBreak;
if (node.type === paragraph) {
return _toConsumableArray(node.content.content);
}
if (node.isBlock) {
var textContent = node.textContent;
var lines = textContent.split('\n');
var newText = [];
lines.forEach(function (line, index) {
if (line !== '') {
newText.push(line ? schema.text(line) : schema.text(' '));
}
if (lines.length > 1 && index !== lines.length - 1) {
newText.push(hardBreak.create());
}
});
return newText;
}
return [node];
};