import {
memo,
useCallback,
useRef,
} from 'react'
import { useTranslation } from 'react-i18next'
import { useClickAway } from 'ahooks'
import type { NodeProps } from 'reactflow'
import NodeResizer from '../nodes/_base/components/node-resizer'
import {
useNodeDataUpdate,
useNodesInteractions,
} from '../hooks'
import { useStore } from '../store'
import {
NoteEditor,
NoteEditorContextProvider,
NoteEditorToolbar,
} from './note-editor'
import { THEME_MAP } from './constants'
import { useNote } from './hooks'
import type { NoteNodeType } from './types'
import cn from '@/utils/classnames'
const Icon = () => {
return (
)
}
const NoteNode = ({
id,
data,
}: NodeProps) => {
const { t } = useTranslation()
const controlPromptEditorRerenderKey = useStore(s => s.controlPromptEditorRerenderKey)
const ref = useRef(null)
const theme = data.theme
const {
handleThemeChange,
handleEditorChange,
handleShowAuthorChange,
} = useNote(id)
const {
handleNodesCopy,
handleNodesDuplicate,
handleNodeDelete,
} = useNodesInteractions()
const { handleNodeDataUpdateWithSyncDraft } = useNodeDataUpdate()
const handleDeleteNode = useCallback(() => {
handleNodeDelete(id)
}, [id, handleNodeDelete])
useClickAway(() => {
handleNodeDataUpdateWithSyncDraft({ id, data: { selected: false } })
}, ref)
return (
<>
}
minWidth={240}
maxWidth={640}
minHeight={88}
/>
{
data.selected && (
)
}
{
data.showAuthor && (
{data.author}
)
}
>
)
}
export default memo(NoteNode)