UNPKG

@logicflow/extension

Version:
125 lines (124 loc) 5.13 kB
"use strict"; 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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RectResize = exports.RectResizeView = exports.RectResizeModel = void 0; var jsx_runtime_1 = require("preact/jsx-runtime"); var core_1 = require("@logicflow/core"); var ControlGroup_1 = __importDefault(require("../control/ControlGroup")); var RectResizeModel = /** @class */ (function (_super) { __extends(RectResizeModel, _super); function RectResizeModel(data, graphModel) { var _this = _super.call(this, data, graphModel) || this; var nodeSize = data.properties.nodeSize; if (nodeSize) { _this.width = nodeSize.width; _this.height = nodeSize.height; } return _this; } RectResizeModel.prototype.initNodeData = function (data) { _super.prototype.initNodeData.call(this, data); this.minWidth = 30; this.minHeight = 30; this.maxWidth = 2000; this.maxHeight = 2000; }; RectResizeModel.prototype.getOutlineStyle = function () { var style = _super.prototype.getOutlineStyle.call(this); var isSilentMode = this.graphModel.editConfigModel.isSilentMode; if (isSilentMode) return style; style.stroke = 'none'; if (style.hover) { style.hover.stroke = 'none'; } return style; }; RectResizeModel.prototype.getResizeOutlineStyle = function () { return { fill: 'none', stroke: 'transparent', // 矩形默认不显示调整边框 strokeWidth: 1, strokeDasharray: '3,3', }; }; RectResizeModel.prototype.getControlPointStyle = function () { return { width: 7, height: 7, fill: '#FFFFFF', stroke: '#000000', }; }; // 该方法需要在重设宽高和最大、最小限制后被调用,不建议在 initNodeData() 方法中使用 RectResizeModel.prototype.enableProportionResize = function (turnOn) { if (turnOn === void 0) { turnOn = true; } if (turnOn) { var ResizePCT = { widthPCT: 100, heightPCT: 100, }; var ResizeBasis = { basisWidth: this.width, basisHeight: this.height, }; var ScaleLimit = { maxScaleLimit: Math.min((this.maxWidth / this.width) * 100, (this.maxHeight / this.height) * 100), minScaleLimit: Math.max((this.minWidth / this.width) * 100, (this.minHeight / this.height) * 100), }; this.PCTResizeInfo = { ResizePCT: ResizePCT, ResizeBasis: ResizeBasis, ScaleLimit: ScaleLimit, }; } else { delete this.PCTResizeInfo; } }; return RectResizeModel; }(core_1.RectNodeModel)); exports.RectResizeModel = RectResizeModel; var RectResizeView = /** @class */ (function (_super) { __extends(RectResizeView, _super); function RectResizeView() { return _super !== null && _super.apply(this, arguments) || this; } RectResizeView.prototype.getControlGroup = function () { var _a = this.props, model = _a.model, graphModel = _a.graphModel; return (0, jsx_runtime_1.jsx)(ControlGroup_1.default, { model: model, graphModel: graphModel }); }; // getResizeShape绘制图形,功能等同于基础矩形的getShape功能,可以通过复写此方法,进行节点自定义 RectResizeView.prototype.getResizeShape = function () { return _super.prototype.getShape.call(this); }; RectResizeView.prototype.getShape = function () { var _a = this.props, isSelected = _a.model.isSelected, isSilentMode = _a.graphModel.editConfigModel.isSilentMode; return ((0, jsx_runtime_1.jsxs)("g", { children: [this.getResizeShape(), isSelected && !isSilentMode ? this.getControlGroup() : ''] })); }; return RectResizeView; }(core_1.RectNode)); exports.RectResizeView = RectResizeView; exports.RectResize = { type: 'rect', view: RectResizeView, model: RectResizeModel, }; exports.default = exports.RectResize;