mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-04-20 05:11:53 +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:
parent
95c759a19c
commit
3e7ff3bb0d
@ -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<SlateElement> = { type }
|
||||
Transforms.setNodes(editor, newProperties, { at: childPath })
|
||||
}
|
||||
}
|
||||
|
||||
if (SlateElement.isElement(child) && child.type !== type) {
|
||||
const newProperties: Partial<SlateElement> = { type }
|
||||
Transforms.setNodes(editor, newProperties, { at: childPath })
|
||||
switch (slateIndex) {
|
||||
case 0:
|
||||
type = 'title'
|
||||
enforceType(type)
|
||||
break
|
||||
case 1:
|
||||
type = 'paragraph'
|
||||
enforceType(type)
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user