/** Angular */ import * as ng from "@angular/core"; /** Nested modules */ import { PageBag } from "../page/pageBag"; /** Joint Js*/ import "graphlib"; import "dagre"; import * as joint from "jointjs"; /** Model */ import * as Model from "./nodeEditorModel"; import { PortHighlightedArgs } from "./baseGraphNode"; import { SelectionMode } from "cmf.core/src/domain/extensions/feedback"; import { NodeEditor as NodeEditorBase, LinkOptionClickedEventArgs, LinkStartEventArgs, LinkCancelEventArgs, LinkRemovedEventArgs, LinkConnectedEventArgs, LinkVerticesChangedEventArgs, NodeRemovedEventArgs, NodeCollapsedEventArgs, NodePositionChangedEventArgs, NodeEditorLinkEditArgs, NodeEditorNodeEditArgs, NodeEditorClipboardEvent, TO_REPLACE_WITH_ICON_ID, DEFAULT_DIAGRAM_GRID_SIZE, IN_PORT_GROUP, OUT_PORT_GROUP, MIN_ZOOM, MAX_ZOOM, GRAPH_PAPER_RELATIVE_SIZE_MULTIPLIER, MOUSE_MOVE_THROTTLE_MS } from "./nodeEditorBase"; export { Model, SelectionMode, LinkOptionClickedEventArgs, LinkStartEventArgs, LinkCancelEventArgs, LinkRemovedEventArgs, LinkConnectedEventArgs, LinkVerticesChangedEventArgs, NodeRemovedEventArgs, NodeCollapsedEventArgs, NodePositionChangedEventArgs, NodeEditorLinkEditArgs, NodeEditorNodeEditArgs, NodeEditorClipboardEvent, TO_REPLACE_WITH_ICON_ID, DEFAULT_DIAGRAM_GRID_SIZE, IN_PORT_GROUP, OUT_PORT_GROUP, MIN_ZOOM, MAX_ZOOM, GRAPH_PAPER_RELATIVE_SIZE_MULTIPLIER, MOUSE_MOVE_THROTTLE_MS }; /** * @whatItDoes * * This component is able to by intermediate of a graph (with nodes connected by links) a model consisting on several information * related! The data model has a set of nodes and a set of links. Each link points to two nodes (source and target) * Also nodes have input/output ports where the links will be connected * * The nodes use a component that extends the `BaseGraphNode` component that are used to render the node graphically and give some behavior * * This component offers an API to manage the model (add, remove, edit nodes or links), but also the capacity to control * things like the zoom the pan and some auto-arranging algorithms * * @howToUse * * To use it just include it in a template and provide a dataModel with at least two nodes * (so the user can move the nodes and create/remove links between them) and to the rest of the operations use the * following API through a reference to the instantiated component * * #### API * * getCurrentData() : `NodeEditorModel` - Returns the current data model * * addNode(node: `NodeEditorNode`) : `string` - Adds a new Node to the model and returns its id * * addLink(link: `NodeEditorLink`) : `string` - Adds a new Link to the model and returns its id * * editLink(link: `NodeEditorLinkEditArgs`) : `NodeEditorModel` - Edits a link and returns the updated data model * * editNode(node: `NodeEditorNodeEditArgs`) : `NodeEditorModel` - Edits a node and returns the updated data model * * removeNode(id: `string`) : `boolean` - Removes a Node and returns the success of the operation * * removeLink(id: `string`) : `boolean` - Removes a Link and returns the success of the operation * * applyGridLayout(options: `NodeEditorGridLayoutOptions`) : * `Promise` - Rearrange the nodes in the graph in a grid layout fashion and returns the updated data model * * fitToWindow() : `void` - Adjusts zoom and pan to show all elements in the graph * * toggleCollapseAll(collapsed: `boolean`): `void` - Collapses/Expands all nodes * * zoomIn(): `void` - Zoom in * * zoomOut(): `void` - Zoom out * * setZoom(newZoom: `number`): `void` - Sets a new zoom value * * getCurrentZoom(): `number` - Returns the current zoom value * * setMinZoom(): `void` - Sets the min zoom value * * setMaxZoom(): `void` - Sets the max zoom value * * setPan(h: `number`, v: `number`): `void` - Sets the pan * * panInitial(): `void` - Resets the pan * * getCurrentPan(): `NodeEditorPan` - Returns the current pan * * getLocalMouseCoordinates(): `NodeEditorPoint` - Returns the current mouse coordinates on the graph * * updateComponentProperties(nodeId: string, properties: {[key: string]: any}): `void` - Updates a node input or output properties and triggers changes * * This component is used with the inputs and outputs mentioned below. * * ### Inputs * `function`: **validateLink** - The function used to validate a new link * `NodeEditorModel` : **data** - The model with all the nodes and the links between them * `NodeEditorLinkOption[]` : **linkDefaultOptions** - Default options for the link menu * `boolean` : **canChangeLinks** - Allow to create or remove links (vertices changes are not blocked), defaults true * `SelectionMode` : **selectionMode** - Defines the selection mode for the nodes present in the component (the selection can be none, single or multiple) * * ### Outputs * `NodeEditorModel` : **linkStart** - When users starts dragging a new link * `NodeEditorModel` : **linkCancel** - When users cancels dragging a new link * `LinkRemovedEventArgs` : **linkRemoved** - When a link was removed from the model * `LinkVerticesChangedEventArgs` : **linkVerticesChanged** - When the vertices of a link changed * `NodeRemovedEventArgs` : **nodeRemoved** - When a node was removed from the model * `NodeCollapsedEventArgs` : **nodeCollapsed** - When a node was collapsed/expanded * `NodePositionChangedEventArgs` : **nodePositionChanged** - When a node was dragged and changed its position * `Model.NodeEditorNode[]` : **nodeSelectionChanged** - When the selection of nodes changes * `LinkOptionClickedEventArgs` : **linkOptionClicked** - When an option from a link menu was selected * `LinkConnectedEventArgs` : **linkConnected** - When a link was connected to a node * `NodeEditorClipboardEvent` : **cut** - When the browser cut event is fired * `NodeEditorClipboardEvent` : **copy** - When the browser copy event is fired * `NodeEditorClipboardEvent` : **paste** - When the browser paste event is fired * `Model.NodeEditorPoint` : **keyboardCopy** - Same as above, kept here for compatibility porpuses * `Model.NodeEditorPoint` : **keyboardPaste** - Same as above, kept here for compatibility porpuses * * ### Example * To use the component, assume this HTML Template as an example: * * ```HTML * * * ``` * * @description * * ## NodeEditor Component * * ### Dependencies * * #### Components * * SimpleGraphNode : `cmf.core.controls` * * #### Services * * NgModuleFactoryLoader : `@angular/core` * * Compiler : `@angular/core` * * NgZone : `@angular/core` * * #### Directives * * ElementQuery : `cmf.core.controls` * */ export declare class NodeEditor extends NodeEditorBase implements ng.OnChanges, ng.OnInit, ng.AfterViewInit, ng.OnDestroy { private _pageBag; private _elementRef; _viewContainerRef: ng.ViewContainerRef; _loader: ng.NgModuleFactoryLoader; _compiler: ng.Compiler; private _ngZone; _injector: ng.Injector; /** * Graph holder element query */ private _graphContainerElementQuery; /** * Diagram Graph Paper */ private _paper; /** * Node Editor Model */ private _data; /** * Graph zoom */ private _zoom; /** * Viewport jquery object */ private _viewportJQ; /** * Paper jquery object */ private _paperJQ; /** * If user is dragging the current view */ private _dragging; /** * Dragging current mouse position */ private _dragMoveMousePosition; /** * Paper current mouse position */ private _paperMousePosition; /** * Dragging old mouse position */ private _dragOldMousePosition; /** * Highlighted port */ _highlightedPort: PortHighlightedArgs; /** * Current port while by dragging a new link */ private _newLinkTargetPort; /** * Used to set link port in nested baseGraphNode */ private _linksChanged; /** * New link connected (created) */ private _createdLink; /** * New link removed */ private _removedLink; /** * Highlighted links */ private _highlightedLinks; /** * Initial paper width */ private _initialWidth; /** * initial paper height */ private _initialHeight; /** * Utils */ private _utils; /** * Send remove events or not */ private _sendRemoveEvents; /** * If the api method "removeNode" was called to avoid bouncing events (being notified for an action that was done explicitly) */ private APINodeRemovedCalled; /** * If the api method "removeLink" was called to avoid bouncing events (being notified for an action that was done explicitly) */ private APILinkRemovedCalled; /** * Saves the state of the ctrl key press */ private _isCtrlKeyPressed; /** * Defines if the keypress events were subscribed */ private _keysEventsSubscribed; /** * Defines if the cut/copy/paste events were subscribed */ private _eventsSubscribed; /** * Current nodes selection */ private _selection; /** * Mouse screen position - used to calculate local mouse coordinates */ private _mouseScreenPosition; /** * Array to hold the enter/exit page events subscription */ private _pageEvents; /** * Defines the selection mode for the nodes present in the component (the selection can be none, single or multiple) */ selectionMode: SelectionMode; /** * Highlighted link */ _highlightedLink: Model.NodeEditorLink; /** * Highlighted link popup pivot */ _highlightedLinkOPopupPivot: Model.NodeEditorPoint; /** * Clicked link */ _clickedLink: Model.NodeEditorLink; /** * Clicked link popup pivot */ _clickedLinkPopupPivot: Model.NodeEditorPoint; /** * Node Editor Model */ data: Model.NodeEditorModel; /** * Link default options */ linkDefaultOptions: Model.NodeEditorLinkOption[]; /** * Validate link callback */ validateLink: (source: any, target: any) => boolean; /** * Defines if the component will allow self linking */ selfLinking: boolean; /** * Defined if the component will allow to create or remove links */ canChangeLinks: boolean; /** * On link clicked * @event onLinkClicked emits when a new link is double clicked */ linkOptionClicked: ng.EventEmitter; /** * Linked start add event * @event linkStart */ linkStart: ng.EventEmitter; /** * Linked cancel add event * @event linkCancel */ linkCancel: ng.EventEmitter; /** * Link removed event * @event linkRemoved emits the new data model when internally changed */ linkRemoved: ng.EventEmitter; /** * Link connected * @event linkConnected */ linkConnected: ng.EventEmitter; /** * Link vertices changed * @event linkVerticesChanged */ linkVerticesChanged: ng.EventEmitter; /** * Node removed event * @event nodeRemoved */ nodeRemoved: ng.EventEmitter; /** * Node collapsed/expanded event * @event nodeCollapsed */ nodeCollapsed: ng.EventEmitter; /** * Node selection event * @event nodeSelectionChanged */ nodeSelectionChanged: ng.EventEmitter; /** * Node position changed * @event nodePositionChanged */ nodePositionChanged: ng.EventEmitter; /** * Zoom changed * @event zoomChanged */ zoomChanged: ng.EventEmitter; /** * Pan changed * @event panChanged */ panChanged: ng.EventEmitter; /** * Browser "cut" event * @event cut */ cut: ng.EventEmitter; /** * Browser "copy" event * @event copy */ copy: ng.EventEmitter; /** * Browser "paste" event * @event paste */ paste: ng.EventEmitter; /** * Browser "copy" event * @event keyboardCopy */ keyboardCopy: ng.EventEmitter; /** * Browser "paste" event * @event keyboardPaste */ keyboardPaste: ng.EventEmitter; /** * linkVerticesChanged output event debounced */ private linkVerticesChangedDebounced; /** * nodePositionChanged output event debounced */ private nodePositionChangedDebounced; /** * Constructor */ constructor(_pageBag: PageBag, _elementRef: ng.ElementRef, _viewContainerRef: ng.ViewContainerRef, _loader: ng.NgModuleFactoryLoader, _compiler: ng.Compiler, _ngZone: ng.NgZone, _injector: ng.Injector); /** * On graph change - notify model changes */ private onGraphChanged; /** * On element remove (can be both nodes and links) - update data model and notify */ private onGraphRemoveElement; /** * On element add (the diagram can only add links) - update model and notify */ private onGraphAddElement; /** * On link menu option click */ onLinkOptionClick(link: Model.NodeEditorLink, option: Model.NodeEditorLinkOption): void; /** * On link double click */ private onLinkClick; /** * On paper right click - deselects elements */ private onPaperLeftClick; /** * On paper right click */ private onPaperRightClick; /** * On link mouse enter */ private onCellEnter; /** * On link mouse leave */ private onCellLeave; /** * On cell pointer up */ private onCellPointerUp; /** * Deselects all nodes * @param exception Will no deselected this node * @returns True if any node was deselected, false otherwise */ private deselectAllNodes; /** * Gets list of selected nodes */ private getSelectNodes; /** * Update node inputs * @param cell Element that contains the nested component, which inputs are going to be updated * @param selected Value of "selected" input */ updateSelected(cell: joint.dia.Cell, selected: boolean): void; /** * On cell pointer click - update selection * @param cellView Clicked cell */ private onCellClick; /** * On link connect */ private onLinkConnect; /** * On link dragging */ private onLinkDragging; /** * On port highlighted */ private onPortHighlighted; /** * When node is removed */ private onNodeRemoved; /** * On node collapsed */ private onNodeCollapsed; /** * Used to reset the private properties that are passed down to the node components inputs */ private resetComponentsInputsProperties; /** * Refresh node graph components inputs */ private refreshNodeComponentsInputs; /** * Build diagram content using a data model * @param data the data model */ private buildGraphFromDataModel; /** * Creates a joint graph node based on the provided node editor node * @param node the new Node */ private buildGraphNode; /** * New link * @param link the new link */ private buildGraphLink; /** * Remove element from graph */ removeElement(id: string): boolean; /** * Get pointer coordinates * @param event */ private getPointerCoordinates; /** * On mouse wheel * @param event */ private onMouseWheel; /** * On mouse down * @param event * @param x * @param y */ private onMouseDown; /** * On mouse move * @param event */ private onMouseMove; /** * On mouse up * @param event */ private onMouseUp; /** * Zoom in internal */ private zoomInInternal; /** * Zoom out internal */ private zoomOutInternal; /** * Transform graph paper */ private transformPaper; /** * Gets the current data model * @returns the current data model */ getCurrentData(): Model.NodeEditorModel; /** * Adds a new node to the diagram * @param node the new node definition * @returns the modified data model after the operation */ addNode(node: Model.NodeEditorNode): string; /** * Add a new link to the diagram * @param node the new link definition * @returns the modified data model after the operation */ addLink(link: Model.NodeEditorLink): string; /** * Edit a node * @param args the properties to edit * @return success of operation */ editNode(args: NodeEditorNodeEditArgs): Model.NodeEditorModel; /** * Edit a link * @param args the properties to edit * @return success of operation */ editLink(args: NodeEditorLinkEditArgs): Model.NodeEditorModel; /** * Removes a node from the diagram * @param id the id of the node to remove * @returns the modified data model after the operation */ removeNode(id: string): boolean; /** * Removes a link from the diagram * @param id the id of the link to remove * @returns the modified data model after the operation */ removeLink(id: string): boolean; /** * Applies an auto-grid-layout to the diagram to rearrange the items * @param options the new layout options * @returns the modified data model after the operation */ applyGridLayout(options: Model.NodeEditorGridLayoutOptions): Promise; /** * Fit content of the graph to window */ fitToWindow(): void; /** * Expand/Collapse all nodes * @param collapsed true to collapse all and false to expand all */ toggleCollapseAll(collapsed: boolean): void; /** * Zoom in */ zoomIn(): void; /** * Zoom out */ zoomOut(): void; /** * Set paper zoom * @param newZoom the new zoom * @param notifyPanChanged used to avoid notification on first setZoom */ setZoom(newZoom: number, notifyPanChanged?: boolean): void; /** * Set min zoom */ setMinZoom(): void; /** * Set max zoom */ setMaxZoom(): void; /** * Set pan * @param h amount horizontally * @param v amount vertically */ setPan(point: Model.NodeEditorPoint): void; /** * Scroll to initial position */ panInitial(): void; /** * Get current pan */ getCurrentPan(): Model.NodeEditorPoint; /** * Get current zoom */ getCurrentZoom(): number; /** * Get local mouse coordinates */ getLocalMouseCoordinates(originalMousePosition: Model.NodeEditorPoint): Model.NodeEditorPoint; /** * Updates the inner component inputs and outputs * Should receive an object with the inputs and outputs that must be updated * @param nodeId Node ID * @param properties Properties to update */ updateComponentProperties(nodeId: string, properties: { [key: string]: any; }): void; /** * Animates a link in the model * @param linkId Link ID * @param duration Animation duration in seconds, 1 by default */ animateLink(linkId: string, duration?: number): void; /** * After view init - setup pan, zoom, size, mouse events */ ngAfterViewInit(): void; /** * Setup left ctrl press events - used to enable multi selection */ private setupKeyEvents; /** * Setups cut/copy/paste events */ private setupEvents; onEnterPage: () => void; onExitPage: () => void; /** * On Destroy */ ngOnDestroy(): void; /** * On component init */ ngOnInit(): void; /** * On changes method * * @param changes the changes made to the component properties */ ngOnChanges(changes: ng.SimpleChanges): void; } export declare class NodeEditorModule { }