mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-29 01:50:06 +02:00
Rename <Slate>
component value
prop to initialValue
(#5421)
* Rename `slate-react` Slate component `value` prop to `initialValue` Fixes #4992 * Update documentation: `value` -> `initialValue` * Add a changeset record * Make props order consistent
This commit is contained in:
5
.changeset/tiny-suns-lick.md
Normal file
5
.changeset/tiny-suns-lick.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate-react': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Rename `<Slate>` component prop from `value` to `initialValue` to emphasize uncontrolled nature of it
|
@@ -53,7 +53,7 @@ const App = () => {
|
|||||||
const [editor] = useState(() => withReact(createEditor()))
|
const [editor] = useState(() => withReact(createEditor()))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable />
|
<Editable />
|
||||||
</Slate>
|
</Slate>
|
||||||
)
|
)
|
||||||
|
@@ -309,7 +309,7 @@ const [value, setValue] = useState(initialValue)
|
|||||||
const [selection, setSelection] = useState(null)
|
const [selection, setSelection] = useState(null)
|
||||||
|
|
||||||
<Slate
|
<Slate
|
||||||
value={value}
|
initialValue={initialValue}
|
||||||
selection={selection}
|
selection={selection}
|
||||||
onChange={(value, selection) => {
|
onChange={(value, selection) => {
|
||||||
setValue(value)
|
setValue(value)
|
||||||
|
@@ -81,7 +81,7 @@ const initialValue = [
|
|||||||
const App = () => {
|
const App = () => {
|
||||||
const [editor] = useState(() => withReact(createEditor()))
|
const [editor] = useState(() => withReact(createEditor()))
|
||||||
// Render the Slate context.
|
// Render the Slate context.
|
||||||
return <Slate editor={editor} value={initialValue} />
|
return <Slate editor={editor} initialValue={initialValue} />
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ const App = () => {
|
|||||||
const [editor] = useState(() => withReact(createEditor()))
|
const [editor] = useState(() => withReact(createEditor()))
|
||||||
return (
|
return (
|
||||||
// Add the editable component inside the context.
|
// Add the editable component inside the context.
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable />
|
<Editable />
|
||||||
</Slate>
|
</Slate>
|
||||||
)
|
)
|
||||||
|
@@ -20,7 +20,7 @@ const App = () => {
|
|||||||
const [editor] = useState(() => withReact(createEditor()))
|
const [editor] = useState(() => withReact(createEditor()))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable />
|
<Editable />
|
||||||
</Slate>
|
</Slate>
|
||||||
)
|
)
|
||||||
@@ -41,7 +41,7 @@ const App = () => {
|
|||||||
const [editor] = useState(() => withReact(createEditor()))
|
const [editor] = useState(() => withReact(createEditor()))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable
|
<Editable
|
||||||
// Define a new handler which prints the key that was pressed.
|
// Define a new handler which prints the key that was pressed.
|
||||||
onKeyDown={event => {
|
onKeyDown={event => {
|
||||||
@@ -71,7 +71,7 @@ const App = () => {
|
|||||||
const [editor] = useState(() => withReact(createEditor()))
|
const [editor] = useState(() => withReact(createEditor()))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable
|
<Editable
|
||||||
onKeyDown={event => {
|
onKeyDown={event => {
|
||||||
if (event.key === '&') {
|
if (event.key === '&') {
|
||||||
|
@@ -18,7 +18,7 @@ const App = () => {
|
|||||||
const [editor] = useState(() => withReact(createEditor()))
|
const [editor] = useState(() => withReact(createEditor()))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable
|
<Editable
|
||||||
onKeyDown={event => {
|
onKeyDown={event => {
|
||||||
if (event.key === '&') {
|
if (event.key === '&') {
|
||||||
@@ -88,7 +88,7 @@ const App = () => {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable
|
<Editable
|
||||||
// Pass in the `renderElement` function.
|
// Pass in the `renderElement` function.
|
||||||
renderElement={renderElement}
|
renderElement={renderElement}
|
||||||
@@ -142,7 +142,7 @@ const App = () => {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable
|
<Editable
|
||||||
renderElement={renderElement}
|
renderElement={renderElement}
|
||||||
onKeyDown={event => {
|
onKeyDown={event => {
|
||||||
@@ -200,7 +200,7 @@ const App = () => {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable
|
<Editable
|
||||||
renderElement={renderElement}
|
renderElement={renderElement}
|
||||||
onKeyDown={event => {
|
onKeyDown={event => {
|
||||||
|
@@ -27,7 +27,7 @@ const App = () => {
|
|||||||
const [editor] = useState(() => withReact(createEditor()))
|
const [editor] = useState(() => withReact(createEditor()))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable
|
<Editable
|
||||||
renderElement={renderElement}
|
renderElement={renderElement}
|
||||||
onKeyDown={event => {
|
onKeyDown={event => {
|
||||||
@@ -72,7 +72,7 @@ const App = () => {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable
|
<Editable
|
||||||
renderElement={renderElement}
|
renderElement={renderElement}
|
||||||
onKeyDown={event => {
|
onKeyDown={event => {
|
||||||
@@ -163,7 +163,7 @@ const App = () => {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable
|
<Editable
|
||||||
renderElement={renderElement}
|
renderElement={renderElement}
|
||||||
// Pass in the `renderLeaf` function.
|
// Pass in the `renderLeaf` function.
|
||||||
|
@@ -35,7 +35,7 @@ const App = () => {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable
|
<Editable
|
||||||
renderElement={renderElement}
|
renderElement={renderElement}
|
||||||
renderLeaf={renderLeaf}
|
renderLeaf={renderLeaf}
|
||||||
@@ -142,7 +142,7 @@ const App = () => {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable
|
<Editable
|
||||||
renderElement={renderElement}
|
renderElement={renderElement}
|
||||||
renderLeaf={renderLeaf}
|
renderLeaf={renderLeaf}
|
||||||
@@ -200,7 +200,7 @@ const App = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
// Add a toolbar with buttons that call the same methods.
|
// Add a toolbar with buttons that call the same methods.
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<div>
|
<div>
|
||||||
<button
|
<button
|
||||||
onMouseDown={event => {
|
onMouseDown={event => {
|
||||||
|
@@ -18,7 +18,7 @@ const App = () => {
|
|||||||
const [editor] = useState(() => withReact(createEditor()))
|
const [editor] = useState(() => withReact(createEditor()))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable />
|
<Editable />
|
||||||
</Slate>
|
</Slate>
|
||||||
)
|
)
|
||||||
@@ -45,7 +45,7 @@ const App = () => {
|
|||||||
return (
|
return (
|
||||||
<Slate
|
<Slate
|
||||||
editor={editor}
|
editor={editor}
|
||||||
value={initialValue}
|
initialValue={initialValue}
|
||||||
onChange={value => {
|
onChange={value => {
|
||||||
const isAstChange = editor.operations.some(
|
const isAstChange = editor.operations.some(
|
||||||
op => 'set_selection' !== op.type
|
op => 'set_selection' !== op.type
|
||||||
@@ -85,7 +85,7 @@ const App = () => {
|
|||||||
return (
|
return (
|
||||||
<Slate
|
<Slate
|
||||||
editor={editor}
|
editor={editor}
|
||||||
value={initialValue}
|
initialValue={initialValue}
|
||||||
onChange={value => {
|
onChange={value => {
|
||||||
const isAstChange = editor.operations.some(
|
const isAstChange = editor.operations.some(
|
||||||
op => 'set_selection' !== op.type
|
op => 'set_selection' !== op.type
|
||||||
@@ -145,7 +145,7 @@ const App = () => {
|
|||||||
return (
|
return (
|
||||||
<Slate
|
<Slate
|
||||||
editor={editor}
|
editor={editor}
|
||||||
value={initialValue}
|
initialValue={initialValue}
|
||||||
onChange={value => {
|
onChange={value => {
|
||||||
const isAstChange = editor.operations.some(
|
const isAstChange = editor.operations.some(
|
||||||
op => 'set_selection' !== op.type
|
op => 'set_selection' !== op.type
|
||||||
|
@@ -19,18 +19,18 @@ import { EDITOR_TO_ON_CHANGE } from '../utils/weak-maps'
|
|||||||
|
|
||||||
export const Slate = (props: {
|
export const Slate = (props: {
|
||||||
editor: ReactEditor
|
editor: ReactEditor
|
||||||
value: Descendant[]
|
initialValue: Descendant[]
|
||||||
children: React.ReactNode
|
children: React.ReactNode
|
||||||
onChange?: (value: Descendant[]) => void
|
onChange?: (value: Descendant[]) => void
|
||||||
}) => {
|
}) => {
|
||||||
const { editor, children, onChange, value, ...rest } = props
|
const { editor, children, onChange, initialValue, ...rest } = props
|
||||||
const unmountRef = useRef(false)
|
const unmountRef = useRef(false)
|
||||||
|
|
||||||
const [context, setContext] = React.useState<SlateContextValue>(() => {
|
const [context, setContext] = React.useState<SlateContextValue>(() => {
|
||||||
if (!Node.isNodeList(value)) {
|
if (!Node.isNodeList(initialValue)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`[Slate] value is invalid! Expected a list of elements but got: ${Scrubber.stringify(
|
`[Slate] initialValue is invalid! Expected a list of elements but got: ${Scrubber.stringify(
|
||||||
value
|
initialValue
|
||||||
)}`
|
)}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ export const Slate = (props: {
|
|||||||
`[Slate] editor is invalid! You passed: ${Scrubber.stringify(editor)}`
|
`[Slate] editor is invalid! You passed: ${Scrubber.stringify(editor)}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
editor.children = value
|
editor.children = initialValue
|
||||||
Object.assign(editor, rest)
|
Object.assign(editor, rest)
|
||||||
return { v: 0, editor }
|
return { v: 0, editor }
|
||||||
})
|
})
|
||||||
|
@@ -10,7 +10,9 @@ const createNodeMock = () => ({
|
|||||||
|
|
||||||
class MockResizeObserver {
|
class MockResizeObserver {
|
||||||
observe() {}
|
observe() {}
|
||||||
|
|
||||||
unobserve() {}
|
unobserve() {}
|
||||||
|
|
||||||
disconnect() {}
|
disconnect() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,14 +23,18 @@ describe('slate-react', () => {
|
|||||||
describe('NODE_TO_KEY logic', () => {
|
describe('NODE_TO_KEY logic', () => {
|
||||||
test('should not unmount the node that gets split on a split_node operation', async () => {
|
test('should not unmount the node that gets split on a split_node operation', async () => {
|
||||||
const editor = withReact(createEditor())
|
const editor = withReact(createEditor())
|
||||||
const value = [{ type: 'block', children: [{ text: 'test' }] }]
|
const initialValue = [{ type: 'block', children: [{ text: 'test' }] }]
|
||||||
const mounts = jest.fn()
|
const mounts = jest.fn()
|
||||||
|
|
||||||
let el: ReactTestRenderer
|
let el: ReactTestRenderer
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
el = create(
|
el = create(
|
||||||
<Slate editor={editor} value={value} onChange={() => {}}>
|
<Slate
|
||||||
|
editor={editor}
|
||||||
|
initialValue={initialValue}
|
||||||
|
onChange={() => {}}
|
||||||
|
>
|
||||||
<Editable
|
<Editable
|
||||||
renderElement={({ children }) => {
|
renderElement={({ children }) => {
|
||||||
useEffect(() => mounts(), [])
|
useEffect(() => mounts(), [])
|
||||||
@@ -52,7 +58,7 @@ describe('slate-react', () => {
|
|||||||
|
|
||||||
test('should not unmount the node that gets merged into on a merge_node operation', async () => {
|
test('should not unmount the node that gets merged into on a merge_node operation', async () => {
|
||||||
const editor = withReact(createEditor())
|
const editor = withReact(createEditor())
|
||||||
const value = [
|
const initialValue = [
|
||||||
{ type: 'block', children: [{ text: 'te' }] },
|
{ type: 'block', children: [{ text: 'te' }] },
|
||||||
{ type: 'block', children: [{ text: 'st' }] },
|
{ type: 'block', children: [{ text: 'st' }] },
|
||||||
]
|
]
|
||||||
@@ -62,7 +68,11 @@ describe('slate-react', () => {
|
|||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
el = create(
|
el = create(
|
||||||
<Slate editor={editor} value={value} onChange={() => {}}>
|
<Slate
|
||||||
|
editor={editor}
|
||||||
|
initialValue={initialValue}
|
||||||
|
onChange={() => {}}
|
||||||
|
>
|
||||||
<Editable
|
<Editable
|
||||||
renderElement={({ children }) => {
|
renderElement={({ children }) => {
|
||||||
useEffect(() => mounts(), [])
|
useEffect(() => mounts(), [])
|
||||||
|
@@ -73,7 +73,7 @@ const CheckListsExample = () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable
|
<Editable
|
||||||
renderElement={renderElement}
|
renderElement={renderElement}
|
||||||
placeholder="Get to work…"
|
placeholder="Get to work…"
|
||||||
|
@@ -46,7 +46,7 @@ const CodeHighlightingExample = () => {
|
|||||||
const onKeyDown = useOnKeydown(editor)
|
const onKeyDown = useOnKeydown(editor)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<ExampleToolbar />
|
<ExampleToolbar />
|
||||||
<SetNodeToDecorations />
|
<SetNodeToDecorations />
|
||||||
<Editable
|
<Editable
|
||||||
@@ -324,7 +324,7 @@ const App = () => {
|
|||||||
const [editor] = useState(() => withReact(createEditor()))
|
const [editor] = useState(() => withReact(createEditor()))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable />
|
<Editable />
|
||||||
</Slate>
|
</Slate>
|
||||||
)
|
)
|
||||||
|
@@ -13,7 +13,7 @@ const initialValue: Descendant[] = [
|
|||||||
const PlainTextExample = () => {
|
const PlainTextExample = () => {
|
||||||
const editor = useMemo(() => withHistory(withReact(createEditor())), [])
|
const editor = useMemo(() => withHistory(withReact(createEditor())), [])
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable
|
<Editable
|
||||||
placeholder="Type something"
|
placeholder="Type something"
|
||||||
renderPlaceholder={({ children, attributes }) => (
|
renderPlaceholder={({ children, attributes }) => (
|
||||||
|
@@ -15,7 +15,7 @@ const EditableVoidsExample = () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
<InsertEditableVoidButton />
|
<InsertEditableVoidButton />
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
|
@@ -16,7 +16,7 @@ import {
|
|||||||
const EmbedsExample = () => {
|
const EmbedsExample = () => {
|
||||||
const editor = useMemo(() => withEmbeds(withReact(createEditor())), [])
|
const editor = useMemo(() => withEmbeds(withReact(createEditor())), [])
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable
|
<Editable
|
||||||
renderElement={props => <Element {...props} />}
|
renderElement={props => <Element {...props} />}
|
||||||
placeholder="Enter some text..."
|
placeholder="Enter some text..."
|
||||||
|
@@ -74,7 +74,7 @@ const ForcedLayoutExample = () => {
|
|||||||
[]
|
[]
|
||||||
)
|
)
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable
|
<Editable
|
||||||
renderElement={renderElement}
|
renderElement={renderElement}
|
||||||
placeholder="Enter a title…"
|
placeholder="Enter a title…"
|
||||||
|
@@ -17,7 +17,7 @@ const HoveringMenuExample = () => {
|
|||||||
const editor = useMemo(() => withHistory(withReact(createEditor())), [])
|
const editor = useMemo(() => withHistory(withReact(createEditor())), [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<HoveringToolbar />
|
<HoveringToolbar />
|
||||||
<Editable
|
<Editable
|
||||||
renderLeaf={props => <Leaf {...props} />}
|
renderLeaf={props => <Leaf {...props} />}
|
||||||
|
@@ -25,7 +25,7 @@ const HugeDocumentExample = () => {
|
|||||||
const renderElement = useCallback(props => <Element {...props} />, [])
|
const renderElement = useCallback(props => <Element {...props} />, [])
|
||||||
const editor = useMemo(() => withReact(createEditor()), [])
|
const editor = useMemo(() => withReact(createEditor()), [])
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable renderElement={renderElement} spellCheck autoFocus />
|
<Editable renderElement={renderElement} spellCheck autoFocus />
|
||||||
</Slate>
|
</Slate>
|
||||||
)
|
)
|
||||||
|
@@ -25,7 +25,7 @@ const IFrameExample = () => {
|
|||||||
const handleBlur = useCallback(() => ReactEditor.deselect(editor), [editor])
|
const handleBlur = useCallback(() => ReactEditor.deselect(editor), [editor])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
<MarkButton format="bold" icon="format_bold" />
|
<MarkButton format="bold" icon="format_bold" />
|
||||||
<MarkButton format="italic" icon="format_italic" />
|
<MarkButton format="italic" icon="format_italic" />
|
||||||
|
@@ -25,7 +25,7 @@ const ImagesExample = () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
<InsertImageButton />
|
<InsertImageButton />
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
|
@@ -98,7 +98,7 @@ const InlinesExample = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SlateReact.Slate editor={editor} value={initialValue}>
|
<SlateReact.Slate editor={editor} initialValue={initialValue}>
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
<AddLinkButton />
|
<AddLinkButton />
|
||||||
<RemoveLinkButton />
|
<RemoveLinkButton />
|
||||||
|
@@ -48,7 +48,7 @@ const MarkdownPreviewExample = () => {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable
|
<Editable
|
||||||
decorate={decorate}
|
decorate={decorate}
|
||||||
renderLeaf={renderLeaf}
|
renderLeaf={renderLeaf}
|
||||||
|
@@ -70,7 +70,7 @@ const MarkdownShortcutsExample = () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable
|
<Editable
|
||||||
onDOMBeforeInput={handleDOMBeforeInput}
|
onDOMBeforeInput={handleDOMBeforeInput}
|
||||||
renderElement={renderElement}
|
renderElement={renderElement}
|
||||||
|
@@ -73,7 +73,7 @@ const MentionExample = () => {
|
|||||||
return (
|
return (
|
||||||
<Slate
|
<Slate
|
||||||
editor={editor}
|
editor={editor}
|
||||||
value={initialValue}
|
initialValue={initialValue}
|
||||||
onChange={() => {
|
onChange={() => {
|
||||||
const { selection } = editor
|
const { selection } = editor
|
||||||
|
|
||||||
|
@@ -91,7 +91,7 @@ const PasteHtmlExample = () => {
|
|||||||
[]
|
[]
|
||||||
)
|
)
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable
|
<Editable
|
||||||
renderElement={renderElement}
|
renderElement={renderElement}
|
||||||
renderLeaf={renderLeaf}
|
renderLeaf={renderLeaf}
|
||||||
|
@@ -6,7 +6,7 @@ import { withHistory } from 'slate-history'
|
|||||||
const PlainTextExample = () => {
|
const PlainTextExample = () => {
|
||||||
const editor = useMemo(() => withHistory(withReact(createEditor())), [])
|
const editor = useMemo(() => withHistory(withReact(createEditor())), [])
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable placeholder="Enter some plain text..." />
|
<Editable placeholder="Enter some plain text..." />
|
||||||
</Slate>
|
</Slate>
|
||||||
)
|
)
|
||||||
|
@@ -5,7 +5,7 @@ import { Slate, Editable, withReact } from 'slate-react'
|
|||||||
const ReadOnlyExample = () => {
|
const ReadOnlyExample = () => {
|
||||||
const editor = useMemo(() => withReact(createEditor()), [])
|
const editor = useMemo(() => withReact(createEditor()), [])
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable readOnly placeholder="Enter some plain text..." />
|
<Editable readOnly placeholder="Enter some plain text..." />
|
||||||
</Slate>
|
</Slate>
|
||||||
)
|
)
|
||||||
|
@@ -28,7 +28,7 @@ const RichTextExample = () => {
|
|||||||
const editor = useMemo(() => withHistory(withReact(createEditor())), [])
|
const editor = useMemo(() => withHistory(withReact(createEditor())), [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
<MarkButton format="bold" icon="format_bold" />
|
<MarkButton format="bold" icon="format_bold" />
|
||||||
<MarkButton format="italic" icon="format_italic" />
|
<MarkButton format="italic" icon="format_italic" />
|
||||||
|
@@ -51,7 +51,7 @@ const ScrollIntoViewExample = () => {
|
|||||||
const PlainTextEditor = () => {
|
const PlainTextEditor = () => {
|
||||||
const editor = useMemo(() => withHistory(withReact(createEditor())), [])
|
const editor = useMemo(() => withHistory(withReact(createEditor())), [])
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable placeholder="Enter some plain text..." />
|
<Editable placeholder="Enter some plain text..." />
|
||||||
</Slate>
|
</Slate>
|
||||||
)
|
)
|
||||||
|
@@ -37,7 +37,7 @@ const SearchHighlightingExample = () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
<div
|
<div
|
||||||
className={css`
|
className={css`
|
||||||
|
@@ -31,7 +31,7 @@ const ShadowEditor = () => {
|
|||||||
const editor = useMemo(() => withHistory(withReact(createEditor())), [])
|
const editor = useMemo(() => withHistory(withReact(createEditor())), [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable placeholder="Enter some plain text..." />
|
<Editable placeholder="Enter some plain text..." />
|
||||||
</Slate>
|
</Slate>
|
||||||
)
|
)
|
||||||
|
@@ -11,7 +11,7 @@ const StylingExample = () => {
|
|||||||
<div style={{ display: 'flex', flexDirection: 'column', gap: '40px' }}>
|
<div style={{ display: 'flex', flexDirection: 'column', gap: '40px' }}>
|
||||||
<Slate
|
<Slate
|
||||||
editor={editor1}
|
editor={editor1}
|
||||||
value={[
|
initialValue={[
|
||||||
{
|
{
|
||||||
type: 'paragraph',
|
type: 'paragraph',
|
||||||
children: [{ text: 'This editor is styled using the style prop.' }],
|
children: [{ text: 'This editor is styled using the style prop.' }],
|
||||||
@@ -29,7 +29,7 @@ const StylingExample = () => {
|
|||||||
|
|
||||||
<Slate
|
<Slate
|
||||||
editor={editor2}
|
editor={editor2}
|
||||||
value={[
|
initialValue={[
|
||||||
{
|
{
|
||||||
type: 'paragraph',
|
type: 'paragraph',
|
||||||
children: [
|
children: [
|
||||||
|
@@ -18,7 +18,7 @@ const TablesExample = () => {
|
|||||||
[]
|
[]
|
||||||
)
|
)
|
||||||
return (
|
return (
|
||||||
<Slate editor={editor} value={initialValue}>
|
<Slate editor={editor} initialValue={initialValue}>
|
||||||
<Editable renderElement={renderElement} renderLeaf={renderLeaf} />
|
<Editable renderElement={renderElement} renderLeaf={renderLeaf} />
|
||||||
</Slate>
|
</Slate>
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user