UNPKG

@jsplumb/core

Version:

Visual connectivity for webapps. This is the core package, which is imported by specific renderers. You probably want to import @jsplumb/browser-ui, as it is currently the only renderer available.

1,521 lines (1,413 loc) 123 kB
/** * This package is the core of the jsPlumb Community Edition. * * * @packageDocumentation */ import { AbstractSegment } from '@jsplumb/common'; import { AnchorPlacement } from '@jsplumb/common'; import { AnchorSpec } from '@jsplumb/common'; import { ArrowOverlayOptions } from '@jsplumb/common'; import { BlankEndpointParams } from '@jsplumb/common'; import { Connector } from '@jsplumb/common'; import { ConnectorOptions } from '@jsplumb/common'; import { ConnectorSpec } from '@jsplumb/common'; import { Constructable } from '@jsplumb/util'; import { DotEndpointParams } from '@jsplumb/common'; import { EndpointRepresentationParams } from '@jsplumb/common'; import { EndpointSpec } from '@jsplumb/common'; import { EndpointStyle } from '@jsplumb/common'; import { EventGenerator } from '@jsplumb/util'; import { Extents } from '@jsplumb/util'; import { FullOverlaySpec } from '@jsplumb/common'; import { Geometry } from '@jsplumb/common'; import { LabelOverlayOptions } from '@jsplumb/common'; import { Merge } from '@jsplumb/util'; import { OverlayOptions } from '@jsplumb/common'; import { OverlaySpec } from '@jsplumb/common'; import { PaintAxis } from '@jsplumb/common'; import { PaintStyle } from '@jsplumb/common'; import { PerimeterAnchorShapes } from '@jsplumb/common'; import { PointNearPath } from '@jsplumb/common'; import { PointXY } from '@jsplumb/util'; import { RectangleEndpointParams } from '@jsplumb/common'; import { RotatedPointXY } from '@jsplumb/util'; import { Rotations } from '@jsplumb/util'; import { Segment } from '@jsplumb/common'; import { SegmentParams } from '@jsplumb/common'; import { Size } from '@jsplumb/util'; export declare const ABSOLUTE = "absolute"; /** * @internal */ export declare abstract class AbstractConnector implements Connector { connection: Connection; abstract type: string; edited: boolean; stub: number | number[]; sourceStub: number; targetStub: number; maxStub: number; typeId: string; gap: number; sourceGap: number; targetGap: number; segments: Array<Segment>; totalLength: number; segmentProportions: Array<[number, number]>; segmentProportionalLengths: Array<number>; protected paintInfo: PaintGeometry; strokeWidth: number; x: number; y: number; w: number; h: number; segment: number; bounds: Extents; cssClass: string; hoverClass: string; abstract getDefaultStubs(): [number, number]; geometry: Geometry; constructor(connection: Connection, params: ConnectorOptions); getTypeDescriptor(): string; getIdPrefix(): string; protected setGeometry(g: Geometry, internal: boolean): void; /** * Subclasses can override this. By default we just pass back the geometry we are using internally. */ exportGeometry(): Geometry; /** * Subclasses can override this. By default we just set the given geometry as our internal representation. */ importGeometry(g: Geometry): boolean; resetGeometry(): void; /** * * @param g * @param dx * @param dy */ abstract transformGeometry(g: Geometry, dx: number, dy: number): Geometry; /** * Helper method for subclasses - AnchorPlacement is a common component of a connector geometry. * @internal * @param a * @param dx * @param dy */ protected transformAnchorPlacement(a: AnchorPlacement, dx: number, dy: number): AnchorPlacement; abstract _compute(geometry: PaintGeometry, params: ConnectorComputeParams): void; resetBounds(): void; /** * Function: findSegmentForPoint * Returns the segment that is closest to the given [x,y], * null if nothing found. This function returns a JS * object with: * * d - distance from segment * l - proportional location in segment * x - x point on the segment * y - y point on the segment * s - the segment itself. */ findSegmentForPoint(x: number, y: number): SegmentForPoint; lineIntersection(x1: number, y1: number, x2: number, y2: number): Array<PointXY>; boxIntersection(x: number, y: number, w: number, h: number): Array<PointXY>; boundingBoxIntersection(box: any): Array<PointXY>; _updateSegmentProportions(): void; /** * returns [segment, proportion of travel in segment, segment index] for the segment * that contains the point which is 'location' distance along the entire path, where * 'location' is a decimal between 0 and 1 inclusive. in this connector type, paths * are made up of a list of segments, each of which contributes some fraction to * the total length. * From 1.3.10 this also supports the 'absolute' property, which lets us specify a location * as the absolute distance in pixels, rather than a proportion of the total path. */ _findSegmentForLocation(location: number, absolute?: boolean): { segment: Segment; proportion: number; index: number; }; _addSegment(clazz: Constructable<Segment>, params: any): void; _clearSegments(): void; getLength(): number; private _prepareCompute; updateBounds(segment: Segment): void; private dumpSegmentsToConsole; pointOnPath(location: number, absolute?: boolean): PointXY; gradientAtPoint(location: number, absolute?: boolean): number; pointAlongPathFrom(location: number, distance: number, absolute?: boolean): PointXY; compute(params: ConnectorComputeParams): void; setAnchorOrientation(idx: number, orientation: number[]): void; } export declare interface AbstractSelectOptions<E> { scope?: SelectionList; source?: ElementSelectionSpecifier<E>; target?: ElementSelectionSpecifier<E>; } export declare const ADD_CLASS_ACTION = "add"; export declare interface AddGroupOptions<E> extends GroupOptions { el: E; collapsed?: boolean; } /** * @internal */ export declare type AnchorComputeParams = { xy?: PointXY; wh?: Size; txy?: PointXY; twh?: Size; element?: Endpoint; timestamp?: string; index?: number; tElement?: Endpoint; connection?: Connection; elementId?: string; rotation?: Rotations; tRotation?: Rotations; }; declare type AnchorListEntry = { theta: number; order: number; c: ConnectionFacade; b: boolean; elId: string; epId: string; }; declare type AnchorLists = { top: Array<AnchorListEntry>; right: Array<AnchorListEntry>; bottom: Array<AnchorListEntry>; left: Array<AnchorListEntry>; }; export declare type AnchorOrientationHint = -1 | 0 | 1; /** * @internal */ export declare interface AnchorRecord { x: number; y: number; ox: AnchorOrientationHint; oy: AnchorOrientationHint; offx: number; offy: number; iox: AnchorOrientationHint; ioy: AnchorOrientationHint; cls: string; } /** * @internal */ export declare class ArcSegment extends AbstractSegment { static segmentType: string; type: string; cx: number; cy: number; radius: number; anticlockwise: boolean; startAngle: number; endAngle: number; sweep: number; length: number; circumference: number; frac: number; constructor(params: ArcSegmentParams); private _calcAngle; private _calcAngleForLocation; getPath(isFirstSegment: boolean): string; getLength(): number; /** * returns the point on the segment's path that is 'location' along the length of the path, where 'location' is a decimal from * 0 to 1 inclusive. */ pointOnPath(location: number, absolute?: boolean): PointXY; /** * returns the gradient of the segment at the given point. */ gradientAtPoint(location: number, absolute?: boolean): number; pointAlongPathFrom(location: number, distance: number, absolute?: boolean): PointXY; } /** * @internal */ export declare interface ArcSegmentParams extends SegmentParams { cx: number; cy: number; r: number; ac: boolean; startAngle?: number; endAngle?: number; } export declare class ArrowOverlay extends Overlay { instance: JsPlumbInstance; component: Component; width: number; length: number; foldback: number; direction: number; location: number; paintStyle: PaintStyle; static type: string; type: string; cachedDimensions: Size; constructor(instance: JsPlumbInstance, component: Component, p: ArrowOverlayOptions); draw(component: Component, currentConnectionPaintStyle: PaintStyle, absolutePosition?: PointXY): any; updateFrom(d: any): void; } export declare function att(...attName: Array<string>): string; export declare const ATTRIBUTE_GROUP = "data-jtk-group"; export declare const ATTRIBUTE_MANAGED = "data-jtk-managed"; export declare const ATTRIBUTE_NOT_DRAGGABLE = "data-jtk-not-draggable"; export declare const ATTRIBUTE_SCOPE = "data-jtk-scope"; export declare const ATTRIBUTE_SCOPE_PREFIX: string; export declare const ATTRIBUTE_TABINDEX = "tabindex"; export declare type Axis = [Face, Face]; /** * Defines the method signature for the callback to the `beforeDetach` interceptor. Returning false from this method * prevents the connection from being detached. The interceptor is fired by the core, meaning that it will be invoked * regardless of whether the detach occurred programmatically, or via the mouse. * @public */ export declare type BeforeDetachInterceptor = (c: Connection) => boolean; /** * Defines the method signature for the callback to the `beforeDrag` interceptor. This method can return boolean `false` to * abort the connection drag, or it can return an object containing values that will be used as the `data` for the connection * that is created. * @public */ export declare type BeforeDragInterceptor<E = any> = (params: BeforeDragParams<E>) => boolean | Record<string, any>; /** * The parameters passed to a `beforeDrag` interceptor. * @public */ export declare interface BeforeDragParams<E> { endpoint: Endpoint; source: E; sourceId: string; connection: Connection; } /** * Defines the method signature for the callback to the `beforeDrop` interceptor. * @public */ export declare type BeforeDropInterceptor = (params: BeforeDropParams) => boolean; /** * Definition of the parameters passed to the `beforeDrop` interceptor. * @public */ export declare interface BeforeDropParams { sourceId: string; targetId: string; scope: string; connection: Connection; dropEndpoint: Endpoint; } /** * Defines the method signature for the callback to the `beforeStartDetach` interceptor. * @public */ export declare type BeforeStartDetachInterceptor<E = any> = (params: BeforeStartDetachParams<E>) => boolean; /** * The parameters passed to a `beforeStartDetach` interceptor. * @public */ export declare interface BeforeStartDetachParams<E> extends BeforeDragParams<E> { } /** * Extends EndpointTypeDescriptor to add the options supported by an `addSourceSelector` or `addTargetSelector` call. * @public */ export declare interface BehaviouralTypeDescriptor<T = any> extends EndpointTypeDescriptor { /** * A function that can be used to extract a set of parameters pertinent to the connection that is being dragged * from a given source or dropped on a given target. * @param el - The element that is the drag source * @param eventTarget - The element that captured the event that started the connection drag. */ parameterExtractor?: (el: T, eventTarget: T, event: Event) => Record<string, any>; /** * Optional policy for dropping existing connections that have been detached by their source/target. * * - 'strict' (`RedropPolicy.STRICT`) indicates that a connection can only be dropped back onto a part of * an element that matches the original source/target's selector. * * - 'any' (`RedropPolicy.ANY`) indicates that a connection can be dropped anywhere onto an element. * * - 'anySource' (`RedropPolicy.ANY_SOURCE`) indicates that a connection can be dropped onto any part of an element that * is configured as a source selector. * * - 'anyTarget' (`RedropPolicy.ANY_TARGET`) indicates that a connection can be dropped onto any part of an element that * is configured as a target selector. * * - 'anySourceOrTarget' (`RedropPolicy.ANY_SOURCE_OR_TARGET`) indicates that a connection can be dropped onto any part of an element that * is configured as a source selector or a target selector. */ redrop?: RedropPolicy; /** * Optional function that is used to determine whether at the start of a drag, a given element is able to accept * new connections. For a source element returning false from here aborts the connection drag. For a target element * returning false from here means the target element is not active as a drop target. */ canAcceptNewConnection?: (el: Element, e: Event) => boolean; /** * Optional set of values to extract from an element when a drag starts from that element. For target selectors this option is ignored. */ extract?: Record<string, string>; /** * If true, only one endpoint will be created on any given element for this type descriptor, and subsequent connections will * all attach to that endpoint. Defaults to false. */ uniqueEndpoint?: boolean; /** * Optional function to call if the user begins a new connection drag when the associated element is full. * @param value * @param event */ onMaxConnections?: (value: any, event?: any) => any; /** * Optional type for connections dragged from a source selector. This option is ignored for target selectors. */ edgeType?: string; /** * Optional logical id for the endpoint associated with a source or target selector. */ portId?: string; /** * Defaults to true. If false, the user will not be permitted to drag a connection from the current node to itself. */ allowLoopback?: boolean; /** * Optional rank for a given source or target selector. When selecting a selector from a list of candidates, rank can be used * to prioritise them. Higher values take precedence. */ rank?: number; /** * Optional selector identifying the ancestor of the event target that could be the element to which connections * are added. By default this is the internal attribute jsPlumb uses to mark managed elements (data-jtk-managed) */ parentSelector?: string; /** * This function offers a means for you to provide the anchor to use for * a new drag, or a drop. You're given the source/target element, the proportional location on * the element that the drag started/drop occurred, the associated type descriptor, and * the originating event. Return null if you don't wish to provide a value, * and any other return value will be treated as an AnchorSpec. * @param el * @param elxy * @param def * @param e */ anchorPositionFinder?: (el: Element, elxy: PointXY, def: BehaviouralTypeDescriptor, e: Event) => AnchorSpec | null; /** * Whether or not an endpoint created from this definition should subsequently * behave as a source for dragging connections with the mouse. */ source?: boolean; /** * Whether or not an endpoint created from this definition should subsequently * behave as a target for dragging connections with the mouse. */ target?: boolean; } export declare class BlankEndpoint extends EndpointRepresentation<ComputedBlankEndpoint> { constructor(endpoint: Endpoint, params?: BlankEndpointParams); static type: string; type: string; } export declare const BlankEndpointHandler: EndpointHandler<BlankEndpoint, ComputedBlankEndpoint>; export declare const BLOCK = "block"; export declare const BOTTOM = FaceValues.bottom; export declare const CHECK_CONDITION = "checkCondition"; export declare const CHECK_DROP_ALLOWED = "checkDropAllowed"; export declare const CLASS_CONNECTED = "jtk-connected"; export declare const CLASS_CONNECTOR = "jtk-connector"; export declare const CLASS_CONNECTOR_OUTLINE = "jtk-connector-outline"; export declare const CLASS_ENDPOINT = "jtk-endpoint"; export declare const CLASS_ENDPOINT_ANCHOR_PREFIX = "jtk-endpoint-anchor"; export declare const CLASS_ENDPOINT_CONNECTED = "jtk-endpoint-connected"; export declare const CLASS_ENDPOINT_DROP_ALLOWED = "jtk-endpoint-drop-allowed"; export declare const CLASS_ENDPOINT_DROP_FORBIDDEN = "jtk-endpoint-drop-forbidden"; export declare const CLASS_ENDPOINT_FLOATING = "jtk-floating-endpoint"; export declare const CLASS_ENDPOINT_FULL = "jtk-endpoint-full"; export declare const CLASS_GROUP_COLLAPSED = "jtk-group-collapsed"; export declare const CLASS_GROUP_EXPANDED = "jtk-group-expanded"; export declare const CLASS_OVERLAY = "jtk-overlay"; /** * @internal */ export declare type ClassAction = typeof ADD_CLASS_ACTION | typeof REMOVE_CLASS_ACTION; export declare function classList(...className: Array<string>): string; export declare function cls(...className: Array<string>): string; /** * Base class for Endpoint and Connection. * @public */ export declare abstract class Component extends EventGenerator { instance: JsPlumbInstance; abstract getTypeDescriptor(): string; abstract getDefaultOverlayKey(): string; abstract getIdPrefix(): string; abstract getXY(): PointXY; defaultLabelLocation: number | [number, number]; overlays: Record<string, Overlay>; overlayPositions: Record<string, PointXY>; overlayPlacements: Record<string, Extents>; clone: () => Component; deleted: boolean; segment: number; x: number; y: number; w: number; h: number; id: string; visible: boolean; typeId: string; params: Record<string, any>; paintStyle: PaintStyle; hoverPaintStyle: PaintStyle; paintStyleInUse: PaintStyle; _hover: boolean; lastPaintedAt: string; data: Record<string, any>; _defaultType: ComponentTypeDescriptor; events: any; parameters: ComponentParameters; _types: Set<string>; _typeCache: {}; cssClass: string; hoverClass: string; beforeDetach: BeforeDetachInterceptor; beforeDrop: BeforeDropInterceptor; protected constructor(instance: JsPlumbInstance, params?: ComponentOptions); /** * Called internally when the user is trying to disconnect the given connection. * @internal * @param connection */ isDetachAllowed(connection: Connection): boolean; /** * @internal * @param sourceId * @param targetId * @param scope * @param connection * @param dropEndpoint */ isDropAllowed(sourceId: string, targetId: string, scope: string, connection: Connection, dropEndpoint: Endpoint): boolean; /** * @internal */ getDefaultType(): ComponentTypeDescriptor; /** * @internal */ appendToDefaultType(obj: Record<string, any>): void; /** * @internal */ getId(): string; /** * @internal */ cacheTypeItem(key: string, item: any, typeId: string): void; /** * @internal */ getCachedTypeItem(key: string, typeId: string): any; /** * @internal */ setType(typeId: string, params?: any): void; /** * @internal */ getType(): string[]; /** * @internal */ reapplyTypes(params?: any): void; /** * @internal */ hasType(typeId: string): boolean; /** * @internal */ addType(typeId: string, params?: any): void; /** * @internal */ removeType(typeId: string, params?: any): void; /** * @internal */ clearTypes(params?: any): void; /** * @internal */ toggleType(typeId: string, params?: any): void; /** * @internal */ applyType(t: any, params?: any): void; /** * @internal */ setPaintStyle(style: PaintStyle): void; /** * @internal */ getPaintStyle(): PaintStyle; /** * @internal */ setHoverPaintStyle(style: PaintStyle): void; /** * @internal */ getHoverPaintStyle(): PaintStyle; /** * @internal */ destroy(): void; /** * @internal */ isHover(): boolean; /** * @internal */ mergeParameters(p: ComponentParameters): void; /** * @internal */ setVisible(v: boolean): void; /** * @internal */ isVisible(): boolean; /** * @internal */ setAbsoluteOverlayPosition(overlay: Overlay, xy: PointXY): void; /** * @internal */ getAbsoluteOverlayPosition(overlay: Overlay): PointXY; /** * @internal */ private _clazzManip; /** * Adds a css class to the component * @param clazz Class to add. May be a space separated list. * @param cascade This is for subclasses to use, if they wish to. For instance, a Connection might want to optionally cascade a css class * down to its endpoints. * @public */ addClass(clazz: string, cascade?: boolean): void; /** * Removes a css class from the component * @param clazz Class to remove. May be a space separated list. * @param cascade This is for subclasses to use, if they wish to. For instance, a Connection might want to optionally cascade a css class * removal down to its endpoints. * @public */ removeClass(clazz: string, cascade?: boolean): void; /** * Returns a space-separated list of the current classes assigned to this component. * @public */ getClass(): string; /** * @internal */ shouldFireEvent(event: string, value: any, originalEvent?: Event): boolean; /** * Gets any backing data stored against the given component. * @public */ getData(): Record<string, any>; /** * Sets backing data stored against the given component, overwriting any current value. * @param d * @public */ setData(d: any): void; /** * Merges the given backing data into any current backing data. * @param d * @public */ mergeData(d: any): void; /** * Add an overlay to the component. This method is not intended for use by users of the API. You must `revalidate` * an associated element for this component if you call this method directly. Consider using the `addOverlay` method * of `JsPlumbInstance` instead, which adds the overlay and then revalidates. * @param overlay * @internal */ addOverlay(overlay: OverlaySpec): Overlay; /** * Get the Overlay with the given ID. You can optionally provide a type parameter for this method in order to get * a typed return value (such as `LabelOverlay`, `ArrowOverlay`, etc), since some overlays have methods that * others do not. * @param id ID of the overlay to retrieve. * @public */ getOverlay<T extends Overlay>(id: string): T; /** * Gets all the overlays registered on this component. * @public */ getOverlays(): Record<string, Overlay>; /** * Hide the overlay with the given id. * @param id * @public */ hideOverlay(id: string): void; /** * Hide all overlays, or a specific set of overlays. * @param ids optional list of ids to hide. * @public */ hideOverlays(...ids: Array<string>): void; /** * Show a specific overlay (set it to be visible) * @param id * @public */ showOverlay(id: string): void; /** * Show all overlays, or a specific set of overlays. * @param ids optional list of ids to show. * @public */ showOverlays(...ids: Array<string>): void; /** * Remove all overlays from this component. * @public */ removeAllOverlays(): void; /** * Remove the overlay with the given id. * @param overlayId * @param dontCleanup This is an internal parameter. You are not encouraged to provide a value for this. * @internal */ removeOverlay(overlayId: string, dontCleanup?: boolean): void; /** * Remove the given set of overlays, specified by their ids. * @param overlays * @public */ removeOverlays(...overlays: string[]): void; /** * Return this component's label, if one is set. * @public */ getLabel(): string; /** * @internal */ getLabelOverlay(): LabelOverlay; /** * Set this component's label. * @param l Either some text, or a function which returns some text, or an existing label overlay. * @public */ setLabel(l: string | Function | LabelOverlay): void; } /** * @internal */ export declare interface ComponentOptions { parameters?: Record<string, any>; beforeDetach?: BeforeDetachInterceptor; beforeDrop?: BeforeDropInterceptor; hoverClass?: string; events?: Record<string, (value: any, event: any) => any>; scope?: string; cssClass?: string; data?: any; id?: string; label?: string; labelLocation?: number; overlays?: Array<OverlaySpec>; } export declare type ComponentParameters = Record<string, any>; /** * Base interface for type descriptors for internal methods. * @internal */ export declare interface ComponentTypeDescriptor extends TypeDescriptorBase { overlays: Record<string, OverlaySpec>; } export declare type ComputedBlankEndpoint = [number, number, number, number]; export declare type ComputedDotEndpoint = [number, number, number, number, number]; /** * @internal */ export declare interface ComputedPosition { curX: number; curY: number; ox: AnchorOrientationHint; oy: AnchorOrientationHint; x: number; y: number; } export declare type ComputedRectangleEndpoint = [number, number, number, number]; /** * @public */ export declare class Connection<E = any> extends Component { instance: JsPlumbInstance; connector: AbstractConnector; defaultLabelLocation: number; scope: string; typeId: string; getIdPrefix(): string; getDefaultOverlayKey(): string; getXY(): { x: number; y: number; }; previousConnection: Connection; /** * The id of the source of the connection * @public */ sourceId: string; /** * The id of the target of the connection * @public */ targetId: string; /** * The element that is the source of the connection * @public */ source: E; /** * The element that is the target of the connection * @public */ target: E; /** * Whether or not this connection is detachable * @public */ detachable: boolean; /** * Whether or not this connection should be reattached if it were detached via the mouse * @public */ reattach: boolean; /** * UUIDs of the endpoints. If this is not specifically provided in the constructor of the connection it will * be null. * @public */ readonly uuids: [string, string]; /** * Connection's cost. * @public */ cost: number; /** * Whether or not the connection is directed. * @public */ directed: boolean; /** * Source and target endpoints. * @public */ endpoints: [Endpoint<E>, Endpoint<E>]; endpointStyles: [PaintStyle, PaintStyle]; readonly endpointSpec: EndpointSpec; readonly endpointsSpec: [EndpointSpec, EndpointSpec]; endpointStyle: PaintStyle; endpointHoverStyle: PaintStyle; readonly endpointHoverStyles: [PaintStyle, PaintStyle]; /** * @internal */ suspendedEndpoint: Endpoint<E>; /** * @internal */ suspendedIndex: number; /** * @internal */ suspendedElement: E; /** * @internal */ suspendedElementId: string; /** * @internal */ suspendedElementType: string; /** * @internal */ _forceReattach: boolean; /** * @internal */ _forceDetach: boolean; /** * List of current proxies for this connection. Used when collapsing groups and when dealing with scrolling lists. * @internal */ proxies: Array<{ ep: Endpoint<E>; originalEp: Endpoint<E>; }>; /** * @internal */ pending: boolean; /** * Connections should never be constructed directly by users of the library. * @internal * @param instance * @param params */ constructor(instance: JsPlumbInstance, params: ConnectionOptions<E>); makeEndpoint(isSource: boolean, el: any, elId: string, anchor?: AnchorSpec, ep?: Endpoint): Endpoint; static type: string; getTypeDescriptor(): string; isDetachable(ep?: Endpoint): boolean; setDetachable(detachable: boolean): void; isReattach(): boolean; setReattach(reattach: boolean): void; applyType(t: ConnectionTypeDescriptor, typeMap: any): void; /** * Adds the given class to the UI elements being used to represent this connection's connector, and optionally to * the UI elements representing the connection's endpoints. * @param c class to add * @param cascade If true, also add the class to the connection's endpoints. * @public */ addClass(c: string, cascade?: boolean): void; /** * Removes the given class from the UI elements being used to represent this connection's connector, and optionally from * the UI elements representing the connection's endpoints. * @param c class to remove * @param cascade If true, also remove the class from the connection's endpoints. * @public */ removeClass(c: string, cascade?: boolean): void; /** * Sets the visible state of the connection. * @param v * @public */ setVisible(v: boolean): void; /** * @internal */ destroy(): void; getUuids(): [string, string]; /** * @internal */ prepareConnector(connectorSpec: ConnectorSpec, typeId?: string): AbstractConnector; /** * @internal */ setPreparedConnector(connector: AbstractConnector, doNotRepaint?: boolean, doNotChangeListenerComponent?: boolean, typeId?: string): void; /** * @internal * @param connectorSpec * @param doNotRepaint * @param doNotChangeListenerComponent * @param typeId */ _setConnector(connectorSpec: ConnectorSpec, doNotRepaint?: boolean, doNotChangeListenerComponent?: boolean, typeId?: string): void; /** * Replace the Endpoint at the given index with a new Endpoint. This is used by the Toolkit edition, if changes to an edge type * cause a change in Endpoint. * @param idx 0 for source, 1 for target * @param endpointDef Spec for the new Endpoint. * @public */ replaceEndpoint(idx: number, endpointDef: EndpointSpec): void; } /** * Definition of the parameters passed to a listener for the `connection:detach` event. * @public */ export declare interface ConnectionDetachedParams<E = any> extends ConnectionEstablishedParams<E> { } export declare class ConnectionDragSelector { selector: string; def: SourceOrTargetDefinition; exclude: boolean; readonly id: string; redrop: RedropPolicy; constructor(selector: string, def: SourceOrTargetDefinition, exclude?: boolean); setEnabled(enabled: boolean): void; isEnabled(): boolean; } /** * Definition of the parameters passed to a listener for the `connection` event. * @public */ export declare interface ConnectionEstablishedParams<E = any> { connection: Connection<E>; source: E; sourceEndpoint: Endpoint<E>; sourceId: string; target: E; targetEndpoint: Endpoint<E>; targetId: string; } declare interface ConnectionFacade { endpoints: [Endpoint, Endpoint]; placeholder?: boolean; } /** * Definition of the parameters passed to a listener for the `connection:move` event. * @public */ export declare interface ConnectionMovedParams<E = any> { connection: Connection<E>; index: number; originalSourceId: string; newSourceId: string; originalTargetId: string; newTargetId: string; originalEndpoint: Endpoint<E>; newEndpoint: Endpoint<E>; } /** * @internal */ export declare type ConnectionOptions<E = any> = Merge<ConnectParams<E>, { source?: E; target?: E; sourceEndpoint?: Endpoint; targetEndpoint?: Endpoint; previousConnection?: Connection<E>; geometry?: any; }>; export declare class ConnectionSelection extends SelectionBase<Connection> { setDetachable(d: boolean): ConnectionSelection; setReattach(d: boolean): ConnectionSelection; setConnector(spec: ConnectorSpec): ConnectionSelection; deleteAll(): void; repaint(): ConnectionSelection; } /** * Definition of a connection type. * @public */ export declare interface ConnectionTypeDescriptor extends TypeDescriptor { /** * Whether or not connections of this type should be detachable with the mouse. Defaults to true. */ detachable?: boolean; /** * Whether or not when a user detaches a connection of this type it should be automatically * reattached. Defaults to false. */ reattach?: boolean; /** * Specs for the [source, target] endpoints for connections of this type. */ endpoints?: [EndpointSpec, EndpointSpec]; } export declare type ConnectorComputeParams = { sourcePos: AnchorPlacement; targetPos: AnchorPlacement; sourceEndpoint: Endpoint; targetEndpoint: Endpoint; strokeWidth: number; sourceInfo: ViewportElement<any>; targetInfo: ViewportElement<any>; }; export declare const Connectors: { get: (connection: Connection, name: string, params: any) => AbstractConnector; register: (name: string, conn: Constructable<AbstractConnector>) => void; }; /** * Options for the `connect` call on a JsPlumbInstance */ export declare interface ConnectParams<E> { /** * Optional UUIDs to assign to the source and target endpoints. */ uuids?: [UUID, UUID]; /** * Source for the connection - an Endpoint, or an element */ source?: Element | Endpoint; /** * Source for the connection - an Endpoint, or an element */ target?: Element | Endpoint; /** * Whether or not the connection is detachable. Defaults to true. */ detachable?: boolean; /** * Whether or not to delete the connection's endpoints when this connection is detached. Defaults to false. Does not * delete endpoints if they have other connections. */ deleteEndpointsOnDetach?: boolean; /** * Whether or not to delete any endpoints that were created by this connect call if at some * point in the future the endpoint has no remaining connections. Defaults to false. */ deleteEndpointsOnEmpty?: boolean; /** * Whether or not to reattach this connection automatically should it be detached via user intervention. Defaults to false. */ reattach?: boolean; /** * Spec for the endpoint to use for both source and target endpoints. */ endpoint?: EndpointSpec; /** * Individual endpoint specs for the source/target endpoints. */ endpoints?: [EndpointSpec, EndpointSpec]; /** * Spec for the anchor to use for both source and target endpoints. */ anchor?: AnchorSpec; /** * Individual anchor specs for the source/target endpoints. */ anchors?: [AnchorSpec, AnchorSpec]; /** * Optional label to set on the connection. In the default browser UI implementation this is rendered as a `label` attribute on the SVG element representing the connection. */ label?: string; /** * Spec for the connector used to paint the connection. */ connector?: ConnectorSpec; /** * Optional list of overlays to attach to the connection. */ overlays?: Array<OverlaySpec>; /** * Spec for the styles to use on both source and target endpoints */ endpointStyle?: EndpointStyle; /** * Individual specs for the source/target endpoint styles. */ endpointStyles?: [EndpointStyle, EndpointStyle]; /** * Spec for the styles to use on both source and target endpoints when they are in hover state */ endpointHoverStyle?: EndpointStyle; /** * Individual specs for the source/target endpoint styles when they are in hover state. */ endpointHoverStyles?: [EndpointStyle, EndpointStyle]; /** * Optional port IDs for the source and target endpoints */ ports?: [string, string]; /** * Type of the connection. Used in conjunction with the `registerConnectionType` method. */ type?: string; /** * Paint style for the connector. */ paintStyle?: PaintStyle; /** * Paint style for the connector when in hover mode. */ hoverPaintStyle?: PaintStyle; /** * Whether or not the connection is considered to be 'directed' */ directed?: boolean; /** * Cost of the connection. Defaults to 1. */ cost?: number; /** * Optional extra parameters to associate with the connection */ parameters?: Record<string, any>; id?: string; data?: any; cssClass?: string; hoverClass?: string; outlineColor?: string; outlineWidth?: number; color?: string; lineWidth?: number; scope?: string; } /** * Convert the given input into an object in the form of a `FullOverlaySpec` * @param spec */ export declare function convertToFullOverlaySpec(spec: string | OverlaySpec): FullOverlaySpec; export declare function createFloatingAnchor(instance: JsPlumbInstance, element: Element, elementId: string): LightweightFloatingAnchor; export declare function _createPerimeterAnchor(params: Record<string, any>): LightweightPerimeterAnchor; export declare class CustomOverlay extends Overlay { instance: JsPlumbInstance; component: Component; create: (c: Component) => any; constructor(instance: JsPlumbInstance, component: Component, p: CustomOverlayOptions); static type: string; type: string; updateFrom(d: any): void; } /** * @public */ export declare interface CustomOverlayOptions extends OverlayOptions { create: (c: Component) => any; } export declare const DEFAULT_KEY_ALLOW_NESTED_GROUPS = "allowNestedGroups"; export declare const DEFAULT_KEY_ANCHOR = "anchor"; export declare const DEFAULT_KEY_ANCHORS = "anchors"; export declare const DEFAULT_KEY_CONNECTION_OVERLAYS = "connectionOverlays"; export declare const DEFAULT_KEY_CONNECTIONS_DETACHABLE = "connectionsDetachable"; export declare const DEFAULT_KEY_CONNECTOR = "connector"; export declare const DEFAULT_KEY_CONTAINER = "container"; export declare const DEFAULT_KEY_ENDPOINT = "endpoint"; export declare const DEFAULT_KEY_ENDPOINT_HOVER_STYLE = "endpointHoverStyle"; export declare const DEFAULT_KEY_ENDPOINT_HOVER_STYLES = "endpointHoverStyles"; export declare const DEFAULT_KEY_ENDPOINT_OVERLAYS = "endpointOverlays"; export declare const DEFAULT_KEY_ENDPOINT_STYLE = "endpointStyle"; export declare const DEFAULT_KEY_ENDPOINT_STYLES = "endpointStyles"; export declare const DEFAULT_KEY_ENDPOINTS = "endpoints"; export declare const DEFAULT_KEY_HOVER_CLASS = "hoverClass"; export declare const DEFAULT_KEY_HOVER_PAINT_STYLE = "hoverPaintStyle"; export declare const DEFAULT_KEY_LIST_STYLE = "listStyle"; export declare const DEFAULT_KEY_MAX_CONNECTIONS = "maxConnections"; export declare const DEFAULT_KEY_PAINT_STYLE = "paintStyle"; export declare const DEFAULT_KEY_REATTACH_CONNECTIONS = "reattachConnections"; export declare const DEFAULT_KEY_SCOPE = "scope"; /** * Optional parameters to the `DeleteConnection` method. */ export declare type DeleteConnectionOptions = { /** * if true, force deletion even if the connection tries to cancel the deletion. */ force?: boolean; /** * If false, an event won't be fired. Otherwise a `connection:detach` event will be fired. */ fireEvent?: boolean; /** * Optional original event that resulted in the connection being deleted. */ originalEvent?: Event; /** * internally when a connection is deleted, it may be because the endpoint it was on is being deleted. * in that case we want to ignore that endpoint. */ endpointToIgnore?: Endpoint; }; export declare class DiamondOverlay extends ArrowOverlay { instance: JsPlumbInstance; static type: string; type: string; constructor(instance: JsPlumbInstance, component: Component, p: ArrowOverlayOptions); } export declare class DotEndpoint extends EndpointRepresentation<ComputedDotEndpoint> { radius: number; defaultOffset: number; defaultInnerRadius: number; constructor(endpoint: Endpoint, params?: DotEndpointParams); static type: string; type: string; } export declare const DotEndpointHandler: EndpointHandler<DotEndpoint, ComputedDotEndpoint>; export declare type ElementSelectionSpecifier<E> = E | Array<E> | '*'; export declare class Endpoint<E = any> extends Component { instance: JsPlumbInstance; getIdPrefix(): string; getTypeDescriptor(): string; getXY(): { x: number; y: number; }; connections: Array<Connection<E>>; endpoint: EndpointRepresentation<any>; element: E; elementId: string; dragAllowedWhenFull: boolean; timestamp: string; portId: string; maxConnections: number; proxiedBy: Endpoint<E>; connectorClass: string; connectorHoverClass: string; finalEndpoint: Endpoint<E>; enabled: boolean; isSource: boolean; isTarget: boolean; isTemporarySource: boolean; connectionCost: number; connectionsDirected: boolean; connectionsDetachable: boolean; reattachConnections: boolean; currentAnchorClass: string; referenceEndpoint: Endpoint<E>; edgeType: string; connector: ConnectorSpec; connectorOverlays: Array<OverlaySpec>; connectorStyle: PaintStyle; connectorHoverStyle: PaintStyle; deleteOnEmpty: boolean; uuid: string; scope: string; _anchor: LightweightAnchor; defaultLabelLocation: [number, number]; getDefaultOverlayKey(): string; constructor(instance: JsPlumbInstance, params: InternalEndpointOptions<E>); private _updateAnchorClass; private setPreparedAnchor; /** * Called by the router when a dynamic anchor has changed its current location. * @param currentAnchor */ _anchorLocationChanged(currentAnchor: LightweightAnchor): void; setAnchor(anchorParams: AnchorSpec | Array<AnchorSpec>): Endpoint; addConnection(conn: Connection): void; /** * Detaches this Endpoint from the given Connection. If `deleteOnEmpty` is set to true and there are no * Connections after this one is detached, the Endpoint is deleted. * @param connection Connection from which to detach. * @param idx Optional, used internally to identify if this is the source (0) or target endpoint (1). Sometimes we already know this when we call this method. * @param transientDetach For internal use only. */ detachFromConnection(connection: Connection, idx?: number, transientDetach?: boolean): void; /** * Delete every connection in the instance. * @param params */ deleteEveryConnection(params?: DeleteConnectionOptions): void; /** * Removes all connections from this endpoint to the given other endpoint. * @param otherEndpoint */ detachFrom(otherEndpoint: Endpoint): Endpoint; setVisible(v: boolean, doNotChangeConnections?: boolean, doNotNotifyOtherEndpoint?: boolean): void; applyType(t: any, typeMap: any): void; destroy(): void; isFull(): boolean; isFloating(): boolean; /** * Test if this Endpoint is connected to the given Endpoint. * @param otherEndpoint */ isConnectedTo(otherEndpoint: Endpoint): boolean; setDragAllowedWhenFull(allowed: boolean): void; getUuid(): string; connectorSelector(): Connection; private prepareEndpoint; setEndpoint<C>(ep: EndpointSpec | EndpointRepresentation<C>): void; private setPreparedEndpoint; addClass(clazz: string, cascade?: boolean): void; removeClass(clazz: string, cascade?: boolean): void; } export declare type EndpointComputeFunction<T> = (endpoint: EndpointRepresentation<T>, anchorPoint: AnchorPlacement, orientation: Orientation, endpointStyle: any) => T; export declare const EndpointFactory: { get: (ep: Endpoint, name: string, params: any) => EndpointRepresentation<any>; clone: <C>(epr: EndpointRepresentation<C>) => EndpointRepresentation<C>; compute: <T>(endpoint: EndpointRepresentation<T>, anchorPoint: AnchorPlacement, orientation: Orientation, endpointStyle: any) => T; registerHandler: <E, T_1>(eph: EndpointHandler<E, T_1>) => void; }; export declare interface EndpointHandler<E, T> { type: string; compute: EndpointComputeFunction<T>; getParams(endpoint: E): Record<string, any>; cls: Constructable<EndpointRepresentation<T>>; } export declare interface EndpointOptions<E = any> { parameters?: Record<string, any>; scope?: string; cssClass?: string; data?: any; hoverClass?: string; /** * Optional definition for both the source and target anchors for any connection created with this endpoint as its source. * If you do not supply this, the default `anchors` definition for the jsPlumb instance will be used */ anchor?: AnchorSpec; /** * Optional definition for the source and target anchors for any connection created with this endpoint as its source. * If you do not supply this, the default `anchors` definition for the jsPlumb instance will be used */ anchors?: [AnchorSpec, AnchorSpec]; /** * Optional endpoint definition. If you do not supply this, the default endpoint definition for the jsPlumb instance will be used */ endpoint?: EndpointSpec; /** * Whether or not the endpoint is initially enabled. Defaults to true. */ enabled?: boolean; /** * Optional paint style to assign to the endpoint */ paintStyle?: PaintStyle; /** * Optional paint style to assign, on hover, to the endpoint. */ hoverPaintStyle?: PaintStyle; /** * Maximum number of connections this endpoint supports. Defaults to 1. Use a value of -1 to indicate there is no limit. */ maxConnections?: number; /** * Optional paint style to assign to a connection that is created with this endpoint as its source. */ connectorStyle?: PaintStyle; /** * Optional paint style to assign, on hover, to a connection that is created with this endpoint as its source. */ connectorHoverStyle?: PaintStyle; /** * Optional connector definition for connections that are created with this endpoint as their source. */ connector?: ConnectorSpec; /** * Optional list of overlays to add to a connection that is created with this endpoint as its source. */ connectorOverlays?: Array<OverlaySpec>; /** * Optional class to assign to connections that have this endpoint as their source. */ connectorClass?: string; /** * Optional class to assign, on mouse hover, to connections that have this endpoint as their source. */ connectorHoverClass?: string; /** * Whether or not connections that have this endpoint as their source are configured to be detachable with the mouse. Defaults to true. */ connectionsDetachable?: boolean; /** * Whether or not this Endpoint acts as a source for connections dragged with the mouse. Defaults to false. */ source?: boolean; /** * Whether or not this Endpoint acts as a target for connections dragged with the mouse. Defaults to false. */ target?: boolean; /** * Optional 'type' for connections that have this endpoint as their source. */ edgeType?: strin