@contentful/field-editor-reference 2.20.9 → 2.20.10
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/dist/field-editor-reference.cjs.development.js +1 -67
- package/dist/field-editor-reference.cjs.development.js.map +1 -1
- package/dist/field-editor-reference.cjs.production.min.js +1 -1
- package/dist/field-editor-reference.cjs.production.min.js.map +1 -1
- package/dist/field-editor-reference.esm.js +1 -67
- package/dist/field-editor-reference.esm.js.map +1 -1
- package/package.json +2 -2
- package/dist/assets/WrappedAssetCard/shortenStorageUnit.d.ts +0 -17
|
@@ -5,7 +5,7 @@ import tokens from '@contentful/forma-36-tokens';
|
|
|
5
5
|
import get from 'lodash-es/get';
|
|
6
6
|
import moment from 'moment';
|
|
7
7
|
import deepEqual from 'deep-equal';
|
|
8
|
-
import { FieldConnector, isValidImage, entityHelpers } from '@contentful/field-editor-shared';
|
|
8
|
+
import { FieldConnector, isValidImage, entityHelpers, shortenStorageUnit } from '@contentful/field-editor-shared';
|
|
9
9
|
import constate from 'constate';
|
|
10
10
|
import isNumber from 'lodash-es/isNumber';
|
|
11
11
|
import arrayMove from 'array-move';
|
|
@@ -2993,72 +2993,6 @@ function MultipleEntryReferenceEditor(props) {
|
|
|
2993
2993
|
});
|
|
2994
2994
|
}
|
|
2995
2995
|
|
|
2996
|
-
/**
|
|
2997
|
-
* Transforms a number into a localized string (en-US)
|
|
2998
|
-
* toLocaleString(1000); // "1,000"
|
|
2999
|
-
* @param {Number} number
|
|
3000
|
-
*/
|
|
3001
|
-
function toLocaleString(number) {
|
|
3002
|
-
return number.toLocaleString('en-US');
|
|
3003
|
-
}
|
|
3004
|
-
|
|
3005
|
-
function formatFloat(value, localize) {
|
|
3006
|
-
return localize ? toLocaleString(value) : value.toFixed(2) // remove floating point if not necessary
|
|
3007
|
-
.replace(/\.(0)*$|0*$/, '');
|
|
3008
|
-
}
|
|
3009
|
-
/**
|
|
3010
|
-
* Make a storage unit number more readable by making them smaller
|
|
3011
|
-
* shortenStorageUnit(1000, 'GB'); // "1 TB"
|
|
3012
|
-
* shortenStorageUnit(0.001, 'TB'); // "1 GB"
|
|
3013
|
-
* @param value
|
|
3014
|
-
* @param uom Unit of measure
|
|
3015
|
-
* @returns
|
|
3016
|
-
*/
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
function shortenStorageUnit(value, uom) {
|
|
3020
|
-
if (value <= 0) {
|
|
3021
|
-
return '0 B';
|
|
3022
|
-
}
|
|
3023
|
-
|
|
3024
|
-
var units = ['PB', 'TB', 'GB', 'MB', 'KB', 'B'];
|
|
3025
|
-
|
|
3026
|
-
var getBigger = function getBigger(unit) {
|
|
3027
|
-
return units[units.indexOf(unit) - 1];
|
|
3028
|
-
};
|
|
3029
|
-
|
|
3030
|
-
var getSmaller = function getSmaller(unit) {
|
|
3031
|
-
return units[units.indexOf(unit) + 1];
|
|
3032
|
-
};
|
|
3033
|
-
|
|
3034
|
-
var isBiggestUnit = function isBiggestUnit(unit) {
|
|
3035
|
-
return units.indexOf(unit) === 0;
|
|
3036
|
-
};
|
|
3037
|
-
|
|
3038
|
-
var isSmallestUnit = function isSmallestUnit(unit) {
|
|
3039
|
-
return units.indexOf(unit) === units.length - 1;
|
|
3040
|
-
};
|
|
3041
|
-
|
|
3042
|
-
var reduce = function reduce(number, unit) {
|
|
3043
|
-
if (number < 0.99 && !isSmallestUnit(unit)) {
|
|
3044
|
-
return reduce(number * 1000, getSmaller(unit));
|
|
3045
|
-
} else if (number >= 1000 && !isBiggestUnit(unit)) {
|
|
3046
|
-
return reduce(number / 1000, getBigger(unit));
|
|
3047
|
-
} else {
|
|
3048
|
-
return {
|
|
3049
|
-
number: number,
|
|
3050
|
-
unit: unit
|
|
3051
|
-
};
|
|
3052
|
-
}
|
|
3053
|
-
};
|
|
3054
|
-
|
|
3055
|
-
var _reduce = reduce(value, uom),
|
|
3056
|
-
number = _reduce.number,
|
|
3057
|
-
unit = _reduce.unit;
|
|
3058
|
-
|
|
3059
|
-
return formatFloat(number, false) + " " + unit;
|
|
3060
|
-
}
|
|
3061
|
-
|
|
3062
2996
|
var styles$4 = {
|
|
3063
2997
|
cardDropdown: /*#__PURE__*/css({
|
|
3064
2998
|
width: '300px'
|