@scaleflex/widget-utils 4.4.0 → 4.5.1
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.
- package/CHANGELOG.md +16 -0
- package/lib/AbortController.js +20 -0
- package/lib/BlurHash/base83.js +10 -0
- package/lib/BlurHash/decode.js +80 -0
- package/lib/BlurHash/error.js +28 -0
- package/lib/BlurHash/utils.js +22 -0
- package/lib/CustomDate.js +157 -0
- package/lib/EventTracker.js +42 -0
- package/lib/FOCUSABLE_ELEMENTS.js +1 -0
- package/lib/LinkHelper.js +153 -0
- package/lib/NetworkError.js +30 -0
- package/lib/ProgressTimeout.js +45 -0
- package/lib/RateLimitedQueue.js +197 -0
- package/lib/RequestError.js +36 -0
- package/lib/Timeframes/getDateRange.js +45 -0
- package/lib/TranslationMissingKeysConsoleHelper.js +113 -0
- package/lib/Translator.js +200 -0
- package/lib/addUrlParams.js +27 -0
- package/lib/adjustUpdatedFolders.js +22 -0
- package/lib/asyncTimeout.js +6 -0
- package/lib/audioMimeTypes.js +3 -0
- package/lib/blobToDataURI.js +13 -0
- package/lib/callIfFunction.js +10 -0
- package/lib/canEditVideo.js +9 -0
- package/lib/canvasToBlob.js +18 -0
- package/lib/capitalizeFirstLetter.js +4 -0
- package/lib/checkConnection.js +4 -0
- package/lib/checkFileOrFolderNameValidation.js +4 -0
- package/lib/checkIfPngSvgGIF.js +3 -0
- package/lib/checkImageIfPngJpegOrWebpOrAvif.js +5 -0
- package/lib/checkItemsSupportExportWithReason.js +41 -0
- package/lib/checkPermissions.js +26 -0
- package/lib/cloudimageSupportedInputMimeTypes.js +2 -0
- package/lib/clsx.js +14 -0
- package/lib/constants.js +572 -0
- package/lib/convertBytesToMb.js +5 -0
- package/lib/convertGbToBytes.js +4 -0
- package/lib/convertVideoFileTypeToSupported.js +17 -0
- package/lib/copyText.js +25 -0
- package/lib/createFolderVirtualPath.js +14 -0
- package/lib/createThunk.js +349 -0
- package/lib/customEncodeURIComponent.js +47 -0
- package/lib/dataURItoBlob.js +33 -0
- package/lib/dataURItoFile.js +4 -0
- package/lib/dateStrToClearDateTime.js +20 -0
- package/lib/debounce.js +14 -0
- package/lib/deepEqual.js +23 -0
- package/lib/deepMerge.js +56 -0
- package/lib/deserializeFunction.js +5 -0
- package/lib/documentMimeTypes.js +2 -0
- package/lib/downloadFromBlob.js +16 -0
- package/lib/emitSocketProgress.js +18 -0
- package/lib/escapeRegExp.js +4 -0
- package/lib/extractFileDataNoBlob.js +12 -0
- package/lib/fetchWithNetworkError.js +14 -0
- package/lib/fieldsQueriesGetters.js +46 -0
- package/lib/findAllDOMElements.js +18 -0
- package/lib/findAllRegexMatchesInString.js +16 -0
- package/lib/findDOMElement.js +17 -0
- package/lib/findIndex.js +9 -0
- package/lib/formatDuration.js +22 -0
- package/lib/formatNumbers.js +32 -0
- package/lib/formatResolution.js +17 -0
- package/lib/formatSeconds.js +14 -0
- package/lib/generateFileId.js +53 -0
- package/lib/generateI18nKeyFromString.js +11 -0
- package/lib/generatePsdThumbnail/adaptHexBoundries.js +9 -0
- package/lib/generatePsdThumbnail/bufferToHex.js +12 -0
- package/lib/generatePsdThumbnail/generatePsdThumbnail.js +36 -0
- package/lib/generatePsdThumbnail/generatePsdThumbnailBytes.js +8 -0
- package/lib/generatePsdThumbnail/generatePsdThumbnailHex.js +4 -0
- package/lib/generateSelectInputPlaceholder.js +24 -0
- package/lib/getActionErrorState.js +17 -0
- package/lib/getArraysMutualObjects.js +12 -0
- package/lib/getBytesRemaining.js +9 -0
- package/lib/getClientTimezone.js +5 -0
- package/lib/getCloudimagePrefixedUrl.js +23 -0
- package/lib/getDateDaysFromNow.js +17 -0
- package/lib/getDateMinusDay.js +5 -0
- package/lib/getDateString.js +20 -0
- package/lib/getDaysLeft.js +9 -0
- package/lib/getDecodedUriComponent.js +10 -0
- package/lib/getDownloadSpeed.js +7 -0
- package/lib/getDroppedFiles/index.js +24 -0
- package/lib/getDroppedFiles/utils/fallbackApi.js +7 -0
- package/lib/getDroppedFiles/utils/webkitGetAsEntryApi/getFilesAndDirectoriesFromDirectory.js +36 -0
- package/lib/getDroppedFiles/utils/webkitGetAsEntryApi/getRelativePath.js +16 -0
- package/lib/getDroppedFiles/utils/webkitGetAsEntryApi/index.js +57 -0
- package/lib/getEncodedWrappedUrl.js +7 -0
- package/lib/getFileAssetsTokenUrl.js +14 -0
- package/lib/getFileCdnLink.js +6 -0
- package/lib/getFileDefaultIcon.js +14 -0
- package/lib/getFileDetails.js +81 -0
- package/lib/getFileExtension.js +32 -0
- package/lib/getFileLink.js +17 -0
- package/lib/getFileNameAndExtension.js +22 -0
- package/lib/getFileType.js +23 -0
- package/lib/getFileTypeExtension.js +22 -0
- package/lib/getFilterFileFormatIcon.js +6 -0
- package/lib/getFolderDetails.js +30 -0
- package/lib/getFormattedPreviewUrl.js +79 -0
- package/lib/getHoursAndMinutes.js +9 -0
- package/lib/getImageEditUrl.js +36 -0
- package/lib/getImgFileDimensions.js +25 -0
- package/lib/getItemIcon.js +112 -0
- package/lib/getItemPath.js +10 -0
- package/lib/getItemPreviewWidthHeight.js +10 -0
- package/lib/getItemsSizeInBytes.js +12 -0
- package/lib/getJsonParsedValue.js +11 -0
- package/lib/getLinkWithNewParams.js +13 -0
- package/lib/getMetadataMultiSelectQuery.js +66 -0
- package/lib/getNormalizedItems.js +55 -0
- package/lib/getObjectsMutualProperties.js +32 -0
- package/lib/getRandomNumber.js +12 -0
- package/lib/getSocketHost.js +7 -0
- package/lib/getSpeed.js +8 -0
- package/lib/getTime.js +18 -0
- package/lib/getTimeStamp.js +18 -0
- package/lib/handleError.js +13 -0
- package/lib/handlePressEnter.js +9 -0
- package/lib/handlePromise.js +39 -0
- package/lib/hasProperty.js +3 -0
- package/lib/hexToRgb.js +15 -0
- package/lib/htmlSanitizer.js +6 -0
- package/lib/humanReadableDate.js +45 -0
- package/lib/humanReadableDateWithTranslations.js +29 -0
- package/lib/i18n.client.js +54 -0
- package/lib/ignoreEvent.js +10 -0
- package/lib/index.js +0 -0
- package/lib/injectVirtualPathToFolders.js +24 -0
- package/lib/isAi.js +7 -0
- package/lib/isArchive.js +12 -0
- package/lib/isAudio.js +9 -0
- package/lib/isAudioAndSupportsPlayback.js +10 -0
- package/lib/isCloudimageFastPreviewSupported.js +16 -0
- package/lib/isDOMElement.js +9 -0
- package/lib/isDocument.js +10 -0
- package/lib/isDragDropSupported.js +20 -0
- package/lib/isEmptyObject.js +4 -0
- package/lib/isEps.js +8 -0
- package/lib/isFile.js +5 -0
- package/lib/isFileSupportedByCloudimage.js +14 -0
- package/lib/isFolder.js +4 -0
- package/lib/isFontFile.js +9 -0
- package/lib/isFunction.js +4 -0
- package/lib/isImage.js +11 -0
- package/lib/isJpg.js +8 -0
- package/lib/isMobileDevice.js +12 -0
- package/lib/isNetworkError.js +7 -0
- package/lib/isNumber.js +4 -0
- package/lib/isObjectType.js +5 -0
- package/lib/isObjectURL.js +10 -0
- package/lib/isOpenedFromAdobe.js +3 -0
- package/lib/isOtf.js +10 -0
- package/lib/isPdf.js +9 -0
- package/lib/isPhotoshopFile.js +8 -0
- package/lib/isPreviewSupported.js +12 -0
- package/lib/isPromise.js +5 -0
- package/lib/metadata/checkFieldValidation.js +51 -0
- package/lib/metadata/generateItemMetadataState.js +63 -0
- package/lib/metadata/generateMetadataDefaultState.js +30 -0
- package/lib/metadata/getFileCustomMetadataGroups.js +23 -0
- package/lib/metadata/getGeoPointValidationErrors.js +32 -0
- package/lib/metadata/getMetaAttachmentFields.js +9 -0
- package/lib/metadata/getMetadataEmptyAssets.js +28 -0
- package/lib/metadata/getMetadataFieldGeoPointValue.js +42 -0
- package/lib/metadata/getMetadataFieldVariantValue.js +31 -0
- package/lib/metadata/getMetadataGroups.js +16 -0
- package/lib/metadata/getRequiredMetadataFields.js +13 -0
- package/lib/metadata/isM0LegacyMetaVersion.js +5 -0
- package/lib/metadata/isM1EdgyMetaVersion.js +5 -0
- package/lib/metadata/mapMetaAttachmentsObjsToUuids.js +21 -0
- package/lib/metadata/updateValidationErrors.js +59 -0
- package/lib/metadata/validateItemMetadata.js +70 -0
- package/lib/styledComponentsMixins/truncate.mixin.js +8 -0
- package/package.json +3 -3
|
@@ -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,36 @@
|
|
|
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
|
+
_classCallCheck(this, RequestError);
|
|
25
|
+
_this = _callSuper(this, RequestError, [message]);
|
|
26
|
+
_this.name = "Request Error (".concat(code, ")");
|
|
27
|
+
_this.code = code;
|
|
28
|
+
_this.message = message;
|
|
29
|
+
_this.details = details;
|
|
30
|
+
_this.codeLabel = codeLabel;
|
|
31
|
+
return _this;
|
|
32
|
+
}
|
|
33
|
+
_inherits(RequestError, _Error);
|
|
34
|
+
return _createClass(RequestError);
|
|
35
|
+
}(/*#__PURE__*/_wrapNativeSuper(Error));
|
|
36
|
+
export default RequestError;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var getDateRange = function getDateRange(dateRange) {
|
|
2
|
+
var formatDate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (newDate) {
|
|
3
|
+
return newDate;
|
|
4
|
+
};
|
|
5
|
+
var isFuture = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
6
|
+
var min = 60 * 1000;
|
|
7
|
+
var hour = 60 * min;
|
|
8
|
+
var day = 24 * hour;
|
|
9
|
+
var date = '';
|
|
10
|
+
var getDateFormat = function getDateFormat(timeFrame) {
|
|
11
|
+
return formatDate(new Date(isFuture ? Date.now() + timeFrame * day : Date.now() - timeFrame * day));
|
|
12
|
+
};
|
|
13
|
+
switch (Math.abs(dateRange)) {
|
|
14
|
+
case 0:
|
|
15
|
+
// Today
|
|
16
|
+
date = getDateFormat(0);
|
|
17
|
+
break;
|
|
18
|
+
case 1:
|
|
19
|
+
// Past/next 24 hours (1 day)
|
|
20
|
+
date = getDateFormat(1);
|
|
21
|
+
break;
|
|
22
|
+
case 2:
|
|
23
|
+
// Past/next 7 days (1 week)
|
|
24
|
+
date = getDateFormat(7);
|
|
25
|
+
break;
|
|
26
|
+
case 3:
|
|
27
|
+
// Past/next 30 days (1 month)
|
|
28
|
+
date = getDateFormat(30);
|
|
29
|
+
break;
|
|
30
|
+
case 4:
|
|
31
|
+
// Past/next 90 days (3 months)
|
|
32
|
+
date = getDateFormat(90);
|
|
33
|
+
break;
|
|
34
|
+
case 5:
|
|
35
|
+
// Past/next 180 days (6 months)
|
|
36
|
+
date = getDateFormat(180);
|
|
37
|
+
break;
|
|
38
|
+
case 6:
|
|
39
|
+
// past/next 365 days (1 year)
|
|
40
|
+
date = getDateFormat(365);
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
return date;
|
|
44
|
+
};
|
|
45
|
+
export default getDateRange;
|
|
@@ -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 };
|
|
@@ -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,27 @@
|
|
|
1
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
2
|
+
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."); }
|
|
3
|
+
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; } }
|
|
4
|
+
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; }
|
|
5
|
+
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; } }
|
|
6
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
7
|
+
/**
|
|
8
|
+
* Check if the passed url has query params already or not and based on this add ?newProp=value or &newProp=value
|
|
9
|
+
* to the url.
|
|
10
|
+
* @param {string} url - any valid URL
|
|
11
|
+
* @param {object | string} newParams - new parameters to be added to the url as query param { newParam: value, newParam2: value2 } or 'newProp=value&newProp2=value2...'
|
|
12
|
+
* @returns {string} - url with newProp added to it
|
|
13
|
+
*/
|
|
14
|
+
export default (function () {
|
|
15
|
+
var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
16
|
+
var newParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
17
|
+
if (url) {
|
|
18
|
+
var params = typeof newParams === 'string' ? newParams : Object.entries(newParams).map(function (_ref) {
|
|
19
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
20
|
+
key = _ref2[0],
|
|
21
|
+
value = _ref2[1];
|
|
22
|
+
return "".concat(key, "=").concat(value);
|
|
23
|
+
}).join('&');
|
|
24
|
+
return "".concat(url).concat(url.includes('?') ? '&' : '?').concat(params);
|
|
25
|
+
}
|
|
26
|
+
return '';
|
|
27
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
* Adjust updated folders as currently BE API returns string instead of object for visibility field
|
|
9
|
+
* To fix that problem, visibilities object is merged to visibility
|
|
10
|
+
* BE task to fix it https://scaleflexhq.atlassian.net/browse/FRA-2010, after it's fixed, this function will not be
|
|
11
|
+
* needed anymore
|
|
12
|
+
* @param {Array} folders - array of folders
|
|
13
|
+
* @returns {Array} - updated array of folders
|
|
14
|
+
*/
|
|
15
|
+
export default (function (folders) {
|
|
16
|
+
return folders.map(function (folder) {
|
|
17
|
+
if (typeof folder.visibility === 'string') {
|
|
18
|
+
folder.visibility = _objectSpread({}, folder.visibilities);
|
|
19
|
+
}
|
|
20
|
+
return folder;
|
|
21
|
+
});
|
|
22
|
+
});
|