@contentful/field-editor-slug 1.1.12 → 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.
@@ -1,915 +1,21 @@
1
1
  import React__default, { useCallback, createElement } from 'react';
2
2
  import { FieldConnector } from '@contentful/field-editor-shared';
3
+ import { TextInput, Spinner, ValidationMessage } from '@contentful/f36-components';
4
+ import { LinkIcon } from '@contentful/f36-icons';
3
5
  import { useDebounce } from 'use-debounce';
4
6
  import getSlug from 'speakingurl';
5
7
  import tokens from '@contentful/f36-tokens';
6
8
  import { css } from 'emotion';
7
- import { TextInput, Spinner, ValidationMessage } from '@contentful/f36-components';
8
- import { LinkIcon } from '@contentful/f36-icons';
9
-
10
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
11
- try {
12
- var info = gen[key](arg);
13
- var value = info.value;
14
- } catch (error) {
15
- reject(error);
16
- return;
17
- }
18
-
19
- if (info.done) {
20
- resolve(value);
21
- } else {
22
- Promise.resolve(value).then(_next, _throw);
23
- }
24
- }
25
-
26
- function _asyncToGenerator(fn) {
27
- return function () {
28
- var self = this,
29
- args = arguments;
30
- return new Promise(function (resolve, reject) {
31
- var gen = fn.apply(self, args);
32
-
33
- function _next(value) {
34
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
35
- }
36
-
37
- function _throw(err) {
38
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
39
- }
40
-
41
- _next(undefined);
42
- });
43
- };
44
- }
45
-
46
- function _extends() {
47
- _extends = Object.assign || function (target) {
48
- for (var i = 1; i < arguments.length; i++) {
49
- var source = arguments[i];
50
-
51
- for (var key in source) {
52
- if (Object.prototype.hasOwnProperty.call(source, key)) {
53
- target[key] = source[key];
54
- }
55
- }
56
- }
57
-
58
- return target;
59
- };
60
-
61
- return _extends.apply(this, arguments);
62
- }
63
-
64
- function _inheritsLoose(subClass, superClass) {
65
- subClass.prototype = Object.create(superClass.prototype);
66
- subClass.prototype.constructor = subClass;
67
-
68
- _setPrototypeOf(subClass, superClass);
69
- }
70
-
71
- function _setPrototypeOf(o, p) {
72
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
73
- o.__proto__ = p;
74
- return o;
75
- };
76
-
77
- return _setPrototypeOf(o, p);
78
- }
79
-
80
- function createCommonjsModule(fn, module) {
81
- return module = { exports: {} }, fn(module, module.exports), module.exports;
82
- }
83
-
84
- var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
85
- /**
86
- * Copyright (c) 2014-present, Facebook, Inc.
87
- *
88
- * This source code is licensed under the MIT license found in the
89
- * LICENSE file in the root directory of this source tree.
90
- */
91
- var runtime = function (exports) {
92
-
93
- var Op = Object.prototype;
94
- var hasOwn = Op.hasOwnProperty;
95
- var undefined$1; // More compressible than void 0.
96
-
97
- var $Symbol = typeof Symbol === "function" ? Symbol : {};
98
- var iteratorSymbol = $Symbol.iterator || "@@iterator";
99
- var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
100
- var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
101
-
102
- function define(obj, key, value) {
103
- Object.defineProperty(obj, key, {
104
- value: value,
105
- enumerable: true,
106
- configurable: true,
107
- writable: true
108
- });
109
- return obj[key];
110
- }
111
-
112
- try {
113
- // IE 8 has a broken Object.defineProperty that only works on DOM objects.
114
- define({}, "");
115
- } catch (err) {
116
- define = function define(obj, key, value) {
117
- return obj[key] = value;
118
- };
119
- }
120
-
121
- function wrap(innerFn, outerFn, self, tryLocsList) {
122
- // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
123
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
124
- var generator = Object.create(protoGenerator.prototype);
125
- var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next,
126
- // .throw, and .return methods.
127
-
128
- generator._invoke = makeInvokeMethod(innerFn, self, context);
129
- return generator;
130
- }
131
-
132
- exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion
133
- // record like context.tryEntries[i].completion. This interface could
134
- // have been (and was previously) designed to take a closure to be
135
- // invoked without arguments, but in all the cases we care about we
136
- // already have an existing method we want to call, so there's no need
137
- // to create a new function object. We can even get away with assuming
138
- // the method takes exactly one argument, since that happens to be true
139
- // in every case, so we don't have to touch the arguments object. The
140
- // only additional allocation required is the completion record, which
141
- // has a stable shape and so hopefully should be cheap to allocate.
142
-
143
- function tryCatch(fn, obj, arg) {
144
- try {
145
- return {
146
- type: "normal",
147
- arg: fn.call(obj, arg)
148
- };
149
- } catch (err) {
150
- return {
151
- type: "throw",
152
- arg: err
153
- };
154
- }
155
- }
156
-
157
- var GenStateSuspendedStart = "suspendedStart";
158
- var GenStateSuspendedYield = "suspendedYield";
159
- var GenStateExecuting = "executing";
160
- var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as
161
- // breaking out of the dispatch switch statement.
162
-
163
- var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and
164
- // .constructor.prototype properties for functions that return Generator
165
- // objects. For full spec compliance, you may wish to configure your
166
- // minifier not to mangle the names of these two functions.
167
-
168
- function Generator() {}
169
-
170
- function GeneratorFunction() {}
171
-
172
- function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that
173
- // don't natively support it.
174
-
175
-
176
- var IteratorPrototype = {};
177
- define(IteratorPrototype, iteratorSymbol, function () {
178
- return this;
179
- });
180
- var getProto = Object.getPrototypeOf;
181
- var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
182
-
183
- if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
184
- // This environment has a native %IteratorPrototype%; use it instead
185
- // of the polyfill.
186
- IteratorPrototype = NativeIteratorPrototype;
187
- }
188
-
189
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
190
- GeneratorFunction.prototype = GeneratorFunctionPrototype;
191
- define(Gp, "constructor", GeneratorFunctionPrototype);
192
- define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
193
- GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
194
- // Iterator interface in terms of a single ._invoke method.
195
-
196
- function defineIteratorMethods(prototype) {
197
- ["next", "throw", "return"].forEach(function (method) {
198
- define(prototype, method, function (arg) {
199
- return this._invoke(method, arg);
200
- });
201
- });
202
- }
203
-
204
- exports.isGeneratorFunction = function (genFun) {
205
- var ctor = typeof genFun === "function" && genFun.constructor;
206
- return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can
207
- // do is to check its .name property.
208
- (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
209
- };
210
-
211
- exports.mark = function (genFun) {
212
- if (Object.setPrototypeOf) {
213
- Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
214
- } else {
215
- genFun.__proto__ = GeneratorFunctionPrototype;
216
- define(genFun, toStringTagSymbol, "GeneratorFunction");
217
- }
218
-
219
- genFun.prototype = Object.create(Gp);
220
- return genFun;
221
- }; // Within the body of any async function, `await x` is transformed to
222
- // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
223
- // `hasOwn.call(value, "__await")` to determine if the yielded value is
224
- // meant to be awaited.
225
-
226
-
227
- exports.awrap = function (arg) {
228
- return {
229
- __await: arg
230
- };
231
- };
232
-
233
- function AsyncIterator(generator, PromiseImpl) {
234
- function invoke(method, arg, resolve, reject) {
235
- var record = tryCatch(generator[method], generator, arg);
236
-
237
- if (record.type === "throw") {
238
- reject(record.arg);
239
- } else {
240
- var result = record.arg;
241
- var value = result.value;
242
-
243
- if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
244
- return PromiseImpl.resolve(value.__await).then(function (value) {
245
- invoke("next", value, resolve, reject);
246
- }, function (err) {
247
- invoke("throw", err, resolve, reject);
248
- });
249
- }
250
-
251
- return PromiseImpl.resolve(value).then(function (unwrapped) {
252
- // When a yielded Promise is resolved, its final value becomes
253
- // the .value of the Promise<{value,done}> result for the
254
- // current iteration.
255
- result.value = unwrapped;
256
- resolve(result);
257
- }, function (error) {
258
- // If a rejected Promise was yielded, throw the rejection back
259
- // into the async generator function so it can be handled there.
260
- return invoke("throw", error, resolve, reject);
261
- });
262
- }
263
- }
264
-
265
- var previousPromise;
266
-
267
- function enqueue(method, arg) {
268
- function callInvokeWithMethodAndArg() {
269
- return new PromiseImpl(function (resolve, reject) {
270
- invoke(method, arg, resolve, reject);
271
- });
272
- }
273
-
274
- return previousPromise = // If enqueue has been called before, then we want to wait until
275
- // all previous Promises have been resolved before calling invoke,
276
- // so that results are always delivered in the correct order. If
277
- // enqueue has not been called before, then it is important to
278
- // call invoke immediately, without waiting on a callback to fire,
279
- // so that the async generator function has the opportunity to do
280
- // any necessary setup in a predictable way. This predictability
281
- // is why the Promise constructor synchronously invokes its
282
- // executor callback, and why async functions synchronously
283
- // execute code before the first await. Since we implement simple
284
- // async functions in terms of async generators, it is especially
285
- // important to get this right, even though it requires care.
286
- previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later
287
- // invocations of the iterator.
288
- callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
289
- } // Define the unified helper method that is used to implement .next,
290
- // .throw, and .return (see defineIteratorMethods).
291
-
292
-
293
- this._invoke = enqueue;
294
- }
295
-
296
- defineIteratorMethods(AsyncIterator.prototype);
297
- define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
298
- return this;
299
- });
300
- exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
301
- // AsyncIterator objects; they just return a Promise for the value of
302
- // the final result produced by the iterator.
303
-
304
- exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
305
- if (PromiseImpl === void 0) PromiseImpl = Promise;
306
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
307
- return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
308
- : iter.next().then(function (result) {
309
- return result.done ? result.value : iter.next();
310
- });
311
- };
312
-
313
- function makeInvokeMethod(innerFn, self, context) {
314
- var state = GenStateSuspendedStart;
315
- return function invoke(method, arg) {
316
- if (state === GenStateExecuting) {
317
- throw new Error("Generator is already running");
318
- }
319
-
320
- if (state === GenStateCompleted) {
321
- if (method === "throw") {
322
- throw arg;
323
- } // Be forgiving, per 25.3.3.3.3 of the spec:
324
- // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
325
-
326
-
327
- return doneResult();
328
- }
329
-
330
- context.method = method;
331
- context.arg = arg;
332
-
333
- while (true) {
334
- var delegate = context.delegate;
335
-
336
- if (delegate) {
337
- var delegateResult = maybeInvokeDelegate(delegate, context);
338
-
339
- if (delegateResult) {
340
- if (delegateResult === ContinueSentinel) continue;
341
- return delegateResult;
342
- }
343
- }
344
-
345
- if (context.method === "next") {
346
- // Setting context._sent for legacy support of Babel's
347
- // function.sent implementation.
348
- context.sent = context._sent = context.arg;
349
- } else if (context.method === "throw") {
350
- if (state === GenStateSuspendedStart) {
351
- state = GenStateCompleted;
352
- throw context.arg;
353
- }
354
-
355
- context.dispatchException(context.arg);
356
- } else if (context.method === "return") {
357
- context.abrupt("return", context.arg);
358
- }
359
-
360
- state = GenStateExecuting;
361
- var record = tryCatch(innerFn, self, context);
362
-
363
- if (record.type === "normal") {
364
- // If an exception is thrown from innerFn, we leave state ===
365
- // GenStateExecuting and loop back for another invocation.
366
- state = context.done ? GenStateCompleted : GenStateSuspendedYield;
367
-
368
- if (record.arg === ContinueSentinel) {
369
- continue;
370
- }
371
-
372
- return {
373
- value: record.arg,
374
- done: context.done
375
- };
376
- } else if (record.type === "throw") {
377
- state = GenStateCompleted; // Dispatch the exception by looping back around to the
378
- // context.dispatchException(context.arg) call above.
379
-
380
- context.method = "throw";
381
- context.arg = record.arg;
382
- }
383
- }
384
- };
385
- } // Call delegate.iterator[context.method](context.arg) and handle the
386
- // result, either by returning a { value, done } result from the
387
- // delegate iterator, or by modifying context.method and context.arg,
388
- // setting context.delegate to null, and returning the ContinueSentinel.
389
-
390
-
391
- function maybeInvokeDelegate(delegate, context) {
392
- var method = delegate.iterator[context.method];
393
-
394
- if (method === undefined$1) {
395
- // A .throw or .return when the delegate iterator has no .throw
396
- // method always terminates the yield* loop.
397
- context.delegate = null;
398
-
399
- if (context.method === "throw") {
400
- // Note: ["return"] must be used for ES3 parsing compatibility.
401
- if (delegate.iterator["return"]) {
402
- // If the delegate iterator has a return method, give it a
403
- // chance to clean up.
404
- context.method = "return";
405
- context.arg = undefined$1;
406
- maybeInvokeDelegate(delegate, context);
407
-
408
- if (context.method === "throw") {
409
- // If maybeInvokeDelegate(context) changed context.method from
410
- // "return" to "throw", let that override the TypeError below.
411
- return ContinueSentinel;
412
- }
413
- }
414
-
415
- context.method = "throw";
416
- context.arg = new TypeError("The iterator does not provide a 'throw' method");
417
- }
418
-
419
- return ContinueSentinel;
420
- }
421
-
422
- var record = tryCatch(method, delegate.iterator, context.arg);
423
-
424
- if (record.type === "throw") {
425
- context.method = "throw";
426
- context.arg = record.arg;
427
- context.delegate = null;
428
- return ContinueSentinel;
429
- }
430
-
431
- var info = record.arg;
432
-
433
- if (!info) {
434
- context.method = "throw";
435
- context.arg = new TypeError("iterator result is not an object");
436
- context.delegate = null;
437
- return ContinueSentinel;
438
- }
439
-
440
- if (info.done) {
441
- // Assign the result of the finished delegate to the temporary
442
- // variable specified by delegate.resultName (see delegateYield).
443
- context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield).
444
-
445
- context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the
446
- // exception, let the outer generator proceed normally. If
447
- // context.method was "next", forget context.arg since it has been
448
- // "consumed" by the delegate iterator. If context.method was
449
- // "return", allow the original .return call to continue in the
450
- // outer generator.
451
-
452
- if (context.method !== "return") {
453
- context.method = "next";
454
- context.arg = undefined$1;
455
- }
456
- } else {
457
- // Re-yield the result returned by the delegate method.
458
- return info;
459
- } // The delegate iterator is finished, so forget it and continue with
460
- // the outer generator.
461
-
462
-
463
- context.delegate = null;
464
- return ContinueSentinel;
465
- } // Define Generator.prototype.{next,throw,return} in terms of the
466
- // unified ._invoke helper method.
467
-
468
-
469
- defineIteratorMethods(Gp);
470
- define(Gp, toStringTagSymbol, "Generator"); // A Generator should always return itself as the iterator object when the
471
- // @@iterator function is called on it. Some browsers' implementations of the
472
- // iterator prototype chain incorrectly implement this, causing the Generator
473
- // object to not be returned from this call. This ensures that doesn't happen.
474
- // See https://github.com/facebook/regenerator/issues/274 for more details.
475
-
476
- define(Gp, iteratorSymbol, function () {
477
- return this;
478
- });
479
- define(Gp, "toString", function () {
480
- return "[object Generator]";
481
- });
482
-
483
- function pushTryEntry(locs) {
484
- var entry = {
485
- tryLoc: locs[0]
486
- };
487
-
488
- if (1 in locs) {
489
- entry.catchLoc = locs[1];
490
- }
491
-
492
- if (2 in locs) {
493
- entry.finallyLoc = locs[2];
494
- entry.afterLoc = locs[3];
495
- }
496
-
497
- this.tryEntries.push(entry);
498
- }
499
-
500
- function resetTryEntry(entry) {
501
- var record = entry.completion || {};
502
- record.type = "normal";
503
- delete record.arg;
504
- entry.completion = record;
505
- }
506
-
507
- function Context(tryLocsList) {
508
- // The root entry object (effectively a try statement without a catch
509
- // or a finally block) gives us a place to store values thrown from
510
- // locations where there is no enclosing try statement.
511
- this.tryEntries = [{
512
- tryLoc: "root"
513
- }];
514
- tryLocsList.forEach(pushTryEntry, this);
515
- this.reset(true);
516
- }
517
-
518
- exports.keys = function (object) {
519
- var keys = [];
520
-
521
- for (var key in object) {
522
- keys.push(key);
523
- }
524
-
525
- keys.reverse(); // Rather than returning an object with a next method, we keep
526
- // things simple and return the next function itself.
527
-
528
- return function next() {
529
- while (keys.length) {
530
- var key = keys.pop();
531
-
532
- if (key in object) {
533
- next.value = key;
534
- next.done = false;
535
- return next;
536
- }
537
- } // To avoid creating an additional object, we just hang the .value
538
- // and .done properties off the next function object itself. This
539
- // also ensures that the minifier will not anonymize the function.
540
-
541
-
542
- next.done = true;
543
- return next;
544
- };
545
- };
546
-
547
- function values(iterable) {
548
- if (iterable) {
549
- var iteratorMethod = iterable[iteratorSymbol];
550
-
551
- if (iteratorMethod) {
552
- return iteratorMethod.call(iterable);
553
- }
554
-
555
- if (typeof iterable.next === "function") {
556
- return iterable;
557
- }
558
-
559
- if (!isNaN(iterable.length)) {
560
- var i = -1,
561
- next = function next() {
562
- while (++i < iterable.length) {
563
- if (hasOwn.call(iterable, i)) {
564
- next.value = iterable[i];
565
- next.done = false;
566
- return next;
567
- }
568
- }
569
-
570
- next.value = undefined$1;
571
- next.done = true;
572
- return next;
573
- };
574
-
575
- return next.next = next;
576
- }
577
- } // Return an iterator with no values.
578
-
579
-
580
- return {
581
- next: doneResult
582
- };
583
- }
584
-
585
- exports.values = values;
586
-
587
- function doneResult() {
588
- return {
589
- value: undefined$1,
590
- done: true
591
- };
592
- }
593
-
594
- Context.prototype = {
595
- constructor: Context,
596
- reset: function reset(skipTempReset) {
597
- this.prev = 0;
598
- this.next = 0; // Resetting context._sent for legacy support of Babel's
599
- // function.sent implementation.
600
-
601
- this.sent = this._sent = undefined$1;
602
- this.done = false;
603
- this.delegate = null;
604
- this.method = "next";
605
- this.arg = undefined$1;
606
- this.tryEntries.forEach(resetTryEntry);
607
-
608
- if (!skipTempReset) {
609
- for (var name in this) {
610
- // Not sure about the optimal order of these conditions:
611
- if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
612
- this[name] = undefined$1;
613
- }
614
- }
615
- }
616
- },
617
- stop: function stop() {
618
- this.done = true;
619
- var rootEntry = this.tryEntries[0];
620
- var rootRecord = rootEntry.completion;
621
-
622
- if (rootRecord.type === "throw") {
623
- throw rootRecord.arg;
624
- }
625
-
626
- return this.rval;
627
- },
628
- dispatchException: function dispatchException(exception) {
629
- if (this.done) {
630
- throw exception;
631
- }
632
-
633
- var context = this;
634
-
635
- function handle(loc, caught) {
636
- record.type = "throw";
637
- record.arg = exception;
638
- context.next = loc;
639
-
640
- if (caught) {
641
- // If the dispatched exception was caught by a catch block,
642
- // then let that catch block handle the exception normally.
643
- context.method = "next";
644
- context.arg = undefined$1;
645
- }
646
-
647
- return !!caught;
648
- }
649
9
 
650
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
651
- var entry = this.tryEntries[i];
652
- var record = entry.completion;
653
-
654
- if (entry.tryLoc === "root") {
655
- // Exception thrown outside of any try block that could handle
656
- // it, so set the completion value of the entire function to
657
- // throw the exception.
658
- return handle("end");
659
- }
660
-
661
- if (entry.tryLoc <= this.prev) {
662
- var hasCatch = hasOwn.call(entry, "catchLoc");
663
- var hasFinally = hasOwn.call(entry, "finallyLoc");
664
-
665
- if (hasCatch && hasFinally) {
666
- if (this.prev < entry.catchLoc) {
667
- return handle(entry.catchLoc, true);
668
- } else if (this.prev < entry.finallyLoc) {
669
- return handle(entry.finallyLoc);
670
- }
671
- } else if (hasCatch) {
672
- if (this.prev < entry.catchLoc) {
673
- return handle(entry.catchLoc, true);
674
- }
675
- } else if (hasFinally) {
676
- if (this.prev < entry.finallyLoc) {
677
- return handle(entry.finallyLoc);
678
- }
679
- } else {
680
- throw new Error("try statement without catch or finally");
681
- }
682
- }
683
- }
684
- },
685
- abrupt: function abrupt(type, arg) {
686
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
687
- var entry = this.tryEntries[i];
688
-
689
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
690
- var finallyEntry = entry;
691
- break;
692
- }
693
- }
694
-
695
- if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
696
- // Ignore the finally entry if control is not jumping to a
697
- // location outside the try/catch block.
698
- finallyEntry = null;
699
- }
700
-
701
- var record = finallyEntry ? finallyEntry.completion : {};
702
- record.type = type;
703
- record.arg = arg;
704
-
705
- if (finallyEntry) {
706
- this.method = "next";
707
- this.next = finallyEntry.finallyLoc;
708
- return ContinueSentinel;
709
- }
710
-
711
- return this.complete(record);
712
- },
713
- complete: function complete(record, afterLoc) {
714
- if (record.type === "throw") {
715
- throw record.arg;
716
- }
717
-
718
- if (record.type === "break" || record.type === "continue") {
719
- this.next = record.arg;
720
- } else if (record.type === "return") {
721
- this.rval = this.arg = record.arg;
722
- this.method = "return";
723
- this.next = "end";
724
- } else if (record.type === "normal" && afterLoc) {
725
- this.next = afterLoc;
726
- }
727
-
728
- return ContinueSentinel;
729
- },
730
- finish: function finish(finallyLoc) {
731
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
732
- var entry = this.tryEntries[i];
733
-
734
- if (entry.finallyLoc === finallyLoc) {
735
- this.complete(entry.completion, entry.afterLoc);
736
- resetTryEntry(entry);
737
- return ContinueSentinel;
738
- }
739
- }
740
- },
741
- "catch": function _catch(tryLoc) {
742
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
743
- var entry = this.tryEntries[i];
744
-
745
- if (entry.tryLoc === tryLoc) {
746
- var record = entry.completion;
747
-
748
- if (record.type === "throw") {
749
- var thrown = record.arg;
750
- resetTryEntry(entry);
751
- }
752
-
753
- return thrown;
754
- }
755
- } // The context.catch method must only be called with a location
756
- // argument that corresponds to a known catch block.
757
-
758
-
759
- throw new Error("illegal catch attempt");
760
- },
761
- delegateYield: function delegateYield(iterable, resultName, nextLoc) {
762
- this.delegate = {
763
- iterator: values(iterable),
764
- resultName: resultName,
765
- nextLoc: nextLoc
766
- };
767
-
768
- if (this.method === "next") {
769
- // Deliberately forget the last sent value so that we don't
770
- // accidentally pass it on to the delegate.
771
- this.arg = undefined$1;
772
- }
773
-
774
- return ContinueSentinel;
775
- }
776
- }; // Regardless of whether this script is executing as a CommonJS module
777
- // or not, return the runtime object so that we can declare the variable
778
- // regeneratorRuntime in the outer scope, which allows this module to be
779
- // injected easily by `bin/regenerator --include-runtime script.js`.
780
-
781
- return exports;
782
- }( // If this script is executing as a CommonJS module, use module.exports
783
- // as the regeneratorRuntime namespace. Otherwise create a new empty
784
- // object. Either way, the resulting object will be used to initialize
785
- // the regeneratorRuntime variable at the top of this file.
786
- module.exports );
787
-
788
- try {
789
- regeneratorRuntime = runtime;
790
- } catch (accidentalStrictMode) {
791
- // This module should not be running in strict mode, so the above
792
- // assignment should always work unless something is misconfigured. Just
793
- // in case runtime.js accidentally runs in strict mode, in modern engines
794
- // we can explicitly access globalThis. In older engines we can escape
795
- // strict mode using a global Function call. This could conceivably fail
796
- // if a Content Security Policy forbids using Function, but in that case
797
- // the proper solution is to fix the accidental strict mode problem. If
798
- // you've misconfigured your bundler to force strict mode and applied a
799
- // CSP to forbid Function, and you're not willing to fix either of those
800
- // problems, please detail your unique predicament in a GitHub issue.
801
- if (typeof globalThis === "object") {
802
- globalThis.regeneratorRuntime = runtime;
803
- } else {
804
- Function("r", "regeneratorRuntime = r")(runtime);
805
- }
806
- }
807
- });
808
-
809
- function getTitleField(sdk, trackingFieldId) {
810
- var entry = sdk.entry,
811
- contentType = sdk.contentType;
812
-
813
- if (trackingFieldId && entry.fields[trackingFieldId]) {
814
- return entry.fields[trackingFieldId];
815
- }
816
-
817
- return entry.fields[contentType.displayField];
818
- }
819
-
820
- var TrackingFieldConnector = /*#__PURE__*/function (_React$Component) {
821
- _inheritsLoose(TrackingFieldConnector, _React$Component);
822
-
823
- function TrackingFieldConnector(props) {
824
- var _this;
825
-
826
- _this = _React$Component.call(this, props) || this;
827
- _this.unsubscribeValue = null;
828
- _this.unsubscribeLocalizedValue = null;
829
- _this.unsubscribeSysChanges = null;
830
- var titleField = getTitleField(props.sdk, props.trackingFieldId);
831
- var entrySys = props.sdk.entry.getSys();
832
- var isSame = titleField ? props.field.id === titleField.id : false;
833
- _this.state = {
834
- titleValue: titleField ? titleField.getValue() : '',
835
- isPublished: Boolean(entrySys.publishedVersion),
836
- isSame: isSame
837
- };
838
- return _this;
839
- }
840
-
841
- var _proto = TrackingFieldConnector.prototype;
842
-
843
- _proto.componentDidMount = function componentDidMount() {
844
- var _this2 = this;
845
-
846
- this.unsubscribeSysChanges = this.props.sdk.entry.onSysChanged(function (sys) {
847
- _this2.setState({
848
- isPublished: Boolean(sys.publishedVersion)
849
- });
850
- });
851
- var titleField = getTitleField(this.props.sdk, this.props.trackingFieldId); // the content type's display field might not exist
852
-
853
- if (!titleField) {
854
- return;
855
- }
856
-
857
- if (!this.state.isSame) {
858
- this.unsubscribeLocalizedValue = titleField.onValueChanged(this.props.field.locale, function (value) {
859
- _this2.setState({
860
- titleValue: value
861
- });
862
- });
863
- }
864
-
865
- if (this.props.field.locale !== this.props.defaultLocale) {
866
- if (!this.props.isOptionalLocaleWithFallback) {
867
- this.unsubscribeValue = titleField.onValueChanged(this.props.defaultLocale, function (value) {
868
- if (!titleField.getValue(_this2.props.field.locale)) {
869
- _this2.setState({
870
- titleValue: value
871
- });
872
- }
873
- });
874
- }
875
- }
876
- };
877
-
878
- _proto.componentWillUnmount = function componentWillUnmount() {
879
- if (typeof this.unsubscribeValue === 'function') {
880
- this.unsubscribeValue();
881
- }
882
-
883
- if (typeof this.unsubscribeLocalizedValue === 'function') {
884
- this.unsubscribeLocalizedValue();
885
- }
886
-
887
- if (typeof this.unsubscribeSysChanges === 'function') {
888
- this.unsubscribeSysChanges();
889
- }
890
- };
891
-
892
- _proto.render = function render() {
893
- return this.props.children(_extends({}, this.state));
894
- };
895
-
896
- return TrackingFieldConnector;
897
- }(React__default.Component);
898
- TrackingFieldConnector.defaultProps = {
899
- children: function children() {
900
- return null;
901
- }
902
- };
903
-
904
- var CF_GENERATED_SLUG_MAX_LENGTH = 75;
905
- var languages = ['ar', 'az', 'cs', 'de', 'dv', 'en', 'es', 'fa', 'fi', 'fr', 'ge', 'gr', 'hu', 'it', 'lt', 'lv', 'my', 'mk', 'nl', 'pl', 'pt', 'ro', 'ru', 'sk', 'sr', 'tr', 'uk', 'vn'];
10
+ const CF_GENERATED_SLUG_MAX_LENGTH = 75;
11
+ const languages = ['ar', 'az', 'cs', 'de', 'dv', 'en', 'es', 'fa', 'fi', 'fr', 'ge', 'gr', 'hu', 'it', 'lt', 'lv', 'my', 'mk', 'nl', 'pl', 'pt', 'ro', 'ru', 'sk', 'sr', 'tr', 'uk', 'vn'];
906
12
  /**
907
13
  * Extracts the first two lowercased characters from the locale,
908
14
  * and returns the supported language prefix.
909
15
  */
910
16
 
911
17
  function supportedLanguage(locale) {
912
- var prefix = locale.slice(0, 2).toLowerCase();
18
+ const prefix = locale.slice(0, 2).toLowerCase();
913
19
  return languages[languages.indexOf(prefix)];
914
20
  }
915
21
  /**
@@ -925,11 +31,7 @@ function supportedLanguage(locale) {
925
31
  */
926
32
 
927
33
 
928
- function slugify(text, locale) {
929
- if (locale === void 0) {
930
- locale = 'en';
931
- }
932
-
34
+ function slugify(text, locale = 'en') {
933
35
  return getSlug(text, {
934
36
  separator: '-',
935
37
  lang: supportedLanguage(locale) || 'en',
@@ -944,29 +46,29 @@ function slugify(text, locale) {
944
46
  }
945
47
 
946
48
  function formatTwoDigit(num) {
947
- var asString = String(num);
948
- return asString.length === 1 ? "0" + asString : asString;
49
+ const asString = String(num);
50
+ return asString.length === 1 ? `0${asString}` : asString;
949
51
  }
950
52
 
951
53
  function formatUtcDate(date) {
952
- var year = date.getFullYear();
953
- var month = formatTwoDigit(date.getUTCMonth() + 1);
954
- var day = formatTwoDigit(date.getUTCDate());
955
- var hour = formatTwoDigit(date.getUTCHours());
956
- var minutes = formatTwoDigit(date.getUTCMinutes());
957
- var seconds = formatTwoDigit(date.getUTCSeconds());
958
- return year + " " + month + " " + day + " at " + hour + " " + minutes + " " + seconds;
54
+ const year = date.getFullYear();
55
+ const month = formatTwoDigit(date.getUTCMonth() + 1);
56
+ const day = formatTwoDigit(date.getUTCDate());
57
+ const hour = formatTwoDigit(date.getUTCHours());
58
+ const minutes = formatTwoDigit(date.getUTCMinutes());
59
+ const seconds = formatTwoDigit(date.getUTCSeconds());
60
+ return `${year} ${month} ${day} at ${hour} ${minutes} ${seconds}`;
959
61
  }
960
62
 
961
- function untitledSlug(_ref) {
962
- var isOptionalLocaleWithFallback = _ref.isOptionalLocaleWithFallback,
963
- createdAt = _ref.createdAt;
964
-
63
+ function untitledSlug({
64
+ isOptionalLocaleWithFallback,
65
+ createdAt
66
+ }) {
965
67
  if (isOptionalLocaleWithFallback) {
966
68
  return ''; // Will result in `undefined` slug.
967
69
  }
968
70
 
969
- var createdAtFormatted = formatUtcDate(new Date(createdAt));
71
+ const createdAtFormatted = formatUtcDate(new Date(createdAt));
970
72
  return slugify('Untitled entry ' + createdAtFormatted, 'en-US');
971
73
  }
972
74
 
@@ -974,13 +76,13 @@ function makeSlug(title, options) {
974
76
  return title ? slugify(title, options.locale) : untitledSlug(options);
975
77
  }
976
78
 
977
- var inputContainer = /*#__PURE__*/css({
79
+ const inputContainer = /*#__PURE__*/css({
978
80
  position: 'relative'
979
81
  });
980
- var input = /*#__PURE__*/css({
82
+ const input = /*#__PURE__*/css({
981
83
  paddingLeft: '40px'
982
84
  });
983
- var icon = /*#__PURE__*/css({
85
+ const icon = /*#__PURE__*/css({
984
86
  position: 'absolute',
985
87
  left: '10px',
986
88
  top: '8px',
@@ -989,32 +91,34 @@ var icon = /*#__PURE__*/css({
989
91
  height: '25px',
990
92
  fill: tokens.gray500
991
93
  });
992
- var spinnerContainer = /*#__PURE__*/css({
94
+ const spinnerContainer = /*#__PURE__*/css({
993
95
  position: 'absolute',
994
96
  zIndex: 2,
995
97
  right: '8px',
996
98
  top: '8px'
997
99
  });
998
- var uniqueValidationError = /*#__PURE__*/css({
100
+ const uniqueValidationError = /*#__PURE__*/css({
999
101
  marginTop: tokens.spacingS
1000
102
  });
1001
103
 
1002
104
  function useSlugUpdater(props, check) {
1003
- var value = props.value,
1004
- setValue = props.setValue,
1005
- createdAt = props.createdAt,
1006
- locale = props.locale,
1007
- titleValue = props.titleValue,
1008
- isOptionalLocaleWithFallback = props.isOptionalLocaleWithFallback;
1009
- React__default.useEffect(function () {
105
+ const {
106
+ value,
107
+ setValue,
108
+ createdAt,
109
+ locale,
110
+ titleValue,
111
+ isOptionalLocaleWithFallback
112
+ } = props;
113
+ React__default.useEffect(() => {
1010
114
  if (check === false) {
1011
115
  return;
1012
116
  }
1013
117
 
1014
- var newSlug = makeSlug(titleValue, {
1015
- isOptionalLocaleWithFallback: isOptionalLocaleWithFallback,
1016
- locale: locale,
1017
- createdAt: createdAt
118
+ const newSlug = makeSlug(titleValue, {
119
+ isOptionalLocaleWithFallback,
120
+ locale,
121
+ createdAt
1018
122
  });
1019
123
 
1020
124
  if (newSlug !== value) {
@@ -1024,31 +128,27 @@ function useSlugUpdater(props, check) {
1024
128
  }
1025
129
 
1026
130
  function useUniqueChecker(props) {
1027
- var performUniqueCheck = props.performUniqueCheck;
1028
-
1029
- var _React$useState = React__default.useState(props.value ? 'checking' : 'unique'),
1030
- status = _React$useState[0],
1031
- setStatus = _React$useState[1];
1032
-
1033
- var _useDebounce = useDebounce(props.value, 1000),
1034
- debouncedValue = _useDebounce[0];
131
+ const {
132
+ performUniqueCheck
133
+ } = props;
134
+ const [status, setStatus] = React__default.useState(props.value ? 'checking' : 'unique');
135
+ const [debouncedValue] = useDebounce(props.value, 1000);
1035
136
  /**
1036
137
  * Check the uniqueness of the slug in the current space.
1037
138
  * The slug is unique if there is no published entry other than the
1038
139
  * current one, with the same slug.
1039
140
  */
1040
141
 
1041
-
1042
- React__default.useEffect(function () {
142
+ React__default.useEffect(() => {
1043
143
  if (!debouncedValue) {
1044
144
  setStatus('unique');
1045
145
  return;
1046
146
  }
1047
147
 
1048
148
  setStatus('checking');
1049
- performUniqueCheck(debouncedValue).then(function (unique) {
149
+ performUniqueCheck(debouncedValue).then(unique => {
1050
150
  setStatus(unique ? 'unique' : 'duplicate');
1051
- })["catch"](function () {
151
+ }).catch(() => {
1052
152
  setStatus('checking');
1053
153
  });
1054
154
  }, [debouncedValue, performUniqueCheck]);
@@ -1056,13 +156,15 @@ function useUniqueChecker(props) {
1056
156
  }
1057
157
 
1058
158
  function SlugEditorFieldStatic(props) {
1059
- var hasError = props.hasError,
1060
- isDisabled = props.isDisabled,
1061
- value = props.value,
1062
- setValue = props.setValue,
1063
- _onChange = props.onChange,
1064
- _onBlur = props.onBlur;
1065
- var status = useUniqueChecker(props);
159
+ const {
160
+ hasError,
161
+ isDisabled,
162
+ value,
163
+ setValue,
164
+ onChange,
165
+ onBlur
166
+ } = props;
167
+ const status = useUniqueChecker(props);
1066
168
  return React__default.createElement("div", {
1067
169
  className: inputContainer
1068
170
  }, React__default.createElement(LinkIcon, {
@@ -1072,16 +174,16 @@ function SlugEditorFieldStatic(props) {
1072
174
  isInvalid: hasError || status === 'duplicate',
1073
175
  isDisabled: isDisabled,
1074
176
  value: value || '',
1075
- onChange: function onChange(e) {
177
+ onChange: e => {
1076
178
  setValue(e.target.value);
1077
179
 
1078
- if (_onChange) {
1079
- _onChange();
180
+ if (onChange) {
181
+ onChange();
1080
182
  }
1081
183
  },
1082
- onBlur: function onBlur() {
1083
- if (_onBlur) {
1084
- _onBlur();
184
+ onBlur: () => {
185
+ if (onBlur) {
186
+ onBlur();
1085
187
  }
1086
188
  }
1087
189
  }), status === 'checking' && React__default.createElement("div", {
@@ -1094,21 +196,22 @@ function SlugEditorFieldStatic(props) {
1094
196
  }, "This slug has already been published in another entry"));
1095
197
  }
1096
198
  function SlugEditorField(props) {
1097
- var titleValue = props.titleValue,
1098
- isOptionalLocaleWithFallback = props.isOptionalLocaleWithFallback,
1099
- locale = props.locale,
1100
- createdAt = props.createdAt,
1101
- value = props.value;
1102
- var areEqual = React__default.useCallback(function () {
1103
- var potentialSlug = makeSlug(titleValue, {
199
+ const {
200
+ titleValue,
201
+ isOptionalLocaleWithFallback,
202
+ locale,
203
+ createdAt,
204
+ value
205
+ } = props;
206
+ const areEqual = React__default.useCallback(() => {
207
+ const potentialSlug = makeSlug(titleValue, {
1104
208
  isOptionalLocaleWithFallback: isOptionalLocaleWithFallback,
1105
209
  locale: locale,
1106
210
  createdAt: createdAt
1107
211
  });
1108
212
  return value === potentialSlug;
1109
213
  }, [titleValue, isOptionalLocaleWithFallback, locale, createdAt, value]);
1110
-
1111
- var _React$useState2 = React__default.useState(function () {
214
+ const [check, setCheck] = React__default.useState(() => {
1112
215
  if (props.value) {
1113
216
  if (!props.titleValue) {
1114
217
  return false;
@@ -1118,70 +221,137 @@ function SlugEditorField(props) {
1118
221
  }
1119
222
 
1120
223
  return true;
1121
- }),
1122
- check = _React$useState2[0],
1123
- setCheck = _React$useState2[1];
1124
-
1125
- React__default.useEffect(function () {
224
+ });
225
+ React__default.useEffect(() => {
1126
226
  if (areEqual()) {
1127
227
  setCheck(true);
1128
228
  }
1129
229
  }, [props.titleValue, areEqual]);
1130
230
  useSlugUpdater(props, check);
1131
- return React__default.createElement(SlugEditorFieldStatic, _extends({}, props, {
1132
- onChange: function onChange() {
231
+ return React__default.createElement(SlugEditorFieldStatic, { ...props,
232
+ onChange: () => {
1133
233
  setCheck(false);
1134
234
  },
1135
- onBlur: function onBlur() {
235
+ onBlur: () => {
1136
236
  if (areEqual()) {
1137
237
  setCheck(true);
1138
238
  }
1139
239
  }
1140
- }));
240
+ });
1141
241
  }
1142
242
 
1143
- function isSupportedFieldTypes(val) {
1144
- return val === 'Symbol';
243
+ function getTitleField(sdk, trackingFieldId) {
244
+ const {
245
+ entry,
246
+ contentType
247
+ } = sdk;
248
+
249
+ if (trackingFieldId && entry.fields[trackingFieldId]) {
250
+ return entry.fields[trackingFieldId];
251
+ }
252
+
253
+ return entry.fields[contentType.displayField];
1145
254
  }
1146
255
 
1147
- function FieldConnectorCallback(_ref) {
1148
- var Component = _ref.Component,
1149
- value = _ref.value,
1150
- disabled = _ref.disabled,
1151
- setValue = _ref.setValue,
1152
- errors = _ref.errors,
1153
- titleValue = _ref.titleValue,
1154
- isOptionalLocaleWithFallback = _ref.isOptionalLocaleWithFallback,
1155
- locale = _ref.locale,
1156
- createdAt = _ref.createdAt,
1157
- performUniqueCheck = _ref.performUniqueCheck;
1158
- // it is needed to silent permission errors
1159
- // this happens when setValue is called on a field which is disabled for permission reasons
1160
- var safeSetValue = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
1161
- var _args = arguments;
1162
- return runtime_1.wrap(function _callee$(_context) {
1163
- while (1) {
1164
- switch (_context.prev = _context.next) {
1165
- case 0:
1166
- _context.prev = 0;
1167
- _context.next = 3;
1168
- return setValue.apply(void 0, _args);
256
+ class TrackingFieldConnector extends React__default.Component {
257
+ constructor(props) {
258
+ super(props);
259
+ this.unsubscribeValue = null;
260
+ this.unsubscribeLocalizedValue = null;
261
+ this.unsubscribeSysChanges = null;
262
+ const titleField = getTitleField(props.sdk, props.trackingFieldId);
263
+ const entrySys = props.sdk.entry.getSys();
264
+ const isSame = titleField ? props.field.id === titleField.id : false;
265
+ this.state = {
266
+ titleValue: titleField ? titleField.getValue() : '',
267
+ isPublished: Boolean(entrySys.publishedVersion),
268
+ isSame
269
+ };
270
+ }
271
+
272
+ componentDidMount() {
273
+ this.unsubscribeSysChanges = this.props.sdk.entry.onSysChanged(sys => {
274
+ this.setState({
275
+ isPublished: Boolean(sys.publishedVersion)
276
+ });
277
+ });
278
+ const titleField = getTitleField(this.props.sdk, this.props.trackingFieldId); // the content type's display field might not exist
1169
279
 
1170
- case 3:
1171
- _context.next = 7;
1172
- break;
280
+ if (!titleField) {
281
+ return;
282
+ }
1173
283
 
1174
- case 5:
1175
- _context.prev = 5;
1176
- _context.t0 = _context["catch"](0);
284
+ if (!this.state.isSame) {
285
+ this.unsubscribeLocalizedValue = titleField.onValueChanged(this.props.field.locale, value => {
286
+ this.setState({
287
+ titleValue: value
288
+ });
289
+ });
290
+ }
1177
291
 
1178
- case 7:
1179
- case "end":
1180
- return _context.stop();
1181
- }
292
+ if (this.props.field.locale !== this.props.defaultLocale) {
293
+ if (!this.props.isOptionalLocaleWithFallback) {
294
+ this.unsubscribeValue = titleField.onValueChanged(this.props.defaultLocale, value => {
295
+ if (!titleField.getValue(this.props.field.locale)) {
296
+ this.setState({
297
+ titleValue: value
298
+ });
299
+ }
300
+ });
1182
301
  }
1183
- }, _callee, null, [[0, 5]]);
1184
- })), [setValue]);
302
+ }
303
+ }
304
+
305
+ componentWillUnmount() {
306
+ if (typeof this.unsubscribeValue === 'function') {
307
+ this.unsubscribeValue();
308
+ }
309
+
310
+ if (typeof this.unsubscribeLocalizedValue === 'function') {
311
+ this.unsubscribeLocalizedValue();
312
+ }
313
+
314
+ if (typeof this.unsubscribeSysChanges === 'function') {
315
+ this.unsubscribeSysChanges();
316
+ }
317
+ }
318
+
319
+ render() {
320
+ return this.props.children({ ...this.state
321
+ });
322
+ }
323
+
324
+ }
325
+ TrackingFieldConnector.defaultProps = {
326
+ children: () => {
327
+ return null;
328
+ }
329
+ };
330
+
331
+ function isSupportedFieldTypes(val) {
332
+ return val === 'Symbol';
333
+ }
334
+
335
+ function FieldConnectorCallback({
336
+ Component,
337
+ value,
338
+ disabled,
339
+ setValue,
340
+ errors,
341
+ titleValue,
342
+ isOptionalLocaleWithFallback,
343
+ locale,
344
+ createdAt,
345
+ performUniqueCheck
346
+ }) {
347
+ // it is needed to silent permission errors
348
+ // this happens when setValue is called on a field which is disabled for permission reasons
349
+ const safeSetValue = useCallback(async (...args) => {
350
+ try {
351
+ await setValue(...args);
352
+ } catch (e) {// do nothing
353
+ }
354
+ }, [setValue]);
1185
355
  return createElement("div", {
1186
356
  "data-test-id": "slug-editor"
1187
357
  }, createElement(Component, {
@@ -1198,76 +368,83 @@ function FieldConnectorCallback(_ref) {
1198
368
  }
1199
369
 
1200
370
  function SlugEditor(props) {
1201
- var _parameters$instance$, _parameters$instance, _entrySys$contentType3, _entrySys$contentType4;
1202
-
1203
- var field = props.field,
1204
- parameters = props.parameters;
1205
- var _props$baseSdk = props.baseSdk,
1206
- locales = _props$baseSdk.locales,
1207
- entry = _props$baseSdk.entry,
1208
- space = _props$baseSdk.space;
371
+ var _parameters$instance, _entrySys$contentType3, _entrySys$contentType4;
372
+
373
+ const {
374
+ field,
375
+ parameters
376
+ } = props;
377
+ const {
378
+ locales,
379
+ entry,
380
+ space
381
+ } = props.baseSdk;
1209
382
 
1210
383
  if (!isSupportedFieldTypes(field.type)) {
1211
- throw new Error("\"" + field.type + "\" field type is not supported by SlugEditor");
384
+ throw new Error(`"${field.type}" field type is not supported by SlugEditor`);
1212
385
  }
1213
386
 
1214
- var trackingFieldId = (_parameters$instance$ = parameters == null ? void 0 : (_parameters$instance = parameters.instance) == null ? void 0 : _parameters$instance.trackingFieldId) != null ? _parameters$instance$ : undefined;
1215
- var entrySys = entry.getSys();
1216
- var isLocaleOptional = locales.optional[field.locale];
1217
- var localeFallbackCode = locales.fallbacks[field.locale]; // If the field or the locale are not required (there's a locale setting that
387
+ const trackingFieldId = (parameters == null ? void 0 : (_parameters$instance = parameters.instance) == null ? void 0 : _parameters$instance.trackingFieldId) ?? undefined;
388
+ const entrySys = entry.getSys();
389
+ const isLocaleOptional = locales.optional[field.locale];
390
+ const localeFallbackCode = locales.fallbacks[field.locale]; // If the field or the locale are not required (there's a locale setting that
1218
391
  // allows publishing even if the field is required) and if the locale has a
1219
392
  // fallback than there's no need for a slug unless the user manually enters
1220
393
  // one or the title field is also localized with a custom value.
1221
394
 
1222
- var isOptionalFieldLocale = Boolean(!field.required || isLocaleOptional);
1223
- var isOptionalLocaleWithFallback = Boolean(isOptionalFieldLocale && localeFallbackCode && locales.available.includes(localeFallbackCode));
1224
- var performUniqueCheck = useCallback(function (value) {
1225
- var _entrySys$contentType, _entrySys$contentType2, _searchQuery;
1226
-
1227
- var searchQuery = (_searchQuery = {
1228
- content_type: entrySys == null ? void 0 : (_entrySys$contentType = entrySys.contentType) == null ? void 0 : (_entrySys$contentType2 = _entrySys$contentType.sys) == null ? void 0 : _entrySys$contentType2.id
1229
- }, _searchQuery["fields." + field.id + "." + field.locale] = value, _searchQuery['sys.id[ne]'] = entrySys.id, _searchQuery['sys.publishedAt[exists]'] = true, _searchQuery.limit = 0, _searchQuery);
1230
- return space.getEntries(searchQuery).then(function (res) {
395
+ const isOptionalFieldLocale = Boolean(!field.required || isLocaleOptional);
396
+ const isOptionalLocaleWithFallback = Boolean(isOptionalFieldLocale && localeFallbackCode && locales.available.includes(localeFallbackCode));
397
+ const performUniqueCheck = useCallback(value => {
398
+ var _entrySys$contentType, _entrySys$contentType2;
399
+
400
+ const searchQuery = {
401
+ content_type: entrySys == null ? void 0 : (_entrySys$contentType = entrySys.contentType) == null ? void 0 : (_entrySys$contentType2 = _entrySys$contentType.sys) == null ? void 0 : _entrySys$contentType2.id,
402
+ [`fields.${field.id}.${field.locale}`]: value,
403
+ 'sys.id[ne]': entrySys.id,
404
+ 'sys.publishedAt[exists]': true,
405
+ limit: 0
406
+ };
407
+ return space.getEntries(searchQuery).then(res => {
1231
408
  return res.total === 0;
1232
409
  });
1233
410
  }, [entrySys == null ? void 0 : (_entrySys$contentType3 = entrySys.contentType) == null ? void 0 : (_entrySys$contentType4 = _entrySys$contentType3.sys) == null ? void 0 : _entrySys$contentType4.id, field.id, field.locale, entrySys.id, space]);
1234
411
  return createElement(TrackingFieldConnector, {
1235
412
  sdk: props.baseSdk,
1236
413
  field: field,
1237
- defaultLocale: locales["default"],
414
+ defaultLocale: locales.default,
1238
415
  isOptionalLocaleWithFallback: isOptionalLocaleWithFallback,
1239
416
  trackingFieldId: trackingFieldId
1240
- }, function (_ref3) {
1241
- var titleValue = _ref3.titleValue,
1242
- isPublished = _ref3.isPublished,
1243
- isSame = _ref3.isSame;
1244
- return createElement(FieldConnector, {
1245
- field: field,
1246
- isInitiallyDisabled: props.isInitiallyDisabled,
1247
- throttle: 0
1248
- }, function (_ref4) {
1249
- var value = _ref4.value,
1250
- errors = _ref4.errors,
1251
- disabled = _ref4.disabled,
1252
- setValue = _ref4.setValue,
1253
- externalReset = _ref4.externalReset;
1254
- var shouldTrackTitle = isPublished === false && isSame === false;
1255
- var Component = shouldTrackTitle ? SlugEditorField : SlugEditorFieldStatic;
1256
- return createElement(FieldConnectorCallback, {
1257
- Component: Component,
1258
- titleValue: titleValue,
1259
- value: value,
1260
- errors: errors,
1261
- disabled: disabled,
1262
- setValue: setValue,
1263
- isOptionalLocaleWithFallback: isOptionalLocaleWithFallback,
1264
- createdAt: entrySys.createdAt,
1265
- locale: field.locale,
1266
- performUniqueCheck: performUniqueCheck,
1267
- key: "slug-editor-" + externalReset
1268
- });
417
+ }, ({
418
+ titleValue,
419
+ isPublished,
420
+ isSame
421
+ }) => createElement(FieldConnector, {
422
+ field: field,
423
+ isInitiallyDisabled: props.isInitiallyDisabled,
424
+ throttle: 0
425
+ }, ({
426
+ value,
427
+ errors,
428
+ disabled,
429
+ setValue,
430
+ externalReset
431
+ }) => {
432
+ const shouldTrackTitle = isPublished === false && isSame === false;
433
+ const Component = shouldTrackTitle ? SlugEditorField : SlugEditorFieldStatic;
434
+ return createElement(FieldConnectorCallback, {
435
+ Component: Component,
436
+ titleValue: titleValue,
437
+ value: value,
438
+ errors: errors,
439
+ disabled: disabled,
440
+ setValue: setValue,
441
+ isOptionalLocaleWithFallback: isOptionalLocaleWithFallback,
442
+ createdAt: entrySys.createdAt,
443
+ locale: field.locale,
444
+ performUniqueCheck: performUniqueCheck,
445
+ key: `slug-editor-${externalReset}`
1269
446
  });
1270
- });
447
+ }));
1271
448
  }
1272
449
  SlugEditor.defaultProps = {
1273
450
  isInitiallyDisabled: true