ControlGroup.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. var __assign = (this && this.__assign) || function () {
  16. __assign = Object.assign || function(t) {
  17. for (var s, i = 1, n = arguments.length; i < n; i++) {
  18. s = arguments[i];
  19. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  20. t[p] = s[p];
  21. }
  22. return t;
  23. };
  24. return __assign.apply(this, arguments);
  25. };
  26. Object.defineProperty(exports, "__esModule", { value: true });
  27. var preact_1 = require("preact");
  28. var Control_1 = require("./Control");
  29. var Rect_1 = require("../BasicShape/Rect");
  30. var ControlGroup = /** @class */ (function (_super) {
  31. __extends(ControlGroup, _super);
  32. function ControlGroup() {
  33. var _this = _super.call(this) || this;
  34. _this.state = {};
  35. return _this;
  36. }
  37. ControlGroup.prototype.getResizeControl = function () {
  38. var _a = this.props, model = _a.model, graphModel = _a.graphModel;
  39. var x = model.x, y = model.y, width = model.width, height = model.height;
  40. var box = {
  41. minX: x - width / 2,
  42. minY: y - height / 2,
  43. maxX: x + width / 2,
  44. maxY: y + height / 2,
  45. };
  46. var minX = box.minX, minY = box.minY, maxX = box.maxX, maxY = box.maxY;
  47. var controlList = [
  48. // 左上角
  49. {
  50. x: minX,
  51. y: minY,
  52. },
  53. // 右上角
  54. {
  55. x: maxX,
  56. y: minY,
  57. },
  58. // 右下角
  59. {
  60. x: maxX,
  61. y: maxY,
  62. },
  63. // 左下角
  64. {
  65. x: minX,
  66. y: maxY,
  67. },
  68. ];
  69. return controlList.map(function (control, index) { return (preact_1.h(Control_1.default, __assign({ index: index }, control, { model: model, graphModel: graphModel }))); });
  70. };
  71. // 一般节点被选中了会有outline, 先不用这个
  72. ControlGroup.prototype.getGroupSolid = function () {
  73. var model = this.props.model;
  74. var x = model.x, y = model.y, width = model.width, height = model.height;
  75. var style = model.getResizeOutlineStyle();
  76. return (preact_1.h(Rect_1.default, __assign({ fill: "none" }, style, { x: x, y: y, width: width, height: height })));
  77. };
  78. ControlGroup.prototype.render = function () {
  79. return (preact_1.h("g", { className: "lf-resize-control" },
  80. this.getGroupSolid(),
  81. this.getResizeControl()));
  82. };
  83. return ControlGroup;
  84. }(preact_1.Component));
  85. exports.default = ControlGroup;