123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _react = _interopRequireDefault(require("react"));
- var _Logger = _interopRequireDefault(require("./Logger"));
- var _API = _interopRequireDefault(require("./services/API.js"));
- require("./ModuleLoader.css");
- var _reactMaterialize = require("react-materialize");
- var _fontawesomeSvgCore = require("@fortawesome/fontawesome-svg-core");
- var _reactFontawesome = require("@fortawesome/react-fontawesome");
- var _freeSolidSvgIcons = require("@fortawesome/free-solid-svg-icons");
- var _ModuleUtilities = require("../modules/ModuleUtilities");
- var _Types = _interopRequireDefault(require("../modules/Types"));
- var _Systems = _interopRequireDefault(require("./Systems"));
- var _CoreSystem = _interopRequireDefault(require("./CoreSystem"));
- var _modules = _interopRequireDefault(require("../modules/"));
- var _services = _interopRequireDefault(require("../modules/services"));
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- 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 _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 _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); }
- _Systems.default.addModules(_modules.default);
- _Systems.default.addServices(_services.default);
- var Extendable = _modules.default.ExtendableContainer;
- var Core = new _CoreSystem.default();
- _Systems.default.setCore(Core); ////////////////////////////////////////////
- _fontawesomeSvgCore.library.add(_freeSolidSvgIcons.faEraser);
- _fontawesomeSvgCore.library.add(_freeSolidSvgIcons.faTrash);
- _fontawesomeSvgCore.library.add(_freeSolidSvgIcons.faEye);
- _fontawesomeSvgCore.library.add(_freeSolidSvgIcons.faEyeSlash);
- var ModuleLoader =
- /*#__PURE__*/
- function (_React$Component) {
- _inherits(ModuleLoader, _React$Component);
- function ModuleLoader(props) {
- var _this;
- _classCallCheck(this, ModuleLoader);
- _this = _possibleConstructorReturn(this, _getPrototypeOf(ModuleLoader).call(this, props));
- _this._searchModules();
- return _this;
- }
- _createClass(ModuleLoader, [{
- key: "_searchModules",
- value: function _searchModules() {
- this.modules = _Systems.default.getModules(); //this.modules = [...this.modules, Systems.getLoadedServices()];
- _Logger.default.log('Modules Loaded :', this.modules);
- this.services = _Systems.default.getServices();
- _Logger.default.log('Services Loaded :', this.services);
- }
- }, {
- key: "render",
- value: function render() {
- var ModuleList = _Systems.default.getModule("ModulesList", "Base");
- return _react.default.createElement("div", {
- className: "ModuleLoader"
- }, _react.default.createElement("h5", null, "ModuleList"), _react.default.createElement("div", {
- className: "row"
- }, _react.default.createElement(ModuleList, {
- list: this.modules,
- className: "col s12"
- }), _react.default.createElement(ModuleList, {
- list: this.services,
- className: "col s12"
- })));
- }
- }]);
- return ModuleLoader;
- }(_react.default.Component); // {
- // ctor: Container,
- // inputs: {
- // width:1,
- // children: [{
- // ...item
- // }]
- // }
- // }
- var MemoryLoader =
- /*#__PURE__*/
- function (_React$Component2) {
- _inherits(MemoryLoader, _React$Component2);
- function MemoryLoader(props) {
- var _this2;
- _classCallCheck(this, MemoryLoader);
- _this2 = _possibleConstructorReturn(this, _getPrototypeOf(MemoryLoader).call(this, props));
- _this2.state = {
- tree: null,
- main: null,
- export: false,
- counter: 0,
- vision: localStorage.getItem("AdminVision")
- };
- _this2.tree = {}; // this.systemAdmin = <SystemAdmin />;
- _API.default.setUrl("/");
- Core.onUpdate(function () {
- _this2.onUpdate();
- });
- _this2._elist = window.addEventListener("keydown", function (event) {
- if (!((window.navigator.platform.match("Mac") ? event.metaKey : event.ctrlKey) && event.which == 83)) return true;
- _this2._save(Core.export());
- if (window.M) window.M.toast({
- html: 'Project saved! -------',
- displayLength: 5000
- });else if (window.Materialize) window.Materialize.toast('Project saved! --------------', 5000);
- event.preventDefault();
- return false;
- });
- return _this2;
- }
- _createClass(MemoryLoader, [{
- key: "onUpdate",
- value: function onUpdate() {
- if (this.mounted) {
- console.log("UPDATE OK");
- this.forceUpdate();
- }
- }
- }, {
- key: "componentDidMount",
- value: function componentDidMount() {
- this.mounted = true;
- this._load();
- }
- }, {
- key: "componentWillUnmount",
- value: function componentWillUnmount() {
- window.removeEventListener("keydown", this._elist);
- this.mounted = false;
- }
- }, {
- key: "addService",
- value: function addService(m) {
- m.id = parseInt(Math.random() * 1234567890) % 7654321;
- Core.loadService(m);
- Core.refresh();
- }
- }, {
- key: "toggleMode",
- value: function toggleMode() {
- if (localStorage.getItem("AdminMode") === "admin") {
- localStorage.setItem("AdminMode", "");
- } else {
- localStorage.setItem("AdminMode", "admin");
- }
- Core.refresh(true);
- this.forceUpdate();
- }
- }, {
- key: "toggle",
- value: function toggle() {
- if (localStorage.getItem("AdminVision") === "admin") {
- localStorage.setItem("AdminVision", "");
- this.setState({
- vision: false
- });
- } else {
- localStorage.setItem("AdminVision", "admin");
- this.setState({
- vision: true
- });
- }
- }
- }, {
- key: "addRoot",
- value: function addRoot(mod) {
- var answer = prompt("Add Name");
- if (answer) {
- mod.id = answer;
- var route = prompt("Add Route");
- this.setState({
- main: [mod]
- });
- Core.loadModule(mod, true);
- Core.RoutingSystem.addRoute(route, mod.id);
- Core.go(route);
- this._save(Core.export());
- }
- }
- }, {
- key: "_save",
- value: function _save(structure) {
- console.log(structure);
- localStorage.setItem('Site', JSON.stringify(structure));
- }
- }, {
- key: "_load",
- value: function _load() {
- if (localStorage.getItem('Site')) {
- try {
- var structure = JSON.parse(localStorage.getItem('Site'));
- this.setState({
- main: structure,
- counter: 0
- });
- Core.import(structure);
- console.log("Loaded", structure, this);
- } catch (e) {
- _Logger.default.error("Memory Loader : Failed to parse localStorage Site.", e);
- }
- }
- }
- }, {
- key: "exportToFile",
- value: function exportToFile() {
- function download(filename, text) {
- var element = document.createElement('a');
- element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
- element.setAttribute('download', filename);
- element.style.display = 'none';
- document.body.appendChild(element);
- element.click();
- document.body.removeChild(element);
- }
- download('Modularity' + new Date().toISOString() + '.txt', JSON.stringify(Core.export()));
- }
- }, {
- key: "importFromFile",
- value: function importFromFile(event) {
- var self = this;
- var input = event.target;
- var reader = new FileReader();
- reader.onload = function () {
- var text = reader.result;
- var answer = window.confirm("Import : " + text);
- if (answer) {
- try {
- Core.import(JSON.parse(text));
- Core.refresh(true);
- } catch (e) {
- alert("No good file!");
- }
- }
- };
- reader.readAsText(input.files[0]);
- }
- }, {
- key: "render",
- value: function render() {
- var _this3 = this;
- var modules = Core.renderModules();
- var services = Core.renderServices();
- if (!modules) console.log("Core Modules rendered: " + modules);
- if (!services) console.log("Core services rendered: " + services);
- return _react.default.createElement("div", null, this.state.vision ? _react.default.createElement("div", null, _react.default.createElement(_reactMaterialize.Card, {
- className: "MemoryLoaderUI",
- key: 'UI'
- }, _react.default.createElement("div", {
- className: "row"
- }, _react.default.createElement(_reactMaterialize.Button, {
- type: "button",
- className: "btn btn-primary col s6",
- onClick: function onClick() {
- return _this3.toggle();
- }
- }, _react.default.createElement(_reactFontawesome.FontAwesomeIcon, {
- icon: "eye"
- })), _react.default.createElement(_reactMaterialize.Button, {
- className: "btn btn-primary darken-1 col s6",
- onClick: function onClick() {
- return _this3.toggleMode();
- }
- }, "Admin"), _react.default.createElement(_reactMaterialize.Button, {
- className: "btn btn-primary col s6",
- onClick: function onClick() {
- return _this3._save(Core.export());
- }
- }, _react.default.createElement(_reactMaterialize.Icon, null, "save")), _react.default.createElement(_reactMaterialize.Button, {
- className: "btn btn-primary col s6",
- onClick: function onClick() {
- return _this3.exportToFile();
- }
- }, _react.default.createElement(_reactMaterialize.Icon, null, "file_download")), _react.default.createElement(_reactMaterialize.TextInput, {
- type: "file",
- label: _react.default.createElement(_reactMaterialize.Icon, null, "file_upload"),
- s: 12,
- onChange: function onChange(e) {
- return _this3.importFromFile(e);
- }
- }), _react.default.createElement("div", {
- className: "col s12"
- }, _react.default.createElement("div", null, _react.default.createElement(_ModuleUtilities.InputMarker, {
- name: "root",
- onDrop: function onDrop(mod) {
- return _this3.addRoot(mod);
- }
- })), _react.default.createElement("div", null, _react.default.createElement(_ModuleUtilities.InputMarker, {
- name: "services",
- onDrop: function onDrop(mod) {
- return _this3.addService(mod);
- }
- })), _react.default.createElement("div", null, _react.default.createElement(Extendable, {
- header: "Add input"
- }, _react.default.createElement(InputGeneratorUI, null))), _react.default.createElement("div", null, _react.default.createElement(Extendable, {
- header: "Add output"
- }, _react.default.createElement(OutputGeneratorUI, null))), _react.default.createElement("div", null, _react.default.createElement(Extendable, {
- header: "Core I/O"
- }, _react.default.createElement(IO, null)))))), services ? services : '', _react.default.createElement(ModuleLoader, null)) : _react.default.createElement(_reactMaterialize.Card, {
- className: "MemoryLoaderUI mini",
- key: 'UI'
- }, _react.default.createElement("div", {
- className: "row"
- }, _react.default.createElement("button", {
- type: "button",
- className: "btn btn-primary col s12",
- onClick: function onClick() {
- return _this3.toggle();
- }
- }, _react.default.createElement(_reactFontawesome.FontAwesomeIcon, {
- icon: "eye-slash"
- })))), modules ? modules : 'No render');
- }
- }]);
- return MemoryLoader;
- }(_react.default.Component);
- var SolidLoader =
- /*#__PURE__*/
- function (_React$Component3) {
- _inherits(SolidLoader, _React$Component3);
- function SolidLoader(props) {
- var _this4;
- _classCallCheck(this, SolidLoader);
- _this4 = _possibleConstructorReturn(this, _getPrototypeOf(SolidLoader).call(this, props));
- _this4.state = {
- script: props.script || {}
- };
- _API.default.setUrl("/");
- Core.onUpdate(function () {
- return _this4.onUpdate();
- });
- return _this4;
- }
- _createClass(SolidLoader, [{
- key: "onUpdate",
- value: function onUpdate() {
- this.forceUpdate();
- }
- }, {
- key: "componentDidMount",
- value: function componentDidMount() {
- this._load();
- }
- }, {
- key: "_load",
- value: function _load() {
- if (this.state.script) {
- try {
- var structure = this.props.script;
- this.setState({
- main: structure,
- counter: 0
- });
- Core.import(structure);
- console.log("Loaded", structure, this);
- } catch (e) {
- _Logger.default.error("Solid Loader : Failed to parse SiteScript.", e);
- }
- }
- }
- }, {
- key: "render",
- value: function render() {
- var modules = Core.renderModules();
- var services = Core.renderServices();
- return _react.default.createElement("div", null, modules ? modules : 'No render');
- }
- }]);
- return SolidLoader;
- }(_react.default.Component);
- var IO =
- /*#__PURE__*/
- function (_React$Component4) {
- _inherits(IO, _React$Component4);
- function IO(props) {
- var _this5;
- _classCallCheck(this, IO);
- _this5 = _possibleConstructorReturn(this, _getPrototypeOf(IO).call(this, props));
- _this5.state = {};
- return _this5;
- }
- _createClass(IO, [{
- key: "render",
- value: function render() {
- var _this6 = this;
- console.log(Core.inputs);
- var inputs = Core.inputs || {};
- var outputs = Core.outputs || {};
- var renderedInputs = Object.keys(inputs).map(function (key, indx) {
- Core.getInput(key).onUpdate(function () {
- return _this6.forceUpdate();
- });
- return _react.default.createElement("div", {
- key: indx + Math.random()
- }, (0, _ModuleUtilities.RendererInput)(Core.getInput(key), function (name, value) {
- return Core.updateInput(_objectSpread({}, inputs[key], {
- value: value
- }));
- }), _react.default.createElement("span", {
- onClick: function onClick() {
- return Core.removeInput(key);
- }
- }, _react.default.createElement(_reactMaterialize.Icon, null, "delete")));
- });
- var renderedOutputs = Object.keys(outputs).map(function (key, indx) {
- return _react.default.createElement("div", {
- key: indx
- }, (0, _ModuleUtilities.RendererOutput)(Core.getOutput(key), function (name, value) {
- return Core.updateOutput(_objectSpread({}, outputs[key], {
- value: value
- }));
- }), _react.default.createElement("span", {
- onClick: function onClick() {
- return Core.removeOutput(key);
- }
- }, _react.default.createElement(_reactMaterialize.Icon, null, "delete")));
- });
- return _react.default.createElement("div", null, _react.default.createElement("div", null, renderedInputs), _react.default.createElement("div", null, renderedOutputs));
- }
- }]);
- return IO;
- }(_react.default.Component);
- var InputGeneratorUI =
- /*#__PURE__*/
- function (_React$Component5) {
- _inherits(InputGeneratorUI, _React$Component5);
- function InputGeneratorUI(props) {
- var _this7;
- _classCallCheck(this, InputGeneratorUI);
- _this7 = _possibleConstructorReturn(this, _getPrototypeOf(InputGeneratorUI).call(this, props));
- _this7.state = {
- type: _Types.default.Text,
- arrType: _Types.default.Text,
- name: '',
- defaultValue: ''
- };
- return _this7;
- }
- _createClass(InputGeneratorUI, [{
- key: "submit",
- value: function submit() {
- Core.addInput(_objectSpread({}, this.state));
- }
- }, {
- key: "render",
- value: function render() {
- var _this8 = this;
- return _react.default.createElement("div", {
- className: "InputGenerator",
- style: {
- background: "white"
- }
- }, _react.default.createElement("div", {
- className: "row"
- }, _react.default.createElement(_reactMaterialize.Select, {
- s: 12,
- type: "select",
- label: "Type",
- defaultValue: _Types.default.Text,
- onChange: function onChange(e) {
- return _this8.setState({
- type: parseInt(e.target.value)
- });
- }
- }, Object.keys(_Types.default).map(function (key, indx) {
- return _react.default.createElement("option", {
- key: indx,
- value: _Types.default[key]
- }, key);
- }))), _react.default.createElement("div", {
- className: "row"
- }, this.state.type === _Types.default["Array"] ? _react.default.createElement(_reactMaterialize.Select, {
- s: 12,
- type: "select",
- label: "Array Type",
- defaultValue: _Types.default.Text,
- onChange: function onChange(e) {
- return _this8.setState({
- arrType: parseInt(e.target.value)
- });
- }
- }, Object.keys(_Types.default).map(function (key, indx) {
- return _react.default.createElement("option", {
- key: indx,
- value: _Types.default[key],
- disabled: key == "Array"
- }, key);
- })) : ''), _react.default.createElement("div", {
- className: "row"
- }, _react.default.createElement("input", {
- className: "col s12",
- type: "text",
- onChange: function onChange(e) {
- return _this8.setState({
- name: e.target.value
- });
- },
- placeholder: "Name"
- })), _react.default.createElement("div", {
- className: "row"
- }, _react.default.createElement("input", {
- className: "col s12",
- type: "text",
- onChange: function onChange(e) {
- return _this8.setState({
- defaultValue: e.target.value
- });
- },
- placeholder: "Default"
- })), _react.default.createElement("div", {
- className: "row"
- }, _react.default.createElement(_reactMaterialize.Button, {
- className: "btn btn-primary col s12",
- type: "text",
- onClick: function onClick(e) {
- return _this8.submit();
- }
- }, "Add")));
- }
- }]);
- return InputGeneratorUI;
- }(_react.default.Component);
- var OutputGeneratorUI =
- /*#__PURE__*/
- function (_React$Component6) {
- _inherits(OutputGeneratorUI, _React$Component6);
- function OutputGeneratorUI(props) {
- var _this9;
- _classCallCheck(this, OutputGeneratorUI);
- _this9 = _possibleConstructorReturn(this, _getPrototypeOf(OutputGeneratorUI).call(this, props));
- _this9.state = {
- type: 0,
- arrType: 0,
- name: ''
- };
- return _this9;
- }
- _createClass(OutputGeneratorUI, [{
- key: "submit",
- value: function submit() {
- Core.addOutput(_objectSpread({}, this.state));
- }
- }, {
- key: "render",
- value: function render() {
- var _this10 = this;
- return _react.default.createElement("div", {
- className: "OutputGenerator",
- style: {
- background: "white"
- }
- }, _react.default.createElement("div", {
- className: "row"
- }, _react.default.createElement(_reactMaterialize.Select, {
- s: 12,
- type: "select",
- label: "Type",
- defaultValue: "2",
- onChange: function onChange(e) {
- return _this10.setState({
- type: parseInt(e.target.value)
- });
- }
- }, Object.keys(_Types.default).map(function (key, indx) {
- return _react.default.createElement("option", {
- key: indx,
- value: _Types.default[key]
- }, key);
- }))), _react.default.createElement("div", {
- className: "row"
- }, this.state.type === _Types.default["Array"] ? _react.default.createElement(_reactMaterialize.Select, {
- s: 12,
- type: "select",
- label: "Array Type",
- defaultValue: "2",
- onChange: function onChange(e) {
- return _this10.setState({
- arrType: parseInt(e.target.value)
- });
- }
- }, Object.keys(_Types.default).map(function (key, indx) {
- return _react.default.createElement("option", {
- key: indx,
- value: _Types.default[key],
- disabled: key == "Array"
- }, key);
- })) : ''), _react.default.createElement("div", {
- className: "row"
- }, _react.default.createElement("input", {
- className: "col s12",
- type: "text",
- onChange: function onChange(e) {
- return _this10.setState({
- name: e.target.value
- });
- },
- placeholder: "Name"
- })), _react.default.createElement("div", {
- className: "row"
- }, _react.default.createElement(_reactMaterialize.Button, {
- className: "btn btn-primary col s12",
- type: "text",
- onClick: function onClick(e) {
- return _this10.submit();
- }
- }, "Add")));
- }
- }]);
- return OutputGeneratorUI;
- }(_react.default.Component);
- ModuleLoader.MemoryLoader = MemoryLoader;
- ModuleLoader.SolidLoader = SolidLoader;
- var _default = ModuleLoader;
- exports.default = _default;
|