mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-09 08:46:35 +02:00
Layout example fix (#4463)
* Update forced-layout example Enforce layout to an explicit block index to allow for other block types * Update site/examples/forced-layout.tsx * fix layout example to comply with linting rules Co-authored-by: Lukas Murdock <lukas.murdock@gmail.com>
This commit is contained in:
@@ -32,13 +32,27 @@ const withLayout = editor => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const [child, childPath] of Node.children(editor, path)) {
|
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) {
|
if (SlateElement.isElement(child) && child.type !== type) {
|
||||||
const newProperties: Partial<SlateElement> = { type }
|
const newProperties: Partial<SlateElement> = { type }
|
||||||
Transforms.setNodes(editor, newProperties, { at: childPath })
|
Transforms.setNodes(editor, newProperties, { at: childPath })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (slateIndex) {
|
||||||
|
case 0:
|
||||||
|
type = 'title'
|
||||||
|
enforceType(type)
|
||||||
|
break
|
||||||
|
case 1:
|
||||||
|
type = 'paragraph'
|
||||||
|
enforceType(type)
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return normalizeNode([node, path])
|
return normalizeNode([node, path])
|
||||||
|
Reference in New Issue
Block a user