loadax
Version:
Universal powerful solution for creating web app
1,403 lines (1,161 loc) • 42.2 kB
JavaScript
"use strict";
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
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 _typeof(obj) { "@babel/helpers - typeof"; 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 _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
return mod && mod.__esModule ? mod : {
"default": mod
};
};
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ModuleLoader = exports.ModuleType = exports.LOADAX_UST_REGISTER = exports.LOADAX_RESTORE_ACTION = void 0;
var axios_1 = _get__("__importDefault")(require("axios"));
exports.LOADAX_RESTORE_ACTION = "LOADAX_RESTORE_ACTION";
exports.LOADAX_UST_REGISTER = "LOADAX_UST_REGISTER";
var ModuleType;
(function (ModuleType) {
ModuleType[ModuleType["instance"] = 0] = "instance";
ModuleType[ModuleType["page"] = 1] = "page";
ModuleType[ModuleType["lib"] = 2] = "lib";
ModuleType[ModuleType["component"] = 3] = "component";
})(_assign__("ModuleType", exports.ModuleType || (exports.ModuleType = {})));
var addStyles = function addStyles(module) {
var isAdded = document.getElementById("st-".concat(module.name));
if (!isAdded) {
var head = document.getElementsByTagName('head')[0];
var container = document.createElement('link');
container.id = "st-".concat(module.name);
container.href = module.css;
container.rel = 'stylesheet';
head.appendChild(container);
}
};
var addStore = function addStore(stores, context) {
if (context.active) {
var _iterator = _createForOfIteratorHelper(stores),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var store = _step.value;
context.active.postMessage({
namespace: store.name,
payload: store.value
});
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
return context.active;
}
};
var listenerRegistration = function listenerRegistration(event, emit) {
var _ctx = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var _UTS = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "";
var valids = JSON.stringify(event.data) !== '{}';
var ctx = _ctx || _get__("ModuleLoader");
if (ctx.isInstance) {
if (event.data === exports.LOADAX_RESTORE_ACTION) {
if (ctx.StoreFloatContext) {
ctx.StoreFloatContext.postMessage({
namespace: exports.LOADAX_RESTORE_ACTION,
payload: _get__("cacheStore")
});
}
} else {
if (valids) {
_assign__("cacheStore", event.data);
}
}
}
if (_typeof(event.data) === "object" && valids) {
_get__("syncUts")(event.data, _UTS);
emit(event.data);
}
};
var isUstRegister = function isUstRegister(UST) {
var USTS = JSON.parse(localStorage.getItem('USTS') || '[]');
return USTS.indexOf(UST) === -1;
};
var syncUts = function syncUts(data, _UTS) {
if (_UTS.length > 0) {
var uts = _UTS.split(".").reverse();
localStorage.setItem(_UTS, JSON.stringify(_get__("syncAsGlobalValueByUts")(data, uts, uts.length - 1)));
}
};
var listenerCanBeAdded = function listenerCanBeAdded(emtText) {
return _get__("registeredUST").indexOf(emtText) === -1;
};
var syncAsGlobalValueByUts = function syncAsGlobalValueByUts(obj, namespace, index) {
var result = null;
try {
result = obj[namespace[index]];
if (index > 0) {
return _get__("syncAsGlobalValueByUts")(result, namespace, index - 1);
}
} catch (e) {
console.log(e);
}
return result;
};
var cacheStore = {};
var registeredUST = [];
var loadPwaHandler = function loadPwaHandler(pwa, action, context) {
var activeCtx = null;
if (context.installing) {
context.installing.addEventListener('statechange', function () {
if (this.state === 'activated') {
action(_get__("addStore")(pwa.store, context) || null);
pwa.app(context);
}
});
}
if (context.active) {
action(_get__("addStore")(pwa.store, context) || null);
pwa.app(context);
}
return activeCtx;
};
var loadPwaAppInstance = function loadPwaAppInstance(pwa, action) {
var url = pwa.url || 'main/ws-loadax.js';
return navigator.serviceWorker.getRegistration(url).then(function (context) {
if (context) {
return _get__("loadPwaHandler")(pwa, action, context);
} else {
return navigator.serviceWorker.register(url).then(function (context) {
return _get__("loadPwaHandler")(pwa, action, context);
});
}
});
};
var StoreManager = /*#__PURE__*/function () {
function StoreManager() {
_classCallCheck(this, StoreManager);
}
_createClass(StoreManager, null, [{
key: "setValue",
value: function setValue(value, store) {
if (store) {
store.postMessage(value);
}
}
}, {
key: "sync",
value: function sync(value, store) {
if (store) {
store.postMessage(value);
}
}
}, {
key: "getValue",
value: function getValue() {
var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var namespace = arguments.length > 1 ? arguments[1] : undefined;
var index = arguments.length > 2 ? arguments[2] : undefined;
var result = {};
result[namespace[index]] = obj[namespace[index]];
if (index > 0) {
result = this.getValue(obj[namespace[index]], namespace, index - 1);
}
return result;
}
}, {
key: "getState",
value: function getState(action, data) {
var ns = action.split(".").reverse();
return this.getValue(data, ns, ns.length - 1);
}
}]);
return StoreManager;
}();
var ModuleLoader = /*#__PURE__*/function () {
function ModuleLoader(apiUrl) {
_classCallCheck(this, ModuleLoader);
this.isInstance = false;
this.StoreFloatContext = null;
this.activeModules = [];
this.loadedModules = [];
this.baseApi = '';
this.baseApi = apiUrl;
}
_createClass(ModuleLoader, [{
key: "storeAction",
value: function storeAction(value) {
_get__("StoreManager").setValue(value, this.StoreFloatContext);
}
}, {
key: "storeActionScope",
value: function storeActionScope(value) {
_get__("StoreManager").setValue(value, this.StoreFloatContext);
}
}, {
key: "storeSync",
value: function storeSync() {
_get__("StoreManager").sync({
namespace: "sync"
}, this.StoreFloatContext);
}
}, {
key: "isNotRegisteredUST",
value: function isNotRegisteredUST(UST) {
return _get__("isUstRegister")(UST);
}
}, {
key: "registerUST",
value: function registerUST(UST) {
var list = JSON.parse(localStorage.getItem('USTS') || '[]');
if (list.indexOf(UST) === -1) {
list.push(UST);
localStorage.setItem("USTS", JSON.stringify(list));
}
}
}, {
key: "storeEmit",
value: function storeEmit(emit) {
var _this = this;
var _ust = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
navigator.serviceWorker.addEventListener("message", function (e) {
return _get__("listenerRegistration")(e, emit, _this, _ust);
});
}
}, {
key: "setStoreContext",
value: function setStoreContext(store) {
this.StoreFloatContext = store;
}
}, {
key: "findLoadedModule",
value: function findLoadedModule(name) {
return this.loadedModules.find(function (module) {
return module.name === name;
});
}
}, {
key: "moduleIsNotExist",
value: function moduleIsNotExist(name) {
return this.loadedModules.findIndex(function (module) {
return module.name === name;
}) === -1;
}
}, {
key: "findModule",
value: function findModule(name) {
return this.activeModules.find(function (module) {
return module.name === name;
});
}
}, {
key: "getModules",
value: function () {
var _getModules = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
var url,
_yield$_get__$default,
data,
_args = arguments;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
url = _args.length > 0 && _args[0] !== undefined ? _args[0] : this.baseApi;
_context.prev = 1;
_context.next = 4;
return _get__("axios_1")["default"].get(url);
case 4:
_yield$_get__$default = _context.sent;
data = _yield$_get__$default.data;
this.activeModules = data;
_context.next = 12;
break;
case 9:
_context.prev = 9;
_context.t0 = _context["catch"](1);
console.error(_context.t0);
case 12:
case "end":
return _context.stop();
}
}
}, _callee, this, [[1, 9]]);
}));
function getModules() {
return _getModules.apply(this, arguments);
}
return getModules;
}()
}, {
key: "getModule",
value: function () {
var _getModule = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(name) {
var foundModule, _yield$_get__$default2, data;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
foundModule = this.findModule(name);
if (!(this.moduleIsNotExist(name) && foundModule)) {
_context2.next = 14;
break;
}
_context2.prev = 2;
_get__("addStyles")(foundModule);
_context2.next = 6;
return _get__("axios_1")["default"].get(foundModule.path);
case 6:
_yield$_get__$default2 = _context2.sent;
data = _yield$_get__$default2.data;
this.loadedModules.push(data);
_context2.next = 14;
break;
case 11:
_context2.prev = 11;
_context2.t0 = _context2["catch"](2);
console.error(_context2.t0);
case 14:
case "end":
return _context2.stop();
}
}
}, _callee2, this, [[2, 11]]);
}));
function getModule(_x) {
return _getModule.apply(this, arguments);
}
return getModule;
}()
}, {
key: "getStaticModule",
value: function () {
var _getStaticModule = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(module) {
var foundModule, _yield$_get__$default3, data;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
foundModule = this.findModule(module.name);
if (!foundModule) {
_context3.next = 14;
break;
}
_get__("addStyles")(foundModule);
_context3.prev = 3;
_context3.next = 6;
return _get__("axios_1")["default"].get(foundModule.path);
case 6:
_yield$_get__$default3 = _context3.sent;
data = _yield$_get__$default3.data;
this.loadedModules.push({
name: foundModule.name,
version: foundModule.version,
path: foundModule.path,
type: foundModule.type,
pageRoute: foundModule.pageRoute,
childrenRoutes: foundModule.childrenRoutes,
css: foundModule.css,
module: data
});
_context3.next = 14;
break;
case 11:
_context3.prev = 11;
_context3.t0 = _context3["catch"](3);
console.error(_context3.t0);
case 14:
case "end":
return _context3.stop();
}
}
}, _callee3, this, [[3, 11]]);
}));
function getStaticModule(_x2) {
return _getStaticModule.apply(this, arguments);
}
return getStaticModule;
}()
}, {
key: "injectAllStaticModules",
value: function () {
var _injectAllStaticModules = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
var index;
return regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.prev = 0;
_context4.next = 3;
return this.getModules();
case 3:
_context4.t0 = regeneratorRuntime.keys(this.activeModules);
case 4:
if ((_context4.t1 = _context4.t0()).done) {
_context4.next = 11;
break;
}
index = _context4.t1.value;
_get__("addStyles")(this.activeModules[index]);
_context4.next = 9;
return this.getStaticModule(this.activeModules[index]);
case 9:
_context4.next = 4;
break;
case 11:
_context4.next = 16;
break;
case 13:
_context4.prev = 13;
_context4.t2 = _context4["catch"](0);
console.error(_context4.t2);
case 16:
return _context4.abrupt("return", this.loadedModules);
case 17:
case "end":
return _context4.stop();
}
}
}, _callee4, this, [[0, 13]]);
}));
function injectAllStaticModules() {
return _injectAllStaticModules.apply(this, arguments);
}
return injectAllStaticModules;
}()
}, {
key: "injectAllModules",
value: function () {
var _injectAllModules = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
var index;
return regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.prev = 0;
_context5.next = 3;
return this.getModules();
case 3:
_context5.t0 = regeneratorRuntime.keys(this.activeModules);
case 4:
if ((_context5.t1 = _context5.t0()).done) {
_context5.next = 11;
break;
}
index = _context5.t1.value;
_get__("addStyles")(this.activeModules[index]);
_context5.next = 9;
return this.getModule(this.activeModules[index].name);
case 9:
_context5.next = 4;
break;
case 11:
_context5.next = 16;
break;
case 13:
_context5.prev = 13;
_context5.t2 = _context5["catch"](0);
console.error(_context5.t2);
case 16:
return _context5.abrupt("return", this.loadedModules);
case 17:
case "end":
return _context5.stop();
}
}
}, _callee5, this, [[0, 13]]);
}));
function injectAllModules() {
return _injectAllModules.apply(this, arguments);
}
return injectAllModules;
}()
}, {
key: "getAppComponent",
value: function getAppComponent(name) {
return this.loadedModules.find(function (addedModule) {
return addedModule.name === name && addedModule.type === _get__("ModuleType").component;
});
}
}, {
key: "getAppLib",
value: function getAppLib(name) {
return this.loadedModules.find(function (addedModule) {
return addedModule.name === name && addedModule.type === _get__("ModuleType").lib;
});
}
}, {
key: "injectModule",
value: function () {
var _injectModule = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(name) {
return regeneratorRuntime.wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
_context6.prev = 0;
_context6.next = 3;
return this.getModule(name);
case 3:
_context6.next = 8;
break;
case 5:
_context6.prev = 5;
_context6.t0 = _context6["catch"](0);
console.error(_context6.t0);
case 8:
return _context6.abrupt("return", this.findLoadedModule(name));
case 9:
case "end":
return _context6.stop();
}
}
}, _callee6, this, [[0, 5]]);
}));
function injectModule(_x3) {
return _injectModule.apply(this, arguments);
}
return injectModule;
}()
}, {
key: "executeModule",
value: function executeModule(name) {
var foundModule = this.findModule(name);
var foundLoadedModule = this.findLoadedModule(name);
if (foundModule && foundLoadedModule) {
_get__("addStyles")(foundLoadedModule);
eval(foundLoadedModule.module);
}
}
}, {
key: "asPwa",
value: function () {
var _asPwa = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7(pwa) {
var _this2 = this;
return regeneratorRuntime.wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
_context7.prev = 0;
_context7.next = 3;
return _get__("loadPwaAppInstance")(pwa, function (ctx) {
if (pwa.asInstance) _this2.asInstance();
_this2.setStoreContext(ctx);
});
case 3:
_context7.next = 8;
break;
case 5:
_context7.prev = 5;
_context7.t0 = _context7["catch"](0);
console.log(_context7.t0.message);
case 8:
case "end":
return _context7.stop();
}
}
}, _callee7, null, [[0, 5]]);
}));
function asPwa(_x4) {
return _asPwa.apply(this, arguments);
}
return asPwa;
}()
}, {
key: "asInstance",
value: function asInstance() {
this.isInstance = true;
}
}], [{
key: "storeAction",
value: function storeAction(value) {
_get__("StoreManager").setValue(value, this.StoreFloatContext);
}
}, {
key: "storeActionScope",
value: function storeActionScope(value) {
_get__("StoreManager").setValue(value, this.StoreFloatContext);
}
}, {
key: "storeSync",
value: function storeSync() {
_get__("StoreManager").sync({
namespace: "sync"
}, this.StoreFloatContext);
}
}, {
key: "clearUTS",
value: function clearUTS() {
localStorage.setItem('USTS', JSON.stringify([]));
}
}, {
key: "isNotRegisteredUST",
value: function isNotRegisteredUST(UST) {
return _get__("isUstRegister")(UST);
}
}, {
key: "registerUST",
value: function registerUST(UST) {
var list = JSON.parse(localStorage.getItem('USTS') || '[]');
if (list.indexOf(UST) === -1) {
list.push(UST);
localStorage.setItem("USTS", JSON.stringify(list));
}
}
}, {
key: "storeEmit",
value: function storeEmit(emit) {
var _ust = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
var emitString = JSON.stringify(emit);
if (_get__("listenerCanBeAdded")(emitString)) {
navigator.serviceWorker.addEventListener("message", function (e) {
return _get__("listenerRegistration")(e, emit, null, _ust);
});
_get__("registeredUST").push(emitString);
}
}
}, {
key: "setStoreContext",
value: function setStoreContext(store) {
this.StoreFloatContext = store;
}
}, {
key: "findLoadedFloatModule",
value: function findLoadedFloatModule(name) {
return this.floatLoadedModules.find(function (module) {
return module.name === name;
});
}
}, {
key: "floatModuleIsNotExist",
value: function floatModuleIsNotExist(name) {
return this.floatLoadedModules.findIndex(function (module) {
return module.name === name;
}) === -1;
}
}, {
key: "findFloatModule",
value: function findFloatModule(name) {
return this.floatModules.find(function (module) {
return module.name === name;
});
}
}, {
key: "getFloatModules",
value: function () {
var _getFloatModules = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8(url) {
var _yield$_get__$default4, data;
return regeneratorRuntime.wrap(function _callee8$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
_context8.prev = 0;
_context8.next = 3;
return _get__("axios_1")["default"].get(url);
case 3:
_yield$_get__$default4 = _context8.sent;
data = _yield$_get__$default4.data;
this.floatModules = data;
_context8.next = 11;
break;
case 8:
_context8.prev = 8;
_context8.t0 = _context8["catch"](0);
console.error(_context8.t0);
case 11:
case "end":
return _context8.stop();
}
}
}, _callee8, this, [[0, 8]]);
}));
function getFloatModules(_x5) {
return _getFloatModules.apply(this, arguments);
}
return getFloatModules;
}()
}, {
key: "getFloatModule",
value: function () {
var _getFloatModule = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9(module) {
var foundFloatModule, _yield$_get__$default5, data;
return regeneratorRuntime.wrap(function _callee9$(_context9) {
while (1) {
switch (_context9.prev = _context9.next) {
case 0:
foundFloatModule = this.findFloatModule(module.name);
if (!(this.floatModuleIsNotExist(module.name) && foundFloatModule)) {
_context9.next = 14;
break;
}
_get__("addStyles")(foundFloatModule);
_context9.prev = 3;
_context9.next = 6;
return _get__("axios_1")["default"].get(foundFloatModule.path);
case 6:
_yield$_get__$default5 = _context9.sent;
data = _yield$_get__$default5.data;
this.floatLoadedModules.push({
name: foundFloatModule.name,
version: foundFloatModule.version,
path: foundFloatModule.path,
type: foundFloatModule.type,
pageRoute: foundFloatModule.pageRoute,
childrenRoutes: foundFloatModule.childrenRoutes,
css: foundFloatModule.css,
module: data
});
_context9.next = 14;
break;
case 11:
_context9.prev = 11;
_context9.t0 = _context9["catch"](3);
console.error(_context9.t0);
case 14:
case "end":
return _context9.stop();
}
}
}, _callee9, this, [[3, 11]]);
}));
function getFloatModule(_x6) {
return _getFloatModule.apply(this, arguments);
}
return getFloatModule;
}()
}, {
key: "getFloatStaticModule",
value: function () {
var _getFloatStaticModule = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10(moduleUrl) {
var _yield$_get__$default6, data;
return regeneratorRuntime.wrap(function _callee10$(_context10) {
while (1) {
switch (_context10.prev = _context10.next) {
case 0:
_context10.prev = 0;
_context10.next = 3;
return _get__("axios_1")["default"].get(moduleUrl);
case 3:
_yield$_get__$default6 = _context10.sent;
data = _yield$_get__$default6.data;
this.floatLoadedModules.push(data);
_context10.next = 11;
break;
case 8:
_context10.prev = 8;
_context10.t0 = _context10["catch"](0);
console.error(_context10.t0);
case 11:
case "end":
return _context10.stop();
}
}
}, _callee10, this, [[0, 8]]);
}));
function getFloatStaticModule(_x7) {
return _getFloatStaticModule.apply(this, arguments);
}
return getFloatStaticModule;
}()
}, {
key: "getStaticFloatModule",
value: function () {
var _getStaticFloatModule = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11(module) {
var foundFloatModule, _yield$_get__$default7, data;
return regeneratorRuntime.wrap(function _callee11$(_context11) {
while (1) {
switch (_context11.prev = _context11.next) {
case 0:
foundFloatModule = this.findFloatModule(module.name);
if (!foundFloatModule) {
_context11.next = 14;
break;
}
_context11.prev = 2;
_get__("addStyles")(foundFloatModule);
_context11.next = 6;
return _get__("axios_1")["default"].get(foundFloatModule.path);
case 6:
_yield$_get__$default7 = _context11.sent;
data = _yield$_get__$default7.data;
this.floatLoadedModules.push({
name: foundFloatModule.name,
version: foundFloatModule.version,
path: foundFloatModule.path,
type: foundFloatModule.type,
pageRoute: foundFloatModule.pageRoute,
childrenRoutes: foundFloatModule.childrenRoutes,
css: foundFloatModule.css,
module: data
});
_context11.next = 14;
break;
case 11:
_context11.prev = 11;
_context11.t0 = _context11["catch"](2);
console.error(_context11.t0);
case 14:
case "end":
return _context11.stop();
}
}
}, _callee11, this, [[2, 11]]);
}));
function getStaticFloatModule(_x8) {
return _getStaticFloatModule.apply(this, arguments);
}
return getStaticFloatModule;
}()
}, {
key: "injectFloatModules",
value: function () {
var _injectFloatModules = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee12(apiUrl) {
var index;
return regeneratorRuntime.wrap(function _callee12$(_context12) {
while (1) {
switch (_context12.prev = _context12.next) {
case 0:
_context12.prev = 0;
_context12.next = 3;
return this.getFloatModules(apiUrl);
case 3:
_context12.t0 = regeneratorRuntime.keys(this.floatModules);
case 4:
if ((_context12.t1 = _context12.t0()).done) {
_context12.next = 11;
break;
}
index = _context12.t1.value;
_get__("addStyles")(this.floatModules[index]);
_context12.next = 9;
return this.getFloatModule(this.floatModules[index]);
case 9:
_context12.next = 4;
break;
case 11:
_context12.next = 16;
break;
case 13:
_context12.prev = 13;
_context12.t2 = _context12["catch"](0);
console.error(_context12.t2);
case 16:
return _context12.abrupt("return", this.floatLoadedModules);
case 17:
case "end":
return _context12.stop();
}
}
}, _callee12, this, [[0, 13]]);
}));
function injectFloatModules(_x9) {
return _injectFloatModules.apply(this, arguments);
}
return injectFloatModules;
}()
}, {
key: "injectFloatModule",
value: function () {
var _injectFloatModule = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee13(name, moduleUrl) {
return regeneratorRuntime.wrap(function _callee13$(_context13) {
while (1) {
switch (_context13.prev = _context13.next) {
case 0:
_context13.prev = 0;
_context13.next = 3;
return this.getFloatStaticModule("".concat(moduleUrl, "/").concat(name));
case 3:
_context13.next = 8;
break;
case 5:
_context13.prev = 5;
_context13.t0 = _context13["catch"](0);
console.error(_context13.t0);
case 8:
return _context13.abrupt("return", this.findLoadedFloatModule(name));
case 9:
case "end":
return _context13.stop();
}
}
}, _callee13, this, [[0, 5]]);
}));
function injectFloatModule(_x10, _x11) {
return _injectFloatModule.apply(this, arguments);
}
return injectFloatModule;
}()
}, {
key: "executeFloatModule",
value: function executeFloatModule(name) {
var foundFloatModule = this.findFloatModule(name);
var foundFloatLoadedModule = this.findLoadedFloatModule(name);
if (foundFloatModule && foundFloatLoadedModule) {
_get__("addStyles")(foundFloatLoadedModule);
eval(foundFloatLoadedModule.module);
}
}
}, {
key: "asPwa",
value: function () {
var _asPwa2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee14(pwa) {
var _this3 = this;
return regeneratorRuntime.wrap(function _callee14$(_context14) {
while (1) {
switch (_context14.prev = _context14.next) {
case 0:
_context14.prev = 0;
_context14.next = 3;
return _get__("loadPwaAppInstance")(pwa, function (ctx) {
if (pwa.asInstance) _this3.asInstance();
_this3.StoreFloatContext = ctx;
});
case 3:
_context14.next = 8;
break;
case 5:
_context14.prev = 5;
_context14.t0 = _context14["catch"](0);
console.log(_context14.t0.message);
case 8:
case "end":
return _context14.stop();
}
}
}, _callee14, null, [[0, 5]]);
}));
function asPwa(_x12) {
return _asPwa2.apply(this, arguments);
}
return asPwa;
}()
}, {
key: "asInstance",
value: function asInstance() {
this.isInstance = true;
}
}]);
return ModuleLoader;
}();
exports.ModuleLoader = _get__("ModuleLoader");
_get__("ModuleLoader").isInstance = false;
_get__("ModuleLoader").StoreFloatContext = null;
_get__("ModuleLoader").floatModules = [];
_get__("ModuleLoader").floatLoadedModules = [];
function _getGlobalObject() {
try {
if (!!global) {
return global;
}
} catch (e) {
try {
if (!!window) {
return window;
}
} catch (e) {
return this;
}
}
}
;
var _RewireModuleId__ = null;
function _getRewireModuleId__() {
if (_RewireModuleId__ === null) {
var globalVariable = _getGlobalObject();
if (!globalVariable.__$$GLOBAL_REWIRE_NEXT_MODULE_ID__) {
globalVariable.__$$GLOBAL_REWIRE_NEXT_MODULE_ID__ = 0;
}
_RewireModuleId__ = __$$GLOBAL_REWIRE_NEXT_MODULE_ID__++;
}
return _RewireModuleId__;
}
function _getRewireRegistry__() {
var theGlobalVariable = _getGlobalObject();
if (!theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__) {
theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__ = Object.create(null);
}
return theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__;
}
function _getRewiredData__() {
var moduleId = _getRewireModuleId__();
var registry = _getRewireRegistry__();
var rewireData = registry[moduleId];
if (!rewireData) {
registry[moduleId] = Object.create(null);
rewireData = registry[moduleId];
}
return rewireData;
}
(function registerResetAll() {
var theGlobalVariable = _getGlobalObject();
if (!theGlobalVariable['__rewire_reset_all__']) {
theGlobalVariable['__rewire_reset_all__'] = function () {
theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__ = Object.create(null);
};
}
})();
var INTENTIONAL_UNDEFINED = '__INTENTIONAL_UNDEFINED__';
var _RewireAPI__ = {};
(function () {
function addPropertyToAPIObject(name, value) {
Object.defineProperty(_RewireAPI__, name, {
value: value,
enumerable: false,
configurable: true
});
}
addPropertyToAPIObject('__get__', _get__);
addPropertyToAPIObject('__GetDependency__', _get__);
addPropertyToAPIObject('__Rewire__', _set__);
addPropertyToAPIObject('__set__', _set__);
addPropertyToAPIObject('__reset__', _reset__);
addPropertyToAPIObject('__ResetDependency__', _reset__);
addPropertyToAPIObject('__with__', _with__);
})();
function _get__(variableName) {
var rewireData = _getRewiredData__();
if (rewireData[variableName] === undefined) {
return _get_original__(variableName);
} else {
var value = rewireData[variableName];
if (value === INTENTIONAL_UNDEFINED) {
return undefined;
} else {
return value;
}
}
}
function _get_original__(variableName) {
switch (variableName) {
case "__importDefault":
return __importDefault;
case "ModuleType":
return ModuleType;
case "ModuleLoader":
return ModuleLoader;
case "cacheStore":
return cacheStore;
case "syncUts":
return syncUts;
case "syncAsGlobalValueByUts":
return syncAsGlobalValueByUts;
case "registeredUST":
return registeredUST;
case "addStore":
return addStore;
case "loadPwaHandler":
return loadPwaHandler;
case "StoreManager":
return StoreManager;
case "isUstRegister":
return isUstRegister;
case "listenerRegistration":
return listenerRegistration;
case "listenerCanBeAdded":
return listenerCanBeAdded;
case "axios_1":
return axios_1;
case "addStyles":
return addStyles;
case "loadPwaAppInstance":
return loadPwaAppInstance;
}
return undefined;
}
function _assign__(variableName, value) {
var rewireData = _getRewiredData__();
if (rewireData[variableName] === undefined) {
return _set_original__(variableName, value);
} else {
return rewireData[variableName] = value;
}
}
function _set_original__(variableName, _value) {
switch (variableName) {
case "ModuleType":
return ModuleType = _value;
case "cacheStore":
return cacheStore = _value;
}
return undefined;
}
function _update_operation__(operation, variableName, prefix) {
var oldValue = _get__(variableName);
var newValue = operation === '++' ? oldValue + 1 : oldValue - 1;
_assign__(variableName, newValue);
return prefix ? newValue : oldValue;
}
function _set__(variableName, value) {
var rewireData = _getRewiredData__();
if (_typeof(variableName) === 'object') {
Object.keys(variableName).forEach(function (name) {
rewireData[name] = variableName[name];
});
return function () {
Object.keys(variableName).forEach(function (name) {
_reset__(variableName);
});
};
} else {
if (value === undefined) {
rewireData[variableName] = INTENTIONAL_UNDEFINED;
} else {
rewireData[variableName] = value;
}
return function () {
_reset__(variableName);
};
}
}
function _reset__(variableName) {
var rewireData = _getRewiredData__();
delete rewireData[variableName];
if (Object.keys(rewireData).length == 0) {
delete _getRewireRegistry__()[_getRewireModuleId__];
}
;
}
function _with__(object) {
var rewireData = _getRewiredData__();
var rewiredVariableNames = Object.keys(object);
var previousValues = {};
function reset() {
rewiredVariableNames.forEach(function (variableName) {
rewireData[variableName] = previousValues[variableName];
});
}
return function (callback) {
rewiredVariableNames.forEach(function (variableName) {
previousValues[variableName] = rewireData[variableName];
rewireData[variableName] = object[variableName];
});
var result = callback();
if (!!result && typeof result.then == 'function') {
result.then(reset)["catch"](reset);
} else {
reset();
}
return result;
};
}
var _typeOfOriginalExport = _typeof(module.exports);
function addNonEnumerableProperty(name, value) {
Object.defineProperty(module.exports, name, {
value: value,
enumerable: false,
configurable: true
});
}
if ((_typeOfOriginalExport === 'object' || _typeOfOriginalExport === 'function') && Object.isExtensible(module.exports)) {
addNonEnumerableProperty('__get__', _get__);
addNonEnumerableProperty('__GetDependency__', _get__);
addNonEnumerableProperty('__Rewire__', _set__);
addNonEnumerableProperty('__set__', _set__);
addNonEnumerableProperty('__reset__', _reset__);
addNonEnumerableProperty('__ResetDependency__', _reset__);
addNonEnumerableProperty('__with__', _with__);
addNonEnumerableProperty('__RewireAPI__', _RewireAPI__);
}