refactor(types): rename ActionTypes to ReactFlowActionTypes
This commit is contained in:
@@ -2,7 +2,7 @@ import { useEffect } from 'react';
|
|||||||
|
|
||||||
import { useStore, useStoreActions } from '../store/hooks';
|
import { useStore, useStoreActions } from '../store/hooks';
|
||||||
import useKeyPress from './useKeyPress';
|
import useKeyPress from './useKeyPress';
|
||||||
import { isNode, getConnectedEdges } from '../utils/graph';
|
import { isNode, getConnectedEdges, isEdge } from '../utils/graph';
|
||||||
import { Elements, KeyCode, ElementId, FlowElement } from '../types';
|
import { Elements, KeyCode, ElementId, FlowElement } from '../types';
|
||||||
|
|
||||||
interface HookParams {
|
interface HookParams {
|
||||||
@@ -22,7 +22,8 @@ export default ({ deleteKeyCode, multiSelectionKeyCode, onElementsRemove }: Hook
|
|||||||
const multiSelectionKeyPressed = useKeyPress(multiSelectionKeyCode);
|
const multiSelectionKeyPressed = useKeyPress(multiSelectionKeyCode);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const { edges, selectedElements } = store.getState();
|
const { elements, selectedElements } = store.getState();
|
||||||
|
const edges = elements.filter(isEdge);
|
||||||
|
|
||||||
if (onElementsRemove && deleteKeyPressed && selectedElements) {
|
if (onElementsRemove && deleteKeyPressed && selectedElements) {
|
||||||
const selectedNodes = selectedElements.filter(isNode);
|
const selectedNodes = selectedElements.filter(isNode);
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ interface SetConnectionMode {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ActionTypes =
|
export type ReactFlowActionTypes =
|
||||||
| OnConnectAction
|
| OnConnectAction
|
||||||
| OnConnectStartAction
|
| OnConnectStartAction
|
||||||
| OnConnectStopAction
|
| OnConnectStopAction
|
||||||
|
|||||||
+34
-34
@@ -18,7 +18,7 @@ import {
|
|||||||
} from '../types';
|
} from '../types';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ActionTypes,
|
ReactFlowActionTypes,
|
||||||
SET_ON_CONNECT,
|
SET_ON_CONNECT,
|
||||||
SET_ON_CONNECT_START,
|
SET_ON_CONNECT_START,
|
||||||
SET_ON_CONNECT_STOP,
|
SET_ON_CONNECT_STOP,
|
||||||
@@ -53,112 +53,112 @@ import {
|
|||||||
SET_CONNECTION_MODE,
|
SET_CONNECTION_MODE,
|
||||||
} from './action-types';
|
} from './action-types';
|
||||||
|
|
||||||
export const setOnConnect = (onConnect: OnConnectFunc): ActionTypes => ({
|
export const setOnConnect = (onConnect: OnConnectFunc): ReactFlowActionTypes => ({
|
||||||
type: SET_ON_CONNECT,
|
type: SET_ON_CONNECT,
|
||||||
payload: {
|
payload: {
|
||||||
onConnect,
|
onConnect,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const setOnConnectStart = (onConnectStart: OnConnectStartFunc): ActionTypes => ({
|
export const setOnConnectStart = (onConnectStart: OnConnectStartFunc): ReactFlowActionTypes => ({
|
||||||
type: SET_ON_CONNECT_START,
|
type: SET_ON_CONNECT_START,
|
||||||
payload: {
|
payload: {
|
||||||
onConnectStart,
|
onConnectStart,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const setOnConnectStop = (onConnectStop: OnConnectStopFunc): ActionTypes => ({
|
export const setOnConnectStop = (onConnectStop: OnConnectStopFunc): ReactFlowActionTypes => ({
|
||||||
type: SET_ON_CONNECT_STOP,
|
type: SET_ON_CONNECT_STOP,
|
||||||
payload: {
|
payload: {
|
||||||
onConnectStop,
|
onConnectStop,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const setOnConnectEnd = (onConnectEnd: OnConnectEndFunc): ActionTypes => ({
|
export const setOnConnectEnd = (onConnectEnd: OnConnectEndFunc): ReactFlowActionTypes => ({
|
||||||
type: SET_ON_CONNECT_END,
|
type: SET_ON_CONNECT_END,
|
||||||
payload: {
|
payload: {
|
||||||
onConnectEnd,
|
onConnectEnd,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const setElements = (elements: Elements): ActionTypes => ({
|
export const setElements = (elements: Elements): ReactFlowActionTypes => ({
|
||||||
type: SET_ELEMENTS,
|
type: SET_ELEMENTS,
|
||||||
elements,
|
elements,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const batchUpdateNodeDimensions = (updates: NodeDimensionUpdate[]): ActionTypes => ({
|
export const batchUpdateNodeDimensions = (updates: NodeDimensionUpdate[]): ReactFlowActionTypes => ({
|
||||||
type: BATCH_UPDATE_NODE_DIMENSIONS,
|
type: BATCH_UPDATE_NODE_DIMENSIONS,
|
||||||
updates,
|
updates,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const updateNodeDimensions = (payload: NodeDimensionUpdate): ActionTypes => ({
|
export const updateNodeDimensions = (payload: NodeDimensionUpdate): ReactFlowActionTypes => ({
|
||||||
type: UPDATE_NODE_DIMENSIONS,
|
type: UPDATE_NODE_DIMENSIONS,
|
||||||
payload,
|
payload,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const updateNodePos = (payload: NodePosUpdate): ActionTypes => ({
|
export const updateNodePos = (payload: NodePosUpdate): ReactFlowActionTypes => ({
|
||||||
type: UPDATE_NODE_POS,
|
type: UPDATE_NODE_POS,
|
||||||
payload,
|
payload,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const updateNodePosDiff = (payload: NodeDiffUpdate): ActionTypes => ({
|
export const updateNodePosDiff = (payload: NodeDiffUpdate): ReactFlowActionTypes => ({
|
||||||
type: UPDATE_NODE_POS_DIFF,
|
type: UPDATE_NODE_POS_DIFF,
|
||||||
payload,
|
payload,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const setUserSelection = (mousePos: XYPosition): ActionTypes => ({
|
export const setUserSelection = (mousePos: XYPosition): ReactFlowActionTypes => ({
|
||||||
type: SET_USER_SELECTION,
|
type: SET_USER_SELECTION,
|
||||||
mousePos,
|
mousePos,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const updateUserSelection = (mousePos: XYPosition): ActionTypes => ({
|
export const updateUserSelection = (mousePos: XYPosition): ReactFlowActionTypes => ({
|
||||||
type: SET_USER_SELECTION,
|
type: SET_USER_SELECTION,
|
||||||
mousePos,
|
mousePos,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const unsetUserSelection = (): ActionTypes => ({
|
export const unsetUserSelection = (): ReactFlowActionTypes => ({
|
||||||
type: UNSET_USER_SELECTION,
|
type: UNSET_USER_SELECTION,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const setSelection = (selectionActive: boolean): ActionTypes => ({
|
export const setSelection = (selectionActive: boolean): ReactFlowActionTypes => ({
|
||||||
type: SET_SELECTION,
|
type: SET_SELECTION,
|
||||||
payload: {
|
payload: {
|
||||||
selectionActive,
|
selectionActive,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const unsetNodesSelection = (): ActionTypes => ({
|
export const unsetNodesSelection = (): ReactFlowActionTypes => ({
|
||||||
type: UNSET_NODES_SELECTION,
|
type: UNSET_NODES_SELECTION,
|
||||||
payload: {
|
payload: {
|
||||||
nodesSelectionActive: false,
|
nodesSelectionActive: false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const resetSelectedElements = (): ActionTypes => ({
|
export const resetSelectedElements = (): ReactFlowActionTypes => ({
|
||||||
type: RESET_SELECTED_ELEMENTS,
|
type: RESET_SELECTED_ELEMENTS,
|
||||||
payload: {
|
payload: {
|
||||||
selectedElements: null,
|
selectedElements: null,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const setSelectedElements = (elements: Elements): ActionTypes => ({
|
export const setSelectedElements = (elements: Elements): ReactFlowActionTypes => ({
|
||||||
type: SET_SELECTED_ELEMENTS,
|
type: SET_SELECTED_ELEMENTS,
|
||||||
elements,
|
elements,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const addSelectedElements = (elements: Elements): ActionTypes => ({
|
export const addSelectedElements = (elements: Elements): ReactFlowActionTypes => ({
|
||||||
type: ADD_SELECTED_ELEMENTS,
|
type: ADD_SELECTED_ELEMENTS,
|
||||||
elements,
|
elements,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const updateTransform = (transform: Transform): ActionTypes => ({
|
export const updateTransform = (transform: Transform): ReactFlowActionTypes => ({
|
||||||
type: UPDATE_TRANSFORM,
|
type: UPDATE_TRANSFORM,
|
||||||
payload: {
|
payload: {
|
||||||
transform,
|
transform,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const updateSize = (size: Dimensions): ActionTypes => ({
|
export const updateSize = (size: Dimensions): ReactFlowActionTypes => ({
|
||||||
type: UPDATE_SIZE,
|
type: UPDATE_SIZE,
|
||||||
payload: {
|
payload: {
|
||||||
width: size.width || 500,
|
width: size.width || 500,
|
||||||
@@ -166,47 +166,47 @@ export const updateSize = (size: Dimensions): ActionTypes => ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const initD3Zoom = (payload: InitD3ZoomPayload): ActionTypes => ({
|
export const initD3Zoom = (payload: InitD3ZoomPayload): ReactFlowActionTypes => ({
|
||||||
type: INIT_D3ZOOM,
|
type: INIT_D3ZOOM,
|
||||||
payload,
|
payload,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const setMinZoom = (minZoom: number): ActionTypes => ({
|
export const setMinZoom = (minZoom: number): ReactFlowActionTypes => ({
|
||||||
type: SET_MINZOOM,
|
type: SET_MINZOOM,
|
||||||
payload: { minZoom },
|
payload: { minZoom },
|
||||||
});
|
});
|
||||||
|
|
||||||
export const setMaxZoom = (maxZoom: number): ActionTypes => ({
|
export const setMaxZoom = (maxZoom: number): ReactFlowActionTypes => ({
|
||||||
type: SET_MAXZOOM,
|
type: SET_MAXZOOM,
|
||||||
payload: { maxZoom },
|
payload: { maxZoom },
|
||||||
});
|
});
|
||||||
|
|
||||||
export const setTranslateExtent = (translateExtent: TranslateExtent): ActionTypes => ({
|
export const setTranslateExtent = (translateExtent: TranslateExtent): ReactFlowActionTypes => ({
|
||||||
type: SET_TRANSLATEEXTENT,
|
type: SET_TRANSLATEEXTENT,
|
||||||
payload: { translateExtent },
|
payload: { translateExtent },
|
||||||
});
|
});
|
||||||
|
|
||||||
export const setConnectionPosition = (connectionPosition: XYPosition): ActionTypes => ({
|
export const setConnectionPosition = (connectionPosition: XYPosition): ReactFlowActionTypes => ({
|
||||||
type: SET_CONNECTION_POSITION,
|
type: SET_CONNECTION_POSITION,
|
||||||
payload: { connectionPosition },
|
payload: { connectionPosition },
|
||||||
});
|
});
|
||||||
|
|
||||||
export const setConnectionNodeId = (payload: SetConnectionId): ActionTypes => ({
|
export const setConnectionNodeId = (payload: SetConnectionId): ReactFlowActionTypes => ({
|
||||||
type: SET_CONNECTION_NODEID,
|
type: SET_CONNECTION_NODEID,
|
||||||
payload,
|
payload,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const setSnapToGrid = (snapToGrid: boolean): ActionTypes => ({
|
export const setSnapToGrid = (snapToGrid: boolean): ReactFlowActionTypes => ({
|
||||||
type: SET_SNAPTOGRID,
|
type: SET_SNAPTOGRID,
|
||||||
payload: { snapToGrid },
|
payload: { snapToGrid },
|
||||||
});
|
});
|
||||||
|
|
||||||
export const setSnapGrid = (snapGrid: SnapGrid): ActionTypes => ({
|
export const setSnapGrid = (snapGrid: SnapGrid): ReactFlowActionTypes => ({
|
||||||
type: SET_SNAPGRID,
|
type: SET_SNAPGRID,
|
||||||
payload: { snapGrid },
|
payload: { snapGrid },
|
||||||
});
|
});
|
||||||
|
|
||||||
export const setInteractive = (isInteractive: boolean): ActionTypes => ({
|
export const setInteractive = (isInteractive: boolean): ReactFlowActionTypes => ({
|
||||||
type: SET_INTERACTIVE,
|
type: SET_INTERACTIVE,
|
||||||
payload: {
|
payload: {
|
||||||
nodesDraggable: isInteractive,
|
nodesDraggable: isInteractive,
|
||||||
@@ -215,27 +215,27 @@ export const setInteractive = (isInteractive: boolean): ActionTypes => ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const setNodesDraggable = (nodesDraggable: boolean): ActionTypes => ({
|
export const setNodesDraggable = (nodesDraggable: boolean): ReactFlowActionTypes => ({
|
||||||
type: SET_NODES_DRAGGABLE,
|
type: SET_NODES_DRAGGABLE,
|
||||||
payload: { nodesDraggable },
|
payload: { nodesDraggable },
|
||||||
});
|
});
|
||||||
|
|
||||||
export const setNodesConnectable = (nodesConnectable: boolean): ActionTypes => ({
|
export const setNodesConnectable = (nodesConnectable: boolean): ReactFlowActionTypes => ({
|
||||||
type: SET_NODES_CONNECTABLE,
|
type: SET_NODES_CONNECTABLE,
|
||||||
payload: { nodesConnectable },
|
payload: { nodesConnectable },
|
||||||
});
|
});
|
||||||
|
|
||||||
export const setElementsSelectable = (elementsSelectable: boolean): ActionTypes => ({
|
export const setElementsSelectable = (elementsSelectable: boolean): ReactFlowActionTypes => ({
|
||||||
type: SET_ELEMENTS_SELECTABLE,
|
type: SET_ELEMENTS_SELECTABLE,
|
||||||
payload: { elementsSelectable },
|
payload: { elementsSelectable },
|
||||||
});
|
});
|
||||||
|
|
||||||
export const setMultiSelectionActive = (multiSelectionActive: boolean): ActionTypes => ({
|
export const setMultiSelectionActive = (multiSelectionActive: boolean): ReactFlowActionTypes => ({
|
||||||
type: SET_MULTI_SELECTION_ACTIVE,
|
type: SET_MULTI_SELECTION_ACTIVE,
|
||||||
payload: { multiSelectionActive },
|
payload: { multiSelectionActive },
|
||||||
});
|
});
|
||||||
|
|
||||||
export const setConnectionMode = (connectionMode: ConnectionMode): ActionTypes => ({
|
export const setConnectionMode = (connectionMode: ConnectionMode): ReactFlowActionTypes => ({
|
||||||
type: SET_CONNECTION_MODE,
|
type: SET_CONNECTION_MODE,
|
||||||
payload: { connectionMode },
|
payload: { connectionMode },
|
||||||
});
|
});
|
||||||
|
|||||||
+5
-2
@@ -1,4 +1,4 @@
|
|||||||
import { bindActionCreators } from 'redux';
|
import { bindActionCreators, Store } from 'redux';
|
||||||
import { useStore as useStoreRedux, useSelector, useDispatch, TypedUseSelectorHook } from 'react-redux';
|
import { useStore as useStoreRedux, useSelector, useDispatch, TypedUseSelectorHook } from 'react-redux';
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
|
|
||||||
@@ -21,4 +21,7 @@ export function useActions(actionSelector: (value: any) => any): any {
|
|||||||
|
|
||||||
export const useStoreActions = useActions;
|
export const useStoreActions = useActions;
|
||||||
export const useStoreState = useTypedSelector;
|
export const useStoreState = useTypedSelector;
|
||||||
export const useStore = useStoreRedux;
|
export const useStore = (): Store<ReactFlowState, any> => {
|
||||||
|
const store = useStoreRedux<ReactFlowState, any>();
|
||||||
|
return store;
|
||||||
|
};
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { getHandleBounds } from '../components/Nodes/utils';
|
|||||||
|
|
||||||
import { ReactFlowState, FlowElement, Node, XYPosition } from '../types';
|
import { ReactFlowState, FlowElement, Node, XYPosition } from '../types';
|
||||||
import {
|
import {
|
||||||
ActionTypes,
|
ReactFlowActionTypes,
|
||||||
ADD_SELECTED_ELEMENTS,
|
ADD_SELECTED_ELEMENTS,
|
||||||
BATCH_UPDATE_NODE_DIMENSIONS,
|
BATCH_UPDATE_NODE_DIMENSIONS,
|
||||||
INIT_D3ZOOM,
|
INIT_D3ZOOM,
|
||||||
@@ -42,7 +42,7 @@ import {
|
|||||||
|
|
||||||
import { initialState } from './index';
|
import { initialState } from './index';
|
||||||
|
|
||||||
export default function reactFlowReducer(state = initialState, action: ActionTypes): ReactFlowState {
|
export default function reactFlowReducer(state = initialState, action: ReactFlowActionTypes): ReactFlowState {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case SET_ELEMENTS: {
|
case SET_ELEMENTS: {
|
||||||
const propElements = action.elements;
|
const propElements = action.elements;
|
||||||
|
|||||||
Reference in New Issue
Block a user