@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.
- 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 +38 -0
- package/lib/TranslationMissingKeysConsoleHelper.js +113 -0
- package/lib/Translator.js +200 -0
- package/lib/getLinkWithNewParams.js +13 -0
- package/lib/getMetadataMultiSelectQuery.js +66 -0
- package/lib/getNonce.js +26 -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/isPsd.js +8 -0
- package/lib/isScriptFile.js +12 -0
- package/lib/isSupportedVideo.js +8 -0
- package/lib/isSvg.js +5 -0
- package/lib/isTextFile.js +8 -0
- package/lib/isThumbnailCloudimgSupported.js +13 -0
- package/lib/isThumbnailLocallySupported.js +9 -0
- package/lib/isTiff.js +8 -0
- package/lib/isTransparencySupported.js +12 -0
- package/lib/isTtf.js +11 -0
- package/lib/isUploadableFile.js +7 -0
- package/lib/isUrl.js +5 -0
- package/lib/isValidUri.js +18 -0
- package/lib/isVideo.js +8 -0
- package/lib/isVideoResourceIntensive.js +9 -0
- package/lib/literalDateFromDateObj.js +6 -0
- package/lib/logErrorIfDevEnv.js +7 -0
- package/lib/lowercaseFirstLetter.js +4 -0
- package/lib/mapArrayByStep.js +12 -0
- package/lib/mimeTypes.js +60 -0
- package/lib/nanoid.js +18 -0
- package/lib/openLink.js +3 -0
- package/lib/openLinkInNewTab.js +12 -0
- package/lib/prettyETA.js +15 -0
- package/lib/prettyFileSize.js +7 -0
- package/lib/preventDefault.js +4 -0
- package/lib/provideSvgStrWithCurrColor.js +10 -0
- package/lib/recursiveFnCall.js +26 -0
- package/lib/removeAllUrlParams.js +4 -0
- package/lib/removeDuplicatesFromArray.js +20 -0
- package/lib/removeEmptyFolders.js +8 -0
- package/lib/removeFileExtension.js +4 -0
- package/lib/removeUrlParamsWithRegex.js +14 -0
- package/lib/reorder.js +15 -0
- package/lib/requestFile.js +36 -0
- package/lib/rgbToHex.js +4 -0
- package/lib/secondsToTime.js +10 -0
- package/lib/serializeFunction.js +4 -0
- package/lib/settle.js +19 -0
- package/lib/sortEntitiesByName.js +18 -0
- package/lib/splitCamelCase.js +4 -0
- package/lib/splitPathToPathsAndNames.js +25 -0
- package/lib/stopPropagation.js +4 -0
- package/lib/timeZones.js +1 -0
- package/lib/toArray.js +6 -0
- package/lib/toLowerCase.js +5 -0
- package/lib/toggleElementFullscreen.js +27 -0
- package/lib/visibility.js +39 -0
- package/package.json +3 -3
- package/CHANGELOG.md +0 -7431
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import RequestError from '@scaleflex/widget-utils/lib/RequestError';
|
|
2
|
+
import { I18N_GRID_UUID, I18N_PROD_BASE_URL } from '@scaleflex/widget-utils/lib/constants';
|
|
3
|
+
var hardcodedErrorMsg = 'Error while loading languages.';
|
|
4
|
+
export var getBackendTranslations = function getBackendTranslations(_ref) {
|
|
5
|
+
var i18nFetchApiEndpoint = _ref.i18nFetchApiEndpoint;
|
|
6
|
+
return new Promise(function (resolve, reject) {
|
|
7
|
+
var xhr = new XMLHttpRequest();
|
|
8
|
+
xhr.responseType = 'json';
|
|
9
|
+
xhr.onload = function () {
|
|
10
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
11
|
+
resolve(xhr.response);
|
|
12
|
+
} else {
|
|
13
|
+
var _xhr$response, _xhr$response2, _xhr$response3, _xhr$response4;
|
|
14
|
+
reject(new RequestError({
|
|
15
|
+
code: xhr.status,
|
|
16
|
+
message: ((_xhr$response = xhr.response) === null || _xhr$response === void 0 ? void 0 : _xhr$response.msg) || "Error code ".concat(xhr.status),
|
|
17
|
+
details: ((_xhr$response2 = xhr.response) === null || _xhr$response2 === void 0 ? void 0 : _xhr$response2.hint) || ((_xhr$response3 = xhr.response) === null || _xhr$response3 === void 0 ? void 0 : _xhr$response3.msg) || ((_xhr$response4 = xhr.response) === null || _xhr$response4 === void 0 ? void 0 : _xhr$response4.detail) || hardcodedErrorMsg
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
xhr.onerror = function () {
|
|
22
|
+
reject(new RequestError({
|
|
23
|
+
code: xhr.status,
|
|
24
|
+
message: hardcodedErrorMsg
|
|
25
|
+
}));
|
|
26
|
+
};
|
|
27
|
+
xhr.open('GET', "".concat(i18nFetchApiEndpoint, "/export?grid=").concat(I18N_GRID_UUID));
|
|
28
|
+
xhr.send();
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
export var sendMissingTranslationToBackend = function sendMissingTranslationToBackend(missingTranslation) {
|
|
32
|
+
return new Promise(function (resolve, reject) {
|
|
33
|
+
var xhr = new XMLHttpRequest();
|
|
34
|
+
xhr.responseType = 'json';
|
|
35
|
+
xhr.onload = function () {
|
|
36
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
37
|
+
resolve(xhr.response);
|
|
38
|
+
} else {
|
|
39
|
+
var _xhr$response5;
|
|
40
|
+
console.warn("Error in sending translation key to backend ".concat((_xhr$response5 = xhr.response) === null || _xhr$response5 === void 0 ? void 0 : _xhr$response5.hint, ", ").concat(xhr.status));
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
xhr.onerror = function () {
|
|
44
|
+
var _xhr$response6;
|
|
45
|
+
console.warn("Error in sending translation key to backend ".concat((_xhr$response6 = xhr.response) === null || _xhr$response6 === void 0 ? void 0 : _xhr$response6.hint, ", ").concat(xhr.status));
|
|
46
|
+
};
|
|
47
|
+
var payload = {
|
|
48
|
+
grid_uuid: I18N_GRID_UUID,
|
|
49
|
+
translations_requests: [missingTranslation]
|
|
50
|
+
};
|
|
51
|
+
xhr.open('POST', "".concat(I18N_PROD_BASE_URL, "/api/import/request-translations?grid_uuid=").concat(I18N_GRID_UUID));
|
|
52
|
+
xhr.send(JSON.stringify(payload));
|
|
53
|
+
});
|
|
54
|
+
};
|
package/lib/index.js
ADDED
|
File without changes
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import createFoldervirtualPath from './createFolderVirtualPath';
|
|
2
|
+
import removeEmptyFolders from './removeEmptyFolders';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Util used to add vitual pathes to folders
|
|
6
|
+
* @property { _folders } array
|
|
7
|
+
* @property { parentPath } string
|
|
8
|
+
* @returns { folderWithPath }
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
var _injectVirtualPathToFolders = function injectVirtualPathToFolders() {
|
|
12
|
+
var _folders = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
13
|
+
var parentPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
14
|
+
return _folders.map(function (folder) {
|
|
15
|
+
var folderWithPath = createFoldervirtualPath(folder, parentPath);
|
|
16
|
+
var subFolders = folder.folders;
|
|
17
|
+
if (subFolders) {
|
|
18
|
+
var nonEmptySubFolders = removeEmptyFolders(subFolders);
|
|
19
|
+
folderWithPath.folders = _injectVirtualPathToFolders(nonEmptySubFolders, folderWithPath.path);
|
|
20
|
+
}
|
|
21
|
+
return folderWithPath;
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
export default _injectVirtualPathToFolders;
|
package/lib/isAi.js
ADDED
package/lib/isArchive.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import getFileExtension from './getFileExtension';
|
|
2
|
+
export default function isArchive() {
|
|
3
|
+
var file = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
4
|
+
if (!file) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
var ArchiveExtensions = ['zip', 'tar', 'rar', 'gz', '7z'];
|
|
8
|
+
var fileType = getFileExtension(file).toLowerCase();
|
|
9
|
+
return ArchiveExtensions.some(function (ext) {
|
|
10
|
+
return fileType.includes(ext);
|
|
11
|
+
});
|
|
12
|
+
}
|
package/lib/isAudio.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import getFileType from './getFileType';
|
|
2
|
+
import AudioMimeTypes from './audioMimeTypes';
|
|
3
|
+
export default function isAudio(file) {
|
|
4
|
+
if (!file) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
var fileType = getFileType(file).toLowerCase();
|
|
8
|
+
return AudioMimeTypes.includes(fileType);
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SUPPORTED_AUDIO_PLAYBACK_MMIE_TYPE } from './constants';
|
|
2
|
+
import getFileType from './getFileType';
|
|
3
|
+
import isAudio from './isAudio';
|
|
4
|
+
export default function isAudioAndSupportsPlayback(file) {
|
|
5
|
+
if (!file || !isAudio(file)) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
var fileType = getFileType(file).toLowerCase();
|
|
9
|
+
return SUPPORTED_AUDIO_PLAYBACK_MMIE_TYPE.includes(fileType);
|
|
10
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BYTES_TO_MEGA_BYTES, LARGE_FILE_SIZE_IN_MB } from './constants';
|
|
2
|
+
import isAi from './isAi';
|
|
3
|
+
import isEps from './isEps';
|
|
4
|
+
import isJpg from './isJpg';
|
|
5
|
+
import isTiff from './isTiff';
|
|
6
|
+
export default function isCloudimageFastPreviewSupported(file) {
|
|
7
|
+
if (!file) return false;
|
|
8
|
+
var _ref = (file === null || file === void 0 ? void 0 : file.size) || {},
|
|
9
|
+
_ref$bytes = _ref.bytes,
|
|
10
|
+
bytes = _ref$bytes === void 0 ? 1 : _ref$bytes;
|
|
11
|
+
var isLargeJpgFile = bytes / BYTES_TO_MEGA_BYTES > LARGE_FILE_SIZE_IN_MB && isJpg(file);
|
|
12
|
+
if (isTiff(file) || isAi(file) || isEps(file) || isLargeJpgFile) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
/**
|
|
3
|
+
* Check if an object is a DOM element. Duck-typing based on `nodeType`.
|
|
4
|
+
*
|
|
5
|
+
* @param {*} obj
|
|
6
|
+
*/
|
|
7
|
+
export default function isDOMElement(obj) {
|
|
8
|
+
return obj && _typeof(obj) === 'object' && obj.nodeType === Node.ELEMENT_NODE;
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import DocumentMimeTypes from './documentMimeTypes';
|
|
2
|
+
import getFileType from './getFileType';
|
|
3
|
+
export default function isDocument() {
|
|
4
|
+
var file = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
5
|
+
if (!file) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
var fileType = getFileType(file).toLowerCase();
|
|
9
|
+
return DocumentMimeTypes.includes(fileType);
|
|
10
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the browser supports Drag & Drop (not supported on mobile devices, for example).
|
|
3
|
+
* @property {HTMLElement} htmlElement
|
|
4
|
+
* @returns {boolean}
|
|
5
|
+
*/
|
|
6
|
+
export default function isDragDropSupported(htmlElement) {
|
|
7
|
+
var element = htmlElement || document.createElement('div');
|
|
8
|
+
if (element !== document) {
|
|
9
|
+
if (!('draggable' in element) || !('ondragstart' in element && 'ondrop' in element)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
if (!('FormData' in window)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (!('FileReader' in window)) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
}
|
package/lib/isEps.js
ADDED
package/lib/isFile.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import cloudimageSupportedInputMimiTypes from './cloudimageSupportedInputMimeTypes';
|
|
2
|
+
import getFileType from './getFileType';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Check if the selected item type is supported input for cloudimage
|
|
6
|
+
*
|
|
7
|
+
* @param {object} item
|
|
8
|
+
* @returns {Boolean}
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
var isFileSupportedByCloudimage = function isFileSupportedByCloudimage(file) {
|
|
12
|
+
return cloudimageSupportedInputMimiTypes.includes(getFileType(file));
|
|
13
|
+
};
|
|
14
|
+
export default isFileSupportedByCloudimage;
|
package/lib/isFolder.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import mimeTypes from './mimeTypes';
|
|
2
|
+
import getFileType from './getFileType';
|
|
3
|
+
var isFontFile = function isFontFile() {
|
|
4
|
+
var file = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
5
|
+
if (!file) return false;
|
|
6
|
+
var fileType = getFileType(file).toLowerCase();
|
|
7
|
+
return fileType.toLowerCase().includes('font') || fileType === mimeTypes.otf || fileType === mimeTypes.ttf || fileType === mimeTypes.xttf || fileType === mimeTypes.sfnt;
|
|
8
|
+
};
|
|
9
|
+
export default isFontFile;
|
package/lib/isImage.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import getFileType from './getFileType';
|
|
2
|
+
export default function isImage() {
|
|
3
|
+
var file = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
4
|
+
if (!file) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// More determined logic as some mimeTypes like photoshop has (image/vnd.photoshop...)
|
|
9
|
+
// which shouldn't be treated as image in that case.
|
|
10
|
+
return /^image\/(jpeg|jpg|png|gif|apng|avif|heif|heic|svg\+xml|svg|webp|x-icon|bmp|x-ms-bmp|tiff|vnd\.microsoft\.icon)$/.test(getFileType(file).toLowerCase());
|
|
11
|
+
}
|
package/lib/isJpg.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if current device reports itself as “mobile”.
|
|
3
|
+
* Very simple, not very reliable.
|
|
4
|
+
*
|
|
5
|
+
* @returns {boolean}
|
|
6
|
+
*/
|
|
7
|
+
export default function isMobileDevice() {
|
|
8
|
+
if (typeof window !== 'undefined' && window.navigator && window.navigator.userAgent && window.navigator.userAgent.match(/Mobi/)) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
}
|
package/lib/isNumber.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
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
|
+
var isObjectType = function isObjectType(variable) {
|
|
3
|
+
return _typeof(variable) === 'object' && !Array.isArray(variable) && variable !== null;
|
|
4
|
+
};
|
|
5
|
+
export default isObjectType;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a URL string is an object URL from `URL.createObjectURL`.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} url
|
|
5
|
+
* @returns {boolean}
|
|
6
|
+
*/
|
|
7
|
+
export default function isObjectURL() {
|
|
8
|
+
var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
9
|
+
return url.indexOf('blob:') === 0;
|
|
10
|
+
}
|
package/lib/isOtf.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import mimeTypes from './mimeTypes';
|
|
2
|
+
import getFileType from './getFileType';
|
|
3
|
+
var isOtf = function isOtf(file) {
|
|
4
|
+
if (!file) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
var fileType = getFileType(file).toLowerCase();
|
|
8
|
+
return fileType === mimeTypes.otf || file.name.includes('.otf');
|
|
9
|
+
};
|
|
10
|
+
export default isOtf;
|
package/lib/isPdf.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import getFileType from './getFileType';
|
|
2
|
+
import mimeTypes from './mimeTypes';
|
|
3
|
+
var PDF_MIME_TYPES = [mimeTypes.pdf, mimeTypes.postScript];
|
|
4
|
+
export default function isPdf(file) {
|
|
5
|
+
if (!file) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
return PDF_MIME_TYPES.includes(getFileType(file).toLowerCase());
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import isImage from './isImage';
|
|
2
|
+
import isPdf from './isPdf';
|
|
3
|
+
import isOpenedFromAdobe from './isOpenedFromAdobe';
|
|
4
|
+
import isSupportedVideo from './isSupportedVideo';
|
|
5
|
+
import isFontFile from './isFontFile';
|
|
6
|
+
export default function isPreviewSupported(file) {
|
|
7
|
+
// Checking if we could show a preview for this item or not
|
|
8
|
+
if (isImage(file) || isPdf(file) && !isOpenedFromAdobe() || isSupportedVideo(file) && !isOpenedFromAdobe() || isFontFile(file)) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
}
|
package/lib/isPromise.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
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
|
+
var isPromise = function isPromise(obj) {
|
|
3
|
+
return obj && (obj instanceof Promise || (_typeof(obj) === 'object' || typeof obj === 'function') && typeof obj.then === 'function' && typeof obj["catch"] === 'function');
|
|
4
|
+
};
|
|
5
|
+
export default isPromise;
|
package/lib/isPsd.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import getFileExtension from './getFileExtension';
|
|
2
|
+
export default function isScriptFile() {
|
|
3
|
+
var file = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
4
|
+
if (!file) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
var scriptExtensions = ['js', 'py', 'sh', 'php', 'jsx', 'tsx'];
|
|
8
|
+
var fileType = getFileExtension(file).toLowerCase();
|
|
9
|
+
return scriptExtensions.some(function (ext) {
|
|
10
|
+
return fileType === ext;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import getFileType from './getFileType';
|
|
2
|
+
export default function isSupportedVideo() {
|
|
3
|
+
var file = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
4
|
+
if (!file) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
return /^video\/(mp4|quicktime|3gpp|x-msvideo|webm|x-matroska)/.test(getFileType(file).toLowerCase());
|
|
8
|
+
}
|
package/lib/isSvg.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import getFileType from './getFileType';
|
|
2
|
+
export default function isTextFile() {
|
|
3
|
+
var file = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
4
|
+
if (!file) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
return /^text\/(plain|markdown|yaml|tab-separated-values)/.test(getFileType(file).toLowerCase());
|
|
8
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import isAi from './isAi';
|
|
2
|
+
import isEps from './isEps';
|
|
3
|
+
import isFontFile from './isFontFile';
|
|
4
|
+
import isImage from './isImage';
|
|
5
|
+
import isPdf from './isPdf';
|
|
6
|
+
import isPhotoshopFile from './isPhotoshopFile';
|
|
7
|
+
export default function isThumbnailCloudimgSupported(file) {
|
|
8
|
+
// Checking if we could show a preview for this item or not
|
|
9
|
+
if (isImage(file) || isPdf(file) || isPhotoshopFile(file) || isEps(file) || isAi(file) || isFontFile(file)) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import isImage from './isImage';
|
|
2
|
+
import isPhotoshopFile from './isPhotoshopFile';
|
|
3
|
+
export default function isThumbnailLocallySupported(file) {
|
|
4
|
+
// Checking if we could show a preview for this item or not
|
|
5
|
+
if (isImage(file) || isPhotoshopFile(file)) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
return false;
|
|
9
|
+
}
|
package/lib/isTiff.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import isSvg from '@scaleflex/widget-utils/lib/isSvg';
|
|
2
|
+
import isTiff from './isTiff';
|
|
3
|
+
export default function isTransparencySupported(file) {
|
|
4
|
+
var _file$type, _file$type2, _file$type3;
|
|
5
|
+
if (!file) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
var isPng = (_file$type = file.type) === null || _file$type === void 0 ? void 0 : _file$type.includes('png');
|
|
9
|
+
var isGif = (_file$type2 = file.type) === null || _file$type2 === void 0 ? void 0 : _file$type2.includes('gif');
|
|
10
|
+
var isBmp = (_file$type3 = file.type) === null || _file$type3 === void 0 ? void 0 : _file$type3.includes('bmp');
|
|
11
|
+
return isPng || isGif || isBmp || isSvg(file) || isTiff(file);
|
|
12
|
+
}
|
package/lib/isTtf.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TTF_FONT_MIME_TYPES } from './constants';
|
|
2
|
+
import getFileType from './getFileType';
|
|
3
|
+
var isTtf = function isTtf(file) {
|
|
4
|
+
var _file$name, _file$name$toLowerCas;
|
|
5
|
+
if (!file) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
var fileType = getFileType(file).toLowerCase();
|
|
9
|
+
return TTF_FONT_MIME_TYPES.includes(fileType) && ((_file$name = file.name) === null || _file$name === void 0 ? void 0 : (_file$name$toLowerCas = _file$name.toLowerCase()) === null || _file$name$toLowerCas === void 0 ? void 0 : _file$name$toLowerCas.includes('.ttf'));
|
|
10
|
+
};
|
|
11
|
+
export default isTtf;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// as uploadStep is a property of the files being uploaded, also id is specificed in the files being uploaded
|
|
2
|
+
// cause the files found on backend are using uuid instead of id.
|
|
3
|
+
var isUploadableFile = function isUploadableFile() {
|
|
4
|
+
var file = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
5
|
+
return file ? Boolean(file.uploadStep || file.id) : false;
|
|
6
|
+
};
|
|
7
|
+
export default isUploadableFile;
|
package/lib/isUrl.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var VALID_PROTOCOLS = ['http', 'https', 'ftp'];
|
|
2
|
+
var isValidUri = function isValidUri() {
|
|
3
|
+
var uri = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
4
|
+
if (typeof uri !== 'string') {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// to prevent javascript: for some security reasons
|
|
9
|
+
if (uri.trim().toLowerCase().startsWith('javascript:')) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
var isProtocol = VALID_PROTOCOLS.some(function (protocol) {
|
|
13
|
+
return uri === null || uri === void 0 ? void 0 : uri.startsWith(protocol);
|
|
14
|
+
});
|
|
15
|
+
var uriRex = isProtocol ? /^(http|https|ftp):\/\/[^\s.]+\.[^\s]+$/ : /^(www\.[^:/]+\.[^/]+|[^:/]+:[^/]+)$/;
|
|
16
|
+
return uriRex.test(uri);
|
|
17
|
+
};
|
|
18
|
+
export default isValidUri;
|
package/lib/isVideo.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import getFileType from './getFileType';
|
|
2
|
+
export default function isVideo() {
|
|
3
|
+
var file = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
4
|
+
if (!file) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
return /^video\/(mp4|m4p|m4v|quicktime|3gpp|x-msvideo|webm|x-matroska|x-ms-wmv|x-ms-asf|MP2T|x-flv|ogg)/.test(getFileType(file).toLowerCase());
|
|
8
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export var isVideoResourceIntensive = function isVideoResourceIntensive(file) {
|
|
2
|
+
return file.info.img_w > 720 ||
|
|
3
|
+
// width greater than 720px
|
|
4
|
+
file.info.img_h > 720 ||
|
|
5
|
+
// height greater than 720px
|
|
6
|
+
file.info.video_duration > 5 * 60 ||
|
|
7
|
+
// video duration greater than 5 minutes
|
|
8
|
+
file.size > 100 * 1024 * 1024;
|
|
9
|
+
}; // size greater than 100 MB
|
|
@@ -0,0 +1,6 @@
|
|
|
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
|
+
var literalDateFromDateObj = function literalDateFromDateObj(date) {
|
|
3
|
+
var _date$toISOString;
|
|
4
|
+
return _typeof(date) === 'object' ? (_date$toISOString = date.toISOString()) === null || _date$toISOString === void 0 ? void 0 : _date$toISOString.split('T')[0] : '';
|
|
5
|
+
};
|
|
6
|
+
export default literalDateFromDateObj;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
var logErrorIfDevEnv = function logErrorIfDevEnv(error) {
|
|
2
|
+
var isDev = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
3
|
+
if (error && (isDev || process.env.NODE_ENV === 'development')) {
|
|
4
|
+
console.error("[Development env. error]: ".concat(error.stack || error.message || (error === null || error === void 0 ? void 0 : error.toString()) || error));
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
export default logErrorIfDevEnv;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
var mapArrayByStep = function mapArrayByStep() {
|
|
2
|
+
var array = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
3
|
+
var startIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
4
|
+
var step = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
5
|
+
var callback = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : function () {};
|
|
6
|
+
var mapped = [];
|
|
7
|
+
for (var i = startIndex; i < array.length; i += step) {
|
|
8
|
+
mapped.push(callback(array[i]));
|
|
9
|
+
}
|
|
10
|
+
return mapped;
|
|
11
|
+
};
|
|
12
|
+
export default mapArrayByStep;
|