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