@contentful/field-editor-rich-text 2.0.0-next.5 → 2.0.0-next.6

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.
@@ -14,11 +14,11 @@ var plateCore = require('@udecode/plate-core');
14
14
  var emotion = require('emotion');
15
15
  var deepEquals = _interopDefault(require('fast-deep-equal'));
16
16
  var noop = _interopDefault(require('lodash/noop'));
17
+ var slate = require('slate');
17
18
  var constate = _interopDefault(require('constate'));
18
19
  var plateSerializerDocx = require('@udecode/plate-serializer-docx');
19
20
  var plateBreak = require('@udecode/plate-break');
20
21
  var isHotkey = _interopDefault(require('is-hotkey'));
21
- var slate = require('slate');
22
22
  var Slate = require('slate-react');
23
23
  var f36Components = require('@contentful/f36-components');
24
24
  var mimetype = _interopDefault(require('@contentful/mimetype'));
@@ -28,6 +28,7 @@ var tokens = _interopDefault(require('@contentful/f36-tokens'));
28
28
  var find = _interopDefault(require('lodash/find'));
29
29
  var flow = _interopDefault(require('lodash/flow'));
30
30
  var plateList = require('@udecode/plate-list');
31
+ var plateResetNode = require('@udecode/plate-reset-node');
31
32
  var plateBasicMarks = require('@udecode/plate-basic-marks');
32
33
  var isPlainObject = _interopDefault(require('is-plain-obj'));
33
34
  var plateParagraph = require('@udecode/plate-paragraph');
@@ -708,6 +709,16 @@ var isInlineOrText = function isInlineOrText(node) {
708
709
  return slate.Text.isText(node) || slate.Element.isElement(node) && INLINE_TYPES.includes(node.type);
709
710
  };
710
711
 
712
+ function withLinkTracking(tracking, Component) {
713
+ return function ComponentWithTracking(props) {
714
+ return /*#__PURE__*/React__default.createElement(Component, Object.assign({}, props, {
715
+ onEntityFetchComplete: function onEntityFetchComplete() {
716
+ tracking.onViewportAction('linkRendered');
717
+ }
718
+ }));
719
+ };
720
+ }
721
+
711
722
  // "modern" Edge was released at 79.x
712
723
  var IS_EDGE_LEGACY = typeof navigator !== 'undefined' && /*#__PURE__*/ /Edge?\/(?:[0-6][0-9]|[0-7][0-8])/i.test(navigator.userAgent); // Native `beforeInput` events don't work well with react on Chrome 75
713
724
  // and older, Chrome 76+ can use `beforeInput` though.
@@ -854,10 +865,19 @@ function FetchingWrappedAssetCard(props) {
854
865
  var asset = assets[props.assetId];
855
866
  var defaultLocaleCode = props.sdk.locales["default"];
856
867
  var entityFile = asset != null && (_asset$fields = asset.fields) != null && _asset$fields.file ? asset.fields.file[props.locale] || asset.fields.file[defaultLocaleCode] : undefined;
868
+ var onEntityFetchComplete = props.onEntityFetchComplete;
857
869
  React.useEffect(function () {
858
870
  getOrLoadAsset(props.assetId);
859
871
  }, [props.assetId]); // eslint-disable-line
860
872
 
873
+ React.useEffect(function () {
874
+ if (!asset) {
875
+ return;
876
+ }
877
+
878
+ onEntityFetchComplete == null ? void 0 : onEntityFetchComplete();
879
+ }, [asset, onEntityFetchComplete]);
880
+
861
881
  function getAssetSrc() {
862
882
  if (!(entityFile != null && entityFile.url)) return '';
863
883
  return entityFile.url + "?h=300";
@@ -982,6 +1002,7 @@ function FetchingWrappedEntryCard(props) {
982
1002
  });
983
1003
  }, [props.sdk, entry]);
984
1004
  var defaultLocaleCode = props.sdk.locales["default"];
1005
+ var onEntityFetchComplete = props.onEntityFetchComplete;
985
1006
  React.useEffect(function () {
986
1007
  if (!entry || entry === 'failed') return;
987
1008
  fieldEditorShared.entityHelpers.getEntryImage({
@@ -997,6 +1018,14 @@ function FetchingWrappedEntryCard(props) {
997
1018
  getOrLoadEntry(props.entryId);
998
1019
  }, [props.entryId]); // eslint-disable-line
999
1020
 
1021
+ React.useEffect(function () {
1022
+ if (!entry) {
1023
+ return;
1024
+ }
1025
+
1026
+ onEntityFetchComplete == null ? void 0 : onEntityFetchComplete();
1027
+ }, [entry, onEntityFetchComplete]);
1028
+
1000
1029
  function renderDropdown() {
1001
1030
  if (!props.onEdit || !props.onRemove) return undefined;
1002
1031
  return [props.onEdit ? /*#__PURE__*/React.createElement(f36Components.MenuItem, {
@@ -1084,7 +1113,8 @@ var styles$3 = {
1084
1113
  function LinkedEntityBlock(props) {
1085
1114
  var attributes = props.attributes,
1086
1115
  children = props.children,
1087
- element = props.element;
1116
+ element = props.element,
1117
+ onEntityFetchComplete = props.onEntityFetchComplete;
1088
1118
  var isSelected = Slate.useSelected();
1089
1119
  var editor = useContentfulEditor();
1090
1120
  var sdk = useSdkContext();
@@ -1126,7 +1156,8 @@ function LinkedEntityBlock(props) {
1126
1156
  isDisabled: isDisabled,
1127
1157
  isSelected: isSelected,
1128
1158
  onRemove: handleRemoveClick,
1129
- onEdit: handleEditClick
1159
+ onEdit: handleEditClick,
1160
+ onEntityFetchComplete: onEntityFetchComplete
1130
1161
  }), entityType === 'Asset' && /*#__PURE__*/React__default.createElement(FetchingWrappedAssetCard, {
1131
1162
  sdk: sdk,
1132
1163
  assetId: entityId,
@@ -1134,7 +1165,8 @@ function LinkedEntityBlock(props) {
1134
1165
  isDisabled: isDisabled,
1135
1166
  isSelected: isSelected,
1136
1167
  onRemove: handleRemoveClick,
1137
- onEdit: handleEditClick
1168
+ onEdit: handleEditClick,
1169
+ onEntityFetchComplete: onEntityFetchComplete
1138
1170
  })), children);
1139
1171
  }
1140
1172
 
@@ -1142,201 +1174,197 @@ function createCommonjsModule(fn, module) {
1142
1174
  return module = { exports: {} }, fn(module, module.exports), module.exports;
1143
1175
  }
1144
1176
 
1145
- var runtime_1 = createCommonjsModule(function (module) {
1146
- /**
1147
- * Copyright (c) 2014-present, Facebook, Inc.
1148
- *
1149
- * This source code is licensed under the MIT license found in the
1150
- * LICENSE file in the root directory of this source tree.
1151
- */
1177
+ var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
1178
+ /**
1179
+ * Copyright (c) 2014-present, Facebook, Inc.
1180
+ *
1181
+ * This source code is licensed under the MIT license found in the
1182
+ * LICENSE file in the root directory of this source tree.
1183
+ */
1184
+ var runtime = function (exports) {
1185
+
1186
+ var Op = Object.prototype;
1187
+ var hasOwn = Op.hasOwnProperty;
1188
+ var undefined$1; // More compressible than void 0.
1189
+
1190
+ var $Symbol = typeof Symbol === "function" ? Symbol : {};
1191
+ var iteratorSymbol = $Symbol.iterator || "@@iterator";
1192
+ var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
1193
+ var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
1194
+
1195
+ function define(obj, key, value) {
1196
+ Object.defineProperty(obj, key, {
1197
+ value: value,
1198
+ enumerable: true,
1199
+ configurable: true,
1200
+ writable: true
1201
+ });
1202
+ return obj[key];
1203
+ }
1152
1204
 
1153
- var runtime = (function (exports) {
1154
-
1155
- var Op = Object.prototype;
1156
- var hasOwn = Op.hasOwnProperty;
1157
- var undefined$1; // More compressible than void 0.
1158
- var $Symbol = typeof Symbol === "function" ? Symbol : {};
1159
- var iteratorSymbol = $Symbol.iterator || "@@iterator";
1160
- var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
1161
- var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
1162
-
1163
- function define(obj, key, value) {
1164
- Object.defineProperty(obj, key, {
1165
- value: value,
1166
- enumerable: true,
1167
- configurable: true,
1168
- writable: true
1169
- });
1170
- return obj[key];
1171
- }
1172
- try {
1173
- // IE 8 has a broken Object.defineProperty that only works on DOM objects.
1174
- define({}, "");
1175
- } catch (err) {
1176
- define = function(obj, key, value) {
1177
- return obj[key] = value;
1178
- };
1179
- }
1205
+ try {
1206
+ // IE 8 has a broken Object.defineProperty that only works on DOM objects.
1207
+ define({}, "");
1208
+ } catch (err) {
1209
+ define = function define(obj, key, value) {
1210
+ return obj[key] = value;
1211
+ };
1212
+ }
1180
1213
 
1181
- function wrap(innerFn, outerFn, self, tryLocsList) {
1182
- // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
1183
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
1184
- var generator = Object.create(protoGenerator.prototype);
1185
- var context = new Context(tryLocsList || []);
1214
+ function wrap(innerFn, outerFn, self, tryLocsList) {
1215
+ // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
1216
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
1217
+ var generator = Object.create(protoGenerator.prototype);
1218
+ var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next,
1219
+ // .throw, and .return methods.
1186
1220
 
1187
- // The ._invoke method unifies the implementations of the .next,
1188
- // .throw, and .return methods.
1189
- generator._invoke = makeInvokeMethod(innerFn, self, context);
1221
+ generator._invoke = makeInvokeMethod(innerFn, self, context);
1222
+ return generator;
1223
+ }
1190
1224
 
1191
- return generator;
1192
- }
1193
- exports.wrap = wrap;
1194
-
1195
- // Try/catch helper to minimize deoptimizations. Returns a completion
1196
- // record like context.tryEntries[i].completion. This interface could
1197
- // have been (and was previously) designed to take a closure to be
1198
- // invoked without arguments, but in all the cases we care about we
1199
- // already have an existing method we want to call, so there's no need
1200
- // to create a new function object. We can even get away with assuming
1201
- // the method takes exactly one argument, since that happens to be true
1202
- // in every case, so we don't have to touch the arguments object. The
1203
- // only additional allocation required is the completion record, which
1204
- // has a stable shape and so hopefully should be cheap to allocate.
1205
- function tryCatch(fn, obj, arg) {
1206
- try {
1207
- return { type: "normal", arg: fn.call(obj, arg) };
1208
- } catch (err) {
1209
- return { type: "throw", arg: err };
1225
+ exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion
1226
+ // record like context.tryEntries[i].completion. This interface could
1227
+ // have been (and was previously) designed to take a closure to be
1228
+ // invoked without arguments, but in all the cases we care about we
1229
+ // already have an existing method we want to call, so there's no need
1230
+ // to create a new function object. We can even get away with assuming
1231
+ // the method takes exactly one argument, since that happens to be true
1232
+ // in every case, so we don't have to touch the arguments object. The
1233
+ // only additional allocation required is the completion record, which
1234
+ // has a stable shape and so hopefully should be cheap to allocate.
1235
+
1236
+ function tryCatch(fn, obj, arg) {
1237
+ try {
1238
+ return {
1239
+ type: "normal",
1240
+ arg: fn.call(obj, arg)
1241
+ };
1242
+ } catch (err) {
1243
+ return {
1244
+ type: "throw",
1245
+ arg: err
1246
+ };
1247
+ }
1210
1248
  }
1211
- }
1212
1249
 
1213
- var GenStateSuspendedStart = "suspendedStart";
1214
- var GenStateSuspendedYield = "suspendedYield";
1215
- var GenStateExecuting = "executing";
1216
- var GenStateCompleted = "completed";
1217
-
1218
- // Returning this object from the innerFn has the same effect as
1219
- // breaking out of the dispatch switch statement.
1220
- var ContinueSentinel = {};
1221
-
1222
- // Dummy constructor functions that we use as the .constructor and
1223
- // .constructor.prototype properties for functions that return Generator
1224
- // objects. For full spec compliance, you may wish to configure your
1225
- // minifier not to mangle the names of these two functions.
1226
- function Generator() {}
1227
- function GeneratorFunction() {}
1228
- function GeneratorFunctionPrototype() {}
1229
-
1230
- // This is a polyfill for %IteratorPrototype% for environments that
1231
- // don't natively support it.
1232
- var IteratorPrototype = {};
1233
- define(IteratorPrototype, iteratorSymbol, function () {
1234
- return this;
1235
- });
1250
+ var GenStateSuspendedStart = "suspendedStart";
1251
+ var GenStateSuspendedYield = "suspendedYield";
1252
+ var GenStateExecuting = "executing";
1253
+ var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as
1254
+ // breaking out of the dispatch switch statement.
1236
1255
 
1237
- var getProto = Object.getPrototypeOf;
1238
- var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
1239
- if (NativeIteratorPrototype &&
1240
- NativeIteratorPrototype !== Op &&
1241
- hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
1242
- // This environment has a native %IteratorPrototype%; use it instead
1243
- // of the polyfill.
1244
- IteratorPrototype = NativeIteratorPrototype;
1245
- }
1256
+ var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and
1257
+ // .constructor.prototype properties for functions that return Generator
1258
+ // objects. For full spec compliance, you may wish to configure your
1259
+ // minifier not to mangle the names of these two functions.
1246
1260
 
1247
- var Gp = GeneratorFunctionPrototype.prototype =
1248
- Generator.prototype = Object.create(IteratorPrototype);
1249
- GeneratorFunction.prototype = GeneratorFunctionPrototype;
1250
- define(Gp, "constructor", GeneratorFunctionPrototype);
1251
- define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
1252
- GeneratorFunction.displayName = define(
1253
- GeneratorFunctionPrototype,
1254
- toStringTagSymbol,
1255
- "GeneratorFunction"
1256
- );
1261
+ function Generator() {}
1257
1262
 
1258
- // Helper for defining the .next, .throw, and .return methods of the
1259
- // Iterator interface in terms of a single ._invoke method.
1260
- function defineIteratorMethods(prototype) {
1261
- ["next", "throw", "return"].forEach(function(method) {
1262
- define(prototype, method, function(arg) {
1263
- return this._invoke(method, arg);
1264
- });
1263
+ function GeneratorFunction() {}
1264
+
1265
+ function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that
1266
+ // don't natively support it.
1267
+
1268
+
1269
+ var IteratorPrototype = {};
1270
+ define(IteratorPrototype, iteratorSymbol, function () {
1271
+ return this;
1265
1272
  });
1266
- }
1273
+ var getProto = Object.getPrototypeOf;
1274
+ var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
1267
1275
 
1268
- exports.isGeneratorFunction = function(genFun) {
1269
- var ctor = typeof genFun === "function" && genFun.constructor;
1270
- return ctor
1271
- ? ctor === GeneratorFunction ||
1272
- // For the native GeneratorFunction constructor, the best we can
1273
- // do is to check its .name property.
1274
- (ctor.displayName || ctor.name) === "GeneratorFunction"
1275
- : false;
1276
- };
1276
+ if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
1277
+ // This environment has a native %IteratorPrototype%; use it instead
1278
+ // of the polyfill.
1279
+ IteratorPrototype = NativeIteratorPrototype;
1280
+ }
1277
1281
 
1278
- exports.mark = function(genFun) {
1279
- if (Object.setPrototypeOf) {
1280
- Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
1281
- } else {
1282
- genFun.__proto__ = GeneratorFunctionPrototype;
1283
- define(genFun, toStringTagSymbol, "GeneratorFunction");
1282
+ var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
1283
+ GeneratorFunction.prototype = GeneratorFunctionPrototype;
1284
+ define(Gp, "constructor", GeneratorFunctionPrototype);
1285
+ define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
1286
+ GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
1287
+ // Iterator interface in terms of a single ._invoke method.
1288
+
1289
+ function defineIteratorMethods(prototype) {
1290
+ ["next", "throw", "return"].forEach(function (method) {
1291
+ define(prototype, method, function (arg) {
1292
+ return this._invoke(method, arg);
1293
+ });
1294
+ });
1284
1295
  }
1285
- genFun.prototype = Object.create(Gp);
1286
- return genFun;
1287
- };
1288
1296
 
1289
- // Within the body of any async function, `await x` is transformed to
1290
- // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
1291
- // `hasOwn.call(value, "__await")` to determine if the yielded value is
1292
- // meant to be awaited.
1293
- exports.awrap = function(arg) {
1294
- return { __await: arg };
1295
- };
1297
+ exports.isGeneratorFunction = function (genFun) {
1298
+ var ctor = typeof genFun === "function" && genFun.constructor;
1299
+ return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can
1300
+ // do is to check its .name property.
1301
+ (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
1302
+ };
1296
1303
 
1297
- function AsyncIterator(generator, PromiseImpl) {
1298
- function invoke(method, arg, resolve, reject) {
1299
- var record = tryCatch(generator[method], generator, arg);
1300
- if (record.type === "throw") {
1301
- reject(record.arg);
1304
+ exports.mark = function (genFun) {
1305
+ if (Object.setPrototypeOf) {
1306
+ Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
1302
1307
  } else {
1303
- var result = record.arg;
1304
- var value = result.value;
1305
- if (value &&
1306
- typeof value === "object" &&
1307
- hasOwn.call(value, "__await")) {
1308
- return PromiseImpl.resolve(value.__await).then(function(value) {
1309
- invoke("next", value, resolve, reject);
1310
- }, function(err) {
1311
- invoke("throw", err, resolve, reject);
1308
+ genFun.__proto__ = GeneratorFunctionPrototype;
1309
+ define(genFun, toStringTagSymbol, "GeneratorFunction");
1310
+ }
1311
+
1312
+ genFun.prototype = Object.create(Gp);
1313
+ return genFun;
1314
+ }; // Within the body of any async function, `await x` is transformed to
1315
+ // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
1316
+ // `hasOwn.call(value, "__await")` to determine if the yielded value is
1317
+ // meant to be awaited.
1318
+
1319
+
1320
+ exports.awrap = function (arg) {
1321
+ return {
1322
+ __await: arg
1323
+ };
1324
+ };
1325
+
1326
+ function AsyncIterator(generator, PromiseImpl) {
1327
+ function invoke(method, arg, resolve, reject) {
1328
+ var record = tryCatch(generator[method], generator, arg);
1329
+
1330
+ if (record.type === "throw") {
1331
+ reject(record.arg);
1332
+ } else {
1333
+ var result = record.arg;
1334
+ var value = result.value;
1335
+
1336
+ if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
1337
+ return PromiseImpl.resolve(value.__await).then(function (value) {
1338
+ invoke("next", value, resolve, reject);
1339
+ }, function (err) {
1340
+ invoke("throw", err, resolve, reject);
1341
+ });
1342
+ }
1343
+
1344
+ return PromiseImpl.resolve(value).then(function (unwrapped) {
1345
+ // When a yielded Promise is resolved, its final value becomes
1346
+ // the .value of the Promise<{value,done}> result for the
1347
+ // current iteration.
1348
+ result.value = unwrapped;
1349
+ resolve(result);
1350
+ }, function (error) {
1351
+ // If a rejected Promise was yielded, throw the rejection back
1352
+ // into the async generator function so it can be handled there.
1353
+ return invoke("throw", error, resolve, reject);
1312
1354
  });
1313
1355
  }
1314
-
1315
- return PromiseImpl.resolve(value).then(function(unwrapped) {
1316
- // When a yielded Promise is resolved, its final value becomes
1317
- // the .value of the Promise<{value,done}> result for the
1318
- // current iteration.
1319
- result.value = unwrapped;
1320
- resolve(result);
1321
- }, function(error) {
1322
- // If a rejected Promise was yielded, throw the rejection back
1323
- // into the async generator function so it can be handled there.
1324
- return invoke("throw", error, resolve, reject);
1325
- });
1326
1356
  }
1327
- }
1328
1357
 
1329
- var previousPromise;
1358
+ var previousPromise;
1330
1359
 
1331
- function enqueue(method, arg) {
1332
- function callInvokeWithMethodAndArg() {
1333
- return new PromiseImpl(function(resolve, reject) {
1334
- invoke(method, arg, resolve, reject);
1335
- });
1336
- }
1360
+ function enqueue(method, arg) {
1361
+ function callInvokeWithMethodAndArg() {
1362
+ return new PromiseImpl(function (resolve, reject) {
1363
+ invoke(method, arg, resolve, reject);
1364
+ });
1365
+ }
1337
1366
 
1338
- return previousPromise =
1339
- // If enqueue has been called before, then we want to wait until
1367
+ return previousPromise = // If enqueue has been called before, then we want to wait until
1340
1368
  // all previous Promises have been resolved before calling invoke,
1341
1369
  // so that results are always delivered in the correct order. If
1342
1370
  // enqueue has not been called before, then it is important to
@@ -1348,554 +1376,527 @@ var runtime = (function (exports) {
1348
1376
  // execute code before the first await. Since we implement simple
1349
1377
  // async functions in terms of async generators, it is especially
1350
1378
  // important to get this right, even though it requires care.
1351
- previousPromise ? previousPromise.then(
1352
- callInvokeWithMethodAndArg,
1353
- // Avoid propagating failures to Promises returned by later
1354
- // invocations of the iterator.
1355
- callInvokeWithMethodAndArg
1356
- ) : callInvokeWithMethodAndArg();
1379
+ previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later
1380
+ // invocations of the iterator.
1381
+ callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
1382
+ } // Define the unified helper method that is used to implement .next,
1383
+ // .throw, and .return (see defineIteratorMethods).
1384
+
1385
+
1386
+ this._invoke = enqueue;
1357
1387
  }
1358
1388
 
1359
- // Define the unified helper method that is used to implement .next,
1360
- // .throw, and .return (see defineIteratorMethods).
1361
- this._invoke = enqueue;
1362
- }
1389
+ defineIteratorMethods(AsyncIterator.prototype);
1390
+ define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
1391
+ return this;
1392
+ });
1393
+ exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
1394
+ // AsyncIterator objects; they just return a Promise for the value of
1395
+ // the final result produced by the iterator.
1396
+
1397
+ exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
1398
+ if (PromiseImpl === void 0) PromiseImpl = Promise;
1399
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
1400
+ return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
1401
+ : iter.next().then(function (result) {
1402
+ return result.done ? result.value : iter.next();
1403
+ });
1404
+ };
1363
1405
 
1364
- defineIteratorMethods(AsyncIterator.prototype);
1365
- define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
1366
- return this;
1367
- });
1368
- exports.AsyncIterator = AsyncIterator;
1369
-
1370
- // Note that simple async functions are implemented on top of
1371
- // AsyncIterator objects; they just return a Promise for the value of
1372
- // the final result produced by the iterator.
1373
- exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
1374
- if (PromiseImpl === void 0) PromiseImpl = Promise;
1375
-
1376
- var iter = new AsyncIterator(
1377
- wrap(innerFn, outerFn, self, tryLocsList),
1378
- PromiseImpl
1379
- );
1380
-
1381
- return exports.isGeneratorFunction(outerFn)
1382
- ? iter // If outerFn is a generator, return the full iterator.
1383
- : iter.next().then(function(result) {
1384
- return result.done ? result.value : iter.next();
1385
- });
1386
- };
1406
+ function makeInvokeMethod(innerFn, self, context) {
1407
+ var state = GenStateSuspendedStart;
1408
+ return function invoke(method, arg) {
1409
+ if (state === GenStateExecuting) {
1410
+ throw new Error("Generator is already running");
1411
+ }
1387
1412
 
1388
- function makeInvokeMethod(innerFn, self, context) {
1389
- var state = GenStateSuspendedStart;
1413
+ if (state === GenStateCompleted) {
1414
+ if (method === "throw") {
1415
+ throw arg;
1416
+ } // Be forgiving, per 25.3.3.3.3 of the spec:
1417
+ // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
1390
1418
 
1391
- return function invoke(method, arg) {
1392
- if (state === GenStateExecuting) {
1393
- throw new Error("Generator is already running");
1394
- }
1395
1419
 
1396
- if (state === GenStateCompleted) {
1397
- if (method === "throw") {
1398
- throw arg;
1420
+ return doneResult();
1399
1421
  }
1400
1422
 
1401
- // Be forgiving, per 25.3.3.3.3 of the spec:
1402
- // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
1403
- return doneResult();
1404
- }
1423
+ context.method = method;
1424
+ context.arg = arg;
1425
+
1426
+ while (true) {
1427
+ var delegate = context.delegate;
1405
1428
 
1406
- context.method = method;
1407
- context.arg = arg;
1429
+ if (delegate) {
1430
+ var delegateResult = maybeInvokeDelegate(delegate, context);
1408
1431
 
1409
- while (true) {
1410
- var delegate = context.delegate;
1411
- if (delegate) {
1412
- var delegateResult = maybeInvokeDelegate(delegate, context);
1413
- if (delegateResult) {
1414
- if (delegateResult === ContinueSentinel) continue;
1415
- return delegateResult;
1432
+ if (delegateResult) {
1433
+ if (delegateResult === ContinueSentinel) continue;
1434
+ return delegateResult;
1435
+ }
1416
1436
  }
1417
- }
1418
1437
 
1419
- if (context.method === "next") {
1420
- // Setting context._sent for legacy support of Babel's
1421
- // function.sent implementation.
1422
- context.sent = context._sent = context.arg;
1438
+ if (context.method === "next") {
1439
+ // Setting context._sent for legacy support of Babel's
1440
+ // function.sent implementation.
1441
+ context.sent = context._sent = context.arg;
1442
+ } else if (context.method === "throw") {
1443
+ if (state === GenStateSuspendedStart) {
1444
+ state = GenStateCompleted;
1445
+ throw context.arg;
1446
+ }
1423
1447
 
1424
- } else if (context.method === "throw") {
1425
- if (state === GenStateSuspendedStart) {
1426
- state = GenStateCompleted;
1427
- throw context.arg;
1448
+ context.dispatchException(context.arg);
1449
+ } else if (context.method === "return") {
1450
+ context.abrupt("return", context.arg);
1428
1451
  }
1429
1452
 
1430
- context.dispatchException(context.arg);
1453
+ state = GenStateExecuting;
1454
+ var record = tryCatch(innerFn, self, context);
1431
1455
 
1432
- } else if (context.method === "return") {
1433
- context.abrupt("return", context.arg);
1434
- }
1456
+ if (record.type === "normal") {
1457
+ // If an exception is thrown from innerFn, we leave state ===
1458
+ // GenStateExecuting and loop back for another invocation.
1459
+ state = context.done ? GenStateCompleted : GenStateSuspendedYield;
1435
1460
 
1436
- state = GenStateExecuting;
1461
+ if (record.arg === ContinueSentinel) {
1462
+ continue;
1463
+ }
1437
1464
 
1438
- var record = tryCatch(innerFn, self, context);
1439
- if (record.type === "normal") {
1440
- // If an exception is thrown from innerFn, we leave state ===
1441
- // GenStateExecuting and loop back for another invocation.
1442
- state = context.done
1443
- ? GenStateCompleted
1444
- : GenStateSuspendedYield;
1465
+ return {
1466
+ value: record.arg,
1467
+ done: context.done
1468
+ };
1469
+ } else if (record.type === "throw") {
1470
+ state = GenStateCompleted; // Dispatch the exception by looping back around to the
1471
+ // context.dispatchException(context.arg) call above.
1445
1472
 
1446
- if (record.arg === ContinueSentinel) {
1447
- continue;
1473
+ context.method = "throw";
1474
+ context.arg = record.arg;
1475
+ }
1476
+ }
1477
+ };
1478
+ } // Call delegate.iterator[context.method](context.arg) and handle the
1479
+ // result, either by returning a { value, done } result from the
1480
+ // delegate iterator, or by modifying context.method and context.arg,
1481
+ // setting context.delegate to null, and returning the ContinueSentinel.
1482
+
1483
+
1484
+ function maybeInvokeDelegate(delegate, context) {
1485
+ var method = delegate.iterator[context.method];
1486
+
1487
+ if (method === undefined$1) {
1488
+ // A .throw or .return when the delegate iterator has no .throw
1489
+ // method always terminates the yield* loop.
1490
+ context.delegate = null;
1491
+
1492
+ if (context.method === "throw") {
1493
+ // Note: ["return"] must be used for ES3 parsing compatibility.
1494
+ if (delegate.iterator["return"]) {
1495
+ // If the delegate iterator has a return method, give it a
1496
+ // chance to clean up.
1497
+ context.method = "return";
1498
+ context.arg = undefined$1;
1499
+ maybeInvokeDelegate(delegate, context);
1500
+
1501
+ if (context.method === "throw") {
1502
+ // If maybeInvokeDelegate(context) changed context.method from
1503
+ // "return" to "throw", let that override the TypeError below.
1504
+ return ContinueSentinel;
1505
+ }
1448
1506
  }
1449
1507
 
1450
- return {
1451
- value: record.arg,
1452
- done: context.done
1453
- };
1454
-
1455
- } else if (record.type === "throw") {
1456
- state = GenStateCompleted;
1457
- // Dispatch the exception by looping back around to the
1458
- // context.dispatchException(context.arg) call above.
1459
1508
  context.method = "throw";
1460
- context.arg = record.arg;
1509
+ context.arg = new TypeError("The iterator does not provide a 'throw' method");
1461
1510
  }
1511
+
1512
+ return ContinueSentinel;
1462
1513
  }
1463
- };
1464
- }
1465
1514
 
1466
- // Call delegate.iterator[context.method](context.arg) and handle the
1467
- // result, either by returning a { value, done } result from the
1468
- // delegate iterator, or by modifying context.method and context.arg,
1469
- // setting context.delegate to null, and returning the ContinueSentinel.
1470
- function maybeInvokeDelegate(delegate, context) {
1471
- var method = delegate.iterator[context.method];
1472
- if (method === undefined$1) {
1473
- // A .throw or .return when the delegate iterator has no .throw
1474
- // method always terminates the yield* loop.
1475
- context.delegate = null;
1515
+ var record = tryCatch(method, delegate.iterator, context.arg);
1476
1516
 
1477
- if (context.method === "throw") {
1478
- // Note: ["return"] must be used for ES3 parsing compatibility.
1479
- if (delegate.iterator["return"]) {
1480
- // If the delegate iterator has a return method, give it a
1481
- // chance to clean up.
1482
- context.method = "return";
1483
- context.arg = undefined$1;
1484
- maybeInvokeDelegate(delegate, context);
1517
+ if (record.type === "throw") {
1518
+ context.method = "throw";
1519
+ context.arg = record.arg;
1520
+ context.delegate = null;
1521
+ return ContinueSentinel;
1522
+ }
1485
1523
 
1486
- if (context.method === "throw") {
1487
- // If maybeInvokeDelegate(context) changed context.method from
1488
- // "return" to "throw", let that override the TypeError below.
1489
- return ContinueSentinel;
1490
- }
1491
- }
1524
+ var info = record.arg;
1492
1525
 
1526
+ if (!info) {
1493
1527
  context.method = "throw";
1494
- context.arg = new TypeError(
1495
- "The iterator does not provide a 'throw' method");
1528
+ context.arg = new TypeError("iterator result is not an object");
1529
+ context.delegate = null;
1530
+ return ContinueSentinel;
1496
1531
  }
1497
1532
 
1498
- return ContinueSentinel;
1499
- }
1533
+ if (info.done) {
1534
+ // Assign the result of the finished delegate to the temporary
1535
+ // variable specified by delegate.resultName (see delegateYield).
1536
+ context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield).
1500
1537
 
1501
- var record = tryCatch(method, delegate.iterator, context.arg);
1538
+ context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the
1539
+ // exception, let the outer generator proceed normally. If
1540
+ // context.method was "next", forget context.arg since it has been
1541
+ // "consumed" by the delegate iterator. If context.method was
1542
+ // "return", allow the original .return call to continue in the
1543
+ // outer generator.
1502
1544
 
1503
- if (record.type === "throw") {
1504
- context.method = "throw";
1505
- context.arg = record.arg;
1506
- context.delegate = null;
1507
- return ContinueSentinel;
1508
- }
1545
+ if (context.method !== "return") {
1546
+ context.method = "next";
1547
+ context.arg = undefined$1;
1548
+ }
1549
+ } else {
1550
+ // Re-yield the result returned by the delegate method.
1551
+ return info;
1552
+ } // The delegate iterator is finished, so forget it and continue with
1553
+ // the outer generator.
1509
1554
 
1510
- var info = record.arg;
1511
1555
 
1512
- if (! info) {
1513
- context.method = "throw";
1514
- context.arg = new TypeError("iterator result is not an object");
1515
1556
  context.delegate = null;
1516
1557
  return ContinueSentinel;
1517
- }
1518
-
1519
- if (info.done) {
1520
- // Assign the result of the finished delegate to the temporary
1521
- // variable specified by delegate.resultName (see delegateYield).
1522
- context[delegate.resultName] = info.value;
1523
-
1524
- // Resume execution at the desired location (see delegateYield).
1525
- context.next = delegate.nextLoc;
1526
-
1527
- // If context.method was "throw" but the delegate handled the
1528
- // exception, let the outer generator proceed normally. If
1529
- // context.method was "next", forget context.arg since it has been
1530
- // "consumed" by the delegate iterator. If context.method was
1531
- // "return", allow the original .return call to continue in the
1532
- // outer generator.
1533
- if (context.method !== "return") {
1534
- context.method = "next";
1535
- context.arg = undefined$1;
1536
- }
1537
-
1538
- } else {
1539
- // Re-yield the result returned by the delegate method.
1540
- return info;
1541
- }
1558
+ } // Define Generator.prototype.{next,throw,return} in terms of the
1559
+ // unified ._invoke helper method.
1542
1560
 
1543
- // The delegate iterator is finished, so forget it and continue with
1544
- // the outer generator.
1545
- context.delegate = null;
1546
- return ContinueSentinel;
1547
- }
1548
1561
 
1549
- // Define Generator.prototype.{next,throw,return} in terms of the
1550
- // unified ._invoke helper method.
1551
- defineIteratorMethods(Gp);
1562
+ defineIteratorMethods(Gp);
1563
+ define(Gp, toStringTagSymbol, "Generator"); // A Generator should always return itself as the iterator object when the
1564
+ // @@iterator function is called on it. Some browsers' implementations of the
1565
+ // iterator prototype chain incorrectly implement this, causing the Generator
1566
+ // object to not be returned from this call. This ensures that doesn't happen.
1567
+ // See https://github.com/facebook/regenerator/issues/274 for more details.
1552
1568
 
1553
- define(Gp, toStringTagSymbol, "Generator");
1569
+ define(Gp, iteratorSymbol, function () {
1570
+ return this;
1571
+ });
1572
+ define(Gp, "toString", function () {
1573
+ return "[object Generator]";
1574
+ });
1554
1575
 
1555
- // A Generator should always return itself as the iterator object when the
1556
- // @@iterator function is called on it. Some browsers' implementations of the
1557
- // iterator prototype chain incorrectly implement this, causing the Generator
1558
- // object to not be returned from this call. This ensures that doesn't happen.
1559
- // See https://github.com/facebook/regenerator/issues/274 for more details.
1560
- define(Gp, iteratorSymbol, function() {
1561
- return this;
1562
- });
1576
+ function pushTryEntry(locs) {
1577
+ var entry = {
1578
+ tryLoc: locs[0]
1579
+ };
1563
1580
 
1564
- define(Gp, "toString", function() {
1565
- return "[object Generator]";
1566
- });
1581
+ if (1 in locs) {
1582
+ entry.catchLoc = locs[1];
1583
+ }
1567
1584
 
1568
- function pushTryEntry(locs) {
1569
- var entry = { tryLoc: locs[0] };
1585
+ if (2 in locs) {
1586
+ entry.finallyLoc = locs[2];
1587
+ entry.afterLoc = locs[3];
1588
+ }
1570
1589
 
1571
- if (1 in locs) {
1572
- entry.catchLoc = locs[1];
1590
+ this.tryEntries.push(entry);
1573
1591
  }
1574
1592
 
1575
- if (2 in locs) {
1576
- entry.finallyLoc = locs[2];
1577
- entry.afterLoc = locs[3];
1593
+ function resetTryEntry(entry) {
1594
+ var record = entry.completion || {};
1595
+ record.type = "normal";
1596
+ delete record.arg;
1597
+ entry.completion = record;
1578
1598
  }
1579
1599
 
1580
- this.tryEntries.push(entry);
1581
- }
1582
-
1583
- function resetTryEntry(entry) {
1584
- var record = entry.completion || {};
1585
- record.type = "normal";
1586
- delete record.arg;
1587
- entry.completion = record;
1588
- }
1589
-
1590
- function Context(tryLocsList) {
1591
- // The root entry object (effectively a try statement without a catch
1592
- // or a finally block) gives us a place to store values thrown from
1593
- // locations where there is no enclosing try statement.
1594
- this.tryEntries = [{ tryLoc: "root" }];
1595
- tryLocsList.forEach(pushTryEntry, this);
1596
- this.reset(true);
1597
- }
1598
-
1599
- exports.keys = function(object) {
1600
- var keys = [];
1601
- for (var key in object) {
1602
- keys.push(key);
1600
+ function Context(tryLocsList) {
1601
+ // The root entry object (effectively a try statement without a catch
1602
+ // or a finally block) gives us a place to store values thrown from
1603
+ // locations where there is no enclosing try statement.
1604
+ this.tryEntries = [{
1605
+ tryLoc: "root"
1606
+ }];
1607
+ tryLocsList.forEach(pushTryEntry, this);
1608
+ this.reset(true);
1603
1609
  }
1604
- keys.reverse();
1605
-
1606
- // Rather than returning an object with a next method, we keep
1607
- // things simple and return the next function itself.
1608
- return function next() {
1609
- while (keys.length) {
1610
- var key = keys.pop();
1611
- if (key in object) {
1612
- next.value = key;
1613
- next.done = false;
1614
- return next;
1615
- }
1616
- }
1617
1610
 
1618
- // To avoid creating an additional object, we just hang the .value
1619
- // and .done properties off the next function object itself. This
1620
- // also ensures that the minifier will not anonymize the function.
1621
- next.done = true;
1622
- return next;
1623
- };
1624
- };
1611
+ exports.keys = function (object) {
1612
+ var keys = [];
1625
1613
 
1626
- function values(iterable) {
1627
- if (iterable) {
1628
- var iteratorMethod = iterable[iteratorSymbol];
1629
- if (iteratorMethod) {
1630
- return iteratorMethod.call(iterable);
1614
+ for (var key in object) {
1615
+ keys.push(key);
1631
1616
  }
1632
1617
 
1633
- if (typeof iterable.next === "function") {
1634
- return iterable;
1635
- }
1618
+ keys.reverse(); // Rather than returning an object with a next method, we keep
1619
+ // things simple and return the next function itself.
1636
1620
 
1637
- if (!isNaN(iterable.length)) {
1638
- var i = -1, next = function next() {
1639
- while (++i < iterable.length) {
1640
- if (hasOwn.call(iterable, i)) {
1641
- next.value = iterable[i];
1642
- next.done = false;
1643
- return next;
1644
- }
1645
- }
1621
+ return function next() {
1622
+ while (keys.length) {
1623
+ var key = keys.pop();
1646
1624
 
1647
- next.value = undefined$1;
1648
- next.done = true;
1625
+ if (key in object) {
1626
+ next.value = key;
1627
+ next.done = false;
1628
+ return next;
1629
+ }
1630
+ } // To avoid creating an additional object, we just hang the .value
1631
+ // and .done properties off the next function object itself. This
1632
+ // also ensures that the minifier will not anonymize the function.
1649
1633
 
1650
- return next;
1651
- };
1652
1634
 
1653
- return next.next = next;
1654
- }
1655
- }
1635
+ next.done = true;
1636
+ return next;
1637
+ };
1638
+ };
1656
1639
 
1657
- // Return an iterator with no values.
1658
- return { next: doneResult };
1659
- }
1660
- exports.values = values;
1640
+ function values(iterable) {
1641
+ if (iterable) {
1642
+ var iteratorMethod = iterable[iteratorSymbol];
1661
1643
 
1662
- function doneResult() {
1663
- return { value: undefined$1, done: true };
1664
- }
1644
+ if (iteratorMethod) {
1645
+ return iteratorMethod.call(iterable);
1646
+ }
1665
1647
 
1666
- Context.prototype = {
1667
- constructor: Context,
1668
-
1669
- reset: function(skipTempReset) {
1670
- this.prev = 0;
1671
- this.next = 0;
1672
- // Resetting context._sent for legacy support of Babel's
1673
- // function.sent implementation.
1674
- this.sent = this._sent = undefined$1;
1675
- this.done = false;
1676
- this.delegate = null;
1677
-
1678
- this.method = "next";
1679
- this.arg = undefined$1;
1680
-
1681
- this.tryEntries.forEach(resetTryEntry);
1682
-
1683
- if (!skipTempReset) {
1684
- for (var name in this) {
1685
- // Not sure about the optimal order of these conditions:
1686
- if (name.charAt(0) === "t" &&
1687
- hasOwn.call(this, name) &&
1688
- !isNaN(+name.slice(1))) {
1689
- this[name] = undefined$1;
1690
- }
1648
+ if (typeof iterable.next === "function") {
1649
+ return iterable;
1691
1650
  }
1692
- }
1693
- },
1694
1651
 
1695
- stop: function() {
1696
- this.done = true;
1652
+ if (!isNaN(iterable.length)) {
1653
+ var i = -1,
1654
+ next = function next() {
1655
+ while (++i < iterable.length) {
1656
+ if (hasOwn.call(iterable, i)) {
1657
+ next.value = iterable[i];
1658
+ next.done = false;
1659
+ return next;
1660
+ }
1661
+ }
1697
1662
 
1698
- var rootEntry = this.tryEntries[0];
1699
- var rootRecord = rootEntry.completion;
1700
- if (rootRecord.type === "throw") {
1701
- throw rootRecord.arg;
1702
- }
1663
+ next.value = undefined$1;
1664
+ next.done = true;
1665
+ return next;
1666
+ };
1703
1667
 
1704
- return this.rval;
1705
- },
1668
+ return next.next = next;
1669
+ }
1670
+ } // Return an iterator with no values.
1706
1671
 
1707
- dispatchException: function(exception) {
1708
- if (this.done) {
1709
- throw exception;
1710
- }
1711
1672
 
1712
- var context = this;
1713
- function handle(loc, caught) {
1714
- record.type = "throw";
1715
- record.arg = exception;
1716
- context.next = loc;
1673
+ return {
1674
+ next: doneResult
1675
+ };
1676
+ }
1717
1677
 
1718
- if (caught) {
1719
- // If the dispatched exception was caught by a catch block,
1720
- // then let that catch block handle the exception normally.
1721
- context.method = "next";
1722
- context.arg = undefined$1;
1723
- }
1678
+ exports.values = values;
1724
1679
 
1725
- return !! caught;
1726
- }
1680
+ function doneResult() {
1681
+ return {
1682
+ value: undefined$1,
1683
+ done: true
1684
+ };
1685
+ }
1727
1686
 
1728
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1729
- var entry = this.tryEntries[i];
1730
- var record = entry.completion;
1687
+ Context.prototype = {
1688
+ constructor: Context,
1689
+ reset: function reset(skipTempReset) {
1690
+ this.prev = 0;
1691
+ this.next = 0; // Resetting context._sent for legacy support of Babel's
1692
+ // function.sent implementation.
1731
1693
 
1732
- if (entry.tryLoc === "root") {
1733
- // Exception thrown outside of any try block that could handle
1734
- // it, so set the completion value of the entire function to
1735
- // throw the exception.
1736
- return handle("end");
1694
+ this.sent = this._sent = undefined$1;
1695
+ this.done = false;
1696
+ this.delegate = null;
1697
+ this.method = "next";
1698
+ this.arg = undefined$1;
1699
+ this.tryEntries.forEach(resetTryEntry);
1700
+
1701
+ if (!skipTempReset) {
1702
+ for (var name in this) {
1703
+ // Not sure about the optimal order of these conditions:
1704
+ if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
1705
+ this[name] = undefined$1;
1706
+ }
1707
+ }
1737
1708
  }
1709
+ },
1710
+ stop: function stop() {
1711
+ this.done = true;
1712
+ var rootEntry = this.tryEntries[0];
1713
+ var rootRecord = rootEntry.completion;
1738
1714
 
1739
- if (entry.tryLoc <= this.prev) {
1740
- var hasCatch = hasOwn.call(entry, "catchLoc");
1741
- var hasFinally = hasOwn.call(entry, "finallyLoc");
1715
+ if (rootRecord.type === "throw") {
1716
+ throw rootRecord.arg;
1717
+ }
1742
1718
 
1743
- if (hasCatch && hasFinally) {
1744
- if (this.prev < entry.catchLoc) {
1745
- return handle(entry.catchLoc, true);
1746
- } else if (this.prev < entry.finallyLoc) {
1747
- return handle(entry.finallyLoc);
1748
- }
1719
+ return this.rval;
1720
+ },
1721
+ dispatchException: function dispatchException(exception) {
1722
+ if (this.done) {
1723
+ throw exception;
1724
+ }
1749
1725
 
1750
- } else if (hasCatch) {
1751
- if (this.prev < entry.catchLoc) {
1752
- return handle(entry.catchLoc, true);
1753
- }
1726
+ var context = this;
1754
1727
 
1755
- } else if (hasFinally) {
1756
- if (this.prev < entry.finallyLoc) {
1757
- return handle(entry.finallyLoc);
1758
- }
1728
+ function handle(loc, caught) {
1729
+ record.type = "throw";
1730
+ record.arg = exception;
1731
+ context.next = loc;
1759
1732
 
1760
- } else {
1761
- throw new Error("try statement without catch or finally");
1733
+ if (caught) {
1734
+ // If the dispatched exception was caught by a catch block,
1735
+ // then let that catch block handle the exception normally.
1736
+ context.method = "next";
1737
+ context.arg = undefined$1;
1762
1738
  }
1763
- }
1764
- }
1765
- },
1766
1739
 
1767
- abrupt: function(type, arg) {
1768
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1769
- var entry = this.tryEntries[i];
1770
- if (entry.tryLoc <= this.prev &&
1771
- hasOwn.call(entry, "finallyLoc") &&
1772
- this.prev < entry.finallyLoc) {
1773
- var finallyEntry = entry;
1774
- break;
1740
+ return !!caught;
1775
1741
  }
1776
- }
1777
1742
 
1778
- if (finallyEntry &&
1779
- (type === "break" ||
1780
- type === "continue") &&
1781
- finallyEntry.tryLoc <= arg &&
1782
- arg <= finallyEntry.finallyLoc) {
1783
- // Ignore the finally entry if control is not jumping to a
1784
- // location outside the try/catch block.
1785
- finallyEntry = null;
1786
- }
1743
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1744
+ var entry = this.tryEntries[i];
1745
+ var record = entry.completion;
1787
1746
 
1788
- var record = finallyEntry ? finallyEntry.completion : {};
1789
- record.type = type;
1790
- record.arg = arg;
1747
+ if (entry.tryLoc === "root") {
1748
+ // Exception thrown outside of any try block that could handle
1749
+ // it, so set the completion value of the entire function to
1750
+ // throw the exception.
1751
+ return handle("end");
1752
+ }
1791
1753
 
1792
- if (finallyEntry) {
1793
- this.method = "next";
1794
- this.next = finallyEntry.finallyLoc;
1795
- return ContinueSentinel;
1796
- }
1754
+ if (entry.tryLoc <= this.prev) {
1755
+ var hasCatch = hasOwn.call(entry, "catchLoc");
1756
+ var hasFinally = hasOwn.call(entry, "finallyLoc");
1797
1757
 
1798
- return this.complete(record);
1799
- },
1758
+ if (hasCatch && hasFinally) {
1759
+ if (this.prev < entry.catchLoc) {
1760
+ return handle(entry.catchLoc, true);
1761
+ } else if (this.prev < entry.finallyLoc) {
1762
+ return handle(entry.finallyLoc);
1763
+ }
1764
+ } else if (hasCatch) {
1765
+ if (this.prev < entry.catchLoc) {
1766
+ return handle(entry.catchLoc, true);
1767
+ }
1768
+ } else if (hasFinally) {
1769
+ if (this.prev < entry.finallyLoc) {
1770
+ return handle(entry.finallyLoc);
1771
+ }
1772
+ } else {
1773
+ throw new Error("try statement without catch or finally");
1774
+ }
1775
+ }
1776
+ }
1777
+ },
1778
+ abrupt: function abrupt(type, arg) {
1779
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1780
+ var entry = this.tryEntries[i];
1800
1781
 
1801
- complete: function(record, afterLoc) {
1802
- if (record.type === "throw") {
1803
- throw record.arg;
1804
- }
1782
+ if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
1783
+ var finallyEntry = entry;
1784
+ break;
1785
+ }
1786
+ }
1805
1787
 
1806
- if (record.type === "break" ||
1807
- record.type === "continue") {
1808
- this.next = record.arg;
1809
- } else if (record.type === "return") {
1810
- this.rval = this.arg = record.arg;
1811
- this.method = "return";
1812
- this.next = "end";
1813
- } else if (record.type === "normal" && afterLoc) {
1814
- this.next = afterLoc;
1815
- }
1788
+ if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
1789
+ // Ignore the finally entry if control is not jumping to a
1790
+ // location outside the try/catch block.
1791
+ finallyEntry = null;
1792
+ }
1816
1793
 
1817
- return ContinueSentinel;
1818
- },
1794
+ var record = finallyEntry ? finallyEntry.completion : {};
1795
+ record.type = type;
1796
+ record.arg = arg;
1819
1797
 
1820
- finish: function(finallyLoc) {
1821
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1822
- var entry = this.tryEntries[i];
1823
- if (entry.finallyLoc === finallyLoc) {
1824
- this.complete(entry.completion, entry.afterLoc);
1825
- resetTryEntry(entry);
1798
+ if (finallyEntry) {
1799
+ this.method = "next";
1800
+ this.next = finallyEntry.finallyLoc;
1826
1801
  return ContinueSentinel;
1827
1802
  }
1828
- }
1829
- },
1830
1803
 
1831
- "catch": function(tryLoc) {
1832
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1833
- var entry = this.tryEntries[i];
1834
- if (entry.tryLoc === tryLoc) {
1835
- var record = entry.completion;
1836
- if (record.type === "throw") {
1837
- var thrown = record.arg;
1804
+ return this.complete(record);
1805
+ },
1806
+ complete: function complete(record, afterLoc) {
1807
+ if (record.type === "throw") {
1808
+ throw record.arg;
1809
+ }
1810
+
1811
+ if (record.type === "break" || record.type === "continue") {
1812
+ this.next = record.arg;
1813
+ } else if (record.type === "return") {
1814
+ this.rval = this.arg = record.arg;
1815
+ this.method = "return";
1816
+ this.next = "end";
1817
+ } else if (record.type === "normal" && afterLoc) {
1818
+ this.next = afterLoc;
1819
+ }
1820
+
1821
+ return ContinueSentinel;
1822
+ },
1823
+ finish: function finish(finallyLoc) {
1824
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1825
+ var entry = this.tryEntries[i];
1826
+
1827
+ if (entry.finallyLoc === finallyLoc) {
1828
+ this.complete(entry.completion, entry.afterLoc);
1838
1829
  resetTryEntry(entry);
1830
+ return ContinueSentinel;
1839
1831
  }
1840
- return thrown;
1841
1832
  }
1842
- }
1833
+ },
1834
+ "catch": function _catch(tryLoc) {
1835
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1836
+ var entry = this.tryEntries[i];
1843
1837
 
1844
- // The context.catch method must only be called with a location
1845
- // argument that corresponds to a known catch block.
1846
- throw new Error("illegal catch attempt");
1847
- },
1838
+ if (entry.tryLoc === tryLoc) {
1839
+ var record = entry.completion;
1848
1840
 
1849
- delegateYield: function(iterable, resultName, nextLoc) {
1850
- this.delegate = {
1851
- iterator: values(iterable),
1852
- resultName: resultName,
1853
- nextLoc: nextLoc
1854
- };
1841
+ if (record.type === "throw") {
1842
+ var thrown = record.arg;
1843
+ resetTryEntry(entry);
1844
+ }
1855
1845
 
1856
- if (this.method === "next") {
1857
- // Deliberately forget the last sent value so that we don't
1858
- // accidentally pass it on to the delegate.
1859
- this.arg = undefined$1;
1860
- }
1846
+ return thrown;
1847
+ }
1848
+ } // The context.catch method must only be called with a location
1849
+ // argument that corresponds to a known catch block.
1861
1850
 
1862
- return ContinueSentinel;
1863
- }
1864
- };
1865
1851
 
1866
- // Regardless of whether this script is executing as a CommonJS module
1867
- // or not, return the runtime object so that we can declare the variable
1868
- // regeneratorRuntime in the outer scope, which allows this module to be
1869
- // injected easily by `bin/regenerator --include-runtime script.js`.
1870
- return exports;
1852
+ throw new Error("illegal catch attempt");
1853
+ },
1854
+ delegateYield: function delegateYield(iterable, resultName, nextLoc) {
1855
+ this.delegate = {
1856
+ iterator: values(iterable),
1857
+ resultName: resultName,
1858
+ nextLoc: nextLoc
1859
+ };
1860
+
1861
+ if (this.method === "next") {
1862
+ // Deliberately forget the last sent value so that we don't
1863
+ // accidentally pass it on to the delegate.
1864
+ this.arg = undefined$1;
1865
+ }
1866
+
1867
+ return ContinueSentinel;
1868
+ }
1869
+ }; // Regardless of whether this script is executing as a CommonJS module
1870
+ // or not, return the runtime object so that we can declare the variable
1871
+ // regeneratorRuntime in the outer scope, which allows this module to be
1872
+ // injected easily by `bin/regenerator --include-runtime script.js`.
1871
1873
 
1872
- }(
1873
- // If this script is executing as a CommonJS module, use module.exports
1874
+ return exports;
1875
+ }( // If this script is executing as a CommonJS module, use module.exports
1874
1876
  // as the regeneratorRuntime namespace. Otherwise create a new empty
1875
1877
  // object. Either way, the resulting object will be used to initialize
1876
1878
  // the regeneratorRuntime variable at the top of this file.
1877
- module.exports
1878
- ));
1879
-
1880
- try {
1881
- regeneratorRuntime = runtime;
1882
- } catch (accidentalStrictMode) {
1883
- // This module should not be running in strict mode, so the above
1884
- // assignment should always work unless something is misconfigured. Just
1885
- // in case runtime.js accidentally runs in strict mode, in modern engines
1886
- // we can explicitly access globalThis. In older engines we can escape
1887
- // strict mode using a global Function call. This could conceivably fail
1888
- // if a Content Security Policy forbids using Function, but in that case
1889
- // the proper solution is to fix the accidental strict mode problem. If
1890
- // you've misconfigured your bundler to force strict mode and applied a
1891
- // CSP to forbid Function, and you're not willing to fix either of those
1892
- // problems, please detail your unique predicament in a GitHub issue.
1893
- if (typeof globalThis === "object") {
1894
- globalThis.regeneratorRuntime = runtime;
1895
- } else {
1896
- Function("r", "regeneratorRuntime = r")(runtime);
1879
+ module.exports );
1880
+
1881
+ try {
1882
+ regeneratorRuntime = runtime;
1883
+ } catch (accidentalStrictMode) {
1884
+ // This module should not be running in strict mode, so the above
1885
+ // assignment should always work unless something is misconfigured. Just
1886
+ // in case runtime.js accidentally runs in strict mode, in modern engines
1887
+ // we can explicitly access globalThis. In older engines we can escape
1888
+ // strict mode using a global Function call. This could conceivably fail
1889
+ // if a Content Security Policy forbids using Function, but in that case
1890
+ // the proper solution is to fix the accidental strict mode problem. If
1891
+ // you've misconfigured your bundler to force strict mode and applied a
1892
+ // CSP to forbid Function, and you're not willing to fix either of those
1893
+ // problems, please detail your unique predicament in a GitHub issue.
1894
+ if (typeof globalThis === "object") {
1895
+ globalThis.regeneratorRuntime = runtime;
1896
+ } else {
1897
+ Function("r", "regeneratorRuntime = r")(runtime);
1898
+ }
1897
1899
  }
1898
- }
1899
1900
  });
1900
1901
 
1901
1902
  /* eslint-disable you-dont-need-lodash-underscore/find */
@@ -2164,13 +2165,13 @@ function getWithEmbeddedEntityEvents(nodeType, sdk) {
2164
2165
  }
2165
2166
 
2166
2167
  var createEmbeddedEntityPlugin = function createEmbeddedEntityPlugin(nodeType, hotkey) {
2167
- return function (sdk) {
2168
+ return function (sdk, tracking) {
2168
2169
  return {
2169
2170
  key: nodeType,
2170
2171
  type: nodeType,
2171
2172
  isElement: true,
2172
2173
  isVoid: true,
2173
- component: LinkedEntityBlock,
2174
+ component: withLinkTracking(tracking, LinkedEntityBlock),
2174
2175
  options: {
2175
2176
  hotkey: hotkey
2176
2177
  },
@@ -2228,12 +2229,20 @@ function FetchingWrappedInlineEntryCard(props) {
2228
2229
  return entries[props.entryId];
2229
2230
  }, [entries, props.entryId]);
2230
2231
  var allContentTypes = props.sdk.space.getCachedContentTypes();
2232
+ var onEntityFetchComplete = props.onEntityFetchComplete;
2231
2233
  var contentType = React__default.useMemo(function () {
2232
2234
  if (!entry || entry === 'failed' || !allContentTypes) return undefined;
2233
2235
  return allContentTypes.find(function (contentType) {
2234
2236
  return contentType.sys.id === entry.sys.contentType.sys.id;
2235
2237
  });
2236
2238
  }, [allContentTypes, entry]);
2239
+ React__default.useEffect(function () {
2240
+ if (!entry) {
2241
+ return;
2242
+ }
2243
+
2244
+ onEntityFetchComplete == null ? void 0 : onEntityFetchComplete();
2245
+ }, [entry, onEntityFetchComplete]);
2237
2246
  var contentTypeName = contentType ? contentType.name : '';
2238
2247
  var title = React__default.useMemo(function () {
2239
2248
  return getEntryTitle({
@@ -2329,12 +2338,10 @@ var styles$6 = {
2329
2338
  marginRight: '10px'
2330
2339
  }),
2331
2340
  root: /*#__PURE__*/emotion.css({
2332
- margin: '0 1px',
2341
+ display: 'inline-block',
2342
+ margin: "0 " + tokens.spacing2Xs,
2333
2343
  fontSize: 'inherit',
2334
2344
  span: {
2335
- webkitUserSelect: 'none',
2336
- mozUserSelect: 'none',
2337
- msUserSelect: 'none',
2338
2345
  userSelect: 'none'
2339
2346
  }
2340
2347
  })
@@ -2377,7 +2384,8 @@ function EmbeddedEntityInline(props) {
2377
2384
  isSelected: isSelected,
2378
2385
  isDisabled: isDisabled,
2379
2386
  onRemove: handleRemoveClick,
2380
- onEdit: handleEditClick
2387
+ onEdit: handleEditClick,
2388
+ onEntityFetchComplete: props.onEntityFetchComplete
2381
2389
  })), props.children);
2382
2390
  }
2383
2391
 
@@ -2487,7 +2495,7 @@ function ToolbarEmbeddedEntityInlineButton(props) {
2487
2495
  className: "rich-text__embedded-entry-list-icon " + styles$6.icon
2488
2496
  }), /*#__PURE__*/React.createElement("span", null, "Inline entry")));
2489
2497
  }
2490
- function createEmbeddedEntityInlinePlugin(sdk) {
2498
+ function createEmbeddedEntityInlinePlugin(sdk, tracking) {
2491
2499
  var htmlAttributeName = 'data-embedded-entity-inline-id';
2492
2500
  return {
2493
2501
  key: Contentful.INLINES.EMBEDDED_ENTRY,
@@ -2495,7 +2503,7 @@ function createEmbeddedEntityInlinePlugin(sdk) {
2495
2503
  isElement: true,
2496
2504
  isInline: true,
2497
2505
  isVoid: true,
2498
- component: EmbeddedEntityInline,
2506
+ component: withLinkTracking(tracking, EmbeddedEntityInline),
2499
2507
  options: {
2500
2508
  hotkey: 'mod+shift+2'
2501
2509
  },
@@ -2609,14 +2617,25 @@ function ToolbarHeadingButton(props) {
2609
2617
  unwrapFromRoot(editor);
2610
2618
  }
2611
2619
 
2620
+ var prevOnChange = editor.onChange;
2621
+ /*
2622
+ The focus might happen at point in time when
2623
+ `toggleNodeType` changes aren't rendered yet, causing the browser
2624
+ to place the cursor at the start of the text.
2625
+ We wait for the change event before focusing
2626
+ the editor again. This ensures the cursor is back at the previous
2627
+ position.*/
2628
+
2629
+ editor.onChange = function () {
2630
+ Slate.ReactEditor.focus(editor);
2631
+ editor.onChange = prevOnChange;
2632
+ prevOnChange.apply(void 0, arguments);
2633
+ };
2634
+
2612
2635
  plateCore.toggleNodeType(editor, {
2613
2636
  activeType: type,
2614
2637
  inactiveType: type
2615
- }); // TODO: Figure out why focus only works with timeout here.
2616
-
2617
- setTimeout(function () {
2618
- Slate.ReactEditor.focus(editor);
2619
- }, 0);
2638
+ });
2620
2639
  };
2621
2640
  }
2622
2641
 
@@ -2746,16 +2765,6 @@ var createHeadingPlugin = function createHeadingPlugin() {
2746
2765
  allow: Contentful.HEADINGS
2747
2766
  }
2748
2767
  }],
2749
- exitBreak: [// Pressing ENTER at the start or end of a heading text inserts a
2750
- // normal paragraph
2751
- {
2752
- hotkey: 'enter',
2753
- query: {
2754
- allow: Contentful.HEADINGS,
2755
- end: true,
2756
- start: true
2757
- }
2758
- }],
2759
2768
  normalizer: [{
2760
2769
  match: {
2761
2770
  type: Contentful.HEADINGS
@@ -2766,6 +2775,31 @@ var createHeadingPlugin = function createHeadingPlugin() {
2766
2775
  },
2767
2776
  transform: (_transform = {}, _transform[Contentful.BLOCKS.PARAGRAPH] = transformUnwrap, _transform["default"] = transformLift, _transform)
2768
2777
  }],
2778
+ then: function then(editor) {
2779
+ return {
2780
+ exitBreak: [// Pressing ENTER at the start or end of a heading text inserts a
2781
+ // normal paragraph.
2782
+ {
2783
+ hotkey: 'enter',
2784
+ query: {
2785
+ allow: Contentful.HEADINGS,
2786
+ end: true,
2787
+ start: true,
2788
+ // Exclude headings inside lists as it interferes with the list's
2789
+ // insertBreak implementation
2790
+ filter: function filter(_ref2) {
2791
+ var path = _ref2[1];
2792
+ return !plateCore.getAbove(editor, {
2793
+ at: path,
2794
+ match: {
2795
+ type: Contentful.BLOCKS.LIST_ITEM
2796
+ }
2797
+ });
2798
+ }
2799
+ }
2800
+ }]
2801
+ };
2802
+ },
2769
2803
  plugins: Contentful.HEADINGS.map(function (nodeType, idx) {
2770
2804
  var level = idx + 1;
2771
2805
  var tagName = "h" + level;
@@ -3469,6 +3503,13 @@ function EntityHyperlink(props) {
3469
3503
  var isReadOnly = Slate.useReadOnly();
3470
3504
  var sdk = useSdkContext();
3471
3505
  var target = props.element.data.target;
3506
+ var onEntityFetchComplete = props.onEntityFetchComplete;
3507
+ React.useEffect(function () {
3508
+ // The real entity loading happens in the tooltip
3509
+ // Since that is deferred the link is considered rendered as soon
3510
+ // the component mounts (link text displayed)
3511
+ onEntityFetchComplete == null ? void 0 : onEntityFetchComplete();
3512
+ }, [onEntityFetchComplete]);
3472
3513
  if (!target) return null;
3473
3514
 
3474
3515
  function handleClick(event) {
@@ -3599,7 +3640,7 @@ var getNodeOfType = function getNodeOfType(type) {
3599
3640
  };
3600
3641
  };
3601
3642
 
3602
- var createHyperlinkPlugin = function createHyperlinkPlugin(sdk) {
3643
+ var createHyperlinkPlugin = function createHyperlinkPlugin(sdk, tracking) {
3603
3644
  var common = {
3604
3645
  isElement: true,
3605
3646
  isInline: true
@@ -3630,7 +3671,7 @@ var createHyperlinkPlugin = function createHyperlinkPlugin(sdk) {
3630
3671
  _extends({}, common, {
3631
3672
  key: Contentful.INLINES.ENTRY_HYPERLINK,
3632
3673
  type: Contentful.INLINES.ENTRY_HYPERLINK,
3633
- component: EntityHyperlink,
3674
+ component: withLinkTracking(tracking, EntityHyperlink),
3634
3675
  deserializeHtml: {
3635
3676
  rules: [{
3636
3677
  validNodeName: ['A']
@@ -3644,7 +3685,7 @@ var createHyperlinkPlugin = function createHyperlinkPlugin(sdk) {
3644
3685
  _extends({}, common, {
3645
3686
  key: Contentful.INLINES.ASSET_HYPERLINK,
3646
3687
  type: Contentful.INLINES.ASSET_HYPERLINK,
3647
- component: EntityHyperlink,
3688
+ component: withLinkTracking(tracking, EntityHyperlink),
3648
3689
  deserializeHtml: {
3649
3690
  rules: [{
3650
3691
  validNodeName: ['A']
@@ -3666,7 +3707,7 @@ var createHyperlinkPlugin = function createHyperlinkPlugin(sdk) {
3666
3707
  };
3667
3708
 
3668
3709
  var _templateObject$4, _templateObject2$3, _templateObject3$3, _styles;
3669
- var baseStyle = /*#__PURE__*/emotion.css(_templateObject$4 || (_templateObject$4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n padding: 0;\n margin: 0 0 1.25rem 1.25rem;\n div:first-child {\n margin: 0;\n line-height: ", ";\n }\n"])), tokens.lineHeightDefault);
3710
+ var baseStyle = /*#__PURE__*/emotion.css(_templateObject$4 || (_templateObject$4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n padding: 0;\n margin: 0 0 1.25rem 1.25rem;\n\n div:first-child {\n margin: 0;\n line-height: ", ";\n }\n"])), tokens.lineHeightDefault);
3670
3711
  var styles$d = (_styles = {}, _styles[Contentful.BLOCKS.UL_LIST] = /*#__PURE__*/emotion.css(_templateObject2$3 || (_templateObject2$3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n list-style-type: disc;\n ul {\n list-style-type: circle;\n ul {\n list-style-type: square;\n }\n }\n "]))), _styles[Contentful.BLOCKS.OL_LIST] = /*#__PURE__*/emotion.css(_templateObject3$3 || (_templateObject3$3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n list-style-type: decimal;\n ol {\n list-style-type: upper-alpha;\n ol {\n list-style-type: lower-roman;\n ol {\n list-style-type: lower-alpha;\n }\n }\n }\n "]))), _styles);
3671
3712
 
3672
3713
  function createList(Tag, block) {
@@ -3681,7 +3722,7 @@ var ListUL = /*#__PURE__*/createList('ul', Contentful.BLOCKS.UL_LIST);
3681
3722
  var ListOL = /*#__PURE__*/createList('ol', Contentful.BLOCKS.OL_LIST);
3682
3723
 
3683
3724
  var _templateObject$5;
3684
- var style = /*#__PURE__*/emotion.css(_templateObject$5 || (_templateObject$5 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin: 0;\n list-style: inherit;\n ol,\n ul {\n margin: 0 0 0 ", ";\n }\n"])), tokens.spacingL);
3725
+ var style = /*#__PURE__*/emotion.css(_templateObject$5 || (_templateObject$5 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin: 0;\n list-style: inherit;\n margin-top: ", ";\n\n ol,\n ul {\n margin: 0 0 0 ", ";\n }\n"])), tokens.spacingXs, tokens.spacingL);
3685
3726
  function ListItem(props) {
3686
3727
  return /*#__PURE__*/React.createElement("li", Object.assign({}, props.attributes, {
3687
3728
  className: style
@@ -3749,66 +3790,285 @@ var insertParagraphAsChild = function insertParagraphAsChild(editor, _ref5) {
3749
3790
  };
3750
3791
 
3751
3792
  /**
3752
- * A copy of Plate's list plugin with a few adjustments
3753
- * to support pasting any element
3793
+ * Build a new list item node while preserving marks
3754
3794
  */
3755
- var getListInsertFragment = function getListInsertFragment(editor) {
3756
- var insertFragment = editor.insertFragment;
3757
- var li = plateCore.getPlugin(editor, plateList.ELEMENT_LI);
3758
- var ul = plateCore.getPlugin(editor, plateList.ELEMENT_UL);
3759
- var ol = plateCore.getPlugin(editor, plateList.ELEMENT_OL);
3760
3795
 
3761
- var isListRoot = function isListRoot(node) {
3762
- return [ul.type, ol.type].includes(node.type);
3796
+ var emptyListItemNode = function emptyListItemNode(editor, withChildren) {
3797
+ if (withChildren === void 0) {
3798
+ withChildren = false;
3799
+ }
3800
+
3801
+ var children = [];
3802
+
3803
+ if (withChildren) {
3804
+ var marks = slate.Editor.marks(editor) || {};
3805
+ children = [{
3806
+ type: Contentful.BLOCKS.PARAGRAPH,
3807
+ data: {},
3808
+ children: [_extends({
3809
+ text: ''
3810
+ }, marks)]
3811
+ }];
3812
+ }
3813
+
3814
+ return {
3815
+ type: Contentful.BLOCKS.LIST_ITEM,
3816
+ data: {},
3817
+ children: children
3763
3818
  };
3819
+ };
3820
+ /**
3821
+ * Insert list item if selection is in li>p.
3822
+ */
3764
3823
 
3765
- var getFirstAncestorOfType = function getFirstAncestorOfType(root, entry, _ref) {
3766
- var type = _ref.type;
3767
- var ancestor = slate.Path.parent(entry[1]);
3768
3824
 
3769
- while (slate.Node.get(root, ancestor).type !== type) {
3770
- ancestor = slate.Path.parent(ancestor);
3825
+ var insertListItem = function insertListItem(editor) {
3826
+ if (!editor.selection) {
3827
+ return false;
3828
+ } // Naming it paragraph for simplicity but can be a heading as well
3829
+
3830
+
3831
+ var paragraph = plateCore.getAbove(editor, {
3832
+ match: {
3833
+ type: Contentful.TEXT_CONTAINERS
3771
3834
  }
3835
+ });
3772
3836
 
3773
- return [slate.Node.get(root, ancestor), ancestor];
3774
- };
3837
+ if (!paragraph) {
3838
+ return false;
3839
+ }
3840
+
3841
+ var paragraphPath = paragraph[1];
3842
+ var listItem = plateCore.getParent(editor, paragraphPath);
3843
+
3844
+ if (!listItem) {
3845
+ return false;
3846
+ }
3847
+
3848
+ var listItemNode = listItem[0],
3849
+ listItemPath = listItem[1];
3850
+
3851
+ if (listItemNode.type !== Contentful.BLOCKS.LIST_ITEM) {
3852
+ return false;
3853
+ } // We are in a li>p (or heading)
3854
+
3855
+
3856
+ slate.Editor.withoutNormalizing(editor, function () {
3857
+ if (!editor.selection) {
3858
+ return;
3859
+ } // Check the cursor position in the current paragraph
3860
+
3861
+
3862
+ var isAtStart = plateCore.isSelectionAtBlockStart(editor);
3863
+ var isAtEnd = plateCore.isSelectionAtBlockEnd(editor);
3864
+ var isAtStartOfListItem = isAtStart && plateCore.isFirstChild(paragraphPath);
3865
+ var shouldSplit = !isAtStart && !isAtEnd; // Split the current paragraph content if necessary
3866
+
3867
+ if (shouldSplit) {
3868
+ slate.Transforms.splitNodes(editor);
3869
+ } // Insert the new li
3870
+
3871
+
3872
+ var newListItemPath = isAtStartOfListItem ? listItemPath : slate.Path.next(listItemPath);
3873
+ plateCore.insertNodes(editor, // Add an empty paragraph to the new li if We will not move some
3874
+ // paragraphs over there.
3875
+ emptyListItemNode(editor, !shouldSplit), {
3876
+ at: newListItemPath
3877
+ }); // Move children *after* selection to the new li
3878
+
3879
+ var fromPath = isAtStart ? paragraphPath : slate.Path.next(paragraphPath);
3880
+ var fromStartIndex = fromPath[fromPath.length - 1] || 0; // On split we don't add paragraph to the new li so we move
3881
+ // content to the very beginning. Otherwise, account for the empty
3882
+ // paragraph at the beginning by moving the content after
3883
+
3884
+ var toPath = newListItemPath.concat([shouldSplit ? 0 : 1]);
3885
+
3886
+ if (!isAtStartOfListItem) {
3887
+ plateCore.moveChildren(editor, {
3888
+ at: listItemPath,
3889
+ to: toPath,
3890
+ fromStartIndex: fromStartIndex
3891
+ });
3892
+ } // Move cursor to the start of the new li
3893
+
3894
+
3895
+ slate.Transforms.select(editor, newListItemPath);
3896
+ slate.Transforms.collapse(editor, {
3897
+ edge: 'start'
3898
+ });
3899
+ }); // Returning True skips processing other editor.insertBreak handlers
3900
+
3901
+ return true;
3902
+ };
3903
+
3904
+ /**
3905
+ * Credit: Copied & modified version from Plate's list plugin to support
3906
+ * list items with multiple children.
3907
+ *
3908
+ * See: https://github.com/udecode/plate/blob/main/packages/nodes/list
3909
+ */
3910
+
3911
+ var listBreak = function listBreak(editor) {
3912
+ if (!editor.selection) return false;
3913
+ var res = plateList.getListItemEntry(editor, {});
3914
+ var moved; // If selection is in a li
3915
+
3916
+ if (res) {
3917
+ var list = res.list,
3918
+ listItem = res.listItem;
3919
+ var childNode = listItem[0].children[0]; // If selected li is empty, move it up.
3920
+
3921
+ if (plateCore.isBlockAboveEmpty(editor) && listItem[0].children.length === 1 && Contentful.TEXT_CONTAINERS.includes(childNode.type)) {
3922
+ moved = plateList.moveListItemUp(editor, {
3923
+ list: list,
3924
+ listItem: listItem
3925
+ });
3926
+ if (moved) return true;
3927
+ }
3928
+ }
3929
+
3930
+ var didReset = plateResetNode.onKeyDownResetNode(editor, plateCore.mockPlugin({
3931
+ options: {
3932
+ rules: [{
3933
+ types: [plateCore.getPluginType(editor, plateList.ELEMENT_LI)],
3934
+ defaultType: plateCore.getPluginType(editor, plateCore.ELEMENT_DEFAULT),
3935
+ predicate: function predicate() {
3936
+ return !moved && plateCore.isBlockAboveEmpty(editor);
3937
+ },
3938
+ onReset: function onReset(_editor) {
3939
+ return plateList.unwrapList(_editor);
3940
+ }
3941
+ }]
3942
+ }
3943
+ }))(plateResetNode.SIMULATE_BACKSPACE);
3944
+
3945
+ if (didReset) {
3946
+ return true;
3947
+ }
3775
3948
  /**
3776
- * Removes the "empty" leading lis. Empty in this context means lis only with other lis as children.
3777
- *
3778
- * @returns If argument is not a list root, returns it, otherwise returns ul[] or li[].
3949
+ * If selection is in li > p, insert li.
3779
3950
  */
3780
3951
 
3781
3952
 
3782
- var trimList = function trimList(listRoot) {
3783
- if (!isListRoot(listRoot)) {
3784
- return [listRoot];
3785
- }
3953
+ if (!moved) {
3954
+ var inserted = insertListItem(editor);
3955
+ if (inserted) return true;
3956
+ }
3786
3957
 
3787
- var textEntries = Array.from(slate.Node.texts(listRoot));
3788
- var commonAncestorEntry = textEntries.reduce(function (commonAncestor, textEntry) {
3789
- return slate.Path.isAncestor(commonAncestor[1], textEntry[1]) ? commonAncestor : slate.Node.common(listRoot, textEntry[1], commonAncestor[1]);
3790
- }, // any list item would do, we grab the first one
3791
- getFirstAncestorOfType(listRoot, textEntries[0], li));
3792
- return isListRoot(commonAncestorEntry[0]) ? commonAncestorEntry[0].children : [commonAncestorEntry[0]];
3958
+ return false;
3959
+ };
3960
+
3961
+ var insertListBreak = function insertListBreak(editor) {
3962
+ var insertBreak = editor.insertBreak;
3963
+ return function () {
3964
+ if (listBreak(editor)) return;
3965
+ insertBreak();
3793
3966
  };
3967
+ };
3968
+
3969
+ /**
3970
+ * Credit: Modified version of Plate's list plugin
3971
+ * See: https://github.com/udecode/plate/blob/main/packages/nodes/list
3972
+ */
3973
+
3974
+ var getFirstAncestorOfType = function getFirstAncestorOfType(root, entry) {
3975
+ var ancestor = slate.Path.parent(entry[1]);
3976
+
3977
+ while (slate.Node.get(root, ancestor).type !== Contentful.BLOCKS.LIST_ITEM) {
3978
+ ancestor = slate.Path.parent(ancestor);
3979
+ }
3980
+
3981
+ return [slate.Node.get(root, ancestor), ancestor];
3982
+ };
3983
+
3984
+ var isListRoot = function isListRoot(node) {
3985
+ return [Contentful.BLOCKS.UL_LIST, Contentful.BLOCKS.OL_LIST].includes(node.type);
3986
+ };
3987
+ /**
3988
+ * Removes the "empty" leading lis. Empty in this context means lis only with other lis as children.
3989
+ *
3990
+ * @returns If argument is not a list root, returns it, otherwise returns ul[] or li[].
3991
+ */
3992
+
3993
+
3994
+ var trimList = function trimList(listRoot) {
3995
+ if (!isListRoot(listRoot)) {
3996
+ return [listRoot];
3997
+ }
3998
+
3999
+ var textEntries = Array.from(slate.Node.texts(listRoot));
4000
+ var commonAncestorEntry = textEntries.reduce(function (commonAncestor, textEntry) {
4001
+ return slate.Path.isAncestor(commonAncestor[1], textEntry[1]) ? commonAncestor : slate.Node.common(listRoot, textEntry[1], commonAncestor[1]);
4002
+ }, // any list item would do, we grab the first one
4003
+ getFirstAncestorOfType(listRoot, textEntries[0]));
4004
+ return isListRoot(commonAncestorEntry[0]) ? commonAncestorEntry[0].children : [commonAncestorEntry[0]];
4005
+ };
4006
+ /**
4007
+ * Removes leading li when pasting a single li with a single child.
4008
+ */
3794
4009
 
4010
+
4011
+ var trimLiWrapper = function trimLiWrapper(nodes) {
4012
+ if (nodes.length !== 1) {
4013
+ return nodes;
4014
+ }
4015
+
4016
+ var node = nodes[0];
4017
+
4018
+ if (node.type !== Contentful.BLOCKS.LIST_ITEM || node.children.length !== 1) {
4019
+ return nodes;
4020
+ }
4021
+
4022
+ return node.children;
4023
+ };
4024
+
4025
+ var unwrapTextContainerAtStart = function unwrapTextContainerAtStart(nodes) {
4026
+ var node = nodes[0];
4027
+
4028
+ if (Contentful.TEXT_CONTAINERS.includes(node.type)) {
4029
+ return [].concat(node.children, nodes.slice(1));
4030
+ }
4031
+
4032
+ return nodes;
4033
+ };
4034
+
4035
+ var insertListFragment = function insertListFragment(editor) {
4036
+ var insertFragment = editor.insertFragment;
3795
4037
  return function (fragment) {
4038
+ if (!editor.selection) {
4039
+ return;
4040
+ }
4041
+
3796
4042
  var liEntry = plateCore.findNode(editor, {
3797
4043
  match: {
3798
- type: li.type
4044
+ type: Contentful.BLOCKS.LIST_ITEM
3799
4045
  },
3800
4046
  mode: 'lowest'
3801
4047
  });
3802
4048
 
3803
4049
  if (liEntry) {
3804
- var liPath = liEntry[1]; // FIXME: this is a temporarily workaround and needs a follow-up to properly
3805
- // non-text elements
3806
-
3807
- var nodes = fragment.flatMap(function (node) {
4050
+ var nodes = unwrapTextContainerAtStart(trimLiWrapper(fragment.flatMap(function (node) {
3808
4051
  return trimList(node);
4052
+ })));
4053
+ var firstBlockIndex = nodes.findIndex(function (node) {
4054
+ return slate.Editor.isBlock(editor, node);
3809
4055
  });
3810
- return slate.Transforms.insertNodes(editor, nodes, {
3811
- at: editor.selection || slate.Path.next(liPath),
4056
+
4057
+ if (firstBlockIndex < 0) {
4058
+ firstBlockIndex = nodes.length;
4059
+ }
4060
+
4061
+ var inlines = nodes.slice(0, firstBlockIndex);
4062
+ var blocks = nodes.slice(firstBlockIndex); // Two calls to insertNodes are required here. Otherwise, all blocks
4063
+ // after a text or inline element occurrence will be unwrapped for
4064
+ // some reason.
4065
+
4066
+ slate.Transforms.insertNodes(editor, inlines, {
4067
+ at: editor.selection,
4068
+ select: true
4069
+ });
4070
+ return slate.Transforms.insertNodes(editor, blocks, {
4071
+ at: editor.selection,
3812
4072
  select: true
3813
4073
  });
3814
4074
  }
@@ -3820,18 +4080,37 @@ var getListInsertFragment = function getListInsertFragment(editor) {
3820
4080
  };
3821
4081
  };
3822
4082
 
3823
- var options = {
3824
- validLiChildrenTypes: Contentful.LIST_ITEM_BLOCKS
3825
- };
3826
- var withList = function withList(editor, plugin) {
3827
- var insertFragment = editor.insertFragment;
3828
- plateList.withList(editor, _extends({}, plugin, {
3829
- options: options
3830
- })); // Reverts any overrides to insertFragment
4083
+ /**
4084
+ * Credit: Modified version of Plate's list plugin
4085
+ * See: https://github.com/udecode/plate/blob/main/packages/nodes/list
4086
+ */
4087
+ var validLiChildrenTypes = Contentful.LIST_ITEM_BLOCKS;
4088
+ var withList = function withList(editor) {
4089
+ var deleteBackward = editor.deleteBackward,
4090
+ deleteForward = editor.deleteForward,
4091
+ deleteFragment = editor.deleteFragment;
4092
+
4093
+ editor.deleteBackward = function (unit) {
4094
+ if (plateList.deleteBackwardList(editor, unit)) return;
4095
+ deleteBackward(unit);
4096
+ };
3831
4097
 
3832
- editor.insertFragment = insertFragment; // Use our custom getListInsertFragment
4098
+ editor.deleteForward = function (unit) {
4099
+ if (plateList.deleteForwardList(editor)) return;
4100
+ deleteForward(unit);
4101
+ };
3833
4102
 
3834
- editor.insertFragment = getListInsertFragment(editor);
4103
+ editor.deleteFragment = function () {
4104
+ if (plateList.deleteFragmentList(editor)) return;
4105
+ deleteFragment();
4106
+ };
4107
+
4108
+ editor.insertBreak = insertListBreak(editor);
4109
+ editor.insertFragment = insertListFragment(editor); // TODO: replace with Normalizer rules
4110
+
4111
+ editor.normalizeNode = plateList.normalizeList(editor, {
4112
+ validLiChildrenTypes: validLiChildrenTypes
4113
+ });
3835
4114
  return editor;
3836
4115
  };
3837
4116
 
@@ -5221,22 +5500,52 @@ function createTextPlugin() {
5221
5500
  return {
5222
5501
  key: 'TextPlugin',
5223
5502
  withOverrides: function withOverrides(editor) {
5224
- var deleteForward = editor.deleteForward; // When pressing delete instead of backspace
5503
+ // Reverts the change made upstream that caused the cursor
5504
+ // to be trapped inside inline elements.
5505
+ //
5506
+ // Reverts https://github.com/ianstormtaylor/slate/pull/4578/
5507
+ // Related https://github.com/ianstormtaylor/slate/issues/4704
5508
+ var insertText = editor.insertText;
5509
+
5510
+ editor.insertText = function (text) {
5511
+ var selection = editor.selection; // If the cursor is at the end of an inline, move it outside
5512
+ // before inserting
5513
+
5514
+ if (selection && slate.Range.isCollapsed(selection)) {
5515
+ var _Editor$above;
5516
+
5517
+ var inlinePath = (_Editor$above = slate.Editor.above(editor, {
5518
+ match: function match(n) {
5519
+ return slate.Editor.isInline(editor, n);
5520
+ },
5521
+ mode: 'highest'
5522
+ })) == null ? void 0 : _Editor$above[1];
5523
+
5524
+ if (inlinePath && slate.Editor.isEnd(editor, selection.anchor, inlinePath)) {
5525
+ var point = slate.Editor.after(editor, inlinePath);
5526
+ slate.Transforms.setSelection(editor, {
5527
+ anchor: point,
5528
+ focus: point
5529
+ });
5530
+ }
5531
+ }
5225
5532
 
5226
- editor.deleteForward = function (unit) {
5227
- var _editor$selection;
5533
+ return insertText(text);
5534
+ }; // When pressing delete instead of backspace
5535
+
5536
+
5537
+ var deleteForward = editor.deleteForward;
5228
5538
 
5229
- var _Editor$nodes = slate.Editor.nodes(editor, {
5230
- at: (_editor$selection = editor.selection) == null ? void 0 : _editor$selection.focus.path,
5231
- match: function match(node) {
5232
- return Contentful.TEXT_CONTAINERS.includes(node.type);
5539
+ editor.deleteForward = function (unit) {
5540
+ var entry = plateCore.getAbove(editor, {
5541
+ match: {
5542
+ type: Contentful.TEXT_CONTAINERS
5233
5543
  }
5234
- }),
5235
- nodes = _Editor$nodes[0];
5544
+ });
5236
5545
 
5237
- if (nodes) {
5238
- var paragraphOrHeading = nodes[0],
5239
- path = nodes[1];
5546
+ if (entry) {
5547
+ var paragraphOrHeading = entry[0],
5548
+ path = entry[1];
5240
5549
  var isTextEmpty = plateCore.isAncestorEmpty(editor, paragraphOrHeading); // We ignore paragraphs/headings that are children of ul, ol, blockquote, tables, etc
5241
5550
 
5242
5551
  var isRootLevel = path.length === 1;
@@ -5293,8 +5602,9 @@ var transformVoid = function transformVoid(editor, _ref) {
5293
5602
  var createVoidsPlugin = function createVoidsPlugin() {
5294
5603
  return {
5295
5604
  key: 'VoidsPlugin',
5296
- exitBreak: [// Can insert before first void block
5297
- {
5605
+ exitBreak: [{
5606
+ // Inserts a new paragraph *before* a void element if it's the very first
5607
+ // node on the editor
5298
5608
  hotkey: 'enter',
5299
5609
  before: true,
5300
5610
  query: {
@@ -5304,8 +5614,8 @@ var createVoidsPlugin = function createVoidsPlugin() {
5304
5614
  return isRootLevel(path) && plateCore.isFirstChild(path) && !!node.isVoid;
5305
5615
  }
5306
5616
  }
5307
- }, // Can insert after a void block
5308
- {
5617
+ }, {
5618
+ // Inserts a new paragraph on enter when a void element is focused
5309
5619
  hotkey: 'enter',
5310
5620
  query: {
5311
5621
  filter: function filter(_ref2) {
@@ -5340,8 +5650,8 @@ var getPlugins = function getPlugins(sdk, tracking) {
5340
5650
  return [// AST must come after the HTML deserializer
5341
5651
  plateCore.createDeserializeHtmlPlugin(), plateCore.createDeserializeAstPlugin(), plateSerializerDocx.createDeserializeDocxPlugin(), // Global shortcuts
5342
5652
  createDragAndDropPlugin(), // Block Elements
5343
- createParagraphPlugin(), createListPlugin(), createHrPlugin(), createHeadingPlugin(), createQuotePlugin(), createTablePlugin(tracking), createEmbeddedEntryBlockPlugin(sdk), createEmbeddedAssetBlockPlugin(sdk), // Inline elements
5344
- createHyperlinkPlugin(sdk), createEmbeddedEntityInlinePlugin(sdk), // Marks
5653
+ createParagraphPlugin(), createListPlugin(), createHrPlugin(), createHeadingPlugin(), createQuotePlugin(), createTablePlugin(tracking), createEmbeddedEntryBlockPlugin(sdk, tracking), createEmbeddedAssetBlockPlugin(sdk, tracking), // Inline elements
5654
+ createHyperlinkPlugin(sdk, tracking), createEmbeddedEntityInlinePlugin(sdk, tracking), // Marks
5345
5655
  createMarksPlugin(), // Other
5346
5656
  createTrailingParagraphPlugin(), createTextPlugin(), createVoidsPlugin(), createSelectOnBackspacePlugin(), // Pasting content from other sources
5347
5657
  createPasteHTMLPlugin(), // These plugins drive their configurations from the list of plugins
@@ -5612,13 +5922,9 @@ var StickyToolbarWrapper = function StickyToolbarWrapper(_ref) {
5612
5922
  var _excluded = ["sdk", "isInitiallyDisabled", "onAction"];
5613
5923
  var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
5614
5924
  var tracking = useTrackingContext();
5615
- var docFromAdapter = contentfulSlatejsAdapter.toSlatejsDocument({
5616
- document: props.value || Contentful.EMPTY_DOCUMENT,
5617
- schema: schema
5618
- });
5619
- var doc = sanitizeIncomingSlateDoc(docFromAdapter);
5925
+ var editor = useContentfulEditor();
5620
5926
 
5621
- var _useState = React.useState(doc),
5927
+ var _useState = React.useState([]),
5622
5928
  value = _useState[0],
5623
5929
  setValue = _useState[1];
5624
5930
 
@@ -5628,12 +5934,33 @@ var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
5628
5934
  var plugins = React__default.useMemo(function () {
5629
5935
  return getPlugins(props.sdk, tracking);
5630
5936
  }, [props.sdk, tracking]);
5937
+ React__default.useEffect(function () {
5938
+ if (!editor) {
5939
+ return;
5940
+ }
5941
+
5942
+ var docFromAdapter = contentfulSlatejsAdapter.toSlatejsDocument({
5943
+ document: props.value || Contentful.EMPTY_DOCUMENT,
5944
+ schema: schema
5945
+ });
5946
+ var doc = sanitizeIncomingSlateDoc(docFromAdapter); // Slate throws an error if the value on the initial render is invalid
5947
+ // so we directly set the value on the editor in order
5948
+ // to be able to trigger normalization on the initial value before rendering
5949
+ // TODO: use https://plate.udecode.io/docs/Plate#normalizeinitialvalue when working
5950
+
5951
+ editor.children = doc;
5952
+ slate.Editor.normalize(editor, {
5953
+ force: true
5954
+ }); // We set the value so that the rendering can take over from here
5955
+
5956
+ setValue(editor.children);
5957
+ }, [props.value, editor]);
5631
5958
  return /*#__PURE__*/React__default.createElement("div", {
5632
5959
  className: styles$j.root,
5633
5960
  "data-test-id": "rich-text-editor"
5634
5961
  }, /*#__PURE__*/React__default.createElement(plateCore.Plate, {
5635
5962
  id: getContentfulEditorId(props.sdk),
5636
- initialValue: value,
5963
+ value: value,
5637
5964
  plugins: plugins,
5638
5965
  disableCorePlugins: disableCorePlugins,
5639
5966
  editableProps: {