HtmlResize.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. var core_1 = require("@logicflow/core");
  17. var ControlGroup_1 = require("../Control/ControlGroup");
  18. var HtmlResizeModel = /** @class */ (function (_super) {
  19. __extends(HtmlResizeModel, _super);
  20. function HtmlResizeModel(data, graphModel) {
  21. var _this = _super.call(this, data, graphModel) || this;
  22. var nodeSize = _this.properties.nodeSize;
  23. if (nodeSize) {
  24. _this.width = nodeSize.width;
  25. _this.height = nodeSize.height;
  26. }
  27. return _this;
  28. }
  29. HtmlResizeModel.prototype.initNodeData = function (data) {
  30. _super.prototype.initNodeData.call(this, data);
  31. this.minWidth = 30;
  32. this.minHeight = 30;
  33. this.maxWidth = 2000;
  34. this.maxHeight = 2000;
  35. };
  36. HtmlResizeModel.prototype.getOutlineStyle = function () {
  37. var style = _super.prototype.getOutlineStyle.call(this);
  38. var isSilentMode = this.graphModel.editConfigModel.isSilentMode;
  39. if (isSilentMode)
  40. return style;
  41. style.stroke = 'none';
  42. if (style.hover) {
  43. style.hover.stroke = 'none';
  44. }
  45. return style;
  46. };
  47. HtmlResizeModel.prototype.getResizeOutlineStyle = function () {
  48. return {
  49. stroke: '#000000',
  50. strokeWidth: 1,
  51. strokeDasharray: '3,3',
  52. };
  53. };
  54. HtmlResizeModel.prototype.getControlPointStyle = function () {
  55. return {
  56. width: 7,
  57. height: 7,
  58. fill: '#FFFFFF',
  59. stroke: '#000000',
  60. };
  61. };
  62. // 该方法需要在重设宽高和最大、最小限制后被调用,不建议在 initNodeData() 方法中使用
  63. HtmlResizeModel.prototype.enableProportionResize = function (turnOn) {
  64. if (turnOn === void 0) { turnOn = true; }
  65. if (turnOn) {
  66. var ResizePCT = { widthPCT: 100, hightPCT: 100 };
  67. var ResizeBasis = { basisWidth: this.width, basisHeight: this.height };
  68. var ScaleLimit = {
  69. maxScaleLimit: Math.min((this.maxWidth / this.width) * 100, (this.maxHeight / this.height) * 100),
  70. minScaleLimit: Math.max((this.minWidth / this.width) * 100, (this.minHeight / this.height) * 100),
  71. };
  72. this.PCTResizeInfo = { ResizePCT: ResizePCT, ResizeBasis: ResizeBasis, ScaleLimit: ScaleLimit };
  73. }
  74. else {
  75. delete this.PCTResizeInfo;
  76. }
  77. };
  78. return HtmlResizeModel;
  79. }(core_1.HtmlNodeModel));
  80. var HtmlResizeView = /** @class */ (function (_super) {
  81. __extends(HtmlResizeView, _super);
  82. function HtmlResizeView() {
  83. return _super !== null && _super.apply(this, arguments) || this;
  84. }
  85. HtmlResizeView.prototype.getControlGroup = function () {
  86. var _a = this.props, model = _a.model, graphModel = _a.graphModel;
  87. return (core_1.h(ControlGroup_1.default, { model: model, graphModel: graphModel }));
  88. };
  89. // getResizeShape绘制图形,功能等同于基础矩形的getShape功能,可以通过复写此方法,进行节点自定义
  90. HtmlResizeView.prototype.getResizeShape = function () {
  91. return _super.prototype.getShape.call(this);
  92. };
  93. HtmlResizeView.prototype.getShape = function () {
  94. var _a = this.props, isSelected = _a.model.isSelected, isSilentMode = _a.graphModel.editConfigModel.isSilentMode;
  95. return (core_1.h("g", null,
  96. this.getResizeShape(),
  97. isSelected && !isSilentMode ? this.getControlGroup() : ''));
  98. };
  99. return HtmlResizeView;
  100. }(core_1.HtmlNode));
  101. var HtmlResize = {
  102. type: 'html',
  103. view: HtmlResizeView,
  104. model: HtmlResizeModel,
  105. };
  106. exports.default = HtmlResize;