skinny-widgets
Version:
skinnable web components widgets collection
1,190 lines (1,006 loc) • 1.21 MB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.window = global.window || {}));
}(this, (function (exports) { 'use strict';
function _typeof$1T(obj) { "@babel/helpers - typeof"; return _typeof$1T = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof$1T(obj); }
function _createForOfIteratorHelper$q(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$t(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$t(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$t(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$t(o, minLen); }
function _arrayLikeToArray$t(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; }
function _classCallCheck$22(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties$22(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$22(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$22(Constructor.prototype, protoProps); if (staticProps) _defineProperties$22(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
var LOG_LEVEL_DEFAULT = 'info,error,warn';
var ConsoleLogger = /*#__PURE__*/function () {
function ConsoleLogger() {
_classCallCheck$22(this, ConsoleLogger);
}
_createClass$22(ConsoleLogger, [{
key: "levels",
get: function get() {
return this._levels;
},
set: function set(levels) {
this._logLevel = levels;
this._levels = levels.split(",");
}
}, {
key: "logLevel",
get: function get() {
return this._logLevel || LOG_LEVEL_DEFAULT;
},
set: function set(level) {
this._logLevel = level;
this._levels = level.split(",");
}
}, {
key: "info",
value: function info() {
if (this.levels.indexOf('info') > -1) {
if (typeof console !== 'undefined') {
console.log.apply(console, arguments);
}
}
}
}, {
key: "debug",
value: function debug() {
if (this.levels.indexOf('debug') > -1) {
if (typeof console !== 'undefined') {
console.debug.apply(console, arguments);
}
}
}
}, {
key: "error",
value: function error() {
if (this.levels.indexOf('error') > -1) {
if (typeof console !== 'undefined') {
console.error.apply(console, arguments);
}
}
}
}, {
key: "warn",
value: function warn() {
if (this.levels.indexOf('warn') > -1) {
if (typeof console !== 'undefined') {
console.warn.apply(console, arguments);
}
}
}
}], [{
key: "instance",
value: function instance() {
if (!ConsoleLogger._instance) {
ConsoleLogger._instance = new ConsoleLogger();
ConsoleLogger._instance.levels = LOG_LEVEL_DEFAULT;
}
return ConsoleLogger._instance;
}
}, {
key: "info",
value: function info() {
ConsoleLogger.instance().info(arguments);
}
}, {
key: "debug",
value: function debug() {
ConsoleLogger.instance().debug(arguments);
}
}, {
key: "error",
value: function error() {
ConsoleLogger.instance().error(arguments);
}
}, {
key: "warn",
value: function warn() {
ConsoleLogger.instance().warn(arguments);
}
}]);
return ConsoleLogger;
}();
var MemoryLogger = /*#__PURE__*/function () {
function MemoryLogger() {
_classCallCheck$22(this, MemoryLogger);
}
_createClass$22(MemoryLogger, [{
key: "logs",
get: function get() {
if (!this._logs) {
this._logs = [];
}
return this._logs;
},
set: function set(logs) {
this._logs = logs;
}
}, {
key: "levels",
get: function get() {
return this._levels;
},
set: function set(levels) {
this._logLevel = levels;
this._levels = levels.split(",");
}
}, {
key: "logLevel",
get: function get() {
return this._logLevel || LOG_LEVEL_DEFAULT;
},
set: function set(level) {
this._logLevel = level;
this._levels = level.split(",");
}
}, {
key: "info",
value: function info() {
if (this.levels.indexOf('info') > -1) {
this.logs.push({
time: Date.now(),
message: arguments
});
}
}
}, {
key: "debug",
value: function debug() {
if (this.levels.indexOf('debug') > -1) {
this.logs.push({
time: Date.now(),
message: arguments
});
}
}
}, {
key: "error",
value: function error() {
if (this.levels.indexOf('error') > -1) {
this.logs.push({
time: Date.now(),
message: arguments
});
}
}
}, {
key: "warn",
value: function warn() {
if (this.levels.indexOf('warn') > -1) {
this.logs.push({
time: Date.now(),
message: arguments
});
}
}
}], [{
key: "instance",
value: function instance() {
if (!MemoryLogger._instance) {
MemoryLogger._instance = new MemoryLogger();
MemoryLogger._instance.levels = LOG_LEVEL_DEFAULT;
}
return MemoryLogger._instance;
}
}, {
key: "info",
value: function info() {
MemoryLogger.instance().info(arguments);
}
}, {
key: "debug",
value: function debug() {
MemoryLogger.instance().debug(arguments);
}
}, {
key: "error",
value: function error() {
MemoryLogger.instance().error(arguments);
}
}, {
key: "warn",
value: function warn() {
MemoryLogger.instance().warn(arguments);
}
}]);
return MemoryLogger;
}();
var SESSION_LOGS_ATTR = "skLogs";
var SessionLogger = /*#__PURE__*/function () {
function SessionLogger() {
_classCallCheck$22(this, SessionLogger);
}
_createClass$22(SessionLogger, [{
key: "logs",
get: function get() {
if (!this._logs) {
try {
var prevLogs = sessionStorage.get(SESSION_LOGS_ATTR) || "[]";
if (prevLogs) {
var logsParsed = JSON.parse(prevLogs);
if (Array.isArray(logsParsed) && logsParsed.length > -1) {
this._logs = logsParsed;
} else {
this._logs = [];
}
} else {
this._logs = [];
}
} catch (_unused) {
this._logs = [];
}
}
return this._logs;
},
set: function set(logs) {
this._logs = logs;
}
}, {
key: "levels",
get: function get() {
return this._levels;
},
set: function set(levels) {
this._logLevel = levels;
this._levels = levels.split(",");
}
}, {
key: "logLevel",
get: function get() {
return this._logLevel || LOG_LEVEL_DEFAULT;
},
set: function set(level) {
this._logLevel = level;
this._levels = level.split(",");
}
}, {
key: "writeLog",
value: function writeLog() {
var message = [];
var _iterator = _createForOfIteratorHelper$q(arguments),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var arg = _step.value;
if (typeof arg === "string" || typeof arg === "number") {
message.push(arg.toString());
} else if (_typeof$1T(arg) === "object") {
var subArg = {};
var _iterator2 = _createForOfIteratorHelper$q(Object.getOwnPropertyNames(arg)),
_step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var subArgName = _step2.value;
if (["caller", "callee", "arguments", "length"].indexOf(subArgName) < 0) {
if (typeof arg[subArgName] === "string" || typeof arg[subArgName] === "number") {
subArg[subArgName] = arg[subArgName];
}
}
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
try {
if (Object.getOwnPropertyNames(subArg).length > -1) {
message.push(JSON.stringify(subArg));
}
} catch (_unused2) {}
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
if (message.length > -1) {
this.logs.push({
time: Date.now(),
message: message
});
sessionStorage.setItem(SESSION_LOGS_ATTR, JSON.stringify(this.logs));
}
}
}, {
key: "info",
value: function info() {
if (this.levels.indexOf('info') > -1) {
this.writeLog(arguments);
}
}
}, {
key: "debug",
value: function debug() {
if (this.levels.indexOf('debug') > -1) {
this.writeLog(arguments);
}
}
}, {
key: "error",
value: function error() {
if (this.levels.indexOf('error') > -1) {
this.writeLog(arguments);
}
}
}, {
key: "warn",
value: function warn() {
if (this.levels.indexOf('warn') > -1) {
this.writeLog(arguments);
}
}
}], [{
key: "instance",
value: function instance() {
if (!SessionLogger._instance) {
SessionLogger._instance = new SessionLogger();
SessionLogger._instance.levels = LOG_LEVEL_DEFAULT;
}
return SessionLogger._instance;
}
}, {
key: "info",
value: function info() {
SessionLogger.instance().info(arguments);
}
}, {
key: "debug",
value: function debug() {
SessionLogger.instance().debug(arguments);
}
}, {
key: "error",
value: function error() {
SessionLogger.instance().error(arguments);
}
}, {
key: "warn",
value: function warn() {
SessionLogger.instance().warn(arguments);
}
}]);
return SessionLogger;
}();
function _createForOfIteratorHelper$p(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$s(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$s(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$s(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$s(o, minLen); }
function _arrayLikeToArray$s(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; }
function _typeof$1S(obj) { "@babel/helpers - typeof"; return _typeof$1S = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof$1S(obj); }
function _newArrowCheck$F(innerThis, boundThis) { if (innerThis !== boundThis) { throw new TypeError("Cannot instantiate an arrow function"); } }
function _classCallCheck$21(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties$21(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$21(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$21(Constructor.prototype, protoProps); if (staticProps) _defineProperties$21(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
var ResLoader = /*#__PURE__*/function () {
function ResLoader() {
_classCallCheck$21(this, ResLoader);
}
_createClass$21(ResLoader, null, [{
key: "dynamicImportSupported",
value: function dynamicImportSupported() {
try {
new Function('import("")');
return true;
} catch (err) {
return false;
}
}
}, {
key: "isInIE",
value: function isInIE() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
if (msie > 0) {
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
}
var trident = ua.indexOf('Trident/');
if (trident > 0) {
var rv = ua.indexOf('rv:');
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
}
var edge = ua.indexOf('Edge/');
if (edge > 0) {
return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
}
return false;
}
}, {
key: "loadJson",
value: function loadJson(url) {
var _this = this;
return new Promise(function (resolve, reject) {
_newArrowCheck$F(this, _this);
fetch(url).then(function (response) {
var _this2 = this;
response.json().then(function (json) {
_newArrowCheck$F(this, _this2);
resolve(json);
}.bind(this));
});
}.bind(this));
}
}, {
key: "loadClass",
value: function loadClass(className, path, callback) {
var _this3 = this;
var nowindow = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
var dynImportOff = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
var loaded;
var setToWin = function setToWin() {
_newArrowCheck$F(this, _this3);
if (!nowindow) {
loaded.then(function (m) {
if (m[className]) {
window[className] = m[className];
return m;
}
});
}
}.bind(this);
var applyCallback = function applyCallback() {
_newArrowCheck$F(this, _this3);
if (callback) {
loaded.then(callback);
}
}.bind(this);
if (!dynImportOff && ResLoader.dynamicImportSupported() && !ResLoader.isInIE()) {
loaded = require("".concat(path));
setToWin();
applyCallback();
return loaded;
} else {
loaded = new Promise(function (resolve, reject) {
var script = document.createElement('script');
script.onload = resolve;
script.onerror = reject;
script.async = true;
script.src = path;
document.body.appendChild(script);
}.bind(this));
setToWin();
applyCallback();
return loaded;
}
}
}, {
key: "deepCopy",
value: function deepCopy(from, to, level) {
var maxLevel = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 256;
if (from == null || _typeof$1S(from) != "object") return from;
if (from.constructor != Object && from.constructor != Array) return from;
if (from.constructor == Date || from.constructor == RegExp || from.constructor == Function || from.constructor == String || from.constructor == Number || from.constructor == Boolean) return new from.constructor(from);
to = to || new from.constructor();
if (!level) level = 0;
level++;
if (level <= maxLevel) {
for (var name in from) {
to[name] = ResLoader.deepCopy(from[name], null);
}
}
return to;
}
}, {
key: "instIndex",
value: function instIndex(className, path, factory) {
return factory ? className + '::' + path + '::' + factory.toString().replace(/(\r\n|\n|\r| |\t)/gm, "") : className + '::' + path;
}
}, {
key: "promiseStore",
value: function promiseStore() {
var resLoader = window.ResLoader ? window.ResLoader : ResLoader;
if (!resLoader._loadPromises) {
resLoader._loadPromises = new Map();
}
return resLoader._loadPromises;
}
}, {
key: "instanceStore",
value: function instanceStore() {
var resLoader = window.ResLoader ? window.ResLoader : ResLoader;
if (!resLoader._loadInstances) {
resLoader._loadInstances = new Map();
}
return resLoader._loadInstances;
}
}, {
key: "cacheClassDefs",
value: function cacheClassDefs() {
var _iterator = _createForOfIteratorHelper$p(arguments),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var def = _step.value;
if (def.name && !window[def.name]) {
window[def.name] = def;
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}
/**
* does class and instance loading.
* If class with the same name and path was previously loaded it's previous instance will be returned
* by default and until forceNewInstance arg is set.
*
* className - class name string
* path - loading path
* factory - external method to create and setup new instance
* forceNewInstance - will do new instance with provided argument factory or class constructor.
* keepState - link state props from prev instance
* deepClone - recursive copy from prev instance
* promiseStore - use external Map for loading promises cache
* instanceStore - use external Map for class instance cache
* cloneImpl - use external implementation for deepClone operation
* dynImmportOff - turn of dynamic import use (e.g. for transpilled code)
* sync return instance without promise, class def must be preloaded and assigned to window
* */
}, {
key: "dynLoad",
value: function dynLoad(className, path, factory, forceNewInstance, keepState, deepClone, promiseStore, instanceStore, cloneImpl, dynImportOff, sync, stDef) {
var _this4 = this;
var index = ResLoader.instIndex(className, path, factory);
var promises;
var instances;
var doNewInstance = function doNewInstance(model) {
var instance;
if (factory) {
instance = factory(model.constructor);
} else {
instance = new model.constructor();
}
if (keepState) {
if (deepClone) {
if (cloneImpl && typeof cloneImpl === 'function') {
instance = cloneImpl(model);
} else {
ResLoader.deepCopy(model, instance);
}
} else {
Object.assign(instance, model);
}
}
return instance;
};
if (!promiseStore) {
promises = ResLoader.promiseStore();
} else {
promises = promiseStore;
}
if (!instanceStore) {
instances = ResLoader.instanceStore();
} else {
instances = instanceStore;
}
if (instances.get(index)) {
if (forceNewInstance) {
var model = instances.get(index);
var instance = doNewInstance(model);
return sync ? instance : Promise.resolve(instance);
} else {
return sync ? instances.get(index) : Promise.resolve(instances.get(index));
}
} else {
if (sync) {
if (stDef && !window[className]) {
window[className] = stDef;
}
var def = Function('return ' + className)();
var _instance;
if (factory) {
_instance = factory(def);
} else {
_instance = new def();
}
instances.set(index, _instance);
promises.set(index, Promise.resolve(_instance));
return _instance;
} else {
if (!promises.get(index)) {
promises.set(index, new Promise(function (resolve, reject) {
var _this5 = this;
_newArrowCheck$F(this, _this4);
try {
if (stDef && !window[className]) {
window[className] = stDef;
}
var _def = Function('return ' + className)();
var _instance2;
if (factory) {
_instance2 = factory(_def);
} else {
_instance2 = new _def();
}
instances.set(index, _instance2);
resolve(_instance2);
} catch (_unused) {
if (path.endsWith(".json")) {
promises.set(index, ResLoader.loadJson(path));
promises.get(index).then(function (m) {
_newArrowCheck$F(this, _this5);
resolve(m);
}.bind(this));
} else {
promises.set(index, ResLoader.loadClass(className, path, null, false, dynImportOff));
promises.get(index).then(function (m) {
_newArrowCheck$F(this, _this5);
var def = typeof m[className] === 'function' ? m[className] : window[className];
if (def) {
var _instance3;
if (factory) {
_instance3 = factory(def);
} else {
_instance3 = new def();
}
instances.set(index, _instance3);
resolve(_instance3);
} else {
reject("expected constructor for ".concat(className, " not found"));
}
}.bind(this));
}
}
}.bind(this)));
}
if (forceNewInstance) {
return new Promise(function (resolve, reject) {
var _this6 = this;
_newArrowCheck$F(this, _this4);
var onLoaded = promises.get(index);
onLoaded.then(function (model) {
_newArrowCheck$F(this, _this6);
var instance = doNewInstance(model);
if (!instances.get(index)) {
instances.set(index, instance);
}
return resolve(instance);
}.bind(this));
}.bind(this));
} else {
return promises.get(index);
}
}
}
}
}]);
return ResLoader;
}();
function _classCallCheck$20(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties$20(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$20(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$20(Constructor.prototype, protoProps); if (staticProps) _defineProperties$20(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
var JsonPathPlusDriver = /*#__PURE__*/function () {
function JsonPathPlusDriver() {
_classCallCheck$20(this, JsonPathPlusDriver);
}
_createClass$20(JsonPathPlusDriver, [{
key: "query",
value: function query(data, path) {
return window.JSONPath.JSONPath({
path: path,
json: data
});
}
}]);
return JsonPathPlusDriver;
}();
function _toConsumableArray$4(arr) { return _arrayWithoutHoles$4(arr) || _iterableToArray$4(arr) || _unsupportedIterableToArray$r(arr) || _nonIterableSpread$4(); }
function _nonIterableSpread$4() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray$4(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles$4(arr) { if (Array.isArray(arr)) return _arrayLikeToArray$r(arr); }
function _createForOfIteratorHelper$o(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$r(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$r(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$r(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$r(o, minLen); }
function _arrayLikeToArray$r(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; }
function _newArrowCheck$E(innerThis, boundThis) { if (innerThis !== boundThis) { throw new TypeError("Cannot instantiate an arrow function"); } }
function _classCallCheck$1$(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties$1$(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$1$(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$1$(Constructor.prototype, protoProps); if (staticProps) _defineProperties$1$(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
var JSONPATH_CN = "JsonPath";
var JSONPATH_PT = "/node_modules/sk-core/src/json-path.js";
if (window.hasOwnProperty('jsonpath')) {
if (typeof window.jsonpath.JSONPath === 'function') {
new window.jsonpath.JSONPath();
}
}
var logger$1 = ConsoleLogger.instance();
var SkJsonPathDriver = /*#__PURE__*/function () {
function SkJsonPathDriver() {
_classCallCheck$1$(this, SkJsonPathDriver);
}
_createClass$1$(SkJsonPathDriver, [{
key: "libPath",
get: function get() {
return window.skJsonPathUrl ? window.skJsonPathUrl : '/node_modules/sk-jsonpath/src/jsonpath.js';
}
}, {
key: "lib",
value: function lib() {
if (!this._lib) {
if (window.hasOwnProperty('jsonpath')) {
this._lib = typeof window.jsonpath.JSONPath === 'function' ? window.jsonpath.JSONPath() : null;
} else {
this.libLoadPromise = new Promise(function (resolve, reject) {
var _this = this;
var onLoaded = ResLoader.loadClass('JSONPath', this.libPath, null, false, true);
onLoaded.then(function () {
_newArrowCheck$E(this, _this);
if (window.hasOwnProperty('jsonpath')) {
this._lib = new window.jsonpath.JSONPath();
resolve(this._lib);
} else {
reject('Unable to load sk-jsonpath library');
}
}.bind(this));
}.bind(this));
}
}
return this._lib;
}
}, {
key: "query",
value: function query() {
var args = arguments;
var impl = null;
if (this._lib && typeof this._lib.query === 'function') {
impl = this._lib;
}
if (!impl) {
if (!this.notLoadedWarnShown) {
logger$1.warn('JSONPath lib not inited, using fallback impl');
this.notLoadedWarnShown = true;
}
var pathString = args[1] ? args[1].replace('$.', '') : ''; // fallback simple recursive path drill impl
var data = args[0];
var path = pathString.split('.');
if (path.length == 1) {
return [data[path[0]]];
} else {
var item = data;
var _iterator = _createForOfIteratorHelper$o(path),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var token = _step.value;
item = item[token];
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
return item;
}
} else {
var _impl;
return (_impl = impl).query.apply(_impl, _toConsumableArray$4(args));
}
}
}]);
return SkJsonPathDriver;
}();
var JsonPath = /*#__PURE__*/function () {
function JsonPath() {
_classCallCheck$1$(this, JsonPath);
}
_createClass$1$(JsonPath, [{
key: "driClass",
get: function get() {
return window.JsonPathPlusEsmDriver ? // esm driver bundled at compile time
window.JsonPathPlusEsmDriver : window.JSONPath && window.JSONPath.JSONPath ? // jsonpath-plus library pluged statically at runtime
JsonPathPlusDriver : SkJsonPathDriver; //fallback
}
}, {
key: "dri",
get: function get() {
if (!this._dri) {
this._dri = new this.driClass();
}
return this._dri;
},
set: function set(dri) {
this._dri = dri;
}
}, {
key: "query",
value: function query() {
var _this$dri;
return (_this$dri = this.dri).query.apply(_this$dri, arguments);
}
}]);
return JsonPath;
}();
function _classCallCheck$1_(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties$1_(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$1_(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$1_(Constructor.prototype, protoProps); if (staticProps) _defineProperties$1_(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
var REQ_TYPE_GET = "GET";
var REQ_TYPE_POST = "POST";
var REQ_TYPE_PUT = "PUT";
var REQ_TYPE_DELETE = "DELETE";
var REQ_TYPE_OPTIONS = "OPTIONS";
var CONTENT_TYPE_JSON = "application/json";
var HEADER_CONTENT_TYPE = "Content-Type";
var HEADER_AUTHORIZATION = "Authorization";
var ARG_CONTENT_TYPE_AUTO = "auto";
var AUTH_TYPE_BASIC = "basic";
var HttpClientBase = /*#__PURE__*/function () {
function HttpClientBase() {
_classCallCheck$1_(this, HttpClientBase);
}
_createClass$1_(HttpClientBase, [{
key: "get",
value: function get(url, contentType) {
return this.request(url, REQ_TYPE_GET, contentType ? contentType : null, null);
}
}, {
key: "post",
value: function post(url, contentType, body) {
return this.request(url, REQ_TYPE_POST, contentType ? contentType : null, body);
}
}, {
key: "put",
value: function put(url, contentType, body) {
return this.request(url, REQ_TYPE_PUT, contentType ? contentType : null, body);
}
}, {
key: "delete",
value: function _delete(url, contentType, body) {
return this.request(url, REQ_TYPE_DELETE, contentType ? contentType : null, body);
}
}, {
key: "options",
value: function options(url, contentType, body) {
return this.request(url, REQ_TYPE_OPTIONS, contentType ? contentType : null, body);
}
}]);
return HttpClientBase;
}();
function _typeof$1R(obj) { "@babel/helpers - typeof"; return _typeof$1R = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof$1R(obj); }
function _newArrowCheck$D(innerThis, boundThis) { if (innerThis !== boundThis) { throw new TypeError("Cannot instantiate an arrow function"); } }
function _classCallCheck$1Z(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties$1Z(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$1Z(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$1Z(Constructor.prototype, protoProps); if (staticProps) _defineProperties$1Z(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits$1N(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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf$1N(subClass, superClass); }
function _setPrototypeOf$1N(o, p) { _setPrototypeOf$1N = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf$1N(o, p); }
function _createSuper$1N(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$1N(); return function _createSuperInternal() { var Super = _getPrototypeOf$1N(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf$1N(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn$1N(this, result); }; }
function _possibleConstructorReturn$1N(self, call) { if (call && (_typeof$1R(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized$1N(self); }
function _assertThisInitialized$1N(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct$1N() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf$1N(o) { _getPrototypeOf$1N = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf$1N(o); }
var XmlHttpClient = /*#__PURE__*/function (_HttpClientBase) {
_inherits$1N(XmlHttpClient, _HttpClientBase);
var _super = _createSuper$1N(XmlHttpClient);
function XmlHttpClient() {
_classCallCheck$1Z(this, XmlHttpClient);
return _super.apply(this, arguments);
}
_createClass$1Z(XmlHttpClient, [{
key: "request",
value: //auth;
//headers;
function request(url) {
var _this = this;
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'GET';
var contentType = arguments.length > 2 ? arguments[2] : undefined;
var body = arguments.length > 3 ? arguments[3] : undefined;
var headers = arguments.length > 4 ? arguments[4] : undefined;
return new Promise(function (resolve, reject) {
var _this2 = this;
_newArrowCheck$D(this, _this);
var xhr = new XMLHttpRequest();
xhr.open(type, url);
if (contentType !== ARG_CONTENT_TYPE_AUTO) {
xhr.setRequestHeader(HEADER_CONTENT_TYPE, contentType ? contentType : CONTENT_TYPE_JSON);
}
if (this.auth && this.auth.type === AUTH_TYPE_BASIC) {
xhr.setRequestHeader(HEADER_AUTHORIZATION, "Basic " + btoa(this.auth.username + ':' + this.auth.password));
}
if (this.headers && _typeof$1R(this.headers) === 'object') {
for (var _i = 0, _Object$keys = Object.keys(this.headers); _i < _Object$keys.length; _i++) {
var headerName = _Object$keys[_i];
xhr.setRequestHeader(headerName, this.headers[headerName]);
}
}
if (headers && _typeof$1R(headers) === 'object') {
for (var _i2 = 0, _Object$keys2 = Object.keys(headers); _i2 < _Object$keys2.length; _i2++) {
var _headerName = _Object$keys2[_i2];
xhr.setRequestHeader(_headerName, headers[_headerName]);
}
}
if (!ResLoader.isInIE()) {
xhr.responseType = 'json';
}
xhr.onreadystatechange = function (event) {
_newArrowCheck$D(this, _this2);
var request = event.target;
if (request.readyState === XMLHttpRequest.DONE) {
if (request.status === 200) {
resolve(request);
} else {
reject(request);
}
}
}.bind(this);
if (body) {
xhr.send(body);
} else {
xhr.send();
}
}.bind(this));
}
}]);
return XmlHttpClient;
}(HttpClientBase);
function _typeof$1Q(obj) { "@babel/helpers - typeof"; return _typeof$1Q = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof$1Q(obj); }
function _classCallCheck$1Y(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties$1Y(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$1Y(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$1Y(Constructor.prototype, protoProps); if (staticProps) _defineProperties$1Y(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
var HgTemplateEngine = /*#__PURE__*/function () {
function HgTemplateEngine(handlebars) {
_classCallCheck$1Y(this, HgTemplateEngine);
this.handlebars = handlebars;
}
_createClass$1Y(HgTemplateEngine, [{
key: "renderString",
value: function renderString(tplString, data) {
var templateFunc = this.handlebars.compile(tplString);
var result = templateFunc(data);
return result;
}
}, {
key: "render",
value: function render(tpl, data) {
if (_typeof$1Q(tpl) === 'object') {
var wrapper = document.createElement('div');
wrapper.appendChild(tpl);
var templateString = wrapper.outerHTML.toString();
var rendered = this.renderString(templateString, data);
var wrapper2 = document.createElement('div');
wrapper2.insertAdjacentHTML('beforeend', rendered);
return wrapper2.firstElementChild.innerHTML;
} else {
return this.renderString(tpl, data);
}
}
}]);
return HgTemplateEngine;
}();
function _typeof$1P(obj) { "@babel/helpers - typeof"; return _typeof$1P = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof$1P(obj); }
function _classCallCheck$1X(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties$1X(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$1X(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$1X(Constructor.prototype, protoProps); if (staticProps) _defineProperties$1X(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
var BaseTemplateEngine = /*#__PURE__*/function () {
function BaseTemplateEngine() {
_classCallCheck$1X(this, BaseTemplateEngine);
}
_createClass$1X(BaseTemplateEngine, [{
key: "renderMustacheVars",
value: function renderMustacheVars(el, map) {
var wrapper = document.createElement('div');
wrapper.appendChild(el);
var template = wrapper.outerHTML.toString();
for (var _i = 0, _Object$keys = Object.keys(map); _i < _Object$keys.length; _i++) {
var key = _Object$keys[_i];
template = template.replace(new RegExp('{{ ' + key + ' }}', 'g'), map[key]);
}
var wrapper2 = document.createElement('div');
wrapper2.insertAdjacentHTML('beforeend', template);
return wrapper2.firstElementChild.innerHTML;
}
}, {
key: "renderString",
value: function renderString(tplString, data) {
var resultString = (' ' + tplString).slice(1);
for (var _i2 = 0, _Object$keys2 = Object.keys(data); _i2 < _Object$keys2.length; _i2++) {
var key = _Object$keys2[_i2];
resultString = resultString.replace(new RegExp('{{ ' + key + ' }}', 'g'), data[key]);
}
return resultString;
}
}, {
key: "render",
value: function render(tpl, data) {
if (_typeof$1P(tpl) === 'object') {
return this.renderMustacheVars(tpl, data);
} else {
return thi