123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _react = _interopRequireDefault(require("react"));
- var _Types = _interopRequireDefault(require("./Types.js"));
- var _Logger = _interopRequireDefault(require("../systems/Logger"));
- var _reactFontawesome = require("@fortawesome/react-fontawesome");
- var _reactMaterialize = require("react-materialize");
- var _reactJsonView = _interopRequireDefault(require("react-json-view"));
- var _ModuleUtilities = require("./ModuleUtilities");
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- 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); }
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
- function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
- 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; } }
- 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; }
- 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; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- 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); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
- 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); }
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
- var AdminModule =
- /*#__PURE__*/
- function (_React$Component) {
- _inherits(AdminModule, _React$Component);
- function AdminModule(props) {
- var _this;
- _classCallCheck(this, AdminModule);
- _this = _possibleConstructorReturn(this, _getPrototypeOf(AdminModule).call(this, props));
- _this.dynamicProperties();
- _this.readOnly = props.readOnly;
- _this._mode = props.__adminmode || 'closed';
- if (props.withAdmin) {
- _this._mode = 'normal';
- }
- var disabledEvents = ['onClick'];
- _this.disableEvents = {};
- for (var i in disabledEvents) {
- _this.disableEvents[disabledEvents[i]] = _this._stopPropagation;
- }
- return _this;
- }
- _createClass(AdminModule, [{
- key: "_stopPropagation",
- value: function _stopPropagation(e) {
- e.stopPropagation();
- e.preventDefault();
- }
- }, {
- key: "_addChild",
- value: function _addChild(item) {
- console.log(item);
- var mod = _objectSpread({}, item, {
- inputs: _objectSpread({}, item.inputs),
- outputs: _objectSpread({}, item.outputs),
- children: _toConsumableArray(item.children)
- });
- mod.id = this.__genRandom();
- this.props.System.loadModule(mod);
- this.props.System.addChild(this.getId(), mod.id);
- this.props.System.__refresh();
- if (this.onChildAdd) this.onChildAdd(mod.id);
- }
- }, {
- key: "_removeMe",
- value: function _removeMe() {
- this.props.System.remove(this.getId());
- this.props.System.__refresh();
- }
- }, {
- key: "_connect",
- value: function _connect(input, output) {
- // output!
- this.props.System.connect(input, output);
- }
- }, {
- key: "_change",
- value: function _change(name, value, input) {
- var v = (0, _ModuleUtilities.Resolver)(input, value);
- this[name].update(value);
- this.props.System.change(this.getId(), name, v); //this.props.System.__refresh();
- }
- }, {
- key: "_changeID",
- value: function _changeID(newid) {
- if (newid && newid !== this.getId()) {
- this.props.System.rename(this.getId(), newid);
- this.props.System.__refresh();
- }
- }
- }, {
- key: "__factoryInput",
- value: function __factoryInput(input) {
- return (0, _ModuleUtilities.RendererInput)(input, this._change.bind(this));
- }
- }, {
- key: "__factoryOutput",
- value: function __factoryOutput(output) {
- return (0, _ModuleUtilities.RendererOutput)(output);
- }
- }, {
- key: "__renderID",
- value: function __renderID() {
- var _this2 = this;
- return this.updateID && !this.readOnly ? _react.default.createElement("input", {
- type: "text",
- onBlur: function onBlur(e) {
- return _this2._changeID(e.target.value);
- },
- defaultValue: this.__id
- }) : _react.default.createElement("span", {
- onClick: function onClick() {
- _this2.updateID = true;
- _this2.forceUpdate();
- }
- }, '' + this.__id);
- }
- }, {
- key: "__reorder",
- value: function __reorder(times) {
- this.props.System.reorder(this.getId(), times);
- this.props.System.__refresh();
- }
- }, {
- key: "__setAdminUIPosition",
- value: function __setAdminUIPosition(times) {
- var positions = ["top-left", "top-center", "top-right", "bottom-left", "bottom", "bottom-right"];
- var indx = positions.indexOf(this.properties.EditPosition);
- var res = this.properties.EditPosition;
- if (indx === -1) {
- res = positions[1];
- } else {
- if (indx - times >= 0 && indx - times < positions.length) res = positions[indx - times];
- }
- this.properties.EditPosition = res;
- }
- }, {
- key: "dynamicProperties",
- value: function dynamicProperties() {
- this.properties = {};
- this.properties.EditPosition = this.constructor.EditPosition;
- this.properties.Inputs = this.constructor.Inputs || {};
- this.properties.Outputs = this.constructor.Outputs || {};
- }
- }, {
- key: "render",
- value: function render() {
- var _this3 = this;
- var position = this.properties.EditPosition;
- var CtorInputs = this.properties.Inputs;
- var CtorOutputs = this.properties.Outputs;
- var inputs = '',
- outputs = ''; // analyze inputs!
- if (this.props.inputs) inputs = Object.keys(CtorInputs || {}).map(function (i, indx) {
- return _react.default.createElement("div", {
- key: _this3.getId() + indx
- }, _this3.__factoryInput(_objectSpread({}, CtorInputs[i], _this3.props.inputs[i])));
- });
- if (this.props.outputs) outputs = Object.keys(CtorOutputs || {}).map(function (i, indx) {
- return _react.default.createElement("div", {
- key: 'out' + _this3.getId() + indx
- }, _this3.__factoryOutput(_objectSpread({}, CtorOutputs[i], _this3.props.outputs[i])));
- });
- if (this._mode === 'closed') return '';
- return _react.default.createElement(_reactMaterialize.Card, _extends({
- className: "blue-grey darken-1 AdminModule semi Position-".concat(position, " ").concat(this._mode == "open" ? 'top' : ''),
- key: '666999666999Admina' + this.getId(),
- onMouseEnter: function onMouseEnter() {
- _this3._mode = 'open';
- _this3.forceUpdate();
- },
- onMouseLeave: function onMouseLeave() {
- _this3._mode = 'normal';
- _this3.forceUpdate();
- }
- }, this.disableEvents, {
- header: _react.default.createElement("div", null, _react.default.createElement("h6", null, _react.default.createElement("b", null, "ID:"), this.__renderID(), _react.default.createElement("span", null, _react.default.createElement("i", {
- className: "material-icons cursor small",
- onClick: function onClick() {
- return _this3.__reorder(-1);
- }
- }, "arrow_drop_up"), _react.default.createElement("i", {
- className: "material-icons cursor small",
- onClick: function onClick() {
- return _this3.__reorder(1);
- }
- }, "arrow_drop_down")), _react.default.createElement("span", null, _react.default.createElement("i", {
- className: "material-icons cursor small",
- onClick: function onClick() {
- return _this3.__setAdminUIPosition(-1);
- }
- }, "arrow_left"), _react.default.createElement("i", {
- className: "material-icons cursor small",
- onClick: function onClick() {
- return _this3.__setAdminUIPosition(1);
- }
- }, "arrow_right"))))
- }), this._mode == 'open' ? _react.default.createElement("div", null, _react.default.createElement("div", {
- className: "row"
- }, _react.default.createElement(_ModuleUtilities.InputMarker, {
- onDrop: function onDrop(mod) {
- return _this3._addChild(mod);
- },
- name: "Add child",
- className: "col s12"
- })), inputs != '' ? _react.default.createElement("div", {
- className: "bars"
- }, inputs) : '', outputs != '' ? _react.default.createElement("div", {
- className: "bars"
- }, outputs) : '', _react.default.createElement("div", null, _react.default.createElement(_ModuleUtilities.RemoveMarker, {
- className: "col s12",
- onRemove: function onRemove() {
- return _this3._removeMe();
- }
- }))) : '');
- }
- }]);
- return AdminModule;
- }(_react.default.Component);
- var _default = AdminModule;
- exports.default = _default;
|