UNPKG

@atlaskit/editor-plugin-block-menu

Version:

BlockMenu plugin for @atlaskit/editor-core

51 lines (50 loc) 1.72 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.unwrapListStep = void 0; var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); /** * Given an array of nodes, processes each list removing all parent list nodes and * just returning their child contents. * * For lists with block content (bulletList, orderedList), it extracts the block nodes directly. * For lists with inline content (taskList, decisionList), it wraps the content in paragraphs. * * @example * Input: * - bulletList * - listItem "1" * - paragraph "1" * - listItem "2" * - paragraph "2" * * Output: * - paragraph "1" * - paragraph "2" * * @param nodes * @param context * @returns */ var unwrapListStep = exports.unwrapListStep = function unwrapListStep(nodes, context) { var listTypes = [context.schema.nodes.bulletList, context.schema.nodes.orderedList, context.schema.nodes.taskList, context.schema.nodes.decisionList]; return nodes.flatMap(function (node) { if (listTypes.some(function (type) { return node.type === type; })) { var listItems = []; node.forEach(function (listItem) { // if isTaskItem or isDecisionItem, convert to paragraph if (listItem.type.name === 'taskItem' || listItem.type.name === 'decisionItem') { listItems.push(context.schema.nodes.paragraph.create({}, listItem.content)); } else { listItems.push.apply(listItems, (0, _toConsumableArray2.default)(listItem.children)); } }); return listItems; } return node; }); };