@scaleflex/widget-utils 4.4.0 → 4.5.0
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 +8 -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 +570 -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,57 @@
|
|
|
1
|
+
import toArray from '../../../toArray';
|
|
2
|
+
import getRelativePath from './getRelativePath';
|
|
3
|
+
import getFilesAndDirectoriesFromDirectory from './getFilesAndDirectoriesFromDirectory';
|
|
4
|
+
export default function webkitGetAsEntryApi(dataTransfer, logDropError) {
|
|
5
|
+
var files = [];
|
|
6
|
+
var rootPromises = [];
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Returns a resolved promise, when :files array is enhanced
|
|
10
|
+
*
|
|
11
|
+
* @param {(FileSystemFileEntry|FileSystemDirectoryEntry)} entry
|
|
12
|
+
* @returns {Promise} - empty promise that resolves when :files is enhanced with a file
|
|
13
|
+
*/
|
|
14
|
+
var _createPromiseToAddFileOrParseDirectory = function createPromiseToAddFileOrParseDirectory(entry) {
|
|
15
|
+
return new Promise(function (resolve) {
|
|
16
|
+
// This is a base call
|
|
17
|
+
if (entry.isFile) {
|
|
18
|
+
// Creates a new File object which can be used to read the file.
|
|
19
|
+
entry.file(function (file) {
|
|
20
|
+
file.relativePath = getRelativePath(entry);
|
|
21
|
+
files.push(file);
|
|
22
|
+
resolve();
|
|
23
|
+
},
|
|
24
|
+
// Make sure we resolve on error anyway, it's fine if only one file couldn't be read!
|
|
25
|
+
function (error) {
|
|
26
|
+
logDropError(error);
|
|
27
|
+
resolve();
|
|
28
|
+
});
|
|
29
|
+
// This is a recursive call
|
|
30
|
+
} else if (entry.isDirectory) {
|
|
31
|
+
var directoryReader = entry.createReader();
|
|
32
|
+
getFilesAndDirectoriesFromDirectory(directoryReader, [], logDropError, {
|
|
33
|
+
onSuccess: function onSuccess(entries) {
|
|
34
|
+
var promises = entries.map(function (entry) {
|
|
35
|
+
return _createPromiseToAddFileOrParseDirectory(entry);
|
|
36
|
+
});
|
|
37
|
+
Promise.all(promises).then(function () {
|
|
38
|
+
return resolve();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// For each dropped item, - make sure it's a file/directory, and start deepening in!
|
|
47
|
+
toArray(dataTransfer.items).forEach(function (item) {
|
|
48
|
+
var entry = item.webkitGetAsEntry();
|
|
49
|
+
// :entry can be null when we drop the url e.g.
|
|
50
|
+
if (entry) {
|
|
51
|
+
rootPromises.push(_createPromiseToAddFileOrParseDirectory(entry));
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return Promise.all(rootPromises).then(function () {
|
|
55
|
+
return files;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FILEROBOT_V3_URL, FILEROBOT_FILE_URL_REGEX } from './constants';
|
|
2
|
+
var getEncodedWrappedUrl = function getEncodedWrappedUrl(url) {
|
|
3
|
+
var _url$match;
|
|
4
|
+
var wrapperUrl = url.includes(FILEROBOT_V3_URL) ? "https://".concat(FILEROBOT_V3_URL, "/") : ((_url$match = url.match(FILEROBOT_FILE_URL_REGEX)) === null || _url$match === void 0 ? void 0 : _url$match[0]) || '';
|
|
5
|
+
return wrapperUrl ? "".concat(wrapperUrl).concat(encodeURIComponent(url)) : url;
|
|
6
|
+
};
|
|
7
|
+
export default getEncodedWrappedUrl;
|
|
@@ -0,0 +1,14 @@
|
|
|
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 _wrapRegExp() { _wrapRegExp = function _wrapRegExp(e, r) { return new BabelRegExp(e, void 0, r); }; var e = RegExp.prototype, r = new WeakMap(); function BabelRegExp(e, t, p) { var o = RegExp(e, t); return r.set(o, p || r.get(e)), _setPrototypeOf(o, BabelRegExp.prototype); } function buildGroups(e, t) { var p = r.get(t); return Object.keys(p).reduce(function (r, t) { var o = p[t]; if ("number" == typeof o) r[t] = e[o];else { for (var i = 0; void 0 === e[o[i]] && i + 1 < o.length;) i++; r[t] = e[o[i]]; } return r; }, Object.create(null)); } return _inherits(BabelRegExp, RegExp), BabelRegExp.prototype.exec = function (r) { var t = e.exec.call(this, r); if (t) { t.groups = buildGroups(t, this); var p = t.indices; p && (p.groups = buildGroups(p, this)); } return t; }, BabelRegExp.prototype[Symbol.replace] = function (t, p) { if ("string" == typeof p) { var o = r.get(this); return e[Symbol.replace].call(this, t, p.replace(/\$<([^>]+)>/g, function (e, r) { var t = o[r]; return "$" + (Array.isArray(t) ? t.join("$") : t); })); } if ("function" == typeof p) { var i = this; return e[Symbol.replace].call(this, t, function () { var e = arguments; return "object" != _typeof(e[e.length - 1]) && (e = [].slice.call(e)).push(buildGroups(e, i)), p.apply(this, e); }); } return e[Symbol.replace].call(this, t, p); }, _wrapRegExp.apply(this, arguments); }
|
|
3
|
+
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); }
|
|
4
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
5
|
+
var getFileAssetsTokenUrl = function getFileAssetsTokenUrl(fileUrl) {
|
|
6
|
+
var isDev = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
7
|
+
return fileUrl ? fileUrl.replace(/*#__PURE__*/_wrapRegExp(/(\/\/)([\w-]*)\.(\w*)\.(\w*)\/(v7\/)?/, {
|
|
8
|
+
protocol: 1,
|
|
9
|
+
token: 2,
|
|
10
|
+
secondLvlDomain: 3,
|
|
11
|
+
topLvlDomain: 4
|
|
12
|
+
}), "$<protocol>assets".concat(isDev ? '-dev' : '', ".$<secondLvlDomain>.$<topLvlDomain>/$<token>/")) : fileUrl;
|
|
13
|
+
};
|
|
14
|
+
export default getFileAssetsTokenUrl;
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
import { FILE_TYPES_AND_ICONS } from './constants';
|
|
3
|
+
import getFileExtension from './getFileExtension';
|
|
4
|
+
var getFileDefaultIcon = function getFileDefaultIcon(file) {
|
|
5
|
+
if (!file || _typeof(file) !== 'object') {
|
|
6
|
+
return '';
|
|
7
|
+
}
|
|
8
|
+
var extension = getFileExtension(file);
|
|
9
|
+
if (!extension) {
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
12
|
+
return FILE_TYPES_AND_ICONS[extension === null || extension === void 0 ? void 0 : extension.toLowerCase()] || FILE_TYPES_AND_ICONS._default;
|
|
13
|
+
};
|
|
14
|
+
export default getFileDefaultIcon;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
2
|
+
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."); }
|
|
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 _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
5
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
6
|
+
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; }
|
|
7
|
+
import { TIME_OPTIONS } from './constants';
|
|
8
|
+
import getItemIcon from './getItemIcon';
|
|
9
|
+
import getFileExtension from './getFileExtension';
|
|
10
|
+
import prettyFileSize from './prettyFileSize';
|
|
11
|
+
import getFileType from './getFileType';
|
|
12
|
+
import humanReadableDateWithTranslations from './humanReadableDateWithTranslations';
|
|
13
|
+
import Translator from './Translator';
|
|
14
|
+
import { getActualVisibility, getVisibilityI18nLabel } from './visibility';
|
|
15
|
+
export default (function (file, i18n) {
|
|
16
|
+
var _fileInfo$img_w, _fileInfo$img_h, _getFileExtension, _file$owner, _fileInfo$brand, _file$folder;
|
|
17
|
+
var fileInfo = (file === null || file === void 0 ? void 0 : file.info) || {};
|
|
18
|
+
var width = (_fileInfo$img_w = fileInfo.img_w) !== null && _fileInfo$img_w !== void 0 ? _fileInfo$img_w : fileInfo.video_w;
|
|
19
|
+
var height = (_fileInfo$img_h = fileInfo.img_h) !== null && _fileInfo$img_h !== void 0 ? _fileInfo$img_h : fileInfo.video_h;
|
|
20
|
+
var isDefined = width && height;
|
|
21
|
+
var type = getFileType(file);
|
|
22
|
+
var extension = ((_getFileExtension = getFileExtension(file)) === null || _getFileExtension === void 0 ? void 0 : _getFileExtension.toUpperCase()) || '';
|
|
23
|
+
var videoDuration = fileInfo.video_duration;
|
|
24
|
+
var transcodingProgress = file.transcodingProgress;
|
|
25
|
+
var uuid = file.uuid;
|
|
26
|
+
var name = file.name;
|
|
27
|
+
var urls = file.url;
|
|
28
|
+
var preview = file.preview || getItemIcon({
|
|
29
|
+
fileOrFolder: file
|
|
30
|
+
});
|
|
31
|
+
var createdAt = file.created_at ? new Date(file.created_at).toLocaleTimeString(Translator.LANGUAGE, TIME_OPTIONS) : '';
|
|
32
|
+
var hasI18n = typeof i18n === 'function';
|
|
33
|
+
var humanReadableCreatedAt = hasI18n ? humanReadableDateWithTranslations(file.created_at, i18n) : createdAt;
|
|
34
|
+
var createdBy = (_file$owner = file.owner) === null || _file$owner === void 0 ? void 0 : _file$owner.name;
|
|
35
|
+
var modifiedAt = file.modified_at || file.updated_at ? new Date(file.modified_at).toLocaleTimeString(Translator.LANGUAGE, TIME_OPTIONS) : '';
|
|
36
|
+
var humanReadableModifiedAt = hasI18n ? humanReadableDateWithTranslations(file.modified_at, i18n) : modifiedAt;
|
|
37
|
+
var ratio = isDefined ? (width / height).toPrecision(3) : 0;
|
|
38
|
+
var size = prettyFileSize(file.size);
|
|
39
|
+
var tags = file !== null && file !== void 0 && file.tags ? file.tags : {};
|
|
40
|
+
var resolution = isDefined ? "".concat(width, " \xD7 ").concat(height) : null;
|
|
41
|
+
var actualVisibility = getActualVisibility(file.visibility);
|
|
42
|
+
var visibility = hasI18n ? i18n(getVisibilityI18nLabel(actualVisibility)) : actualVisibility;
|
|
43
|
+
var brandsAndLogos = (((_fileInfo$brand = fileInfo.brand) === null || _fileInfo$brand === void 0 ? void 0 : _fileInfo$brand.extracted) || []).map(function (item) {
|
|
44
|
+
return item === null || item === void 0 ? void 0 : item.classes;
|
|
45
|
+
});
|
|
46
|
+
var brandAndLogosLabels = brandsAndLogos.map(function (item) {
|
|
47
|
+
var _item$;
|
|
48
|
+
return item === null || item === void 0 ? void 0 : (_item$ = item[0]) === null || _item$ === void 0 ? void 0 : _item$.label;
|
|
49
|
+
});
|
|
50
|
+
var filteredBrandAndLogosLabels = _toConsumableArray(new Set(brandAndLogosLabels));
|
|
51
|
+
var meta = file.meta || {};
|
|
52
|
+
var folderPath = (_file$folder = file.folder) === null || _file$folder === void 0 ? void 0 : _file$folder.name;
|
|
53
|
+
var colorMode = fileInfo.color_space;
|
|
54
|
+
return {
|
|
55
|
+
uuid: uuid,
|
|
56
|
+
name: name,
|
|
57
|
+
type: type,
|
|
58
|
+
extension: extension,
|
|
59
|
+
size: size,
|
|
60
|
+
createdAt: createdAt,
|
|
61
|
+
humanReadableCreatedAt: humanReadableCreatedAt,
|
|
62
|
+
createdBy: createdBy,
|
|
63
|
+
modifiedAt: modifiedAt,
|
|
64
|
+
humanReadableModifiedAt: humanReadableModifiedAt,
|
|
65
|
+
info: fileInfo,
|
|
66
|
+
width: width,
|
|
67
|
+
height: height,
|
|
68
|
+
urls: urls,
|
|
69
|
+
ratio: ratio,
|
|
70
|
+
resolution: resolution,
|
|
71
|
+
tags: tags,
|
|
72
|
+
visibility: visibility,
|
|
73
|
+
meta: meta,
|
|
74
|
+
preview: preview,
|
|
75
|
+
videoDuration: videoDuration,
|
|
76
|
+
transcodingProgress: transcodingProgress,
|
|
77
|
+
brandAndLogosLabels: filteredBrandAndLogosLabels,
|
|
78
|
+
folderPath: folderPath,
|
|
79
|
+
colorMode: colorMode
|
|
80
|
+
};
|
|
81
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export default (function () {
|
|
2
|
+
var _file$info, _file$info2;
|
|
3
|
+
var file = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
4
|
+
var notFoundStr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
5
|
+
var neglectMimeType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
6
|
+
var ext = file.extension || ((_file$info = file.info) === null || _file$info === void 0 ? void 0 : _file$info.ext) || ((_file$info2 = file.info) === null || _file$info2 === void 0 ? void 0 : _file$info2.img_type);
|
|
7
|
+
if (ext) {
|
|
8
|
+
return ext;
|
|
9
|
+
}
|
|
10
|
+
var fileMeta = file.meta;
|
|
11
|
+
if (fileMeta && fileMeta.img_type) {
|
|
12
|
+
return fileMeta.img_type;
|
|
13
|
+
}
|
|
14
|
+
var fileMime = file.mime || file.file_type;
|
|
15
|
+
var mimeSeparatorIndex = fileMime === null || fileMime === void 0 ? void 0 : fileMime.lastIndexOf('/');
|
|
16
|
+
if (fileMime && mimeSeparatorIndex && mimeSeparatorIndex !== -1 && !neglectMimeType) {
|
|
17
|
+
return fileMime.slice(mimeSeparatorIndex + 1);
|
|
18
|
+
}
|
|
19
|
+
var fileName = file.name;
|
|
20
|
+
var nameSeparatorIndex = fileName === null || fileName === void 0 ? void 0 : fileName.lastIndexOf('.');
|
|
21
|
+
if (fileName && nameSeparatorIndex && nameSeparatorIndex !== -1) {
|
|
22
|
+
var fileExtension = fileName.slice(nameSeparatorIndex + 1);
|
|
23
|
+
var fileExtensionEndIndex = fileExtension.search(/[^\w\d]/);
|
|
24
|
+
return fileExtensionEndIndex !== -1 ? fileExtension.slice(0, fileExtensionEndIndex) : fileExtension;
|
|
25
|
+
}
|
|
26
|
+
var fileType = file.type;
|
|
27
|
+
var typeSeparatorIndex = fileType === null || fileType === void 0 ? void 0 : fileType.lastIndexOf('/');
|
|
28
|
+
if (fileType && typeSeparatorIndex && typeSeparatorIndex !== -1) {
|
|
29
|
+
return fileType.slice(typeSeparatorIndex + 1);
|
|
30
|
+
}
|
|
31
|
+
return notFoundStr;
|
|
32
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export default (function (file) {
|
|
2
|
+
var specificUrlProperty = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
3
|
+
var defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
4
|
+
var _ref = file || {},
|
|
5
|
+
url = _ref.url;
|
|
6
|
+
if (typeof url === 'string') {
|
|
7
|
+
return url;
|
|
8
|
+
}
|
|
9
|
+
if (specificUrlProperty) {
|
|
10
|
+
return (url === null || url === void 0 ? void 0 : url[specificUrlProperty]) || defaultValue;
|
|
11
|
+
}
|
|
12
|
+
var _ref2 = url || {},
|
|
13
|
+
publicUrl = _ref2["public"],
|
|
14
|
+
permalink = _ref2.permalink,
|
|
15
|
+
cdn = _ref2.cdn;
|
|
16
|
+
return cdn || publicUrl || permalink || url || defaultValue;
|
|
17
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Takes a full filename string and returns an object {name, extension}
|
|
3
|
+
*
|
|
4
|
+
* @param {string} fullFileName
|
|
5
|
+
* @returns {object} {name, extension}
|
|
6
|
+
*/
|
|
7
|
+
export default function getFileNameAndExtension(fullFileName, fileType) {
|
|
8
|
+
var lastDot = fullFileName.lastIndexOf('.');
|
|
9
|
+
// these count as no extension: "no-dot", "trailing-dot."
|
|
10
|
+
if (lastDot === -1 || lastDot === fullFileName.length - 1) {
|
|
11
|
+
var _fileType$split;
|
|
12
|
+
return {
|
|
13
|
+
name: fullFileName,
|
|
14
|
+
extension: fileType === null || fileType === void 0 ? void 0 : (_fileType$split = fileType.split('/')) === null || _fileType$split === void 0 ? void 0 : _fileType$split[1]
|
|
15
|
+
};
|
|
16
|
+
} else {
|
|
17
|
+
return {
|
|
18
|
+
name: fullFileName.slice(0, lastDot),
|
|
19
|
+
extension: fullFileName.slice(lastDot + 1)
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import getFileNameAndExtension from './getFileNameAndExtension';
|
|
2
|
+
import mimeTypes from './mimeTypes';
|
|
3
|
+
|
|
4
|
+
// if type is set in the file object already, use that
|
|
5
|
+
// otherwise extract it from the file name (not the best)
|
|
6
|
+
export default function getFileType(file) {
|
|
7
|
+
var _file$info, _file$info2, _file$data, _getFileNameAndExtens;
|
|
8
|
+
if (!file) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
var type = file.type || file.mime || ((_file$info = file.info) === null || _file$info === void 0 ? void 0 : _file$info.type) || ((_file$info2 = file.info) === null || _file$info2 === void 0 ? void 0 : _file$info2.img_type) || ((_file$data = file.data) === null || _file$data === void 0 ? void 0 : _file$data.type);
|
|
12
|
+
if (type) {
|
|
13
|
+
return type;
|
|
14
|
+
}
|
|
15
|
+
var fileExtension = file.name ? (_getFileNameAndExtens = getFileNameAndExtension(file.name).extension) === null || _getFileNameAndExtens === void 0 ? void 0 : _getFileNameAndExtens.toLowerCase() : null;
|
|
16
|
+
if (fileExtension && mimeTypes[fileExtension]) {
|
|
17
|
+
// else, see if we can map extension to a mime type
|
|
18
|
+
return mimeTypes[fileExtension];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// if all fails, fall back to a generic byte stream type
|
|
22
|
+
return 'application/octet-stream';
|
|
23
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var mimeToExtensions = {
|
|
2
|
+
'audio/mp3': 'mp3',
|
|
3
|
+
'audio/ogg': 'ogg',
|
|
4
|
+
'audio/webm': 'webm',
|
|
5
|
+
'image/gif': 'gif',
|
|
6
|
+
'image/heic': 'heic',
|
|
7
|
+
'image/heif': 'heif',
|
|
8
|
+
'image/jpeg': 'jpg',
|
|
9
|
+
'image/png': 'png',
|
|
10
|
+
'image/svg+xml': 'svg',
|
|
11
|
+
'video/mp4': 'mp4',
|
|
12
|
+
'video/ogg': 'ogv',
|
|
13
|
+
'video/quicktime': 'mov',
|
|
14
|
+
'video/webm': 'webm',
|
|
15
|
+
'video/x-matroska': 'mkv',
|
|
16
|
+
'video/x-msvideo': 'avi'
|
|
17
|
+
};
|
|
18
|
+
export default function getFileTypeExtension(mimeType) {
|
|
19
|
+
// Remove the ; bit in 'video/x-matroska;codecs=avc1'
|
|
20
|
+
mimeType = mimeType.replace(/;.*$/, '');
|
|
21
|
+
return mimeToExtensions[mimeType] || null;
|
|
22
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FILTER_FILE_FORMAT_ICONS } from './constants';
|
|
2
|
+
export default function getFilterFileFormatIcon() {
|
|
3
|
+
var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
4
|
+
var _format = format.replace(/\|(.*)/, '').toLowerCase().trim();
|
|
5
|
+
return FILTER_FILE_FORMAT_ICONS[_format] || FILTER_FILE_FORMAT_ICONS.file;
|
|
6
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { TIME_OPTIONS } from './constants';
|
|
2
|
+
export default (function (folder, language) {
|
|
3
|
+
var _folder$size, _folder$count, _folder$count2;
|
|
4
|
+
var uuid = folder.uuid;
|
|
5
|
+
var name = folder.name;
|
|
6
|
+
var path = folder.path;
|
|
7
|
+
var type = folder.type || 'folder';
|
|
8
|
+
var size = (_folder$size = folder.size) === null || _folder$size === void 0 ? void 0 : _folder$size.total_recursive_pretty;
|
|
9
|
+
var filesRecursive = folder === null || folder === void 0 ? void 0 : (_folder$count = folder.count) === null || _folder$count === void 0 ? void 0 : _folder$count.files_recursive;
|
|
10
|
+
var filesDirect = folder === null || folder === void 0 ? void 0 : (_folder$count2 = folder.count) === null || _folder$count2 === void 0 ? void 0 : _folder$count2.files_direct;
|
|
11
|
+
var updadtedAt = folder.updated_at ? new Date(folder.updated_at).toLocaleTimeString(language, TIME_OPTIONS) : '';
|
|
12
|
+
var createdAt = folder.created_at ? new Date(folder.created_at).toLocaleTimeString(language, TIME_OPTIONS) : '';
|
|
13
|
+
var visibility = folder.visibility;
|
|
14
|
+
var filesCount = folder.filesCount;
|
|
15
|
+
var assetsPreviews = folder.assetsPreviews;
|
|
16
|
+
return {
|
|
17
|
+
uuid: uuid,
|
|
18
|
+
name: name,
|
|
19
|
+
path: path,
|
|
20
|
+
type: type,
|
|
21
|
+
size: size,
|
|
22
|
+
filesRecursive: filesRecursive,
|
|
23
|
+
filesDirect: filesDirect,
|
|
24
|
+
updadtedAt: updadtedAt,
|
|
25
|
+
createdAt: createdAt,
|
|
26
|
+
visibility: visibility,
|
|
27
|
+
filesCount: filesCount,
|
|
28
|
+
assetsPreviews: assetsPreviews
|
|
29
|
+
};
|
|
30
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
import { FILEROBOT_FILE_URL_REGEX, FILEROBOT_V3_URL } from './constants';
|
|
8
|
+
var FILEROBOT_SECOND_LEVEL_DOMAIN = 'filerobot';
|
|
9
|
+
var DEFAULT_FILEROBOT_SUBDOMAIN_PROD = 'assets';
|
|
10
|
+
var DEFAULT_FILEROBOT_SUBDOMAIN_DEV = 'assets-dev';
|
|
11
|
+
var TOP_LEVEL_DOMAIN = 'com';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Ge preview url from filerobot url
|
|
15
|
+
*
|
|
16
|
+
* Based on documentation https://scaleflexhq.atlassian.net/wiki/spaces/DEVOPS/pages/166199297/Delivery+Filerobot+Hub+Thumbs+v3
|
|
17
|
+
*
|
|
18
|
+
* There are 2 cases:
|
|
19
|
+
* 1) when there is v7 in the url
|
|
20
|
+
* v2 https://fldytuwm.filerobot.com/v7/120049.jpg into v3 https://assets.filerobot.com/fldytuwm/120049.jpg
|
|
21
|
+
* v2 https://cdn.scaleflex.com/cloudimage.io/checkerboard.svg?vh=938ef5 into v3 https://assets.filerobot.com/scaleflex/cloudimage.io/checkerboard.svg?vh=938ef5
|
|
22
|
+
*
|
|
23
|
+
* 2)when there is no v7 in the url
|
|
24
|
+
* v2 https://fyjnhqim.filerobot.com/ganchev/test_files+doubled/01+-+StyleSense+-+Falsche+Darstellung.png?vh=2b64bd into https://assets.filerobot.com/fyjnhqim/ganchev/test_files+doubled/01+-+StyleSense+-+Falsche+Darstellung.png?vh=2b64bd
|
|
25
|
+
* v2 https://fyjnhqim.filerobot.com/.internal/video_thumbnails/2oaTbKYAtv/20220818_112552.jpg into https://assets.filerobot.com/fyjnhqim/.internal/video_thumbnails/2oaTbKYAtv/20220818_112552.jpg
|
|
26
|
+
*
|
|
27
|
+
* @returns {string} -- New url based on the rules above
|
|
28
|
+
*
|
|
29
|
+
* @param {string} url -- Filerobot file url
|
|
30
|
+
* @param {boolean} replaceWithAssetsToken -- was `isHubMode` that recognize whether to replace the CDN link with the assets token or not.
|
|
31
|
+
*/
|
|
32
|
+
export default (function (_ref) {
|
|
33
|
+
var _url$match;
|
|
34
|
+
var _ref$url = _ref.url,
|
|
35
|
+
url = _ref$url === void 0 ? '' : _ref$url,
|
|
36
|
+
isDevEnv = _ref.isDevEnv,
|
|
37
|
+
_ref$replaceWithAsset = _ref.replaceWithAssetsToken,
|
|
38
|
+
replaceWithAssetsToken = _ref$replaceWithAsset === void 0 ? false : _ref$replaceWithAsset,
|
|
39
|
+
containerToken = _ref.containerToken;
|
|
40
|
+
var _ref2 = ((_url$match = url.match(FILEROBOT_FILE_URL_REGEX)) === null || _url$match === void 0 ? void 0 : _url$match.groups) || {},
|
|
41
|
+
protocol = _ref2.protocol,
|
|
42
|
+
token = _ref2.token,
|
|
43
|
+
secondLevelDomain = _ref2.secondLevelDomain,
|
|
44
|
+
topLevelDomain = _ref2.topLevelDomain;
|
|
45
|
+
if (url.includes('blob:')) return url;
|
|
46
|
+
if (url.includes(FILEROBOT_V3_URL)) {
|
|
47
|
+
if (isDevEnv) {
|
|
48
|
+
return url.replace(DEFAULT_FILEROBOT_SUBDOMAIN_PROD, DEFAULT_FILEROBOT_SUBDOMAIN_DEV);
|
|
49
|
+
}
|
|
50
|
+
return url;
|
|
51
|
+
}
|
|
52
|
+
var debug = function debug() {
|
|
53
|
+
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
54
|
+
if (localStorage.getItem('debug_previews') !== '1') {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
console.trace(_objectSpread(_objectSpread({}, data), {}, {
|
|
58
|
+
url: url,
|
|
59
|
+
isDevEnv: isDevEnv,
|
|
60
|
+
containerToken: containerToken,
|
|
61
|
+
protocol: protocol,
|
|
62
|
+
token: token,
|
|
63
|
+
secondLevelDomain: secondLevelDomain,
|
|
64
|
+
topLevelDomain: topLevelDomain
|
|
65
|
+
}));
|
|
66
|
+
};
|
|
67
|
+
if (replaceWithAssetsToken) {
|
|
68
|
+
var matchFilerobotCdnUrlRegExp = new RegExp("".concat(protocol).concat(token, "\\.").concat(secondLevelDomain, "\\.").concat(topLevelDomain, "\\/(v7\\/)?"));
|
|
69
|
+
var previewToken = isDevEnv ? DEFAULT_FILEROBOT_SUBDOMAIN_DEV : DEFAULT_FILEROBOT_SUBDOMAIN_PROD;
|
|
70
|
+
var previewUrl = "".concat(protocol).concat(previewToken, ".").concat(FILEROBOT_SECOND_LEVEL_DOMAIN, ".").concat(TOP_LEVEL_DOMAIN, "/").concat(containerToken, "/");
|
|
71
|
+
debug({
|
|
72
|
+
previewUrl: previewUrl,
|
|
73
|
+
finalUrl: url.replace(matchFilerobotCdnUrlRegExp, previewUrl)
|
|
74
|
+
});
|
|
75
|
+
return url.replace(matchFilerobotCdnUrlRegExp, previewUrl);
|
|
76
|
+
}
|
|
77
|
+
debug();
|
|
78
|
+
return url;
|
|
79
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function to extract time from time stamp and convert into string as hh:mm e.g. 15:55
|
|
3
|
+
* @param {Number} timeStamp - sets the new date by adding the provided number of days for the current date
|
|
4
|
+
* @returns {String} - time in format HH:mm
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export default (function (timeStamp) {
|
|
8
|
+
return new Date(timeStamp).toLocaleTimeString().replace(/(.*)\D\d+/, '$1');
|
|
9
|
+
});
|
|
@@ -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 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
|
+
import getFileLink from '@scaleflex/widget-utils/lib/getFileLink';
|
|
8
|
+
import getFormattedPreviewUrl from '@scaleflex/widget-utils/lib/getFormattedPreviewUrl';
|
|
9
|
+
import { IMAGE_EDITOR_MODES } from './constants';
|
|
10
|
+
var getImageEditUrl = function getImageEditUrl(file) {
|
|
11
|
+
var _file$info;
|
|
12
|
+
var formattedPreviewOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
13
|
+
if (!file) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
var mode = formattedPreviewOptions.mode,
|
|
17
|
+
containerWidth = formattedPreviewOptions.containerWidth;
|
|
18
|
+
var isCloudimageMode = mode === IMAGE_EDITOR_MODES.CLOUDIMAGE;
|
|
19
|
+
var previewUrl = ((_file$info = file.info) === null || _file$info === void 0 ? void 0 : _file$info.preview) || file.preview;
|
|
20
|
+
var url = isCloudimageMode && previewUrl || getFileLink(file);
|
|
21
|
+
if (!url) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
url = getFormattedPreviewUrl(_objectSpread(_objectSpread({}, formattedPreviewOptions), {}, {
|
|
25
|
+
url: url
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
// Only for cloudimage mode, as regular mode we need the full image quality on saving to be saved in the expected resolution.
|
|
29
|
+
if (isCloudimageMode && !previewUrl) {
|
|
30
|
+
var _url, _file$info2, _file$info3;
|
|
31
|
+
var queryParamPrefixSymbol = (_url = url) !== null && _url !== void 0 && _url.includes('?') ? '&' : '?';
|
|
32
|
+
url = url && "".concat(url).concat(queryParamPrefixSymbol, "w=").concat(((_file$info2 = file.info) === null || _file$info2 === void 0 ? void 0 : _file$info2.img_w) >= containerWidth ? containerWidth : (_file$info3 = file.info) === null || _file$info3 === void 0 ? void 0 : _file$info3.img_w);
|
|
33
|
+
}
|
|
34
|
+
return url;
|
|
35
|
+
};
|
|
36
|
+
export default getImageEditUrl;
|
|
@@ -0,0 +1,25 @@
|
|
|
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 getImgFileDimensions = function getImgFileDimensions(imgFile) {
|
|
3
|
+
return new Promise(function (resolve) {
|
|
4
|
+
var isFileNotSrcString = _typeof(imgFile) === 'object';
|
|
5
|
+
var tempImgUrl = isFileNotSrcString ? URL.createObjectURL(imgFile) : imgFile;
|
|
6
|
+
var image = new Image();
|
|
7
|
+
image.src = tempImgUrl;
|
|
8
|
+
image.onload = function () {
|
|
9
|
+
resolve({
|
|
10
|
+
width: image.width,
|
|
11
|
+
height: image.height
|
|
12
|
+
});
|
|
13
|
+
if (isFileNotSrcString) {
|
|
14
|
+
URL.revokeObjectURL(tempImgUrl);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
image.onerror = function () {
|
|
18
|
+
console.warn("Error in recognizing image dimensions for: \"".concat(tempImgUrl, "\""));
|
|
19
|
+
if (isFileNotSrcString) {
|
|
20
|
+
URL.revokeObjectURL(tempImgUrl);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
export default getImgFileDimensions;
|
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
import getFileExtension from './getFileExtension';
|
|
8
|
+
import getFileLink from './getFileLink';
|
|
9
|
+
import isImage from './isImage';
|
|
10
|
+
import isThumbnailCloudimgSupported from './isThumbnailCloudimgSupported';
|
|
11
|
+
import isPdf from './isPdf';
|
|
12
|
+
import { FILE_TYPES_AND_ICONS, LAYOUTS_IDS, COLORS } from './constants';
|
|
13
|
+
import getItemPreviewWidthAndHeight from './getItemPreviewWidthHeight';
|
|
14
|
+
import isCloudimageFastPreviewSupported from './isCloudimageFastPreviewSupported';
|
|
15
|
+
import isFolder from './isFolder';
|
|
16
|
+
import isAi from './isAi';
|
|
17
|
+
import getFormattedPreviewUrl from './getFormattedPreviewUrl';
|
|
18
|
+
var ultrafastPrefix = 'https://scaleflex.ultrafast.io/';
|
|
19
|
+
var folderIcon = 'https://cdn.scaleflex.com/assets/folder-preview/folder.png';
|
|
20
|
+
var replaceAirstoreWithFilerobot = function replaceAirstoreWithFilerobot() {
|
|
21
|
+
var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
22
|
+
return url.replace('.airstore.io/', '.filerobot.com/').replace(/(\?|&)func=proxy&?/, '$1').replace(/(\?|&)$/, '');
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// showFuncAndHeight : false , when we need it to cover the entire background
|
|
26
|
+
var getItemIcon = function getItemIcon(_ref) {
|
|
27
|
+
var _fileOrFolder$info, _fileOrFolder$info2, _fileOrFolder$info3, _fileOrFolder$info4;
|
|
28
|
+
var fileOrFolder = _ref.fileOrFolder,
|
|
29
|
+
_ref$viewLayout = _ref.viewLayout,
|
|
30
|
+
viewLayout = _ref$viewLayout === void 0 ? LAYOUTS_IDS.GRID : _ref$viewLayout,
|
|
31
|
+
_ref$showFuncAndHeigh = _ref.showFuncAndHeight,
|
|
32
|
+
showFuncAndHeight = _ref$showFuncAndHeigh === void 0 ? false : _ref$showFuncAndHeigh,
|
|
33
|
+
forceIcon = _ref.forceIcon,
|
|
34
|
+
_ref$showWidth = _ref.showWidth,
|
|
35
|
+
showWidth = _ref$showWidth === void 0 ? true : _ref$showWidth,
|
|
36
|
+
showVideoGif = _ref.showVideoGif,
|
|
37
|
+
_ref$cloudimgFunc = _ref.cloudimgFunc,
|
|
38
|
+
cloudimgFunc = _ref$cloudimgFunc === void 0 ? '' : _ref$cloudimgFunc,
|
|
39
|
+
_ref$isImageTranspare = _ref.isImageTransparencySupported,
|
|
40
|
+
isImageTransparencySupported = _ref$isImageTranspare === void 0 ? false : _ref$isImageTranspare,
|
|
41
|
+
container = _ref.container,
|
|
42
|
+
isDevEnv = _ref.isDevEnv;
|
|
43
|
+
if (!fileOrFolder) {
|
|
44
|
+
return '';
|
|
45
|
+
}
|
|
46
|
+
if (fileOrFolder.preview && !forceIcon && !isImageTransparencySupported) {
|
|
47
|
+
return fileOrFolder.preview;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// TODO: if remote file then don't take its icon as it might not public till BE implements it
|
|
51
|
+
if (fileOrFolder.icon && !fileOrFolder.isRemote) {
|
|
52
|
+
return fileOrFolder.icon;
|
|
53
|
+
}
|
|
54
|
+
if (isFolder(fileOrFolder)) {
|
|
55
|
+
return folderIcon;
|
|
56
|
+
}
|
|
57
|
+
var thumbnail = (showVideoGif ? (fileOrFolder === null || fileOrFolder === void 0 ? void 0 : (_fileOrFolder$info = fileOrFolder.info) === null || _fileOrFolder$info === void 0 ? void 0 : _fileOrFolder$info.video_gif) || (fileOrFolder === null || fileOrFolder === void 0 ? void 0 : (_fileOrFolder$info2 = fileOrFolder.info) === null || _fileOrFolder$info2 === void 0 ? void 0 : _fileOrFolder$info2.video_thumbnail) : (fileOrFolder === null || fileOrFolder === void 0 ? void 0 : (_fileOrFolder$info3 = fileOrFolder.info) === null || _fileOrFolder$info3 === void 0 ? void 0 : _fileOrFolder$info3.video_thumbnail) || (fileOrFolder === null || fileOrFolder === void 0 ? void 0 : (_fileOrFolder$info4 = fileOrFolder.info) === null || _fileOrFolder$info4 === void 0 ? void 0 : _fileOrFolder$info4.image_thumbnail)) || (fileOrFolder === null || fileOrFolder === void 0 ? void 0 : fileOrFolder.thumbnail);
|
|
58
|
+
if (thumbnail) {
|
|
59
|
+
// replacing any thumbnail that has the airstore domain and replacing with filerobot domain
|
|
60
|
+
// to be able to apply cdn transformation
|
|
61
|
+
// new videos uploaded will have the filerobot domain
|
|
62
|
+
// so only apply this for the old videos
|
|
63
|
+
var newThumbnail = replaceAirstoreWithFilerobot(thumbnail);
|
|
64
|
+
if (container) {
|
|
65
|
+
newThumbnail = getFormattedPreviewUrl({
|
|
66
|
+
url: newThumbnail,
|
|
67
|
+
isDevEnv: isDevEnv,
|
|
68
|
+
containerToken: container
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
var _getItemPreviewWidthA = getItemPreviewWidthAndHeight(viewLayout),
|
|
72
|
+
_getItemPreviewWidthA2 = _slicedToArray(_getItemPreviewWidthA, 2),
|
|
73
|
+
width = _getItemPreviewWidthA2[0],
|
|
74
|
+
height = _getItemPreviewWidthA2[1];
|
|
75
|
+
return "".concat(newThumbnail, "?w=").concat(width, "&h=").concat(height);
|
|
76
|
+
}
|
|
77
|
+
var extension = getFileExtension(fileOrFolder);
|
|
78
|
+
if (isPdf(fileOrFolder) && !isAi(fileOrFolder)) {
|
|
79
|
+
var link = replaceAirstoreWithFilerobot(getFileLink(fileOrFolder));
|
|
80
|
+
if (link) {
|
|
81
|
+
link = link.replace('func=proxy', '');
|
|
82
|
+
var separator = link[link.length - 1] !== '&' && (link.lastIndexOf('?') !== -1 ? '&' : '?');
|
|
83
|
+
return "".concat(link).concat(separator || '', "w=200&force_format=webp,jpeg&doc_page=1&bypass_process_proxy=1");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (isThumbnailCloudimgSupported(fileOrFolder) || isImageTransparencySupported) {
|
|
87
|
+
var _fileOrFolder$url, _fileOrFolder$remote, _fileOrFolder$remote$;
|
|
88
|
+
// fileOrFolder.remote?.body?.url for having the url for imported image from url
|
|
89
|
+
var _link = replaceAirstoreWithFilerobot(getFileLink(fileOrFolder, (fileOrFolder === null || fileOrFolder === void 0 ? void 0 : (_fileOrFolder$url = fileOrFolder.url) === null || _fileOrFolder$url === void 0 ? void 0 : _fileOrFolder$url.version_preview_link) && 'version_preview_link', ((_fileOrFolder$remote = fileOrFolder.remote) === null || _fileOrFolder$remote === void 0 ? void 0 : (_fileOrFolder$remote$ = _fileOrFolder$remote.body) === null || _fileOrFolder$remote$ === void 0 ? void 0 : _fileOrFolder$remote$.url) || ''));
|
|
90
|
+
var bgColor = COLORS.LIGHT.HOVER.replace('#', '');
|
|
91
|
+
if (_link) {
|
|
92
|
+
// TODO: ADD A CDN URL THAT LOAD ANY URL FOR SUPPORTING RESIZED THUMBNAILS FROM OTHER 3RD PARTIES AS scaleflex.cloudimg.io HAS SPECIFIC DOMAINS.
|
|
93
|
+
// TMP SOLUTION FOR AVOIDING ADDING THE CDN'S QUERY PARAMS
|
|
94
|
+
// THAT CAUSE AN ERROR IN LOADING THE FILE OF CANVA DESIGN FROM THEIR URL
|
|
95
|
+
if (_link.startsWith('https://export-download.canva.com')) {
|
|
96
|
+
return _link;
|
|
97
|
+
}
|
|
98
|
+
var _separator = _link.lastIndexOf('?') !== -1 ? '&' : '?';
|
|
99
|
+
var _getItemPreviewWidthA3 = getItemPreviewWidthAndHeight(viewLayout),
|
|
100
|
+
_getItemPreviewWidthA4 = _slicedToArray(_getItemPreviewWidthA3, 2),
|
|
101
|
+
_width = _getItemPreviewWidthA4[0],
|
|
102
|
+
_height = _getItemPreviewWidthA4[1];
|
|
103
|
+
return "".concat(_link).concat(_separator || '').concat(showWidth ? "w=".concat(_width) : '').concat(showFuncAndHeight ? "&h=".concat(_height, "&func=").concat(cloudimgFunc || 'fit', "&bg_colour=").concat(bgColor) : '').concat(!isImage(fileOrFolder) ? '&bypass_process_proxy=1' : '').concat(isCloudimageFastPreviewSupported(fileOrFolder) ? '&ci_fast_preview=1' : '').replace('&&', '&').replace(/\?$/, '');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (extension) {
|
|
107
|
+
return FILE_TYPES_AND_ICONS[extension.toLowerCase()] || FILE_TYPES_AND_ICONS._default;
|
|
108
|
+
}
|
|
109
|
+
return FILE_TYPES_AND_ICONS._default;
|
|
110
|
+
};
|
|
111
|
+
export default getItemIcon;
|
|
112
|
+
export { ultrafastPrefix };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var getItemPath = function getItemPath(item) {
|
|
2
|
+
var _item$url;
|
|
3
|
+
if ((_item$url = item.url) !== null && _item$url !== void 0 && _item$url.path || item.path) {
|
|
4
|
+
var _item$url2;
|
|
5
|
+
var wholePath = ((_item$url2 = item.url) === null || _item$url2 === void 0 ? void 0 : _item$url2.path) || item.path;
|
|
6
|
+
var lastFolderSeparatorIndex = wholePath.lastIndexOf('/');
|
|
7
|
+
return wholePath.substr(0, lastFolderSeparatorIndex) || '/';
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
export default getItemPath;
|