UNPKG

@atlaskit/editor-plugin-block-menu

Version:

BlockMenu plugin for @atlaskit/editor-core

61 lines (60 loc) 2.22 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.listToDecisionListStep = void 0; var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); var _nodeChecks = require("../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 */ var listToDecisionListStep = exports.listToDecisionListStep = function listToDecisionListStep(nodes, context) { var schema = context.schema; var paragraphType = schema.nodes.paragraph; var unsupportedContent = []; var transformedNodes = nodes.map(function (node) { if (!(0, _nodeChecks.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, (0, _toConsumableArray2.default)(child.children)); } else if (child.isInline) { itemContent.push(child); } else if (!(0, _nodeChecks.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((0, _toConsumableArray2.default)(transformedNodes), unsupportedContent); };