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

Merge branch 'master' of github.com:ianstormtaylor/slate

This commit is contained in:
Ian Storm Taylor
2019-12-01 22:53:14 -05:00

View File

@@ -12,13 +12,7 @@ import {
import { Button, Icon, Toolbar } from '../components' import { Button, Icon, Toolbar } from '../components'
const MentionExample = () => { const promptMention = editor => {
const editor = useMemo(
() => withMentions(withReact(withHistory(createEditor()))),
[]
)
const promptMention = () => {
const name = window.prompt('Who would you like to mention?') const name = window.prompt('Who would you like to mention?')
if (!name) return if (!name) return
const regex = new RegExp(`^${name}`, 'i') const regex = new RegExp(`^${name}`, 'i')
@@ -27,6 +21,12 @@ const MentionExample = () => {
editor.exec({ type: 'insert_mention', id }) editor.exec({ type: 'insert_mention', id })
} }
const MentionExample = () => {
const editor = useMemo(
() => withMentions(withReact(withHistory(createEditor()))),
[]
)
return ( return (
<Slate editor={editor} defaultValue={initialValue}> <Slate editor={editor} defaultValue={initialValue}>
<Toolbar> <Toolbar>
@@ -38,7 +38,7 @@ const MentionExample = () => {
onKeyDown={event => { onKeyDown={event => {
if (event.key === '@') { if (event.key === '@') {
event.preventDefault() event.preventDefault()
promptMention() promptMention(editor)
} }
}} }}
/> />
@@ -121,7 +121,7 @@ const MentionButton = () => {
active={isMentionActive(editor)} active={isMentionActive(editor)}
onMouseDown={event => { onMouseDown={event => {
event.preventDefault() event.preventDefault()
promptMention() promptMention(editor)
}} }}
> >
<Icon>person_pin</Icon> <Icon>person_pin</Icon>