1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-31 02:49:56 +02:00

Add format_text command, and editor.marks state (#3308)

* add format_text command, refactor command extensions

* update onChange to not receive selection

* update docs

* fix tests
This commit is contained in:
Ian Storm Taylor
2019-12-12 15:37:55 -05:00
committed by GitHub
parent ed40c08b80
commit 6552da940a
37 changed files with 350 additions and 647 deletions

View File

@@ -9,7 +9,6 @@ We'll show you how. Let's start with our app from earlier:
```js
const App = () => {
const editor = useMemo(() => withReact(createEditor()), [])
const [selection, setSelection] = useState(null)
const [value, setValue] = useState([
{
type: 'paragraph',
@@ -18,15 +17,7 @@ const App = () => {
])
return (
<Slate
editor={editor}
value={value}
selection={selection}
onChange={(value, selection) => {
setValue(value)
setSelection(selection)
}}
>
<Slate editor={editor} value={value} onChange={value => setValue(value)}>
<Editable
onKeyDown={event => {
if (event.key === '&') {
@@ -76,7 +67,6 @@ Now, let's add that renderer to our `Editor`:
```js
const App = () => {
const editor = useMemo(() => withReact(createEditor()), [])
const [selection, setSelection] = useState(null)
const [value, setValue] = useState([
{
type: 'paragraph',
@@ -96,15 +86,7 @@ const App = () => {
}, [])
return (
<Slate
editor={editor}
value={value}
selection={selection}
onChange={(value, selection) => {
setValue(value)
setSelection(selection)
}}
>
<Slate editor={editor} value={value} onChange={value => setValue(value)}>
<Editable
// Pass in the `renderElement` function.
renderElement={renderElement}
@@ -140,7 +122,6 @@ import { Editor } from 'slate'
const App = () => {
const editor = useMemo(() => withReact(createEditor()), [])
const [selection, setSelection] = useState(null)
const [value, setValue] = useState([
{
type: 'paragraph',
@@ -158,15 +139,7 @@ const App = () => {
}, [])
return (
<Slate
editor={editor}
value={value}
selection={selection}
onChange={(value, selection) => {
setValue(value)
setSelection(selection)
}}
>
<Slate editor={editor} value={value} onChange={value => setValue(value)}>
<Editable
renderElement={renderElement}
onKeyDown={event => {
@@ -220,15 +193,7 @@ const App = () => {
}, [])
return (
<Slate
editor={editor}
value={value}
selection={selection}
onChange={(value, selection) => {
setValue(value)
setSelection(selection)
}}
>
<Slate editor={editor} value={value} onChange={value => setValue(value)}>
<Editable
renderElement={renderElement}
onKeyDown={event => {