@scaleflex/widget-utils 4.8.6 → 4.8.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/lib/LinkHelper.js +153 -0
  2. package/lib/NetworkError.js +30 -0
  3. package/lib/ProgressTimeout.js +45 -0
  4. package/lib/RateLimitedQueue.js +197 -0
  5. package/lib/RequestError.js +38 -0
  6. package/lib/TranslationMissingKeysConsoleHelper.js +113 -0
  7. package/lib/Translator.js +200 -0
  8. package/lib/getLinkWithNewParams.js +13 -0
  9. package/lib/getMetadataMultiSelectQuery.js +66 -0
  10. package/lib/getNonce.js +26 -0
  11. package/lib/getNormalizedItems.js +55 -0
  12. package/lib/getObjectsMutualProperties.js +32 -0
  13. package/lib/getRandomNumber.js +12 -0
  14. package/lib/getSocketHost.js +7 -0
  15. package/lib/getSpeed.js +8 -0
  16. package/lib/getTime.js +18 -0
  17. package/lib/getTimeStamp.js +18 -0
  18. package/lib/handleError.js +13 -0
  19. package/lib/handlePressEnter.js +9 -0
  20. package/lib/handlePromise.js +39 -0
  21. package/lib/hasProperty.js +3 -0
  22. package/lib/hexToRgb.js +15 -0
  23. package/lib/htmlSanitizer.js +6 -0
  24. package/lib/humanReadableDate.js +45 -0
  25. package/lib/humanReadableDateWithTranslations.js +29 -0
  26. package/lib/i18n.client.js +54 -0
  27. package/lib/ignoreEvent.js +10 -0
  28. package/lib/index.js +0 -0
  29. package/lib/injectVirtualPathToFolders.js +24 -0
  30. package/lib/isAi.js +7 -0
  31. package/lib/isArchive.js +12 -0
  32. package/lib/isAudio.js +9 -0
  33. package/lib/isAudioAndSupportsPlayback.js +10 -0
  34. package/lib/isCloudimageFastPreviewSupported.js +16 -0
  35. package/lib/isDOMElement.js +9 -0
  36. package/lib/isDocument.js +10 -0
  37. package/lib/isDragDropSupported.js +20 -0
  38. package/lib/isEmptyObject.js +4 -0
  39. package/lib/isEps.js +8 -0
  40. package/lib/isFile.js +5 -0
  41. package/lib/isFileSupportedByCloudimage.js +14 -0
  42. package/lib/isFolder.js +4 -0
  43. package/lib/isFontFile.js +9 -0
  44. package/lib/isFunction.js +4 -0
  45. package/lib/isImage.js +11 -0
  46. package/lib/isJpg.js +8 -0
  47. package/lib/isMobileDevice.js +12 -0
  48. package/lib/isNetworkError.js +7 -0
  49. package/lib/isNumber.js +4 -0
  50. package/lib/isObjectType.js +5 -0
  51. package/lib/isObjectURL.js +10 -0
  52. package/lib/isOpenedFromAdobe.js +3 -0
  53. package/lib/isOtf.js +10 -0
  54. package/lib/isPdf.js +9 -0
  55. package/lib/isPhotoshopFile.js +8 -0
  56. package/lib/isPreviewSupported.js +12 -0
  57. package/lib/isPromise.js +5 -0
  58. package/lib/isPsd.js +8 -0
  59. package/lib/isScriptFile.js +12 -0
  60. package/lib/isSupportedVideo.js +8 -0
  61. package/lib/isSvg.js +5 -0
  62. package/lib/isTextFile.js +8 -0
  63. package/lib/isThumbnailCloudimgSupported.js +13 -0
  64. package/lib/isThumbnailLocallySupported.js +9 -0
  65. package/lib/isTiff.js +8 -0
  66. package/lib/isTransparencySupported.js +12 -0
  67. package/lib/isTtf.js +11 -0
  68. package/lib/isUploadableFile.js +7 -0
  69. package/lib/isUrl.js +5 -0
  70. package/lib/isValidUri.js +18 -0
  71. package/lib/isVideo.js +8 -0
  72. package/lib/isVideoResourceIntensive.js +9 -0
  73. package/lib/literalDateFromDateObj.js +6 -0
  74. package/lib/logErrorIfDevEnv.js +7 -0
  75. package/lib/lowercaseFirstLetter.js +4 -0
  76. package/lib/mapArrayByStep.js +12 -0
  77. package/lib/mimeTypes.js +60 -0
  78. package/lib/nanoid.js +18 -0
  79. package/lib/openLink.js +3 -0
  80. package/lib/openLinkInNewTab.js +12 -0
  81. package/lib/prettyETA.js +15 -0
  82. package/lib/prettyFileSize.js +7 -0
  83. package/lib/preventDefault.js +4 -0
  84. package/lib/provideSvgStrWithCurrColor.js +10 -0
  85. package/lib/recursiveFnCall.js +26 -0
  86. package/lib/removeAllUrlParams.js +4 -0
  87. package/lib/removeDuplicatesFromArray.js +20 -0
  88. package/lib/removeEmptyFolders.js +8 -0
  89. package/lib/removeFileExtension.js +4 -0
  90. package/lib/removeUrlParamsWithRegex.js +14 -0
  91. package/lib/reorder.js +15 -0
  92. package/lib/requestFile.js +36 -0
  93. package/lib/rgbToHex.js +4 -0
  94. package/lib/secondsToTime.js +10 -0
  95. package/lib/serializeFunction.js +4 -0
  96. package/lib/settle.js +19 -0
  97. package/lib/sortEntitiesByName.js +18 -0
  98. package/lib/splitCamelCase.js +4 -0
  99. package/lib/splitPathToPathsAndNames.js +25 -0
  100. package/lib/stopPropagation.js +4 -0
  101. package/lib/timeZones.js +1 -0
  102. package/lib/toArray.js +6 -0
  103. package/lib/toLowerCase.js +5 -0
  104. package/lib/toggleElementFullscreen.js +27 -0
  105. package/lib/visibility.js +39 -0
  106. package/package.json +3 -3
  107. package/CHANGELOG.md +0 -7431
@@ -0,0 +1,153 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
5
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
7
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
8
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
9
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
10
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
11
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
12
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
13
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
14
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
15
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
16
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
17
+ import getEncodedWrappedUrl from './getEncodedWrappedUrl';
18
+ var LinkHelper = /*#__PURE__*/function () {
19
+ /**
20
+ * @param {string} href
21
+ */
22
+ function LinkHelper(_ref) {
23
+ var href = _ref.href,
24
+ _ref$wrapEncodeUrl = _ref.wrapEncodeUrl,
25
+ wrapEncodeUrl = _ref$wrapEncodeUrl === void 0 ? false : _ref$wrapEncodeUrl;
26
+ _classCallCheck(this, LinkHelper);
27
+ /**
28
+ * @type {HTMLAnchorElement}
29
+ * @private
30
+ */
31
+ _defineProperty(this, "_link", void 0);
32
+ this._link = document.createElement('a');
33
+ this.wrapEncodeUrl = wrapEncodeUrl;
34
+ this._link.href = wrapEncodeUrl ? getEncodedWrappedUrl(href) : href;
35
+ }
36
+
37
+ /**
38
+ * @returns {HTMLAnchorElement}
39
+ */
40
+ return _createClass(LinkHelper, [{
41
+ key: "link",
42
+ get: function get() {
43
+ return this._link;
44
+ }
45
+
46
+ /**
47
+ * @returns {string}
48
+ */
49
+ }, {
50
+ key: "href",
51
+ get: function get() {
52
+ return this._link.href;
53
+ }
54
+
55
+ /**
56
+ * @returns {string}
57
+ */
58
+ }, {
59
+ key: "origin",
60
+ get: function get() {
61
+ return this._link.origin;
62
+ }
63
+
64
+ /**
65
+ * @returns {string}
66
+ */
67
+ }, {
68
+ key: "search",
69
+ get: function get() {
70
+ return this._link.search;
71
+ }
72
+
73
+ /**
74
+ * @returns {Object}
75
+ */
76
+ }, {
77
+ key: "searchParams",
78
+ get: function get() {
79
+ var _searchParams = {};
80
+ if (!this._link.search) {
81
+ return _searchParams;
82
+ }
83
+ var _params = this._link.search.replace('?', '').split('&');
84
+ var _iterator = _createForOfIteratorHelper(_params),
85
+ _step;
86
+ try {
87
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
88
+ var param = _step.value;
89
+ if (!param) {
90
+ continue;
91
+ }
92
+ var _param$split = param.split('='),
93
+ _param$split2 = _slicedToArray(_param$split, 2),
94
+ key = _param$split2[0],
95
+ value = _param$split2[1];
96
+ if (value !== undefined) {
97
+ _searchParams[key] = value;
98
+ }
99
+ }
100
+ } catch (err) {
101
+ _iterator.e(err);
102
+ } finally {
103
+ _iterator.f();
104
+ }
105
+ return _searchParams;
106
+ }
107
+
108
+ /**
109
+ * @description automatically prepends '?' symbol
110
+ * @param {Object} params
111
+ * @returns {string}
112
+ */
113
+ }, {
114
+ key: "transferSearchTo",
115
+ value:
116
+ /**
117
+ * @param {string} href
118
+ * @returns {string}
119
+ */
120
+ function transferSearchTo(href) {
121
+ var newLink = document.createElement('a');
122
+ newLink.href = href;
123
+ newLink.search = this._link.search;
124
+ return newLink.href;
125
+ }
126
+
127
+ /**
128
+ * @description duplicates are replaced by the newer params
129
+ * @param {Object} params
130
+ * @returns {string} returns href
131
+ */
132
+ }, {
133
+ key: "appendSearchParams",
134
+ value: function appendSearchParams(params) {
135
+ var _paramsParams = _objectSpread(_objectSpread(_objectSpread({}, this.searchParams), params), this.wrapEncodeUrl ? {
136
+ ci_url_encoded: 1
137
+ } : {});
138
+ var newLink = document.createElement('a');
139
+ newLink.href = this._link.href;
140
+ newLink.search = LinkHelper.stringifySearchParams(_paramsParams);
141
+ return newLink.href;
142
+ }
143
+ }], [{
144
+ key: "stringifySearchParams",
145
+ value: function stringifySearchParams(params) {
146
+ var _paramKeys = Object.keys(params).map(function (key) {
147
+ return "".concat(key, "=").concat(params[key]);
148
+ });
149
+ return _paramKeys.length > 0 ? "?".concat(_paramKeys.join('&')) : '';
150
+ }
151
+ }]);
152
+ }();
153
+ export default LinkHelper;
@@ -0,0 +1,30 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
3
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
4
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
5
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
6
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
7
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
8
+ function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
9
+ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
10
+ function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
11
+ function _wrapNativeSuper(t) { var r = "function" == typeof Map ? new Map() : void 0; return _wrapNativeSuper = function _wrapNativeSuper(t) { if (null === t || !_isNativeFunction(t)) return t; if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function"); if (void 0 !== r) { if (r.has(t)) return r.get(t); r.set(t, Wrapper); } function Wrapper() { return _construct(t, arguments, _getPrototypeOf(this).constructor); } return Wrapper.prototype = Object.create(t.prototype, { constructor: { value: Wrapper, enumerable: !1, writable: !0, configurable: !0 } }), _setPrototypeOf(Wrapper, t); }, _wrapNativeSuper(t); }
12
+ function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; }
13
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
14
+ function _isNativeFunction(t) { try { return -1 !== Function.toString.call(t).indexOf("[native code]"); } catch (n) { return "function" == typeof t; } }
15
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
16
+ function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
17
+ var NetworkError = /*#__PURE__*/function (_Error) {
18
+ function NetworkError(error) {
19
+ var _this;
20
+ var xhr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
21
+ _classCallCheck(this, NetworkError);
22
+ _this = _callSuper(this, NetworkError, ["This looks like a network error, the endpoint might be blocked by an internet provider or a firewall.\n\nSource error: [".concat(error, "]")]);
23
+ _this.isNetworkError = true;
24
+ _this.request = xhr;
25
+ return _this;
26
+ }
27
+ _inherits(NetworkError, _Error);
28
+ return _createClass(NetworkError);
29
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
30
+ export default NetworkError;
@@ -0,0 +1,45 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
3
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
4
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ /**
8
+ * Helper to abort upload requests if there has not been any progress for `timeout` ms.
9
+ * Create an instance using `timer = new ProgressTimeout(10000, onTimeout)`
10
+ * Call `timer.progress()` to signal that there has been progress of any kind.
11
+ * Call `timer.done()` when the upload has completed.
12
+ */
13
+ var ProgressTimeout = /*#__PURE__*/function () {
14
+ function ProgressTimeout(timeout, timeoutHandler) {
15
+ _classCallCheck(this, ProgressTimeout);
16
+ this._timeout = timeout;
17
+ this._onTimedOut = timeoutHandler;
18
+ this._isDone = false;
19
+ this._aliveTimer = null;
20
+ this._onTimedOut = this._onTimedOut.bind(this);
21
+ }
22
+ return _createClass(ProgressTimeout, [{
23
+ key: "progress",
24
+ value: function progress() {
25
+ // Some browsers fire another progress event when the upload is
26
+ // cancelled, so we have to ignore progress after the timer was
27
+ // told to stop.
28
+ if (this._isDone) return;
29
+ if (this._timeout > 0) {
30
+ if (this._aliveTimer) clearTimeout(this._aliveTimer);
31
+ this._aliveTimer = setTimeout(this._onTimedOut, this._timeout);
32
+ }
33
+ }
34
+ }, {
35
+ key: "done",
36
+ value: function done() {
37
+ if (this._aliveTimer) {
38
+ clearTimeout(this._aliveTimer);
39
+ this._aliveTimer = null;
40
+ }
41
+ this._isDone = true;
42
+ }
43
+ }]);
44
+ }();
45
+ export default ProgressTimeout;
@@ -0,0 +1,197 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
3
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
4
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ /**
8
+ * Array.prototype.findIndex ponyfill for old browsers.
9
+ */
10
+ function findIndex(array, predicate) {
11
+ for (var i = 0; i < array.length; i++) {
12
+ if (predicate(array[i])) return i;
13
+ }
14
+ return -1;
15
+ }
16
+ function createCancelError() {
17
+ return new Error('Cancelled');
18
+ }
19
+ var RateLimitedQueue = /*#__PURE__*/function () {
20
+ function RateLimitedQueue(limit) {
21
+ _classCallCheck(this, RateLimitedQueue);
22
+ if (typeof limit !== 'number' || limit === 0) {
23
+ this.limit = Infinity;
24
+ } else {
25
+ this.limit = limit;
26
+ }
27
+ this.activeRequests = 0;
28
+ // eslint-disable-next-line no-unused-expressions
29
+ this.pauseTimer;
30
+ this.queuedHandlers = [];
31
+ this.paused = false;
32
+ }
33
+ return _createClass(RateLimitedQueue, [{
34
+ key: "_call",
35
+ value: function _call(fn) {
36
+ var _this = this;
37
+ this.activeRequests += 1;
38
+ var _done = false;
39
+ var cancelActive;
40
+ try {
41
+ cancelActive = fn();
42
+ } catch (err) {
43
+ this.activeRequests -= 1;
44
+ throw err;
45
+ }
46
+ return {
47
+ abort: function abort() {
48
+ if (_done) return;
49
+ _done = true;
50
+ _this.activeRequests -= 1;
51
+ cancelActive();
52
+ _this._queueNext();
53
+ },
54
+ done: function done() {
55
+ if (_done) return;
56
+ _done = true;
57
+ _this.activeRequests -= 1;
58
+ _this._queueNext();
59
+ }
60
+ };
61
+ }
62
+ }, {
63
+ key: "_queueNext",
64
+ value: function _queueNext() {
65
+ var _this2 = this;
66
+ // Do it soon but not immediately, this allows clearing out the entire queue synchronously
67
+ // one by one without continuously _advancing_ it (and starting new tasks before immediately
68
+ // aborting them)
69
+ Promise.resolve().then(function () {
70
+ _this2._next();
71
+ });
72
+ }
73
+ }, {
74
+ key: "_next",
75
+ value: function _next() {
76
+ if (this.paused || this.activeRequests >= this.limit) {
77
+ return;
78
+ }
79
+ if (this.queuedHandlers.length === 0) {
80
+ return;
81
+ }
82
+
83
+ // Dispatch the next request, and update the abort/done handlers
84
+ // so that cancelling it does the Right Thing (and doesn't just try
85
+ // to dequeue an already-running request).
86
+ var next = this.queuedHandlers.shift();
87
+ var handler = this._call(next.fn);
88
+ next.abort = handler.abort;
89
+ next.done = handler.done;
90
+ }
91
+ }, {
92
+ key: "_queue",
93
+ value: function _queue(fn) {
94
+ var _this3 = this;
95
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
96
+ var handler = {
97
+ fn: fn,
98
+ priority: options.priority || 0,
99
+ abort: function abort() {
100
+ _this3._dequeue(handler);
101
+ },
102
+ done: function done() {
103
+ throw new Error('Cannot mark a queued request as done: this indicates a bug');
104
+ }
105
+ };
106
+ var index = findIndex(this.queuedHandlers, function (other) {
107
+ return handler.priority > other.priority;
108
+ });
109
+ if (index === -1) {
110
+ this.queuedHandlers.push(handler);
111
+ } else {
112
+ this.queuedHandlers.splice(index, 0, handler);
113
+ }
114
+ return handler;
115
+ }
116
+ }, {
117
+ key: "_dequeue",
118
+ value: function _dequeue(handler) {
119
+ var index = this.queuedHandlers.indexOf(handler);
120
+ if (index !== -1) {
121
+ this.queuedHandlers.splice(index, 1);
122
+ }
123
+ }
124
+ }, {
125
+ key: "run",
126
+ value: function run(fn, queueOptions) {
127
+ if (!this.paused && this.activeRequests < this.limit) {
128
+ return this._call(fn);
129
+ }
130
+ return this._queue(fn, queueOptions);
131
+ }
132
+ }, {
133
+ key: "wrapPromiseFunction",
134
+ value: function wrapPromiseFunction(fn, queueOptions) {
135
+ var _this4 = this;
136
+ return function () {
137
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
138
+ args[_key] = arguments[_key];
139
+ }
140
+ var queuedRequest;
141
+ var outerPromise = new Promise(function (resolve, reject) {
142
+ queuedRequest = _this4.run(function () {
143
+ var cancelError;
144
+ var innerPromise;
145
+ try {
146
+ innerPromise = Promise.resolve(fn.apply(void 0, args));
147
+ } catch (err) {
148
+ innerPromise = Promise.reject(err);
149
+ }
150
+ innerPromise.then(function (result) {
151
+ if (cancelError) {
152
+ reject(cancelError);
153
+ } else {
154
+ queuedRequest.done();
155
+ resolve(result);
156
+ }
157
+ }, function (err) {
158
+ if (cancelError) {
159
+ reject(cancelError);
160
+ } else {
161
+ queuedRequest.done();
162
+ reject(err);
163
+ }
164
+ });
165
+ return function () {
166
+ cancelError = createCancelError();
167
+ };
168
+ }, queueOptions);
169
+ });
170
+ outerPromise.abort = function () {
171
+ queuedRequest.abort();
172
+ };
173
+ return outerPromise;
174
+ };
175
+ }
176
+ }, {
177
+ key: "resume",
178
+ value: function resume() {
179
+ this.paused = false;
180
+ clearTimeout(this.pauseTimer);
181
+ for (var i = 0; i < this.limit; i++) {
182
+ this._queueNext();
183
+ }
184
+ }
185
+ }, {
186
+ key: "pause",
187
+ value: function pause() {
188
+ var duration = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
189
+ this.paused = true;
190
+ clearTimeout(this.pauseTimer);
191
+ if (duration != null) {
192
+ this.pauseTimer = setTimeout(this.resume, duration);
193
+ }
194
+ }
195
+ }]);
196
+ }();
197
+ export { RateLimitedQueue as default };
@@ -0,0 +1,38 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
3
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
4
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
5
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
6
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
7
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
8
+ function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
9
+ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
10
+ function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
11
+ function _wrapNativeSuper(t) { var r = "function" == typeof Map ? new Map() : void 0; return _wrapNativeSuper = function _wrapNativeSuper(t) { if (null === t || !_isNativeFunction(t)) return t; if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function"); if (void 0 !== r) { if (r.has(t)) return r.get(t); r.set(t, Wrapper); } function Wrapper() { return _construct(t, arguments, _getPrototypeOf(this).constructor); } return Wrapper.prototype = Object.create(t.prototype, { constructor: { value: Wrapper, enumerable: !1, writable: !0, configurable: !0 } }), _setPrototypeOf(Wrapper, t); }, _wrapNativeSuper(t); }
12
+ function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; }
13
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
14
+ function _isNativeFunction(t) { try { return -1 !== Function.toString.call(t).indexOf("[native code]"); } catch (n) { return "function" == typeof t; } }
15
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
16
+ function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
17
+ var RequestError = /*#__PURE__*/function (_Error) {
18
+ function RequestError(_ref) {
19
+ var _this;
20
+ var code = _ref.code,
21
+ codeLabel = _ref.codeLabel,
22
+ message = _ref.message,
23
+ details = _ref.details,
24
+ response = _ref.response;
25
+ _classCallCheck(this, RequestError);
26
+ _this = _callSuper(this, RequestError, [message]);
27
+ _this.name = "Request Error (".concat(code, ")");
28
+ _this.code = code;
29
+ _this.message = message;
30
+ _this.details = details;
31
+ _this.codeLabel = codeLabel;
32
+ _this.response = response;
33
+ return _this;
34
+ }
35
+ _inherits(RequestError, _Error);
36
+ return _createClass(RequestError);
37
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
38
+ export default RequestError;
@@ -0,0 +1,113 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
3
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
5
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
6
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
7
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
8
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
9
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
11
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
12
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
13
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
14
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
15
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
16
+ import { I18N_GRID_UUID, I18N_PROD_BASE_URL } from '@scaleflex/widget-utils/lib/constants';
17
+
18
+ /**
19
+ * Class to console log all missing translation keys and generate curl for convenience.
20
+ *
21
+ * How to use?
22
+ * - Create instance for your project:
23
+ * const missingKeysConsoleHelper = new TranslationMissingKeysConsoleHelper({ name, gridUuid, ... })
24
+ * > Notice! Each project should have only one instance of the class (e.g one instance for Hub and one more for Widget)
25
+ * - Run method handleMissingKey each time when missing key detected:
26
+ * missingKeysConsoleHelper.handleMissingKey(key, valueOrDefault)
27
+ * - Enable console helper by adding localStorage prop "translationMissingKeysConsoleHelperEnabled"=true OR by enabled config
28
+ * As the result you should see all missing keys in browser console with generated cURL for convenience.
29
+ *
30
+ * IMPORTANT! For any updates in the class need to sync and double check Hub project as well!
31
+ */
32
+ var TranslationMissingKeysConsoleHelper = /*#__PURE__*/function () {
33
+ function TranslationMissingKeysConsoleHelper() {
34
+ var _this = this;
35
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
36
+ name = _ref.name,
37
+ baseApiUrl = _ref.baseApiUrl,
38
+ gridUuid = _ref.gridUuid,
39
+ debounceDelay = _ref.debounceDelay,
40
+ _ref$consoleGroupColl = _ref.consoleGroupCollapsed,
41
+ consoleGroupCollapsed = _ref$consoleGroupColl === void 0 ? false : _ref$consoleGroupColl,
42
+ _ref$enabled = _ref.enabled,
43
+ enabled = _ref$enabled === void 0 ? localStorage.getItem('translationMissingKeysConsoleHelperEnabled') === 'true' : _ref$enabled;
44
+ _classCallCheck(this, TranslationMissingKeysConsoleHelper);
45
+ _defineProperty(this, "name", 'WIDGET');
46
+ // Name is used in logs titles. Useful when class is used for multiple projects (e.g. Hub and Widget)
47
+ _defineProperty(this, "baseApiUrl", I18N_PROD_BASE_URL);
48
+ _defineProperty(this, "gridUuid", I18N_GRID_UUID);
49
+ _defineProperty(this, "debounceDelay", 2000);
50
+ // Delay to not console log too often
51
+ _defineProperty(this, "consoleGroupCollapsed", false);
52
+ _defineProperty(this, "enabled", false);
53
+ _defineProperty(this, "_missingKeys", {});
54
+ _defineProperty(this, "_timer", null);
55
+ if (name) {
56
+ this.name = name;
57
+ }
58
+ if (baseApiUrl) {
59
+ this.baseApiUrl = baseApiUrl;
60
+ }
61
+ if (gridUuid) {
62
+ this.gridUuid = gridUuid;
63
+ }
64
+ if (debounceDelay) {
65
+ this.debounceDelay = debounceDelay;
66
+ }
67
+ if (enabled === true) {
68
+ this.enabled = true;
69
+ console.log("%cTranslationMissingKeysConsoleHelper enabled for ".concat(this.name), 'font-weight:600;');
70
+ }
71
+ this.consoleGroupCollapsed = consoleGroupCollapsed;
72
+ this.renderCurl = this.renderCurl.bind(this);
73
+ this._missingKeys = new Proxy(this._missingKeys, {
74
+ set: function set(target, propName, value, receiver) {
75
+ if (_this._timer) {
76
+ clearTimeout(_this._timer);
77
+ }
78
+ _this._timer = setTimeout(_this.renderCurl, _this.debounceDelay);
79
+ return Reflect.set(target, propName, value, receiver);
80
+ }
81
+ });
82
+ }
83
+ return _createClass(TranslationMissingKeysConsoleHelper, [{
84
+ key: "renderCurl",
85
+ value: function renderCurl() {
86
+ console[this.consoleGroupCollapsed ? 'groupCollapsed' : 'group']("[".concat(this.name, "] Translations missing keys group"));
87
+ console.log("%c[".concat(this.name, "] Missing keys"), 'font-weight:600;font-size:200%;');
88
+ console.table(_objectSpread({}, this._missingKeys));
89
+ console.log('%ccURL (check carefully data before send):', 'font-weight:600;font-size:150%;');
90
+ console.log("\ncurl '".concat(this.baseApiUrl, "/api/import/request-translations?grid_uuid=").concat(this.gridUuid, "' \\\n --data-raw '{\"grid_uuid\":\"").concat(this.gridUuid, "\",\"translations_requests\":").concat(JSON.stringify(Object.entries(this._missingKeys).map(function (_ref2) {
91
+ var _ref3 = _slicedToArray(_ref2, 2),
92
+ key = _ref3[0],
93
+ value = _ref3[1];
94
+ return {
95
+ key: key,
96
+ lang: 'en',
97
+ "default": value
98
+ };
99
+ })).replaceAll("'", "'\\''"), "}'\n "));
100
+ console.groupEnd();
101
+ }
102
+ }, {
103
+ key: "handleMissingKey",
104
+ value: function handleMissingKey(key) {
105
+ var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
106
+ if (!this.enabled) {
107
+ return;
108
+ }
109
+ this._missingKeys[key] = value;
110
+ }
111
+ }]);
112
+ }();
113
+ export { TranslationMissingKeysConsoleHelper as default };