import React, { type FC, useMemo } from 'react' import { useTranslation } from 'react-i18next' import { useKeyPress } from 'ahooks' import { useDocumentContext } from '../../index' import Button from '@/app/components/base/button' import { getKeyboardKeyCodeBySystem, getKeyboardKeyNameBySystem } from '@/app/components/workflow/utils' type IActionButtonsProps = { handleCancel: () => void handleSave: () => void loading: boolean actionType?: 'edit' | 'add' handleRegeneration?: () => void isChildChunk?: boolean } const ActionButtons: FC = ({ handleCancel, handleSave, loading, actionType = 'edit', handleRegeneration, isChildChunk = false, }) => { const { t } = useTranslation() const mode = useDocumentContext(s => s.mode) const parentMode = useDocumentContext(s => s.parentMode) useKeyPress(['esc'], (e) => { e.preventDefault() handleCancel() }) useKeyPress(`${getKeyboardKeyCodeBySystem('ctrl')}.s`, (e) => { e.preventDefault() if (loading) return handleSave() }, { exactMatch: true, useCapture: true }) const isParentChildParagraphMode = useMemo(() => { return mode === 'hierarchical' && parentMode === 'paragraph' }, [mode, parentMode]) return (
{(isParentChildParagraphMode && actionType === 'edit' && !isChildChunk) ? : null }
) } ActionButtons.displayName = 'ActionButtons' export default React.memo(ActionButtons)