diff --git a/packages/web/src/designer/Designer.js b/packages/web/src/designer/Designer.js index 665bed943..9e769e0dc 100644 --- a/packages/web/src/designer/Designer.js +++ b/packages/web/src/designer/Designer.js @@ -27,10 +27,11 @@ export default function Designer({ value, onChange }) { const changeTable = React.useCallback( (table, index) => { - onChange({ + const newValue = { ...value, tables: (tables || []).map((t, i) => (i == index ? table : t)), - }); + }; + onChange(newValue); }, [onChange] ); @@ -38,12 +39,7 @@ export default function Designer({ value, onChange }) { return ( e.preventDefault()} onDrop={handleDrop}> {(tables || []).map((table, index) => ( - + ))} ); diff --git a/packages/web/src/designer/DesignerTable.js b/packages/web/src/designer/DesignerTable.js index 3ee2df78d..aee8921ee 100644 --- a/packages/web/src/designer/DesignerTable.js +++ b/packages/web/src/designer/DesignerTable.js @@ -12,12 +12,14 @@ const Header = styled.div` text-align: center; padding: 2px; background: lightblue; + cursor: pointer; `; const ColumnsWrapper = styled.div` max-height: 400px; - overflow-y: scroll; + overflow-y: auto; width: 100%; + margin: 5px; `; export default function DesignerTable(props) { @@ -28,47 +30,50 @@ export default function DesignerTable(props) { const moveStartXRef = React.useRef(null); const moveStartYRef = React.useRef(null); - const handleMove = React.useCallback( - (e) => { - let diffX = e.clientX - moveStartXRef.current; - let diffY = e.clientY - moveStartYRef.current; - moveStartXRef.current = e.clientX; - moveStartYRef.current = e.clientY; + const handleMove = React.useCallback((e) => { + let diffX = e.clientX - moveStartXRef.current; + let diffY = e.clientY - moveStartYRef.current; + moveStartXRef.current = e.clientX; + moveStartYRef.current = e.clientY; - movingPositionRef.current = { - left: (movingPositionRef.current.left || 0) + diffX, - top: (movingPositionRef.current.top || 0) + diffY, - }; - setMovingPosition(movingPositionRef.current); - // onChangeTable( - // { - // ...props, - // left: (left || 0) + diffX, - // top: (top || 0) + diffY, - // }, - // index - // ); - }, - [onChangeTable] - ); - - const handleMoveEnd = React.useCallback((e) => { - setMovingPosition(null); - - onChangeTable( - { - ...props, - left: movingPositionRef.current.left, - top: movingPositionRef.current.top, - }, - index - ); - - // this.props.model.fixPositions(); - - // this.props.designer.changedModel(true); + movingPositionRef.current = { + left: (movingPositionRef.current.left || 0) + diffX, + top: (movingPositionRef.current.top || 0) + diffY, + }; + setMovingPosition(movingPositionRef.current); + // onChangeTable( + // { + // ...props, + // left: (left || 0) + diffX, + // top: (top || 0) + diffY, + // }, + // index + // ); }, []); + const handleMoveEnd = React.useCallback( + (e) => { + if (movingPositionRef.current) { + onChangeTable( + { + ...props, + left: movingPositionRef.current.left, + top: movingPositionRef.current.top, + }, + index + ); + } + + movingPositionRef.current = null; + setMovingPosition(null); + + // this.props.model.fixPositions(); + + // this.props.designer.changedModel(true); + }, + [onChangeTable, index] + ); + React.useEffect(() => { if (movingPosition) { document.addEventListener('mousemove', handleMove, true);