SubSystem.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _react = _interopRequireDefault(require("react"));
  7. var _Module2 = _interopRequireDefault(require("../Module"));
  8. var _ = _interopRequireDefault(require("../"));
  9. var _Logger = _interopRequireDefault(require("../../systems/Logger"));
  10. var _Systems = _interopRequireDefault(require("../../systems/Systems"));
  11. var _CoreSystem = _interopRequireDefault(require("../../systems/CoreSystem"));
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  14. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
  15. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  16. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  18. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  19. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  20. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  21. function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
  22. function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
  23. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  24. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  25. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  26. var SubSystem =
  27. /*#__PURE__*/
  28. function (_Module) {
  29. _inherits(SubSystem, _Module);
  30. function SubSystem(props) {
  31. var _this;
  32. _classCallCheck(this, SubSystem);
  33. _this = _possibleConstructorReturn(this, _getPrototypeOf(SubSystem).call(this, props));
  34. _this.view = '';
  35. _this.import.onUpdate(function (data) {
  36. _this.load(data);
  37. _this.forceUpdate();
  38. });
  39. _this.load(_this.import.value);
  40. _this.loadIO();
  41. return _this;
  42. }
  43. _createClass(SubSystem, [{
  44. key: "load",
  45. value: function load(data) {
  46. this.success = false;
  47. try {
  48. this.data = JSON.parse(data);
  49. var Core = new _CoreSystem.default(this.getId());
  50. _Systems.default.addSystem(Core);
  51. Core.import(this.data);
  52. this.success = true;
  53. } catch (e) {
  54. _Logger.default.warning("Cannot Parse import field! No json!", e);
  55. }
  56. }
  57. }, {
  58. key: "loadIO",
  59. value: function loadIO() {
  60. var _this2 = this;
  61. var Core = _Systems.default.getSystem(this.getId());
  62. var _loop = function _loop(key) {
  63. _this2.generateOutput(_this2.LinkManager.addOutputRef(_this2[key] || (_this2.props.outputs[key] ? _objectSpread({}, _this2.props.outputs[key], {
  64. pid: _this2.getId()
  65. }) : null) || Core.inputs[key]), key);
  66. var Input = Core.getInput(key);
  67. Input.onUpdate(function () {
  68. return _this2[key].set(Input.value);
  69. });
  70. };
  71. for (var key in Core.inputs) {
  72. _loop(key);
  73. }
  74. var _loop2 = function _loop2(key) {
  75. _this2.generateInput(_this2.LinkManager.addInputRef(_this2[key] || (_this2.props.inputs[key] ? _objectSpread({}, _this2.props.inputs[key], {
  76. pid: _this2.getId()
  77. }) : null) || Core.outputs[key]), key);
  78. var Output = Core.getOutput(key);
  79. if (_this2[key].value) Output.set(_this2[key].value);
  80. _this2[key].onUpdate(function () {
  81. return Output.set(_this2[key].value);
  82. });
  83. };
  84. for (var key in Core.outputs) {
  85. _loop2(key);
  86. }
  87. }
  88. }, {
  89. key: "render",
  90. value: function render() {
  91. if (!this.success) return _react.default.createElement("div", null, "SubSystem", _get(_getPrototypeOf(SubSystem.prototype), "render", this).call(this));
  92. return _react.default.createElement("div", {
  93. className: "SubSystem"
  94. }, _Systems.default.getSystem(this.getId()).renderModules(), _get(_getPrototypeOf(SubSystem.prototype), "render", this).call(this));
  95. }
  96. }]);
  97. return SubSystem;
  98. }(_Module2.default);
  99. SubSystem.EditPosition = "top-right";
  100. SubSystem.Inputs = {
  101. import: {
  102. type: _Module2.default.Types.Text,
  103. defaultValue: "{}"
  104. }
  105. };
  106. SubSystem.Category = "Subsystem";
  107. var _default = SubSystem;
  108. exports.default = _default;