@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,200 @@
1
+ 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; }
2
+ 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; }
3
+ 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); }
4
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
5
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
6
+ 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); } }
7
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
8
+ 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; }
9
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
10
+ 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); }
11
+ import has from './hasProperty';
12
+ // import { sendMissingTranslationToBackend } from './i18n.client'
13
+ import TranslationMissingKeysConsoleHelper from './TranslationMissingKeysConsoleHelper';
14
+
15
+ /**
16
+ * Translates strings with interpolation & pluralization support.
17
+ * Extensible with custom dictionaries and pluralization functions.
18
+ *
19
+ * Borrows heavily from and inspired by Polyglot https://github.com/airbnb/polyglot.js,
20
+ * basically a stripped-down version of it. Differences: pluralization functions are not hardcoded
21
+ * and can be easily added among with dictionaries, nested objects are used for pluralization
22
+ * as opposed to `||||` delimeter
23
+ *
24
+ * Usage example: `translator.translate('files_chosen', {smart_count: 3})`
25
+ */
26
+
27
+ var sentKeys = {};
28
+ var missingKeysConsoleHelper = new TranslationMissingKeysConsoleHelper();
29
+ var Translator = /*#__PURE__*/function () {
30
+ /**
31
+ * @param {object|Array<object>} locales - locale or list of locales.
32
+ */
33
+ function Translator(locales) {
34
+ var _this = this;
35
+ _classCallCheck(this, Translator);
36
+ this.locale = {
37
+ strings: {},
38
+ pluralize: function pluralize(n) {
39
+ if (n === 1) {
40
+ return 0;
41
+ }
42
+ return 1;
43
+ }
44
+ };
45
+ if (Array.isArray(locales)) {
46
+ locales.forEach(function (locale) {
47
+ return _this._apply(locale);
48
+ });
49
+ } else {
50
+ this._apply(locales);
51
+ }
52
+ }
53
+ return _createClass(Translator, [{
54
+ key: "_apply",
55
+ value: function _apply(locale) {
56
+ if (!locale || !locale.strings) {
57
+ return;
58
+ }
59
+ var prevLocale = this.locale;
60
+ var keysHaveTranslations = Object.keys(locale.strings).filter(function (k) {
61
+ return locale.strings[k];
62
+ });
63
+ var preparedLocaleStrings = {};
64
+ keysHaveTranslations.forEach(function (k) {
65
+ preparedLocaleStrings[k] = locale.strings[k];
66
+ });
67
+ this.locale = _extends({}, prevLocale, {
68
+ strings: _extends({}, prevLocale.strings, preparedLocaleStrings)
69
+ });
70
+ this.locale.pluralize = locale.pluralize || prevLocale.pluralize;
71
+ }
72
+
73
+ /**
74
+ * Takes a string with placeholder variables like `%{smart_count} file selected`
75
+ * and replaces it with values from options `{smart_count: 5}`
76
+ *
77
+ * @license https://github.com/airbnb/polyglot.js/blob/master/LICENSE
78
+ * taken from https://github.com/airbnb/polyglot.js/blob/master/lib/polyglot.js#L299
79
+ *
80
+ * @param {string} phrase that needs interpolation, with placeholders
81
+ * @param {object} options with values that will be used to replace placeholders
82
+ * @returns {string} interpolated
83
+ */
84
+ }, {
85
+ key: "interpolate",
86
+ value: function interpolate(phrase, options) {
87
+ var split = String.prototype.split;
88
+ var interpolated = [phrase];
89
+ for (var arg in options) {
90
+ if (arg !== '_' && has(options, arg)) {
91
+ var replacement = options[arg];
92
+ // We create a new `RegExp` each time instead of using a more-efficient
93
+ // string replace so that the same argument can be replaced multiple times
94
+ // in the same phrase.
95
+ interpolated = insertReplacement(interpolated, new RegExp('%\\{' + arg + '\\}', 'g'), replacement);
96
+ }
97
+ }
98
+ return interpolated;
99
+ function insertReplacement(source, rx, replacement) {
100
+ var newParts = [];
101
+ source.forEach(function (chunk) {
102
+ // When the source contains multiple placeholders for interpolation,
103
+ // we should ignore chunks that are not strings, because those
104
+ // can be JSX objects and will be otherwise incorrectly turned into strings.
105
+ // Without this condition we’d get this: [object Object] hello [object Object] my <button>
106
+ if (typeof chunk !== 'string') {
107
+ return newParts.push(chunk);
108
+ }
109
+ split.call(chunk, rx).forEach(function (raw, i, list) {
110
+ if (raw !== '') {
111
+ newParts.push(raw);
112
+ }
113
+
114
+ // Interlace with the `replacement` value
115
+ if (i < list.length - 1) {
116
+ newParts.push(replacement);
117
+ }
118
+ });
119
+ });
120
+ return newParts;
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Public translate method
126
+ *
127
+ * @param {string} key
128
+ * @param {object} options with values that will be used later to replace placeholders in string
129
+ * @returns {string} translated (and interpolated)
130
+ */
131
+ }, {
132
+ key: "translate",
133
+ value: function translate(key, options) {
134
+ var _this$translateArray;
135
+ return (_this$translateArray = this.translateArray(key, options)) === null || _this$translateArray === void 0 ? void 0 : _this$translateArray.join('');
136
+ }
137
+
138
+ /**
139
+ * Get a translation and return the translated and interpolated parts as an array.
140
+ *
141
+ * @param {string} key
142
+ * @param {object} options with values that will be used to replace placeholders or default string value if key doesn't have value
143
+ * - string => used as default value
144
+ * - object => uses the `default` property as the translation default value and others for placeholder.
145
+ * @returns {Array} The translated and interpolated parts, in order.
146
+ */
147
+ }, {
148
+ key: "translateArray",
149
+ value: function translateArray(key, options) {
150
+ if (!Translator.BACKEND_TRANSLATIONS) {
151
+ return [];
152
+ }
153
+ // JSON.parse() for handling the plural case that's being received from backend as string.
154
+ try {
155
+ var _this$locale$strings$, _this$locale$strings$2, _options$default;
156
+ var value = (_this$locale$strings$ = this.locale.strings[key]) !== null && _this$locale$strings$ !== void 0 && (_this$locale$strings$2 = _this$locale$strings$.startsWith) !== null && _this$locale$strings$2 !== void 0 && _this$locale$strings$2.call(_this$locale$strings$, '{"') ? JSON.parse(this.locale.strings[key]) : this.locale.strings[key];
157
+ var valueOrDefault = !value && typeof options === 'string' ? options : (_options$default = options === null || options === void 0 ? void 0 : options["default"]) !== null && _options$default !== void 0 ? _options$default : value || '';
158
+ var hasPluralForms = _typeof(value) === 'object';
159
+
160
+ // For sending to the backend the missing translation keys
161
+ if (key && Translator.BACKEND_TRANSLATIONS && !Translator.BACKEND_TRANSLATIONS[key] && !sentKeys[key]) {
162
+ var valueOrDefaultWithStrPlural = hasPluralForms ? JSON.stringify(valueOrDefault) : valueOrDefault;
163
+
164
+ /**
165
+ * Auto translations disabled. Should be used manual creation instead of that.
166
+ * As a helper could be used "Missing keys Console Helper" -- https://scaleflexhq.atlassian.net/wiki/spaces/FIL/pages/594444447/Hub+Widget+projects+translations#Missing-keys-Console-Helper
167
+ */
168
+ // if (!Translator.IS_DEV) {
169
+ // sendMissingTranslationToBackend({
170
+ // key,
171
+ // fallBackLang: 'en',
172
+ // lang: 'en',
173
+ // default: valueOrDefaultWithStrPlural
174
+ // })
175
+ // }
176
+
177
+ missingKeysConsoleHelper.handleMissingKey(key, valueOrDefaultWithStrPlural);
178
+ sentKeys[key] = true;
179
+ Translator.BACKEND_TRANSLATIONS = _objectSpread(_objectSpread({}, Translator.BACKEND_TRANSLATIONS), {}, _defineProperty({}, key, valueOrDefault));
180
+ }
181
+ if (hasPluralForms) {
182
+ if (options && _typeof(options) === 'object' && typeof options.smart_count !== 'undefined') {
183
+ var plural = this.locale.pluralize(options.smart_count);
184
+ return this.interpolate(value[plural], options);
185
+ } else {
186
+ throw new Error('Attempted to use a string with plural forms, but no value was given for %{smart_count}');
187
+ }
188
+ }
189
+ return this.interpolate(value, options);
190
+ } catch (err) {}
191
+ }
192
+ }]);
193
+ }();
194
+ // For saving the backend translations retrieved from core.
195
+ _defineProperty(Translator, "BACKEND_TRANSLATIONS", null);
196
+ // For saving the current environment of the project, determined from core.
197
+ _defineProperty(Translator, "IS_DEV", true);
198
+ // For knowing the current used language incase some missing key is faced then send to the backend in right lang.
199
+ _defineProperty(Translator, "LANGUAGE", 'en');
200
+ export { Translator as default };
@@ -0,0 +1,13 @@
1
+ export default (function (link, imageParams) {
2
+ var separator = link !== null && link !== void 0 && link.includes('?') ? '&' : '?';
3
+ var params = Object.keys(imageParams).filter(function (key) {
4
+ return imageParams[key] !== 'auto';
5
+ }).filter(function (key) {
6
+ return imageParams[key];
7
+ }).map(function (key) {
8
+ return "".concat(key, "=").concat(imageParams[key]);
9
+ }).join('&');
10
+ return Object.keys(imageParams).some(function (key) {
11
+ return imageParams[key] && imageParams[key] !== 'auto';
12
+ }) ? "".concat(link).concat(separator).concat(params) : link;
13
+ });
@@ -0,0 +1,66 @@
1
+ import { isStaticSelectOption } from '@scaleflex/widget-explorer/lib/utils/filters';
2
+ import { FILTER_CONDITIONS } from './constants';
3
+ import { getFieldValueQuery } from './fieldsQueriesGetters';
4
+ var createStaticValueIsQuery = function createStaticValueIsQuery(key, value) {
5
+ return "".concat(key, ":").concat(value.join(','));
6
+ };
7
+ var createIsQuery = function createIsQuery(key, value) {
8
+ if (isStaticSelectOption(value)) {
9
+ return createStaticValueIsQuery(key, value);
10
+ }
11
+ return "".concat(key, ":=").concat(value.join(','));
12
+ };
13
+ var createIsNotQuery = function createIsNotQuery(key, value) {
14
+ return value.map(function (item) {
15
+ return "".concat(key, ":-").concat(item);
16
+ }).join(' ');
17
+ };
18
+ var createContainsQuery = function createContainsQuery(metadataFilter, value) {
19
+ return getFieldValueQuery(metadataFilter, value);
20
+ };
21
+ var createContainsNotQuery = function createContainsNotQuery(_ref) {
22
+ var metadataFilter = _ref.metadataFilter,
23
+ key = _ref.key,
24
+ value = _ref.value,
25
+ extraValue = _ref.extraValue;
26
+ var valueQuery = getFieldValueQuery(metadataFilter, value);
27
+ var extraValueQuery = extraValue.map(function (item) {
28
+ return "".concat(key, ":-").concat(item);
29
+ }).join(' ');
30
+ return "".concat(valueQuery, " ").concat(extraValueQuery).trim();
31
+ };
32
+
33
+ /**
34
+ * Generates a multi-select field query based on the metadata filter.
35
+ * Docs: https://scaleflexhq.atlassian.net/wiki/spaces/FIL/pages/466452497
36
+ *
37
+ * @param {Object} metadataFilter - The metadata filter object.
38
+ * @returns {string} - The resulting query string.
39
+ */
40
+
41
+ export var getMetadataMultiSelectQuery = function getMetadataMultiSelectQuery(metadataFilter) {
42
+ var key = metadataFilter.key,
43
+ _metadataFilter$value = metadataFilter.value,
44
+ value = _metadataFilter$value === void 0 ? [] : _metadataFilter$value,
45
+ _metadataFilter$condi = metadataFilter.condition,
46
+ condition = _metadataFilter$condi === void 0 ? FILTER_CONDITIONS.IS : _metadataFilter$condi,
47
+ _metadataFilter$extra = metadataFilter.extraValue,
48
+ extraValue = _metadataFilter$extra === void 0 ? [] : _metadataFilter$extra;
49
+ switch (condition) {
50
+ case FILTER_CONDITIONS.IS:
51
+ return createIsQuery(key, value);
52
+ case FILTER_CONDITIONS.IS_NOT:
53
+ return createIsNotQuery(key, value);
54
+ case FILTER_CONDITIONS.CONTAINS:
55
+ return createContainsQuery(metadataFilter, value.join(','));
56
+ case FILTER_CONDITIONS.CONTAINS_NOT:
57
+ return createContainsNotQuery({
58
+ metadataFilter: metadataFilter,
59
+ key: key,
60
+ value: value.join(','),
61
+ extraValue: extraValue
62
+ });
63
+ default:
64
+ return '';
65
+ }
66
+ };
@@ -0,0 +1,26 @@
1
+ var cachedNonce = null;
2
+
3
+ /**
4
+ * Resolves a CSP nonce for dynamically injected <style> and <script> elements.
5
+ *
6
+ * Resolution order:
7
+ * 1. An explicit nonce passed via the widget config (`coreProps.nonce`).
8
+ * 2. Auto-detected from `<meta property="csp-nonce" content="…">` in the host page.
9
+ *
10
+ * The auto-detected value is cached after the first lookup.
11
+ *
12
+ * @param {string} [explicitNonce] - Nonce provided explicitly through config.
13
+ * @returns {string|undefined} The resolved nonce, or undefined when none is available.
14
+ */
15
+ var getNonce = function getNonce(explicitNonce) {
16
+ if (explicitNonce) return explicitNonce;
17
+ if (cachedNonce !== null) return cachedNonce || undefined;
18
+ if (typeof document !== 'undefined') {
19
+ var meta = document.querySelector('meta[property="csp-nonce"]');
20
+ cachedNonce = meta ? meta.getAttribute('content') : '';
21
+ } else {
22
+ cachedNonce = '';
23
+ }
24
+ return cachedNonce || undefined;
25
+ };
26
+ export default getNonce;
@@ -0,0 +1,55 @@
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 _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; }
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
+ * Retrieves the value of a nested property from an object using a string key.
9
+ *
10
+ * @param {string} key - The string key representing the nested property.
11
+ * @param {object} item - The object from which to retrieve the nested property.
12
+ * @return {*} - The value of the nested property.
13
+ */
14
+ export var getItemKey = function getItemKey(key, item) {
15
+ if (key.includes('.')) {
16
+ var properties = key.split('.');
17
+ return properties.reduce(function (property, prop) {
18
+ return property[prop];
19
+ }, item);
20
+ } else {
21
+ return item[key];
22
+ }
23
+ };
24
+
25
+ /**
26
+ * Generates a normalized version of the given items array.
27
+ *
28
+ * @param {Array} items - The array of items to be normalized.
29
+ * @param {Object} options - options for the function, consists of the following.
30
+ * @param {Object} extraProps - (optional) Additional properties to add to each normalized item.
31
+ * @param {string} key - (optional) The key to use as the unique identifier for each item.
32
+ * @param {string} returnedKey - (optional) the key used in the function's returned's object.
33
+ * @return {Object} An object containing the normalized slices and an array of UUIDs.
34
+ */
35
+ var getNormalizedItems = function getNormalizedItems(items, options) {
36
+ var _ref = options || {},
37
+ _ref$extraProps = _ref.extraProps,
38
+ extraProps = _ref$extraProps === void 0 ? {} : _ref$extraProps,
39
+ _ref$key = _ref.key,
40
+ key = _ref$key === void 0 ? 'uuid' : _ref$key,
41
+ _ref$returnedKey = _ref.returnedKey,
42
+ returnedKey = _ref$returnedKey === void 0 ? 'uuids' : _ref$returnedKey;
43
+ var normalizedSlices = {};
44
+ var normalizedItemsUuids = [];
45
+ items.forEach(function (item) {
46
+ var itemKey = getItemKey(key, item);
47
+ var normalizedItem = _objectSpread(_objectSpread({}, item), extraProps);
48
+ normalizedSlices[itemKey] = normalizedItem;
49
+ normalizedItemsUuids.push(itemKey);
50
+ });
51
+ return _defineProperty({
52
+ normalizedSlices: normalizedSlices
53
+ }, returnedKey, normalizedItemsUuids);
54
+ };
55
+ export default getNormalizedItems;
@@ -0,0 +1,32 @@
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 _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; }
3
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
4
+ 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); }
5
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
6
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ 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; } }
8
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
9
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
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
+ var _getObjectsMutualProperties = function getObjectsMutualProperties() {
12
+ var arrayOfObjects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [{}];
13
+ return Array.isArray(arrayOfObjects) && (arrayOfObjects.length > 1 ? arrayOfObjects.reduce(function (prevObj, currObj) {
14
+ var commonObj = {};
15
+ Object.keys(prevObj).forEach(function (key) {
16
+ if (prevObj[key] && currObj[key]) {
17
+ if (prevObj[key] === currObj[key]) {
18
+ commonObj[key] = prevObj[key];
19
+ } else if (Array.isArray(prevObj[key]) && Array.isArray(currObj[key])) {
20
+ var mutualProps = _getObjectsMutualProperties([].concat(_toConsumableArray(prevObj[key]), _toConsumableArray(currObj[key])));
21
+ commonObj[key] = Object.keys(mutualProps).map(function (key) {
22
+ return _defineProperty({}, key, mutualProps[key]);
23
+ });
24
+ } else if (_typeof(prevObj[key]) === 'object' && _typeof(currObj[key]) === 'object') {
25
+ commonObj[key] = _getObjectsMutualProperties([prevObj[key], currObj[key]]);
26
+ }
27
+ }
28
+ });
29
+ return commonObj;
30
+ }) : arrayOfObjects[0] || {});
31
+ };
32
+ export default _getObjectsMutualProperties;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @returns {number} -- random number between min and max
3
+ *
4
+ * @param {number} min -- minimum number
5
+ * @param {number} max -- maximum number
6
+ */
7
+ var getRandomNumber = function getRandomNumber(min, max) {
8
+ min = Math.ceil(min);
9
+ max = Math.floor(max);
10
+ return Math.floor(Math.random() * (max - min) + min);
11
+ };
12
+ export default getRandomNumber;
@@ -0,0 +1,7 @@
1
+ export default function getSocketHost(url) {
2
+ // get the host domain
3
+ var regex = /^(?:https?:\/\/|\/\/)?(?:[^@\n]+@)?(?:www\.)?([^\n]+)/i;
4
+ var host = regex.exec(url)[1];
5
+ var socketProtocol = /^http:\/\//i.test(url) ? 'ws' : 'wss';
6
+ return "".concat(socketProtocol, "://").concat(host);
7
+ }
@@ -0,0 +1,8 @@
1
+ export default function getSpeed() {
2
+ var fileProgress = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
3
+ var totalFinished = fileProgress.bytesFinished || fileProgress.percentage;
4
+ var endTime = new Date().getTime();
5
+ var timeDuration = (endTime - fileProgress.startedAt) / 1000;
6
+ var uploadSpeedInBps = totalFinished / timeDuration;
7
+ return uploadSpeedInBps;
8
+ }
package/lib/getTime.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Returns a timestamp in the format of `hours:minutes Am or PM`
3
+ */
4
+
5
+ export default function getTime() {
6
+ var showAmPm = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
7
+ var i18n = arguments.length > 1 ? arguments[1] : undefined;
8
+ var date = new Date();
9
+ var hours = date.getHours();
10
+ var minutes = date.getMinutes();
11
+ var ampm = hours >= 12 ? (i18n === null || i18n === void 0 ? void 0 : i18n('mutualizedTimePeriodPm')) || 'PM' : (i18n === null || i18n === void 0 ? void 0 : i18n('mutualizedTimePeriodAm')) || 'AM';
12
+ hours = hours % 12;
13
+ hours = hours || 12; // the hour '0' should be '12'
14
+ hours = hours < 10 ? '0' + hours : hours;
15
+ minutes = minutes < 10 ? '0' + minutes : minutes;
16
+ var strTime = hours + ':' + minutes + (showAmPm ? ' ' + ampm : '');
17
+ return strTime;
18
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Returns a timestamp in the format of `hours:minutes:seconds`
3
+ */
4
+ export default function getTimeStamp() {
5
+ var noSeconds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
6
+ var date = new Date();
7
+ var hours = pad(date.getHours().toString());
8
+ var minutes = pad(date.getMinutes().toString());
9
+ var seconds = pad(date.getSeconds().toString());
10
+ return hours + ':' + minutes + (noSeconds ? ':' + seconds : '');
11
+ }
12
+
13
+ /**
14
+ * Adds zero to strings shorter than two characters
15
+ */
16
+ function pad(str) {
17
+ return str.length !== 2 ? 0 + str : str;
18
+ }
@@ -0,0 +1,13 @@
1
+ var handleError = function handleError(error, infoFn) {
2
+ var _ref;
3
+ if (!error || !infoFn) {
4
+ return;
5
+ }
6
+ var message = error.message,
7
+ details = error.details;
8
+ infoFn({
9
+ message: (_ref = message !== null && message !== void 0 ? message : error.status) !== null && _ref !== void 0 ? _ref : error.toString(),
10
+ details: details
11
+ }, 'error', 5000);
12
+ };
13
+ export default handleError;
@@ -0,0 +1,9 @@
1
+ var handlePressEnter = function handlePressEnter() {
2
+ var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
3
+ var callback = arguments.length > 1 ? arguments[1] : undefined;
4
+ if ((event.key === 'Enter' || event.keyCode === 13) && typeof callback === 'function') {
5
+ event.preventDefault();
6
+ callback();
7
+ }
8
+ };
9
+ export default handlePressEnter;
@@ -0,0 +1,39 @@
1
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
+ import isPromise from './isPromise';
3
+
4
+ /**
5
+ * Wraps the promise passed with try/catch block and fires the callback provided depending on success/failture.
6
+ *
7
+ * @param (promise: promise) - promise to be processed
8
+ * @param (successCallback: function) - callback function to be implemented incase of success
9
+ * @param (errorCallback: function) - callback function to be implemented incase of error caught
10
+ - assuming default clbk function would be info(error: error instance, type: error, timeout: 5000)
11
+ * @param (finishCallback: function) - callback function to be implemented after finishing in both cases success/fail.
12
+ */
13
+ var handlePromise = function handlePromise(promise) {
14
+ var successCallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
15
+ return null;
16
+ };
17
+ var errorCallback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {
18
+ return null;
19
+ };
20
+ var finishCallback = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : function () {
21
+ return null;
22
+ };
23
+ if (isPromise(promise)) {
24
+ // To throw the rejection of the promise to be able to use (.catch)
25
+ if (typeof promise.throwRejection === 'function') {
26
+ promise.throwRejection();
27
+ }
28
+ var newPromise = promise.then(successCallback)["catch"](function (error) {
29
+ if (typeof errorCallback === 'function') {
30
+ errorCallback(error, 'error', 5000);
31
+ }
32
+ })["finally"](finishCallback);
33
+
34
+ // To copy the properties of the original promise eg. if it's thunk function we will have (abort, requestId...etc.)
35
+ _extends(newPromise, promise);
36
+ return newPromise;
37
+ }
38
+ };
39
+ export default handlePromise;
@@ -0,0 +1,3 @@
1
+ export default function has(object, key) {
2
+ return Object.prototype.hasOwnProperty.call(object, key);
3
+ }
@@ -0,0 +1,15 @@
1
+ // Imported from https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb
2
+ var hexToRgb = function hexToRgb(hex) {
3
+ // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
4
+ var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
5
+ hex = hex.replace(shorthandRegex, function (m, r, g, b) {
6
+ return r + r + g + g + b + b;
7
+ });
8
+ var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
9
+ return result ? {
10
+ r: parseInt(result[1], 16),
11
+ g: parseInt(result[2], 16),
12
+ b: parseInt(result[3], 16)
13
+ } : {};
14
+ };
15
+ export default hexToRgb;
@@ -0,0 +1,6 @@
1
+ import DOMPurify from 'dompurify';
2
+ var htmlSanitizer = function htmlSanitizer() {
3
+ var html = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
4
+ return DOMPurify.sanitize(html);
5
+ };
6
+ export default htmlSanitizer;
@@ -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 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 _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; }
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
+ * @param {Date} date
9
+ * @param {object} [translations] - Object with translations. Notice: it's used for Hub.
10
+ * @returns {string} - For example: "18 hours ago"
11
+ */
12
+ var humanReadableDate = function humanReadableDate(date, translationsList) {
13
+ var translations = _objectSpread({
14
+ ago: 'ago',
15
+ second: 'second',
16
+ seconds: 'seconds',
17
+ minute: 'minute',
18
+ minutes: 'minutes',
19
+ hour: 'hour',
20
+ hours: 'hours',
21
+ day: 'day',
22
+ days: 'days',
23
+ month: 'month',
24
+ months: 'months',
25
+ year: 'year',
26
+ years: 'years'
27
+ }, translationsList || {});
28
+ var timeAgo = function timeAgo(interval, periodMultiple, periodSingle) {
29
+ return "".concat(Math.floor(interval), " ").concat(Math.floor(interval) > 1 ? periodMultiple : periodSingle, " ").concat(translations.ago);
30
+ };
31
+ var seconds = Math.floor((new Date() - new Date(date)) / 1000);
32
+ var interval = seconds / 31536000;
33
+ if (interval > 1) return timeAgo(interval, translations.years, translations.year);
34
+ interval = seconds / 2592000;
35
+ if (interval > 1) return timeAgo(interval, translations.months, translations.month);
36
+ interval = seconds / 86400;
37
+ if (interval > 1) return timeAgo(interval, translations.days, translations.day);
38
+ interval = seconds / 3600;
39
+ if (interval > 1) return timeAgo(interval, translations.hours, translations.hour);
40
+ interval = seconds / 60;
41
+ if (interval > 1) return timeAgo(interval, translations.minutes, translations.minute);
42
+ interval = seconds;
43
+ return timeAgo(interval, translations.seconds, translations.second);
44
+ };
45
+ export default humanReadableDate;
@@ -0,0 +1,29 @@
1
+ import capitalizeFirstLetter from './capitalizeFirstLetter';
2
+ import humanReadableDate from './humanReadableDate';
3
+
4
+ /**
5
+ * Wrapper over function humanReadableDate but with translations
6
+ */
7
+ var humanReadableDateWithTranslations = function humanReadableDateWithTranslations(date, i18n) {
8
+ var t = function t(str) {
9
+ return i18n("timeAgo".concat(str.split(' ').filter(Boolean).map(function (item) {
10
+ return capitalizeFirstLetter(item.trim());
11
+ }).join('')), str) || str;
12
+ };
13
+ return humanReadableDate(date, {
14
+ ago: t('ago'),
15
+ second: t('second'),
16
+ seconds: t('seconds'),
17
+ minute: t('minute'),
18
+ minutes: t('minutes'),
19
+ hour: t('hour'),
20
+ hours: t('hours'),
21
+ day: t('day'),
22
+ days: t('days'),
23
+ month: t('month'),
24
+ months: t('months'),
25
+ year: t('year'),
26
+ years: t('years')
27
+ });
28
+ };
29
+ export default humanReadableDateWithTranslations;