|
@@ -2,6 +2,7 @@ import { useEffect, useMemo, useState } from "react"
|
|
import { Button, Form, Modal, Input } from 'antd'
|
|
import { Button, Form, Modal, Input } from 'antd'
|
|
import { CloseOutlined, PlusOutlined, RotateRightOutlined } from '@ant-design/icons'
|
|
import { CloseOutlined, PlusOutlined, RotateRightOutlined } from '@ant-design/icons'
|
|
import style from './style.module.scss'
|
|
import style from './style.module.scss'
|
|
|
|
+import { title, compass } from './board'
|
|
import ReactEditeTable, { InputEditor } from 'react-edit-table'
|
|
import ReactEditeTable, { InputEditor } from 'react-edit-table'
|
|
|
|
|
|
import type { Board, BoardShape, ShapeType, ExtractShape } from "./board"
|
|
import type { Board, BoardShape, ShapeType, ExtractShape } from "./board"
|
|
@@ -171,16 +172,23 @@ const RotateInput = ({ shape }: { shape: ExtractShape<'rotate'> }) => (
|
|
const shapeCompontes: { [key in ShapeType]?: ComponentType<{ shape: any }> } = {
|
|
const shapeCompontes: { [key in ShapeType]?: ComponentType<{ shape: any }> } = {
|
|
Tag: TextInput,
|
|
Tag: TextInput,
|
|
Table: ContentInput,
|
|
Table: ContentInput,
|
|
- Compass: RotateInput
|
|
|
|
|
|
+ Compass: RotateInput,
|
|
|
|
+ Title: TextInput
|
|
}
|
|
}
|
|
|
|
|
|
export type EShapeProps = {
|
|
export type EShapeProps = {
|
|
board: Board
|
|
board: Board
|
|
}
|
|
}
|
|
export const EShape = ({ board }: EShapeProps) => {
|
|
export const EShape = ({ board }: EShapeProps) => {
|
|
- const [shape, setShape] = useState<BoardShape | null>(null)
|
|
|
|
-
|
|
|
|
|
|
+ const [shape, setShape] = useState<BoardShape | null>(null)
|
|
const Edit = shape && shapeCompontes[shape.data.type]
|
|
const Edit = shape && shapeCompontes[shape.data.type]
|
|
|
|
+ const disabledDelete: boolean = ([title, compass] as any).includes(shape?.data.type)
|
|
|
|
+ const renderDelete = !disabledDelete && (
|
|
|
|
+ <Form.Item label="形状">
|
|
|
|
+ <Button type="primary" onClick={() => shape!.delete()}>删除</Button>
|
|
|
|
+ </Form.Item>
|
|
|
|
+ )
|
|
|
|
+
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
board.bus.on('selectShape', setShape)
|
|
board.bus.on('selectShape', setShape)
|
|
return () => {
|
|
return () => {
|
|
@@ -188,13 +196,26 @@ export const EShape = ({ board }: EShapeProps) => {
|
|
}
|
|
}
|
|
}, [board])
|
|
}, [board])
|
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ const keydownHandler = (ev: KeyboardEvent) => {
|
|
|
|
+ if (ev.key === 'Delete' && shape && !disabledDelete) {
|
|
|
|
+ shape.delete()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ window.addEventListener('keydown', keydownHandler)
|
|
|
|
+ return () => {
|
|
|
|
+ window.removeEventListener('keydown', keydownHandler)
|
|
|
|
+ }
|
|
|
|
+ }, [board, shape, disabledDelete])
|
|
|
|
+
|
|
return shape ? (
|
|
return shape ? (
|
|
<div className={style['def-shape-edit']}>
|
|
<div className={style['def-shape-edit']}>
|
|
{ Edit && <Edit shape={shape} /> }
|
|
{ Edit && <Edit shape={shape} /> }
|
|
- <Form.Item label="形状">
|
|
|
|
- <Button type="primary" onClick={() => shape.delete()}>删除</Button>
|
|
|
|
- </Form.Item>
|
|
|
|
- <div className={`ant-form-item ${style['def-close-shape-edit']}`} onClick={() => setShape(null)}>
|
|
|
|
|
|
+ { renderDelete }
|
|
|
|
+ <div
|
|
|
|
+ className={`ant-form-item ${style['def-close-shape-edit']}`}
|
|
|
|
+ onClick={() => setShape(null)}
|
|
|
|
+ >
|
|
<CloseOutlined className={`${style['icon']}`} onClick={() => board.unSelectShape()} />
|
|
<CloseOutlined className={`${style['icon']}`} onClick={() => board.unSelectShape()} />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|