ngx-diagrams
Version:
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 7.2.0.
2,054 lines (2,045 loc) • 164 kB
JavaScript
import { __spread, __values, __extends, __assign, __read } from 'tslib';
import { EventEmitter, Component, ChangeDetectionStrategy, Renderer2, ChangeDetectorRef, Input, Output, ViewChild, ViewContainerRef, ElementRef, NgModule, Injectable, ComponentFactoryResolver, RendererFactory2, ɵɵdefineInjectable, ɵɵinject } from '@angular/core';
import { Subject, BehaviorSubject, ReplaySubject, combineLatest } from 'rxjs';
import { tap, takeUntil, map, filter, mapTo, distinctUntilChanged, take, delay } from 'rxjs/operators';
import { flatMap, uniq, some } from 'lodash';
import { CommonModule } from '@angular/common';
import { graphlib, layout } from 'dagre';
/**
* @fileoverview added by tsickle
* Generated from: lib/utils/tool-kit.util.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @enum {number} */
var LOG_LEVEL = {
'LOG': 0,
'ERROR': 1,
};
LOG_LEVEL[LOG_LEVEL['LOG']] = 'LOG';
LOG_LEVEL[LOG_LEVEL['ERROR']] = 'ERROR';
// @internal
/** @type {?} */
var __DEV__ = true;
// @internal
/** @type {?} */
var __LOG__ = LOG_LEVEL.ERROR;
/**
* @return {?}
*/
function enableDiagramProdMode() {
__DEV__ = false;
}
// @internal
/**
* @param {?} level
* @return {?}
*/
function setLogLevel(level) {
__LOG__ = level;
}
// @internal
/**
* @return {?}
*/
function isDev() {
return __DEV__;
}
// @internal
/**
* @param {?} message
* @param {?=} level
* @param {...?} args
* @return {?}
*/
function log(message, level) {
if (level === void 0) { level = LOG_LEVEL.LOG; }
var args = [];
for (var _i = 2; _i < arguments.length; _i++) {
args[_i - 2] = arguments[_i];
}
if (isDev() && __LOG__ === level) {
if (__LOG__ === LOG_LEVEL.ERROR) {
console.error.apply(console, __spread([message], args));
}
console.log.apply(console, __spread([message], args));
}
}
/**
* rxjs log operator
* \@internal
* @param {?} message
* @param {?=} level
* @param {...?} args
* @return {?}
*/
function withLog(message, level) {
if (level === void 0) { level = LOG_LEVEL.LOG; }
var args = [];
for (var _i = 2; _i < arguments.length; _i++) {
args[_i - 2] = arguments[_i];
}
return (/**
* @template T
* @param {?} source
* @return {?}
*/
function (source) { return (isDev() ? source.pipe(tap((/**
* @param {?} val
* @return {?}
*/
function (val) { return log.apply(void 0, __spread([message, level, val], args)); }))) : source); });
}
/**
* Generates a unique ID
* @return {?}
*/
function UID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (/**
* @param {?} c
* @return {?}
*/
function (c) {
/** @type {?} */
var r = (Math.random() * 16) | 0;
/** @type {?} */
var v = c === 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
}));
}
/**
* @template T
* @param {?} val
* @return {?}
*/
function isArray(val) {
return Array.isArray(val);
}
/**
* @param {?} val
* @return {?}
*/
function isString(val) {
return typeof val === 'string';
}
/**
* @param {?} val
* @return {?}
*/
function isFunction(val) {
return typeof val === 'function';
}
// @internal
/**
* @param {?} v
* @return {?}
*/
function isNil(v) {
return v === null || v === undefined;
}
/**
* @template T
* @param {?} value
* @return {?}
*/
function coerceArray(value) {
if (isNil(value)) {
return [];
}
return Array.isArray(value) ? value : [value];
}
/**
* @template T
* @param {?} map
* @return {?}
*/
function mapToArray(map) {
/** @type {?} */
var result = [];
for (var key in map) {
if (!isNil(map[key])) {
result.push(map[key]);
}
}
return result;
}
/**
* @template T
* @param {?} arr
* @return {?}
*/
function arrayToMap(arr) {
var e_1, _a;
/** @type {?} */
var result = {};
try {
for (var arr_1 = __values(arr), arr_1_1 = arr_1.next(); !arr_1_1.done; arr_1_1 = arr_1.next()) {
var val = arr_1_1.value;
if (!isNil(val)) {
result[val.id] = val;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (arr_1_1 && !arr_1_1.done && (_a = arr_1.return)) _a.call(arr_1);
}
finally { if (e_1) throw e_1.error; }
}
return result;
}
/**
* @param {?} firstPoint
* @param {?} lastPoint
* @return {?}
*/
function generateLinePath(firstPoint, lastPoint) {
return "M" + firstPoint.x$ + "," + firstPoint.y + " L " + lastPoint.x$ + "," + lastPoint.y;
}
/**
* @param {?} firstPoint
* @param {?} lastPoint
* @param {?=} curvy
* @return {?}
*/
function generateCurvePath(firstPoint, lastPoint, curvy) {
if (curvy === void 0) { curvy = 0; }
/** @type {?} */
var isHorizontal = Math.abs(firstPoint.x - lastPoint.x) > Math.abs(firstPoint.y - lastPoint.y);
/** @type {?} */
var curvyX = isHorizontal ? curvy : 0;
/** @type {?} */
var curvyY = isHorizontal ? 0 : curvy;
return "M" + firstPoint.x + "," + firstPoint.y + " C " + (firstPoint.x + curvyX) + "," + (firstPoint.y + curvyY) + "\n " + (lastPoint.x - curvyX) + "," + (lastPoint.y - curvyY) + " " + lastPoint.x + "," + lastPoint.y;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/interfaces/event.interface.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
// region events
/**
* @template T
*/
var
// region events
/**
* @template T
*/
BaseEvent = /** @class */ (function () {
function BaseEvent(entity) {
var _this = this;
this.id = UID();
this.entity = entity;
this.entityId = entity.id;
this.firing = true;
this.stopPropagation = (/**
* @return {?}
*/
function () { return (_this.firing = false); });
}
return BaseEvent;
}());
if (false) {
/** @type {?} */
BaseEvent.prototype.entity;
/** @type {?} */
BaseEvent.prototype.entityId;
/** @type {?} */
BaseEvent.prototype.stopPropagation;
/** @type {?} */
BaseEvent.prototype.firing;
/** @type {?} */
BaseEvent.prototype.id;
}
/**
* @template T
*/
var /**
* @template T
*/
LockEvent = /** @class */ (function (_super) {
__extends(LockEvent, _super);
function LockEvent(entity, locked) {
if (locked === void 0) { locked = false; }
var _this = _super.call(this, entity) || this;
_this.locked = locked;
return _this;
}
return LockEvent;
}(BaseEvent));
if (false) {
/** @type {?} */
LockEvent.prototype.locked;
}
/**
* @template P, T
*/
var /**
* @template P, T
*/
ParentChangeEvent = /** @class */ (function (_super) {
__extends(ParentChangeEvent, _super);
function ParentChangeEvent(entity, parent) {
var _this = _super.call(this, entity) || this;
_this.parent = parent;
return _this;
}
return ParentChangeEvent;
}(BaseEvent));
if (false) {
/** @type {?} */
ParentChangeEvent.prototype.parent;
}
/**
* @template T
*/
var /**
* @template T
*/
SelectionEvent = /** @class */ (function (_super) {
__extends(SelectionEvent, _super);
function SelectionEvent(entity, selected) {
var _this = _super.call(this, entity) || this;
_this.isSelected = selected;
return _this;
}
return SelectionEvent;
}(BaseEvent));
if (false) {
/** @type {?} */
SelectionEvent.prototype.isSelected;
}
/**
* @template T
*/
var /**
* @template T
*/
PaintedEvent = /** @class */ (function (_super) {
__extends(PaintedEvent, _super);
function PaintedEvent(entity, painted) {
if (painted === void 0) { painted = false; }
var _this = _super.call(this, entity) || this;
_this.isPainted = painted;
return _this;
}
return PaintedEvent;
}(BaseEvent));
if (false) {
/** @type {?} */
PaintedEvent.prototype.isPainted;
}
/**
* @record
*/
function DestroyOptions() { }
if (false) {
/** @type {?|undefined} */
DestroyOptions.prototype.propagate;
/** @type {?|undefined} */
DestroyOptions.prototype.emit;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/base.entity.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var BaseEntity = /** @class */ (function () {
function BaseEntity(id, logPrefix) {
if (logPrefix === void 0) { logPrefix = ''; }
this._destroyed = new Subject();
this._destroyed$ = this._destroyed.asObservable();
this._locked = new BehaviorSubject(false);
this._locked$ = this._locked.asObservable();
this._id = id || UID();
this._logPrefix = "" + logPrefix;
}
Object.defineProperty(BaseEntity.prototype, "id", {
get: /**
* @return {?}
*/
function () {
return this._id;
},
set: /**
* @param {?} id
* @return {?}
*/
function (id) {
this._id = id;
},
enumerable: true,
configurable: true
});
/**
* @param {?} message
* @param {...?} args
* @return {?}
*/
BaseEntity.prototype.log = /**
* @param {?} message
* @param {...?} args
* @return {?}
*/
function (message) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
log.apply(void 0, __spread([this._logPrefix + " " + message + ": ", LOG_LEVEL.LOG], args));
};
/**
* @param {?} message
* @param {...?} args
* @return {?}
*/
BaseEntity.prototype.withLog = /**
* @param {?} message
* @param {...?} args
* @return {?}
*/
function (message) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
return withLog.apply(void 0, __spread([this._logPrefix + " " + message + ": ", LOG_LEVEL.LOG], args));
};
/**
* @return {?}
*/
BaseEntity.prototype.getLocked = /**
* @return {?}
*/
function () {
return this._locked.getValue();
};
/**
* @param {?=} locked
* @return {?}
*/
BaseEntity.prototype.setLocked = /**
* @param {?=} locked
* @return {?}
*/
function (locked) {
if (locked === void 0) { locked = true; }
this._locked.next(locked);
};
// tslint:disable-next-line
// tslint:disable-next-line
/**
* @param {?=} lookupTable
* @param {?=} clone
* @return {?}
*/
BaseEntity.prototype.doClone =
// tslint:disable-next-line
/**
* @param {?=} lookupTable
* @param {?=} clone
* @return {?}
*/
function (lookupTable, clone) {
if (lookupTable === void 0) { lookupTable = {}; }
/*noop*/
};
/**
* @param {?=} lookupTable
* @return {?}
*/
BaseEntity.prototype.clone = /**
* @param {?=} lookupTable
* @return {?}
*/
function (lookupTable) {
if (lookupTable === void 0) { lookupTable = {}; }
// try and use an existing clone first
if (lookupTable[this.id]) {
return lookupTable[this.id];
}
/** @type {?} */
var clone = __assign({}, this);
clone.id = UID();
// clone.clearListeners();
lookupTable[this.id] = clone;
this.doClone(lookupTable, clone);
return clone;
};
/**
* @return {?}
*/
BaseEntity.prototype.lockChanges = /**
* @return {?}
*/
function () {
var _this = this;
return this._locked$.pipe(takeUntil(this.onEntityDestroy()), map((/**
* @param {?} locked
* @return {?}
*/
function (locked) { return new LockEvent(_this, locked); })), this.withLog('lockChanges'));
};
/**
* @param {?=} options
* @return {?}
*/
BaseEntity.prototype.destroy = /**
* @param {?=} options
* @return {?}
*/
function (options) {
/** @type {?} */
var defaultOptions = __assign({ emit: true, propagate: true }, options);
this.log('entity destroyed');
this._destroyed.next(defaultOptions);
this._destroyed.complete();
};
/**
* @return {?}
*/
BaseEntity.prototype.onEntityDestroy = /**
* @return {?}
*/
function () {
return this._destroyed$.pipe(filter((/**
* @param {?} opts
* @return {?}
*/
function (opts) { return opts.emit; })), mapTo(new BaseEvent(this)));
};
return BaseEntity;
}());
if (false) {
/**
* @type {?}
* @private
*/
BaseEntity.prototype._id;
/**
* a prefix to make logs more easier
* @type {?}
* @private
*/
BaseEntity.prototype._logPrefix;
/**
* @type {?}
* @private
*/
BaseEntity.prototype._destroyed;
/**
* @type {?}
* @private
*/
BaseEntity.prototype._destroyed$;
/**
* @type {?}
* @private
*/
BaseEntity.prototype._locked;
/**
* @type {?}
* @private
*/
BaseEntity.prototype._locked$;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/models/base.model.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @template X
*/
var /**
* @template X
*/
BaseModel = /** @class */ (function (_super) {
__extends(BaseModel, _super);
function BaseModel(type, id, logPrefix) {
if (logPrefix === void 0) { logPrefix = '[Base]'; }
var _this = _super.call(this, id, logPrefix) || this;
_this._parent = new BehaviorSubject(null);
_this._parent$ = _this._parent.asObservable();
_this._selected = new BehaviorSubject(false);
_this._selected$ = _this._selected.asObservable();
_this._painted = new BehaviorSubject(false);
_this._painted$ = _this._painted.asObservable();
_this._type = type;
return _this;
}
/**
* @return {?}
*/
BaseModel.prototype.getParent = /**
* @return {?}
*/
function () {
return this._parent.getValue();
};
/**
* @param {?} parent
* @return {?}
*/
BaseModel.prototype.setParent = /**
* @param {?} parent
* @return {?}
*/
function (parent) {
this._parent.next(parent);
};
/**
* @return {?}
*/
BaseModel.prototype.parentChanges = /**
* @return {?}
*/
function () {
var _this = this;
return this._parent$.pipe(takeUntil(this.onEntityDestroy()), map((/**
* @param {?} p
* @return {?}
*/
function (p) { return new ParentChangeEvent(_this, p); })));
};
/**
* @return {?}
*/
BaseModel.prototype.getPainted = /**
* @return {?}
*/
function () {
return this._painted.getValue();
};
/**
* @param {?=} painted
* @return {?}
*/
BaseModel.prototype.setPainted = /**
* @param {?=} painted
* @return {?}
*/
function (painted) {
if (painted === void 0) { painted = true; }
this._painted.next(painted);
};
/**
* @return {?}
*/
BaseModel.prototype.paintChanges = /**
* @return {?}
*/
function () {
var _this = this;
return this._painted$.pipe(takeUntil(this.onEntityDestroy()), map((/**
* @param {?} p
* @return {?}
*/
function (p) { return new PaintedEvent(_this, p); })));
};
/**
* @return {?}
*/
BaseModel.prototype.getType = /**
* @return {?}
*/
function () {
return this._type;
};
/**
* @return {?}
*/
BaseModel.prototype.getSelected = /**
* @return {?}
*/
function () {
return this._selected.getValue();
};
/**
* @return {?}
*/
BaseModel.prototype.selectSelected = /**
* @return {?}
*/
function () {
return this._selected.asObservable();
};
/**
* @param {?=} selected
* @return {?}
*/
BaseModel.prototype.setSelected = /**
* @param {?=} selected
* @return {?}
*/
function (selected) {
if (selected === void 0) { selected = true; }
this._selected.next(selected);
};
/**
* @return {?}
*/
BaseModel.prototype.selectionChanges = /**
* @return {?}
*/
function () {
var _this = this;
return this._selected$.pipe(takeUntil(this.onEntityDestroy()), map((/**
* @param {?} s
* @return {?}
*/
function (s) { return new SelectionEvent(_this, s); })), this.withLog('selectionChanges'));
};
/**
* @return {?}
*/
BaseModel.prototype.getSelectedEntities = /**
* @return {?}
*/
function () {
return this._selected.value ? [this] : [];
};
return BaseModel;
}(BaseEntity));
if (false) {
/**
* @type {?}
* @private
*/
BaseModel.prototype._type;
/**
* @type {?}
* @private
*/
BaseModel.prototype._parent;
/**
* @type {?}
* @private
*/
BaseModel.prototype._parent$;
/**
* @type {?}
* @private
*/
BaseModel.prototype._selected;
/**
* @type {?}
* @private
*/
BaseModel.prototype._selected$;
/**
* @type {?}
* @private
*/
BaseModel.prototype._painted;
/**
* @type {?}
* @private
*/
BaseModel.prototype._painted$;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/models/node.model.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @template P
*/
var /**
* @template P
*/
NodeModel = /** @class */ (function (_super) {
__extends(NodeModel, _super);
function NodeModel(nodeType, id, extras, x, y, width, height, logPrefix) {
if (nodeType === void 0) { nodeType = 'default'; }
if (extras === void 0) { extras = {}; }
if (x === void 0) { x = 0; }
if (y === void 0) { y = 0; }
if (width === void 0) { width = 0; }
if (height === void 0) { height = 0; }
if (logPrefix === void 0) { logPrefix = '[Node]'; }
var _this = _super.call(this, nodeType, id, logPrefix) || this;
_this._extras = new BehaviorSubject(extras);
_this._ports = new BehaviorSubject({});
_this._dimensions = new BehaviorSubject({ width: width, height: height });
_this._coords = new BehaviorSubject({ x: x, y: y });
_this.extras$ = _this._extras.asObservable();
_this.ports$ = _this._ports.asObservable();
_this.coords$ = _this._coords.asObservable();
_this.dimensions$ = _this._dimensions.asObservable();
return _this;
}
/**
* @return {?}
*/
NodeModel.prototype.getCoords = /**
* @return {?}
*/
function () {
return this._coords.getValue();
};
/**
* @param {?} __0
* @return {?}
*/
NodeModel.prototype.setCoords = /**
* @param {?} __0
* @return {?}
*/
function (_a) {
var x = _a.x, y = _a.y;
var _b = this.getCoords(), oldX = _b.x, oldY = _b.y;
Object.values(this._ports.getValue()).forEach((/**
* @param {?} port
* @return {?}
*/
function (port) {
Object.values(port.getLinks()).forEach((/**
* @param {?} link
* @return {?}
*/
function (link) {
/** @type {?} */
var point = link.getPointForPort(port);
var _a = point.getCoords(), pointX = _a.x, pointY = _a.y;
point.setCoords({ x: pointX + x - oldX, y: pointY + y - oldY });
}));
}));
this._coords.next({ x: x, y: y });
};
// TODO: implement better transition on auto arrange!
// TODO: implement better transition on auto arrange!
/**
* @param {?} __0
* @return {?}
*/
NodeModel.prototype.transitionToCoords =
// TODO: implement better transition on auto arrange!
/**
* @param {?} __0
* @return {?}
*/
function (_a) {
var x = _a.x, y = _a.y;
// const transitionCompleted = new ReplaySubject(1);
// let { x: oldX, y: oldY } = this.getCoords();
// console.log(x, y, oldX, oldY);
// interval(0)
// .pipe(takeUntil(transitionCompleted))
// .subscribe(
// () => {
// if (oldX < x) {
// oldX++;
// } else if (oldX > x) {
// oldX--;
// }
// if (y > oldY) {
// oldY++;
// } else if (y < oldY) {
// oldY--;
// }
// Object.values(this._ports.getValue()).forEach(port => {
// Object.values(port.getLinks()).forEach(link => {
// const point = link.getPointForPort(port);
// const { x: pointX, y: pointY } = point.getCoords();
// point.setCoords({ x: pointX + x - oldX, y: pointY + y - oldY });
// });
// });
// this._coords.next({ x: oldX, y: oldY });
// if (x === oldX && y === oldY) {
// transitionCompleted.next(true);
// transitionCompleted.complete();
// }
// },
// err => {
// console.error(err);
// },
// () => {
// console.log('finished transition');
// }
// );
};
// TODO: override selectionChanges and replace this with it (convert to rx)
// TODO: override selectionChanges and replace this with it (convert to rx)
/**
* @return {?}
*/
NodeModel.prototype.getSelectedEntities =
// TODO: override selectionChanges and replace this with it (convert to rx)
/**
* @return {?}
*/
function () {
/** @type {?} */
var entities = _super.prototype.getSelectedEntities.call(this);
// add the points of each link that are selected here
if (this.getSelected()) {
Object.values(this._ports.getValue()).forEach((/**
* @param {?} port
* @return {?}
*/
function (port) {
/** @type {?} */
var links = Object.values(port.getLinks());
entities = entities.concat(links.map((/**
* @param {?} link
* @return {?}
*/
function (link) {
return link.getPointForPort(port);
})));
}));
}
this.log('selectedEntities', entities);
return entities;
};
// TODO: map to BaseEvent
// TODO: map to BaseEvent
/**
* @return {?}
*/
NodeModel.prototype.coordsChanges =
// TODO: map to BaseEvent
/**
* @return {?}
*/
function () {
return this.coords$.pipe(takeUntil(this.onEntityDestroy()));
};
/**
* @return {?}
*/
NodeModel.prototype.selectCoords = /**
* @return {?}
*/
function () {
return this.coords$.pipe(takeUntil(this.onEntityDestroy()), distinctUntilChanged());
};
/**
* @return {?}
*/
NodeModel.prototype.selectX = /**
* @return {?}
*/
function () {
return this.selectCoords().pipe(map((/**
* @param {?} c
* @return {?}
*/
function (c) { return c.x; })), this.withLog('selectX'), distinctUntilChanged());
};
/**
* @return {?}
*/
NodeModel.prototype.selectY = /**
* @return {?}
*/
function () {
return this.selectCoords().pipe(map((/**
* @param {?} c
* @return {?}
*/
function (c) { return c.y; })), this.withLog('selectY'), distinctUntilChanged());
};
/**
* Assign a port to the node and set the node as its getParent
* @returns the inserted port
*/
/**
* Assign a port to the node and set the node as its getParent
* @param {?} port
* @return {?} the inserted port
*/
NodeModel.prototype.addPort = /**
* Assign a port to the node and set the node as its getParent
* @param {?} port
* @return {?} the inserted port
*/
function (port) {
var _a;
port.setParent(this);
this._ports.next(__assign({}, this._ports.value, (_a = {}, _a[port.id] = port, _a)));
return port;
};
/**
* @param {?} id
* @return {?}
*/
NodeModel.prototype.getPort = /**
* @param {?} id
* @return {?}
*/
function (id) {
return this._ports.value[id];
};
/**
* @param {?=} selector
* @return {?}
*/
NodeModel.prototype.selectPorts = /**
* @param {?=} selector
* @return {?}
*/
function (selector) {
// TODO: implement selector
// TODO: create coerce func
return this.ports$.pipe(takeUntil(this.onEntityDestroy()), distinctUntilChanged(), map((/**
* @param {?} ports
* @return {?}
*/
function (ports) { return mapToArray(ports); })), this.withLog('selectPorts'));
};
/**
* @param {?=} ids
* @return {?}
*/
NodeModel.prototype.getPorts = /**
* @param {?=} ids
* @return {?}
*/
function (ids) {
return this._ports.getValue();
};
/**
* @param {?} __0
* @return {?}
*/
NodeModel.prototype.setDimensions = /**
* @param {?} __0
* @return {?}
*/
function (_a) {
var width = _a.width, height = _a.height;
this._dimensions.next({ width: width, height: height });
};
/**
* @return {?}
*/
NodeModel.prototype.getDimensions = /**
* @return {?}
*/
function () {
return this._dimensions.getValue();
};
// TODO: return BaseEvent extension
// TODO: return BaseEvent extension
/**
* @return {?}
*/
NodeModel.prototype.dimensionChanges =
// TODO: return BaseEvent extension
/**
* @return {?}
*/
function () {
return this.dimensions$.pipe(takeUntil(this.onEntityDestroy()), distinctUntilChanged(), this.withLog('DimensionChanges'));
};
/**
* @return {?}
*/
NodeModel.prototype.getHeight = /**
* @return {?}
*/
function () {
return this._dimensions.getValue().height;
};
/**
* @return {?}
*/
NodeModel.prototype.getWidth = /**
* @return {?}
*/
function () {
return this._dimensions.getValue().width;
};
/**
* @return {?}
*/
NodeModel.prototype.selectWidth = /**
* @return {?}
*/
function () {
return this.dimensions$.pipe(takeUntil(this.onEntityDestroy()), map((/**
* @param {?} d
* @return {?}
*/
function (d) { return d.width; })), distinctUntilChanged(), this.withLog('selectWidth'));
};
/**
* @return {?}
*/
NodeModel.prototype.selectHeight = /**
* @return {?}
*/
function () {
return this.dimensions$.pipe(takeUntil(this.onEntityDestroy()), map((/**
* @param {?} d
* @return {?}
*/
function (d) { return d.width; })), distinctUntilChanged(), this.withLog('selectHeight'));
};
/**
* @param {?} extras
* @return {?}
*/
NodeModel.prototype.setExtras = /**
* @param {?} extras
* @return {?}
*/
function (extras) {
this._extras.next(extras);
};
/**
* @return {?}
*/
NodeModel.prototype.getExtras = /**
* @return {?}
*/
function () {
return this._extras.getValue();
};
/**
* @template E
* @param {?=} selector
* @return {?}
*/
NodeModel.prototype.selectExtras = /**
* @template E
* @param {?=} selector
* @return {?}
*/
function (selector) {
// TODO: impl selector
return this.extras$.pipe(takeUntil(this.onEntityDestroy()), distinctUntilChanged());
};
return NodeModel;
}(BaseModel));
if (false) {
/** @type {?} */
NodeModel.prototype.id;
/** @type {?} */
NodeModel.prototype.diagramEngine;
/**
* @type {?}
* @private
*/
NodeModel.prototype._extras;
/**
* @type {?}
* @private
*/
NodeModel.prototype._ports;
/**
* @type {?}
* @private
*/
NodeModel.prototype._coords;
/**
* @type {?}
* @private
*/
NodeModel.prototype._dimensions;
/**
* @type {?}
* @private
*/
NodeModel.prototype.extras$;
/**
* @type {?}
* @private
*/
NodeModel.prototype.ports$;
/**
* @type {?}
* @private
*/
NodeModel.prototype.coords$;
/**
* @type {?}
* @private
*/
NodeModel.prototype.dimensions$;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/models/point.model.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var PointModel = /** @class */ (function (_super) {
__extends(PointModel, _super);
function PointModel(link, _a) {
var x = _a.x, y = _a.y;
var _this = _super.call(this) || this;
_this._coords = new BehaviorSubject({ x: x, y: y });
_this.coords$ = _this._coords.asObservable();
_this.setParent(link);
return _this;
}
/**
* @return {?}
*/
PointModel.prototype.isConnectedToPort = /**
* @return {?}
*/
function () {
return this.getParent().getPortForPoint(this) !== null;
};
/**
* @return {?}
*/
PointModel.prototype.getLink = /**
* @return {?}
*/
function () {
return this.getParent();
};
/**
* @param {?=} options
* @return {?}
*/
PointModel.prototype.destroy = /**
* @param {?=} options
* @return {?}
*/
function (options) {
if (this.getParent) {
this.getParent().removePoint(this);
}
_super.prototype.destroy.call(this, options);
};
/**
* @param {?} newCoords
* @return {?}
*/
PointModel.prototype.setCoords = /**
* @param {?} newCoords
* @return {?}
*/
function (newCoords) {
this._coords.next(__assign({}, this._coords.getValue(), newCoords));
};
/**
* @return {?}
*/
PointModel.prototype.selectCoords = /**
* @return {?}
*/
function () {
return this.coords$.pipe(takeUntil(this.onEntityDestroy()), distinctUntilChanged());
};
/**
* @return {?}
*/
PointModel.prototype.getCoords = /**
* @return {?}
*/
function () {
return this._coords.getValue();
};
/**
* @return {?}
*/
PointModel.prototype.selectX = /**
* @return {?}
*/
function () {
return this.selectCoords().pipe(map((/**
* @param {?} c
* @return {?}
*/
function (c) { return c.x; })), distinctUntilChanged());
};
/**
* @return {?}
*/
PointModel.prototype.selectY = /**
* @return {?}
*/
function () {
return this.selectCoords().pipe(map((/**
* @param {?} c
* @return {?}
*/
function (c) { return c.y; })), distinctUntilChanged());
};
return PointModel;
}(BaseModel));
if (false) {
/**
* @type {?}
* @private
*/
PointModel.prototype._coords;
/**
* @type {?}
* @private
*/
PointModel.prototype.coords$;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/models/link.model.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var LinkModel = /** @class */ (function (_super) {
__extends(LinkModel, _super);
function LinkModel(linkType, id) {
if (linkType === void 0) { linkType = 'default'; }
var _this = _super.call(this, linkType, id) || this;
_this.label = new BehaviorSubject(null);
_this.points = [new PointModel(_this, { x: 0, y: 0 }), new PointModel(_this, { x: 0, y: 0 })];
_this.extras = {};
_this.sourcePort = null;
_this.targetPort = null;
return _this;
}
/**
* @param {?} name
* @return {?}
*/
LinkModel.prototype.setName = /**
* @param {?} name
* @return {?}
*/
function (name) {
this.name = name;
};
/**
* @return {?}
*/
LinkModel.prototype.getName = /**
* @return {?}
*/
function () {
return this.name;
};
/**
* @return {?}
*/
LinkModel.prototype.getExtras = /**
* @return {?}
*/
function () {
return this.extras;
};
/**
* @param {?} extras
* @return {?}
*/
LinkModel.prototype.setExtras = /**
* @param {?} extras
* @return {?}
*/
function (extras) {
this.extras = extras;
};
/**
* @param {?=} options
* @return {?}
*/
LinkModel.prototype.destroy = /**
* @param {?=} options
* @return {?}
*/
function (options) {
if (this.sourcePort) {
this.sourcePort.removeLink(this);
}
if (this.targetPort) {
this.targetPort.removeLink(this);
}
_super.prototype.destroy.call(this, options);
};
/**
* @param {?=} lookupTable
* @param {?=} clone
* @return {?}
*/
LinkModel.prototype.doClone = /**
* @param {?=} lookupTable
* @param {?=} clone
* @return {?}
*/
function (lookupTable, clone) {
if (lookupTable === void 0) { lookupTable = {}; }
clone.setPoints(this.getPoints().map((/**
* @param {?} point
* @return {?}
*/
function (point) {
return point.clone(lookupTable);
})));
if (this.sourcePort) {
clone.setSourcePort(this.sourcePort.clone(lookupTable));
}
if (this.targetPort) {
clone.setTargetPort(this.targetPort.clone(lookupTable));
}
};
/**
* @param {?} point
* @return {?}
*/
LinkModel.prototype.isLastPoint = /**
* @param {?} point
* @return {?}
*/
function (point) {
/** @type {?} */
var index = this.getPointIndex(point);
return index === this.points.length - 1;
};
/**
* @param {?} point
* @return {?}
*/
LinkModel.prototype.getPointIndex = /**
* @param {?} point
* @return {?}
*/
function (point) {
return this.points.indexOf(point);
};
/**
* @param {?} id
* @return {?}
*/
LinkModel.prototype.getPointModel = /**
* @param {?} id
* @return {?}
*/
function (id) {
var e_1, _a;
try {
for (var _b = __values(this.points), _c = _b.next(); !_c.done; _c = _b.next()) {
var point = _c.value;
if (point.id === id) {
return point;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
return null;
};
/**
* @param {?} point
* @return {?}
*/
LinkModel.prototype.getPortForPoint = /**
* @param {?} point
* @return {?}
*/
function (point) {
if (this.sourcePort !== null && this.getFirstPoint().id === point.id) {
return this.sourcePort;
}
if (this.targetPort !== null && this.getLastPoint().id === point.id) {
return this.targetPort;
}
return null;
};
/**
* @param {?} port
* @return {?}
*/
LinkModel.prototype.getPointForPort = /**
* @param {?} port
* @return {?}
*/
function (port) {
if (this.sourcePort !== null && this.sourcePort.id === port.id) {
return this.getFirstPoint();
}
if (this.targetPort !== null && this.targetPort.id === port.id) {
return this.getLastPoint();
}
return null;
};
/**
* @return {?}
*/
LinkModel.prototype.getFirstPoint = /**
* @return {?}
*/
function () {
return this.points[0];
};
/**
* @return {?}
*/
LinkModel.prototype.getLastPoint = /**
* @return {?}
*/
function () {
return this.points[this.points.length - 1];
};
/**
* @param {?} port
* @return {?}
*/
LinkModel.prototype.setSourcePort = /**
* @param {?} port
* @return {?}
*/
function (port) {
if (port !== null) {
port.addLink(this);
}
if (this.sourcePort !== null) {
this.sourcePort.removeLink(this);
}
this.sourcePort = port;
};
/**
* @return {?}
*/
LinkModel.prototype.getSourcePort = /**
* @return {?}
*/
function () {
return this.sourcePort;
};
/**
* @return {?}
*/
LinkModel.prototype.getTargetPort = /**
* @return {?}
*/
function () {
return this.targetPort;
};
/**
* @param {?} port
* @return {?}
*/
LinkModel.prototype.setTargetPort = /**
* @param {?} port
* @return {?}
*/
function (port) {
if (port !== null) {
port.addLink(this);
}
if (this.targetPort !== null) {
this.targetPort.removeLink(this);
}
this.targetPort = port;
};
/**
* @param {?} __0
* @return {?}
*/
LinkModel.prototype.point = /**
* @param {?} __0
* @return {?}
*/
function (_a) {
var x = _a.x, y = _a.y;
return this.addPoint(this.generatePoint({ x: x, y: y }));
};
/**
* @return {?}
*/
LinkModel.prototype.getPoints = /**
* @return {?}
*/
function () {
return this.points;
};
/**
* @param {?} points
* @return {?}
*/
LinkModel.prototype.setPoints = /**
* @param {?} points
* @return {?}
*/
function (points) {
var _this = this;
points.forEach((/**
* @param {?} point
* @return {?}
*/
function (point) {
point.setParent(_this);
}));
this.points = points;
};
/**
* @param {?} label
* @return {?}
*/
LinkModel.prototype.setLabel = /**
* @param {?} label
* @return {?}
*/
function (label) {
label.setParent(this);
this.label.next(label);
label.setPainted();
};
/**
* @return {?}
*/
LinkModel.prototype.selectLabel = /**
* @return {?}
*/
function () {
return this.label.asObservable();
};
/**
* @return {?}
*/
LinkModel.prototype.getLabel = /**
* @return {?}
*/
function () {
return this.label.getValue();
};
/**
* @return {?}
*/
LinkModel.prototype.resetLabel = /**
* @return {?}
*/
function () {
/** @type {?} */
var currentLabel = this.label.getValue();
if (currentLabel) {
currentLabel.setParent(null);
currentLabel.setPainted(false);
}
this.label.next(null);
};
/**
* @param {?} pointModel
* @return {?}
*/
LinkModel.prototype.removePoint = /**
* @param {?} pointModel
* @return {?}
*/
function (pointModel) {
this.points.splice(this.getPointIndex(pointModel), 1);
};
/**
* @param {?} pointModel
* @return {?}
*/
LinkModel.prototype.removePointsBefore = /**
* @param {?} pointModel
* @return {?}
*/
function (pointModel) {
this.points.splice(0, this.getPointIndex(pointModel));
};
/**
* @param {?} pointModel
* @return {?}
*/
LinkModel.prototype.removePointsAfter = /**
* @param {?} pointModel
* @return {?}
*/
function (pointModel) {
this.points.splice(this.getPointIndex(pointModel) + 1);
};
/**
* @return {?}
*/
LinkModel.prototype.removeMiddlePoints = /**
* @return {?}
*/
function () {
if (this.points.length > 2) {
this.points.splice(0, this.points.length - 2);
}
};
/**
* @template P
* @param {?} pointModel
* @param {?=} index
* @return {?}
*/
LinkModel.prototype.addPoint = /**
* @template P
* @param {?} pointModel
* @param {?=} index
* @return {?}
*/
function (pointModel, index) {
if (index === void 0) { index = 1; }
pointModel.setParent(this);
this.points.splice(index, 0, pointModel);
return pointModel;
};
/**
* @param {?} __0
* @return {?}
*/
LinkModel.prototype.generatePoint = /**
* @param {?} __0
* @return {?}
*/
function (_a) {
var _b = _a.x, x = _b === void 0 ? 0 : _b, _c = _a.y, y = _c === void 0 ? 0 : _c;
return new PointModel(this, { x: x, y: y });
};
return LinkModel;
}(BaseModel));
if (false) {
/** @type {?} */
LinkModel.prototype.diagramEngine;
/**
* @type {?}
* @private
*/
LinkModel.prototype.name;
/**
* @type {?}
* @private
*/
LinkModel.prototype.sourcePort;
/**
* @type {?}
* @private
*/
LinkModel.prototype.targetPort;
/**
* @type {?}
* @private
*/
LinkModel.prototype.points;
/**
* @type {?}
* @private
*/
LinkModel.prototype.extras;
/**
* @type {?}
* @private
*/
LinkModel.prototype.label;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/models/port.model.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var PortModel = /** @class */ (function (_super) {
__extends(PortModel, _super);
function PortModel(name, type, id, maximumLinks, linkType) {
var _this = _super.call(this, type, id) || this;
_this.name = name;
_this.links$ = new BehaviorSubject({});
_this.maximumLinks = maximumLinks;
_this.x$ = new BehaviorSubject(0);
_this.y$ = new BehaviorSubject(0);
_this.height$ = new BehaviorSubject(0);
_this.width$ = new BehaviorSubject(0);
_this.linkType = linkType;
return _this;
}
/**
* @return {?}
*/
PortModel.prototype.getNode = /**
* @return {?}
*/
function () {
return this.getParent();
};
/**
* @return {?}
*/
PortModel.prototype.getName = /**
* @return {?}
*/
function () {
return this.name;
};
/**
* @return {?}
*/
PortModel.prototype.selectX = /**
* @return {?}
*/
function () {
return this.x$.asObservable();
};
/**
* @return {?}
*/
PortModel.prototype.selectY = /**
* @return {?}
*/
function () {
return this.y$.asObservable();
};
/**
* @return {?}
*/
PortModel.prototype.getY = /**
* @return {?}
*/
function () {
return this.y$.getValue();
};
/**
* @return {?}
*/
PortModel.prototype.getX = /**
* @return {?}
*/
function () {
return this.x$.getValue();
};
/**
* @return {?}
*/
PortModel.prototype.getHeight = /**
* @return {?}
*/
function () {
return this.height$.getValue();
};
/**
* @return {?}
*/
PortModel.prototype.getWidth = /**
* @return {?}
*/
function () {
return this.width$.getValue();
};
/**
* @return {?}
*/
PortModel.prototype.getMaximumLinks = /**
* @return {?}
*/
function () {
return this.maximumLinks;
};
/**
* @param {?} maximumLinks
* @return {?}
*/
PortModel.prototype.setMaximumLinks = /**
* @param {?} maximumLinks
* @return {?}
*/
function (maximumLinks) {
this.maximumLinks = maximumLinks;
};
/**
* @return {?}
*/
PortModel.prototype.getLinkType = /**
* @return {?}
*/
function () {
return this.linkType;
};
/**
* @param {?} type
* @return {?}
*/
PortModel.prototype.setLinkType = /**
* @param {?} type
* @return {?}
*/
function (type) {
this.linkType = type;
};
/**
* @param {?} link
* @return {?}
*/
PortModel.prototype.removeLink = /**
* @param {?} link
* @return {?}
*/
function (link) {
/** @type {?} */
var links = this.links$.getValue();
delete links[link.id];
this.links$.next(__assign({}, links));
};
/**
* @param {?} link
* @return {?}
*/
PortModel.prototype.addLink = /**
* @param {?} link
* @return {?}
*/
function (link) {
var _a;
this.links$.next(__assign({}, this.links$.value, (_a = {}, _a[link.id] = link, _a)));
};
/**
* @return {?}
*/
PortModel.prototype.getLinks = /**
* @return {?}
*/
function () {
return this.links$.getValue();
};
/**
* @return {?}
*/
PortModel.prototype.selectLinks = /**
* @return {?}
*/
function () {
return this.links$.asObservable();
};
/**
* @param {?} __0
* @return {?}
*/
PortModel.prototype.updateCoords = /**
* @param {?} __0
* @return {?}
*/
function (_a) {
var x = _a.x, y = _a.y, width = _a.width, height = _a.height;
this.x$.next(x);
this.y$.next(y);
this.width$.next(width);
this.height$.next(height);
};
/**
* @param {?} port
* @return {?}
*/
PortModel.prototype.canLinkToPort = /**
* @param {?} port
* @return {?}
*/
function (port) {
return true;
};
/**
* @return {?}
*/
PortModel.prototype.isLocked = /**
* @return {?}
*/
function () {
return _super.prototype.getLocked.call(this);
};
/**
* @return {?}
*/
PortModel.prototype.createLinkModel = /**
* @return {?}
*/
function () {
/** @type {?} */
var numberOfLinks = Object.keys(this.links$.getValue()).length;
if (this.maximumLinks === 1 && numberOfLinks >= 1) {
/** @type {?} */
var linkToRemove = Object.values(this.links$.getValue())[0];
linkToRemove.destroy();
return null;
}
else if (numberOfLinks >= this.maximumLinks) {
// for the moment we will remove the first link by default
/** @type {?} */
var linkToRemove = Object.values(this.links$.getValue())[0];
linkToRemove.destroy();
return null;
}
return null;
};
return PortModel;
}(BaseModel));
if (false) {
/**
* @type {?}
* @private
*/
PortModel.prototype.name;
/**
* @type {?}
* @private
*/
PortModel.prototype.links$;
/**
* @type {?}
* @private
*/
PortModel.prototype.maximumLinks;
/**
* @type {?}
* @private
*/
PortModel.prototype.linkType;
/**
* @type {?}
* @private
*/
PortModel.prototype.x$;
/**
* @type {?}
* @private
*/
PortModel.prototype.y$;
/**
* @type {?}
* @private
*/
PortModel.prototype.width$;
/**
* @type {?}
* @private
*/
PortModel.prototype.height$;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/models/diagram.model.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var DiagramModel = /** @class */ (function (_super) {
__extends(DiagramModel, _super);
function DiagramModel(diagramEngine, id) {
var _this = _super.call(this, id) || this;
_this.diagramEngine = diagramEngine;
_this.nodes$ = new BehaviorSubject({});
_this.links$ = new BehaviorSubject({});
_this.zoom$ = new BehaviorSubject(100);
_this.offsetX$ = new BehaviorSubject(0);
_this.offsetY$ = new BehaviorSubject(0);
_this.gridSize$ = new BehaviorSubject(0);
return _this;
}
// TODO: support the following events for links and nodes
// removed, updated<positionChanged/dataChanged>, added
// TODO: support the following events for links and nodes
// removed, updated<positionChanged/dataChanged>, added
/**
* @return {?}
*/
DiagramModel.prototype.getNodes =
// TODO: support the following events for links and nodes
// removed, updated<positionChanged/dataChanged>, added
/**
* @return {?}
*/
function () {
return this.nodes$.getValue();
};
/**
* @param {?