diff --git a/site/examples/forced-layout.tsx b/site/examples/forced-layout.tsx index 7d2c5f6a4..6ca6c1122 100644 --- a/site/examples/forced-layout.tsx +++ b/site/examples/forced-layout.tsx @@ -32,11 +32,25 @@ const withLayout = editor => { } for (const [child, childPath] of Node.children(editor, path)) { - const type = childPath[0] === 0 ? 'title' : 'paragraph' + let type: string + const slateIndex = childPath[0] + const enforceType = type => { + if (SlateElement.isElement(child) && child.type !== type) { + const newProperties: Partial = { type } + Transforms.setNodes(editor, newProperties, { at: childPath }) + } + } - if (SlateElement.isElement(child) && child.type !== type) { - const newProperties: Partial = { type } - Transforms.setNodes(editor, newProperties, { at: childPath }) + switch (slateIndex) { + case 0: + type = 'title' + enforceType(type) + break + case 1: + type = 'paragraph' + enforceType(type) + default: + break } } }