|
|
|
@ -11,11 +11,11 @@ import { EditorContent, useEditor } from '@tiptap/react' |
|
|
|
import { Event } from 'nostr-tools' |
|
|
|
import { Event } from 'nostr-tools' |
|
|
|
import { Dispatch, forwardRef, SetStateAction, useImperativeHandle } from 'react' |
|
|
|
import { Dispatch, forwardRef, SetStateAction, useImperativeHandle } from 'react' |
|
|
|
import { useTranslation } from 'react-i18next' |
|
|
|
import { useTranslation } from 'react-i18next' |
|
|
|
|
|
|
|
import { usePostEditor } from '../PostEditorProvider' |
|
|
|
import CustomMention from './CustomMention' |
|
|
|
import CustomMention from './CustomMention' |
|
|
|
import { FileHandler } from './FileHandler' |
|
|
|
import { FileHandler } from './FileHandler' |
|
|
|
import Preview from './Preview' |
|
|
|
import Preview from './Preview' |
|
|
|
import suggestion from './suggestion' |
|
|
|
import suggestion from './suggestion' |
|
|
|
import { usePostEditor } from '../PostEditorProvider' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export type TPostTextareaHandle = { |
|
|
|
export type TPostTextareaHandle = { |
|
|
|
appendText: (text: string) => void |
|
|
|
appendText: (text: string) => void |
|
|
|
@ -28,8 +28,9 @@ const PostTextarea = forwardRef< |
|
|
|
setText: Dispatch<SetStateAction<string>> |
|
|
|
setText: Dispatch<SetStateAction<string>> |
|
|
|
defaultContent?: string |
|
|
|
defaultContent?: string |
|
|
|
parentEvent?: Event |
|
|
|
parentEvent?: Event |
|
|
|
|
|
|
|
onSubmit?: () => void |
|
|
|
} |
|
|
|
} |
|
|
|
>(({ text = '', setText, defaultContent, parentEvent }, ref) => { |
|
|
|
>(({ text = '', setText, defaultContent, parentEvent, onSubmit }, ref) => { |
|
|
|
const { t } = useTranslation() |
|
|
|
const { t } = useTranslation() |
|
|
|
const { setUploadingFiles } = usePostEditor() |
|
|
|
const { setUploadingFiles } = usePostEditor() |
|
|
|
const editor = useEditor({ |
|
|
|
const editor = useEditor({ |
|
|
|
@ -54,6 +55,15 @@ const PostTextarea = forwardRef< |
|
|
|
attributes: { |
|
|
|
attributes: { |
|
|
|
class: |
|
|
|
class: |
|
|
|
'border rounded-lg p-3 min-h-52 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring' |
|
|
|
'border rounded-lg p-3 min-h-52 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring' |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
handleKeyDown: (_view, event) => { |
|
|
|
|
|
|
|
// Handle Ctrl+Enter or Cmd+Enter for submit
|
|
|
|
|
|
|
|
if ((event.ctrlKey || event.metaKey) && event.key === 'Enter') { |
|
|
|
|
|
|
|
event.preventDefault() |
|
|
|
|
|
|
|
onSubmit?.() |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
content: postContentCache.getPostCache({ defaultContent, parentEvent }), |
|
|
|
content: postContentCache.getPostCache({ defaultContent, parentEvent }), |
|
|
|
|