(editor: Editor)
| 11 | }; |
| 12 | |
| 13 | const withLayoutNormalization = (editor: Editor) => { |
| 14 | const { normalizeNode } = editor; |
| 15 | |
| 16 | editor.normalizeNode = (entry) => { |
| 17 | const [, path] = entry; |
| 18 | |
| 19 | // Make sure there is at least a paragraph in the editor |
| 20 | if (path.length === 0) { |
| 21 | if (editor.children.length < 1) { |
| 22 | const paragraph: ParagraphElement = { |
| 23 | id: createNodeId(), |
| 24 | type: ElementType.Paragraph, |
| 25 | children: [{ text: '' }], |
| 26 | }; |
| 27 | Transforms.insertNodes(editor, paragraph, { at: path.concat(0) }); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | // Fall back to the original `normalizeNode` to enforce other constraints. |
| 32 | normalizeNode(entry); |
| 33 | }; |
| 34 | |
| 35 | return editor; |
| 36 | }; |
| 37 | |
| 38 | const withInlineNormalization = (editor: Editor) => { |
| 39 | const { normalizeNode } = editor; |
no test coverage detected