@contentful/field-editor-rich-text 2.0.0-next.16 → 2.0.0-next.19

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.
@@ -254,25 +254,29 @@ function getContentfulEditorId(sdk) {
254
254
  }
255
255
  var editorContext = /*#__PURE__*/React.createContext('');
256
256
  var ContentfulEditorIdProvider = editorContext.Provider;
257
- function useContentfulEditorId() {
258
- var id = React.useContext(editorContext);
257
+ function useContentfulEditorId(id) {
258
+ var contextId = React.useContext(editorContext);
259
259
 
260
- if (!id) {
260
+ if (id) {
261
+ return id;
262
+ }
263
+
264
+ if (!contextId) {
261
265
  throw new Error('could not find editor id. Please ensure the component is wrapped in <ContentfulEditorIdProvider> ');
262
266
  }
263
267
 
264
- return id;
268
+ return contextId;
265
269
  } // This hook re-renders when the value changes
266
270
  // Use case: Toolbar icons, for example
267
271
 
268
- function useContentfulEditor() {
269
- var editorId = useContentfulEditorId();
272
+ function useContentfulEditor(id) {
273
+ var editorId = useContentfulEditorId(id);
270
274
  var editor = plateCore.usePlateEditorState(editorId);
271
275
  return editor;
272
276
  } // This doesn't re-render when the value changes
273
277
 
274
- function useContentfulEditorRef() {
275
- var editorId = useContentfulEditorId();
278
+ function useContentfulEditorRef(id) {
279
+ var editorId = useContentfulEditorId(id);
276
280
  var editor = plateCore.usePlateEditorRef(editorId);
277
281
  return editor;
278
282
  }
@@ -421,6 +425,23 @@ function moveToTheNextLine(editor) {
421
425
  unit: 'line'
422
426
  });
423
427
  }
428
+ function moveToTheNextChar(editor) {
429
+ slate.Transforms.move(editor, {
430
+ distance: 1,
431
+ unit: 'character'
432
+ });
433
+ }
434
+ function insertEmptyParagraph(editor) {
435
+ var emptyParagraph = {
436
+ type: Contentful.BLOCKS.PARAGRAPH,
437
+ children: [{
438
+ text: ''
439
+ }],
440
+ data: {},
441
+ isVoid: false
442
+ };
443
+ slate.Transforms.insertNodes(editor, emptyParagraph);
444
+ }
424
445
  function getElementFromCurrentSelection(editor) {
425
446
  if (!editor.selection) return [];
426
447
  return Array.from(slate.Editor.nodes(editor, {
@@ -607,6 +628,13 @@ var focus = function focus(editor) {
607
628
  }, 0);
608
629
  }
609
630
  };
631
+ function toggleElement(editor, options, editorOptions) {
632
+ plateCore.toggleNodeType(editor, options, editorOptions); // We must reset `data` from one element to another
633
+
634
+ slate.Transforms.setNodes(editor, {
635
+ data: {}
636
+ });
637
+ }
610
638
 
611
639
  function withLinkTracking(Component) {
612
640
  return function ComponentWithTracking(props) {
@@ -1065,197 +1093,201 @@ function createCommonjsModule(fn, module) {
1065
1093
  return module = { exports: {} }, fn(module, module.exports), module.exports;
1066
1094
  }
1067
1095
 
1068
- var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
1069
- /**
1070
- * Copyright (c) 2014-present, Facebook, Inc.
1071
- *
1072
- * This source code is licensed under the MIT license found in the
1073
- * LICENSE file in the root directory of this source tree.
1074
- */
1075
- var runtime = function (exports) {
1076
-
1077
- var Op = Object.prototype;
1078
- var hasOwn = Op.hasOwnProperty;
1079
- var undefined$1; // More compressible than void 0.
1080
-
1081
- var $Symbol = typeof Symbol === "function" ? Symbol : {};
1082
- var iteratorSymbol = $Symbol.iterator || "@@iterator";
1083
- var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
1084
- var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
1085
-
1086
- function define(obj, key, value) {
1087
- Object.defineProperty(obj, key, {
1088
- value: value,
1089
- enumerable: true,
1090
- configurable: true,
1091
- writable: true
1092
- });
1093
- return obj[key];
1094
- }
1096
+ var runtime_1 = createCommonjsModule(function (module) {
1097
+ /**
1098
+ * Copyright (c) 2014-present, Facebook, Inc.
1099
+ *
1100
+ * This source code is licensed under the MIT license found in the
1101
+ * LICENSE file in the root directory of this source tree.
1102
+ */
1095
1103
 
1096
- try {
1097
- // IE 8 has a broken Object.defineProperty that only works on DOM objects.
1098
- define({}, "");
1099
- } catch (err) {
1100
- define = function define(obj, key, value) {
1101
- return obj[key] = value;
1102
- };
1103
- }
1104
+ var runtime = (function (exports) {
1105
+
1106
+ var Op = Object.prototype;
1107
+ var hasOwn = Op.hasOwnProperty;
1108
+ var undefined$1; // More compressible than void 0.
1109
+ var $Symbol = typeof Symbol === "function" ? Symbol : {};
1110
+ var iteratorSymbol = $Symbol.iterator || "@@iterator";
1111
+ var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
1112
+ var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
1113
+
1114
+ function define(obj, key, value) {
1115
+ Object.defineProperty(obj, key, {
1116
+ value: value,
1117
+ enumerable: true,
1118
+ configurable: true,
1119
+ writable: true
1120
+ });
1121
+ return obj[key];
1122
+ }
1123
+ try {
1124
+ // IE 8 has a broken Object.defineProperty that only works on DOM objects.
1125
+ define({}, "");
1126
+ } catch (err) {
1127
+ define = function(obj, key, value) {
1128
+ return obj[key] = value;
1129
+ };
1130
+ }
1104
1131
 
1105
- function wrap(innerFn, outerFn, self, tryLocsList) {
1106
- // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
1107
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
1108
- var generator = Object.create(protoGenerator.prototype);
1109
- var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next,
1110
- // .throw, and .return methods.
1132
+ function wrap(innerFn, outerFn, self, tryLocsList) {
1133
+ // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
1134
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
1135
+ var generator = Object.create(protoGenerator.prototype);
1136
+ var context = new Context(tryLocsList || []);
1111
1137
 
1112
- generator._invoke = makeInvokeMethod(innerFn, self, context);
1113
- return generator;
1114
- }
1138
+ // The ._invoke method unifies the implementations of the .next,
1139
+ // .throw, and .return methods.
1140
+ generator._invoke = makeInvokeMethod(innerFn, self, context);
1115
1141
 
1116
- exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion
1117
- // record like context.tryEntries[i].completion. This interface could
1118
- // have been (and was previously) designed to take a closure to be
1119
- // invoked without arguments, but in all the cases we care about we
1120
- // already have an existing method we want to call, so there's no need
1121
- // to create a new function object. We can even get away with assuming
1122
- // the method takes exactly one argument, since that happens to be true
1123
- // in every case, so we don't have to touch the arguments object. The
1124
- // only additional allocation required is the completion record, which
1125
- // has a stable shape and so hopefully should be cheap to allocate.
1126
-
1127
- function tryCatch(fn, obj, arg) {
1128
- try {
1129
- return {
1130
- type: "normal",
1131
- arg: fn.call(obj, arg)
1132
- };
1133
- } catch (err) {
1134
- return {
1135
- type: "throw",
1136
- arg: err
1137
- };
1138
- }
1142
+ return generator;
1143
+ }
1144
+ exports.wrap = wrap;
1145
+
1146
+ // Try/catch helper to minimize deoptimizations. Returns a completion
1147
+ // record like context.tryEntries[i].completion. This interface could
1148
+ // have been (and was previously) designed to take a closure to be
1149
+ // invoked without arguments, but in all the cases we care about we
1150
+ // already have an existing method we want to call, so there's no need
1151
+ // to create a new function object. We can even get away with assuming
1152
+ // the method takes exactly one argument, since that happens to be true
1153
+ // in every case, so we don't have to touch the arguments object. The
1154
+ // only additional allocation required is the completion record, which
1155
+ // has a stable shape and so hopefully should be cheap to allocate.
1156
+ function tryCatch(fn, obj, arg) {
1157
+ try {
1158
+ return { type: "normal", arg: fn.call(obj, arg) };
1159
+ } catch (err) {
1160
+ return { type: "throw", arg: err };
1139
1161
  }
1162
+ }
1140
1163
 
1141
- var GenStateSuspendedStart = "suspendedStart";
1142
- var GenStateSuspendedYield = "suspendedYield";
1143
- var GenStateExecuting = "executing";
1144
- var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as
1145
- // breaking out of the dispatch switch statement.
1146
-
1147
- var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and
1148
- // .constructor.prototype properties for functions that return Generator
1149
- // objects. For full spec compliance, you may wish to configure your
1150
- // minifier not to mangle the names of these two functions.
1151
-
1152
- function Generator() {}
1153
-
1154
- function GeneratorFunction() {}
1155
-
1156
- function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that
1157
- // don't natively support it.
1164
+ var GenStateSuspendedStart = "suspendedStart";
1165
+ var GenStateSuspendedYield = "suspendedYield";
1166
+ var GenStateExecuting = "executing";
1167
+ var GenStateCompleted = "completed";
1168
+
1169
+ // Returning this object from the innerFn has the same effect as
1170
+ // breaking out of the dispatch switch statement.
1171
+ var ContinueSentinel = {};
1172
+
1173
+ // Dummy constructor functions that we use as the .constructor and
1174
+ // .constructor.prototype properties for functions that return Generator
1175
+ // objects. For full spec compliance, you may wish to configure your
1176
+ // minifier not to mangle the names of these two functions.
1177
+ function Generator() {}
1178
+ function GeneratorFunction() {}
1179
+ function GeneratorFunctionPrototype() {}
1180
+
1181
+ // This is a polyfill for %IteratorPrototype% for environments that
1182
+ // don't natively support it.
1183
+ var IteratorPrototype = {};
1184
+ define(IteratorPrototype, iteratorSymbol, function () {
1185
+ return this;
1186
+ });
1158
1187
 
1188
+ var getProto = Object.getPrototypeOf;
1189
+ var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
1190
+ if (NativeIteratorPrototype &&
1191
+ NativeIteratorPrototype !== Op &&
1192
+ hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
1193
+ // This environment has a native %IteratorPrototype%; use it instead
1194
+ // of the polyfill.
1195
+ IteratorPrototype = NativeIteratorPrototype;
1196
+ }
1159
1197
 
1160
- var IteratorPrototype = {};
1161
- define(IteratorPrototype, iteratorSymbol, function () {
1162
- return this;
1198
+ var Gp = GeneratorFunctionPrototype.prototype =
1199
+ Generator.prototype = Object.create(IteratorPrototype);
1200
+ GeneratorFunction.prototype = GeneratorFunctionPrototype;
1201
+ define(Gp, "constructor", GeneratorFunctionPrototype);
1202
+ define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
1203
+ GeneratorFunction.displayName = define(
1204
+ GeneratorFunctionPrototype,
1205
+ toStringTagSymbol,
1206
+ "GeneratorFunction"
1207
+ );
1208
+
1209
+ // Helper for defining the .next, .throw, and .return methods of the
1210
+ // Iterator interface in terms of a single ._invoke method.
1211
+ function defineIteratorMethods(prototype) {
1212
+ ["next", "throw", "return"].forEach(function(method) {
1213
+ define(prototype, method, function(arg) {
1214
+ return this._invoke(method, arg);
1215
+ });
1163
1216
  });
1164
- var getProto = Object.getPrototypeOf;
1165
- var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
1217
+ }
1166
1218
 
1167
- if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
1168
- // This environment has a native %IteratorPrototype%; use it instead
1169
- // of the polyfill.
1170
- IteratorPrototype = NativeIteratorPrototype;
1171
- }
1219
+ exports.isGeneratorFunction = function(genFun) {
1220
+ var ctor = typeof genFun === "function" && genFun.constructor;
1221
+ return ctor
1222
+ ? ctor === GeneratorFunction ||
1223
+ // For the native GeneratorFunction constructor, the best we can
1224
+ // do is to check its .name property.
1225
+ (ctor.displayName || ctor.name) === "GeneratorFunction"
1226
+ : false;
1227
+ };
1172
1228
 
1173
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
1174
- GeneratorFunction.prototype = GeneratorFunctionPrototype;
1175
- define(Gp, "constructor", GeneratorFunctionPrototype);
1176
- define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
1177
- GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
1178
- // Iterator interface in terms of a single ._invoke method.
1179
-
1180
- function defineIteratorMethods(prototype) {
1181
- ["next", "throw", "return"].forEach(function (method) {
1182
- define(prototype, method, function (arg) {
1183
- return this._invoke(method, arg);
1184
- });
1185
- });
1229
+ exports.mark = function(genFun) {
1230
+ if (Object.setPrototypeOf) {
1231
+ Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
1232
+ } else {
1233
+ genFun.__proto__ = GeneratorFunctionPrototype;
1234
+ define(genFun, toStringTagSymbol, "GeneratorFunction");
1186
1235
  }
1236
+ genFun.prototype = Object.create(Gp);
1237
+ return genFun;
1238
+ };
1187
1239
 
1188
- exports.isGeneratorFunction = function (genFun) {
1189
- var ctor = typeof genFun === "function" && genFun.constructor;
1190
- return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can
1191
- // do is to check its .name property.
1192
- (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
1193
- };
1240
+ // Within the body of any async function, `await x` is transformed to
1241
+ // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
1242
+ // `hasOwn.call(value, "__await")` to determine if the yielded value is
1243
+ // meant to be awaited.
1244
+ exports.awrap = function(arg) {
1245
+ return { __await: arg };
1246
+ };
1194
1247
 
1195
- exports.mark = function (genFun) {
1196
- if (Object.setPrototypeOf) {
1197
- Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
1248
+ function AsyncIterator(generator, PromiseImpl) {
1249
+ function invoke(method, arg, resolve, reject) {
1250
+ var record = tryCatch(generator[method], generator, arg);
1251
+ if (record.type === "throw") {
1252
+ reject(record.arg);
1198
1253
  } else {
1199
- genFun.__proto__ = GeneratorFunctionPrototype;
1200
- define(genFun, toStringTagSymbol, "GeneratorFunction");
1201
- }
1202
-
1203
- genFun.prototype = Object.create(Gp);
1204
- return genFun;
1205
- }; // Within the body of any async function, `await x` is transformed to
1206
- // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
1207
- // `hasOwn.call(value, "__await")` to determine if the yielded value is
1208
- // meant to be awaited.
1209
-
1210
-
1211
- exports.awrap = function (arg) {
1212
- return {
1213
- __await: arg
1214
- };
1215
- };
1216
-
1217
- function AsyncIterator(generator, PromiseImpl) {
1218
- function invoke(method, arg, resolve, reject) {
1219
- var record = tryCatch(generator[method], generator, arg);
1220
-
1221
- if (record.type === "throw") {
1222
- reject(record.arg);
1223
- } else {
1224
- var result = record.arg;
1225
- var value = result.value;
1226
-
1227
- if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
1228
- return PromiseImpl.resolve(value.__await).then(function (value) {
1229
- invoke("next", value, resolve, reject);
1230
- }, function (err) {
1231
- invoke("throw", err, resolve, reject);
1232
- });
1233
- }
1234
-
1235
- return PromiseImpl.resolve(value).then(function (unwrapped) {
1236
- // When a yielded Promise is resolved, its final value becomes
1237
- // the .value of the Promise<{value,done}> result for the
1238
- // current iteration.
1239
- result.value = unwrapped;
1240
- resolve(result);
1241
- }, function (error) {
1242
- // If a rejected Promise was yielded, throw the rejection back
1243
- // into the async generator function so it can be handled there.
1244
- return invoke("throw", error, resolve, reject);
1254
+ var result = record.arg;
1255
+ var value = result.value;
1256
+ if (value &&
1257
+ typeof value === "object" &&
1258
+ hasOwn.call(value, "__await")) {
1259
+ return PromiseImpl.resolve(value.__await).then(function(value) {
1260
+ invoke("next", value, resolve, reject);
1261
+ }, function(err) {
1262
+ invoke("throw", err, resolve, reject);
1245
1263
  });
1246
1264
  }
1265
+
1266
+ return PromiseImpl.resolve(value).then(function(unwrapped) {
1267
+ // When a yielded Promise is resolved, its final value becomes
1268
+ // the .value of the Promise<{value,done}> result for the
1269
+ // current iteration.
1270
+ result.value = unwrapped;
1271
+ resolve(result);
1272
+ }, function(error) {
1273
+ // If a rejected Promise was yielded, throw the rejection back
1274
+ // into the async generator function so it can be handled there.
1275
+ return invoke("throw", error, resolve, reject);
1276
+ });
1247
1277
  }
1278
+ }
1248
1279
 
1249
- var previousPromise;
1280
+ var previousPromise;
1250
1281
 
1251
- function enqueue(method, arg) {
1252
- function callInvokeWithMethodAndArg() {
1253
- return new PromiseImpl(function (resolve, reject) {
1254
- invoke(method, arg, resolve, reject);
1255
- });
1256
- }
1282
+ function enqueue(method, arg) {
1283
+ function callInvokeWithMethodAndArg() {
1284
+ return new PromiseImpl(function(resolve, reject) {
1285
+ invoke(method, arg, resolve, reject);
1286
+ });
1287
+ }
1257
1288
 
1258
- return previousPromise = // If enqueue has been called before, then we want to wait until
1289
+ return previousPromise =
1290
+ // If enqueue has been called before, then we want to wait until
1259
1291
  // all previous Promises have been resolved before calling invoke,
1260
1292
  // so that results are always delivered in the correct order. If
1261
1293
  // enqueue has not been called before, then it is important to
@@ -1267,527 +1299,554 @@ var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
1267
1299
  // execute code before the first await. Since we implement simple
1268
1300
  // async functions in terms of async generators, it is especially
1269
1301
  // important to get this right, even though it requires care.
1270
- previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later
1271
- // invocations of the iterator.
1272
- callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
1273
- } // Define the unified helper method that is used to implement .next,
1274
- // .throw, and .return (see defineIteratorMethods).
1275
-
1276
-
1277
- this._invoke = enqueue;
1302
+ previousPromise ? previousPromise.then(
1303
+ callInvokeWithMethodAndArg,
1304
+ // Avoid propagating failures to Promises returned by later
1305
+ // invocations of the iterator.
1306
+ callInvokeWithMethodAndArg
1307
+ ) : callInvokeWithMethodAndArg();
1278
1308
  }
1279
1309
 
1280
- defineIteratorMethods(AsyncIterator.prototype);
1281
- define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
1282
- return this;
1283
- });
1284
- exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
1285
- // AsyncIterator objects; they just return a Promise for the value of
1286
- // the final result produced by the iterator.
1287
-
1288
- exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
1289
- if (PromiseImpl === void 0) PromiseImpl = Promise;
1290
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
1291
- return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
1292
- : iter.next().then(function (result) {
1293
- return result.done ? result.value : iter.next();
1294
- });
1295
- };
1310
+ // Define the unified helper method that is used to implement .next,
1311
+ // .throw, and .return (see defineIteratorMethods).
1312
+ this._invoke = enqueue;
1313
+ }
1296
1314
 
1297
- function makeInvokeMethod(innerFn, self, context) {
1298
- var state = GenStateSuspendedStart;
1299
- return function invoke(method, arg) {
1300
- if (state === GenStateExecuting) {
1301
- throw new Error("Generator is already running");
1302
- }
1315
+ defineIteratorMethods(AsyncIterator.prototype);
1316
+ define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
1317
+ return this;
1318
+ });
1319
+ exports.AsyncIterator = AsyncIterator;
1320
+
1321
+ // Note that simple async functions are implemented on top of
1322
+ // AsyncIterator objects; they just return a Promise for the value of
1323
+ // the final result produced by the iterator.
1324
+ exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
1325
+ if (PromiseImpl === void 0) PromiseImpl = Promise;
1326
+
1327
+ var iter = new AsyncIterator(
1328
+ wrap(innerFn, outerFn, self, tryLocsList),
1329
+ PromiseImpl
1330
+ );
1331
+
1332
+ return exports.isGeneratorFunction(outerFn)
1333
+ ? iter // If outerFn is a generator, return the full iterator.
1334
+ : iter.next().then(function(result) {
1335
+ return result.done ? result.value : iter.next();
1336
+ });
1337
+ };
1303
1338
 
1304
- if (state === GenStateCompleted) {
1305
- if (method === "throw") {
1306
- throw arg;
1307
- } // Be forgiving, per 25.3.3.3.3 of the spec:
1308
- // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
1339
+ function makeInvokeMethod(innerFn, self, context) {
1340
+ var state = GenStateSuspendedStart;
1309
1341
 
1342
+ return function invoke(method, arg) {
1343
+ if (state === GenStateExecuting) {
1344
+ throw new Error("Generator is already running");
1345
+ }
1310
1346
 
1311
- return doneResult();
1347
+ if (state === GenStateCompleted) {
1348
+ if (method === "throw") {
1349
+ throw arg;
1312
1350
  }
1313
1351
 
1314
- context.method = method;
1315
- context.arg = arg;
1316
-
1317
- while (true) {
1318
- var delegate = context.delegate;
1352
+ // Be forgiving, per 25.3.3.3.3 of the spec:
1353
+ // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
1354
+ return doneResult();
1355
+ }
1319
1356
 
1320
- if (delegate) {
1321
- var delegateResult = maybeInvokeDelegate(delegate, context);
1357
+ context.method = method;
1358
+ context.arg = arg;
1322
1359
 
1323
- if (delegateResult) {
1324
- if (delegateResult === ContinueSentinel) continue;
1325
- return delegateResult;
1326
- }
1360
+ while (true) {
1361
+ var delegate = context.delegate;
1362
+ if (delegate) {
1363
+ var delegateResult = maybeInvokeDelegate(delegate, context);
1364
+ if (delegateResult) {
1365
+ if (delegateResult === ContinueSentinel) continue;
1366
+ return delegateResult;
1327
1367
  }
1368
+ }
1328
1369
 
1329
- if (context.method === "next") {
1330
- // Setting context._sent for legacy support of Babel's
1331
- // function.sent implementation.
1332
- context.sent = context._sent = context.arg;
1333
- } else if (context.method === "throw") {
1334
- if (state === GenStateSuspendedStart) {
1335
- state = GenStateCompleted;
1336
- throw context.arg;
1337
- }
1370
+ if (context.method === "next") {
1371
+ // Setting context._sent for legacy support of Babel's
1372
+ // function.sent implementation.
1373
+ context.sent = context._sent = context.arg;
1338
1374
 
1339
- context.dispatchException(context.arg);
1340
- } else if (context.method === "return") {
1341
- context.abrupt("return", context.arg);
1375
+ } else if (context.method === "throw") {
1376
+ if (state === GenStateSuspendedStart) {
1377
+ state = GenStateCompleted;
1378
+ throw context.arg;
1342
1379
  }
1343
1380
 
1344
- state = GenStateExecuting;
1345
- var record = tryCatch(innerFn, self, context);
1381
+ context.dispatchException(context.arg);
1346
1382
 
1347
- if (record.type === "normal") {
1348
- // If an exception is thrown from innerFn, we leave state ===
1349
- // GenStateExecuting and loop back for another invocation.
1350
- state = context.done ? GenStateCompleted : GenStateSuspendedYield;
1383
+ } else if (context.method === "return") {
1384
+ context.abrupt("return", context.arg);
1385
+ }
1351
1386
 
1352
- if (record.arg === ContinueSentinel) {
1353
- continue;
1354
- }
1387
+ state = GenStateExecuting;
1355
1388
 
1356
- return {
1357
- value: record.arg,
1358
- done: context.done
1359
- };
1360
- } else if (record.type === "throw") {
1361
- state = GenStateCompleted; // Dispatch the exception by looping back around to the
1362
- // context.dispatchException(context.arg) call above.
1389
+ var record = tryCatch(innerFn, self, context);
1390
+ if (record.type === "normal") {
1391
+ // If an exception is thrown from innerFn, we leave state ===
1392
+ // GenStateExecuting and loop back for another invocation.
1393
+ state = context.done
1394
+ ? GenStateCompleted
1395
+ : GenStateSuspendedYield;
1363
1396
 
1364
- context.method = "throw";
1365
- context.arg = record.arg;
1366
- }
1367
- }
1368
- };
1369
- } // Call delegate.iterator[context.method](context.arg) and handle the
1370
- // result, either by returning a { value, done } result from the
1371
- // delegate iterator, or by modifying context.method and context.arg,
1372
- // setting context.delegate to null, and returning the ContinueSentinel.
1373
-
1374
-
1375
- function maybeInvokeDelegate(delegate, context) {
1376
- var method = delegate.iterator[context.method];
1377
-
1378
- if (method === undefined$1) {
1379
- // A .throw or .return when the delegate iterator has no .throw
1380
- // method always terminates the yield* loop.
1381
- context.delegate = null;
1382
-
1383
- if (context.method === "throw") {
1384
- // Note: ["return"] must be used for ES3 parsing compatibility.
1385
- if (delegate.iterator["return"]) {
1386
- // If the delegate iterator has a return method, give it a
1387
- // chance to clean up.
1388
- context.method = "return";
1389
- context.arg = undefined$1;
1390
- maybeInvokeDelegate(delegate, context);
1391
-
1392
- if (context.method === "throw") {
1393
- // If maybeInvokeDelegate(context) changed context.method from
1394
- // "return" to "throw", let that override the TypeError below.
1395
- return ContinueSentinel;
1396
- }
1397
+ if (record.arg === ContinueSentinel) {
1398
+ continue;
1397
1399
  }
1398
1400
 
1401
+ return {
1402
+ value: record.arg,
1403
+ done: context.done
1404
+ };
1405
+
1406
+ } else if (record.type === "throw") {
1407
+ state = GenStateCompleted;
1408
+ // Dispatch the exception by looping back around to the
1409
+ // context.dispatchException(context.arg) call above.
1399
1410
  context.method = "throw";
1400
- context.arg = new TypeError("The iterator does not provide a 'throw' method");
1411
+ context.arg = record.arg;
1401
1412
  }
1402
-
1403
- return ContinueSentinel;
1404
1413
  }
1414
+ };
1415
+ }
1405
1416
 
1406
- var record = tryCatch(method, delegate.iterator, context.arg);
1417
+ // Call delegate.iterator[context.method](context.arg) and handle the
1418
+ // result, either by returning a { value, done } result from the
1419
+ // delegate iterator, or by modifying context.method and context.arg,
1420
+ // setting context.delegate to null, and returning the ContinueSentinel.
1421
+ function maybeInvokeDelegate(delegate, context) {
1422
+ var method = delegate.iterator[context.method];
1423
+ if (method === undefined$1) {
1424
+ // A .throw or .return when the delegate iterator has no .throw
1425
+ // method always terminates the yield* loop.
1426
+ context.delegate = null;
1407
1427
 
1408
- if (record.type === "throw") {
1409
- context.method = "throw";
1410
- context.arg = record.arg;
1411
- context.delegate = null;
1412
- return ContinueSentinel;
1413
- }
1428
+ if (context.method === "throw") {
1429
+ // Note: ["return"] must be used for ES3 parsing compatibility.
1430
+ if (delegate.iterator["return"]) {
1431
+ // If the delegate iterator has a return method, give it a
1432
+ // chance to clean up.
1433
+ context.method = "return";
1434
+ context.arg = undefined$1;
1435
+ maybeInvokeDelegate(delegate, context);
1414
1436
 
1415
- var info = record.arg;
1437
+ if (context.method === "throw") {
1438
+ // If maybeInvokeDelegate(context) changed context.method from
1439
+ // "return" to "throw", let that override the TypeError below.
1440
+ return ContinueSentinel;
1441
+ }
1442
+ }
1416
1443
 
1417
- if (!info) {
1418
1444
  context.method = "throw";
1419
- context.arg = new TypeError("iterator result is not an object");
1420
- context.delegate = null;
1421
- return ContinueSentinel;
1445
+ context.arg = new TypeError(
1446
+ "The iterator does not provide a 'throw' method");
1422
1447
  }
1423
1448
 
1424
- if (info.done) {
1425
- // Assign the result of the finished delegate to the temporary
1426
- // variable specified by delegate.resultName (see delegateYield).
1427
- context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield).
1428
-
1429
- context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the
1430
- // exception, let the outer generator proceed normally. If
1431
- // context.method was "next", forget context.arg since it has been
1432
- // "consumed" by the delegate iterator. If context.method was
1433
- // "return", allow the original .return call to continue in the
1434
- // outer generator.
1435
-
1436
- if (context.method !== "return") {
1437
- context.method = "next";
1438
- context.arg = undefined$1;
1439
- }
1440
- } else {
1441
- // Re-yield the result returned by the delegate method.
1442
- return info;
1443
- } // The delegate iterator is finished, so forget it and continue with
1444
- // the outer generator.
1449
+ return ContinueSentinel;
1450
+ }
1445
1451
 
1452
+ var record = tryCatch(method, delegate.iterator, context.arg);
1446
1453
 
1454
+ if (record.type === "throw") {
1455
+ context.method = "throw";
1456
+ context.arg = record.arg;
1447
1457
  context.delegate = null;
1448
1458
  return ContinueSentinel;
1449
- } // Define Generator.prototype.{next,throw,return} in terms of the
1450
- // unified ._invoke helper method.
1451
-
1452
-
1453
- defineIteratorMethods(Gp);
1454
- define(Gp, toStringTagSymbol, "Generator"); // A Generator should always return itself as the iterator object when the
1455
- // @@iterator function is called on it. Some browsers' implementations of the
1456
- // iterator prototype chain incorrectly implement this, causing the Generator
1457
- // object to not be returned from this call. This ensures that doesn't happen.
1458
- // See https://github.com/facebook/regenerator/issues/274 for more details.
1459
-
1460
- define(Gp, iteratorSymbol, function () {
1461
- return this;
1462
- });
1463
- define(Gp, "toString", function () {
1464
- return "[object Generator]";
1465
- });
1459
+ }
1466
1460
 
1467
- function pushTryEntry(locs) {
1468
- var entry = {
1469
- tryLoc: locs[0]
1470
- };
1461
+ var info = record.arg;
1471
1462
 
1472
- if (1 in locs) {
1473
- entry.catchLoc = locs[1];
1474
- }
1463
+ if (! info) {
1464
+ context.method = "throw";
1465
+ context.arg = new TypeError("iterator result is not an object");
1466
+ context.delegate = null;
1467
+ return ContinueSentinel;
1468
+ }
1475
1469
 
1476
- if (2 in locs) {
1477
- entry.finallyLoc = locs[2];
1478
- entry.afterLoc = locs[3];
1470
+ if (info.done) {
1471
+ // Assign the result of the finished delegate to the temporary
1472
+ // variable specified by delegate.resultName (see delegateYield).
1473
+ context[delegate.resultName] = info.value;
1474
+
1475
+ // Resume execution at the desired location (see delegateYield).
1476
+ context.next = delegate.nextLoc;
1477
+
1478
+ // If context.method was "throw" but the delegate handled the
1479
+ // exception, let the outer generator proceed normally. If
1480
+ // context.method was "next", forget context.arg since it has been
1481
+ // "consumed" by the delegate iterator. If context.method was
1482
+ // "return", allow the original .return call to continue in the
1483
+ // outer generator.
1484
+ if (context.method !== "return") {
1485
+ context.method = "next";
1486
+ context.arg = undefined$1;
1479
1487
  }
1480
1488
 
1481
- this.tryEntries.push(entry);
1489
+ } else {
1490
+ // Re-yield the result returned by the delegate method.
1491
+ return info;
1482
1492
  }
1483
1493
 
1484
- function resetTryEntry(entry) {
1485
- var record = entry.completion || {};
1486
- record.type = "normal";
1487
- delete record.arg;
1488
- entry.completion = record;
1489
- }
1494
+ // The delegate iterator is finished, so forget it and continue with
1495
+ // the outer generator.
1496
+ context.delegate = null;
1497
+ return ContinueSentinel;
1498
+ }
1490
1499
 
1491
- function Context(tryLocsList) {
1492
- // The root entry object (effectively a try statement without a catch
1493
- // or a finally block) gives us a place to store values thrown from
1494
- // locations where there is no enclosing try statement.
1495
- this.tryEntries = [{
1496
- tryLoc: "root"
1497
- }];
1498
- tryLocsList.forEach(pushTryEntry, this);
1499
- this.reset(true);
1500
- }
1500
+ // Define Generator.prototype.{next,throw,return} in terms of the
1501
+ // unified ._invoke helper method.
1502
+ defineIteratorMethods(Gp);
1501
1503
 
1502
- exports.keys = function (object) {
1503
- var keys = [];
1504
+ define(Gp, toStringTagSymbol, "Generator");
1504
1505
 
1505
- for (var key in object) {
1506
- keys.push(key);
1507
- }
1506
+ // A Generator should always return itself as the iterator object when the
1507
+ // @@iterator function is called on it. Some browsers' implementations of the
1508
+ // iterator prototype chain incorrectly implement this, causing the Generator
1509
+ // object to not be returned from this call. This ensures that doesn't happen.
1510
+ // See https://github.com/facebook/regenerator/issues/274 for more details.
1511
+ define(Gp, iteratorSymbol, function() {
1512
+ return this;
1513
+ });
1508
1514
 
1509
- keys.reverse(); // Rather than returning an object with a next method, we keep
1510
- // things simple and return the next function itself.
1515
+ define(Gp, "toString", function() {
1516
+ return "[object Generator]";
1517
+ });
1511
1518
 
1512
- return function next() {
1513
- while (keys.length) {
1514
- var key = keys.pop();
1519
+ function pushTryEntry(locs) {
1520
+ var entry = { tryLoc: locs[0] };
1515
1521
 
1516
- if (key in object) {
1517
- next.value = key;
1518
- next.done = false;
1519
- return next;
1520
- }
1521
- } // To avoid creating an additional object, we just hang the .value
1522
- // and .done properties off the next function object itself. This
1523
- // also ensures that the minifier will not anonymize the function.
1522
+ if (1 in locs) {
1523
+ entry.catchLoc = locs[1];
1524
+ }
1524
1525
 
1526
+ if (2 in locs) {
1527
+ entry.finallyLoc = locs[2];
1528
+ entry.afterLoc = locs[3];
1529
+ }
1525
1530
 
1526
- next.done = true;
1527
- return next;
1528
- };
1529
- };
1531
+ this.tryEntries.push(entry);
1532
+ }
1530
1533
 
1531
- function values(iterable) {
1532
- if (iterable) {
1533
- var iteratorMethod = iterable[iteratorSymbol];
1534
+ function resetTryEntry(entry) {
1535
+ var record = entry.completion || {};
1536
+ record.type = "normal";
1537
+ delete record.arg;
1538
+ entry.completion = record;
1539
+ }
1534
1540
 
1535
- if (iteratorMethod) {
1536
- return iteratorMethod.call(iterable);
1537
- }
1541
+ function Context(tryLocsList) {
1542
+ // The root entry object (effectively a try statement without a catch
1543
+ // or a finally block) gives us a place to store values thrown from
1544
+ // locations where there is no enclosing try statement.
1545
+ this.tryEntries = [{ tryLoc: "root" }];
1546
+ tryLocsList.forEach(pushTryEntry, this);
1547
+ this.reset(true);
1548
+ }
1538
1549
 
1539
- if (typeof iterable.next === "function") {
1540
- return iterable;
1550
+ exports.keys = function(object) {
1551
+ var keys = [];
1552
+ for (var key in object) {
1553
+ keys.push(key);
1554
+ }
1555
+ keys.reverse();
1556
+
1557
+ // Rather than returning an object with a next method, we keep
1558
+ // things simple and return the next function itself.
1559
+ return function next() {
1560
+ while (keys.length) {
1561
+ var key = keys.pop();
1562
+ if (key in object) {
1563
+ next.value = key;
1564
+ next.done = false;
1565
+ return next;
1541
1566
  }
1567
+ }
1542
1568
 
1543
- if (!isNaN(iterable.length)) {
1544
- var i = -1,
1545
- next = function next() {
1546
- while (++i < iterable.length) {
1547
- if (hasOwn.call(iterable, i)) {
1548
- next.value = iterable[i];
1549
- next.done = false;
1550
- return next;
1551
- }
1552
- }
1569
+ // To avoid creating an additional object, we just hang the .value
1570
+ // and .done properties off the next function object itself. This
1571
+ // also ensures that the minifier will not anonymize the function.
1572
+ next.done = true;
1573
+ return next;
1574
+ };
1575
+ };
1553
1576
 
1554
- next.value = undefined$1;
1555
- next.done = true;
1556
- return next;
1557
- };
1577
+ function values(iterable) {
1578
+ if (iterable) {
1579
+ var iteratorMethod = iterable[iteratorSymbol];
1580
+ if (iteratorMethod) {
1581
+ return iteratorMethod.call(iterable);
1582
+ }
1558
1583
 
1559
- return next.next = next;
1560
- }
1561
- } // Return an iterator with no values.
1584
+ if (typeof iterable.next === "function") {
1585
+ return iterable;
1586
+ }
1562
1587
 
1588
+ if (!isNaN(iterable.length)) {
1589
+ var i = -1, next = function next() {
1590
+ while (++i < iterable.length) {
1591
+ if (hasOwn.call(iterable, i)) {
1592
+ next.value = iterable[i];
1593
+ next.done = false;
1594
+ return next;
1595
+ }
1596
+ }
1563
1597
 
1564
- return {
1565
- next: doneResult
1566
- };
1567
- }
1598
+ next.value = undefined$1;
1599
+ next.done = true;
1568
1600
 
1569
- exports.values = values;
1601
+ return next;
1602
+ };
1570
1603
 
1571
- function doneResult() {
1572
- return {
1573
- value: undefined$1,
1574
- done: true
1575
- };
1604
+ return next.next = next;
1605
+ }
1576
1606
  }
1577
1607
 
1578
- Context.prototype = {
1579
- constructor: Context,
1580
- reset: function reset(skipTempReset) {
1581
- this.prev = 0;
1582
- this.next = 0; // Resetting context._sent for legacy support of Babel's
1583
- // function.sent implementation.
1608
+ // Return an iterator with no values.
1609
+ return { next: doneResult };
1610
+ }
1611
+ exports.values = values;
1584
1612
 
1585
- this.sent = this._sent = undefined$1;
1586
- this.done = false;
1587
- this.delegate = null;
1588
- this.method = "next";
1589
- this.arg = undefined$1;
1590
- this.tryEntries.forEach(resetTryEntry);
1613
+ function doneResult() {
1614
+ return { value: undefined$1, done: true };
1615
+ }
1591
1616
 
1592
- if (!skipTempReset) {
1593
- for (var name in this) {
1594
- // Not sure about the optimal order of these conditions:
1595
- if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
1596
- this[name] = undefined$1;
1597
- }
1617
+ Context.prototype = {
1618
+ constructor: Context,
1619
+
1620
+ reset: function(skipTempReset) {
1621
+ this.prev = 0;
1622
+ this.next = 0;
1623
+ // Resetting context._sent for legacy support of Babel's
1624
+ // function.sent implementation.
1625
+ this.sent = this._sent = undefined$1;
1626
+ this.done = false;
1627
+ this.delegate = null;
1628
+
1629
+ this.method = "next";
1630
+ this.arg = undefined$1;
1631
+
1632
+ this.tryEntries.forEach(resetTryEntry);
1633
+
1634
+ if (!skipTempReset) {
1635
+ for (var name in this) {
1636
+ // Not sure about the optimal order of these conditions:
1637
+ if (name.charAt(0) === "t" &&
1638
+ hasOwn.call(this, name) &&
1639
+ !isNaN(+name.slice(1))) {
1640
+ this[name] = undefined$1;
1598
1641
  }
1599
1642
  }
1600
- },
1601
- stop: function stop() {
1602
- this.done = true;
1603
- var rootEntry = this.tryEntries[0];
1604
- var rootRecord = rootEntry.completion;
1643
+ }
1644
+ },
1605
1645
 
1606
- if (rootRecord.type === "throw") {
1607
- throw rootRecord.arg;
1608
- }
1646
+ stop: function() {
1647
+ this.done = true;
1609
1648
 
1610
- return this.rval;
1611
- },
1612
- dispatchException: function dispatchException(exception) {
1613
- if (this.done) {
1614
- throw exception;
1615
- }
1649
+ var rootEntry = this.tryEntries[0];
1650
+ var rootRecord = rootEntry.completion;
1651
+ if (rootRecord.type === "throw") {
1652
+ throw rootRecord.arg;
1653
+ }
1616
1654
 
1617
- var context = this;
1655
+ return this.rval;
1656
+ },
1618
1657
 
1619
- function handle(loc, caught) {
1620
- record.type = "throw";
1621
- record.arg = exception;
1622
- context.next = loc;
1658
+ dispatchException: function(exception) {
1659
+ if (this.done) {
1660
+ throw exception;
1661
+ }
1623
1662
 
1624
- if (caught) {
1625
- // If the dispatched exception was caught by a catch block,
1626
- // then let that catch block handle the exception normally.
1627
- context.method = "next";
1628
- context.arg = undefined$1;
1629
- }
1663
+ var context = this;
1664
+ function handle(loc, caught) {
1665
+ record.type = "throw";
1666
+ record.arg = exception;
1667
+ context.next = loc;
1630
1668
 
1631
- return !!caught;
1669
+ if (caught) {
1670
+ // If the dispatched exception was caught by a catch block,
1671
+ // then let that catch block handle the exception normally.
1672
+ context.method = "next";
1673
+ context.arg = undefined$1;
1632
1674
  }
1633
1675
 
1634
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1635
- var entry = this.tryEntries[i];
1636
- var record = entry.completion;
1676
+ return !! caught;
1677
+ }
1637
1678
 
1638
- if (entry.tryLoc === "root") {
1639
- // Exception thrown outside of any try block that could handle
1640
- // it, so set the completion value of the entire function to
1641
- // throw the exception.
1642
- return handle("end");
1643
- }
1679
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1680
+ var entry = this.tryEntries[i];
1681
+ var record = entry.completion;
1644
1682
 
1645
- if (entry.tryLoc <= this.prev) {
1646
- var hasCatch = hasOwn.call(entry, "catchLoc");
1647
- var hasFinally = hasOwn.call(entry, "finallyLoc");
1683
+ if (entry.tryLoc === "root") {
1684
+ // Exception thrown outside of any try block that could handle
1685
+ // it, so set the completion value of the entire function to
1686
+ // throw the exception.
1687
+ return handle("end");
1688
+ }
1648
1689
 
1649
- if (hasCatch && hasFinally) {
1650
- if (this.prev < entry.catchLoc) {
1651
- return handle(entry.catchLoc, true);
1652
- } else if (this.prev < entry.finallyLoc) {
1653
- return handle(entry.finallyLoc);
1654
- }
1655
- } else if (hasCatch) {
1656
- if (this.prev < entry.catchLoc) {
1657
- return handle(entry.catchLoc, true);
1658
- }
1659
- } else if (hasFinally) {
1660
- if (this.prev < entry.finallyLoc) {
1661
- return handle(entry.finallyLoc);
1662
- }
1663
- } else {
1664
- throw new Error("try statement without catch or finally");
1690
+ if (entry.tryLoc <= this.prev) {
1691
+ var hasCatch = hasOwn.call(entry, "catchLoc");
1692
+ var hasFinally = hasOwn.call(entry, "finallyLoc");
1693
+
1694
+ if (hasCatch && hasFinally) {
1695
+ if (this.prev < entry.catchLoc) {
1696
+ return handle(entry.catchLoc, true);
1697
+ } else if (this.prev < entry.finallyLoc) {
1698
+ return handle(entry.finallyLoc);
1699
+ }
1700
+
1701
+ } else if (hasCatch) {
1702
+ if (this.prev < entry.catchLoc) {
1703
+ return handle(entry.catchLoc, true);
1704
+ }
1705
+
1706
+ } else if (hasFinally) {
1707
+ if (this.prev < entry.finallyLoc) {
1708
+ return handle(entry.finallyLoc);
1665
1709
  }
1666
- }
1667
- }
1668
- },
1669
- abrupt: function abrupt(type, arg) {
1670
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1671
- var entry = this.tryEntries[i];
1672
1710
 
1673
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
1674
- var finallyEntry = entry;
1675
- break;
1711
+ } else {
1712
+ throw new Error("try statement without catch or finally");
1676
1713
  }
1677
1714
  }
1715
+ }
1716
+ },
1678
1717
 
1679
- if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
1680
- // Ignore the finally entry if control is not jumping to a
1681
- // location outside the try/catch block.
1682
- finallyEntry = null;
1718
+ abrupt: function(type, arg) {
1719
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1720
+ var entry = this.tryEntries[i];
1721
+ if (entry.tryLoc <= this.prev &&
1722
+ hasOwn.call(entry, "finallyLoc") &&
1723
+ this.prev < entry.finallyLoc) {
1724
+ var finallyEntry = entry;
1725
+ break;
1683
1726
  }
1727
+ }
1684
1728
 
1685
- var record = finallyEntry ? finallyEntry.completion : {};
1686
- record.type = type;
1687
- record.arg = arg;
1729
+ if (finallyEntry &&
1730
+ (type === "break" ||
1731
+ type === "continue") &&
1732
+ finallyEntry.tryLoc <= arg &&
1733
+ arg <= finallyEntry.finallyLoc) {
1734
+ // Ignore the finally entry if control is not jumping to a
1735
+ // location outside the try/catch block.
1736
+ finallyEntry = null;
1737
+ }
1688
1738
 
1689
- if (finallyEntry) {
1690
- this.method = "next";
1691
- this.next = finallyEntry.finallyLoc;
1692
- return ContinueSentinel;
1693
- }
1739
+ var record = finallyEntry ? finallyEntry.completion : {};
1740
+ record.type = type;
1741
+ record.arg = arg;
1694
1742
 
1695
- return this.complete(record);
1696
- },
1697
- complete: function complete(record, afterLoc) {
1698
- if (record.type === "throw") {
1699
- throw record.arg;
1700
- }
1743
+ if (finallyEntry) {
1744
+ this.method = "next";
1745
+ this.next = finallyEntry.finallyLoc;
1746
+ return ContinueSentinel;
1747
+ }
1701
1748
 
1702
- if (record.type === "break" || record.type === "continue") {
1703
- this.next = record.arg;
1704
- } else if (record.type === "return") {
1705
- this.rval = this.arg = record.arg;
1706
- this.method = "return";
1707
- this.next = "end";
1708
- } else if (record.type === "normal" && afterLoc) {
1709
- this.next = afterLoc;
1710
- }
1749
+ return this.complete(record);
1750
+ },
1711
1751
 
1712
- return ContinueSentinel;
1713
- },
1714
- finish: function finish(finallyLoc) {
1715
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1716
- var entry = this.tryEntries[i];
1752
+ complete: function(record, afterLoc) {
1753
+ if (record.type === "throw") {
1754
+ throw record.arg;
1755
+ }
1717
1756
 
1718
- if (entry.finallyLoc === finallyLoc) {
1719
- this.complete(entry.completion, entry.afterLoc);
1720
- resetTryEntry(entry);
1721
- return ContinueSentinel;
1722
- }
1723
- }
1724
- },
1725
- "catch": function _catch(tryLoc) {
1726
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1727
- var entry = this.tryEntries[i];
1757
+ if (record.type === "break" ||
1758
+ record.type === "continue") {
1759
+ this.next = record.arg;
1760
+ } else if (record.type === "return") {
1761
+ this.rval = this.arg = record.arg;
1762
+ this.method = "return";
1763
+ this.next = "end";
1764
+ } else if (record.type === "normal" && afterLoc) {
1765
+ this.next = afterLoc;
1766
+ }
1728
1767
 
1729
- if (entry.tryLoc === tryLoc) {
1730
- var record = entry.completion;
1768
+ return ContinueSentinel;
1769
+ },
1731
1770
 
1732
- if (record.type === "throw") {
1733
- var thrown = record.arg;
1734
- resetTryEntry(entry);
1735
- }
1771
+ finish: function(finallyLoc) {
1772
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1773
+ var entry = this.tryEntries[i];
1774
+ if (entry.finallyLoc === finallyLoc) {
1775
+ this.complete(entry.completion, entry.afterLoc);
1776
+ resetTryEntry(entry);
1777
+ return ContinueSentinel;
1778
+ }
1779
+ }
1780
+ },
1736
1781
 
1737
- return thrown;
1782
+ "catch": function(tryLoc) {
1783
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1784
+ var entry = this.tryEntries[i];
1785
+ if (entry.tryLoc === tryLoc) {
1786
+ var record = entry.completion;
1787
+ if (record.type === "throw") {
1788
+ var thrown = record.arg;
1789
+ resetTryEntry(entry);
1738
1790
  }
1739
- } // The context.catch method must only be called with a location
1740
- // argument that corresponds to a known catch block.
1741
-
1791
+ return thrown;
1792
+ }
1793
+ }
1742
1794
 
1743
- throw new Error("illegal catch attempt");
1744
- },
1745
- delegateYield: function delegateYield(iterable, resultName, nextLoc) {
1746
- this.delegate = {
1747
- iterator: values(iterable),
1748
- resultName: resultName,
1749
- nextLoc: nextLoc
1750
- };
1795
+ // The context.catch method must only be called with a location
1796
+ // argument that corresponds to a known catch block.
1797
+ throw new Error("illegal catch attempt");
1798
+ },
1751
1799
 
1752
- if (this.method === "next") {
1753
- // Deliberately forget the last sent value so that we don't
1754
- // accidentally pass it on to the delegate.
1755
- this.arg = undefined$1;
1756
- }
1800
+ delegateYield: function(iterable, resultName, nextLoc) {
1801
+ this.delegate = {
1802
+ iterator: values(iterable),
1803
+ resultName: resultName,
1804
+ nextLoc: nextLoc
1805
+ };
1757
1806
 
1758
- return ContinueSentinel;
1807
+ if (this.method === "next") {
1808
+ // Deliberately forget the last sent value so that we don't
1809
+ // accidentally pass it on to the delegate.
1810
+ this.arg = undefined$1;
1759
1811
  }
1760
- }; // Regardless of whether this script is executing as a CommonJS module
1761
- // or not, return the runtime object so that we can declare the variable
1762
- // regeneratorRuntime in the outer scope, which allows this module to be
1763
- // injected easily by `bin/regenerator --include-runtime script.js`.
1764
1812
 
1765
- return exports;
1766
- }( // If this script is executing as a CommonJS module, use module.exports
1813
+ return ContinueSentinel;
1814
+ }
1815
+ };
1816
+
1817
+ // Regardless of whether this script is executing as a CommonJS module
1818
+ // or not, return the runtime object so that we can declare the variable
1819
+ // regeneratorRuntime in the outer scope, which allows this module to be
1820
+ // injected easily by `bin/regenerator --include-runtime script.js`.
1821
+ return exports;
1822
+
1823
+ }(
1824
+ // If this script is executing as a CommonJS module, use module.exports
1767
1825
  // as the regeneratorRuntime namespace. Otherwise create a new empty
1768
1826
  // object. Either way, the resulting object will be used to initialize
1769
1827
  // the regeneratorRuntime variable at the top of this file.
1770
- module.exports );
1771
-
1772
- try {
1773
- regeneratorRuntime = runtime;
1774
- } catch (accidentalStrictMode) {
1775
- // This module should not be running in strict mode, so the above
1776
- // assignment should always work unless something is misconfigured. Just
1777
- // in case runtime.js accidentally runs in strict mode, in modern engines
1778
- // we can explicitly access globalThis. In older engines we can escape
1779
- // strict mode using a global Function call. This could conceivably fail
1780
- // if a Content Security Policy forbids using Function, but in that case
1781
- // the proper solution is to fix the accidental strict mode problem. If
1782
- // you've misconfigured your bundler to force strict mode and applied a
1783
- // CSP to forbid Function, and you're not willing to fix either of those
1784
- // problems, please detail your unique predicament in a GitHub issue.
1785
- if (typeof globalThis === "object") {
1786
- globalThis.regeneratorRuntime = runtime;
1787
- } else {
1788
- Function("r", "regeneratorRuntime = r")(runtime);
1789
- }
1828
+ module.exports
1829
+ ));
1830
+
1831
+ try {
1832
+ regeneratorRuntime = runtime;
1833
+ } catch (accidentalStrictMode) {
1834
+ // This module should not be running in strict mode, so the above
1835
+ // assignment should always work unless something is misconfigured. Just
1836
+ // in case runtime.js accidentally runs in strict mode, in modern engines
1837
+ // we can explicitly access globalThis. In older engines we can escape
1838
+ // strict mode using a global Function call. This could conceivably fail
1839
+ // if a Content Security Policy forbids using Function, but in that case
1840
+ // the proper solution is to fix the accidental strict mode problem. If
1841
+ // you've misconfigured your bundler to force strict mode and applied a
1842
+ // CSP to forbid Function, and you're not willing to fix either of those
1843
+ // problems, please detail your unique predicament in a GitHub issue.
1844
+ if (typeof globalThis === "object") {
1845
+ globalThis.regeneratorRuntime = runtime;
1846
+ } else {
1847
+ Function("r", "regeneratorRuntime = r")(runtime);
1790
1848
  }
1849
+ }
1791
1850
  });
1792
1851
 
1793
1852
  /* eslint-disable you-dont-need-lodash-underscore/find */
@@ -1901,11 +1960,12 @@ function _selectEntityAndInsert() {
1901
1960
  case 12:
1902
1961
  slate.Transforms.select(editor, selection);
1903
1962
  insertBlock(editor, nodeType, entity);
1963
+ ensureFollowingParagraph(editor);
1904
1964
  logAction('insert', {
1905
1965
  nodeType: nodeType
1906
1966
  });
1907
1967
 
1908
- case 15:
1968
+ case 16:
1909
1969
  case "end":
1910
1970
  return _context.stop();
1911
1971
  }
@@ -1915,6 +1975,43 @@ function _selectEntityAndInsert() {
1915
1975
  return _selectEntityAndInsert.apply(this, arguments);
1916
1976
  }
1917
1977
 
1978
+ function ensureFollowingParagraph(editor) {
1979
+ /*
1980
+ If the new block isn't followed by a sibling paragraph we insert a new empty one
1981
+ */
1982
+ var next = slate.Editor.next(editor);
1983
+
1984
+ if (!next) {
1985
+ return insertEmptyParagraph(editor);
1986
+ }
1987
+
1988
+ var parent = slate.Editor.above(editor, {
1989
+ voids: false,
1990
+ match: function match(e) {
1991
+ return !slate.Element.isElement(e) || ![Contentful.BLOCKS.EMBEDDED_ASSET, Contentful.BLOCKS.EMBEDDED_ENTRY].includes(e.type);
1992
+ }
1993
+ });
1994
+
1995
+ if (slate.Editor.isEditor(parent)) {
1996
+ // at level 0, a following paragraph is handled by the tralingParagraph plugin
1997
+ moveToTheNextChar(editor);
1998
+ return;
1999
+ }
2000
+
2001
+ var paragraph = slate.Editor.above(editor, {
2002
+ at: next[1],
2003
+ match: function match(e) {
2004
+ return slate.Element.isElement(e) && Contentful.TEXT_CONTAINERS.includes(e.type);
2005
+ }
2006
+ });
2007
+
2008
+ if (!paragraph || !parent || !slate.Path.isChild(paragraph[1], parent[1])) {
2009
+ return insertEmptyParagraph(editor);
2010
+ }
2011
+
2012
+ moveToTheNextChar(editor);
2013
+ }
2014
+
1918
2015
  var createNode = function createNode(nodeType, entity) {
1919
2016
  return {
1920
2017
  type: nodeType,
@@ -1962,11 +2059,29 @@ function EmbeddedEntityBlockToolbarIcon(_ref) {
1962
2059
  var editor = useContentfulEditor();
1963
2060
  var sdk = useSdkContext();
1964
2061
 
1965
- var handleClick = function handleClick(event) {
1966
- event.preventDefault();
1967
- onClose();
1968
- selectEntityAndInsert(nodeType, sdk, editor, editor.tracking.onToolbarAction);
1969
- };
2062
+ var handleClick = /*#__PURE__*/function () {
2063
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(event) {
2064
+ return runtime_1.wrap(function _callee$(_context) {
2065
+ while (1) {
2066
+ switch (_context.prev = _context.next) {
2067
+ case 0:
2068
+ event.preventDefault();
2069
+ onClose();
2070
+ _context.next = 4;
2071
+ return selectEntityAndInsert(nodeType, sdk, editor, editor.tracking.onToolbarAction);
2072
+
2073
+ case 4:
2074
+ case "end":
2075
+ return _context.stop();
2076
+ }
2077
+ }
2078
+ }, _callee);
2079
+ }));
2080
+
2081
+ return function handleClick(_x) {
2082
+ return _ref2.apply(this, arguments);
2083
+ };
2084
+ }();
1970
2085
 
1971
2086
  var type = getEntityTypeFromNodeType(nodeType);
1972
2087
  var baseClass = "rich-text__" + nodeType;
@@ -2299,15 +2414,18 @@ function _selectEntityAndInsert$1() {
2299
2414
  return _context2.abrupt("return");
2300
2415
 
2301
2416
  case 10:
2302
- inlineEntryNode = createInlineEntryNode(entry.sys.id); // Got to wait until focus is really back on the editor or setSelection() won't work.
2303
-
2304
- setTimeout(function () {
2305
- slate.Transforms.setSelection(editor, selection);
2306
- slate.Transforms.insertNodes(editor, inlineEntryNode);
2307
- }, 0);
2417
+ inlineEntryNode = createInlineEntryNode(entry.sys.id);
2308
2418
  logAction('insert', {
2309
2419
  nodeType: Contentful.INLINES.EMBEDDED_ENTRY
2310
- });
2420
+ }); // Got to wait until focus is really back on the editor or setSelection() won't work.
2421
+
2422
+ return _context2.abrupt("return", new Promise(function (resolve) {
2423
+ setTimeout(function () {
2424
+ slate.Transforms.setSelection(editor, selection);
2425
+ slate.Transforms.insertNodes(editor, inlineEntryNode);
2426
+ resolve();
2427
+ }, 0);
2428
+ }));
2311
2429
 
2312
2430
  case 13:
2313
2431
  case "end":
@@ -2348,6 +2466,9 @@ function ToolbarEmbeddedEntityInlineButton(props) {
2348
2466
  return selectEntityAndInsert$1(editor, sdk, editor.tracking.onToolbarAction);
2349
2467
 
2350
2468
  case 6:
2469
+ moveToTheNextChar(editor);
2470
+
2471
+ case 7:
2351
2472
  case "end":
2352
2473
  return _context.stop();
2353
2474
  }
@@ -2498,7 +2619,7 @@ function ToolbarHeadingButton(props) {
2498
2619
  var prevOnChange = editor.onChange;
2499
2620
  /*
2500
2621
  The focus might happen at point in time when
2501
- `toggleNodeType` changes aren't rendered yet, causing the browser
2622
+ `toggleElement` (helper for toggleNodeType) changes aren't rendered yet, causing the browser
2502
2623
  to place the cursor at the start of the text.
2503
2624
  We wait for the change event before focusing
2504
2625
  the editor again. This ensures the cursor is back at the previous
@@ -2514,7 +2635,7 @@ function ToolbarHeadingButton(props) {
2514
2635
  editor.tracking.onToolbarAction(isActive ? 'remove' : 'insert', {
2515
2636
  nodeType: type
2516
2637
  });
2517
- plateCore.toggleNodeType(editor, {
2638
+ toggleElement(editor, {
2518
2639
  activeType: type,
2519
2640
  inactiveType: type
2520
2641
  });
@@ -2644,7 +2765,7 @@ var buildHeadingEventHandler = function buildHeadingEventHandler(type) {
2644
2765
  editor.tracking.onShortcutAction(isActive ? 'remove' : 'insert', {
2645
2766
  nodeType: type
2646
2767
  });
2647
- plateCore.toggleNodeType(editor, {
2768
+ toggleElement(editor, {
2648
2769
  activeType: type,
2649
2770
  inactiveType: Contentful.BLOCKS.PARAGRAPH
2650
2771
  });
@@ -4089,6 +4210,178 @@ var createListPlugin = function createListPlugin() {
4089
4210
  });
4090
4211
  };
4091
4212
 
4213
+ var listTypes = [Contentful.BLOCKS.UL_LIST, Contentful.BLOCKS.OL_LIST];
4214
+
4215
+ var unwrapList = function unwrapList(editor, _temp) {
4216
+ var _ref = _temp === void 0 ? {} : _temp,
4217
+ at = _ref.at;
4218
+
4219
+ slate.Editor.withoutNormalizing(editor, function () {
4220
+ do {
4221
+ plateCore.unwrapNodes(editor, {
4222
+ at: at,
4223
+ match: {
4224
+ type: Contentful.BLOCKS.LIST_ITEM
4225
+ },
4226
+ split: true
4227
+ });
4228
+ plateCore.unwrapNodes(editor, {
4229
+ at: at,
4230
+ match: {
4231
+ type: listTypes
4232
+ },
4233
+ split: true
4234
+ });
4235
+ } while (plateCore.getAbove(editor, {
4236
+ match: {
4237
+ type: listTypes,
4238
+ at: at
4239
+ }
4240
+ }));
4241
+ });
4242
+ };
4243
+
4244
+ var toggleList = function toggleList(editor, _ref2) {
4245
+ var type = _ref2.type;
4246
+ return slate.Editor.withoutNormalizing(editor, function () {
4247
+ if (!editor.selection) {
4248
+ return;
4249
+ }
4250
+
4251
+ if (plateCore.isCollapsed(editor.selection) || !plateCore.isRangeAcrossBlocks(editor)) {
4252
+ // selection is collapsed
4253
+ var res = plateList.getListItemEntry(editor);
4254
+
4255
+ if (res) {
4256
+ var list = res.list;
4257
+
4258
+ if (list[0].type !== type) {
4259
+ plateCore.setNodes(editor, {
4260
+ type: type
4261
+ }, {
4262
+ at: editor.selection,
4263
+ match: function match(n) {
4264
+ return listTypes.includes(n.type);
4265
+ },
4266
+ mode: 'lowest'
4267
+ });
4268
+ } else {
4269
+ unwrapList(editor);
4270
+ }
4271
+ } else {
4272
+ var _list = {
4273
+ type: type,
4274
+ children: [],
4275
+ data: {}
4276
+ };
4277
+ plateCore.wrapNodes(editor, _list);
4278
+ var nodes = [].concat(plateCore.getNodes(editor, {
4279
+ match: {
4280
+ type: plateCore.getPluginType(editor, plateCore.ELEMENT_DEFAULT)
4281
+ }
4282
+ }));
4283
+ var listItem = {
4284
+ type: Contentful.BLOCKS.LIST_ITEM,
4285
+ children: [],
4286
+ data: {}
4287
+ };
4288
+
4289
+ for (var _iterator = _createForOfIteratorHelperLoose(nodes), _step; !(_step = _iterator()).done;) {
4290
+ var _step$value = _step.value,
4291
+ path = _step$value[1];
4292
+ plateCore.wrapNodes(editor, listItem, {
4293
+ at: path
4294
+ });
4295
+ }
4296
+ }
4297
+ } else {
4298
+ // selection is a range
4299
+ var _Range$edges = slate.Range.edges(editor.selection),
4300
+ startPoint = _Range$edges[0],
4301
+ endPoint = _Range$edges[1];
4302
+
4303
+ var commonEntry = slate.Node.common(editor, startPoint.path, endPoint.path);
4304
+
4305
+ if (listTypes.includes(commonEntry[0].type) || commonEntry[0].type === Contentful.BLOCKS.LIST_ITEM) {
4306
+ if (commonEntry[0].type !== type) {
4307
+ var startList = plateCore.findNode(editor, {
4308
+ at: slate.Range.start(editor.selection),
4309
+ match: {
4310
+ type: listTypes
4311
+ },
4312
+ mode: 'lowest'
4313
+ });
4314
+ var endList = plateCore.findNode(editor, {
4315
+ at: slate.Range.end(editor.selection),
4316
+ match: {
4317
+ type: listTypes
4318
+ },
4319
+ mode: 'lowest'
4320
+ });
4321
+
4322
+ if (!startList || !endList) {
4323
+ return;
4324
+ }
4325
+
4326
+ var rangeLength = Math.min(startList[1].length, endList[1].length);
4327
+ plateCore.setNodes(editor, {
4328
+ type: type
4329
+ }, {
4330
+ at: editor.selection,
4331
+ match: function match(n, path) {
4332
+ return listTypes.includes(n.type) && path.length >= rangeLength;
4333
+ },
4334
+ mode: 'all'
4335
+ });
4336
+ } else {
4337
+ unwrapList(editor);
4338
+ }
4339
+ } else {
4340
+ var rootPathLength = commonEntry[1].length;
4341
+
4342
+ var _nodes = Array.from(plateCore.getNodes(editor, {
4343
+ mode: 'all'
4344
+ })).filter(function (_ref3) {
4345
+ var path = _ref3[1];
4346
+ return path.length === rootPathLength + 1;
4347
+ }).reverse();
4348
+
4349
+ _nodes.forEach(function (n) {
4350
+ if (listTypes.includes(n[0].type)) {
4351
+ plateCore.setNodes(editor, {
4352
+ type: type
4353
+ }, {
4354
+ at: n[1]
4355
+ });
4356
+ } else {
4357
+ plateCore.setNodes(editor, {
4358
+ type: plateCore.getPluginType(editor, plateList.ELEMENT_LIC)
4359
+ }, {
4360
+ at: n[1]
4361
+ });
4362
+ var _listItem = {
4363
+ type: Contentful.BLOCKS.LIST_ITEM,
4364
+ children: [],
4365
+ data: {}
4366
+ };
4367
+ plateCore.wrapNodes(editor, _listItem, {
4368
+ at: n[1]
4369
+ });
4370
+ var _list2 = {
4371
+ type: type,
4372
+ children: [],
4373
+ data: {}
4374
+ };
4375
+ plateCore.wrapNodes(editor, _list2, {
4376
+ at: n[1]
4377
+ });
4378
+ }
4379
+ });
4380
+ }
4381
+ }
4382
+ });
4383
+ };
4384
+
4092
4385
  function ToolbarListButton(props) {
4093
4386
  var sdk = useSdkContext();
4094
4387
  var editor = useContentfulEditor();
@@ -4096,7 +4389,7 @@ function ToolbarListButton(props) {
4096
4389
  function handleClick(type) {
4097
4390
  return function () {
4098
4391
  if (!(editor != null && editor.selection)) return;
4099
- plateList.toggleList(editor, {
4392
+ toggleList(editor, {
4100
4393
  type: type
4101
4394
  });
4102
4395
  focus(editor);
@@ -4557,6 +4850,18 @@ function isEmptyElement(element) {
4557
4850
  return element.textContent === '';
4558
4851
  }
4559
4852
 
4853
+ var buildParagraphKeyDownHandler = function buildParagraphKeyDownHandler(editor, _ref) {
4854
+ var hotkey = _ref.options.hotkey;
4855
+ return function (event) {
4856
+ if (editor.selection && hotkey && isHotkey(hotkey, event)) {
4857
+ toggleElement(editor, {
4858
+ activeType: Contentful.BLOCKS.PARAGRAPH,
4859
+ inactiveType: Contentful.BLOCKS.PARAGRAPH
4860
+ });
4861
+ }
4862
+ };
4863
+ };
4864
+
4560
4865
  var createParagraphPlugin = function createParagraphPlugin() {
4561
4866
  var _transform;
4562
4867
 
@@ -4566,6 +4871,9 @@ var createParagraphPlugin = function createParagraphPlugin() {
4566
4871
  options: {
4567
4872
  hotkey: ['mod+opt+0']
4568
4873
  },
4874
+ handlers: {
4875
+ onKeyDown: buildParagraphKeyDownHandler
4876
+ },
4569
4877
  softBreak: [// create a new line with SHIFT+Enter inside a paragraph
4570
4878
  {
4571
4879
  hotkey: 'shift+enter',
@@ -4582,8 +4890,8 @@ var createParagraphPlugin = function createParagraphPlugin() {
4582
4890
  }
4583
4891
  },
4584
4892
  normalizer: [{
4585
- validChildren: function validChildren(_, _ref) {
4586
- var node = _ref[0];
4893
+ validChildren: function validChildren(_, _ref2) {
4894
+ var node = _ref2[0];
4587
4895
  return isInlineOrText(node);
4588
4896
  },
4589
4897
  transform: (_transform = {}, _transform[Contentful.BLOCKS.PARAGRAPH] = transformUnwrap, _transform["default"] = transformLift, _transform)
@@ -4769,10 +5077,6 @@ function toggleQuote(editor, logAction) {
4769
5077
  },
4770
5078
  split: true
4771
5079
  });
4772
- var _editor$selection = editor.selection,
4773
- anchor = _editor$selection.anchor,
4774
- focus = _editor$selection.focus;
4775
- var isTripleSelection = anchor.path[0] !== focus.path[0] && anchor.offset === 0 && focus.offset === 0;
4776
5080
 
4777
5081
  if (!isActive) {
4778
5082
  var quote = {
@@ -4780,9 +5084,7 @@ function toggleQuote(editor, logAction) {
4780
5084
  data: {},
4781
5085
  children: []
4782
5086
  };
4783
- slate.Transforms.wrapNodes(editor, quote, {
4784
- at: isTripleSelection ? editor.selection.anchor : undefined
4785
- });
5087
+ slate.Transforms.wrapNodes(editor, quote);
4786
5088
  }
4787
5089
  });
4788
5090
  }
@@ -5359,15 +5661,7 @@ var createTablePlugin = function createTablePlugin() {
5359
5661
  });
5360
5662
 
5361
5663
  if (fragmentHasTable) {
5362
- var emptyParagraph = {
5363
- type: Contentful.BLOCKS.PARAGRAPH,
5364
- children: [{
5365
- text: ''
5366
- }],
5367
- data: {},
5368
- isVoid: false
5369
- };
5370
- slate.Transforms.insertNodes(editor, emptyParagraph);
5664
+ insertEmptyParagraph(editor);
5371
5665
  }
5372
5666
 
5373
5667
  insertFragment(fragments);
@@ -5496,6 +5790,20 @@ function ToolbarTableButton(props) {
5496
5790
  function createTextPlugin() {
5497
5791
  return {
5498
5792
  key: 'TextPlugin',
5793
+ handlers: {
5794
+ // Triple selection in a non-Firefox browser undesirably selects
5795
+ // the start of the next block. Editor.unhangRange helps removing
5796
+ // the extra block at the end.
5797
+ onMouseUp: function onMouseUp(editor) {
5798
+ return function () {
5799
+ if (!editor.selection) {
5800
+ return;
5801
+ }
5802
+
5803
+ slate.Transforms.setSelection(editor, slate.Editor.unhangRange(editor, editor.selection));
5804
+ };
5805
+ }
5806
+ },
5499
5807
  withOverrides: function withOverrides(editor) {
5500
5808
  // Reverts the change made upstream that caused the cursor
5501
5809
  // to be trapped inside inline elements.
@@ -6107,7 +6415,10 @@ var useNormalizedSlateValue = function useNormalizedSlateValue(_ref) {
6107
6415
  schema: schema
6108
6416
  }); // Sets editor value & kicks normalization
6109
6417
 
6110
- slate.Transforms.insertNodes(editor, doc); // TODO: return the editor itself to avoid recompiling & initializing all
6418
+ editor.children = doc;
6419
+ slate.Editor.normalize(editor, {
6420
+ force: true
6421
+ }); // TODO: return the editor itself to avoid recompiling & initializing all
6111
6422
  // of the plugins again. It's currently not possible due to a bug in Plate
6112
6423
  // with initialValues
6113
6424
  // See: https://slate-js.slack.com/archives/C013QHXSCG1/p1645112799942819
@@ -6150,8 +6461,9 @@ var useOnValueChanged = function useOnValueChanged(_ref) {
6150
6461
 
6151
6462
  var _excluded = ["sdk", "isInitiallyDisabled", "onAction"];
6152
6463
  var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
6153
- var id = useContentfulEditorId();
6154
- var editor = useContentfulEditor();
6464
+ var id = getContentfulEditorId(props.sdk); // TODO: remove in favor of getting the editor from useNormalizedSlateValue after upgrading to Plate v10
6465
+
6466
+ var editor = useContentfulEditor(id);
6155
6467
  var plugins = React__default.useMemo(function () {
6156
6468
  var _props$onAction;
6157
6469
 
@@ -6169,7 +6481,20 @@ var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
6169
6481
  var classNames = emotion.cx(styles$j.editor, props.minHeight !== undefined ? emotion.css({
6170
6482
  minHeight: props.minHeight
6171
6483
  }) : undefined, props.isDisabled ? styles$j.disabled : styles$j.enabled, props.isToolbarHidden && styles$j.hiddenToolbar);
6172
- return /*#__PURE__*/React__default.createElement("div", {
6484
+ React.useEffect(function () {
6485
+ // Ensure the plate state is cleared after the component unmounts
6486
+ // This prevent new editors for the same field to display old outdated values
6487
+ // Typical scenario: coming back to the entry editor after restoring a previous entry version
6488
+ plateCore.getPlateActions(id).enabled(true);
6489
+ return function () {
6490
+ return plateCore.getPlateActions(id).enabled(false);
6491
+ };
6492
+ }, [id]);
6493
+ return /*#__PURE__*/React__default.createElement(SdkProvider, {
6494
+ sdk: props.sdk
6495
+ }, /*#__PURE__*/React__default.createElement(ContentfulEditorIdProvider, {
6496
+ value: id
6497
+ }, /*#__PURE__*/React__default.createElement("div", {
6173
6498
  className: styles$j.root,
6174
6499
  "data-test-id": "rich-text-editor"
6175
6500
  }, /*#__PURE__*/React__default.createElement(plateCore.Plate, {
@@ -6186,7 +6511,7 @@ var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
6186
6511
  isDisabled: props.isDisabled
6187
6512
  }, /*#__PURE__*/React__default.createElement(Toolbar, {
6188
6513
  isDisabled: props.isDisabled
6189
- }))));
6514
+ }))))));
6190
6515
  };
6191
6516
 
6192
6517
  var RichTextEditor = function RichTextEditor(props) {
@@ -6198,11 +6523,8 @@ var RichTextEditor = function RichTextEditor(props) {
6198
6523
  var isEmptyValue = React.useCallback(function (value) {
6199
6524
  return !value || deepEquals(value, Contentful.EMPTY_DOCUMENT);
6200
6525
  }, []);
6201
- var editorId = getContentfulEditorId(sdk);
6202
6526
  return /*#__PURE__*/React__default.createElement(fieldEditorReference.EntityProvider, {
6203
6527
  sdk: sdk
6204
- }, /*#__PURE__*/React__default.createElement(SdkProvider, {
6205
- sdk: sdk
6206
6528
  }, /*#__PURE__*/React__default.createElement(fieldEditorShared.FieldConnector, {
6207
6529
  throttle: 0,
6208
6530
  field: sdk.field,
@@ -6214,17 +6536,15 @@ var RichTextEditor = function RichTextEditor(props) {
6214
6536
  disabled = _ref.disabled,
6215
6537
  setValue = _ref.setValue,
6216
6538
  externalReset = _ref.externalReset;
6217
- return /*#__PURE__*/React__default.createElement(ContentfulEditorIdProvider, {
6218
- value: editorId
6219
- }, /*#__PURE__*/React__default.createElement(ConnectedRichTextEditor, Object.assign({}, otherProps, {
6539
+ return /*#__PURE__*/React__default.createElement(ConnectedRichTextEditor, Object.assign({}, otherProps, {
6220
6540
  key: "rich-text-editor-" + externalReset,
6221
6541
  value: lastRemoteValue,
6222
6542
  sdk: sdk,
6223
6543
  onAction: onAction,
6224
6544
  isDisabled: disabled,
6225
6545
  onChange: setValue
6226
- })));
6227
- })));
6546
+ }));
6547
+ }));
6228
6548
  };
6229
6549
 
6230
6550
  var LINK_TYPES$1 = {