@contentful/field-editor-shared 1.1.8 → 1.2.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.
@@ -4,913 +4,86 @@ import throttle from 'lodash-es/throttle';
4
4
  import { Note } from '@contentful/f36-note';
5
5
  import tokens from '@contentful/f36-tokens';
6
6
  import { cx, css } from 'emotion';
7
- import isNumber from 'lodash-es/isNumber';
8
7
  import ReactDOM from 'react-dom';
9
8
  import { Modal, ModalHeader } from '@contentful/f36-components';
9
+ import isNumber from 'lodash-es/isNumber';
10
10
  import get from 'lodash-es/get';
11
11
  import isObject from 'lodash-es/isObject';
12
12
  import isString from 'lodash-es/isString';
13
13
 
14
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
15
- try {
16
- var info = gen[key](arg);
17
- var value = info.value;
18
- } catch (error) {
19
- reject(error);
20
- return;
21
- }
22
-
23
- if (info.done) {
24
- resolve(value);
25
- } else {
26
- Promise.resolve(value).then(_next, _throw);
27
- }
28
- }
29
-
30
- function _asyncToGenerator(fn) {
31
- return function () {
32
- var self = this,
33
- args = arguments;
34
- return new Promise(function (resolve, reject) {
35
- var gen = fn.apply(self, args);
36
-
37
- function _next(value) {
38
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
39
- }
40
-
41
- function _throw(err) {
42
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
43
- }
44
-
45
- _next(undefined);
46
- });
47
- };
48
- }
49
-
50
- function _extends() {
51
- _extends = Object.assign || function (target) {
52
- for (var i = 1; i < arguments.length; i++) {
53
- var source = arguments[i];
54
-
55
- for (var key in source) {
56
- if (Object.prototype.hasOwnProperty.call(source, key)) {
57
- target[key] = source[key];
58
- }
59
- }
60
- }
61
-
62
- return target;
63
- };
64
-
65
- return _extends.apply(this, arguments);
66
- }
67
-
68
- function _inheritsLoose(subClass, superClass) {
69
- subClass.prototype = Object.create(superClass.prototype);
70
- subClass.prototype.constructor = subClass;
71
-
72
- _setPrototypeOf(subClass, superClass);
73
- }
74
-
75
- function _setPrototypeOf(o, p) {
76
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
77
- o.__proto__ = p;
78
- return o;
79
- };
80
-
81
- return _setPrototypeOf(o, p);
82
- }
83
-
84
- function createCommonjsModule(fn, module) {
85
- return module = { exports: {} }, fn(module, module.exports), module.exports;
86
- }
87
-
88
- var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
89
- /**
90
- * Copyright (c) 2014-present, Facebook, Inc.
91
- *
92
- * This source code is licensed under the MIT license found in the
93
- * LICENSE file in the root directory of this source tree.
94
- */
95
- var runtime = function (exports) {
96
-
97
- var Op = Object.prototype;
98
- var hasOwn = Op.hasOwnProperty;
99
- var undefined$1; // More compressible than void 0.
100
-
101
- var $Symbol = typeof Symbol === "function" ? Symbol : {};
102
- var iteratorSymbol = $Symbol.iterator || "@@iterator";
103
- var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
104
- var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
105
-
106
- function define(obj, key, value) {
107
- Object.defineProperty(obj, key, {
108
- value: value,
109
- enumerable: true,
110
- configurable: true,
111
- writable: true
112
- });
113
- return obj[key];
114
- }
115
-
116
- try {
117
- // IE 8 has a broken Object.defineProperty that only works on DOM objects.
118
- define({}, "");
119
- } catch (err) {
120
- define = function define(obj, key, value) {
121
- return obj[key] = value;
122
- };
123
- }
124
-
125
- function wrap(innerFn, outerFn, self, tryLocsList) {
126
- // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
127
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
128
- var generator = Object.create(protoGenerator.prototype);
129
- var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next,
130
- // .throw, and .return methods.
131
-
132
- generator._invoke = makeInvokeMethod(innerFn, self, context);
133
- return generator;
134
- }
135
-
136
- exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion
137
- // record like context.tryEntries[i].completion. This interface could
138
- // have been (and was previously) designed to take a closure to be
139
- // invoked without arguments, but in all the cases we care about we
140
- // already have an existing method we want to call, so there's no need
141
- // to create a new function object. We can even get away with assuming
142
- // the method takes exactly one argument, since that happens to be true
143
- // in every case, so we don't have to touch the arguments object. The
144
- // only additional allocation required is the completion record, which
145
- // has a stable shape and so hopefully should be cheap to allocate.
146
-
147
- function tryCatch(fn, obj, arg) {
148
- try {
149
- return {
150
- type: "normal",
151
- arg: fn.call(obj, arg)
152
- };
153
- } catch (err) {
154
- return {
155
- type: "throw",
156
- arg: err
157
- };
158
- }
159
- }
160
-
161
- var GenStateSuspendedStart = "suspendedStart";
162
- var GenStateSuspendedYield = "suspendedYield";
163
- var GenStateExecuting = "executing";
164
- var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as
165
- // breaking out of the dispatch switch statement.
166
-
167
- var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and
168
- // .constructor.prototype properties for functions that return Generator
169
- // objects. For full spec compliance, you may wish to configure your
170
- // minifier not to mangle the names of these two functions.
171
-
172
- function Generator() {}
173
-
174
- function GeneratorFunction() {}
175
-
176
- function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that
177
- // don't natively support it.
178
-
179
-
180
- var IteratorPrototype = {};
181
- define(IteratorPrototype, iteratorSymbol, function () {
182
- return this;
183
- });
184
- var getProto = Object.getPrototypeOf;
185
- var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
186
-
187
- if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
188
- // This environment has a native %IteratorPrototype%; use it instead
189
- // of the polyfill.
190
- IteratorPrototype = NativeIteratorPrototype;
191
- }
192
-
193
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
194
- GeneratorFunction.prototype = GeneratorFunctionPrototype;
195
- define(Gp, "constructor", GeneratorFunctionPrototype);
196
- define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
197
- GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
198
- // Iterator interface in terms of a single ._invoke method.
199
-
200
- function defineIteratorMethods(prototype) {
201
- ["next", "throw", "return"].forEach(function (method) {
202
- define(prototype, method, function (arg) {
203
- return this._invoke(method, arg);
14
+ class FieldConnector extends React.Component {
15
+ constructor(props) {
16
+ super(props);
17
+ this.unsubscribeErrors = null;
18
+ this.unsubscribeDisabled = null;
19
+ this.unsubscribeValue = null;
20
+
21
+ this.setValue = async value => {
22
+ if (this.props.isEmptyValue(value ?? null)) {
23
+ this.setState({
24
+ value: undefined
204
25
  });
205
- });
206
- }
207
-
208
- exports.isGeneratorFunction = function (genFun) {
209
- var ctor = typeof genFun === "function" && genFun.constructor;
210
- return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can
211
- // do is to check its .name property.
212
- (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
213
- };
214
-
215
- exports.mark = function (genFun) {
216
- if (Object.setPrototypeOf) {
217
- Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
218
26
  } else {
219
- genFun.__proto__ = GeneratorFunctionPrototype;
220
- define(genFun, toStringTagSymbol, "GeneratorFunction");
221
- }
222
-
223
- genFun.prototype = Object.create(Gp);
224
- return genFun;
225
- }; // Within the body of any async function, `await x` is transformed to
226
- // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
227
- // `hasOwn.call(value, "__await")` to determine if the yielded value is
228
- // meant to be awaited.
229
-
230
-
231
- exports.awrap = function (arg) {
232
- return {
233
- __await: arg
234
- };
235
- };
236
-
237
- function AsyncIterator(generator, PromiseImpl) {
238
- function invoke(method, arg, resolve, reject) {
239
- var record = tryCatch(generator[method], generator, arg);
240
-
241
- if (record.type === "throw") {
242
- reject(record.arg);
243
- } else {
244
- var result = record.arg;
245
- var value = result.value;
246
-
247
- if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
248
- return PromiseImpl.resolve(value.__await).then(function (value) {
249
- invoke("next", value, resolve, reject);
250
- }, function (err) {
251
- invoke("throw", err, resolve, reject);
252
- });
253
- }
254
-
255
- return PromiseImpl.resolve(value).then(function (unwrapped) {
256
- // When a yielded Promise is resolved, its final value becomes
257
- // the .value of the Promise<{value,done}> result for the
258
- // current iteration.
259
- result.value = unwrapped;
260
- resolve(result);
261
- }, function (error) {
262
- // If a rejected Promise was yielded, throw the rejection back
263
- // into the async generator function so it can be handled there.
264
- return invoke("throw", error, resolve, reject);
265
- });
266
- }
267
- }
268
-
269
- var previousPromise;
270
-
271
- function enqueue(method, arg) {
272
- function callInvokeWithMethodAndArg() {
273
- return new PromiseImpl(function (resolve, reject) {
274
- invoke(method, arg, resolve, reject);
275
- });
276
- }
277
-
278
- return previousPromise = // If enqueue has been called before, then we want to wait until
279
- // all previous Promises have been resolved before calling invoke,
280
- // so that results are always delivered in the correct order. If
281
- // enqueue has not been called before, then it is important to
282
- // call invoke immediately, without waiting on a callback to fire,
283
- // so that the async generator function has the opportunity to do
284
- // any necessary setup in a predictable way. This predictability
285
- // is why the Promise constructor synchronously invokes its
286
- // executor callback, and why async functions synchronously
287
- // execute code before the first await. Since we implement simple
288
- // async functions in terms of async generators, it is especially
289
- // important to get this right, even though it requires care.
290
- previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later
291
- // invocations of the iterator.
292
- callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
293
- } // Define the unified helper method that is used to implement .next,
294
- // .throw, and .return (see defineIteratorMethods).
295
-
296
-
297
- this._invoke = enqueue;
298
- }
299
-
300
- defineIteratorMethods(AsyncIterator.prototype);
301
- define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
302
- return this;
303
- });
304
- exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
305
- // AsyncIterator objects; they just return a Promise for the value of
306
- // the final result produced by the iterator.
307
-
308
- exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
309
- if (PromiseImpl === void 0) PromiseImpl = Promise;
310
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
311
- return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
312
- : iter.next().then(function (result) {
313
- return result.done ? result.value : iter.next();
314
- });
315
- };
316
-
317
- function makeInvokeMethod(innerFn, self, context) {
318
- var state = GenStateSuspendedStart;
319
- return function invoke(method, arg) {
320
- if (state === GenStateExecuting) {
321
- throw new Error("Generator is already running");
322
- }
323
-
324
- if (state === GenStateCompleted) {
325
- if (method === "throw") {
326
- throw arg;
327
- } // Be forgiving, per 25.3.3.3.3 of the spec:
328
- // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
329
-
330
-
331
- return doneResult();
332
- }
333
-
334
- context.method = method;
335
- context.arg = arg;
336
-
337
- while (true) {
338
- var delegate = context.delegate;
339
-
340
- if (delegate) {
341
- var delegateResult = maybeInvokeDelegate(delegate, context);
342
-
343
- if (delegateResult) {
344
- if (delegateResult === ContinueSentinel) continue;
345
- return delegateResult;
346
- }
347
- }
348
-
349
- if (context.method === "next") {
350
- // Setting context._sent for legacy support of Babel's
351
- // function.sent implementation.
352
- context.sent = context._sent = context.arg;
353
- } else if (context.method === "throw") {
354
- if (state === GenStateSuspendedStart) {
355
- state = GenStateCompleted;
356
- throw context.arg;
357
- }
358
-
359
- context.dispatchException(context.arg);
360
- } else if (context.method === "return") {
361
- context.abrupt("return", context.arg);
362
- }
363
-
364
- state = GenStateExecuting;
365
- var record = tryCatch(innerFn, self, context);
366
-
367
- if (record.type === "normal") {
368
- // If an exception is thrown from innerFn, we leave state ===
369
- // GenStateExecuting and loop back for another invocation.
370
- state = context.done ? GenStateCompleted : GenStateSuspendedYield;
371
-
372
- if (record.arg === ContinueSentinel) {
373
- continue;
374
- }
375
-
376
- return {
377
- value: record.arg,
378
- done: context.done
379
- };
380
- } else if (record.type === "throw") {
381
- state = GenStateCompleted; // Dispatch the exception by looping back around to the
382
- // context.dispatchException(context.arg) call above.
383
-
384
- context.method = "throw";
385
- context.arg = record.arg;
386
- }
387
- }
388
- };
389
- } // Call delegate.iterator[context.method](context.arg) and handle the
390
- // result, either by returning a { value, done } result from the
391
- // delegate iterator, or by modifying context.method and context.arg,
392
- // setting context.delegate to null, and returning the ContinueSentinel.
393
-
394
-
395
- function maybeInvokeDelegate(delegate, context) {
396
- var method = delegate.iterator[context.method];
397
-
398
- if (method === undefined$1) {
399
- // A .throw or .return when the delegate iterator has no .throw
400
- // method always terminates the yield* loop.
401
- context.delegate = null;
402
-
403
- if (context.method === "throw") {
404
- // Note: ["return"] must be used for ES3 parsing compatibility.
405
- if (delegate.iterator["return"]) {
406
- // If the delegate iterator has a return method, give it a
407
- // chance to clean up.
408
- context.method = "return";
409
- context.arg = undefined$1;
410
- maybeInvokeDelegate(delegate, context);
411
-
412
- if (context.method === "throw") {
413
- // If maybeInvokeDelegate(context) changed context.method from
414
- // "return" to "throw", let that override the TypeError below.
415
- return ContinueSentinel;
416
- }
417
- }
418
-
419
- context.method = "throw";
420
- context.arg = new TypeError("The iterator does not provide a 'throw' method");
421
- }
422
-
423
- return ContinueSentinel;
424
- }
425
-
426
- var record = tryCatch(method, delegate.iterator, context.arg);
427
-
428
- if (record.type === "throw") {
429
- context.method = "throw";
430
- context.arg = record.arg;
431
- context.delegate = null;
432
- return ContinueSentinel;
433
- }
434
-
435
- var info = record.arg;
436
-
437
- if (!info) {
438
- context.method = "throw";
439
- context.arg = new TypeError("iterator result is not an object");
440
- context.delegate = null;
441
- return ContinueSentinel;
442
- }
443
-
444
- if (info.done) {
445
- // Assign the result of the finished delegate to the temporary
446
- // variable specified by delegate.resultName (see delegateYield).
447
- context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield).
448
-
449
- context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the
450
- // exception, let the outer generator proceed normally. If
451
- // context.method was "next", forget context.arg since it has been
452
- // "consumed" by the delegate iterator. If context.method was
453
- // "return", allow the original .return call to continue in the
454
- // outer generator.
455
-
456
- if (context.method !== "return") {
457
- context.method = "next";
458
- context.arg = undefined$1;
459
- }
460
- } else {
461
- // Re-yield the result returned by the delegate method.
462
- return info;
463
- } // The delegate iterator is finished, so forget it and continue with
464
- // the outer generator.
465
-
466
-
467
- context.delegate = null;
468
- return ContinueSentinel;
469
- } // Define Generator.prototype.{next,throw,return} in terms of the
470
- // unified ._invoke helper method.
471
-
472
-
473
- defineIteratorMethods(Gp);
474
- define(Gp, toStringTagSymbol, "Generator"); // A Generator should always return itself as the iterator object when the
475
- // @@iterator function is called on it. Some browsers' implementations of the
476
- // iterator prototype chain incorrectly implement this, causing the Generator
477
- // object to not be returned from this call. This ensures that doesn't happen.
478
- // See https://github.com/facebook/regenerator/issues/274 for more details.
479
-
480
- define(Gp, iteratorSymbol, function () {
481
- return this;
482
- });
483
- define(Gp, "toString", function () {
484
- return "[object Generator]";
485
- });
486
-
487
- function pushTryEntry(locs) {
488
- var entry = {
489
- tryLoc: locs[0]
490
- };
491
-
492
- if (1 in locs) {
493
- entry.catchLoc = locs[1];
494
- }
495
-
496
- if (2 in locs) {
497
- entry.finallyLoc = locs[2];
498
- entry.afterLoc = locs[3];
499
- }
500
-
501
- this.tryEntries.push(entry);
502
- }
503
-
504
- function resetTryEntry(entry) {
505
- var record = entry.completion || {};
506
- record.type = "normal";
507
- delete record.arg;
508
- entry.completion = record;
509
- }
510
-
511
- function Context(tryLocsList) {
512
- // The root entry object (effectively a try statement without a catch
513
- // or a finally block) gives us a place to store values thrown from
514
- // locations where there is no enclosing try statement.
515
- this.tryEntries = [{
516
- tryLoc: "root"
517
- }];
518
- tryLocsList.forEach(pushTryEntry, this);
519
- this.reset(true);
520
- }
521
-
522
- exports.keys = function (object) {
523
- var keys = [];
524
-
525
- for (var key in object) {
526
- keys.push(key);
27
+ this.setState({
28
+ value
29
+ });
527
30
  }
528
31
 
529
- keys.reverse(); // Rather than returning an object with a next method, we keep
530
- // things simple and return the next function itself.
531
-
532
- return function next() {
533
- while (keys.length) {
534
- var key = keys.pop();
535
-
536
- if (key in object) {
537
- next.value = key;
538
- next.done = false;
539
- return next;
540
- }
541
- } // To avoid creating an additional object, we just hang the .value
542
- // and .done properties off the next function object itself. This
543
- // also ensures that the minifier will not anonymize the function.
544
-
545
-
546
- next.done = true;
547
- return next;
548
- };
32
+ await this.triggerSetValueCallbacks(value);
549
33
  };
550
34
 
551
- function values(iterable) {
552
- if (iterable) {
553
- var iteratorMethod = iterable[iteratorSymbol];
554
-
555
- if (iteratorMethod) {
556
- return iteratorMethod.call(iterable);
557
- }
558
-
559
- if (typeof iterable.next === "function") {
560
- return iterable;
561
- }
562
-
563
- if (!isNaN(iterable.length)) {
564
- var i = -1,
565
- next = function next() {
566
- while (++i < iterable.length) {
567
- if (hasOwn.call(iterable, i)) {
568
- next.value = iterable[i];
569
- next.done = false;
570
- return next;
571
- }
572
- }
573
-
574
- next.value = undefined$1;
575
- next.done = true;
576
- return next;
577
- };
578
-
579
- return next.next = next;
580
- }
581
- } // Return an iterator with no values.
582
-
583
-
584
- return {
585
- next: doneResult
586
- };
587
- }
588
-
589
- exports.values = values;
590
-
591
- function doneResult() {
592
- return {
593
- value: undefined$1,
594
- done: true
595
- };
596
- }
597
-
598
- Context.prototype = {
599
- constructor: Context,
600
- reset: function reset(skipTempReset) {
601
- this.prev = 0;
602
- this.next = 0; // Resetting context._sent for legacy support of Babel's
603
- // function.sent implementation.
604
-
605
- this.sent = this._sent = undefined$1;
606
- this.done = false;
607
- this.delegate = null;
608
- this.method = "next";
609
- this.arg = undefined$1;
610
- this.tryEntries.forEach(resetTryEntry);
611
-
612
- if (!skipTempReset) {
613
- for (var name in this) {
614
- // Not sure about the optimal order of these conditions:
615
- if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
616
- this[name] = undefined$1;
617
- }
618
- }
619
- }
620
- },
621
- stop: function stop() {
622
- this.done = true;
623
- var rootEntry = this.tryEntries[0];
624
- var rootRecord = rootEntry.completion;
625
-
626
- if (rootRecord.type === "throw") {
627
- throw rootRecord.arg;
628
- }
629
-
630
- return this.rval;
631
- },
632
- dispatchException: function dispatchException(exception) {
633
- if (this.done) {
634
- throw exception;
635
- }
636
-
637
- var context = this;
638
-
639
- function handle(loc, caught) {
640
- record.type = "throw";
641
- record.arg = exception;
642
- context.next = loc;
643
-
644
- if (caught) {
645
- // If the dispatched exception was caught by a catch block,
646
- // then let that catch block handle the exception normally.
647
- context.method = "next";
648
- context.arg = undefined$1;
649
- }
650
-
651
- return !!caught;
652
- }
653
-
654
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
655
- var entry = this.tryEntries[i];
656
- var record = entry.completion;
657
-
658
- if (entry.tryLoc === "root") {
659
- // Exception thrown outside of any try block that could handle
660
- // it, so set the completion value of the entire function to
661
- // throw the exception.
662
- return handle("end");
663
- }
664
-
665
- if (entry.tryLoc <= this.prev) {
666
- var hasCatch = hasOwn.call(entry, "catchLoc");
667
- var hasFinally = hasOwn.call(entry, "finallyLoc");
668
-
669
- if (hasCatch && hasFinally) {
670
- if (this.prev < entry.catchLoc) {
671
- return handle(entry.catchLoc, true);
672
- } else if (this.prev < entry.finallyLoc) {
673
- return handle(entry.finallyLoc);
674
- }
675
- } else if (hasCatch) {
676
- if (this.prev < entry.catchLoc) {
677
- return handle(entry.catchLoc, true);
678
- }
679
- } else if (hasFinally) {
680
- if (this.prev < entry.finallyLoc) {
681
- return handle(entry.finallyLoc);
682
- }
683
- } else {
684
- throw new Error("try statement without catch or finally");
685
- }
686
- }
687
- }
688
- },
689
- abrupt: function abrupt(type, arg) {
690
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
691
- var entry = this.tryEntries[i];
692
-
693
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
694
- var finallyEntry = entry;
695
- break;
696
- }
697
- }
698
-
699
- if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
700
- // Ignore the finally entry if control is not jumping to a
701
- // location outside the try/catch block.
702
- finallyEntry = null;
703
- }
704
-
705
- var record = finallyEntry ? finallyEntry.completion : {};
706
- record.type = type;
707
- record.arg = arg;
708
-
709
- if (finallyEntry) {
710
- this.method = "next";
711
- this.next = finallyEntry.finallyLoc;
712
- return ContinueSentinel;
713
- }
714
-
715
- return this.complete(record);
716
- },
717
- complete: function complete(record, afterLoc) {
718
- if (record.type === "throw") {
719
- throw record.arg;
720
- }
721
-
722
- if (record.type === "break" || record.type === "continue") {
723
- this.next = record.arg;
724
- } else if (record.type === "return") {
725
- this.rval = this.arg = record.arg;
726
- this.method = "return";
727
- this.next = "end";
728
- } else if (record.type === "normal" && afterLoc) {
729
- this.next = afterLoc;
730
- }
731
-
732
- return ContinueSentinel;
733
- },
734
- finish: function finish(finallyLoc) {
735
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
736
- var entry = this.tryEntries[i];
737
-
738
- if (entry.finallyLoc === finallyLoc) {
739
- this.complete(entry.completion, entry.afterLoc);
740
- resetTryEntry(entry);
741
- return ContinueSentinel;
742
- }
743
- }
744
- },
745
- "catch": function _catch(tryLoc) {
746
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
747
- var entry = this.tryEntries[i];
748
-
749
- if (entry.tryLoc === tryLoc) {
750
- var record = entry.completion;
751
-
752
- if (record.type === "throw") {
753
- var thrown = record.arg;
754
- resetTryEntry(entry);
755
- }
756
-
757
- return thrown;
758
- }
759
- } // The context.catch method must only be called with a location
760
- // argument that corresponds to a known catch block.
761
-
762
-
763
- throw new Error("illegal catch attempt");
764
- },
765
- delegateYield: function delegateYield(iterable, resultName, nextLoc) {
766
- this.delegate = {
767
- iterator: values(iterable),
768
- resultName: resultName,
769
- nextLoc: nextLoc
770
- };
771
-
772
- if (this.method === "next") {
773
- // Deliberately forget the last sent value so that we don't
774
- // accidentally pass it on to the delegate.
775
- this.arg = undefined$1;
776
- }
777
-
778
- return ContinueSentinel;
779
- }
780
- }; // Regardless of whether this script is executing as a CommonJS module
781
- // or not, return the runtime object so that we can declare the variable
782
- // regeneratorRuntime in the outer scope, which allows this module to be
783
- // injected easily by `bin/regenerator --include-runtime script.js`.
784
-
785
- return exports;
786
- }( // If this script is executing as a CommonJS module, use module.exports
787
- // as the regeneratorRuntime namespace. Otherwise create a new empty
788
- // object. Either way, the resulting object will be used to initialize
789
- // the regeneratorRuntime variable at the top of this file.
790
- module.exports );
791
-
792
- try {
793
- regeneratorRuntime = runtime;
794
- } catch (accidentalStrictMode) {
795
- // This module should not be running in strict mode, so the above
796
- // assignment should always work unless something is misconfigured. Just
797
- // in case runtime.js accidentally runs in strict mode, in modern engines
798
- // we can explicitly access globalThis. In older engines we can escape
799
- // strict mode using a global Function call. This could conceivably fail
800
- // if a Content Security Policy forbids using Function, but in that case
801
- // the proper solution is to fix the accidental strict mode problem. If
802
- // you've misconfigured your bundler to force strict mode and applied a
803
- // CSP to forbid Function, and you're not willing to fix either of those
804
- // problems, please detail your unique predicament in a GitHub issue.
805
- if (typeof globalThis === "object") {
806
- globalThis.regeneratorRuntime = runtime;
807
- } else {
808
- Function("r", "regeneratorRuntime = r")(runtime);
809
- }
810
- }
811
- });
812
-
813
- var FieldConnector = /*#__PURE__*/function (_React$Component) {
814
- _inheritsLoose(FieldConnector, _React$Component);
815
-
816
- function FieldConnector(props) {
817
- var _props$isInitiallyDis;
818
-
819
- var _this;
820
-
821
- _this = _React$Component.call(this, props) || this;
822
- _this.unsubscribeErrors = null;
823
- _this.unsubscribeDisabled = null;
824
- _this.unsubscribeValue = null;
825
-
826
- _this.setValue = /*#__PURE__*/function () {
827
- var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(value) {
828
- return runtime_1.wrap(function _callee$(_context) {
829
- while (1) {
830
- switch (_context.prev = _context.next) {
831
- case 0:
832
- if (_this.props.isEmptyValue(value != null ? value : null)) {
833
- _this.setState({
834
- value: undefined
835
- });
836
- } else {
837
- _this.setState({
838
- value: value
839
- });
840
- }
841
-
842
- _context.next = 3;
843
- return _this.triggerSetValueCallbacks(value);
844
-
845
- case 3:
846
- case "end":
847
- return _context.stop();
848
- }
849
- }
850
- }, _callee);
851
- }));
852
-
853
- return function (_x) {
854
- return _ref.apply(this, arguments);
855
- };
856
- }();
857
-
858
- _this.triggerSetValueCallbacks = throttle(function (value) {
859
- return new Promise(function (resolve, reject) {
860
- if (_this.props.isEmptyValue(value != null ? value : null)) {
861
- _this.props.field.removeValue().then(resolve)["catch"](reject);
35
+ this.triggerSetValueCallbacks = throttle(value => {
36
+ return new Promise((resolve, reject) => {
37
+ if (this.props.isEmptyValue(value ?? null)) {
38
+ this.props.field.removeValue().then(resolve).catch(reject);
862
39
  } else {
863
- _this.props.field.setValue(value).then(resolve)["catch"](reject);
40
+ this.props.field.setValue(value).then(resolve).catch(reject);
864
41
  }
865
42
  });
866
- }, _this.props.throttle, {
867
- leading: _this.props.throttle === 0
43
+ }, this.props.throttle, {
44
+ leading: this.props.throttle === 0
868
45
  });
869
- var initialValue = props.field.getValue();
870
- _this.state = {
46
+ const initialValue = props.field.getValue();
47
+ this.state = {
871
48
  isLocalValueChange: false,
872
49
  externalReset: 0,
873
50
  value: initialValue,
874
51
  lastRemoteValue: initialValue,
875
- disabled: (_props$isInitiallyDis = props.isInitiallyDisabled) != null ? _props$isInitiallyDis : false,
52
+ disabled: props.isInitiallyDisabled ?? false,
876
53
  errors: []
877
54
  };
878
- return _this;
879
55
  }
880
56
 
881
- var _proto = FieldConnector.prototype;
882
-
883
- _proto.componentDidMount = function componentDidMount() {
884
- var _this2 = this;
885
-
886
- var field = this.props.field;
887
- this.unsubscribeErrors = field.onSchemaErrorsChanged(function (errors) {
888
- _this2.setState({
57
+ componentDidMount() {
58
+ const {
59
+ field
60
+ } = this.props;
61
+ this.unsubscribeErrors = field.onSchemaErrorsChanged(errors => {
62
+ this.setState({
889
63
  errors: errors || []
890
64
  });
891
65
  });
892
- this.unsubscribeDisabled = field.onIsDisabledChanged(function (disabled) {
893
- _this2.setState({
894
- disabled: disabled
66
+ this.unsubscribeDisabled = field.onIsDisabledChanged(disabled => {
67
+ this.setState({
68
+ disabled
895
69
  });
896
70
  });
897
- this.unsubscribeValue = field.onValueChanged(function (value) {
898
- _this2.setState(function (currentState) {
899
- var isLocalValueChange = _this2.props.isEqualValues(value, currentState.value);
900
-
901
- var lastRemoteValue = isLocalValueChange ? currentState.lastRemoteValue : value;
902
- var externalReset = currentState.externalReset + (isLocalValueChange ? 0 : 1);
71
+ this.unsubscribeValue = field.onValueChanged(value => {
72
+ this.setState(currentState => {
73
+ const isLocalValueChange = this.props.isEqualValues(value, currentState.value);
74
+ const lastRemoteValue = isLocalValueChange ? currentState.lastRemoteValue : value;
75
+ const externalReset = currentState.externalReset + (isLocalValueChange ? 0 : 1);
903
76
  return {
904
- value: value,
905
- lastRemoteValue: lastRemoteValue,
906
- isLocalValueChange: isLocalValueChange,
907
- externalReset: externalReset
77
+ value,
78
+ lastRemoteValue,
79
+ isLocalValueChange,
80
+ externalReset
908
81
  };
909
82
  });
910
83
  });
911
- };
84
+ }
912
85
 
913
- _proto.componentWillUnmount = function componentWillUnmount() {
86
+ componentWillUnmount() {
914
87
  if (typeof this.unsubscribeErrors === 'function') {
915
88
  this.unsubscribeErrors();
916
89
  }
@@ -922,27 +95,26 @@ var FieldConnector = /*#__PURE__*/function (_React$Component) {
922
95
  if (typeof this.unsubscribeValue === 'function') {
923
96
  this.unsubscribeValue();
924
97
  }
925
- };
98
+ }
926
99
 
927
- _proto.render = function render() {
928
- return this.props.children(_extends({}, this.state, {
100
+ render() {
101
+ return this.props.children({ ...this.state,
929
102
  setValue: this.setValue,
930
103
  disabled: this.props.isDisabled || this.state.disabled
931
- }));
932
- };
104
+ });
105
+ }
933
106
 
934
- return FieldConnector;
935
- }(React.Component);
107
+ }
936
108
  FieldConnector.defaultProps = {
937
- children: function children() {
109
+ children: () => {
938
110
  return null;
939
111
  },
940
112
  // eslint-disable-next-line -- TODO: describe this disable
941
- isEmptyValue: function isEmptyValue(value) {
113
+ isEmptyValue: value => {
942
114
  return value === null || value === '';
943
115
  },
944
116
  // eslint-disable-next-line -- TODO: describe this disable
945
- isEqualValues: function isEqualValues(value1, value2) {
117
+ isEqualValues: (value1, value2) => {
946
118
  return isEqual(value1, value2);
947
119
  },
948
120
  throttle: 300
@@ -955,29 +127,31 @@ function PredefinedValuesError() {
955
127
  }, "The widget failed to initialize. You can fix the problem by providing predefined values under the validations tab in the field settings.");
956
128
  }
957
129
 
958
- var styles = {
130
+ const styles = {
959
131
  invalid: /*#__PURE__*/css({
960
132
  color: tokens.red600
961
133
  })
962
134
  };
963
135
  function CharCounter(props) {
964
- var _cx;
965
-
966
- var count = 0;
136
+ let count = 0;
967
137
 
968
138
  if (props.value) {
969
139
  count = props.value.length;
970
140
  }
971
141
 
972
- var valid = count === 0 || props.checkConstraint(count);
142
+ const valid = count === 0 || props.checkConstraint(count);
973
143
  return React.createElement("span", {
974
144
  "data-status-code": valid ? null : 'invalid-size',
975
- className: cx((_cx = {}, _cx[styles.invalid] = !valid, _cx))
145
+ className: cx({
146
+ [styles.invalid]: !valid
147
+ })
976
148
  }, count, " characters");
977
149
  }
978
150
 
979
151
  function CharValidation(props) {
980
- var constraints = props.constraints;
152
+ const {
153
+ constraints
154
+ } = props;
981
155
 
982
156
  if (constraints.type === 'max') {
983
157
  return React.createElement("span", null, "Maximum ", constraints.max, " characters");
@@ -988,10 +162,11 @@ function CharValidation(props) {
988
162
  }
989
163
  }
990
164
 
165
+ /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-use-before-define */
991
166
  function open(componentRenderer) {
992
- var rootDom = null;
167
+ let rootDom = null;
993
168
 
994
- var getRoot = function getRoot() {
169
+ const getRoot = () => {
995
170
  if (rootDom === null) {
996
171
  rootDom = document.createElement('div');
997
172
  rootDom.setAttribute('id', 'field-editor-modal-root');
@@ -1001,29 +176,30 @@ function open(componentRenderer) {
1001
176
  return rootDom;
1002
177
  };
1003
178
 
1004
- return new Promise(function (resolve) {
1005
- var currentConfig = {
1006
- onClose: onClose,
179
+ return new Promise(resolve => {
180
+ let currentConfig = {
181
+ onClose,
1007
182
  isShown: true
1008
183
  };
1009
184
 
1010
- function render(_ref) {
1011
- var onClose = _ref.onClose,
1012
- isShown = _ref.isShown;
185
+ function render({
186
+ onClose,
187
+ isShown
188
+ }) {
1013
189
  ReactDOM.render(componentRenderer({
1014
- onClose: onClose,
1015
- isShown: isShown
190
+ onClose,
191
+ isShown
1016
192
  }), getRoot());
1017
193
  }
1018
194
 
1019
- function onClose() {
1020
- currentConfig = _extends({}, currentConfig, {
195
+ function onClose(...args) {
196
+ currentConfig = { ...currentConfig,
1021
197
  isShown: false
1022
- });
198
+ };
1023
199
  render(currentConfig); // eslint-disable-next-line -- TODO: describe this disable @typescript-eslint/ban-ts-comment
1024
200
  // @ts-ignore
1025
201
 
1026
- resolve.apply(void 0, arguments);
202
+ resolve(...args);
1027
203
  getRoot().remove();
1028
204
  }
1029
205
 
@@ -1031,15 +207,13 @@ function open(componentRenderer) {
1031
207
  });
1032
208
  }
1033
209
  function openDialog(options, Component) {
1034
- var key = Date.now();
1035
- var size = isNumber(options.width) ? options.width + "px" : options.width;
1036
- return open(function (_ref2) {
1037
- var isShown = _ref2.isShown,
1038
- onClose = _ref2.onClose;
1039
-
1040
- var onCloseHandler = function onCloseHandler() {
1041
- return onClose();
1042
- };
210
+ const key = Date.now();
211
+ const size = isNumber(options.width) ? `${options.width}px` : options.width;
212
+ return open(({
213
+ isShown,
214
+ onClose
215
+ }) => {
216
+ const onCloseHandler = () => onClose();
1043
217
 
1044
218
  return React.createElement(Modal, {
1045
219
  key: key,
@@ -1050,23 +224,21 @@ function openDialog(options, Component) {
1050
224
  isShown: isShown,
1051
225
  onClose: onCloseHandler,
1052
226
  size: size || '700px'
1053
- }, function () {
1054
- return React.createElement(React.Fragment, null, options.title && React.createElement(ModalHeader, {
1055
- testId: "dialog-title",
1056
- title: options.title,
1057
- onClose: onCloseHandler
1058
- }), React.createElement("div", {
1059
- style: {
1060
- minHeight: options.minHeight || 'auto'
1061
- }
1062
- }, React.createElement(Component, {
1063
- onClose: onClose
1064
- })));
1065
- });
227
+ }, () => React.createElement(React.Fragment, null, options.title && React.createElement(ModalHeader, {
228
+ testId: "dialog-title",
229
+ title: options.title,
230
+ onClose: onCloseHandler
231
+ }), React.createElement("div", {
232
+ style: {
233
+ minHeight: options.minHeight || 'auto'
234
+ }
235
+ }, React.createElement(Component, {
236
+ onClose: onClose
237
+ }))));
1066
238
  });
1067
239
  }
1068
240
  var ModalDialogLauncher = {
1069
- openDialog: openDialog
241
+ openDialog
1070
242
  };
1071
243
 
1072
244
  var ModalDialogLauncher$1 = {
@@ -1082,7 +254,7 @@ function titleOrDefault(title, defaultTitle) {
1082
254
  }
1083
255
 
1084
256
  if (title) {
1085
- var trimmedTitle = title.trim();
257
+ const trimmedTitle = title.trim();
1086
258
 
1087
259
  if (trimmedTitle.length === 0) {
1088
260
  return defaultTitle;
@@ -1094,36 +266,41 @@ function titleOrDefault(title, defaultTitle) {
1094
266
  return defaultTitle;
1095
267
  }
1096
268
 
1097
- function getFieldValue(_ref) {
1098
- var entity = _ref.entity,
1099
- fieldId = _ref.fieldId,
1100
- localeCode = _ref.localeCode,
1101
- defaultLocaleCode = _ref.defaultLocaleCode;
1102
- var values = get(entity, ['fields', fieldId]);
269
+ function getFieldValue({
270
+ /**
271
+ * Expects an entity fetched with a flag Skip-Transformation: true
272
+ */
273
+ entity,
274
+ fieldId,
275
+ localeCode,
276
+ defaultLocaleCode
277
+ }) {
278
+ const values = get(entity, ['fields', fieldId]);
1103
279
 
1104
280
  if (!isObject(values)) {
1105
281
  return;
1106
282
  }
1107
283
 
1108
- var firstLocaleCode = Object.keys(values)[0];
284
+ const firstLocaleCode = Object.keys(values)[0];
1109
285
  return values[localeCode] || values[defaultLocaleCode] || values[firstLocaleCode];
1110
286
  }
1111
- function getAssetTitle(_ref2) {
287
+ function getAssetTitle({
288
+ asset,
289
+ localeCode,
290
+ defaultLocaleCode,
291
+ defaultTitle
292
+ }) {
1112
293
  var _asset$fields;
1113
294
 
1114
- var asset = _ref2.asset,
1115
- localeCode = _ref2.localeCode,
1116
- defaultLocaleCode = _ref2.defaultLocaleCode,
1117
- defaultTitle = _ref2.defaultTitle;
1118
- var title = getFieldValue({
295
+ const title = getFieldValue({
1119
296
  entity: {
1120
297
  fields: {
1121
298
  title: (_asset$fields = asset.fields) == null ? void 0 : _asset$fields.title
1122
299
  }
1123
300
  },
1124
301
  fieldId: 'title',
1125
- localeCode: localeCode,
1126
- defaultLocaleCode: defaultLocaleCode
302
+ localeCode,
303
+ defaultLocaleCode
1127
304
  });
1128
305
  return titleOrDefault(title, defaultTitle);
1129
306
  }
@@ -1134,88 +311,80 @@ function getAssetTitle(_ref2) {
1134
311
  * @returns {boolean}
1135
312
  */
1136
313
 
1137
- var isAssetField = function isAssetField(field) {
1138
- return field.type === 'Link' && field.linkType === 'Asset';
1139
- };
314
+ const isAssetField = field => field.type === 'Link' && field.linkType === 'Asset';
1140
315
  /**
1141
316
  * Returns true if field is a Title
1142
317
  */
1143
318
 
1144
- function isDisplayField(_ref3) {
1145
- var field = _ref3.field,
1146
- contentType = _ref3.contentType;
319
+ function isDisplayField({
320
+ field,
321
+ contentType
322
+ }) {
1147
323
  return field.id === contentType.displayField;
1148
324
  }
1149
325
  /**
1150
326
  * Returns true if field is a short Description
1151
327
  */
1152
328
 
1153
- function isDescriptionField(_ref4) {
1154
- var field = _ref4.field,
1155
- contentType = _ref4.contentType;
329
+ function isDescriptionField({
330
+ field,
331
+ contentType
332
+ }) {
333
+ const isTextField = field => ['Symbol', 'Text'].includes(field.type);
1156
334
 
1157
- var isTextField = function isTextField(field) {
1158
- return ['Symbol', 'Text'].includes(field.type);
1159
- };
1160
-
1161
- var isMaybeSlugField = function isMaybeSlugField(field) {
1162
- return /\bslug\b/.test(field.name);
1163
- };
335
+ const isMaybeSlugField = field => /\bslug\b/.test(field.name);
1164
336
 
1165
337
  return isTextField(field) && !isDisplayField({
1166
- field: field,
1167
- contentType: contentType
338
+ field,
339
+ contentType
1168
340
  }) && !isMaybeSlugField(field);
1169
341
  }
1170
- function getEntityDescription(_ref5) {
1171
- var entity = _ref5.entity,
1172
- contentType = _ref5.contentType,
1173
- localeCode = _ref5.localeCode,
1174
- defaultLocaleCode = _ref5.defaultLocaleCode;
1175
-
342
+ function getEntityDescription({
343
+ entity,
344
+ contentType,
345
+ localeCode,
346
+ defaultLocaleCode
347
+ }) {
1176
348
  if (!contentType) {
1177
349
  return '';
1178
350
  }
1179
351
 
1180
- var descriptionField = contentType.fields.find(function (field) {
1181
- return isDescriptionField({
1182
- field: field,
1183
- contentType: contentType
1184
- });
1185
- });
352
+ const descriptionField = contentType.fields.find(field => isDescriptionField({
353
+ field,
354
+ contentType
355
+ }));
1186
356
 
1187
357
  if (!descriptionField) {
1188
358
  return '';
1189
359
  }
1190
360
 
1191
361
  return getFieldValue({
1192
- entity: entity,
362
+ entity,
1193
363
  fieldId: descriptionField.id,
1194
- localeCode: localeCode,
1195
- defaultLocaleCode: defaultLocaleCode
364
+ localeCode,
365
+ defaultLocaleCode
1196
366
  }) || '';
1197
367
  }
1198
- function getEntryTitle(_ref6) {
1199
- var entry = _ref6.entry,
1200
- contentType = _ref6.contentType,
1201
- localeCode = _ref6.localeCode,
1202
- defaultLocaleCode = _ref6.defaultLocaleCode,
1203
- defaultTitle = _ref6.defaultTitle;
1204
- var title;
368
+ function getEntryTitle({
369
+ entry,
370
+ contentType,
371
+ localeCode,
372
+ defaultLocaleCode,
373
+ defaultTitle
374
+ }) {
375
+ let title;
1205
376
 
1206
377
  if (!contentType) {
1207
378
  return defaultTitle;
1208
379
  }
1209
380
 
1210
- var displayField = contentType.displayField;
381
+ const displayField = contentType.displayField;
1211
382
 
1212
383
  if (!displayField) {
1213
384
  return defaultTitle;
1214
385
  }
1215
386
 
1216
- var displayFieldInfo = contentType.fields.find(function (field) {
1217
- return field.id === displayField;
1218
- });
387
+ const displayFieldInfo = contentType.fields.find(field => field.id === displayField);
1219
388
 
1220
389
  if (!displayFieldInfo) {
1221
390
  return defaultTitle;
@@ -1228,8 +397,8 @@ function getEntryTitle(_ref6) {
1228
397
  title = getFieldValue({
1229
398
  entity: entry,
1230
399
  fieldId: displayField,
1231
- localeCode: localeCode,
1232
- defaultLocaleCode: defaultLocaleCode
400
+ localeCode,
401
+ defaultLocaleCode
1233
402
  });
1234
403
 
1235
404
  if (!title) {
@@ -1239,15 +408,15 @@ function getEntryTitle(_ref6) {
1239
408
  title = getFieldValue({
1240
409
  entity: entry,
1241
410
  fieldId: displayFieldInfo.id,
1242
- localeCode: localeCode,
1243
- defaultLocaleCode: defaultLocaleCode
411
+ localeCode,
412
+ defaultLocaleCode
1244
413
  });
1245
414
  }
1246
415
  } else {
1247
416
  title = getFieldValue({
1248
417
  entity: entry,
1249
418
  fieldId: displayField,
1250
- defaultLocaleCode: defaultLocaleCode,
419
+ defaultLocaleCode,
1251
420
  localeCode: ''
1252
421
  });
1253
422
 
@@ -1255,7 +424,7 @@ function getEntryTitle(_ref6) {
1255
424
  title = getFieldValue({
1256
425
  entity: entry,
1257
426
  fieldId: displayFieldInfo.id,
1258
- defaultLocaleCode: defaultLocaleCode,
427
+ defaultLocaleCode,
1259
428
  localeCode: ''
1260
429
  });
1261
430
  }
@@ -1287,70 +456,36 @@ function getEntryStatus(sys) {
1287
456
  * given entities file. The promise may resolve with null.
1288
457
  */
1289
458
 
1290
- var getEntryImage = /*#__PURE__*/function () {
1291
- var _ref8 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref7, getAsset) {
1292
- var entry, contentType, localeCode, assetLink, assetId, asset, file, isImage;
1293
- return runtime_1.wrap(function _callee$(_context) {
1294
- while (1) {
1295
- switch (_context.prev = _context.next) {
1296
- case 0:
1297
- entry = _ref7.entry, contentType = _ref7.contentType, localeCode = _ref7.localeCode;
1298
-
1299
- if (contentType) {
1300
- _context.next = 3;
1301
- break;
1302
- }
1303
-
1304
- return _context.abrupt("return", null);
1305
-
1306
- case 3:
1307
- assetLink = contentType.fields.find(isAssetField);
1308
-
1309
- if (assetLink) {
1310
- _context.next = 6;
1311
- break;
1312
- }
1313
-
1314
- return _context.abrupt("return", null);
1315
-
1316
- case 6:
1317
- assetId = get(entry.fields, [assetLink.id, localeCode, 'sys', 'id']);
1318
-
1319
- if (assetId) {
1320
- _context.next = 9;
1321
- break;
1322
- }
1323
-
1324
- return _context.abrupt("return", null);
1325
-
1326
- case 9:
1327
- _context.prev = 9;
1328
- _context.next = 12;
1329
- return getAsset(assetId);
1330
-
1331
- case 12:
1332
- asset = _context.sent;
1333
- file = get(asset, ['fields', 'file', localeCode]);
1334
- isImage = Boolean(get(file, ['details', 'image'], false));
1335
- return _context.abrupt("return", isImage ? file : null);
1336
-
1337
- case 18:
1338
- _context.prev = 18;
1339
- _context.t0 = _context["catch"](9);
1340
- return _context.abrupt("return", null);
1341
-
1342
- case 21:
1343
- case "end":
1344
- return _context.stop();
1345
- }
1346
- }
1347
- }, _callee, null, [[9, 18]]);
1348
- }));
459
+ const getEntryImage = async ({
460
+ entry,
461
+ contentType,
462
+ localeCode
463
+ }, getAsset) => {
464
+ if (!contentType) {
465
+ return null;
466
+ }
1349
467
 
1350
- return function getEntryImage(_x, _x2) {
1351
- return _ref8.apply(this, arguments);
1352
- };
1353
- }();
468
+ const assetLink = contentType.fields.find(isAssetField);
469
+
470
+ if (!assetLink) {
471
+ return null;
472
+ }
473
+
474
+ const assetId = get(entry.fields, [assetLink.id, localeCode, 'sys', 'id']);
475
+
476
+ if (!assetId) {
477
+ return null;
478
+ }
479
+
480
+ try {
481
+ const asset = await getAsset(assetId);
482
+ const file = get(asset, ['fields', 'file', localeCode]);
483
+ const isImage = Boolean(get(file, ['details', 'image'], false));
484
+ return isImage ? file : null;
485
+ } catch (e) {
486
+ return null;
487
+ }
488
+ };
1354
489
 
1355
490
  var entityHelpers = {
1356
491
  __proto__: null,
@@ -1366,33 +501,27 @@ var entityHelpers = {
1366
501
  };
1367
502
 
1368
503
  /* eslint-disable @typescript-eslint/no-explicit-any */
1369
- function fromFieldValidations(validations, fieldType) {
1370
- if (validations === void 0) {
1371
- validations = [];
1372
- }
1373
-
1374
- var sizeValidation = validations.find(function (v) {
1375
- return 'size' in v;
1376
- });
1377
- var size = sizeValidation && sizeValidation.size || {};
1378
- var min = size.min;
1379
- var max = size.max;
504
+ function fromFieldValidations(validations = [], fieldType) {
505
+ const sizeValidation = validations.find(v => 'size' in v);
506
+ const size = sizeValidation && sizeValidation.size || {};
507
+ const min = size.min;
508
+ const max = size.max;
1380
509
 
1381
510
  if (isNumber(min) && isNumber(max)) {
1382
511
  return {
1383
512
  type: 'min-max',
1384
- min: min,
1385
- max: max
513
+ min,
514
+ max
1386
515
  };
1387
516
  } else if (isNumber(min)) {
1388
517
  return {
1389
518
  type: 'min',
1390
- min: min
519
+ min
1391
520
  };
1392
521
  } else if (isNumber(max)) {
1393
522
  return {
1394
523
  type: 'max',
1395
- max: max
524
+ max
1396
525
  };
1397
526
  } else {
1398
527
  return {
@@ -1423,7 +552,7 @@ var constraints = {
1423
552
  * Checks whether the passed content type matches one of our valid MIME types
1424
553
  */
1425
554
  function isValidImage(file) {
1426
- var validMimeTypes = ['image/avif', 'image/bmp', 'image/x-windows-bmp', 'image/gif', 'image/webp', // This is not a valid MIME type but we supported it in the past.
555
+ const validMimeTypes = ['image/avif', 'image/bmp', 'image/x-windows-bmp', 'image/gif', 'image/webp', // This is not a valid MIME type but we supported it in the past.
1427
556
  'image/jpg', 'image/jpeg', 'image/pjpeg', 'image/x-jps', 'image/png', 'image/svg+xml'];
1428
557
  return validMimeTypes.includes(file.contentType);
1429
558
  }
@@ -1456,42 +585,34 @@ function shortenStorageUnit(value, uom) {
1456
585
  return '0 B';
1457
586
  }
1458
587
 
1459
- var units = ['PB', 'TB', 'GB', 'MB', 'KB', 'B'];
588
+ const units = ['PB', 'TB', 'GB', 'MB', 'KB', 'B'];
1460
589
 
1461
- var getBigger = function getBigger(unit) {
1462
- return units[units.indexOf(unit) - 1];
1463
- };
590
+ const getBigger = unit => units[units.indexOf(unit) - 1];
1464
591
 
1465
- var getSmaller = function getSmaller(unit) {
1466
- return units[units.indexOf(unit) + 1];
1467
- };
592
+ const getSmaller = unit => units[units.indexOf(unit) + 1];
1468
593
 
1469
- var isBiggestUnit = function isBiggestUnit(unit) {
1470
- return units.indexOf(unit) === 0;
1471
- };
594
+ const isBiggestUnit = unit => units.indexOf(unit) === 0;
1472
595
 
1473
- var isSmallestUnit = function isSmallestUnit(unit) {
1474
- return units.indexOf(unit) === units.length - 1;
1475
- };
596
+ const isSmallestUnit = unit => units.indexOf(unit) === units.length - 1;
1476
597
 
1477
- var reduce = function reduce(number, unit) {
598
+ const reduce = (number, unit) => {
1478
599
  if (number < 0.99 && !isSmallestUnit(unit)) {
1479
600
  return reduce(number * 1000, getSmaller(unit));
1480
601
  } else if (number >= 1000 && !isBiggestUnit(unit)) {
1481
602
  return reduce(number / 1000, getBigger(unit));
1482
603
  } else {
1483
604
  return {
1484
- number: number,
1485
- unit: unit
605
+ number,
606
+ unit
1486
607
  };
1487
608
  }
1488
609
  };
1489
610
 
1490
- var _reduce = reduce(value, uom),
1491
- number = _reduce.number,
1492
- unit = _reduce.unit;
1493
-
1494
- return formatFloat(number, false) + " " + unit;
611
+ const {
612
+ number,
613
+ unit
614
+ } = reduce(value, uom);
615
+ return `${formatFloat(number, false)} ${unit}`;
1495
616
  }
1496
617
 
1497
618
  export { CharCounter, CharValidation, constraints as ConstraintsUtils, FieldConnector, ModalDialogLauncher$1 as ModalDialogLauncher, PredefinedValuesError, entityHelpers, isValidImage, shortenStorageUnit, toLocaleString };