(state: EditorState)
| 17 | } |
| 18 | |
| 19 | function wrapInContainer(state: EditorState) { |
| 20 | const { doc } = state; |
| 21 | const containerType = state.schema.nodes.container; |
| 22 | |
| 23 | const contentNodes: PmNode[] = []; |
| 24 | const globalContentNodes: PmNode[] = []; |
| 25 | |
| 26 | doc.forEach((node) => { |
| 27 | if (node.type.name === 'globalContent') { |
| 28 | globalContentNodes.push(node); |
| 29 | } else { |
| 30 | contentNodes.push(node); |
| 31 | } |
| 32 | }); |
| 33 | |
| 34 | const containerContent = |
| 35 | contentNodes.length > 0 |
| 36 | ? contentNodes |
| 37 | : [state.schema.nodes.paragraph.create()]; |
| 38 | |
| 39 | const containerNode = containerType.create(null, containerContent); |
| 40 | |
| 41 | const newDocContent = [...globalContentNodes, containerNode]; |
| 42 | |
| 43 | const tr = state.tr; |
| 44 | tr.replaceWith(0, doc.content.size, newDocContent); |
| 45 | tr.setMeta('addToHistory', false); |
| 46 | |
| 47 | return tr; |
| 48 | } |
| 49 | |
| 50 | export interface ContainerOptions { |
| 51 | HTMLAttributes: Record<string, unknown>; |
no test coverage detected