mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-24 16:02:55 +02:00
Fix forced layout example (#3294)
This commit is contained in:
committed by
Ian Storm Taylor
parent
26b67578d4
commit
28c31c2c0c
@@ -1,12 +1,12 @@
|
|||||||
import React, { useState, useCallback, useMemo } from 'react'
|
import React, { useState, useCallback, useMemo } from 'react'
|
||||||
import { Slate, Editable, withReact } from 'slate-react'
|
import { Slate, Editable, withReact } from 'slate-react'
|
||||||
import { Editor, createEditor } from 'slate'
|
import { Editor, createEditor, Node } from 'slate'
|
||||||
import { withHistory } from 'slate-history'
|
import { withHistory } from 'slate-history'
|
||||||
|
|
||||||
const withLayout = editor => {
|
const withLayout = editor => {
|
||||||
const { normalizeNode } = editor
|
const { normalizeNode } = editor
|
||||||
|
|
||||||
editor.normalizeNode = path => {
|
editor.normalizeNode = ([node, path]) => {
|
||||||
if (path.length === 0) {
|
if (path.length === 0) {
|
||||||
if (editor.children.length < 1) {
|
if (editor.children.length < 1) {
|
||||||
const title = { type: 'title', children: [{ text: 'Untitled' }] }
|
const title = { type: 'title', children: [{ text: 'Untitled' }] }
|
||||||
@@ -27,7 +27,7 @@ const withLayout = editor => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return normalizeNode(path)
|
return normalizeNode([node, path])
|
||||||
}
|
}
|
||||||
|
|
||||||
return editor
|
return editor
|
||||||
|
Reference in New Issue
Block a user