@logicflow/react-node-registry
Version:
LogicFlow React Shape
103 lines • 5.09 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReactNodeModel = void 0;
var core_1 = require("@logicflow/core");
var lodash_es_1 = require("lodash-es");
var ReactNodeModel = /** @class */ (function (_super) {
__extends(ReactNodeModel, _super);
function ReactNodeModel(data, graphModel) {
var _this = _super.call(this, data, graphModel) || this;
var properties = data.properties;
if (properties) {
var _a = properties._showTitle, _showTitle = _a === void 0 ? false : _a, _b = properties.style, style = _b === void 0 ? {} : _b;
if (_showTitle) {
_this.minWidth = 160;
_this.minHeight = 80;
_this.text.editable = false;
// 判断当前节点宽高是否小于最小宽高,如果是,强制设置为最小宽高
var newWidth = _this.width < _this.minWidth ? _this.minWidth : _this.width;
var newHeight = _this.height < _this.minHeight ? _this.minHeight : _this.height;
_this.setProperties(__assign(__assign({ _expanded: false }, properties), { style: __assign({ overflow: 'visible' }, (0, lodash_es_1.cloneDeep)(style)), width: newWidth, height: newHeight }));
_this.setNodeActions([
{
name: '复制',
callback: function (nodeModel, graphModel) {
graphModel.cloneNode(nodeModel.id);
},
},
{
name: '删除',
callback: function (nodeModel, graphModel) {
graphModel.deleteNode(nodeModel.id);
},
},
]);
}
}
return _this;
}
ReactNodeModel.prototype.setAttributes = function () {
var _a = this.properties, width = _a.width, height = _a.height, radius = _a.radius, _showTitle = _a._showTitle, _titleHeight = _a._titleHeight;
if (!(0, lodash_es_1.isNil)(width)) {
this.width = width;
}
if (!(0, lodash_es_1.isNil)(height)) {
this.height = height;
}
if (!(0, lodash_es_1.isNil)(radius)) {
this.radius = radius;
}
if (this.__baseHeight === undefined) {
this.__baseHeight = (0, lodash_es_1.isNil)(height) ? this.height : height;
}
var extra = _showTitle ? (_titleHeight !== null && _titleHeight !== void 0 ? _titleHeight : 28) : 0;
var base = (0, lodash_es_1.isNil)(height) ? this.__baseHeight : height;
this.height = base + extra;
};
ReactNodeModel.prototype.getTextStyle = function () {
// const { x, y, width, height } = this
var _a = this.properties, _b = _a.refX, refX = _b === void 0 ? 0 : _b, _c = _a.refY, refY = _c === void 0 ? 0 : _c, textStyle = _a.textStyle;
var style = _super.prototype.getTextStyle.call(this);
// 通过 transform 重新设置 text 的位置
return __assign(__assign(__assign({}, style), ((0, lodash_es_1.cloneDeep)(textStyle) || {})), { transform: "matrix(1 0 0 1 ".concat(refX, " ").concat(refY, ")") });
};
ReactNodeModel.prototype.getNodeStyle = function () {
var style = _super.prototype.getNodeStyle.call(this);
var customNodeStyle = this.properties.style;
return __assign(__assign({}, style), ((0, lodash_es_1.cloneDeep)(customNodeStyle) || {}));
};
ReactNodeModel.prototype.setNodeActions = function (actions) {
this.__actions =
(0, lodash_es_1.isArray)(actions) && !(0, lodash_es_1.isEmpty)(actions) ? (0, lodash_es_1.cloneDeep)(actions) : [];
};
return ReactNodeModel;
}(core_1.HtmlNodeModel));
exports.ReactNodeModel = ReactNodeModel;
exports.default = ReactNodeModel;
//# sourceMappingURL=model.js.map