react-dag-editor
Advanced tools
Comparing version 0.3.9 to 0.4.0
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "0.3.9", | ||
"version": "0.4.0", | ||
"dependencies": { | ||
@@ -10,0 +10,0 @@ "@fluentui/merge-styles": "^8.2.0", |
@@ -5,3 +5,2 @@ import * as React from "react"; | ||
import type { EventChannel } from "../utils/eventChannel"; | ||
import { IGraphState } from "../models/state"; | ||
export interface IGetCanvasKeyboardEventHandlers { | ||
@@ -11,3 +10,2 @@ featureControl: ReturnType<typeof useFeatureControl>; | ||
graphConfig: IGraphConfig; | ||
graphState: IGraphState; | ||
setCurHoverNode(nodeId: string | undefined): void; | ||
@@ -14,0 +12,0 @@ setCurHoverPort(value: [string, string] | undefined): void; |
@@ -7,4 +7,2 @@ import * as React from "react"; | ||
import { metaControl } from "../utils/keyboard"; | ||
import { isSelected } from "../models/status"; | ||
import { IGraphState } from "../models/state"; | ||
@@ -15,3 +13,2 @@ export interface IGetCanvasKeyboardEventHandlers { | ||
graphConfig: IGraphConfig; | ||
graphState: IGraphState; | ||
setCurHoverNode(nodeId: string | undefined): void; | ||
@@ -27,3 +24,2 @@ setCurHoverPort(value: [string, string] | undefined): void; | ||
graphConfig, | ||
graphState, | ||
setCurHoverNode, | ||
@@ -53,6 +49,2 @@ setCurHoverPort, | ||
type: GraphCanvasEvent.Delete, | ||
data: { | ||
nodes: graphState.data.present.nodes.filter(isSelected), | ||
edges: graphState.data.present.edges.filter(isSelected), | ||
}, | ||
}); | ||
@@ -191,3 +183,2 @@ | ||
graphConfig, | ||
graphState, | ||
isDeleteDisabled, | ||
@@ -194,0 +185,0 @@ isPasteDisabled, |
import { MutableRefObject, RefObject } from "react"; | ||
import { IContainerRect } from "../models/geometry"; | ||
import { IGraphState } from "../models/state"; | ||
import { EventChannel } from "../utils/eventChannel"; | ||
export declare const useUpdateViewportCallback: (rectRef: MutableRefObject<IContainerRect | undefined>, svgRef: RefObject<SVGSVGElement>, eventChannel: EventChannel) => () => void; | ||
export declare const useContainerRect: (svgRef: RefObject<SVGSVGElement>, containerRef: RefObject<HTMLDivElement>, updateViewport: () => void) => void; | ||
export declare const useUpdateViewportCallback: (rectRef: MutableRefObject<IContainerRect | undefined>, svgRef: RefObject<SVGSVGElement>, eventChannel: EventChannel) => (force?: boolean) => void; | ||
export declare const useContainerRect: (state: IGraphState, svgRef: RefObject<SVGSVGElement>, containerRef: RefObject<HTMLDivElement>, updateViewport: (force?: boolean) => void) => void; |
@@ -10,2 +10,3 @@ import { | ||
import { IContainerRect } from "../models/geometry"; | ||
import { IGraphState } from "../models/state"; | ||
import { debounce } from "../utils"; | ||
@@ -22,8 +23,8 @@ import { EventChannel } from "../utils/eventChannel"; | ||
): boolean => { | ||
if (a === b) { | ||
return false; | ||
} | ||
if (!a || !b) { | ||
return true; | ||
} | ||
if (a === b) { | ||
return false; | ||
} | ||
return ( | ||
@@ -42,19 +43,27 @@ a.top !== b.top || | ||
) => | ||
useCallback((): void => { | ||
const viewportRect = svgRef.current?.getBoundingClientRect(); | ||
if (isRectChanged(rectRef.current, viewportRect)) { | ||
rectRef.current = viewportRect; | ||
eventChannel.trigger({ | ||
type: GraphCanvasEvent.ViewportResize, | ||
viewportRect, | ||
}); | ||
} | ||
}, [eventChannel, rectRef, svgRef]); | ||
useCallback( | ||
(force = false): void => { | ||
const viewportRect = svgRef.current?.getBoundingClientRect(); | ||
if (force || isRectChanged(rectRef.current, viewportRect)) { | ||
rectRef.current = viewportRect; | ||
eventChannel.trigger({ | ||
type: GraphCanvasEvent.ViewportResize, | ||
viewportRect, | ||
}); | ||
} | ||
}, | ||
[eventChannel, rectRef, svgRef] | ||
); | ||
export const useContainerRect = ( | ||
state: IGraphState, | ||
svgRef: RefObject<SVGSVGElement>, | ||
containerRef: RefObject<HTMLDivElement>, | ||
updateViewport: () => void | ||
updateViewport: (force?: boolean) => void | ||
): void => { | ||
useLayoutEffect(updateViewport, [updateViewport]); | ||
useLayoutEffect(() => { | ||
if (!state.viewport.rect) { | ||
updateViewport(true); | ||
} | ||
}, [updateViewport, state.viewport.rect]); | ||
@@ -61,0 +70,0 @@ useEffect(() => { |
@@ -108,3 +108,2 @@ import * as React from "react"; | ||
graphConfig, | ||
graphState: graphController.state, | ||
setCurHoverNode, | ||
@@ -111,0 +110,0 @@ setCurHoverPort, |
@@ -13,3 +13,2 @@ import * as React from "react"; | ||
import { IGraphSettings } from "./state"; | ||
import { HashMap, OrderedMap } from "../collections"; | ||
interface IEventBase<E = Event | React.SyntheticEvent> { | ||
@@ -199,11 +198,4 @@ rawEvent: E; | ||
export interface ICanvasSimpleEvent { | ||
type: GraphCanvasEvent.UpdateNodeSelectionBySelectBox | GraphCanvasEvent.Copy | GraphCanvasEvent.Undo | GraphCanvasEvent.Redo | GraphCanvasEvent.ResetSelection | GraphCanvasEvent.ResetUndoStack; | ||
type: GraphCanvasEvent.UpdateNodeSelectionBySelectBox | GraphCanvasEvent.Copy | GraphCanvasEvent.Undo | GraphCanvasEvent.Redo | GraphCanvasEvent.Delete | GraphCanvasEvent.ResetSelection | GraphCanvasEvent.ResetUndoStack; | ||
} | ||
export interface ICanvasDeleteEvent<NodeData = unknown, EdgeData = unknown, PortData = unknown> { | ||
type: GraphCanvasEvent.Delete; | ||
data: { | ||
nodes: OrderedMap<string, NodeModel<NodeData, PortData>>; | ||
edges: HashMap<string, EdgeModel<EdgeData>>; | ||
}; | ||
} | ||
export interface ICanvasPasteEvent<NodeData = unknown, EdgeData = unknown, PortData = unknown> { | ||
@@ -253,3 +245,3 @@ type: GraphCanvasEvent.Paste; | ||
} | ||
export type ICanvasEvent<NodeData = unknown, EdgeData = unknown, PortData = unknown> = ICanvasCommonEvent | ICanvasViewportResizeEvent | ICanvasNavigateEvent<NodeData, PortData> | ICanvasVirtualizationEvent | ICanvasZoomEvent | ICanvasPanEvent | ICanvasPinchEvent | ICanvasSelectStartEvent | ICanvasSelectMoveEvent | ICanvasUpdateNodeSelectionBySelectBoxEvent | ICanvasSimpleEvent | ICanvasDeleteEvent<NodeData, EdgeData, PortData> | ICanvasPasteEvent<NodeData, EdgeData, PortData> | ICanvasKeyboardEvent | ICanvasAddNodeEvent | ICanvasAddEndNodeEvent | IScrollIntoViewEvent | ICanvasResetViewportEvent | ICanvasZoomToEvent | ICanvasZoomToFitEvent | ICanvasSetDataEvent | ICanvasUpdateDataEvent | ICanvasScrollToEvent; | ||
export type ICanvasEvent<NodeData = unknown, EdgeData = unknown, PortData = unknown> = ICanvasCommonEvent | ICanvasViewportResizeEvent | ICanvasNavigateEvent<NodeData, PortData> | ICanvasVirtualizationEvent | ICanvasZoomEvent | ICanvasPanEvent | ICanvasPinchEvent | ICanvasSelectStartEvent | ICanvasSelectMoveEvent | ICanvasUpdateNodeSelectionBySelectBoxEvent | ICanvasSimpleEvent | ICanvasPasteEvent<NodeData, EdgeData, PortData> | ICanvasKeyboardEvent | ICanvasAddNodeEvent | ICanvasAddEndNodeEvent | IScrollIntoViewEvent | ICanvasResetViewportEvent | ICanvasZoomToEvent | ICanvasZoomToFitEvent | ICanvasSetDataEvent | ICanvasUpdateDataEvent | ICanvasScrollToEvent; | ||
export interface INodeCommonEvent<NodeData = unknown, PortData = unknown> extends IEventBase { | ||
@@ -256,0 +248,0 @@ type: Exclude<GraphNodeEvent, GraphNodeEvent.Resizing | GraphNodeEvent.DragStart | GraphNodeEvent.Drag | GraphNodeEvent.DragEnd | GraphNodeEvent.Click | GraphNodeEvent.SelectAll | GraphNodeEvent.Centralize | GraphNodeEvent.Locate | GraphNodeEvent.Add | GraphNodeEvent.ContextMenu | GraphNodeEvent.Select>; |
@@ -13,3 +13,2 @@ import * as React from "react"; | ||
import { IGraphSettings } from "./state"; | ||
import { HashMap, OrderedMap } from "../collections"; | ||
@@ -257,2 +256,3 @@ interface IEventBase<E = Event | React.SyntheticEvent> { | ||
| GraphCanvasEvent.Redo | ||
| GraphCanvasEvent.Delete | ||
| GraphCanvasEvent.ResetSelection | ||
@@ -262,14 +262,2 @@ | GraphCanvasEvent.ResetUndoStack; | ||
export interface ICanvasDeleteEvent< | ||
NodeData = unknown, | ||
EdgeData = unknown, | ||
PortData = unknown | ||
> { | ||
type: GraphCanvasEvent.Delete; | ||
data: { | ||
nodes: OrderedMap<string, NodeModel<NodeData, PortData>>; | ||
edges: HashMap<string, EdgeModel<EdgeData>>; | ||
}; | ||
} | ||
export interface ICanvasPasteEvent< | ||
@@ -362,3 +350,2 @@ NodeData = unknown, | ||
| ICanvasSimpleEvent | ||
| ICanvasDeleteEvent<NodeData, EdgeData, PortData> | ||
| ICanvasPasteEvent<NodeData, EdgeData, PortData> | ||
@@ -365,0 +352,0 @@ | ICanvasKeyboardEvent |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1581483
49674