Open linonetwo opened 12 months ago
Type that I'm using in src/type.d.ts
declare module 'the-graph' {
import { Graph, GraphEdge, GraphNode } from 'fbp-graph';
import { MutableRefObject } from 'react';
import { Component as NoFloComponent } from 'noflo';
import { JSONSchema7Type } from 'json-schema';
export interface ITheGraphEditorContextMenuOptions {
element: ITheGraphEditor;
graph: Graph;
item: Graph | GraphNode | GraphEdge;
itemKey: 'graph' | 'node' | 'edge';
/**
* Keyof this.props.menus
* For example, `'main'`
*/
type: string;
x?: number;
y?: number;
}
export interface ITheGraphProps {
contextMenu?: contextMenu;
getEditorRef?: MutableRefObject<ITheGraphEditor | undefined>;
getMenuDef?: (options: ITheGraphEditorContextMenuOptions) => any;
graph: Graph;
height: number | string;
library?: IFBPLibrary;
offsetX?: number;
onEdgeSelection: (edgeID: string, edge: any, toggle: boolean) => void;
onNodeSelection: (nodeID: string, node: any, toggle: boolean) => void;
onPanScale: (x: number, y: number, scale: number) => void;
readonly: boolean;
width: number | string;
}
export interface ITheGraphEditorState {
height: number;
maxZoom: number;
minZoom: number;
scale: number;
tooltip: string;
tooltipVisible: boolean;
tooltipX: number;
tooltipY: number;
trackStartX: number | null;
trackStartY: number | null;
width: number;
x: number;
y: number;
}
/**
* Things accessible in the-graph/the-graph-app.js
*/
export interface ITheGraphEditor {
debounceLibraryRefesh: () => void;
dirty: boolean;
focusNode: (node: GraphNode) => void;
getComponent: (name: string) => void;
hideContext: () => void;
lastScale: number;
lastX: number;
lastY: number;
library: IFBPLibrary;
libraryDirty: boolean;
pinching: boolean;
refs: {
graph?: ITheGraphEditorGraph;
};
registerComponent: (definition: NoFloComponent, generated: boolean) => void;
/**
* This is undefined, because it is in the-graph/the-graph-graph.js
* Set the preview bounding rect by drag event
* In the-graph/the-graph-graph.js
* ```js
* appDomNode.addEventListener('mousemove', this.renderPreviewEdge);
* appDomNode.addEventListener('panmove', this.renderPreviewEdge);
* appDomNode.addEventListener('tap', this.cancelPreviewEdge);
*/
renderPreviewEdge?: (event: MouseEvent | TouchEvent) => void;
rerender: () => void;
setState: (state: Partial<ITheGraphEditorState>) => void;
showContext: (options: ITheGraphEditorContextMenuOptions) => void;
state: ITheGraphEditorState;
theme: 'dark' | 'light';
triggerAutolayout: () => void;
triggerFit: () => void;
unselectAll: () => void;
zoomFactor: number;
zoomX: number;
zoomY: number;
} export interface ITheGraphEditorGraphState { animatedEdges: GraphEdge[]; displaySelectionGroup: boolean; edgePreview: GraphEdge | null; edgePreviewX: number; edgePreviewY: number; errorNodes: GraphNode[]; forceSelection: boolean; offsetX: number; offsetY: number; selectedEdges: GraphEdge[]; selectedNodes: GraphNode[]; } export interface ITheGraphEditorGraphProps { app: ITheGraphEditor | null; graph: Graph; library: IFBPLibrary; // allows overriding icon of a node nodeIcons: Record<string, string>; offsetX: number; offsetY: number; } export interface ITheGraphEditorGraph { addEdge: Function; cancelPreviewEdge: Function; context: {}; dirty: false; edgeStart: Function; getComponentInfo: Function; getGraphInport: Function; getGraphOutport: Function; getNodeInport: Function; getNodeOutport: Function; getPorts: Function; markDirty: Function; mounted: true; moveGroup: Function; /**
*/
portInfo?: Record<string, { inports: INoFloProtocolComponentPort[]; outports: INoFloProtocolComponentPort[] }>;
props: ITheGraphEditorGraphProps;
refs: {};
renderPreviewEdge: Function;
resetPortRoute: Function;
setAnimatedEdges: Function;
setErrorNodes: Function;
setSelectedEdges: Function;
setSelectedNodes: Function;
state: ITheGraphEditorGraphState;
subscribeGraph: Function;
triggerRender: Function;
updateIcon: Function;
}
export function App(props: ITheGraphProps): JSX.Element;
export interface INoFloProtocolComponentPort {
addressable?: boolean;
/**
*/
export interface INoFloUIComponentPort extends Omit<INoFloProtocolComponentPort, 'id'> {
name: string;
}
function componentsFromGraph(graph: Graph): INoFloUIComponent[];
export interface INoFloUIComponent {
description: string;
icon: string;
inports?: INoFloUIComponentPort[];
name: string;
outports?: INoFloUIComponentPort[];
/**
True means this is not a Elementary component */ subgraph?: boolean; unnamespaced?: boolean; } export interface INoFloProtocolComponent extends Omit<INoFloUIComponent, 'inports' | 'outports'> { inPorts?: INoFloProtocolComponentPort[]; outPorts?: INoFloProtocolComponentPort[]; } export type IFBPLibrary = Record<string, INoFloUIComponent>; function libraryFromGraph(graph: Graph): IFBPLibrary;
export const library = { componentsFromGraph, libraryFromGraph, };
function styleFromTheme(theme: 'dark' | 'light'): {
height: number;
lineWidth: number;
nodeSize: number;
width: number;
};
function renderThumbnail(contextcontext: CanvasRenderingContext2D | null, graph: Graph, properties: ReturnType
export interface ITheGraphNavProps { graph: Graph; height: number; onPanTo?: (panTo: { x: number; y: number; }, event: MouseEvent) => void; onTap?: () => void; viewrectangle?: number[]; viewscale: number; width: number; } function NavComponent(props: ITheGraphNavProps): JSX.Element; export const nav = { Component: NavComponent, };
/**
npm run fontawesome
module.exports = {
'500px': '',
'address-book': '',
'address-book-o': '',
*/
export const FONT_AWESOME: Record<string, string>;
/*
{ snap: 36 }
in noflo-ui example.
*/
function applyAutolayout(graph: Graph, keilerGraph, props: { snap: number }): void;
export const autolayout = {
applyToGraph: applyAutolayout,
};
}
declare module 'the-graph/the-graph-nav/the-graph-nav' {
import { nav } from 'the-graph';
export const Component = nav.Component;
}declare module 'the-graph/the-graph/the-graph-autolayout' { import { autolayout } from 'the-graph'; // eslint-disable-next-line unicorn/prefer-export-from export default autolayout; }
declare module 'klayjs-noflo/klay-noflo' { import { Graph } from 'fbp-graph'; export interface IKlayLayoutOptions { direction: string; graph: Graph; options: { algorithm: string; borderSpacing: number; crossMin: string; direction: string; edgeRouting: string; edgeSpacingFactor: number; inLayerSpacingFactor: number; intCoordinates: boolean; layoutHierarchy: boolean; nodeLayering: string; nodePlace: string; spacing: number; }; portInfo: | Record<string, { inports: INoFloProtocolComponentPort[]; outports: INoFloProtocolComponentPort[]; }> | undefined; } export const klayNoflo: { init(options: { onSuccess: (keilerGraph: unknown) => void; workerScript: string }): typeof klayNoflo; layout(options: IKlayLayoutOptions): void; }; }
Giving typescript typing can let developer better understand waht props this react component needs.
Currently, it is hard to embed this react component due to lack of example and typing, thanks.