@contentful/field-editor-shared 0.21.0 → 0.24.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 +44 -0
- package/dist/FieldConnector.d.ts +2 -2
- package/dist/field-editor-shared.cjs.development.js +346 -245
- package/dist/field-editor-shared.cjs.development.js.map +1 -1
- package/dist/field-editor-shared.cjs.production.min.js +1 -1
- package/dist/field-editor-shared.cjs.production.min.js.map +1 -1
- package/dist/field-editor-shared.esm.js +344 -246
- package/dist/field-editor-shared.esm.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/utils/isValidImage.d.ts +5 -0
- package/dist/utils/shortenStorageUnit.d.ts +17 -0
- package/package.json +5 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,50 @@
|
|
|
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.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)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* add shortenStorageUnit util to shared ([#852](https://github.com/contentful/field-editors/issues/852)) ([142472b](https://github.com/contentful/field-editors/commit/142472b57fc1ca2843dd414c5320fdb5b5b11e62))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [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)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* export shared util to validate images ([#846](https://github.com/contentful/field-editors/issues/846)) ([f26c481](https://github.com/contentful/field-editors/commit/f26c481cc5abf275acb4e4a65b462be487708117))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## [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)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Bug Fixes
|
|
32
|
+
|
|
33
|
+
* FieldConnector setValue race conditions ([#803](https://github.com/contentful/field-editors/issues/803)) ([15a5aa6](https://github.com/contentful/field-editors/commit/15a5aa68a6f3f6c7183444c8fd11de1e70208aa7))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# [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)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### Features
|
|
43
|
+
|
|
44
|
+
* 💡 new color tokens ([#778](https://github.com/contentful/field-editors/issues/778)) ([fba548d](https://github.com/contentful/field-editors/commit/fba548de32305016df7f2685634eefb14294828f))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
6
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)
|
|
7
51
|
|
|
8
52
|
|
package/dist/FieldConnector.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ export interface FieldConnectorChildProps<ValueType> {
|
|
|
14
14
|
interface FieldConnectorState<ValueType> {
|
|
15
15
|
isLocalValueChange: boolean;
|
|
16
16
|
externalReset: number;
|
|
17
|
-
lastSetValue: ValueType | Nullable;
|
|
18
17
|
lastRemoteValue: ValueType | Nullable;
|
|
19
18
|
value: ValueType | Nullable;
|
|
20
19
|
disabled: boolean;
|
|
@@ -39,7 +38,8 @@ export declare class FieldConnector<ValueType> extends React.Component<FieldConn
|
|
|
39
38
|
unsubscribeErrors: Function | null;
|
|
40
39
|
unsubscribeDisabled: Function | null;
|
|
41
40
|
unsubscribeValue: Function | null;
|
|
42
|
-
setValue:
|
|
41
|
+
setValue: (value: ValueType | Nullable) => Promise<void>;
|
|
42
|
+
triggerSetValueCallbacks: import("lodash").DebouncedFunc<(value: ValueType | Nullable) => Promise<unknown>>;
|
|
43
43
|
componentDidMount(): void;
|
|
44
44
|
componentWillUnmount(): void;
|
|
45
45
|
render(): React.ReactNode;
|
|
@@ -5,8 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
6
|
|
|
7
7
|
var React = _interopDefault(require('react'));
|
|
8
|
-
var throttle = _interopDefault(require('lodash/throttle'));
|
|
9
8
|
var isEqual = _interopDefault(require('lodash/isEqual'));
|
|
9
|
+
var throttle = _interopDefault(require('lodash/throttle'));
|
|
10
10
|
var forma36ReactComponents = require('@contentful/forma-36-react-components');
|
|
11
11
|
var tokens = _interopDefault(require('@contentful/forma-36-tokens'));
|
|
12
12
|
var emotion = require('emotion');
|
|
@@ -73,256 +73,18 @@ function _extends() {
|
|
|
73
73
|
function _inheritsLoose(subClass, superClass) {
|
|
74
74
|
subClass.prototype = Object.create(superClass.prototype);
|
|
75
75
|
subClass.prototype.constructor = subClass;
|
|
76
|
-
subClass.__proto__ = superClass;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
var FieldConnector = /*#__PURE__*/function (_React$Component) {
|
|
80
|
-
_inheritsLoose(FieldConnector, _React$Component);
|
|
81
|
-
|
|
82
|
-
function FieldConnector(props) {
|
|
83
|
-
var _this;
|
|
84
76
|
|
|
85
|
-
|
|
86
|
-
_this.unsubscribeErrors = null;
|
|
87
|
-
_this.unsubscribeDisabled = null;
|
|
88
|
-
_this.unsubscribeValue = null;
|
|
89
|
-
_this.setValue = throttle(function (value) {
|
|
90
|
-
if (_this.props.isEmptyValue(value === undefined ? null : value)) {
|
|
91
|
-
return new Promise(function (resolve, reject) {
|
|
92
|
-
_this.setState({
|
|
93
|
-
lastSetValue: undefined
|
|
94
|
-
}, function () {
|
|
95
|
-
_this.props.field.removeValue().then(resolve)["catch"](reject);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
} else {
|
|
99
|
-
return new Promise(function (resolve, reject) {
|
|
100
|
-
_this.setState({
|
|
101
|
-
lastSetValue: value
|
|
102
|
-
}, function () {
|
|
103
|
-
_this.props.field.setValue(value).then(resolve)["catch"](reject);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}, _this.props.throttle, {
|
|
108
|
-
leading: _this.props.throttle === 0
|
|
109
|
-
});
|
|
110
|
-
var initialValue = props.field.getValue();
|
|
111
|
-
_this.state = {
|
|
112
|
-
isLocalValueChange: false,
|
|
113
|
-
externalReset: 0,
|
|
114
|
-
value: initialValue,
|
|
115
|
-
lastSetValue: initialValue,
|
|
116
|
-
lastRemoteValue: initialValue,
|
|
117
|
-
disabled: props.isInitiallyDisabled,
|
|
118
|
-
errors: []
|
|
119
|
-
};
|
|
120
|
-
return _this;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
var _proto = FieldConnector.prototype;
|
|
124
|
-
|
|
125
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
126
|
-
var _this2 = this;
|
|
127
|
-
|
|
128
|
-
var field = this.props.field;
|
|
129
|
-
this.unsubscribeErrors = field.onSchemaErrorsChanged(function (errors) {
|
|
130
|
-
_this2.setState({
|
|
131
|
-
errors: errors || []
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
this.unsubscribeDisabled = field.onIsDisabledChanged(function (disabled) {
|
|
135
|
-
_this2.setState({
|
|
136
|
-
disabled: disabled
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
this.unsubscribeValue = field.onValueChanged(function (value) {
|
|
140
|
-
_this2.setState(function (currentState) {
|
|
141
|
-
var isLocalValueChange = _this2.props.isEqualValues(value, currentState.lastSetValue);
|
|
142
|
-
|
|
143
|
-
var lastRemoteValue = isLocalValueChange ? currentState.lastRemoteValue : value;
|
|
144
|
-
var externalReset = currentState.externalReset + (isLocalValueChange ? 0 : 1);
|
|
145
|
-
return {
|
|
146
|
-
value: value,
|
|
147
|
-
lastSetValue: value,
|
|
148
|
-
lastRemoteValue: lastRemoteValue,
|
|
149
|
-
isLocalValueChange: isLocalValueChange,
|
|
150
|
-
externalReset: externalReset
|
|
151
|
-
};
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
157
|
-
if (typeof this.unsubscribeErrors === 'function') {
|
|
158
|
-
this.unsubscribeErrors();
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (typeof this.unsubscribeDisabled === 'function') {
|
|
162
|
-
this.unsubscribeDisabled();
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (typeof this.unsubscribeValue === 'function') {
|
|
166
|
-
this.unsubscribeValue();
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
_proto.render = function render() {
|
|
171
|
-
var childProps = _extends({}, this.state); // `lastSetValue` can be either the `setValue()` value right after it got called
|
|
172
|
-
// or the current remote value. No use-case for passing this to child.
|
|
173
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
174
|
-
// @ts-ignore
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
delete childProps.lastSetValue;
|
|
178
|
-
return this.props.children(_extends({}, childProps, {
|
|
179
|
-
// @ts-expect-error
|
|
180
|
-
setValue: this.setValue
|
|
181
|
-
}));
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
return FieldConnector;
|
|
185
|
-
}(React.Component);
|
|
186
|
-
FieldConnector.defaultProps = {
|
|
187
|
-
children: function children() {
|
|
188
|
-
return null;
|
|
189
|
-
},
|
|
190
|
-
// eslint-disable-next-line
|
|
191
|
-
isEmptyValue: function isEmptyValue(value) {
|
|
192
|
-
return value === null || value === '';
|
|
193
|
-
},
|
|
194
|
-
// eslint-disable-next-line
|
|
195
|
-
isEqualValues: function isEqualValues(value1, value2) {
|
|
196
|
-
return isEqual(value1, value2);
|
|
197
|
-
},
|
|
198
|
-
throttle: 300
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
function PredefinedValuesError() {
|
|
202
|
-
return React.createElement(forma36ReactComponents.Note, {
|
|
203
|
-
noteType: "warning",
|
|
204
|
-
testId: "predefined-values-warning"
|
|
205
|
-
}, "The widget failed to initialize. You can fix the problem by providing predefined values under the validations tab in the field settings.");
|
|
77
|
+
_setPrototypeOf(subClass, superClass);
|
|
206
78
|
}
|
|
207
79
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
};
|
|
213
|
-
function CharCounter(props) {
|
|
214
|
-
var _cx;
|
|
215
|
-
|
|
216
|
-
var count = 0;
|
|
217
|
-
|
|
218
|
-
if (props.value) {
|
|
219
|
-
count = props.value.length;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
var valid = count === 0 || props.checkConstraint(count);
|
|
223
|
-
return React.createElement("span", {
|
|
224
|
-
"data-status-code": valid ? null : 'invalid-size',
|
|
225
|
-
className: emotion.cx((_cx = {}, _cx[styles.invalid] = !valid, _cx))
|
|
226
|
-
}, count, " characters");
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
function CharValidation(props) {
|
|
230
|
-
var constraints = props.constraints;
|
|
231
|
-
|
|
232
|
-
if (constraints.type === 'max') {
|
|
233
|
-
return React.createElement("span", null, "Maximum ", constraints.max, " characters");
|
|
234
|
-
} else if (constraints.type === 'min') {
|
|
235
|
-
return React.createElement("span", null, "Requires at least ", constraints.min, " characters");
|
|
236
|
-
} else {
|
|
237
|
-
return React.createElement("span", null, "Requires between ", constraints.min, " and ", constraints.max, " characters");
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function open(componentRenderer) {
|
|
242
|
-
var rootDom = null;
|
|
243
|
-
|
|
244
|
-
var getRoot = function getRoot() {
|
|
245
|
-
if (rootDom === null) {
|
|
246
|
-
rootDom = document.createElement('div');
|
|
247
|
-
rootDom.setAttribute('id', 'field-editor-modal-root');
|
|
248
|
-
document.body.appendChild(rootDom);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
return rootDom;
|
|
80
|
+
function _setPrototypeOf(o, p) {
|
|
81
|
+
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
82
|
+
o.__proto__ = p;
|
|
83
|
+
return o;
|
|
252
84
|
};
|
|
253
85
|
|
|
254
|
-
return
|
|
255
|
-
var currentConfig = {
|
|
256
|
-
onClose: onClose,
|
|
257
|
-
isShown: true
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
function render(_ref) {
|
|
261
|
-
var onClose = _ref.onClose,
|
|
262
|
-
isShown = _ref.isShown;
|
|
263
|
-
ReactDOM.render(componentRenderer({
|
|
264
|
-
onClose: onClose,
|
|
265
|
-
isShown: isShown
|
|
266
|
-
}), getRoot());
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
function onClose() {
|
|
270
|
-
currentConfig = _extends({}, currentConfig, {
|
|
271
|
-
isShown: false
|
|
272
|
-
});
|
|
273
|
-
render(currentConfig);
|
|
274
|
-
resolve.apply(void 0, arguments);
|
|
275
|
-
getRoot().remove();
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
render(currentConfig);
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
function openDialog(options, Component) {
|
|
282
|
-
var key = Date.now();
|
|
283
|
-
var size = isNumber(options.width) ? options.width + "px" : options.width;
|
|
284
|
-
return open(function (_ref2) {
|
|
285
|
-
var isShown = _ref2.isShown,
|
|
286
|
-
onClose = _ref2.onClose;
|
|
287
|
-
|
|
288
|
-
var onCloseHandler = function onCloseHandler() {
|
|
289
|
-
return onClose();
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
return React.createElement(forma36ReactComponents.Modal, {
|
|
293
|
-
key: key,
|
|
294
|
-
shouldCloseOnOverlayClick: options.shouldCloseOnOverlayClick || false,
|
|
295
|
-
shouldCloseOnEscapePress: options.shouldCloseOnEscapePress || false,
|
|
296
|
-
allowHeightOverflow: options.allowHeightOverflow || false,
|
|
297
|
-
position: options.position || 'center',
|
|
298
|
-
isShown: isShown,
|
|
299
|
-
onClose: onCloseHandler,
|
|
300
|
-
size: size || '700px'
|
|
301
|
-
}, function () {
|
|
302
|
-
return React.createElement(React.Fragment, null, options.title && React.createElement(forma36ReactComponents.Modal.Header, {
|
|
303
|
-
testId: "dialog-title",
|
|
304
|
-
title: options.title,
|
|
305
|
-
onClose: onCloseHandler
|
|
306
|
-
}), React.createElement("div", {
|
|
307
|
-
style: {
|
|
308
|
-
minHeight: options.minHeight || 'auto'
|
|
309
|
-
}
|
|
310
|
-
}, React.createElement(Component, {
|
|
311
|
-
onClose: onClose
|
|
312
|
-
})));
|
|
313
|
-
});
|
|
314
|
-
});
|
|
86
|
+
return _setPrototypeOf(o, p);
|
|
315
87
|
}
|
|
316
|
-
var ModalDialogLauncher = {
|
|
317
|
-
openDialog: openDialog
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
var ModalDialogLauncher$1 = {
|
|
321
|
-
__proto__: null,
|
|
322
|
-
open: open,
|
|
323
|
-
openDialog: openDialog,
|
|
324
|
-
'default': ModalDialogLauncher
|
|
325
|
-
};
|
|
326
88
|
|
|
327
89
|
function createCommonjsModule(fn, module) {
|
|
328
90
|
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
@@ -1052,6 +814,267 @@ var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
|
|
|
1052
814
|
}
|
|
1053
815
|
});
|
|
1054
816
|
|
|
817
|
+
var FieldConnector = /*#__PURE__*/function (_React$Component) {
|
|
818
|
+
_inheritsLoose(FieldConnector, _React$Component);
|
|
819
|
+
|
|
820
|
+
function FieldConnector(props) {
|
|
821
|
+
var _this;
|
|
822
|
+
|
|
823
|
+
_this = _React$Component.call(this, props) || this;
|
|
824
|
+
_this.unsubscribeErrors = null;
|
|
825
|
+
_this.unsubscribeDisabled = null;
|
|
826
|
+
_this.unsubscribeValue = null;
|
|
827
|
+
|
|
828
|
+
_this.setValue = /*#__PURE__*/function () {
|
|
829
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(value) {
|
|
830
|
+
return runtime_1.wrap(function _callee$(_context) {
|
|
831
|
+
while (1) {
|
|
832
|
+
switch (_context.prev = _context.next) {
|
|
833
|
+
case 0:
|
|
834
|
+
if (_this.props.isEmptyValue(value != null ? value : null)) {
|
|
835
|
+
_this.setState({
|
|
836
|
+
value: undefined
|
|
837
|
+
});
|
|
838
|
+
} else {
|
|
839
|
+
_this.setState({
|
|
840
|
+
value: value
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
_context.next = 3;
|
|
845
|
+
return _this.triggerSetValueCallbacks(value);
|
|
846
|
+
|
|
847
|
+
case 3:
|
|
848
|
+
case "end":
|
|
849
|
+
return _context.stop();
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
}, _callee);
|
|
853
|
+
}));
|
|
854
|
+
|
|
855
|
+
return function (_x) {
|
|
856
|
+
return _ref.apply(this, arguments);
|
|
857
|
+
};
|
|
858
|
+
}();
|
|
859
|
+
|
|
860
|
+
_this.triggerSetValueCallbacks = throttle(function (value) {
|
|
861
|
+
return new Promise(function (resolve, reject) {
|
|
862
|
+
if (_this.props.isEmptyValue(value != null ? value : null)) {
|
|
863
|
+
_this.props.field.removeValue().then(resolve)["catch"](reject);
|
|
864
|
+
} else {
|
|
865
|
+
_this.props.field.setValue(value).then(resolve)["catch"](reject);
|
|
866
|
+
}
|
|
867
|
+
});
|
|
868
|
+
}, _this.props.throttle, {
|
|
869
|
+
leading: _this.props.throttle === 0
|
|
870
|
+
});
|
|
871
|
+
var initialValue = props.field.getValue();
|
|
872
|
+
_this.state = {
|
|
873
|
+
isLocalValueChange: false,
|
|
874
|
+
externalReset: 0,
|
|
875
|
+
value: initialValue,
|
|
876
|
+
lastRemoteValue: initialValue,
|
|
877
|
+
disabled: props.isInitiallyDisabled,
|
|
878
|
+
errors: []
|
|
879
|
+
};
|
|
880
|
+
return _this;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
var _proto = FieldConnector.prototype;
|
|
884
|
+
|
|
885
|
+
_proto.componentDidMount = function componentDidMount() {
|
|
886
|
+
var _this2 = this;
|
|
887
|
+
|
|
888
|
+
var field = this.props.field;
|
|
889
|
+
this.unsubscribeErrors = field.onSchemaErrorsChanged(function (errors) {
|
|
890
|
+
_this2.setState({
|
|
891
|
+
errors: errors || []
|
|
892
|
+
});
|
|
893
|
+
});
|
|
894
|
+
this.unsubscribeDisabled = field.onIsDisabledChanged(function (disabled) {
|
|
895
|
+
_this2.setState({
|
|
896
|
+
disabled: disabled
|
|
897
|
+
});
|
|
898
|
+
});
|
|
899
|
+
this.unsubscribeValue = field.onValueChanged(function (value) {
|
|
900
|
+
_this2.setState(function (currentState) {
|
|
901
|
+
var isLocalValueChange = _this2.props.isEqualValues(value, currentState.value);
|
|
902
|
+
|
|
903
|
+
var lastRemoteValue = isLocalValueChange ? currentState.lastRemoteValue : value;
|
|
904
|
+
var externalReset = currentState.externalReset + (isLocalValueChange ? 0 : 1);
|
|
905
|
+
return {
|
|
906
|
+
value: value,
|
|
907
|
+
lastRemoteValue: lastRemoteValue,
|
|
908
|
+
isLocalValueChange: isLocalValueChange,
|
|
909
|
+
externalReset: externalReset
|
|
910
|
+
};
|
|
911
|
+
});
|
|
912
|
+
});
|
|
913
|
+
};
|
|
914
|
+
|
|
915
|
+
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
916
|
+
if (typeof this.unsubscribeErrors === 'function') {
|
|
917
|
+
this.unsubscribeErrors();
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
if (typeof this.unsubscribeDisabled === 'function') {
|
|
921
|
+
this.unsubscribeDisabled();
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
if (typeof this.unsubscribeValue === 'function') {
|
|
925
|
+
this.unsubscribeValue();
|
|
926
|
+
}
|
|
927
|
+
};
|
|
928
|
+
|
|
929
|
+
_proto.render = function render() {
|
|
930
|
+
return this.props.children(_extends({}, this.state, {
|
|
931
|
+
setValue: this.setValue
|
|
932
|
+
}));
|
|
933
|
+
};
|
|
934
|
+
|
|
935
|
+
return FieldConnector;
|
|
936
|
+
}(React.Component);
|
|
937
|
+
FieldConnector.defaultProps = {
|
|
938
|
+
children: function children() {
|
|
939
|
+
return null;
|
|
940
|
+
},
|
|
941
|
+
// eslint-disable-next-line
|
|
942
|
+
isEmptyValue: function isEmptyValue(value) {
|
|
943
|
+
return value === null || value === '';
|
|
944
|
+
},
|
|
945
|
+
// eslint-disable-next-line
|
|
946
|
+
isEqualValues: function isEqualValues(value1, value2) {
|
|
947
|
+
return isEqual(value1, value2);
|
|
948
|
+
},
|
|
949
|
+
throttle: 300
|
|
950
|
+
};
|
|
951
|
+
|
|
952
|
+
function PredefinedValuesError() {
|
|
953
|
+
return React.createElement(forma36ReactComponents.Note, {
|
|
954
|
+
noteType: "warning",
|
|
955
|
+
testId: "predefined-values-warning"
|
|
956
|
+
}, "The widget failed to initialize. You can fix the problem by providing predefined values under the validations tab in the field settings.");
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
var styles = {
|
|
960
|
+
invalid: /*#__PURE__*/emotion.css({
|
|
961
|
+
color: tokens.red600
|
|
962
|
+
})
|
|
963
|
+
};
|
|
964
|
+
function CharCounter(props) {
|
|
965
|
+
var _cx;
|
|
966
|
+
|
|
967
|
+
var count = 0;
|
|
968
|
+
|
|
969
|
+
if (props.value) {
|
|
970
|
+
count = props.value.length;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
var valid = count === 0 || props.checkConstraint(count);
|
|
974
|
+
return React.createElement("span", {
|
|
975
|
+
"data-status-code": valid ? null : 'invalid-size',
|
|
976
|
+
className: emotion.cx((_cx = {}, _cx[styles.invalid] = !valid, _cx))
|
|
977
|
+
}, count, " characters");
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
function CharValidation(props) {
|
|
981
|
+
var constraints = props.constraints;
|
|
982
|
+
|
|
983
|
+
if (constraints.type === 'max') {
|
|
984
|
+
return React.createElement("span", null, "Maximum ", constraints.max, " characters");
|
|
985
|
+
} else if (constraints.type === 'min') {
|
|
986
|
+
return React.createElement("span", null, "Requires at least ", constraints.min, " characters");
|
|
987
|
+
} else {
|
|
988
|
+
return React.createElement("span", null, "Requires between ", constraints.min, " and ", constraints.max, " characters");
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
function open(componentRenderer) {
|
|
993
|
+
var rootDom = null;
|
|
994
|
+
|
|
995
|
+
var getRoot = function getRoot() {
|
|
996
|
+
if (rootDom === null) {
|
|
997
|
+
rootDom = document.createElement('div');
|
|
998
|
+
rootDom.setAttribute('id', 'field-editor-modal-root');
|
|
999
|
+
document.body.appendChild(rootDom);
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
return rootDom;
|
|
1003
|
+
};
|
|
1004
|
+
|
|
1005
|
+
return new Promise(function (resolve) {
|
|
1006
|
+
var currentConfig = {
|
|
1007
|
+
onClose: onClose,
|
|
1008
|
+
isShown: true
|
|
1009
|
+
};
|
|
1010
|
+
|
|
1011
|
+
function render(_ref) {
|
|
1012
|
+
var onClose = _ref.onClose,
|
|
1013
|
+
isShown = _ref.isShown;
|
|
1014
|
+
ReactDOM.render(componentRenderer({
|
|
1015
|
+
onClose: onClose,
|
|
1016
|
+
isShown: isShown
|
|
1017
|
+
}), getRoot());
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
function onClose() {
|
|
1021
|
+
currentConfig = _extends({}, currentConfig, {
|
|
1022
|
+
isShown: false
|
|
1023
|
+
});
|
|
1024
|
+
render(currentConfig);
|
|
1025
|
+
resolve.apply(void 0, arguments);
|
|
1026
|
+
getRoot().remove();
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
render(currentConfig);
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
function openDialog(options, Component) {
|
|
1033
|
+
var key = Date.now();
|
|
1034
|
+
var size = isNumber(options.width) ? options.width + "px" : options.width;
|
|
1035
|
+
return open(function (_ref2) {
|
|
1036
|
+
var isShown = _ref2.isShown,
|
|
1037
|
+
onClose = _ref2.onClose;
|
|
1038
|
+
|
|
1039
|
+
var onCloseHandler = function onCloseHandler() {
|
|
1040
|
+
return onClose();
|
|
1041
|
+
};
|
|
1042
|
+
|
|
1043
|
+
return React.createElement(forma36ReactComponents.Modal, {
|
|
1044
|
+
key: key,
|
|
1045
|
+
shouldCloseOnOverlayClick: options.shouldCloseOnOverlayClick || false,
|
|
1046
|
+
shouldCloseOnEscapePress: options.shouldCloseOnEscapePress || false,
|
|
1047
|
+
allowHeightOverflow: options.allowHeightOverflow || false,
|
|
1048
|
+
position: options.position || 'center',
|
|
1049
|
+
isShown: isShown,
|
|
1050
|
+
onClose: onCloseHandler,
|
|
1051
|
+
size: size || '700px'
|
|
1052
|
+
}, function () {
|
|
1053
|
+
return React.createElement(React.Fragment, null, options.title && React.createElement(forma36ReactComponents.Modal.Header, {
|
|
1054
|
+
testId: "dialog-title",
|
|
1055
|
+
title: options.title,
|
|
1056
|
+
onClose: onCloseHandler
|
|
1057
|
+
}), React.createElement("div", {
|
|
1058
|
+
style: {
|
|
1059
|
+
minHeight: options.minHeight || 'auto'
|
|
1060
|
+
}
|
|
1061
|
+
}, React.createElement(Component, {
|
|
1062
|
+
onClose: onClose
|
|
1063
|
+
})));
|
|
1064
|
+
});
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
var ModalDialogLauncher = {
|
|
1068
|
+
openDialog: openDialog
|
|
1069
|
+
};
|
|
1070
|
+
|
|
1071
|
+
var ModalDialogLauncher$1 = {
|
|
1072
|
+
__proto__: null,
|
|
1073
|
+
open: open,
|
|
1074
|
+
openDialog: openDialog,
|
|
1075
|
+
'default': ModalDialogLauncher
|
|
1076
|
+
};
|
|
1077
|
+
|
|
1055
1078
|
function titleOrDefault(title, defaultTitle) {
|
|
1056
1079
|
if (!isString(title)) {
|
|
1057
1080
|
return defaultTitle;
|
|
@@ -1359,6 +1382,81 @@ var constraints = {
|
|
|
1359
1382
|
makeChecker: makeChecker
|
|
1360
1383
|
};
|
|
1361
1384
|
|
|
1385
|
+
/**
|
|
1386
|
+
* Checks whether the passed content type matches one of our valid MIME types
|
|
1387
|
+
*/
|
|
1388
|
+
function isValidImage(file) {
|
|
1389
|
+
var validMimeTypes = ['image/bmp', 'image/x-windows-bmp', 'image/gif', 'image/webp', // This is not a valid MIME type but we supported it in the past.
|
|
1390
|
+
'image/jpg', 'image/jpeg', 'image/pjpeg', 'image/x-jps', 'image/png', 'image/svg+xml'];
|
|
1391
|
+
return validMimeTypes.includes(file.contentType);
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
/**
|
|
1395
|
+
* Transforms a number into a localized string (en-US)
|
|
1396
|
+
* toLocaleString(1000); // "1,000"
|
|
1397
|
+
* @param {Number} number
|
|
1398
|
+
*/
|
|
1399
|
+
function toLocaleString(number) {
|
|
1400
|
+
return number.toLocaleString('en-US');
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
function formatFloat(value, localize) {
|
|
1404
|
+
return localize ? toLocaleString(value) : value.toFixed(2) // remove floating point if not necessary
|
|
1405
|
+
.replace(/\.(0)*$|0*$/, '');
|
|
1406
|
+
}
|
|
1407
|
+
/**
|
|
1408
|
+
* Make a storage unit number more readable by making them smaller
|
|
1409
|
+
* shortenStorageUnit(1000, 'GB'); // "1 TB"
|
|
1410
|
+
* shortenStorageUnit(0.001, 'TB'); // "1 GB"
|
|
1411
|
+
* @param value
|
|
1412
|
+
* @param uom Unit of measure
|
|
1413
|
+
* @returns
|
|
1414
|
+
*/
|
|
1415
|
+
|
|
1416
|
+
|
|
1417
|
+
function shortenStorageUnit(value, uom) {
|
|
1418
|
+
if (value <= 0) {
|
|
1419
|
+
return '0 B';
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
var units = ['PB', 'TB', 'GB', 'MB', 'KB', 'B'];
|
|
1423
|
+
|
|
1424
|
+
var getBigger = function getBigger(unit) {
|
|
1425
|
+
return units[units.indexOf(unit) - 1];
|
|
1426
|
+
};
|
|
1427
|
+
|
|
1428
|
+
var getSmaller = function getSmaller(unit) {
|
|
1429
|
+
return units[units.indexOf(unit) + 1];
|
|
1430
|
+
};
|
|
1431
|
+
|
|
1432
|
+
var isBiggestUnit = function isBiggestUnit(unit) {
|
|
1433
|
+
return units.indexOf(unit) === 0;
|
|
1434
|
+
};
|
|
1435
|
+
|
|
1436
|
+
var isSmallestUnit = function isSmallestUnit(unit) {
|
|
1437
|
+
return units.indexOf(unit) === units.length - 1;
|
|
1438
|
+
};
|
|
1439
|
+
|
|
1440
|
+
var reduce = function reduce(number, unit) {
|
|
1441
|
+
if (number < 0.99 && !isSmallestUnit(unit)) {
|
|
1442
|
+
return reduce(number * 1000, getSmaller(unit));
|
|
1443
|
+
} else if (number >= 1000 && !isBiggestUnit(unit)) {
|
|
1444
|
+
return reduce(number / 1000, getBigger(unit));
|
|
1445
|
+
} else {
|
|
1446
|
+
return {
|
|
1447
|
+
number: number,
|
|
1448
|
+
unit: unit
|
|
1449
|
+
};
|
|
1450
|
+
}
|
|
1451
|
+
};
|
|
1452
|
+
|
|
1453
|
+
var _reduce = reduce(value, uom),
|
|
1454
|
+
number = _reduce.number,
|
|
1455
|
+
unit = _reduce.unit;
|
|
1456
|
+
|
|
1457
|
+
return formatFloat(number, false) + " " + unit;
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1362
1460
|
exports.CharCounter = CharCounter;
|
|
1363
1461
|
exports.CharValidation = CharValidation;
|
|
1364
1462
|
exports.ConstraintsUtils = constraints;
|
|
@@ -1366,4 +1464,7 @@ exports.FieldConnector = FieldConnector;
|
|
|
1366
1464
|
exports.ModalDialogLauncher = ModalDialogLauncher$1;
|
|
1367
1465
|
exports.PredefinedValuesError = PredefinedValuesError;
|
|
1368
1466
|
exports.entityHelpers = entityHelpers;
|
|
1467
|
+
exports.isValidImage = isValidImage;
|
|
1468
|
+
exports.shortenStorageUnit = shortenStorageUnit;
|
|
1469
|
+
exports.toLocaleString = toLocaleString;
|
|
1369
1470
|
//# sourceMappingURL=field-editor-shared.cjs.development.js.map
|