UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

126 lines 3.41 kB
import ApplicationCard from './applicationCard'; import Blockquote from './blockquote'; import BulletList from './bulletList'; import CodeBlock from './codeBlock'; import DecisionItem from './decisionItem'; import DecisionList from './decisionList'; import Doc from './doc'; import Emoji from './emoji'; import HardBreak from './hardBreak'; import Heading from './heading'; import ListItem from './listItem'; import Media from './media'; import MediaGroup from './mediaGroup'; import Mention from './mention'; import OrderedList from './orderedList'; import Panel from './panel'; import Paragraph from './paragraph'; import Rule from './rule'; import TaskItem from './taskItem'; import TaskList from './taskList'; import Table from './table'; import TableCell from './tableCell'; import TableHeader from './tableHeader'; import TableRow from './tableRow'; import UnknownBlock from './unknownBlock'; export var nodeToReact = { 'applicationCard': ApplicationCard, 'blockquote': Blockquote, 'bulletList': BulletList, 'codeBlock': CodeBlock, 'decisionItem': DecisionItem, 'decisionList': DecisionList, 'doc': Doc, 'emoji': Emoji, 'hardBreak': HardBreak, 'heading': Heading, 'listItem': ListItem, 'media': Media, 'mediaGroup': MediaGroup, 'mention': Mention, 'orderedList': OrderedList, 'panel': Panel, 'paragraph': Paragraph, 'rule': Rule, 'taskItem': TaskItem, 'taskList': TaskList, 'table': Table, 'tableCell': TableCell, 'tableHeader': TableHeader, 'tableRow': TableRow, 'unknownBlock': UnknownBlock, }; export var toReact = function (node) { return nodeToReact[node.type.name]; }; /* * Wraps adjecent textnodes in a textWrapper * * Input: * [ * { * type: 'text', * text: 'Hello' * }, * { * type: 'text', * text: 'World!', * marks: [ * { * type: 'strong' * } * ] * } * ] * * Output: * [ * { * type: 'textWrapper', * content: [ * { * type: 'text', * text: 'Hello' * }, * { * type: 'text', * text: 'World!', * marks: [ * { * type: 'strong' * } * ] * } * ] * } * ] */ export var mergeTextNodes = function (nodes) { return nodes.reduce(function (acc, current) { if (!isText(current.type.name)) { acc.push(current); return acc; } // Append node to previous node, if it was a text wrapper if (acc.length > 0 && isTextWrapper(acc[acc.length - 1].type.name)) { acc[acc.length - 1].content.push(current); } else { acc.push({ type: { name: 'textWrapper', }, content: [current] }); } return acc; }, []); }; export var isText = function (type) { return type === 'text'; }; export var isTextWrapper = function (type) { return type === 'textWrapper'; }; export { ApplicationCard, Blockquote, BulletList, CodeBlock, DecisionItem, DecisionList, Doc, Emoji, HardBreak, Heading, ListItem, Media, MediaGroup, Mention, OrderedList, Panel, Paragraph, Rule, TaskItem, TaskList, Table, TableCell, TableHeader, TableRow, UnknownBlock, }; //# sourceMappingURL=index.js.map