@atlaskit/editor-plugin-block-menu
Version:
BlockMenu plugin for @atlaskit/editor-core
54 lines • 1.91 kB
JavaScript
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
import { isListWithIndentation } from '../nodeChecks';
/**
* Transforms a bulletList, orderedList, or taskList into a decisionList.
*
* Notes
* - decisionLists and taskList only support text as children - need to ensure content is converted to text
*
* @example
* Input (nested bulletList):
* - bulletList
* - listItem "1.1"
* - listItem "1.2"
* - listItem "1.3"
*
* Output (flat decisionList):
* - decisionList
* - decisionItem "1"
* - decisionItem "1.1"
* - decisionItem "2"
*
* @param nodes - Array of nodes to transform
* @param context - Transform context with schema and target node type
* @returns array of transformed nodes
*/
export var listToDecisionListStep = function listToDecisionListStep(nodes, context) {
var schema = context.schema;
var paragraphType = schema.nodes.paragraph;
var unsupportedContent = [];
var transformedNodes = nodes.map(function (node) {
if (!isListWithIndentation(node.type.name, schema)) {
return node;
}
var decisionItems = [];
node.forEach(function (item) {
var itemContent = [];
item.forEach(function (child) {
if (child.type === paragraphType) {
// paragraph may contain hard breaks etc.
itemContent.push.apply(itemContent, _toConsumableArray(child.children));
} else if (child.isInline) {
itemContent.push(child);
} else if (!isListWithIndentation(child.type.name, schema)) {
unsupportedContent.push(child);
}
});
var decisionItem = schema.nodes.decisionItem.create({}, itemContent);
decisionItems.push(decisionItem);
});
var decisionList = schema.nodes.decisionList.create({}, decisionItems);
return decisionList || node;
});
return [].concat(_toConsumableArray(transformedNodes), unsupportedContent);
};