feat: mouse right click can add new comment

This commit is contained in:
hjlarry
2026-01-29 09:13:12 +08:00
parent 0495dc5085
commit 26dd6c128c
31 changed files with 160 additions and 15 deletions

View File

@ -9,6 +9,7 @@ type MentionInputProps = {
onSubmit: (content: string, mentionedUserIds: string[]) => void
placeholder?: string
autoFocus?: boolean
disabled?: boolean
className?: string
}

View File

@ -10,6 +10,8 @@ type CommentInputProps = {
position: { x: number, y: number }
onSubmit: (content: string, mentionedUserIds: string[]) => void
onCancel: () => void
autoFocus?: boolean
disabled?: boolean
onPositionChange?: (position: {
pageX: number
pageY: number
@ -18,7 +20,14 @@ type CommentInputProps = {
}) => void
}
export const CommentInput: FC<CommentInputProps> = memo(({ position, onSubmit, onCancel, onPositionChange }) => {
export const CommentInput: FC<CommentInputProps> = memo(({
position,
onSubmit,
onCancel,
autoFocus = true,
disabled = false,
onPositionChange,
}) => {
const [content, setContent] = useState('')
const { t } = useTranslation()
const { userProfile } = useAppContext()
@ -124,7 +133,10 @@ export const CommentInput: FC<CommentInputProps> = memo(({ position, onSubmit, o
return (
<div
className="absolute z-[60] w-96"
className={cn(
'absolute z-[60] w-96',
disabled && 'pointer-events-none opacity-80',
)}
style={{
left: position.x,
top: position.y,
@ -162,7 +174,8 @@ export const CommentInput: FC<CommentInputProps> = memo(({ position, onSubmit, o
onChange={setContent}
onSubmit={handleMentionSubmit}
placeholder={t('comments.placeholder.add', { ns: 'workflow' })}
autoFocus
autoFocus={autoFocus}
disabled={disabled}
className="relative"
/>
</div>

View File

@ -5,6 +5,7 @@ import { CommentCursor } from './cursor'
const mockState = {
controlMode: ControlMode.Pointer,
isCommentPlacing: false,
mousePosition: {
elementX: 10,
elementY: 20,

View File

@ -7,8 +7,9 @@ import { ControlMode } from '../types'
export const CommentCursor: FC = memo(() => {
const controlMode = useStore(s => s.controlMode)
const mousePosition = useStore(s => s.mousePosition)
const isCommentPlacing = useStore(s => s.isCommentPlacing)
if (controlMode !== ControlMode.Comment)
if (controlMode !== ControlMode.Comment || isCommentPlacing)
return null
return (