mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-12 21:00:02 +08:00
44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
import './styles.scss'
|
|
|
|
import Document from '@tiptap/extension-document'
|
|
import Image from '@tiptap/extension-image'
|
|
import Paragraph from '@tiptap/extension-paragraph'
|
|
import Text from '@tiptap/extension-text'
|
|
import { Dropcursor } from '@tiptap/extensions'
|
|
import { EditorContent, useEditor } from '@tiptap/react'
|
|
import React, { useCallback } from 'react'
|
|
|
|
export default () => {
|
|
const editor = useEditor({
|
|
extensions: [Document, Paragraph, Text, Image.configure({ resize: { minWidth: 100, minHeight: 100 } }), Dropcursor],
|
|
content: `
|
|
<p>This is a basic example of implementing images. Drag to re-order.</p>
|
|
<img src="https://unsplash.it/seed/tiptap/800/400" />
|
|
<img src="https://unsplash.it/seed/tiptap-2/800/400" />
|
|
`,
|
|
})
|
|
|
|
const addImage = useCallback(() => {
|
|
const url = window.prompt('URL')
|
|
|
|
if (url) {
|
|
editor.chain().focus().setImage({ src: url }).run()
|
|
}
|
|
}, [editor])
|
|
|
|
if (!editor) {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div className="control-group">
|
|
<div className="button-group">
|
|
<button onClick={addImage}>Set image</button>
|
|
</div>
|
|
</div>
|
|
<EditorContent editor={editor} />
|
|
</>
|
|
)
|
|
}
|