Module.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 _Types = _interopRequireDefault(require("./Types"));
  8. var _ModuleUtilities = require("./ModuleUtilities");
  9. var _AdminModule2 = _interopRequireDefault(require("./AdminModule.js"));
  10. var _Systems = _interopRequireDefault(require("../systems/Systems"));
  11. require("./Module.css");
  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 _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
  15. function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
  16. function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
  17. function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
  18. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  19. 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); } }
  20. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  21. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  22. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  23. 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); }
  24. function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
  25. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  26. 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); }
  27. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  28. window.ModuleRefs = {};
  29. var Module =
  30. /*#__PURE__*/
  31. function (_AdminModule) {
  32. _inherits(Module, _AdminModule);
  33. // we need reference
  34. function Module(props) {
  35. var _this;
  36. _classCallCheck(this, Module);
  37. _this = _possibleConstructorReturn(this, _getPrototypeOf(Module).call(this, props));
  38. _this.decorate(props.systemID, _assertThisInitialized(_this));
  39. _this.__id = props.id || _this.__genRandom();
  40. _this._finalInputs = {};
  41. _this._finalOutputs = {};
  42. _this._loadInputs(props.inrefs || {});
  43. _this._loadOutputs(props.outrefs || {});
  44. _this._loadChildren(props.children);
  45. return _this;
  46. }
  47. _createClass(Module, [{
  48. key: "setState",
  49. value: function setState(data) {
  50. if (this._ismounted) {
  51. _get(_getPrototypeOf(Module.prototype), "setState", this).call(this, data);
  52. }
  53. }
  54. }, {
  55. key: "decorate",
  56. value: function decorate() {
  57. var systemid = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "core";
  58. _Systems.default.decorate(systemid, this);
  59. }
  60. }, {
  61. key: "forceUpdate",
  62. value: function forceUpdate() {
  63. if (this._ismounted) {
  64. _get(_getPrototypeOf(Module.prototype), "forceUpdate", this).call(this);
  65. }
  66. }
  67. }, {
  68. key: "componentDidMount",
  69. value: function componentDidMount() {
  70. this._ismounted = true;
  71. }
  72. }, {
  73. key: "componentWillUnmount",
  74. value: function componentWillUnmount() {
  75. this._ismounted = false;
  76. }
  77. }, {
  78. key: "componentWillReceiveProps",
  79. value: function componentWillReceiveProps(props) {
  80. for (var i in props) {
  81. if (this.constructor.Inputs[i] && this[i] && this[i].value !== props[i]) {
  82. this[i].update(props[i]);
  83. }
  84. } // this._loadInputs(props.inrefs || {});
  85. // this._loadOutputs(props.outrefs || {});
  86. this.forceUpdate();
  87. }
  88. }, {
  89. key: "_loadChildren",
  90. value: function _loadChildren(children) {//this.props.children = children;
  91. }
  92. }, {
  93. key: "_loadInputs",
  94. value: function _loadInputs(inputs) {
  95. for (var i in this.constructor.Inputs) {
  96. this.generateInput(inputs[i], i, false);
  97. }
  98. }
  99. }, {
  100. key: "generateInput",
  101. value: function generateInput(input, i) {
  102. var _this2 = this;
  103. var dynamic = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  104. this[i] = input || this.LinkManager.ghostInputRef((this.props.inputs || {})[i] || this._defaultInput(i), true, this.props);
  105. this[i].onUpdate(function () {
  106. return _this2.forceUpdate();
  107. });
  108. if (dynamic) {
  109. this.properties.Inputs[i] = input;
  110. this.props.inrefs[i] = this[i];
  111. this.props.inputs[i] = this[i];
  112. }
  113. }
  114. }, {
  115. key: "_loadOutputs",
  116. value: function _loadOutputs(outputs) {
  117. for (var i in this.constructor.Outputs) {
  118. this.generateOutput(outputs[i], i, false);
  119. }
  120. }
  121. }, {
  122. key: "generateOutput",
  123. value: function generateOutput(output, i) {
  124. var dynamic = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  125. this[i] = output || this.LinkManager.ghostOutputRef((this.props.outputs || {})[i] || this._defaultOutput(i), true, this.props);
  126. if (this[i].value !== undefined) this[i].set(this[i].value);
  127. if (dynamic) {
  128. this.properties.Outputs[i] = output;
  129. this.props.outputs[i] = this[i];
  130. }
  131. }
  132. }, {
  133. key: "__genRandom",
  134. value: function __genRandom() {
  135. return '' + parseInt(Math.random() * 123456) % 56921;
  136. }
  137. }, {
  138. key: "_defaultInput",
  139. value: function _defaultInput(name) {
  140. return {
  141. name: name,
  142. value: this.props[name] || this.constructor.Inputs[name].defaultValue,
  143. type: this.constructor.Inputs[name].type
  144. };
  145. }
  146. }, {
  147. key: "_defaultOutput",
  148. value: function _defaultOutput(name) {
  149. return {
  150. name: name,
  151. value: this.constructor.Outputs[name].defaultValue
  152. };
  153. }
  154. }, {
  155. key: "getId",
  156. value: function getId() {
  157. return this.__id;
  158. }
  159. }, {
  160. key: "getRef",
  161. value: function getRef() {
  162. return this.__ref;
  163. }
  164. }, {
  165. key: "render",
  166. value: function render() {
  167. var withChildren = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  168. var res = [];
  169. if (localStorage.getItem('AdminMode') === "admin" && this.props.systemID === 'core') res[0] = _get(_getPrototypeOf(Module.prototype), "render", this).call(this);
  170. if (Array.isArray(this.props.children) && withChildren) res = [res[0]].concat(_toConsumableArray(this.props.children));else if (this.props.children && withChildren) res.push(this.props.children);
  171. return res;
  172. }
  173. }]);
  174. return Module;
  175. }(_AdminModule2.default);
  176. Module.Inputs = {// view: {
  177. // type: Types.View
  178. // }
  179. };
  180. Module.Category = "Base";
  181. Module.Types = _Types.default;
  182. Module.InputMarker = _ModuleUtilities.InputMarker;
  183. Module.RemoveMarker = _ModuleUtilities.RemoveMarker;
  184. Module.OutputMarker = _ModuleUtilities.OutputMarker;
  185. var _default = Module;
  186. exports.default = _default;