View.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 _modularityFront = _interopRequireDefault(require("modularity-front"));
  8. var _reactMaterialize = require("react-materialize");
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. 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); }
  11. function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
  12. function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
  13. function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
  14. 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; } }
  15. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16. 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); } }
  17. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  18. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  19. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  20. 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); }
  21. function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
  22. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  23. 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); }
  24. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  25. var Module = _modularityFront.default.Module;
  26. var ViewModule =
  27. /*#__PURE__*/
  28. function (_Modularity$Module) {
  29. _inherits(ViewModule, _Modularity$Module);
  30. function ViewModule(props) {
  31. var _this;
  32. _classCallCheck(this, ViewModule);
  33. _this = _possibleConstructorReturn(this, _getPrototypeOf(ViewModule).call(this, props));
  34. _this.state = {
  35. routes: _this.Routes.value || {},
  36. keys: function () {
  37. var keys = Object.keys(_this.Routes.value || {});
  38. keys.sort(function (a, b) {
  39. return b.length - a.length;
  40. });
  41. return keys;
  42. }()
  43. };
  44. _this.Routes.onUpdate(function (routes) {
  45. var keys = Object.keys(routes);
  46. keys.sort(function (a, b) {
  47. return b.length - a.length;
  48. });
  49. _this.setState({
  50. routes: routes,
  51. keys: keys
  52. });
  53. });
  54. var route = _this.RoutingSystem.getRoute();
  55. console.log(route.url);
  56. return _this;
  57. }
  58. _createClass(ViewModule, [{
  59. key: "onChildAdd",
  60. value: function onChildAdd(modid) {
  61. var route = this.RoutingSystem.getRoute();
  62. var url = window.prompt("View URL ", route.url);
  63. var routes = this.Routes.value || {};
  64. routes[url] = routes[url] ? [].concat(_toConsumableArray(routes[url]), [modid]) : [modid];
  65. this.Routes.update(routes);
  66. }
  67. }, {
  68. key: "getMatchingMods",
  69. value: function getMatchingMods() {
  70. var route = this.RoutingSystem.getRoute();
  71. var url = route.url;
  72. var keys = this.state.keys;
  73. for (var i = 0; i < keys.length; i++) {
  74. if (url.startsWith(keys[i])) {
  75. return this.state.routes[keys[i]];
  76. }
  77. } // console.log("Routes ", keys);
  78. return this.state.routes[route.url];
  79. }
  80. }, {
  81. key: "render",
  82. value: function render() {
  83. var _this2 = this;
  84. var subview = this.getMatchingMods() || [];
  85. return _react.default.createElement("div", null, subview.map(function (id) {
  86. return _this2.ModuleSystem.modules[id];
  87. }), _get(_getPrototypeOf(ViewModule.prototype), "render", this).call(this, false));
  88. }
  89. }]);
  90. return ViewModule;
  91. }(_modularityFront.default.Module);
  92. ViewModule.Inputs = {
  93. Routes: {
  94. type: Module.Types.Object,
  95. defaultValue: {}
  96. }
  97. };
  98. ViewModule.Category = "Nikatlas";
  99. ViewModule.EditPosition = "top-right";
  100. var _default = ViewModule;
  101. exports.default = _default;