@scaleflex/widget-utils 4.8.7 → 4.8.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/package.json +25 -25
  2. package/lib/AbortController.js +0 -20
  3. package/lib/BlurHash/base83.js +0 -10
  4. package/lib/BlurHash/decode.js +0 -80
  5. package/lib/BlurHash/error.js +0 -28
  6. package/lib/BlurHash/utils.js +0 -22
  7. package/lib/CustomDate.js +0 -157
  8. package/lib/EventTracker.js +0 -42
  9. package/lib/FOCUSABLE_ELEMENTS.js +0 -1
  10. package/lib/Timeframes/getDateRange.js +0 -45
  11. package/lib/addUrlParams.js +0 -27
  12. package/lib/adjustUpdatedFolders.js +0 -22
  13. package/lib/asyncTimeout.js +0 -6
  14. package/lib/audioMimeTypes.js +0 -3
  15. package/lib/blobToDataURI.js +0 -13
  16. package/lib/callIfFunction.js +0 -10
  17. package/lib/canEditVideo.js +0 -9
  18. package/lib/canvasToBlob.js +0 -18
  19. package/lib/capitalizeFirstLetter.js +0 -4
  20. package/lib/checkConnection.js +0 -4
  21. package/lib/checkFileOrFolderNameValidation.js +0 -4
  22. package/lib/checkIfPngSvgGIF.js +0 -3
  23. package/lib/checkImageIfPngJpegOrWebpOrAvif.js +0 -5
  24. package/lib/checkItemsSupportExportWithReason.js +0 -41
  25. package/lib/checkPermissions.js +0 -26
  26. package/lib/cloudimageSupportedInputMimeTypes.js +0 -2
  27. package/lib/clsx.js +0 -14
  28. package/lib/constants.js +0 -572
  29. package/lib/convertBytesToMb.js +0 -5
  30. package/lib/convertGbToBytes.js +0 -4
  31. package/lib/convertVideoFileTypeToSupported.js +0 -17
  32. package/lib/copyText.js +0 -25
  33. package/lib/createFolderVirtualPath.js +0 -14
  34. package/lib/createThunk.js +0 -350
  35. package/lib/customEncodeURIComponent.js +0 -47
  36. package/lib/dataURItoBlob.js +0 -33
  37. package/lib/dataURItoFile.js +0 -4
  38. package/lib/dateStrToClearDateTime.js +0 -20
  39. package/lib/debounce.js +0 -14
  40. package/lib/deepEqual.js +0 -23
  41. package/lib/deepMerge.js +0 -56
  42. package/lib/deserializeFunction.js +0 -23
  43. package/lib/documentMimeTypes.js +0 -2
  44. package/lib/downloadFromBlob.js +0 -16
  45. package/lib/emitSocketProgress.js +0 -18
  46. package/lib/escapeRegExp.js +0 -4
  47. package/lib/extractFileDataNoBlob.js +0 -12
  48. package/lib/fetchWithNetworkError.js +0 -14
  49. package/lib/fieldsQueriesGetters.js +0 -46
  50. package/lib/findAllDOMElements.js +0 -18
  51. package/lib/findAllRegexMatchesInString.js +0 -16
  52. package/lib/findDOMElement.js +0 -17
  53. package/lib/findIndex.js +0 -9
  54. package/lib/formatDuration.js +0 -22
  55. package/lib/formatNumbers.js +0 -32
  56. package/lib/formatResolution.js +0 -17
  57. package/lib/formatSeconds.js +0 -14
  58. package/lib/generateFileId.js +0 -53
  59. package/lib/generateI18nKeyFromString.js +0 -11
  60. package/lib/generatePsdThumbnail/adaptHexBoundries.js +0 -9
  61. package/lib/generatePsdThumbnail/bufferToHex.js +0 -12
  62. package/lib/generatePsdThumbnail/generatePsdThumbnail.js +0 -36
  63. package/lib/generatePsdThumbnail/generatePsdThumbnailBytes.js +0 -8
  64. package/lib/generatePsdThumbnail/generatePsdThumbnailHex.js +0 -4
  65. package/lib/generateSelectInputPlaceholder.js +0 -24
  66. package/lib/getActionErrorState.js +0 -17
  67. package/lib/getArraysMutualObjects.js +0 -12
  68. package/lib/getBytesRemaining.js +0 -9
  69. package/lib/getClientTimezone.js +0 -5
  70. package/lib/getCloudimagePrefixedUrl.js +0 -23
  71. package/lib/getDateDaysFromNow.js +0 -17
  72. package/lib/getDateMinusDay.js +0 -5
  73. package/lib/getDateString.js +0 -20
  74. package/lib/getDaysLeft.js +0 -9
  75. package/lib/getDecodedUriComponent.js +0 -10
  76. package/lib/getDownloadSpeed.js +0 -7
  77. package/lib/getDroppedFiles/index.js +0 -24
  78. package/lib/getDroppedFiles/utils/fallbackApi.js +0 -7
  79. package/lib/getDroppedFiles/utils/webkitGetAsEntryApi/getFilesAndDirectoriesFromDirectory.js +0 -36
  80. package/lib/getDroppedFiles/utils/webkitGetAsEntryApi/getRelativePath.js +0 -16
  81. package/lib/getDroppedFiles/utils/webkitGetAsEntryApi/index.js +0 -57
  82. package/lib/getEncodedWrappedUrl.js +0 -7
  83. package/lib/getFileAssetsTokenUrl.js +0 -14
  84. package/lib/getFileCdnLink.js +0 -6
  85. package/lib/getFileDefaultIcon.js +0 -14
  86. package/lib/getFileDetails.js +0 -81
  87. package/lib/getFileExtension.js +0 -32
  88. package/lib/getFileLink.js +0 -17
  89. package/lib/getFileNameAndExtension.js +0 -22
  90. package/lib/getFileType.js +0 -23
  91. package/lib/getFileTypeExtension.js +0 -22
  92. package/lib/getFilterFileFormatIcon.js +0 -6
  93. package/lib/getFolderDetails.js +0 -30
  94. package/lib/getFormattedPreviewUrl.js +0 -79
  95. package/lib/getHoursAndMinutes.js +0 -9
  96. package/lib/getImageEditUrl.js +0 -36
  97. package/lib/getImgFileDimensions.js +0 -25
  98. package/lib/getItemIcon.js +0 -112
  99. package/lib/getItemPath.js +0 -10
  100. package/lib/getItemPreviewWidthHeight.js +0 -10
  101. package/lib/getItemsSizeInBytes.js +0 -12
  102. package/lib/getJsonParsedValue.js +0 -11
  103. package/lib/metadata/checkFieldValidation.js +0 -51
  104. package/lib/metadata/generateItemMetadataState.js +0 -63
  105. package/lib/metadata/generateMetadataDefaultState.js +0 -30
  106. package/lib/metadata/getFileCustomMetadataGroups.js +0 -23
  107. package/lib/metadata/getGeoPointValidationErrors.js +0 -32
  108. package/lib/metadata/getMetaAttachmentFields.js +0 -9
  109. package/lib/metadata/getMetadataEmptyAssets.js +0 -28
  110. package/lib/metadata/getMetadataFieldGeoPointValue.js +0 -42
  111. package/lib/metadata/getMetadataFieldVariantValue.js +0 -31
  112. package/lib/metadata/getMetadataGroups.js +0 -16
  113. package/lib/metadata/getRequiredMetadataFields.js +0 -13
  114. package/lib/metadata/isM0LegacyMetaVersion.js +0 -5
  115. package/lib/metadata/isM1EdgyMetaVersion.js +0 -5
  116. package/lib/metadata/mapMetaAttachmentsObjsToUuids.js +0 -21
  117. package/lib/metadata/updateValidationErrors.js +0 -59
  118. package/lib/metadata/validateItemMetadata.js +0 -70
  119. package/lib/styledComponentsMixins/truncate.mixin.js +0 -8
@@ -1,112 +0,0 @@
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 };
@@ -1,10 +0,0 @@
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;
@@ -1,10 +0,0 @@
1
- import { LAYOUTS_IDS } from './constants';
2
- var getItemPreviewWidthAndHeight = function getItemPreviewWidthAndHeight(viewLayout) {
3
- var isListView = viewLayout === LAYOUTS_IDS.LIST;
4
- var baseWidth = isListView ? 100 : 200;
5
- var baseHeight = isListView ? 70 : 150;
6
- var width = parseInt(baseWidth * devicePixelRatio);
7
- var height = parseInt(baseHeight * devicePixelRatio);
8
- return [width, height];
9
- };
10
- export default getItemPreviewWidthAndHeight;
@@ -1,12 +0,0 @@
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 getItemsSizeInBytes = function getItemsSizeInBytes() {
3
- var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
4
- return items.reduce(function (totalItemsSize) {
5
- var _currentItem$size, _currentItem$size2;
6
- var currentItem = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
7
- var itemSize = ((_currentItem$size = currentItem.size) === null || _currentItem$size === void 0 ? void 0 : _currentItem$size.total_recursive_bytes) || ((_currentItem$size2 = currentItem.size) === null || _currentItem$size2 === void 0 ? void 0 : _currentItem$size2.bytes) || currentItem.total_recursive_bytes || _typeof(currentItem.size) !== 'object' && currentItem.size || 0;
8
- totalItemsSize += Number(itemSize);
9
- return totalItemsSize;
10
- }, 0);
11
- };
12
- export default getItemsSizeInBytes;
@@ -1,11 +0,0 @@
1
- // if the value is a possible (JSON string) then we need to parse it to JS object, if not and it's a real string or other type then return it.
2
- var getJsonParsedValue = function getJsonParsedValue(value) {
3
- var parsedValue = value;
4
- if (typeof parsedValue === 'string') {
5
- try {
6
- parsedValue = JSON.parse(parsedValue);
7
- } catch (e) {}
8
- }
9
- return parsedValue;
10
- };
11
- export default getJsonParsedValue;
@@ -1,51 +0,0 @@
1
- import getGeoPointValidationErrors from './getGeoPointValidationErrors';
2
- import isValidUri from '../isValidUri';
3
-
4
- /**
5
- * Check is metadata field value valid
6
- * @param {(string|number|array)} value
7
- * @param {string} [fieldValidation]
8
- * @param {boolean} [required]
9
- * @returns {(boolean|string)} - If TRUE field is valid, if FALSE or message field is not valid.
10
- * @param {boolean} [canEdit=true]
11
- */
12
- function checkFieldValidation(_ref) {
13
- var fieldValue = _ref.fieldValue,
14
- fieldValidation = _ref.fieldValidation,
15
- isFieldRequired = _ref.isFieldRequired,
16
- _ref$editable = _ref.editable,
17
- editable = _ref$editable === void 0 ? true : _ref$editable,
18
- i18n = _ref.i18n,
19
- fieldType = _ref.fieldType;
20
- if (isFieldRequired && editable && (!fieldValue || Array.isArray(fieldValue) && !fieldValue.length)) {
21
- return typeof i18n === 'function' ? i18n('mutualizedFieldRequired') : 'Field is required!';
22
- }
23
-
24
- /**
25
- * When field is required but current user can't edit the field, we have to set that current value is valid to unlock other fields save.
26
- */
27
- if (isFieldRequired && !editable) {
28
- return true;
29
- }
30
- if (fieldType === 'attachment-uri' && !isValidUri(fieldValue) && fieldValue) {
31
- return false;
32
- }
33
- if (fieldType === 'geopoint' && Object.keys(getGeoPointValidationErrors({
34
- geoPoint: fieldValue
35
- })).length > 0 && fieldValue) {
36
- return false;
37
- }
38
- if (!fieldValidation) {
39
- // If no fieldValidation rules return TRUE (field valid)
40
- return true;
41
- }
42
- if (typeof fieldValidation !== 'string') {
43
- console.warn('Metadata field validation: support string only!', {
44
- fieldValue: fieldValue,
45
- fieldValidation: fieldValidation
46
- });
47
- return true;
48
- }
49
- return new RegExp(fieldValidation).test(fieldValue) ? true : "String \"".concat(fieldValue, "\" not match regexp ").concat(fieldValidation);
50
- }
51
- export default checkFieldValidation;
@@ -1,63 +0,0 @@
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 generateMetadataDefaultState from '@scaleflex/widget-utils/lib/metadata/generateMetadataDefaultState';
8
-
9
- /**
10
- * @param {object[]} metaDataGroups
11
- * @param {object} item - File or folder
12
- * @param {object[]} metaRegionalGroups
13
- * @returns {object} - Item metadata state
14
- */
15
- export function generateItemMetadataState(metaDataGroups, item, metaRegionalGroups) {
16
- var defaultState = generateMetadataDefaultState(metaDataGroups, metaRegionalGroups);
17
- var itemMetadataState = _objectSpread(_objectSpread({}, defaultState), JSON.parse(JSON.stringify(item.meta || {})));
18
-
19
- /**
20
- * Sometimes we have cases when field had simple value like string (ex: {title: "My title"}) and then
21
- * field config was changed and now we have regional_variants. Now {title: {en: "Eng title", fr: "title"}}
22
- */
23
- (metaDataGroups || []).forEach(function (group) {
24
- ((group || {}).fields || []).forEach(function (field) {
25
- var _metaRegionalGroups$f;
26
- var fieldRegionalVariants = metaRegionalGroups === null || metaRegionalGroups === void 0 ? void 0 : (_metaRegionalGroups$f = metaRegionalGroups.find(function (group) {
27
- return group.uuid === (field === null || field === void 0 ? void 0 : field.regional_variants_group_uuid);
28
- })) === null || _metaRegionalGroups$f === void 0 ? void 0 : _metaRegionalGroups$f.variants;
29
- var fieldHasRegionalVars = (fieldRegionalVariants || []).length > 0;
30
- var isStateValueObject = _typeof(itemMetadataState[field.key]) === 'object' && !Array.isArray(itemMetadataState[field.key]) && itemMetadataState[field.key] !== null;
31
- if (fieldHasRegionalVars && !isStateValueObject || !fieldHasRegionalVars && isStateValueObject) {
32
- itemMetadataState[field.key] = defaultState[field.key];
33
- }
34
- if ((field === null || field === void 0 ? void 0 : field.type) === 'tags' && fieldHasRegionalVars) {
35
- // Fix bug https://sfx.li/6AGcWPsVyfZakK (also we need 2 fixed: BE and @scaleflex/ui)
36
- itemMetadataState[field.key] = itemMetadataState[field.key] || {};
37
- fieldRegionalVariants.forEach(function (regVar) {
38
- var _itemMetadataState$fi;
39
- var value = (_itemMetadataState$fi = itemMetadataState[field.key]) === null || _itemMetadataState$fi === void 0 ? void 0 : _itemMetadataState$fi[regVar === null || regVar === void 0 ? void 0 : regVar.api_value];
40
- itemMetadataState[field.key][regVar === null || regVar === void 0 ? void 0 : regVar.api_value] = adaptStringifiedArray(value);
41
- });
42
- }
43
- });
44
- });
45
- return itemMetadataState;
46
- }
47
- function adaptStringifiedArray(value) {
48
- if (value) {
49
- if (Array.isArray(value)) {
50
- return value;
51
- } else if (typeof value === 'string') {
52
- try {
53
- var arrayVal = JSON.parse(value);
54
- if (arrayVal && Array.isArray(arrayVal)) {
55
- return arrayVal;
56
- }
57
- } catch (error) {
58
- console.warn("Meta tag field has not valid value, must be an array but we receive \"".concat(value, "\""));
59
- }
60
- }
61
- }
62
- return [];
63
- }
@@ -1,30 +0,0 @@
1
- /**
2
- * @param {{fields: object}[]} metabaseGroups
3
- * @param {object[]} metaRegionalGroups
4
- * @returns {object}
5
- */
6
- function generateMetadataDefaultState(metabaseGroups, metaRegionalGroups) {
7
- var defaultMetadata = {};
8
- (metabaseGroups || []).forEach(function (group) {
9
- ((group || {}).fields || []).filter(function (field) {
10
- return field.key;
11
- }).forEach(function (field) {
12
- var _metaRegionalGroups$f;
13
- var value = typeof field.default_value !== 'undefined' ? field.default_value : ['tags', 'multi-select'].indexOf(field.type) > -1 ? [] : null;
14
- var fieldRegionalVariants = metaRegionalGroups === null || metaRegionalGroups === void 0 ? void 0 : (_metaRegionalGroups$f = metaRegionalGroups.find(function (group) {
15
- return group.uuid === (field === null || field === void 0 ? void 0 : field.regional_variants_group_uuid);
16
- })) === null || _metaRegionalGroups$f === void 0 ? void 0 : _metaRegionalGroups$f.variants;
17
- if (fieldRegionalVariants && Array.isArray(fieldRegionalVariants)) {
18
- defaultMetadata[field.key] = defaultMetadata[field.key] || {};
19
- fieldRegionalVariants.forEach(function (_ref) {
20
- var regionalVariantKey = _ref.api_value;
21
- defaultMetadata[field.key][regionalVariantKey] = value;
22
- });
23
- } else {
24
- defaultMetadata[field.key] = value;
25
- }
26
- });
27
- });
28
- return defaultMetadata;
29
- }
30
- export default generateMetadataDefaultState;
@@ -1,23 +0,0 @@
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 { METADATA_MODEL_TYPE_IDS } from '../constants';
8
- var getFileCustomMetadataGroup = function getFileCustomMetadataGroup(metadataModel) {
9
- var _metadataModel$filter;
10
- var customMetadataGroups = [];
11
- metadataModel === null || metadataModel === void 0 ? void 0 : (_metadataModel$filter = metadataModel.filter(function (_ref) {
12
- var appliesTo = _ref.applies_to;
13
- return appliesTo === METADATA_MODEL_TYPE_IDS.FILES;
14
- })) === null || _metadataModel$filter === void 0 ? void 0 : _metadataModel$filter.forEach(function (_ref2) {
15
- var _ref3;
16
- var groups = _ref2.groups;
17
- customMetadataGroups.push.apply(customMetadataGroups, _toConsumableArray((_ref3 = groups || []) === null || _ref3 === void 0 ? void 0 : _ref3.filter(function (group) {
18
- return !group.isRoot;
19
- })));
20
- });
21
- return customMetadataGroups;
22
- };
23
- export default getFileCustomMetadataGroup;
@@ -1,32 +0,0 @@
1
- import { MAX_LONGITUDE, MIN_LONGITUDE, MAX_LATITUDE, MIN_LATITUDE } from '@scaleflex/widget-common/lib/MetaData/MetaDataFieldTypes/MetadataGeoPointField/constants';
2
- import getMetadataFieldGeoPointValue from './getMetadataFieldGeoPointValue';
3
- var getGeoPointValidationErrors = function getGeoPointValidationErrors(_ref) {
4
- var _ref$geoPoint = _ref.geoPoint,
5
- geoPoint = _ref$geoPoint === void 0 ? '' : _ref$geoPoint,
6
- _ref$showDistanceFiel = _ref.showDistanceField,
7
- showDistanceField = _ref$showDistanceFiel === void 0 ? false : _ref$showDistanceFiel;
8
- if (!geoPoint || typeof geoPoint !== 'string') return {};
9
- var baseGeoPoint = geoPoint.replace('~', '');
10
- var errors = {};
11
- var _ref2 = getMetadataFieldGeoPointValue(baseGeoPoint, showDistanceField) || {},
12
- longitude = _ref2.longitude,
13
- latitude = _ref2.latitude,
14
- distance = _ref2.distance;
15
- if (!longitude && !latitude) {
16
- return errors;
17
- }
18
- var longitudeNum = Number(longitude);
19
- var latitudeNum = Number(latitude);
20
- var isLongitudeValid = longitudeNum >= MIN_LONGITUDE && longitudeNum <= MAX_LONGITUDE;
21
- var isLatitudeValid = latitudeNum >= MIN_LATITUDE && latitudeNum <= MAX_LATITUDE;
22
- if (showDistanceField && !distance) errors.distance = 'metadataDistanceGeoPointFieldError';
23
- if (!isLongitudeValid) errors.longitude = 'metadataLongitudeGeoPointLimitFieldError';
24
- if (!isLatitudeValid) errors.latitude = 'metadataLatitudeGeoPointLimitFieldError';
25
- if (!longitude || !latitude) {
26
- if (!longitude) errors.longitude = 'metadataLongitudeGeoPointFieldError';
27
- if (!latitude) errors.latitude = 'metadataLatitudeGeoPointFieldError';
28
- return errors;
29
- }
30
- return errors;
31
- };
32
- export default getGeoPointValidationErrors;
@@ -1,9 +0,0 @@
1
- var getMetaAttachmentFields = function getMetaAttachmentFields(customMetadataGroups) {
2
- return customMetadataGroups.reduce(function (acc, curr) {
3
- var filteredFields = curr.fields.filter(function (field) {
4
- return field.type === 'attachments-assets';
5
- });
6
- return acc.concat(filteredFields);
7
- }, []);
8
- };
9
- export default getMetaAttachmentFields;
@@ -1,28 +0,0 @@
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 isAssetHasMetadataValue = function isAssetHasMetadataValue(value) {
3
- return Array.isArray(value) && value.length || _typeof(value) === 'object' && Object.keys(value || {}).length || typeof value === 'string' && value.length;
4
- };
5
- var getEmptyAssets = function getEmptyAssets(requiredMetadataFields, assets) {
6
- return assets.filter(function (_ref) {
7
- var _ref$meta = _ref.meta,
8
- meta = _ref$meta === void 0 ? {} : _ref$meta;
9
- return requiredMetadataFields.some(function (_ref2) {
10
- var key = _ref2.key;
11
- return !isAssetHasMetadataValue(meta[key]);
12
- });
13
- });
14
- };
15
- var getMetadataEmptyAssets = function getMetadataEmptyAssets(requiredMetadataFields, assets) {
16
- return requiredMetadataFields.reduce(function (acc, curr) {
17
- var assetsHaveEmptyMetadata = assets.filter(function (_ref3) {
18
- var _ref3$meta = _ref3.meta,
19
- meta = _ref3$meta === void 0 ? {} : _ref3$meta;
20
- return !isAssetHasMetadataValue(meta[curr.key]);
21
- });
22
- if (assetsHaveEmptyMetadata.length) {
23
- acc[curr.key] = assetsHaveEmptyMetadata;
24
- }
25
- return acc;
26
- }, {});
27
- };
28
- export { getEmptyAssets, isAssetHasMetadataValue, getMetadataEmptyAssets };
@@ -1,42 +0,0 @@
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 _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; }
11
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
12
- 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); }
13
- import { REMOVE_PARENTHESES_REGEX } from '@scaleflex/widget-common/lib/MetaData/MetaDataFieldTypes/MetadataGeoPointField/constants';
14
- var getMetadataFieldGeoPointValue = function getMetadataFieldGeoPointValue(value) {
15
- var showDistanceField = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
16
- if (!value) return _objectSpread({
17
- latitude: '',
18
- longitude: ''
19
- }, showDistanceField && {
20
- distance: ''
21
- });
22
- var _value$split = value.split('..'),
23
- _value$split2 = _slicedToArray(_value$split, 2),
24
- geoPart = _value$split2[0],
25
- _value$split2$ = _value$split2[1],
26
- distance = _value$split2$ === void 0 ? '' : _value$split2$;
27
- var _geoPart$replace$spli = geoPart.replace(REMOVE_PARENTHESES_REGEX, '').split(','),
28
- _geoPart$replace$spli2 = _slicedToArray(_geoPart$replace$spli, 2),
29
- _geoPart$replace$spli3 = _geoPart$replace$spli2[0],
30
- latitude = _geoPart$replace$spli3 === void 0 ? '' : _geoPart$replace$spli3,
31
- _geoPart$replace$spli4 = _geoPart$replace$spli2[1],
32
- longitude = _geoPart$replace$spli4 === void 0 ? '' : _geoPart$replace$spli4;
33
- return showDistanceField ? {
34
- latitude: latitude,
35
- longitude: longitude,
36
- distance: distance
37
- } : {
38
- latitude: latitude,
39
- longitude: longitude
40
- };
41
- };
42
- export default getMetadataFieldGeoPointValue;
@@ -1,31 +0,0 @@
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 getJsonParsedValue from '@scaleflex/widget-utils/lib/getJsonParsedValue';
3
- var checkFieldVariantValue = function checkFieldVariantValue(value, possibleValues) {
4
- var _possibleValues$filte, _possibleValues$find;
5
- return Array.isArray(value) ? possibleValues === null || possibleValues === void 0 ? void 0 : (_possibleValues$filte = possibleValues.filter(function (element) {
6
- return value.includes(element === null || element === void 0 ? void 0 : element.internal_unique_value);
7
- })) === null || _possibleValues$filte === void 0 ? void 0 : _possibleValues$filte.map(function (selectedVal) {
8
- return selectedVal === null || selectedVal === void 0 ? void 0 : selectedVal.label;
9
- }) : possibleValues === null || possibleValues === void 0 ? void 0 : (_possibleValues$find = possibleValues.find(function (possibleValue) {
10
- return (possibleValue === null || possibleValue === void 0 ? void 0 : possibleValue.internal_unique_value) === value;
11
- })) === null || _possibleValues$find === void 0 ? void 0 : _possibleValues$find.label;
12
- };
13
- var getMetadataFieldVariantValue = function getMetadataFieldVariantValue(_ref) {
14
- var value = _ref.value,
15
- possibleValues = _ref.possibleValues,
16
- regionalVariantsGroupUuid = _ref.regionalVariantsGroupUuid,
17
- _ref$metaRegionalFilt = _ref.metaRegionalFilters,
18
- metaRegionalFilters = _ref$metaRegionalFilt === void 0 ? {} : _ref$metaRegionalFilt,
19
- _ref$joinArrayValues = _ref.joinArrayValues,
20
- joinArrayValues = _ref$joinArrayValues === void 0 ? false : _ref$joinArrayValues;
21
- var parsedValue = getJsonParsedValue(value);
22
- if (regionalVariantsGroupUuid) {
23
- return parsedValue[metaRegionalFilters === null || metaRegionalFilters === void 0 ? void 0 : metaRegionalFilters[regionalVariantsGroupUuid]] || (_typeof(parsedValue) === 'object' ? '' : parsedValue);
24
- }
25
- if (possibleValues && possibleValues.length > 0) {
26
- var fieldVariantValue = checkFieldVariantValue(value, possibleValues);
27
- return joinArrayValues && Array.isArray(fieldVariantValue) ? fieldVariantValue.join(', ') : fieldVariantValue;
28
- }
29
- return (value === null || value === void 0 ? void 0 : value.constructor) === Object ? JSON.stringify(value) : value;
30
- };
31
- export default getMetadataFieldVariantValue;
@@ -1,16 +0,0 @@
1
- import { METADATA_MODEL_TYPE_IDS } from '@scaleflex/widget-utils/lib/constants';
2
- var getMetadataGroups = function getMetadataGroups(metadataModel) {
3
- var metaModelType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : METADATA_MODEL_TYPE_IDS.FILES;
4
- var isRootOnly = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
5
- var model = (metadataModel || []).find(function (model) {
6
- return model.applies_to === metaModelType;
7
- }) || {};
8
- var groups = ((model === null || model === void 0 ? void 0 : model.groups) || []).filter(function (group) {
9
- return group && (group.fields || []).length > 0;
10
- });
11
- return isRootOnly ? groups.filter(function (_ref) {
12
- var isRoot = _ref.isRoot;
13
- return isRoot;
14
- }) : groups;
15
- };
16
- export default getMetadataGroups;
@@ -1,13 +0,0 @@
1
- var getRequiredMetadataFields = function getRequiredMetadataFields() {
2
- var metadataGroups = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
3
- return metadataGroups.reduce(function (acc, curr) {
4
- var fields = curr.fields || [];
5
- fields.forEach(function (field) {
6
- if (field.required) {
7
- acc.push(field);
8
- }
9
- });
10
- return acc;
11
- }, []);
12
- };
13
- export default getRequiredMetadataFields;
@@ -1,5 +0,0 @@
1
- import { METADATA_VERSIONS } from '../constants';
2
- var isM0LegacyMetaVersion = function isM0LegacyMetaVersion(metadataVersion) {
3
- return metadataVersion === METADATA_VERSIONS.M0_LEGACY;
4
- };
5
- export default isM0LegacyMetaVersion;
@@ -1,5 +0,0 @@
1
- import { METADATA_VERSIONS } from '../constants';
2
- var isM1EdgyMetaVersion = function isM1EdgyMetaVersion(metadataVersion) {
3
- return metadataVersion === METADATA_VERSIONS.M1_EDGY;
4
- };
5
- export default isM1EdgyMetaVersion;
@@ -1,21 +0,0 @@
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 getMetaAttachmentFields from './getMetaAttachmentFields';
3
- var mapMetaAttachmentsObjsToUuids = function mapMetaAttachmentsObjsToUuids(_ref) {
4
- var meta = _ref.meta,
5
- _ref$customMetadataGr = _ref.customMetadataGroups,
6
- customMetadataGroups = _ref$customMetadataGr === void 0 ? [] : _ref$customMetadataGr;
7
- var attachmentsAssetsFields = getMetaAttachmentFields(customMetadataGroups);
8
- attachmentsAssetsFields.forEach(function (_ref2) {
9
- var key = _ref2.key;
10
- var attachmentAssetsValue = meta[key] || [];
11
- var attachmentAssetsArray = attachmentAssetsValue.map(function (item) {
12
- if (_typeof(item) === 'object') {
13
- return item.uuid;
14
- }
15
- return item;
16
- });
17
- meta[key] = attachmentAssetsArray;
18
- });
19
- return meta;
20
- };
21
- export default mapMetaAttachmentsObjsToUuids;
@@ -1,59 +0,0 @@
1
- import checkFieldValidation from './checkFieldValidation';
2
-
3
- /**
4
- * @param {object} errors
5
- * @param {string} key
6
- * @param {string} [regionalVariantFieldKey]
7
- * @param {any} fieldValue
8
- * @param {regexp} [fieldValidation]
9
- * @param {boolean} [isFieldRequired]
10
- * @param {(boolean|string[])} [canEdit=true]
11
- */
12
- function updateValidationErrors(_ref) {
13
- var errors = _ref.errors,
14
- key = _ref.key,
15
- regionalVariantFieldKey = _ref.regionalVariantFieldKey,
16
- fieldValue = _ref.fieldValue,
17
- fieldValidation = _ref.fieldValidation,
18
- isFieldRequired = _ref.isFieldRequired,
19
- _ref$canEdit = _ref.canEdit,
20
- canEdit = _ref$canEdit === void 0 ? true : _ref$canEdit,
21
- i18n = _ref.i18n,
22
- fieldType = _ref.fieldType;
23
- var errorsClone = JSON.parse(JSON.stringify(errors || {}));
24
- var editable = canEdit === true || regionalVariantFieldKey && Array.isArray(canEdit) && canEdit.indexOf(regionalVariantFieldKey) > -1;
25
- var isValid = checkFieldValidation({
26
- fieldValue: fieldValue,
27
- fieldValidation: fieldValidation,
28
- isFieldRequired: isFieldRequired,
29
- editable: editable,
30
- i18n: i18n,
31
- fieldType: fieldType
32
- });
33
- if (isValid === true) {
34
- // Valid, remove error
35
- if (regionalVariantFieldKey) {
36
- if (errorsClone[key] && Object.prototype.hasOwnProperty.call(errorsClone[key], regionalVariantFieldKey)) {
37
- delete errorsClone[key][regionalVariantFieldKey];
38
- if (!Object.keys(errorsClone[key]).length) {
39
- // Object empty, need to remove
40
- delete errorsClone[key];
41
- }
42
- }
43
- } else {
44
- if (Object.prototype.hasOwnProperty.call(errorsClone, key)) {
45
- delete errorsClone[key];
46
- }
47
- }
48
- } else {
49
- // Not valid, add error
50
- if (regionalVariantFieldKey) {
51
- errorsClone[key] = errorsClone[key] || {};
52
- errorsClone[key][regionalVariantFieldKey] = isValid || true;
53
- } else {
54
- errorsClone[key] = isValid || true;
55
- }
56
- }
57
- return errorsClone;
58
- }
59
- export default updateValidationErrors;