MCPcopy Create free account
hub / github.com/churichard/notabase / withLayoutNormalization

Function withLayoutNormalization

editor/plugins/withNormalization.ts:13–36  ·  view source on GitHub ↗
(editor: Editor)

Source from the content-addressed store, hash-verified

11};
12
13const 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
38const withInlineNormalization = (editor: Editor) => {
39 const { normalizeNode } = editor;

Callers 1

withNormalizationFunction · 0.85

Calls 1

createNodeIdFunction · 0.90

Tested by

no test coverage detected