|
@@ -7,7 +7,7 @@ import React, { useCallback, useState } from 'react';
|
|
|
|
|
|
|
|
import { usePlayground, usePlaygroundDrag } from '@flowgram.ai/playground-react';
|
|
import { usePlayground, usePlaygroundDrag } from '@flowgram.ai/playground-react';
|
|
|
|
|
|
|
|
-export function Card() {
|
|
|
|
|
|
|
+export function StaticCard() {
|
|
|
return (
|
|
return (
|
|
|
<div
|
|
<div
|
|
|
style={{
|
|
style={{
|
|
@@ -15,16 +15,23 @@ export function Card() {
|
|
|
height: 100,
|
|
height: 100,
|
|
|
position: 'absolute',
|
|
position: 'absolute',
|
|
|
color: 'white',
|
|
color: 'white',
|
|
|
- backgroundColor: 'red',
|
|
|
|
|
- left: 500,
|
|
|
|
|
- top: 500,
|
|
|
|
|
|
|
+ backgroundColor: 'gray',
|
|
|
|
|
+ left: 200,
|
|
|
|
|
+ top: 200,
|
|
|
|
|
+ alignItems: 'center',
|
|
|
|
|
+ justifyContent: 'center',
|
|
|
|
|
+ display: 'flex',
|
|
|
}}
|
|
}}
|
|
|
- ></div>
|
|
|
|
|
|
|
+ >
|
|
|
|
|
+ {' '}
|
|
|
|
|
+ Static Card
|
|
|
|
|
+ </div>
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export function DragableCard() {
|
|
export function DragableCard() {
|
|
|
- const [pos, setPos] = useState({ x: 200, y: 100 });
|
|
|
|
|
|
|
+ const [pos, setPos] = useState({ x: 100, y: 50 });
|
|
|
|
|
+ // Used for dragging, the canvas will automatically scroll when dragged to the edge
|
|
|
// 用于拖拽,拖拽到边缘时候会自动滚动画布
|
|
// 用于拖拽,拖拽到边缘时候会自动滚动画布
|
|
|
const dragger = usePlaygroundDrag();
|
|
const dragger = usePlaygroundDrag();
|
|
|
const playground = usePlayground();
|
|
const playground = usePlayground();
|
|
@@ -32,20 +39,19 @@ export function DragableCard() {
|
|
|
(e: React.MouseEvent) => {
|
|
(e: React.MouseEvent) => {
|
|
|
const startPos = { x: pos.x, y: pos.y };
|
|
const startPos = { x: pos.x, y: pos.y };
|
|
|
dragger.start(e, {
|
|
dragger.start(e, {
|
|
|
|
|
+ // start Drag
|
|
|
onDragStart() {
|
|
onDragStart() {
|
|
|
playground.config.grabDisable = true;
|
|
playground.config.grabDisable = true;
|
|
|
- // start drag
|
|
|
|
|
},
|
|
},
|
|
|
onDrag(dragEvent) {
|
|
onDrag(dragEvent) {
|
|
|
- // 需要 除去当前的缩放比例
|
|
|
|
|
setPos({
|
|
setPos({
|
|
|
x: startPos.x + (dragEvent.endPos.x - dragEvent.startPos.x) / dragEvent.scale,
|
|
x: startPos.x + (dragEvent.endPos.x - dragEvent.startPos.x) / dragEvent.scale,
|
|
|
y: startPos.y + (dragEvent.endPos.y - dragEvent.startPos.y) / dragEvent.scale,
|
|
y: startPos.y + (dragEvent.endPos.y - dragEvent.startPos.y) / dragEvent.scale,
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
|
|
|
+ // end drag
|
|
|
onDragEnd() {
|
|
onDragEnd() {
|
|
|
playground.config.grabDisable = false;
|
|
playground.config.grabDisable = false;
|
|
|
- // end drag
|
|
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
// e.stopPropagation();
|
|
// e.stopPropagation();
|
|
@@ -62,10 +68,16 @@ export function DragableCard() {
|
|
|
height: 100,
|
|
height: 100,
|
|
|
position: 'absolute',
|
|
position: 'absolute',
|
|
|
color: 'white',
|
|
color: 'white',
|
|
|
- backgroundColor: 'blue',
|
|
|
|
|
|
|
+ backgroundColor: '#0089ff',
|
|
|
left: pos.x,
|
|
left: pos.x,
|
|
|
top: pos.y,
|
|
top: pos.y,
|
|
|
|
|
+ alignItems: 'center',
|
|
|
|
|
+ justifyContent: 'center',
|
|
|
|
|
+ display: 'flex',
|
|
|
}}
|
|
}}
|
|
|
- ></div>
|
|
|
|
|
|
|
+ >
|
|
|
|
|
+ {' '}
|
|
|
|
|
+ Draggable Card
|
|
|
|
|
+ </div>
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|