@contentful/field-editor-shared 0.23.0 → 0.26.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 CHANGED
@@ -3,165 +3,118 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- # [0.23.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.22.1...@contentful/field-editor-shared@0.23.0) (2021-09-16)
7
-
6
+ # [0.26.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.25.1...@contentful/field-editor-shared@0.26.0) (2021-11-04)
8
7
 
9
8
  ### Features
10
9
 
11
- * export shared util to validate images ([#846](https://github.com/contentful/field-editors/issues/846)) ([f26c481](https://github.com/contentful/field-editors/commit/f26c481cc5abf275acb4e4a65b462be487708117))
12
-
10
+ - Forma v4 components adoption ([#805](https://github.com/contentful/field-editors/issues/805)) ([526bde6](https://github.com/contentful/field-editors/commit/526bde6e10e0ee3789705ec10fb31489af7ca59e))
13
11
 
12
+ ### BREAKING CHANGES
14
13
 
14
+ - adopts a new Forma v4 beta
15
15
 
16
+ ## [0.25.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.25.0...@contentful/field-editor-shared@0.25.1) (2021-10-14)
16
17
 
17
- ## [0.22.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.22.0...@contentful/field-editor-shared@0.22.1) (2021-08-19)
18
-
18
+ **Note:** Version bump only for package @contentful/field-editor-shared
19
19
 
20
- ### Bug Fixes
20
+ # [0.25.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.24.0...@contentful/field-editor-shared@0.25.0) (2021-10-06)
21
21
 
22
- * FieldConnector setValue race conditions ([#803](https://github.com/contentful/field-editors/issues/803)) ([15a5aa6](https://github.com/contentful/field-editors/commit/15a5aa68a6f3f6c7183444c8fd11de1e70208aa7))
22
+ ### Features
23
23
 
24
+ - [EXT-3161] bump app sdk to v4 ([#881](https://github.com/contentful/field-editors/issues/881)) ([9c4a2af](https://github.com/contentful/field-editors/commit/9c4a2af07da203d59fb5f15c3a5188ecc64b1d44))
24
25
 
26
+ # [0.24.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.23.0...@contentful/field-editor-shared@0.24.0) (2021-09-17)
25
27
 
28
+ ### Features
26
29
 
30
+ - add shortenStorageUnit util to shared ([#852](https://github.com/contentful/field-editors/issues/852)) ([142472b](https://github.com/contentful/field-editors/commit/142472b57fc1ca2843dd414c5320fdb5b5b11e62))
27
31
 
28
- # [0.22.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.21.0...@contentful/field-editor-shared@0.22.0) (2021-07-23)
29
-
32
+ # [0.23.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.22.1...@contentful/field-editor-shared@0.23.0) (2021-09-16)
30
33
 
31
34
  ### Features
32
35
 
33
- * 💡 new color tokens ([#778](https://github.com/contentful/field-editors/issues/778)) ([fba548d](https://github.com/contentful/field-editors/commit/fba548de32305016df7f2685634eefb14294828f))
34
-
35
-
36
+ - export shared util to validate images ([#846](https://github.com/contentful/field-editors/issues/846)) ([f26c481](https://github.com/contentful/field-editors/commit/f26c481cc5abf275acb4e4a65b462be487708117))
36
37
 
38
+ ## [0.22.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.22.0...@contentful/field-editor-shared@0.22.1) (2021-08-19)
37
39
 
40
+ ### Bug Fixes
38
41
 
39
- # [0.21.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.18.0...@contentful/field-editor-shared@0.21.0) (2021-07-06)
42
+ - FieldConnector setValue race conditions ([#803](https://github.com/contentful/field-editors/issues/803)) ([15a5aa6](https://github.com/contentful/field-editors/commit/15a5aa68a6f3f6c7183444c8fd11de1e70208aa7))
40
43
 
44
+ # [0.22.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.21.0...@contentful/field-editor-shared@0.22.0) (2021-07-23)
41
45
 
42
46
  ### Features
43
47
 
44
- * [] bump forma tokens ([#756](https://github.com/contentful/field-editors/issues/756)) ([befc60f](https://github.com/contentful/field-editors/commit/befc60f9f495b0d1e072e9cba969d139da8f674a))
45
-
48
+ - 💡 new color tokens ([#778](https://github.com/contentful/field-editors/issues/778)) ([fba548d](https://github.com/contentful/field-editors/commit/fba548de32305016df7f2685634eefb14294828f))
46
49
 
50
+ # [0.21.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.18.0...@contentful/field-editor-shared@0.21.0) (2021-07-06)
47
51
 
52
+ ### Features
48
53
 
54
+ - [] bump forma tokens ([#756](https://github.com/contentful/field-editors/issues/756)) ([befc60f](https://github.com/contentful/field-editors/commit/befc60f9f495b0d1e072e9cba969d139da8f674a))
49
55
 
50
56
  # [0.20.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.18.0...@contentful/field-editor-shared@0.20.0) (2021-07-06)
51
57
 
52
-
53
58
  ### Features
54
59
 
55
- * [] bump forma tokens ([#756](https://github.com/contentful/field-editors/issues/756)) ([befc60f](https://github.com/contentful/field-editors/commit/befc60f9f495b0d1e072e9cba969d139da8f674a))
56
-
57
-
58
-
59
-
60
+ - [] bump forma tokens ([#756](https://github.com/contentful/field-editors/issues/756)) ([befc60f](https://github.com/contentful/field-editors/commit/befc60f9f495b0d1e072e9cba969d139da8f674a))
60
61
 
61
62
  # [0.19.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.18.0...@contentful/field-editor-shared@0.19.0) (2021-06-23)
62
63
 
63
-
64
64
  ### Features
65
65
 
66
- * [] bump forma tokens ([#756](https://github.com/contentful/field-editors/issues/756)) ([befc60f](https://github.com/contentful/field-editors/commit/befc60f9f495b0d1e072e9cba969d139da8f674a))
67
-
68
-
69
-
70
-
66
+ - [] bump forma tokens ([#756](https://github.com/contentful/field-editors/issues/756)) ([befc60f](https://github.com/contentful/field-editors/commit/befc60f9f495b0d1e072e9cba969d139da8f674a))
71
67
 
72
68
  # [0.18.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.17.0...@contentful/field-editor-shared@0.18.0) (2021-06-23)
73
69
 
74
-
75
70
  ### Features
76
71
 
77
- * [] bump app sdk ([#755](https://github.com/contentful/field-editors/issues/755)) ([aa0c217](https://github.com/contentful/field-editors/commit/aa0c2179d4edbb1a37453e1e3bdf0ae11991166f))
78
-
79
-
80
-
81
-
72
+ - [] bump app sdk ([#755](https://github.com/contentful/field-editors/issues/755)) ([aa0c217](https://github.com/contentful/field-editors/commit/aa0c2179d4edbb1a37453e1e3bdf0ae11991166f))
82
73
 
83
74
  # [0.17.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.16.0...@contentful/field-editor-shared@0.17.0) (2021-06-22)
84
75
 
85
-
86
76
  ### Features
87
77
 
88
- * [EXT-2826] make app-sdk a peer depedency ([#748](https://github.com/contentful/field-editors/issues/748)) ([f1d1d01](https://github.com/contentful/field-editors/commit/f1d1d01d89d59d70ab2c831a513ab2580ea64d7e))
89
-
90
-
91
-
92
-
78
+ - [EXT-2826] make app-sdk a peer depedency ([#748](https://github.com/contentful/field-editors/issues/748)) ([f1d1d01](https://github.com/contentful/field-editors/commit/f1d1d01d89d59d70ab2c831a513ab2580ea64d7e))
93
79
 
94
80
  # [0.16.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.15.1...@contentful/field-editor-shared@0.16.0) (2021-02-19)
95
81
 
96
-
97
82
  ### Features
98
83
 
99
- * bump min version of forma-36 ([#606](https://github.com/contentful/field-editors/issues/606)) ([fd57c7a](https://github.com/contentful/field-editors/commit/fd57c7a4312766af38c01507f17706ab22992617))
100
-
101
-
102
-
103
-
84
+ - bump min version of forma-36 ([#606](https://github.com/contentful/field-editors/issues/606)) ([fd57c7a](https://github.com/contentful/field-editors/commit/fd57c7a4312766af38c01507f17706ab22992617))
104
85
 
105
86
  ## [0.15.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.15.0...@contentful/field-editor-shared@0.15.1) (2021-02-09)
106
87
 
107
-
108
88
  ### Bug Fixes
109
89
 
110
- * **tags:** Editor permissions handles entities with metadata ([#584](https://github.com/contentful/field-editors/issues/584)) ([32636da](https://github.com/contentful/field-editors/commit/32636daf05e0ba9abb47eafe9893850db2c6601f))
111
-
112
-
113
-
114
-
90
+ - **tags:** Editor permissions handles entities with metadata ([#584](https://github.com/contentful/field-editors/issues/584)) ([32636da](https://github.com/contentful/field-editors/commit/32636daf05e0ba9abb47eafe9893850db2c6601f))
115
91
 
116
92
  # [0.15.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.14.0...@contentful/field-editor-shared@0.15.0) (2021-02-01)
117
93
 
118
-
119
94
  ### Features
120
95
 
121
- * swap ui-extension-sdk to app-sdk ([#576](https://github.com/contentful/field-editors/issues/576)) ([ac88b4b](https://github.com/contentful/field-editors/commit/ac88b4bd4573a72f521246fc8fcc873520ca90d4))
122
-
123
-
124
-
125
-
96
+ - swap ui-extension-sdk to app-sdk ([#576](https://github.com/contentful/field-editors/issues/576)) ([ac88b4b](https://github.com/contentful/field-editors/commit/ac88b4bd4573a72f521246fc8fcc873520ca90d4))
126
97
 
127
98
  # [0.14.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.13.3...@contentful/field-editor-shared@0.14.0) (2021-01-20)
128
99
 
129
-
130
100
  ### Features
131
101
 
132
- * update minimal forma-36 versions to use updated design ([#565](https://github.com/contentful/field-editors/issues/565)) ([332c734](https://github.com/contentful/field-editors/commit/332c734bfaf54f0e9773fcbb460d743b1f5459ec))
133
-
134
-
135
-
136
-
102
+ - update minimal forma-36 versions to use updated design ([#565](https://github.com/contentful/field-editors/issues/565)) ([332c734](https://github.com/contentful/field-editors/commit/332c734bfaf54f0e9773fcbb460d743b1f5459ec))
137
103
 
138
104
  ## [0.13.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.13.2...@contentful/field-editor-shared@0.13.3) (2021-01-12)
139
105
 
140
106
  **Note:** Version bump only for package @contentful/field-editor-shared
141
107
 
142
-
143
-
144
-
145
-
146
108
  ## [0.13.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.13.1...@contentful/field-editor-shared@0.13.2) (2020-12-16)
147
109
 
148
110
  **Note:** Version bump only for package @contentful/field-editor-shared
149
111
 
150
-
151
-
152
-
153
-
154
112
  ## [0.13.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.13.0...@contentful/field-editor-shared@0.13.1) (2020-11-06)
155
113
 
156
114
  **Note:** Version bump only for package @contentful/field-editor-shared
157
115
 
158
-
159
-
160
-
161
-
162
116
  # [0.13.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.12.0...@contentful/field-editor-shared@0.13.0) (2020-08-24)
163
117
 
164
-
165
118
  ### Features
166
119
 
167
- * extract field component to default-field-editors package ([#365](https://github.com/contentful/field-editors/issues/365)) ([eb78219](https://github.com/contentful/field-editors/commit/eb78219d52c3dcfb91824f3106f44312aaaf1f8e))
120
+ - extract field component to default-field-editors package ([#365](https://github.com/contentful/field-editors/issues/365)) ([eb78219](https://github.com/contentful/field-editors/commit/eb78219d52c3dcfb91824f3106f44312aaaf1f8e))
@@ -1,6 +1,6 @@
1
1
  /// <reference types="lodash" />
2
2
  import React from 'react';
3
- import { FieldAPI } from '@contentful/app-sdk';
3
+ import { FieldAPI, ValidationError } from '@contentful/app-sdk';
4
4
  declare type Nullable = null | undefined;
5
5
  export interface FieldConnectorChildProps<ValueType> {
6
6
  isLocalValueChange: boolean;
@@ -8,7 +8,7 @@ export interface FieldConnectorChildProps<ValueType> {
8
8
  lastRemoteValue: ValueType | Nullable;
9
9
  value: ValueType | Nullable;
10
10
  disabled: boolean;
11
- errors: Error[];
11
+ errors: ValidationError[];
12
12
  setValue: (value: ValueType | Nullable) => Promise<unknown>;
13
13
  }
14
14
  interface FieldConnectorState<ValueType> {
@@ -17,7 +17,7 @@ interface FieldConnectorState<ValueType> {
17
17
  lastRemoteValue: ValueType | Nullable;
18
18
  value: ValueType | Nullable;
19
19
  disabled: boolean;
20
- errors: Error[];
20
+ errors: ValidationError[];
21
21
  }
22
22
  interface FieldConnectorProps<ValueType> {
23
23
  field: FieldAPI;
@@ -7,11 +7,12 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
7
7
  var React = _interopDefault(require('react'));
8
8
  var isEqual = _interopDefault(require('lodash/isEqual'));
9
9
  var throttle = _interopDefault(require('lodash/throttle'));
10
- var forma36ReactComponents = require('@contentful/forma-36-react-components');
11
- var tokens = _interopDefault(require('@contentful/forma-36-tokens'));
10
+ var f36Note = require('@contentful/f36-note');
11
+ var tokens = _interopDefault(require('@contentful/f36-tokens'));
12
12
  var emotion = require('emotion');
13
13
  var isNumber = _interopDefault(require('lodash/isNumber'));
14
14
  var ReactDOM = _interopDefault(require('react-dom'));
15
+ var f36Components = require('@contentful/f36-components');
15
16
  var get = _interopDefault(require('lodash/get'));
16
17
  var isObject = _interopDefault(require('lodash/isObject'));
17
18
  var isString = _interopDefault(require('lodash/isString'));
@@ -950,8 +951,8 @@ FieldConnector.defaultProps = {
950
951
  };
951
952
 
952
953
  function PredefinedValuesError() {
953
- return React.createElement(forma36ReactComponents.Note, {
954
- noteType: "warning",
954
+ return React.createElement(f36Note.Note, {
955
+ variant: "warning",
955
956
  testId: "predefined-values-warning"
956
957
  }, "The widget failed to initialize. You can fix the problem by providing predefined values under the validations tab in the field settings.");
957
958
  }
@@ -1021,7 +1022,9 @@ function open(componentRenderer) {
1021
1022
  currentConfig = _extends({}, currentConfig, {
1022
1023
  isShown: false
1023
1024
  });
1024
- render(currentConfig);
1025
+ render(currentConfig); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1026
+ // @ts-ignore
1027
+
1025
1028
  resolve.apply(void 0, arguments);
1026
1029
  getRoot().remove();
1027
1030
  }
@@ -1040,7 +1043,7 @@ function openDialog(options, Component) {
1040
1043
  return onClose();
1041
1044
  };
1042
1045
 
1043
- return React.createElement(forma36ReactComponents.Modal, {
1046
+ return React.createElement(f36Components.Modal, {
1044
1047
  key: key,
1045
1048
  shouldCloseOnOverlayClick: options.shouldCloseOnOverlayClick || false,
1046
1049
  shouldCloseOnEscapePress: options.shouldCloseOnEscapePress || false,
@@ -1050,7 +1053,7 @@ function openDialog(options, Component) {
1050
1053
  onClose: onCloseHandler,
1051
1054
  size: size || '700px'
1052
1055
  }, function () {
1053
- return React.createElement(React.Fragment, null, options.title && React.createElement(forma36ReactComponents.Modal.Header, {
1056
+ return React.createElement(React.Fragment, null, options.title && React.createElement(f36Components.ModalHeader, {
1054
1057
  testId: "dialog-title",
1055
1058
  title: options.title,
1056
1059
  onClose: onCloseHandler
@@ -1120,33 +1123,62 @@ function getAssetTitle(_ref2) {
1120
1123
  });
1121
1124
  return titleOrDefault(title, defaultTitle);
1122
1125
  }
1123
- function getEntityDescription(_ref3) {
1124
- var entity = _ref3.entity,
1125
- contentType = _ref3.contentType,
1126
- localeCode = _ref3.localeCode,
1127
- defaultLocaleCode = _ref3.defaultLocaleCode;
1126
+ /**
1127
+ * Returns true if field is an Asset
1128
+ *
1129
+ * @param field
1130
+ * @returns {boolean}
1131
+ */
1128
1132
 
1129
- if (!contentType) {
1130
- return '';
1131
- }
1133
+ var isAssetField = function isAssetField(field) {
1134
+ return field.type === 'Link' && field.linkType === 'Asset';
1135
+ };
1136
+ /**
1137
+ * Returns true if field is a Title
1138
+ */
1139
+
1140
+ function isDisplayField(_ref3) {
1141
+ var field = _ref3.field,
1142
+ contentType = _ref3.contentType;
1143
+ return field.id === contentType.displayField;
1144
+ }
1145
+ /**
1146
+ * Returns true if field is a short Description
1147
+ */
1148
+
1149
+ function isDescriptionField(_ref4) {
1150
+ var field = _ref4.field,
1151
+ contentType = _ref4.contentType;
1132
1152
 
1133
1153
  var isTextField = function isTextField(field) {
1134
1154
  return ['Symbol', 'Text'].includes(field.type);
1135
1155
  };
1136
1156
 
1137
- var isDisplayField = function isDisplayField(field) {
1138
- return field.id === contentType.displayField;
1139
- };
1140
-
1141
1157
  var isMaybeSlugField = function isMaybeSlugField(field) {
1142
1158
  return /\bslug\b/.test(field.name);
1143
1159
  };
1144
1160
 
1145
- var isDescriptionField = function isDescriptionField(field) {
1146
- return isTextField(field) && !isDisplayField(field) && !isMaybeSlugField(field);
1147
- };
1161
+ return isTextField(field) && !isDisplayField({
1162
+ field: field,
1163
+ contentType: contentType
1164
+ }) && !isMaybeSlugField(field);
1165
+ }
1166
+ function getEntityDescription(_ref5) {
1167
+ var entity = _ref5.entity,
1168
+ contentType = _ref5.contentType,
1169
+ localeCode = _ref5.localeCode,
1170
+ defaultLocaleCode = _ref5.defaultLocaleCode;
1148
1171
 
1149
- var descriptionField = contentType.fields.find(isDescriptionField);
1172
+ if (!contentType) {
1173
+ return '';
1174
+ }
1175
+
1176
+ var descriptionField = contentType.fields.find(function (field) {
1177
+ return isDescriptionField({
1178
+ field: field,
1179
+ contentType: contentType
1180
+ });
1181
+ });
1150
1182
 
1151
1183
  if (!descriptionField) {
1152
1184
  return '';
@@ -1159,12 +1191,12 @@ function getEntityDescription(_ref3) {
1159
1191
  defaultLocaleCode: defaultLocaleCode
1160
1192
  }) || '';
1161
1193
  }
1162
- function getEntryTitle(_ref4) {
1163
- var entry = _ref4.entry,
1164
- contentType = _ref4.contentType,
1165
- localeCode = _ref4.localeCode,
1166
- defaultLocaleCode = _ref4.defaultLocaleCode,
1167
- defaultTitle = _ref4.defaultTitle;
1194
+ function getEntryTitle(_ref6) {
1195
+ var entry = _ref6.entry,
1196
+ contentType = _ref6.contentType,
1197
+ localeCode = _ref6.localeCode,
1198
+ defaultLocaleCode = _ref6.defaultLocaleCode,
1199
+ defaultTitle = _ref6.defaultTitle;
1168
1200
  var title;
1169
1201
 
1170
1202
  if (!contentType) {
@@ -1252,13 +1284,13 @@ function getEntryStatus(sys) {
1252
1284
  */
1253
1285
 
1254
1286
  var getEntryImage = /*#__PURE__*/function () {
1255
- var _ref6 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref5, getAsset) {
1287
+ var _ref8 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref7, getAsset) {
1256
1288
  var entry, contentType, localeCode, assetLink, assetId, asset, file, isImage;
1257
1289
  return runtime_1.wrap(function _callee$(_context) {
1258
1290
  while (1) {
1259
1291
  switch (_context.prev = _context.next) {
1260
1292
  case 0:
1261
- entry = _ref5.entry, contentType = _ref5.contentType, localeCode = _ref5.localeCode;
1293
+ entry = _ref7.entry, contentType = _ref7.contentType, localeCode = _ref7.localeCode;
1262
1294
 
1263
1295
  if (contentType) {
1264
1296
  _context.next = 3;
@@ -1268,9 +1300,7 @@ var getEntryImage = /*#__PURE__*/function () {
1268
1300
  return _context.abrupt("return", null);
1269
1301
 
1270
1302
  case 3:
1271
- assetLink = contentType.fields.find(function (field) {
1272
- return field.type === 'Link' && field.linkType === 'Asset';
1273
- });
1303
+ assetLink = contentType.fields.find(isAssetField);
1274
1304
 
1275
1305
  if (assetLink) {
1276
1306
  _context.next = 6;
@@ -1314,7 +1344,7 @@ var getEntryImage = /*#__PURE__*/function () {
1314
1344
  }));
1315
1345
 
1316
1346
  return function getEntryImage(_x, _x2) {
1317
- return _ref6.apply(this, arguments);
1347
+ return _ref8.apply(this, arguments);
1318
1348
  };
1319
1349
  }();
1320
1350
 
@@ -1322,6 +1352,9 @@ var entityHelpers = {
1322
1352
  __proto__: null,
1323
1353
  getFieldValue: getFieldValue,
1324
1354
  getAssetTitle: getAssetTitle,
1355
+ isAssetField: isAssetField,
1356
+ isDisplayField: isDisplayField,
1357
+ isDescriptionField: isDescriptionField,
1325
1358
  getEntityDescription: getEntityDescription,
1326
1359
  getEntryTitle: getEntryTitle,
1327
1360
  getEntryStatus: getEntryStatus,
@@ -1391,6 +1424,72 @@ function isValidImage(file) {
1391
1424
  return validMimeTypes.includes(file.contentType);
1392
1425
  }
1393
1426
 
1427
+ /**
1428
+ * Transforms a number into a localized string (en-US)
1429
+ * toLocaleString(1000); // "1,000"
1430
+ * @param {Number} number
1431
+ */
1432
+ function toLocaleString(number) {
1433
+ return number.toLocaleString('en-US');
1434
+ }
1435
+
1436
+ function formatFloat(value, localize) {
1437
+ return localize ? toLocaleString(value) : value.toFixed(2) // remove floating point if not necessary
1438
+ .replace(/\.(0)*$|0*$/, '');
1439
+ }
1440
+ /**
1441
+ * Make a storage unit number more readable by making them smaller
1442
+ * shortenStorageUnit(1000, 'GB'); // "1 TB"
1443
+ * shortenStorageUnit(0.001, 'TB'); // "1 GB"
1444
+ * @param value
1445
+ * @param uom Unit of measure
1446
+ * @returns
1447
+ */
1448
+
1449
+
1450
+ function shortenStorageUnit(value, uom) {
1451
+ if (value <= 0) {
1452
+ return '0 B';
1453
+ }
1454
+
1455
+ var units = ['PB', 'TB', 'GB', 'MB', 'KB', 'B'];
1456
+
1457
+ var getBigger = function getBigger(unit) {
1458
+ return units[units.indexOf(unit) - 1];
1459
+ };
1460
+
1461
+ var getSmaller = function getSmaller(unit) {
1462
+ return units[units.indexOf(unit) + 1];
1463
+ };
1464
+
1465
+ var isBiggestUnit = function isBiggestUnit(unit) {
1466
+ return units.indexOf(unit) === 0;
1467
+ };
1468
+
1469
+ var isSmallestUnit = function isSmallestUnit(unit) {
1470
+ return units.indexOf(unit) === units.length - 1;
1471
+ };
1472
+
1473
+ var reduce = function reduce(number, unit) {
1474
+ if (number < 0.99 && !isSmallestUnit(unit)) {
1475
+ return reduce(number * 1000, getSmaller(unit));
1476
+ } else if (number >= 1000 && !isBiggestUnit(unit)) {
1477
+ return reduce(number / 1000, getBigger(unit));
1478
+ } else {
1479
+ return {
1480
+ number: number,
1481
+ unit: unit
1482
+ };
1483
+ }
1484
+ };
1485
+
1486
+ var _reduce = reduce(value, uom),
1487
+ number = _reduce.number,
1488
+ unit = _reduce.unit;
1489
+
1490
+ return formatFloat(number, false) + " " + unit;
1491
+ }
1492
+
1394
1493
  exports.CharCounter = CharCounter;
1395
1494
  exports.CharValidation = CharValidation;
1396
1495
  exports.ConstraintsUtils = constraints;
@@ -1399,4 +1498,6 @@ exports.ModalDialogLauncher = ModalDialogLauncher$1;
1399
1498
  exports.PredefinedValuesError = PredefinedValuesError;
1400
1499
  exports.entityHelpers = entityHelpers;
1401
1500
  exports.isValidImage = isValidImage;
1501
+ exports.shortenStorageUnit = shortenStorageUnit;
1502
+ exports.toLocaleString = toLocaleString;
1402
1503
  //# sourceMappingURL=field-editor-shared.cjs.development.js.map