@contentful/field-editor-slug 1.1.12 → 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 (39) hide show
  1. package/dist/cjs/SlugEditor.js +139 -0
  2. package/dist/cjs/SlugEditor.test.js +508 -0
  3. package/dist/cjs/SlugEditorField.js +186 -0
  4. package/dist/cjs/TrackingFieldConnector.js +137 -0
  5. package/dist/cjs/index.js +24 -0
  6. package/dist/cjs/services/makeSlug.js +42 -0
  7. package/dist/cjs/services/makeSlug.test.js +14 -0
  8. package/dist/cjs/services/slugify.js +64 -0
  9. package/dist/cjs/services/slugify.test.js +30 -0
  10. package/dist/cjs/styles.js +68 -0
  11. package/dist/esm/SlugEditor.js +90 -0
  12. package/dist/esm/SlugEditor.test.js +460 -0
  13. package/dist/esm/SlugEditorField.js +129 -0
  14. package/dist/esm/TrackingFieldConnector.js +88 -0
  15. package/dist/esm/index.js +3 -0
  16. package/dist/esm/services/makeSlug.js +24 -0
  17. package/dist/esm/services/makeSlug.test.js +10 -0
  18. package/dist/esm/services/slugify.js +49 -0
  19. package/dist/esm/services/slugify.test.js +26 -0
  20. package/dist/esm/styles.js +33 -0
  21. package/dist/{SlugEditor.d.ts → types/SlugEditor.d.ts} +24 -24
  22. package/dist/types/SlugEditor.test.d.ts +1 -0
  23. package/dist/{SlugEditorField.d.ts → types/SlugEditorField.d.ts} +18 -18
  24. package/dist/{TrackingFieldConnector.d.ts → types/TrackingFieldConnector.d.ts} +29 -29
  25. package/dist/{index.d.ts → types/index.d.ts} +3 -3
  26. package/dist/{services → types/services}/makeSlug.d.ts +8 -8
  27. package/dist/types/services/makeSlug.test.d.ts +1 -0
  28. package/dist/{services → types/services}/slugify.d.ts +12 -12
  29. package/dist/types/services/slugify.test.d.ts +1 -0
  30. package/dist/{styles.d.ts → types/styles.d.ts} +6 -6
  31. package/package.json +25 -11
  32. package/CHANGELOG.md +0 -200
  33. package/dist/field-editor-slug.cjs.development.js +0 -1286
  34. package/dist/field-editor-slug.cjs.development.js.map +0 -1
  35. package/dist/field-editor-slug.cjs.production.min.js +0 -2
  36. package/dist/field-editor-slug.cjs.production.min.js.map +0 -1
  37. package/dist/field-editor-slug.esm.js +0 -1277
  38. package/dist/field-editor-slug.esm.js.map +0 -1
  39. package/dist/index.js +0 -8
@@ -1,1277 +0,0 @@
1
- import React__default, { useCallback, createElement } from 'react';
2
- import { FieldConnector } from '@contentful/field-editor-shared';
3
- import { useDebounce } from 'use-debounce';
4
- import getSlug from 'speakingurl';
5
- import tokens from '@contentful/f36-tokens';
6
- 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
-
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'];
906
- /**
907
- * Extracts the first two lowercased characters from the locale,
908
- * and returns the supported language prefix.
909
- */
910
-
911
- function supportedLanguage(locale) {
912
- var prefix = locale.slice(0, 2).toLowerCase();
913
- return languages[languages.indexOf(prefix)];
914
- }
915
- /**
916
- * Returns the slug for a given string and locale.
917
- * If the locale belongs to a language supported by SpeakingURL, it
918
- * is used as the symbol language. Otherwise, the symbol language
919
- * is english.
920
- * Slug suggestions are limited to 75 characters.
921
- *
922
- * @param {string} text To be turned into a slug.
923
- * @param {string?} locale
924
- * @returns {string} Slug for provided text.
925
- */
926
-
927
-
928
- function slugify(text, locale) {
929
- if (locale === void 0) {
930
- locale = 'en';
931
- }
932
-
933
- return getSlug(text, {
934
- separator: '-',
935
- lang: supportedLanguage(locale) || 'en',
936
- truncate: CF_GENERATED_SLUG_MAX_LENGTH + 1,
937
- custom: {
938
- "'": '',
939
- '`': '',
940
- '’': '',
941
- '‘': ''
942
- }
943
- });
944
- }
945
-
946
- function formatTwoDigit(num) {
947
- var asString = String(num);
948
- return asString.length === 1 ? "0" + asString : asString;
949
- }
950
-
951
- 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;
959
- }
960
-
961
- function untitledSlug(_ref) {
962
- var isOptionalLocaleWithFallback = _ref.isOptionalLocaleWithFallback,
963
- createdAt = _ref.createdAt;
964
-
965
- if (isOptionalLocaleWithFallback) {
966
- return ''; // Will result in `undefined` slug.
967
- }
968
-
969
- var createdAtFormatted = formatUtcDate(new Date(createdAt));
970
- return slugify('Untitled entry ' + createdAtFormatted, 'en-US');
971
- }
972
-
973
- function makeSlug(title, options) {
974
- return title ? slugify(title, options.locale) : untitledSlug(options);
975
- }
976
-
977
- var inputContainer = /*#__PURE__*/css({
978
- position: 'relative'
979
- });
980
- var input = /*#__PURE__*/css({
981
- paddingLeft: '40px'
982
- });
983
- var icon = /*#__PURE__*/css({
984
- position: 'absolute',
985
- left: '10px',
986
- top: '8px',
987
- zIndex: 2,
988
- width: '25px',
989
- height: '25px',
990
- fill: tokens.gray500
991
- });
992
- var spinnerContainer = /*#__PURE__*/css({
993
- position: 'absolute',
994
- zIndex: 2,
995
- right: '8px',
996
- top: '8px'
997
- });
998
- var uniqueValidationError = /*#__PURE__*/css({
999
- marginTop: tokens.spacingS
1000
- });
1001
-
1002
- 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 () {
1010
- if (check === false) {
1011
- return;
1012
- }
1013
-
1014
- var newSlug = makeSlug(titleValue, {
1015
- isOptionalLocaleWithFallback: isOptionalLocaleWithFallback,
1016
- locale: locale,
1017
- createdAt: createdAt
1018
- });
1019
-
1020
- if (newSlug !== value) {
1021
- setValue(newSlug);
1022
- }
1023
- }, [value, titleValue, isOptionalLocaleWithFallback, check, createdAt, locale, setValue]);
1024
- }
1025
-
1026
- 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];
1035
- /**
1036
- * Check the uniqueness of the slug in the current space.
1037
- * The slug is unique if there is no published entry other than the
1038
- * current one, with the same slug.
1039
- */
1040
-
1041
-
1042
- React__default.useEffect(function () {
1043
- if (!debouncedValue) {
1044
- setStatus('unique');
1045
- return;
1046
- }
1047
-
1048
- setStatus('checking');
1049
- performUniqueCheck(debouncedValue).then(function (unique) {
1050
- setStatus(unique ? 'unique' : 'duplicate');
1051
- })["catch"](function () {
1052
- setStatus('checking');
1053
- });
1054
- }, [debouncedValue, performUniqueCheck]);
1055
- return status;
1056
- }
1057
-
1058
- 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);
1066
- return React__default.createElement("div", {
1067
- className: inputContainer
1068
- }, React__default.createElement(LinkIcon, {
1069
- className: icon
1070
- }), React__default.createElement(TextInput, {
1071
- className: input,
1072
- isInvalid: hasError || status === 'duplicate',
1073
- isDisabled: isDisabled,
1074
- value: value || '',
1075
- onChange: function onChange(e) {
1076
- setValue(e.target.value);
1077
-
1078
- if (_onChange) {
1079
- _onChange();
1080
- }
1081
- },
1082
- onBlur: function onBlur() {
1083
- if (_onBlur) {
1084
- _onBlur();
1085
- }
1086
- }
1087
- }), status === 'checking' && React__default.createElement("div", {
1088
- className: spinnerContainer
1089
- }, React__default.createElement(Spinner, {
1090
- testId: "slug-editor-spinner"
1091
- })), status === 'duplicate' && React__default.createElement(ValidationMessage, {
1092
- testId: "slug-editor-duplicate-error",
1093
- className: uniqueValidationError
1094
- }, "This slug has already been published in another entry"));
1095
- }
1096
- 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, {
1104
- isOptionalLocaleWithFallback: isOptionalLocaleWithFallback,
1105
- locale: locale,
1106
- createdAt: createdAt
1107
- });
1108
- return value === potentialSlug;
1109
- }, [titleValue, isOptionalLocaleWithFallback, locale, createdAt, value]);
1110
-
1111
- var _React$useState2 = React__default.useState(function () {
1112
- if (props.value) {
1113
- if (!props.titleValue) {
1114
- return false;
1115
- }
1116
-
1117
- return areEqual();
1118
- }
1119
-
1120
- return true;
1121
- }),
1122
- check = _React$useState2[0],
1123
- setCheck = _React$useState2[1];
1124
-
1125
- React__default.useEffect(function () {
1126
- if (areEqual()) {
1127
- setCheck(true);
1128
- }
1129
- }, [props.titleValue, areEqual]);
1130
- useSlugUpdater(props, check);
1131
- return React__default.createElement(SlugEditorFieldStatic, _extends({}, props, {
1132
- onChange: function onChange() {
1133
- setCheck(false);
1134
- },
1135
- onBlur: function onBlur() {
1136
- if (areEqual()) {
1137
- setCheck(true);
1138
- }
1139
- }
1140
- }));
1141
- }
1142
-
1143
- function isSupportedFieldTypes(val) {
1144
- return val === 'Symbol';
1145
- }
1146
-
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);
1169
-
1170
- case 3:
1171
- _context.next = 7;
1172
- break;
1173
-
1174
- case 5:
1175
- _context.prev = 5;
1176
- _context.t0 = _context["catch"](0);
1177
-
1178
- case 7:
1179
- case "end":
1180
- return _context.stop();
1181
- }
1182
- }
1183
- }, _callee, null, [[0, 5]]);
1184
- })), [setValue]);
1185
- return createElement("div", {
1186
- "data-test-id": "slug-editor"
1187
- }, createElement(Component, {
1188
- locale: locale,
1189
- createdAt: createdAt,
1190
- performUniqueCheck: performUniqueCheck,
1191
- hasError: errors.length > 0,
1192
- value: value,
1193
- isOptionalLocaleWithFallback: isOptionalLocaleWithFallback,
1194
- isDisabled: disabled,
1195
- titleValue: titleValue,
1196
- setValue: safeSetValue
1197
- }));
1198
- }
1199
-
1200
- 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;
1209
-
1210
- if (!isSupportedFieldTypes(field.type)) {
1211
- throw new Error("\"" + field.type + "\" field type is not supported by SlugEditor");
1212
- }
1213
-
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
1218
- // allows publishing even if the field is required) and if the locale has a
1219
- // fallback than there's no need for a slug unless the user manually enters
1220
- // one or the title field is also localized with a custom value.
1221
-
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) {
1231
- return res.total === 0;
1232
- });
1233
- }, [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
- return createElement(TrackingFieldConnector, {
1235
- sdk: props.baseSdk,
1236
- field: field,
1237
- defaultLocale: locales["default"],
1238
- isOptionalLocaleWithFallback: isOptionalLocaleWithFallback,
1239
- 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
- });
1269
- });
1270
- });
1271
- }
1272
- SlugEditor.defaultProps = {
1273
- isInitiallyDisabled: true
1274
- };
1275
-
1276
- export { SlugEditor, makeSlug, slugify };
1277
- //# sourceMappingURL=field-editor-slug.esm.js.map