UNPKG

@atlaskit/editor-plugin-block-menu

Version:

BlockMenu plugin for @atlaskit/editor-core

59 lines (56 loc) 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.unwrapExpandStep = void 0; var _utils = require("../utils"); var _unwrapStep = require("./unwrapStep"); /** * Unwraps an expand/nestedExpand node, converting its title attribute to a paragraph * and prepending it to the children. * * Any nestedExpand children are converted to regular expands since nestedExpand * can only exist inside an expand. * * Example: expand({ title: 'title' })(p('b')) → [p('title'), p('b')] * Example: expand({ title: 'outer' })(nestedExpand({ title: 'inner' })(p('x'))) * → [p('outer'), expand({ title: 'inner' })(p('x'))] */ var unwrapExpandStep = exports.unwrapExpandStep = function unwrapExpandStep(nodes, context) { var schema = context.schema; var outputNodes = []; var _schema$nodes = schema.nodes, expand = _schema$nodes.expand, nestedExpand = _schema$nodes.nestedExpand; nodes.forEach(function (node) { var isExpand = node.type.name === expand.name || node.type.name === nestedExpand.name; if (isExpand) { var _node$attrs; var title = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.title; // Create a paragraph from the title if it exists if (title) { var titleParagraph = schema.nodes.paragraph.createAndFill({}, schema.text(title)); if (titleParagraph) { outputNodes.push(titleParagraph); } } // Add the children, converting any nestedExpands to regular expands // since nestedExpand can only exist inside an expand node.children.forEach(function (child) { if (child.type.name === nestedExpand.name) { var expandNode = (0, _utils.convertNestedExpandToExpand)(child, schema); if (expandNode) { outputNodes.push(expandNode); } else { outputNodes.push(child); } } else { outputNodes.push(child); } }); } else { (0, _unwrapStep.unwrapStep)([node], context); } }); return outputNodes; };