({shape, data, shapeStatus})
| 25 | * @constructor |
| 26 | */ |
| 27 | export const Header = ({shape, data, shapeStatus}) => { |
| 28 | const {t} = useTranslation(); |
| 29 | const [edit, setEdit] = useState(false); |
| 30 | const [isAdvancedConfigurationOpen, setAdvancedConfigurationOpen] = useState(false); |
| 31 | const inputRef = useRef(null); |
| 32 | const dispatch = useDispatch(); |
| 33 | |
| 34 | useEffect(() => { |
| 35 | inputRef.current && inputRef.current.focus({ |
| 36 | cursor: 'end', |
| 37 | }); |
| 38 | }); |
| 39 | |
| 40 | const onInputBlur = () => { |
| 41 | if (inputRef.current.input.value === '') { |
| 42 | return; |
| 43 | } |
| 44 | if (shape.page.sm.getShapes(s => s.id !== shape.id).some(s => s.text === inputRef.current.input.value)) { |
| 45 | message.error(t('nodeTextDuplicate')); |
| 46 | return; |
| 47 | } |
| 48 | shape.text = inputRef.current.input.value; |
| 49 | shape.page.triggerEvent({ |
| 50 | type: EVENT_NAME.NODE_NAME_CHANGED, |
| 51 | value: { |
| 52 | id: shape.id, |
| 53 | name: shape.text, |
| 54 | }, |
| 55 | }); |
| 56 | setEdit(false); |
| 57 | }; |
| 58 | |
| 59 | /** |
| 60 | * menu点击事件. |
| 61 | * |
| 62 | * @param e 事件对象. |
| 63 | */ |
| 64 | const onMenuClick = (e) => { |
| 65 | const m = shape.drawer.getToolMenus().find(t => t.key === e.key); |
| 66 | if (m.action) { |
| 67 | if (e.key === 'rename') { |
| 68 | m.action(setEdit); |
| 69 | } else if (e.key === 'advancedConfiguration') { |
| 70 | m.action(setAdvancedConfigurationOpen); |
| 71 | } else { |
| 72 | m.action(); |
| 73 | } |
| 74 | } |
| 75 | }; |
| 76 | |
| 77 | /** |
| 78 | * 获取文本组件,处于编辑态时,需要能修改标题;否则只展示标题. |
| 79 | * |
| 80 | * @return {JSX.Element} 标题组件. |
| 81 | */ |
| 82 | const getTitle = () => { |
| 83 | if (edit) { |
| 84 | return (<> |
nothing calls this directly
no test coverage detected