1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-21 22:45:18 +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,21 +12,21 @@ import {
import { Button, Icon, Toolbar } from '../components' import { Button, Icon, Toolbar } from '../components'
const promptMention = editor => {
const name = window.prompt('Who would you like to mention?')
if (!name) return
const regex = new RegExp(`^${name}`, 'i')
const match = Object.entries(USERS).find(([, name]) => regex.test(name))
const id = match ? match[0] : 57
editor.exec({ type: 'insert_mention', id })
}
const MentionExample = () => { const MentionExample = () => {
const editor = useMemo( const editor = useMemo(
() => withMentions(withReact(withHistory(createEditor()))), () => withMentions(withReact(withHistory(createEditor()))),
[] []
) )
const promptMention = () => {
const name = window.prompt('Who would you like to mention?')
if (!name) return
const regex = new RegExp(`^${name}`, 'i')
const match = Object.entries(USERS).find(([, name]) => regex.test(name))
const id = match ? match[0] : 57
editor.exec({ type: 'insert_mention', id })
}
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>