From 2f93c917e0b2f929a7bc8dfe0e0c959256abfb22 Mon Sep 17 00:00:00 2001 From: Braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Thu, 15 Jul 2021 21:15:25 +0200 Subject: [PATCH] fix: user selection deps: upgrade to latest revue-draggable --- package.json | 2 +- src/components/UserSelection/index.tsx | 5 +- src/container/FlowRenderer/index.tsx | 22 +- src/container/GraphView/index.tsx | 269 ++++++++++------ src/container/RevueFlow/index.tsx | 424 +++++++++++++++++-------- src/store/configure-store.ts | 2 - src/utils/index.ts | 2 +- yarn.lock | 8 +- 8 files changed, 493 insertions(+), 241 deletions(-) diff --git a/package.json b/package.json index d3ec2fae..e30e40c6 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "lint": "yarn lint:js" }, "dependencies": { - "@braks/revue-draggable": "^0.1.3", + "@braks/revue-draggable": "^0.1.10", "@types/d3": "^7.0.0", "d3": "^7.0.0", "d3-selection": "^3.0.0", diff --git a/src/components/UserSelection/index.tsx b/src/components/UserSelection/index.tsx index 4cd6f9be..88d12204 100644 --- a/src/components/UserSelection/index.tsx +++ b/src/components/UserSelection/index.tsx @@ -30,13 +30,12 @@ const SelectionRect = defineComponent({ return null; } - console.log('selectionrect'); return () => (
diff --git a/src/container/FlowRenderer/index.tsx b/src/container/FlowRenderer/index.tsx index 84aa2923..684f4820 100644 --- a/src/container/FlowRenderer/index.tsx +++ b/src/container/FlowRenderer/index.tsx @@ -25,57 +25,57 @@ const FlowRenderer = defineComponent({ components: { UserSelection, ZoomPane, NodesSelection }, props: { onPaneClick: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, default: undefined as any }, onPaneContextMenu: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, default: undefined as any }, onPaneScroll: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, default: undefined as any }, onElementsRemove: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, default: undefined as any }, onMove: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, default: undefined as any }, onMoveStart: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, default: undefined as any }, onMoveEnd: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, default: undefined as any }, onSelectionDragStart: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, default: undefined as any }, onSelectionDrag: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, default: undefined as any }, onSelectionDragStop: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, default: undefined as any }, onSelectionContextMenu: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, default: undefined as any }, diff --git a/src/container/GraphView/index.tsx b/src/container/GraphView/index.tsx index 27aa2daf..ccfc16a7 100644 --- a/src/container/GraphView/index.tsx +++ b/src/container/GraphView/index.tsx @@ -1,10 +1,10 @@ +import { defineComponent, inject, onBeforeMount, onMounted, ref, reactive, PropType, CSSProperties } from 'vue'; import FlowRenderer from '../FlowRenderer'; import NodeRenderer from '../NodeRenderer'; import EdgeRenderer from '../EdgeRenderer'; import { onLoadProject, onLoadGetElements, onLoadToObject } from '../../utils/graph'; import { RevueFlowProps } from '../RevueFlow'; import { NodeTypesType, EdgeTypesType, ConnectionLineType, KeyCode, RevueFlowStore } from '../../types'; -import { CSSProperties, defineComponent, inject, onBeforeMount, onMounted, PropType, ref } from 'vue'; import useZoomPanHelper from '../../hooks/useZoomPanHelper'; export interface GraphViewProps extends Omit { @@ -337,6 +337,21 @@ const GraphView = defineComponent({ required: false, default: undefined as any }, + onSelectionDragStart: { + type: Function as unknown as PropType, + required: false, + default: undefined as any + }, + onSelectionDrag: { + type: Function as unknown as PropType, + required: false, + default: undefined as any + }, + onSelectionDragStop: { + type: Function as unknown as PropType, + required: false, + default: undefined as any + }, edgeUpdaterRadius: { type: Number as PropType, required: false, @@ -344,6 +359,74 @@ const GraphView = defineComponent({ } }, setup(props) { + const { + nodeTypes, + edgeTypes, + onMove, + onMoveStart, + onMoveEnd, + onLoad, + onElementClick, + onNodeDoubleClick, + onEdgeDoubleClick, + onNodeMouseEnter, + onNodeMouseMove, + onNodeMouseLeave, + onNodeContextMenu, + onNodeDragStart, + onNodeDrag, + onNodeDragStop, + onSelectionDragStart, + onSelectionDrag, + onSelectionDragStop, + onSelectionContextMenu, + connectionMode, + connectionLineType, + connectionLineStyle, + connectionLineComponent, + selectionKeyCode, + multiSelectionKeyCode, + zoomActivationKeyCode, + onElementsRemove, + deleteKeyCode, + onConnect, + onConnectStart, + onConnectStop, + onConnectEnd, + snapToGrid, + snapGrid, + onlyRenderVisibleElements, + nodesDraggable, + nodesConnectable, + elementsSelectable, + selectNodesOnDrag, + minZoom, + maxZoom, + defaultZoom, + defaultPosition, + translateExtent, + nodeExtent, + arrowHeadColor, + markerEndId, + zoomOnScroll, + zoomOnPinch, + panOnScroll, + panOnScrollSpeed, + panOnScrollMode, + zoomOnDoubleClick, + paneMoveable, + onPaneClick, + onPaneScroll, + onPaneContextMenu, + onEdgeUpdate, + onEdgeContextMenu, + onEdgeMouseEnter, + onEdgeMouseMove, + onEdgeMouseLeave, + edgeUpdaterRadius, + onEdgeUpdateStart, + onEdgeUpdateEnd + } = reactive(props); const store = inject('store'); const isInitialized = ref(false); @@ -351,8 +434,8 @@ const GraphView = defineComponent({ const { zoomIn, zoomOut, zoomTo, transform, fitView, initialized } = useZoomPanHelper(); if (!isInitialized.value && initialized) { - if (props.onLoad && store) { - props.onLoad({ + if (onLoad && store) { + onLoad({ fitView: (params = { padding: 0.1 }) => fitView(params), zoomIn, zoomOut, @@ -368,139 +451,139 @@ const GraphView = defineComponent({ }); onBeforeMount(() => { - if (props.onConnect) { - store?.setOnConnect(props.onConnect); + if (onConnect) { + store?.setOnConnect(onConnect); } - if (props.onConnectStart) { - store?.setOnConnectStart(props.onConnectStart); + if (onConnectStart) { + store?.setOnConnectStart(onConnectStart); } - if (props.onConnectStop) { - store?.setOnConnectStop(props.onConnectStop); + if (onConnectStop) { + store?.setOnConnectStop(onConnectStop); } - if (props.onConnectEnd) { - store?.setOnConnectEnd(props.onConnectEnd); + if (onConnectEnd) { + store?.setOnConnectEnd(onConnectEnd); } - if (typeof props.snapToGrid !== 'undefined') { - store?.setSnapToGrid(props.snapToGrid); + if (typeof snapToGrid !== 'undefined') { + store?.setSnapToGrid(snapToGrid); } - if (typeof props.snapGrid !== 'undefined') { - store?.setSnapGrid(props.snapGrid); + if (typeof snapGrid !== 'undefined') { + store?.setSnapGrid(snapGrid); } - if (typeof props.nodesDraggable !== 'undefined') { - store?.setNodesDraggable(!!props.nodesDraggable); + if (typeof nodesDraggable !== 'undefined') { + store?.setNodesDraggable(!!nodesDraggable); } - if (typeof props.nodesConnectable !== 'undefined') { - store?.setNodesConnectable(!!props.nodesConnectable); + if (typeof nodesConnectable !== 'undefined') { + store?.setNodesConnectable(!!nodesConnectable); } - if (typeof props.elementsSelectable !== 'undefined') { - store?.setElementsSelectable(!!props.elementsSelectable); + if (typeof elementsSelectable !== 'undefined') { + store?.setElementsSelectable(!!elementsSelectable); } - if (typeof props.minZoom !== 'undefined') { - store?.setMinZoom(props.minZoom as any); + if (typeof minZoom !== 'undefined') { + store?.setMinZoom(minZoom); } - if (typeof props.maxZoom !== 'undefined') { - store?.setMaxZoom(props.maxZoom as any); + if (typeof maxZoom !== 'undefined') { + store?.setMaxZoom(maxZoom); } - if (typeof props.translateExtent !== 'undefined') { - store?.setTranslateExtent(props.translateExtent as any); + if (typeof translateExtent !== 'undefined') { + store?.setTranslateExtent(translateExtent); } - if (typeof props.nodeExtent !== 'undefined') { - store?.setNodeExtent(props.nodeExtent as any); + if (typeof nodeExtent !== 'undefined') { + store?.setNodeExtent(nodeExtent); } }); onMounted(() => { - if (typeof props.nodesConnectable !== 'undefined') { - store?.setNodesConnectable(!!props.nodesConnectable); + if (typeof nodesConnectable !== 'undefined') { + store?.setNodesConnectable(!!nodesConnectable); } }); onMounted(() => { - if (typeof props.elementsSelectable !== 'undefined') { - store?.setElementsSelectable(!!props.elementsSelectable); + if (typeof elementsSelectable !== 'undefined') { + store?.setElementsSelectable(!!elementsSelectable); } - if (typeof props.connectionMode !== 'undefined') { - store?.setConnectionMode(props.connectionMode as any); + if (typeof connectionMode !== 'undefined') { + store?.setConnectionMode(connectionMode); } }); return () => ( ); diff --git a/src/container/RevueFlow/index.tsx b/src/container/RevueFlow/index.tsx index 57146f85..c9d3fd7c 100644 --- a/src/container/RevueFlow/index.tsx +++ b/src/container/RevueFlow/index.tsx @@ -1,4 +1,14 @@ -import { computed, CSSProperties, defineComponent, HTMLAttributes, onBeforeUnmount, onUpdated, PropType, provide } from 'vue'; +import { + computed, + CSSProperties, + defineComponent, + HTMLAttributes, + onBeforeUnmount, + PropType, + provide, + reactive, + watchEffect +} from 'vue'; import GraphView from '../GraphView'; import DefaultNode from '../../components/Nodes/DefaultNode'; import InputNode from '../../components/Nodes/InputNode'; @@ -25,7 +35,8 @@ import { KeyCode, PanOnScrollMode, OnEdgeUpdateFunc, - NodeExtent + NodeExtent, + RevueFlowStore } from '../../types'; import '../../style.css'; import '../../theme-default.css'; @@ -147,104 +158,104 @@ const RevueFlow = defineComponent({ default: () => defaultEdgeTypes }, onMove: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onMoveStart: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onMoveEnd: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onLoad: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onElementClick: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onNodeDoubleClick: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onEdgeDoubleClick: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onNodeMouseEnter: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onNodeMouseMove: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onNodeMouseLeave: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onNodeContextMenu: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onNodeDragStart: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onNodeDrag: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onNodeDragStop: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onSelectionContextMenu: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onElementsRemove: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onConnect: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onConnectStart: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onConnectStop: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onConnectEnd: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, connectionMode: { type: String as PropType, @@ -264,7 +275,7 @@ const RevueFlow = defineComponent({ connectionLineComponent: { type: Object as PropType, required: false, - default: undefined as any + default: undefined }, selectionKeyCode: { type: [Number, String] as PropType, @@ -397,147 +408,308 @@ const RevueFlow = defineComponent({ default: true }, onPaneClick: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onPaneScroll: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onPaneContextMenu: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onEdgeUpdate: { - type: Function() as PropType, + type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onEdgeMouseEnter: { type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onEdgeContextMenu: { type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onEdgeMouseMove: { type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onEdgeMouseLeave: { type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onEdgeUpdateEnd: { type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined }, onEdgeUpdateStart: { type: Function as unknown as PropType, required: false, - default: undefined as any + default: undefined + }, + onSelectionDragStart: { + type: Function as unknown as PropType, + required: false, + default: undefined + }, + onSelectionDrag: { + type: Function as unknown as PropType, + required: false, + default: undefined + }, + onSelectionDragStop: { + type: Function as unknown as PropType, + required: false, + default: undefined + }, + onSelectionChange: { + type: Function as unknown as PropType, + required: false, + default: undefined }, edgeUpdaterRadius: { type: Number as PropType, required: false, default: 10 + }, + onDrop: { + type: Function as unknown as PropType<(e: DragEvent) => any>, + required: false, + default: undefined as any + }, + onDragover: { + type: Function as unknown as PropType<(e: DragEvent) => any>, + required: false, + default: undefined as any } + + /* // focus events + onFocus: FocusEvent, + onFocusin: FocusEvent, + onFocusout: FocusEvent, + onBlur: FocusEvent, + + // keyboard events + onKeydown: KeyboardEvent, + onKeypress: KeyboardEvent, + onKeyup: KeyboardEvent, + + // mouse events + onAuxclick: MouseEvent, + onClick: MouseEvent, + onContextmenu: MouseEvent, + onDblclick: MouseEvent, + onMousedown: MouseEvent, + onMouseenter: MouseEvent, + onMouseleave: MouseEvent, + onMousemove: MouseEvent, + onMouseout: MouseEvent, + onMouseover: MouseEvent, + onMouseup: MouseEvent, + + // selection events + onSelect: Event, + + // UI events + onScroll: UIEvent, + + // touch events + onTouchcancel: TouchEvent, + onTouchend: TouchEvent, + onTouchmove: TouchEvent, + onTouchstart: TouchEvent, + + // pointer events + onPointerdown: PointerEvent, + onPointermove: PointerEvent, + onPointerup: PointerEvent, + onPointercancel: PointerEvent, + onPointerenter: PointerEvent, + onPointerleave: PointerEvent, + onPointerover: PointerEvent, + onPointerout: PointerEvent, + + // wheel events + onWheel: WheelEvent, + + // transition events + onTransitionend: TransitionEvent, + onTransitionstart: TransitionEvent, + */ }, setup(props, { slots }) { + const { + elements = [], + nodeTypes = defaultNodeTypes, + edgeTypes = defaultEdgeTypes, + onElementClick, + onLoad, + onMove, + onMoveStart, + onMoveEnd, + onElementsRemove, + onConnect, + onConnectStart, + onConnectStop, + onConnectEnd, + onNodeMouseEnter, + onNodeMouseMove, + onNodeMouseLeave, + onNodeContextMenu, + onNodeDoubleClick, + onNodeDragStart, + onNodeDrag, + onNodeDragStop, + onSelectionChange, + onSelectionDragStart, + onSelectionDrag, + onSelectionDragStop, + onSelectionContextMenu, + connectionMode = ConnectionMode.Strict, + connectionLineType = ConnectionLineType.Bezier, + connectionLineStyle, + connectionLineComponent, + deleteKeyCode = 'Backspace', + selectionKeyCode = 'Shift', + multiSelectionKeyCode = 'Meta', + zoomActivationKeyCode = 'Meta', + snapToGrid = false, + snapGrid = [15, 15], + onlyRenderVisibleElements = false, + selectNodesOnDrag = true, + nodesDraggable, + nodesConnectable, + elementsSelectable, + minZoom, + maxZoom, + defaultZoom = 1, + defaultPosition = [0, 0], + translateExtent, + nodeExtent, + arrowHeadColor = '#b1b1b7', + markerEndId, + zoomOnScroll = true, + zoomOnPinch = true, + panOnScroll = false, + panOnScrollSpeed = 0.5, + panOnScrollMode = PanOnScrollMode.Free, + zoomOnDoubleClick = true, + paneMoveable = true, + onPaneClick, + onPaneScroll, + onPaneContextMenu, + onEdgeUpdate, + onEdgeContextMenu, + onEdgeDoubleClick, + onEdgeMouseEnter, + onEdgeMouseMove, + onEdgeMouseLeave, + onEdgeUpdateStart, + onEdgeUpdateEnd, + edgeUpdaterRadius = 10, + nodeTypesId = '1', + edgeTypesId = '1', + ...rest + } = reactive(props); const store = configureStore(initialState)(); - provide('store', store); - store.setElements(props.elements); - onUpdated(() => { - store.setElements(props.elements); + provide('store', store); + store.setElements(elements); + + watchEffect(() => { + store.setElements(elements); + onSelectionChange?.(store.selectedElements); }); onBeforeUnmount(() => { store.$reset(); store.setElements([]); }); - const nodeTypesParsed = computed(() => props.nodeTypes && createNodeTypes(props.nodeTypes)); - const edgeTypesParsed = computed(() => props.edgeTypes && createEdgeTypes(props.edgeTypes)); + const nodeTypesParsed = computed(() => nodeTypes && createNodeTypes(nodeTypes)); + const edgeTypesParsed = computed(() => edgeTypes && createEdgeTypes(edgeTypes)); return () => ( -
+
{slots.default ? slots.default() : ''}
); } }); - export default RevueFlow; diff --git a/src/store/configure-store.ts b/src/store/configure-store.ts index 6bdef40a..fbca1eba 100644 --- a/src/store/configure-store.ts +++ b/src/store/configure-store.ts @@ -206,11 +206,9 @@ export default function configureStore( this.userSelectionRect.draw = false; if (!selectedNodes || selectedNodes.length === 0) { - console.log('Foo'); this.selectedElements = null; this.nodesSelectionActive = false; } else { - console.log('bar'); this.selectedNodesBbox = getRectOfNodes(selectedNodes); this.nodesSelectionActive = true; } diff --git a/src/utils/index.ts b/src/utils/index.ts index 12544a4c..5377cab5 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,7 +1,7 @@ import { Dimensions, XYPosition, NodeExtent } from '../types'; import { DraggableEvent } from '@braks/revue-draggable'; -export const isInputDOMNode = (e: MouseEvent | DraggableEvent | KeyboardEvent): boolean => { +export const isInputDOMNode = (e: KeyboardEvent | DraggableEvent['event']): boolean => { const target = e.target as HTMLElement; return ['INPUT', 'SELECT', 'TEXTAREA', 'BUTTON'].includes(target.nodeName) || target.hasAttribute('contentEditable'); }; diff --git a/yarn.lock b/yarn.lock index 9107211f..31c062ff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -262,10 +262,10 @@ "@babel/helper-validator-identifier" "^7.14.5" to-fast-properties "^2.0.0" -"@braks/revue-draggable@^0.1.3": - version "0.1.3" - resolved "https://registry.yarnpkg.com/@braks/revue-draggable/-/revue-draggable-0.1.3.tgz#837a46bde7c87f8f6642ed4fb85697653ee6d068" - integrity sha512-9Ad35cUzkuaC7wTXSpJIYAH2kmgIh/VtL062MXTiFZ9OIZxAUMUfCnIgDTWY0sZNoxmO8CPD3XUP/YfbxoMESQ== +"@braks/revue-draggable@^0.1.10": + version "0.1.10" + resolved "https://registry.yarnpkg.com/@braks/revue-draggable/-/revue-draggable-0.1.10.tgz#d6c7de3de44f1fbce09b37ba35a80100418850ba" + integrity sha512-m8cXb1NADAYQxhNUqfrzIhlvRPacaBEy/J8FVemkQCZLhzd5lHUMaTv+5hiYRgljXcoRLWO21HF4NtqWZ1kQuw== dependencies: vue-demi latest