ControlGroup.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = function (d, b) {
  3. extendStatics = Object.setPrototypeOf ||
  4. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  6. return extendStatics(d, b);
  7. };
  8. return function (d, b) {
  9. extendStatics(d, b);
  10. function __() { this.constructor = d; }
  11. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  12. };
  13. })();
  14. var __assign = (this && this.__assign) || function () {
  15. __assign = Object.assign || function(t) {
  16. for (var s, i = 1, n = arguments.length; i < n; i++) {
  17. s = arguments[i];
  18. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  19. t[p] = s[p];
  20. }
  21. return t;
  22. };
  23. return __assign.apply(this, arguments);
  24. };
  25. import { h, Component } from 'preact';
  26. import Control from './Control';
  27. import Rect from '../BasicShape/Rect';
  28. var ControlGroup = /** @class */ (function (_super) {
  29. __extends(ControlGroup, _super);
  30. function ControlGroup() {
  31. var _this = _super.call(this) || this;
  32. _this.state = {};
  33. return _this;
  34. }
  35. ControlGroup.prototype.getResizeControl = function () {
  36. var _a = this.props, model = _a.model, graphModel = _a.graphModel;
  37. var x = model.x, y = model.y, width = model.width, height = model.height;
  38. var box = {
  39. minX: x - width / 2,
  40. minY: y - height / 2,
  41. maxX: x + width / 2,
  42. maxY: y + height / 2,
  43. };
  44. var minX = box.minX, minY = box.minY, maxX = box.maxX, maxY = box.maxY;
  45. var controlList = [
  46. // 左上角
  47. {
  48. x: minX,
  49. y: minY,
  50. },
  51. // 右上角
  52. {
  53. x: maxX,
  54. y: minY,
  55. },
  56. // 右下角
  57. {
  58. x: maxX,
  59. y: maxY,
  60. },
  61. // 左下角
  62. {
  63. x: minX,
  64. y: maxY,
  65. },
  66. ];
  67. return controlList.map(function (control, index) { return (h(Control, __assign({ index: index }, control, { model: model, graphModel: graphModel }))); });
  68. };
  69. // 一般节点被选中了会有outline, 先不用这个
  70. ControlGroup.prototype.getGroupSolid = function () {
  71. var model = this.props.model;
  72. var x = model.x, y = model.y, width = model.width, height = model.height;
  73. var style = model.getResizeOutlineStyle();
  74. return (h(Rect, __assign({ fill: "none" }, style, { x: x, y: y, width: width, height: height })));
  75. };
  76. ControlGroup.prototype.render = function () {
  77. return (h("g", { className: "lf-resize-control" },
  78. this.getGroupSolid(),
  79. this.getResizeControl()));
  80. };
  81. return ControlGroup;
  82. }(Component));
  83. export default ControlGroup;