UNPKG

@atlaskit/editor-plugin-block-menu

Version:

BlockMenu plugin for @atlaskit/editor-core

47 lines (45 loc) 1.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.wrapIntoListStep = void 0; var _nodeChecks = require("../nodeChecks"); var _utils = require("../utils"); var wrapIntoTaskOrDecisionList = function wrapIntoTaskOrDecisionList(nodes, targetNodeTypeName, schema) { var itemNodeType = targetNodeTypeName === 'taskList' ? schema.nodes.taskItem : schema.nodes.decisionItem; var inlineContent = nodes.flatMap(function (node) { if (node.isTextblock) { return node.children; } else if (node.isText) { return [node]; } return []; }); var itemNode = itemNodeType.create({}, inlineContent); var outputNode = schema.nodes[targetNodeTypeName].createAndFill({}, itemNode); return outputNode ? [outputNode] : nodes; }; var wrapIntoBulletOrOrderedList = function wrapIntoBulletOrOrderedList(nodes, targetNodeTypeName, schema) { var listItemNodes = nodes.map(function (node) { return schema.nodes.listItem.createAndFill({}, node.isTextblock ? (0, _utils.convertTextNodeToParagraph)(node, schema) : node); }).filter(function (node) { return node !== null; }); if (listItemNodes.length === 0) { return nodes; } var outputNode = schema.nodes[targetNodeTypeName].createAndFill({}, listItemNodes); return outputNode ? [outputNode] : nodes; }; /** * Wraps nodes into bullet list, numbered list, task list, or decision list. * * @param nodes - The nodes to wrap. * @param context - The transformation context containing schema and target node type. * @returns The wrapped nodes. */ var wrapIntoListStep = exports.wrapIntoListStep = function wrapIntoListStep(nodes, context) { var schema = context.schema, targetNodeTypeName = context.targetNodeTypeName; return (0, _nodeChecks.isListWithTextContentOnly)(targetNodeTypeName, schema) ? wrapIntoTaskOrDecisionList(nodes, targetNodeTypeName, schema) : wrapIntoBulletOrOrderedList(nodes, targetNodeTypeName, schema); };